[Freeswitch-svn] [commit] r13084 - in freeswitch/trunk: libs/esl/src libs/esl/src/include src src/include src/mod/endpoints/mod_sofia

FreeSWITCH SVN anthm at freeswitch.org
Mon Apr 20 10:07:54 PDT 2009


Author: anthm
Date: Mon Apr 20 12:07:54 2009
New Revision: 13084

Log:
ndlb_sendrecv_in_session var NDLB-sendrecv-in-session profile option to reverse the effects of MODENDP-148

Modified:
   freeswitch/trunk/libs/esl/src/esl_event.c
   freeswitch/trunk/libs/esl/src/include/esl_event.h
   freeswitch/trunk/src/include/switch_types.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
   freeswitch/trunk/src/switch_event.c

Modified: freeswitch/trunk/libs/esl/src/esl_event.c
==============================================================================
--- freeswitch/trunk/libs/esl/src/esl_event.c	(original)
+++ freeswitch/trunk/libs/esl/src/esl_event.c	Mon Apr 20 12:07:54 2009
@@ -121,6 +121,8 @@
 	"SESSION_HEARTBEAT",
 	"CLIENT_DISCONNECTED",
 	"SERVER_DISCONNECTED",
+	"SEND_INFO",
+	"RECV_INFO",
 	"ALL"
 };
 

Modified: freeswitch/trunk/libs/esl/src/include/esl_event.h
==============================================================================
--- freeswitch/trunk/libs/esl/src/include/esl_event.h	(original)
+++ freeswitch/trunk/libs/esl/src/include/esl_event.h	Mon Apr 20 12:07:54 2009
@@ -109,6 +109,8 @@
 	ESL_EVENT_SESSION_HEARTBEAT,
 	ESL_EVENT_CLIENT_DISCONNECTED,
 	ESL_EVENT_SERVER_DISCONNECTED,
+	ESL_EVENT_SEND_INFO,
+	ESL_EVENT_RECV_INFO,
 	ESL_EVENT_ALL
 } esl_event_types_t;
 

Modified: freeswitch/trunk/src/include/switch_types.h
==============================================================================
--- freeswitch/trunk/src/include/switch_types.h	(original)
+++ freeswitch/trunk/src/include/switch_types.h	Mon Apr 20 12:07:54 2009
@@ -1257,6 +1257,8 @@
 	SWITCH_EVENT_SESSION_HEARTBEAT,
 	SWITCH_EVENT_CLIENT_DISCONNECTED,
 	SWITCH_EVENT_SERVER_DISCONNECTED,
+	SWITCH_EVENT_SEND_INFO,
+	SWITCH_EVENT_RECV_INFO,
 	SWITCH_EVENT_ALL
 } switch_event_types_t;
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	Mon Apr 20 12:07:54 2009
@@ -2869,6 +2869,56 @@
 
 		}
 		break;
+	case SWITCH_EVENT_SEND_INFO:
+		{
+			const char *profile_name = switch_event_get_header(event, "profile");
+			const char *ct = switch_event_get_header(event, "content-type");
+			const char *to_uri = switch_event_get_header(event, "to-uri");
+			const char *from_uri = switch_event_get_header(event, "from-uri");
+			const char *body = switch_event_get_body(event);
+			sofia_profile_t *profile;
+			nua_handle_t *nh;
+
+			if (!profile_name) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Profile Name\n");
+				return;
+			}
+
+			if (!to_uri) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n");
+				return;
+			}
+
+			if (!from_uri) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n");
+				return;
+			}
+
+			
+			if (!(profile = sofia_glue_find_profile(profile_name))) {
+				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find profile %s\n", profile_name);
+				return;
+			}
+
+			
+			nh = nua_handle(profile->nua, 
+							NULL, 
+							NUTAG_URL(to_uri), 
+							SIPTAG_FROM_STR(from_uri), 
+							SIPTAG_TO_STR(to_uri), 
+							SIPTAG_CONTACT_STR(profile->url), 
+							TAG_END());
+			
+			nua_info(nh,
+					 TAG_IF(ct, SIPTAG_CONTENT_TYPE_STR(ct)), 
+					 TAG_IF(!switch_strlen_zero(body), SIPTAG_PAYLOAD_STR(body)),
+					 TAG_END());
+
+				
+			sofia_glue_release_profile(profile);
+			
+		}
+		break;
 	case SWITCH_EVENT_TRAP:
 		{
 			const char *cond = switch_event_get_header(event, "condition");
@@ -3018,6 +3068,11 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
+	if (switch_event_bind(modname, SWITCH_EVENT_SEND_INFO, SWITCH_EVENT_SUBCLASS_ANY, general_event_handler, NULL) != SWITCH_STATUS_SUCCESS) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Couldn't bind!\n");
+		return SWITCH_STATUS_GENERR;
+	}
+
 	/* connect my internal structure to the blank pointer passed to me */
 	*module_interface = switch_loadable_module_create_module_interface(pool, modname);
 	sofia_endpoint_interface = switch_loadable_module_create_interface(*module_interface, SWITCH_ENDPOINT_INTERFACE);

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Mon Apr 20 12:07:54 2009
@@ -190,7 +190,8 @@
 
 typedef enum {
 	PFLAG_NDLB_TO_IN_200_CONTACT = (1 << 0),
-	PFLAG_NDLB_BROKEN_AUTH_HASH = (1 << 1)
+	PFLAG_NDLB_BROKEN_AUTH_HASH = (1 << 1),
+	PFLAG_NDLB_SENDRECV_IN_SESSION = (1 << 2)
 } sofia_NDLB_t;
 
 typedef enum {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Mon Apr 20 12:07:54 2009
@@ -1668,6 +1668,12 @@
 						} else {
 							profile->ndlb &= ~PFLAG_NDLB_BROKEN_AUTH_HASH;
 						}
+					} else if (!strcasecmp(var, "NDLB-sendrecv-in-session")) {
+						if (switch_true(val)) {
+							profile->ndlb |= PFLAG_NDLB_SENDRECV_IN_SESSION;
+						} else {
+							profile->ndlb &= ~PFLAG_NDLB_SENDRECV_IN_SESSION;
+						}
 					} else if (!strcasecmp(var, "pass-rfc2833")) {
 						if (switch_true(val)) {
 							sofia_set_pflag(profile, PFLAG_PASS_RFC2833);
@@ -2215,6 +2221,12 @@
 						if (switch_true(val)) {
 							profile->ndlb |= PFLAG_NDLB_BROKEN_AUTH_HASH;
 						}
+					} else if (!strcasecmp(var, "NDLB-sendrecv-in-session")) {
+						if (switch_true(val)) {
+							profile->ndlb |= PFLAG_NDLB_SENDRECV_IN_SESSION;
+						} else {
+							profile->ndlb &= ~PFLAG_NDLB_SENDRECV_IN_SESSION;
+						}
 					} else if (!strcasecmp(var, "pass-rfc2833")) {
 						if (switch_true(val)) {
 							sofia_set_pflag(profile, PFLAG_PASS_RFC2833);
@@ -3863,6 +3875,7 @@
 	const char *rec_header;
 	const char *clientcode_header;
 	switch_dtmf_t dtmf = { 0, switch_core_default_dtmf_duration(0) };
+	switch_event_t *event;
 
 	if (session) {
 		/* Get the channel */
@@ -3932,7 +3945,7 @@
 				/* Send 200 OK response */
 				nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
 
-				return;
+				goto end;
 			} else {
 				goto fail;
 			}
@@ -3946,7 +3959,7 @@
 			} else {
 				goto fail;
 			}
-			return;
+			goto end;
 		}
 
 		if ((rec_header = sofia_glue_get_unknown_header(sip, "record"))) {
@@ -3978,13 +3991,66 @@
 					}
 				}
 			}
-			return;
+			goto end;
 		}
 	}
-	return;
+	goto end;
 
   fail:
-	nua_respond(nh, 488, "Unsupported Request", NUTAG_WITH_THIS(nua), TAG_END());
+
+	/* *shrug* just ok it */
+	nua_respond(nh, SIP_200_OK, NUTAG_WITH_THIS(nua), TAG_END());
+
+ end:
+
+
+	if (switch_event_create(&event, SWITCH_EVENT_RECV_INFO) == SWITCH_STATUS_SUCCESS) {
+		
+		if (sip->sip_content_type) {
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Content-Type", "%s", sip->sip_content_type->c_type);
+		}
+
+		if (sip->sip_from && sip->sip_from->a_url) {
+			if (sip->sip_from->a_url->url_user) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-From-User", sip->sip_from->a_url->url_user);
+			}
+
+			if (sip->sip_from->a_url->url_host) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-From-Host", sip->sip_from->a_url->url_host);
+			}
+		}
+
+		if (sip->sip_to && sip->sip_to->a_url) {
+			if (sip->sip_to->a_url->url_user) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-To-User", sip->sip_to->a_url->url_user);
+			}
+
+			if (sip->sip_to->a_url->url_host) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-To-Host", sip->sip_to->a_url->url_host);
+			}
+		}
+
+
+		if (sip->sip_contact && sip->sip_contact->m_url) {
+			if (sip->sip_contact->m_url->url_user) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Contact-User", sip->sip_contact->m_url->url_user);
+			}
+
+			if (sip->sip_contact->m_url->url_host) {
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "SIP-Contact-Host", sip->sip_contact->m_url->url_host);
+			}
+		}
+
+		if (sip->sip_payload->pl_data) {
+			switch_event_add_body(event, "%s", sip->sip_payload->pl_data);
+		}
+
+		switch_event_fire(&event);
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "dispatched freeswitch event for INFO\n");
+	}
+
+	return;
+
 }
 
 #define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params")

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	Mon Apr 20 12:07:54 2009
@@ -117,6 +117,8 @@
 	const char *family;
 	const char *pass_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_video_fmtp");
 	const char *ov_fmtp = switch_channel_get_variable(tech_pvt->channel, "sip_force_video_fmtp");
+	char srbuf[128] = "";
+	const char *var_val;
 
 	if (sofia_test_pflag(tech_pvt->profile, PFLAG_SUPPRESS_CNG) ||
 		((val = switch_channel_get_variable(tech_pvt->channel, "supress_cng")) && switch_true(val)) ||
@@ -155,14 +157,22 @@
 
 	tech_pvt->session_id++;
 
+	if ((tech_pvt->profile->ndlb & PFLAG_NDLB_SENDRECV_IN_SESSION) || 
+		((var_val=switch_channel_get_variable(tech_pvt->channel, "ndlb_sendrecv_in_session")) && switch_true(var_val))) {
+		switch_snprintf(srbuf, sizeof(srbuf), "a=%s\n", sr);
+		sr = NULL;
+	}
+	
 	family = strchr(ip, ':') ? "IP6" : "IP4";
 	switch_snprintf(buf, sizeof(buf),
 					"v=0\n"
 					"o=FreeSWITCH %010u %010u IN %s %s\n"
 					"s=FreeSWITCH\n"
 					"c=IN %s %s\n" "t=0 0\n"
-					"m=audio %d RTP/%sAVP", 
-					tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, port,
+					"%sm=audio %d RTP/%sAVP", 
+					tech_pvt->owner_id, tech_pvt->session_id, family, ip, family, ip, 
+					srbuf,
+					port,
 					(!switch_strlen_zero(tech_pvt->local_crypto_key) 
 					&& sofia_test_flag(tech_pvt,TFLAG_SECURE)) ? "S" : "");
 

Modified: freeswitch/trunk/src/switch_event.c
==============================================================================
--- freeswitch/trunk/src/switch_event.c	(original)
+++ freeswitch/trunk/src/switch_event.c	Mon Apr 20 12:07:54 2009
@@ -175,6 +175,8 @@
 	"SESSION_HEARTBEAT",
 	"CLIENT_DISCONNECTED",
 	"SERVER_DISCONNECTED",
+	"SEND_INFO",
+	"RECV_INFO",
 	"ALL"
 };
 



More information about the Freeswitch-svn mailing list