Index: app_directory.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v retrieving revision 1.14 diff -u -r1.14 app_directory.c --- app_directory.c 9 Nov 2003 06:16:07 -0000 1.14 +++ app_directory.c 7 Dec 2003 19:22:19 -0000 @@ -31,13 +31,16 @@ static char *app = "Directory"; static char *synopsis = "Provide directory of voicemail extensions"; -static char *descrip = -" Directory(context): Presents the user with a directory of extensions from\n" -"which they may select by name. The list of names and extensions is\n" -"discovered from voicemail.conf. The context argument is required, and\n" -"specifies the context in which to interpret the extensions. Returns 0\n" -"unless the user hangs up. It also sets up the channel on exit to enter the\n" -"extension the user selected.\n"; +static char *descrip = +" Directory(vm-context,ext-context): Presents the user with a directory of\n" +"extensions from which they may select by name. The list of names and\n" +"extensions is discovered from voicemail.conf. The voicemail context argument\n" +"is required, and specifies the voicemail context that the user is queried\n" +"from. Extension context is the context in which the extension will be\n" +"executed. If this is not supplied, it is assumed that the voicemail\n" +"context is also the extension context. Returns 0 unless the user hangs up.\n" +"It also sets up the channel on exit to enter the extension the user\n" +"selected.\n"; /* For simplicity, I'm keeping the format compatible with the voicemail config, but i'm open to suggestions for isolating it */ @@ -120,7 +123,7 @@ return tmp; } -static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char digit) +static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context,char *to_context, char digit) { /* Read in the first three digits.. "digit" is the first digit, already read */ char ext[NUMDIGITS + 1]; @@ -129,9 +132,10 @@ int found=0; char *start, *pos, *conv,*stringp=NULL; char fn[256]; - char fn2[256]; - if (!context || !strlen(context)) { - ast_log(LOG_WARNING, "Directory must be called with an argument (context in which to interpret extensions)\n"); + + if ( (!context||!strlen(context)) || (!to_context || !strlen(to_context)) ) + { + ast_log(LOG_WARNING, "Directory must be called with two arguments (voicemail context,dialplan context)\n"); return -1; } memset(ext, 0, sizeof(ext)); @@ -174,18 +178,11 @@ /* We have a match -- play a greeting if they have it */ /* Check for the VoiceMail2 greeting first */ snprintf(fn, sizeof(fn), "%s/voicemail/%s/%s/greet", (char *)ast_config_AST_SPOOL_DIR, context, v->name); - /* Otherwise, check for an old-style Voicemail greeting */ - snprintf(fn2, sizeof(fn2), "%s/vm/%s/greet", (char *)ast_config_AST_SPOOL_DIR, v->name); if (ast_fileexists(fn, NULL, chan->language) > 0) { res = ast_streamfile(chan, fn, chan->language); if (!res) res = ast_waitstream(chan, AST_DIGIT_ANY); ast_stopstream(chan); - } else if (ast_fileexists(fn2, NULL, chan->language) > 0) { - res = ast_streamfile(chan, fn2, chan->language); - if (!res) - res = ast_waitstream(chan, AST_DIGIT_ANY); - ast_stopstream(chan); } else { res = ast_say_digit_str(chan, v->name, AST_DIGIT_ANY, chan->language); } @@ -201,7 +198,7 @@ if (res == '1') { strncpy(chan->exten, v->name, sizeof(chan->exten)-1); chan->priority = 0; - strncpy(chan->context, context, sizeof(chan->context)-1); + strncpy(chan->context, to_context, sizeof(chan->context)-1); res = 0; break; } else if (res == '*') { @@ -232,6 +229,8 @@ int res = 0; struct localuser *u; struct ast_config *cfg; + char *tmp; + char *context, *to_context; if (!data) { ast_log(LOG_WARNING, "directory requires an argument (context)\n"); return -1; @@ -242,6 +241,29 @@ return -1; } LOCAL_USER_ADD(u); + + tmp = malloc(sizeof(char)*strlen(data)); + strncpy(tmp,data,strlen(data)+1); + context=strsep(&tmp,"|"); + to_context=strsep(&tmp,"\0"); + free(tmp); + + if(option_verbose > 3) + { + ast_log(LOG_WARNING,"context = %s\n",context); + ast_log(LOG_WARNING,"to_context = %s\n",to_context); + } + + if (!to_context) + { + // if no to context is specified, make both contexts equal. + to_context=context; + if(option_verbose > 3) + { + ast_log(LOG_WARNING,"to_context *NOW* = %s\n",to_context); + } + } + top: if (chan->_state != AST_STATE_UP) res = ast_answer(chan); @@ -253,7 +275,7 @@ if (!res) res = ast_waitfordigit(chan, 5000); if (res > 0) { - res = do_directory(chan, cfg, (char *)data, res); + res = do_directory(chan, cfg, (char *)context,(char *)to_context, res); if (res > 0) { res = ast_waitstream(chan, AST_DIGIT_ANY); ast_stopstream(chan);