Revision
16395
Author
anthm
Date
2010-01-18 14:31:47 -0600 (Mon, 18 Jan 2010)

Log Message

set chanvars on both directions in sip and introduce sip_to_tag and sip_from_tag vars

Modified Paths

Diff

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16394 => 16395)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-01-18 20:31:44 UTC (rev 16394)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2010-01-18 20:31:47 UTC (rev 16395)
@@ -85,6 +85,69 @@
 #endif
 }
 
+
+static void _set_chanvars(switch_core_session_t *session, url_t *url, const char *user_var,
+							  const char *host_var, const char *port_var, const char *uri_var, const char *params_var)
+{
+	const char *user = NULL, *host = NULL, *port = NULL;
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+	char new_port[25] = "";
+
+	if (url) {
+		user = url->url_user;
+		host = url->url_host;
+		port = url->url_port;
+		if (!zstr(url->url_params)) {
+			switch_channel_set_variable(channel, params_var, url->url_params);
+		}
+	}
+
+	if (zstr(user)) {
+		user = "nobody";
+	}
+
+	if (zstr(host)) {
+		host = "nowhere";
+	}
+
+	check_decode(user, session);
+
+	if (user) {
+		switch_channel_set_variable(channel, user_var, user);
+	}
+
+
+	if (port) {
+		switch_snprintf(new_port, sizeof(new_port), ":%s", port);
+	}
+
+	switch_channel_set_variable(channel, port_var, port);
+	
+}
+#define set_chanvars(session, url, varprefix) _set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params")
+
+
+static void extract_vars(sip_t const *sip, switch_core_session_t *session)
+{
+	switch_channel_t *channel = switch_core_session_get_channel(session);
+
+	if (sip) {
+		if (sip->sip_from && sip->sip_from->a_url) set_chanvars(session, sip->sip_from->a_url, sip_from);
+		if (sip->sip_request && sip->sip_request->rq_url) set_chanvars(session, sip->sip_request->rq_url, sip_req);
+		if (sip->sip_to && sip->sip_to->a_url) set_chanvars(session, sip->sip_to->a_url, sip_to);
+		if (sip->sip_contact && sip->sip_contact->m_url) set_chanvars(session, sip->sip_contact->m_url, sip_contact);
+		if (sip->sip_referred_by && sip->sip_referred_by->b_url) set_chanvars(session, sip->sip_referred_by->b_url, sip_referred_by);
+		if (sip->sip_to && sip->sip_to->a_tag) {
+					switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
+		}
+		if (sip->sip_from && sip->sip_from->a_tag) {
+			switch_channel_set_variable(channel, "sip_from_tag", sip->sip_from->a_tag);
+		}
+	}
+}
+
+
+
 void sofia_handle_sip_i_notify(switch_core_session_t *session, int status,
 							   char const *phrase,
 							   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
@@ -644,6 +707,17 @@
 	case nua_r_prack:
 		break;
 	case nua_i_ack:
+		{
+			if (channel && sip) {
+				if (sip->sip_to && sip->sip_to->a_tag) {
+					switch_channel_set_variable(channel, "sip_to_tag", sip->sip_to->a_tag);
+				}
+				
+				if (sip->sip_from && sip->sip_from->a_tag) {
+					switch_channel_set_variable(channel, "sip_from_tag", sip->sip_from->a_tag);
+				}
+			}
+		}
 	case nua_r_ack:
 		if (channel) switch_channel_set_flag(channel, CF_MEDIA_ACK);
 		break;
@@ -3474,6 +3548,8 @@
 
 			switch_channel_set_flag(channel, CF_MEDIA_ACK);
 
+			extract_vars(sip, session);
+			
 			if ((x_freeswitch_support = sofia_glue_get_unknown_header(sip, "X-FS-Support"))) {
 				tech_pvt->x_freeswitch_support_remote = switch_core_session_strdup(session, x_freeswitch_support);
 			}
@@ -5269,7 +5345,7 @@
 
 #define url_set_chanvars(session, url, varprefix) _url_set_chanvars(session, url, #varprefix "_user", #varprefix "_host", #varprefix "_port", #varprefix "_uri", #varprefix "_params")
 
-const char *_url_set_chanvars(switch_core_session_t *session, url_t *url, const char *user_var,
+static const char *_url_set_chanvars(switch_core_session_t *session, url_t *url, const char *user_var,
 							  const char *host_var, const char *port_var, const char *uri_var, const char *params_var)
 {
 	const char *user = NULL, *host = NULL, *port = NULL;
@@ -5319,6 +5395,7 @@
 	return uri;
 }
 
+
 void sofia_handle_sip_i_reinvite(switch_core_session_t *session, 
 							   nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[])
 {