about summary refs log tree commit diff stats
path: root/src/xmpp/iq.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-07 21:54:04 +0100
committerJames Booth <boothj5@gmail.com>2014-09-07 21:54:04 +0100
commit14ede0e44c412c7b586feb932c0b9ca2ee1b048f (patch)
tree7c53793ae67e44b7df75855ece041cf0f7743e3f /src/xmpp/iq.c
parentee6208866a1834cfea23ceec6ef2224dc05d3a24 (diff)
parent8f08c7a21ef506fdb97816d2be96a2a5e17e6527 (diff)
downloadprofani-tty-14ede0e44c412c7b586feb932c0b9ca2ee1b048f.tar.gz
Merge branch 'master' into roomconfig
Conflicts:
	src/server_events.h
Diffstat (limited to 'src/xmpp/iq.c')
-rw-r--r--src/xmpp/iq.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 2431f151..8a85177e 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -286,6 +286,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();
 
@@ -296,6 +298,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);