about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2020-07-02 17:15:42 +0200
committerMichael Vetter <jubalh@iodoru.org>2020-07-02 17:15:42 +0200
commitb14b7114922766ee30721902cd4248a856834d68 (patch)
treee99c33d6a031089d2ce988593f37f13e9597deb9 /src
parent728cb55b687438e26e2778cbbd35beaf5dd6c75f (diff)
downloadprofani-tty-b14b7114922766ee30721902cd4248a856834d68.tar.gz
message.c: Parse incoming message stanzas according to type
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/message.c65
1 files changed, 34 insertions, 31 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 31f441de..0bb1d4f6 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -110,6 +110,7 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
         return 1;
     }
 
+    // type according to RFC 6121
     const char *type = xmpp_stanza_get_type(stanza);
 
     if (type == NULL) {
@@ -127,44 +128,46 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con
 
     if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) {
         _handle_error(stanza);
-    }
-
-    // XEP-0045: Multi-User Chat
-    if (g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
+    } else if (g_strcmp0(type, STANZA_TYPE_GROUPCHAT) == 0) {
+        // XEP-0045: Multi-User Chat
         _handle_groupchat(stanza);
-    }
+    } else if (g_strcmp0(type, STANZA_TYPE_HEADLINE) == 0) {
+        //TODO: implement headline
+    } else {
+        // type: chat, normal (default if none is set)
 
-    // XEP-0045: Multi-User Chat
-    xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
-    if (mucuser) {
-        _handle_muc_user(stanza);
-    }
+        // XEP-0045: Multi-User Chat - invites - presence
+        xmpp_stanza_t *mucuser = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
+        if (mucuser) {
+            _handle_muc_user(stanza);
+        }
 
-    // XEP-0249: Direct MUC Invitations
-    xmpp_stanza_t *conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
-    if (conference) {
-        _handle_conference(stanza);
-    }
+        // XEP-0249: Direct MUC Invitations
+        xmpp_stanza_t *conference = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CONFERENCE);
+        if (conference) {
+            _handle_conference(stanza);
+        }
 
-    // XEP-0158: CAPTCHA Forms
-    xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA);
-    if (captcha) {
-        _handle_captcha(stanza);
-    }
+        // XEP-0158: CAPTCHA Forms
+        xmpp_stanza_t *captcha = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_CAPTCHA);
+        if (captcha) {
+            _handle_captcha(stanza);
+        }
 
-    // XEP-0184: Message Delivery Receipts
-    xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
-    if (receipts) {
-        _handle_receipt_received(stanza);
-    }
+        // XEP-0184: Message Delivery Receipts
+        xmpp_stanza_t *receipts = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_RECEIPTS);
+        if (receipts) {
+            _handle_receipt_received(stanza);
+        }
 
-    // XEP-0060: Publish-Subscribe
-    xmpp_stanza_t *event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
-    if (event) {
-        _handle_pubsub(stanza, event);
-    }
+        // XEP-0060: Publish-Subscribe
+        xmpp_stanza_t *event = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_PUBSUB_EVENT);
+        if (event) {
+            _handle_pubsub(stanza, event);
+        }
 
-    _handle_chat(stanza, FALSE);
+        _handle_chat(stanza, FALSE);
+    }
 
     return 1;
 }