[Freeswitch-svn] [commit] r13169 - freeswitch/trunk/src/mod/endpoints/mod_sofia

FreeSWITCH SVN brian at freeswitch.org
Mon Apr 27 11:18:29 PDT 2009


Author: brian
Date: Mon Apr 27 13:18:29 2009
New Revision: 13169

Log:
add contact lookup for lazy ppl

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c

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 27 13:18:29 2009
@@ -2875,7 +2875,7 @@
 
 				switch_assert(id);
 				contact = sofia_glue_get_url_from_contact(buf, 0);
-
+				
 				if ((p = strstr(contact, ";fs_"))) {
 					*p = '\0';
 				}
@@ -2906,32 +2906,60 @@
 			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 *local_user_full = switch_event_get_header(event, "local-user");
 			const char *from_uri = switch_event_get_header(event, "from-uri");
 			const char *body = switch_event_get_body(event);
-			sofia_profile_t *profile;
+			sofia_profile_t *profile = NULL;
 			nua_handle_t *nh;
+			char *local_dup = NULL;
+			char *local_user, *local_host;
+			char buf[1024] = "";
+			char *p;
 
+			
 			if (!profile_name) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing Profile Name\n");
-				return;
+				goto done;
 			}
 
-			if (!to_uri) {
+			if (!to_uri && !local_user_full) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing To-URI header\n");
-				return;
+				goto done;
 			}
 
 			if (!from_uri) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing From-URI header\n");
-				return;
+				goto done;
 			}
 
 			
 			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;
+				goto done;
 			}
 			
+
+			if (local_user_full) {
+				local_dup = strdup(local_user_full);
+				local_user = local_dup;
+				if ((local_host = strchr(local_user, '@'))) {
+					*local_host++ = '\0';
+				}
+
+				if (!local_user || !local_host || !sofia_reg_find_reg_url(profile, local_user, local_host, buf, sizeof(buf))) {
+					switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find local user\n");
+					goto done;
+				}
+
+				to_uri = sofia_glue_get_url_from_contact(buf, 0);
+				
+				if ((p = strstr(to_uri, ";fs_"))) {
+					*p = '\0';
+				}
+
+			}
+
+
 			nh = nua_handle(profile->nua, 
 							NULL, 
 							NUTAG_URL(to_uri), 
@@ -2948,8 +2976,14 @@
 					 TAG_IF(!switch_strlen_zero(body), SIPTAG_PAYLOAD_STR(body)),
 					 TAG_END());
 
-				
-			sofia_glue_release_profile(profile);
+
+			if (profile) {
+				sofia_glue_release_profile(profile);
+			}
+			
+		done:
+
+			switch_safe_free(local_dup);
 			
 		}
 		break;



More information about the Freeswitch-svn mailing list