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