-
Notifications
You must be signed in to change notification settings - Fork 2
/
parser.h
71 lines (57 loc) · 1.64 KB
/
parser.h
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
64
65
66
67
68
69
70
71
//#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "http-parser/http_parser.h"
#define PARSER_DATA_VECTOR_SIZE 64
#define MESSAGE_BEGIN 1
#define URL 2
#define HEADER_FIELD 3
#define HEADER_VALUE 4
#define HEADERS_COMPLETE 5
#define BODY 6
#define MESSAGE_COMPLETE 7
typedef struct {
uint16_t* vector;
int vector_index;
char* input_pointer;
int input_index;
} http_parser_data;
/* Executes the parser. Returns number of parsed bytes. Sets
* `parser->http_errno` on error. */
size_t custom_parser_execute(http_parser* parser,
const http_parser_settings* settings,
const char* str,
size_t len);
void free_parser(http_parser* parser);
http_parser_settings* make_settings(void);
http_parser* make_parser(uint16_t* vector);
/**
* Executed at begin of message.
*/
int http_message_begin_cb(http_parser* parser);
/**
* Executed when parsed the url.
*/
int http_url_cb(http_parser* parser, const char* chunk, size_t len);
/**
* Executed on each header field.
*/
int http_header_field_cb(http_parser* parser, const char* chunk, size_t len);
/**
* Executed on each header value.
*/
int http_header_value_cb(http_parser* parser, const char* chunk, size_t len);
/**
* Executed when completed header parsing.
*/
int http_headers_complete_cb(http_parser* parser);
/**
* Executed on body
*/
int http_body_cb(http_parser* parser, const char* chunk, size_t len);
/**
* Is executed when request fully parsed.
* User can read all request options from "&parser->data.request".
*/
int http_message_complete_cb(http_parser* parser);