[package] firewall: make ESTABLISHED,RELATED rules match before INVALID, use conntrac...
[openwrt.git] / package / uhttpd / src / uhttpd-utils.h
1 /*
2 * uhttpd - Tiny single-threaded httpd - Utility header
3 *
4 * Copyright (C) 2010 Jo-Philipp Wich <xm@subsignal.org>
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 */
18
19 #ifndef _UHTTPD_UTILS_
20
21 #include <stdarg.h>
22 #include <fcntl.h>
23 #include <pwd.h>
24 #include <sys/stat.h>
25
26 #ifdef HAVE_SHADOW
27 #include <shadow.h>
28 #endif
29
30 #define min(x, y) (((x) < (y)) ? (x) : (y))
31 #define max(x, y) (((x) > (y)) ? (x) : (y))
32
33 #define array_size(x) \
34 (sizeof(x) / sizeof(x[0]))
35
36 #define foreach_header(i, h) \
37 for( i = 0; (i + 1) < (sizeof(h) / sizeof(h[0])) && h[i]; i += 2 )
38
39 #define fd_cloexec(fd) \
40 fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)
41
42 #define ensure_out(x) \
43 do { if((x) < 0) goto out; } while(0)
44
45 #define ensure_ret(x) \
46 do { if((x) < 0) return -1; } while(0)
47
48
49 struct path_info {
50 char *root;
51 char *phys;
52 char *name;
53 char *info;
54 char *query;
55 int redirected;
56 struct stat stat;
57 };
58
59
60 const char * sa_straddr(void *sa);
61 const char * sa_strport(void *sa);
62 int sa_port(void *sa);
63 int sa_rfc1918(void *sa);
64
65 char *strfind(char *haystack, int hslen, const char *needle, int ndlen);
66
67 int select_intr(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
68
69 int uh_tcp_send(struct client *cl, const char *buf, int len);
70 int uh_tcp_peek(struct client *cl, char *buf, int len);
71 int uh_tcp_recv(struct client *cl, char *buf, int len);
72
73 int uh_http_sendhf(
74 struct client *cl, int code, const char *summary,
75 const char *fmt, ...
76 );
77
78 #define uh_http_response(cl, code, message) \
79 uh_http_sendhf(cl, code, message, message)
80
81 int uh_http_sendc(struct client *cl, const char *data, int len);
82
83 int uh_http_sendf(
84 struct client *cl, struct http_request *req,
85 const char *fmt, ...
86 );
87
88 int uh_http_send(
89 struct client *cl, struct http_request *req,
90 const char *buf, int len
91 );
92
93
94 int uh_urldecode(char *buf, int blen, const char *src, int slen);
95 int uh_urlencode(char *buf, int blen, const char *src, int slen);
96 int uh_b64decode(char *buf, int blen, const unsigned char *src, int slen);
97
98
99 struct auth_realm * uh_auth_add(char *path, char *user, char *pass);
100
101 int uh_auth_check(
102 struct client *cl, struct http_request *req, struct path_info *pi
103 );
104
105
106 struct path_info * uh_path_lookup(struct client *cl, const char *url);
107
108 struct listener * uh_listener_add(int sock, struct config *conf);
109 struct listener * uh_listener_lookup(int sock);
110
111 struct client * uh_client_add(int sock, struct listener *serv);
112 struct client * uh_client_lookup(int sock);
113 void uh_client_remove(int sock);
114
115 #ifdef HAVE_CGI
116 struct interpreter * uh_interpreter_add(const char *extn, const char *path);
117 struct interpreter * uh_interpreter_lookup(const char *path);
118 #endif
119
120 #endif
This page took 0.053136 seconds and 5 git commands to generate.