mirror of
https://github.com/profanity-im/profanity.git
synced 2025-01-03 14:57:42 -05:00
Use hash table for disco features
This commit is contained in:
parent
29380a39cd
commit
ac3ab39e23
@ -61,7 +61,7 @@ typedef struct prof_conn_t {
|
|||||||
int priority;
|
int priority;
|
||||||
char *domain;
|
char *domain;
|
||||||
GHashTable *available_resources;
|
GHashTable *available_resources;
|
||||||
GSList *disco_infos;
|
GHashTable *features_by_jid;
|
||||||
} ProfConnection;
|
} ProfConnection;
|
||||||
|
|
||||||
static ProfConnection conn;
|
static ProfConnection conn;
|
||||||
@ -85,7 +85,7 @@ void connection_init(void)
|
|||||||
conn.xmpp_conn = NULL;
|
conn.xmpp_conn = NULL;
|
||||||
conn.xmpp_ctx = NULL;
|
conn.xmpp_ctx = NULL;
|
||||||
conn.domain = NULL;
|
conn.domain = NULL;
|
||||||
conn.disco_infos = NULL;
|
conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
|
||||||
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
|
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,19 +203,10 @@ connection_get_fulljid(void)
|
|||||||
return xmpp_conn_get_jid(conn.xmpp_conn);
|
return xmpp_conn_get_jid(conn.xmpp_conn);
|
||||||
}
|
}
|
||||||
|
|
||||||
DiscoInfo*
|
GHashTable*
|
||||||
connection_get_disco_info(const char *const jid)
|
connection_get_features(const char *const jid)
|
||||||
{
|
{
|
||||||
GSList *curr = conn.disco_infos;
|
return g_hash_table_lookup(conn.features_by_jid, jid);
|
||||||
while (curr) {
|
|
||||||
DiscoInfo *disco_info = curr->data;
|
|
||||||
if (g_strcmp0(disco_info->jid, jid) == 0) {
|
|
||||||
return disco_info;
|
|
||||||
}
|
|
||||||
curr = g_slist_next(curr);
|
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
GList*
|
GList*
|
||||||
@ -365,54 +356,52 @@ connection_send_stanza(const char *const stanza)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
_disco_info_destroy(DiscoInfo *info)
|
|
||||||
{
|
|
||||||
if (info) {
|
|
||||||
free(info->jid);
|
|
||||||
if (info->features) {
|
|
||||||
g_hash_table_destroy(info->features);
|
|
||||||
}
|
|
||||||
free(info);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
connection_disco_items_free(void)
|
connection_disco_items_free(void)
|
||||||
{
|
{
|
||||||
g_slist_free_full(conn.disco_infos, (GDestroyNotify)_disco_info_destroy);
|
g_hash_table_destroy(conn.features_by_jid);
|
||||||
conn.disco_infos = NULL;
|
conn.features_by_jid = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
connection_supports(const char *const feature)
|
connection_supports(const char *const feature)
|
||||||
{
|
{
|
||||||
DiscoInfo *disco_info;
|
GList *jids = g_hash_table_get_keys(conn.features_by_jid);
|
||||||
GSList *curr = conn.disco_infos;
|
|
||||||
|
GList *curr = jids;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
disco_info = curr->data;
|
char *jid = curr->data;
|
||||||
if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
|
GHashTable *features = g_hash_table_lookup(conn.features_by_jid, jid);
|
||||||
|
if (features && g_hash_table_lookup(features, feature)) {
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
curr = g_slist_next(curr);
|
|
||||||
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(jids);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
char*
|
char*
|
||||||
connection_jid_for_feature(const char *const feature)
|
connection_jid_for_feature(const char *const feature)
|
||||||
{
|
{
|
||||||
DiscoInfo *disco_info;
|
GList *jids = g_hash_table_get_keys(conn.features_by_jid);
|
||||||
GSList *curr = conn.disco_infos;
|
|
||||||
|
GList *curr = jids;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
disco_info = curr->data;
|
char *jid = curr->data;
|
||||||
if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
|
GHashTable *features = g_hash_table_lookup(conn.features_by_jid, jid);
|
||||||
return disco_info->jid;
|
if (features && g_hash_table_lookup(features, feature)) {
|
||||||
|
return jid;
|
||||||
}
|
}
|
||||||
curr = g_slist_next(curr);
|
|
||||||
|
curr = g_list_next(curr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g_list_free(jids);
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -422,11 +411,10 @@ connection_set_disco_items(GSList *items)
|
|||||||
GSList *curr = items;
|
GSList *curr = items;
|
||||||
while (curr) {
|
while (curr) {
|
||||||
DiscoItem *item = curr->data;
|
DiscoItem *item = curr->data;
|
||||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
g_hash_table_insert(conn.features_by_jid, strdup(item->jid),
|
||||||
info->jid = strdup(item->jid);
|
g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL));
|
||||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
|
||||||
conn.disco_infos = g_slist_append(conn.disco_infos, info);
|
iq_disco_info_request_onconnect(item->jid);
|
||||||
iq_disco_info_request_onconnect(info->jid);
|
|
||||||
|
|
||||||
curr = g_slist_next(curr);
|
curr = g_slist_next(curr);
|
||||||
}
|
}
|
||||||
@ -446,10 +434,7 @@ _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status
|
|||||||
conn.domain = strdup(my_jid->domainpart);
|
conn.domain = strdup(my_jid->domainpart);
|
||||||
jid_destroy(my_jid);
|
jid_destroy(my_jid);
|
||||||
|
|
||||||
DiscoInfo *info = malloc(sizeof(struct disco_info_t));
|
g_hash_table_insert(conn.features_by_jid, strdup(conn.domain), g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL));
|
||||||
info->jid = strdup(conn.domain);
|
|
||||||
info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
|
|
||||||
conn.disco_infos = g_slist_append(conn.disco_infos, info);
|
|
||||||
|
|
||||||
session_login_success(connection_is_secured());
|
session_login_success(connection_is_secured());
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ xmpp_conn_t* connection_get_conn(void);
|
|||||||
xmpp_ctx_t* connection_get_ctx(void);
|
xmpp_ctx_t* connection_get_ctx(void);
|
||||||
char *connection_get_domain(void);
|
char *connection_get_domain(void);
|
||||||
char* connection_jid_for_feature(const char *const feature);
|
char* connection_jid_for_feature(const char *const feature);
|
||||||
DiscoInfo* connection_get_disco_info(const char *const jid);
|
GHashTable* connection_get_features(const char *const jid);
|
||||||
|
|
||||||
void connection_add_available_resource(Resource *resource);
|
void connection_add_available_resource(Resource *resource);
|
||||||
void connection_remove_available_resource(const char *const resource);
|
void connection_remove_available_resource(const char *const resource);
|
||||||
|
@ -1903,8 +1903,8 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
|
|||||||
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
|
||||||
|
|
||||||
if (query) {
|
if (query) {
|
||||||
DiscoInfo *disco_info = connection_get_disco_info(from);
|
GHashTable *features = connection_get_features(from);
|
||||||
if (disco_info == NULL) {
|
if (features == NULL) {
|
||||||
log_error("No matching disco item found for %s", from);
|
log_error("No matching disco item found for %s", from);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -1915,7 +1915,7 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
|
|||||||
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
|
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
|
||||||
const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
|
const char *var = xmpp_stanza_get_attribute(child, STANZA_ATTR_VAR);
|
||||||
if (var) {
|
if (var) {
|
||||||
g_hash_table_add(disco_info->features, strdup(var));
|
g_hash_table_add(features, strdup(var));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
child = xmpp_stanza_get_next(child);
|
child = xmpp_stanza_get_next(child);
|
||||||
|
@ -105,11 +105,6 @@ typedef struct disco_identity_t {
|
|||||||
char *category;
|
char *category;
|
||||||
} DiscoIdentity;
|
} DiscoIdentity;
|
||||||
|
|
||||||
typedef struct disco_info_t {
|
|
||||||
char *jid;
|
|
||||||
GHashTable *features;
|
|
||||||
} DiscoInfo;
|
|
||||||
|
|
||||||
void session_init(void);
|
void session_init(void);
|
||||||
jabber_conn_status_t session_connect_with_details(const char *const jid, const char *const passwd,
|
jabber_conn_status_t session_connect_with_details(const char *const jid, const char *const passwd,
|
||||||
const char *const altdomain, const int port, const char *const tls_policy);
|
const char *const altdomain, const int port, const char *const tls_policy);
|
||||||
@ -119,7 +114,6 @@ void session_shutdown(void);
|
|||||||
void session_process_events(int millis);
|
void session_process_events(int millis);
|
||||||
char* session_get_account_name(void);
|
char* session_get_account_name(void);
|
||||||
|
|
||||||
|
|
||||||
jabber_conn_status_t connection_get_status(void);
|
jabber_conn_status_t connection_get_status(void);
|
||||||
char *connection_get_presence_msg(void);
|
char *connection_get_presence_msg(void);
|
||||||
const char* connection_get_fulljid(void);
|
const char* connection_get_fulljid(void);
|
||||||
|
Loading…
Reference in New Issue
Block a user