diff --git a/discord/discord.c b/discord/discord.c index 539575dca7..ff2d1d5d01 100644 --- a/discord/discord.c +++ b/discord/discord.c @@ -149,7 +149,7 @@ static bool discord_download_avatar( strlcpy(transf->path, buf, sizeof(transf->path)); RARCH_LOG("[discord] downloading avatar from: %s\n", url_encoded); - task_push_http_transfer(url_encoded, true, NULL, cb_generic_download, transf); + task_push_http_transfer_file(url_encoded, true, NULL, cb_generic_download, transf); return false; } diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index a00f1049c9..f6fc4b5401 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -3991,7 +3991,7 @@ static int generic_action_ok_network(const char *path, strlcpy(transf->path, url_path, sizeof(transf->path)); net_http_urlencode_full(url_path_encoded, url_path, sizeof(url_path_encoded)); - task_push_http_transfer(url_path_encoded, suppress_msg, url_label, callback, transf); + task_push_http_transfer_file(url_path_encoded, suppress_msg, url_label, callback, transf); return generic_action_ok_displaylist_push(path, NULL, label, type, idx, entry_idx, type_id2); @@ -4293,7 +4293,7 @@ static int action_ok_download_generic(const char *path, else net_http_urlencode_full(s3, s2, sizeof(s3)); - task_push_http_transfer(s3, suppress_msg, msg_hash_to_str(enum_idx), cb, transf); + task_push_http_transfer_file(s3, suppress_msg, msg_hash_to_str(enum_idx), cb, transf); #endif return 0; } diff --git a/menu/menu_networking.c b/menu/menu_networking.c index 7df2fe7ea9..14c60d8199 100644 --- a/menu/menu_networking.c +++ b/menu/menu_networking.c @@ -241,7 +241,7 @@ finish: strlcpy(transf->path, parent_dir, sizeof(transf->path)); net_http_urlencode_full(parent_dir_encoded, parent_dir, PATH_MAX_LENGTH * sizeof(char)); - task_push_http_transfer(parent_dir_encoded, true, + task_push_http_transfer_file(parent_dir_encoded, true, "index_dirs", cb_net_generic_subdir, transf); free(parent_dir); diff --git a/tasks/task_core_updater.c b/tasks/task_core_updater.c index 9ff481fcae..af84836c4a 100644 --- a/tasks/task_core_updater.c +++ b/tasks/task_core_updater.c @@ -260,7 +260,7 @@ static void task_core_updater_get_list_handler(retro_task_t *task) transf->user_data = (void*)list_handle; /* Push HTTP transfer task */ - list_handle->http_task = (retro_task_t*)task_push_http_transfer( + list_handle->http_task = (retro_task_t*)task_push_http_transfer_file( buildbot_url, true, NULL, cb_http_task_core_updater_get_list, transf); @@ -288,7 +288,7 @@ static void task_core_updater_get_list_handler(retro_task_t *task) task, task_get_progress(list_handle->http_task)); } - /* Wait for task_push_http_transfer() + /* Wait for task_push_http_transfer_file() * callback to trigger */ if (list_handle->http_task_complete) list_handle->status = CORE_UPDATER_LIST_END; @@ -626,7 +626,7 @@ static void task_core_updater_download_handler(retro_task_t *task) transf->user_data = (void*)download_handle; /* Push HTTP transfer task */ - download_handle->http_task = (retro_task_t*)task_push_http_transfer( + download_handle->http_task = (retro_task_t*)task_push_http_transfer_file( download_handle->remote_core_path, true, NULL, cb_http_task_core_updater_download, transf); @@ -673,7 +673,7 @@ static void task_core_updater_download_handler(retro_task_t *task) } } - /* Wait for task_push_http_transfer() + /* Wait for task_push_http_transfer_file() * callback to trigger */ if (download_handle->http_task_complete) download_handle->status = CORE_UPDATER_DOWNLOAD_WAIT_DECOMPRESS; diff --git a/tasks/task_file_transfer.h b/tasks/task_file_transfer.h index f663bdf216..be5812bbd1 100644 --- a/tasks/task_file_transfer.h +++ b/tasks/task_file_transfer.h @@ -77,6 +77,9 @@ typedef struct void *user_data; } file_transfer_t; +void* task_push_http_transfer_file(const char* url, bool mute, const char* type, + retro_task_callback_t cb, file_transfer_t* transfer_data); + RETRO_END_DECLS #endif diff --git a/tasks/task_http.c b/tasks/task_http.c index 2379ab9513..da2a054b34 100644 --- a/tasks/task_http.c +++ b/tasks/task_http.c @@ -250,13 +250,9 @@ static void* task_push_http_transfer_generic( retro_task_callback_t cb, void *user_data) { task_finder_data_t find_data; - char tmp[255]; - const char *s = NULL; retro_task_t *t = NULL; http_handle_t *http = NULL; - tmp[0] = '\0'; - find_data.func = task_http_finder; find_data.userdata = (void*)url; @@ -299,22 +295,6 @@ static void* task_push_http_transfer_generic( t->user_data = user_data; t->progress = -1; - if (user_data) - s = ((file_transfer_t*)user_data)->path; - else - s = url; - - strlcpy(tmp, - msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp)); - strlcat(tmp, " ", sizeof(tmp)); - - if (strstr(s, ".index")) - strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp)); - else - strlcat(tmp, s, sizeof(tmp)); - - t->title = strdup(tmp); - task_queue_push(t); return t; @@ -334,11 +314,47 @@ void* task_push_http_transfer(const char *url, bool mute, { if (string_is_empty(url)) return NULL; + return task_push_http_transfer_generic( net_http_connection_new(url, "GET", NULL), url, mute, type, cb, user_data); } +void* task_push_http_transfer_file(const char* url, bool mute, + const char* type, + retro_task_callback_t cb, file_transfer_t* transfer_data) +{ + const char *s = NULL; + char tmp[255] = ""; + retro_task_t *t = NULL; + + if (string_is_empty(url)) + return NULL; + + t = task_push_http_transfer_generic( + net_http_connection_new(url, "GET", NULL), + url, mute, type, cb, transfer_data); + + if (!t) + return NULL; + + if (transfer_data) + s = transfer_data->path; + else + s = url; + + strlcpy(tmp, msg_hash_to_str(MSG_DOWNLOADING), sizeof(tmp)); + strlcat(tmp, " ", sizeof(tmp)); + + if (strstr(s, ".index")) + strlcat(tmp, msg_hash_to_str(MSG_INDEX_FILE), sizeof(tmp)); + else + strlcat(tmp, s, sizeof(tmp)); + + t->title = strdup(tmp); + return t; +} + void* task_push_http_transfer_with_user_agent(const char *url, bool mute, const char *type, const char* user_agent, retro_task_callback_t cb, void *user_data) diff --git a/tasks/task_pl_thumbnail_download.c b/tasks/task_pl_thumbnail_download.c index b8f3d571b8..383293913b 100644 --- a/tasks/task_pl_thumbnail_download.c +++ b/tasks/task_pl_thumbnail_download.c @@ -269,7 +269,7 @@ static void download_pl_thumbnail(pl_thumb_handle_t *pl_thumb) /* Note: We don't actually care if this fails since that * just means the file is missing from the server, so it's * not something we can handle here... */ - pl_thumb->http_task = (retro_task_t*)task_push_http_transfer( + pl_thumb->http_task = (retro_task_t*)task_push_http_transfer_file( url, true, NULL, cb_http_task_download_pl_thumbnail, transf); /* ...if it does fail, however, we can immediately @@ -411,7 +411,7 @@ static void task_pl_thumbnail_download_handler(retro_task_t *task) if (!pl_thumb->http_task) pl_thumb->http_task_complete = true; - /* > Wait for task_push_http_transfer() + /* > Wait for task_push_http_transfer_file() * callback to trigger */ if (pl_thumb->http_task_complete) pl_thumb->http_task = NULL; @@ -726,7 +726,7 @@ static void task_pl_entry_thumbnail_download_handler(retro_task_t *task) if (!pl_thumb->http_task) pl_thumb->http_task_complete = true; - /* > Wait for task_push_http_transfer() + /* > Wait for task_push_http_transfer_file() * callback to trigger */ if (pl_thumb->http_task_complete) pl_thumb->http_task = NULL;