source: branches/backfire/package/uhttpd/src/uhttpd-utils.h @ 22962

Last change on this file since 22962 was 22962, checked in by jow, 6 years ago

[backfire] merge r22630, r22692, r22805

File size: 3.1 KB
Line 
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 <shadow.h>
25#include <sys/stat.h>
26
27#define min(x, y) (((x) < (y)) ? (x) : (y))
28#define max(x, y) (((x) > (y)) ? (x) : (y))
29
30#define array_size(x) \
31        (sizeof(x) / sizeof(x[0]))
32
33#define foreach_header(i, h) \
34        for( i = 0; (i + 1) < (sizeof(h) / sizeof(h[0])) && h[i]; i += 2 )
35
36#define fd_cloexec(fd) \
37        fcntl(fd, F_SETFD, fcntl(fd, F_GETFD) | FD_CLOEXEC)
38
39#define ensure_out(x) \
40        do { if((x) < 0) goto out; } while(0)
41
42#define ensure_ret(x) \
43        do { if((x) < 0) return -1; } while(0)
44
45
46struct path_info {
47        char *root;
48        char *phys;
49        char *name;
50        char *info;
51        char *query;
52        struct stat stat;
53};
54
55
56const char * sa_straddr(void *sa);
57const char * sa_strport(void *sa);
58int sa_port(void *sa);
59int sa_rfc1918(void *sa);
60
61char *strfind(char *haystack, int hslen, const char *needle, int ndlen);
62
63int select_intr(int n, fd_set *r, fd_set *w, fd_set *e, struct timeval *t);
64
65int uh_tcp_send(struct client *cl, const char *buf, int len);
66int uh_tcp_peek(struct client *cl, char *buf, int len);
67int uh_tcp_recv(struct client *cl, char *buf, int len);
68
69int uh_http_sendhf(
70        struct client *cl, int code, const char *summary,
71        const char *fmt, ...
72);
73
74#define uh_http_response(cl, code, message) \
75        uh_http_sendhf(cl, code, message, message)
76
77int uh_http_sendc(struct client *cl, const char *data, int len);
78
79int uh_http_sendf(
80        struct client *cl, struct http_request *req,
81        const char *fmt, ...
82);
83
84int uh_http_send(
85        struct client *cl, struct http_request *req,
86        const char *buf, int len
87);
88
89
90int uh_urldecode(char *buf, int blen, const char *src, int slen);
91int uh_urlencode(char *buf, int blen, const char *src, int slen);
92int uh_b64decode(char *buf, int blen, const unsigned char *src, int slen);
93
94
95struct auth_realm * uh_auth_add(char *path, char *user, char *pass);
96
97int uh_auth_check(
98        struct client *cl, struct http_request *req, struct path_info *pi
99);
100
101
102struct path_info * uh_path_lookup(struct client *cl, const char *url);
103
104struct listener * uh_listener_add(int sock, struct config *conf);
105struct listener * uh_listener_lookup(int sock);
106
107struct client * uh_client_add(int sock, struct listener *serv);
108struct client * uh_client_lookup(int sock);
109void uh_client_remove(int sock);
110
111#ifdef HAVE_CGI
112struct interpreter * uh_interpreter_add(const char *extn, const char *path);
113struct interpreter * uh_interpreter_lookup(const char *path);
114#endif
115
116#endif
Note: See TracBrowser for help on using the repository browser.