1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Abort autping when existing attempt already in progress

This commit is contained in:
James Booth 2015-12-31 00:33:05 +00:00
parent 2847e39659
commit 08d30a4a83

View File

@ -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_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 int _caps_response_handler_legacy(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *const userdata);
static gboolean autoping_wait = FALSE;
void void
iq_add_handlers(void) iq_add_handlers(void)
{ {
@ -526,13 +528,15 @@ _error_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza,
static int static int
_auto_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)
{ {
autoping_wait = FALSE;
char *id = xmpp_stanza_get_id(stanza); char *id = xmpp_stanza_get_id(stanza);
if (id == NULL) { if (id == NULL) {
log_debug("IQ pong handler fired."); log_debug("Autoping: Pong handler fired.");
return 0; 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); char *type = xmpp_stanza_get_type(stanza);
if (type == NULL) { if (type == NULL) {
@ -850,15 +854,23 @@ _autoping_timed_handler(xmpp_conn_t *const conn, void *const userdata)
return 1; 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_ctx_t *ctx = (xmpp_ctx_t *)userdata;
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL); xmpp_stanza_t *iq = stanza_create_ping_iq(ctx, NULL);
char *id = xmpp_stanza_get_id(iq); char *id = xmpp_stanza_get_id(iq);
log_debug("Autoping: Sending ping request: %s", id);
// add pong handler // add pong handler
xmpp_id_handler_add(conn, _auto_pong_handler, id, ctx); xmpp_id_handler_add(conn, _auto_pong_handler, id, ctx);
xmpp_send(conn, iq); xmpp_send(conn, iq);
xmpp_stanza_release(iq); xmpp_stanza_release(iq);
autoping_wait = TRUE;
return 1; return 1;
} }