mirror of
https://github.com/dborth/fceugx.git
synced 2024-11-01 06:55:05 +01:00
tidy up http code
This commit is contained in:
parent
5aa1e79d75
commit
db6ab63ed1
@ -171,7 +171,7 @@ static char * tcp_readln(const s32 s, const u16 max_length, const u64 start_time
|
||||
return ret;
|
||||
}
|
||||
|
||||
static bool tcp_read(const s32 s, u8 **buffer, const u32 length)
|
||||
static int tcp_read(const s32 s, u8 **buffer, const u32 length)
|
||||
{
|
||||
u8 *p;
|
||||
u32 step, left, block, received;
|
||||
@ -224,7 +224,7 @@ static bool tcp_read(const s32 s, u8 **buffer, const u32 length)
|
||||
return left == 0;
|
||||
}
|
||||
|
||||
static bool tcp_write(const s32 s, const u8 *buffer, const u32 length)
|
||||
static int tcp_write(const s32 s, const u8 *buffer, const u32 length)
|
||||
{
|
||||
const u8 *p;
|
||||
u32 step, left, block, sent;
|
||||
@ -304,6 +304,7 @@ static bool http_split_url(char **host, char **path, const char *url)
|
||||
bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
const u32 max_size)
|
||||
{
|
||||
int res = 0;
|
||||
char *http_host;
|
||||
u16 http_port;
|
||||
char *http_path;
|
||||
@ -336,10 +337,9 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
r += sprintf(r, "Host: %s\r\n", http_host);
|
||||
r += sprintf(r, "Cache-Control: no-cache\r\n\r\n");
|
||||
|
||||
bool b = tcp_write(s, (u8 *) request, strlen(request));
|
||||
res = tcp_write(s, (u8 *) request, strlen(request));
|
||||
|
||||
free(request);
|
||||
linecount = 0;
|
||||
|
||||
for (linecount = 0; linecount < 32; linecount++)
|
||||
{
|
||||
@ -382,11 +382,9 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
return false;
|
||||
}
|
||||
|
||||
int res = 1;
|
||||
|
||||
if (buffer != NULL)
|
||||
{
|
||||
b = tcp_read(s, &buffer, content_length);
|
||||
res = tcp_read(s, &buffer, content_length);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -395,8 +393,10 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
u32 bytesLeft = content_length;
|
||||
u32 readSize;
|
||||
|
||||
u8 * fbuffer = (u8 *) malloc(bufSize);
|
||||
ShowProgress("Downloading...", 0, content_length);
|
||||
u8 * fbuffer = (u8 *) malloc(bufSize);
|
||||
if(fbuffer)
|
||||
{
|
||||
while (bytesLeft > 0)
|
||||
{
|
||||
if (bytesLeft < bufSize)
|
||||
@ -404,8 +404,8 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
else
|
||||
readSize = bufSize;
|
||||
|
||||
b = tcp_read(s, &fbuffer, readSize);
|
||||
if (!b)
|
||||
res = tcp_read(s, &fbuffer, readSize);
|
||||
if (!res)
|
||||
break;
|
||||
res = fwrite(fbuffer, 1, readSize, hfile);
|
||||
if (!res)
|
||||
@ -415,17 +415,20 @@ bool http_request(const char *url, FILE * hfile, u8 * buffer,
|
||||
ShowProgress("Downloading...", (content_length - bytesLeft),
|
||||
content_length);
|
||||
}
|
||||
free(fbuffer);
|
||||
}
|
||||
CancelAction();
|
||||
}
|
||||
|
||||
if (!b || !res)
|
||||
net_close(s);
|
||||
|
||||
if (!res)
|
||||
{
|
||||
result = HTTPR_ERR_RECEIVE;
|
||||
net_close(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
result = HTTPR_OK;
|
||||
net_close(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user