From 6e4a9de61810e544c23c7f5e7faab77709d88efb Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 30 Dec 2015 23:42:27 +0000 Subject: [PATCH 1/4] boothj5 theme changes --- themes/boothj5 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/themes/boothj5 b/themes/boothj5 index e20a44b9..aea45c1d 100644 --- a/themes/boothj5 +++ b/themes/boothj5 @@ -70,10 +70,10 @@ resource.title=true resource.message=true statuses.console=all statuses.chat=all -statuses.muc=all +statuses.muc=none roster=true roster.offline=true -roster.empty=true +roster.empty=false roster.by=group roster.order=presence roster.count=true From a0c9b0cb7057e3b4d2f193a5f90467957f7a651a Mon Sep 17 00:00:00 2001 From: James Booth Date: Wed, 30 Dec 2015 23:50:39 +0000 Subject: [PATCH 2/4] Renamed autoping handler --- src/xmpp/iq.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 9aa8cdb7..5930f83f 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -93,7 +93,7 @@ static int _room_kick_result_handler(xmpp_conn_t *const conn, xmpp_stanza_t *con static int _enable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); static int _disable_carbons_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); -static int _ping_timed_handler(xmpp_conn_t *const conn, void *const userdata); +static int _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata); static int _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); @@ -119,7 +119,7 @@ iq_add_handlers(void) if (prefs_get_autoping() != 0) { int millis = prefs_get_autoping() * 1000; - xmpp_timed_handler_add(conn, _ping_timed_handler, millis, ctx); + xmpp_timed_handler_add(conn, _autoping_timed_handler, millis, ctx); } } @@ -130,11 +130,11 @@ iq_set_autoping(const int seconds) xmpp_ctx_t * const ctx = connection_get_ctx(); if (jabber_get_connection_status() == JABBER_CONNECTED) { - xmpp_timed_handler_delete(conn, _ping_timed_handler); + xmpp_timed_handler_delete(conn, _autoping_timed_handler); if (seconds != 0) { int millis = seconds * 1000; - xmpp_timed_handler_add(conn, _ping_timed_handler, millis, + xmpp_timed_handler_add(conn, _autoping_timed_handler, millis, ctx); } } @@ -550,7 +550,7 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); prefs_set_autoping(0); cons_show_error("Server ping not supported, autoping disabled."); - xmpp_timed_handler_delete(conn, _ping_timed_handler); + xmpp_timed_handler_delete(conn, _autoping_timed_handler); } } } @@ -839,7 +839,7 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, } static int -_ping_timed_handler(xmpp_conn_t *const conn, void *const userdata) +_autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata) { xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; From 2847e39659e40c9d0a4a7160d2a16ab221329dcc Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 31 Dec 2015 00:11:58 +0000 Subject: [PATCH 3/4] Tidy ping handlers --- src/xmpp/iq.c | 106 ++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 51 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 5930f83f..2fbc471a 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -126,18 +126,20 @@ iq_add_handlers(void) void iq_set_autoping(const int seconds) { - xmpp_conn_t * const conn = connection_get_conn(); - xmpp_ctx_t * const ctx = connection_get_ctx(); - - if (jabber_get_connection_status() == JABBER_CONNECTED) { - xmpp_timed_handler_delete(conn, _autoping_timed_handler); - - if (seconds != 0) { - int millis = seconds * 1000; - xmpp_timed_handler_add(conn, _autoping_timed_handler, millis, - ctx); - } + if (jabber_get_connection_status() != JABBER_CONNECTED) { + return; } + + xmpp_conn_t * const conn = connection_get_conn(); + xmpp_timed_handler_delete(conn, _autoping_timed_handler); + + if (seconds == 0) { + return; + } + + int millis = seconds * 1000; + xmpp_ctx_t * const ctx = connection_get_ctx(); + xmpp_timed_handler_add(conn, _autoping_timed_handler, millis, ctx); } void @@ -522,42 +524,45 @@ _error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, } static int -_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, - void *const userdata) +_auto_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { char *id = xmpp_stanza_get_id(stanza); - char *type = xmpp_stanza_get_type(stanza); - - if (id) { - log_debug("IQ pong handler fired, id: %s.", id); - } else { + if (id == NULL) { log_debug("IQ pong handler fired."); + return 0; } - if (id && type) { - // show warning if error - if (strcmp(type, STANZA_TYPE_ERROR) == 0) { - char *error_msg = stanza_get_error_message(stanza); - log_warning("Server ping (id=%s) responded with error: %s", id, error_msg); - free(error_msg); + log_debug("IQ pong handler fired, id: %s.", id); - // turn off autoping if error type is 'cancel' - xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); - if (error) { - char *errtype = xmpp_stanza_get_type(error); - if (errtype) { - if (strcmp(errtype, "cancel") == 0) { - log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); - prefs_set_autoping(0); - cons_show_error("Server ping not supported, autoping disabled."); - xmpp_timed_handler_delete(conn, _autoping_timed_handler); - } - } - } - } + char *type = xmpp_stanza_get_type(stanza); + if (type == NULL) { + return 0; + } + if (g_strcmp0(type, STANZA_TYPE_ERROR) != 0) { + return 0; + } + + // show warning if error + char *error_msg = stanza_get_error_message(stanza); + log_warning("Server ping (id=%s) responded with error: %s", id, error_msg); + free(error_msg); + + // turn off autoping if error type is 'cancel' + xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); + if (error == NULL) { + return 0; + } + char *errtype = xmpp_stanza_get_type(error); + if (errtype == NULL) { + return 0; + } + if (g_strcmp0(errtype, "cancel") == 0) { + log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id); + prefs_set_autoping(0); + cons_show_error("Server ping not supported, autoping disabled."); + xmpp_timed_handler_delete(conn, _autoping_timed_handler); } - // remove this handler return 0; } @@ -841,20 +846,19 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, static int _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata) { - xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; - - if (jabber_get_connection_status() == JABBER_CONNECTED) { - - xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL); - char *id = xmpp_stanza_get_id(iq); - - // add pong handler - xmpp_id_handler_add(conn, _pong_handler, id, ctx); - - xmpp_send(conn, iq); - xmpp_stanza_release(iq); + if (jabber_get_connection_status() != JABBER_CONNECTED) { + return 1; } + xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; + xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL); + char *id = xmpp_stanza_get_id(iq); + + // add pong handler + xmpp_id_handler_add(conn, _auto_pong_handler, id, ctx); + + xmpp_send(conn, iq); + xmpp_stanza_release(iq); return 1; } From 08d30a4a8392548afef6b61b7d72ea9299484cd9 Mon Sep 17 00:00:00 2001 From: James Booth Date: Thu, 31 Dec 2015 00:33:05 +0000 Subject: [PATCH 4/4] Abort autping when existing attempt already in progress --- src/xmpp/iq.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 2fbc471a..dc1bbc4a 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -98,6 +98,8 @@ static int _caps_response_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const static int _caps_response_handler_for_jid(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); static int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata); +static gboolean autoping_wait = FALSE; + void iq_add_handlers(void) { @@ -526,13 +528,15 @@ _error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, static int _auto_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata) { + autoping_wait = FALSE; + char *id = xmpp_stanza_get_id(stanza); if (id == NULL) { - log_debug("IQ pong handler fired."); + log_debug("Autoping: Pong handler fired."); return 0; } - log_debug("IQ pong handler fired, id: %s.", id); + log_debug("Autoping: Pong handler fired: %s.", id); char *type = xmpp_stanza_get_type(stanza); if (type == NULL) { @@ -850,15 +854,23 @@ _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata) return 1; } + if (autoping_wait) { + log_debug("Autoping: Existing ping already in progress, aborting"); + return 1; + } + xmpp_ctx_t *ctx = (xmpp_ctx_t *)userdata; xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL); char *id = xmpp_stanza_get_id(iq); + log_debug("Autoping: Sending ping request: %s", id); // add pong handler xmpp_id_handler_add(conn, _auto_pong_handler, id, ctx); xmpp_send(conn, iq); xmpp_stanza_release(iq); + autoping_wait = TRUE; + return 1; }