Home | History | Annotate | Line # | Download | only in httpd
bozohttpd.h revision 1.4
      1 /*	$NetBSD: bozohttpd.h,v 1.4 2007/11/04 15:20:11 rtr Exp $	*/
      2 
      3 /*	$eterna: bozohttpd.h,v 1.13 2006/05/17 08:19:10 mrg Exp $	*/
      4 
      5 /*
      6  * Copyright (c) 1997-2006 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 #include <stdio.h>
     37 
     38 /* headers */
     39 struct headers {
     40 	/*const*/ char *h_header;
     41 	/*const*/ char *h_value;	/* this gets free()'ed etc at times */
     42 	SIMPLEQ_ENTRY(headers)	h_next;
     43 };
     44 
     45 /* http_req */
     46 typedef struct {
     47 	int	hr_method;
     48 #define	HTTP_GET	0x01
     49 #define HTTP_POST	0x02
     50 #define HTTP_HEAD	0x03
     51 #define HTTP_OPTIONS	0x04	/* not supported */
     52 #define HTTP_PUT	0x05	/* not supported */
     53 #define HTTP_DELETE	0x06	/* not supported */
     54 #define HTTP_TRACE	0x07	/* not supported */
     55 #define HTTP_CONNECT	0x08	/* not supported */
     56 	const char *hr_methodstr;
     57 	char	*hr_url;
     58 	const char *hr_proto;
     59 	const char *hr_content_type;
     60 	const char *hr_content_length;
     61 	const char *hr_allow;
     62 	const char *hr_host;		/* HTTP/1.1 Host: */
     63 	const char *hr_referrer;
     64 	const char *hr_remotehost;
     65 	const char *hr_remoteaddr;
     66 	const char *hr_serverport;
     67 #ifdef DO_HTPASSWD
     68 	const char *hr_authrealm;
     69 	const char *hr_authuser;
     70 	const char *hr_authpass;
     71 #endif
     72 	SIMPLEQ_HEAD(, headers)	hr_headers;
     73 	int	hr_nheaders;
     74 } http_req;
     75 
     76 struct content_map {
     77 	const char *name;	/* postfix of file */
     78 	const char *type;	/* matching content-type */
     79 	const char *encoding;	/* matching content-encoding */
     80 	const char *encoding11;	/* matching content-encoding (HTTP/1.1) */
     81 	const char *cgihandler;	/* optional CGI handler */
     82 };
     83 
     84 #define WRSZ	(64 * 1024)
     85 
     86 /* debug flags */
     87 #define DEBUG_NORMAL	1
     88 #define DEBUG_FAT	2
     89 #define DEBUG_OBESE	3
     90 #define DEBUG_EXPLODING	4
     91 
     92 #define	strornull(x)	((x) ? (x) : "<null>")
     93 
     94 extern	int	dflag;
     95 extern	const char *index_html;
     96 extern	const char *server_software;
     97 extern	char	*myname;
     98 
     99 #ifdef DEBUG
    100 void	debug__(int, const char *, ...)
    101 			__attribute__((__format__(__printf__, 2, 3)));
    102 #define debug(x)	debug__ x
    103 #else
    104 #define	debug(x)
    105 #endif /* DEBUG */
    106 
    107 void	warning(const char *, ...)
    108 		__attribute__((__format__(__printf__, 1, 2)));
    109 void	error(int, const char *, ...)
    110 		__attribute__((__format__(__printf__, 2, 3)));
    111 void	http_error(int, http_req *, const char *);
    112 
    113 void	check_special_files(http_req *, const char *);
    114 char	*http_date(void);
    115 void	print_header(http_req *, struct stat *, const char *, const char *);
    116 
    117 char	*dgetln(int, ssize_t *, ssize_t	(*)(int, void *, size_t));
    118 char	*strnsep(char **, const char *, ssize_t *);
    119 
    120 void	*bozomalloc(size_t);
    121 void	*bozorealloc(void *, size_t);
    122 char	*bozostrdup(const char *);
    123 
    124 extern	const char *Iflag;
    125 extern	int	Iflag_set;
    126 extern	int	bflag, fflag;
    127 extern	char	*slashdir;
    128 extern	const char http_09[];
    129 extern	const char http_10[];
    130 extern	const char http_11[];
    131 extern	const char text_plain[];
    132 
    133 /* bozotic io */
    134 extern	int	(*bozoprintf)(const char *, ...);
    135 extern	ssize_t	(*bozoread)(int, void *, size_t);
    136 extern	ssize_t	(*bozowrite)(int, const void *, size_t);
    137 extern	int	(*bozoflush)(FILE *);
    138 
    139 
    140 /* ssl-bozo.c */
    141 #ifndef NO_SSL_SUPPORT
    142 extern	void	ssl_set_opts(char *, char *);
    143 extern	void	ssl_init(void);
    144 extern	void	ssl_accept(void);
    145 extern	void	ssl_destroy(void);
    146 #else
    147 #define ssl_set_opts(x, y)	/* nothing */
    148 #define ssl_init()		/* nothing */
    149 #define ssl_accept()		/* nothing */
    150 #define ssl_destroy()		/* nothing */
    151 #endif
    152 
    153 
    154 /* auth-bozo.c */
    155 #ifdef DO_HTPASSWD
    156 extern	void	auth_check(http_req *, const char *);
    157 extern	int	auth_check_headers(http_req *, char *, char *, ssize_t);
    158 extern	void	auth_check_special_files(http_req *, const char *);
    159 extern	void	auth_check_401(http_req *, int);
    160 extern	void	auth_cgi_setenv(http_req *, char ***);
    161 extern	int	auth_cgi_count(http_req *);
    162 #else
    163 #define		auth_check(x, y)		/* nothing */
    164 #define		auth_check_headers(x, y, z, a)	0
    165 #define		auth_check_special_files(x, y)	/* nothing */
    166 #define		auth_check_401(x, y)		/* nothing */
    167 #define		auth_cgi_setenv(x, y)		/* nothing */
    168 #define		auth_cgi_count(x)		0
    169 #endif /* DO_HTPASSWD */
    170 
    171 
    172 /* cgi-bozo.c */
    173 #ifndef NO_CGIBIN_SUPPORT
    174 void	set_cgibin(char *);
    175 void	spsetenv(const char *env, const char *val, char **envp);
    176 void	process_cgi(http_req *);
    177 void	add_content_map_cgi(char *, char *);
    178 #else
    179 #define	process_cgi(r)				/* nothing */
    180 #endif /* NO_CGIBIN_SUPPORT */
    181 
    182 
    183 /* daemon-bozo.c */
    184 extern	const char *Iflag;
    185 extern	int	Iflag_set;
    186 #ifndef NO_DAEMON_MODE
    187 extern	char	*iflag;
    188 
    189 void	daemon_init(void);
    190 void	daemon_fork(void);
    191 #else
    192 #define daemon_init()				/* nothing */
    193 #define daemon_fork()				/* nothing */
    194 #endif /* NO_DAEMON_MODE */
    195 
    196 
    197 /* tilde-luzah-bozo.c */
    198 #ifndef NO_USER_SUPPORT
    199 extern	int	uflag;
    200 extern	const char *public_html;
    201 
    202 char *	user_transform(http_req *, int *);
    203 #else
    204 #define user_transform(a, b)			/* nothing */
    205 #endif /* NO_USER_SUPPORT */
    206 
    207 
    208 /* dir-index-bozo.c */
    209 #ifndef NO_DIRINDEX_SUPPORT
    210 extern	int	Xflag;
    211 extern	int	Hflag;
    212 int	directory_index(http_req *, const char *, int);
    213 #else
    214 #define directory_index(a, b, c)		0
    215 #endif /* NO_DIRINDEX_SUPPORT */
    216 
    217 
    218 /* content-bozo.c */
    219 const char *content_type(http_req *, const char *);
    220 const char *content_encoding(http_req *, const char *);
    221 struct content_map *match_content_map(const char *, int);
    222 struct content_map *get_content_map(const char *);
    223 #ifndef NO_DYNAMIC_CONTENT
    224 void	add_content_map_mime(char *, char *, char *, char *);
    225 #endif
    226