[Freeswitch-svn] [commit] r8303 - in freeswitch/trunk/src/mod: applications/mod_voicemail endpoints/mod_sofia

Freeswitch SVN anthm at freeswitch.org
Thu May 8 12:09:49 EDT 2008


Author: anthm
Date: Thu May  8 12:09:49 2008
New Revision: 8303

Modified:
   freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
test

Modified: freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_voicemail/mod_voicemail.c	Thu May  8 12:09:49 2008
@@ -2156,7 +2156,7 @@
 static void  message_query_handler(switch_event_t *event)
 {
 	char *account = switch_event_get_header(event, "message-account");
-	int sent = 0;
+	int created = 0;
 	switch_event_t *new_event = NULL;
 
 	if (account) {
@@ -2194,8 +2194,7 @@
 						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
 						switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Voice-Message", "%d/%d (%d/%d)", 
 							total_new_messages, total_saved_messages, total_new_urgent_messages, total_saved_urgent_messages);
-						switch_event_fire(&new_event);
-						sent++;
+						created++;
 					}
 				}
 			}
@@ -2205,13 +2204,26 @@
 
 	}
 
-	if (!sent) {
+	if (!created) {
 		if (switch_event_create(&new_event, SWITCH_EVENT_MESSAGE_WAITING) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Messages-Waiting", "no");
 			switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, "MWI-Message-Account", account);
-			switch_event_fire(&new_event);
 		}
 	}
+
+	if (new_event) {
+		switch_event_header_t *hp;
+
+		for (hp = event->headers; hp; hp = hp->next) {
+			if (!strncasecmp(hp->name, "vm-", 3)) {
+				switch_event_add_header(new_event, SWITCH_STACK_BOTTOM, hp->name + 3, hp->value);
+			}
+		}
+
+		switch_event_fire(&new_event);
+	}
+
+
 }
 
 #define VOICEMAIL_SYNTAX "rss [<host> <port> <uri> <user> <domain>]"

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c	Thu May  8 12:09:49 2008
@@ -188,6 +188,11 @@
 	return r;
 }
 
+struct mwi_helper {
+	sofia_profile_t *profile;
+	int total;
+};
+
 static void actual_sofia_presence_mwi_event_handler(switch_event_t *event)
 {
 	char *account, *dup_account, *yn, *host, *user;
@@ -195,8 +200,9 @@
 	sofia_profile_t *profile = NULL;
 	switch_stream_handle_t stream = { 0 };
 	switch_event_header_t *hp;
-	int count = 0;
-	
+	struct mwi_helper h = { 0 };
+	char *pname = NULL;
+
 	switch_assert(event != NULL);
 
 	if (!(account = switch_event_get_header(event, "mwi-message-account"))) {
@@ -213,11 +219,31 @@
 	switch_assert(dup_account != NULL);
 	sofia_glue_get_user_host(dup_account, &user, &host);
 
-	if (!host || !(profile = sofia_glue_find_profile(host))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", switch_str_nil(host));
-		return;
+
+	if ((pname = switch_event_get_header(event, "sofia-profile"))) {
+		if ((profile = sofia_glue_find_profile(pname))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "using profile %s\n", pname);
+		} else {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "no profile %s\n", pname);
+		}
+	}
+
+	if (!profile) {
+		if (!host || !(profile = sofia_glue_find_profile(host))) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile %s\n", switch_str_nil(host));
+			switch_safe_free(dup_account);
+			return;
+		}
 	}
 	
+	if (profile->domain_name && profile->domain_name != host) {
+		host = profile->domain_name;
+	}
+
+	h.profile = profile;
+	h.total = 0;
+
+
 	SWITCH_STANDARD_STREAM(stream);
 
 	for (hp = event->headers; hp; hp = hp->next) {
@@ -239,19 +265,18 @@
 						 stream.data, user, host);
 	
 
-
 	switch_assert (sql != NULL);
 	sofia_glue_execute_sql_callback(profile,
 									SWITCH_FALSE,
 									profile->ireg_mutex,
 									sql,
 									sofia_presence_mwi_callback,
-									&count);
+									&h);
 
 	switch_safe_free(sql);
 
 	
-	if (!count) {
+	if (h.total) {
 		sql = switch_mprintf("select sip_user,sip_host,contact,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", 
 							 stream.data, user, host);
 	
@@ -263,7 +288,7 @@
 										profile->ireg_mutex,
 										sql,
 										sofia_presence_mwi_callback2,
-										profile);
+										&h);
 		
 		switch_safe_free(sql);
 	}
@@ -640,6 +665,7 @@
 	if (!strcasecmp(event_name, "message-summary")) {
 		if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
 			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", user, host);
+			switch_event_add_header(event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", "%s", profile->name);
 			switch_event_fire(&event);
 		}
 		return 0;
@@ -1073,18 +1099,15 @@
 	char *expires = argv[10];
 	char *body = argv[13];
 	char *exp;
-	sofia_profile_t *profile = NULL;
+	//sofia_profile_t *profile = NULL;
 	char *id = NULL;
 	nua_handle_t *nh;
 	int expire_sec = atoi(expires);
-	int *total = (int *) pArg;
+	//int *total = (int *) pArg;
+	struct mwi_helper *h = (struct mwi_helper *) pArg;
 	
-	if (!(profile = sofia_glue_find_profile(sub_to_host))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", sub_to_host);
-		return 0;
-	}
 	
-	if (!(nh = nua_handle_by_call_id(profile->nua, call_id))) {
+	if (!(nh = nua_handle_by_call_id(h->profile->nua, call_id))) {
 		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find handle for %s\n", call_id);
 		return 0;
 	}
@@ -1103,8 +1126,7 @@
 	switch_safe_free(id);
 	switch_safe_free(exp);
 
-	sofia_glue_release_profile(profile);
-	(*total)++;
+	h->total++;
 	return 0;
 }
 
@@ -1118,25 +1140,20 @@
 	char *event = "message-summary";
 	char *contact = argv[2];
 	char *body = argv[3];
-	sofia_profile_t *profile = NULL;
 	char *id = NULL;
 	nua_handle_t *nh;
-
+	struct mwi_helper *h = (struct mwi_helper *) pArg;
+	
 	
-	if (!(profile = sofia_glue_find_profile(sub_to_host))) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Cannot find profile for host %s\n", sub_to_host);
-		return 0;
-	}
-
 	id = switch_mprintf("sip:%s@%s", sub_to_user, sub_to_host);
 
 	contact = sofia_glue_get_url_from_contact(contact, 0);
 	
-	nh = nua_handle(profile->nua, NULL,
+	nh = nua_handle(h->profile->nua, NULL,
 					NUTAG_URL(contact),
 					SIPTAG_FROM_STR(id),
 					SIPTAG_TO_STR(id),
-					SIPTAG_CONTACT_STR(profile->url),
+					SIPTAG_CONTACT_STR(h->profile->url),
 					TAG_END());
 	
 	nua_notify(nh,
@@ -1145,8 +1162,6 @@
 
 	switch_safe_free(id);
 	
-	sofia_glue_release_profile(profile);
-	
 	return 0;
 }
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c	Thu May  8 12:09:49 2008
@@ -688,12 +688,14 @@
 
 	if (regtype == REG_REGISTER) {
 		char *new_contact = NULL;
+
 		if (exptime) {
 			new_contact = switch_mprintf("%s;expires=%ld", contact_str, (long)exptime);
 			nua_respond(nh, SIP_200_OK, SIPTAG_CONTACT_STR(new_contact), NUTAG_WITH_THIS(nua), TAG_END());
 			switch_safe_free(new_contact);
 			if (switch_event_create(&event, SWITCH_EVENT_MESSAGE_QUERY) == SWITCH_STATUS_SUCCESS) {
 				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "Message-Account", "sip:%s@%s", to_user, to_host);
+				switch_event_add_header(event, SWITCH_STACK_BOTTOM, "VM-Sofia-Profile", "%s", profile->name);
 				switch_event_fire(&event);
 			}
 		} else {



More information about the Freeswitch-svn mailing list