Home | History | Annotate | Line # | Download | only in httpd
bozohttpd.h revision 1.7
      1 /*	$NetBSD: bozohttpd.h,v 1.7 2009/02/09 17:06:11 joerg Exp $	*/
      2 
      3 /*	$eterna: bozohttpd.h,v 1.18 2008/03/03 03:36:11 mrg Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1997-2008 Matthew R. Green
      7  * All rights reserved.
      8  *
      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.
     18  * 3. The name of the author may not be used to endorse or promote products
     19  *    derived from this software without specific prior written permission.
     20  *
     21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     28  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     29  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     31  * SUCH DAMAGE.
     32  *
     33  */
     34 #include <sys/queue.h>
     35 #include <sys/stat.h>
     36 
     37 #include <stdio.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_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;
     82 
     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 */
     89 };
     90 
     91 #define WRSZ	(64 * 1024)
     92 
     93 /* debug flags */
     94 #define DEBUG_NORMAL	1
     95 #define DEBUG_FAT	2
     96 #define DEBUG_OBESE	3
     97 #define DEBUG_EXPLODING	4
     98 
     99 #define	strornull(x)	((x) ? (x) : "<null>")
    100 
    101 extern	int	dflag;
    102 extern	const char *index_html;
    103 extern	const char *server_software;
    104 extern	char	*myname;
    105 
    106 #ifdef DEBUG
    107 void	debug__(int, const char *, ...)
    108 			__attribute__((__format__(__printf__, 2, 3)));
    109 #define debug(x)	debug__ x
    110 #else
    111 #define	debug(x)
    112 #endif /* DEBUG */
    113 
    114 void	warning(const char *, ...)
    115 		__attribute__((__format__(__printf__, 1, 2)));
    116 void	error(int, const char *, ...)
    117 		__attribute__((__format__(__printf__, 2, 3)));
    118 void	http_error(int, http_req *, const char *)
    119 		__attribute__((__noreturn__));
    120 
    121 void	check_special_files(http_req *, const char *);
    122 char	*http_date(void);
    123 void	print_header(http_req *, struct stat *, const char *, const char *);
    124 
    125 char	*bozodgetln(int, ssize_t *, ssize_t	(*)(int, void *, size_t));
    126 char	*bozostrnsep(char **, const char *, ssize_t *);
    127 
    128 void	*bozomalloc(size_t);
    129 void	*bozorealloc(void *, size_t);
    130 char	*bozostrdup(const char *);
    131 
    132 extern	const char *Iflag;
    133 extern	int	Iflag_set;
    134 extern	int	bflag, fflag;
    135 extern	char	*slashdir;
    136 extern	const char http_09[];
    137 extern	const char http_10[];
    138 extern	const char http_11[];
    139 extern	const char text_plain[];
    140 
    141 /* bozotic io */
    142 extern	int	(*bozoprintf)(const char *, ...);
    143 extern	ssize_t	(*bozoread)(int, void *, size_t);
    144 extern	ssize_t	(*bozowrite)(int, const void *, size_t);
    145 extern	int	(*bozoflush)(FILE *);
    146 
    147 
    148 /* ssl-bozo.c */
    149 #ifndef NO_SSL_SUPPORT
    150 extern	void	ssl_set_opts(char *, char *);
    151 extern	void	ssl_init(void);
    152 extern	void	ssl_accept(void);
    153 extern	void	ssl_destroy(void);
    154 #else
    155 #define ssl_set_opts(x, y)	/* nothing */
    156 #define ssl_init()		/* nothing */
    157 #define ssl_accept()		/* nothing */
    158 #define ssl_destroy()		/* nothing */
    159 #endif
    160 
    161 
    162 /* auth-bozo.c */
    163 #ifdef DO_HTPASSWD
    164 extern	void	auth_check(http_req *, const char *);
    165 extern	int	auth_check_headers(http_req *, char *, char *, ssize_t);
    166 extern	void	auth_check_special_files(http_req *, const char *);
    167 extern	void	auth_check_401(http_req *, int);
    168 extern	void	auth_cgi_setenv(http_req *, char ***);
    169 extern	int	auth_cgi_count(http_req *);
    170 #else
    171 #define		auth_check(x, y)		/* nothing */
    172 #define		auth_check_headers(x, y, z, a)	0
    173 #define		auth_check_special_files(x, y)	/* nothing */
    174 #define		auth_check_401(x, y)		/* nothing */
    175 #define		auth_cgi_setenv(x, y)		/* nothing */
    176 #define		auth_cgi_count(x)		0
    177 #endif /* DO_HTPASSWD */
    178 
    179 
    180 /* cgi-bozo.c */
    181 #ifndef NO_CGIBIN_SUPPORT
    182 void	set_cgibin(char *);
    183 void	spsetenv(const char *env, const char *val, char **envp);
    184 void	process_cgi(http_req *);
    185 void	add_content_map_cgi(char *, char *);
    186 #else
    187 #define	process_cgi(r)				/* nothing */
    188 #endif /* NO_CGIBIN_SUPPORT */
    189 
    190 
    191 /* daemon-bozo.c */
    192 extern	const char *Iflag;
    193 extern	int	Iflag_set;
    194 #ifndef NO_DAEMON_MODE
    195 extern	char	*iflag;
    196 
    197 void	daemon_init(void);
    198 void	daemon_fork(void);
    199 #else
    200 #define daemon_init()				/* nothing */
    201 #define daemon_fork()				/* nothing */
    202 #endif /* NO_DAEMON_MODE */
    203 
    204 
    205 /* tilde-luzah-bozo.c */
    206 #ifndef NO_USER_SUPPORT
    207 extern	int	uflag;
    208 extern	const char *public_html;
    209 
    210 char *	user_transform(http_req *, int *);
    211 #endif /* NO_USER_SUPPORT */
    212 
    213 
    214 /* dir-index-bozo.c */
    215 #ifndef NO_DIRINDEX_SUPPORT
    216 extern	int	Xflag;
    217 extern	int	Hflag;
    218 int	directory_index(http_req *, const char *, int);
    219 #else
    220 #define directory_index(a, b, c)		0
    221 #endif /* NO_DIRINDEX_SUPPORT */
    222 
    223 
    224 /* content-bozo.c */
    225 const char *content_type(http_req *, const char *);
    226 const char *content_encoding(http_req *, const char *);
    227 struct content_map *match_content_map(const char *, int);
    228 struct content_map *get_content_map(const char *);
    229 #ifndef NO_DYNAMIC_CONTENT
    230 void	add_content_map_mime(char *, char *, char *, char *);
    231 #endif
    232