2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 * \brief Configuration File Parser
23 #ifndef _ASTERISK_CONFIG_H
24 #define _ASTERISK_CONFIG_H
26 #if defined(__cplusplus) || defined(c_plusplus)
36 /*! \brief Structure for variables, used for configurations and for channel variables
42 int object; /*!< 0 for variable, 1 for object */
43 int blanklines; /*!< Number of blanklines following entry */
44 struct ast_comment *precomments;
45 struct ast_comment *sameline;
46 struct ast_variable *next;
50 typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, int withcomments);
51 typedef struct ast_variable *realtime_var_get(const char *database, const char *table, va_list ap);
52 typedef struct ast_config *realtime_multi_get(const char *database, const char *table, va_list ap);
53 typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
54 typedef int realtime_store(const char *database, const char *table, va_list ap);
55 typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, va_list ap);
57 /*! \brief Configuration engine structure, used to define realtime drivers */
58 struct ast_config_engine {
60 config_load_func *load_func;
61 realtime_var_get *realtime_func;
62 realtime_multi_get *realtime_multi_func;
63 realtime_update *update_func;
64 realtime_store *store_func;
65 realtime_destroy *destroy_func;
66 struct ast_config_engine *next;
69 /*! \brief Load a config file
70 * \param filename path of file to open. If no preceding '/' character, path is considered relative to AST_CONFIG_DIR
71 * Create a config structure from a given configuration file.
73 * Returns NULL on error, or an ast_config data structure on success
75 struct ast_config *ast_config_load(const char *filename);
76 struct ast_config *ast_config_load_with_comments(const char *filename);
78 /*! \brief Destroys a config
79 * \param config pointer to config data structure
80 * Free memory associated with a given config
83 void ast_config_destroy(struct ast_config *config);
85 /*! \brief Goes through categories
86 * \param config Which config structure you wish to "browse"
87 * \param prev A pointer to a previous category.
88 * This funtion is kind of non-intuitive in it's use. To begin, one passes NULL as the second arguement. It will return a pointer to the string of the first category in the file. From here on after, one must then pass the previous usage's return value as the second pointer, and it will return a pointer to the category name afterwards.
90 * Returns a category on success, or NULL on failure/no-more-categories
92 char *ast_category_browse(struct ast_config *config, const char *prev);
94 /*! \brief Goes through variables
95 * Somewhat similar in intent as the ast_category_browse.
96 * List variables of config file category
98 * Returns ast_variable list on success, or NULL on failure
100 struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category);
102 /*! \brief Gets a variable
103 * \param config which (opened) config to use
104 * \param category category under which the variable lies
105 * \param variable which variable you wish to get the data for
106 * Goes through a given config file in the given category and searches for the given variable
108 * Returns the variable value on success, or NULL if unable to find it.
110 const char *ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable);
112 /*! \brief Retrieve a category if it exists
113 * \param config which config to use
114 * \param category_name name of the category you're looking for
115 * This will search through the categories within a given config file for a match.
117 * Returns pointer to category if found, NULL if not.
119 struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name);
121 /*! \brief Check for category duplicates
122 * \param config which config to use
123 * \param category_name name of the category you're looking for
124 * This will search through the categories within a given config file for a match.
126 * Return non-zero if found
128 int ast_category_exist(const struct ast_config *config, const char *category_name);
130 /*! \brief Retrieve realtime configuration
131 * \param family which family/config to lookup
132 * This will use builtin configuration backends to look up a particular
133 * entity in realtime and return a variable list of its parameters. Note
134 * that unlike the variables in ast_config, the resulting list of variables
135 * MUST be freed with ast_variables_destroy() as there is no container.
137 struct ast_variable *ast_load_realtime(const char *family, ...);
138 struct ast_variable *ast_load_realtime_all(const char *family, ...);
140 /*! \brief Retrieve realtime configuration
141 * \param family which family/config to lookup
142 * This will use builtin configuration backends to look up a particular
143 * entity in realtime and return a variable list of its parameters. Unlike
144 * the ast_load_realtime, this function can return more than one entry and
145 * is thus stored inside a taditional ast_config structure rather than
146 * just returning a linked list of variables.
148 struct ast_config *ast_load_realtime_multientry(const char *family, ...);
150 /*! \brief Update realtime configuration
151 * \param family which family/config to be updated
152 * \param keyfield which field to use as the key
153 * \param lookup which value to look for in the key field to match the entry.
154 * This function is used to update a parameter in realtime configuration space.
157 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...);
159 /*! \brief Check if realtime engine is configured for family
160 * returns 1 if family is configured in realtime and engine exists
161 * \param family which family/config to be checked
163 int ast_check_realtime(const char *family);
165 /*! \brief Check if there's any realtime engines loaded */
166 int ast_realtime_enabled(void);
168 /*! \brief Free variable list
169 * \param var the linked list of variables to free
170 * This function frees a list of variables.
172 void ast_variables_destroy(struct ast_variable *var);
174 /*! \brief Register config engine */
175 int ast_config_engine_register(struct ast_config_engine *newconfig);
177 /*! \brief Deegister config engine */
178 int ast_config_engine_deregister(struct ast_config_engine *del);
180 int register_config_cli(void);
181 int read_config_maps(void);
183 struct ast_config *ast_config_new(void);
184 struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
185 void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat);
186 const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var);
188 struct ast_category *ast_category_new(const char *name);
189 void ast_category_append(struct ast_config *config, struct ast_category *cat);
190 int ast_category_delete(struct ast_config *cfg, const char *category);
191 void ast_category_destroy(struct ast_category *cat);
192 struct ast_variable *ast_category_detach_variables(struct ast_category *cat);
193 void ast_category_rename(struct ast_category *cat, const char *name);
195 struct ast_variable *ast_variable_new(const char *name, const char *value);
196 void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
197 int ast_variable_delete(struct ast_category *category, const char *variable, const char *match);
198 int ast_variable_update(struct ast_category *category, const char *variable, const char *value, const char *match);
200 int config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
202 struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, int withcomments);
204 #if defined(__cplusplus) || defined(c_plusplus)
208 #endif /* _ASTERISK_CONFIG_H */