1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Use autocomplete instead of hash table for subscription requests

This commit is contained in:
James Booth 2013-05-05 23:20:27 +01:00
parent ae4c54bdcc
commit 53eeb0ef45
3 changed files with 16 additions and 22 deletions

View File

@ -571,16 +571,17 @@ cons_show_software_version(const char * const jid, const char * const presence,
void void
cons_show_received_subs(void) cons_show_received_subs(void)
{ {
GList *received = presence_get_subscription_requests(); GSList *received = presence_get_subscription_requests();
if (received == NULL) { if (received == NULL) {
cons_show("No outstanding subscription requests."); cons_show("No outstanding subscription requests.");
} else { } else {
cons_show("Outstanding subscription requests from:", cons_show("Outstanding subscription requests from:",
g_list_length(received)); g_slist_length(received));
while (received != NULL) { while (received != NULL) {
cons_show(" %s", received->data); cons_show(" %s", received->data);
received = g_list_next(received); received = g_slist_next(received);
} }
g_slist_free_full(received, g_free);
} }
} }

View File

@ -37,7 +37,7 @@
#include "xmpp/stanza.h" #include "xmpp/stanza.h"
#include "xmpp/xmpp.h" #include "xmpp/xmpp.h"
static GHashTable *sub_requests; static Autocomplete sub_requests_ac;
#define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, \ #define HANDLE(ns, type, func) xmpp_handler_add(conn, func, ns, \
STANZA_NAME_PRESENCE, type, ctx) STANZA_NAME_PRESENCE, type, ctx)
@ -63,8 +63,7 @@ void _send_caps_request(char *node, char *caps_key, char *id, char *from);
void void
presence_init(void) presence_init(void)
{ {
sub_requests = sub_requests_ac = autocomplete_new();
g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
} }
void void
@ -92,7 +91,8 @@ presence_subscription(const char * const jid, const jabber_subscr_t action)
const char *type = NULL; const char *type = NULL;
Jid *jidp = jid_create(jid); Jid *jidp = jid_create(jid);
g_hash_table_remove(sub_requests, jidp->barejid);
autocomplete_remove(sub_requests_ac, jidp->barejid);
switch (action) switch (action)
{ {
@ -123,28 +123,22 @@ presence_subscription(const char * const jid, const jabber_subscr_t action)
jid_destroy(jidp); jid_destroy(jidp);
} }
GList * GSList *
presence_get_subscription_requests(void) presence_get_subscription_requests(void)
{ {
return g_hash_table_get_keys(sub_requests); return autocomplete_get_list(sub_requests_ac);
} }
gint gint
presence_sub_request_count(void) presence_sub_request_count(void)
{ {
if (sub_requests == NULL) { return autocomplete_length(sub_requests_ac);
return 0;
} else {
return g_hash_table_size(sub_requests);
}
} }
void void
presence_free_sub_requests(void) presence_free_sub_requests(void)
{ {
if (sub_requests != NULL) { autocomplete_free(sub_requests_ac);
g_hash_table_remove_all(sub_requests);
}
} }
void void
@ -293,7 +287,7 @@ _unsubscribed_handler(xmpp_conn_t * const conn,
log_debug("Unsubscribed presence handler fired for %s", from); log_debug("Unsubscribed presence handler fired for %s", from);
prof_handle_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED); prof_handle_subscription(from_jid->barejid, PRESENCE_UNSUBSCRIBED);
g_hash_table_remove(sub_requests, from_jid->barejid); autocomplete_remove(sub_requests_ac, from_jid->barejid);
jid_destroy(from_jid); jid_destroy(from_jid);
@ -309,7 +303,7 @@ _subscribed_handler(xmpp_conn_t * const conn,
log_debug("Subscribed presence handler fired for %s", from); log_debug("Subscribed presence handler fired for %s", from);
prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED); prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBED);
g_hash_table_remove(sub_requests, from_jid->barejid); autocomplete_remove(sub_requests_ac, from_jid->barejid);
jid_destroy(from_jid); jid_destroy(from_jid);
@ -325,8 +319,7 @@ _subscribe_handler(xmpp_conn_t * const conn,
log_debug("Subscribe presence handler fired for %s", from); log_debug("Subscribe presence handler fired for %s", from);
prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE); prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
g_hash_table_insert(sub_requests, strdup(from_jid->barejid), autocomplete_add(sub_requests_ac, strdup(from_jid->barejid));
strdup(from_jid->barejid));
jid_destroy(from_jid); jid_destroy(from_jid);

View File

@ -103,7 +103,7 @@ void message_send_duck(const char * const query);
// presence functions // presence functions
void presence_subscription(const char * const jid, const jabber_subscr_t action); void presence_subscription(const char * const jid, const jabber_subscr_t action);
GList* presence_get_subscription_requests(void); GSList* presence_get_subscription_requests(void);
gint presence_sub_request_count(void); gint presence_sub_request_count(void);
void presence_join_room(Jid *jid); void presence_join_room(Jid *jid);
void presence_change_room_nick(const char * const room, const char * const nick); void presence_change_room_nick(const char * const room, const char * const nick);