Merge pull request #6413 from fr500/staging

remove task_push_http_transfer_raw, encode before sending data to the…
This commit is contained in:
Andrés 2018-03-18 11:13:03 -05:00 committed by GitHub
commit a8fc4b204a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 82 additions and 68 deletions

View File

@ -1906,7 +1906,7 @@ static void cheevos_unlocked(void *task_data, void *user_data,
RARCH_ERR("[CHEEVOS]: error awarding achievement %u, retrying...\n", cheevo->id);
cheevos_make_unlock_url(cheevo, url, sizeof(url));
task_push_http_transfer_raw(url, true, NULL, cheevos_unlocked, cheevo);
task_push_http_transfer(url, true, NULL, cheevos_unlocked, cheevo);
}
}
@ -1961,7 +1961,7 @@ static void cheevos_test_cheevo_set(const cheevoset_t *set)
runloop_msg_queue_push(cheevo->description, 0, 3 * 60, false);
cheevos_make_unlock_url(cheevo, url, sizeof(url));
task_push_http_transfer_raw(url, true, NULL,
task_push_http_transfer(url, true, NULL,
cheevos_unlocked, cheevo);
if(settings->bools.cheevos_auto_screenshot)
@ -2176,7 +2176,7 @@ static void cheevos_test_leaderboards(void)
char formatted_value[16];
cheevos_make_lboard_url(lboard, url, sizeof(url));
task_push_http_transfer_raw(url, true, NULL,
task_push_http_transfer(url, true, NULL,
cheevos_lboard_submit, lboard);
RARCH_LOG("[CHEEVOS]: submit lboard %s\n", lboard->title);

View File

@ -2089,6 +2089,8 @@ MSG_HASH(MSG_DISK_EJECTED,
"Ejected")
MSG_HASH(MSG_DOWNLOADING,
"Downloading")
MSG_HASH(MSG_INDEX_FILE,
"Index File")
MSG_HASH(MSG_DOWNLOAD_FAILED,
"Download failed")
MSG_HASH(MSG_ERROR,

View File

@ -68,7 +68,11 @@ uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error);
/* Cleans up all memory. */
void net_http_delete(struct http_t *state);
void net_http_urlencode_full(char **dest, const char *source);
/* URL Encode a string */
void net_http_urlencode(char **dest, const char *source);
/* Re-encode a full URL */
void net_http_urlencode_full(char *dest, const char *source, size_t size);
RETRO_END_DECLS

View File

@ -33,6 +33,7 @@
#include <compat/strl.h>
#include <string/stdstring.h>
#include <retro_common_api.h>
#include <retro_miscellaneous.h>
enum
{
@ -101,8 +102,9 @@ void urlencode_lut_init()
}
}
/* caller is responsible for deleting the destination buffer */
void net_http_urlencode_full(char **dest, const char *source)
/* URL Encode a string
caller is responsible for deleting the destination buffer */
void net_http_urlencode(char **dest, const char *source)
{
char *enc = NULL;
/* Assume every character will be encoded, so we need 3 times the space. */
@ -129,6 +131,34 @@ void net_http_urlencode_full(char **dest, const char *source)
(*dest)[len - 1] = '\0';
}
/* Re-encode a full URL */
void net_http_urlencode_full(char *dest, const char *source, size_t size)
{
char *tmp;
char url_domain[PATH_MAX_LENGTH];
char url_path[PATH_MAX_LENGTH];
char url_encoded[PATH_MAX_LENGTH];
int count = 0;
strlcpy (url_path, source, sizeof(url_path));
tmp = url_path;
while (count < 3 && tmp[0] != '\0')
{
tmp = strchr(tmp, '/');
count ++;
tmp++;
}
strlcpy(url_domain, source, tmp - url_path);
strlcpy(url_path, tmp, sizeof(url_path));
tmp = NULL;
net_http_urlencode(&tmp, url_path);
snprintf(dest, size, "%s/%s", url_domain, tmp);
free (tmp);
}
static int net_http_new_socket(struct http_connection_t *conn)
{
int ret;

View File

@ -51,6 +51,8 @@
#include "../../lakka.h"
#include "../../wifi/wifi_driver.h"
#include <net/net_http.h>
#ifdef HAVE_NETWORKING
#include "../../network/netplay/netplay.h"
#include "../../network/netplay/netplay_discovery.h"
@ -2370,7 +2372,7 @@ static int generic_action_ok_network(const char *path,
char url_path[PATH_MAX_LENGTH];
settings_t *settings = config_get_ptr();
unsigned type_id2 = 0;
menu_file_transfer_t *transf = NULL;
file_transfer_t *transf = NULL;
const char *url_label = NULL;
retro_task_callback_t callback = NULL;
bool refresh = true;
@ -2442,7 +2444,7 @@ static int generic_action_ok_network(const char *path,
generic_action_ok_command(CMD_EVENT_NETWORK_INIT);
transf = (menu_file_transfer_t*)calloc(1, sizeof(*transf));
transf = (file_transfer_t*)calloc(1, sizeof(*transf));
strlcpy(transf->path, url_path, sizeof(transf->path));
task_push_http_transfer(url_path, suppress_msg, url_label, callback, transf);
@ -2466,7 +2468,7 @@ default_action_ok_list(action_ok_lakka_list, MENU_ENUM_LABEL_CB_LAKKA_LIST)
static void cb_generic_dir_download(void *task_data,
void *user_data, const char *err)
{
menu_file_transfer_t *transf = (menu_file_transfer_t*)user_data;
file_transfer_t *transf = (file_transfer_t*)user_data;
if (transf)
{
@ -2477,7 +2479,7 @@ static void cb_generic_dir_download(void *task_data,
}
}
/* expects http_transfer_t*, menu_file_transfer_t* */
/* expects http_transfer_t*, file_transfer_t* */
static void cb_generic_download(void *task_data,
void *user_data, const char *err)
{
@ -2486,7 +2488,7 @@ static void cb_generic_download(void *task_data,
bool extract = true;
#endif
const char *dir_path = NULL;
menu_file_transfer_t *transf = (menu_file_transfer_t*)user_data;
file_transfer_t *transf = (file_transfer_t*)user_data;
settings_t *settings = config_get_ptr();
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
@ -2651,13 +2653,14 @@ static int action_ok_download_generic(const char *path,
{
#ifdef HAVE_NETWORKING
char s[PATH_MAX_LENGTH];
char s2[PATH_MAX_LENGTH];
char s3[PATH_MAX_LENGTH];
menu_file_transfer_t *transf = NULL;
file_transfer_t *transf = NULL;
settings_t *settings = config_get_ptr();
bool suppress_msg = false;
retro_task_callback_t cb = cb_generic_download;
s[0] = s3[0] = '\0';
s[0] = s2[0] = s3[0] = '\0';
fill_pathname_join(s,
settings->paths.network_buildbot_assets_url,
@ -2721,12 +2724,14 @@ static int action_ok_download_generic(const char *path,
break;
}
fill_pathname_join(s3, s, path, sizeof(s3));
fill_pathname_join(s2, s, path, sizeof(s2));
transf = (menu_file_transfer_t*)calloc(1, sizeof(*transf));
transf = (file_transfer_t*)calloc(1, sizeof(*transf));
transf->enum_idx = enum_idx;
strlcpy(transf->path, path, sizeof(transf->path));
net_http_urlencode_full(s3, s2, sizeof(s));
task_push_http_transfer(s3, suppress_msg, msg_hash_to_str(enum_idx), cb, transf);
#endif
return 0;

View File

@ -127,12 +127,6 @@ enum
ACTION_OK_DL_CONTENT_SETTINGS
};
typedef struct
{
enum msg_hash_enums enum_idx;
char path[PATH_MAX_LENGTH];
} menu_file_transfer_t;
/* FIXME - Externs, refactor */
extern size_t hack_shader_pass;
extern unsigned rpl_entry_selection_ptr;

View File

@ -186,7 +186,7 @@ void cb_net_generic_subdir(void *task_data, void *user_data, const char *err)
#ifdef HAVE_NETWORKING
char subdir_path[PATH_MAX_LENGTH];
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
menu_file_transfer_t *state = (menu_file_transfer_t*)user_data;
file_transfer_t *state = (file_transfer_t*)user_data;
subdir_path[0] = '\0';
@ -228,7 +228,7 @@ void cb_net_generic(void *task_data, void *user_data, const char *err)
#ifdef HAVE_NETWORKING
bool refresh = false;
http_transfer_data_t *data = (http_transfer_data_t*)task_data;
menu_file_transfer_t *state = (menu_file_transfer_t*)user_data;
file_transfer_t *state = (file_transfer_t*)user_data;
if (core_buf)
free(core_buf);
@ -263,7 +263,7 @@ finish:
if (!err && !strstr(state->path, file_path_str(FILE_PATH_INDEX_DIRS_URL)))
{
char *parent_dir = (char*)malloc(PATH_MAX_LENGTH * sizeof(char));
menu_file_transfer_t *transf = NULL;
file_transfer_t *transf = NULL;
parent_dir[0] = '\0';
@ -273,7 +273,7 @@ finish:
file_path_str(FILE_PATH_INDEX_DIRS_URL),
PATH_MAX_LENGTH * sizeof(char));
transf = (menu_file_transfer_t*)malloc(sizeof(*transf));
transf = (file_transfer_t*)malloc(sizeof(*transf));
transf->enum_idx = MSG_UNKNOWN;
strlcpy(transf->path, parent_dir, sizeof(transf->path));

View File

@ -399,6 +399,7 @@ enum msg_hash_enums
MSG_REMOVED_DISK_FROM_TRAY,
MSG_FAILED_TO_REMOVE_DISK_FROM_TRAY,
MSG_GOT_INVALID_DISK_INDEX,
MSG_INDEX_FILE,
MSG_DOWNLOADING,
MSG_EXTRACTING,
MSG_EXTRACTING_FILE,

View File

@ -767,13 +767,13 @@ static void netplay_announce(void)
netplay_get_architecture(frontend_architecture, sizeof(frontend_architecture));
net_http_urlencode_full(&username, settings->paths.username);
net_http_urlencode_full(&corename, system->info.library_name);
net_http_urlencode_full(&gamename,
net_http_urlencode(&username, settings->paths.username);
net_http_urlencode(&corename, system->info.library_name);
net_http_urlencode(&gamename,
!string_is_empty(path_basename(path_get(RARCH_PATH_BASENAME))) ?
path_basename(path_get(RARCH_PATH_BASENAME)) : "N/A");
net_http_urlencode_full(&coreversion, system->info.library_version);
net_http_urlencode_full(&frontend_ident, frontend_architecture);
net_http_urlencode(&coreversion, system->info.library_version);
net_http_urlencode(&frontend_ident, frontend_architecture);
buf[0] = '\0';

View File

@ -249,6 +249,7 @@ static void* task_push_http_transfer_generic(
{
task_finder_data_t find_data;
char tmp[255];
char* s = NULL;
retro_task_t *t = NULL;
http_handle_t *http = NULL;
@ -297,8 +298,16 @@ static void* task_push_http_transfer_generic(
t->user_data = user_data;
t->progress = -1;
s= ((file_transfer_t*)user_data)->path;
if (strstr(s, ".index"))
{
snprintf(tmp, sizeof(tmp), "%s %s",
msg_hash_to_str(MSG_DOWNLOADING), msg_hash_to_str(MSG_INDEX_FILE));
}
else
snprintf(tmp, sizeof(tmp), "%s '%s'",
msg_hash_to_str(MSG_DOWNLOADING), path_basename(url));
msg_hash_to_str(MSG_DOWNLOADING), path_basename(s));
t->title = strdup(tmp);
@ -320,40 +329,6 @@ void* task_push_http_transfer(const char *url, bool mute,
retro_task_callback_t cb, void *user_data)
{
struct http_connection_t *conn;
char *tmp;
char url_domain[PATH_MAX_LENGTH];
char url_path[PATH_MAX_LENGTH];
char url_encoded[PATH_MAX_LENGTH];
int count = 0;
strlcpy (url_path, url, sizeof(url_path));
tmp = url_path;
while (count < 3 && tmp[0] != '\0')
{
tmp = strchr(tmp, '/');
count ++;
tmp++;
}
strlcpy(url_domain, url, tmp - url_path);
strlcpy(url_path, tmp, sizeof(url_path));
tmp = NULL;
net_http_urlencode_full (&tmp, url_path);
snprintf(url_encoded, sizeof(url_encoded), "%s/%s", url_domain, tmp);
conn = net_http_connection_new(url_encoded, "GET", NULL);
free (tmp);
return task_push_http_transfer_generic(conn, url, mute, type, cb, user_data);
}
void* task_push_http_transfer_raw(const char *url, bool mute,
const char *type,
retro_task_callback_t cb, void *user_data)
{
struct http_connection_t *conn;
conn = net_http_connection_new(url, "GET", NULL);

View File

@ -92,6 +92,12 @@ typedef struct nbio_handle
transfer_cb_t cb;
} nbio_handle_t;
typedef struct
{
enum msg_hash_enums enum_idx;
char path[PATH_MAX_LENGTH];
} file_transfer_t;
#ifdef HAVE_NETWORKING
typedef struct
{
@ -102,9 +108,6 @@ typedef struct
void *task_push_http_transfer(const char *url, bool mute, const char *type,
retro_task_callback_t cb, void *userdata);
void *task_push_http_transfer_raw(const char *url, bool mute, const char *type,
retro_task_callback_t cb, void *userdata);
void *task_push_http_post_transfer(const char *url, const char *post_data, bool mute, const char *type,
retro_task_callback_t cb, void *userdata);