1 /* $Id: confparse.h 5114 2002-02-18 01:17:24Z rra $
3 ** Configuration file parsing interface.
6 #ifndef INN_CONFPARSE_H
7 #define INN_CONFPARSE_H 1
9 #include <inn/defines.h>
11 /* Avoid including <inn/vector.h> unless the client needs it. */
14 /* The opaque data type representing a configuration tree. */
19 /* Parse the given file and build a configuration tree. This does purely
20 syntactic parsing; no semantic checking is done. After the file name, a
21 NULL-terminated list of const char * pointers should be given, naming the
22 top-level group types that the caller is interested in. If none are given
23 (if the second argument is NULL), the entire file is parsed. (This is
24 purely for efficiency reasons; if one doesn't care about speed, everything
25 will work the same if no types are given.)
27 Returns a config_group for the top-level group representing the entire
28 file. Generally one never wants to query parameters in this group;
29 instead, the client should then call config_find_group for the group type
30 of interest. Returns NULL on failure to read the file or on a parse
31 failure; errors are reported via warn. */
32 struct config_group *config_parse_file(const char *filename, /* types */ ...);
34 /* config_find_group returns the first group of the given type found in the
35 tree rooted at its argument. config_next_group returns the next group in
36 the tree of the same type as the given group (or NULL if none is found).
37 This can be used to do such things as enumerate all "peer" groups in a
38 configuration file. */
39 struct config_group *config_find_group(struct config_group *,
41 struct config_group *config_next_group(struct config_group *);
43 /* Accessor functions for group information. */
44 const char *config_group_type(struct config_group *);
45 const char *config_group_tag(struct config_group *);
47 /* Look up a parameter in a given config tree. The second argument is the
48 name of the parameter, and the result will be stored in the third argument
49 if the function returns true. If it returns false, the third argument is
50 unchanged and that parameter wasn't set (or was set to an invalid value for
51 the expected type). */
52 bool config_param_boolean(struct config_group *, const char *, bool *);
53 bool config_param_integer(struct config_group *, const char *, long *);
54 bool config_param_real(struct config_group *, const char *, double *);
55 bool config_param_string(struct config_group *, const char *, const char **);
56 bool config_param_list(struct config_group *, const char *, struct vector *);
58 /* Used for checking a configuration file, returns a vector of all parameters
59 set for the given config_group, including inherited ones. */
60 struct vector *config_params(struct config_group *);
62 /* Used for reporting semantic errors, config_error_param reports the given
63 error at a particular parameter in a config_group and config_error_group
64 reports an error at the definition of that group. The error is reported
66 void config_error_group(struct config_group *, const char *format, ...);
67 void config_error_param(struct config_group *, const char *key,
68 const char *format, ...);
70 /* Free all space allocated by the tree rooted at config_group. One normally
71 never wants to do this. WARNING: This includes the storage allocated for
72 all strings returned by config_param_string and config_param_list for any
73 configuration groups in this tree. */
74 void config_free(struct config_group *);
78 #endif /* INN_CONFPARSE_H */