xref: /openbsd/usr.sbin/httpd/httpd.h (revision 9b7c3dbb)
1 /*	$OpenBSD: httpd.h,v 1.116 2016/09/01 10:59:38 reyk Exp $	*/
2 
3 /*
4  * Copyright (c) 2006 - 2015 Reyk Floeter <reyk@openbsd.org>
5  * Copyright (c) 2006, 2007 Pierre-Yves Ritschard <pyr@openbsd.org>
6  * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org>
7  *
8  * Permission to use, copy, modify, and distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  */
20 
21 #ifndef _HTTPD_H
22 #define _HTTPD_H
23 
24 #include <sys/types.h>
25 #include <sys/socket.h>
26 #include <sys/queue.h>
27 #include <sys/tree.h>
28 #include <sys/time.h>
29 
30 #include <net/if.h>
31 
32 #include <stdarg.h>
33 #include <limits.h>
34 #include <event.h>
35 #include <imsg.h>
36 #include <tls.h>
37 #include <vis.h>
38 
39 #include "patterns.h"
40 
41 #ifndef nitems
42 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
43 #endif
44 
45 #define CONF_FILE		"/etc/httpd.conf"
46 #define HTTPD_SOCKET		"/var/run/httpd.sock"
47 #define HTTPD_USER		"www"
48 #define HTTPD_SERVERNAME	"OpenBSD httpd"
49 #define HTTPD_DOCROOT		"/htdocs"
50 #define HTTPD_INDEX		"index.html"
51 #define HTTPD_FCGI_SOCKET	"/run/slowcgi.sock"
52 #define HTTPD_LOGROOT		"/logs"
53 #define HTTPD_ACCESS_LOG	"access.log"
54 #define HTTPD_ERROR_LOG		"error.log"
55 #define HTTPD_DEFAULT_TYPE	{ "bin", "application", "octet-stream", NULL }
56 #define HTTPD_LOGVIS		VIS_NL|VIS_TAB|VIS_CSTYLE
57 #define HTTPD_TLS_CERT		"/etc/ssl/server.crt"
58 #define HTTPD_TLS_KEY		"/etc/ssl/private/server.key"
59 #define HTTPD_TLS_CIPHERS	"compat"
60 #define HTTPD_TLS_DHE_PARAMS	"none"
61 #define HTTPD_TLS_ECDHE_CURVE	"auto"
62 #define FD_RESERVE		5
63 
64 #define SERVER_MAX_CLIENTS	1024
65 #define SERVER_TIMEOUT		600
66 #define SERVER_CACHESIZE	-1	/* use default size */
67 #define SERVER_NUMPROC		3
68 #define SERVER_MAXPROC		32
69 #define SERVER_MAXHEADERLENGTH	8192
70 #define SERVER_MAXREQUESTS	100	/* max requests per connection */
71 #define SERVER_MAXREQUESTBODY	1048576	/* 1M */
72 #define SERVER_BACKLOG		10
73 #define SERVER_OUTOF_FD_RETRIES	5
74 #define SERVER_MAX_PREFETCH	256
75 #define SERVER_MIN_PREFETCHED	32
76 #define SERVER_HSTS_DEFAULT_AGE	31536000
77 
78 #define MEDIATYPE_NAMEMAX	128	/* file name extension */
79 #define MEDIATYPE_TYPEMAX	64	/* length of type/subtype */
80 
81 #define CONFIG_RELOAD		0x00
82 #define CONFIG_MEDIA		0x01
83 #define CONFIG_SERVERS		0x02
84 #define CONFIG_AUTH		0x04
85 #define CONFIG_ALL		0xff
86 
87 #define FCGI_CONTENT_SIZE	65535
88 
89 enum httpchunk {
90 	TOREAD_UNLIMITED		= -1,
91 	TOREAD_HTTP_HEADER		= -2,
92 	TOREAD_HTTP_CHUNK_LENGTH	= -3,
93 	TOREAD_HTTP_CHUNK_TRAILER	= -4,
94 	TOREAD_HTTP_NONE		= -5
95 };
96 
97 #if DEBUG
98 #define DPRINTF		log_debug
99 #else
100 #define DPRINTF(x...)	do {} while(0)
101 #endif
102 
103 struct ctl_flags {
104 	uint8_t		 cf_opts;
105 	uint32_t	 cf_flags;
106 };
107 
108 enum key_type {
109 	KEY_TYPE_NONE		= 0,
110 	KEY_TYPE_COOKIE,
111 	KEY_TYPE_HEADER,
112 	KEY_TYPE_PATH,
113 	KEY_TYPE_QUERY,
114 	KEY_TYPE_URL,
115 	KEY_TYPE_MAX
116 };
117 
118 TAILQ_HEAD(kvlist, kv);
119 RB_HEAD(kvtree, kv);
120 
121 struct kv {
122 	char			*kv_key;
123 	char			*kv_value;
124 
125 	enum key_type		 kv_type;
126 
127 #define KV_FLAG_INVALID		 0x01
128 #define KV_FLAG_GLOBBING	 0x02
129 	uint8_t			 kv_flags;
130 
131 	struct kvlist		 kv_children;
132 	struct kv		*kv_parent;
133 	TAILQ_ENTRY(kv)		 kv_entry;
134 
135 	RB_ENTRY(kv)		 kv_node;
136 };
137 
138 struct portrange {
139 	in_port_t		 val[2];
140 	uint8_t			 op;
141 };
142 
143 struct address {
144 	struct sockaddr_storage	 ss;
145 	int			 ipproto;
146 	int			 prefixlen;
147 	struct portrange	 port;
148 	char			 ifname[IFNAMSIZ];
149 	TAILQ_ENTRY(address)	 entry;
150 };
151 TAILQ_HEAD(addresslist, address);
152 
153 /* initially control.h */
154 struct control_sock {
155 	const char	*cs_name;
156 	struct event	 cs_ev;
157 	struct event	 cs_evt;
158 	int		 cs_fd;
159 	int		 cs_restricted;
160 	void		*cs_env;
161 
162 	TAILQ_ENTRY(control_sock) cs_entry;
163 };
164 TAILQ_HEAD(control_socks, control_sock);
165 
166 struct {
167 	struct event	 ev;
168 	int		 fd;
169 } control_state;
170 
171 struct imsgev {
172 	struct imsgbuf		 ibuf;
173 	void			(*handler)(int, short, void *);
174 	struct event		 ev;
175 	struct privsep_proc	*proc;
176 	void			*data;
177 	short			 events;
178 };
179 
180 #define IMSG_SIZE_CHECK(imsg, p) do {				\
181 	if (IMSG_DATA_SIZE(imsg) < sizeof(*p))			\
182 		fatalx("bad length imsg received");		\
183 } while (0)
184 #define IMSG_DATA_SIZE(imsg)	((imsg)->hdr.len - IMSG_HEADER_SIZE)
185 
186 struct ctl_conn {
187 	TAILQ_ENTRY(ctl_conn)	 entry;
188 	uint8_t			 flags;
189 	unsigned int		 waiting;
190 #define CTL_CONN_NOTIFY		 0x01
191 	struct imsgev		 iev;
192 
193 };
194 TAILQ_HEAD(ctl_connlist, ctl_conn);
195 
196 enum imsg_type {
197 	IMSG_NONE,
198 	IMSG_CTL_OK,
199 	IMSG_CTL_FAIL,
200 	IMSG_CTL_VERBOSE,
201 	IMSG_CTL_PROCFD,
202 	IMSG_CTL_RESET,
203 	IMSG_CTL_SHUTDOWN,
204 	IMSG_CTL_RELOAD,
205 	IMSG_CTL_NOTIFY,
206 	IMSG_CTL_END,
207 	IMSG_CTL_START,
208 	IMSG_CTL_REOPEN,
209 	IMSG_CFG_SERVER,
210 	IMSG_CFG_TLS,
211 	IMSG_CFG_MEDIA,
212 	IMSG_CFG_AUTH,
213 	IMSG_CFG_DONE,
214 	IMSG_LOG_ACCESS,
215 	IMSG_LOG_ERROR,
216 	IMSG_LOG_OPEN
217 };
218 
219 enum privsep_procid {
220 	PROC_ALL	= -1,
221 	PROC_PARENT	= 0,
222 	PROC_SERVER,
223 	PROC_LOGGER,
224 	PROC_MAX
225 } privsep_process;
226 
227 /* Attach the control socket to the following process */
228 #define PROC_CONTROL	PROC_LOGGER
229 
230 /* Define default parent socket number */
231 #define PARENT_SOCK_FILENO	3
232 
233 #define PROC_MAX_INSTANCES	128
234 
235 struct privsep_pipes {
236 	int				*pp_pipes[PROC_MAX];
237 };
238 
239 struct privsep {
240 	struct privsep_pipes		*ps_pipes[PROC_MAX];
241 	struct privsep_pipes		*ps_pp;
242 
243 	struct imsgev			*ps_ievs[PROC_MAX];
244 	const char			*ps_title[PROC_MAX];
245 	uint8_t				 ps_what[PROC_MAX];
246 
247 	unsigned int			 ps_instances[PROC_MAX];
248 	unsigned int			 ps_instance;
249 
250 	struct control_sock		 ps_csock;
251 	struct control_socks		 ps_rcsocks;
252 
253 	/* Event and signal handlers */
254 	struct event			 ps_evsigint;
255 	struct event			 ps_evsigterm;
256 	struct event			 ps_evsigchld;
257 	struct event			 ps_evsighup;
258 	struct event			 ps_evsigpipe;
259 	struct event			 ps_evsigusr1;
260 
261 	int				 ps_noaction;
262 	struct passwd			*ps_pw;
263 	struct httpd			*ps_env;
264 };
265 
266 struct privsep_proc {
267 	const char		*p_title;
268 	enum privsep_procid	 p_id;
269 	int			(*p_cb)(int, struct privsep_proc *,
270 				    struct imsg *);
271 	void			(*p_init)(struct privsep *,
272 				    struct privsep_proc *);
273 	void			(*p_shutdown)(void);
274 	const char		*p_chroot;
275 	struct privsep		*p_ps;
276 	struct httpd		*p_env;
277 };
278 
279 struct privsep_fd {
280 	enum privsep_procid		 pf_procid;
281 	unsigned int			 pf_instance;
282 };
283 
284 enum fcgistate {
285 	FCGI_READ_HEADER,
286 	FCGI_READ_CONTENT,
287 	FCGI_READ_PADDING
288 };
289 
290 struct client {
291 	uint32_t		 clt_id;
292 	pid_t			 clt_pid;
293 	void			*clt_srv;
294 	void			*clt_srv_conf;
295 	uint32_t		 clt_srv_id;
296 	struct sockaddr_storage	 clt_srv_ss;
297 	struct str_match	 clt_srv_match;
298 
299 	int			 clt_s;
300 	in_port_t		 clt_port;
301 	struct sockaddr_storage	 clt_ss;
302 	struct bufferevent	*clt_bev;
303 	struct evbuffer		*clt_output;
304 	struct event		 clt_ev;
305 	void			*clt_descreq;
306 	void			*clt_descresp;
307 	int			 clt_sndbufsiz;
308 
309 	int			 clt_fd;
310 	struct tls		*clt_tls_ctx;
311 	struct bufferevent	*clt_srvbev;
312 	int			 clt_srvbev_throttled;
313 
314 	off_t			 clt_toread;
315 	size_t			 clt_headerlen;
316 	unsigned int		 clt_persist;
317 	int			 clt_line;
318 	int			 clt_done;
319 	int			 clt_chunk;
320 	int			 clt_inflight;
321 	enum fcgistate		 clt_fcgi_state;
322 	int			 clt_fcgi_toread;
323 	int			 clt_fcgi_padding_len;
324 	int			 clt_fcgi_type;
325 	int			 clt_fcgi_chunked;
326 	int			 clt_fcgi_end;
327 	int			 clt_fcgi_status;
328 	int			 clt_fcgi_headersdone;
329 	char			*clt_remote_user;
330 	struct evbuffer		*clt_srvevb;
331 
332 	struct evbuffer		*clt_log;
333 	struct timeval		 clt_timeout;
334 	struct timeval		 clt_tv_start;
335 	struct timeval		 clt_tv_last;
336 	struct event		 clt_inflightevt;
337 
338 	SPLAY_ENTRY(client)	 clt_nodes;
339 };
340 SPLAY_HEAD(client_tree, client);
341 
342 #define SRVFLAG_INDEX		0x00000001
343 #define SRVFLAG_NO_INDEX	0x00000002
344 #define SRVFLAG_AUTO_INDEX	0x00000004
345 #define SRVFLAG_NO_AUTO_INDEX	0x00000008
346 #define SRVFLAG_ROOT		0x00000010
347 #define SRVFLAG_LOCATION	0x00000020
348 #define SRVFLAG_FCGI		0x00000040
349 #define SRVFLAG_NO_FCGI		0x00000080
350 #define SRVFLAG_LOG		0x00000100
351 #define SRVFLAG_NO_LOG		0x00000200
352 #define SRVFLAG_SOCKET		0x00000400
353 #define SRVFLAG_SYSLOG		0x00000800
354 #define SRVFLAG_NO_SYSLOG	0x00001000
355 #define SRVFLAG_TLS		0x00002000
356 #define SRVFLAG_ACCESS_LOG	0x00004000
357 #define SRVFLAG_ERROR_LOG	0x00008000
358 #define SRVFLAG_AUTH		0x00010000
359 #define SRVFLAG_NO_AUTH		0x00020000
360 #define SRVFLAG_BLOCK		0x00040000
361 #define SRVFLAG_NO_BLOCK	0x00080000
362 #define SRVFLAG_LOCATION_MATCH	0x00100000
363 #define SRVFLAG_SERVER_MATCH	0x00200000
364 #define SRVFLAG_SERVER_HSTS	0x00400000
365 #define SRVFLAG_DEFAULT_TYPE	0x00800000
366 
367 #define SRVFLAG_BITS							\
368 	"\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX"		\
369 	"\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG\13SOCKET"	\
370 	"\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG"		\
371 	"\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH"		\
372 	"\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE"
373 
374 #define TCPFLAG_NODELAY		0x01
375 #define TCPFLAG_NNODELAY	0x02
376 #define TCPFLAG_SACK		0x04
377 #define TCPFLAG_NSACK		0x08
378 #define TCPFLAG_BUFSIZ		0x10
379 #define TCPFLAG_IPTTL		0x20
380 #define TCPFLAG_IPMINTTL	0x40
381 #define TCPFLAG_NSPLICE		0x80
382 #define TCPFLAG_DEFAULT		0x00
383 
384 #define TCPFLAG_BITS						\
385 	"\10\01NODELAY\02NO_NODELAY\03SACK\04NO_SACK"		\
386 	"\05SOCKET_BUFFER_SIZE\06IP_TTL\07IP_MINTTL\10NO_SPLICE"
387 
388 #define HSTSFLAG_SUBDOMAINS	0x01
389 #define HSTSFLAG_PRELOAD	0x02
390 #define HSTSFLAG_BITS		"\10\01SUBDOMAINS\02PRELOAD"
391 
392 enum log_format {
393 	LOG_FORMAT_COMMON,
394 	LOG_FORMAT_COMBINED,
395 	LOG_FORMAT_CONNECTION
396 };
397 
398 struct log_file {
399 	char			log_name[NAME_MAX];
400 	int			log_fd;
401 	uint32_t		log_id;
402 	TAILQ_ENTRY(log_file)	log_entry;
403 };
404 TAILQ_HEAD(log_files, log_file) log_files;
405 
406 struct media_type {
407 	char			 media_name[MEDIATYPE_NAMEMAX];
408 	char			 media_type[MEDIATYPE_TYPEMAX];
409 	char			 media_subtype[MEDIATYPE_TYPEMAX];
410 	char			*media_encoding;
411 	RB_ENTRY(media_type)	 media_entry;
412 };
413 RB_HEAD(mediatypes, media_type);
414 
415 struct auth {
416 	char			 auth_htpasswd[PATH_MAX];
417 	uint32_t		 auth_id;
418 	TAILQ_ENTRY(auth)	 auth_entry;
419 };
420 TAILQ_HEAD(serverauth, auth);
421 
422 struct server_config {
423 	uint32_t		 id;
424 	uint32_t		 parent_id;
425 	char			 name[HOST_NAME_MAX+1];
426 	char			 location[NAME_MAX];
427 	char			 index[NAME_MAX];
428 	char			 root[PATH_MAX];
429 	char			 socket[PATH_MAX];
430 	char			 accesslog[NAME_MAX];
431 	char			 errorlog[NAME_MAX];
432 	struct media_type	 default_type;
433 
434 	in_port_t		 port;
435 	struct sockaddr_storage	 ss;
436 	int			 prefixlen;
437 	struct timeval		 timeout;
438 	uint32_t		 maxrequests;
439 	size_t			 maxrequestbody;
440 
441 	uint8_t			*tls_cert;
442 	size_t			 tls_cert_len;
443 	char			*tls_cert_file;
444 	char			 tls_ciphers[NAME_MAX];
445 	char			 tls_dhe_params[NAME_MAX];
446 	char			 tls_ecdhe_curve[NAME_MAX];
447 	uint8_t			*tls_key;
448 	size_t			 tls_key_len;
449 	char			*tls_key_file;
450 	uint32_t		 tls_protocols;
451 
452 	uint32_t		 flags;
453 	int			 strip;
454 	uint8_t			 tcpflags;
455 	int			 tcpbufsiz;
456 	int			 tcpbacklog;
457 	uint8_t			 tcpipttl;
458 	uint8_t			 tcpipminttl;
459 
460 	enum log_format		 logformat;
461 	struct log_file		*logaccess;
462 	struct log_file		*logerror;
463 
464 	char			 auth_realm[NAME_MAX];
465 	uint32_t		 auth_id;
466 	const struct auth	*auth;
467 
468 	int			 return_code;
469 	char			*return_uri;
470 	off_t			 return_uri_len;
471 
472 	int			 hsts_max_age;
473 	uint8_t			 hsts_flags;
474 
475 	TAILQ_ENTRY(server_config) entry;
476 };
477 TAILQ_HEAD(serverhosts, server_config);
478 
479 struct tls_config {
480 	uint32_t		 id;
481 
482 	size_t			 tls_cert_len;
483 	size_t			 tls_key_len;
484 };
485 
486 struct server {
487 	TAILQ_ENTRY(server)	 srv_entry;
488 	struct server_config	 srv_conf;
489 	struct serverhosts	 srv_hosts;
490 
491 	int			 srv_s;
492 	struct event		 srv_ev;
493 	struct event		 srv_evt;
494 
495 	struct tls		 *srv_tls_ctx;
496 	struct tls_config	 *srv_tls_config;
497 
498 	struct client_tree	 srv_clients;
499 };
500 TAILQ_HEAD(serverlist, server);
501 
502 struct httpd {
503 	uint8_t			 sc_opts;
504 	uint32_t		 sc_flags;
505 	const char		*sc_conffile;
506 	struct event		 sc_ev;
507 	uint16_t		 sc_prefork_server;
508 	uint16_t		 sc_id;
509 	int			 sc_paused;
510 	char			*sc_chroot;
511 	char			*sc_logdir;
512 
513 	struct serverlist	*sc_servers;
514 	struct mediatypes	*sc_mediatypes;
515 	struct media_type	 sc_default_type;
516 	struct serverauth	*sc_auth;
517 
518 	struct privsep		*sc_ps;
519 	int			 sc_reload;
520 };
521 
522 #define HTTPD_OPT_VERBOSE		0x01
523 #define HTTPD_OPT_NOACTION		0x04
524 
525 /* control.c */
526 int	 control_init(struct privsep *, struct control_sock *);
527 int	 control_listen(struct control_sock *);
528 void	 control_cleanup(struct control_sock *);
529 void	 control_dispatch_imsg(int, short, void *);
530 void	 control_imsg_forward(struct privsep *, struct imsg *);
531 struct ctl_conn	*
532 	 control_connbyfd(int);
533 
534 extern  struct ctl_connlist ctl_conns;
535 
536 /* parse.y */
537 int	 parse_config(const char *, struct httpd *);
538 int	 load_config(const char *, struct httpd *);
539 int	 cmdline_symset(char *);
540 
541 /* server.c */
542 void	 server(struct privsep *, struct privsep_proc *);
543 int	 server_tls_cmp(struct server *, struct server *, int);
544 int	 server_tls_load_keypair(struct server *);
545 int	 server_privinit(struct server *);
546 void	 server_purge(struct server *);
547 void	 serverconfig_free(struct server_config *);
548 void	 serverconfig_reset(struct server_config *);
549 int	 server_socket_af(struct sockaddr_storage *, in_port_t);
550 in_port_t
551 	 server_socket_getport(struct sockaddr_storage *);
552 int	 server_socket_connect(struct sockaddr_storage *, in_port_t,
553 	    struct server_config *);
554 void	 server_write(struct bufferevent *, void *);
555 void	 server_read(struct bufferevent *, void *);
556 void	 server_error(struct bufferevent *, short, void *);
557 void	 server_log(struct client *, const char *);
558 void	 server_sendlog(struct server_config *, int, const char *, ...)
559 	    __attribute__((__format__ (printf, 3, 4)));
560 void	 server_close(struct client *, const char *);
561 void	 server_dump(struct client *, const void *, size_t);
562 int	 server_client_cmp(struct client *, struct client *);
563 int	 server_bufferevent_printf(struct client *, const char *, ...)
564 	    __attribute__((__format__ (printf, 2, 3)));
565 int	 server_bufferevent_print(struct client *, const char *);
566 int	 server_bufferevent_write_buffer(struct client *,
567 	    struct evbuffer *);
568 int	 server_bufferevent_write_chunk(struct client *,
569 	    struct evbuffer *, size_t);
570 int	 server_bufferevent_add(struct event *, int);
571 int	 server_bufferevent_write(struct client *, void *, size_t);
572 struct server *
573 	 server_byaddr(struct sockaddr *, in_port_t);
574 struct server_config *
575 	 serverconfig_byid(uint32_t);
576 int	 server_foreach(int (*)(struct server *,
577 	    struct server_config *, void *), void *);
578 struct server *
579 	 server_match(struct server *, int);
580 
581 SPLAY_PROTOTYPE(client_tree, client, clt_nodes, server_client_cmp);
582 
583 /* server_http.c */
584 void	 server_http_init(struct server *);
585 void	 server_http(void);
586 int	 server_httpdesc_init(struct client *);
587 void	 server_read_http(struct bufferevent *, void *);
588 void	 server_abort_http(struct client *, unsigned int, const char *);
589 unsigned int
590 	 server_httpmethod_byname(const char *);
591 const char
592 	*server_httpmethod_byid(unsigned int);
593 const char
594 	*server_httperror_byid(unsigned int);
595 void	 server_read_httpcontent(struct bufferevent *, void *);
596 void	 server_read_httpchunks(struct bufferevent *, void *);
597 int	 server_writeheader_http(struct client *clt, struct kv *, void *);
598 int	 server_headers(struct client *, void *,
599 	    int (*)(struct client *, struct kv *, void *), void *);
600 int	 server_writeresponse_http(struct client *);
601 int	 server_response_http(struct client *, unsigned int, struct media_type *,
602 	    off_t, time_t);
603 void	 server_reset_http(struct client *);
604 void	 server_close_http(struct client *);
605 int	 server_response(struct httpd *, struct client *);
606 const char *
607 	 server_root_strip(const char *, int);
608 struct server_config *
609 	 server_getlocation(struct client *, const char *);
610 const char *
611 	 server_http_host(struct sockaddr_storage *, char *, size_t);
612 char	*server_http_parsehost(char *, char *, size_t, int *);
613 ssize_t	 server_http_time(time_t, char *, size_t);
614 int	 server_log_http(struct client *, unsigned int, size_t);
615 
616 /* server_file.c */
617 int	 server_file(struct httpd *, struct client *);
618 void	 server_file_error(struct bufferevent *, short, void *);
619 
620 /* server_fcgi.c */
621 int	 server_fcgi(struct httpd *, struct client *);
622 int	 fcgi_add_stdin(struct client *, struct evbuffer *);
623 
624 /* httpd.c */
625 void		 event_again(struct event *, int, short,
626 		    void (*)(int, short, void *),
627 		    struct timeval *, struct timeval *, void *);
628 int		 expand_string(char *, size_t, const char *, const char *);
629 const char	*url_decode(char *);
630 char		*url_encode(const char *);
631 const char	*canonicalize_host(const char *, char *, size_t);
632 const char	*canonicalize_path(const char *, char *, size_t);
633 size_t		 path_info(char *);
634 char		*escape_html(const char *);
635 void		 socket_rlimit(int);
636 char		*evbuffer_getline(struct evbuffer *);
637 char		*get_string(uint8_t *, size_t);
638 void		*get_data(uint8_t *, size_t);
639 int		 sockaddr_cmp(struct sockaddr *, struct sockaddr *, int);
640 struct in6_addr *prefixlen2mask6(uint8_t, uint32_t *);
641 uint32_t	 prefixlen2mask(uint8_t);
642 int		 accept_reserve(int, struct sockaddr *, socklen_t *, int,
643 		    volatile int *);
644 struct kv	*kv_add(struct kvtree *, char *, char *);
645 int		 kv_set(struct kv *, char *, ...)
646 		    __attribute__((__format__ (printf, 2, 3)));
647 int		 kv_setkey(struct kv *, char *, ...)
648 		    __attribute__((__format__ (printf, 2, 3)));
649 void		 kv_delete(struct kvtree *, struct kv *);
650 struct kv	*kv_extend(struct kvtree *, struct kv *, char *);
651 void		 kv_purge(struct kvtree *);
652 void		 kv_free(struct kv *);
653 struct kv	*kv_inherit(struct kv *, struct kv *);
654 int		 kv_log(struct evbuffer *, struct kv *);
655 struct kv	*kv_find(struct kvtree *, struct kv *);
656 int		 kv_cmp(struct kv *, struct kv *);
657 struct media_type
658 		*media_add(struct mediatypes *, struct media_type *);
659 void		 media_delete(struct mediatypes *, struct media_type *);
660 void		 media_purge(struct mediatypes *);
661 struct media_type *
662 		 media_find(struct mediatypes *, const char *);
663 struct media_type *
664 		 media_find_config(struct httpd *, struct server_config *,
665 		    const char *);
666 int		 media_cmp(struct media_type *, struct media_type *);
667 RB_PROTOTYPE(kvtree, kv, kv_node, kv_cmp);
668 RB_PROTOTYPE(mediatypes, media_type, media_entry, media_cmp);
669 struct auth	*auth_add(struct serverauth *, struct auth *);
670 struct auth	*auth_byid(struct serverauth *, uint32_t);
671 void		 auth_free(struct serverauth *, struct auth *);
672 const char	*print_host(struct sockaddr_storage *, char *, size_t);
673 const char	*print_time(struct timeval *, struct timeval *, char *, size_t);
674 const char	*printb_flags(const uint32_t, const char *);
675 void		 getmonotime(struct timeval *);
676 
677 extern struct httpd *httpd_env;
678 
679 /* log.c */
680 void	log_init(int, int);
681 void	log_procinit(const char *);
682 void	log_verbose(int);
683 void	log_warn(const char *, ...)
684 	    __attribute__((__format__ (printf, 1, 2)));
685 void	log_warnx(const char *, ...)
686 	    __attribute__((__format__ (printf, 1, 2)));
687 void	log_info(const char *, ...)
688 	    __attribute__((__format__ (printf, 1, 2)));
689 void	log_debug(const char *, ...)
690 	    __attribute__((__format__ (printf, 1, 2)));
691 void	logit(int, const char *, ...)
692 	    __attribute__((__format__ (printf, 2, 3)));
693 void	vlog(int, const char *, va_list)
694 	    __attribute__((__format__ (printf, 2, 0)));
695 __dead void fatal(const char *, ...)
696 	    __attribute__((__format__ (printf, 1, 2)));
697 __dead void fatalx(const char *, ...)
698 	    __attribute__((__format__ (printf, 1, 2)));
699 
700 /* proc.c */
701 enum privsep_procid
702 	    proc_getid(struct privsep_proc *, unsigned int, const char *);
703 void	 proc_init(struct privsep *, struct privsep_proc *, unsigned int,
704 	    int, char **);
705 void	 proc_kill(struct privsep *);
706 void	 proc_connect(struct privsep *);
707 void	 proc_dispatch(int, short event, void *);
708 void	 proc_run(struct privsep *, struct privsep_proc *,
709 	    struct privsep_proc *, unsigned int,
710 	    void (*)(struct privsep *, struct privsep_proc *, void *), void *);
711 void	 proc_range(struct privsep *, enum privsep_procid, int *, int *);
712 int	 proc_compose_imsg(struct privsep *, enum privsep_procid, int,
713 	    u_int16_t, u_int32_t, int, void *, u_int16_t);
714 int	 proc_compose(struct privsep *, enum privsep_procid,
715 	    uint16_t, void *, uint16_t);
716 int	 proc_composev_imsg(struct privsep *, enum privsep_procid, int,
717 	    u_int16_t, u_int32_t, int, const struct iovec *, int);
718 int	 proc_composev(struct privsep *, enum privsep_procid,
719 	    uint16_t, const struct iovec *, int);
720 int	 proc_forward_imsg(struct privsep *, struct imsg *,
721 	    enum privsep_procid, int);
722 struct imsgbuf *
723 	 proc_ibuf(struct privsep *, enum privsep_procid, int);
724 struct imsgev *
725 	 proc_iev(struct privsep *, enum privsep_procid, int);
726 void	 imsg_event_add(struct imsgev *);
727 int	 imsg_compose_event(struct imsgev *, uint16_t, uint32_t,
728 	    pid_t, int, void *, uint16_t);
729 int	 imsg_composev_event(struct imsgev *, uint16_t, uint32_t,
730 	    pid_t, int, const struct iovec *, int);
731 
732 /* config.c */
733 int	 config_init(struct httpd *);
734 void	 config_purge(struct httpd *, unsigned int);
735 int	 config_setreset(struct httpd *, unsigned int);
736 int	 config_getreset(struct httpd *, struct imsg *);
737 int	 config_getcfg(struct httpd *, struct imsg *);
738 int	 config_setserver(struct httpd *, struct server *);
739 int	 config_settls(struct httpd *, struct server *);
740 int	 config_getserver(struct httpd *, struct imsg *);
741 int	 config_gettls(struct httpd *, struct imsg *);
742 int	 config_setmedia(struct httpd *, struct media_type *);
743 int	 config_getmedia(struct httpd *, struct imsg *);
744 int	 config_setauth(struct httpd *, struct auth *);
745 int	 config_getauth(struct httpd *, struct imsg *);
746 
747 /* logger.c */
748 void	 logger(struct privsep *, struct privsep_proc *);
749 int	 logger_open_priv(struct imsg *);
750 
751 #endif /* _HTTPD_H */
752