about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorDmitry Podgorny <pasis.ua@gmail.com>2019-06-03 13:04:04 +0300
committerDmitry Podgorny <pasis.ua@gmail.com>2019-06-03 13:28:00 +0300
commit6138a5f79be3e5f1c36f94accf7b836ca23a1bc6 (patch)
tree3c10d9e1ac9206b452417b4287ef69142a9eee2e
parent5b4277840a9822945ccdb552a0a56cc3a62c49f3 (diff)
downloadprofani-tty-6138a5f79be3e5f1c36f94accf7b836ca23a1bc6.tar.gz
Cancel autoping timer on disconnect or connection loss
If Profanity is disconnected in any way before ping response is
received, the autoping timer will expire after the next connection
is established. As result, user will be disconnected immediately.

Cancel autoping timer in ev_disconnect_cleanup(), so it is done
for all kind of disconnections.
-rw-r--r--src/event/common.c1
-rw-r--r--src/xmpp/iq.c20
-rw-r--r--src/xmpp/xmpp.h1
-rw-r--r--tests/unittests/xmpp/stub_xmpp.c1
4 files changed, 15 insertions, 8 deletions
diff --git a/src/event/common.c b/src/event/common.c
index 062e680b..dd5ede98 100644
--- a/src/event/common.c
+++ b/src/event/common.c
@@ -53,6 +53,7 @@ ev_disconnect_cleanup(void)
     ui_disconnected();
     session_disconnect();
     roster_destroy();
+    iq_autoping_timer_cancel();
     muc_invites_clear();
     muc_confserver_clear();
     chat_sessions_clear();
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 7800ef3c..24208244 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -263,6 +263,16 @@ iq_id_handler_add(const char *const id, ProfIqCallback func, ProfIqFreeCallback
 }
 
 void
+iq_autoping_timer_cancel(void)
+{
+    autoping_wait = FALSE;
+    if (autoping_time) {
+        g_timer_destroy(autoping_time);
+        autoping_time = NULL;
+    }
+}
+
+void
 iq_autoping_check(void)
 {
     if (connection_get_status() != JABBER_CONNECTED) {
@@ -283,10 +293,8 @@ iq_autoping_check(void)
     if (timeout > 0 && seconds_elapsed >= timeout) {
         cons_show("Autoping response timed out after %u seconds.", timeout);
         log_debug("Autoping check: timed out after %u seconds, disconnecting", timeout);
+        iq_autoping_timer_cancel();
         session_autoping_fail();
-        autoping_wait = FALSE;
-        g_timer_destroy(autoping_time);
-        autoping_time = NULL;
     }
 }
 
@@ -1371,11 +1379,7 @@ _autoping_timed_send(xmpp_conn_t *const conn, void *const userdata)
 static int
 _auto_pong_id_handler(xmpp_stanza_t *const stanza, void *const userdata)
 {
-    autoping_wait = FALSE;
-    if (autoping_time) {
-        g_timer_destroy(autoping_time);
-        autoping_time = NULL;
-    }
+    iq_autoping_timer_cancel();
 
     const char *id = xmpp_stanza_get_id(stanza);
     if (id == NULL) {
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index d5330599..d04d88fd 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -187,6 +187,7 @@ void iq_room_affiliation_set(const char *const room, const char *const jid, char
 void iq_room_kick_occupant(const char *const room, const char *const nick, const char *const reason);
 void iq_room_role_set(const char *const room, const char *const nick, char *role, const char *const reason);
 void iq_room_role_list(const char * const room, char *role);
+void iq_autoping_timer_cancel(void);
 void iq_autoping_check(void);
 void iq_http_upload_request(HTTPUpload *upload);
 void iq_command_list(const char *const target);
diff --git a/tests/unittests/xmpp/stub_xmpp.c b/tests/unittests/xmpp/stub_xmpp.c
index df862b9b..41870d73 100644
--- a/tests/unittests/xmpp/stub_xmpp.c
+++ b/tests/unittests/xmpp/stub_xmpp.c
@@ -206,6 +206,7 @@ void iq_room_role_set(const char * const room, const char * const nick, char *ro
     const char * const reason) {}
 void iq_room_role_list(const char * const room, char *role) {}
 void iq_last_activity_request(gchar *jid) {}
+void iq_autoping_timer_cancel(void) {}
 void iq_autoping_check(void) {}
 void iq_rooms_cache_clear(void) {}
 void iq_command_list(const char *const target) {}