about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--src/xmpp/connection.c16
-rw-r--r--src/xmpp/connection.h1
-rw-r--r--src/xmpp/iq.c53
3 files changed, 36 insertions, 34 deletions
diff --git a/src/xmpp/connection.c b/src/xmpp/connection.c
index 1c85bf79..4c34fda4 100644
--- a/src/xmpp/connection.c
+++ b/src/xmpp/connection.c
@@ -391,6 +391,22 @@ connection_supports(const char *const feature)
     return FALSE;
 }
 
+char*
+connection_item_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;
+        }
+        curr = g_slist_next(curr);
+    }
+
+    return NULL;
+}
+
 void
 connection_set_disco_items(GSList *items)
 {
diff --git a/src/xmpp/connection.h b/src/xmpp/connection.h
index 1b056954..dce84046 100644
--- a/src/xmpp/connection.h
+++ b/src/xmpp/connection.h
@@ -58,6 +58,7 @@ 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);
 
 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 297d1bd2..83ef858e 100644
--- a/src/xmpp/iq.c
+++ b/src/xmpp/iq.c
@@ -309,36 +309,21 @@ iq_disable_carbons(void)
 void
 iq_http_upload_request(HTTPUpload *upload)
 {
-    GSList *disco_items = connection_get_disco_items();
-    DiscoInfo *disco_info;
-    if (disco_items && (g_slist_length(disco_items) > 0)) {
-        while (disco_items) {
-            disco_info = disco_items->data;
-            if (g_hash_table_lookup_extended(disco_info->features, STANZA_NS_HTTP_UPLOAD, NULL, NULL)) {
-                break;
-            }
-            disco_items = g_slist_next(disco_items);
-            if (!disco_items) {
-                cons_show_error("XEP-0363 HTTP File Upload is not supported by the server");
-                return;
-            }
-        }
-    } else {
-        cons_show_error("No disco items");
+    char *item = connection_item_for_feature(STANZA_NS_HTTP_UPLOAD);
+    if (item == 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, disco_info->item, upload);
-
+    xmpp_stanza_t *iq = stanza_create_http_upload_request(ctx, id, item, upload);
     iq_id_handler_add(id, _http_upload_response_id_handler, upload);
-
     free(id);
 
     iq_send_stanza(iq);
     xmpp_stanza_release(iq);
+
     return;
 }
 
@@ -1920,22 +1905,22 @@ _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 = connection_get_disco_items();
+        GSList *curr = connection_get_disco_items();
+        if (curr == NULL) {
+            return 1;
+        }
+
         DiscoInfo *disco_info;
-        if (disco_items && (g_slist_length(disco_items) > 0)) {
-            while (disco_items) {
-                disco_info = disco_items->data;
-                if (g_strcmp0(disco_info->item, from) == 0) {
-                    break;
-                }
-                disco_items = g_slist_next(disco_items);
-                if (!disco_items) {
-                    log_error("No matching disco item found for %s", from);
-                    return 1;
-                }
+        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;
             }
-        } else {
-            return 1;
         }
 
         while (child) {
91'>291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397