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

Freeswitch SVN anthm at freeswitch.org
Thu Jul 17 16:47:42 EDT 2008


Author: anthm
Date: Thu Jul 17 16:47:42 2008
New Revision: 9077

Modified:
   freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
   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:
add reboot options to flush_inbound_reg

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	Thu Jul 17 16:47:42 2008
@@ -1394,12 +1394,25 @@
 	}
 
 	if (!strcasecmp(argv[1], "flush_inbound_reg")) {
+		int reboot = 0;
+
 		if (argc > 2) {
-			sofia_reg_expire_call_id(profile, argv[2]);
-			stream->write_function(stream, "+OK flushing all registrations matching specified call_id\n");
+			if (!strcasecmp(argv[2], "reboot")) {
+				reboot = 1;
+				argc = 2;
+			}
+		}
+
+		if (argc > 2) {
+			if (argc > 3 && !strcasecmp(argv[3], "reboot")) {
+				reboot = 1;
+			}
+
+			sofia_reg_expire_call_id(profile, argv[2], reboot);
+			stream->write_function(stream, "+OK %s all registrations matching specified call_id\n", reboot ? "rebooting" : "flushing");
 		} else {
-			sofia_reg_check_expire(profile, 0);
-			stream->write_function(stream, "+OK flushing all registrations\n");
+			sofia_reg_check_expire(profile, 0, reboot);
+			stream->write_function(stream, "+OK %s all registrations\n", reboot ? "rebooting" : "flushing");
 		}
 
 		goto done;

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	Thu Jul 17 16:47:42 2008
@@ -563,7 +563,7 @@
 
 void sofia_glue_execute_sql(sofia_profile_t *profile, char **sqlp, switch_bool_t sql_already_dynamic);
 void sofia_glue_actually_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex);
-void sofia_reg_check_expire(sofia_profile_t *profile, time_t now);
+void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot);
 void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now);
 void sofia_reg_unregister(sofia_profile_t *profile);
 switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool);
@@ -651,9 +651,10 @@
 void sofia_glue_tech_patch_sdp(private_object_t *tech_pvt);
 switch_status_t sofia_glue_tech_proxy_remote_addr(private_object_t *tech_pvt);
 void sofia_presence_event_thread_start(void);
-void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id);
+void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot);
 switch_status_t sofia_glue_tech_choose_video_port(private_object_t *tech_pvt, int force);
 switch_status_t sofia_glue_tech_set_video_codec(private_object_t *tech_pvt, int force);
 const char *sofia_glue_strip_proto(const char *uri);
 switch_status_t reconfig_sofia(sofia_profile_t *profile);
 void sofia_glue_del_gateway(sofia_gateway_t *gp);
+void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent);

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	Thu Jul 17 16:47:42 2008
@@ -449,7 +449,7 @@
 
 		if (++loops >= 100) {
 			if (++ireg_loops >= IREG_SECONDS) {
-				sofia_reg_check_expire(profile, switch_timestamp(NULL));
+				sofia_reg_check_expire(profile, switch_timestamp(NULL), 0);
 				ireg_loops = 0;
 			}
 

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 Jul 17 16:47:42 2008
@@ -1160,7 +1160,7 @@
 
 	nua_notify(nh,
 			   NUTAG_NEWSUB(1),
-			   TAG_IF(strstr(o_contact, ";nat"), NUTAG_PROXY(contact)),
+			   TAG_IF(strstr(o_contact, ";fs_nat"), NUTAG_PROXY(contact)),
 			   SIPTAG_EVENT_STR(event), SIPTAG_CONTENT_TYPE_STR("application/simple-message-summary"), SIPTAG_PAYLOAD_STR(body), TAG_END());
 
 	switch_safe_free(contact);

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 Jul 17 16:47:42 2008
@@ -237,9 +237,57 @@
 	return 0;
 }
 
+void sofia_reg_send_reboot(sofia_profile_t *profile, const char *user, const char *host, const char *contact, const char *user_agent)
+{
+	const char *event = "check-sync";
+	nua_handle_t *nh;
+	char *contact_url = NULL;
+	char *id = NULL;
+
+	if (switch_stristr("snom", user_agent)) {
+		event = "check-sync;reboot=true";
+	} else if (switch_stristr("linksys", user_agent)) {
+		event = "reboot_now";
+	}
+
+	if ((contact_url = sofia_glue_get_url_from_contact((char *)contact, 1))) {
+		char *p;
+		id = switch_mprintf("sip:%s@%s", user, host);
+
+		if ((p = strstr(contact_url, ";fs_"))) {
+			*p = '\0';
+		}
+		
+		nh = nua_handle(profile->nua, NULL, 
+						NUTAG_URL(contact_url), 
+						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(""),
+				   TAG_END());
+
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Sending reboot command to %s\n", contact_url);
+		free(contact_url);
+	}
+
+	switch_safe_free(id);
+}
+
+
 int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	switch_event_t *s_event;
+	sofia_profile_t *profile = (sofia_profile_t *) pArg;
+	
+	if (argc > 10 && atoi(argv[10]) == 1) {
+		sofia_reg_send_reboot(profile, argv[1], argv[2], argv[3], argv[7]);
+	}
 
 	if (argc >= 3) {
 		if (switch_event_create_subclass(&s_event, SWITCH_EVENT_CUSTOM, MY_EVENT_EXPIRE) == SWITCH_STATUS_SUCCESS) {
@@ -256,21 +304,39 @@
 	return 0;
 }
 
-void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id)
+void sofia_reg_expire_call_id(sofia_profile_t *profile, const char *call_id, int reboot)
 {
 	char sql[1024];
 	char *psql = sql;
+	char *user = strdup(call_id);
+	char *host = NULL;
+
+	switch_assert(user);
+
+	if ((host = strchr(user, '@'))) {
+		*host++ = '\0';
+	}
+	
+	if (!host) {
+		host = "none";
+	}
 
-	switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id);
+	switch_snprintf(sql, sizeof(sql), "select *,%d from sip_registrations where call_id='%s' or (sip_user='%s' && sip_host='%s')", 
+					reboot, call_id, user, host);
+	
 	switch_mutex_lock(profile->ireg_mutex);
-	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile);
 	switch_mutex_unlock(profile->ireg_mutex);
 
-	switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s'", call_id);
+	switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where call_id='%s' or (sip_user='%s' && sip_host='%s')", 
+					call_id, user, host);
 	sofia_glue_execute_sql(profile, &psql, SWITCH_FALSE);
+
+	switch_safe_free(user);
+
 }
 
-void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
+void sofia_reg_check_expire(sofia_profile_t *profile, time_t now, int reboot)
 {
 	char sql[1024];
 
@@ -294,12 +360,12 @@
 	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);
+		switch_snprintf(sql, sizeof(sql), "select *,%d from sip_registrations where expires > 0 and expires <= %ld", reboot, (long) now);
 	} else {
-		switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where expires > 0", profile->name);
+		switch_snprintf(sql, sizeof(sql), "select *,%d from sip_registrations where expires > 0", reboot);
 	}
 
-	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, NULL);
+	sofia_glue_execute_sql_callback(profile, SWITCH_TRUE, NULL, sql, sofia_reg_del_callback, profile);
 	if (now) {
 		switch_snprintf(sql, sizeof(sql), "delete from sip_registrations where expires > 0 and expires <= %ld", (long) now);
 	} else {



More information about the Freeswitch-svn mailing list