bozohttpd.h revision 1.1 1 /* $eterna: bozohttpd.h,v 1.13 2006/05/17 08:19:10 mrg Exp $ */
2
3 /*
4 * Copyright (c) 1997-2006 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer and
14 * dedication in the documentation and/or other materials provided
15 * with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 *
31 */
32
33 #include <sys/stat.h>
34
35 #include <stdio.h>
36
37 #include "queue.h"
38
39 /* headers */
40 struct headers {
41 const char *h_header;
42 /*const*/ char *h_value; /* this gets free()'ed etc at times */
43 SIMPLEQ_ENTRY(headers) h_next;
44 };
45
46 /* http_req */
47 typedef struct {
48 int hr_method;
49 #define HTTP_GET 0x01
50 #define HTTP_POST 0x02
51 #define HTTP_HEAD 0x03
52 #define HTTP_OPTIONS 0x04 /* not supported */
53 #define HTTP_PUT 0x05 /* not supported */
54 #define HTTP_DELETE 0x06 /* not supported */
55 #define HTTP_TRACE 0x07 /* not supported */
56 #define HTTP_CONNECT 0x08 /* not supported */
57 const char *hr_methodstr;
58 char *hr_url;
59 const char *hr_proto;
60 const char *hr_content_type;
61 const char *hr_content_length;
62 const char *hr_allow;
63 const char *hr_host; /* HTTP/1.1 Host: */
64 const char *hr_referrer;
65 const char *hr_remotehost;
66 const char *hr_remoteaddr;
67 const char *hr_serverport;
68 #ifdef DO_HTPASSWD
69 const char *hr_authrealm;
70 const char *hr_authuser;
71 const char *hr_authpass;
72 #endif
73 SIMPLEQ_HEAD(, headers) hr_headers;
74 int hr_nheaders;
75 } http_req;
76
77 struct content_map {
78 const char *name; /* postfix of file */
79 const char *type; /* matching content-type */
80 const char *encoding; /* matching content-encoding */
81 const char *encoding11; /* matching content-encoding (HTTP/1.1) */
82 const char *cgihandler; /* optional CGI handler */
83 };
84
85 #define WRSZ (64 * 1024)
86
87 /* debug flags */
88 #define DEBUG_NORMAL 1
89 #define DEBUG_FAT 2
90 #define DEBUG_OBESE 3
91 #define DEBUG_EXPLODING 4
92
93 #define strornull(x) ((x) ? (x) : "<null>")
94
95 extern int dflag;
96 extern const char *index_html;
97 extern const char *server_software;
98 extern char *myname;
99
100 #ifdef DEBUG
101 void debug__(int, const char *, ...)
102 __attribute__((__format__(__printf__, 2, 3)));
103 #define debug(x) debug__ x
104 #else
105 #define debug(x)
106 #endif /* DEBUG */
107
108 void warning(const char *, ...)
109 __attribute__((__format__(__printf__, 1, 2)));
110 void error(int, const char *, ...)
111 __attribute__((__format__(__printf__, 2, 3)));
112 void http_error(int, http_req *, const char *);
113
114 void check_special_files(http_req *, const char *);
115 char *http_date(void);
116 void print_header(http_req *, struct stat *, const char *, const char *);
117
118 char *dgetln(int, ssize_t *, ssize_t (*)(int, void *, size_t));
119 char *strnsep(char **, const char *, ssize_t *);
120
121 void *bozomalloc(size_t);
122 void *bozorealloc(void *, size_t);
123 char *bozostrdup(const char *);
124
125 extern const char *Iflag;
126 extern int Iflag_set;
127 extern int bflag, fflag;
128 extern char *slashdir;
129 extern const char http_09[];
130 extern const char http_10[];
131 extern const char http_11[];
132 extern const char text_plain[];
133
134 /* bozotic io */
135 extern int (*bozoprintf)(const char *, ...);
136 extern ssize_t (*bozoread)(int, void *, size_t);
137 extern ssize_t (*bozowrite)(int, const void *, size_t);
138 extern int (*bozoflush)(FILE *);
139
140
141 /* ssl-bozo.c */
142 #ifndef NO_SSL_SUPPORT
143 extern void ssl_set_opts(char *, char *);
144 extern void ssl_init(void);
145 extern void ssl_accept(void);
146 extern void ssl_destroy(void);
147 #else
148 #define ssl_set_opts(x, y) /* nothing */
149 #define ssl_init() /* nothing */
150 #define ssl_accept() /* nothing */
151 #define ssl_destroy() /* nothing */
152 #endif
153
154
155 /* auth-bozo.c */
156 #ifdef DO_HTPASSWD
157 extern void auth_check(http_req *, const char *);
158 extern int auth_check_headers(http_req *, char *, char *, ssize_t);
159 extern void auth_check_special_files(http_req *, const char *);
160 extern void auth_check_401(http_req *, int);
161 extern void auth_cgi_setenv(http_req *, char ***);
162 extern int auth_cgi_count(http_req *);
163 #else
164 #define auth_check(x, y) /* nothing */
165 #define auth_check_headers(x, y, z, a) 0
166 #define auth_check_special_files(x, y) /* nothing */
167 #define auth_check_401(x, y) /* nothing */
168 #define auth_cgi_setenv(x, y) /* nothing */
169 #define auth_cgi_count(x) 0
170 #endif /* DO_HTPASSWD */
171
172
173 /* cgi-bozo.c */
174 #ifndef NO_CGIBIN_SUPPORT
175 void set_cgibin(char *);
176 void spsetenv(const char *env, const char *val, char **envp);
177 void process_cgi(http_req *);
178 void add_content_map_cgi(char *, char *);
179 #else
180 #define process_cgi(r) /* nothing */
181 #endif /* NO_CGIBIN_SUPPORT */
182
183
184 /* daemon-bozo.c */
185 extern const char *Iflag;
186 extern int Iflag_set;
187 #ifndef NO_DAEMON_MODE
188 extern char *iflag;
189
190 void daemon_init(void);
191 void daemon_fork(void);
192 #else
193 #define daemon_init() /* nothing */
194 #define daemon_fork() /* nothing */
195 #endif /* NO_DAEMON_MODE */
196
197
198 /* tilde-luzah-bozo.c */
199 #ifndef NO_USER_SUPPORT
200 extern int uflag;
201 extern const char *public_html;
202
203 char * user_transform(http_req *, int *);
204 #else
205 #define user_transform(a, b) /* nothing */
206 #endif /* NO_USER_SUPPORT */
207
208
209 /* dir-index-bozo.c */
210 #ifndef NO_DIRINDEX_SUPPORT
211 extern int Xflag;
212 extern int Hflag;
213 int directory_index(http_req *, const char *, int);
214 #else
215 #define directory_index(a, b, c) 0
216 #endif /* NO_DIRINDEX_SUPPORT */
217
218
219 /* content-bozo.c */
220 const char *content_type(http_req *, const char *);
221 const char *content_encoding(http_req *, const char *);
222 struct content_map *match_content_map(const char *, int);
223 struct content_map *get_content_map(const char *);
224 #ifndef NO_DYNAMIC_CONTENT
225 void add_content_map_mime(char *, char *, char *, char *);
226 #endif
227