2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (C) 1999 - 2005, Digium, Inc.
6 * Mark Spencer <markster@digium.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief Provide a directory of extensions
23 * \author Mark Spencer <markster@digium.com>
25 * \ingroup applications
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
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 #include "asterisk/utils.h"
44 #include "asterisk/res_odbc.h"
46 static char odbc_database[80] = "asterisk";
47 static char odbc_table[80] = "voicemessages";
48 static char vmfmts[80] = "wav";
51 static char *app = "Directory";
53 static char *synopsis = "Provide directory of voicemail extensions";
54 static char *descrip =
55 " Directory(vm-context[,dial-context[,options]]): This application will present\n"
56 "the calling channel with a directory of extensions from which they can search\n"
57 "by name. The list of names and corresponding extensions is retrieved from the\n"
58 "voicemail configuration file, voicemail.conf.\n"
59 " This application will immediately exit if one of the following DTMF digits are\n"
60 "received and the extension to jump to exists:\n"
61 " 0 - Jump to the 'o' extension, if it exists.\n"
62 " * - Jump to the 'a' extension, if it exists.\n\n"
64 " vm-context - This is the context within voicemail.conf to use for the\n"
66 " dial-context - This is the dialplan context to use when looking for an\n"
67 " extension that the user has selected, or when jumping to the\n"
68 " 'o' or 'a' extension.\n\n"
70 " e In addition to the name, also read the extension number to the\n"
71 " caller before presenting dialing options.\n"
72 " f[(<n>)] Allow the caller to enter the first name of a user in the\n"
73 " directory instead of using the last name. If specified, the\n"
74 " optional number argument will be used for the number of\n"
75 " characters the user should enter.\n"
76 " l[(<n>)] Allow the caller to enter the last name of a user in the\n"
77 " directory. This is the default. If specified, the\n"
78 " optional number argument will be used for the number of\n"
79 " characters the user should enter.\n"
80 " b[(<n>)] Allow the caller to enter either the first or the last name\n"
81 " of a user in the directory. If specified, the optional number\n"
82 " argument will be used for the number of characters the user\n"
84 " m Instead of reading each name sequentially and asking for\n"
85 " confirmation, create a menu of up to 8 names.\n"
86 " p(<n>) Pause for n milliseconds after the digits are typed. This is\n"
87 " helpful for people with cellphones, who are not holding the\n"
88 " receiver to their ear while entering DTMF.\n"
90 " Only one of the f, l, or b options may be specified. If more than one is\n"
91 " specified, then Directory will act as if 'b' was specified. The number\n"
92 " of characters for the user to type defaults to 3.\n";
94 /* For simplicity, I'm keeping the format compatible with the voicemail config,
95 but i'm open to suggestions for isolating it */
97 #define VOICEMAIL_CONFIG "voicemail.conf"
100 OPT_LISTBYFIRSTNAME = (1 << 0),
101 OPT_SAYEXTENSION = (1 << 1),
102 OPT_FROMVOICEMAIL = (1 << 2),
103 OPT_SELECTFROMMENU = (1 << 3),
104 OPT_LISTBYLASTNAME = (1 << 4),
105 OPT_LISTBYEITHER = OPT_LISTBYFIRSTNAME | OPT_LISTBYLASTNAME,
106 OPT_PAUSE = (1 << 5),
107 } directory_option_flags;
110 OPT_ARG_FIRSTNAME = 0,
111 OPT_ARG_LASTNAME = 1,
114 /* This *must* be the last value in this enum! */
115 OPT_ARG_ARRAY_SIZE = 4,
118 struct directory_item {
119 char exten[AST_MAX_EXTENSION + 1];
120 char name[AST_MAX_EXTENSION + 1];
121 char key[50]; /* Text to order items. Either lastname+firstname or firstname+lastname */
123 AST_LIST_ENTRY(directory_item) entry;
126 AST_APP_OPTIONS(directory_app_options, {
127 AST_APP_OPTION_ARG('f', OPT_LISTBYFIRSTNAME, OPT_ARG_FIRSTNAME),
128 AST_APP_OPTION_ARG('l', OPT_LISTBYLASTNAME, OPT_ARG_LASTNAME),
129 AST_APP_OPTION_ARG('b', OPT_LISTBYEITHER, OPT_ARG_EITHER),
130 AST_APP_OPTION_ARG('p', OPT_PAUSE, OPT_ARG_PAUSE),
131 AST_APP_OPTION('e', OPT_SAYEXTENSION),
132 AST_APP_OPTION('v', OPT_FROMVOICEMAIL),
133 AST_APP_OPTION('m', OPT_SELECTFROMMENU),
137 struct generic_prepare_struct {
142 static SQLHSTMT generic_prepare(struct odbc_obj *obj, void *data)
144 struct generic_prepare_struct *gps = data;
148 res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
149 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
150 ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
154 res = SQLPrepare(stmt, (unsigned char *)gps->sql, SQL_NTS);
155 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
156 ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", (char *)gps->sql);
157 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
161 if (!ast_strlen_zero(gps->param))
162 SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(gps->param), 0, (void *)gps->param, 0, NULL);
167 static void retrieve_file(char *dir)
173 void *fdm = MAP_FAILED;
176 char fmt[80]="", empty[10] = "";
180 struct odbc_obj *obj;
181 struct generic_prepare_struct gps = { .sql = sql, .param = dir };
183 obj = ast_odbc_request_obj(odbc_database, 1);
186 ast_copy_string(fmt, vmfmts, sizeof(fmt));
187 c = strchr(fmt, '|');
190 if (!strcasecmp(fmt, "wav49"))
192 snprintf(full_fn, sizeof(full_fn), "%s.%s", dir, fmt);
193 snprintf(sql, sizeof(sql), "SELECT recording FROM %s WHERE dir=? AND msgnum=-1", odbc_table);
194 stmt = ast_odbc_prepare_and_execute(obj, generic_prepare, &gps);
197 ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
200 res = SQLFetch(stmt);
201 if (res == SQL_NO_DATA) {
202 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
204 } else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
205 ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
206 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
209 fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, AST_FILE_MODE);
211 ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
212 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
216 res = SQLGetData(stmt, 1, SQL_BINARY, empty, 0, &colsize);
220 lseek(fd, fdlen - 1, SEEK_SET);
221 if (write(fd, tmp, 1) != 1) {
227 fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
229 if (fdm != MAP_FAILED) {
230 memset(fdm, 0, fdlen);
231 res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
232 if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
233 ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
234 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
238 SQLFreeHandle(SQL_HANDLE_STMT, stmt);
240 ast_odbc_release_obj(obj);
242 ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
243 if (fdm != MAP_FAILED)
251 static int compare(const char *text, const char *template)
256 digit = toupper(*text++);
320 if (*template++ != digit)
327 /* play name of mailbox owner.
328 * returns: -1 for bad or missing extension
329 * '1' for selected entry from directory
330 * '*' for skipped entry from directory
332 static int play_mailbox_owner(struct ast_channel *chan, const char *context,
333 const char *ext, const char *name, struct ast_flags *flags)
338 /* Check for the VoiceMail2 greeting first */
339 snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
340 ast_config_AST_SPOOL_DIR, context, ext);
345 if (ast_fileexists(fn, NULL, chan->language) <= 0) {
346 /* no file, check for an old-style Voicemail greeting */
347 snprintf(fn, sizeof(fn), "%s/vm/%s/greet",
348 ast_config_AST_SPOOL_DIR, ext);
354 if (ast_fileexists(fn, NULL, chan->language) > 0) {
355 res = ast_stream_and_wait(chan, fn, AST_DIGIT_ANY);
356 ast_stopstream(chan);
357 /* If Option 'e' was specified, also read the extension number with the name */
358 if (ast_test_flag(flags, OPT_SAYEXTENSION)) {
359 ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
360 res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
363 res = ast_say_character_str(chan, S_OR(name, ext), AST_DIGIT_ANY, chan->language);
364 if (!ast_strlen_zero(name) && ast_test_flag(flags, OPT_SAYEXTENSION)) {
365 ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
366 res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
370 ast_filedelete(fn, NULL);
376 static int select_entry(struct ast_channel *chan, const char *context, const char *dialcontext, const struct directory_item *item, struct ast_flags *flags)
378 ast_debug(1, "Selecting '%s' - %s@%s\n", item->name, item->exten, dialcontext);
380 if (ast_test_flag(flags, OPT_FROMVOICEMAIL)) {
381 /* We still want to set the exten though */
382 ast_copy_string(chan->exten, item->exten, sizeof(chan->exten));
383 } else if (ast_goto_if_exists(chan, dialcontext, item->exten, 1)) {
385 "Can't find extension '%s' in context '%s'. "
386 "Did you pass the wrong context to Directory?\n",
387 item->exten, dialcontext);
394 static int select_item_seq(struct ast_channel *chan, struct directory_item **items, int count, const char *context, const char *dialcontext, struct ast_flags *flags)
396 struct directory_item *item, **ptr;
399 for (ptr = items, i = 0; i < count; i++, ptr++) {
402 for (loop = 3 ; loop > 0; loop--) {
403 res = play_mailbox_owner(chan, context, item->exten, item->name, flags);
406 res = ast_stream_and_wait(chan, "dir-instr", AST_DIGIT_ANY);
408 res = ast_waitfordigit(chan, 3000);
409 ast_stopstream(chan);
411 if (res == '1') { /* Name selected */
412 return select_entry(chan, context, dialcontext, item, flags) ? -1 : 1;
413 } else if (res == '*') {
414 /* Skip to next match in list */
425 /* Nothing was selected */
429 static int select_item_menu(struct ast_channel *chan, struct directory_item **items, int count, const char *context, const char *dialcontext, struct ast_flags *flags)
431 struct directory_item **block, *item;
432 int i, limit, res = 0;
435 for (block = items; count; block += limit, count -= limit) {
440 for (i = 0; i < limit && !res; i++) {
443 snprintf(buf, sizeof(buf), "digits/%d", i + 1);
444 /* Press <num> for <name>, [ extension <ext> ] */
445 res = ast_streamfile(chan, "dir-multi1", chan->language);
447 res = ast_waitstream(chan, AST_DIGIT_ANY);
449 res = ast_streamfile(chan, buf, chan->language);
451 res = ast_waitstream(chan, AST_DIGIT_ANY);
453 res = ast_streamfile(chan, "dir-multi2", chan->language);
455 res = ast_waitstream(chan, AST_DIGIT_ANY);
457 res = play_mailbox_owner(chan, context, item->exten, item->name, flags);
459 res = ast_waitstream(chan, AST_DIGIT_ANY);
461 res = ast_waitfordigit(chan, 800);
464 /* Press "9" for more names. */
465 if (!res && count > limit) {
466 res = ast_streamfile(chan, "dir-multi9", chan->language);
468 res = ast_waitstream(chan, AST_DIGIT_ANY);
472 res = ast_waitfordigit(chan, 3000);
475 if (res && res > '0' && res < '1' + limit) {
476 return select_entry(chan, context, dialcontext, block[res - '1'], flags) ? -1 : 1;
485 /* Nothing was selected */
489 static struct ast_config *realtime_directory(char *context)
491 struct ast_config *cfg;
492 struct ast_config *rtdata;
493 struct ast_category *cat;
494 struct ast_variable *var;
496 const char *fullname;
497 const char *hidefromdir;
499 struct ast_flags config_flags = { 0 };
501 /* Load flat file config. */
502 cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
505 /* Loading config failed. */
506 ast_log(LOG_WARNING, "Loading config failed.\n");
510 /* Get realtime entries, categorized by their mailbox number
511 and present in the requested context */
512 rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);
514 /* if there are no results, just return the entries from the config file */
518 /* Does the context exist within the config file? If not, make one */
519 cat = ast_category_get(cfg, context);
521 cat = ast_category_new(context, "", 99999);
523 ast_log(LOG_WARNING, "Out of memory\n");
524 ast_config_destroy(cfg);
527 ast_category_append(cfg, cat);
531 while ( (mailbox = ast_category_browse(rtdata, mailbox)) ) {
532 fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
533 if (ast_true((hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir")))) {
537 snprintf(tmp, sizeof(tmp), "no-password,%s", S_OR(fullname, ""));
538 var = ast_variable_new(mailbox, tmp, "");
540 ast_variable_append(cat, var);
542 ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
544 ast_config_destroy(rtdata);
549 static int check_match(struct directory_item **result, const char *item_fullname, const char *item_ext, const char *pattern_ext, int use_first_name)
551 struct directory_item *item;
552 const char *key = NULL;
556 /* Set key to last name or first name depending on search mode */
558 key = strchr(item_fullname, ' ');
565 if (compare(key, pattern_ext))
569 item = ast_calloc(1, sizeof(*item));
572 ast_copy_string(item->name, item_fullname, sizeof(item->name));
573 ast_copy_string(item->exten, item_ext, sizeof(item->exten));
575 ast_copy_string(item->key, key, sizeof(item->key));
576 if (key != item_fullname) {
577 /* Key is the last name. Append first name to key in order to sort Last,First */
578 namelen = key - item_fullname - 1;
579 if (namelen > sizeof(item->key) - strlen(item->key) - 1)
580 namelen = sizeof(item->key) - strlen(item->key) - 1;
581 strncat(item->key, item_fullname, namelen);
588 typedef AST_LIST_HEAD_NOLOCK(, directory_item) itemlist;
590 static int search_directory(const char *context, struct ast_config *vmcfg, struct ast_config *ucfg, const char *ext, struct ast_flags flags, itemlist *alist)
592 struct ast_variable *v;
593 char buf[AST_MAX_EXTENSION + 1], *pos, *bufptr, *cat;
594 struct directory_item *item;
597 ast_debug(2, "Pattern: %s\n", ext);
599 for (v = ast_variable_browse(vmcfg, context); v; v = v->next) {
602 if (strcasestr(v->value, "hidefromdir=yes"))
605 ast_copy_string(buf, v->value, sizeof(buf));
608 /* password,Full Name,email,pager,options */
609 strsep(&bufptr, ",");
610 pos = strsep(&bufptr, ",");
613 if (ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
614 res = check_match(&item, pos, v->name, ext, 0 /* use_first_name */);
616 if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
617 res = check_match(&item, pos, v->name, ext, 1 /* use_first_name */);
625 AST_LIST_INSERT_TAIL(alist, item, entry);
630 for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
632 if (!strcasecmp(cat, "general"))
634 if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
637 /* Find all candidate extensions */
638 pos = ast_variable_retrieve(ucfg, cat, "fullname");
643 if (ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
644 res = check_match(&item, pos, v->name, ext, 0 /* use_first_name */);
646 if (!res && ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
647 res = check_match(&item, pos, v->name, ext, 1 /* use_first_name */);
655 AST_LIST_INSERT_TAIL(alist, item, entry);
662 static void sort_items(struct directory_item **sorted, int count)
665 struct directory_item **ptr, *tmp;
670 /* Bubble-sort items by the key */
673 for (ptr = sorted, i = 0; i < count - 1; i++, ptr++) {
674 if (strcasecmp(ptr[0]->key, ptr[1]->key) > 0) {
684 static int goto_exten(struct ast_channel *chan, const char *dialcontext, char *ext)
686 if (!ast_goto_if_exists(chan, dialcontext, ext, 1) ||
687 (!ast_strlen_zero(chan->macrocontext) &&
688 !ast_goto_if_exists(chan, chan->macrocontext, ext, 1))) {
691 ast_log(LOG_WARNING, "Can't find extension '%s' in current context. "
692 "Not Exiting the Directory!\n", ext);
697 static int do_directory(struct ast_channel *chan, struct ast_config *vmcfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int digits, struct ast_flags *flags)
699 /* Read in the first three digits.. "digit" is the first digit, already read */
701 itemlist alist = AST_LIST_HEAD_NOLOCK_INIT_VALUE;
702 struct directory_item *item, **ptr, **sorted = NULL;
706 if (ast_strlen_zero(context)) {
708 "Directory must be called with an argument "
709 "(context in which to interpret extensions)\n");
713 if (digit == '0' && !goto_exten(chan, dialcontext, "o")) {
717 if (digit == '*' && !goto_exten(chan, dialcontext, "a")) {
722 if (ast_readstring(chan, ext + 1, digits - 1, 3000, 3000, "#") < 0)
725 res = search_directory(context, vmcfg, ucfg, ext, *flags, &alist);
729 /* Count items in the list */
731 AST_LIST_TRAVERSE(&alist, item, entry) {
736 res = ast_streamfile(chan, "dir-nomatch", chan->language);
741 /* Create plain array of pointers to items (for sorting) */
742 sorted = ast_calloc(count, sizeof(*sorted));
745 AST_LIST_TRAVERSE(&alist, item, entry) {
750 sort_items(sorted, count);
753 ast_debug(2, "Listing matching entries:\n");
754 for (ptr = sorted, i = 0; i < count; i++, ptr++) {
755 ast_log(LOG_DEBUG, "%s: %s\n", ptr[0]->exten, ptr[0]->name);
759 if (ast_test_flag(flags, OPT_SELECTFROMMENU)) {
760 /* Offer multiple entries at the same time */
761 res = select_item_menu(chan, sorted, count, context, dialcontext, flags);
763 /* Offer entries one by one */
764 res = select_item_seq(chan, sorted, count, context, dialcontext, flags);
768 res = ast_streamfile(chan, "dir-nomore", chan->language);
775 while ((item = AST_LIST_REMOVE_HEAD(&alist, entry)))
781 static int directory_exec(struct ast_channel *chan, void *data)
783 int res = 0, digit = 3;
784 struct ast_config *cfg, *ucfg;
785 const char *dirintro;
786 char *parse, *opts[OPT_ARG_ARRAY_SIZE];
787 struct ast_flags flags = { 0 };
788 struct ast_flags config_flags = { 0 };
789 enum { FIRST, LAST, BOTH } which = LAST;
790 char digits[9] = "digits/3";
791 AST_DECLARE_APP_ARGS(args,
792 AST_APP_ARG(vmcontext);
793 AST_APP_ARG(dialcontext);
794 AST_APP_ARG(options);
797 if (ast_strlen_zero(data)) {
798 ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
802 parse = ast_strdupa(data);
804 AST_STANDARD_APP_ARGS(args, parse);
806 if (args.options && ast_app_parse_options(directory_app_options, &flags, opts, args.options))
809 if (ast_strlen_zero(args.dialcontext))
810 args.dialcontext = args.vmcontext;
812 cfg = realtime_directory(args.vmcontext);
814 ast_log(LOG_ERROR, "Unable to read the configuration data!\n");
818 ucfg = ast_config_load("users.conf", config_flags);
820 dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
821 if (ast_strlen_zero(dirintro))
822 dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
824 if (ast_test_flag(&flags, OPT_LISTBYFIRSTNAME) && ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
825 if (!ast_strlen_zero(opts[OPT_ARG_EITHER])) {
826 digit = atoi(opts[OPT_ARG_EITHER]);
829 } else if (ast_test_flag(&flags, OPT_LISTBYFIRSTNAME)) {
830 if (!ast_strlen_zero(opts[OPT_ARG_FIRSTNAME])) {
831 digit = atoi(opts[OPT_ARG_FIRSTNAME]);
835 if (!ast_strlen_zero(opts[OPT_ARG_LASTNAME])) {
836 digit = atoi(opts[OPT_ARG_LASTNAME]);
841 /* If no options specified, search by last name */
842 if (!ast_test_flag(&flags, OPT_LISTBYFIRSTNAME) && !ast_test_flag(&flags, OPT_LISTBYLASTNAME)) {
843 ast_set_flag(&flags, OPT_LISTBYLASTNAME);
849 } else if (digit < 1) {
852 digits[7] = digit + '0';
854 if (chan->_state != AST_STATE_UP)
855 res = ast_answer(chan);
858 if (!ast_strlen_zero(dirintro) && !res) {
859 res = ast_stream_and_wait(chan, dirintro, AST_DIGIT_ANY);
861 res = ast_stream_and_wait(chan, "dir-welcome", AST_DIGIT_ANY) ||
862 ast_stream_and_wait(chan, "dir-pls-enter", AST_DIGIT_ANY) ||
863 ast_stream_and_wait(chan, digits, AST_DIGIT_ANY) ||
864 ast_stream_and_wait(chan,
865 which == FIRST ? "dir-first" :
866 which == LAST ? "dir-last" :
867 "dir-firstlast", AST_DIGIT_ANY) ||
868 ast_stream_and_wait(chan, "dir-usingkeypad", AST_DIGIT_ANY);
870 ast_stopstream(chan);
872 res = ast_waitfordigit(chan, 5000);
877 res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, digit, &flags);
881 res = ast_waitstream(chan, AST_DIGIT_ANY);
882 ast_stopstream(chan);
889 ast_config_destroy(ucfg);
890 ast_config_destroy(cfg);
892 return res < 0 ? -1 : 0;
895 static int unload_module(void)
898 res = ast_unregister_application(app);
902 static int load_module(void)
905 struct ast_flags config_flags = { 0 };
906 struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG, config_flags);
910 if ((tmp = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {
911 ast_copy_string(odbc_database, tmp, sizeof(odbc_database));
913 if ((tmp = ast_variable_retrieve(cfg, "general", "odbctable"))) {
914 ast_copy_string(odbc_table, tmp, sizeof(odbc_table));
916 if ((tmp = ast_variable_retrieve(cfg, "general", "format"))) {
917 ast_copy_string(vmfmts, tmp, sizeof(vmfmts));
919 ast_config_destroy(cfg);
921 ast_log(LOG_WARNING, "Unable to load " VOICEMAIL_CONFIG " - ODBC defaults will be used\n");
924 return ast_register_application(app, directory_exec, synopsis, descrip);
927 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Extension Directory");