summaryrefslogtreecommitdiffstats
path: root/src/lib-http/http-parser.h
blob: 915e4849efbb8c4e70dda6fd1c17389891cc2fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef HTTP_PARSER_H
#define HTTP_PARSER_H

/*
 * Character definitions
 */

extern const unsigned char _http_token_char_mask;
extern const unsigned char _http_value_char_mask;
extern const unsigned char _http_text_char_mask;
extern const unsigned char _http_qdtext_char_mask;
extern const unsigned char _http_ctext_char_mask;
extern const unsigned char _http_token68_char_mask;

extern const unsigned char _http_char_lookup[256];

static inline bool http_char_is_token(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_token_char_mask) != 0;
}

static inline bool http_char_is_value(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_value_char_mask) != 0;
}

static inline bool http_char_is_text(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_text_char_mask) != 0;
}

static inline bool http_char_is_qdtext(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_qdtext_char_mask) != 0;
}

static inline bool http_char_is_ctext(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_ctext_char_mask) != 0;
}

static inline bool http_char_is_token68(unsigned char ch) {
	return (_http_char_lookup[ch] & _http_token68_char_mask) != 0;
}

/*
 * HTTP value parsing
 */

struct http_parser {
	const unsigned char *begin, *cur, *end;
};

void http_parser_init(struct http_parser *parser,
			const unsigned char *data, size_t size);

void http_parse_ows(struct http_parser *parser);

int http_parser_skip_token(struct http_parser *parser);
int http_parse_token(struct http_parser *parser, const char **token_r);
int http_parse_token_list_next(struct http_parser *parser,
	const char **token_r);

int http_parse_quoted_string(struct http_parser *parser, const char **str_r);
int http_parse_token_or_qstring(struct http_parser *parser,
	const char **word_r);

#endif