diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/xmpp/capabilities.c | 79 | ||||
-rw-r--r-- | src/xmpp/capabilities.h | 3 | ||||
-rw-r--r-- | src/xmpp/iq.c | 2 | ||||
-rw-r--r-- | src/xmpp/stanza.c | 51 | ||||
-rw-r--r-- | src/xmpp/stanza.h | 2 |
5 files changed, 77 insertions, 60 deletions
diff --git a/src/xmpp/capabilities.c b/src/xmpp/capabilities.c index f773a559..26cb3c0c 100644 --- a/src/xmpp/capabilities.c +++ b/src/xmpp/capabilities.c @@ -106,6 +106,27 @@ caps_init(void) my_sha1 = NULL; } +GList* +caps_get_features(void) +{ + GList *result = NULL; + + GList *curr = prof_features; + while (curr) { + result = g_list_append(result, curr->data); + curr = g_list_next(curr); + } + + GList *plugin_features = plugins_get_disco_features(); + curr = plugin_features; + while (curr) { + result = g_list_append(result, curr->data); + curr = g_list_next(curr); + } + + return result; +} + void caps_add_by_ver(const char *const ver, EntityCapabilities *caps) { @@ -540,7 +561,7 @@ char* caps_get_my_sha1(xmpp_ctx_t *const ctx) { if (my_sha1 == NULL) { - xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); + xmpp_stanza_t *query = stanza_create_caps_query_element(ctx); my_sha1 = caps_create_sha1_str(query); xmpp_stanza_release(query); } @@ -557,62 +578,6 @@ caps_reset_ver(void) } } -xmpp_stanza_t* -caps_create_query_response_stanza(xmpp_ctx_t *const ctx) -{ - xmpp_stanza_t *query = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(query, STANZA_NAME_QUERY); - xmpp_stanza_set_ns(query, XMPP_NS_DISCO_INFO); - - xmpp_stanza_t *identity = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(identity, "identity"); - xmpp_stanza_set_attribute(identity, "category", "client"); - xmpp_stanza_set_attribute(identity, "type", "console"); - - GString *name_str = g_string_new("Profanity "); - g_string_append(name_str, PACKAGE_VERSION); - if (strcmp(PACKAGE_STATUS, "development") == 0) { -#ifdef HAVE_GIT_VERSION - g_string_append(name_str, "dev."); - g_string_append(name_str, PROF_GIT_BRANCH); - g_string_append(name_str, "."); - g_string_append(name_str, PROF_GIT_REVISION); -#else - g_string_append(name_str, "dev"); -#endif - } - xmpp_stanza_set_attribute(identity, "name", name_str->str); - g_string_free(name_str, TRUE); - xmpp_stanza_add_child(query, identity); - xmpp_stanza_release(identity); - - GList *curr = prof_features; - while (curr) { - xmpp_stanza_t *feature = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(feature, STANZA_NAME_FEATURE); - xmpp_stanza_set_attribute(feature, STANZA_ATTR_VAR, curr->data); - xmpp_stanza_add_child(query, feature); - xmpp_stanza_release(feature); - - curr = g_list_next(curr); - } - - GList *plugin_features = plugins_get_disco_features(); - curr = plugin_features; - while (curr) { - xmpp_stanza_t *feature = xmpp_stanza_new(ctx); - xmpp_stanza_set_name(feature, STANZA_NAME_FEATURE); - xmpp_stanza_set_attribute(feature, STANZA_ATTR_VAR, curr->data); - xmpp_stanza_add_child(query, feature); - xmpp_stanza_release(feature); - - curr = g_list_next(curr); - } - g_list_free(plugin_features); - - return query; -} - void caps_close(void) { diff --git a/src/xmpp/capabilities.h b/src/xmpp/capabilities.h index 88563fcc..9556860f 100644 --- a/src/xmpp/capabilities.h +++ b/src/xmpp/capabilities.h @@ -54,8 +54,9 @@ void caps_add_by_jid(const char *const jid, EntityCapabilities *caps); void caps_map_jid_to_ver(const char *const jid, const char *const ver); gboolean caps_contains(const char *const ver); +GList* caps_get_features(void); + char* caps_create_sha1_str(xmpp_stanza_t *const query); -xmpp_stanza_t* caps_create_query_response_stanza(xmpp_ctx_t *const ctx); EntityCapabilities* caps_create(xmpp_stanza_t *query); char* caps_get_my_sha1(xmpp_ctx_t *const ctx); diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c index 2d27be0c..3aa0bfbf 100644 --- a/src/xmpp/iq.c +++ b/src/xmpp/iq.c @@ -1349,7 +1349,7 @@ _disco_info_get_handler(xmpp_stanza_t *const stanza) xmpp_stanza_set_id(response, xmpp_stanza_get_id(stanza)); xmpp_stanza_set_attribute(response, STANZA_ATTR_TO, from); xmpp_stanza_set_type(response, STANZA_TYPE_RESULT); - xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); + xmpp_stanza_t *query = stanza_create_caps_query_element(ctx); if (node_str) { xmpp_stanza_set_attribute(query, STANZA_ATTR_NODE, node_str); } diff --git a/src/xmpp/stanza.c b/src/xmpp/stanza.c index 18c2bf66..0bbc99dd 100644 --- a/src/xmpp/stanza.c +++ b/src/xmpp/stanza.c @@ -36,6 +36,10 @@ #include "config.h" +#ifdef HAVE_GIT_VERSION +#include "gitversion.h" +#endif + #include <stdlib.h> #include <string.h> #include <stdio.h> @@ -1052,6 +1056,51 @@ stanza_create_room_config_submit_iq(xmpp_ctx_t *ctx, const char *const room, Dat return iq; } +xmpp_stanza_t* +stanza_create_caps_query_element(xmpp_ctx_t *ctx) +{ + xmpp_stanza_t *query = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(query, STANZA_NAME_QUERY); + xmpp_stanza_set_ns(query, XMPP_NS_DISCO_INFO); + + xmpp_stanza_t *identity = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(identity, "identity"); + xmpp_stanza_set_attribute(identity, "category", "client"); + xmpp_stanza_set_attribute(identity, "type", "console"); + + GString *name_str = g_string_new("Profanity "); + g_string_append(name_str, PACKAGE_VERSION); + if (strcmp(PACKAGE_STATUS, "development") == 0) { +#ifdef HAVE_GIT_VERSION + g_string_append(name_str, "dev."); + g_string_append(name_str, PROF_GIT_BRANCH); + g_string_append(name_str, "."); + g_string_append(name_str, PROF_GIT_REVISION); +#else + g_string_append(name_str, "dev"); +#endif + } + xmpp_stanza_set_attribute(identity, "name", name_str->str); + g_string_free(name_str, TRUE); + xmpp_stanza_add_child(query, identity); + xmpp_stanza_release(identity); + + GList *features = caps_get_features(); + GList *curr = features; + while (curr) { + xmpp_stanza_t *feature = xmpp_stanza_new(ctx); + xmpp_stanza_set_name(feature, STANZA_NAME_FEATURE); + xmpp_stanza_set_attribute(feature, STANZA_ATTR_VAR, curr->data); + xmpp_stanza_add_child(query, feature); + xmpp_stanza_release(feature); + + curr = g_list_next(curr); + } + g_list_free(features); + + return query; +} + gboolean stanza_contains_chat_state(xmpp_stanza_t *stanza) { @@ -1712,7 +1761,7 @@ stanza_attach_caps(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence) xmpp_stanza_t *caps = xmpp_stanza_new(ctx); xmpp_stanza_set_name(caps, STANZA_NAME_C); xmpp_stanza_set_ns(caps, STANZA_NS_CAPS); - xmpp_stanza_t *query = caps_create_query_response_stanza(ctx); + xmpp_stanza_t *query = stanza_create_caps_query_element(ctx); char *sha1 = caps_get_my_sha1(ctx); xmpp_stanza_set_attribute(caps, STANZA_ATTR_HASH, "sha-1"); diff --git a/src/xmpp/stanza.h b/src/xmpp/stanza.h index bc649107..f4d76971 100644 --- a/src/xmpp/stanza.h +++ b/src/xmpp/stanza.h @@ -291,6 +291,8 @@ void stanza_attach_caps(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence); void stanza_attach_show(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence, const char *const show); void stanza_attach_status(xmpp_ctx_t *const ctx, xmpp_stanza_t *const presence, const char *const status); +xmpp_stanza_t* stanza_create_caps_query_element(xmpp_ctx_t *ctx); + const char* stanza_get_presence_string_from_type(resource_presence_t presence_type); xmpp_stanza_t* stanza_create_software_version_iq(xmpp_ctx_t *ctx, const char *const fulljid); xmpp_stanza_t* stanza_create_disco_items_iq(xmpp_ctx_t *ctx, const char *const id, const char *const jid); |