forked from cozis/xHTTP
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxhttp.h
81 lines (63 loc) · 1.73 KB
/
xhttp.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
#ifndef XHTTP_H
#define XHTTP_H
typedef void *xh_handle;
typedef struct {
char *str; int len;
} xh_string;
typedef struct {
xh_string key, val;
} xh_pair;
typedef struct {
xh_pair *list;
int count;
} xh_table;
typedef enum {
XH_GET = 1,
XH_HEAD = 2,
XH_POST = 4,
XH_PUT = 8,
XH_DELETE = 16,
XH_CONNECT = 32,
XH_OPTIONS = 64,
XH_TRACE = 128,
XH_PATCH = 256,
} xh_method;
typedef struct {
xh_method method_id;
xh_string method;
xh_string params;
xh_string URL;
unsigned int version_minor;
unsigned int version_major;
xh_table headers;
xh_string body;
} xh_request;
typedef struct {
int status;
xh_table headers;
xh_string body;
const char *file;
_Bool close;
} xh_response;
typedef struct {
_Bool reuse_address;
unsigned int maximum_parallel_connections;
unsigned int backlog;
} xh_config;
typedef void (*xh_callback)(xh_request*, xh_response*, void*);
const char *xhttp(const char *addr, unsigned short port,
xh_callback callback, void *userp,
xh_handle *handle, const xh_config *config);
void xh_quit(xh_handle handle);
xh_config xh_get_default_configs();
void xh_header_add(xh_response *res, const char *name, const char *valfmt, ...);
void xh_header_rem(xh_response *res, const char *name);
const char *xh_header_get(void *req_or_res, const char *name);
_Bool xh_header_cmp(const char *a, const char *b);
int xh_urlcmp(const char *URL, const char *fmt, ...);
int xh_vurlcmp(const char *URL, const char *fmt, va_list va);
#define xh_string_new(s, l) \
((xh_string) { (s), ((int) (l)) < 0 ? (int) strlen(s) : (int) (l) })
#define xh_string_from_literal(s) \
((xh_string) { (s), sizeof(s)-1 })
#endif // #ifndef XHTTP_H