]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-3029 --resolve
authorMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 23 Dec 2011 21:07:33 +0000 (16:07 -0500)
committerMarc Olivier Chouinard <mochouinard@moctel.com>
Fri, 23 Dec 2011 21:07:33 +0000 (16:07 -0500)
src/mod/endpoints/mod_sofia/mod_sofia.c
src/mod/endpoints/mod_sofia/mod_sofia.h
src/mod/endpoints/mod_sofia/sofia_glue.c

index b748e6147eb564f22563bfe9be2c1c46354b8297..c02f1f8ee1a3a0748685c19fca8329afc1b8816b 100644 (file)
@@ -3516,6 +3516,22 @@ static switch_status_t cmd_profile(char **argv, int argc, switch_stream_handle_t
 
                goto done;
        }
+       
+       if (!strcasecmp(argv[1], "recover")) {
+               if (argv[2] && !strcasecmp(argv[2], "flush")) {
+                       sofia_glue_profile_recover(profile, SWITCH_TRUE);
+                       stream->write_function(stream, "Flushing recovery database.\n");
+               } else {
+                       int x = sofia_glue_profile_recover(profile, SWITCH_FALSE);
+                       if (x) {
+                               stream->write_function(stream, "Recovered %d call(s)\n", x);
+                       } else {
+                               stream->write_function(stream, "No calls to recover.\n");
+                       }
+               }
+
+               goto done;
+       }
 
        if (!strcasecmp(argv[1], "register")) {
                char *gname = argv[2];
index 984c80f39f3c5242a108ca1ab400fda1c04dee74..490fe1a9d43b2d51cae9df37c0b8d991a052063c 100644 (file)
@@ -1120,6 +1120,7 @@ int sofia_sla_supported(sip_t const *sip);
 void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *session, switch_bool_t force);
 void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *session);
 int sofia_glue_recover(switch_bool_t flush);
+int sofia_glue_profile_recover(sofia_profile_t *profile, switch_bool_t flush);
 void sofia_profile_destroy(sofia_profile_t *profile);
 switch_status_t sip_dig_function(_In_opt_z_ const char *cmd, _In_opt_ switch_core_session_t *session, _In_ switch_stream_handle_t *stream);
 const char *sofia_gateway_status_name(sofia_gateway_status_t status);
index 472efe9003497d46465fc98acd3aaa19b3d55bce..a2b2580f1fba50bc83cf4b3b932c251a54ed8faa 100644 (file)
@@ -5715,7 +5715,6 @@ static int recover_callback(void *pArg, int argc, char **argv, char **columnName
 int sofia_glue_recover(switch_bool_t flush)
 {
        sofia_profile_t *profile;
-       char *sql;
        int r = 0;
        switch_console_callback_match_t *matches;
 
@@ -5724,34 +5723,44 @@ int sofia_glue_recover(switch_bool_t flush)
                switch_console_callback_match_node_t *m;
                for (m = matches->head; m; m = m->next) {
                        if ((profile = sofia_glue_find_profile(m->val))) {
+                               r += sofia_glue_profile_recover(profile, flush);
+                       }
+               }
+               switch_console_free_matches(&matches);
+       }
+       return r;
+}
 
-                               struct recover_helper h = { 0 };
-                               h.profile = profile;
-                               h.total = 0;
+int sofia_glue_profile_recover(sofia_profile_t *profile, switch_bool_t flush)
+{
+       char *sql;                              
+       int r = 0;
 
-                               sofia_clear_pflag_locked(profile, PFLAG_STANDBY);
+       if (profile) {
+               struct recover_helper h = { 0 };
+               h.profile = profile;
+               h.total = 0;
 
-                               if (flush) {
-                                       sql = switch_mprintf("delete from sip_recovery where profile_name='%q'", profile->name);
-                                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
-                               } else {
+               sofia_clear_pflag_locked(profile, PFLAG_STANDBY);
 
-                                       sql = switch_mprintf("select profile_name, hostname, uuid, metadata "
-                                                                                "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+               if (flush) {
+                       sql = switch_mprintf("delete from sip_recovery where profile_name='%q'", profile->name);
+                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
+               } else {
 
-                                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, recover_callback, &h);
-                                       r += h.total;
-                                       free(sql);
-                                       sql = NULL;
+                       sql = switch_mprintf("select profile_name, hostname, uuid, metadata "
+                                                                "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
 
-                                       sql = switch_mprintf("delete "
-                                                                                "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+                       sofia_glue_execute_sql_callback(profile, profile->ireg_mutex, sql, recover_callback, &h);
+                       r += h.total;
+                       free(sql);
+                       sql = NULL;
 
-                                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
-                               }
-                       }
+                       sql = switch_mprintf("delete "
+                                                                "from sip_recovery where runtime_uuid!='%q' and profile_name='%q'", switch_core_get_uuid(), profile->name);
+
+                       sofia_glue_execute_sql_now(profile, &sql, SWITCH_TRUE);
                }
-               switch_console_free_matches(&matches);
        }
 
        return r;