about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-27 23:14:41 +0000
committerJames Booth <boothj5@gmail.com>2013-02-27 23:14:41 +0000
commitaeb0bfa13c81241b14b97234e90b702d357e949a (patch)
treee0404787a628036f809e7e52d34a83a6aada25a1 /src/xmpp
parent24f0d9e6e5b63539d09d52a52e7963dd2cfc92eb (diff)
downloadprofani-tty-aeb0bfa13c81241b14b97234e90b702d357e949a.tar.gz
Init and shutdown of libstrophe moved, free resources before creating
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/connection.c36
-rw-r--r--src/xmpp/xmpp.h1
2 files changed, 25 insertions, 12 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index d3198db9..4120fd99 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -95,11 +95,14 @@ jabber_init(const int disable_tls)
     log_info("Initialising XMPP");
     jabber_conn.conn_status = JABBER_STARTED;
     jabber_conn.presence_message = NULL;
+    jabber_conn.conn = NULL;
+    jabber_conn.ctx = NULL;
     jabber_conn.tls_disabled = disable_tls;
     presence_init();
     caps_init();
     available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free,
         (GDestroyNotify)resource_destroy);
+    xmpp_initialize();
 }
 
 jabber_conn_status_t
@@ -171,8 +174,9 @@ jabber_disconnect(void)
         _connection_free_saved_details();
         _connection_free_session_data();
         xmpp_conn_release(jabber_conn.conn);
+        jabber_conn.conn = NULL;
         xmpp_ctx_free(jabber_conn.ctx);
-        xmpp_shutdown();
+        jabber_conn.ctx = NULL;
     }
 
     jabber_conn.conn_status = JABBER_STARTED;
@@ -180,6 +184,12 @@ jabber_disconnect(void)
 }
 
 void
+jabber_shutdown(void)
+{
+    xmpp_shutdown();
+}
+
+void
 jabber_process_events(void)
 {
     // run xmpp event loop if connected, connecting or disconnecting
@@ -369,15 +379,21 @@ _jabber_connect(const char * const fulljid, const char * const passwd,
     jid_destroy(jid);
 
     log_info("Connecting as %s", fulljid);
-    xmpp_initialize();
     jabber_conn.log = _xmpp_get_file_logger();
+
+    if (jabber_conn.conn != NULL) {
+        xmpp_conn_release(jabber_conn.conn);
+    }
+    if (jabber_conn.ctx != NULL) {
+        xmpp_ctx_free(jabber_conn.ctx);
+    }
     jabber_conn.ctx = xmpp_ctx_new(NULL, jabber_conn.log);
     jabber_conn.conn = xmpp_conn_new(jabber_conn.ctx);
     xmpp_conn_set_jid(jabber_conn.conn, fulljid);
     xmpp_conn_set_pass(jabber_conn.conn, passwd);
-
-    if (jabber_conn.tls_disabled)
+    if (jabber_conn.tls_disabled) {
         xmpp_conn_disable_tls(jabber_conn.conn);
+    }
 
     int connect_status = xmpp_connect_client(jabber_conn.conn, altdomain, 0,
         _connection_handler, jabber_conn.ctx);
@@ -467,14 +483,12 @@ _connection_handler(xmpp_conn_t * const conn,
             if (prefs_get_reconnect() != 0) {
                 assert(reconnect_timer == NULL);
                 reconnect_timer = g_timer_new();
-                // TODO: free resources but leave saved_user untouched
+                // free resources but leave saved_user untouched
+                _connection_free_session_data();
             } else {
                 _connection_free_saved_account();
                 _connection_free_saved_details();
                 _connection_free_session_data();
-                xmpp_conn_release(jabber_conn.conn);
-                xmpp_ctx_free(jabber_conn.ctx);
-                xmpp_shutdown();
             }
 
         // login attempt failed
@@ -486,15 +500,13 @@ _connection_handler(xmpp_conn_t * const conn,
                 _connection_free_saved_account();
                 _connection_free_saved_details();
                 _connection_free_session_data();
-                xmpp_conn_release(jabber_conn.conn);
-                xmpp_ctx_free(jabber_conn.ctx);
-                xmpp_shutdown();
             } else {
                 log_debug("Connection handler: Restarting reconnect timer");
                 if (prefs_get_reconnect() != 0) {
                     g_timer_start(reconnect_timer);
                 }
-                // TODO: free resources but leave saved_user untouched
+                // free resources but leave saved_user untouched
+                _connection_free_session_data();
             }
         }
 
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 3fc9c633..5efbdf00 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -64,6 +64,7 @@ jabber_conn_status_t jabber_connect_with_details(const char * const jid,
 jabber_conn_status_t jabber_connect_with_account(const ProfAccount * const account,
     const char * const passwd);
 void jabber_disconnect(void);
+void jabber_shutdown(void);
 void jabber_process_events(void);
 const char * jabber_get_jid(void);
 jabber_conn_status_t jabber_get_connection_status(void);