http-parser.h revision 0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7
2454dfa32c93c20a8522c6ed42fe057baaac9f9aStephan Bosch#ifndef HTTP_PARSER_H
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen#define HTTP_PARSER_H
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen/*
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen * Character definitions
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen */
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern const unsigned char _http_token_char_mask;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenextern const unsigned char _http_value_char_mask;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenextern const unsigned char _http_text_char_mask;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenextern const unsigned char _http_qdtext_char_mask;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenextern const unsigned char _http_ctext_char_mask;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenextern const unsigned char _http_token68_char_mask;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenextern const unsigned char _http_char_lookup[256];
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstatic inline bool http_char_is_token(unsigned char ch) {
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen return (_http_char_lookup[ch] & _http_token_char_mask) != 0;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen}
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstatic inline bool http_char_is_value(unsigned char ch) {
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen return (_http_char_lookup[ch] & _http_value_char_mask) != 0;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen}
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstatic inline bool http_char_is_text(unsigned char ch) {
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen return (_http_char_lookup[ch] & _http_text_char_mask) != 0;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen}
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenstatic inline bool http_char_is_qdtext(unsigned char ch) {
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen return (_http_char_lookup[ch] & _http_qdtext_char_mask) != 0;
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen}
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic inline bool http_char_is_ctext(unsigned char ch) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen return (_http_char_lookup[ch] & _http_ctext_char_mask) != 0;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen}
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenstatic inline bool http_char_is_token68(unsigned char ch) {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen return (_http_char_lookup[ch] & _http_token68_char_mask) != 0;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen}
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen/*
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen * HTTP value parsing
29543188462c9348f365ec29115d777ffe4769d3Timo Sirainen */
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainenstruct http_parser {
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const unsigned char *begin, *cur, *end;
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen};
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainen
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainenvoid http_parser_init(struct http_parser *parser,
0f97c2b6ec76e7f600e983cb952cf265a6189114Timo Sirainen const unsigned char *data, size_t size);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
e0aff4c7e3336ec4b5edbcfc3a72e1e118603ee2Timo Sirainenvoid http_parse_ows(struct http_parser *parser);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenint http_parser_skip_token(struct http_parser *parser);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenint http_parse_token(struct http_parser *parser, const char **token_r);
34b724d1d7e50b1ab24267a3b6fc089b1147c1abAki Tuomiint http_parse_token_list_next(struct http_parser *parser,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char **token_r);
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainenint http_parse_quoted_string(struct http_parser *parser, const char **str_r);
7ff6268cc35102675d73d44d680bed13d0709f7bTimo Sirainenint http_parse_token_or_qstring(struct http_parser *parser,
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen const char **word_r);
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainen
1da5113b93f5dd0543a155040daa7ae3f3718b8bTimo Sirainen#endif
66e1cf5014bec1cf1a8339be6fccc9be5ad3c793Timo Sirainen