about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-07 23:28:16 +0100
committerJames Booth <boothj5@gmail.com>2016-05-07 23:28:16 +0100
commit6ce8edc194f76e5a95d99887f378c0fee1202366 (patch)
treec6f577db00d67505cb455bea0538a16882f5fa18 /src
parent9596591610ae01a47cbd37f636094da6bb44d054 (diff)
downloadprofani-tty-6ce8edc194f76e5a95d99887f378c0fee1202366.tar.gz
Move disco info struct to connection
Diffstat (limited to 'src')
-rw-r--r--src/command/commands.c2
-rw-r--r--src/xmpp/connection.c58
-rw-r--r--src/xmpp/connection.h7
-rw-r--r--src/xmpp/iq.c6
-rw-r--r--src/xmpp/session.c53
-rw-r--r--src/xmpp/session.h2
-rw-r--r--src/xmpp/xmpp.h2
7 files changed, 70 insertions, 60 deletions
diff --git a/src/command/commands.c b/src/command/commands.c
index d3e0fc92..3cbca95e 100644
--- a/src/command/commands.c
+++ b/src/command/commands.c
@@ -2991,7 +2991,7 @@ cmd_blocked(ProfWin *window, const char *const command, gchar **args)
         return TRUE;
     }
 
-    if (!session_service_supports(XMPP_FEATURE_BLOCKING)) {
+    if (!connection_supports(XMPP_FEATURE_BLOCKING)) {
         cons_show("Blocking not supported by server.");
         return TRUE;
     }
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 56026c0c..bcce14be 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -60,6 +60,7 @@ typedef struct prof_conn_t {
     int priority;
     char *domain;
     GHashTable *available_resources;
+    GSList *disco_items;
 } ProfConnection;
 
 static ProfConnection conn;
@@ -82,6 +83,7 @@ void connection_init(void)
     conn.xmpp_conn = NULL;
     conn.xmpp_ctx = NULL;
     conn.domain = NULL;
+    conn.disco_items = NULL;
     conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
 }
 
@@ -199,6 +201,12 @@ connection_get_fulljid(void)
     return xmpp_conn_get_jid(conn.xmpp_conn);
 }
 
+GSList*
+connection_get_disco_items(void)
+{
+    return conn.disco_items;
+}
+
 GList*
 connection_get_available_resources(void)
 {
@@ -283,6 +291,12 @@ connection_set_presence_msg(const char *const message)
 }
 
 void
+connection_set_disco_items(GSList *disco_items)
+{
+    conn.disco_items = disco_items;
+}
+
+void
 connection_free_domain(void)
 {
     FREE_SET_NULL(conn.domain);
@@ -352,6 +366,50 @@ connection_send_stanza(const char *const stanza)
     }
 }
 
+void
+connection_disco_on_login(void)
+{
+    DiscoInfo *info = malloc(sizeof(struct disco_info_t));
+    info->item = strdup(conn.domain);
+    info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
+    conn.disco_items = g_slist_append(conn.disco_items, info);
+}
+
+void
+_disco_item_destroy(DiscoInfo *info)
+{
+    if (info) {
+        free(info->item);
+        if (info->features) {
+            g_hash_table_destroy(info->features);
+        }
+        free(info);
+    }
+}
+
+void
+connection_disco_items_free(void)
+{
+    g_slist_free_full(conn.disco_items, (GDestroyNotify)_disco_item_destroy);
+    conn.disco_items = NULL;
+}
+
+gboolean
+connection_supports(const char *const feature)
+{
+    DiscoInfo *disco_info;
+    GSList *curr = conn.disco_items;
+    while (curr) {
+        disco_info = curr->data;
+        if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
+            return TRUE;
+        }
+        curr = g_slist_next(curr);
+    }
+
+    return FALSE;
+}
+
 static void
 _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status, const int error,
     xmpp_stream_error_t *const stream_error, void *const userdata)
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index 20b4cd74..6d6218ea 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -41,14 +41,14 @@ void connection_init(void);
 
 jabber_conn_status_t connection_connect(const char *const fulljid, const char *const passwd, const char *const altdomain, int port,
     const char *const tls_policy);
-
-char *connection_get_domain(void);
+void connection_disco_on_login(void);
 
 void connection_set_status(jabber_conn_status_t status);
 void connection_set_presence_msg(const char *const message);
 void connection_set_priority(const int priority);
 void connection_set_domain(char *domain);
 void connection_set_priority(int priority);
+void connection_set_disco_items(GSList *disco_items);
 
 void connection_free_conn(void);
 void connection_free_ctx(void);
@@ -58,6 +58,9 @@ void connection_free_log(void);
 
 xmpp_conn_t* connection_get_conn(void);
 xmpp_ctx_t* connection_get_ctx(void);
+char *connection_get_domain(void);
+GSList* connection_get_disco_items(void);
+
 void connection_add_available_resource(Resource *resource);
 void connection_remove_available_resource(const char *const resource);
 void connection_remove_all_available_resources(void);
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index ccee7edf..f17cdcb7 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -309,7 +309,7 @@ iq_disable_carbons(void)
 void
 iq_http_upload_request(HTTPUpload *upload)
 {
-    GSList *disco_items = session_get_disco_items();
+    GSList *disco_items = connection_get_disco_items();
     DiscoInfo *disco_info;
     if (disco_items && (g_slist_length(disco_items) > 0)) {
         while (disco_items) {
@@ -1920,7 +1920,7 @@ _disco_info_response_id_handler_onconnect(xmpp_stanza_t *const stanza, void *con
     if (query) {
         xmpp_stanza_t *child = xmpp_stanza_get_children(query);
 
-        GSList *disco_items = session_get_disco_items();
+        GSList *disco_items = connection_get_disco_items();
         DiscoInfo *disco_info;
         if (disco_items && (g_slist_length(disco_items) > 0)) {
             while (disco_items) {
@@ -2055,7 +2055,7 @@ _disco_items_result_handler(xmpp_stanza_t *const stanza)
                 DiscoInfo *info = malloc(sizeof(struct disco_info_t));
                 info->item = strdup(item->jid);
                 info->features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
-                session_set_disco_items(g_slist_append(session_get_disco_items(), info));
+                connection_set_disco_items(g_slist_append(connection_get_disco_items(), info));
                 iq_disco_info_request_onconnect(info->item);
                 res_items = g_slist_next(res_items);
             }
diff --git a/src/xmpp/session.c b/src/xmpp/session.c
index 975b066f..8634a585 100644
--- a/src/xmpp/session.c
+++ b/src/xmpp/session.c
@@ -66,8 +66,6 @@
 #include "xmpp/stanza.h"
 #include "xmpp/xmpp.h"
 
-static GSList *disco_items;
-
 // for auto reconnect
 static struct {
     char *name;
@@ -91,8 +89,6 @@ static void _session_free_saved_account(void);
 static void _session_free_saved_details(void);
 static void _session_free_session_data(void);
 
-static void _session_info_destroy(DiscoInfo *info);
-
 void
 session_init(void)
 {
@@ -100,7 +96,6 @@ session_init(void)
     connection_init();
     presence_sub_requests_init();
     caps_init();
-    disco_items = NULL;
     xmpp_initialize();
 }
 
@@ -273,33 +268,6 @@ session_process_events(int millis)
     }
 }
 
-GSList*
-session_get_disco_items(void)
-{
-    return (disco_items);
-}
-
-gboolean
-session_service_supports(const char *const feature)
-{
-    DiscoInfo *disco_info;
-    while (disco_items) {
-        disco_info = disco_items->data;
-        if (g_hash_table_lookup_extended(disco_info->features, feature, NULL, NULL)) {
-            return TRUE;
-        }
-        disco_items = g_slist_next(disco_items);
-    }
-
-    return FALSE;
-}
-
-void
-session_set_disco_items(GSList *_disco_items)
-{
-    disco_items = _disco_items;
-}
-
 char*
 session_get_account_name(void)
 {
@@ -342,11 +310,8 @@ session_login_success(gboolean secured)
     blocking_request();
 
     // items discovery
-    DiscoInfo *info = malloc(sizeof(struct disco_info_t));
-    info->item = strdup(connection_get_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);
+    connection_disco_on_login();
+    iq_disco_info_request_onconnect(connection_get_domain());
     iq_disco_items_request_onconnect(connection_get_domain());
 
     if (prefs_get_boolean(PREF_CARBONS)){
@@ -393,18 +358,6 @@ session_lost_connection(void)
 }
 
 static void
-_session_info_destroy(DiscoInfo *info)
-{
-    if (info) {
-        free(info->item);
-        if (info->features) {
-            g_hash_table_destroy(info->features);
-        }
-        free(info);
-    }
-}
-
-static void
 _session_reconnect(void)
 {
     // reconnect with account.
@@ -441,8 +394,6 @@ _session_free_saved_details(void)
 static void
 _session_free_session_data(void)
 {
-    g_slist_free_full(disco_items, (GDestroyNotify)_session_info_destroy);
-    disco_items = NULL;
     connection_remove_all_available_resources();
     chat_sessions_clear();
     presence_clear_sub_requests();
diff --git a/src/xmpp/session.h b/src/xmpp/session.h
index da404c60..62337386 100644
--- a/src/xmpp/session.h
+++ b/src/xmpp/session.h
@@ -49,8 +49,6 @@
 void session_login_success(gboolean secured);
 void session_login_failed(void);
 void session_lost_connection(void);
-GSList* session_get_disco_items(void);
-void session_set_disco_items(GSList *_disco_items);
 void session_autoping_fail(void);
 
 #endif
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 86f57fa8..14cc84b4 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -119,7 +119,6 @@ void session_shutdown(void);
 void session_process_events(int millis);
 char* session_get_account_name(void);
 
-gboolean session_service_supports(const char *const feature);
 
 jabber_conn_status_t connection_get_status(void);
 char *connection_get_presence_msg(void);
@@ -132,6 +131,7 @@ TLSCertificate* connection_get_tls_peer_cert(void);
 gboolean connection_is_secured(void);
 gboolean connection_send_stanza(const char *const stanza);
 GList* connection_get_available_resources(void);
+gboolean connection_supports(const char *const feature);
 
 char* message_send_chat(const char *const barejid, const char *const msg, const char *const oob_url);
 char* message_send_chat_otr(const char *const barejid, const char *const msg);