Asterisk - The Open Source Telephony Project  18.5.0
include/asterisk/config.h
Go to the documentation of this file.
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (C) 1999 - 2005, Digium, Inc.
5  *
6  * Mark Spencer <[email protected]>
7  *
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.
13  *
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.
17  */
18 
19 /*! \file
20  * \brief Configuration File Parser
21  */
22 
23 #ifndef _ASTERISK_CONFIG_H
24 #define _ASTERISK_CONFIG_H
25 
26 #if defined(__cplusplus) || defined(c_plusplus)
27 extern "C" {
28 #endif
29 
30 #include "asterisk/utils.h"
31 #include "asterisk/inline_api.h"
32 
33 struct ast_config;
34 
35 struct ast_category;
36 
37 /*! Options for ast_config_load()
38  */
39 enum {
40  /*! Load the configuration, including comments */
42  /*! On a reload, give us a -1 if the file hasn't changed. */
44  /*! Don't attempt to cache mtime on this config file. */
45  CONFIG_FLAG_NOCACHE = (1 << 2),
46  /*! Don't attempt to load from realtime (typically called from a realtime driver dependency) */
48 };
49 
50 /*! Flags for ast_config_text_file_save2()
51  */
54  /*! Insure a context doesn't effectively change if a template changes (pre 13.2 behavior) */
56 };
57 
58 #define CONFIG_STATUS_FILEMISSING (void *)0
59 #define CONFIG_STATUS_FILEUNCHANGED (void *)-1
60 #define CONFIG_STATUS_FILEINVALID (void *)-2
61 
62 /*!
63  * \brief Types used in ast_realtime_require_field
64  */
65 typedef enum {
80 } require_type;
81 
82 /*! \brief Structure for variables, used for configurations and for channel variables */
83 struct ast_variable {
84  /*! Variable name. Stored in stuff[] at struct end. */
85  const char *name;
86  /*! Variable value. Stored in stuff[] at struct end. */
87  const char *value;
88 
89  /*! Next node in the list. */
90  struct ast_variable *next;
91 
92  /*! Filename where variable found. Stored in stuff[] at struct end. */
93  const char *file;
94 
95  int lineno;
96  int object; /*!< 0 for variable, 1 for object */
97  int blanklines; /*!< Number of blanklines following entry */
98  int inherited; /*!< 1 for inherited from template or other base */
101  struct ast_comment *trailing; /*!< the last object in the list will get assigned any trailing comments when EOF is hit */
102  /*!
103  * \brief Contents of file, name, and value in that order stuffed here.
104  * \note File must be stuffed before name because of ast_include_rename().
105  */
106  char stuff[0];
107 };
108 
109 typedef struct ast_config *config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked);
110 typedef struct ast_variable *realtime_var_get(const char *database, const char *table, const struct ast_variable *fields);
111 typedef struct ast_config *realtime_multi_get(const char *database, const char *table, const struct ast_variable *fields);
112 typedef int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
113 typedef int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
114 typedef int realtime_store(const char *database, const char *table, const struct ast_variable *fields);
115 typedef int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields);
116 
117 /*!
118  * \brief Function pointer called to ensure database schema is properly configured for realtime use
119  * \since 1.6.1
120  */
121 typedef int realtime_require(const char *database, const char *table, va_list ap);
122 
123 /*!
124  * \brief Function pointer called to clear the database cache and free resources used for such
125  * \since 1.6.1
126  */
127 typedef int realtime_unload(const char *database, const char *table);
128 
129 /*! \brief Configuration engine structure, used to define realtime drivers */
131  char *name;
142 };
143 
144 /*!
145  * \brief Load a config file
146  *
147  * \param filename path of file to open. If no preceding '/' character,
148  * path is considered relative to AST_CONFIG_DIR
149  * \param who_asked The module which is making this request.
150  * \param flags Optional flags:
151  * CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
152  * CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
153  * CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
154  *
155  * \details
156  * Create a config structure from a given configuration file.
157  *
158  * \return an ast_config data structure on success
159  * \retval NULL on error
160  */
161 struct ast_config *ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags);
162 
163 /*!
164  * \brief Load a config file
165  *
166  * \param filename path of file to open. If no preceding '/' character,
167  * path is considered relative to AST_CONFIG_DIR
168  * \param flags Optional flags:
169  * CONFIG_FLAG_WITHCOMMENTS - load the file with comments intact;
170  * CONFIG_FLAG_FILEUNCHANGED - check the file mtime and return CONFIG_STATUS_FILEUNCHANGED if the mtime is the same; or
171  * CONFIG_FLAG_NOCACHE - don't cache file mtime (main purpose of this option is to save memory on temporary files).
172  *
173  * \details
174  * Create a config structure from a given configuration file.
175  *
176  * \return an ast_config data structure on success
177  * \retval NULL on error
178  */
179 #define ast_config_load(filename, flags) ast_config_load2(filename, AST_MODULE, flags)
180 
181 /*!
182  * \brief Destroys a config
183  *
184  * \param config pointer to config data structure
185  *
186  * \details
187  * Free memory associated with a given config
188  */
189 void ast_config_destroy(struct ast_config *config);
190 
191 /*!
192  * \brief returns the root ast_variable of a config
193  *
194  * \param config pointer to an ast_config data structure
195  * \param cat name of the category for which you want the root
196  *
197  * \return the category specified
198  */
199 struct ast_variable *ast_category_root(struct ast_config *config, char *cat);
200 
201 /*!
202  * \brief Sorts categories in a config in the order of a numerical value contained within them.
203  *
204  * \param config The config structure you wish to sort
205  * \param comparator variable Which numerical value you wish to sort by
206  * \param descending If true, we sort highest to lowest instead of lowest to highest
207  *
208  * \details
209  * This function will assume a value of 0 for any non-numerical strings and NULL fields.
210  */
211 void ast_config_sort_categories(struct ast_config *config, int descending,
212  int (*comparator)(struct ast_category *p, struct ast_category *q));
213 
214 /*!
215  * \brief Browse categories with filters
216  *
217  * \param config Which config structure you wish to "browse"
218  * \param category_name An optional category name.
219  * Pass NULL to not restrict by category name.
220  * \param prev A pointer to the starting category structure.
221  * Pass NULL to start at the beginning.
222  * \param filter An optional comma-separated list of <name_regex>=<value_regex>
223  * pairs. Only categories with matching variables will be returned.
224  * The special name 'TEMPLATES' can be used with the special values
225  * 'include' or 'restrict' to include templates in the result or
226  * restrict the result to only templates.
227  *
228  * \retval a category on success
229  * \retval NULL on failure/no-more-categories
230  */
232  const char *category_name, struct ast_category *prev, const char *filter);
233 
234 /*!
235  * \brief Browse categories
236  *
237  * \param config Which config structure you wish to "browse"
238  * \param prev_name A pointer to a previous category name.
239  *
240  * \details
241  * This function is kind of non-intuitive in it's use.
242  * To begin, one passes NULL as the second argument.
243  * It will return a pointer to the string of the first category in the file.
244  * From here on after, one must then pass the previous usage's return value
245  * as the second pointer, and it will return a pointer to the category name
246  * afterwards.
247  *
248  * \retval a category name on success
249  * \retval NULL on failure/no-more-categories
250  *
251  * \note ast_category_browse maintains internal state. Therefore is not thread
252  * safe, cannot be called recursively, and it is not safe to add or remove
253  * categories while browsing.
254  * ast_category_browse_filtered does not have these restrictions.
255  */
256 char *ast_category_browse(struct ast_config *config, const char *prev_name);
257 
258 /*!
259  * \brief Browse variables
260  * \param config Which config structure you wish to "browse"
261  * \param category_name Which category to "browse"
262  * \param filter an optional comma-separated list of <name_regex>=<value_regex>
263  * pairs. Only categories with matching variables will be browsed.
264  * The special name 'TEMPLATES' can be used with the special values
265  * 'include' or 'restrict' to include templates in the result or
266  * restrict the result to only templates.
267  *
268  * \details
269  * Somewhat similar in intent as the ast_category_browse.
270  * List variables of config file category
271  *
272  * \retval ast_variable list on success
273  * \retval NULL on failure
274  */
275 struct ast_variable *ast_variable_browse_filtered(const struct ast_config *config,
276  const char *category_name, const char *filter);
277 struct ast_variable *ast_variable_browse(const struct ast_config *config,
278  const char *category_name);
279 
280 /*!
281  * \brief given a pointer to a category, return the root variable.
282  *
283  * \details
284  * This is equivalent to ast_variable_browse(), but more efficient if we
285  * already have the struct ast_category * (e.g. from ast_category_get())
286  */
287 struct ast_variable *ast_category_first(struct ast_category *cat);
288 
289 /*!
290  * \brief Gets a variable by context and variable names
291  *
292  * \param config which (opened) config to use
293  * \param category category under which the variable lies
294  * \param variable which variable you wish to get the data for
295  * \param filter an optional comma-separated list of <name_regex>=<value_regex>
296  * pairs. Only categories with matching variables will be searched.
297  * The special name 'TEMPLATES' can be used with the special values
298  * 'include' or 'restrict' to include templates in the result or
299  * restrict the result to only templates.
300  *
301  * \retval The variable value on success
302  * \retval NULL if unable to find it.
303  */
304 const char *ast_variable_retrieve_filtered(struct ast_config *config,
305  const char *category, const char *variable, const char *filter);
306 const char *ast_variable_retrieve(struct ast_config *config,
307  const char *category, const char *variable);
308 
309 /*!
310  * \brief Gets a variable value from a specific category structure by name
311  *
312  * \param category category structure under which the variable lies
313  * \param variable which variable you wish to get the data for
314  *
315  * \details
316  * Goes through a given category and searches for the given variable
317  *
318  * \retval The variable value on success
319  * \retval NULL if unable to find it.
320  */
321 const char *ast_variable_find(const struct ast_category *category, const char *variable);
322 
323 /*!
324  * \brief Gets the value of a variable from a variable list by name
325  *
326  * \param list variable list to search
327  * \param variable which variable you wish to get the data for
328  *
329  * \details
330  * Goes through a given variable list and searches for the given variable
331  *
332  * \retval The variable value on success
333  * \retval NULL if unable to find it.
334  */
335 const char *ast_variable_find_in_list(const struct ast_variable *list, const char *variable);
336 
337 /*!
338  * \brief Gets the value of the LAST occurrence of a variable from a variable list
339  *
340  * \param list The ast_variable list to search
341  * \param variable The name of the ast_variable you wish to fetch data for
342  *
343  * \details
344  * Iterates over a given ast_variable list to search for the last occurrence of an
345  * ast_variable entry with a name attribute matching the given name (variable).
346  * This is useful if the list has duplicate entries (such as in cases where entries
347  * are created by a template)
348  *
349  * \retval The variable value on success
350  * \retval NULL if unable to find it.
351  */
352 const char *ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable);
353 
354 /*!
355  * \brief Gets a variable from a variable list by name
356  * \since 13.9.0
357  *
358  * \param list variable list to search
359  * \param variable name you wish to get the data for
360  *
361  * \details
362  * Goes through a given variable list and searches for the given variable
363  *
364  * \retval The variable (not the value) on success
365  * \retval NULL if unable to find it.
366  */
367 const struct ast_variable *ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name);
368 
369 /*!
370  * \brief Retrieve a category if it exists
371  *
372  * \param config which config to use
373  * \param category_name name of the category you're looking for
374  * \param filter If a config contains more than 1 category with the same name,
375  * you can specify a filter to narrow the search. The filter is a comma-separated
376  * list of <name_regex>=<value_regex> pairs. Only a category with matching
377  * variables will be returned. The special name 'TEMPLATES' can be used with the
378  * special values 'include' or 'restrict' to include templates in the result or
379  * restrict the result to only templates.
380  *
381  * \details
382  * This will search through the categories within a given config file for a match.
383  *
384  * \retval pointer to category if found
385  * \retval NULL if not.
386  */
387 struct ast_category *ast_category_get(const struct ast_config *config,
388  const char *category_name, const char *filter);
389 
390 /*!
391  * \brief Return the name of the category
392  *
393  * \param category category structure
394  *
395  * \retval pointer to category name if found
396  * \retval NULL if not.
397  */
398 const char *ast_category_get_name(const struct ast_category *category);
399 
400 /*!
401  * \brief Check if category is a template
402  *
403  * \param category category structure
404  *
405  * \retval 1 if a template.
406  * \retval 0 if not.
407  */
408 int ast_category_is_template(const struct ast_category *category);
409 
410 /*!
411  * \brief Return the template names this category inherits from
412  *
413  * \param category category structure
414  *
415  * \return an ast_str (which must be freed after use) with a comma
416  * separated list of templates names or NULL if there were no templates.
417  */
418 struct ast_str *ast_category_get_templates(const struct ast_category *category);
419 
420 /*!
421  * \brief Check for category duplicates
422  *
423  * \param config which config to use
424  * \param category_name name of the category you're looking for
425  * \param filter an optional comma-separated list of <name_regex>=<value_regex>
426  * pairs. Only categories with matching variables will be returned.
427  * The special name 'TEMPLATES' can be used with the special values
428  * 'include' or 'restrict' to include templates in the result or
429  * restrict the result to only templates.
430  *
431  * \details
432  * This will search through the categories within a given config file for a match.
433  *
434  * \return non-zero if found
435  */
436 int ast_category_exist(const struct ast_config *config, const char *category_name,
437  const char *filter);
438 
439 /*!
440  * \brief Retrieve realtime configuration
441  *
442  * \param family which family/config to lookup
443  *
444  * \details
445  * This will use builtin configuration backends to look up a particular
446  * entity in realtime and return a variable list of its parameters.
447  *
448  * \note
449  * Unlike the variables in ast_config, the resulting list of variables
450  * MUST be freed with ast_variables_destroy() as there is no container.
451  *
452  * \note
453  * The difference between these two calls is that ast_load_realtime excludes
454  * fields whose values are NULL, while ast_load_realtime_all loads all columns.
455  *
456  * \note
457  * You should use the constant SENTINEL to terminate arguments, in
458  * order to preserve cross-platform compatibility.
459  */
460 struct ast_variable *ast_load_realtime_fields(const char *family, const struct ast_variable *fields);
461 struct ast_variable *ast_load_realtime(const char *family, ...) attribute_sentinel;
462 struct ast_variable *ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields);
463 struct ast_variable *ast_load_realtime_all(const char *family, ...) attribute_sentinel;
464 
465 /*!
466  * \brief Release any resources cached for a realtime family
467  * \since 1.6.1
468  *
469  * \param family which family/config to destroy
470  *
471  * \details
472  * Various backends may cache attributes about a realtime data storage
473  * facility; on reload, a front end resource may request to purge that cache.
474  *
475  * \retval 0 If any cache was purged
476  * \retval -1 If no cache was found
477  */
478 int ast_unload_realtime(const char *family);
479 
480 /*!
481  * \brief Inform realtime what fields that may be stored
482  * \since 1.6.1
483  *
484  * \param family which family/config is referenced
485  *
486  * \details
487  * This will inform builtin configuration backends that particular fields
488  * may be updated during the use of that configuration section. This is
489  * mainly to be used during startup routines, to ensure that various fields
490  * exist in the backend. The backends may take various actions, such as
491  * creating new fields in the data store or warning the administrator that
492  * new fields may need to be created, in order to ensure proper function.
493  *
494  * The arguments are specified in groups of 3: column name, column type,
495  * and column size. The column types are specified as integer constants,
496  * defined by the enum require_type. Note that the size is specified as
497  * the number of equivalent character fields that a field may take up, even
498  * if a field is otherwise specified as an integer type. This is due to
499  * the fact that some fields have historically been specified as character
500  * types, even if they contained integer values.
501  *
502  * A family should always specify its fields to the minimum necessary
503  * requirements to fulfill all possible values (within reason; for example,
504  * a timeout value may reasonably be specified as an INTEGER2, with size 5.
505  * Even though values above 32767 seconds are possible, they are unlikely
506  * to be useful, and we should not complain about that size).
507  *
508  * \retval 0 Required fields met specified standards
509  * \retval -1 One or more fields was missing or insufficient
510  *
511  * \note You should use the constant SENTINEL to terminate arguments, in
512  * order to preserve cross-platform compatibility.
513  *
514  * TODO The return value of this function is routinely ignored. Ignoring
515  * the return value means that it's mostly pointless to be calling this.
516  * You'll see some warning messages potentially, but that's it.
517  *
518  * XXX This function is super useful for detecting configuration problems
519  * early, but unfortunately, the latest in configuration management, sorcery,
520  * doesn't work well with this. Users of sorcery are familiar with the fields
521  * they will need to write but don't know if realtime is being used. Sorcery
522  * knows what storage mechanism is being used but has no high-level knowledge
523  * of what sort of data is going to be written.
524  */
525 int ast_realtime_require_field(const char *family, ...) attribute_sentinel;
526 
527 /*!
528  * \brief Retrieve realtime configuration
529  *
530  * \param family which family/config to lookup
531  * \param fields list of fields
532  *
533  * \details
534  * This will use builtin configuration backends to look up a particular
535  * entity in realtime and return a variable list of its parameters. Unlike
536  * the ast_load_realtime, this function can return more than one entry and
537  * is thus stored inside a traditional ast_config structure rather than
538  * just returning a linked list of variables.
539  *
540  * \return An ast_config with one or more results
541  * \retval NULL Error or no results returned
542  */
543 struct ast_config *ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields);
544 
545 /*!
546  * \brief Retrieve realtime configuration
547  *
548  * \param family which family/config to lookup
549  *
550  * \details
551  * This will use builtin configuration backends to look up a particular
552  * entity in realtime and return a variable list of its parameters. Unlike
553  * the ast_load_realtime, this function can return more than one entry and
554  * is thus stored inside a traditional ast_config structure rather than
555  * just returning a linked list of variables.
556  *
557  * \return An ast_config with one or more results
558  * \retval NULL Error or no results returned
559  *
560  * \note You should use the constant SENTINEL to terminate arguments, in
561  * order to preserve cross-platform compatibility.
562  */
563 struct ast_config *ast_load_realtime_multientry(const char *family, ...) attribute_sentinel;
564 
565 /*!
566  * \brief Update realtime configuration
567  *
568  * \param family which family/config to be updated
569  * \param keyfield which field to use as the key
570  * \param lookup which value to look for in the key field to match the entry.
571  * \param fields fields to update
572  *
573  * \details
574  * This function is used to update a parameter in realtime configuration space.
575  *
576  * \return Number of rows affected, or -1 on error.
577  */
578 int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
579 
580 /*!
581  * \brief Update realtime configuration
582  *
583  * \param family which family/config to be updated
584  * \param keyfield which field to use as the key
585  * \param lookup which value to look for in the key field to match the entry.
586  *
587  * \details
588  * This function is used to update a parameter in realtime configuration space.
589  *
590  * \return Number of rows affected, or -1 on error.
591  *
592  * \note You should use the constant SENTINEL to terminate arguments, in
593  * order to preserve cross-platform compatibility.
594  */
595 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
596 
597 /*!
598  * \brief Update realtime configuration
599  *
600  * \param family which family/config to be updated
601  * \param lookup_fields fields used to look up entries
602  * \param update_fields fields to update
603  *
604  * \details
605  * This function is used to update a parameter in realtime configuration space.
606  * It includes the ability to lookup a row based upon multiple key criteria.
607  * As a result, this function includes two sentinel values, one to terminate
608  * lookup values and the other to terminate the listing of fields to update.
609  *
610  * \return Number of rows affected, or -1 on error.
611  */
612 int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields);
613 
614 /*!
615  * \brief Update realtime configuration
616  *
617  * \param family which family/config to be updated
618  *
619  * \details
620  * This function is used to update a parameter in realtime configuration space.
621  * It includes the ability to lookup a row based upon multiple key criteria.
622  * As a result, this function includes two sentinel values, one to terminate
623  * lookup values and the other to terminate the listing of fields to update.
624  *
625  * \return Number of rows affected, or -1 on error.
626  *
627  * \note You should use the constant SENTINEL to terminate arguments, in
628  * order to preserve cross-platform compatibility.
629  */
630 int ast_update2_realtime(const char *family, ...) attribute_sentinel;
631 
632 /*!
633  * \brief Create realtime configuration
634  *
635  * \param family which family/config to be created
636  * \param fields fields themselves
637  *
638  * \details
639  * This function is used to create a parameter in realtime configuration space.
640  *
641  * \return Number of rows affected, or -1 on error.
642  *
643  * \note
644  * On the MySQL engine only, for reasons of backwards compatibility, the return
645  * value is the insert ID. This value is nonportable and may be changed in a
646  * future version to match the other engines.
647  */
648 int ast_store_realtime_fields(const char *family, const struct ast_variable *fields);
649 
650 /*!
651  * \brief Create realtime configuration
652  *
653  * \param family which family/config to be created
654  *
655  * \details
656  * This function is used to create a parameter in realtime configuration space.
657  *
658  * \return Number of rows affected, or -1 on error.
659  *
660  * \note
661  * On the MySQL engine only, for reasons of backwards compatibility, the return
662  * value is the insert ID. This value is nonportable and may be changed in a
663  * future version to match the other engines.
664  *
665  * \note You should use the constant SENTINEL to terminate arguments, in
666  * order to preserve cross-platform compatibility.
667  */
668 int ast_store_realtime(const char *family, ...) attribute_sentinel;
669 
670 /*!
671  * \brief Destroy realtime configuration
672  *
673  * \param family which family/config to be destroyed
674  * \param keyfield which field to use as the key
675  * \param lookup which value to look for in the key field to match the entry.
676  * \param fields fields themselves
677  *
678  * \details
679  * This function is used to destroy an entry in realtime configuration space.
680  * Additional params are used as keys.
681  *
682  * \return Number of rows affected, or -1 on error.
683  */
684 int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields);
685 
686 /*!
687  * \brief Destroy realtime configuration
688  *
689  * \param family which family/config to be destroyed
690  * \param keyfield which field to use as the key
691  * \param lookup which value to look for in the key field to match the entry.
692  *
693  * \details
694  * This function is used to destroy an entry in realtime configuration space.
695  * Additional params are used as keys.
696  *
697  * \return Number of rows affected, or -1 on error.
698  *
699  * \note You should use the constant SENTINEL to terminate arguments, in
700  * order to preserve cross-platform compatibility.
701  */
702 int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup, ...) attribute_sentinel;
703 
704 /*!
705  * \brief Check if realtime engine is configured for family
706  * \param family which family/config to be checked
707  * \return 1 if family is configured in realtime and engine exists
708  */
709 int ast_check_realtime(const char *family);
710 
711 /*! \brief Check if there's any realtime engines loaded */
712 int ast_realtime_enabled(void);
713 
714 /*!
715  * \brief Duplicate variable list
716  * \param var the linked list of variables to clone
717  * \return A duplicated list which you'll need to free with
718  * ast_variables_destroy or NULL when out of memory.
719  *
720  * \note Do not depend on this to copy more than just name, value and filename
721  * (the arguments to ast_variables_new).
722  */
724 
725 /*!
726  * \brief Reverse a variable list
727  * \param var the linked list of variables to reverse
728  * \return The head of the reversed variable list
729  *
730  * \note The variable list var is not preserved in this function and should
731  * not be used after reversing it.
732  */
733 struct ast_variable *ast_variables_reverse(struct ast_variable *var);
734 
735 /*!
736  * \brief Free variable list
737  * \param var the linked list of variables to free
738  *
739  * \details
740  * This function frees a list of variables.
741  */
742 void ast_variables_destroy(struct ast_variable *var);
743 
744 /*!
745  * \brief Register config engine
746  * \retval 1 Always
747  */
748 int ast_config_engine_register(struct ast_config_engine *newconfig);
749 
750 /*!
751  * \brief Deregister config engine
752  * \retval 0 Always
753  */
755 
756 /*!
757  * \brief Determine if a mapping exists for a given family
758  *
759  * \param family which family you are looking to see if a mapping exists for
760  * \retval 1 if it is mapped
761  * \retval 0 if it is not
762  */
763 int ast_realtime_is_mapping_defined(const char *family);
764 
765 #ifdef TEST_FRAMEWORK
766 /*!
767  * \brief Add an explicit mapping for a family
768  *
769  * \param name Family name
770  * \param driver Driver to use
771  * \param database Database to access
772  * \param table Table to use
773  * \param priority Priority of this mapping
774  */
775 int ast_realtime_append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority);
776 #endif
777 
778 /*!
779  * \brief Exposed initialization method for core process
780  *
781  * \details
782  * This method is intended for use only with the core initialization and is
783  * not designed to be called from any user applications.
784  */
785 int register_config_cli(void);
786 
787 /*! \brief Create a new base configuration structure */
788 struct ast_config *ast_config_new(void);
789 
790 /*!
791  * \brief Retrieve the current category name being built.
792  *
793  * \details
794  * API for backend configuration engines while building a configuration set.
795  */
796 struct ast_category *ast_config_get_current_category(const struct ast_config *cfg);
797 
798 /*!
799  * \brief Set the category within the configuration as being current.
800  *
801  * \details
802  * API for backend configuration engines while building a configuration set.
803  */
804 void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat);
805 
806 /*!
807  * \brief Retrieve a configuration variable within the configuration set.
808  *
809  * \details
810  * Retrieves the named variable \p var within category \p cat of configuration
811  * set \p cfg. If not found, attempts to retrieve the named variable \p var
812  * from within category \em general.
813  *
814  * \return Value of \p var, or NULL if not found.
815  */
816 const char *ast_config_option(struct ast_config *cfg, const char *cat, const char *var);
817 
818 /*!
819  * \brief Create a category
820  *
821  * \param name name of new category
822  * \param in_file filename which contained the new config
823  * \param lineno line number
824  */
825 struct ast_category *ast_category_new(const char *name, const char *in_file, int lineno);
826 
827 /*!
828  * \brief Create a category that is not backed by a file
829  *
830  * \param name name of new category
831  */
832 #define ast_category_new_dynamic(name) ast_category_new(name, "", -1)
833 
834 /*!
835  * \brief Create a nameless category that is not backed by a file
836  */
837 #define ast_category_new_anonymous() ast_category_new_dynamic("")
838 
839 /*!
840  * \brief Create a category making it a template
841  *
842  * \param name name of new template
843  * \param in_file filename which contained the new config
844  * \param lineno line number
845  */
846 struct ast_category *ast_category_new_template(const char *name, const char *in_file, int lineno);
847 
848 /*!
849  * \brief Inserts new category
850  *
851  * \param config which config to use
852  * \param cat newly created category to insert
853  * \param match which category to insert above
854  *
855  * \details
856  * This function is used to insert a new category above another category
857  * matching the match parameter.
858  *
859  * \retval 0 if succeeded
860  * \retval -1 if the specified match category wasn't found
861  */
862 int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match);
863 
864 /*!
865  * \brief Delete a category
866  *
867  * \param config which config to use
868  * \param category category to delete
869  *
870  * \return the category after the deleted one which could be NULL.
871  *
872  * \note It is not safe to call ast_category_delete while browsing with
873  * ast_category_browse. It is safe with ast_category_browse_filtered.
874  */
875 struct ast_category *ast_category_delete(struct ast_config *cfg, struct ast_category *category);
876 
877 /*!
878  * \brief Appends a category to a config
879  *
880  * \param config which config to use
881  * \param cat category to insert
882  */
883 void ast_category_append(struct ast_config *config, struct ast_category *cat);
884 
885 /*!
886  * \brief Applies base (template) to category.
887  *
888  * \param existing existing category
889  * \param base base category
890  *
891  * \details
892  * This function is used to apply a base (template) to an existing category
893  *
894  * \retval 0 if succeeded
895  * \retval -1 if the memory allocation failed
896  */
897 int ast_category_inherit(struct ast_category *existing, const struct ast_category *base);
898 
899 /*!
900  * \brief Removes and destroys all variables in a category
901  *
902  * \param category category to empty
903  *
904  * \retval 0 if succeeded
905  * \retval -1 if categopry is NULL
906  */
907 int ast_category_empty(struct ast_category *category);
908 
909 void ast_category_destroy(struct ast_category *cat);
911 void ast_category_rename(struct ast_category *cat, const char *name);
912 
913 struct ast_variable *_ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno);
914 #define ast_variable_new(name, value, filename) _ast_variable_new(name, value, filename, __FILE__, __PRETTY_FUNCTION__, __LINE__)
915 
916 struct ast_config_include *ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size);
917 struct ast_config_include *ast_include_find(struct ast_config *conf, const char *included_file);
918 void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file);
919 void ast_variable_append(struct ast_category *category, struct ast_variable *variable);
920 void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line);
921 int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line);
922 
923 /*!
924  * \brief Performs an in-place sort on the variable list by ascending name
925  *
926  * \param head The variable list head
927  *
928  * \return The new list head
929  */
930 struct ast_variable *ast_variable_list_sort(struct ast_variable *head);
931 
932 /*!
933  * \brief Appends a variable list to the end of another list
934  *
935  * \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL
936  * but the content may be to initialize a new list. If so, upon return, this parameter will be updated
937  * with a pointer to the new list head.
938  * \param search_hint The place in the current list to start searching for the end of the list.
939  * Might help performance on longer lists. If NULL, it defaults to head.
940  * \param new_var The head of the new variable list to be appended
941  *
942  * \return The tail of the resulting list.
943  *
944  * \note If the existing *head is NULL, it will be updated to new_var. This allows you to call
945  * ast_variable_list_append in a loop or callback without initializing the list first.
946  */
947 struct ast_variable *ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint,
948  struct ast_variable *new_var);
949 #define ast_variable_list_append(head, new_var) ast_variable_list_append_hint(head, NULL, new_var)
950 
951 /*!
952  * \brief Replace a variable in the given list with a new value
953  * \since 13.30.0
954  *
955  * \param head A pointer to an ast_variable * of the existing variable list head. May NOT be NULL
956  * but the content may be to initialize a new list. If so, upon return, this parameter will be updated
957  * with a pointer to the new list head.
958  * \param replacement The variable that replaces another variable in the list with the
959  * same name.
960  *
961  * \retval 0 if a variable was replaced in the list
962  * \retval -1 if no replacement occured
963  *
964  * \note The variable name comparison is performed case-sensitively
965  * \note If a variable is replaced, its memory is freed.
966  */
967 int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement);
968 
969 /*!
970  * \brief Update variable value within a config
971  *
972  * \param category Category element within the config
973  * \param variable Name of the variable to change
974  * \param value New value of the variable
975  * \param match If set, previous value of the variable (if NULL or zero-length, no matching will be done)
976  * \param object Boolean of whether to make the new variable an object
977  *
978  * \return 0 on success or -1 on failure.
979  */
980 int ast_variable_update(struct ast_category *category, const char *variable,
981  const char *value, const char *match, unsigned int object);
982 
983 /*!
984  * \brief Save a config text file
985  * \since 13.2.0
986  *
987  * \param filename Filename
988  * \param cfg ast_config
989  * \param generator generator
990  * \param flags List of config_save_flags
991  *
992  * \return 0 on success or -1 on failure.
993  */
994 int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags);
995 
996 /*!
997  * \brief Save a config text file preserving the pre 13.2 behavior
998  *
999  * \param filename Filename
1000  * \param cfg ast_config
1001  * \param generator generator
1002  *
1003  * \return 0 on success or -1 on failure.
1004  */
1005 int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator);
1006 
1007 struct ast_config *ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked);
1008 /*!
1009  * \brief
1010  * Copies the contents of one ast_config into another
1011  *
1012  * \note
1013  * This creates a config on the heap. The caller of this must
1014  * be prepared to free the memory returned.
1015  *
1016  * \param orig the config to copy
1017  * \return The new config on success, NULL on failure.
1018  */
1019 struct ast_config *ast_config_copy(const struct ast_config *orig);
1020 
1021 /*!
1022  * \brief
1023  * Flags that affect the behaviour of config hooks.
1024  */
1027 };
1028 
1029 /*
1030  * \brief Callback when configuration is updated
1031  *
1032  * \param cfg A copy of the configuration that is being changed.
1033  * This MUST be freed by the callback before returning.
1034  */
1035 typedef int (*config_hook_cb)(struct ast_config *cfg);
1036 
1037 /*!
1038  * \brief
1039  * Register a config hook for a particular file and module
1040  *
1041  * \param name The name of the hook you are registering.
1042  * \param filename The file whose config you wish to hook into.
1043  * \param module The module that is reloading the config. This
1044  * can be useful if multiple modules may possibly
1045  * reload the same file, but you are only interested
1046  * when a specific module reloads the file
1047  * \param flags Flags that affect the way hooks work.
1048  * \param hook The callback to be called when config is loaded.
1049  * return 0 Success
1050  * return -1 Unsuccess, also known as UTTER AND COMPLETE FAILURE
1051  */
1052 int ast_config_hook_register(const char *name,
1053  const char *filename,
1054  const char *module,
1055  enum config_hook_flags flags,
1056  config_hook_cb hook);
1057 
1058 /*!
1059  * \brief
1060  * Unregister a config hook
1061  *
1062  * \param name The name of the hook to unregister
1063  */
1064 void ast_config_hook_unregister(const char *name);
1065 
1066 /*!
1067  * \brief Support code to parse config file arguments
1068  *
1069  * \details
1070  * The function ast_parse_arg() provides a generic interface to parse
1071  * strings (e.g. numbers, network addresses and so on) in a flexible
1072  * way, e.g. by doing proper error and bound checks, provide default
1073  * values, and so on.
1074  * The function (described later) takes a string as an argument,
1075  * a set of flags to specify the result format and checks to perform,
1076  * a pointer to the result, and optionally some additional arguments.
1077  *
1078  * \return It returns 0 on success, != 0 otherwise.
1079  */
1081  /* low 4 bits of flags are used for the operand type */
1082  PARSE_TYPE = 0x000f,
1083  /* numeric types, with optional default value and bound checks.
1084  * Additional arguments are passed by value.
1085  */
1086  PARSE_INT32 = 0x0001,
1087  PARSE_UINT32 = 0x0002,
1088  PARSE_DOUBLE = 0x0003,
1089 #if 0 /* not supported yet */
1090  PARSE_INT16 = 0x0004,
1091  PARSE_UINT16 = 0x0005,
1092 #endif
1093 
1094  /* Returns an int processed by ast_app_parse_timelen.
1095  * The first argument is an enum ast_timelen value (required).
1096  */
1097  PARSE_TIMELEN = 0x0006,
1098 
1099  /* Returns a struct ast_sockaddr, with optional default value
1100  * (passed by reference) and port handling (accept, ignore,
1101  * require, forbid). The format is 'ipaddress[:port]'. IPv6 address
1102  * literals need square brackets around them if a port is specified.
1103  */
1104  PARSE_ADDR = 0x000e,
1105 
1106  /* Returns a struct sockaddr_in, with optional default value
1107  * (passed by reference) and port handling (accept, ignore,
1108  * require, forbid). The format is 'host.name[:port]'
1109  */
1110  PARSE_INADDR = 0x000f,
1111 
1112  /* Other data types can be added as needed */
1113 
1114  /* If PARSE_DEFAULT is set, next argument is a default value
1115  * which is returned in case of error. The argument is passed
1116  * by value in case of numeric types, by reference in other cases.
1117  */
1118  PARSE_DEFAULT = 0x0010, /* assign default on error */
1119 
1120  /* Request a range check, applicable to numbers. Two additional
1121  * arguments are passed by value, specifying the low-high end of
1122  * the range (inclusive). An error is returned if the value
1123  * is outside or inside the range, respectively.
1124  */
1125  PARSE_IN_RANGE = 0x0020, /* accept values inside a range */
1126  PARSE_OUT_RANGE = 0x0040, /* accept values outside a range */
1127  PARSE_RANGE_DEFAULTS = 0x0080, /* default to range min/max on range error */
1128 
1129  /* Port handling, for ast_sockaddr. accept/ignore/require/forbid
1130  * port number after the hostname or address.
1131  */
1132  PARSE_PORT_MASK = 0x0300, /* 0x000: accept port if present */
1133  PARSE_PORT_IGNORE = 0x0100, /* 0x100: ignore port if present */
1134  PARSE_PORT_REQUIRE = 0x0200, /* 0x200: require port number */
1135  PARSE_PORT_FORBID = 0x0300, /* 0x100: forbid port number */
1136 };
1137 
1138 /*!
1139  * \brief The argument parsing routine.
1140  *
1141  * \param arg the string to parse. It is not modified.
1142  * \param flags combination of ast_parse_flags to specify the
1143  * return type and additional checks.
1144  * \param result pointer to the result. NULL is valid here, and can
1145  * be used to perform only the validity checks.
1146  * \param ... extra arguments are required according to flags.
1147  *
1148  * \retval 0 in case of success, != 0 otherwise.
1149  * \retval result returns the parsed value in case of success,
1150  * the default value in case of error, or it is left unchanged
1151  * in case of error and no default specified. Note that in certain
1152  * cases (e.g. sockaddr_in, with multi-field return values) some
1153  * of the fields in result may be changed even if an error occurs.
1154  *
1155  * \details
1156  * Examples of use:
1157  * ast_parse_arg("223", PARSE_INT32|PARSE_IN_RANGE, &a, -1000, 1000);
1158  * returns 0, a = 223
1159  * ast_parse_arg("22345", PARSE_INT32|PARSE_IN_RANGE|PARSE_DEFAULT, &a, 9999, 10, 100);
1160  * returns 1, a = 9999
1161  * ast_parse_arg("22345ssf", PARSE_UINT32|PARSE_IN_RANGE, &b, 10, 100);
1162  * returns 1, b unchanged
1163  * ast_parse_arg("12", PARSE_UINT32|PARSE_IN_RANGE|PARSE_RANGE_DEFAULTS, &a, 1, 10);
1164  * returns 1, a = 10
1165  * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 1000);
1166  * returns 0, a = 1000
1167  * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE, &a, TIMELEN_SECONDS, -1000, 250000);
1168  * returns 0, a = 223000
1169  * ast_parse_arg("223", PARSE_TIMELEN|PARSE_IN_RANGE|PARSE_DEFAULT, &a, TIMELEN_SECONDS, 9999, -1000, 250000);
1170  * returns 0, a = 9999
1171  * ast_parse_arg("www.foo.biz:44", PARSE_INADDR, &sa);
1172  * returns 0, sa contains address and port
1173  * ast_parse_arg("www.foo.biz", PARSE_INADDR|PARSE_PORT_REQUIRE, &sa);
1174  * returns 1 because port is missing, sa contains address
1175  */
1176 int ast_parse_arg(const char *arg, enum ast_parse_flags flags,
1177  void *result, ...);
1178 
1179 /*
1180  * Parsing config file options in C is slightly annoying because we cannot use
1181  * string in a switch() statement, yet we need a similar behaviour, with many
1182  * branches and a break on a matching one.
1183  * The following somehow simplifies the job: we create a block using
1184  * the CV_START and CV_END macros, and then within the block we can run
1185  * actions such as "if (condition) { body; break; }"
1186  * Additional macros are present to run simple functions (e.g. ast_copy_string)
1187  * or to pass arguments to ast_parse_arg()
1188  *
1189  * As an example:
1190 
1191  CV_START(v->name, v->value); // start the block
1192  CV_STR("foo", x_foo); // static string
1193  CV_DSTR("bar", y_bar); // malloc'ed string
1194  CV_F("bar", ...); // call a generic function
1195  CV_END; // end the block
1196  */
1197 
1198 /*! \brief the macro to open a block for variable parsing */
1199 #define CV_START(__in_var, __in_val) \
1200  do { \
1201  const char *__var = __in_var; \
1202  const char *__val = __in_val;
1203 
1204 /*! \brief close a variable parsing block */
1205 #define CV_END } while (0)
1206 
1207 /*! \brief call a generic function if the name matches. */
1208 #define CV_F(__pattern, __body) if (!strcasecmp((__var), __pattern)) { __body; break; }
1209 
1210 /*!
1211  * \brief helper macros to assign the value to a BOOL, UINT, static string and
1212  * dynamic string
1213  */
1214 #define CV_BOOL(__x, __dst) CV_F(__x, (__dst) = ast_true(__val) )
1215 #define CV_UINT(__x, __dst) CV_F(__x, (__dst) = strtoul(__val, NULL, 0) )
1216 #define CV_STR(__x, __dst) CV_F(__x, ast_copy_string(__dst, __val, sizeof(__dst)))
1217 #define CV_DSTR(__x, __dst) CV_F(__x, ast_free(__dst); __dst = ast_strdup(__val))
1218 #define CV_STRFIELD(__x, __obj, __field) CV_F(__x, ast_string_field_set(__obj, __field, __val))
1219 
1220 /*! \brief Check if require type is an integer type */
1222 int ast_rq_is_int(require_type type),
1223 {
1224  switch (type) {
1225  case RQ_INTEGER1:
1226  case RQ_UINTEGER1:
1227  case RQ_INTEGER2:
1228  case RQ_UINTEGER2:
1229  case RQ_INTEGER3:
1230  case RQ_UINTEGER3:
1231  case RQ_INTEGER4:
1232  case RQ_UINTEGER4:
1233  case RQ_INTEGER8:
1234  case RQ_UINTEGER8:
1235  return 1;
1236  default:
1237  return 0;
1238  }
1239 }
1241 
1242 /*!
1243  * \brief Remove standard encoding from realtime values, which ensures
1244  * that a semicolon embedded within a single value is not treated upon
1245  * retrieval as multiple values.
1246  * \param chunk Data to be decoded
1247  * \return The decoded data, in the original buffer
1248  * \since 1.8
1249  * \warning This function modifies the original buffer
1250  */
1251 char *ast_realtime_decode_chunk(char *chunk);
1252 
1253 /*!
1254  * \brief Encodes a chunk of data for realtime
1255  * \param dest Destination buffer
1256  * \param maxlen Length passed through to ast_str_* functions
1257  * \param chunk Source data to be encoded
1258  * \return Buffer within dest
1259  * \since 1.8
1260  */
1261 char *ast_realtime_encode_chunk(struct ast_str **dest, ssize_t maxlen, const char *chunk);
1262 
1263 /*!
1264  * \brief Tests 2 variable values to see if they match
1265  * \since 13.9.0
1266  *
1267  * \param left Variable to test
1268  * \param right Variable to match against with an optional realtime-style operator in the name
1269  *
1270  * \retval 1 matches
1271  * \retval 0 doesn't match
1272  *
1273  * \details
1274  *
1275  * The values of the variables are passed to ast_strings_match.
1276  * If right->name is suffixed with a space and an operator, that operator
1277  * is also passed to ast_strings_match.
1278  *
1279  * Examples:
1280  *
1281  * left->name = "id" (ignored)
1282  * left->value = "abc"
1283  * right->name = "id regex" (id is ignored)
1284  * right->value = "a[bdef]c"
1285  *
1286  * will result in ast_strings_match("abc", "regex", "a[bdef]c") which will return 1.
1287  *
1288  * left->name = "id" (ignored)
1289  * left->value = "abc"
1290  * right->name = "id" (ignored)
1291  * right->value = "abc"
1292  *
1293  * will result in ast_strings_match("abc", NULL, "abc") which will return 1.
1294  *
1295  * See the documentation for ast_strings_match for the valid operators.
1296  */
1297 int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right);
1298 
1299 /*!
1300  * \brief Tests 2 variable lists to see if they match
1301  * \since 13.9.0
1302  *
1303  * \param left Variable list to test
1304  * \param right Variable list with an optional realtime-style operator in the names
1305  * \param exact_match If true, all variables in left must match all variables in right
1306  * and vice versa. This does exact value matches only. Operators aren't supported.
1307  * Except for order, the left and right lists must be equal.
1308  *
1309  * If false, every variable in the right list must match some variable in the left list
1310  * using the operators supplied. Variables in the left list that aren't in the right
1311  * list are ignored for matching purposes.
1312  *
1313  * \retval 1 matches
1314  * \retval 0 doesn't match
1315  *
1316  * \details
1317  * Iterates over the variable lists calling ast_variables_match. If any match fails
1318  * or a variable in the right list isn't in the left list, 0 is returned.
1319  */
1320 int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right,
1321  int exact_match);
1322 
1323 #if defined(__cplusplus) || defined(c_plusplus)
1324 }
1325 #endif
1326 
1327 #endif /* _ASTERISK_CONFIG_H */
int ast_category_is_template(const struct ast_category *category)
Check if category is a template.
Definition: main/config.c:1033
struct ast_category * ast_category_new(const char *name, const char *in_file, int lineno)
Create a category.
Definition: extconf.c:2790
struct ast_variable * ast_load_realtime(const char *family,...) attribute_sentinel
Definition: main/config.c:3339
struct ast_variable * next
struct ast_variable * ast_variables_reverse(struct ast_variable *var)
Reverse a variable list.
Definition: main/config.c:567
require_type
Types used in ast_realtime_require_field.
static const char type[]
Definition: chan_ooh323.c:109
char * ast_realtime_decode_chunk(char *chunk)
Remove standard encoding from realtime values, which ensures that a semicolon embedded within a singl...
Definition: main/config.c:3625
struct ast_config_include * ast_include_new(struct ast_config *conf, const char *from_file, const char *included_file, int is_exec, const char *exec_file, int from_lineno, char *real_included_file_name, int real_included_file_name_size)
Definition: extconf.c:1075
struct ast_variable * ast_variable_list_sort(struct ast_variable *head)
Performs an in-place sort on the variable list by ascending name.
Definition: main/config.c:622
int ast_config_text_file_save(const char *filename, const struct ast_config *cfg, const char *generator)
Save a config text file preserving the pre 13.2 behavior.
Definition: main/config.c:2531
realtime_destroy * destroy_func
Structure to keep comments for rewriting configuration files.
Definition: main/config.c:84
void ast_variable_insert(struct ast_category *category, struct ast_variable *variable, const char *line)
Definition: main/config.c:501
struct ast_variable * _ast_variable_new(const char *name, const char *value, const char *filename, const char *file, const char *function, int lineno)
Definition: main/config.c:288
void ast_variables_destroy(struct ast_variable *var)
Free variable list.
Definition: extconf.c:1263
char * config
Definition: conf2ael.c:66
int ast_variable_delete(struct ast_category *category, const char *variable, const char *match, const char *line)
Definition: main/config.c:1399
struct ast_variable * ast_variable_browse(const struct ast_config *config, const char *category_name)
Definition: extconf.c:1216
int register_config_cli(void)
Exposed initialization method for core process.
Definition: main/config.c:4066
struct ast_category * ast_category_delete(struct ast_config *cfg, struct ast_category *category)
Delete a category.
Definition: main/config.c:1478
int ast_unload_realtime(const char *family)
Release any resources cached for a realtime family.
Definition: main/config.c:3406
struct ast_variable * realtime_var_get(const char *database, const char *table, const struct ast_variable *fields)
static int entity
Definition: isdn_lib.c:259
realtime_store * store_func
int ast_config_text_file_save2(const char *filename, const struct ast_config *cfg, const char *generator, uint32_t flags)
Save a config text file.
Definition: main/config.c:2555
int ast_check_realtime(const char *family)
Check if realtime engine is configured for family.
Definition: main/config.c:3363
struct ast_config * ast_config_load2(const char *filename, const char *who_asked, struct ast_flags flags)
Load a config file.
Definition: main/config.c:3154
Structure for variables, used for configurations and for channel variables.
struct ast_comment * sameline
#define var
Definition: ast_expr2f.c:614
struct ast_config * ast_load_realtime_multientry_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3426
int ast_category_exist(const struct ast_config *config, const char *category_name, const char *filter)
Check for category duplicates.
Definition: main/config.c:1061
int ast_config_engine_deregister(struct ast_config_engine *del)
Deregister config engine.
Definition: main/config.c:3006
realtime_multi_get * realtime_multi_func
struct ast_category * ast_config_get_current_category(const struct ast_config *cfg)
Retrieve the current category name being built.
Definition: extconf.c:2783
struct ast_category * prev
Definition: main/config.c:244
int ast_config_engine_register(struct ast_config_engine *newconfig)
Register config engine.
Definition: main/config.c:2990
int(* config_hook_cb)(struct ast_config *cfg)
static int match(struct ast_sockaddr *addr, unsigned short callno, unsigned short dcallno, const struct chan_iax2_pvt *cur, int check_dcallno)
Definition: chan_iax2.c:2315
char * ast_category_browse(struct ast_config *config, const char *prev_name)
Browse categories.
Definition: extconf.c:3328
realtime_unload * unload_func
int realtime_update2(const char *database, const char *table, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
realtime_update * update_func
void ast_category_destroy(struct ast_category *cat)
Definition: extconf.c:2847
realtime_var_get * realtime_func
static int priority
const char * ast_variable_find_last_in_list(const struct ast_variable *list, const char *variable)
Gets the value of the LAST occurrence of a variable from a variable list.
Definition: main/config.c:842
char * exec_file
if it&#39;s an exec, you&#39;ll have both the /var/tmp to read, and the original script
Definition: main/config.c:273
int ast_update_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Update realtime configuration.
Definition: main/config.c:3489
struct ast_config * ast_config_internal_load(const char *configfile, struct ast_config *cfg, struct ast_flags flags, const char *suggested_incl_file, const char *who_asked)
Definition: main/config.c:3112
int realtime_unload(const char *database, const char *table)
Function pointer called to clear the database cache and free resources used for such.
struct ast_category * ast_category_browse_filtered(struct ast_config *config, const char *category_name, struct ast_category *prev, const char *filter)
Browse categories with filters.
Definition: main/config.c:1335
struct ast_str * ast_category_get_templates(const struct ast_category *category)
Return the template names this category inherits from.
Definition: main/config.c:1038
Configuration engine structure, used to define realtime drivers.
int ast_category_inherit(struct ast_category *existing, const struct ast_category *base)
Applies base (template) to category.
Definition: main/config.c:1367
Utility functions.
struct ast_config_engine * next
const char * ast_variable_retrieve_filtered(struct ast_config *config, const char *category, const char *variable, const char *filter)
Gets a variable by context and variable names.
Definition: main/config.c:719
int realtime_destroy(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
int ast_realtime_enabled(void)
Check if there&#39;s any realtime engines loaded.
Definition: main/config.c:3377
int ast_update2_realtime(const char *family,...) attribute_sentinel
Update realtime configuration.
Definition: main/config.c:3525
All configuration options for statsd client.
Definition: res_statsd.c:95
#define attribute_sentinel
Definition: compiler.h:65
struct ast_comment * trailing
static char * table
Definition: cdr_odbc.c:58
void ast_config_hook_unregister(const char *name)
Unregister a config hook.
Definition: main/config.c:4104
void ast_category_rename(struct ast_category *cat, const char *name)
Definition: main/config.c:1362
struct ast_variable * ast_category_root(struct ast_config *config, char *cat)
returns the root ast_variable of a config
Definition: main/config.c:1162
int ast_store_realtime(const char *family,...) attribute_sentinel
Create realtime configuration.
Definition: main/config.c:3570
int ast_realtime_require_field(const char *family,...) attribute_sentinel
Inform realtime what fields that may be stored.
Definition: main/config.c:3382
int ast_variable_list_replace(struct ast_variable **head, struct ast_variable *replacement)
Replace a variable in the given list with a new value.
Definition: main/config.c:668
int ast_config_hook_register(const char *name, const char *filename, const char *module, enum config_hook_flags flags, config_hook_cb hook)
Register a config hook for a particular file and module.
Definition: main/config.c:4132
Inlinable API function macro.
int ast_store_realtime_fields(const char *family, const struct ast_variable *fields)
Create realtime configuration.
Definition: main/config.c:3549
char * included_file
file name included
Definition: main/config.c:278
struct ast_variable * ast_category_first(struct ast_category *cat)
given a pointer to a category, return the root variable.
Definition: main/config.c:1157
struct ast_config * config_load_func(const char *database, const char *table, const char *configfile, struct ast_config *config, struct ast_flags flags, const char *suggested_include_file, const char *who_asked)
void ast_config_destroy(struct ast_config *config)
Destroys a config.
Definition: extconf.c:1290
const char * ast_variable_find_in_list(const struct ast_variable *list, const char *variable)
Gets the value of a variable from a variable list by name.
Definition: main/config.c:830
realtime_require * require_func
char stuff[0]
Contents of file, name, and value in that order stuffed here.
struct ast_config * ast_config_new(void)
Create a new base configuration structure.
Definition: extconf.c:3276
struct ast_variable * ast_variable_list_append_hint(struct ast_variable **head, struct ast_variable *search_hint, struct ast_variable *new_var)
Appends a variable list to the end of another list.
Definition: main/config.c:648
int ast_realtime_append_mapping(const char *name, const char *driver, const char *database, const char *table, int priority)
Add an explicit mapping for a family.
Definition: main/config.c:2868
char * ast_realtime_encode_chunk(struct ast_str **dest, ssize_t maxlen, const char *chunk)
Encodes a chunk of data for realtime.
Definition: main/config.c:3637
struct ast_config * ast_load_realtime_multientry(const char *family,...) attribute_sentinel
Retrieve realtime configuration.
Definition: main/config.c:3452
The descriptor of a dynamic string XXX storage will be optimized later if needed We use the ts field ...
Definition: strings.h:584
static struct ast_generator generator
Definition: app_fax.c:359
void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat)
Set the category within the configuration as being current.
Definition: extconf.c:3364
int ast_category_insert(struct ast_config *config, struct ast_category *cat, const char *match)
Inserts new category.
Definition: main/config.c:1083
struct ast_comment * precomments
void ast_include_rename(struct ast_config *conf, const char *from_file, const char *to_file)
Definition: main/config.c:385
struct ast_config * ast_config_copy(const struct ast_config *orig)
Copies the contents of one ast_config into another.
Definition: main/config.c:3079
int ast_parse_arg(const char *arg, enum ast_parse_flags flags, void *result,...)
The argument parsing routine.
Definition: main/config.c:3657
int ast_variable_update(struct ast_category *category, const char *variable, const char *value, const char *match, unsigned int object)
Update variable value within a config.
Definition: main/config.c:1444
const char * ast_variable_find(const struct ast_category *category, const char *variable)
Gets a variable value from a specific category structure by name.
Definition: main/config.c:735
struct ast_variable * ast_category_detach_variables(struct ast_category *cat)
Definition: main/config.c:1351
int ast_realtime_is_mapping_defined(const char *family)
Determine if a mapping exists for a given family.
Definition: main/config.c:3026
Structure used to handle boolean flags.
Definition: utils.h:199
config_hook_flags
Flags that affect the behaviour of config hooks.
void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
Definition: extconf.c:1178
struct ast_variable * ast_load_realtime_all_fields(const char *family, const struct ast_variable *fields)
Definition: main/config.c:3266
void ast_category_append(struct ast_config *config, struct ast_category *cat)
Appends a category to a config.
Definition: extconf.c:2835
struct ast_config * realtime_multi_get(const char *database, const char *table, const struct ast_variable *fields)
struct ast_category * ast_category_new_template(const char *name, const char *in_file, int lineno)
Create a category making it a template.
Definition: main/config.c:995
const char * ast_variable_retrieve(struct ast_config *config, const char *category, const char *variable)
Definition: main/config.c:694
int realtime_require(const char *database, const char *table, va_list ap)
Function pointer called to ensure database schema is properly configured for realtime use...
int ast_category_empty(struct ast_category *category)
Removes and destroys all variables in a category.
Definition: main/config.c:1510
realtime_update2 * update2_func
int ast_variable_lists_match(const struct ast_variable *left, const struct ast_variable *right, int exact_match)
Tests 2 variable lists to see if they match.
Definition: main/config.c:772
void ast_config_sort_categories(struct ast_config *config, int descending, int(*comparator)(struct ast_category *p, struct ast_category *q))
Sorts categories in a config in the order of a numerical value contained within them.
Definition: main/config.c:1171
int ast_destroy_realtime(const char *family, const char *keyfield, const char *lookup,...) attribute_sentinel
Destroy realtime configuration.
Definition: main/config.c:3606
struct ast_variable * ast_variable_browse_filtered(const struct ast_config *config, const char *category_name, const char *filter)
Browse variables.
struct ast_variable * ast_load_realtime_fields(const char *family, const struct ast_variable *fields)
Retrieve realtime configuration.
Definition: main/config.c:3304
config_load_func * load_func
static PGresult * result
Definition: cel_pgsql.c:88
const struct ast_variable * ast_variable_find_variable_in_list(const struct ast_variable *list, const char *variable_name)
Gets a variable from a variable list by name.
Definition: main/config.c:740
const char * ast_config_option(struct ast_config *cfg, const char *cat, const char *var)
Retrieve a configuration variable within the configuration set.
Definition: main/config.c:684
int ast_variables_match(const struct ast_variable *left, const struct ast_variable *right)
Tests 2 variable values to see if they match.
Definition: main/config.c:752
struct ast_config_include * ast_include_find(struct ast_config *conf, const char *included_file)
Definition: extconf.c:1164
ast_parse_flags
Support code to parse config file arguments.
int ast_update_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Update realtime configuration.
Definition: main/config.c:3468
static int filter(struct ast_channel *chan, const char *cmd, char *parse, char *buf, size_t len)
Definition: func_strings.c:709
struct ast_category * ast_category_get(const struct ast_config *config, const char *category_name, const char *filter)
Retrieve a category if it exists.
Definition: main/config.c:1022
int ast_rq_is_int(require_type type)
Check if require type is an integer type.
int ast_destroy_realtime_fields(const char *family, const char *keyfield, const char *lookup, const struct ast_variable *fields)
Destroy realtime configuration.
Definition: main/config.c:3586
struct ast_variable * ast_variables_dup(struct ast_variable *var)
Duplicate variable list.
Definition: main/config.c:545
struct ast_variable * ast_load_realtime_all(const char *family,...) attribute_sentinel
Definition: main/config.c:3287
int realtime_update(const char *database, const char *table, const char *keyfield, const char *entity, const struct ast_variable *fields)
const char * ast_category_get_name(const struct ast_category *category)
Return the name of the category.
Definition: main/config.c:1028
int ast_update2_realtime_fields(const char *family, const struct ast_variable *lookup_fields, const struct ast_variable *update_fields)
Update realtime configuration.
Definition: main/config.c:3505
int realtime_store(const char *database, const char *table, const struct ast_variable *fields)
#define AST_INLINE_API(hdr, body)
Definition: inline_api.h:54