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

Freeswitch SVN anthm at freeswitch.org
Wed May 7 16:06:47 EDT 2008


Author: anthm
Date: Wed May  7 16:06:46 2008
New Revision: 8296

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
   freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c

Log:
use this one

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h	Wed May  7 16:06:46 2008
@@ -196,6 +196,7 @@
 	switch_queue_t *presence_queue;
 	switch_queue_t *mwi_queue;
 	struct sofia_private destroy_private;
+	struct sofia_private keep_private;
 };
 extern struct mod_sofia_globals mod_sofia_globals;
 

Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	(original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c	Wed May  7 16:06:46 2008
@@ -177,7 +177,7 @@
 	switch_channel_t *channel = NULL;
 	sofia_gateway_t *gateway = NULL;
 
-	if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private) {
+	if (sofia_private && sofia_private != &mod_sofia_globals.destroy_private && sofia_private != &mod_sofia_globals.keep_private) {
 		if ((gateway = sofia_private->gateway)) {
 			if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
 				switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
@@ -339,9 +339,15 @@
 
   done:
 
-	if ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh)) {
-		//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Destroy handle requested.\n");
-		nua_handle_destroy(nh);
+	switch (event) {
+	case nua_i_subscribe:
+		break;
+	default:
+		if (nh && ((sofia_private && sofia_private->destroy_nh) || !nua_handle_magic(nh))) {
+			//switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Destroy handle [%s]\n", nua_event_name(event));
+			nua_handle_destroy(nh);
+		}
+		break;
 	}
 
 	if (gateway) {

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	Wed May  7 16:06:46 2008
@@ -107,7 +107,6 @@
 						SIPTAG_CONTACT_STR(profile->url), TAG_END());
 
 	switch_safe_free(contact);
-	nua_handle_bind(msg_nh, &mod_sofia_globals.destroy_private);
 	nua_message(msg_nh, SIPTAG_CONTENT_TYPE_STR("text/html"), SIPTAG_PAYLOAD_STR(body), TAG_END());
 
 	switch_safe_free(ffrom);
@@ -1043,7 +1042,7 @@
 	}
 
 	switch_snprintf(exp, sizeof(exp), "active;expires=%ld", (long) exptime); 
-
+	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
 	nua_notify(nh,
 			   SIPTAG_SUBSCRIPTION_STATE_STR(exp),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR(ct), SIPTAG_PAYLOAD_STR(pl), TAG_END());
@@ -1096,7 +1095,7 @@
 		expire_sec = 3600;
 	}
 	exp = switch_mprintf("active;expires=%ld", expire_sec);
-
+	nua_handle_bind(nh, &mod_sofia_globals.keep_private);
 	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());
@@ -1140,7 +1139,6 @@
 					SIPTAG_CONTACT_STR(profile->url),
 					TAG_END());
 	
-	nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
 	nua_notify(nh,
 			   NUTAG_NEWSUB(1),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
@@ -1338,7 +1336,7 @@
 		sent_reply++;
 
 #if 0
-		nua_handle_bind(nh, &mod_sofia_globals.destroy_private);
+
 		nua_notify(nh, 
 				   NUTAG_NEWSUB(1),
 				   SIPTAG_SUBSCRIPTION_STATE_STR(sstr), SIPTAG_EVENT_STR(event), 

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	Wed May  7 16:06:46 2008
@@ -97,6 +97,7 @@
 		
 		switch (ostate) {
 		case REG_STATE_NOREG:
+			gateway_ptr->status = SOFIA_GATEWAY_UP;
 			break;
 		case REG_STATE_REGISTER:
 			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "registered %s\n", gateway_ptr->name);
@@ -110,7 +111,7 @@
 			gateway_ptr->state = REG_STATE_NOREG;
 			break;
 		case REG_STATE_UNREGED:
-
+			gateway_ptr->status = SOFIA_GATEWAY_DOWN;
             sofia_reg_kill_reg(gateway_ptr, 1);
 
 			if ((gateway_ptr->nh = nua_handle(gateway_ptr->profile->nua, NULL,
@@ -204,6 +205,20 @@
 	return 0;
 }
 
+
+int sofia_sub_del_callback(void *pArg, int argc, char **argv, char **columnNames)
+{
+	sofia_profile_t *profile = (sofia_profile_t *) pArg;
+	nua_handle_t *nh;
+
+	if (argv[0]) {
+		if ((nh = nua_handle_by_call_id(profile->nua, argv[0]))) {
+			nua_handle_destroy(nh);
+		}
+	}
+	return 0;
+}
+
 int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	switch_event_t *s_event;
@@ -262,13 +277,15 @@
     }
 #endif
 
+
+	switch_mutex_lock(profile->ireg_mutex);
+
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0 and expires <= %ld", profile->name, (long) now);
 	} else {
 		switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
 	}
 
-	switch_mutex_lock(profile->ireg_mutex);
 	sofia_glue_execute_sql_callback(profile,
 									SWITCH_TRUE,
 									NULL,
@@ -291,6 +308,21 @@
 
 	sofia_glue_actually_execute_sql(profile, SWITCH_FALSE, sql, NULL);
 	
+
+
+	if (now) {
+		switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
+	} else {
+		switch_snprintf(sql, sizeof(sql), "select call_id from sip_subscriptions where expires > 0");
+	}
+
+	sofia_glue_execute_sql_callback(profile,
+									SWITCH_TRUE,
+									NULL,
+									sql,
+									sofia_sub_del_callback,
+									profile);
+
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_subscriptions where expires > 0 and expires <= %ld", (long) now);
 	} else {



More information about the Freeswitch-svn mailing list