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

Freeswitch SVN anthm at freeswitch.org
Thu Dec 13 18:30:16 EST 2007


Author: anthm
Date: Thu Dec 13 18:30:16 2007
New Revision: 6773

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

Log:
update

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	Thu Dec 13 18:30:16 2007
@@ -1736,7 +1736,7 @@
 			switch_odbc_handle_exec(profile->master_odbc, reg_sql, NULL);
 		}
 
-		if (switch_odbc_handle_exec(profile->master_odbc, "delete from sip_subscriptions where sip_user != ''", NULL) != SWITCH_ODBC_SUCCESS) {
+		if (switch_odbc_handle_exec(profile->master_odbc, "select * from sip_subscriptions where sip_user == ''", NULL) != SWITCH_ODBC_SUCCESS) {
 			switch_odbc_handle_exec(profile->master_odbc, "DROP TABLE sip_subscriptions", NULL);
 			switch_odbc_handle_exec(profile->master_odbc, sub_sql, NULL);
 		}
@@ -1754,7 +1754,7 @@
 		}
 
 		switch_core_db_test_reactive(profile->master_db, "select sip_user from sip_registrations", "DROP TABLE sip_registrations", reg_sql);
-		switch_core_db_test_reactive(profile->master_db, "delete from sip_subscriptions where sip_user != ''", "DROP TABLE sip_subscriptions", sub_sql);
+		switch_core_db_test_reactive(profile->master_db, "select * from sip_subscriptions where sip_user == ''", "DROP TABLE sip_subscriptions", sub_sql);
 		switch_core_db_test_reactive(profile->master_db, "select * from sip_authentication", "DROP TABLE sip_authentication", auth_sql);
 
 	}

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 Dec 13 18:30:16 2007
@@ -35,6 +35,7 @@
 #include "mod_sofia.h"
 
 static int sofia_presence_mwi_callback(void *pArg, int argc, char **argv, char **columnNames);
+static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames);
 static int sofia_presence_sub_reg_callback(void *pArg, int argc, char **argv, char **columnNames);
 static int sofia_presence_resub_callback(void *pArg, int argc, char **argv, char **columnNames);
 static int sofia_presence_sub_callback(void *pArg, int argc, char **argv, char **columnNames);
@@ -182,7 +183,8 @@
 	sofia_profile_t *profile = NULL;
 	switch_stream_handle_t stream = { 0 };
 	switch_event_header_t *hp;
-
+	int count = 0;
+	
 	switch_assert(event != NULL);
 
 	if (!(account = switch_event_get_header(event, "mwi-message-account"))) {
@@ -224,7 +226,7 @@
 	sql = switch_mprintf("select *,'%q' from sip_subscriptions where event='message-summary' and sub_to_user='%q' and sub_to_host='%q'", 
 						 stream.data, user, host);
 	
-	switch_safe_free(stream.data);
+
 
 	switch_assert (sql != NULL);
 	sofia_glue_execute_sql_callback(profile,
@@ -232,9 +234,31 @@
 									profile->ireg_mutex,
 									sql,
 									sofia_presence_mwi_callback,
-									profile);
+									&count);
 
 	switch_safe_free(sql);
+
+	
+	if (!count) {
+		sql = switch_mprintf("select *,'%q' from sip_registrations where sip_user='%q' and sip_host='%q'", 
+							 stream.data, user, host);
+	
+
+		
+		switch_assert (sql != NULL);
+		sofia_glue_execute_sql_callback(profile,
+										SWITCH_FALSE,
+										profile->ireg_mutex,
+										sql,
+										sofia_presence_mwi_callback2,
+										profile);
+		
+		switch_safe_free(sql);
+	}
+
+
+	switch_safe_free(stream.data);
+
 	switch_safe_free(dup_account);
 	if (profile) {
 		sofia_glue_release_profile(profile);
@@ -622,6 +646,7 @@
 	char *id = NULL;
 	nua_handle_t *nh;
 	int expire_sec = atoi(expires);
+	int *total = (int *) 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);
@@ -643,11 +668,47 @@
 	nua_notify(nh,
 			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
-
+	
 	switch_safe_free(id);
 	switch_safe_free(exp);
 
 	sofia_glue_release_profile(profile);
+	*total++;
+	return 0;
+}
+
+
+
+
+static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char **columnNames)
+{
+	char *sub_to_user = argv[1];
+	char *sub_to_host = argv[2];
+	char *event = "message-summary";
+	char *body = argv[7];
+	sofia_profile_t *profile = NULL;
+	char *id = NULL;
+	nua_handle_t *nh;
+
+	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);
+	
+	nh = nua_handle(profile->nua, NULL,
+					SIPTAG_FROM_STR(id),
+					SIPTAG_TO_STR(id), SIPTAG_CONTACT_STR(profile->url), TAG_END());
+	
+	
+	nua_notify(nh,
+			   NUTAG_NEWSUB(1),
+			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
+
+	switch_safe_free(id);
+
+	sofia_glue_release_profile(profile);
 
 	return 0;
 }



More information about the Freeswitch-trunk mailing list