summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2021-02-13 12:26:17 +0300
committerdefanor <defanor@uberspace.net>2021-02-13 12:26:17 +0300
commit2203c7f147c80e238af620f44138e0e3ff41318f (patch)
treea4cec996fdad052707fc30f25379487ae6d65ea1
parent289c9a88b4e0323f4b9d038e78219ab56a948073 (diff)
Handle carbons-forwarded messages in the console module
-rw-r--r--src/rexmpp_console.c43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/rexmpp_console.c b/src/rexmpp_console.c
index 1e3106b..b44e045 100644
--- a/src/rexmpp_console.c
+++ b/src/rexmpp_console.c
@@ -113,6 +113,49 @@ void rexmpp_console_on_send (rexmpp_t *s, xmlNodePtr node) {
void rexmpp_console_on_recv (rexmpp_t *s, xmlNodePtr node) {
if (rexmpp_xml_match(node, "jabber:client", "message")) {
+ xmlNodePtr sent = rexmpp_xml_find_child(node, "urn:xmpp:carbons:2", "sent");
+ if (sent != NULL) {
+ xmlNodePtr fwd =
+ rexmpp_xml_find_child(sent, "urn:xmpp:forward:0", "forwarded");
+ if (fwd != NULL) {
+ xmlNodePtr msg =
+ rexmpp_xml_find_child(fwd, "jabber:client", "message");
+ if (msg != NULL) {
+ char *to = xmlGetProp(msg, "to");
+ char *str = rexmpp_console_message_string(s, msg);
+ if (str != NULL) {
+ rexmpp_console_printf(s, "You tell %s: %s\n", to, str);
+ free(str);
+ }
+ if (to != NULL) {
+ free(to);
+ }
+ }
+ }
+ }
+
+ xmlNodePtr received =
+ rexmpp_xml_find_child(node, "urn:xmpp:carbons:2", "received");
+ if (received != NULL) {
+ xmlNodePtr fwd =
+ rexmpp_xml_find_child(received, "urn:xmpp:forward:0", "forwarded");
+ if (fwd != NULL) {
+ xmlNodePtr msg =
+ rexmpp_xml_find_child(fwd, "jabber:client", "message");
+ if (msg != NULL) {
+ char *from = xmlGetProp(msg, "from");
+ char *str = rexmpp_console_message_string(s, msg);
+ if (str != NULL) {
+ rexmpp_console_printf(s, "%s tells you: %s\n", from, str);
+ free(str);
+ }
+ if (from != NULL) {
+ free(from);
+ }
+ }
+ }
+ }
+
char *from = xmlGetProp(node, "from");
if (from != NULL) {
char *str = rexmpp_console_message_string(s, node);