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

Added id handler for pings, disable ping on error type 'cancel'

This commit is contained in:
James Booth 2014-01-26 00:53:24 +00:00
parent 3d7e923254
commit 16de267906
3 changed files with 45 additions and 0 deletions

View File

@ -461,3 +461,11 @@ handle_roster_add(const char * const barejid, const char * const name)
ui_roster_add(barejid, name);
ui_current_page_off();
}
void
handle_autoping_cancel(void)
{
prefs_set_autoping(0);
cons_show_error("Server ping not supported, autoping disabled.");
ui_current_page_off();
}

View File

@ -74,5 +74,6 @@ void handle_group_remove(const char * const contact,
const char * const group);
void handle_roster_remove(const char * const barejid);
void handle_roster_add(const char * const barejid, const char * const name);
void handle_autoping_cancel(void);
#endif

View File

@ -161,6 +161,37 @@ _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
return 1;
}
static int
_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 != NULL && type != NULL) {
// show warning if error
if (strcmp(type, STANZA_TYPE_ERROR) == 0) {
log_warning("Server ping (id=%s) responded with error", 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 != NULL) {
char *errtype = xmpp_stanza_get_type(error);
if (errtype != NULL) {
if (strcmp(errtype, "cancel") == 0) {
log_warning("Server ping (id=%s) error type 'cancel', disabling autoping.", id);
handle_autoping_cancel();
xmpp_timed_handler_delete(conn, _ping_timed_handler);
}
}
}
}
}
// remove this handler
return 0;
}
static int
_ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
{
@ -169,6 +200,11 @@ _ping_timed_handler(xmpp_conn_t * const conn, void * const userdata)
if (jabber_get_connection_status() == JABBER_CONNECTED) {
xmpp_stanza_t *iq = stanza_create_ping_iq(ctx);
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);
}