2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Configuration File Parser
23 * \author Mark Spencer <markster@digium.com>
25 * Includes the Asterisk Realtime API - ARA
26 * See doc/realtime.txt and doc/extconfig.txt
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
40 #define AST_INCLUDE_GLOB 1
41 #ifdef AST_INCLUDE_GLOB
42 #if defined(__Darwin__) || defined(__CYGWIN__)
43 #define GLOB_ABORTED GLOB_ABEND
48 #include "asterisk/config.h"
49 #include "asterisk/cli.h"
50 #include "asterisk/lock.h"
51 #include "asterisk/options.h"
52 #include "asterisk/logger.h"
53 #include "asterisk/utils.h"
54 #include "asterisk/channel.h"
55 #include "asterisk/app.h"
57 #define MAX_NESTED_COMMENTS 128
58 #define COMMENT_START ";--"
59 #define COMMENT_END "--;"
60 #define COMMENT_META ';'
61 #define COMMENT_TAG '-'
63 static char *extconfig_conf = "extconfig.conf";
65 static struct ast_config_map {
66 struct ast_config_map *next;
72 } *config_maps = NULL;
74 AST_MUTEX_DEFINE_STATIC(config_lock);
75 static struct ast_config_engine *config_engine_list;
77 #define MAX_INCLUDE_LEVEL 10
80 struct ast_comment *next;
86 int ignored; /* do not let user of the config see this category */
87 struct ast_variable *root;
88 struct ast_variable *last;
89 struct ast_category *next;
93 struct ast_category *root;
94 struct ast_category *last;
95 struct ast_category *current;
96 struct ast_category *last_browse; /* used to cache the last category supplied via category_browse */
98 int max_include_level;
101 struct ast_variable *ast_variable_new(const char *name, const char *value)
103 struct ast_variable *variable;
104 int name_len = strlen(name) + 1;
106 if ((variable = ast_calloc(1, name_len + strlen(value) + 1 + sizeof(*variable)))) {
107 variable->name = variable->stuff;
108 variable->value = variable->stuff + name_len;
109 strcpy(variable->name,name);
110 strcpy(variable->value,value);
116 void ast_variable_append(struct ast_category *category, struct ast_variable *variable)
121 category->last->next = variable;
123 category->root = variable;
124 category->last = variable;
127 void ast_variables_destroy(struct ast_variable *v)
129 struct ast_variable *vn;
138 struct ast_variable *ast_variable_browse(const struct ast_config *config, const char *category)
140 struct ast_category *cat = NULL;
142 if (category && config->last_browse && (config->last_browse->name == category))
143 cat = config->last_browse;
145 cat = ast_category_get(config, category);
147 return (cat) ? cat->root : NULL;
150 char *ast_variable_retrieve(const struct ast_config *config, const char *category, const char *variable)
152 struct ast_variable *v;
155 for (v = ast_variable_browse(config, category); v; v = v->next) {
156 if (!strcasecmp(variable, v->name))
160 struct ast_category *cat;
162 for (cat = config->root; cat; cat = cat->next)
163 for (v = cat->root; v; v = v->next)
164 if (!strcasecmp(variable, v->name))
171 static struct ast_variable *variable_clone(const struct ast_variable *old)
173 struct ast_variable *new = ast_variable_new(old->name, old->value);
176 new->lineno = old->lineno;
177 new->object = old->object;
178 new->blanklines = old->blanklines;
179 /* TODO: clone comments? */
185 static void move_variables(struct ast_category *old, struct ast_category *new)
187 struct ast_variable *var = old->root;
190 /* we can just move the entire list in a single op */
191 ast_variable_append(new, var);
194 struct ast_variable *next = var->next;
196 ast_variable_append(new, var);
202 struct ast_category *ast_category_new(const char *name)
204 struct ast_category *category;
206 if ((category = ast_calloc(1, sizeof(*category))))
207 ast_copy_string(category->name, name, sizeof(category->name));
211 static struct ast_category *category_get(const struct ast_config *config, const char *category_name, int ignored)
213 struct ast_category *cat;
215 /* try exact match first, then case-insensitive match */
216 for (cat = config->root; cat; cat = cat->next) {
217 if (cat->name == category_name && (ignored || !cat->ignored))
221 for (cat = config->root; cat; cat = cat->next) {
222 if (!strcasecmp(cat->name, category_name) && (ignored || !cat->ignored))
229 struct ast_category *ast_category_get(const struct ast_config *config, const char *category_name)
231 return category_get(config, category_name, 0);
234 int ast_category_exist(const struct ast_config *config, const char *category_name)
236 return !!ast_category_get(config, category_name);
239 void ast_category_append(struct ast_config *config, struct ast_category *category)
242 config->last->next = category;
244 config->root = category;
245 config->last = category;
246 config->current = category;
249 void ast_category_destroy(struct ast_category *cat)
251 ast_variables_destroy(cat->root);
255 static struct ast_category *next_available_category(struct ast_category *cat)
257 for (; cat && cat->ignored; cat = cat->next);
262 char *ast_category_browse(struct ast_config *config, const char *prev)
264 struct ast_category *cat = NULL;
266 if (prev && config->last_browse && (config->last_browse->name == prev))
267 cat = config->last_browse->next;
268 else if (!prev && config->root)
271 for (cat = config->root; cat; cat = cat->next) {
272 if (cat->name == prev) {
278 for (cat = config->root; cat; cat = cat->next) {
279 if (!strcasecmp(cat->name, prev)) {
288 cat = next_available_category(cat);
290 config->last_browse = cat;
291 return (cat) ? cat->name : NULL;
294 struct ast_variable *ast_category_detach_variables(struct ast_category *cat)
296 struct ast_variable *v;
304 void ast_category_rename(struct ast_category *cat, const char *name)
306 ast_copy_string(cat->name, name, sizeof(cat->name));
309 static void inherit_category(struct ast_category *new, const struct ast_category *base)
311 struct ast_variable *var;
313 for (var = base->root; var; var = var->next)
314 ast_variable_append(new, variable_clone(var));
317 struct ast_config *ast_config_new(void)
319 struct ast_config *config;
321 if ((config = ast_calloc(1, sizeof(*config))))
322 config->max_include_level = MAX_INCLUDE_LEVEL;
326 int ast_variable_delete(struct ast_category *category, char *variable)
328 struct ast_variable *cur, *prev=NULL;
329 cur = category->root;
331 if (cur->name == variable) {
333 prev->next = cur->next;
334 if (cur == category->last)
335 category->last = prev;
337 category->root = cur->next;
338 if (cur == category->last)
339 category->last = NULL;
342 ast_variables_destroy(cur);
349 cur = category->root;
351 if (!strcasecmp(cur->name, variable)) {
353 prev->next = cur->next;
354 if (cur == category->last)
355 category->last = prev;
357 category->root = cur->next;
358 if (cur == category->last)
359 category->last = NULL;
362 ast_variables_destroy(cur);
371 int ast_variable_update(struct ast_category *category, char *variable, char *value)
373 struct ast_variable *cur, *prev=NULL, *newer;
374 newer = ast_variable_new(variable, value);
377 cur = category->root;
379 if (cur->name == variable) {
380 newer->next = cur->next;
384 category->root = newer;
385 if (category->last == cur)
386 category->last = newer;
388 ast_variables_destroy(cur);
395 cur = category->root;
397 if (!strcasecmp(cur->name, variable)) {
398 newer->next = cur->next;
402 category->root = newer;
403 if (category->last == cur)
404 category->last = newer;
406 ast_variables_destroy(cur);
415 category->root = newer;
419 int ast_category_delete(struct ast_config *cfg, char *category)
421 struct ast_category *prev=NULL, *cat;
424 if (cat->name == category) {
425 ast_variables_destroy(cat->root);
427 prev->next = cat->next;
428 if (cat == cfg->last)
431 cfg->root = cat->next;
432 if (cat == cfg->last)
443 if (!strcasecmp(cat->name, category)) {
444 ast_variables_destroy(cat->root);
446 prev->next = cat->next;
447 if (cat == cfg->last)
450 cfg->root = cat->next;
451 if (cat == cfg->last)
463 void ast_config_destroy(struct ast_config *cfg)
465 struct ast_category *cat, *catn;
472 ast_variables_destroy(cat->root);
480 struct ast_category *ast_config_get_current_category(const struct ast_config *cfg)
485 void ast_config_set_current_category(struct ast_config *cfg, const struct ast_category *cat)
487 /* cast below is just to silence compiler warning about dropping "const" */
488 cfg->current = (struct ast_category *) cat;
491 static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile, int withcomments)
495 struct ast_variable *v;
496 char cmd[512], exec_file[512];
497 int object, do_exec, do_include;
499 /* Actually parse the entry */
501 struct ast_category *newcat = NULL;
504 /* A category header */
505 c = strchr(cur, ']');
507 ast_log(LOG_WARNING, "parse error: no closing ']', line %d of %s\n", lineno, configfile);
515 if (!(*cat = newcat = ast_category_new(catname))) {
518 /* If there are options or categories to inherit from, process them now */
520 if (!(cur = strchr(c, ')'))) {
521 ast_log(LOG_WARNING, "parse error: no closing ')', line %d of %s\n", lineno, configfile);
525 while ((cur = strsep(&c, ","))) {
526 if (!strcasecmp(cur, "!")) {
528 } else if (!strcasecmp(cur, "+")) {
529 *cat = category_get(cfg, catname, 1);
531 ast_config_destroy(cfg);
533 ast_category_destroy(newcat);
534 ast_log(LOG_WARNING, "Category addition requested, but category '%s' does not exist, line %d of %s\n", catname, lineno, configfile);
538 move_variables(newcat, *cat);
539 ast_category_destroy(newcat);
543 struct ast_category *base;
545 base = category_get(cfg, cur, 1);
547 ast_log(LOG_WARNING, "Inheritance requested, but category '%s' does not exist, line %d of %s\n", cur, lineno, configfile);
550 inherit_category(*cat, base);
555 ast_category_append(cfg, *cat);
556 } else if (cur[0] == '#') {
560 while(*c && (*c > 32)) c++;
563 /* Find real argument */
564 c = ast_skip_blanks(c + 1);
569 do_include = !strcasecmp(cur, "include");
571 do_exec = !strcasecmp(cur, "exec");
574 if (do_exec && !ast_opt_exec_includes) {
575 ast_log(LOG_WARNING, "Cannot perform #exec unless execincludes option is enabled in asterisk.conf (options section)!\n");
578 if (do_include || do_exec) {
580 /* Strip off leading and trailing "'s and <>'s */
581 while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
582 /* Get rid of leading mess */
584 while (!ast_strlen_zero(cur)) {
585 c = cur + strlen(cur) - 1;
586 if ((*c == '>') || (*c == '<') || (*c == '\"'))
591 /* #exec </path/to/executable>
592 We create a tmp file, then we #include it, then we delete it. */
594 snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%d.%ld", (int)time(NULL), (long)pthread_self());
595 snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
596 ast_safe_system(cmd);
601 do_include = ast_config_internal_load(cur, cfg, withcomments) ? 1 : 0;
602 if(!ast_strlen_zero(exec_file))
608 ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n",
609 do_exec ? "exec" : "include",
610 do_exec ? "/path/to/executable" : "filename",
616 ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
618 /* Just a line (variable = value) */
621 "parse error: No category context for line %d of %s\n", lineno, configfile);
624 c = strchr(cur, '=');
634 if ((v = ast_variable_new(ast_strip(cur), ast_strip(c)))) {
637 /* Put and reset comments */
639 ast_variable_append(*cat, v);
644 ast_log(LOG_WARNING, "No '=' (equal sign) in line %d of %s\n", lineno, configfile);
651 static struct ast_config *config_text_file_load(const char *database, const char *table, const char *filename, struct ast_config *cfg, int withcomments)
655 char *new_buf, *comment_p, *process_buf;
658 int comment = 0, nest[MAX_NESTED_COMMENTS];
659 struct ast_category *cat = NULL;
663 cat = ast_config_get_current_category(cfg);
665 if (filename[0] == '/') {
666 ast_copy_string(fn, filename, sizeof(fn));
668 snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, filename);
671 #ifdef AST_INCLUDE_GLOB
675 globbuf.gl_offs = 0; /* initialize it to silence gcc */
677 glob_ret = glob(fn, GLOB_NOCHECK, NULL, &globbuf);
679 glob_ret = glob(fn, GLOB_NOMAGIC|GLOB_BRACE, NULL, &globbuf);
681 if (glob_ret == GLOB_NOSPACE)
683 "Glob Expansion of pattern '%s' failed: Not enough memory\n", fn);
684 else if (glob_ret == GLOB_ABORTED)
686 "Glob Expansion of pattern '%s' failed: Read error\n", fn);
688 /* loop over expanded files */
690 for (i=0; i<globbuf.gl_pathc; i++) {
691 ast_copy_string(fn, globbuf.gl_pathv[i], sizeof(fn));
694 if (stat(fn, &statbuf))
697 if (!S_ISREG(statbuf.st_mode)) {
698 ast_log(LOG_WARNING, "'%s' is not a regular file, ignoring\n", fn);
701 if ((option_verbose > 1) && !option_debug) {
702 ast_verbose(VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
705 if (!(f = fopen(fn, "r"))) {
707 ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
708 else if (option_verbose > 1)
709 ast_verbose( "Not found (%s)\n", strerror(errno));
714 ast_log(LOG_DEBUG, "Parsing %s\n", fn);
715 else if (option_verbose > 1)
716 ast_verbose("Found\n");
719 if (fgets(buf, sizeof(buf), f)) {
725 while ((comment_p = strchr(new_buf, COMMENT_META))) {
726 if ((comment_p > new_buf) && (*(comment_p-1) == '\\')) {
727 /* Yuck, gotta memmove */
728 memmove(comment_p - 1, comment_p, strlen(comment_p) + 1);
730 } else if(comment_p[1] == COMMENT_TAG && comment_p[2] == COMMENT_TAG && (comment_p[3] != '-')) {
731 /* Meta-Comment start detected ";--" */
732 if (comment < MAX_NESTED_COMMENTS) {
734 new_buf = comment_p + 3;
736 nest[comment-1] = lineno;
738 ast_log(LOG_ERROR, "Maximum nest limit of %d reached.\n", MAX_NESTED_COMMENTS);
740 } else if ((comment_p >= new_buf + 2) &&
741 (*(comment_p - 1) == COMMENT_TAG) &&
742 (*(comment_p - 2) == COMMENT_TAG)) {
743 /* Meta-Comment end detected */
745 new_buf = comment_p + 1;
747 /* Back to non-comment now */
749 /* Actually have to move what's left over the top, then continue */
751 oldptr = process_buf + strlen(process_buf);
752 memmove(oldptr, new_buf, strlen(new_buf) + 1);
755 process_buf = new_buf;
759 /* If ; is found, and we are not nested in a comment,
760 we immediately stop all comment processing */
764 new_buf = comment_p + 1;
768 char *buf = ast_strip(process_buf);
769 if (!ast_strlen_zero(buf)) {
770 if (process_text_line(cfg, &cat, buf, lineno, filename, withcomments)) {
781 ast_log(LOG_WARNING,"Unterminated comment detected beginning on line %d\n", nest[comment]);
783 #ifdef AST_INCLUDE_GLOB
797 int config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator)
803 struct ast_variable *var;
804 struct ast_category *cat;
807 if (configfile[0] == '/') {
808 ast_copy_string(fn, configfile, sizeof(fn));
810 snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, configfile);
813 ast_copy_string(date, ctime(&t), sizeof(date));
815 if ((f = fopen(fn, "w+"))) {
817 if ((f = fopen(fn, "w"))) {
819 if ((option_verbose > 1) && !option_debug)
820 ast_verbose( VERBOSE_PREFIX_2 "Saving '%s': ", fn);
822 fprintf(f, ";! Automatically generated configuration file\n");
823 fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
824 fprintf(f, ";! Generator: %s\n", generator);
825 fprintf(f, ";! Creation Date: %s", date);
829 /* Dump section with any appropriate comment */
830 fprintf(f, "\n[%s]\n", cat->name);
834 fprintf(f, "%s %s %s ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
836 fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
837 if (var->blanklines) {
838 blanklines = var->blanklines;
846 /* Put an empty line */
851 if ((option_verbose > 1) && !option_debug)
852 ast_verbose("Saved\n");
855 printf("Unable to open for writing: %s\n", fn);
856 else if (option_verbose > 1)
857 printf( "Unable to write (%s)", strerror(errno));
864 static void clear_config_maps(void)
866 struct ast_config_map *map;
868 ast_mutex_lock(&config_lock);
870 while (config_maps) {
872 config_maps = config_maps->next;
876 ast_mutex_unlock(&config_lock);
879 static int append_mapping(char *name, char *driver, char *database, char *table)
881 struct ast_config_map *map;
884 length = sizeof(*map);
885 length += strlen(name) + 1;
886 length += strlen(driver) + 1;
887 length += strlen(database) + 1;
889 length += strlen(table) + 1;
891 if (!(map = ast_calloc(1, length)))
894 map->name = map->stuff;
895 strcpy(map->name, name);
896 map->driver = map->name + strlen(map->name) + 1;
897 strcpy(map->driver, driver);
898 map->database = map->driver + strlen(map->driver) + 1;
899 strcpy(map->database, database);
901 map->table = map->database + strlen(map->database) + 1;
902 strcpy(map->table, table);
904 map->next = config_maps;
906 if (option_verbose > 1)
907 ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",
908 map->name, map->driver, map->database, map->table ? map->table : map->name);
914 int read_config_maps(void)
916 struct ast_config *config, *configtmp;
917 struct ast_variable *v;
918 char *driver, *table, *database, *stringp;
922 configtmp = ast_config_new();
923 configtmp->max_include_level = 1;
924 config = ast_config_internal_load(extconfig_conf, configtmp, 0);
926 ast_config_destroy(configtmp);
930 for (v = ast_variable_browse(config, "settings"); v; v = v->next) {
932 driver = strsep(&stringp, ",");
934 /* check if the database text starts with a double quote */
935 if (*stringp == '"') {
937 database = strsep(&stringp, "\"");
938 strsep(&stringp, ",");
940 /* apparently this text has no quotes */
941 database = strsep(&stringp, ",");
944 table = strsep(&stringp, ",");
946 if (!strcmp(v->name, extconfig_conf)) {
947 ast_log(LOG_WARNING, "Cannot bind '%s'!\n", extconfig_conf);
951 if (!strcmp(v->name, "asterisk.conf")) {
952 ast_log(LOG_WARNING, "Cannot bind 'asterisk.conf'!\n");
956 if (!strcmp(v->name, "logger.conf")) {
957 ast_log(LOG_WARNING, "Cannot bind 'logger.conf'!\n");
961 if (!driver || !database)
963 if (!strcasecmp(v->name, "sipfriends")) {
964 ast_log(LOG_WARNING, "The 'sipfriends' table is obsolete, update your config to use sipusers and sippeers, though they can point to the same table.\n");
965 append_mapping("sipusers", driver, database, table ? table : "sipfriends");
966 append_mapping("sippeers", driver, database, table ? table : "sipfriends");
967 } else if (!strcasecmp(v->name, "iaxfriends")) {
968 ast_log(LOG_WARNING, "The 'iaxfriends' table is obsolete, update your config to use iaxusers and iaxpeers, though they can point to the same table.\n");
969 append_mapping("iaxusers", driver, database, table ? table : "iaxfriends");
970 append_mapping("iaxpeers", driver, database, table ? table : "iaxfriends");
972 append_mapping(v->name, driver, database, table);
975 ast_config_destroy(config);
979 int ast_config_engine_register(struct ast_config_engine *new)
981 struct ast_config_engine *ptr;
983 ast_mutex_lock(&config_lock);
985 if (!config_engine_list) {
986 config_engine_list = new;
988 for (ptr = config_engine_list; ptr->next; ptr=ptr->next);
992 ast_mutex_unlock(&config_lock);
993 ast_log(LOG_NOTICE,"Registered Config Engine %s\n", new->name);
998 int ast_config_engine_deregister(struct ast_config_engine *del)
1000 struct ast_config_engine *ptr, *last=NULL;
1002 ast_mutex_lock(&config_lock);
1004 for (ptr = config_engine_list; ptr; ptr=ptr->next) {
1007 last->next = ptr->next;
1009 config_engine_list = ptr->next;
1015 ast_mutex_unlock(&config_lock);
1020 /*! \brief Find realtime engine for realtime family */
1021 static struct ast_config_engine *find_engine(const char *family, char *database, int dbsiz, char *table, int tabsiz)
1023 struct ast_config_engine *eng, *ret = NULL;
1024 struct ast_config_map *map;
1026 ast_mutex_lock(&config_lock);
1028 for (map = config_maps; map; map = map->next) {
1029 if (!strcasecmp(family, map->name)) {
1031 ast_copy_string(database, map->database, dbsiz);
1033 ast_copy_string(table, map->table ? map->table : family, tabsiz);
1038 /* Check if the required driver (engine) exist */
1040 for (eng = config_engine_list; !ret && eng; eng = eng->next) {
1041 if (!strcasecmp(eng->name, map->driver))
1046 ast_mutex_unlock(&config_lock);
1048 /* if we found a mapping, but the engine is not available, then issue a warning */
1050 ast_log(LOG_WARNING, "Realtime mapping for '%s' found to engine '%s', but the engine is not available\n", map->name, map->driver);
1055 static struct ast_config_engine text_file_engine = {
1057 .load_func = config_text_file_load,
1060 struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg, int withcomments)
1064 struct ast_config_engine *loader = &text_file_engine;
1065 struct ast_config *result;
1067 if (cfg->include_level == cfg->max_include_level) {
1068 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
1072 cfg->include_level++;
1074 if (strcmp(filename, extconfig_conf) && strcmp(filename, "asterisk.conf") && config_engine_list) {
1075 struct ast_config_engine *eng;
1077 eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
1080 if (eng && eng->load_func) {
1083 eng = find_engine("global", db, sizeof(db), table, sizeof(table));
1084 if (eng && eng->load_func)
1089 result = loader->load_func(db, table, filename, cfg, withcomments);
1092 result->include_level--;
1097 struct ast_config *ast_config_load(const char *filename)
1099 struct ast_config *cfg;
1100 struct ast_config *result;
1102 cfg = ast_config_new();
1106 result = ast_config_internal_load(filename, cfg, 0);
1108 ast_config_destroy(cfg);
1113 struct ast_config *ast_config_load_with_comments(const char *filename)
1115 struct ast_config *cfg;
1116 struct ast_config *result;
1118 cfg = ast_config_new();
1122 result = ast_config_internal_load(filename, cfg, 1);
1124 ast_config_destroy(cfg);
1129 struct ast_variable *ast_load_realtime(const char *family, ...)
1131 struct ast_config_engine *eng;
1134 struct ast_variable *res=NULL;
1137 va_start(ap, family);
1138 eng = find_engine(family, db, sizeof(db), table, sizeof(table));
1139 if (eng && eng->realtime_func)
1140 res = eng->realtime_func(db, table, ap);
1146 /*! \brief Check if realtime engine is configured for family */
1147 int ast_check_realtime(const char *family)
1149 struct ast_config_engine *eng;
1151 eng = find_engine(family, NULL, 0, NULL, 0);
1158 struct ast_config *ast_load_realtime_multientry(const char *family, ...)
1160 struct ast_config_engine *eng;
1163 struct ast_config *res=NULL;
1166 va_start(ap, family);
1167 eng = find_engine(family, db, sizeof(db), table, sizeof(table));
1168 if (eng && eng->realtime_multi_func)
1169 res = eng->realtime_multi_func(db, table, ap);
1175 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
1177 struct ast_config_engine *eng;
1183 va_start(ap, lookup);
1184 eng = find_engine(family, db, sizeof(db), table, sizeof(table));
1185 if (eng && eng->update_func)
1186 res = eng->update_func(db, table, keyfield, lookup, ap);
1192 static int config_command(int fd, int argc, char **argv)
1194 struct ast_config_engine *eng;
1195 struct ast_config_map *map;
1197 ast_mutex_lock(&config_lock);
1199 ast_cli(fd, "\n\n");
1200 for (eng = config_engine_list; eng; eng = eng->next) {
1201 ast_cli(fd, "\nConfig Engine: %s\n", eng->name);
1202 for (map = config_maps; map; map = map->next)
1203 if (!strcasecmp(map->driver, eng->name)) {
1204 ast_cli(fd, "===> %s (db=%s, table=%s)\n", map->name, map->database,
1205 map->table ? map->table : map->name);
1210 ast_mutex_unlock(&config_lock);
1215 static char show_config_help[] =
1216 "Usage: show config mappings\n"
1217 " Shows the filenames to config engines.\n";
1219 static struct ast_cli_entry config_command_struct = {
1220 { "show", "config", "mappings", NULL }, config_command, "Show Config mappings (file names to config engines)", show_config_help, NULL
1223 int register_config_cli()
1225 return ast_cli_register(&config_command_struct);