1999-10-30 01:01:34 +00:00
|
|
|
/*
|
2005-09-14 20:46:50 +00:00
|
|
|
* Asterisk -- An open source telephony toolkit.
|
1999-10-30 01:01:34 +00:00
|
|
|
*
|
2005-01-21 07:06:25 +00:00
|
|
|
* Copyright (C) 1999 - 2005, Digium, Inc.
|
1999-10-30 01:01:34 +00:00
|
|
|
*
|
2004-10-02 00:58:31 +00:00
|
|
|
* Mark Spencer <markster@digium.com>
|
1999-10-30 01:01:34 +00:00
|
|
|
*
|
2005-09-14 20:46:50 +00:00
|
|
|
* See http://www.asterisk.org for more information about
|
|
|
|
* the Asterisk project. Please do not directly contact
|
|
|
|
* any of the maintainers of this project for assistance;
|
|
|
|
* the project provides a web site, mailing lists and IRC
|
|
|
|
* channels for your use.
|
|
|
|
*
|
1999-10-30 01:01:34 +00:00
|
|
|
* This program is free software, distributed under the terms of
|
2005-09-14 20:46:50 +00:00
|
|
|
* the GNU General Public License Version 2. See the LICENSE file
|
|
|
|
* at the top of the source tree.
|
|
|
|
*/
|
|
|
|
|
2005-10-24 20:12:06 +00:00
|
|
|
/*! \file
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-10-24 20:12:06 +00:00
|
|
|
* \brief Provide a directory of extensions
|
2005-12-30 21:18:06 +00:00
|
|
|
*
|
|
|
|
* \author Mark Spencer <markster@digium.com>
|
2005-09-14 20:46:50 +00:00
|
|
|
*
|
2005-11-06 15:09:47 +00:00
|
|
|
* \ingroup applications
|
1999-10-30 01:01:34 +00:00
|
|
|
*/
|
|
|
|
|
2006-06-07 18:54:56 +00:00
|
|
|
#include "asterisk.h"
|
|
|
|
|
|
|
|
ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
|
|
|
|
|
2005-06-06 22:39:32 +00:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2005-04-21 06:02:45 +00:00
|
|
|
#include "asterisk/lock.h"
|
|
|
|
#include "asterisk/file.h"
|
|
|
|
#include "asterisk/logger.h"
|
|
|
|
#include "asterisk/channel.h"
|
|
|
|
#include "asterisk/pbx.h"
|
|
|
|
#include "asterisk/module.h"
|
|
|
|
#include "asterisk/config.h"
|
|
|
|
#include "asterisk/say.h"
|
|
|
|
#include "asterisk/utils.h"
|
2005-11-30 20:09:58 +00:00
|
|
|
#include "asterisk/app.h"
|
1999-10-30 01:01:34 +00:00
|
|
|
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include "asterisk/res_odbc.h"
|
|
|
|
|
|
|
|
static char odbc_database[80] = "asterisk";
|
|
|
|
static char odbc_table[80] = "voicemessages";
|
|
|
|
static char vmfmts[80] = "wav";
|
|
|
|
#endif
|
|
|
|
|
1999-10-30 01:01:34 +00:00
|
|
|
static char *app = "Directory";
|
|
|
|
|
2001-04-10 17:18:04 +00:00
|
|
|
static char *synopsis = "Provide directory of voicemail extensions";
|
|
|
|
static char *descrip =
|
2005-11-11 15:52:55 +00:00
|
|
|
" Directory(vm-context[|dial-context[|options]]): This application will present\n"
|
|
|
|
"the calling channel with a directory of extensions from which they can search\n"
|
|
|
|
"by name. The list of names and corresponding extensions is retrieved from the\n"
|
|
|
|
"voicemail configuration file, voicemail.conf.\n"
|
2006-05-30 16:01:50 +00:00
|
|
|
" This application will immediately exit if one of the following DTMF digits are\n"
|
2005-11-11 15:52:55 +00:00
|
|
|
"received and the extension to jump to exists:\n"
|
|
|
|
" 0 - Jump to the 'o' extension, if it exists.\n"
|
|
|
|
" * - Jump to the 'a' extension, if it exists.\n\n"
|
|
|
|
" Parameters:\n"
|
|
|
|
" vm-context - This is the context within voicemail.conf to use for the\n"
|
|
|
|
" Directory.\n"
|
|
|
|
" dial-context - This is the dialplan context to use when looking for an\n"
|
|
|
|
" extension that the user has selected, or when jumping to the\n"
|
|
|
|
" 'o' or 'a' extension.\n\n"
|
|
|
|
" Options:\n"
|
2006-04-11 15:38:17 +00:00
|
|
|
" e - In addition to the name, also read the extension number to the\n"
|
|
|
|
" caller before presenting dialing options.\n"
|
2005-11-11 15:52:55 +00:00
|
|
|
" f - Allow the caller to enter the first name of a user in the directory\n"
|
2006-04-11 15:38:17 +00:00
|
|
|
" instead of using the last name.\n";
|
2001-04-10 17:18:04 +00:00
|
|
|
|
1999-10-30 01:01:34 +00:00
|
|
|
/* For simplicity, I'm keeping the format compatible with the voicemail config,
|
|
|
|
but i'm open to suggestions for isolating it */
|
|
|
|
|
2005-04-06 18:55:33 +00:00
|
|
|
#define VOICEMAIL_CONFIG "voicemail.conf"
|
1999-10-30 01:01:34 +00:00
|
|
|
|
|
|
|
/* How many digits to read in */
|
|
|
|
#define NUMDIGITS 3
|
|
|
|
|
|
|
|
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
static void retrieve_file(char *dir)
|
|
|
|
{
|
|
|
|
int x = 0;
|
|
|
|
int res;
|
|
|
|
int fd=-1;
|
|
|
|
size_t fdlen = 0;
|
|
|
|
void *fdm=NULL;
|
|
|
|
SQLHSTMT stmt;
|
|
|
|
char sql[256];
|
|
|
|
char fmt[80]="";
|
|
|
|
char *c;
|
|
|
|
SQLLEN colsize;
|
|
|
|
char full_fn[256];
|
|
|
|
|
|
|
|
odbc_obj *obj;
|
|
|
|
obj = fetch_odbc_obj(odbc_database, 0);
|
|
|
|
if (obj) {
|
|
|
|
do {
|
|
|
|
ast_copy_string(fmt, vmfmts, sizeof(fmt));
|
|
|
|
c = strchr(fmt, '|');
|
|
|
|
if (c)
|
|
|
|
*c = '\0';
|
|
|
|
if (!strcasecmp(fmt, "wav49"))
|
|
|
|
strcpy(fmt, "WAV");
|
|
|
|
snprintf(full_fn, sizeof(full_fn), "%s.%s", dir, fmt);
|
|
|
|
res = SQLAllocHandle(SQL_HANDLE_STMT, obj->con, &stmt);
|
|
|
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
|
|
ast_log(LOG_WARNING, "SQL Alloc Handle failed!\n");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
snprintf(sql, sizeof(sql), "SELECT recording FROM %s WHERE dir=? AND msgnum=-1", odbc_table);
|
|
|
|
res = SQLPrepare(stmt, (unsigned char *)sql, SQL_NTS);
|
|
|
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
|
|
ast_log(LOG_WARNING, "SQL Prepare failed![%s]\n", sql);
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
SQLBindParameter(stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, strlen(dir), 0, (void *)dir, 0, NULL);
|
|
|
|
res = odbc_smart_execute(obj, stmt);
|
|
|
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
|
|
ast_log(LOG_WARNING, "SQL Execute error!\n[%s]\n\n", sql);
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = SQLFetch(stmt);
|
|
|
|
if (res == SQL_NO_DATA) {
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
} else if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
|
|
ast_log(LOG_WARNING, "SQL Fetch error!\n[%s]\n\n", sql);
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fd = open(full_fn, O_RDWR | O_CREAT | O_TRUNC, 0770);
|
|
|
|
if (fd < 0) {
|
|
|
|
ast_log(LOG_WARNING, "Failed to write '%s': %s\n", full_fn, strerror(errno));
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
res = SQLGetData(stmt, 1, SQL_BINARY, NULL, 0, &colsize);
|
|
|
|
fdlen = colsize;
|
|
|
|
if (fd > -1) {
|
|
|
|
char tmp[1]="";
|
|
|
|
lseek(fd, fdlen - 1, SEEK_SET);
|
|
|
|
if (write(fd, tmp, 1) != 1) {
|
|
|
|
close(fd);
|
|
|
|
fd = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (fd > -1)
|
|
|
|
fdm = mmap(NULL, fdlen, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
|
|
|
|
}
|
|
|
|
if (fdm) {
|
|
|
|
memset(fdm, 0, fdlen);
|
|
|
|
res = SQLGetData(stmt, x + 1, SQL_BINARY, fdm, fdlen, &colsize);
|
|
|
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
|
|
|
ast_log(LOG_WARNING, "SQL Get Data error!\n[%s]\n\n", sql);
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
|
|
|
} while (0);
|
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Failed to obtain database object for '%s'!\n", odbc_database);
|
|
|
|
if (fdm)
|
|
|
|
munmap(fdm, fdlen);
|
|
|
|
if (fd > -1)
|
|
|
|
close(fd);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-09-20 20:40:39 +00:00
|
|
|
static char *convert(const char *lastname)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
|
|
|
char *tmp;
|
|
|
|
int lcount = 0;
|
2006-01-11 22:41:34 +00:00
|
|
|
tmp = ast_malloc(NUMDIGITS + 1);
|
1999-10-30 01:01:34 +00:00
|
|
|
if (tmp) {
|
|
|
|
while((*lastname > 32) && lcount < NUMDIGITS) {
|
|
|
|
switch(toupper(*lastname)) {
|
|
|
|
case '1':
|
|
|
|
tmp[lcount++] = '1';
|
|
|
|
break;
|
|
|
|
case '2':
|
|
|
|
case 'A':
|
|
|
|
case 'B':
|
|
|
|
case 'C':
|
|
|
|
tmp[lcount++] = '2';
|
|
|
|
break;
|
|
|
|
case '3':
|
|
|
|
case 'D':
|
|
|
|
case 'E':
|
|
|
|
case 'F':
|
|
|
|
tmp[lcount++] = '3';
|
|
|
|
break;
|
|
|
|
case '4':
|
|
|
|
case 'G':
|
|
|
|
case 'H':
|
|
|
|
case 'I':
|
|
|
|
tmp[lcount++] = '4';
|
|
|
|
break;
|
|
|
|
case '5':
|
|
|
|
case 'J':
|
|
|
|
case 'K':
|
|
|
|
case 'L':
|
|
|
|
tmp[lcount++] = '5';
|
|
|
|
break;
|
|
|
|
case '6':
|
|
|
|
case 'M':
|
|
|
|
case 'N':
|
|
|
|
case 'O':
|
|
|
|
tmp[lcount++] = '6';
|
|
|
|
break;
|
|
|
|
case '7':
|
|
|
|
case 'P':
|
|
|
|
case 'Q':
|
|
|
|
case 'R':
|
|
|
|
case 'S':
|
|
|
|
tmp[lcount++] = '7';
|
|
|
|
break;
|
|
|
|
case '8':
|
|
|
|
case 'T':
|
|
|
|
case 'U':
|
|
|
|
case 'V':
|
|
|
|
tmp[lcount++] = '8';
|
|
|
|
break;
|
|
|
|
case '9':
|
|
|
|
case 'W':
|
|
|
|
case 'X':
|
|
|
|
case 'Y':
|
|
|
|
case 'Z':
|
|
|
|
tmp[lcount++] = '9';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
lastname++;
|
|
|
|
}
|
|
|
|
tmp[lcount] = '\0';
|
|
|
|
}
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
2004-06-22 03:43:41 +00:00
|
|
|
/* play name of mailbox owner.
|
|
|
|
* returns: -1 for bad or missing extension
|
|
|
|
* '1' for selected entry from directory
|
|
|
|
* '*' for skipped entry from directory
|
|
|
|
*/
|
2006-04-28 06:40:40 +00:00
|
|
|
static int play_mailbox_owner(struct ast_channel *chan, char *context,
|
2006-08-19 00:53:54 +00:00
|
|
|
char *dialcontext, char *ext, char *name, int readext,
|
|
|
|
int fromappvm)
|
2006-04-28 06:40:40 +00:00
|
|
|
{
|
2004-06-22 03:43:41 +00:00
|
|
|
int res = 0;
|
2006-04-28 06:40:40 +00:00
|
|
|
int loop;
|
2004-06-22 03:43:41 +00:00
|
|
|
char fn[256];
|
|
|
|
|
|
|
|
/* Check for the VoiceMail2 greeting first */
|
|
|
|
snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet",
|
2006-04-28 06:40:40 +00:00
|
|
|
ast_config_AST_SPOOL_DIR, context, ext);
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
retrieve_file(fn);
|
|
|
|
#endif
|
2004-06-22 03:43:41 +00:00
|
|
|
|
2006-04-28 06:40:40 +00:00
|
|
|
if (ast_fileexists(fn, NULL, chan->language) <= 0) {
|
|
|
|
/* no file, check for an old-style Voicemail greeting */
|
|
|
|
snprintf(fn, sizeof(fn), "%s/vm/%s/greet",
|
|
|
|
ast_config_AST_SPOOL_DIR, ext);
|
|
|
|
}
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
retrieve_file(fn2);
|
|
|
|
#endif
|
2004-06-22 03:43:41 +00:00
|
|
|
|
|
|
|
if (ast_fileexists(fn, NULL, chan->language) > 0) {
|
2006-11-17 23:18:51 +00:00
|
|
|
res = ast_stream_and_wait(chan, fn, AST_DIGIT_ANY);
|
2004-06-22 03:43:41 +00:00
|
|
|
ast_stopstream(chan);
|
2006-04-11 15:38:17 +00:00
|
|
|
/* If Option 'e' was specified, also read the extension number with the name */
|
|
|
|
if (readext) {
|
2006-11-17 23:18:51 +00:00
|
|
|
ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
|
2006-04-11 15:38:17 +00:00
|
|
|
res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
|
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
} else {
|
2006-04-21 20:57:29 +00:00
|
|
|
res = ast_say_character_str(chan, S_OR(name, ext), AST_DIGIT_ANY, chan->language);
|
2006-04-11 15:38:17 +00:00
|
|
|
if (!ast_strlen_zero(name) && readext) {
|
2006-11-17 23:18:51 +00:00
|
|
|
ast_stream_and_wait(chan, "vm-extension", AST_DIGIT_ANY);
|
2006-04-11 15:38:17 +00:00
|
|
|
res = ast_say_character_str(chan, ext, AST_DIGIT_ANY, chan->language);
|
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
}
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
ast_filedelete(fn, NULL);
|
|
|
|
ast_filedelete(fn2, NULL);
|
|
|
|
#endif
|
2004-06-22 03:43:41 +00:00
|
|
|
|
2006-04-28 06:40:40 +00:00
|
|
|
for (loop = 3 ; loop > 0; loop--) {
|
2006-04-14 22:32:13 +00:00
|
|
|
if (!res)
|
2006-11-17 23:18:51 +00:00
|
|
|
res = ast_stream_and_wait(chan, "dir-instr", AST_DIGIT_ANY);
|
2006-04-14 22:32:13 +00:00
|
|
|
if (!res)
|
2004-06-22 03:43:41 +00:00
|
|
|
res = ast_waitfordigit(chan, 3000);
|
|
|
|
ast_stopstream(chan);
|
|
|
|
|
2006-04-28 06:40:40 +00:00
|
|
|
if (res < 0) /* User hungup, so jump out now */
|
|
|
|
break;
|
|
|
|
if (res == '1') { /* Name selected */
|
2006-08-19 00:53:54 +00:00
|
|
|
if (fromappvm) {
|
|
|
|
/* We still want to set the exten though */
|
|
|
|
ast_copy_string(chan->exten, ext, sizeof(chan->exten));
|
|
|
|
} else {
|
|
|
|
if (ast_goto_if_exists(chan, dialcontext, ext, 1)) {
|
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Can't find extension '%s' in context '%s'. "
|
|
|
|
"Did you pass the wrong context to Directory?\n",
|
|
|
|
ext, dialcontext);
|
|
|
|
res = -1;
|
|
|
|
}
|
2006-04-28 06:40:40 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-06-28 15:08:39 +00:00
|
|
|
}
|
2006-04-28 06:40:40 +00:00
|
|
|
if (res == '*') /* Skip to next match in list */
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* Not '1', or '*', so decrement number of tries */
|
|
|
|
res = 0;
|
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
|
|
|
|
return(res);
|
|
|
|
}
|
|
|
|
|
2005-03-03 05:31:43 +00:00
|
|
|
static struct ast_config *realtime_directory(char *context)
|
|
|
|
{
|
2005-04-06 18:55:33 +00:00
|
|
|
struct ast_config *cfg;
|
|
|
|
struct ast_config *rtdata;
|
|
|
|
struct ast_category *cat;
|
|
|
|
struct ast_variable *var;
|
|
|
|
char *mailbox;
|
2006-09-20 20:40:39 +00:00
|
|
|
const char *fullname;
|
|
|
|
const char *hidefromdir;
|
2005-04-06 18:55:33 +00:00
|
|
|
char tmp[100];
|
2005-03-03 05:31:43 +00:00
|
|
|
|
|
|
|
/* Load flat file config. */
|
2005-04-06 18:55:33 +00:00
|
|
|
cfg = ast_config_load(VOICEMAIL_CONFIG);
|
2005-03-03 05:31:43 +00:00
|
|
|
|
|
|
|
if (!cfg) {
|
2005-04-06 18:55:33 +00:00
|
|
|
/* Loading config failed. */
|
|
|
|
ast_log(LOG_WARNING, "Loading config failed.\n");
|
2005-03-03 05:31:43 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2005-04-06 18:55:33 +00:00
|
|
|
/* Get realtime entries, categorized by their mailbox number
|
|
|
|
and present in the requested context */
|
|
|
|
rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);
|
2005-03-03 05:31:43 +00:00
|
|
|
|
2005-04-06 18:55:33 +00:00
|
|
|
/* if there are no results, just return the entries from the config file */
|
|
|
|
if (!rtdata)
|
2005-03-03 05:31:43 +00:00
|
|
|
return cfg;
|
|
|
|
|
2005-04-06 18:55:33 +00:00
|
|
|
/* Does the context exist within the config file? If not, make one */
|
|
|
|
cat = ast_category_get(cfg, context);
|
|
|
|
if (!cat) {
|
2005-03-03 05:31:43 +00:00
|
|
|
cat = ast_category_new(context);
|
|
|
|
if (!cat) {
|
2005-04-06 18:55:33 +00:00
|
|
|
ast_log(LOG_WARNING, "Out of memory\n");
|
2005-03-03 05:31:43 +00:00
|
|
|
ast_config_destroy(cfg);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
ast_category_append(cfg, cat);
|
|
|
|
}
|
|
|
|
|
2006-04-14 22:32:13 +00:00
|
|
|
mailbox = NULL;
|
|
|
|
while ( (mailbox = ast_category_browse(rtdata, mailbox)) ) {
|
2005-04-06 18:55:33 +00:00
|
|
|
fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
|
|
|
|
hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
|
|
|
|
snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
|
|
|
|
fullname ? fullname : "",
|
|
|
|
hidefromdir ? hidefromdir : "no");
|
|
|
|
var = ast_variable_new(mailbox, tmp);
|
|
|
|
if (var)
|
|
|
|
ast_variable_append(cat, var);
|
|
|
|
else
|
|
|
|
ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
|
2005-03-03 05:31:43 +00:00
|
|
|
}
|
2005-04-06 18:55:33 +00:00
|
|
|
ast_config_destroy(rtdata);
|
2005-03-03 05:31:43 +00:00
|
|
|
|
|
|
|
return cfg;
|
|
|
|
}
|
|
|
|
|
2006-09-16 23:53:58 +00:00
|
|
|
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)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
|
|
|
/* Read in the first three digits.. "digit" is the first digit, already read */
|
2006-09-16 23:53:58 +00:00
|
|
|
char ext[NUMDIGITS + 1], *cat;
|
2004-05-03 04:36:46 +00:00
|
|
|
char name[80] = "";
|
1999-10-30 01:01:34 +00:00
|
|
|
struct ast_variable *v;
|
|
|
|
int res;
|
|
|
|
int found=0;
|
2004-06-22 03:43:41 +00:00
|
|
|
int lastuserchoice = 0;
|
2006-09-20 20:40:39 +00:00
|
|
|
char *start, *conv, *stringp = NULL;
|
|
|
|
const char *pos;
|
2004-06-22 03:43:41 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(context)) {
|
2004-06-22 03:43:41 +00:00
|
|
|
ast_log(LOG_WARNING,
|
|
|
|
"Directory must be called with an argument "
|
|
|
|
"(context in which to interpret extensions)\n");
|
2003-03-26 21:09:56 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2004-12-08 21:24:00 +00:00
|
|
|
if (digit == '0') {
|
2006-09-17 14:00:39 +00:00
|
|
|
if (!ast_goto_if_exists(chan, dialcontext, "o", 1) ||
|
2005-09-15 00:56:09 +00:00
|
|
|
(!ast_strlen_zero(chan->macrocontext) &&
|
2005-09-15 01:31:49 +00:00
|
|
|
!ast_goto_if_exists(chan, chan->macrocontext, "o", 1))) {
|
2004-12-08 21:24:00 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Can't find extension 'o' in current context. "
|
|
|
|
"Not Exiting the Directory!\n");
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
}
|
2004-12-21 22:43:25 +00:00
|
|
|
if (digit == '*') {
|
2006-09-17 14:00:39 +00:00
|
|
|
if (!ast_goto_if_exists(chan, dialcontext, "a", 1) ||
|
2005-09-15 00:56:09 +00:00
|
|
|
(!ast_strlen_zero(chan->macrocontext) &&
|
2005-09-15 01:31:49 +00:00
|
|
|
!ast_goto_if_exists(chan, chan->macrocontext, "a", 1))) {
|
2004-12-21 22:43:25 +00:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
ast_log(LOG_WARNING, "Can't find extension 'a' in current context. "
|
|
|
|
"Not Exiting the Directory!\n");
|
|
|
|
res = 0;
|
|
|
|
}
|
|
|
|
}
|
1999-10-30 01:01:34 +00:00
|
|
|
memset(ext, 0, sizeof(ext));
|
|
|
|
ext[0] = digit;
|
2001-08-05 21:46:13 +00:00
|
|
|
res = 0;
|
2002-05-13 22:29:39 +00:00
|
|
|
if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1;
|
1999-10-30 01:01:34 +00:00
|
|
|
if (!res) {
|
|
|
|
/* Search for all names which start with those digits */
|
|
|
|
v = ast_variable_browse(cfg, context);
|
|
|
|
while(v && !res) {
|
|
|
|
/* Find all candidate extensions */
|
|
|
|
while(v) {
|
|
|
|
/* Find a candidate extension */
|
|
|
|
start = strdup(v->value);
|
2005-07-15 22:06:15 +00:00
|
|
|
if (start && !strcasestr(start, "hidefromdir=yes")) {
|
2003-01-30 15:03:20 +00:00
|
|
|
stringp=start;
|
|
|
|
strsep(&stringp, ",");
|
|
|
|
pos = strsep(&stringp, ",");
|
1999-10-30 01:01:34 +00:00
|
|
|
if (pos) {
|
2005-07-10 23:12:25 +00:00
|
|
|
ast_copy_string(name, pos, sizeof(name));
|
1999-10-30 01:01:34 +00:00
|
|
|
/* Grab the last name */
|
2004-08-05 22:02:33 +00:00
|
|
|
if (last && strrchr(pos,' '))
|
1999-10-30 01:01:34 +00:00
|
|
|
pos = strrchr(pos, ' ') + 1;
|
|
|
|
conv = convert(pos);
|
|
|
|
if (conv) {
|
|
|
|
if (!strcmp(conv, ext)) {
|
|
|
|
/* Match! */
|
|
|
|
found++;
|
|
|
|
free(conv);
|
|
|
|
free(start);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(conv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(start);
|
|
|
|
}
|
|
|
|
v = v->next;
|
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
|
1999-10-30 01:01:34 +00:00
|
|
|
if (v) {
|
|
|
|
/* We have a match -- play a greeting if they have it */
|
2006-08-19 00:53:54 +00:00
|
|
|
res = play_mailbox_owner(chan, context, dialcontext, v->name, name, readext, fromappvm);
|
2004-06-22 03:43:41 +00:00
|
|
|
switch (res) {
|
|
|
|
case -1:
|
2004-06-28 15:08:39 +00:00
|
|
|
/* user pressed '1' but extension does not exist, or
|
|
|
|
* user hungup
|
|
|
|
*/
|
2004-06-22 03:43:41 +00:00
|
|
|
lastuserchoice = 0;
|
1999-10-30 01:01:34 +00:00
|
|
|
break;
|
2004-06-22 03:43:41 +00:00
|
|
|
case '1':
|
2005-09-15 01:31:49 +00:00
|
|
|
/* user pressed '1' and extensions exists;
|
|
|
|
play_mailbox_owner will already have done
|
|
|
|
a goto() on the channel
|
|
|
|
*/
|
2004-06-22 03:43:41 +00:00
|
|
|
lastuserchoice = res;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
/* user pressed '*' to skip something found */
|
|
|
|
lastuserchoice = res;
|
1999-10-30 01:01:34 +00:00
|
|
|
res = 0;
|
2004-06-22 03:43:41 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
v = v->next;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
2004-06-22 03:43:41 +00:00
|
|
|
|
2006-09-16 23:53:58 +00:00
|
|
|
if (!res && ucfg) {
|
|
|
|
/* Search users.conf for all names which start with those digits */
|
|
|
|
for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) {
|
|
|
|
if (!strcasecmp(cat, "general"))
|
|
|
|
continue;
|
|
|
|
if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Find all candidate extensions */
|
|
|
|
if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) {
|
|
|
|
ast_copy_string(name, pos, sizeof(name));
|
|
|
|
/* Grab the last name */
|
|
|
|
if (last && strrchr(pos,' '))
|
|
|
|
pos = strrchr(pos, ' ') + 1;
|
|
|
|
conv = convert(pos);
|
|
|
|
if (conv) {
|
|
|
|
if (!strcmp(conv, ext)) {
|
|
|
|
/* Match! */
|
|
|
|
found++;
|
|
|
|
/* We have a match -- play a greeting if they have it */
|
|
|
|
res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext, fromappvm);
|
|
|
|
switch (res) {
|
|
|
|
case -1:
|
|
|
|
/* user pressed '1' but extension does not exist, or
|
|
|
|
* user hungup
|
|
|
|
*/
|
|
|
|
lastuserchoice = 0;
|
|
|
|
break;
|
|
|
|
case '1':
|
|
|
|
/* user pressed '1' and extensions exists;
|
|
|
|
play_mailbox_owner will already have done
|
|
|
|
a goto() on the channel
|
|
|
|
*/
|
|
|
|
lastuserchoice = res;
|
|
|
|
break;
|
|
|
|
case '*':
|
|
|
|
/* user pressed '*' to skip something found */
|
|
|
|
lastuserchoice = res;
|
|
|
|
res = 0;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(conv);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
free(conv);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-22 03:43:41 +00:00
|
|
|
if (lastuserchoice != '1') {
|
2006-04-14 22:32:13 +00:00
|
|
|
res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language);
|
2004-06-22 03:43:41 +00:00
|
|
|
if (!res)
|
|
|
|
res = 1;
|
|
|
|
return res;
|
|
|
|
}
|
2004-06-23 00:06:46 +00:00
|
|
|
return 0;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int directory_exec(struct ast_channel *chan, void *data)
|
|
|
|
{
|
|
|
|
int res = 0;
|
2006-08-21 02:11:39 +00:00
|
|
|
struct ast_module_user *u;
|
2006-09-16 23:53:58 +00:00
|
|
|
struct ast_config *cfg, *ucfg;
|
2004-08-05 22:02:33 +00:00
|
|
|
int last = 1;
|
2006-04-11 15:38:17 +00:00
|
|
|
int readext = 0;
|
2006-08-19 00:53:54 +00:00
|
|
|
int fromappvm = 0;
|
2006-09-20 20:40:39 +00:00
|
|
|
const char *dirintro;
|
|
|
|
char *parse;
|
2005-11-30 20:09:58 +00:00
|
|
|
AST_DECLARE_APP_ARGS(args,
|
|
|
|
AST_APP_ARG(vmcontext);
|
|
|
|
AST_APP_ARG(dialcontext);
|
|
|
|
AST_APP_ARG(options);
|
|
|
|
);
|
2004-08-05 22:02:33 +00:00
|
|
|
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(data)) {
|
2005-10-04 22:44:15 +00:00
|
|
|
ast_log(LOG_WARNING, "Directory requires an argument (context[,dialcontext])\n");
|
1999-10-30 01:01:34 +00:00
|
|
|
return -1;
|
|
|
|
}
|
2005-03-03 05:31:43 +00:00
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
u = ast_module_user_add(chan);
|
2005-10-19 18:19:02 +00:00
|
|
|
|
2006-05-10 13:22:15 +00:00
|
|
|
parse = ast_strdupa(data);
|
2006-01-21 17:50:04 +00:00
|
|
|
|
2005-11-30 20:09:58 +00:00
|
|
|
AST_STANDARD_APP_ARGS(args, parse);
|
|
|
|
|
|
|
|
if (args.options) {
|
|
|
|
if (strchr(args.options, 'f'))
|
|
|
|
last = 0;
|
2006-04-11 15:38:17 +00:00
|
|
|
if (strchr(args.options, 'e'))
|
|
|
|
readext = 1;
|
2006-08-19 00:53:54 +00:00
|
|
|
if (strchr(args.options, 'v'))
|
|
|
|
fromappvm = 1;
|
2005-11-30 20:09:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ast_strlen_zero(args.dialcontext))
|
|
|
|
args.dialcontext = args.vmcontext;
|
2005-03-03 05:31:43 +00:00
|
|
|
|
2005-11-30 20:09:58 +00:00
|
|
|
cfg = realtime_directory(args.vmcontext);
|
2005-10-19 18:19:02 +00:00
|
|
|
if (!cfg) {
|
2005-11-30 20:09:58 +00:00
|
|
|
ast_log(LOG_ERROR, "Unable to read the configuration data!\n");
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
2005-03-03 05:31:43 +00:00
|
|
|
return -1;
|
2005-10-19 18:19:02 +00:00
|
|
|
}
|
2006-09-16 23:53:58 +00:00
|
|
|
|
|
|
|
ucfg = ast_config_load("users.conf");
|
2005-03-03 05:31:43 +00:00
|
|
|
|
2005-11-30 20:09:58 +00:00
|
|
|
dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
|
2005-10-26 19:48:14 +00:00
|
|
|
if (ast_strlen_zero(dirintro))
|
2004-04-29 13:53:38 +00:00
|
|
|
dirintro = ast_variable_retrieve(cfg, "general", "directoryintro");
|
2006-04-14 22:32:13 +00:00
|
|
|
if (ast_strlen_zero(dirintro))
|
|
|
|
dirintro = last ? "dir-intro" : "dir-intro-fn";
|
2005-10-04 22:44:15 +00:00
|
|
|
|
2003-11-09 06:16:07 +00:00
|
|
|
if (chan->_state != AST_STATE_UP)
|
|
|
|
res = ast_answer(chan);
|
2005-10-04 22:44:15 +00:00
|
|
|
|
|
|
|
for (;;) {
|
|
|
|
if (!res)
|
2006-11-17 23:18:51 +00:00
|
|
|
res = ast_stream_and_wait(chan, dirintro, AST_DIGIT_ANY);
|
2005-10-04 22:44:15 +00:00
|
|
|
ast_stopstream(chan);
|
|
|
|
if (!res)
|
|
|
|
res = ast_waitfordigit(chan, 5000);
|
|
|
|
if (res > 0) {
|
2006-09-16 23:53:58 +00:00
|
|
|
res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, last, readext, fromappvm);
|
2005-10-04 22:44:15 +00:00
|
|
|
if (res > 0) {
|
|
|
|
res = ast_waitstream(chan, AST_DIGIT_ANY);
|
|
|
|
ast_stopstream(chan);
|
2006-04-14 22:32:13 +00:00
|
|
|
if (res >= 0)
|
2005-10-04 22:44:15 +00:00
|
|
|
continue;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
}
|
2005-10-04 22:44:15 +00:00
|
|
|
break;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
2006-09-16 23:53:58 +00:00
|
|
|
if (ucfg)
|
|
|
|
ast_config_destroy(ucfg);
|
2005-01-25 06:10:20 +00:00
|
|
|
ast_config_destroy(cfg);
|
2006-08-21 02:11:39 +00:00
|
|
|
ast_module_user_remove(u);
|
1999-10-30 01:01:34 +00:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int unload_module(void)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
2005-10-18 22:52:21 +00:00
|
|
|
int res;
|
|
|
|
res = ast_unregister_application(app);
|
|
|
|
return res;
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
static int load_module(void)
|
1999-10-30 01:01:34 +00:00
|
|
|
{
|
2006-06-30 14:10:53 +00:00
|
|
|
#ifdef USE_ODBC_STORAGE
|
|
|
|
struct ast_config *cfg = ast_config_load(VOICEMAIL_CONFIG);
|
|
|
|
char *tmp;
|
|
|
|
|
|
|
|
if (cfg) {
|
|
|
|
if ((tmp = ast_variable_retrieve(cfg, "general", "odbcstorage"))) {
|
|
|
|
ast_copy_string(odbc_database, tmp, sizeof(odbc_database));
|
|
|
|
}
|
|
|
|
if ((tmp = ast_variable_retrieve(cfg, "general", "odbctable"))) {
|
|
|
|
ast_copy_string(odbc_table, tmp, sizeof(odbc_table));
|
|
|
|
}
|
|
|
|
if ((tmp = ast_variable_retrieve(cfg, "general", "format"))) {
|
|
|
|
ast_copy_string(vmfmts, tmp, sizeof(vmfmts));
|
|
|
|
}
|
|
|
|
ast_config_destroy(cfg);
|
|
|
|
} else
|
|
|
|
ast_log(LOG_WARNING, "Unable to load " VOICEMAIL_CONFIG " - ODBC defaults will be used\n");
|
|
|
|
#endif
|
|
|
|
|
2001-04-10 17:18:04 +00:00
|
|
|
return ast_register_application(app, directory_exec, synopsis, descrip);
|
1999-10-30 01:01:34 +00:00
|
|
|
}
|
|
|
|
|
2006-08-21 02:11:39 +00:00
|
|
|
AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Extension Directory");
|