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