-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhttp.h
executable file
·136 lines (103 loc) · 2.9 KB
/
http.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef HTTP_H_INCLUDED
#define HTTP_H_INCLUDED
#include "pool.h"
#ifdef __cplusplus
extern "C" {
#endif // __cplusplus
typedef enum {
HTTP_OP_UNKNOWN
,HTTP_OP_RESPONSE
,HTTP_OP_GET
,HTTP_OP_PUT
,HTTP_OP_POST
} http_op_t;
typedef struct http_keyval_s {
struct http_keyval_s *next;
char *key;
char *val;
} http_keyval_t;
typedef struct {
char *op;
int op_code;
int response_code;
char *response_message;
char *uri;
char *http_version;
float version;
http_keyval_t *headers, *headers_last;
size_t header_len; /* number of bytes from header to content */
size_t total_len; /* header_len + content_len */
char *content_ptr; /* points to the first byte of content in
buf after the header if
http_header_parse(hdr, buf) returned 1 */
size_t content_len; /* Content-Length: field from header */
char *content_type;
int error_line;
int error_state;
int error_col;
pool_t *pool;
int free_pool;
} http_header_t;
int
http_header_init(http_header_t *http, pool_t *pool);
int
http_header_clear(http_header_t *http);
void
http_header_free(http_header_t *http);
void
http_keyval_free(pool_t *pool, http_keyval_t *root);
char*
http_keyval_get(http_keyval_t *node, char *key, http_keyval_t **found);
/* return successive values of key in header. iter can be null.
Equivaluent to http_keyval_get(http->headers, key, found) */
char*
http_header_get(http_header_t *http, char *key, void **iter);
char *
http_strdup(http_header_t *http, char *str, int len);
/* parses an HTTP client request or server response in buf. Returns
>0 if complete header, 0 if incomplete, or <0 on error. */
int
http_header_parse(http_header_t *http, char *buf, size_t len);
/* returns the number of chars in dst */
int
http_cgi_dec(char *src, int src_len, char *dst, int dst_len);
char*
http_cgi_enc(char *src, int src_len, char *dst, int dst_len);
http_keyval_t*
http_cgi_args(pool_t *pool, char *src, int src_len);
typedef enum url_parse_err_t {
URL_PARSE_ERR_OK=0
,URL_PARSE_ERR_CHAR
,URL_PARSE_ERR_OVER
} url_parse_err_t;
typedef enum url_parse_state_t {
URL_PARSE_PROTO
,URL_PARSE_HOST
,URL_PARSE_PORT
,URL_PARSE_PATH_ARGS
,URL_PARSE_PATH
,URL_PARSE_ARGS
} url_parse_state_t;
typedef struct url_t {
char *url;
char *proto;
char *user;
char *host;
int port;
char *path_args;
char *path;
char *args_str;
http_keyval_t *args;
url_parse_err_t err_code;
url_parse_state_t err_state;
off_t err_pos;
pool_t *pool;
} url_t;
int
url_parse(url_t *url, char *str);
void
url_free(url_t *url);
#ifdef __cplusplus
}
#endif // __cplusplus
#endif // HTTP_H_INCLUDED