settings-parser.h revision b73cc2ac2a6e6234338429871ed4251c72bdbc78
#ifndef SETTINGS_PARSER_H
#define SETTINGS_PARSER_H
struct var_expand_table;
#define SETTINGS_SEPARATOR '/'
#define SETTINGS_SEPARATOR_S "/"
/* STR_VARS pointer begins with either of these initially. Before actually
using the variables all variables in all unexpanded strings need to be
expanded. Afterwards the string pointers should be increased to skip
the initial '1' so it'll be easy to use them. */
#define SETTING_STRVAR_UNEXPANDED "0"
#define SETTING_STRVAR_EXPANDED "1"
/* When parsing streams, this character is translated to LF. */
#define SETTING_STREAM_LF_CHAR "\003"
enum setting_type {
SET_STR_VARS, /* string with %variables */
SET_DEFLIST, /* of type array_t */
SET_STRLIST /* of type ARRAY_TYPE(const_string) */
};
#define SETTING_TYPE_IS_DEFLIST(type) \
struct setting_define {
enum setting_type type;
const char *key;
const struct setting_parser_info *list_info;
};
((struct struct_name *)0)->name, bool), \
((struct struct_name *)0)->name, unsigned int), \
((struct struct_name *)0)->name, unsigned int), \
((struct struct_name *)0)->name, const char *), \
struct setting_parser_info {
const char *module_name;
const struct setting_define *defines;
const void *defaults;
const struct setting_parser_info *parent;
const struct setting_parser_info *const *dependencies;
struct dynamic_settings_parser *dynamic_parsers;
};
/* name=NULL-terminated list of parsers. These follow the static settings.
After this list follows the actual settings. */
struct dynamic_settings_parser {
const char *name;
const struct setting_parser_info *info;
};
enum settings_parser_flags {
};
struct setting_parser_context;
struct setting_parser_context *
enum settings_parser_flags flags);
struct setting_parser_context *
const struct setting_parser_info *const *roots,
/* Return pointer to root setting structure. */
/* If there are multiple roots, return a NULL-terminated list to all of
their settings. */
/* Like settings_parser_get(), but return change struct. */
/* Return the last error. */
/* Return the parser info used for the previously parsed line. */
const struct setting_parser_info *
/* Returns TRUE if the given key is a valid setting. */
const char *key);
/* Parse a single line. Returns 1 if OK, 0 if key is unknown, -1 if error. */
/* Parse data already read in input stream. */
/* Read data from input stream and parser it. returns -1 = error,
0 = done, 1 = not finished yet (stream is non-blocking) */
/* Open file and parse it. */
/* Execute the given binary and wait for it to return the configuration. */
const char *bin_path, const char *config_path,
const char *service);
/* Call all check_func()s to see if currently parsed settings are valid. */
const char **error_r);
/* While parsing values, specifies if STR_VARS strings are already expanded. */
bool is_expanded);
/* Mark all the parsed settings with given keys as being already expanded. */
/* Update variable string pointers to skip over the '1' or '0'.
This is mainly useful when you want to run settings_parser_check() without
actually knowing what the variables are. */
/* Expand all unexpanded variables using the given table. Update the string
pointers so that they can be used without skipping over the '1'. */
const struct var_expand_table *table);
/* Go through all the settings and return the first one that has an unexpanded
setting containing the given %key. */
char var_key, const char *long_var_key,
/* Duplicate the entire settings structure. */
/* Duplicate the entire setting parser. */
struct setting_parser_context *
/* parsers is a name=NULL -terminated list. The parsers are appended as
dynamic_settings_list structures to their parent. All must have the same
parent. The new structures are allocated from the given pool. */
struct setting_parser_info *parent,
const struct dynamic_settings_parser *parsers);
/* Return pointer to beginning of settings for given name, or NULL if there is
no such registered name. */
/* Copy changed settings from src to dest. If conflict_key_r is not NULL and
both src and dest have changed the same setting, return -1 and set the
key name. If it's NULL, the old setting is kept. */
const struct setting_parser_context *src,
/* Return section name escaped */
const char *settings_section_escape(const char *name);
/* Parse time interval string, return as seconds. */
const char **error_r);
/* Parse size string, return as bytes. */
const char **error_r);
#endif