(net_http.c) Cleanups
This commit is contained in:
parent
d8fd5e14d0
commit
e893f98787
21
net_http.c
21
net_http.c
|
@ -33,8 +33,9 @@ enum
|
|||
|
||||
enum
|
||||
{
|
||||
t_full,
|
||||
t_len, t_chunk
|
||||
T_FULL = 0,
|
||||
T_LEN,
|
||||
T_CHUNK
|
||||
};
|
||||
|
||||
static bool net_http_parse_url(char *url, char **domain,
|
||||
|
@ -222,7 +223,7 @@ http_t *net_http_new(const char * url)
|
|||
state->status = -1;
|
||||
state->data = NULL;
|
||||
state->part = p_header_top;
|
||||
state->bodytype= t_full;
|
||||
state->bodytype= T_FULL;
|
||||
state->error = false;
|
||||
state->pos = 0;
|
||||
state->len = 0;
|
||||
|
@ -288,20 +289,18 @@ bool net_http_update(http_t *state, size_t* progress, size_t* total)
|
|||
if (!strncmp(state->data, "Content-Length: ",
|
||||
strlen("Content-Length: ")))
|
||||
{
|
||||
state->bodytype = t_len;
|
||||
state->bodytype = T_LEN;
|
||||
state->len = strtol(state->data +
|
||||
strlen("Content-Length: "), NULL, 10);
|
||||
}
|
||||
if (!strcmp(state->data, "Transfer-Encoding: chunked"))
|
||||
{
|
||||
state->bodytype=t_chunk;
|
||||
}
|
||||
state->bodytype = T_CHUNK;
|
||||
|
||||
/* TODO: save headers somewhere */
|
||||
if (state->data[0]=='\0')
|
||||
{
|
||||
state->part = p_body;
|
||||
if (state->bodytype == t_chunk)
|
||||
if (state->bodytype == T_CHUNK)
|
||||
state->part = p_body_chunklen;
|
||||
}
|
||||
}
|
||||
|
@ -326,7 +325,7 @@ bool net_http_update(http_t *state, size_t* progress, size_t* total)
|
|||
|
||||
if (newlen < 0)
|
||||
{
|
||||
if (state->bodytype == t_full)
|
||||
if (state->bodytype == T_FULL)
|
||||
{
|
||||
state->part = p_done;
|
||||
state->data = (char*)realloc(state->data, state->len);
|
||||
|
@ -344,7 +343,7 @@ bool net_http_update(http_t *state, size_t* progress, size_t* total)
|
|||
}
|
||||
|
||||
parse_again:
|
||||
if (state->bodytype == t_chunk)
|
||||
if (state->bodytype == T_CHUNK)
|
||||
{
|
||||
if (state->part == p_body_chunklen)
|
||||
{
|
||||
|
@ -424,7 +423,7 @@ parse_again:
|
|||
|
||||
if (total)
|
||||
{
|
||||
if (state->bodytype == t_len)
|
||||
if (state->bodytype == T_LEN)
|
||||
*total=state->len;
|
||||
else
|
||||
*total=0;
|
||||
|
|
Loading…
Reference in New Issue