about summary refs log tree commit diff stats
path: root/src/jabber.c
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-01-20 18:23:29 +0000
committerJames Booth <boothj5@gmail.com>2013-01-20 18:23:29 +0000
commiteed09109164bf05b6a3d40604205ce5cc2cfbde1 (patch)
treec1499137d5894ea3628eb245e5ae76d40510aa9d /src/jabber.c
parent64d81c7c4c07f527e76a64477a5b21a1385dbfef (diff)
downloadprofani-tty-eed09109164bf05b6a3d40604205ce5cc2cfbde1.tar.gz
First implementation of sha1 generation from stanza
Diffstat (limited to 'src/jabber.c')
-rw-r--r--src/jabber.c28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/jabber.c b/src/jabber.c
index 353247f4..f5cb9d04 100644
--- a/src/jabber.c
+++ b/src/jabber.c
@@ -208,6 +208,8 @@ sha1_caps_str(xmpp_stanza_t *query)
 {
     GSList *identities = NULL;
     GSList *features = NULL;
+    GSList *form_names = NULL;
+    GHashTable *forms = g_hash_table_new(g_str_hash, g_str_equal);
 
     GString *s = g_string_new("");
     unsigned char hash[SHA_DIGEST_LENGTH];
@@ -240,7 +242,11 @@ sha1_caps_str(xmpp_stanza_t *query)
             char *feature_str = xmpp_stanza_get_attribute(child, "var");
             features = g_slist_insert_sorted(features, feature_str, (GCompareFunc)octet_compare);
         } else if (strcmp(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
-            // check for and add form to string
+            if (strcmp(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) {
+                DataForm *form = stanza_get_form(child);
+                form_names = g_slist_insert_sorted(form_names, form->form_type, (GCompareFunc)octet_compare);
+                g_hash_table_insert(forms, form->form_type, form);
+            }
         }
         child = xmpp_stanza_get_next(child);
     }
@@ -259,6 +265,26 @@ sha1_caps_str(xmpp_stanza_t *query)
         curr = g_slist_next(curr);
     }
 
+    curr = form_names;
+    while (curr != NULL) {
+        DataForm *form = g_hash_table_lookup(forms, curr->data);
+        g_string_append(s, form->form_type);
+        g_string_append(s, "<");
+
+        GSList *curr_field = form->fields;
+        while (curr_field != NULL) {
+            FormField *field = curr_field->data;
+            g_string_append(s, field->var);
+            GSList *curr_value = field->values;
+            while (curr_value != NULL) {
+                g_string_append(s, curr_value->data);
+                g_string_append(s, "<");
+                curr_value = g_slist_next(curr_value);
+            }
+            curr_field = g_slist_next(curr_value);
+        }
+    }
+
     SHA1((unsigned char *)s->str, strlen(s->str), hash);
 
     char *result = g_base64_encode(hash, strlen((char *)hash));