1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-30 21:55:24 +00:00
profanity/src/xmpp/capabilities.c

679 lines
21 KiB
C
Raw Normal View History

2013-01-20 00:16:12 +00:00
/*
2013-02-02 19:47:41 +00:00
* capabilities.c
2013-01-20 00:16:12 +00:00
*
2016-02-14 22:54:46 +00:00
* Copyright (C) 2012 - 2016 James Booth <boothj5@gmail.com>
2013-01-20 00:16:12 +00:00
*
* This file is part of Profanity.
*
* Profanity is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Profanity is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2016-07-24 00:14:49 +00:00
* along with Profanity. If not, see <https://www.gnu.org/licenses/>.
2013-01-20 00:16:12 +00:00
*
* In addition, as a special exception, the copyright holders give permission to
* link the code of portions of this program with the OpenSSL library under
* certain conditions as described in each individual source file, and
* distribute linked combinations including the two.
*
* You must obey the GNU General Public License in all respects for all of the
* code used other than OpenSSL. If you modify file(s) with this exception, you
* may extend this exception to your version of the file(s), but you are not
* obligated to do so. If you do not wish to do so, delete this exception
* statement from your version. If you delete this exception statement from all
* source files in the program, then also delete it here.
*
2013-01-20 00:16:12 +00:00
*/
2016-03-31 20:05:02 +00:00
#include "config.h"
2013-02-02 20:55:58 +00:00
2016-03-31 20:05:02 +00:00
#ifdef HAVE_GIT_VERSION
#include "gitversion.h"
#endif
2013-01-20 00:16:12 +00:00
#include <stdlib.h>
#include <string.h>
2013-01-20 00:35:40 +00:00
#include <glib.h>
2014-10-18 20:40:11 +00:00
#include <glib/gstdio.h>
2016-03-31 20:05:02 +00:00
#ifdef HAVE_LIBMESODE
#include <mesode.h>
#endif
2016-07-24 14:43:51 +00:00
2016-03-31 20:05:02 +00:00
#ifdef HAVE_LIBSTROPHE
2013-01-21 22:18:15 +00:00
#include <strophe.h>
#endif
2013-01-20 00:35:40 +00:00
2013-01-20 00:16:12 +00:00
#include "common.h"
2014-09-21 20:43:42 +00:00
#include "log.h"
2016-07-24 14:43:51 +00:00
#include "plugins/plugins.h"
2016-07-24 15:22:15 +00:00
#include "config/files.h"
2013-02-02 20:55:58 +00:00
#include "xmpp/xmpp.h"
#include "xmpp/stanza.h"
2014-09-05 20:04:16 +00:00
#include "xmpp/form.h"
2014-09-22 23:08:26 +00:00
#include "xmpp/capabilities.h"
2013-01-20 00:16:12 +00:00
2016-07-24 20:35:12 +00:00
static char *cache_loc;
2014-09-22 00:36:45 +00:00
static GKeyFile *cache;
static GHashTable *jid_to_ver;
static GHashTable *jid_to_caps;
2013-01-20 00:57:44 +00:00
static GList *prof_features;
2014-09-22 23:08:26 +00:00
static char *my_sha1;
2014-09-22 00:36:45 +00:00
static void _save_cache(void);
static EntityCapabilities* _caps_by_ver(const char *const ver);
static EntityCapabilities* _caps_by_jid(const char *const jid);
EntityCapabilities* _caps_copy(EntityCapabilities *caps);
2013-01-20 00:35:40 +00:00
void
caps_init(void)
{
2014-09-22 00:36:45 +00:00
log_info("Loading capabilities cache");
2016-07-24 20:35:12 +00:00
cache_loc = files_get_data_path(FILE_CAPSCACHE);
2014-09-22 00:36:45 +00:00
2014-10-18 20:40:11 +00:00
if (g_file_test(cache_loc, G_FILE_TEST_EXISTS)) {
g_chmod(cache_loc, S_IRUSR | S_IWUSR);
}
2014-09-22 00:36:45 +00:00
cache = g_key_file_new();
2016-07-24 20:35:12 +00:00
g_key_file_load_from_file(cache, cache_loc, G_KEY_FILE_KEEP_COMMENTS, NULL);
2014-09-22 00:36:45 +00:00
jid_to_ver = g_hash_table_new_full(g_str_hash, g_str_equal, free, free);
jid_to_caps = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)caps_destroy);
2014-09-22 23:08:26 +00:00
prof_features = NULL;
prof_features = g_list_append(prof_features, strdup(STANZA_NS_CAPS));
prof_features = g_list_append(prof_features, strdup(XMPP_NS_DISCO_INFO));
prof_features = g_list_append(prof_features, strdup(XMPP_NS_DISCO_ITEMS));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_MUC));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_CONFERENCE));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_VERSION));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_CHATSTATES));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_PING));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_RECEIPTS));
prof_features = g_list_append(prof_features, strdup(STANZA_NS_LASTACTIVITY));
2014-09-22 23:08:26 +00:00
my_sha1 = NULL;
2013-01-20 00:35:40 +00:00
}
2013-01-20 00:57:44 +00:00
void
caps_add_by_ver(const char *const ver, EntityCapabilities *caps)
2013-01-20 00:16:12 +00:00
{
if (ver == NULL || caps == NULL) {
return;
}
2014-09-22 00:36:45 +00:00
gboolean cached = g_key_file_has_group(cache, ver);
if (cached) {
return;
}
if (caps->identity) {
DiscoIdentity *identity = caps->identity;
if (identity->name) {
g_key_file_set_string(cache, ver, "name", identity->name);
2014-09-22 00:36:45 +00:00
}
if (identity->category) {
g_key_file_set_string(cache, ver, "category", identity->category);
2014-09-22 00:36:45 +00:00
}
if (identity->type) {
g_key_file_set_string(cache, ver, "type", identity->type);
2014-09-22 00:36:45 +00:00
}
}
if (caps->software) {
g_key_file_set_string(cache, ver, "software", caps->software);
}
if (caps->software_version) {
g_key_file_set_string(cache, ver, "software_version", caps->software_version);
}
if (caps->os) {
g_key_file_set_string(cache, ver, "os", caps->os);
}
if (caps->os_version) {
g_key_file_set_string(cache, ver, "os_version", caps->os_version);
}
if (caps->features) {
GSList *curr_feature = caps->features;
int num = g_slist_length(caps->features);
const gchar* features_list[num];
int curr = 0;
while (curr_feature) {
features_list[curr++] = curr_feature->data;
curr_feature = g_slist_next(curr_feature);
2014-09-22 00:36:45 +00:00
}
g_key_file_set_string_list(cache, ver, "features", features_list, num);
2014-09-22 00:36:45 +00:00
}
_save_cache();
2013-01-20 00:16:12 +00:00
}
void
caps_add_by_jid(const char *const jid, EntityCapabilities *caps)
{
g_hash_table_insert(jid_to_caps, strdup(jid), caps);
}
void
2015-10-26 00:14:23 +00:00
caps_map_jid_to_ver(const char *const jid, const char *const ver)
{
g_hash_table_insert(jid_to_ver, strdup(jid), strdup(ver));
}
2013-01-20 00:57:44 +00:00
gboolean
2015-10-26 00:14:23 +00:00
caps_contains(const char *const ver)
2013-01-20 00:16:12 +00:00
{
return (g_key_file_has_group(cache, ver));
2013-01-20 00:16:12 +00:00
}
2013-01-20 00:35:40 +00:00
static EntityCapabilities*
2015-10-26 00:14:23 +00:00
_caps_by_ver(const char *const ver)
2013-01-20 02:26:54 +00:00
{
if (g_key_file_has_group(cache, ver)) {
EntityCapabilities *new_caps = malloc(sizeof(struct entity_capabilities_t));
2014-09-22 00:36:45 +00:00
char *category = g_key_file_get_string(cache, ver, "category", NULL);
char *type = g_key_file_get_string(cache, ver, "type", NULL);
char *name = g_key_file_get_string(cache, ver, "name", NULL);
if (category || type || name) {
DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
identity->category = category;
identity->type = type;
identity->name = name;
new_caps->identity = identity;
2014-09-22 00:36:45 +00:00
} else {
new_caps->identity = NULL;
2014-09-22 00:36:45 +00:00
}
char *software = g_key_file_get_string(cache, ver, "software", NULL);
2014-09-22 00:36:45 +00:00
if (software) {
new_caps->software = software;
2014-09-22 00:36:45 +00:00
} else {
new_caps->software = NULL;
}
char *software_version = g_key_file_get_string(cache, ver, "software_version", NULL);
2014-09-22 00:36:45 +00:00
if (software_version) {
new_caps->software_version = software_version;
2014-09-22 00:36:45 +00:00
} else {
new_caps->software_version = NULL;
}
char *os = g_key_file_get_string(cache, ver, "os", NULL);
2014-09-22 00:36:45 +00:00
if (os) {
new_caps->os = os;
2014-09-22 00:36:45 +00:00
} else {
new_caps->os = NULL;
}
char *os_version = g_key_file_get_string(cache, ver, "os_version", NULL);
2014-09-22 00:36:45 +00:00
if (os_version) {
new_caps->os_version = os_version;
2014-09-22 00:36:45 +00:00
} else {
new_caps->os_version = NULL;
}
gsize features_len = 0;
gchar **features = g_key_file_get_string_list(cache, ver, "features", &features_len, NULL);
if (features && features_len > 0) {
2014-09-22 00:36:45 +00:00
GSList *features_list = NULL;
int i;
for (i = 0; i < features_len; i++) {
features_list = g_slist_append(features_list, strdup(features[i]));
}
new_caps->features = features_list;
g_strfreev(features);
} else {
new_caps->features = NULL;
}
return new_caps;
} else {
return NULL;
}
2013-01-20 02:26:54 +00:00
}
static EntityCapabilities*
2015-10-26 00:14:23 +00:00
_caps_by_jid(const char *const jid)
{
return g_hash_table_lookup(jid_to_caps, jid);
}
EntityCapabilities*
2015-10-26 00:14:23 +00:00
caps_lookup(const char *const jid)
{
char *ver = g_hash_table_lookup(jid_to_ver, jid);
if (ver) {
EntityCapabilities *caps = _caps_by_ver(ver);
if (caps) {
log_debug("Capabilities lookup %s, found by verification string %s.", jid, ver);
return caps;
}
} else {
EntityCapabilities *caps = _caps_by_jid(jid);
if (caps) {
log_debug("Capabilities lookup %s, found by JID.", jid);
return _caps_copy(caps);
}
}
log_debug("Capabilities lookup %s, none found.", jid);
return NULL;
}
EntityCapabilities*
_caps_copy(EntityCapabilities *caps)
{
if (!caps) {
return NULL;
} else {
EntityCapabilities *result = (EntityCapabilities *)malloc(sizeof(EntityCapabilities));
if (caps->identity) {
DiscoIdentity *identity = (DiscoIdentity*)malloc(sizeof(DiscoIdentity));
identity->category = caps->identity->category ? strdup(caps->identity->category) : NULL;
identity->type = caps->identity->type ? strdup(caps->identity->type) : NULL;
identity->name = caps->identity->name ? strdup(caps->identity->name) : NULL;
result->identity = identity;
} else {
result->identity = NULL;
}
result->software = caps->software ? strdup(caps->software) : NULL;
result->software_version = caps->software_version ? strdup(caps->software_version) : NULL;
result->os = caps->os ? strdup(caps->os) : NULL;
result->os_version = caps->os_version ? strdup(caps->os_version) : NULL;
result->features = NULL;
GSList *curr = caps->features;
while (curr) {
result->features = g_slist_append(result->features, strdup(curr->data));
curr = g_slist_next(curr);
}
return result;
}
}
2015-10-26 00:14:23 +00:00
char*
caps_create_sha1_str(xmpp_stanza_t *const query)
2013-01-21 22:18:15 +00:00
{
GSList *identities = NULL;
GSList *features = NULL;
GSList *form_names = NULL;
2014-09-05 20:04:16 +00:00
GHashTable *forms = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)form_destroy);
2013-01-21 22:18:15 +00:00
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
2014-09-21 20:43:42 +00:00
while (child) {
2013-01-21 22:18:15 +00:00
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");
2013-01-21 22:18:15 +00:00
GString *identity_str = g_string_new(category);
2013-01-21 22:18:15 +00:00
g_string_append(identity_str, "/");
2014-09-21 20:43:42 +00:00
if (type) {
g_string_append(identity_str, type);
2013-01-21 22:18:15 +00:00
}
g_string_append(identity_str, "/");
2014-09-21 20:43:42 +00:00
if (lang) {
g_string_append(identity_str, lang);
2013-01-21 22:18:15 +00:00
}
g_string_append(identity_str, "/");
2014-09-21 20:43:42 +00:00
if (name) {
g_string_append(identity_str, name);
2013-01-21 22:18:15 +00:00
}
g_string_append(identity_str, "<");
identities = g_slist_insert_sorted(identities, g_strdup(identity_str->str), (GCompareFunc)strcmp);
g_string_free(identity_str, TRUE);
2013-01-21 22:18:15 +00:00
} 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);
2013-01-21 22:18:15 +00:00
} else if (g_strcmp0(xmpp_stanza_get_name(child), STANZA_NAME_X) == 0) {
2014-09-21 20:43:42 +00:00
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);
2014-09-06 21:40:57 +00:00
form_names = g_slist_insert_sorted(form_names, g_strdup(form_type), (GCompareFunc)strcmp);
g_hash_table_insert(forms, g_strdup(form_type), form);
2013-01-21 22:18:15 +00:00
}
}
child = xmpp_stanza_get_next(child);
}
2014-09-21 20:43:42 +00:00
GString *s = g_string_new("");
2013-01-21 22:18:15 +00:00
GSList *curr = identities;
2014-09-21 20:43:42 +00:00
while (curr) {
g_string_append(s, curr->data);
2013-01-21 22:18:15 +00:00
curr = g_slist_next(curr);
}
curr = features;
2014-09-21 20:43:42 +00:00
while (curr) {
g_string_append(s, curr->data);
2013-01-21 22:18:15 +00:00
g_string_append(s, "<");
curr = g_slist_next(curr);
}
curr = form_names;
2014-09-21 20:43:42 +00:00
while (curr) {
DataForm *form = g_hash_table_lookup(forms, curr->data);
char *form_type = form_get_form_type_field(form);
2014-09-06 21:40:57 +00:00
g_string_append(s, form_type);
2013-01-21 22:18:15 +00:00
g_string_append(s, "<");
2014-09-21 20:43:42 +00:00
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, "<");
2014-09-21 20:43:42 +00:00
GSList *sorted_values = form_get_field_values_sorted(field);
GSList *curr_value = sorted_values;
while (curr_value) {
g_string_append(s, curr_value->data);
2013-01-21 22:18:15 +00:00
g_string_append(s, "<");
curr_value = g_slist_next(curr_value);
}
2014-09-21 20:43:42 +00:00
g_slist_free(sorted_values);
2013-02-03 17:19:10 +00:00
curr_field = g_slist_next(curr_field);
2013-01-21 22:18:15 +00:00
}
2014-09-21 20:43:42 +00:00
g_slist_free(sorted_fields);
2013-02-03 17:19:10 +00:00
curr = g_slist_next(curr);
2013-01-21 22:18:15 +00:00
}
char *result = p_sha1_hash(s->str);
2013-01-21 22:18:15 +00:00
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);
2013-01-21 22:18:15 +00:00
return result;
}
EntityCapabilities*
2014-09-18 23:49:48 +00:00
caps_create(xmpp_stanza_t *query)
{
2014-09-22 00:36:45 +00:00
char *software = NULL;
char *software_version = NULL;
char *os = NULL;
char *os_version = NULL;
2014-09-18 23:49:48 +00:00
xmpp_stanza_t *softwareinfo = xmpp_stanza_get_child_by_ns(query, STANZA_NS_DATA);
if (softwareinfo) {
2014-09-18 23:49:48 +00:00
DataForm *form = form_create(softwareinfo);
FormField *formField = NULL;
char *form_type = form_get_form_type_field(form);
if (g_strcmp0(form_type, STANZA_DATAFORM_SOFTWARE) == 0) {
GSList *field = form->fields;
while (field) {
2014-09-18 23:49:48 +00:00
formField = field->data;
if (formField->values) {
2014-09-18 23:49:48 +00:00
if (strcmp(formField->var, "software") == 0) {
2014-09-22 00:36:45 +00:00
software = strdup(formField->values->data);
2014-09-18 23:49:48 +00:00
} else if (strcmp(formField->var, "software_version") == 0) {
2014-09-22 00:36:45 +00:00
software_version = strdup(formField->values->data);
2014-09-18 23:49:48 +00:00
} else if (strcmp(formField->var, "os") == 0) {
2014-09-22 00:36:45 +00:00
os = strdup(formField->values->data);
2014-09-18 23:49:48 +00:00
} else if (strcmp(formField->var, "os_version") == 0) {
2014-09-22 00:36:45 +00:00
os_version = strdup(formField->values->data);
2014-09-18 23:49:48 +00:00
}
}
field = g_slist_next(field);
}
}
form_destroy(form);
}
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
GSList *identity_stanzas = NULL;
GSList *features = NULL;
while (child) {
2014-09-18 23:49:48 +00:00
if (g_strcmp0(xmpp_stanza_get_name(child), "feature") == 0) {
features = g_slist_append(features, strdup(xmpp_stanza_get_attribute(child, "var")));
}
if (g_strcmp0(xmpp_stanza_get_name(child), "identity") == 0) {
identity_stanzas = g_slist_append(identity_stanzas, child);
}
2014-09-18 23:49:48 +00:00
child = xmpp_stanza_get_next(child);
}
// find identity by locale
const gchar* const *langs = g_get_language_names();
int num_langs = g_strv_length((gchar**)langs);
xmpp_stanza_t *found = NULL;
GSList *curr_identity = identity_stanzas;
while (curr_identity) {
xmpp_stanza_t *id_stanza = curr_identity->data;
const char *stanza_lang = xmpp_stanza_get_attribute(id_stanza, "xml:lang");
if (stanza_lang) {
int i = 0;
for (i = 0; i < num_langs; i++) {
if (g_strcmp0(langs[i], stanza_lang) == 0) {
found = id_stanza;
break;
}
}
}
if (found) {
break;
2014-09-23 23:30:05 +00:00
}
curr_identity = g_slist_next(curr_identity);
}
// not lang match, use default with no lang
if (!found) {
curr_identity = identity_stanzas;
while (curr_identity) {
xmpp_stanza_t *id_stanza = curr_identity->data;
const char *stanza_lang = xmpp_stanza_get_attribute(id_stanza, "xml:lang");
if (!stanza_lang) {
found = id_stanza;
break;
}
curr_identity = g_slist_next(curr_identity);
}
}
// no matching lang, no identity without lang, use first
if (!found) {
if (identity_stanzas) {
found = identity_stanzas->data;
}
}
2014-09-24 00:06:49 +00:00
g_slist_free(identity_stanzas);
const char *category = NULL;
const char *type = NULL;
const char *name = NULL;
if (found) {
category = xmpp_stanza_get_attribute(found, "category");
type = xmpp_stanza_get_attribute(found, "type");
name = xmpp_stanza_get_attribute(found, "name");
}
EntityCapabilities *new_caps = malloc(sizeof(struct entity_capabilities_t));
2014-09-18 23:49:48 +00:00
if (category || type || name) {
DiscoIdentity *identity = malloc(sizeof(struct disco_identity_t));
identity->category = category ? strdup(category) : NULL;
identity->type = type ? strdup(type) : NULL;
identity->name = name ? strdup(name) : NULL;
new_caps->identity = identity;
2014-09-18 23:49:48 +00:00
} else {
new_caps->identity = NULL;
2014-09-18 23:49:48 +00:00
}
if (software) {
2014-09-22 00:36:45 +00:00
new_caps->software = software;
2014-09-18 23:49:48 +00:00
} else {
new_caps->software = NULL;
}
if (software_version) {
2014-09-22 00:36:45 +00:00
new_caps->software_version = software_version;
2014-09-18 23:49:48 +00:00
} else {
new_caps->software_version = NULL;
}
if (os) {
2014-09-22 00:36:45 +00:00
new_caps->os = os;
2014-09-18 23:49:48 +00:00
} else {
new_caps->os = NULL;
}
if (os_version) {
2014-09-22 00:36:45 +00:00
new_caps->os_version = os_version;
2014-09-18 23:49:48 +00:00
} else {
new_caps->os_version = NULL;
}
if (features) {
2014-09-18 23:49:48 +00:00
new_caps->features = features;
} else {
new_caps->features = NULL;
}
return new_caps;
}
2014-09-22 23:08:26 +00:00
char*
2015-10-26 00:14:23 +00:00
caps_get_my_sha1(xmpp_ctx_t *const ctx)
2014-09-22 23:08:26 +00:00
{
if (my_sha1 == NULL) {
xmpp_stanza_t *query = caps_create_query_response_stanza(ctx);
my_sha1 = caps_create_sha1_str(query);
xmpp_stanza_release(query);
}
return my_sha1;
}
2014-09-18 23:49:48 +00:00
void
caps_reset_ver(void)
{
if (my_sha1) {
g_free(my_sha1);
my_sha1 = NULL;
}
}
2015-10-26 00:14:23 +00:00
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 ");
2016-03-31 20:05:02 +00:00
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;
}
2014-12-22 22:13:42 +00:00
void
caps_close(void)
2013-01-20 00:35:40 +00:00
{
2014-09-22 00:36:45 +00:00
g_key_file_free(cache);
cache = NULL;
g_hash_table_destroy(jid_to_ver);
g_hash_table_destroy(jid_to_caps);
2016-07-24 20:35:12 +00:00
free(cache_loc);
cache_loc = NULL;
g_list_free_full(prof_features, free);
prof_features = NULL;
2013-01-20 00:35:40 +00:00
}
2013-01-20 00:57:44 +00:00
static void
_disco_identity_destroy(DiscoIdentity *disco_identity)
{
if (disco_identity) {
free(disco_identity->category);
free(disco_identity->name);
free(disco_identity->type);
}
}
2014-12-22 22:13:42 +00:00
void
caps_destroy(EntityCapabilities *caps)
2013-01-20 00:57:44 +00:00
{
if (caps) {
_disco_identity_destroy(caps->identity);
free(caps->software);
free(caps->software_version);
free(caps->os);
free(caps->os_version);
if (caps->features) {
2013-02-17 01:04:10 +00:00
g_slist_free_full(caps->features, free);
}
free(caps);
2013-01-20 00:57:44 +00:00
}
}
2013-12-22 23:16:19 +00:00
2014-09-22 00:36:45 +00:00
static void
_save_cache(void)
{
gsize g_data_size;
gchar *g_cache_data = g_key_file_to_data(cache, &g_data_size, NULL);
g_file_set_contents(cache_loc, g_cache_data, g_data_size, NULL);
2014-10-18 20:40:11 +00:00
g_chmod(cache_loc, S_IRUSR | S_IWUSR);
2014-09-22 00:36:45 +00:00
g_free(g_cache_data);
}