|
|
|
@ -8,56 +8,47 @@ http_parser_settings settings;
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_msg_begin(http_parser *parser)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
|
r->message_begin = 1;
|
|
|
|
|
r->last_was_value = 1; // should always start with a header..
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_msg_end(http_parser *parser)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
|
r->message_end = 1;
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_header_end(http_parser *parser)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
|
r->header_end = 1;
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_url(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
|
assert(strncmp(s->mod->name, (at + 1), length - 1) == 0);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_header_field(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
@ -67,7 +58,6 @@ http_on_header_field(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
|
|
|
|
|
r->last_was_value = 0;
|
|
|
|
|
r->headers[r->nheaders - 1].key = (char *)at; // it is from the sandbox's req_resp_data, should persist.
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -75,7 +65,6 @@ http_on_header_field(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_header_value(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
@ -84,7 +73,6 @@ http_on_header_value(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
assert(length < HTTP_HEADERVAL_MAXSZ);
|
|
|
|
|
|
|
|
|
|
r->headers[r->nheaders - 1].val = (char *)at; // it is from the sandbox's req_resp_data, should persist.
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -92,7 +80,6 @@ http_on_header_value(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
static inline int
|
|
|
|
|
http_on_body(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct sandbox * s = parser->data;
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
@ -103,7 +90,6 @@ http_on_body(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
assert(r->body + r->bodylen == at);
|
|
|
|
|
|
|
|
|
|
r->bodylen += length;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -111,20 +97,15 @@ http_on_body(http_parser *parser, const char *at, size_t length)
|
|
|
|
|
int
|
|
|
|
|
http_request_body_get_sb(struct sandbox *s, char **b)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct http_request *r = &s->rqi;
|
|
|
|
|
|
|
|
|
|
*b = r->body;
|
|
|
|
|
return r->bodylen;
|
|
|
|
|
#else
|
|
|
|
|
return 0;
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int
|
|
|
|
|
http_response_header_set_sb(struct sandbox *c, char *key, int len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
// by now, req_resp_data should only be containing response!
|
|
|
|
|
struct http_response *r = &c->rsi;
|
|
|
|
|
|
|
|
|
@ -132,7 +113,6 @@ http_response_header_set_sb(struct sandbox *c, char *key, int len)
|
|
|
|
|
r->nheaders++;
|
|
|
|
|
r->headers[r->nheaders - 1].hdr = key;
|
|
|
|
|
r->headers[r->nheaders - 1].len = len;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -140,13 +120,11 @@ http_response_header_set_sb(struct sandbox *c, char *key, int len)
|
|
|
|
|
int
|
|
|
|
|
http_response_body_set_sb(struct sandbox *c, char *body, int len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct http_response *r = &c->rsi;
|
|
|
|
|
|
|
|
|
|
assert(len <= c->mod->max_resp_sz);
|
|
|
|
|
r->body = body;
|
|
|
|
|
r->bodylen = len;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -154,12 +132,10 @@ http_response_body_set_sb(struct sandbox *c, char *body, int len)
|
|
|
|
|
int
|
|
|
|
|
http_response_status_set_sb(struct sandbox *c, char *status, int len)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct http_response *r = &c->rsi;
|
|
|
|
|
|
|
|
|
|
r->status = status;
|
|
|
|
|
r->stlen = len;
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
@ -168,7 +144,6 @@ int
|
|
|
|
|
http_response_vector_sb(struct sandbox *c)
|
|
|
|
|
{
|
|
|
|
|
int nb = 0;
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
struct http_response *r = &c->rsi;
|
|
|
|
|
|
|
|
|
|
#ifdef USE_HTTP_UVIO
|
|
|
|
@ -206,7 +181,6 @@ http_response_vector_sb(struct sandbox *c)
|
|
|
|
|
r->bufs[nb].iov_len = 2;
|
|
|
|
|
nb++;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
return nb;
|
|
|
|
@ -215,9 +189,7 @@ http_response_vector_sb(struct sandbox *c)
|
|
|
|
|
int
|
|
|
|
|
http_request_parse_sb(struct sandbox *s, size_t l)
|
|
|
|
|
{
|
|
|
|
|
#ifndef STANDALONE
|
|
|
|
|
http_parser_execute(&s->hp, &settings, s->req_resp_data + s->rr_data_len, l);
|
|
|
|
|
#endif
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|