(net_http.c) Move struct definition out of header again

This commit is contained in:
twinaphex 2015-02-16 02:50:32 +01:00
parent 2d5b4f58aa
commit 63cf5a07c3
3 changed files with 31 additions and 29 deletions

View File

@ -584,7 +584,7 @@ struct global
msg_queue_t *msg_queue;
#ifdef HAVE_NETWORKING
msg_queue_t *http_msg_queue;
http_t *http_handle;
struct http_t *http_handle;
http_cb_t http_cb;
#endif

View File

@ -38,6 +38,21 @@ enum
T_CHUNK
};
struct http_t
{
int fd;
int status;
char part;
char bodytype;
bool error;
size_t pos;
size_t len;
size_t buflen;
char * data;
};
static bool net_http_parse_url(char *url, char **domain,
int *port, char **location)
{
@ -174,12 +189,12 @@ static ssize_t net_http_recv(int fd, bool *error,
return -1;
}
http_t *net_http_new(const char * url)
struct http_t *net_http_new(const char * url)
{
bool error;
char *domain = NULL, *location = NULL;
int port = 0, fd = -1;
http_t *state = NULL;
struct http_t *state = NULL;
char *urlcopy =(char*)malloc(strlen(url)+1);
strcpy(urlcopy, url);
@ -218,7 +233,7 @@ http_t *net_http_new(const char * url)
free(urlcopy);
state = (http_t*)malloc(sizeof(http_t));
state = (struct http_t*)malloc(sizeof(struct http_t));
state->fd = fd;
state->status = -1;
state->data = NULL;
@ -239,12 +254,12 @@ fail:
return NULL;
}
int net_http_fd(http_t *state)
int net_http_fd(struct http_t *state)
{
return state->fd;
}
bool net_http_update(http_t *state, size_t* progress, size_t* total)
bool net_http_update(struct http_t *state, size_t* progress, size_t* total)
{
ssize_t newlen = 0;
@ -439,12 +454,12 @@ fail:
return true;
}
int net_http_status(http_t *state)
int net_http_status(struct http_t *state)
{
return state->status;
}
uint8_t* net_http_data(http_t *state, size_t* len, bool accept_error)
uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error)
{
if (!accept_error &&
(state->error || state->status<200 || state->status>299))
@ -460,7 +475,7 @@ uint8_t* net_http_data(http_t *state, size_t* len, bool accept_error)
return (uint8_t*)state->data;
}
void net_http_delete(http_t *state)
void net_http_delete(struct http_t *state)
{
if (state->fd != -1)
socket_close(state->fd);

View File

@ -25,42 +25,29 @@
extern "C" {
#endif
typedef struct
{
int fd;
int status;
char part;
char bodytype;
bool error;
size_t pos;
size_t len;
size_t buflen;
char * data;
} http_t;
struct http_t;
http_t *net_http_new(const char * url);
struct http_t *net_http_new(const char * url);
/* You can use this to call net_http_update
* only when something will happen; select() it for reading. */
int net_http_fd(http_t *state);
int net_http_fd(struct http_t *state);
/* Returns true if it's done, or if something broke.
* 'total' will be 0 if it's not known. */
bool net_http_update(http_t *state, size_t* progress, size_t* total);
bool net_http_update(struct http_t *state, size_t* progress, size_t* total);
/* 200, 404, or whatever. */
int net_http_status(http_t *state);
int net_http_status(struct http_t *state);
/* Returns the downloaded data. The returned buffer is owned by the
* HTTP handler; it's freed by net_http_delete.
*
* If the status is not 20x and accept_error is false, it returns NULL. */
uint8_t* net_http_data(http_t *state, size_t* len, bool accept_error);
uint8_t* net_http_data(struct http_t *state, size_t* len, bool accept_error);
/* Cleans up all memory. */
void net_http_delete(http_t *state);
void net_http_delete(struct http_t *state);
#ifdef __cplusplus
}