about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-10 22:49:58 +0100
committerJames Booth <boothj5@gmail.com>2016-05-10 22:49:58 +0100
commit22c4d91c5068d1fd194ee0383dc6f4b5cf86cdeb (patch)
tree622f5fb248ccc8c40a2dbbfbb42807e7fd40089a
parent02bc4f217cd349c48f99520037ec31e2c9308bb9 (diff)
downloadprofani-tty-22c4d91c5068d1fd194ee0383dc6f4b5cf86cdeb.tar.gz
Remove _session_free_session_data from session.c
-rw-r--r--src/xmpp/connection.c3
-rw-r--r--src/xmpp/session.c80
2 files changed, 44 insertions, 39 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 2b508288..c93cb35a 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -77,7 +77,8 @@ TLSCertificate* _xmppcert_to_profcert(xmpp_tlscert_t *xmpptlscert);
 static int _connection_certfail_cb(xmpp_tlscert_t *xmpptlscert, const char *const errormsg);
 #endif
 
-void connection_init(void)
+void
+connection_init(void)
 {
     xmpp_initialize();
     conn.conn_status = JABBER_STARTED;
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index dd26c5e3..b435a579 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -87,7 +87,6 @@ static void _session_reconnect(void);
 
 static void _session_free_saved_account(void);
 static void _session_free_saved_details(void);
-static void _session_free_session_data(void);
 
 void
 session_init(void)
@@ -218,8 +217,10 @@ session_disconnect(void)
         }
         _session_free_saved_account();
         _session_free_saved_details();
-        _session_free_session_data();
-
+        connection_disco_items_free();
+        connection_remove_all_available_resources();
+        chat_sessions_clear();
+        presence_clear_sub_requests();
         connection_free_conn();
         connection_free_ctx();
     }
@@ -235,7 +236,10 @@ session_shutdown(void)
 {
     _session_free_saved_account();
     _session_free_saved_details();
-    _session_free_session_data();
+    connection_disco_items_free();
+    connection_remove_all_available_resources();
+    chat_sessions_clear();
+    presence_clear_sub_requests();
     xmpp_shutdown();
     connection_free_log();
 }
@@ -248,22 +252,22 @@ session_process_events(int millis)
     jabber_conn_status_t conn_status = connection_get_status();
     switch (conn_status)
     {
-        case JABBER_CONNECTED:
-        case JABBER_CONNECTING:
-        case JABBER_DISCONNECTING:
-            xmpp_run_once(connection_get_ctx(), millis);
-            break;
-        case JABBER_DISCONNECTED:
-            reconnect_sec = prefs_get_reconnect();
-            if ((reconnect_sec != 0) && reconnect_timer) {
-                int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
-                if (elapsed_sec > reconnect_sec) {
-                    _session_reconnect();
-                }
+    case JABBER_CONNECTED:
+    case JABBER_CONNECTING:
+    case JABBER_DISCONNECTING:
+        xmpp_run_once(connection_get_ctx(), millis);
+        break;
+    case JABBER_DISCONNECTED:
+        reconnect_sec = prefs_get_reconnect();
+        if ((reconnect_sec != 0) && reconnect_timer) {
+            int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
+            if (elapsed_sec > reconnect_sec) {
+                _session_reconnect();
             }
-            break;
-        default:
-            break;
+        }
+        break;
+    default:
+        break;
     }
 }
 
@@ -327,14 +331,20 @@ session_login_failed(void)
         sv_ev_failed_login();
         _session_free_saved_account();
         _session_free_saved_details();
-        _session_free_session_data();
+        connection_disco_items_free();
+        connection_remove_all_available_resources();
+        chat_sessions_clear();
+        presence_clear_sub_requests();
     } else {
         log_debug("Connection handler: Restarting reconnect timer");
         if (prefs_get_reconnect() != 0) {
             g_timer_start(reconnect_timer);
         }
         // free resources but leave saved_user untouched
-        _session_free_session_data();
+        connection_disco_items_free();
+        connection_remove_all_available_resources();
+        chat_sessions_clear();
+        presence_clear_sub_requests();
     }
 }
 
@@ -349,7 +359,10 @@ session_lost_connection(void)
         _session_free_saved_account();
         _session_free_saved_details();
     }
-    _session_free_session_data();
+    connection_disco_items_free();
+    connection_remove_all_available_resources();
+    chat_sessions_clear();
+    presence_clear_sub_requests();
 }
 
 static void
@@ -357,16 +370,16 @@ _session_reconnect(void)
 {
     // reconnect with account.
     ProfAccount *account = accounts_get_account(saved_account.name);
-
     if (account == NULL) {
         log_error("Unable to reconnect, account no longer exists: %s", saved_account.name);
-    } else {
-        char *fulljid = create_fulljid(account->jid, account->resource);
-        log_debug("Attempting reconnect with account %s", account->name);
-        connection_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
-        free(fulljid);
-        g_timer_start(reconnect_timer);
+        return;
     }
+
+    char *fulljid = create_fulljid(account->jid, account->resource);
+    log_debug("Attempting reconnect with account %s", account->name);
+    connection_connect(fulljid, saved_account.passwd, account->server, account->port, account->tls_policy);
+    free(fulljid);
+    g_timer_start(reconnect_timer);
 }
 
 static void
@@ -386,12 +399,3 @@ _session_free_saved_details(void)
     FREE_SET_NULL(saved_details.tls_policy);
 }
 
-static void
-_session_free_session_data(void)
-{
-    connection_disco_items_free();
-    connection_remove_all_available_resources();
-    chat_sessions_clear();
-    presence_clear_sub_requests();
-}
-