about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMichael Vetter <jubalh@iodoru.org>2019-11-08 15:05:49 +0100
committerMichael Vetter <jubalh@iodoru.org>2019-11-08 15:05:49 +0100
commit68af0aad65d243e654866eac5a7cd728ee293aa0 (patch)
tree971fe47e4349017a105b5232d29b93753ea14d49
parentcbd85ffd1a202f811ce5445f72ca5167e11ad846 (diff)
downloadprofani-tty-68af0aad65d243e654866eac5a7cd728ee293aa0.tar.gz
_handle_groupchat(): get correct origin-id stanza
The problem is that in _handle_groupchat() we look for
STANZA_NS_STABLE_ID which will result in origin-id or stanza-id.
It seems like prosody servers send origin-id first, so this worked in
all my tests. But actually we cannot be sure of the order.
So far we stopped after the first element was found.

I only found xmpp_stanza_get_child_by_ns() and
xmpp_stanza_get_child_by_name() in libstrophe. But we need a combination
of both.

So I created stanza_get_child_by_name_and_ns() for Profanity. I need to
remember to upstream this to libstrophe later (if they really don't have
such a function).

Fix https://github.com/profanity-im/profanity/issues/1223
-rw-r--r--src/xmpp/message.c4
-rw-r--r--src/xmpp/stanza.c18
-rw-r--r--src/xmpp/stanza.h2
3 files changed, 22 insertions, 2 deletions
diff --git a/src/xmpp/message.c b/src/xmpp/message.c
index 76124ee7..d1808ba5 100644
--- a/src/xmpp/message.c
+++ b/src/xmpp/message.c
@@ -755,8 +755,8 @@ _handle_groupchat(xmpp_stanza_t *const stanza)
     const char *id = xmpp_stanza_get_id(stanza);
     char *originid = NULL;
 
-    xmpp_stanza_t *origin = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_STABLE_ID);
-    if (origin && g_strcmp0(xmpp_stanza_get_name(origin), STANZA_NAME_ORIGIN_ID) == 0) {
+    xmpp_stanza_t *origin = stanza_get_child_by_name_and_ns(stanza, STANZA_NAME_ORIGIN_ID, STANZA_NS_STABLE_ID);
+    if (origin) {
         originid = (char*)xmpp_stanza_get_attribute(origin, STANZA_ATTR_ID);
     }
 
diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c
index 5aa98799..46adb50e 100644
--- a/src/xmpp/stanza.c
+++ b/src/xmpp/stanza.c
@@ -2478,3 +2478,21 @@ _stanza_create_sha1_hash(char *str)
 
    return b64;
 }
+
+xmpp_stanza_t*
+stanza_get_child_by_name_and_ns(xmpp_stanza_t * const stanza, const char * const name, const char * const ns)
+{
+    xmpp_stanza_t *child;
+    const char *child_ns;
+
+    for (child = xmpp_stanza_get_children(stanza); child; child = xmpp_stanza_get_next(child)) {
+        if (strcmp(name, xmpp_stanza_get_name(child)) == 0) {
+            child_ns = xmpp_stanza_get_ns(child);
+            if (child_ns && strcmp(ns, child_ns) == 0) {
+                break;
+            }
+        }
+    }
+
+    return child;
+}
diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h
index ad83d694..0212ed0e 100644
--- a/src/xmpp/stanza.h
+++ b/src/xmpp/stanza.h
@@ -349,4 +349,6 @@ char* stanza_text_strdup(xmpp_stanza_t *stanza);
 XMPPCaps* stanza_parse_caps(xmpp_stanza_t *const stanza);
 void stanza_free_caps(XMPPCaps *caps);
 
+xmpp_stanza_t* stanza_get_child_by_name_and_ns(xmpp_stanza_t * const stanza, const char * const name, const char * const ns);
+
 #endif