about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-05-05 23:20:27 +0100
committerJames Booth <boothj5@gmail.com>2013-05-05 23:20:27 +0100
commit53eeb0ef45dd7cd871d4dca2c59b1dd208ee23c6 (patch)
treec43941a30a5993a6829bb22a1d7bb66f97701d9d
parentae4c54bdccca5ddd883200d0079d28b1f11d8f44 (diff)
downloadprofani-tty-53eeb0ef45dd7cd871d4dca2c59b1dd208ee23c6.tar.gz
Use autocomplete instead of hash table for subscription requests
-rw-r--r--src/ui/console.c7
-rw-r--r--src/xmpp/presence.c29
-rw-r--r--src/xmpp/xmpp.h2
3 files changed, 16 insertions, 22 deletions
diff --git a/src/ui/console.c b/src/ui/console.c
index 33cf1c51..47ae9843 100644
--- a/src/ui/console.c
+++ b/src/ui/console.c
@@ -571,16 +571,17 @@ cons_show_software_version(const char * const jid, const char * const  presence,
 void
 cons_show_received_subs(void)
 {
-    GList *received = presence_get_subscription_requests();
+    GSList *received = presence_get_subscription_requests();
     if (received == NULL) {
         cons_show("No outstanding subscription requests.");
     } else {
         cons_show("Outstanding subscription requests from:",
-            g_list_length(received));
+            g_slist_length(received));
         while (received != NULL) {
             cons_show("  %s", received->data);
-            received = g_list_next(received);
+            received = g_slist_next(received);
         }
+        g_slist_free_full(received, g_free);
     }
 }
 
diff --git a/src/xmpp/presence.c b/src/xmpp/presence.c
index 8dd0080b..1bd1ec93 100644
--- a/src/xmpp/presence.c
+++ b/src/xmpp/presence.c
@@ -37,7 +37,7 @@
 #include "xmpp/stanza.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, \
                                                 STANZA_NAME_PRESENCE, type, ctx)
@@ -63,8 +63,7 @@ void _send_caps_request(char *node, char *caps_key, char *id, char *from);
 void
 presence_init(void)
 {
-    sub_requests =
-        g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
+    sub_requests_ac = autocomplete_new();
 }
 
 void
@@ -92,7 +91,8 @@ presence_subscription(const char * const jid, const jabber_subscr_t action)
     const char *type = NULL;
 
     Jid *jidp = jid_create(jid);
-    g_hash_table_remove(sub_requests, jidp->barejid);
+
+    autocomplete_remove(sub_requests_ac, jidp->barejid);
 
     switch (action)
     {
@@ -123,28 +123,22 @@ presence_subscription(const char * const jid, const jabber_subscr_t action)
     jid_destroy(jidp);
 }
 
-GList *
+GSList *
 presence_get_subscription_requests(void)
 {
-    return g_hash_table_get_keys(sub_requests);
+    return autocomplete_get_list(sub_requests_ac);
 }
 
 gint
 presence_sub_request_count(void)
 {
-    if (sub_requests == NULL) {
-        return 0;
-    } else {
-       return g_hash_table_size(sub_requests);
-    }
+    return autocomplete_length(sub_requests_ac);
 }
 
 void
 presence_free_sub_requests(void)
 {
-    if (sub_requests != NULL) {
-        g_hash_table_remove_all(sub_requests);
-    }
+    autocomplete_free(sub_requests_ac);
 }
 
 void
@@ -293,7 +287,7 @@ _unsubscribed_handler(xmpp_conn_t * const conn,
     log_debug("Unsubscribed presence handler fired for %s", from);
 
     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);
 
@@ -309,7 +303,7 @@ _subscribed_handler(xmpp_conn_t * const conn,
     log_debug("Subscribed presence handler fired for %s", from);
 
     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);
 
@@ -325,8 +319,7 @@ _subscribe_handler(xmpp_conn_t * const conn,
     log_debug("Subscribe presence handler fired for %s", from);
 
     prof_handle_subscription(from_jid->barejid, PRESENCE_SUBSCRIBE);
-    g_hash_table_insert(sub_requests, strdup(from_jid->barejid),
-        strdup(from_jid->barejid));
+    autocomplete_add(sub_requests_ac, strdup(from_jid->barejid));
 
     jid_destroy(from_jid);
 
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index c65fdfd9..c38674b4 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -103,7 +103,7 @@ void message_send_duck(const char * const query);
 
 // presence functions
 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);
 void presence_join_room(Jid *jid);
 void presence_change_room_nick(const char * const room, const char * const nick);