about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-10 23:53:44 +0100
committerJames Booth <boothj5@gmail.com>2016-05-10 23:53:44 +0100
commit7e079f3684b3dc863130716ccca3decec6d0d4b3 (patch)
tree60f88ed1868e276b33e69d1fb03fb4329a989c2c /src/xmpp
parenta7fa27df01057e31e1227213b4d0a6e275887ce0 (diff)
downloadprofani-tty-7e079f3684b3dc863130716ccca3decec6d0d4b3.tar.gz
Add connection_clear_data()
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c29
-rw-r--r--src/xmpp/connection.h4
-rw-r--r--src/xmpp/session.c20
3 files changed, 21 insertions, 32 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 13bda812..283d0efb 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -81,10 +81,10 @@ void
 connection_init(void)
 {
     xmpp_initialize();
-    conn.conn_status = JABBER_DISCONNECTED;
-    conn.presence_message = NULL;
     conn.xmpp_conn = NULL;
     conn.xmpp_ctx = NULL;
+    conn.conn_status = JABBER_DISCONNECTED;
+    conn.presence_message = NULL;
     conn.domain = NULL;
     conn.features_by_jid = NULL;
     conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
@@ -93,8 +93,7 @@ connection_init(void)
 void
 connection_shutdown(void)
 {
-    connection_disco_items_free();
-    connection_remove_all_available_resources();
+    connection_clear_data();
     xmpp_shutdown();
 
     free(conn.xmpp_log);
@@ -206,6 +205,15 @@ connection_disconnect(void)
     }
 }
 
+void
+connection_clear_data(void)
+{
+    g_hash_table_destroy(conn.features_by_jid);
+    conn.features_by_jid = NULL;
+
+    g_hash_table_remove_all(conn.available_resources);
+}
+
 #ifdef HAVE_LIBMESODE
 TLSCertificate*
 connection_get_tls_peer_cert(void)
@@ -350,12 +358,6 @@ connection_remove_available_resource(const char *const resource)
     g_hash_table_remove(conn.available_resources, resource);
 }
 
-void
-connection_remove_all_available_resources(void)
-{
-    g_hash_table_remove_all(conn.available_resources);
-}
-
 char*
 connection_create_uuid(void)
 {
@@ -409,13 +411,6 @@ connection_set_priority(const int priority)
     conn.priority = priority;
 }
 
-void
-connection_disco_items_free(void)
-{
-    g_hash_table_destroy(conn.features_by_jid);
-    conn.features_by_jid = NULL;
-}
-
 static void
 _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status, const int error,
     xmpp_stream_error_t *const stream_error, void *const userdata)
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index 5f403ae0..82ca4ab7 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -58,10 +58,10 @@ xmpp_ctx_t* connection_get_ctx(void);
 char *connection_get_domain(void);
 char* connection_jid_for_feature(const char *const feature);
 GHashTable* connection_get_features(const char *const jid);
-void connection_disco_items_free(void);
+
+void connection_clear_data(void);
 
 void connection_add_available_resource(Resource *resource);
 void connection_remove_available_resource(const char *const resource);
-void connection_remove_all_available_resources(void);
 
 #endif
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index 73b443b7..26e96863 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -208,8 +208,7 @@ session_disconnect(void)
         connection_disconnect();
         _session_free_saved_account();
         _session_free_saved_details();
-        connection_disco_items_free();
-        connection_remove_all_available_resources();
+        connection_clear_data();
         chat_sessions_clear();
         presence_clear_sub_requests();
     }
@@ -317,21 +316,16 @@ session_login_failed(void)
         sv_ev_failed_login();
         _session_free_saved_account();
         _session_free_saved_details();
-        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
-        connection_disco_items_free();
-        connection_remove_all_available_resources();
-        chat_sessions_clear();
-        presence_clear_sub_requests();
     }
+
+    connection_clear_data();
+    chat_sessions_clear();
+    presence_clear_sub_requests();
 }
 
 void
@@ -345,8 +339,8 @@ session_lost_connection(void)
         _session_free_saved_account();
         _session_free_saved_details();
     }
-    connection_disco_items_free();
-    connection_remove_all_available_resources();
+
+    connection_clear_data();
     chat_sessions_clear();
     presence_clear_sub_requests();
 }