about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2019-06-03 13:11:41 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2019-06-03 13:21:52 +0300
commit4344ee2a5a5f4139d45edace5b1d22b159358f25 (patch)
treea8ba3127c01134f1490e954aa189567df4a884c2
parent5b4277840a9822945ccdb552a0a56cc3a62c49f3 (diff)
downloadprofani-tty-4344ee2a5a5f4139d45edace5b1d22b159358f25.tar.gz
Don't clear saved account data in session_disconnect()
If connection loss occurs, it calls session_disconnect() eventually.
This function clears saved account data which is required for
reconnection. Therefore, when reconnect timer expires, we get errors:

02/06/2019 04:53:42: stderr: ERR: (profanity:17115): GLib-CRITICAL **:
                     04:53:42.305: g_key_file_has_group: assertion
                     'group_name != NULL' failed
02/06/2019 04:53:43: prof: ERR: Unable to reconnect, account no longer
                     exists: (null)

To solve it, don't clear the saved data in session_disconnect(). It will
be cleared properly on connection loss if reconnect timer is not
configured. But won't be cleared with /disconnect command.
So, after /disconnect the data will live in memory until the next
/connect.

Also, remove some copy-paste in connection loss path.
-rw-r--r--src/xmpp/session.c35
1 files changed, 7 insertions, 28 deletions
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index 67cbb17f..b2b56695 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -113,14 +113,11 @@ session_connect_with_account(const ProfAccount *const account)
 
     log_info("Connecting using account: %s", account->name);
 
+    _session_free_saved_account();
+    _session_free_saved_details();
+
     // save account name and password for reconnect
-    if (saved_account.name) {
-        free(saved_account.name);
-    }
     saved_account.name = strdup(account->name);
-    if (saved_account.passwd) {
-        free(saved_account.passwd);
-    }
     saved_account.passwd = strdup(account->password);
 
     char *jid = NULL;
@@ -150,6 +147,9 @@ session_connect_with_details(const char *const jid, const char *const passwd, co
     assert(jid != NULL);
     assert(passwd != NULL);
 
+    _session_free_saved_account();
+    _session_free_saved_details();
+
     // save details for reconnect, remember name for account creating on success
     saved_details.name = strdup(jid);
     saved_details.passwd = strdup(passwd);
@@ -196,20 +196,6 @@ session_connect_with_details(const char *const jid, const char *const passwd, co
 void
 session_autoping_fail(void)
 {
-    if (connection_get_status() == JABBER_CONNECTED) {
-        log_info("Closing connection");
-
-        char *account_name = session_get_account_name();
-        const char *fulljid = connection_get_fulljid();
-        plugins_on_disconnect(account_name, fulljid);
-
-        accounts_set_last_activity(session_get_account_name());
-
-        connection_disconnect();
-    }
-
-    connection_set_disconnected();
-
     session_lost_connection();
 }
 
@@ -230,11 +216,7 @@ session_disconnect(void)
 
         connection_disconnect();
 
-        _session_free_saved_account();
-        _session_free_saved_details();
-
         connection_clear_data();
-
         chat_sessions_clear();
         presence_clear_sub_requests();
     }
@@ -359,6 +341,7 @@ session_login_failed(void)
 void
 session_lost_connection(void)
 {
+    /* this callback also clears all cached data */
     sv_ev_lost_connection();
     if (prefs_get_reconnect() != 0) {
         assert(reconnect_timer == NULL);
@@ -367,10 +350,6 @@ session_lost_connection(void)
         _session_free_saved_account();
         _session_free_saved_details();
     }
-
-    connection_clear_data();
-    chat_sessions_clear();
-    presence_clear_sub_requests();
 }
 
 void