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,24 +1905,24 @@ _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(); - 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; - } - } - } else { + GSList *curr = connection_get_disco_items(); + if (curr == NULL) { 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; + } + } + while (child) { const char *stanza_name = xmpp_stanza_get_name(child); if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {