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