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