diff --git a/Makefile.common b/Makefile.common
index 63e59055e4..f088a6b533 100644
--- a/Makefile.common
+++ b/Makefile.common
@@ -832,8 +832,9 @@ endif
ifeq ($(HAVE_NETWORKING), 1)
DEFINES += -DHAVE_NETWORKING
OBJ += libretro-common/net/net_compat.o \
- libretro-common/net/net_http.o \
- tasks/task_http.o
+ libretro-common/net/net_http.o \
+ net_http_special.o \
+ tasks/task_http.o
ifneq ($(findstring Win32,$(OS)),)
LIBS += -lws2_32
diff --git a/cheevos.c b/cheevos.c
index 2dd707ed65..80b7a0be6e 100644
--- a/cheevos.c
+++ b/cheevos.c
@@ -1,6 +1,5 @@
/* RetroArch - A frontend for libretro.
- * Copyright (C) 2010-2014 - Hans-Kristian Arntzen
- * Copyright (C) 2011-2015 - Daniel De Matteis
+ * 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-
@@ -29,6 +28,7 @@
#include "cheevos.h"
#include "dynamic.h"
+#include "net_http_special.h"
enum
{
@@ -167,9 +167,7 @@ static uint32_t cheevos_djb2( const char* str, size_t length )
uint32_t hash = 5381;
while ( aux < end )
- {
hash = ( hash << 5 ) + hash + *aux++;
- }
return hash;
}
@@ -1131,89 +1129,6 @@ void cheevos_unload( void )
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
{
unsigned key_hash;
@@ -1324,7 +1239,7 @@ static int cheevos_login( retro_time_t* timeout )
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 ) );
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;
- 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 );
return 0;
@@ -1393,7 +1308,7 @@ static unsigned cheevos_get_game_id( unsigned char* hash, retro_time_t* timeout
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 ) );
free( (void*)json );
diff --git a/griffin/griffin.c b/griffin/griffin.c
index 763992c64b..d678d042df 100644
--- a/griffin/griffin.c
+++ b/griffin/griffin.c
@@ -734,6 +734,7 @@ NETPLAY
#include "../netplay.c"
#include "../libretro-common/net/net_compat.c"
#include "../libretro-common/net/net_http.c"
+#include "../net_http_special.c"
#include "../tasks/task_http.c"
#endif
diff --git a/msg_hash.h b/msg_hash.h
index 1582cb1a9c..5b866d06ba 100644
--- a/msg_hash.h
+++ b/msg_hash.h
@@ -14,7 +14,6 @@
* If not, see .
*/
-
#ifndef __MSG_HASH_H
#define __MSG_HASH_H
diff --git a/net_http_special.c b/net_http_special.c
new file mode 100644
index 0000000000..05564f6296
--- /dev/null
+++ b/net_http_special.c
@@ -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 .
+ */
+
+#include
+
+#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;
+}
diff --git a/net_http_special.h b/net_http_special.h
new file mode 100644
index 0000000000..b4d1b164b9
--- /dev/null
+++ b/net_http_special.h
@@ -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 .
+ */
+
+#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