mirror of
https://github.com/libretro/RetroArch
synced 2025-02-08 15:40:14 +00:00
Create net_http_special
This commit is contained in:
parent
74030ec5c1
commit
85fb94c452
@ -832,8 +832,9 @@ endif
|
|||||||
ifeq ($(HAVE_NETWORKING), 1)
|
ifeq ($(HAVE_NETWORKING), 1)
|
||||||
DEFINES += -DHAVE_NETWORKING
|
DEFINES += -DHAVE_NETWORKING
|
||||||
OBJ += libretro-common/net/net_compat.o \
|
OBJ += libretro-common/net/net_compat.o \
|
||||||
libretro-common/net/net_http.o \
|
libretro-common/net/net_http.o \
|
||||||
tasks/task_http.o
|
net_http_special.o \
|
||||||
|
tasks/task_http.o
|
||||||
|
|
||||||
ifneq ($(findstring Win32,$(OS)),)
|
ifneq ($(findstring Win32,$(OS)),)
|
||||||
LIBS += -lws2_32
|
LIBS += -lws2_32
|
||||||
|
95
cheevos.c
95
cheevos.c
@ -1,6 +1,5 @@
|
|||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2010-2014 - Hans-Kristian Arntzen
|
* Copyright (C) 2015 - Andre Leiradella
|
||||||
* Copyright (C) 2011-2015 - Daniel De Matteis
|
|
||||||
*
|
*
|
||||||
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
* of the GNU General Public License as published by the Free Software Found-
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
@ -29,6 +28,7 @@
|
|||||||
|
|
||||||
#include "cheevos.h"
|
#include "cheevos.h"
|
||||||
#include "dynamic.h"
|
#include "dynamic.h"
|
||||||
|
#include "net_http_special.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -167,9 +167,7 @@ static uint32_t cheevos_djb2( const char* str, size_t length )
|
|||||||
uint32_t hash = 5381;
|
uint32_t hash = 5381;
|
||||||
|
|
||||||
while ( aux < end )
|
while ( aux < end )
|
||||||
{
|
|
||||||
hash = ( hash << 5 ) + hash + *aux++;
|
hash = ( hash << 5 ) + hash + *aux++;
|
||||||
}
|
|
||||||
|
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
@ -1131,89 +1129,6 @@ void cheevos_unload( void )
|
|||||||
Load achievements from retroachievements.org.
|
Load achievements from retroachievements.org.
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
|
||||||
static int cheevos_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout)
|
|
||||||
{
|
|
||||||
struct http_connection_t* conn = NULL;
|
|
||||||
struct http_t* http = NULL;
|
|
||||||
int ret = -1;
|
|
||||||
retro_time_t t0;
|
|
||||||
uint8_t* data;
|
|
||||||
size_t length;
|
|
||||||
char* res;
|
|
||||||
|
|
||||||
*result = NULL;
|
|
||||||
t0 = retro_get_time_usec();
|
|
||||||
conn = net_http_connection_new(url);
|
|
||||||
|
|
||||||
/* Error creating the connection descriptor. */
|
|
||||||
if (!conn)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
/* Don't bother with timeouts here, it's just a string scan. */
|
|
||||||
while (!net_http_connection_iterate(conn)) {}
|
|
||||||
|
|
||||||
/* Error finishing the connection descriptor. */
|
|
||||||
if (!net_http_connection_done(conn))
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
http = net_http_new(conn);
|
|
||||||
|
|
||||||
/* Error connecting to the endpoint. */
|
|
||||||
if (!http)
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
while (!net_http_update(http, NULL, NULL))
|
|
||||||
{
|
|
||||||
/* Timeout error. */
|
|
||||||
if (timeout && (retro_get_time_usec() - t0) > *timeout)
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
|
|
||||||
data = net_http_data(http, &length, false);
|
|
||||||
|
|
||||||
if (data)
|
|
||||||
{
|
|
||||||
res = (char*)malloc(length + 1);
|
|
||||||
|
|
||||||
/* Allocation error. */
|
|
||||||
if ( !res )
|
|
||||||
goto error;
|
|
||||||
|
|
||||||
memcpy((void*)res, (void*)data, length);
|
|
||||||
res[length] = 0;
|
|
||||||
*result = res;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
length = 0;
|
|
||||||
*result = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size)
|
|
||||||
*size = length;
|
|
||||||
|
|
||||||
ret = 0;
|
|
||||||
|
|
||||||
error:
|
|
||||||
if ( http )
|
|
||||||
net_http_delete( http );
|
|
||||||
|
|
||||||
if ( conn )
|
|
||||||
net_http_connection_free( conn );
|
|
||||||
|
|
||||||
if (timeout)
|
|
||||||
{
|
|
||||||
t0 = retro_get_time_usec() - t0;
|
|
||||||
|
|
||||||
if (t0 < *timeout)
|
|
||||||
*timeout -= t0;
|
|
||||||
else
|
|
||||||
*timeout = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
unsigned key_hash;
|
unsigned key_hash;
|
||||||
@ -1324,7 +1239,7 @@ static int cheevos_login( retro_time_t* timeout )
|
|||||||
|
|
||||||
request[ sizeof( request ) - 1 ] = 0;
|
request[ sizeof( request ) - 1 ] = 0;
|
||||||
|
|
||||||
if ( !cheevos_http_get( &json, NULL, request, timeout ) )
|
if ( !net_http_get( &json, NULL, request, timeout ) )
|
||||||
{
|
{
|
||||||
res = cheevos_get_value( json, 0x0e2dbd26U /* Token */, token, sizeof( token ) );
|
res = cheevos_get_value( json, 0x0e2dbd26U /* Token */, token, sizeof( token ) );
|
||||||
free( (void*)json );
|
free( (void*)json );
|
||||||
@ -1362,7 +1277,7 @@ static int cheevos_get_by_game_id( const char** json, unsigned game_id, retro_ti
|
|||||||
|
|
||||||
request[ sizeof( request ) - 1 ] = 0;
|
request[ sizeof( request ) - 1 ] = 0;
|
||||||
|
|
||||||
if ( !cheevos_http_get( json, NULL, request, timeout ) )
|
if ( !net_http_get( json, NULL, request, timeout ) )
|
||||||
{
|
{
|
||||||
RARCH_LOG( "CHEEVOS got achievements for game id %u\n", game_id );
|
RARCH_LOG( "CHEEVOS got achievements for game id %u\n", game_id );
|
||||||
return 0;
|
return 0;
|
||||||
@ -1393,7 +1308,7 @@ static unsigned cheevos_get_game_id( unsigned char* hash, retro_time_t* timeout
|
|||||||
|
|
||||||
request[ sizeof( request ) - 1 ] = 0;
|
request[ sizeof( request ) - 1 ] = 0;
|
||||||
|
|
||||||
if ( !cheevos_http_get( &json, NULL, request, timeout ) )
|
if ( !net_http_get( &json, NULL, request, timeout ) )
|
||||||
{
|
{
|
||||||
res = cheevos_get_value( json, 0xb4960eecU /* GameID */, game_id, sizeof( game_id ) );
|
res = cheevos_get_value( json, 0xb4960eecU /* GameID */, game_id, sizeof( game_id ) );
|
||||||
free( (void*)json );
|
free( (void*)json );
|
||||||
|
@ -734,6 +734,7 @@ NETPLAY
|
|||||||
#include "../netplay.c"
|
#include "../netplay.c"
|
||||||
#include "../libretro-common/net/net_compat.c"
|
#include "../libretro-common/net/net_compat.c"
|
||||||
#include "../libretro-common/net/net_http.c"
|
#include "../libretro-common/net/net_http.c"
|
||||||
|
#include "../net_http_special.c"
|
||||||
#include "../tasks/task_http.c"
|
#include "../tasks/task_http.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -14,7 +14,6 @@
|
|||||||
* If not, see <http://www.gnu.org/licenses/>.
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __MSG_HASH_H
|
#ifndef __MSG_HASH_H
|
||||||
#define __MSG_HASH_H
|
#define __MSG_HASH_H
|
||||||
|
|
||||||
|
102
net_http_special.c
Normal file
102
net_http_special.c
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* Copyright (C) 2015 - Andre Leiradella
|
||||||
|
*
|
||||||
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <net/net_http.h>
|
||||||
|
|
||||||
|
#include "libretro.h"
|
||||||
|
#include "performance.h"
|
||||||
|
|
||||||
|
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout)
|
||||||
|
{
|
||||||
|
retro_time_t t0;
|
||||||
|
uint8_t* data;
|
||||||
|
size_t length;
|
||||||
|
char* res;
|
||||||
|
int ret = -1;
|
||||||
|
struct http_connection_t* conn = NULL;
|
||||||
|
struct http_t* http = NULL;
|
||||||
|
|
||||||
|
*result = NULL;
|
||||||
|
t0 = retro_get_time_usec();
|
||||||
|
conn = net_http_connection_new(url);
|
||||||
|
|
||||||
|
/* Error creating the connection descriptor. */
|
||||||
|
if (!conn)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
/* Don't bother with timeouts here, it's just a string scan. */
|
||||||
|
while (!net_http_connection_iterate(conn)) {}
|
||||||
|
|
||||||
|
/* Error finishing the connection descriptor. */
|
||||||
|
if (!net_http_connection_done(conn))
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
http = net_http_new(conn);
|
||||||
|
|
||||||
|
/* Error connecting to the endpoint. */
|
||||||
|
if (!http)
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
while (!net_http_update(http, NULL, NULL))
|
||||||
|
{
|
||||||
|
/* Timeout error. */
|
||||||
|
if (timeout && (retro_get_time_usec() - t0) > *timeout)
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
|
||||||
|
data = net_http_data(http, &length, false);
|
||||||
|
|
||||||
|
if (data)
|
||||||
|
{
|
||||||
|
res = (char*)malloc(length + 1);
|
||||||
|
|
||||||
|
/* Allocation error. */
|
||||||
|
if ( !res )
|
||||||
|
goto error;
|
||||||
|
|
||||||
|
memcpy((void*)res, (void*)data, length);
|
||||||
|
res[length] = 0;
|
||||||
|
*result = res;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
length = 0;
|
||||||
|
*result = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (size)
|
||||||
|
*size = length;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
error:
|
||||||
|
if ( http )
|
||||||
|
net_http_delete( http );
|
||||||
|
|
||||||
|
if ( conn )
|
||||||
|
net_http_connection_free( conn );
|
||||||
|
|
||||||
|
if (timeout)
|
||||||
|
{
|
||||||
|
t0 = retro_get_time_usec() - t0;
|
||||||
|
|
||||||
|
if (t0 < *timeout)
|
||||||
|
*timeout -= t0;
|
||||||
|
else
|
||||||
|
*timeout = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
31
net_http_special.h
Normal file
31
net_http_special.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/* RetroArch - A frontend for libretro.
|
||||||
|
* Copyright (C) 2011-2015 - Daniel De Matteis
|
||||||
|
*
|
||||||
|
* RetroArch is free software: you can redistribute it and/or modify it under the terms
|
||||||
|
* of the GNU General Public License as published by the Free Software Found-
|
||||||
|
* ation, either version 3 of the License, or (at your option) any later version.
|
||||||
|
*
|
||||||
|
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
||||||
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
||||||
|
* PURPOSE. See the GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License along with RetroArch.
|
||||||
|
* If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __NET_HTTP_SPECIAL_H
|
||||||
|
#define __NET_HTTP_SPECIAL_H
|
||||||
|
|
||||||
|
#include "libretro.h"
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
int net_http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif
|
Loading…
x
Reference in New Issue
Block a user