bozohttpd.h revision 1.1.1.2 1 /* $eterna: bozohttpd.h,v 1.18 2008/03/03 03:36:11 mrg Exp $ */
2
3 /*
4 * Copyright (c) 1997-2008 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_range;
66 int hr_have_range;
67 off_t hr_first_byte_pos;
68 off_t hr_last_byte_pos;
69 const char *hr_remotehost;
70 const char *hr_remoteaddr;
71 const char *hr_serverport;
72 #ifdef DO_HTPASSWD
73 const char *hr_authrealm;
74 const char *hr_authuser;
75 const char *hr_authpass;
76 #endif
77 SIMPLEQ_HEAD(, headers) hr_headers;
78 int hr_nheaders;
79 } http_req;
80
81 struct content_map {
82 const char *name; /* postfix of file */
83 const char *type; /* matching content-type */
84 const char *encoding; /* matching content-encoding */
85 const char *encoding11; /* matching content-encoding (HTTP/1.1) */
86 const char *cgihandler; /* optional CGI handler */
87 };
88
89 #define WRSZ (64 * 1024)
90
91 /* debug flags */
92 #define DEBUG_NORMAL 1
93 #define DEBUG_FAT 2
94 #define DEBUG_OBESE 3
95 #define DEBUG_EXPLODING 4
96
97 #define strornull(x) ((x) ? (x) : "<null>")
98
99 extern int dflag;
100 extern const char *index_html;
101 extern const char *server_software;
102 extern char *myname;
103
104 #ifdef DEBUG
105 void debug__(int, const char *, ...)
106 __attribute__((__format__(__printf__, 2, 3)));
107 #define debug(x) debug__ x
108 #else
109 #define debug(x)
110 #endif /* DEBUG */
111
112 void warning(const char *, ...)
113 __attribute__((__format__(__printf__, 1, 2)));
114 void error(int, const char *, ...)
115 __attribute__((__format__(__printf__, 2, 3)));
116 void http_error(int, http_req *, const char *)
117 __attribute__((__noreturn__));
118
119 void check_special_files(http_req *, const char *);
120 char *http_date(void);
121 void print_header(http_req *, struct stat *, const char *, const char *);
122
123 char *bozodgetln(int, ssize_t *, ssize_t (*)(int, void *, size_t));
124 char *bozostrnsep(char **, const char *, ssize_t *);
125
126 void *bozomalloc(size_t);
127 void *bozorealloc(void *, size_t);
128 char *bozostrdup(const char *);
129
130 extern const char *Iflag;
131 extern int Iflag_set;
132 extern int bflag, fflag;
133 extern char *slashdir;
134 extern const char http_09[];
135 extern const char http_10[];
136 extern const char http_11[];
137 extern const char text_plain[];
138
139 /* bozotic io */
140 extern int (*bozoprintf)(const char *, ...);
141 extern ssize_t (*bozoread)(int, void *, size_t);
142 extern ssize_t (*bozowrite)(int, const void *, size_t);
143 extern int (*bozoflush)(FILE *);
144
145
146 /* ssl-bozo.c */
147 #ifndef NO_SSL_SUPPORT
148 extern void ssl_set_opts(char *, char *);
149 extern void ssl_init(void);
150 extern void ssl_accept(void);
151 extern void ssl_destroy(void);
152 #else
153 #define ssl_set_opts(x, y) /* nothing */
154 #define ssl_init() /* nothing */
155 #define ssl_accept() /* nothing */
156 #define ssl_destroy() /* nothing */
157 #endif
158
159
160 /* auth-bozo.c */
161 #ifdef DO_HTPASSWD
162 extern void auth_check(http_req *, const char *);
163 extern int auth_check_headers(http_req *, char *, char *, ssize_t);
164 extern void auth_check_special_files(http_req *, const char *);
165 extern void auth_check_401(http_req *, int);
166 extern void auth_cgi_setenv(http_req *, char ***);
167 extern int auth_cgi_count(http_req *);
168 #else
169 #define auth_check(x, y) /* nothing */
170 #define auth_check_headers(x, y, z, a) 0
171 #define auth_check_special_files(x, y) /* nothing */
172 #define auth_check_401(x, y) /* nothing */
173 #define auth_cgi_setenv(x, y) /* nothing */
174 #define auth_cgi_count(x) 0
175 #endif /* DO_HTPASSWD */
176
177
178 /* cgi-bozo.c */
179 #ifndef NO_CGIBIN_SUPPORT
180 void set_cgibin(char *);
181 void spsetenv(const char *env, const char *val, char **envp);
182 void process_cgi(http_req *);
183 void add_content_map_cgi(char *, char *);
184 #else
185 #define process_cgi(r) /* nothing */
186 #endif /* NO_CGIBIN_SUPPORT */
187
188
189 /* daemon-bozo.c */
190 extern const char *Iflag;
191 extern int Iflag_set;
192 #ifndef NO_DAEMON_MODE
193 extern char *iflag;
194
195 void daemon_init(void);
196 void daemon_fork(void);
197 #else
198 #define daemon_init() /* nothing */
199 #define daemon_fork() /* nothing */
200 #endif /* NO_DAEMON_MODE */
201
202
203 /* tilde-luzah-bozo.c */
204 #ifndef NO_USER_SUPPORT
205 extern int uflag;
206 extern const char *public_html;
207
208 char * user_transform(http_req *, int *);
209 #endif /* NO_USER_SUPPORT */
210
211
212 /* dir-index-bozo.c */
213 #ifndef NO_DIRINDEX_SUPPORT
214 extern int Xflag;
215 extern int Hflag;
216 int directory_index(http_req *, const char *, int);
217 #else
218 #define directory_index(a, b, c) 0
219 #endif /* NO_DIRINDEX_SUPPORT */
220
221
222 /* content-bozo.c */
223 const char *content_type(http_req *, const char *);
224 const char *content_encoding(http_req *, const char *);
225 struct content_map *match_content_map(const char *, int);
226 struct content_map *get_content_map(const char *);
227 #ifndef NO_DYNAMIC_CONTENT
228 void add_content_map_mime(char *, char *, char *, char *);
229 #endif
230