mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 12:32:52 +00:00
(libretro-common) net_http - cleanups
This commit is contained in:
parent
ba415b6d3a
commit
5d449d5024
@ -73,6 +73,7 @@ struct http_connection_t
|
||||
static int net_http_new_socket(const char *domain, int port)
|
||||
{
|
||||
int fd;
|
||||
int ret;
|
||||
#ifndef _WIN32
|
||||
#ifndef VITA
|
||||
struct timeval timeout;
|
||||
@ -106,22 +107,21 @@ static int net_http_new_socket(const char *domain, int port)
|
||||
setsockopt(fd, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof timeout);
|
||||
#endif
|
||||
#endif
|
||||
if (connect(fd, addr->ai_addr, addr->ai_addrlen) != 0)
|
||||
{
|
||||
freeaddrinfo_retro(addr);
|
||||
socket_close(fd);
|
||||
return -1;
|
||||
}
|
||||
ret = connect(fd, addr->ai_addr, addr->ai_addrlen);
|
||||
|
||||
freeaddrinfo_retro(addr);
|
||||
|
||||
if (ret != 0)
|
||||
goto error;
|
||||
|
||||
if (!socket_nonblock(fd))
|
||||
{
|
||||
socket_close(fd);
|
||||
return -1;
|
||||
}
|
||||
goto error;
|
||||
|
||||
return fd;
|
||||
|
||||
error:
|
||||
socket_close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void net_http_send(int fd, bool * error,
|
||||
@ -177,28 +177,32 @@ static ssize_t net_http_recv(int fd, bool *error,
|
||||
|
||||
static char* urlencode(const char* url)
|
||||
{
|
||||
unsigned i;
|
||||
int outpos = 0;
|
||||
int outlen = 0;
|
||||
|
||||
int i;
|
||||
for (i=0;url[i]!='\0';i++)
|
||||
char *ret = NULL;
|
||||
|
||||
for (i = 0; url[i] != '\0'; i++)
|
||||
{
|
||||
outlen++;
|
||||
if (url[i]==' ') outlen+=2;
|
||||
if (url[i] == ' ')
|
||||
outlen += 2;
|
||||
}
|
||||
|
||||
char* ret = (char*)malloc(outlen+1);
|
||||
if (!ret) return NULL;
|
||||
ret = (char*)malloc(outlen + 1);
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
int outpos = 0;
|
||||
for (i=0;url[i];i++)
|
||||
for (i = 0; url[i]; i++)
|
||||
{
|
||||
if (url[i]==' ')
|
||||
if (url[i] == ' ')
|
||||
{
|
||||
ret[outpos++] = '%';
|
||||
ret[outpos++] = '2';
|
||||
ret[outpos++] = '0';
|
||||
}
|
||||
else ret[outpos++] = url[i];
|
||||
else
|
||||
ret[outpos++] = url[i];
|
||||
}
|
||||
ret[outpos] = '\0';
|
||||
|
||||
@ -214,7 +218,7 @@ struct http_connection_t *net_http_connection_new(const char *url)
|
||||
if (!conn)
|
||||
return NULL;
|
||||
|
||||
conn->urlcopy = urlencode(url);
|
||||
conn->urlcopy = urlencode(url);
|
||||
|
||||
if (!conn->urlcopy)
|
||||
goto error;
|
||||
@ -223,10 +227,8 @@ struct http_connection_t *net_http_connection_new(const char *url)
|
||||
goto error;
|
||||
|
||||
conn->scan = conn->urlcopy + strlen("http://");
|
||||
|
||||
domain = &conn->domain;
|
||||
|
||||
*domain = conn->scan;
|
||||
*domain = conn->scan;
|
||||
|
||||
return conn;
|
||||
|
||||
@ -242,10 +244,10 @@ bool net_http_connection_iterate(struct http_connection_t *conn)
|
||||
{
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
while (*conn->scan != '/' && *conn->scan != ':' && *conn->scan != '\0')
|
||||
{
|
||||
conn->scan++;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -256,17 +258,16 @@ bool net_http_connection_done(struct http_connection_t *conn)
|
||||
if (!conn)
|
||||
return false;
|
||||
|
||||
location = &conn->location;
|
||||
location = &conn->location;
|
||||
|
||||
if (*conn->scan == '\0')
|
||||
return false;
|
||||
|
||||
*conn->scan = '\0';
|
||||
*conn->scan = '\0';
|
||||
conn->port = 80;
|
||||
|
||||
if (*conn->scan == ':')
|
||||
{
|
||||
|
||||
if (!isdigit((int)conn->scan[1]))
|
||||
return false;
|
||||
|
||||
@ -299,9 +300,9 @@ const char *net_http_connection_url(struct http_connection_t *conn)
|
||||
|
||||
struct http_t *net_http_new(struct http_connection_t *conn)
|
||||
{
|
||||
bool error;
|
||||
int fd = -1;
|
||||
struct http_t *state = NULL;
|
||||
bool error = false;
|
||||
int fd = -1;
|
||||
struct http_t *state = NULL;
|
||||
|
||||
if (!conn)
|
||||
goto error;
|
||||
|
Loading…
x
Reference in New Issue
Block a user