diff options
author | Michael Vetter <jubalh@iodoru.org> | 2020-04-08 17:51:10 +0200 |
---|---|---|
committer | Michael Vetter <jubalh@iodoru.org> | 2020-04-11 16:05:14 +0200 |
commit | 38273fef5c04b9777fd4e030e5a2d15619623bb0 (patch) | |
tree | a1386f572ca28ec8df91a880f76f1813097db3b5 /src/xmpp | |
parent | f3b8cc407dc5ab5a5075095393bfffe5f1c09a33 (diff) | |
download | profani-tty-38273fef5c04b9777fd4e030e5a2d15619623bb0.tar.gz |
First test with receiving MAM
Diffstat (limited to 'src/xmpp')
-rw-r--r-- | src/xmpp/message.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c index 98ab40c8..73ae8549 100644 --- a/src/xmpp/message.c +++ b/src/xmpp/message.c @@ -85,6 +85,7 @@ static void _handle_conference(xmpp_stanza_t *const stanza); static void _handle_captcha(xmpp_stanza_t *const stanza); static void _handle_receipt_received(xmpp_stanza_t *const stanza); static void _handle_chat(xmpp_stanza_t *const stanza); +static gboolean _handle_mam(xmpp_stanza_t *const stanza); static void _send_message_stanza(xmpp_stanza_t *const stanza); @@ -107,10 +108,16 @@ _message_handler(xmpp_conn_t *const conn, xmpp_stanza_t *const stanza, void *con const char *type = xmpp_stanza_get_type(stanza); if (type == NULL) { + if (_handle_mam(stanza)) { + xmpp_free(connection_get_ctx(), text); + return 1; + } + log_info("Received <message> without 'type': %s", text); xmpp_free(connection_get_ctx(), text); return 1; } + xmpp_free(connection_get_ctx(), text); if (g_strcmp0(type, STANZA_TYPE_ERROR) == 0) { @@ -1266,6 +1273,26 @@ _handle_chat(xmpp_stanza_t *const stanza) message_free(message); } +static gboolean +_handle_mam(xmpp_stanza_t *const stanza) +{ + xmpp_stanza_t *result = stanza_get_child_by_name_and_ns(stanza, "result", STANZA_NS_MAM2); + if (!result) { + return FALSE; + } + + xmpp_stanza_t *forwarded = xmpp_stanza_get_child_by_ns(result, STANZA_NS_FORWARD); + if (!forwarded) { + log_warning("MAM received with no forwarded element"); + return FALSE; + } + + xmpp_stanza_t *message_stanza = xmpp_stanza_get_child_by_ns(forwarded, "jabber:client"); + _handle_chat(message_stanza); + + return TRUE; +} + static void _send_message_stanza(xmpp_stanza_t *const stanza) { |