uhttpd:
[project/luci.git] / contrib / package / uhttpd / src / uhttpd-utils.h
1 #ifndef _UHTTPD_UTILS_
2
3 #include <stdarg.h>
4 #include <fcntl.h>
5 #include <sys/stat.h>
6
7 #define min(x, y) (((x) < (y)) ? (x) : (y))
8 #define max(x, y) (((x) > (y)) ? (x) : (y))
9
10 #define array_size(x) \
11         (sizeof(x) / sizeof(x[0]))
12
13 #define foreach_header(i, h) \
14         for( i = 0; (i + 1) < (sizeof(h) / sizeof(h[0])) && h[i]; i += 2 )
15
16 struct uh_path_info {
17         char *root;
18         char *wdir;
19         char *phys;
20         char *name;
21         char *info;
22         char *query;
23         struct stat stat;
24 };
25
26
27 const char * sa_straddr(void *sa);
28 const char * sa_strport(void *sa);
29 int sa_port(void *sa);
30
31 char *strfind(char *haystack, int hslen, const char *needle, int ndlen);
32
33 int uh_tcp_send(struct client *cl, const char *buf, int len);
34 int uh_tcp_peek(struct client *cl, char *buf, int len);
35 int uh_tcp_recv(struct client *cl, char *buf, int len);
36
37 int uh_http_sendhf(struct client *cl, int code, const char *summary, const char *fmt, ...);
38
39 #define uh_http_response(cl, code, message) \
40         uh_http_sendhf(cl, code, message, message)
41
42 int uh_http_sendc(struct client *cl, const char *data, int len);
43
44 int uh_http_sendf(
45         struct client *cl, struct http_request *req,
46         const char *fmt, ...
47 );
48
49 int uh_http_send(
50         struct client *cl, struct http_request *req,
51         const char *buf, int len
52 );
53
54
55 int uh_urldecode(char *buf, int blen, const char *src, int slen);
56 int uh_urlencode(char *buf, int blen, const char *src, int slen);
57 int uh_path_normalize(char *buf, int blen, const char *src, int slen);
58
59 struct uh_path_info * uh_path_lookup(struct client *cl, const char *url);
60
61 struct listener * uh_listener_add(int sock, struct config *conf);
62 struct listener * uh_listener_lookup(int sock);
63
64 struct client * uh_client_add(int sock, struct listener *serv);
65 struct client * uh_client_lookup(int sock);
66 void uh_client_remove(int sock);
67
68 #endif