Fix memory barrier in a debug function
[netbsd-mini2440.git] / libexec / httpd / bozohttpd.h
blob3963fd85df4205f22fb3db0ae31b0d260ae2c971
1 /* $NetBSD: bozohttpd.h,v 1.10 2009/04/18 21:22:03 mrg Exp $ */
3 /* $eterna: bozohttpd.h,v 1.27 2009/05/22 21:51:38 mrg Exp $ */
5 /*
6 * Copyright (c) 1997-2009 Matthew R. Green
7 * All rights reserved.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer and
16 * dedication in the documentation and/or other materials provided
17 * with the distribution.
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.
32 #include <sys/queue.h>
33 #include <sys/stat.h>
35 #include <stdio.h>
37 /* lots of "const" but gets free()'ed etc at times, sigh */
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;
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_file;
59 char *hr_query;
60 const char *hr_proto;
61 const char *hr_content_type;
62 const char *hr_content_length;
63 const char *hr_allow;
64 const char *hr_host; /* HTTP/1.1 Host: */
65 const char *hr_referrer;
66 const char *hr_range;
67 const char *hr_if_modified_since;
68 int hr_have_range;
69 off_t hr_first_byte_pos;
70 off_t hr_last_byte_pos;
71 /*const*/ char *hr_remotehost;
72 /*const*/ char *hr_remoteaddr;
73 /*const*/ char *hr_serverport;
74 #ifdef DO_HTPASSWD
75 /*const*/ char *hr_authrealm;
76 /*const*/ char *hr_authuser;
77 /*const*/ char *hr_authpass;
78 #endif
79 SIMPLEQ_HEAD(, headers) hr_headers;
80 int hr_nheaders;
81 } http_req;
83 struct content_map {
84 const char *name; /* postfix of file */
85 const char *type; /* matching content-type */
86 const char *encoding; /* matching content-encoding */
87 const char *encoding11; /* matching content-encoding (HTTP/1.1) */
88 const char *cgihandler; /* optional CGI handler */
91 /* write in upto 64KiB chunks, and mmap in upto 64MiB chunks */
92 #define WRSZ (64 * 1024)
93 #define MMAPSZ (WRSZ * 1024)
95 /* debug flags */
96 #define DEBUG_NORMAL 1
97 #define DEBUG_FAT 2
98 #define DEBUG_OBESE 3
99 #define DEBUG_EXPLODING 4
101 #define strornull(x) ((x) ? (x) : "<null>")
103 extern int dflag;
104 extern const char *index_html;
105 extern const char *server_software;
106 extern char *myname;
108 #ifdef DEBUG
109 void debug__(int, const char *, ...)
110 __attribute__((__format__(__printf__, 2, 3)));
111 #define debug(x) debug__ x
112 #else
113 #define debug(x)
114 #endif /* DEBUG */
116 void warning(const char *, ...)
117 __attribute__((__format__(__printf__, 1, 2)));
118 void error(int, const char *, ...)
119 __attribute__((__format__(__printf__, 2, 3)))
120 __attribute__((__noreturn__));
121 int http_error(int, http_req *, const char *)
122 __attribute__((__noreturn__));
124 int check_special_files(http_req *, const char *);
125 char *http_date(void);
126 void print_header(http_req *, struct stat *, const char *, const char *);
128 char *bozodgetln(int, ssize_t *, ssize_t (*)(int, void *, size_t));
129 char *bozostrnsep(char **, const char *, ssize_t *);
131 void *bozomalloc(size_t);
132 void *bozorealloc(void *, size_t);
133 char *bozostrdup(const char *);
135 extern const char *Iflag;
136 extern int Iflag_set;
137 extern int bflag, fflag;
138 extern char *slashdir;
139 extern const char http_09[];
140 extern const char http_10[];
141 extern const char http_11[];
142 extern const char text_plain[];
144 /* bozotic io */
145 extern int (*bozoprintf)(const char *, ...);
146 extern ssize_t (*bozoread)(int, void *, size_t);
147 extern ssize_t (*bozowrite)(int, const void *, size_t);
148 extern int (*bozoflush)(FILE *);
151 /* ssl-bozo.c */
152 #ifndef NO_SSL_SUPPORT
153 extern void ssl_set_opts(char *, char *);
154 extern void ssl_init(void);
155 extern void ssl_accept(void);
156 extern void ssl_destroy(void);
157 #else
158 #define ssl_set_opts(x, y) /* nothing */
159 #define ssl_init() /* nothing */
160 #define ssl_accept() /* nothing */
161 #define ssl_destroy() /* nothing */
162 #endif
165 /* auth-bozo.c */
166 #ifdef DO_HTPASSWD
167 extern int auth_check(http_req *, const char *);
168 extern void auth_cleanup(http_req *);
169 extern int auth_check_headers(http_req *, char *, char *, ssize_t);
170 extern int auth_check_special_files(http_req *, const char *);
171 extern void auth_check_401(http_req *, int);
172 extern void auth_cgi_setenv(http_req *, char ***);
173 extern int auth_cgi_count(http_req *);
174 #else
175 #define auth_check(x, y) 0
176 #define auth_cleanup(x) /* nothing */
177 #define auth_check_headers(x, y, z, a) 0
178 #define auth_check_special_files(x, y) 0
179 #define auth_check_401(x, y) /* nothing */
180 #define auth_cgi_setenv(x, y) /* nothing */
181 #define auth_cgi_count(x) 0
182 #endif /* DO_HTPASSWD */
185 /* cgi-bozo.c */
186 #ifndef NO_CGIBIN_SUPPORT
187 extern void set_cgibin(char *);
188 extern void spsetenv(const char *env, const char *val, char **envp);
189 extern int process_cgi(http_req *);
190 extern void add_content_map_cgi(char *, char *);
191 #else
192 #define process_cgi(r) 0
193 #endif /* NO_CGIBIN_SUPPORT */
196 /* daemon-bozo.c */
197 extern const char *Iflag;
198 extern int Iflag_set;
199 #ifndef NO_DAEMON_MODE
200 extern char *iflag;
202 extern void daemon_init(void);
203 extern void daemon_fork(void);
204 extern void daemon_closefds(void);
205 #else
206 #define daemon_init() /* nothing */
207 #define daemon_fork() /* nothing */
208 #define daemon_closefds() /* nothing */
209 #endif /* NO_DAEMON_MODE */
212 /* tilde-luzah-bozo.c */
213 #ifndef NO_USER_SUPPORT
214 extern int uflag;
215 extern const char *public_html;
217 int user_transform(http_req *, int *);
218 #else
219 #define uflag 0
220 #define user_transform(a, b) 0
221 #endif /* NO_USER_SUPPORT */
224 /* dir-index-bozo.c */
225 #ifndef NO_DIRINDEX_SUPPORT
226 extern int Xflag;
227 extern int Hflag;
228 int directory_index(http_req *, const char *, int);
229 #else
230 #define directory_index(a, b, c) 0
231 #endif /* NO_DIRINDEX_SUPPORT */
234 /* content-bozo.c */
235 extern const char *content_type(http_req *, const char *);
236 extern const char *content_encoding(http_req *, const char *);
237 extern struct content_map *match_content_map(const char *, int);
238 extern struct content_map *get_content_map(const char *);
239 #ifndef NO_DYNAMIC_CONTENT
240 void add_content_map_mime(char *, char *, char *, char *);
241 #endif