mirror of
https://github.com/libretro/RetroArch
synced 2025-04-10 06:44:27 +00:00
Merge pull request #2282 from leiradel/master
move http_get to its own file; fix copyright
This commit is contained in:
commit
1f32ee1b49
@ -851,11 +851,13 @@ ifeq ($(HAVE_NETWORKING), 1)
|
|||||||
OBJ += netplay.o
|
OBJ += netplay.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
# Retro Achievements
|
# Retro Achievements (also depends on threads)
|
||||||
|
|
||||||
ifeq ($(HAVE_CHEEVOS), 1)
|
ifeq ($(HAVE_CHEEVOS), 1)
|
||||||
DEFINES += -DHAVE_CHEEVOS
|
ifeq ($(HAVE_THREADS), 1)
|
||||||
OBJ += cheevos.o libretro-common/utils/md5.o
|
DEFINES += -DHAVE_CHEEVOS
|
||||||
|
OBJ += cheevos.o http_get.o libretro-common/utils/md5.o
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
17
cheevos.c
17
cheevos.c
@ -1,5 +1,5 @@
|
|||||||
/* RetroArch - A frontend for libretro.
|
/* RetroArch - A frontend for libretro.
|
||||||
* Copyright (C) 2015 - Andre Leiradella
|
* Copyright (C) 2015 - Andre Leiradella
|
||||||
*
|
*
|
||||||
* 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-
|
||||||
@ -20,7 +20,6 @@
|
|||||||
|
|
||||||
#include <configuration.h>
|
#include <configuration.h>
|
||||||
#include <formats/jsonsax.h>
|
#include <formats/jsonsax.h>
|
||||||
#include <net/net_http.h>
|
|
||||||
#include <rhash.h>
|
#include <rhash.h>
|
||||||
#include <performance.h>
|
#include <performance.h>
|
||||||
#include <runloop.h>
|
#include <runloop.h>
|
||||||
@ -28,7 +27,7 @@
|
|||||||
|
|
||||||
#include "cheevos.h"
|
#include "cheevos.h"
|
||||||
#include "dynamic.h"
|
#include "dynamic.h"
|
||||||
#include "net_http_special.h"
|
#include "http_get.h"
|
||||||
|
|
||||||
enum
|
enum
|
||||||
{
|
{
|
||||||
@ -705,6 +704,9 @@ int cheevos_load( const char* json )
|
|||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
unsigned core_count, unofficial_count;
|
||||||
|
cheevos_readud_t ud;
|
||||||
|
|
||||||
if ( !config_get_ptr()->cheevos.enable )
|
if ( !config_get_ptr()->cheevos.enable )
|
||||||
{
|
{
|
||||||
/* Just return OK if cheevos are disabled. */
|
/* Just return OK if cheevos are disabled. */
|
||||||
@ -713,9 +715,6 @@ int cheevos_load( const char* json )
|
|||||||
|
|
||||||
/* Count the number of achievements in the JSON file. */
|
/* Count the number of achievements in the JSON file. */
|
||||||
|
|
||||||
unsigned core_count, unofficial_count;
|
|
||||||
cheevos_readud_t ud;
|
|
||||||
|
|
||||||
if ( count_cheevos( json, &core_count, &unofficial_count ) != JSONSAX_OK )
|
if ( count_cheevos( json, &core_count, &unofficial_count ) != JSONSAX_OK )
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
@ -1239,7 +1238,7 @@ static int cheevos_login( retro_time_t* timeout )
|
|||||||
|
|
||||||
request[ sizeof( request ) - 1 ] = 0;
|
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 */, token, sizeof( token ) );
|
res = cheevos_get_value( json, 0x0e2dbd26U /* Token */, token, sizeof( token ) );
|
||||||
free( (void*)json );
|
free( (void*)json );
|
||||||
@ -1277,7 +1276,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 ( !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 );
|
RARCH_LOG( "CHEEVOS got achievements for game id %u\n", game_id );
|
||||||
return 0;
|
return 0;
|
||||||
@ -1308,7 +1307,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 ( !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 ) );
|
res = cheevos_get_value( json, 0xb4960eecU /* GameID */, game_id, sizeof( game_id ) );
|
||||||
free( (void*)json );
|
free( (void*)json );
|
||||||
|
@ -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-
|
||||||
|
@ -86,6 +86,7 @@ ACHIEVEMENTS
|
|||||||
|
|
||||||
#include "../libretro-common/formats/json/jsonsax.c"
|
#include "../libretro-common/formats/json/jsonsax.c"
|
||||||
#include "../libretro-common/utils/md5.c"
|
#include "../libretro-common/utils/md5.c"
|
||||||
|
#include "../http_get.c"
|
||||||
#include "../cheevos.c"
|
#include "../cheevos.c"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
101
http_get.c
Normal file
101
http_get.c
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/* 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 "http_get.h"
|
||||||
|
|
||||||
|
int 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;
|
||||||
|
}
|
25
http_get.h
Normal file
25
http_get.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
/* 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __RARCH_HTTP_GET_H
|
||||||
|
#define __RARCH_HTTP_GET_H
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <performance.h>
|
||||||
|
|
||||||
|
int http_get(const char **result, size_t *size, const char *url, retro_time_t *timeout);
|
||||||
|
|
||||||
|
#endif /* __RARCH_HTTP_GET_H */
|
Loading…
x
Reference in New Issue
Block a user