b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen#ifndef HTTP_REQUEST_PARSER_H
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen#define HTTP_REQUEST_PARSER_H
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen
e8f1e510df3ab051a816715c2056f0d10aee929eStephan Bosch#include "http-request.h"
208dcaf62332b80b220c8c66e776f7cc0c39253bStephan Bosch
208dcaf62332b80b220c8c66e776f7cc0c39253bStephan Boschenum http_request_parse_error {
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_NONE = 0, /* no error */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_BROKEN_STREAM, /* stream error */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_BROKEN_REQUEST, /* unrecoverable generic error */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_BAD_REQUEST, /* recoverable generic error */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_NOT_IMPLEMENTED, /* used unimplemented feature
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch (recoverable) */
22b47ecd1e6fd11d69433e4111adc57c40dde270Stephan Bosch HTTP_REQUEST_PARSE_ERROR_EXPECTATION_FAILED, /* unknown item in Expect:
22b47ecd1e6fd11d69433e4111adc57c40dde270Stephan Bosch header (recoverable) */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_METHOD_TOO_LONG, /* method too long (fatal) */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_TARGET_TOO_LONG, /* target too long (fatal) */
fa4d00f73d120603a7886aed7433d6c3fceb9bf5Stephan Bosch HTTP_REQUEST_PARSE_ERROR_PAYLOAD_TOO_LARGE /* payload too large (fatal) */
208dcaf62332b80b220c8c66e776f7cc0c39253bStephan Bosch};
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Boschenum http_request_parse_flags {
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch /* Strictly adhere to the HTTP protocol specification */
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch HTTP_REQUEST_PARSE_FLAG_STRICT = BIT(0)
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch};
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainenstruct http_request_parser *
feba5e502b2131c9a1c766b7ef9ff041dbf71d1dStephan Boschhttp_request_parser_init(struct istream *input,
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch const struct http_request_limits *limits,
7ebcb054e0d3cc4be54038cbf763ec4189d9725bStephan Bosch enum http_request_parse_flags flags) ATTR_NULL(2);
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainenvoid http_request_parser_deinit(struct http_request_parser **_parser);
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen
d7b94e1721d86926891c74ca1998141d55d1adeaStephan Boschint http_request_parse_finish_payload(
d7b94e1721d86926891c74ca1998141d55d1adeaStephan Bosch struct http_request_parser *parser,
d7b94e1721d86926891c74ca1998141d55d1adeaStephan Bosch enum http_request_parse_error *error_code_r,
d7b94e1721d86926891c74ca1998141d55d1adeaStephan Bosch const char **error_r);
d7b94e1721d86926891c74ca1998141d55d1adeaStephan Bosch
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainenint http_request_parse_next(struct http_request_parser *parser,
6dad0888fcec8372f230941c70d8940b8c203b32Stephan Bosch pool_t pool, struct http_request *request,
208dcaf62332b80b220c8c66e776f7cc0c39253bStephan Bosch enum http_request_parse_error *error_code_r, const char **error_r);
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen
b8a1b8eb4f13971c0539ce95edcd99503cc6f475Stephan Boschbool http_request_parser_pending_payload(struct http_request_parser *parser);
b8a1b8eb4f13971c0539ce95edcd99503cc6f475Stephan Bosch
b72c3363092b73cab1da2de4a9d75592e7d8fd6bTimo Sirainen#endif