7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#ifndef HTTP_PARSER_H
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#define HTTP_PARSER_H
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch/*
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch * Character definitions
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_token_char_mask;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_value_char_mask;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_text_char_mask;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_qdtext_char_mask;
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_ctext_char_mask;
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Boschextern const unsigned char _http_token68_char_mask;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschextern const unsigned char _http_char_lookup[256];
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic inline bool http_char_is_token(unsigned char ch) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return (_http_char_lookup[ch] & _http_token_char_mask) != 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic inline bool http_char_is_value(unsigned char ch) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return (_http_char_lookup[ch] & _http_value_char_mask) != 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic inline bool http_char_is_text(unsigned char ch) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return (_http_char_lookup[ch] & _http_text_char_mask) != 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic inline bool http_char_is_qdtext(unsigned char ch) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return (_http_char_lookup[ch] & _http_qdtext_char_mask) != 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstatic inline bool http_char_is_ctext(unsigned char ch) {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch return (_http_char_lookup[ch] & _http_ctext_char_mask) != 0;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch}
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Boschstatic inline bool http_char_is_token68(unsigned char ch) {
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Bosch return (_http_char_lookup[ch] & _http_token68_char_mask) != 0;
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Bosch}
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch/*
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch * HTTP value parsing
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch */
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschstruct http_parser {
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const unsigned char *begin, *cur, *end;
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch};
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_parser_init(struct http_parser *parser,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const unsigned char *data, size_t size);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Boschvoid http_parse_ows(struct http_parser *parser);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
0b5bdb5ba6c8cb928b6d2dcc4636148bfa1a7ec7Stephan Boschint http_parser_skip_token(struct http_parser *parser);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschint http_parse_token(struct http_parser *parser, const char **token_r);
7384b4e78eaab44693c985192276e31322155e32Stephan Boschint http_parse_token_list_next(struct http_parser *parser,
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch const char **token_r);
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch
233a96794faa7734dfc3aea19503c14b29cccfb7Stephan Boschint http_parse_quoted_string(struct http_parser *parser, const char **str_r);
6ee9ce5ed955a1283dc22ad28980bf9cc23d4c4eStephan Boschint http_parse_token_or_qstring(struct http_parser *parser,
6ee9ce5ed955a1283dc22ad28980bf9cc23d4c4eStephan Bosch const char **word_r);
233a96794faa7734dfc3aea19503c14b29cccfb7Stephan Bosch
7384b4e78eaab44693c985192276e31322155e32Stephan Bosch#endif