about summary refs log tree commit diff stats
path: root/src/xmpp
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2014-09-21 01:57:09 +0100
committerJames Booth <boothj5@gmail.com>2014-09-21 01:57:09 +0100
commit7aff51ba4da592268856ae60f33874c4074c255a (patch)
tree04ad868b552aaf4919f0abd1bfc01b6e08a088a5 /src/xmpp
parentc2e173479f694d1db391f4daa1f9a66b0596994d (diff)
downloadprofani-tty-7aff51ba4da592268856ae60f33874c4074c255a.tar.gz
Handle capabilities for room participants
Diffstat (limited to 'src/xmpp')
-rw-r--r--src/xmpp/presence.c77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index f1871006..4dab35bb 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -498,6 +498,45 @@ _unavailable_handler(xmpp_conn_t * const conn,
     return 1;
 }
 
+static void
+_handle_caps(xmpp_stanza_t *const stanza)
+{
+    char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
+
+    if (from) {
+        char *hash = stanza_caps_get_hash(stanza);
+
+        // hash supported xep-0115
+        if (g_strcmp0(hash, "sha-1") == 0) {
+            log_info("Hash %s supported");
+
+            char *ver = stanza_get_caps_ver(stanza);
+            if (ver) {
+                if (caps_contains(ver)) {
+                    log_info("Capabilities cached: %s", ver);
+                    caps_map(from, ver);
+                } else {
+                    log_info("Capabilities not cached: %s, sending service discovery request", ver);
+                    char *node = stanza_caps_get_node(stanza);
+                    char *id = create_unique_id("caps");
+
+                    iq_send_caps_request(from, id, node, ver);
+                }
+            }
+
+        // no hash, or not supported
+        } else {
+            if (hash) {
+                log_info("Hash %s not supported, not sending service discovery request");
+                // send service discovery request, cache against from full jid
+            } else {
+                log_info("No hash specified, not sending service discovery request");
+                // do legacy
+            }
+        }
+    }
+}
+
 static int
 _available_handler(xmpp_conn_t * const conn,
     xmpp_stanza_t * const stanza, void * const userdata)
@@ -580,37 +619,7 @@ _available_handler(xmpp_conn_t * const conn,
     // send disco info for capabilities, if not cached
     if ((g_strcmp0(my_jid->fulljid, from_jid->fulljid) != 0) && (stanza_contains_caps(stanza))) {
         log_info("Presence contains capabilities.");
-
-        char *hash = stanza_caps_get_hash(stanza);
-
-        // hash supported xep-0115
-        if (g_strcmp0(hash, "sha-1") == 0) {
-            log_info("Hash %s supported");
-
-            char *ver = stanza_get_caps_ver(stanza);
-            if (ver) {
-                if (caps_contains(ver)) {
-                    log_info("Capabilities cached: %s", ver);
-                    caps_map(from, ver);
-                } else {
-                    log_info("Capabilities not cached: %s, sending service discovery request", ver);
-                    char *node = stanza_caps_get_node(stanza);
-                    char *id = create_unique_id("caps");
-
-                    iq_send_caps_request(from, id, node, ver);
-                }
-            }
-
-        // no hash, or not supported
-        } else {
-            if (hash) {
-                log_info("Hash %s not supported, not sending service discovery request");
-                // send service discovery request, cache against from full jid
-            } else {
-                log_info("No hash specified, not sending service discovery request");
-                // do legacy
-            }
-        }
+        _handle_caps(stanza);
     }
 
     // create Resource
@@ -717,6 +726,12 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
 
         log_debug("Room presence received from %s", from_jid->fulljid);
 
+        // send disco info for capabilities, if not cached
+        if (stanza_contains_caps(stanza)) {
+            log_info("Presence contains capabilities.");
+            _handle_caps(stanza);
+        }
+
         status_str = stanza_get_status(stanza, NULL);
 
         if ((type != NULL) && (strcmp(type, STANZA_TYPE_UNAVAILABLE) == 0)) {