From b14b7114922766ee30721902cd4248a856834d68 Mon Sep 17 00:00:00 2001 From: Michael Vetter Date: Thu, 2 Jul 2020 17:15:42 +0200 Subject: [PATCH] message.c: Parse incoming message stanzas according to type --- src/xmpp/message.c | 65 ++++++++++++++++++++++++---------------------- 1 file 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; }