| 35 |
35 |
| 36 #ifdef __cplusplus |
36 #ifdef __cplusplus |
| 37 extern "C" { |
37 extern "C" { |
| 38 #endif |
38 #endif |
| 39 |
39 |
| 40 /* |
40 |
| 41 * http parser states |
|
| 42 * |
|
| 43 * 0: start line |
|
| 44 * 1: header |
|
| 45 * 2: finish |
|
| 46 */ |
|
| 47 |
|
| 48 typedef struct _http_parser { |
41 typedef struct _http_parser { |
| 49 HTTPRequest *request; |
42 /* |
| 50 |
43 * http parser type |
| |
44 * |
| |
45 * 0: request |
| |
46 * 1: response |
| |
47 */ |
| |
48 int type; |
| |
49 |
| |
50 /* |
| |
51 * http parser states |
| |
52 * |
| |
53 * 0: start line |
| |
54 * 1: header |
| |
55 * 2: finish |
| |
56 */ |
| 51 int state; |
57 int state; |
| |
58 |
| |
59 /* |
| |
60 * first line (request/response line) |
| |
61 */ |
| 52 cxmutstr start_line; |
62 cxmutstr start_line; |
| |
63 |
| |
64 netbuf *netbuf; |
| |
65 HeaderArray *headers; |
| |
66 cxmutstr method; |
| |
67 cxmutstr uri; |
| |
68 cxmutstr httpv; |
| |
69 cxmutstr msg; |
| |
70 int status; |
| 53 |
71 |
| 54 /* local parser variables */ |
72 /* local parser variables */ |
| 55 int wl; /* only white space */ |
73 int wl; /* only white space */ |
| 56 int tk; /* token: 0: header name 1: header value */ |
74 int tk; /* token: 0: header name 1: header value */ |
| 57 int offset; /* offset of parsed string */ |
75 int offset; /* offset of parsed string */ |
| 60 cxmutstr value; |
78 cxmutstr value; |
| 61 |
79 |
| 62 } HttpParser; |
80 } HttpParser; |
| 63 |
81 |
| 64 HttpParser* http_parser_new(HTTPRequest *request); |
82 HttpParser* http_parser_new(HTTPRequest *request); |
| |
83 HttpParser* http_parser_new2(int type, netbuf *netbuf, HeaderArray *headers); |
| 65 void http_parser_free(HttpParser *parser); |
84 void http_parser_free(HttpParser *parser); |
| |
85 |
| |
86 /* |
| |
87 * updates method, uri and httpv in an HTTPRequest object |
| |
88 */ |
| |
89 void http_parser_update_request(HttpParser *parser, HTTPRequest *request); |
| 66 |
90 |
| 67 /* |
91 /* |
| 68 * process http parsing |
92 * process http parsing |
| 69 * |
93 * |
| 70 * return |
94 * return |