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