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-09 22:44:14 +0100
committerJames Booth <boothj5@gmail.com>2014-09-09 22:44:14 +0100
commit9d74bdb58d349a5ec627c3f67675a7c26020e0c1 (patch)
tree29c620305ac3ff79fb4693da1f9a0d3ecd52a3eb /src/xmpp/iq.c
parentc636134566a473563aaedca8d87999f2485b0b9f (diff)
parentaa7fe0991f604a8ccee56ef8665645b1a6399d30 (diff)
downloadprofani-tty-9d74bdb58d349a5ec627c3f67675a7c26020e0c1.tar.gz
Merge branch 'master' into roomconfig
Diffstat (limited to 'src/xmpp/iq.c')
-rw-r--r--src/xmpp/iq.c66
1 files changed, 20 insertions, 46 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 69592182..9d72207e 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -233,15 +233,18 @@ _error_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
     void * const userdata)
 {
     const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
+    char *error_msg = stanza_get_error_message(stanza);
 
     if (id != NULL) {
-        log_debug("IQ error handler fired, id: %s.", id);
-        log_error("IQ error received, id: %s.", id);
+        log_debug("IQ error handler fired, id: %s, error: %s", id, error_msg);
+        log_error("IQ error received, id: %s, error: %s", id, error_msg);
     } else {
-        log_debug("IQ error handler fired.");
-        log_error("IQ error received.");
+        log_debug("IQ error handler fired, error: %s", error_msg);
+        log_error("IQ error received, error: %s", error_msg);
     }
 
+    free(error_msg);
+
     return 1;
 }
 
@@ -261,7 +264,9 @@ _pong_handler(xmpp_conn_t *const conn, xmpp_stanza_t * const 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);
+            char *error_msg = stanza_get_error_message(stanza);
+            log_warning("Server ping (id=%s) responded with error: %s", id, error_msg);
+            free(error_msg);
 
             // turn off autoping if error type is 'cancel'
             xmpp_stanza_t *error = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_ERROR);
@@ -286,7 +291,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();
@@ -297,46 +311,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;