about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2016-05-08 02:25:34 +0100
committerJames Booth <boothj5@gmail.com>2016-05-08 02:25:34 +0100
commit31e6cc8e38a6647dd2270ce41c0fd3414da95c7e (patch)
treed02b36b999c2bc58e2dd47f4b6b6914d1a43bc3b
parent137202e5dd72175989e251cb890ef051adf641eb (diff)
downloadprofani-tty-31e6cc8e38a6647dd2270ce41c0fd3414da95c7e.tar.gz
Add connection_get_disco_info()
-rw-r--r--src/xmpp/connection.c27
-rw-r--r--src/xmpp/connection.h3
-rw-r--r--src/xmpp/iq.c27
-rw-r--r--src/xmpp/xmpp.h2
4 files changed, 31 insertions, 28 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 4c34fda4..d958403b 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -209,6 +209,21 @@ connection_get_disco_items(void)
     return conn.disco_items;
 }
 
+DiscoInfo*
+connection_get_disco_info(const char *const jid)
+{
+    GSList *curr = conn.disco_items;
+    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*
 connection_get_available_resources(void)
 {
@@ -360,7 +375,7 @@ static void
 _disco_item_destroy(DiscoInfo *info)
 {
     if (info) {
-        free(info->item);
+        free(info->jid);
         if (info->features) {
             g_hash_table_destroy(info->features);
         }
@@ -392,14 +407,14 @@ connection_supports(const char *const feature)
 }
 
 char*
-connection_item_for_feature(const char *const feature)
+connection_jid_for_feature(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 disco_info->item;
+            return disco_info->jid;
         }
         curr = g_slist_next(curr);
     }
@@ -414,10 +429,10 @@ connection_set_disco_items(GSList *items)
     while (curr) {
         DiscoItem *item = curr->data;
         DiscoInfo *info = malloc(sizeof(struct disco_info_t));
-        info->item = strdup(item->jid);
+        info->jid = strdup(item->jid);
         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);
-        iq_disco_info_request_onconnect(info->item);
+        iq_disco_info_request_onconnect(info->jid);
 
         curr = g_slist_next(curr);
     }
@@ -438,7 +453,7 @@ _connection_handler(xmpp_conn_t *const xmpp_conn, const xmpp_conn_event_t status
         jid_destroy(my_jid);
 
         DiscoInfo *info = malloc(sizeof(struct disco_info_t));
-        info->item = strdup(conn.domain);
+        info->jid = 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);
 
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index dce84046..92c951f2 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -58,7 +58,8 @@ 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);
-char* connection_item_for_feature(const char *const feature);
+char* connection_jid_for_feature(const char *const feature);
+DiscoInfo* connection_get_disco_info(const char *const jid);
 
 void connection_add_available_resource(Resource *resource);
 void connection_remove_available_resource(const char *const resource);
diff --git a/src/xmpp/iq.c b/src/xmpp/iq.c
index 83ef858e..fef714e2 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -309,15 +309,15 @@ iq_disable_carbons(void)
 void
 iq_http_upload_request(HTTPUpload *upload)
 {
-    char *item = connection_item_for_feature(STANZA_NS_HTTP_UPLOAD);
-    if (item == NULL) {
+    char *jid = connection_jid_for_feature(STANZA_NS_HTTP_UPLOAD);
+    if (jid == NULL) {
         cons_show_error("XEP-0363 HTTP File Upload is not supported by the server");
         return;
     }
 
     xmpp_ctx_t * const ctx = connection_get_ctx();
     char *id = create_unique_id("http_upload_request");
-    xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, item, upload);
+    xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, jid, upload);
     iq_id_handler_add(id, _http_upload_response_id_handler, upload);
     free(id);
 
@@ -1903,26 +1903,13 @@ _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);
 
     if (query) {
-        xmpp_stanza_t *child = xmpp_stanza_get_children(query);
-
-        GSList *curr = connection_get_disco_items();
-        if (curr == NULL) {
+        DiscoInfo *disco_info = connection_get_disco_info(from);
+        if (disco_info == NULL) {
+            log_error("No matching disco item found for %s", from);
             return 1;
         }
 
-        DiscoInfo *disco_info;
-        while (curr) {
-            disco_info = curr->data;
-            if (g_strcmp0(disco_info->item, from) == 0) {
-                break;
-            }
-            curr = g_slist_next(curr);
-            if (!curr) {
-                log_error("No matching disco item found for %s", from);
-                return 1;
-            }
-        }
-
+        xmpp_stanza_t *child = xmpp_stanza_get_children(query);
         while (child) {
             const char *stanza_name = xmpp_stanza_get_name(child);
             if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
diff --git a/src/xmpp/xmpp.h b/src/xmpp/xmpp.h
index 14cc84b4..8fca8ab5 100644
--- a/src/xmpp/xmpp.h
+++ b/src/xmpp/xmpp.h
@@ -106,7 +106,7 @@ typedef struct disco_identity_t {
 } DiscoIdentity;
 
 typedef struct disco_info_t {
-    char *item;
+    char *jid;
     GHashTable *features;
 } DiscoInfo;