about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-08-20 19:23:32 +0100
committerJames Booth <boothj5@gmail.com>2016-08-20 19:23:32 +0100
commitd61abd35776e2dd448ce9a0cd6576d6ef2c0336e (patch)
treeea98b98b5c8b70e56a45b87ae18a6fada47bdd72
parent39ff3996263698c7fb7b0035ff246f7b29af7b92 (diff)
downloadprofani-tty-d61abd35776e2dd448ce9a0cd6576d6ef2c0336e.tar.gz
Use libstrophe xmpp_message_get_body convenience function
-rw-r--r--src/xmpp/message.c71
1 files changed, 22 insertions, 49 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index ea93c816..bb7b6d18 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -504,12 +504,7 @@ _handle_captcha(xmpp_stanza_t *const stanza)
     }
 
     // XEP-0158
-    xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
-    if (!body) {
-        return;
-    }
-
-    char *message = xmpp_stanza_get_text(body);
+    char *message = xmpp_message_get_body(stanza);
     if (!message) {
         return;
     }
@@ -539,13 +534,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
 
     // handle room broadcasts
     if (!jid->resourcepart) {
-        xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
-        if (!body) {
-            jid_destroy(jid);
-            return;
-        }
-
-        message = xmpp_stanza_get_text(body);
+        message = xmpp_message_get_body(stanza);
         if (!message) {
             jid_destroy(jid);
             return;
@@ -571,15 +560,7 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
         return;
     }
 
-    xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
-
-    // check for and deal with message
-    if (!body) {
-        jid_destroy(jid);
-        return;
-    }
-
-    message = xmpp_stanza_get_text(body);
+    message = xmpp_message_get_body(stanza);
     if (!message) {
         jid_destroy(jid);
         return;
@@ -674,12 +655,7 @@ _receipt_request_handler(xmpp_stanza_t *const stanza)
 void
 _private_chat_handler(xmpp_stanza_t *const stanza, const char *const fulljid)
 {
-    xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_BODY);
-    if (!body) {
-        return;
-    }
-
-    char *message = xmpp_stanza_get_text(body);
+    char *message = xmpp_message_get_body(stanza);
     if (!message) {
         return;
     }
@@ -722,28 +698,25 @@ _handle_carbons(xmpp_stanza_t *const stanza)
         Jid *my_jid = jid_create(connection_get_fulljid());
 
         // check for and deal with message
-        xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY);
-        if (body) {
-            char *message_txt = xmpp_stanza_get_text(body);
-            if (message_txt) {
-                // check for pgp encrypted message
-                char *enc_message = NULL;
-                xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED);
-                if (x) {
-                    enc_message = xmpp_stanza_get_text(x);
-                }
-
-                // if we are the recipient, treat as standard incoming message
-                if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
-                    sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message);
-
-                // else treat as a sent message
-                } else {
-                    sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message);
-                }
-                xmpp_free(ctx, message_txt);
-                xmpp_free(ctx, enc_message);
+        char *message_txt = xmpp_message_get_body(message);
+        if (message_txt) {
+            // check for pgp encrypted message
+            char *enc_message = NULL;
+            xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(message, STANZA_NS_ENCRYPTED);
+            if (x) {
+                enc_message = xmpp_stanza_get_text(x);
+            }
+
+            // if we are the recipient, treat as standard incoming message
+            if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
+                sv_ev_incoming_carbon(jid_from->barejid, jid_from->resourcepart, message_txt, enc_message);
+
+            // else treat as a sent message
+            } else {
+                sv_ev_outgoing_carbon(jid_to->barejid, message_txt, enc_message);
             }
+            xmpp_free(ctx, message_txt);
+            xmpp_free(ctx, enc_message);
         }
 
         jid_destroy(jid_from);