[Asterisk-cvs] asterisk/apps app_directory.c,1.15,1.16

markster at lists.digium.com markster at lists.digium.com
Mon Apr 26 09:42:58 CDT 2004


Update of /usr/cvsroot/asterisk/apps
In directory mongoose.digium.com:/tmp/cvs-serv29220/apps

Modified Files:
	app_directory.c 
Log Message:
Allow two contexts to be specified for directory application (reimplementation fo bug #643)


Index: app_directory.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- app_directory.c	23 Mar 2004 05:32:36 -0000	1.15
+++ app_directory.c	26 Apr 2004 13:48:56 -0000	1.16
@@ -32,13 +32,13 @@
 
 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.  Please note that the context must be the same\n"
-"as the section in voicemail.conf that the mailbox is processed from as well.\n";
+"  Directory(vm-context[|dial-context]): 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";
 
 /* For simplicity, I'm keeping the format compatible with the voicemail config,
    but i'm open to suggestions for isolating it */
@@ -121,7 +121,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 *dialcontext, char digit)
 {
 	/* Read in the first three digits..  "digit" is the first digit, already read */
 	char ext[NUMDIGITS + 1];
@@ -200,10 +200,10 @@
 				ast_stopstream(chan);
 				if (res > -1) {
 					if (res == '1') {
-						if (ast_exists_extension(chan, context, v->name, 1, chan->callerid)) {
+						if (ast_exists_extension(chan, dialcontext, v->name, 1, chan->callerid)) {
 							strncpy(chan->exten, v->name, sizeof(chan->exten)-1);
 							chan->priority = 0;
-							strncpy(chan->context, context, sizeof(chan->context)-1);
+							strncpy(chan->context, dialcontext, sizeof(chan->context)-1);
 							res = 0;
 						} else {
 							ast_log(LOG_WARNING, "Can't find extension '%s' in context '%s'.  Did you pass the wrong context to Directory?\n", v->name, context);
@@ -238,6 +238,7 @@
 	int res = 0;
 	struct localuser *u;
 	struct ast_config *cfg;
+	char *context, *dialcontext;
 	if (!data) {
 		ast_log(LOG_WARNING, "directory requires an argument (context)\n");
 		return -1;
@@ -249,6 +250,13 @@
 	}
 	LOCAL_USER_ADD(u);
 top:
+	context = strdupa(data);
+	dialcontext = strchr(context, '|');
+	if (dialcontext) {
+		*dialcontext = '\0';
+		dialcontext++;
+	} else
+		dialcontext = context;
 	if (chan->_state != AST_STATE_UP) 
 		res = ast_answer(chan);
 	if (!res)
@@ -259,7 +267,7 @@
 	if (!res)
 		res = ast_waitfordigit(chan, 5000);
 	if (res > 0) {
-		res = do_directory(chan, cfg, (char *)data, res);
+		res = do_directory(chan, cfg, context, dialcontext, res);
 		if (res > 0) {
 			res = ast_waitstream(chan, AST_DIGIT_ANY);
 			ast_stopstream(chan);




More information about the svn-commits mailing list