[Freeswitch-svn] [commit] r7865 - in freeswitch/trunk/src: . include mod/applications/mod_dptools

Freeswitch SVN anthm at freeswitch.org
Tue Mar 11 17:32:56 EDT 2008


Author: anthm
Date: Tue Mar 11 17:32:56 2008
New Revision: 7865

Modified:
   freeswitch/trunk/src/include/switch_ivr.h
   freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
   freeswitch/trunk/src/switch_channel.c
   freeswitch/trunk/src/switch_ivr_async.c

Log:
update

Modified: freeswitch/trunk/src/include/switch_ivr.h
==============================================================================
--- freeswitch/trunk/src/include/switch_ivr.h	(original)
+++ freeswitch/trunk/src/include/switch_ivr.h	Tue Mar 11 17:32:56 2008
@@ -747,6 +747,10 @@
 												uint32_t timeout,
 												const char *valid_terminators);
 
+SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, const char *app);
+SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session);
+
+
 /** @} */
 
 SWITCH_END_EXTERN_C

Modified: freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_dptools/mod_dptools.c	Tue Mar 11 17:32:56 2008
@@ -79,6 +79,26 @@
 	}
 }
 
+#define BIND_SYNTAX "<key> <app>"
+SWITCH_STANDARD_APP(dtmf_bind_function)
+{
+	char *argv[2] = { 0 };
+	int argc;
+	char *lbuf = NULL;
+	
+	if (!switch_strlen_zero(data) && (lbuf = switch_core_session_strdup(session, data))
+		&& (argc = switch_separate_string(lbuf, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) == 2) {
+		int kval = atoi(argv[0]);
+		if (switch_ivr_bind_dtmf_meta_session(session, kval, argv[1]) == SWITCH_STATUS_SUCCESS) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Bound: %s %s\n", argv[0], argv[1]);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Bind Error!\n");
+		}
+	} else {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Usage: %s\n", BIND_SYNTAX);
+	}
+}
+
 #define INTERCEPT_SYNTAX "<uuid>"
 SWITCH_STANDARD_APP(intercept_function)
 {
@@ -1609,6 +1629,7 @@
 	SWITCH_ADD_APP(app_interface, "sched_broadcast", SCHED_BROADCAST_DESCR, SCHED_BROADCAST_DESCR, sched_broadcast_function, "[+]<time> <path> [aleg|bleg|both]", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "sched_transfer", SCHED_TRANSF_DESCR, SCHED_TRANSF_DESCR, sched_transfer_function, "[+]<time> <extension> <dialplan> <context>", SAF_SUPPORT_NOMEDIA);
 	SWITCH_ADD_APP(app_interface, "execute_extension", "Execute an extension", "Execute an extension", exe_function, EXE_SYNTAX, SAF_SUPPORT_NOMEDIA);
+	SWITCH_ADD_APP(app_interface, "bind_meta_app", "Bind a key to an application", "Bind a key to an application", dtmf_bind_function, BIND_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "intercept", "intercept", "intercept", intercept_function, INTERCEPT_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "eavesdrop", "eavesdrop on a uuid", "eavesdrop on a uuid", eavesdrop_function, eavesdrop_SYNTAX, SAF_NONE);
 	SWITCH_ADD_APP(app_interface, "three_way", "three way call with a uuid", "three way call with a uuid", three_way_function, eavesdrop_SYNTAX, SAF_NONE);

Modified: freeswitch/trunk/src/switch_channel.c
==============================================================================
--- freeswitch/trunk/src/switch_channel.c	(original)
+++ freeswitch/trunk/src/switch_channel.c	Tue Mar 11 17:32:56 2008
@@ -1913,15 +1913,17 @@
 	switch_time_t uduration = 0, legbillusec = 0, billusec = 0;
 	time_t tt_created = 0, tt_answered = 0, tt_hungup = 0, mtt_created = 0, mtt_answered = 0, mtt_hungup = 0, tt_prof_created, mtt_prof_created;
 
+	if (!(caller_profile = switch_channel_get_caller_profile(channel))) {
+		return SWITCH_STATUS_FALSE;
+	}
 
-	caller_profile = switch_channel_get_caller_profile(channel);
 	if (!(ocp = switch_channel_get_originatee_caller_profile(channel))) {
 		ocp = switch_channel_get_originator_caller_profile(channel);
 	}
 
 	if (!switch_strlen_zero(caller_profile->caller_id_name)) {
 		cid_buf = switch_core_session_sprintf(channel->session, "\"%s\" <%s>", caller_profile->caller_id_name, 
-			switch_str_nil(caller_profile->caller_id_number));
+											  switch_str_nil(caller_profile->caller_id_number));
 	} else {
 		cid_buf = caller_profile->caller_id_number;
 	}

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Tue Mar 11 17:32:56 2008
@@ -1258,6 +1258,104 @@
   return SWITCH_STATUS_SUCCESS;
 }
 
+typedef struct {
+	const char *app;
+} dtmf_meta_app_t;
+
+typedef struct {
+	dtmf_meta_app_t map[10];
+	time_t last_digit;
+	switch_bool_t meta_on;
+} dtmf_meta_data_t;
+
+#define SWITCH_META_VAR_KEY "__dtmf_meta"
+
+static switch_status_t meta_on_dtmf(switch_core_session_t *session, const switch_dtmf_t *dtmf)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
+	time_t now = switch_timestamp(NULL);
+	char digit[2] = "";
+	int dval;
+
+	if (!md) {
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	if (md->meta_on && now - md->last_digit > 5) {
+		md->meta_on = SWITCH_FALSE;
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "%s Meta digit timeout parsing %c\n", switch_channel_get_name(channel), dtmf->digit);
+		return SWITCH_STATUS_SUCCESS;
+	}
+
+	md->last_digit = now;
+
+	if (dtmf->digit == '*') {
+		if (md->meta_on) {
+			md->meta_on = SWITCH_FALSE;
+			return SWITCH_STATUS_SUCCESS;
+		} else {
+			md->meta_on = SWITCH_TRUE;
+			return SWITCH_STATUS_FALSE;
+		}
+	}
+
+	if (md->meta_on) {
+		if (dtmf->digit >= '0' && dtmf->digit <= '9') {
+			*digit = dtmf->digit;
+			dval = atoi(digit);
+			if (md->map[dval].app) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "%s Processing meta digit '%c' [%s]\n", 
+								  switch_channel_get_name(channel), dtmf->digit, md->map[dval].app);
+				switch_ivr_broadcast(switch_core_session_get_uuid(session), md->map[dval].app, SMF_ECHO_ALEG);
+			} else {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "%s Ignoring meta digit '%c' not mapped\n", 
+								  switch_channel_get_name(channel), dtmf->digit);
+								  
+			}
+		}
+		md->meta_on = SWITCH_FALSE;
+		return SWITCH_STATUS_FALSE;
+	}
+
+	return SWITCH_STATUS_SUCCESS;	
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_unbind_dtmf_meta_session(switch_core_session_t *session)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+    switch_channel_set_private(channel, SWITCH_META_VAR_KEY, NULL);
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+SWITCH_DECLARE(switch_status_t) switch_ivr_bind_dtmf_meta_session(switch_core_session_t *session, uint32_t key, const char *app)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	dtmf_meta_data_t *md = switch_channel_get_private(channel, SWITCH_META_VAR_KEY);
+	
+	if (key > 9) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid key %u\n", key);
+		return SWITCH_STATUS_FALSE;
+	}
+
+	if (!md) {
+		md = switch_core_session_alloc(session, sizeof(*md));
+		switch_channel_set_private(channel, SWITCH_META_VAR_KEY, md);
+		switch_core_event_hook_add_recv_dtmf(session, meta_on_dtmf);
+	}
+
+	if (!switch_strlen_zero(app)) {
+		md->map[key].app = switch_core_session_strdup(session, app);
+	} else {
+		md->map[key].app = NULL;
+	}
+
+	return SWITCH_STATUS_SUCCESS;
+}
+
+
+
 struct speech_thread_handle {
 	switch_core_session_t *session;
 	switch_asr_handle_t *ah;



More information about the Freeswitch-svn mailing list