forked from libretro/RetroArch
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move http_get to its own file; fix copyright
- Loading branch information
Showing
6 changed files
with
141 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |