Revision
15474
Author
anthm
Date
2009-11-14 20:16:10 -0600 (Sat, 14 Nov 2009)

Log Message

caller/ee id cleanup

Modified Paths

Diff

Modified: freeswitch/trunk/src/include/switch_utils.h (15473 => 15474)


--- freeswitch/trunk/src/include/switch_utils.h	2009-11-14 21:59:01 UTC (rev 15473)
+++ freeswitch/trunk/src/include/switch_utils.h	2009-11-15 02:16:10 UTC (rev 15474)
@@ -308,6 +308,26 @@
 
 #define switch_set_string(_dst, _src) switch_copy_string(_dst, _src, sizeof(_dst))
 
+
+static inline char *switch_sanitize_number(char *number)
+{
+	char *p = number, *q;
+	char warp[] = "/:";
+	int i;
+
+	if (!(strchr(p, '/') || strchr(p, ':') || strchr(p, '@'))) {
+		return number;
+	}
+
+	while((q = strrchr(p, '@'))) *q = '\0';
+ 
+	for(i = 0; i < strlen(warp); i++) {
+		while(p && (q = strchr(p, warp[i]))) p = q + 1;
+	}
+
+	return p;
+}
+
 static inline switch_bool_t switch_string_var_check(char *s, switch_bool_t disable)
 {
     char *p;

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (15473 => 15474)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2009-11-14 21:59:01 UTC (rev 15473)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c	2009-11-15 02:16:10 UTC (rev 15474)
@@ -179,15 +179,15 @@
 {
 	private_object_t *tech_pvt = (private_object_t *) switch_core_session_get_private(session);
 	const char *callee_name = NULL, *callee_number = NULL;
-	const char *ua = switch_channel_get_variable(tech_pvt->channel, "sip_user_agent");
-	char *pai = NULL;
+	const char *header, *ua = switch_channel_get_variable(tech_pvt->channel, "sip_user_agent");
+	char *pai = NULL, *tmp = NULL;
 
 	if (zstr((callee_name = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_name"))) &&
 		zstr((callee_name = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_name")))) {
 		callee_name = switch_channel_get_variable(tech_pvt->channel, "callee_id_name");
 	}
-
-	if (zstr((callee_number = switch_channel_get_variable(tech_pvt->channel, "origination_callee_id_number"))) &&
+	
+	if (zstr((callee_number = switch_channel_get_variable(tech_pvt->channel, "effective_callee_id_number"))) &&
 		zstr((callee_number = switch_channel_get_variable(tech_pvt->channel, "sip_callee_id_number")))) {
 		callee_number = tech_pvt->caller_profile->destination_number;
 	}
@@ -196,20 +196,30 @@
 		callee_name = callee_number;
 	}
 
+	tmp = switch_core_session_strdup(session, callee_number);
+	callee_number = switch_sanitize_number(tmp);
+
+	tmp = switch_core_session_strdup(session, callee_name);
+	callee_name = switch_sanitize_number(tmp);
+
 	if (!zstr(callee_number) && (zstr(ua) || !switch_stristr("polycom", ua))) {
 		callee_number = switch_core_session_sprintf(session, "sip:%s@%s", callee_number, tech_pvt->profile->sipip);
 	}
 	
+	header = (tech_pvt->cid_type == CID_TYPE_RPID) ? "Remote-Party-ID" : "P-Asserted-Identity";
 
 	if (!zstr(callee_name) && !zstr(callee_number)) {
 		if (switch_stristr("update_display", tech_pvt->x_freeswitch_support_remote)) {
-			pai = switch_core_session_sprintf(tech_pvt->session, "P-Asserted-Identity: \"%s\" <%s>\nX-FS-Display-Name: %s\nX-FS-Display-Number: %s\n", 
-											  callee_name, callee_number, callee_name, callee_number);
+			pai = switch_core_session_sprintf(tech_pvt->session, "%s: \"%s\" <%s>\n"
+											  "X-FS-Display-Name: %s\nX-FS-Display-Number: %s\n", 
+											  header, callee_name, callee_number, callee_name, callee_number);
 		} else {
-			pai = switch_core_session_sprintf(tech_pvt->session, "P-Asserted-Identity: \"%s\" <%s>\n", 
-											  callee_name, callee_number);
+			pai = switch_core_session_sprintf(tech_pvt->session, "%s: \"%s\" <%s>\n", 
+											  header, callee_name, callee_number);
 		}
+
 	}
+
 	return pai;
 }
 
@@ -2859,12 +2869,12 @@
 {
 	switch_call_cause_t cause = SWITCH_CAUSE_DESTINATION_OUT_OF_ORDER;
 	switch_core_session_t *nsession = NULL;
-	char *data, *profile_name, *dest, *dest_num = NULL;
+	char *data, *profile_name, *dest;//, *dest_num = NULL;
 	sofia_profile_t *profile = NULL;
 	switch_caller_profile_t *caller_profile = NULL;
 	private_object_t *tech_pvt = NULL;
 	switch_channel_t *nchannel;
-	char *host = NULL, *dest_to = NULL, *p;
+	char *host = NULL, *dest_to = NULL;
 	const char *hval = NULL;
 
 	*new_session = NULL;
@@ -3088,7 +3098,7 @@
 		}
 	}
 	switch_channel_set_variable(nchannel, "sip_destination_url", tech_pvt->dest);
-
+#if 0
 	dest_num = switch_core_session_strdup(nsession, dest);
 	if ((p = strchr(dest_num, '@'))) {
 		*p = '\0';
@@ -3101,10 +3111,16 @@
 			dest_num = p + 5;
 		}
 	}
+#endif
+
+	caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
 	
 
-	caller_profile = switch_caller_profile_clone(nsession, outbound_profile);
-	caller_profile->destination_number = switch_core_strdup(caller_profile->pool, dest_num);
+	caller_profile->destination_number = switch_sanitize_number(caller_profile->destination_number);
+	caller_profile->caller_id_name = switch_sanitize_number((char *)caller_profile->caller_id_name);
+	caller_profile->caller_id_number = switch_sanitize_number((char *)caller_profile->caller_id_number);
+	
+	//caller_profile->destination_number = switch_core_strdup(caller_profile->pool, dest_num);
 	switch_channel_set_caller_profile(nchannel, caller_profile);
 	switch_channel_set_flag(nchannel, CF_OUTBOUND);
 	sofia_set_flag_locked(tech_pvt, TFLAG_OUTBOUND);
@@ -3157,6 +3173,7 @@
 			switch_assert(ctech_pvt != NULL);
 			tech_pvt->bte = ctech_pvt->te;
 			tech_pvt->bcng_pt = ctech_pvt->cng_pt;
+			tech_pvt->cid_type = ctech_pvt->cid_type;
 		}
 
 		if (switch_channel_test_flag(o_channel, CF_PROXY_MEDIA)) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (15473 => 15474)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-11-14 21:59:01 UTC (rev 15473)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	2009-11-15 02:16:10 UTC (rev 15474)
@@ -645,6 +645,7 @@
 	switch_codec_implementation_t write_impl;
 	char *user_via;
 	char *redirected;
+	sofia_cid_type_t cid_type;
 };
 
 struct callback_t {

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


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-11-14 21:59:01 UTC (rev 15473)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	2009-11-15 02:16:10 UTC (rev 15474)
@@ -501,6 +501,9 @@
 	caller_profile->callee_id_name = switch_core_strdup(caller_profile->pool, name);
 	caller_profile->callee_id_number = switch_core_strdup(caller_profile->pool, number);
 
+	caller_profile->callee_id_name = switch_sanitize_number((char *)caller_profile->callee_id_name);
+	caller_profile->callee_id_number = switch_sanitize_number((char *)caller_profile->callee_id_number);
+
 	switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Update Callee ID to \"%s\" <%s>\n", name, number);
 	
 	if (send) {
@@ -5324,6 +5327,7 @@
 			displayname = rpid->rpid_display;
 		}
 		switch_channel_set_variable(channel, "sip_cid_type", "rpid");
+		tech_pvt->cid_type = CID_TYPE_RPID;
 	}
 
 	if ((passerted = sip_p_asserted_identity(sip))) {
@@ -5338,6 +5342,7 @@
 			displayname = passerted->paid_display;
 		}
 		switch_channel_set_variable(channel, "sip_cid_type", "pid");
+		tech_pvt->cid_type = CID_TYPE_PID;
 	}
 
 	if ((ppreferred = sip_p_preferred_identity(sip))) {
@@ -5353,6 +5358,7 @@
 			displayname = ppreferred->ppid_display;
 		}
 		switch_channel_set_variable(channel, "sip_cid_type", "pid");
+		tech_pvt->cid_type = CID_TYPE_PID;
 	}
 
 	if (from_user) {

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (15473 => 15474)


--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-11-14 21:59:01 UTC (rev 15473)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c	2009-11-15 02:16:10 UTC (rev 15474)
@@ -1632,7 +1632,10 @@
 		
 		if ((val = switch_channel_get_variable(channel, "sip_cid_type"))) {
 			cid_type = sofia_cid_name2type(val);
+		} else {
+			cid_type = tech_pvt->cid_type;
 		}
+
 		switch (cid_type) {
 		case CID_TYPE_PID:
 			if (switch_test_flag(caller_profile, SWITCH_CPF_SCREEN)) {