realtimeify voicemail...
[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(const 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(const 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, ...)
420 {
421         struct ast_config_reg *reg;
422         char db[256]="";
423         char table[256]="";
424         struct ast_variable *res=NULL;
425         va_list ap;
426         va_start(ap, family);
427         reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table));
428         if (reg && reg->realtime_func) 
429                 res = reg->realtime_func(db, table, ap);
430         va_end(ap);
431         return res;
432 }
433
434 int ast_update_realtime(const char *family, const char *keyfield, const char *lookup, ...)
435 {
436         struct ast_config_reg *reg;
437         int res = -1;
438         char db[256]="";
439         char table[256]="";
440         va_list ap;
441         va_start(ap, lookup);
442         reg = get_ast_cust_config_keyword(family, db, sizeof(db), table, sizeof(table));
443         if (reg && reg->update_func) 
444                 res = reg->update_func(db, table, keyfield, lookup, ap);
445         va_end(ap);
446         return res;
447 }
448
449 static struct ast_config *__ast_load(const char *configfile, struct ast_config *tmp, struct ast_category **_tmpc, struct ast_variable **_last, int includelevel)
450 {
451         char fn[256];
452         char buf[8192];
453         char db[256];
454         char table[256];
455         FILE *f;
456         int lineno=0;
457         int master=0;
458         struct ast_config_reg *reg=NULL;
459         struct ast_config *(*load_func)(const char *database, const char *table, const char *, struct ast_config *,struct ast_category **,struct ast_variable **,int);
460
461         load_func=NULL;
462         if (strcmp(configfile,config_conf_file) && strcmp(configfile,"asterisk.conf") && ast_cust_config_list) {
463                 if (global_load_func) {
464                         load_func = global_load_func;
465                 } else {
466                         reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table));
467                         if (reg && reg->static_func) {
468                                 load_func = reg->static_func;
469                         } else {
470                                 reg = get_ast_cust_config_keyword(configfile, db, sizeof(db), table, sizeof(table));
471                                 if (reg && reg->static_func)
472                                         global_load_func = load_func = reg->static_func;
473                         }
474                 }
475
476                 if (load_func) {
477                         ast_log(LOG_NOTICE,"Loading Config %s via %s engine\n",configfile,reg && reg->name ? reg->name : "global");
478                         tmp = load_func(db, table, configfile,tmp, _tmpc, _last, includelevel);
479             
480                         if (tmp)
481                                 return tmp;
482                 }
483         }
484
485         if (configfile[0] == '/') {
486                 strncpy(fn, configfile, sizeof(fn)-1);
487         } else {
488                 snprintf(fn, sizeof(fn), "%s/%s", (char *)ast_config_AST_CONFIG_DIR, configfile);
489         }
490         if ((option_verbose > 1) && !option_debug) {
491                 ast_verbose(  VERBOSE_PREFIX_2 "Parsing '%s': ", fn);
492                 fflush(stdout);
493         }
494         if ((f = fopen(fn, "r"))) {
495                 if (option_debug)
496                         ast_log(LOG_DEBUG, "Parsing %s\n", fn);
497                 else if (option_verbose > 1)
498                         ast_verbose( "Found\n");
499                 if (!tmp) {
500                         tmp = malloc(sizeof(struct ast_config));
501                         if (tmp)
502                                 memset(tmp, 0, sizeof(struct ast_config));
503
504                         master = 1;
505                 }
506                 if (!tmp) {
507                         ast_log(LOG_WARNING, "Out of memory\n");
508                         fclose(f);
509                         return NULL;
510                 }
511                 while(!feof(f)) {
512                         lineno++;
513                         if (fgets(buf, sizeof(buf), f)) {
514                                 if (cfg_process(tmp, _tmpc, _last, buf, lineno, configfile, includelevel)) {
515                                         fclose(f);
516                                         return NULL;
517                                 }
518                         }
519                 }
520                 fclose(f);              
521         } else {
522                 if (option_debug)
523                         ast_log(LOG_DEBUG, "No file to parse: %s\n", fn);
524                 else if (option_verbose > 1)
525                         ast_verbose( "Not found (%s)\n", strerror(errno));
526         }
527         return tmp;
528 }
529
530 int ast_config_register(struct ast_config_reg *new) 
531 {
532         struct ast_config_reg *ptr;
533         ast_mutex_lock(&ast_cust_config_lock);
534         if (!ast_cust_config_list) {
535                 ast_cust_config_list = new;
536         } else {
537                 for(ptr=ast_cust_config_list;ptr->next;ptr=ptr->next);
538                         ptr->next = new;
539         }
540         ast_mutex_unlock(&ast_cust_config_lock);
541         ast_log(LOG_NOTICE,"Registered Config Engine %s\n",new->name);
542         return 1;
543 }
544
545 int ast_config_deregister(struct ast_config_reg *del) 
546 {
547         struct ast_config_reg *ptr=NULL,*last=NULL;
548         ast_mutex_lock(&ast_cust_config_lock);
549         for (ptr=ast_cust_config_list;ptr;ptr=ptr->next) {
550                 if (ptr == del) {
551                         if (last && ptr->next) {
552                                 last->next = ptr->next;
553                         } else if (last && ! ptr->next) {
554                                 last->next = NULL;
555                         } else if (!last && ptr->next) {
556                                 ast_cust_config_list = ptr->next;
557                         } else if (!last && !ptr->next) {
558                                 ast_cust_config_list = NULL;
559                         }
560                 }
561                 last = ptr;
562         }
563         ast_mutex_unlock(&ast_cust_config_lock);
564         return 0;
565 }
566
567 int ast_cust_config_active(void) {
568         return (ast_cust_config >0) ? 1 : 0;
569 }
570
571 struct ast_config *ast_load(char *configfile)
572 {
573         struct ast_category *tmpc=NULL;
574         struct ast_variable *last = NULL;
575
576         return __ast_load(configfile, NULL, &tmpc, &last, 0);
577 }
578
579 char *ast_category_browse(struct ast_config *config, char *prev)
580 {       
581         struct ast_category *cat;
582         if (!prev) {
583                 if (config->root)
584                         return config->root->name;
585                 else
586                         return NULL;
587         }
588         cat = config->root;
589         while(cat) {
590                 if (cat->name == prev) {
591                         if (cat->next)
592                                 return cat->next->name;
593                         else
594                                 return NULL;
595                 }
596                 cat = cat->next;
597         }
598         cat = config->root;
599         while(cat) {
600                 if (!strcasecmp(cat->name, prev)) {
601                         if (cat->next)
602                                 return cat->next->name;
603                         else
604                                 return NULL;
605                 }
606                 cat = cat->next;
607         }
608         return NULL;
609 }
610
611
612 struct ast_config *ast_new_config(void) 
613 {
614         struct ast_config *config;
615         config = malloc(sizeof(struct ast_config));
616         memset(config,0,sizeof(struct ast_config));
617         return config;
618 }
619
620
621
622 struct ast_category *ast_new_category(char *name) 
623 {
624         struct ast_category *category;
625         category = malloc(sizeof(struct ast_category));
626         if (category) {
627                 memset(category,0,sizeof(struct ast_category));
628                 strncpy(category->name,name,sizeof(category->name) - 1);
629         }
630         return category;
631 }
632
633
634 struct ast_variable *ast_new_variable(char *name, char *value) 
635 {
636         struct ast_variable *variable;
637         int length = strlen(name) + strlen(value) + 2 + sizeof(struct ast_variable);
638         variable = malloc(length);
639         if (variable) {
640                 memset(variable, 0, length);
641                 variable->name = variable->stuff;
642                 variable->value = variable->stuff + strlen(name) + 1;           
643                 variable->object=0;
644                 strcpy(variable->name,name);
645                 strcpy(variable->value,value);
646         }
647         return variable;
648 }
649
650 int ast_cust_config_register(struct ast_config_reg *new) 
651 {
652         ast_config_register(new);
653         read_ast_cust_config();
654         return 1;
655 }
656 int ast_cust_config_deregister(struct ast_config_reg *new) 
657 {
658         ast_config_deregister(new);
659         read_ast_cust_config();
660         return 1;
661 }
662
663 static void clear_cust_keywords(void) 
664 {
665         struct ast_config_map *map, *prev;
666         ast_mutex_lock(&ast_cust_config_lock);
667         map = maps;
668         while(map) {
669                 prev = map;
670                 map = map->next;
671                 free(prev);
672         }
673         maps = NULL;
674         ast_mutex_unlock(&ast_cust_config_lock);
675 }
676
677 static int config_command(int fd, int argc, char **argv) 
678 {
679         struct ast_config_reg *key;
680         struct ast_config_map *map;
681         
682         ast_cli(fd,"\n\n");
683         ast_mutex_lock(&ast_cust_config_lock);
684         for (key=get_config_registrations();key;key=key->next) {
685                 ast_cli(fd,"\nConfig Engine: %s\n",key->name);
686                 map = maps;
687                 while(map) {
688                         if (!strcasecmp(map->driver, key->name))
689                                 ast_cli(fd,"===> %s (db=%s, table=%s)\n",map->name, map->database, map->table ? map->table : map->name);
690                         map = map->next;
691                 }
692         }
693         ast_mutex_unlock(&ast_cust_config_lock);
694         ast_cli(fd,"\n\n");
695         
696         return 0;
697 }
698
699 static struct ast_cli_entry config_command_struct = {
700   { "show","config","handles", NULL }, config_command,
701   "Show Config Handles", NULL };
702
703 int register_config_cli() 
704 {
705         return ast_cli_register(&config_command_struct);
706 }
707
708 int read_ast_cust_config(void) 
709 {
710         char *cfg = config_conf_file;
711         struct ast_config *config;
712         struct ast_variable *v;
713         struct ast_config_map *map;
714         int length;
715         char *driver, *table, *database, *stringp;
716
717         clear_cust_keywords();
718         config = ast_load(cfg);
719         if (config) {
720                 for (v = ast_variable_browse(config,"settings");v;v=v->next) {
721                         stringp = v->value;
722                         driver = strsep(&stringp, ",");
723                         database = strsep(&stringp, ",");
724                         table = strsep(&stringp, ",");
725                         
726                         if (!strcmp(v->name,config_conf_file) || !strcmp(v->name,"asterisk.conf")) {
727                                 ast_log(LOG_WARNING, "Cannot bind asterisk.conf or extconfig.conf!\n");
728                         } else if (driver && database) {
729                                 length = sizeof(struct ast_config_map);
730                                 length += strlen(v->name) + 1;
731                                 length += strlen(driver) + 1;
732                                 length += strlen(database) + 1;
733                                 if (table)
734                                         length += strlen(table) + 1;
735                                 map = malloc(length);
736                                 if (map) {
737                                         memset(map, 0, length);
738                                         map->name = map->stuff;
739                                         strcpy(map->name, v->name);
740                                         map->driver = map->name + strlen(map->name) + 1;
741                                         strcpy(map->driver, driver);
742                                         map->database = map->driver + strlen(map->driver) + 1;
743                                         strcpy(map->database, database);
744                                         if (table) {
745                                                 map->table = map->database + strlen(map->database) + 1;
746                                                 strcpy(map->table, table);
747                                         } else
748                                                 map->table = NULL;
749                                         map->next = maps;
750                                         if (option_verbose > 1)
751                                                 ast_verbose(VERBOSE_PREFIX_2 "Binding %s to %s/%s/%s\n",map->name,map->driver, map->database, map->table ? map->table : map->name);
752                                         maps = map;
753                                 }
754                         }
755                 }
756                 
757                 ast_destroy(config);
758         }
759
760         return 0;
761 }