Move caps_create_sha1_str -> stanza_create_caps_sha1_from_query

This commit is contained in:
James Booth
2016-08-14 00:07:08 +01:00
parent 9c4e02db77
commit d5f14abd4e
5 changed files with 127 additions and 127 deletions

View File

@@ -1133,6 +1133,107 @@ stanza_create_ping_iq(xmpp_ctx_t *ctx, const char *const target)
return iq;
}
char*
stanza_create_caps_sha1_from_query(xmpp_stanza_t *const query)
{
GSList *identities = NULL;
GSList *features = NULL;
GSList *form_names = NULL;
GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)form_destroy);
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
while (child) {
if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_IDENTITY) == 0) {
const char *category = xmpp_stanza_get_attribute(child, "category");
const char *type = xmpp_stanza_get_attribute(child, "type");
const char *lang = xmpp_stanza_get_attribute(child, "xml:lang");
const char *name = xmpp_stanza_get_attribute(child, "name");
GString *identity_str = g_string_new(category);
g_string_append(identity_str, "/");
if (type) {
g_string_append(identity_str, type);
}
g_string_append(identity_str, "/");
if (lang) {
g_string_append(identity_str, lang);
}
g_string_append(identity_str, "/");
if (name) {
g_string_append(identity_str, name);
}
g_string_append(identity_str, "<");
identities = g_slist_insert_sorted(identities, g_strdup(identity_str->str), (GCompareFunc)strcmp);
g_string_free(identity_str, TRUE);
} else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_FEATURE) == 0) {
const char *feature_str = xmpp_stanza_get_attribute(child, "var");
features = g_slist_insert_sorted(features, g_strdup(feature_str), (GCompareFunc)strcmp);
} else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
if (g_strcmp0(xmpp_stanza_get_ns(child), STANZA_NS_DATA) == 0) {
DataForm *form = form_create(child);
char *form_type = form_get_form_type_field(form);
form_names = g_slist_insert_sorted(form_names, g_strdup(form_type), (GCompareFunc)strcmp);
g_hash_table_insert(forms, g_strdup(form_type), form);
}
}
child = xmpp_stanza_get_next(child);
}
GString *s = g_string_new("");
GSList *curr = identities;
while (curr) {
g_string_append(s, curr->data);
curr = g_slist_next(curr);
}
curr = features;
while (curr) {
g_string_append(s, curr->data);
g_string_append(s, "<");
curr = g_slist_next(curr);
}
curr = form_names;
while (curr) {
DataForm *form = g_hash_table_lookup(forms, curr->data);
char *form_type = form_get_form_type_field(form);
g_string_append(s, form_type);
g_string_append(s, "<");
GSList *sorted_fields = form_get_non_form_type_fields_sorted(form);
GSList *curr_field = sorted_fields;
while (curr_field) {
FormField *field = curr_field->data;
g_string_append(s, field->var);
g_string_append(s, "<");
GSList *sorted_values = form_get_field_values_sorted(field);
GSList *curr_value = sorted_values;
while (curr_value) {
g_string_append(s, curr_value->data);
g_string_append(s, "<");
curr_value = g_slist_next(curr_value);
}
g_slist_free(sorted_values);
curr_field = g_slist_next(curr_field);
}
g_slist_free(sorted_fields);
curr = g_slist_next(curr);
}
char *result = p_sha1_hash(s->str);
g_string_free(s, TRUE);
g_slist_free_full(identities, g_free);
g_slist_free_full(features, g_free);
g_slist_free_full(form_names, g_free);
g_hash_table_destroy(forms);
return result;
}
GDateTime*
stanza_get_delay(xmpp_stanza_t *const stanza)
{