Index: apps/app_directory.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v retrieving revision 1.25 diff -u -r1.25 app_directory.c --- apps/app_directory.c 28 Jun 2004 15:08:39 -0000 1.25 +++ apps/app_directory.c 2 Aug 2004 22:44:29 -0000 @@ -32,13 +32,15 @@ static char *synopsis = "Provide directory of voicemail extensions"; static char *descrip = -" Directory(vm-context[|dial-context]): Presents the user with a directory\n" +" Directory(vm-context[|dial-context[|f]]): Presents the user with a directory\n" "of extensions from which they may select by name. The list of names \n" "and extensions is discovered from voicemail.conf. The vm-context argument\n" "is required, and specifies the context of voicemail.conf to use. The\n" "dial-context is the context to use for dialing the users, and defaults to\n" -"the vm-context if unspecified. Returns 0 unless the user hangs up. It also\n" -"sets up the channel on exit to enter the extension the user selected.\n"; +"the vm-context if unspecified. The 'f' flag causes the directory to match\n" +" based on the first name in voicemail.conf instead of the last name.\n" +"Returns 0 unless the user hangs up. It also sets up the channel on exit\n" +"to enter the extension the user selected.\n"; /* For simplicity, I'm keeping the format compatible with the voicemail config, but i'm open to suggestions for isolating it */ @@ -52,6 +54,8 @@ LOCAL_USER_DECL; +static int last = 1; + static char *convert(char *lastname) { char *tmp; @@ -208,7 +212,7 @@ return(res); } -static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit) +static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit, char *wname) { /* Read in the first three digits.. "digit" is the first digit, already read */ char ext[NUMDIGITS + 1]; @@ -225,7 +229,6 @@ "(context in which to interpret extensions)\n"); return -1; } - memset(ext, 0, sizeof(ext)); ext[0] = digit; res = 0; @@ -245,7 +248,8 @@ if (pos) { strncpy(name, pos, sizeof(name) - 1); /* Grab the last name */ - if (strrchr(pos, ' ')) + if (last && strrchr(pos,' ')) + /* if (strrchr(pos, ' ')) */ pos = strrchr(pos, ' ') + 1; conv = convert(pos); if (conv) { @@ -312,7 +316,8 @@ int res = 0; struct localuser *u; struct ast_config *cfg; - char *context, *dialcontext, *dirintro; + char *context, *dialcontext, *dirintro, *wname; + if (!data) { ast_log(LOG_WARNING, "directory requires an argument (context[,dialcontext])\n"); return -1; @@ -326,16 +331,30 @@ top: context = ast_strdupa(data); dialcontext = strchr(context, '|'); + wname = '\0'; if (dialcontext) { *dialcontext = '\0'; dialcontext++; - } else + wname = strchr(dialcontext, '|'); + if (wname) { + *wname = '\0'; + wname++; + if (!strcasecmp(wname, "f")) + last = 0; + else + last = 1; + } + } else dialcontext = context; dirintro = ast_variable_retrieve(cfg, context, "directoryintro"); if (!dirintro || ast_strlen_zero(dirintro)) dirintro = ast_variable_retrieve(cfg, "general", "directoryintro"); - if (!dirintro || ast_strlen_zero(dirintro)) - dirintro = "dir-intro"; + if (!dirintro || ast_strlen_zero(dirintro)) { + if (last == 1) + dirintro = "dir-intro-ln"; + else + dirintro = "dir-intro-fn"; + } if (chan->_state != AST_STATE_UP) res = ast_answer(chan); if (!res) @@ -346,7 +365,7 @@ if (!res) res = ast_waitfordigit(chan, 5000); if (res > 0) { - res = do_directory(chan, cfg, context, dialcontext, res); + res = do_directory(chan, cfg, context, dialcontext, res, wname); if (res > 0) { res = ast_waitstream(chan, AST_DIGIT_ANY); ast_stopstream(chan);