-
Notifications
You must be signed in to change notification settings - Fork 57
/
ebb_request_parser.h
97 lines (85 loc) · 2.98 KB
/
ebb_request_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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/* HTTP/1.1 Parser
* Copyright 2008 ryah dahl, ry at tiny clouds punkt org
*
* Based on Zed Shaw's parser for Mongrel.
* Copyright (c) 2005 Zed A. Shaw
*
* This software may be distributed under the "MIT" license included in the
* README
*/
#ifndef ebb_request_parser_h
#define ebb_request_parser_h
#include <sys/types.h>
typedef struct ebb_request ebb_request;
typedef struct ebb_request_parser ebb_request_parser;
typedef void (*ebb_header_cb)(ebb_request*, const char *at, size_t length, int header_index);
typedef void (*ebb_element_cb)(ebb_request*, const char *at, size_t length);
#define EBB_RAGEL_STACK_SIZE 10
#define EBB_MAX_MULTIPART_BOUNDARY_LEN 20
struct ebb_request {
enum { EBB_COPY
, EBB_DELETE
, EBB_GET
, EBB_HEAD
, EBB_LOCK
, EBB_MKCOL
, EBB_MOVE
, EBB_OPTIONS
, EBB_POST
, EBB_PROPFIND
, EBB_PROPPATCH
, EBB_PUT
, EBB_TRACE
, EBB_UNLOCK
} method;
enum { EBB_IDENTITY
, EBB_CHUNKED
} transfer_encoding; /* ro */
size_t content_length; /* ro - 0 if unknown */
size_t body_read; /* ro */
int eating_body; /* ro */
int expect_continue; /* ro */
unsigned int version_major; /* ro */
unsigned int version_minor; /* ro */
int number_of_headers; /* ro */
int keep_alive; /* private - use ebb_request_should_keep_alive */
char multipart_boundary[EBB_MAX_MULTIPART_BOUNDARY_LEN]; /* ro */
unsigned int multipart_boundary_len; /* ro */
/* Public - ordered list of callbacks */
ebb_element_cb on_path;
ebb_element_cb on_query_string;
ebb_element_cb on_uri;
ebb_element_cb on_fragment;
ebb_header_cb on_header_field;
ebb_header_cb on_header_value;
void (*on_headers_complete)(ebb_request *);
ebb_element_cb on_body;
void (*on_complete)(ebb_request *);
void *data;
};
struct ebb_request_parser {
int cs; /* private */
int stack[EBB_RAGEL_STACK_SIZE]; /* private */
int top; /* private */
size_t chunk_size; /* private */
unsigned eating:1; /* private */
ebb_request *current_request; /* ro */
const char *header_field_mark;
const char *header_value_mark;
const char *query_string_mark;
const char *path_mark;
const char *uri_mark;
const char *fragment_mark;
/* Public */
ebb_request* (*new_request)(void*);
void *data;
};
void ebb_request_parser_init(ebb_request_parser *parser);
size_t ebb_request_parser_execute(ebb_request_parser *parser, const char *data, size_t len);
int ebb_request_parser_has_error(ebb_request_parser *parser);
int ebb_request_parser_is_finished(ebb_request_parser *parser);
void ebb_request_init(ebb_request *);
int ebb_request_should_keep_alive(ebb_request *request);
#define ebb_request_has_body(request) \
(request->transfer_encoding == EBB_CHUNKED || request->content_length > 0 )
#endif