about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2015-05-04 21:31:22 +0100
committerJames Booth <boothj5@gmail.com>2015-05-04 21:31:22 +0100
commit65ea572dae158be4ea2c3501e4cdd42fe3e658ee (patch)
treebb722ce848a69369be6a814f87e74098faeaf0df
parenta5677206e9ce5605f74176bb90d673c72bc31caf (diff)
parenta0c872edf85d98d237200ada08a97705a1e18e7f (diff)
downloadprofani-tty-65ea572dae158be4ea2c3501e4cdd42fe3e658ee.tar.gz
Merge branch 'master' into pgp
-rw-r--r--src/xmpp/message.c94
1 files changed, 54 insertions, 40 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 89bc422d..417c68ab 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -638,57 +638,71 @@ _private_chat_handler(xmpp_stanza_t * const stanza, const char * const fulljid)
     xmpp_free(ctx, message);
 }
 
-static int
-_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
+static gboolean
+_handle_carbons(xmpp_stanza_t * const stanza)
 {
-    // ignore if type not chat or absent
-    char *type = xmpp_stanza_get_type(stanza);
-    if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) {
-        return 1;
+    xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
+    if (!carbons) {
+        return FALSE;
     }
 
-    // check if carbon message
-    xmpp_stanza_t *carbons = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CARBONS);
-    if (carbons) {
-        char *name = xmpp_stanza_get_name(carbons);
-        if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0){
-            xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD);
-            xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
+    char *name = xmpp_stanza_get_name(carbons);
+    if ((g_strcmp0(name, "received") == 0) || (g_strcmp0(name, "sent")) == 0) {
+        xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(carbons, STANZA_NS_FORWARD);
+        xmpp_stanza_t *message = xmpp_stanza_get_child_by_name(forwarded, STANZA_NAME_MESSAGE);
 
-            xmpp_ctx_t *ctx = connection_get_ctx();
+        xmpp_ctx_t *ctx = connection_get_ctx();
 
-            gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO);
-            gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM);
+        gchar *to = xmpp_stanza_get_attribute(message, STANZA_ATTR_TO);
+        gchar *from = xmpp_stanza_get_attribute(message, STANZA_ATTR_FROM);
 
-            // happens when receive a carbon of a self sent message
-            if (!to) to = from;
+        // happens when receive a carbon of a self sent message
+        if (!to) to = from;
 
-            Jid *jid_from = jid_create(from);
-            Jid *jid_to = jid_create(to);
-            Jid *my_jid = jid_create(jabber_get_fulljid());
+        Jid *jid_from = jid_create(from);
+        Jid *jid_to = jid_create(to);
+        Jid *my_jid = jid_create(jabber_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 = xmpp_stanza_get_text(body);
-                if (message) {
-                    // if we are the recipient, treat as standard incoming message
-                    if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
-                        sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message);
-                    }
-                    // else treat as a sent message
-                    else{
-                        sv_ev_carbon(jid_to->barejid, message);
-                    }
-                    xmpp_free(ctx, message);
+        // check for and deal with message
+        xmpp_stanza_t *body = xmpp_stanza_get_child_by_name(message, STANZA_NAME_BODY);
+        if (body) {
+            char *message = xmpp_stanza_get_text(body);
+            if (message) {
+                // if we are the recipient, treat as standard incoming message
+                if(g_strcmp0(my_jid->barejid, jid_to->barejid) == 0){
+                    sv_ev_incoming_message(jid_from->barejid, jid_from->resourcepart, message);
                 }
+                // else treat as a sent message
+                else{
+                    sv_ev_carbon(jid_to->barejid, message);
+                }
+                xmpp_free(ctx, message);
             }
-
-            jid_destroy(jid_from);
-            jid_destroy(jid_to);
-            jid_destroy(my_jid);
-            return 1;
         }
+
+        jid_destroy(jid_from);
+        jid_destroy(jid_to);
+        jid_destroy(my_jid);
+
+        return TRUE;
+    }
+
+    return FALSE;
+}
+
+static int
+_chat_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza, void * const userdata)
+{
+    // ignore if type not chat or absent
+    char *type = xmpp_stanza_get_type(stanza);
+    if (!(g_strcmp0(type, "chat") == 0 || type == NULL)) {
+        return 1;
+    }
+
+    // check if carbon message
+    gboolean res = _handle_carbons(stanza);
+    if (res) {
+        return 1;
     }
 
     // ignore handled namespaces