diff options
author | James Booth <boothj5@gmail.com> | 2014-09-09 22:26:14 +0100 |
---|---|---|
committer | James Booth <boothj5@gmail.com> | 2014-09-09 22:26:14 +0100 |
commit | 3417f25dd1116ed2f3950bc8df85d736ad0223d8 (patch) | |
tree | 6eade0b5b2806b79a2a36b9ff3b0ea76b32e09a4 /src | |
parent | 273cddd66116ea498c03caed151ebb14787f7ee0 (diff) | |
download | profani-tty-3417f25dd1116ed2f3950bc8df85d736ad0223d8.tar.gz |
Use stanza_get_error_message for pong errors
Diffstat (limited to 'src')
-rw-r--r-- | src/xmpp/iq.c | 51 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 2 |
2 files changed, 12 insertions, 41 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 6bb2e8a5..8fcd8b7b 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -261,7 +261,16 @@ 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(); + 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) { + char *error_message = stanza_get_error_message(stanza); + handle_ping_error_result(from, error_message); + free(error_message); + return 0; + } GDateTime *sent = (GDateTime *)userdata; GDateTime *now = g_date_time_new_now_local(); @@ -272,46 +281,6 @@ _manual_pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const stanza, g_date_time_unref(sent); 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); return 0; diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index e068eeed..654ba121 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -968,6 +968,8 @@ stanza_get_error_message(xmpp_stanza_t *stanza) if (error_stanza == NULL) { return strdup("unknown"); } else { + + // check for text child xmpp_stanza_t *text_stanza = xmpp_stanza_get_child_by_name(error_stanza, STANZA_NAME_TEXT); // check for text |