When dialing a group of phones it is often desirable to have Asterisk
ignore any "302 Redirect" requests it might receive.

For example: after hours a business may want the general number to ring
multiple extensions so that anyone thats still around can answer it.
However, one of those people may have set their phone to call-forward to
their voicemail or cell phone.

The following patch applies against 1.0.9 and adds another option to the
Dial command.

"i" tells asterisk to ignore any 302 Redirects and continue on dialing
the rest of the extensions.

Brief example: phone at 2000 is set to forward.

extensions.conf:

exten => 2000,1,Dial(SIP/2000&SIP/2002,20,i)

CLI output:

    -- Executing Dial("SIP/2001-eece", "SIP/2000&SIP/2002|20|i") in new stack
    -- Called 2000
    -- Called 2002
    -- SIP/2002-d46a is ringing
    -- Got SIP response 302 "Moved Temporarily" back from 192.168.1.101
    -- Now forwarding SIP/2001-eece to 'Local/[EMAIL PROTECTED]' (thanks to 
SIP/2000-d08d)
    -- Forwarding SIP/2001-eece to 'Local/[EMAIL PROTECTED]' prevented by dial 
option 'i'
Nov  8 11:34:19 NOTICE[27509]: app_dial.c:240 wait_for_answer: Unable to create 
local channel for call forward to 'Local/[EMAIL PROTECTED]'
  == Spawn extension (from-sip, 2000, 1) exited non-zero on 'SIP/2001-eece'

-- 
John Lange
OpenIT ltd. www.Open-IT.ca (204) 885 0872
VoIP, Web services, Linux Consulting, Server Co-Location
--- asterisk-1.0.9/apps/app_dial.c	2005-05-11 20:43:36.000000000 -0500
+++ asterisk-1.0.9.modified/apps/app_dial.c	2005-11-08 11:46:11.000000000 -0600
@@ -59,6 +59,7 @@
 "  This application returns -1 if the originating channel hangs up, or if the\n"
 "call is bridged and either of the parties in the bridge terminate the call.\n"
 "The option string may contain zero or more of the following characters:\n"
+"      'i' -- Asterisk will ignore any 302 REDIRECT it gets from the phone.\n"
 "      't' -- allow the called user transfer the calling user by hitting #.\n"
 "      'T' -- allow the calling user to transfer the call by hitting #.\n"
 "      'f' -- Forces callerid to be set as the extension of the line \n"
@@ -106,6 +107,7 @@
 struct localuser {
 	struct ast_channel *chan;
 	int stillgoing;
+    int allowforward;
 	int allowredirect_in;
 	int allowredirect_out;
 	int ringbackonly;
@@ -228,8 +230,13 @@
 					/* Before processing channel, go ahead and check for forwarding */
 					if (option_verbose > 2)
 						ast_verbose(VERBOSE_PREFIX_3 "Now forwarding %s to '%s/%s' (thanks to %s)\n", in->name, tech, stuff, o->chan->name);
-					/* Setup parameters */
-					o->chan = ast_request(tech, in->nativeformats, stuff);
+                    if (!o->allowforward) {
+                        ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented by dial option 'i'\n", in->name, tech, stuff);
+                        o->chan = NULL;
+                    } else {
+					   /* Setup parameters */
+					   o->chan = ast_request(tech, in->nativeformats, stuff);
+                    }
 					if (!o->chan) {
 						ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
 						o->stillgoing = 0;
@@ -440,6 +447,7 @@
 	int allowdisconnect_in=0;
 	int allowdisconnect_out=0;
 	int noforwardhtml=0;
+    int allowforward=1;
 	int hasmacro = 0;
 	int privacy=0;
 	int announce=0;
@@ -722,6 +730,15 @@
 		}
 		memset(tmp, 0, sizeof(struct localuser));
 		if (transfer) {
+			if (strchr(transfer, 'i')) {
+				allowforward = tmp->allowforward = 0;
+    			if (option_verbose > 5)
+                    ast_verbose(VERBOSE_PREFIX_3 "Dial option prevent forwarding set 'On'\n");
+            } else {
+                allowforward = tmp->allowforward = 1;
+    			if (option_verbose > 5)
+                    ast_verbose(VERBOSE_PREFIX_3 "Dial option prevent forwarding set 'Off'\n");
+            }
 			if (strchr(transfer, 't'))
 				tmp->allowredirect_in = 1;
                         else    tmp->allowredirect_in = 0;
@@ -788,7 +805,11 @@
 				ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' (thanks to %s)\n", chan->name, tech, stuff, tmp->chan->name);
 			/* Setup parameters */
 			ast_hangup(tmp->chan);
-			tmp->chan = ast_request(tech, chan->nativeformats, stuff);
+            if (!tmp->allowforward) {
+                ast_verbose(VERBOSE_PREFIX_3 "Forwarding %s to '%s/%s' prevented by dial option 'i'\n", chan->name, tech, stuff);
+            } else {
+			    tmp->chan = ast_request(tech, chan->nativeformats, stuff);
+            }
 			if (!tmp->chan) {
 				ast_log(LOG_NOTICE, "Unable to create local channel for call forward to '%s/%s'\n", tech, stuff);
 				free(tmp);
_______________________________________________
Asterisk-Dev mailing list
Asterisk-Dev@lists.digium.com
http://lists.digium.com/mailman/listinfo/asterisk-dev
To UNSUBSCRIBE or update options visit:
   http://lists.digium.com/mailman/listinfo/asterisk-dev

Reply via email to