From e668c4f7df2b68a8a1efb27e58a8450e18d11d4e Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 22 May 2023 16:58:57 +0200 Subject: [PATCH 1/4] Extend autoping timer on each stanza we receive. Sometimes the server is too busy sending other stanzas or our connection is saturated because of something else, so the pong arrives too late. Prevent the autoping disconnect event by extending the timeout each time a stanza is received. Signed-off-by: Steffen Jaeckel --- src/xmpp/iq.c | 10 ++++++++-- src/xmpp/message.c | 1 + src/xmpp/presence.c | 1 + src/xmpp/xmpp.h | 2 ++ 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 1e4c272a..dbadd468 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -176,8 +176,7 @@ static int _iq_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("iq stanza handler fired"); - - iq_autoping_timer_cancel(); // reset the autoping timer + autoping_timer_extend(); char* text; size_t text_size; @@ -1391,6 +1390,13 @@ _autoping_timed_send(xmpp_conn_t* const conn, void* const userdata) return 1; } +void +autoping_timer_extend(void) +{ + if (autoping_time) + g_timer_start(autoping_time); +} + static int _auto_pong_id_handler(xmpp_stanza_t* const stanza, void* const userdata) { diff --git a/src/xmpp/message.c b/src/xmpp/message.c index ad9f545e..e9ee166d 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -153,6 +153,7 @@ static int _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("Message stanza handler fired"); + autoping_timer_extend(); if (_handled_by_plugin(stanza)) { return 1; diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c index 36c2f6a9..2b0ae7f7 100644 --- a/src/xmpp/presence.c +++ b/src/xmpp/presence.c @@ -347,6 +347,7 @@ static int _presence_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* const userdata) { log_debug("Presence stanza handler fired"); + autoping_timer_extend(); char* text = NULL; size_t text_size; diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h index 2babe536..cc0b62e7 100644 --- a/src/xmpp/xmpp.h +++ b/src/xmpp/xmpp.h @@ -269,6 +269,8 @@ void iq_mam_request_older(ProfChatWin* win); void iq_register_change_password(const char* const user, const char* const password); void iq_muc_register_nick(const char* const roomjid); +void autoping_timer_extend(void); + EntityCapabilities* caps_lookup(const char* const jid); void caps_close(void); void caps_destroy(EntityCapabilities* caps); From 6f1ea087c890aab1b11414a11625bc2db4531854 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Mon, 22 May 2023 16:59:48 +0200 Subject: [PATCH 2/4] Fix memleak. In some cases it was possible that the `roster_pending_presence` list was not free'd correctly. Signed-off-by: Steffen Jaeckel --- src/xmpp/roster_list.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/xmpp/roster_list.c b/src/xmpp/roster_list.c index a104f9cd..b5a60db7 100644 --- a/src/xmpp/roster_list.c +++ b/src/xmpp/roster_list.c @@ -104,6 +104,17 @@ roster_create(void) roster_pending_presence = NULL; } +static void +_pendingPresence_free(ProfPendingPresence* presence) +{ + if (!presence) + return; + if (presence->last_activity) + g_date_time_unref(presence->last_activity); + free(presence->barejid); + free(presence); +} + void roster_destroy(void) { @@ -119,6 +130,10 @@ roster_destroy(void) free(roster); roster = NULL; + + if (roster_pending_presence) + g_slist_free_full(roster_pending_presence, (GDestroyNotify)_pendingPresence_free); + roster_pending_presence = NULL; } gboolean @@ -716,15 +731,6 @@ roster_compare_presence(PContact a, PContact b) } } -static void -_pendingPresence_free(ProfPendingPresence* presence) -{ - if (!presence) - return; - free(presence->barejid); - free(presence); -} - void roster_process_pending_presence(void) { @@ -734,10 +740,6 @@ roster_process_pending_presence(void) for (iter = roster_pending_presence; iter != NULL; iter = iter->next) { ProfPendingPresence* presence = iter->data; roster_update_presence(presence->barejid, presence->resource, presence->last_activity); - /* seems like resource isn't free on the calling side */ - if (presence->last_activity) { - g_date_time_unref(presence->last_activity); - } } g_slist_free_full(roster_pending_presence, (GDestroyNotify)_pendingPresence_free); From 2b29d1baf3e4dfbc5f2ceafc2e2e3388b6b15452 Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 4 Oct 2023 16:34:08 +0200 Subject: [PATCH 3/4] Fix some glib nullptr-check warning messages Signed-off-by: Steffen Jaeckel --- src/config/accounts.c | 2 +- src/event/server_events.c | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/config/accounts.c b/src/config/accounts.c index 51a7b9cd..16edc219 100644 --- a/src/config/accounts.c +++ b/src/config/accounts.c @@ -481,7 +481,7 @@ static void _accounts_set_string_option(const char* account_name, const char* const option, const char* const value) { if (accounts_account_exists(account_name)) { - g_key_file_set_string(accounts, account_name, option, value); + g_key_file_set_string(accounts, account_name, option, value ?: ""); _save_accounts(); } } diff --git a/src/event/server_events.c b/src/event/server_events.c index 66ee65a9..1638cc7f 100644 --- a/src/event/server_events.c +++ b/src/event/server_events.c @@ -300,7 +300,8 @@ sv_ev_room_history(ProfMessage* message) ProfMucWin* mucwin = wins_get_muc(message->from_jid->barejid); if (mucwin) { // if this is the first successful connection - if (ev_is_first_connect()) { + // or for some reason the `last_msg_timestamp` is not initialized + if (ev_is_first_connect() || !mucwin->last_msg_timestamp) { // save timestamp of last received muc message // so we dont display, if there was no activity in channel, once we reconnect if (mucwin->last_msg_timestamp) { From 970cb706fbd503de7fc28583725e7ace9f15ad9c Mon Sep 17 00:00:00 2001 From: Steffen Jaeckel Date: Wed, 4 Oct 2023 16:44:17 +0200 Subject: [PATCH 4/4] Minor changes * slightly improve PR template * update gitignore Signed-off-by: Steffen Jaeckel --- .github/pull_request_template.md | 9 +++++---- .gitignore | 6 ++++++ 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 4a8702a3..26c901b2 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,9 @@ -# How to test the functionality -* step 1 + +- [ ] I ran valgrind when using my new feature -# I ran valgrind when using my new feature -yes/no +### How to test the functionality +* step 1 +* step 2 diff --git a/.gitignore b/.gitignore index eafcb988..75c8a5f4 100644 --- a/.gitignore +++ b/.gitignore @@ -43,6 +43,9 @@ src/gitversion.h.in src/stamp-h1 src/plugins/profapi.lo +# out-of-tree build folders +build*/ + # binaries profanity **/*.o @@ -89,8 +92,11 @@ python2/ python3/ .DS_Store +.gdbinit *.bak *.orig +*.patch +*.rej breaks *.tar.*