Major changes to res_config to support centralized config, eliminate configuration...
[asterisk/asterisk.git] / config.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Configuration File Parser
5  * 
6  * Copyright (C) 1999-2004, Digium, Inc.
7  *
8  * Mark Spencer <markster@digium.com>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <stdio.h>
15 #include <unistd.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <errno.h>
19 #include <time.h>
20 #include <asterisk/config.h>
21 #include <asterisk/config_pvt.h>
22 #include <asterisk/cli.h>
23 #include <asterisk/lock.h>
24 #include <asterisk/options.h>
25 #include <asterisk/logger.h>
26 #include <asterisk/utils.h>
27 #include "asterisk.h"
28 #include "astconf.h"
29
30
31 static int ast_cust_config=0;
32 struct ast_config *(*global_load_func)(const char *dbname, const char *table, const char *, struct ast_config *,struct ast_category **,struct ast_variable **,int);
33
34 static struct ast_config_map {
35         struct ast_config_map *next;
36         char *name;
37         char *driver;
38         char *database;
39         char *table;
40         char stuff[0];
41 } *maps = NULL;
42
43 AST_MUTEX_DEFINE_STATIC(ast_cust_config_lock);
44 static struct ast_config_reg *ast_cust_config_list;
45 static char *config_conf_file = "extconfig.conf";
46
47 void ast_destroy_realtime(struct ast_variable *v)
48 {
49         struct ast_variable *vn;
50         while(v) {
51                 vn = v;
52                 v = v->next;
53                 free(vn);
54         }
55 }
56
57 void ast_destroy(struct ast_config *ast)
58 {
59         struct ast_category *cat, *catn;
60
61         if (!ast)
62                 return;
63
64         cat = ast->root;
65         while(cat) {
66                 ast_destroy_realtime(cat->root);
67                 catn = cat;
68                 cat = cat->next;
69                 free(catn);
70         }
71         free(ast);
72 }
73
74 int ast_true(char *s)
75 {
76         if (!s)
77                 return 0;
78         /* Determine if this is a true value */
79         if (!strcasecmp(s, "yes") ||
80             !strcasecmp(s, "true") ||
81                 !strcasecmp(s, "y") ||
82                 !strcasecmp(s, "t") ||
83                 !strcasecmp(s, "1") ||
84                 !strcasecmp(s, "on"))
85                         return -1;
86         return 0;
87 }
88
89 int ast_false(char *s)
90 {
91         if (!s)
92                 return 0;
93         /* Determine if this is a false value */
94         if (!strcasecmp(s, "no") ||
95             !strcasecmp(s, "false") ||
96                 !strcasecmp(s, "n") ||
97                 !strcasecmp(s, "f") ||
98                 !strcasecmp(s, "0") ||
99                 !strcasecmp(s, "off"))
100                         return -1;
101         return 0;
102 }
103
104 struct ast_variable *ast_variable_browse(struct ast_config *config, char *category)
105 {
106         struct ast_category *cat;
107         cat = config->root;
108         while(cat) {
109                 if (cat->name == category)
110                         return cat->root;
111                 cat = cat->next;
112         }
113         cat = config->root;
114         while(cat) {
115                 if (!strcasecmp(cat->name, category))
116                         return cat->root;
117                 cat = cat->next;
118         }
119         return NULL;
120 }
121
122 char *ast_variable_retrieve(struct ast_config *config, char *category, char *value)
123 {
124         struct ast_variable *v;
125         if (category) {
126                 v = ast_variable_browse(config, category);
127                 while (v) {
128                         if (value == v->name)
129                                 return v->value;
130                         v=v->next;
131                 }
132                 v = ast_variable_browse(config, category);
133                 while (v) {
134                         if (!strcasecmp(value, v->name))
135                                 return v->value;
136                         v=v->next;
137                 }
138         } else {
139                 struct ast_category *cat;
140                 cat = config->root;
141                 while(cat) {
142                         v = cat->root;
143                         while (v) {
144                                 if (!strcasecmp(value, v->name))
145                                         return v->value;
146                                 v=v->next;
147                         }
148                         cat = cat->next;
149                 }
150         }
151         return NULL;
152 }
153
154 int ast_category_exist(struct ast_config *config, char *category_name)
155 {
156         struct ast_category *category = NULL;
157
158         category = config->root;
159
160         while(category) {
161                 if (!strcasecmp(category->name,category_name)) 
162                         return 1;
163                 category = category->next;
164         } 
165
166         return 0;
167 }
168
169
170 static struct ast_config_reg *get_ast_cust_config_keyword(const char *name, char *database, int dbsiz, char *table, int tabsiz) 
171 {
172         struct ast_config_reg *reg,*ret=NULL;
173         struct ast_config_map *map;
174
175         ast_mutex_lock(&ast_cust_config_lock);
176         map = maps;
177         while(map) {
178                 if (!strcasecmp(name, map->name)) {
179                         strncpy(database, map->database, dbsiz - 1);
180                         if (map->table)
181                                 strncpy(table, map->table, tabsiz - 1);
182                         else
183                                 strncpy(table, name, tabsiz - 1);
184                         break;
185                 }
186                 map = map->next;
187         }
188         if (map) {
189                 for (reg=ast_cust_config_list;reg && !ret;reg=reg->next) {
190                         if (!strcmp(reg->name,map->driver))
191                                 ret=reg;
192                 }
193         }
194         ast_mutex_unlock(&ast_cust_config_lock);
195         return ret;
196 }
197
198 void ast_config_destroy_all(void) 
199 {
200         struct ast_config_reg *key;
201         ast_mutex_lock(&ast_cust_config_lock);
202         for (key=ast_cust_config_list;key;key=key->next) {
203                 ast_config_deregister(key);
204         }
205         ast_cust_config_list = NULL;
206         ast_mutex_unlock(&ast_cust_config_lock);
207 }
208
209 static struct ast_config_reg *get_config_registrations(void) 
210 {
211         return ast_cust_config_list;
212 }
213
214
215 static struct ast_config *__ast_load(const char *configfile, struct ast_config *tmp, struct ast_category **_tmpc, struct ast_variable **_last, int includelevel);
216
217 static int cfg_process(struct ast_config *tmp, struct ast_category **_tmpc, struct ast_variable **_last, char *buf, int lineno, const char *configfile, int includelevel )
218 {
219         char *c;
220         char *cur;
221         char *arg=NULL;
222         struct ast_variable *v;
223         int object;
224         /* Strip off lines using ; as comment */
225         c = strchr(buf, ';');
226         while (c) {
227                 if ((c == buf) || (*(c-1) != '\\')) {
228                         *c = '\0';
229                 } else {
230                         *(c-1) = ';';
231                         memmove(c, c + 1, strlen(c + 1));
232                 }
233                 c = strchr(c + 1, ';');
234         }
235         cur = ast_strip(buf);
236         if (!ast_strlen_zero(cur)) {
237                 /* Actually parse the entry */
238                 if (cur[0] == '[') {
239                         /* A category header */
240                         c = strchr(cur, ']');
241                         if (c) {
242                                 *c = 0;
243                                 *_tmpc = malloc(sizeof(struct ast_category));
244                                 if (!*_tmpc) {
245                                         ast_destroy(tmp);
246                                         ast_log(LOG_WARNING,
247                                                 "Out of memory, line %d\n", lineno);
248                                         return -1;
249                                 }
250                                 memset(*_tmpc, 0, sizeof(struct ast_category));
251                                 strncpy((*_tmpc)->name, cur+1, sizeof((*_tmpc)->name) - 1);
252                                 (*_tmpc)->root =  NULL;
253                                 if (!tmp->prev)
254                                         tmp->root = *_tmpc;
255                                 else
256                                         tmp->prev->next = *_tmpc;
257
258                                 tmp->prev = *_tmpc;
259                                 *_last =  NULL;
260                         } else {
261                                 ast_log(LOG_WARNING, 
262                                         "parse error: no closing ']', line %d of %s\n", lineno, configfile);
263                         }
264                 } else if (cur[0] == '#') {
265                         /* A directive */
266                         cur++;
267                         c = cur;
268                         while(*c && (*c > 32)) c++;
269                         if (*c) {
270                                 *c = '\0';
271                                 c++;
272                                 /* Find real argument */
273                                 while(*c  && (*c < 33)) c++;
274                                 if (!*c)
275                                         c = NULL;
276                         } else 
277                                 c = NULL;
278                         if (!strcasecmp(cur, "include")) {
279                                 /* A #include */
280                                 if (c) {
281                                         while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
282                                         /* Get rid of leading mess */
283                                         cur = c;
284                                         while (!ast_strlen_zero(cur)) {
285                                                 c = cur + strlen(cur) - 1;
286                                                 if ((*c == '>') || (*c == '<') || (*c == '\"'))
287                                                         *c = '\0';
288                                                 else
289                                                         break;
290                                         }
291                                         
292                                         if((c = strchr(cur,':'))) {
293                                                 *c = '\0';
294                                                 c++;
295                                                 arg = c;
296                                         }
297                                         
298                                         if (includelevel < MAX_INCLUDE_LEVEL) {
299                                                 if(arg && cur) {
300                                                         ast_log(LOG_WARNING, "Including files with explicit config engine no longer permitted.  Please use extconfig.conf to specify all mappings\n");
301                                                 } else {
302                                                         __ast_load(cur, tmp, _tmpc, _last, includelevel + 1);
303                                                 }
304                                         } else
305                                                 ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", includelevel);
306                                 } else
307                                         ast_log(LOG_WARNING, "Directive '#include' needs an argument (filename) at line %d of %s\n", lineno, configfile);
308                                 /* Strip off leading and trailing "'s and <>'s */
309                         }
310                         else 
311                                 ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
312                 } else {
313                         /* Just a line (variable = value) */
314                         if (!*_tmpc) {
315                                 ast_log(LOG_WARNING,
316                                         "parse error: No category context for line %d of %s\n", lineno, configfile);
317                                 ast_destroy(tmp);
318                                 return -1;
319                         }
320                         c = strchr(cur, '=');
321                         if (c) {
322                                 *c = 0;
323                                 c++;
324                                 /* Ignore > in => */
325                                 if (*c== '>') {
326                                         object = 1;
327                                         c++;
328                                 } else
329                                         object = 0;
330                                 v = ast_new_variable(ast_strip(cur), ast_strip(c));
331                                 if (v) {
332                                         v->next = NULL;
333                                         v->lineno = lineno;
334                                         v->object = object;
335                                         /* Put and reset comments */
336                                         v->blanklines = 0;
337                                         if (*_last)
338                                                 (*_last)->next = v;
339                                         else
340                                                 (*_tmpc)->root = v;
341                                         *_last = v;
342                                 } else {
343                                         ast_destroy(tmp);
344                                         ast_log(LOG_WARNING, "Out of memory, line %d\n", lineno);
345                                         return -1;
346                                 }
347                         } else {
348                                 ast_log(LOG_WARNING, "No '=' (equal sign) in line %d of %s\n", lineno, configfile);
349                         }
350                                                                                                                 
351                 }
352         }
353         return 0;
354 }
355
356 int ast_save(char *configfile, struct ast_config *cfg, char *generator)
357 {
358         FILE *f;
359         char fn[256];
360         char date[256]="";
361         time_t t;
362         struct ast_variable *var;
363         struct ast_category *cat;
364         int blanklines = 0;
365         if (configfile[0] == '/') {
366                 strncpy(fn, configfile, sizeof(fn)-1);
367         } else {
368                 snprintf(fn, sizeof(fn), "%s/%s", AST_CONFIG_DIR, configfile);
369         }
370         time(&t);
371         strncpy(date, ctime(&t), sizeof(date) - 1);
372         if ((f = fopen(fn, "w"))) {
373                 if ((option_verbose > 1) && !option_debug)
374                         ast_verbose(  VERBOSE_PREFIX_2 "Saving '%s': ", fn);
375                 fprintf(f, ";!\n");
376                 fprintf(f, ";! Automatically generated configuration file\n");
377                 fprintf(f, ";! Filename: %s (%s)\n", configfile, fn);
378                 fprintf(f, ";! Generator: %s\n", generator);
379                 fprintf(f, ";! Creation Date: %s", date);
380                 fprintf(f, ";!\n");
381                 cat = cfg->root;
382                 while(cat) {
383                         /* Dump section with any appropriate comment */
384                         fprintf(f, "[%s]\n", cat->name);
385                         var = cat->root;
386                         while(var) {
387                                 if (var->sameline) 
388                                         fprintf(f, "%s %s %s  ; %s\n", var->name, (var->object ? "=>" : "="), var->value, var->sameline->cmt);
389                                 else    
390                                         fprintf(f, "%s %s %s\n", var->name, (var->object ? "=>" : "="), var->value);
391                                 if (var->blanklines) {
392                                         blanklines = var->blanklines;
393                                         while (blanklines) {
394                                                 fprintf(f, "\n");
395                                                 blanklines--;
396                                         }
397                                 }
398                                         
399                                 var = var->next;
400                         }
401 #if 0
402                         /* Put an empty line */
403                         fprintf(f, "\n");
404 #endif
405                         cat = cat->next;
406                 }
407         } else {
408                 if (option_debug)
409                         printf("Unable to open for writing: %s\n", fn);
410                 else if (option_verbose > 1)
411                         printf( "Unable to write (%s)", strerror(errno));
412                 return -1;
413         }
414         fclose(f);
415         return 0;
416 }
417
418
419 struct ast_variable *ast_load_realtime(const char *family, const char *keyfield, const char *lookup)
420 {
421         struct ast_config_reg *reg;
422         char db[256]="";
423         char table[256]="";
424         reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table));
425         if (reg && reg->realtime_func) 
426                 return reg->realtime_func(db, table, keyfield, lookup);
427         return NULL;
428 }
429
430 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
431 {
432         struct ast_config_reg *reg;
433         int res = -1;
434         char db[256]="";
435         char table[256]="";
436         va_list ap;
437         va_start(ap, lookup);
438         reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table));
439         if (reg && reg->update_func) 
440                 res = reg->update_func(db, table, keyfield, lookup, ap);
441         va_end(ap);
442         return res;
443 }
444
445 static struct ast_config *__ast_load(const char *configfile, struct ast_config *tmp, struct ast_category **_tmpc, struct ast_variable **_last, int includelevel)
446 {
447         char fn[256];
448         char buf[8192];
449         char db[256];
450         char table[256];
451         FILE *f;
452         int lineno=0;
453         int master=0;
454         struct ast_config_reg *reg=NULL;
455         struct ast_config *(*load_func)(const char *database, const char *table, const char *, struct ast_config *,struct ast_category **,struct ast_variable **,int);
456
457         load_func=NULL;
458         if (strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) {
459                 if (global_load_func) {
460                         load_func = global_load_func;
461                 } else {
462                         reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table));
463                         if (reg && reg->static_func) {
464                                 load_func = reg->static_func;
465                         } else {
466                                 reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table));
467                                 if (reg && reg->static_func)
468                                         global_load_func = load_func = reg->static_func;
469                         }
470                 }
471
472                 if (load_func) {
473                         ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global");
474                         tmp = load_func(db, table, configfile,tmp, _tmpc, _last, includelevel);
475             
476                         if (tmp)
477                                 return tmp;
478                 }
479         }
480
481         if (configfile[0] == '/') {
482                 strncpy(fn, configfile, sizeof(fn)-1);
483         } else {
484                 snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, configfile);
485         }
486         if ((option_verbose > 1) && !option_debug) {
487                 ast_verbose(  VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
488                 fflush(stdout);
489         }
490         if ((f = fopen(fn, "r"))) {
491                 if (option_debug)
492                         ast_log(LOG_DEBUG, "Parsing %s\n", fn);
493                 else if (option_verbose > 1)
494                         ast_verbose( "Found\n");
495                 if (!tmp) {
496                         tmp = malloc(sizeof(struct ast_config));
497                         if (tmp)
498                                 memset(tmp, 0, sizeof(struct ast_config));
499
500                         master = 1;
501                 }
502                 if (!tmp) {
503                         ast_log(LOG_WARNING, "Out of memory\n");
504                         fclose(f);
505                         return NULL;
506                 }
507                 while(!feof(f)) {
508                         lineno++;
509                         if (fgets(buf, sizeof(buf), f)) {
510                                 if (cfg_process(tmp, _tmpc, _last, buf, lineno, configfile, includelevel)) {
511                                         fclose(f);
512                                         return NULL;
513                                 }
514                         }
515                 }
516                 fclose(f);              
517         } else {
518                 if (option_debug)
519                         ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
520                 else if (option_verbose > 1)
521                         ast_verbose( "Not found (%s)\n", strerror(errno));
522         }
523         return tmp;
524 }
525
526 int ast_config_register(struct ast_config_reg *new) 
527 {
528         struct ast_config_reg *ptr;
529         ast_mutex_lock(&ast_cust_config_lock);
530         if (!ast_cust_config_list) {
531                 ast_cust_config_list = new;
532         } else {
533                 for(ptr=ast_cust_config_list;ptr->next;ptr=ptr->next);
534                         ptr->next = new;
535         }
536         ast_mutex_unlock(&ast_cust_config_lock);
537         ast_log(LOG_NOTICE,"Registered Config Engine %s\n",new->name);
538         return 1;
539 }
540
541 int ast_config_deregister(struct ast_config_reg *del) 
542 {
543         struct ast_config_reg *ptr=NULL,*last=NULL;
544         ast_mutex_lock(&ast_cust_config_lock);
545         for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
546                 if (ptr == del) {
547                         if (last && ptr->next) {
548                                 last->next = ptr->next;
549                         } else if (last && ! ptr->next) {
550                                 last->next = NULL;
551                         } else if (!last && ptr->next) {
552                                 ast_cust_config_list = ptr->next;
553                         } else if (!last && !ptr->next) {
554                                 ast_cust_config_list = NULL;
555                         }
556                 }
557                 last = ptr;
558         }
559         ast_mutex_unlock(&ast_cust_config_lock);
560         return 0;
561 }
562
563 int ast_cust_config_active(void) {
564         return (ast_cust_config >0) ? 1 : 0;
565 }
566
567 struct ast_config *ast_load(char *configfile)
568 {
569         struct ast_category *tmpc=NULL;
570         struct ast_variable *last = NULL;
571
572         return __ast_load(configfile, NULL, &tmpc, &last, 0);
573 }
574
575 char *ast_category_browse(struct ast_config *config, char *prev)
576 {       
577         struct ast_category *cat;
578         if (!prev) {
579                 if (config->root)
580                         return config->root->name;
581                 else
582                         return NULL;
583         }
584         cat = config->root;
585         while(cat) {
586                 if (cat->name == prev) {
587                         if (cat->next)
588                                 return cat->next->name;
589                         else
590                                 return NULL;
591                 }
592                 cat = cat->next;
593         }
594         cat = config->root;
595         while(cat) {
596                 if (!strcasecmp(cat->name, prev)) {
597                         if (cat->next)
598                                 return cat->next->name;
599                         else
600                                 return NULL;
601                 }
602                 cat = cat->next;
603         }
604         return NULL;
605 }
606
607
608 struct ast_config *ast_new_config(void) 
609 {
610         struct ast_config *config;
611         config = malloc(sizeof(struct ast_config));
612         memset(config,0,sizeof(struct ast_config));
613         return config;
614 }
615
616
617
618 struct ast_category *ast_new_category(char *name) 
619 {
620         struct ast_category *category;
621         category = malloc(sizeof(struct ast_category));
622         if (category) {
623                 memset(category,0,sizeof(struct ast_category));
624                 strncpy(category->name,name,sizeof(category->name) - 1);
625         }
626         return category;
627 }
628
629
630 struct ast_variable *ast_new_variable(char *name, char *value) 
631 {
632         struct ast_variable *variable;
633         int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable);
634         variable = malloc(length);
635         if (variable) {
636                 memset(variable, 0, length);
637                 variable->name = variable->stuff;
638                 variable->value = variable->stuff + strlen(name) + 1;           
639                 variable->object=0;
640                 strcpy(variable->name,name);
641                 strcpy(variable->value,value);
642         }
643         return variable;
644 }
645
646 int ast_cust_config_register(struct ast_config_reg *new) 
647 {
648         ast_config_register(new);
649         read_ast_cust_config();
650         return 1;
651 }
652 int ast_cust_config_deregister(struct ast_config_reg *new) 
653 {
654         ast_config_deregister(new);
655         read_ast_cust_config();
656         return 1;
657 }
658
659 static void clear_cust_keywords(void) 
660 {
661         struct ast_config_map *map, *prev;
662         ast_mutex_lock(&ast_cust_config_lock);
663         map = maps;
664         while(map) {
665                 prev = map;
666                 map = map->next;
667                 free(prev);
668         }
669         maps = NULL;
670         ast_mutex_unlock(&ast_cust_config_lock);
671 }
672
673 static int config_command(int fd, int argc, char **argv) 
674 {
675         struct ast_config_reg *key;
676         struct ast_config_map *map;
677         
678         ast_cli(fd,"\n\n");
679         ast_mutex_lock(&ast_cust_config_lock);
680         for (key=get_config_registrations();key;key=key->next) {
681                 ast_cli(fd,"\nConfig Engine: %s\n",key->name);
682                 map = maps;
683                 while(map) {
684                         if (!strcasecmp(map->driver, key->name))
685                                 ast_cli(fd,"===> %s (db=%s, table=%s)\n",map->name, map->database, map->table ? map->table : map->name);
686                         map = map->next;
687                 }
688         }
689         ast_mutex_unlock(&ast_cust_config_lock);
690         ast_cli(fd,"\n\n");
691         
692         return 0;
693 }
694
695 static struct ast_cli_entry config_command_struct = {
696   { "show","config","handles", NULL }, config_command,
697   "Show Config Handles", NULL };
698
699 int register_config_cli() 
700 {
701         return ast_cli_register(&config_command_struct);
702 }
703
704 int read_ast_cust_config(void) 
705 {
706         char *cfg = config_conf_file;
707         struct ast_config *config;
708         struct ast_variable *v;
709         struct ast_config_map *map;
710         int length;
711         char *driver, *table, *database, *stringp;
712
713         clear_cust_keywords();
714         config = ast_load(cfg);
715         if (config) {
716                 for (v = ast_variable_browse(config,"settings");v;v=v->next) {
717                         stringp = v->value;
718                         driver = strsep(&stringp, ",");
719                         database = strsep(&stringp, ",");
720                         table = strsep(&stringp, ",");
721                         
722                         if (!strcmp(v->name,config_conf_file) || !strcmp(v->name,"asterisk.conf")) {
723                                 ast_log(LOG_WARNING, "Cannot bind asterisk.conf or extconfig.conf!\n");
724                         } else if (driver && database) {
725                                 length = sizeof(struct ast_config_map);
726                                 length += strlen(v->name) + 1;
727                                 length += strlen(driver) + 1;
728                                 length += strlen(database) + 1;
729                                 if (table)
730                                         length += strlen(table) + 1;
731                                 map = malloc(length);
732                                 if (map) {
733                                         memset(map, 0, length);
734                                         map->name = map->stuff;
735                                         strcpy(map->name, v->name);
736                                         map->driver = map->name + strlen(map->name) + 1;
737                                         strcpy(map->driver, driver);
738                                         map->database = map->driver + strlen(map->driver) + 1;
739                                         strcpy(map->database, database);
740                                         if (table) {
741                                                 map->table = map->database + strlen(map->database) + 1;
742                                                 strcpy(map->table, table);
743                                         } else
744                                                 map->table = NULL;
745                                         map->next = maps;
746                                         if (option_verbose > 1)
747                                                 ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",map->name,map->driver, map->database, map->table ? map->table : map->name);
748                                         maps = map;
749                                 }
750                         }
751                 }
752                 
753                 ast_destroy(config);
754         }
755
756         return 0;
757 }