about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2018-09-10 13:09:23 +0200
committerPaul Fariello <paul@fariello.eu>2018-09-10 13:09:23 +0200
commit01428eb85855ea9dd148118ca35a0e20f42cd5ce (patch)
tree1e82938a26e1d7aa7da2a3a0c344b163e459079b /src
parent371b64a8422b13e76b2d2af9f3f481351117f119 (diff)
downloadprofani-tty-01428eb85855ea9dd148118ca35a0e20f42cd5ce.tar.gz
Add special handling for xep-0133 get-user-roster
Diffstat (limited to 'src')
-rw-r--r--src/xmpp/iq.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 3b5f1990..dde803cb 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -1178,9 +1178,48 @@ _command_exec_response_handler(xmpp_stanza_t *const stanza, void *const userdata
         }
         xmpp_stanza_t *x = xmpp_stanza_get_child_by_ns(cmd, STANZA_NS_DATA);
         if (x) {
-            DataForm *form = form_create(x);
-            ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, NULL, NULL, NULL);
-            confwin_handle_configuration(confwin, form);
+            xmpp_stanza_t *roster = xmpp_stanza_get_child_by_ns(x, XMPP_NS_ROSTER);
+            if (roster) {
+                /* Special handling of xep-0133 roster in response */
+                GSList *list = NULL;
+                xmpp_stanza_t *child = xmpp_stanza_get_children(roster);
+                while (child) {
+                    const char *barejid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
+                    gchar *barejid_lower = g_utf8_strdown(barejid, -1);
+                    const char *name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
+                    const char *sub = xmpp_stanza_get_attribute(child, STANZA_ATTR_SUBSCRIPTION);
+                    const char *ask = xmpp_stanza_get_attribute(child, STANZA_ATTR_ASK);
+
+                    GSList *groups = NULL;
+                    xmpp_stanza_t *group_element = xmpp_stanza_get_children(child);
+
+                    while (group_element) {
+                        if (strcmp(xmpp_stanza_get_name(group_element), STANZA_NAME_GROUP) == 0) {
+                            char *groupname = xmpp_stanza_get_text(group_element);
+                            if (groupname) {
+                                groups = g_slist_append(groups, groupname);
+                            }
+                        }
+                        group_element = xmpp_stanza_get_next(group_element);
+                    }
+
+                    gboolean pending_out = FALSE;
+                    if (ask && (strcmp(ask, "subscribe") == 0)) {
+                        pending_out = TRUE;
+                    }
+
+                    PContact contact = p_contact_new(barejid_lower, name, groups, sub, NULL, pending_out);
+                    list = g_slist_append(list, contact);
+                    child = xmpp_stanza_get_next(child);
+                }
+
+                cons_show_roster(list);
+                g_slist_free(list);
+            } else {
+                DataForm *form = form_create(x);
+                ProfConfWin *confwin = (ProfConfWin*)wins_new_config(from, form, NULL, NULL, NULL);
+                confwin_handle_configuration(confwin, form);
+            }
         }
     } else if (g_strcmp0(status, "executing") == 0) {
         win_handle_command_exec_status(win, command, "executing");