mirror of
https://github.com/libretro/RetroArch
synced 2025-04-16 08:43:10 +00:00
Reimplement http transfers using tasks
This commit is contained in:
parent
5d92e9061c
commit
935e03fa97
@ -559,7 +559,7 @@ void net_http_delete(struct http_t *state)
|
||||
|
||||
if (state->fd != -1)
|
||||
socket_close(state->fd);
|
||||
if (state->data)
|
||||
free(state->data);
|
||||
// if (state->data)
|
||||
// free(state->data);
|
||||
free(state);
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
|
||||
#include "../menu.h"
|
||||
#include "../menu_cbs.h"
|
||||
#include "../../msg_hash.h"
|
||||
|
||||
#ifdef HAVE_LIBRETRODB
|
||||
#include "../../database_info.h"
|
||||
@ -25,6 +26,20 @@
|
||||
#include "../../cores/internal_cores.h"
|
||||
|
||||
#include "../../general.h"
|
||||
#include "../../tasks/tasks.h"
|
||||
|
||||
#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU
|
||||
#define CB_CORE_UPDATER_LIST 0x32fd4f01U
|
||||
#define CB_UPDATE_ASSETS 0xbf85795eU
|
||||
#define CB_UPDATE_CORE_INFO_FILES 0xe6084091U
|
||||
#define CB_UPDATE_AUTOCONFIG_PROFILES 0x28ada67dU
|
||||
#define CB_UPDATE_CHEATS 0xc360fec3U
|
||||
#define CB_UPDATE_OVERLAYS 0x699009a0U
|
||||
#define CB_UPDATE_DATABASES 0x931eb8d3U
|
||||
#define CB_UPDATE_SHADERS_GLSL 0x0121a186U
|
||||
#define CB_UPDATE_SHADERS_CG 0xc93a53feU
|
||||
#define CB_CORE_CONTENT_LIST 0xebc51227U
|
||||
#define CB_CORE_CONTENT_DOWNLOAD 0x03b3c0a3U
|
||||
|
||||
#ifndef BIND_ACTION_DEFERRED_PUSH
|
||||
#define BIND_ACTION_DEFERRED_PUSH(cbs, name) \
|
||||
@ -32,10 +47,6 @@
|
||||
cbs->action_deferred_push_ident = #name;
|
||||
#endif
|
||||
|
||||
/* foward declarations */
|
||||
int cb_core_updater_list(void *data_, size_t len);
|
||||
int cb_core_content_list(void *data_, size_t len);
|
||||
|
||||
static int deferred_push_dlist(menu_displaylist_info_t *info, unsigned val)
|
||||
{
|
||||
if (menu_displaylist_push_list(info, val) != 0)
|
||||
@ -282,41 +293,176 @@ static int deferred_push_disk_options(menu_displaylist_info_t *info)
|
||||
char *core_buf;
|
||||
size_t core_len;
|
||||
|
||||
static int cb_net_generic(void *data_, size_t len)
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err)
|
||||
{
|
||||
int ret = -1;
|
||||
char *data = (char*)data_;
|
||||
menu_handle_t *menu = menu_driver_get_ptr();
|
||||
if (!menu || !data)
|
||||
goto end;
|
||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||
|
||||
if (!menu || !data || err)
|
||||
goto finish;
|
||||
|
||||
if (core_buf)
|
||||
free(core_buf);
|
||||
|
||||
core_buf = (char*)malloc((len+1) * sizeof(char));
|
||||
core_buf = (char*)malloc((data->len+1) * sizeof(char));
|
||||
|
||||
if (!core_buf)
|
||||
goto end;
|
||||
goto finish;
|
||||
|
||||
memcpy(core_buf, data, len * sizeof(char));
|
||||
core_buf[len] = '\0';
|
||||
core_len = len;
|
||||
memcpy(core_buf, data->data, data->len * sizeof(char));
|
||||
core_buf[data->len] = '\0';
|
||||
core_len = data->len;
|
||||
ret = 0;
|
||||
|
||||
menu_entries_unset_refresh(true);
|
||||
|
||||
end:
|
||||
return ret;
|
||||
finish:
|
||||
if (data)
|
||||
{
|
||||
if (data->data)
|
||||
free(data->data);
|
||||
free(data);
|
||||
}
|
||||
}
|
||||
|
||||
int cb_core_updater_list(void *data_, size_t len)
|
||||
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
uint32_t crc32, void *userdata)
|
||||
{
|
||||
return cb_net_generic(data_, len);
|
||||
char path[PATH_MAX_LENGTH];
|
||||
|
||||
/* Make directory */
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
path_basedir(path);
|
||||
|
||||
if (!path_mkdir(path))
|
||||
goto error;
|
||||
|
||||
/* Ignore directories. */
|
||||
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
||||
return 1;
|
||||
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
|
||||
RARCH_LOG("path is: %s, CRC32: 0x%x\n", path, crc32);
|
||||
|
||||
if (!zlib_perform_mode(path, valid_exts,
|
||||
cdata, cmode, csize, size, crc32, userdata))
|
||||
goto error;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int cb_core_content_list(void *data_, size_t len)
|
||||
/* expects http_transfer_t*, menu_file_transfer_t* */
|
||||
void cb_generic_download(void *task_data, void *user_data, const char *err)
|
||||
//(void *data, size_t len, const char *dir_path)
|
||||
{
|
||||
return cb_net_generic(data_, len);
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char output_path[PATH_MAX_LENGTH];
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
const char *file_ext = NULL;
|
||||
const char *dir_path = NULL;
|
||||
menu_file_transfer_t *transf = (menu_file_transfer_t*)user_data;
|
||||
settings_t *settings = config_get_ptr();
|
||||
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
|
||||
|
||||
if (!data || !data->data | !transf)
|
||||
goto finish;
|
||||
|
||||
/* we have to determine dir_path at the time of writting or else
|
||||
* we'd run into races when the user changes the setting during an
|
||||
* http transfer. */
|
||||
switch (transf->type_hash)
|
||||
{
|
||||
case CB_CORE_UPDATER_DOWNLOAD:
|
||||
dir_path = settings->libretro_directory;
|
||||
break;
|
||||
case CB_CORE_CONTENT_DOWNLOAD:
|
||||
dir_path = settings->core_assets_directory;
|
||||
break;
|
||||
case CB_UPDATE_CORE_INFO_FILES:
|
||||
dir_path = settings->libretro_info_path;
|
||||
break;
|
||||
case CB_UPDATE_ASSETS:
|
||||
dir_path = settings->assets_directory;
|
||||
break;
|
||||
case CB_UPDATE_AUTOCONFIG_PROFILES:
|
||||
dir_path = settings->input.autoconfig_dir;
|
||||
break;
|
||||
case CB_UPDATE_DATABASES:
|
||||
dir_path = settings->content_database;
|
||||
break;
|
||||
case CB_UPDATE_OVERLAYS:
|
||||
dir_path = settings->overlay_directory;
|
||||
break;
|
||||
case CB_UPDATE_CHEATS:
|
||||
dir_path = settings->cheat_database;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_CG:
|
||||
case CB_UPDATE_SHADERS_GLSL:
|
||||
{
|
||||
const char *dirname = transf->type_hash == CB_UPDATE_SHADERS_CG ?
|
||||
"shaders_cg" : "shaders_glsl";
|
||||
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, dirname,
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
goto finish;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
RARCH_WARN("Unknown transfer type '%u' bailing out.\n", transf->type_hash);
|
||||
break;
|
||||
}
|
||||
|
||||
fill_pathname_join(output_path, dir_path,
|
||||
transf->path, sizeof(output_path));
|
||||
|
||||
if (!retro_write_file(output_path, data->data, data->len))
|
||||
goto finish;
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s: %s.",
|
||||
msg_hash_to_str(MSG_DOWNLOAD_COMPLETE),
|
||||
transf->path);
|
||||
|
||||
rarch_main_msg_queue_push(msg, 1, 90, true);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
/* TODO: this should generate a new task instead of blocking */
|
||||
file_ext = path_get_extension(output_path);
|
||||
|
||||
if (!settings->network.buildbot_auto_extract_archive)
|
||||
goto finish;
|
||||
|
||||
if (!strcasecmp(file_ext, "zip"))
|
||||
{
|
||||
if (!zlib_parse_file(output_path, NULL, zlib_extract_core_callback,
|
||||
(void*)dir_path))
|
||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COULD_NOT_PROCESS_ZIP_FILE));
|
||||
|
||||
if (path_file_exists(output_path))
|
||||
remove(output_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (transf->type_hash == CB_CORE_UPDATER_DOWNLOAD)
|
||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||
|
||||
finish:
|
||||
if (data)
|
||||
{
|
||||
if (data->data)
|
||||
free(data->data);
|
||||
free(data);
|
||||
}
|
||||
|
||||
free(transf);
|
||||
}
|
||||
|
||||
static int deferred_push_core_updater_list(menu_displaylist_info_t *info)
|
||||
|
@ -39,9 +39,9 @@
|
||||
char detect_content_path[PATH_MAX_LENGTH];
|
||||
unsigned rdb_entry_start_game_selection_ptr, rpl_entry_selection_ptr;
|
||||
size_t hack_shader_pass = 0;
|
||||
#ifdef HAVE_NETWORKING
|
||||
char core_updater_path[PATH_MAX_LENGTH];
|
||||
#endif
|
||||
|
||||
/* defined in menu_cbs_deferred_push */
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err);
|
||||
|
||||
int generic_action_ok_displaylist_push(const char *path,
|
||||
const char *label, unsigned type, size_t idx, size_t entry_idx,
|
||||
@ -1114,6 +1114,7 @@ static int action_ok_download_generic(const char *path,
|
||||
char s2[PATH_MAX_LENGTH];
|
||||
char s3[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
menu_file_transfer_t *transf;
|
||||
|
||||
fill_pathname_join(s, settings->network.buildbot_assets_url,
|
||||
"frontend", sizeof(s));
|
||||
@ -1148,7 +1149,9 @@ static int action_ok_download_generic(const char *path,
|
||||
|
||||
fill_pathname_join(s3, s, path, sizeof(s3));
|
||||
|
||||
strlcpy(core_updater_path, path, sizeof(core_updater_path));
|
||||
transf = (menu_file_transfer_t*)calloc(1, sizeof(*transf));
|
||||
transf->type_hash = menu_hash_calculate(type_msg);
|
||||
strlcpy(transf->path, path, sizeof(transf->path));
|
||||
|
||||
snprintf(s2, sizeof(s2),
|
||||
"%s %s.",
|
||||
@ -1157,8 +1160,7 @@ static int action_ok_download_generic(const char *path,
|
||||
|
||||
menu_display_msg_queue_push(s2, 1, 90, true);
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, s3,
|
||||
type_msg, 0, 1, true);
|
||||
rarch_task_push_http_transfer(s3, type_msg, cb_generic_download, transf);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -1383,6 +1385,7 @@ static int generic_action_ok_network(const char *path,
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned type_id2 = 0;
|
||||
const char *url_label = NULL;
|
||||
rarch_task_callback_t callback = NULL;
|
||||
|
||||
menu_entries_set_refresh(true);
|
||||
|
||||
@ -1398,17 +1401,22 @@ static int generic_action_ok_network(const char *path,
|
||||
"cores/gw/.index", sizeof(url_path));
|
||||
url_label = "cb_core_content_list";
|
||||
type_id2 = ACTION_OK_DL_CORE_CONTENT_LIST;
|
||||
callback = cb_net_generic;
|
||||
break;
|
||||
case ACTION_OK_NETWORK_CORE_UPDATER_LIST:
|
||||
fill_pathname_join(url_path, settings->network.buildbot_url,
|
||||
".index", sizeof(url_path));
|
||||
url_label = "cb_core_updater_list";
|
||||
type_id2 = ACTION_OK_DL_CORE_UPDATER_LIST;
|
||||
callback = cb_net_generic;
|
||||
break;
|
||||
}
|
||||
|
||||
rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, url_path, url_label, 0, 1,
|
||||
true);
|
||||
// rarch_main_data_msg_queue_push(DATA_TYPE_HTTP, url_path, url_label, 0, 1,
|
||||
// true);
|
||||
|
||||
rarch_task_push_http_transfer(url_path, url_label, callback, NULL);
|
||||
|
||||
return generic_action_ok_displaylist_push(path,
|
||||
label, type, idx, entry_idx, type_id2);
|
||||
}
|
||||
|
@ -67,9 +67,6 @@ enum
|
||||
|
||||
/* FIXME - Externs, refactor */
|
||||
extern size_t hack_shader_pass;
|
||||
#ifdef HAVE_NETWORKING
|
||||
extern char core_updater_path[PATH_MAX_LENGTH];
|
||||
#endif
|
||||
|
||||
/* Function callbacks */
|
||||
|
||||
@ -200,4 +197,15 @@ void menu_cbs_init(void *data,
|
||||
|
||||
bool menu_playlist_find_associated_core(const char *path, char *s, size_t len);
|
||||
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
void cb_net_generic(void *task_data, void *user_data, const char *err);
|
||||
|
||||
typedef struct {
|
||||
uint32_t type_hash;
|
||||
char path[PATH_MAX_LENGTH];
|
||||
} menu_file_transfer_t;
|
||||
void cb_generic_download(void *task_data, void *user_data, const char *err);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
@ -85,18 +85,11 @@ void rarch_main_data_deinit(void)
|
||||
|
||||
void rarch_main_data_free(void)
|
||||
{
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_uninit();
|
||||
#endif
|
||||
|
||||
memset(&g_data_runloop, 0, sizeof(g_data_runloop));
|
||||
}
|
||||
|
||||
static void data_runloop_iterate(bool is_thread)
|
||||
{
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_iterate (is_thread);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -106,12 +99,6 @@ bool rarch_main_data_active(void)
|
||||
if (input_overlay_data_is_active())
|
||||
return true;
|
||||
#endif
|
||||
#ifdef HAVE_NETWORKING
|
||||
if (rarch_main_data_http_get_handle())
|
||||
return true;
|
||||
if (rarch_main_data_http_conn_get_handle())
|
||||
return true;
|
||||
#endif
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -249,18 +236,11 @@ void rarch_main_data_clear_state(void)
|
||||
rarch_main_data_deinit();
|
||||
rarch_main_data_free();
|
||||
rarch_main_data_init();
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_init();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_init_queues(void)
|
||||
{
|
||||
#ifdef HAVE_NETWORKING
|
||||
rarch_main_data_http_init_msg_queue();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@ -284,8 +264,6 @@ void rarch_main_data_msg_queue_push(unsigned type,
|
||||
break;
|
||||
#ifdef HAVE_NETWORKING
|
||||
case DATA_TYPE_HTTP:
|
||||
queue = rarch_main_data_http_get_msg_queue_ptr();
|
||||
fill_pathname_join_delim(new_msg, msg, msg2, '|', sizeof(new_msg));
|
||||
break;
|
||||
#endif
|
||||
#ifdef HAVE_OVERLAY
|
||||
|
@ -30,19 +30,6 @@
|
||||
#include "../verbosity.h"
|
||||
#include "tasks.h"
|
||||
|
||||
#define CB_CORE_UPDATER_DOWNLOAD 0x7412da7dU
|
||||
#define CB_CORE_UPDATER_LIST 0x32fd4f01U
|
||||
#define CB_UPDATE_ASSETS 0xbf85795eU
|
||||
#define CB_UPDATE_CORE_INFO_FILES 0xe6084091U
|
||||
#define CB_UPDATE_AUTOCONFIG_PROFILES 0x28ada67dU
|
||||
#define CB_UPDATE_CHEATS 0xc360fec3U
|
||||
#define CB_UPDATE_OVERLAYS 0x699009a0U
|
||||
#define CB_UPDATE_DATABASES 0x931eb8d3U
|
||||
#define CB_UPDATE_SHADERS_GLSL 0x0121a186U
|
||||
#define CB_UPDATE_SHADERS_CG 0xc93a53feU
|
||||
#define CB_CORE_CONTENT_LIST 0xebc51227U
|
||||
#define CB_CORE_CONTENT_DOWNLOAD 0x03b3c0a3U
|
||||
|
||||
extern char core_updater_path[PATH_MAX_LENGTH];
|
||||
|
||||
enum http_status_enum
|
||||
@ -63,175 +50,11 @@ typedef struct http_handle
|
||||
transfer_cb_t cb;
|
||||
char elem1[PATH_MAX_LENGTH];
|
||||
} connection;
|
||||
msg_queue_t *msg_queue;
|
||||
struct http_t *handle;
|
||||
transfer_cb_t cb;
|
||||
unsigned status;
|
||||
} http_handle_t;
|
||||
|
||||
int cb_core_updater_list(void *data_, size_t len);
|
||||
int cb_core_content_list(void *data_, size_t len);
|
||||
|
||||
static http_handle_t *http_ptr;
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
#ifdef HAVE_MENU
|
||||
static int zlib_extract_core_callback(const char *name, const char *valid_exts,
|
||||
const uint8_t *cdata, unsigned cmode, uint32_t csize, uint32_t size,
|
||||
uint32_t crc32, void *userdata)
|
||||
{
|
||||
char path[PATH_MAX_LENGTH];
|
||||
|
||||
/* Make directory */
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
path_basedir(path);
|
||||
|
||||
if (!path_mkdir(path))
|
||||
goto error;
|
||||
|
||||
/* Ignore directories. */
|
||||
if (name[strlen(name) - 1] == '/' || name[strlen(name) - 1] == '\\')
|
||||
return 1;
|
||||
|
||||
fill_pathname_join(path, (const char*)userdata, name, sizeof(path));
|
||||
|
||||
RARCH_LOG("path is: %s, CRC32: 0x%x\n", path, crc32);
|
||||
|
||||
if (!zlib_perform_mode(path, valid_exts,
|
||||
cdata, cmode, csize, size, crc32, userdata))
|
||||
goto error;
|
||||
|
||||
return 1;
|
||||
|
||||
error:
|
||||
RARCH_ERR("Failed to deflate to: %s.\n", path);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_MENU
|
||||
static int cb_generic_download(void *data, size_t len,
|
||||
const char *dir_path)
|
||||
{
|
||||
char msg[PATH_MAX_LENGTH];
|
||||
char output_path[PATH_MAX_LENGTH];
|
||||
const char *file_ext = NULL;
|
||||
settings_t *settings = config_get_ptr();
|
||||
|
||||
if (!data)
|
||||
return -1;
|
||||
|
||||
fill_pathname_join(output_path, dir_path,
|
||||
core_updater_path, sizeof(output_path));
|
||||
|
||||
if (!retro_write_file(output_path, data, len))
|
||||
return -1;
|
||||
|
||||
snprintf(msg, sizeof(msg), "%s: %s.",
|
||||
msg_hash_to_str(MSG_DOWNLOAD_COMPLETE),
|
||||
core_updater_path);
|
||||
|
||||
rarch_main_msg_queue_push(msg, 1, 90, true);
|
||||
|
||||
#ifdef HAVE_ZLIB
|
||||
file_ext = path_get_extension(output_path);
|
||||
|
||||
if (!settings->network.buildbot_auto_extract_archive)
|
||||
return 0;
|
||||
|
||||
if (!strcasecmp(file_ext,"zip"))
|
||||
{
|
||||
if (!zlib_parse_file(output_path, NULL, zlib_extract_core_callback,
|
||||
(void*)dir_path))
|
||||
RARCH_LOG("%s\n", msg_hash_to_str(MSG_COULD_NOT_PROCESS_ZIP_FILE));
|
||||
|
||||
if (path_file_exists(output_path))
|
||||
remove(output_path);
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int cb_core_updater_download(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
int ret = cb_generic_download(data, len, settings->libretro_directory);
|
||||
if (ret == 0)
|
||||
event_command(EVENT_CMD_CORE_INFO_INIT);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int cb_core_content_download(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->core_assets_directory);
|
||||
}
|
||||
|
||||
static int cb_update_core_info_files(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->libretro_info_path);
|
||||
}
|
||||
|
||||
static int cb_update_assets(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->assets_directory);
|
||||
}
|
||||
|
||||
static int cb_update_autoconfig_profiles(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->input.autoconfig_dir);
|
||||
}
|
||||
|
||||
static int cb_update_shaders_cg(void *data, size_t len)
|
||||
{
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, "shaders_cg",
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
return -1;
|
||||
|
||||
return cb_generic_download(data, len, shaderdir);
|
||||
}
|
||||
|
||||
static int cb_update_shaders_glsl(void *data, size_t len)
|
||||
{
|
||||
char shaderdir[PATH_MAX_LENGTH];
|
||||
settings_t *settings = config_get_ptr();
|
||||
fill_pathname_join(shaderdir, settings->video.shader_dir, "shaders_glsl",
|
||||
sizeof(shaderdir));
|
||||
if (!path_file_exists(shaderdir))
|
||||
if (!path_mkdir(shaderdir))
|
||||
return -1;
|
||||
|
||||
return cb_generic_download(data, len, shaderdir);
|
||||
}
|
||||
|
||||
static int cb_update_databases(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->content_database);
|
||||
}
|
||||
|
||||
static int cb_update_overlays(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->overlay_directory);
|
||||
}
|
||||
|
||||
static int cb_update_cheats(void *data, size_t len)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
return cb_generic_download(data, len, settings->cheat_database);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int rarch_main_data_http_con_iterate_transfer(http_handle_t *http)
|
||||
{
|
||||
if (!net_http_connection_iterate(http->connection.handle))
|
||||
@ -254,23 +77,6 @@ static int rarch_main_data_http_conn_iterate_transfer_parse(http_handle_t *http)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int rarch_main_data_http_iterate_transfer_parse(http_handle_t *http)
|
||||
{
|
||||
size_t len = 0;
|
||||
char *data = (char*)net_http_data(http->handle, &len, false);
|
||||
|
||||
if (data && http->cb)
|
||||
http->cb(data, len);
|
||||
|
||||
net_http_delete(http->handle);
|
||||
|
||||
http->handle = NULL;
|
||||
msg_queue_clear(http->msg_queue);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static int cb_http_conn_default(void *data_, size_t len)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)data_;
|
||||
@ -291,116 +97,9 @@ static int cb_http_conn_default(void *data_, size_t len)
|
||||
|
||||
http->cb = NULL;
|
||||
|
||||
if (http->connection.elem1[0] != '\0')
|
||||
{
|
||||
uint32_t label_hash = msg_hash_calculate(http->connection.elem1);
|
||||
|
||||
switch (label_hash)
|
||||
{
|
||||
#ifdef HAVE_MENU
|
||||
case CB_CORE_UPDATER_DOWNLOAD:
|
||||
http->cb = &cb_core_updater_download;
|
||||
break;
|
||||
case CB_CORE_CONTENT_DOWNLOAD:
|
||||
http->cb = &cb_core_content_download;
|
||||
break;
|
||||
case CB_CORE_UPDATER_LIST:
|
||||
http->cb = &cb_core_updater_list;
|
||||
break;
|
||||
case CB_CORE_CONTENT_LIST:
|
||||
http->cb = &cb_core_content_list;
|
||||
break;
|
||||
case CB_UPDATE_ASSETS:
|
||||
http->cb = &cb_update_assets;
|
||||
break;
|
||||
case CB_UPDATE_CORE_INFO_FILES:
|
||||
http->cb = &cb_update_core_info_files;
|
||||
break;
|
||||
case CB_UPDATE_AUTOCONFIG_PROFILES:
|
||||
http->cb = &cb_update_autoconfig_profiles;
|
||||
break;
|
||||
case CB_UPDATE_CHEATS:
|
||||
http->cb = &cb_update_cheats;
|
||||
break;
|
||||
case CB_UPDATE_DATABASES:
|
||||
http->cb = &cb_update_databases;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_CG:
|
||||
http->cb = &cb_update_shaders_cg;
|
||||
break;
|
||||
case CB_UPDATE_SHADERS_GLSL:
|
||||
http->cb = &cb_update_shaders_glsl;
|
||||
break;
|
||||
case CB_UPDATE_OVERLAYS:
|
||||
http->cb = &cb_update_overlays;
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* rarch_main_data_http_iterate_poll:
|
||||
*
|
||||
* Polls HTTP message queue to see if any new URLs
|
||||
* are pending.
|
||||
*
|
||||
* If handle is freed, will set up a new http handle.
|
||||
* The transfer will be started on the next frame.
|
||||
*
|
||||
* Returns: 0 when an URL has been pulled and we will
|
||||
* begin transferring on the next frame. Returns -1 if
|
||||
* no HTTP URL has been pulled. Do nothing in that case.
|
||||
**/
|
||||
static int rarch_main_data_http_iterate_poll(http_handle_t *http)
|
||||
{
|
||||
char elem0[PATH_MAX_LENGTH];
|
||||
struct string_list *str_list = NULL;
|
||||
const char *url = msg_queue_pull(http->msg_queue);
|
||||
|
||||
if (!url)
|
||||
return -1;
|
||||
|
||||
/* Can only deal with one HTTP transfer at a time for now */
|
||||
if (http->handle)
|
||||
return -1;
|
||||
|
||||
str_list = string_split(url, "|");
|
||||
|
||||
if (!str_list || (str_list->size < 1))
|
||||
goto error;
|
||||
|
||||
strlcpy(elem0, str_list->elems[0].data, sizeof(elem0));
|
||||
|
||||
http->connection.handle = net_http_connection_new(elem0);
|
||||
|
||||
if (!http->connection.handle)
|
||||
return -1;
|
||||
|
||||
http->connection.cb = &cb_http_conn_default;
|
||||
|
||||
|
||||
if (str_list->size > 1)
|
||||
{
|
||||
strlcpy(http->connection.elem1,
|
||||
str_list->elems[1].data,
|
||||
sizeof(http->connection.elem1));
|
||||
}
|
||||
|
||||
string_list_free(str_list);
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
if (str_list)
|
||||
string_list_free(str_list);
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* rarch_main_data_http_iterate_transfer:
|
||||
*
|
||||
@ -437,11 +136,10 @@ static int rarch_main_data_http_iterate_transfer(void *data)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_iterate(bool is_thread)
|
||||
static void rarch_task_http_transfer_handler(rarch_task_t *task)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return;
|
||||
http_handle_t *http = (http_handle_t*)task->state;
|
||||
http_transfer_data_t *data;
|
||||
|
||||
switch (http->status)
|
||||
{
|
||||
@ -454,69 +152,69 @@ void rarch_main_data_http_iterate(bool is_thread)
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER_PARSE:
|
||||
rarch_main_data_http_iterate_transfer_parse(http);
|
||||
http->status = HTTP_STATUS_POLL;
|
||||
goto task_finished;
|
||||
break;
|
||||
case HTTP_STATUS_TRANSFER:
|
||||
if (!rarch_main_data_http_iterate_transfer(http))
|
||||
http->status = HTTP_STATUS_TRANSFER_PARSE;
|
||||
break;
|
||||
case HTTP_STATUS_POLL:
|
||||
goto task_finished;
|
||||
default:
|
||||
if (rarch_main_data_http_iterate_poll(http) == 0)
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
|
||||
break;
|
||||
}
|
||||
|
||||
return;
|
||||
task_finished:
|
||||
task->finished = true;
|
||||
|
||||
data = (http_transfer_data_t*)calloc(1, sizeof(*data));
|
||||
task->task_data = data;
|
||||
|
||||
if (http->handle)
|
||||
{
|
||||
data->data = (char*)net_http_data(http->handle, &data->len, false);
|
||||
|
||||
if (data->data && http->cb)
|
||||
http->cb(data->data, data->len);
|
||||
|
||||
/* we can't let net_http_delete free our data */
|
||||
net_http_delete(http->handle);
|
||||
}
|
||||
|
||||
free(http);
|
||||
}
|
||||
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void)
|
||||
bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return;
|
||||
rarch_task_t *t;
|
||||
http_handle_t *http;
|
||||
struct http_connection_t *conn;
|
||||
|
||||
if (!http->msg_queue)
|
||||
retro_assert(http->msg_queue = msg_queue_new(8));
|
||||
}
|
||||
|
||||
|
||||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
return http->msg_queue;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->handle == NULL)
|
||||
return NULL;
|
||||
return http->handle;
|
||||
}
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void)
|
||||
{
|
||||
http_handle_t *http = (http_handle_t*)http_ptr;
|
||||
if (!http)
|
||||
return NULL;
|
||||
if (http->connection.handle == NULL)
|
||||
return NULL;
|
||||
return http->connection.handle;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_uninit(void)
|
||||
{
|
||||
if (http_ptr)
|
||||
free(http_ptr);
|
||||
http_ptr = NULL;
|
||||
}
|
||||
|
||||
void rarch_main_data_http_init(void)
|
||||
{
|
||||
http_ptr = (http_handle_t*)calloc(1, sizeof(*http_ptr));
|
||||
if (!url || !*url)
|
||||
return false;
|
||||
|
||||
conn = net_http_connection_new(url);
|
||||
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
http = (http_handle_t*)calloc(1, sizeof(*http));
|
||||
http->connection.handle = conn;
|
||||
http->connection.cb = &cb_http_conn_default;
|
||||
|
||||
if (type)
|
||||
strlcpy(http->connection.elem1, type, sizeof(http->connection.elem1));
|
||||
|
||||
http->status = HTTP_STATUS_CONNECTION_TRANSFER;
|
||||
|
||||
t = (rarch_task_t*)calloc(1, sizeof(*t));
|
||||
t->handler = rarch_task_http_transfer_handler;
|
||||
t->state = http;
|
||||
t->callback = cb;
|
||||
t->user_data = user_data;
|
||||
|
||||
rarch_task_push(t);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -65,27 +65,12 @@ void rarch_task_check(void);
|
||||
void rarch_task_push(rarch_task_t *task);
|
||||
|
||||
#ifdef HAVE_NETWORKING
|
||||
/**
|
||||
* rarch_main_data_http_iterate_transfer:
|
||||
*
|
||||
* Resumes HTTP transfer update.
|
||||
*
|
||||
* Returns: 0 when finished, -1 when we should continue
|
||||
* with the transfer on the next frame.
|
||||
**/
|
||||
void rarch_main_data_http_iterate(bool is_thread);
|
||||
typedef struct {
|
||||
char *data;
|
||||
size_t len;
|
||||
} http_transfer_data_t;
|
||||
|
||||
msg_queue_t *rarch_main_data_http_get_msg_queue_ptr(void);
|
||||
|
||||
void rarch_main_data_http_init_msg_queue(void);
|
||||
|
||||
void *rarch_main_data_http_get_handle(void);
|
||||
|
||||
void *rarch_main_data_http_conn_get_handle(void);
|
||||
|
||||
void rarch_main_data_http_uninit(void);
|
||||
|
||||
void rarch_main_data_http_init(void);
|
||||
bool rarch_task_push_http_transfer(const char *url, const char *type, rarch_task_callback_t cb, void *user_data);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_RPNG
|
||||
|
Loading…
x
Reference in New Issue
Block a user