1 /* $OpenBSD: httpd.h,v 1.164 2023/11/08 19:19:10 millert 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 #include <netinet/in.h> 32 33 #include <stdarg.h> 34 #include <limits.h> 35 #include <event.h> 36 #include <imsg.h> 37 #include <tls.h> 38 #include <vis.h> 39 40 #include "patterns.h" 41 42 #ifndef nitems 43 #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0])) 44 #endif 45 46 #define CONF_FILE "/etc/httpd.conf" 47 #define HTTPD_USER "www" 48 #define HTTPD_SERVERNAME "OpenBSD httpd" 49 #define HTTPD_DOCROOT "/htdocs" 50 #define HTTPD_ERRDOCTEMPLATE "err" /* 3-char name */ 51 #define HTTPD_ERRDOCROOT_MAX (PATH_MAX - sizeof("000.html")) 52 #define HTTPD_INDEX "index.html" 53 #define HTTPD_FCGI_SOCKET "/run/slowcgi.sock" 54 #define HTTPD_LOGROOT "/logs" 55 #define HTTPD_ACCESS_LOG "access.log" 56 #define HTTPD_ERROR_LOG "error.log" 57 #define HTTPD_MAX_ALIAS_IP 16 58 #define HTTPD_REALM_MAX 255 59 #define HTTPD_LOCATION_MAX 255 60 #define HTTPD_DEFAULT_TYPE { "bin", "application", "octet-stream", NULL } 61 #define HTTPD_LOGVIS VIS_NL|VIS_TAB|VIS_CSTYLE 62 #define HTTPD_TLS_CERT "/etc/ssl/server.crt" 63 #define HTTPD_TLS_KEY "/etc/ssl/private/server.key" 64 #define HTTPD_TLS_CONFIG_MAX 511 65 #define HTTPD_TLS_CIPHERS "compat" 66 #define HTTPD_TLS_DHE_PARAMS "none" 67 #define HTTPD_TLS_ECDHE_CURVES "default" 68 #define HTTPD_FCGI_NAME_MAX 511 69 #define HTTPD_FCGI_VAL_MAX 511 70 #define FD_RESERVE 5 71 72 #define SERVER_MAX_CLIENTS 1024 73 #define SERVER_TIMEOUT 600 74 #define SERVER_REQUESTTIMEOUT 60 75 #define SERVER_CACHESIZE -1 /* use default size */ 76 #define SERVER_NUMPROC 3 77 #define SERVER_MAXHEADERLENGTH 8192 78 #define SERVER_MAXREQUESTS 100 /* max requests per connection */ 79 #define SERVER_MAXREQUESTBODY 1048576 /* 1M */ 80 #define SERVER_BACKLOG 10 81 #define SERVER_OUTOF_FD_RETRIES 5 82 #define SERVER_MAX_PREFETCH 256 83 #define SERVER_MIN_PREFETCHED 32 84 #define SERVER_HSTS_DEFAULT_AGE 31536000 85 #define SERVER_MAX_RANGES 4 86 #define SERVER_DEF_TLS_LIFETIME (2 * 3600) 87 #define SERVER_MIN_TLS_LIFETIME (60) 88 #define SERVER_MAX_TLS_LIFETIME (24 * 3600) 89 90 #define MEDIATYPE_NAMEMAX 128 /* file name extension */ 91 #define MEDIATYPE_TYPEMAX 64 /* length of type/subtype */ 92 93 #define CONFIG_RELOAD 0x00 94 #define CONFIG_MEDIA 0x01 95 #define CONFIG_SERVERS 0x02 96 #define CONFIG_AUTH 0x04 97 #define CONFIG_ALL 0xff 98 99 #define FCGI_CONTENT_SIZE 65535 100 #define FCGI_DEFAULT_PORT "9000" 101 102 #define PROC_PARENT_SOCK_FILENO 3 103 #define PROC_MAX_INSTANCES 32 104 105 enum httpchunk { 106 TOREAD_UNLIMITED = -1, 107 TOREAD_HTTP_HEADER = -2, 108 TOREAD_HTTP_CHUNK_LENGTH = -3, 109 TOREAD_HTTP_CHUNK_TRAILER = -4, 110 TOREAD_HTTP_NONE = -5, 111 TOREAD_HTTP_RANGE = TOREAD_HTTP_CHUNK_LENGTH 112 }; 113 114 #if DEBUG 115 #define DPRINTF log_debug 116 #else 117 #define DPRINTF(x...) do {} while(0) 118 #endif 119 120 struct ctl_flags { 121 uint8_t cf_opts; 122 uint32_t cf_flags; 123 uint8_t cf_tls_sid[TLS_MAX_SESSION_ID_LENGTH]; 124 }; 125 126 TAILQ_HEAD(kvlist, kv); 127 RB_HEAD(kvtree, kv); 128 129 struct kv { 130 char *kv_key; 131 char *kv_value; 132 133 struct kvlist kv_children; 134 struct kv *kv_parent; 135 TAILQ_ENTRY(kv) kv_entry; 136 137 RB_ENTRY(kv) kv_node; 138 }; 139 140 struct portrange { 141 in_port_t val[2]; 142 uint8_t op; 143 }; 144 145 struct address { 146 struct sockaddr_storage ss; 147 int ipproto; 148 int prefixlen; 149 struct portrange port; 150 char ifname[IFNAMSIZ]; 151 TAILQ_ENTRY(address) entry; 152 }; 153 TAILQ_HEAD(addresslist, address); 154 155 /* initially control.h */ 156 struct control_sock { 157 const char *cs_name; 158 struct event cs_ev; 159 struct event cs_evt; 160 int cs_fd; 161 int cs_restricted; 162 void *cs_env; 163 164 TAILQ_ENTRY(control_sock) cs_entry; 165 }; 166 TAILQ_HEAD(control_socks, control_sock); 167 168 extern struct { 169 struct event ev; 170 int fd; 171 } control_state; 172 173 struct imsgev { 174 struct imsgbuf ibuf; 175 void (*handler)(int, short, void *); 176 struct event ev; 177 struct privsep_proc *proc; 178 void *data; 179 short events; 180 }; 181 182 #define IMSG_SIZE_CHECK(imsg, p) do { \ 183 if (IMSG_DATA_SIZE(imsg) < sizeof(*p)) \ 184 fatalx("bad length imsg received"); \ 185 } while (0) 186 #define IMSG_DATA_SIZE(imsg) ((imsg)->hdr.len - IMSG_HEADER_SIZE) 187 #define MAX_IMSG_DATA_SIZE (MAX_IMSGSIZE - IMSG_HEADER_SIZE) 188 189 struct ctl_conn { 190 TAILQ_ENTRY(ctl_conn) entry; 191 uint8_t flags; 192 unsigned int waiting; 193 #define CTL_CONN_NOTIFY 0x01 194 struct imsgev iev; 195 196 }; 197 TAILQ_HEAD(ctl_connlist, ctl_conn); 198 199 enum imsg_type { 200 IMSG_NONE, 201 IMSG_CTL_OK, 202 IMSG_CTL_FAIL, 203 IMSG_CTL_VERBOSE, 204 IMSG_CTL_PROCFD, 205 IMSG_CTL_RESET, 206 IMSG_CTL_SHUTDOWN, 207 IMSG_CTL_RELOAD, 208 IMSG_CTL_NOTIFY, 209 IMSG_CTL_END, 210 IMSG_CTL_START, 211 IMSG_CTL_REOPEN, 212 IMSG_CFG_SERVER, 213 IMSG_CFG_TLS, 214 IMSG_CFG_MEDIA, 215 IMSG_CFG_AUTH, 216 IMSG_CFG_FCGI, 217 IMSG_CFG_DONE, 218 IMSG_LOG_ACCESS, 219 IMSG_LOG_ERROR, 220 IMSG_LOG_OPEN, 221 IMSG_TLSTICKET_REKEY 222 }; 223 224 enum privsep_procid { 225 PROC_ALL = -1, 226 PROC_PARENT = 0, 227 PROC_SERVER, 228 PROC_LOGGER, 229 PROC_MAX 230 }; 231 extern enum privsep_procid privsep_process; 232 233 /* Attach the control socket to the following process */ 234 #define PROC_CONTROL PROC_LOGGER 235 236 struct privsep_pipes { 237 int *pp_pipes[PROC_MAX]; 238 }; 239 240 struct privsep { 241 struct privsep_pipes *ps_pipes[PROC_MAX]; 242 struct privsep_pipes *ps_pp; 243 244 struct imsgev *ps_ievs[PROC_MAX]; 245 const char *ps_title[PROC_MAX]; 246 uint8_t ps_what[PROC_MAX]; 247 248 unsigned int ps_instances[PROC_MAX]; 249 unsigned int ps_instance; 250 251 struct control_sock ps_csock; 252 struct control_socks ps_rcsocks; 253 254 /* Event and signal handlers */ 255 struct event ps_evsigint; 256 struct event ps_evsigterm; 257 struct event ps_evsigchld; 258 struct event ps_evsighup; 259 struct event ps_evsigpipe; 260 struct event ps_evsigusr1; 261 262 int ps_noaction; 263 struct passwd *ps_pw; 264 struct httpd *ps_env; 265 }; 266 267 struct privsep_proc { 268 const char *p_title; 269 enum privsep_procid p_id; 270 int (*p_cb)(int, struct privsep_proc *, 271 struct imsg *); 272 void (*p_init)(struct privsep *, 273 struct privsep_proc *); 274 const char *p_chroot; 275 struct privsep *p_ps; 276 void (*p_shutdown)(void); 277 struct passwd *p_pw; 278 }; 279 280 struct privsep_fd { 281 enum privsep_procid pf_procid; 282 unsigned int pf_instance; 283 }; 284 285 enum fcgistate { 286 FCGI_READ_HEADER, 287 FCGI_READ_CONTENT, 288 FCGI_READ_PADDING 289 }; 290 291 struct fcgi_data { 292 enum fcgistate state; 293 int toread; 294 int padding_len; 295 int type; 296 int chunked; 297 int end; 298 int status; 299 int headersdone; 300 int headerssent; 301 }; 302 303 struct range { 304 off_t start; 305 off_t end; 306 }; 307 308 struct range_data { 309 struct range range[SERVER_MAX_RANGES]; 310 int range_count; 311 int range_index; 312 off_t range_toread; 313 314 /* For the Content headers in each part */ 315 struct media_type *range_media; 316 size_t range_total; 317 }; 318 319 struct client { 320 uint32_t clt_id; 321 pid_t clt_pid; 322 void *clt_srv; 323 void *clt_srv_conf; 324 uint32_t clt_srv_id; 325 struct sockaddr_storage clt_srv_ss; 326 struct str_match clt_srv_match; 327 328 int clt_s; 329 in_port_t clt_port; 330 struct sockaddr_storage clt_ss; 331 struct bufferevent *clt_bev; 332 struct evbuffer *clt_output; 333 struct event clt_ev; 334 struct http_descriptor *clt_descreq; 335 struct http_descriptor *clt_descresp; 336 int clt_sndbufsiz; 337 uint64_t clt_boundary; 338 339 int clt_fd; 340 struct tls *clt_tls_ctx; 341 struct bufferevent *clt_srvbev; 342 int clt_srvbev_throttled; 343 344 off_t clt_toread; 345 size_t clt_headerlen; 346 int clt_headersdone; 347 unsigned int clt_persist; 348 unsigned int clt_pipelining; 349 int clt_line; 350 int clt_done; 351 int clt_chunk; 352 int clt_inflight; 353 int clt_fcgi_count; 354 struct range_data clt_ranges; 355 struct fcgi_data clt_fcgi; 356 const char *clt_fcgi_error; 357 char *clt_remote_user; 358 struct evbuffer *clt_srvevb; 359 360 struct evbuffer *clt_log; 361 struct timeval clt_timeout; 362 struct timeval clt_tv_start; 363 struct timeval clt_tv_last; 364 struct event clt_inflightevt; 365 366 SPLAY_ENTRY(client) clt_nodes; 367 }; 368 SPLAY_HEAD(client_tree, client); 369 370 #define SRVFLAG_INDEX 0x00000001 371 #define SRVFLAG_NO_INDEX 0x00000002 372 #define SRVFLAG_AUTO_INDEX 0x00000004 373 #define SRVFLAG_NO_AUTO_INDEX 0x00000008 374 #define SRVFLAG_ROOT 0x00000010 375 #define SRVFLAG_LOCATION 0x00000020 376 #define SRVFLAG_FCGI 0x00000040 377 #define SRVFLAG_NO_FCGI 0x00000080 378 #define SRVFLAG_LOG 0x00000100 379 #define SRVFLAG_NO_LOG 0x00000200 380 #define SRVFLAG_ERRDOCS 0x00000400 381 #define SRVFLAG_SYSLOG 0x00000800 382 #define SRVFLAG_NO_SYSLOG 0x00001000 383 #define SRVFLAG_TLS 0x00002000 384 #define SRVFLAG_ACCESS_LOG 0x00004000 385 #define SRVFLAG_ERROR_LOG 0x00008000 386 #define SRVFLAG_AUTH 0x00010000 387 #define SRVFLAG_NO_AUTH 0x00020000 388 #define SRVFLAG_BLOCK 0x00040000 389 #define SRVFLAG_NO_BLOCK 0x00080000 390 #define SRVFLAG_LOCATION_MATCH 0x00100000 391 #define SRVFLAG_SERVER_MATCH 0x00200000 392 #define SRVFLAG_SERVER_HSTS 0x00400000 393 #define SRVFLAG_DEFAULT_TYPE 0x00800000 394 #define SRVFLAG_PATH_REWRITE 0x01000000 395 #define SRVFLAG_NO_PATH_REWRITE 0x02000000 396 #define SRVFLAG_GZIP_STATIC 0x04000000 397 #define SRVFLAG_LOCATION_FOUND 0x40000000 398 #define SRVFLAG_LOCATION_NOT_FOUND 0x80000000 399 400 #define SRVFLAG_BITS \ 401 "\10\01INDEX\02NO_INDEX\03AUTO_INDEX\04NO_AUTO_INDEX" \ 402 "\05ROOT\06LOCATION\07FCGI\10NO_FCGI\11LOG\12NO_LOG\13ERRDOCS" \ 403 "\14SYSLOG\15NO_SYSLOG\16TLS\17ACCESS_LOG\20ERROR_LOG" \ 404 "\21AUTH\22NO_AUTH\23BLOCK\24NO_BLOCK\25LOCATION_MATCH" \ 405 "\26SERVER_MATCH\27SERVER_HSTS\30DEFAULT_TYPE\31PATH\32NO_PATH" \ 406 "\37LOCATION_FOUND\40LOCATION_NOT_FOUND" 407 408 #define TCPFLAG_NODELAY 0x01 409 #define TCPFLAG_NNODELAY 0x02 410 #define TCPFLAG_SACK 0x04 411 #define TCPFLAG_NSACK 0x08 412 #define TCPFLAG_BUFSIZ 0x10 413 #define TCPFLAG_IPTTL 0x20 414 #define TCPFLAG_IPMINTTL 0x40 415 #define TCPFLAG_NSPLICE 0x80 416 #define TCPFLAG_DEFAULT 0x00 417 418 #define TCPFLAG_BITS \ 419 "\10\01NODELAY\02NO_NODELAY\03SACK\04NO_SACK" \ 420 "\05SOCKET_BUFFER_SIZE\06IP_TTL\07IP_MINTTL\10NO_SPLICE" 421 422 #define HSTSFLAG_SUBDOMAINS 0x01 423 #define HSTSFLAG_PRELOAD 0x02 424 #define HSTSFLAG_BITS "\10\01SUBDOMAINS\02PRELOAD" 425 426 #define TLSFLAG_CA 0x01 427 #define TLSFLAG_CRL 0x02 428 #define TLSFLAG_OPTIONAL 0x04 429 #define TLSFLAG_BITS "\10\01CA\02CRL\03OPTIONAL" 430 431 enum log_format { 432 LOG_FORMAT_COMMON, 433 LOG_FORMAT_COMBINED, 434 LOG_FORMAT_CONNECTION, 435 LOG_FORMAT_FORWARDED 436 }; 437 438 struct log_file { 439 char log_name[PATH_MAX]; 440 int log_fd; 441 uint32_t log_id; 442 TAILQ_ENTRY(log_file) log_entry; 443 }; 444 extern TAILQ_HEAD(log_files, log_file) log_files; 445 446 struct media_type { 447 char media_name[MEDIATYPE_NAMEMAX]; 448 char media_type[MEDIATYPE_TYPEMAX]; 449 char media_subtype[MEDIATYPE_TYPEMAX]; 450 char *media_encoding; 451 RB_ENTRY(media_type) media_entry; 452 }; 453 RB_HEAD(mediatypes, media_type); 454 455 struct auth { 456 char auth_htpasswd[PATH_MAX]; 457 uint32_t auth_id; 458 TAILQ_ENTRY(auth) auth_entry; 459 }; 460 TAILQ_HEAD(serverauth, auth); 461 462 struct server_tls_ticket { 463 uint32_t tt_id; 464 uint32_t tt_keyrev; 465 unsigned char tt_key[TLS_TICKET_KEY_SIZE]; 466 }; 467 468 struct fastcgi_param { 469 char name[HTTPD_FCGI_NAME_MAX]; 470 char value[HTTPD_FCGI_VAL_MAX]; 471 472 TAILQ_ENTRY(fastcgi_param) entry; 473 }; 474 TAILQ_HEAD(server_fcgiparams, fastcgi_param); 475 476 struct server_config { 477 uint32_t id; 478 uint32_t parent_id; 479 char name[HOST_NAME_MAX+1]; 480 char location[HTTPD_LOCATION_MAX]; 481 char root[PATH_MAX]; 482 char path[PATH_MAX]; 483 char index[PATH_MAX]; 484 char accesslog[PATH_MAX]; 485 char errorlog[PATH_MAX]; 486 struct media_type default_type; 487 488 struct sockaddr_storage fastcgi_ss; 489 490 in_port_t port; 491 struct sockaddr_storage ss; 492 int prefixlen; 493 struct timeval timeout; 494 struct timeval requesttimeout; 495 uint32_t maxrequests; 496 size_t maxrequestbody; 497 498 uint8_t *tls_ca; 499 char *tls_ca_file; 500 size_t tls_ca_len; 501 uint8_t *tls_cert; 502 size_t tls_cert_len; 503 char *tls_cert_file; 504 char tls_ciphers[HTTPD_TLS_CONFIG_MAX]; 505 uint8_t *tls_crl; 506 char *tls_crl_file; 507 size_t tls_crl_len; 508 char tls_dhe_params[HTTPD_TLS_CONFIG_MAX]; 509 char tls_ecdhe_curves[HTTPD_TLS_CONFIG_MAX]; 510 uint8_t tls_flags; 511 uint8_t *tls_key; 512 size_t tls_key_len; 513 char *tls_key_file; 514 uint32_t tls_protocols; 515 uint8_t *tls_ocsp_staple; 516 size_t tls_ocsp_staple_len; 517 char *tls_ocsp_staple_file; 518 struct server_tls_ticket tls_ticket_key; 519 int tls_ticket_lifetime; 520 521 uint32_t flags; 522 int strip; 523 uint8_t tcpflags; 524 int tcpbufsiz; 525 int tcpbacklog; 526 uint8_t tcpipttl; 527 uint8_t tcpipminttl; 528 529 enum log_format logformat; 530 struct log_file *logaccess; 531 struct log_file *logerror; 532 533 char auth_realm[HTTPD_REALM_MAX]; 534 uint32_t auth_id; 535 const struct auth *auth; 536 537 int return_code; 538 char *return_uri; 539 off_t return_uri_len; 540 541 int hsts_max_age; 542 uint8_t hsts_flags; 543 544 struct server_fcgiparams fcgiparams; 545 int fcgistrip; 546 char errdocroot[HTTPD_ERRDOCROOT_MAX]; 547 548 TAILQ_ENTRY(server_config) entry; 549 }; 550 TAILQ_HEAD(serverhosts, server_config); 551 552 enum tls_config_type { 553 TLS_CFG_CA, 554 TLS_CFG_CERT, 555 TLS_CFG_CRL, 556 TLS_CFG_KEY, 557 TLS_CFG_OCSP_STAPLE, 558 }; 559 560 struct tls_config { 561 uint32_t id; 562 563 enum tls_config_type tls_type; 564 size_t tls_len; 565 size_t tls_chunk_len; 566 size_t tls_chunk_offset; 567 }; 568 569 struct server { 570 TAILQ_ENTRY(server) srv_entry; 571 struct server_config srv_conf; 572 struct serverhosts srv_hosts; 573 574 int srv_s; 575 struct event srv_ev; 576 struct event srv_evt; 577 578 struct tls *srv_tls_ctx; 579 struct tls_config *srv_tls_config; 580 581 struct client_tree srv_clients; 582 }; 583 TAILQ_HEAD(serverlist, server); 584 585 struct httpd { 586 uint8_t sc_opts; 587 uint32_t sc_flags; 588 const char *sc_conffile; 589 struct event sc_ev; 590 uint16_t sc_prefork_server; 591 uint16_t sc_id; 592 int sc_paused; 593 char *sc_chroot; 594 char *sc_logdir; 595 596 uint8_t sc_tls_sid[TLS_MAX_SESSION_ID_LENGTH]; 597 598 struct serverlist *sc_servers; 599 struct mediatypes *sc_mediatypes; 600 struct media_type sc_default_type; 601 struct serverauth *sc_auth; 602 603 struct privsep *sc_ps; 604 int sc_reload; 605 606 int sc_custom_errdocs; 607 char sc_errdocroot[HTTPD_ERRDOCROOT_MAX]; 608 }; 609 610 #define HTTPD_OPT_VERBOSE 0x01 611 #define HTTPD_OPT_NOACTION 0x04 612 613 /* control.c */ 614 int control_init(struct privsep *, struct control_sock *); 615 int control_listen(struct control_sock *); 616 void control_cleanup(struct control_sock *); 617 void control_dispatch_imsg(int, short, void *); 618 void control_imsg_forward(struct privsep *, struct imsg *); 619 struct ctl_conn * 620 control_connbyfd(int); 621 622 /* parse.y */ 623 int parse_config(const char *, struct httpd *); 624 int load_config(const char *, struct httpd *); 625 int cmdline_symset(char *); 626 627 /* server.c */ 628 void server(struct privsep *, struct privsep_proc *); 629 int server_tls_cmp(struct server *, struct server *); 630 int server_tls_load_ca(struct server *); 631 int server_tls_load_crl(struct server *); 632 int server_tls_load_keypair(struct server *); 633 int server_tls_load_ocsp(struct server *); 634 void server_generate_ticket_key(struct server_config *); 635 int server_privinit(struct server *); 636 void server_purge(struct server *); 637 void serverconfig_free(struct server_config *); 638 void serverconfig_reset(struct server_config *); 639 int server_socket_af(struct sockaddr_storage *, in_port_t); 640 in_port_t 641 server_socket_getport(struct sockaddr_storage *); 642 int server_socket_connect(struct sockaddr_storage *, in_port_t, 643 struct server_config *); 644 void server_write(struct bufferevent *, void *); 645 void server_read(struct bufferevent *, void *); 646 void server_error(struct bufferevent *, short, void *); 647 void server_log(struct client *, const char *); 648 void server_sendlog(struct server_config *, int, const char *, ...) 649 __attribute__((__format__ (printf, 3, 4))); 650 void server_close(struct client *, const char *); 651 void server_dump(struct client *, const void *, size_t); 652 int server_client_cmp(struct client *, struct client *); 653 int server_bufferevent_printf(struct client *, const char *, ...) 654 __attribute__((__format__ (printf, 2, 3))); 655 int server_bufferevent_print(struct client *, const char *); 656 int server_bufferevent_write_buffer(struct client *, 657 struct evbuffer *); 658 int server_bufferevent_write_chunk(struct client *, 659 struct evbuffer *, size_t); 660 int server_bufferevent_add(struct event *, int); 661 int server_bufferevent_write(struct client *, void *, size_t); 662 struct server * 663 server_byaddr(struct sockaddr *, in_port_t); 664 struct server_config * 665 serverconfig_byid(uint32_t); 666 int server_foreach(int (*)(struct server *, 667 struct server_config *, void *), void *); 668 struct server * 669 server_match(struct server *, int); 670 671 SPLAY_PROTOTYPE(client_tree, client, clt_nodes, server_client_cmp); 672 673 /* server_http.c */ 674 void server_http_init(struct server *); 675 void server_http(void); 676 int server_httpdesc_init(struct client *); 677 void server_read_http(struct bufferevent *, void *); 678 void server_abort_http(struct client *, unsigned int, const char *); 679 unsigned int 680 server_httpmethod_byname(const char *); 681 const char 682 *server_httpmethod_byid(unsigned int); 683 const char 684 *server_httperror_byid(unsigned int); 685 void server_read_httpcontent(struct bufferevent *, void *); 686 void server_read_httpchunks(struct bufferevent *, void *); 687 void server_read_httprange(struct bufferevent *, void *); 688 int server_writeheader_http(struct client *clt, struct kv *, void *); 689 int server_headers(struct client *, void *, 690 int (*)(struct client *, struct kv *, void *), void *); 691 int server_writeresponse_http(struct client *); 692 int server_response_http(struct client *, unsigned int, 693 struct media_type *, off_t, time_t); 694 void server_reset_http(struct client *); 695 void server_close_http(struct client *); 696 int server_response(struct httpd *, struct client *); 697 const char * 698 server_root_strip(const char *, int); 699 struct server_config * 700 server_getlocation(struct client *, const char *); 701 int server_locationaccesstest(struct server_config *, const char *); 702 const char * 703 server_http_host(struct sockaddr_storage *, char *, size_t); 704 char *server_http_parsehost(char *, char *, size_t, int *); 705 ssize_t server_http_time(time_t, char *, size_t); 706 int server_log_http(struct client *, unsigned int, size_t); 707 708 /* server_file.c */ 709 int server_file(struct httpd *, struct client *); 710 void server_file_error(struct bufferevent *, short, void *); 711 712 /* server_fcgi.c */ 713 int server_fcgi(struct httpd *, struct client *); 714 int fcgi_add_stdin(struct client *, struct evbuffer *); 715 716 /* httpd.c */ 717 void event_again(struct event *, int, short, 718 void (*)(int, short, void *), 719 struct timeval *, struct timeval *, void *); 720 int expand_string(char *, size_t, const char *, const char *); 721 const char *url_decode(char *); 722 char *url_encode(const char *); 723 const char *canonicalize_path(const char *, char *, size_t); 724 size_t path_info(char *); 725 char *escape_html(const char *); 726 void socket_rlimit(int); 727 char *evbuffer_getline(struct evbuffer *); 728 char *get_string(uint8_t *, size_t); 729 void *get_data(uint8_t *, size_t); 730 int sockaddr_cmp(struct sockaddr *, struct sockaddr *, int); 731 struct in6_addr *prefixlen2mask6(uint8_t, uint32_t *); 732 uint32_t prefixlen2mask(uint8_t); 733 int accept_reserve(int, struct sockaddr *, socklen_t *, int, 734 volatile int *); 735 struct kv *kv_add(struct kvtree *, char *, char *); 736 int kv_set(struct kv *, char *, ...) 737 __attribute__((__format__ (printf, 2, 3))); 738 int kv_setkey(struct kv *, char *, ...) 739 __attribute__((__format__ (printf, 2, 3))); 740 void kv_delete(struct kvtree *, struct kv *); 741 struct kv *kv_extend(struct kvtree *, struct kv *, char *); 742 void kv_purge(struct kvtree *); 743 void kv_free(struct kv *); 744 struct kv *kv_find(struct kvtree *, struct kv *); 745 int kv_cmp(struct kv *, struct kv *); 746 struct media_type 747 *media_add(struct mediatypes *, struct media_type *); 748 void media_delete(struct mediatypes *, struct media_type *); 749 void media_purge(struct mediatypes *); 750 struct media_type * 751 media_find(struct mediatypes *, const char *); 752 struct media_type * 753 media_find_config(struct httpd *, struct server_config *, 754 const char *); 755 int media_cmp(struct media_type *, struct media_type *); 756 RB_PROTOTYPE(kvtree, kv, kv_node, kv_cmp); 757 RB_PROTOTYPE(mediatypes, media_type, media_entry, media_cmp); 758 struct auth *auth_add(struct serverauth *, struct auth *); 759 struct auth *auth_byid(struct serverauth *, uint32_t); 760 void auth_free(struct serverauth *, struct auth *); 761 const char *print_host(struct sockaddr_storage *, char *, size_t); 762 const char *printb_flags(const uint32_t, const char *); 763 void getmonotime(struct timeval *); 764 765 extern struct httpd *httpd_env; 766 767 /* log.c */ 768 void log_init(int, int); 769 void log_procinit(const char *); 770 void log_setverbose(int); 771 int log_getverbose(void); 772 void log_warn(const char *, ...) 773 __attribute__((__format__ (printf, 1, 2))); 774 void log_warnx(const char *, ...) 775 __attribute__((__format__ (printf, 1, 2))); 776 void log_info(const char *, ...) 777 __attribute__((__format__ (printf, 1, 2))); 778 void log_debug(const char *, ...) 779 __attribute__((__format__ (printf, 1, 2))); 780 void logit(int, const char *, ...) 781 __attribute__((__format__ (printf, 2, 3))); 782 void vlog(int, const char *, va_list) 783 __attribute__((__format__ (printf, 2, 0))); 784 __dead void fatal(const char *, ...) 785 __attribute__((__format__ (printf, 1, 2))); 786 __dead void fatalx(const char *, ...) 787 __attribute__((__format__ (printf, 1, 2))); 788 789 /* proc.c */ 790 enum privsep_procid 791 proc_getid(struct privsep_proc *, unsigned int, const char *); 792 void proc_init(struct privsep *, struct privsep_proc *, unsigned int, int, 793 int, char **, enum privsep_procid); 794 void proc_kill(struct privsep *); 795 void proc_connect(struct privsep *); 796 void proc_dispatch(int, short event, void *); 797 void proc_run(struct privsep *, struct privsep_proc *, 798 struct privsep_proc *, unsigned int, 799 void (*)(struct privsep *, struct privsep_proc *, void *), void *); 800 void proc_range(struct privsep *, enum privsep_procid, int *, int *); 801 int proc_compose_imsg(struct privsep *, enum privsep_procid, int, 802 u_int16_t, u_int32_t, int, void *, u_int16_t); 803 int proc_compose(struct privsep *, enum privsep_procid, 804 uint16_t, void *, uint16_t); 805 int proc_composev_imsg(struct privsep *, enum privsep_procid, int, 806 u_int16_t, u_int32_t, int, const struct iovec *, int); 807 int proc_composev(struct privsep *, enum privsep_procid, 808 uint16_t, const struct iovec *, int); 809 int proc_forward_imsg(struct privsep *, struct imsg *, 810 enum privsep_procid, int); 811 struct imsgbuf * 812 proc_ibuf(struct privsep *, enum privsep_procid, int); 813 struct imsgev * 814 proc_iev(struct privsep *, enum privsep_procid, int); 815 int proc_flush_imsg(struct privsep *, enum privsep_procid, int); 816 void imsg_event_add(struct imsgev *); 817 int imsg_compose_event(struct imsgev *, uint16_t, uint32_t, 818 pid_t, int, void *, uint16_t); 819 int imsg_composev_event(struct imsgev *, uint16_t, uint32_t, 820 pid_t, int, const struct iovec *, int); 821 822 /* config.c */ 823 int config_init(struct httpd *); 824 void config_purge(struct httpd *, unsigned int); 825 int config_setreset(struct httpd *, unsigned int); 826 int config_getreset(struct httpd *, struct imsg *); 827 int config_getcfg(struct httpd *, struct imsg *); 828 int config_setserver(struct httpd *, struct server *); 829 int config_setserver_tls(struct httpd *, struct server *); 830 int config_setserver_fcgiparams(struct httpd *, struct server *); 831 int config_getserver(struct httpd *, struct imsg *); 832 int config_getserver_tls(struct httpd *, struct imsg *); 833 int config_getserver_fcgiparams(struct httpd *, struct imsg *); 834 int config_setmedia(struct httpd *, struct media_type *); 835 int config_getmedia(struct httpd *, struct imsg *); 836 int config_setauth(struct httpd *, struct auth *); 837 int config_getauth(struct httpd *, struct imsg *); 838 839 /* logger.c */ 840 void logger(struct privsep *, struct privsep_proc *); 841 int logger_open_priv(struct imsg *); 842 843 #endif /* _HTTPD_H */ 844