about summary refs log tree commit diff stats
path: root/src/xmpp/connection.c
diff options
context:
space:
mode:
authorDominik Heidler <dominik@heidler.eu>2016-04-04 17:26:37 +0200
committerDominik Heidler <dominik@heidler.eu>2016-04-20 00:19:40 +0200
commit28e260c7da7bddebcb7b08003174eb16b9a6f596 (patch)
tree66c35173490c1db9bb9fdc2b10193c11f83887c8 /src/xmpp/connection.c
parent20a0313d17db9c088f317651d1a61cc204f8ce3d (diff)
downloadprofani-tty-28e260c7da7bddebcb7b08003174eb16b9a6f596.tar.gz
Cache all disco items and features on connect
Diffstat (limited to 'src/xmpp/connection.c')
-rw-r--r--src/xmpp/connection.c36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index e760a0b7..710e71b2 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -75,6 +75,7 @@ static struct _jabber_conn_t {
 } jabber_conn;
 
 static GHashTable *available_resources;
+static GSList *disco_items;
 
 // for auto reconnect
 static struct {
@@ -113,6 +114,18 @@ void _connection_free_saved_account(void);
 void _connection_free_saved_details(void);
 void _connection_free_session_data(void);
 
+static void
+_info_destroy(DiscoInfo *info)
+{
+    if (info) {
+        free(info->item);
+        if (info->features) {
+            g_hash_table_remove_all(info->features);
+        }
+        free(info);
+    }
+}
+
 void
 jabber_init(void)
 {
@@ -125,6 +138,7 @@ jabber_init(void)
     presence_sub_requests_init();
     caps_init();
     available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
+    disco_items = NULL;
     xmpp_initialize();
 }
 
@@ -323,6 +337,18 @@ jabber_set_connection_status(jabber_conn_status_t status)
     jabber_conn.conn_status = status;
 }
 
+GSList*
+jabber_get_disco_items(void)
+{
+    return (disco_items);
+}
+
+void
+jabber_set_disco_items(GSList *_disco_items)
+{
+    disco_items = _disco_items;
+}
+
 xmpp_conn_t*
 connection_get_conn(void)
 {
@@ -420,6 +446,8 @@ _connection_free_saved_details(void)
 void
 _connection_free_session_data(void)
 {
+    g_slist_free_full(disco_items, (GDestroyNotify)_info_destroy);
+    disco_items = NULL;
     g_hash_table_remove_all(available_resources);
     chat_sessions_clear();
     presence_clear_sub_requests();
@@ -651,6 +679,14 @@ _connection_handler(xmpp_conn_t *const conn, const xmpp_conn_event_t status, con
         roster_request();
         bookmark_request();
 
+        // items discovery
+        DiscoInfo *info = malloc(sizeof(struct disco_info_t));
+        info->item = strdup(jabber_conn.domain);
+        info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+        disco_items = g_slist_append(disco_items, info);
+        iq_disco_info_request_onconnect(info->item);
+        iq_disco_items_request_onconnect(jabber_conn.domain);
+
         if (prefs_get_boolean(PREF_CARBONS)){
             iq_enable_carbons();
         }