From 8f08c7a21ef506fdb97816d2be96a2a5e17e6527 Mon Sep 17 00:00:00 2001 From: James Booth Date: Sun, 7 Sep 2014 21:50:59 +0100 Subject: Added error handling for /ping command responses --- src/xmpp/iq.c | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/xmpp') diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 17269fe2..6bb2e8a5 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -261,6 +261,8 @@ static int _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, void * const userdata) { + xmpp_ctx_t * const ctx = connection_get_ctx(); + GDateTime *sent = (GDateTime *)userdata; GDateTime *now = g_date_time_new_now_local(); @@ -271,6 +273,44 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, g_date_time_unref(now); char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM); + char *type = xmpp_stanza_get_type(stanza); + + // handle error responses + if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { + xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR); + + // no error stanza + if (error == NULL) { + handle_ping_error_result(from, NULL); + return 0; + } + + // no children of error stanza + xmpp_stanza_t *error_child = xmpp_stanza_get_children(error); + if (error_child == NULL) { + handle_ping_error_result(from, NULL); + return 0; + } + + // text child found + xmpp_stanza_t *error_text_stanza = xmpp_stanza_get_child_by_name(error, STANZA_NAME_TEXT); + if (error_text_stanza != NULL) { + char *error_text = xmpp_stanza_get_text(error_text_stanza); + + // text found + if (error_text != NULL) { + handle_ping_error_result(from, error_text); + xmpp_free(ctx, error_text); + return 0; + } + + // no text child found + } else { + char *error_child_name = xmpp_stanza_get_name(error_child); + handle_ping_error_result(from, error_child_name); + return 0; + } + } handle_ping_result(from, elapsed_millis); -- cgit 1.4.1-2-gfad0