]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add reboot options to flush_inbound_reg
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 17 Jul 2008 20:47:42 +0000 (20:47 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 17 Jul 2008 20:47:42 +0000 (20:47 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@9077 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia.c
src/mod/endpoints/mod_sofia/sofia_presence.c
src/mod/endpoints/mod_sofia/sofia_reg.c

index d547a5065665f138d46cd7f3bee468db8f192897..636f83a840783194e116554b78a6c46816a25953 100644 (file)
@@ -1394,12 +1394,25 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
        }
 
        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;
index 47e56ec96870427f79eb9aa83dbc681bb347cb62..1228671ab701c26634fb8c1696700e27000db660 100644 (file)
@@ -563,7 +563,7 @@ void sofia_presence_handle_sip_i_subscribe(int status,
 
 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 @@ switch_status_t sofia_glue_build_crypto(private_object_t *tech_pvt, int index, s
 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);
index 9e6f426d78fb41cfa0a4a314686a418ffab76586..9e99fefa6c2454aac1b9bdcae6596583ffc82e3a 100644 (file)
@@ -449,7 +449,7 @@ void *SWITCH_THREAD_FUNC sofia_profile_worker_thread_run(switch_thread_t *thread
 
                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;
                        }
 
index 9cebbff4573ceb91233c20e8f5513e378514e41a..49d11f9e2d3dfde0579dcbe145e79e206e15b83a 100644 (file)
@@ -1160,7 +1160,7 @@ static int sofia_presence_mwi_callback2(void *pArg, int argc, char **argv, char
 
        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);
index 9bba11a79a254c4375efac81ce0475ad091a7b6e..a09b269883afa5844e31404fabc69a65510f5b7d 100644 (file)
@@ -237,9 +237,57 @@ int sofia_sub_del_callback(void *pArg, int argc, char **argv, char **columnNames
        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 @@ int sofia_reg_del_callback(void *pArg, int argc, char **argv, char **columnNames
        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);
 
-       switch_snprintf(sql, sizeof(sql), "select *,'%s' from sip_registrations where call_id='%s'", profile->name, call_id);
+       if ((host = strchr(user, '@'))) {
+               *host++ = '\0';
+       }
+       
+       if (!host) {
+               host = "none";
+       }
+
+       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 @@ void sofia_reg_check_expire(sofia_profile_t *profile, time_t now)
        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 {