7f2dc4aa5adc318654075ab834e27a8e30dd0e86
[asterisk/asterisk.git] / apps / app_directory.c
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  *
21  * \brief Provide a directory of extensions
22  *
23  * \author Mark Spencer <markster@digium.com>
24  * 
25  * \ingroup applications
26  */
27  
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include <ctype.h>
33
34 #include "asterisk/paths.h"     /* use ast_config_AST_SPOOL_DIR */
35 #include "asterisk/file.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/say.h"
39 #include "asterisk/app.h"
40
41 #ifdef ODBC_STORAGE
42 #include <sys/mman.h>
43 #include "asterisk/res_odbc.h"
44
45 static char odbc_database[80] = "asterisk";
46 static char odbc_table[80] = "voicemessages";
47 static char vmfmts[80] = "wav";
48 #endif
49
50 static char *app = "Directory";
51
52 static char *synopsis = "Provide directory of voicemail extensions";
53 static char *descrip =
54 "  Directory(vm-context[,dial-context[,options]]): This application will present\n"
55 "the calling channel with a directory of extensions from which they can search\n"
56 "by name. The list of names and corresponding extensions is retrieved from the\n"
57 "voicemail configuration file, voicemail.conf.\n"
58 "  This application will immediately exit if one of the following DTMF digits are\n"
59 "received and the extension to jump to exists:\n"
60 "    0 - Jump to the 'o' extension, if it exists.\n"
61 "    * - Jump to the 'a' extension, if it exists.\n\n"
62 "  Parameters:\n"
63 "    vm-context   - This is the context within voicemail.conf to use for the\n"
64 "                   Directory.\n"
65 "    dial-context - This is the dialplan context to use when looking for an\n"
66 "                   extension that the user has selected, or when jumping to the\n"
67 "                   'o' or 'a' extension.\n\n"
68 "  Options:\n"
69 "    e - In addition to the name, also read the extension number to the\n"
70 "        caller before presenting dialing options.\n"
71 "    f - Allow the caller to enter the first name of a user in the directory\n"
72 "        instead of using the last name.\n";
73
74 /* For simplicity, I'm keeping the format compatible with the voicemail config,
75    but i'm open to suggestions for isolating it */
76
77 #define VOICEMAIL_CONFIG "voicemail.conf"
78
79 /* How many digits to read in */
80 #define NUMDIGITS 3
81
82
83 #ifdef ODBC_STORAGE
84 struct generic_prepare_struct {
85         const char *sql;
86         const char *param;
87 };
88
89 static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
90 {
91         struct generic_prepare_struct *gps = data;
92         SQLHSTMT stmt;
93         int res;
94
95         res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
96         if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
97                 ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
98                 return NULL;
99         }
100
101         res = SQLPrepare(stmt, (unsigned char *)gps->sql, SQL_NTS);
102         if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
103                 ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", (char *)gps->sql);
104                 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
105                 return NULL;
106         }
107
108         if (!ast_strlen_zero(gps->param))
109                 SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(gps->param), 0, (void *)gps->param, 0, NULL);
110
111         return stmt;
112 }
113
114 static void retrieve_file(char *dir)
115 {
116         int x = 0;
117         int res;
118         int fd=-1;
119         size_t fdlen = 0;
120         void *fdm = MAP_FAILED;
121         SQLHSTMT stmt;
122         char sql[256];
123         char fmt[80]="", empty[10] = "";
124         char *c;
125         SQLLEN colsize;
126         char full_fn[256];
127         struct odbc_obj *obj;
128         struct generic_prepare_struct gps = { .sql = sql, .param = dir };
129
130         obj = ast_odbc_request_obj(odbc_database, 1);
131         if (obj) {
132                 do {
133                         ast_copy_string(fmt, vmfmts, sizeof(fmt));
134                         c = strchr(fmt, '|');
135                         if (c)
136                                 *c = '\0';
137                         if (!strcasecmp(fmt, "wav49"))
138                                 strcpy(fmt, "WAV");
139                         snprintf(full_fn, sizeof(full_fn), "%s.%s", dir, fmt);
140                         snprintf(sql, sizeof(sql), "SELECT recording FROM %s WHERE dir=? AND msgnum=-1", odbc_table);
141                         stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
142
143                         if (!stmt) {
144                                 ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
145                                 break;
146                         }
147                         res = SQLFetch(stmt);
148                         if (res == SQL_NO_DATA) {
149                                 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
150                                 break;
151                         } else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
152                                 ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
153                                 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
154                                 break;
155                         }
156                         fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, AST_FILE_MODE);
157                         if (fd < 0) {
158                                 ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
159                                 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
160                                 break;
161                         }
162
163                         res = SQLGetData(stmt, 1, SQL_BINARY, empty, 0, &colsize);
164                         fdlen = colsize;
165                         if (fd > -1) {
166                                 char tmp[1]="";
167                                 lseek(fd, fdlen - 1, SEEK_SET);
168                                 if (write(fd, tmp, 1) != 1) {
169                                         close(fd);
170                                         fd = -1;
171                                         break;
172                                 }
173                                 if (fd > -1)
174                                         fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
175                         }
176                         if (fdm != MAP_FAILED) {
177                                 memset(fdm, 0, fdlen);
178                                 res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
179                                 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
180                                         ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
181                                         SQLFreeHandle(SQL_HANDLE_STMT, stmt);
182                                         break;
183                                 }
184                         }
185                         SQLFreeHandle(SQL_HANDLE_STMT, stmt);
186                 } while (0);
187                 ast_odbc_release_obj(obj);
188         } else
189                 ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
190         if (fdm != MAP_FAILED)
191                 munmap(fdm, fdlen);
192         if (fd > -1)
193                 close(fd);
194         return;
195 }
196 #endif
197
198 static char *convert(const char *lastname)
199 {
200         char *tmp;
201         int lcount = 0;
202         tmp = ast_malloc(NUMDIGITS + 1);
203         if (tmp) {
204                 while((*lastname > 32) && lcount < NUMDIGITS) {
205                         switch(toupper(*lastname)) {
206                         case '1':
207                                 tmp[lcount++] = '1';
208                                 break;
209                         case '2':
210                         case 'A':
211                         case 'B':
212                         case 'C':
213                                 tmp[lcount++] = '2';
214                                 break;
215                         case '3':
216                         case 'D':
217                         case 'E':
218                         case 'F':
219                                 tmp[lcount++] = '3';
220                                 break;
221                         case '4':
222                         case 'G':
223                         case 'H':
224                         case 'I':
225                                 tmp[lcount++] = '4';
226                                 break;
227                         case '5':
228                         case 'J':
229                         case 'K':
230                         case 'L':
231                                 tmp[lcount++] = '5';
232                                 break;
233                         case '6':
234                         case 'M':
235                         case 'N':
236                         case 'O':
237                                 tmp[lcount++] = '6';
238                                 break;
239                         case '7':
240                         case 'P':
241                         case 'Q':
242                         case 'R':
243                         case 'S':
244                                 tmp[lcount++] = '7';
245                                 break;
246                         case '8':
247                         case 'T':
248                         case 'U':
249                         case 'V':
250                                 tmp[lcount++] = '8';
251                                 break;
252                         case '9':
253                         case 'W':
254                         case 'X':
255                         case 'Y':
256                         case 'Z':
257                                 tmp[lcount++] = '9';
258                                 break;
259                         }
260                         lastname++;
261                 }
262                 tmp[lcount] = '\0';
263         }
264         return tmp;
265 }
266
267 /* play name of mailbox owner.
268  * returns:  -1 for bad or missing extension
269  *           '1' for selected entry from directory
270  *           '*' for skipped entry from directory
271  */
272 static int play_mailbox_owner(struct ast_channel *chan, const char *context,
273                 const char *dialcontext, const char *ext, const char *name, int readext,
274                 int fromappvm)
275 {
276         int res = 0;
277         int loop;
278         char fn[256];
279
280         /* Check for the VoiceMail2 greeting first */
281         snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
282                 ast_config_AST_SPOOL_DIR, context, ext);
283 #ifdef ODBC_STORAGE
284         retrieve_file(fn);
285 #endif
286
287         if (ast_fileexists(fn, NULL, chan->language) <= 0) {
288                 /* no file, check for an old-style Voicemail greeting */
289                 snprintf(fn, sizeof(fn), "%s/vm/%s/greet",
290                         ast_config_AST_SPOOL_DIR, ext);
291         }
292 #ifdef ODBC_STORAGE
293         retrieve_file(fn);
294 #endif
295
296         if (ast_fileexists(fn, NULL, chan->language) > 0) {
297                 res = ast_stream_and_wait(chan, fn, AST_DIGIT_ANY);
298                 ast_stopstream(chan);
299                 /* If Option 'e' was specified, also read the extension number with the name */
300                 if (readext) {
301                         ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
302                         res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
303                 }
304         } else {
305                 res = ast_say_character_str(chan, S_OR(name, ext), AST_DIGIT_ANY, chan->language);
306                 if (!ast_strlen_zero(name) && readext) {
307                         ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
308                         res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
309                 }
310         }
311 #ifdef ODBC_STORAGE
312         ast_filedelete(fn, NULL);       
313 #endif
314
315         for (loop = 3 ; loop > 0; loop--) {
316                 if (!res)
317                         res = ast_stream_and_wait(chan, "dir-instr", AST_DIGIT_ANY);
318                 if (!res)
319                         res = ast_waitfordigit(chan, 3000);
320                 ast_stopstream(chan);
321         
322                 if (res < 0) /* User hungup, so jump out now */
323                         break;
324                 if (res == '1') {       /* Name selected */
325                         if (fromappvm) {
326                                 /* We still want to set the exten though */
327                                 ast_copy_string(chan->exten, ext, sizeof(chan->exten));
328                         } else {
329                                 if (ast_goto_if_exists(chan, dialcontext, ext, 1)) {
330                                         ast_log(LOG_WARNING,
331                                                 "Can't find extension '%s' in context '%s'.  "
332                                                 "Did you pass the wrong context to Directory?\n",
333                                                 ext, dialcontext);
334                                         res = -1;
335                                 }
336                         }
337                         break;
338                 }
339                 if (res == '*') /* Skip to next match in list */
340                         break;
341
342                 /* Not '1', or '*', so decrement number of tries */
343                 res = 0;
344         }
345
346         return(res);
347 }
348
349 static struct ast_config *realtime_directory(char *context)
350 {
351         struct ast_config *cfg;
352         struct ast_config *rtdata;
353         struct ast_category *cat;
354         struct ast_variable *var;
355         char *mailbox;
356         const char *fullname;
357         const char *hidefromdir;
358         char tmp[100];
359         struct ast_flags config_flags = { 0 };
360
361         /* Load flat file config. */
362         cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
363
364         if (!cfg) {
365                 /* Loading config failed. */
366                 ast_log(LOG_WARNING, "Loading config failed.\n");
367                 return NULL;
368         }
369
370         /* Get realtime entries, categorized by their mailbox number
371            and present in the requested context */
372         rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);
373
374         /* if there are no results, just return the entries from the config file */
375         if (!rtdata)
376                 return cfg;
377
378         /* Does the context exist within the config file? If not, make one */
379         cat = ast_category_get(cfg, context);
380         if (!cat) {
381                 cat = ast_category_new(context, "", 99999);
382                 if (!cat) {
383                         ast_log(LOG_WARNING, "Out of memory\n");
384                         ast_config_destroy(cfg);
385                         return NULL;
386                 }
387                 ast_category_append(cfg, cat);
388         }
389
390         mailbox = NULL;
391         while ( (mailbox = ast_category_browse(rtdata, mailbox)) ) {
392                 fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
393                 hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
394                 snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
395                          fullname ? fullname : "",
396                          hidefromdir ? hidefromdir : "no");
397                 var = ast_variable_new(mailbox, tmp, "");
398                 if (var)
399                         ast_variable_append(cat, var);
400                 else
401                         ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
402         }
403         ast_config_destroy(rtdata);
404
405         return cfg;
406 }
407
408 static int do_directory(struct ast_channel *chan, struct ast_config *cfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int last, int readext, int fromappvm)
409 {
410         /* Read in the first three digits..  "digit" is the first digit, already read */
411         char ext[NUMDIGITS + 1], *cat;
412         char name[80] = "";
413         struct ast_variable *v;
414         int res;
415         int found=0;
416         int lastuserchoice = 0;
417         char *start, *conv, *stringp = NULL;
418         const char *pos;
419         int breakout = 0;
420
421         if (ast_strlen_zero(context)) {
422                 ast_log(LOG_WARNING,
423                         "Directory must be called with an argument "
424                         "(context in which to interpret extensions)\n");
425                 return -1;
426         }
427         if (digit == '0') {
428                 if (!ast_goto_if_exists(chan, dialcontext, "o", 1) ||
429                     (!ast_strlen_zero(chan->macrocontext) &&
430                      !ast_goto_if_exists(chan, chan->macrocontext, "o", 1))) {
431                         return 0;
432                 } else {
433                         ast_log(LOG_WARNING, "Can't find extension 'o' in current context.  "
434                                 "Not Exiting the Directory!\n");
435                         res = 0;
436                 }
437         }       
438         if (digit == '*') {
439                 if (!ast_goto_if_exists(chan, dialcontext, "a", 1) ||
440                     (!ast_strlen_zero(chan->macrocontext) &&
441                      !ast_goto_if_exists(chan, chan->macrocontext, "a", 1))) {
442                         return 0;
443                 } else {
444                         ast_log(LOG_WARNING, "Can't find extension 'a' in current context.  "
445                                 "Not Exiting the Directory!\n");
446                         res = 0;
447                 }
448         }       
449         memset(ext, 0, sizeof(ext));
450         ext[0] = digit;
451         res = 0;
452         if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1;
453         if (!res) {
454                 /* Search for all names which start with those digits */
455                 v = ast_variable_browse(cfg, context);
456                 while(v && !res) {
457                         /* Find all candidate extensions */
458                         while(v) {
459                                 /* Find a candidate extension */
460                                 start = ast_strdup(v->value);
461                                 if (start && !strcasestr(start, "hidefromdir=yes")) {
462                                         stringp=start;
463                                         strsep(&stringp, ",");
464                                         pos = strsep(&stringp, ",");
465                                         if (pos) {
466                                                 ast_copy_string(name, pos, sizeof(name));
467                                                 /* Grab the last name */
468                                                 if (last && strrchr(pos,' '))
469                                                         pos = strrchr(pos, ' ') + 1;
470                                                 conv = convert(pos);
471                                                 if (conv) {
472                                                         if (!strncmp(conv, ext, strlen(ext))) {
473                                                                 /* Match! */
474                                                                 found++;
475                                                                 ast_free(conv);
476                                                                 ast_free(start);
477                                                                 break;
478                                                         }
479                                                         ast_free(conv);
480                                                 }
481                                         }
482                                         ast_free(start);
483                                 }
484                                 v = v->next;
485                         }
486
487                         if (v) {
488                                 /* We have a match -- play a greeting if they have it */
489                                 res = play_mailbox_owner(chan, context, dialcontext, v->name, name, readext, fromappvm);
490                                 switch (res) {
491                                         case -1:
492                                                 /* user pressed '1' but extension does not exist, or
493                                                  * user hungup
494                                                  */
495                                                 lastuserchoice = 0;
496                                                 break;
497                                         case '1':
498                                                 /* user pressed '1' and extensions exists;
499                                                    play_mailbox_owner will already have done
500                                                    a goto() on the channel
501                                                  */
502                                                 lastuserchoice = res;
503                                                 break;
504                                         case '*':
505                                                 /* user pressed '*' to skip something found */
506                                                 lastuserchoice = res;
507                                                 res = 0;
508                                                 break;
509                                         default:
510                                                 break;
511                                 }
512                                 v = v->next;
513                         }
514                 }
515
516                 if (!res && ucfg) {
517                         /* Search users.conf for all names which start with those digits */
518                         for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) {
519                                 if (!strcasecmp(cat, "general"))
520                                         continue;
521                                 if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
522                                         continue;
523                                 
524                                 /* Find all candidate extensions */
525                                 if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) {
526                                         ast_copy_string(name, pos, sizeof(name));
527                                         /* Grab the last name */
528                                         if (last && strrchr(pos,' '))
529                                                 pos = strrchr(pos, ' ') + 1;
530                                         conv = convert(pos);
531                                         if (conv) {
532                                                 if (!strcmp(conv, ext)) {
533                                                         /* Match! */
534                                                         found++;
535                                                         /* We have a match -- play a greeting if they have it */
536                                                         res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext, fromappvm);
537                                                         switch (res) {
538                                                         case -1:
539                                                                 /* user pressed '1' but extension does not exist, or
540                                                                  * user hungup
541                                                                  */
542                                                                 lastuserchoice = 0;
543                                                                 breakout = 1;
544                                                                 break;
545                                                         case '1':
546                                                                 /* user pressed '1' and extensions exists;
547                                                                    play_mailbox_owner will already have done
548                                                                    a goto() on the channel
549                                                                  */
550                                                                 lastuserchoice = res;
551                                                                 breakout = 1;
552                                                                 break;
553                                                         case '*':
554                                                                 /* user pressed '*' to skip something found */
555                                                                 lastuserchoice = res;
556                                                                 breakout = 0;
557                                                                 res = 0;
558                                                                 break;
559                                                         default:
560                                                                 breakout = 1;
561                                                                 break;
562                                                         }
563                                                         ast_free(conv);
564                                                         if (breakout)
565                                                                 break;
566                                                 } else
567                                                         ast_free(conv);
568                                         }
569                                 }
570                         }
571                 }
572                         
573                 if (lastuserchoice != '1') {
574                         res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language);
575                         if (!res)
576                                 res = 1;
577                         return res;
578                 }
579                 return 0;
580         }
581         return res;
582 }
583
584 static int directory_exec(struct ast_channel *chan, void *data)
585 {
586         int res = 0;
587         struct ast_config *cfg, *ucfg;
588         int last = 1;
589         int readext = 0;
590         int fromappvm = 0;
591         const char *dirintro;
592         char *parse;
593         struct ast_flags config_flags = { 0 };
594         AST_DECLARE_APP_ARGS(args,
595                 AST_APP_ARG(vmcontext);
596                 AST_APP_ARG(dialcontext);
597                 AST_APP_ARG(options);
598         );
599
600         if (ast_strlen_zero(data)) {
601                 ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
602                 return -1;
603         }
604
605         parse = ast_strdupa(data);
606
607         AST_STANDARD_APP_ARGS(args, parse);
608                 
609         if (args.options) {
610                 if (strchr(args.options, 'f'))
611                         last = 0;
612                 if (strchr(args.options, 'e'))
613                         readext = 1;
614                 if (strchr(args.options, 'v'))
615                         fromappvm = 1;
616         }
617
618         if (ast_strlen_zero(args.dialcontext))  
619                 args.dialcontext = args.vmcontext;
620
621         cfg = realtime_directory(args.vmcontext);
622         if (!cfg) {
623                 ast_log(LOG_ERROR, "Unable to read the configuration data!\n");
624                 return -1;
625         }
626         
627         ucfg = ast_config_load("users.conf", config_flags);
628
629         dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
630         if (ast_strlen_zero(dirintro))
631                 dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
632         if (ast_strlen_zero(dirintro))
633                 dirintro = last ? "dir-intro" : "dir-intro-fn";
634
635         if (chan->_state != AST_STATE_UP) 
636                 res = ast_answer(chan);
637
638         for (;;) {
639                 if (!res)
640                         res = ast_stream_and_wait(chan, dirintro, AST_DIGIT_ANY);
641                 ast_stopstream(chan);
642                 if (!res)
643                         res = ast_waitfordigit(chan, 5000);
644                 if (res > 0) {
645                         res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, last, readext, fromappvm);
646                         if (res > 0) {
647                                 res = ast_waitstream(chan, AST_DIGIT_ANY);
648                                 ast_stopstream(chan);
649                                 if (res >= 0)
650                                         continue;
651                         }
652                 }
653                 break;
654         }
655         if (ucfg)
656                 ast_config_destroy(ucfg);
657         ast_config_destroy(cfg);
658         return res;
659 }
660
661 static int unload_module(void)
662 {
663         int res;
664         res = ast_unregister_application(app);
665         return res;
666 }
667
668 static int load_module(void)
669 {
670 #ifdef ODBC_STORAGE
671         struct ast_flags config_flags = { 0 };
672         struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
673         const char *tmp;
674
675         if (cfg) {
676                 if ((tmp = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {
677                         ast_copy_string(odbc_database, tmp, sizeof(odbc_database));
678                 }
679                 if ((tmp = ast_variable_retrieve(cfg, "general", "odbctable"))) {
680                         ast_copy_string(odbc_table, tmp, sizeof(odbc_table));
681                 }
682                 if ((tmp = ast_variable_retrieve(cfg, "general", "format"))) {
683                         ast_copy_string(vmfmts, tmp, sizeof(vmfmts));
684                 }
685                 ast_config_destroy(cfg);
686         } else
687                 ast_log(LOG_WARNING, "Unable to load " VOICEMAIL_CONFIG " - ODBC defaults will be used\n");
688 #endif
689
690         return ast_register_application(app, directory_exec, synopsis, descrip);
691 }
692
693 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Extension Directory");