Revision
14645
Author
anthm
Date
2009-08-26 14:49:35 -0500 (Wed, 26 Aug 2009)

Log Message

add origination_cancel_key variable for a dtmf key that can abort an originating call

Modified Paths

Diff

Modified: freeswitch/trunk/src/switch_ivr_originate.c (14644 => 14645)


--- freeswitch/trunk/src/switch_ivr_originate.c	2009-08-26 17:42:36 UTC (rev 14644)
+++ freeswitch/trunk/src/switch_ivr_originate.c	2009-08-26 19:49:35 UTC (rev 14645)
@@ -618,6 +618,7 @@
 	int timelimit = 60;
 	const char *var;
 	switch_time_t start = 0;
+	const char *cancel_key = NULL;
 
 	switch_assert(peer_channel);
 	
@@ -643,6 +644,8 @@
 	start = switch_micro_time_now();
 
 	if (caller_channel) {
+		cancel_key = switch_channel_get_variable(caller_channel, "origination_cancel_key");
+
 		if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
 			ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback");
 		}
@@ -758,6 +761,18 @@
 		   && !(switch_channel_test_flag(peer_channel, CF_ANSWERED) || switch_channel_test_flag(peer_channel, CF_EARLY_MEDIA))) {
 		int diff = (int) (switch_micro_time_now() - start);
 
+		if (caller_channel && cancel_key) {
+			if (switch_channel_has_dtmf(caller_channel)) {
+				switch_dtmf_t dtmf = { 0, 0 };
+				if (switch_channel_dequeue_dtmf(caller_channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
+					if (dtmf.digit == *cancel_key) {
+						status = SWITCH_STATUS_FALSE;
+						goto done;
+					}
+				}
+			}
+		}
+
 		if (diff > timelimit) {
 			status = SWITCH_STATUS_TIMEOUT;
 			goto done;
@@ -929,7 +944,8 @@
 	originate_global_t oglobals = { 0 };
 	int cdr_total = 0;
 	int local_clobber = 0;
-	
+	const char *cancel_key = NULL;
+
 	oglobals.idx = IDX_NADA;
 	oglobals.early_ok = 1;
 	oglobals.session = session;
@@ -1103,6 +1119,7 @@
 
 	if (caller_channel) {		/* ringback is only useful when there is an originator */
 		ringback_data = NULL;
+		cancel_key = switch_channel_get_variable(caller_channel, "origination_cancel_key");
 
 		if (switch_channel_test_flag(caller_channel, CF_ANSWERED)) {
 			ringback_data = switch_channel_get_variable(caller_channel, "transfer_ringback");
@@ -1871,6 +1888,18 @@
 					switch_status_t tstatus = SWITCH_STATUS_SUCCESS;
 					int silence = 0;
 
+					if (caller_channel && cancel_key) {
+						if (switch_channel_has_dtmf(caller_channel)) {
+							switch_dtmf_t dtmf = { 0, 0 };
+							if (switch_channel_dequeue_dtmf(caller_channel, &dtmf) == SWITCH_STATUS_SUCCESS) {
+								if (dtmf.digit == *cancel_key) {
+									oglobals.idx = IDX_TIMEOUT;
+									goto notready;
+								}
+							}
+						}
+					}
+
 					if (switch_channel_media_ready(caller_channel)) {
 						tstatus = switch_core_session_read_frame(oglobals.session, &read_frame, SWITCH_IO_FLAG_NONE, 0);
 						if (!SWITCH_READ_ACCEPTABLE(tstatus)) {