mirror of
https://github.com/libretro/RetroArch.git
synced 2024-12-03 22:03:04 +00:00
Merge pull request #2300 from leiradel/master
added error messages to the log when net_http_get fails in cheevos.c
This commit is contained in:
commit
cb3445212a
52
cheevos.c
52
cheevos.c
@ -189,6 +189,46 @@ static uint32_t cheevos_djb2(const char* str, size_t length)
|
||||
return hash;
|
||||
}
|
||||
|
||||
#ifdef NDEBUG
|
||||
|
||||
#define http_get net_http_get
|
||||
|
||||
#else
|
||||
|
||||
static int http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout)
|
||||
{
|
||||
int ret = net_http_get(result, size, url, timeout);
|
||||
const char *msg;
|
||||
|
||||
switch (ret)
|
||||
{
|
||||
case NET_HTTP_GET_OK:
|
||||
return ret;
|
||||
|
||||
case NET_HTTP_GET_MALFORMED_URL:
|
||||
msg = "malformed url";
|
||||
break;
|
||||
|
||||
case NET_HTTP_GET_CONNECT_ERROR:
|
||||
msg = "connect error";
|
||||
break;
|
||||
|
||||
case NET_HTTP_GET_TIMEOUT:
|
||||
msg = "timeout";
|
||||
break;
|
||||
|
||||
default:
|
||||
msg = "?";
|
||||
break;
|
||||
}
|
||||
|
||||
RARCH_LOG("CHEEVOS error getting %s: %s\n", url, msg);
|
||||
RARCH_LOG("CHEEVOS http result was %s\n", *result ? *result : "(null)");
|
||||
return ret;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned key_hash;
|
||||
@ -1118,7 +1158,7 @@ static int cheevos_login(retro_time_t *timeout)
|
||||
|
||||
request[sizeof(request) - 1] = 0;
|
||||
|
||||
if (!net_http_get(&json, NULL, request, timeout))
|
||||
if (!http_get(&json, NULL, request, timeout))
|
||||
{
|
||||
res = cheevos_get_value(json, 0x0e2dbd26U /* Token */, cheevos_locals.token, sizeof(cheevos_locals.token));
|
||||
free((void*)json);
|
||||
@ -1151,7 +1191,7 @@ static void cheevo_unlocker(void *payload)
|
||||
request[sizeof(request) - 1] = 0;
|
||||
RARCH_LOG("CHEEVOS awarding achievement %u: %s\n", cheevo->id, request);
|
||||
|
||||
if (!net_http_get(&result, NULL, request, NULL))
|
||||
if (!http_get(&result, NULL, request, NULL))
|
||||
{
|
||||
RARCH_LOG("CHEEVOS awarded achievement %u: %s\n", cheevo->id, result);
|
||||
free((void*)result);
|
||||
@ -1258,7 +1298,7 @@ static int cheevos_get_by_game_id(const char **json, unsigned game_id, retro_tim
|
||||
|
||||
request[sizeof(request) - 1] = 0;
|
||||
|
||||
if (!net_http_get(json, NULL, request, timeout))
|
||||
if (!http_get(json, NULL, request, timeout))
|
||||
{
|
||||
RARCH_LOG("CHEEVOS got achievements for game id %u\n", game_id);
|
||||
return 0;
|
||||
@ -1289,7 +1329,7 @@ static unsigned cheevos_get_game_id(unsigned char *hash, retro_time_t *timeout)
|
||||
|
||||
request[sizeof(request) - 1] = 0;
|
||||
|
||||
if (!net_http_get(&json, NULL, request, timeout))
|
||||
if (!http_get(&json, NULL, request, timeout))
|
||||
{
|
||||
res = cheevos_get_value(json, 0xb4960eecU /* GameID */, game_id, sizeof(game_id));
|
||||
free((void*)json);
|
||||
@ -1320,7 +1360,7 @@ static int cheevos_playing_activity(unsigned game_id, retro_time_t *timeout)
|
||||
|
||||
request[sizeof(request) - 1] = 0;
|
||||
|
||||
if (!net_http_get(&json, NULL, request, timeout))
|
||||
if (!http_get(&json, NULL, request, timeout))
|
||||
{
|
||||
free((void*)json);
|
||||
RARCH_LOG("CHEEVOS posted playing game %u activity\n", game_id);
|
||||
@ -1420,7 +1460,7 @@ static int cheevos_deactivate_unlocks(unsigned game_id, retro_time_t *timeout)
|
||||
|
||||
request[sizeof(request) - 1] = 0;
|
||||
|
||||
if (!net_http_get(&json, NULL, request, timeout))
|
||||
if (!http_get(&json, NULL, request, timeout))
|
||||
{
|
||||
ud.is_element = 0;
|
||||
res = jsonsax_parse(json, &handlers, (void*)&ud);
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "libretro.h"
|
||||
#include "performance.h"
|
||||
#include "net_http_special.h"
|
||||
|
||||
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout)
|
||||
{
|
||||
@ -26,7 +27,7 @@ int net_http_get(const char **result, size_t *size, const char *url, retro_time_
|
||||
uint8_t* data;
|
||||
size_t length;
|
||||
char* res;
|
||||
int ret = -1;
|
||||
int ret = NET_HTTP_GET_OK;
|
||||
struct http_connection_t* conn = NULL;
|
||||
struct http_t* http = NULL;
|
||||
|
||||
@ -43,19 +44,28 @@ int net_http_get(const char **result, size_t *size, const char *url, retro_time_
|
||||
|
||||
/* Error finishing the connection descriptor. */
|
||||
if (!net_http_connection_done(conn))
|
||||
{
|
||||
ret = NET_HTTP_GET_MALFORMED_URL;
|
||||
goto error;
|
||||
}
|
||||
|
||||
http = net_http_new(conn);
|
||||
|
||||
/* Error connecting to the endpoint. */
|
||||
if (!http)
|
||||
{
|
||||
ret = NET_HTTP_GET_CONNECT_ERROR;
|
||||
goto error;
|
||||
}
|
||||
|
||||
while (!net_http_update(http, NULL, NULL))
|
||||
{
|
||||
/* Timeout error. */
|
||||
if (timeout && (retro_get_time_usec() - t0) > *timeout)
|
||||
{
|
||||
ret = NET_HTTP_GET_TIMEOUT;
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
data = net_http_data(http, &length, false);
|
||||
@ -81,8 +91,6 @@ int net_http_get(const char **result, size_t *size, const char *url, retro_time_
|
||||
if (size)
|
||||
*size = length;
|
||||
|
||||
ret = 0;
|
||||
|
||||
error:
|
||||
if ( http )
|
||||
net_http_delete( http );
|
||||
|
@ -18,6 +18,14 @@
|
||||
|
||||
#include "libretro.h"
|
||||
|
||||
enum
|
||||
{
|
||||
NET_HTTP_GET_OK = 0,
|
||||
NET_HTTP_GET_MALFORMED_URL,
|
||||
NET_HTTP_GET_CONNECT_ERROR,
|
||||
NET_HTTP_GET_TIMEOUT,
|
||||
};
|
||||
|
||||
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout);
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user