[Asterisk-cvs] asterisk/apps app_directory.c,1.25,1.26

markster at lists.digium.com markster at lists.digium.com
Thu Aug 5 18:16:33 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory localhost.localdomain:/tmp/cvs-serv20624/apps

Modified Files:
	app_directory.c 
Log Message:
Allow directory to be searched by first name (bug #2208)


Index: app_directory.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- app_directory.c	28 Jun 2004 15:08:39 -0000	1.25
+++ app_directory.c	5 Aug 2004 22:02:33 -0000	1.26
@@ -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[|options]]): 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' option 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 */
@@ -208,7 +210,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, int last)
 {
 	/* Read in the first three digits..  "digit" is the first digit, already read */
 	char ext[NUMDIGITS + 1];
@@ -225,7 +227,6 @@
 			"(context in which to interpret extensions)\n");
 		return -1;
 	}
-
 	memset(ext, 0, sizeof(ext));
 	ext[0] = digit;
 	res = 0;
@@ -245,7 +246,7 @@
 					if (pos) {
 						strncpy(name, pos, sizeof(name) - 1);
 						/* Grab the last name */
-						if (strrchr(pos, ' '))
+						if (last && strrchr(pos,' '))
 							pos = strrchr(pos, ' ') + 1;
 						conv = convert(pos);
 						if (conv) {
@@ -312,7 +313,9 @@
 	int res = 0;
 	struct localuser *u;
 	struct ast_config *cfg;
-	char *context, *dialcontext, *dirintro;
+	int last = 1;
+	char *context, *dialcontext, *dirintro, *options;
+
 	if (!data) {
 		ast_log(LOG_WARNING, "directory requires an argument (context[,dialcontext])\n");
 		return -1;
@@ -329,13 +332,24 @@
 	if (dialcontext) {
 		*dialcontext = '\0';
 		dialcontext++;
-	} else
+		options = strchr(dialcontext, '|');
+		if (options) {
+			*options = '\0';
+			options++; 
+			if (strchr(options, 'f'))
+				last = 0;
+		}
+	} 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)
+			dirintro = "dir-intro";	
+		else
+			dirintro = "dir-intro-fn";
+	}
 	if (chan->_state != AST_STATE_UP) 
 		res = ast_answer(chan);
 	if (!res)
@@ -346,7 +360,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, last);
 		if (res > 0) {
 			res = ast_waitstream(chan, AST_DIGIT_ANY);
 			ast_stopstream(chan);




More information about the svn-commits mailing list