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