17 #ifdef HAVE_INTTYPES_H
18 # include <inttypes.h>
26 #include "sys-socket.h"
27 #include "splaytree.h"
39 # define O_LARGEFILE 0
44 # define SIZE_MAX SIZE_T_MAX
46 # define SIZE_MAX ((size_t)~0)
51 # define SSIZE_MAX ((size_t)~0 >> 1)
55 #include <crt_externs.h>
56 #define environ (* _NSGetEnviron())
58 extern char **environ
;
61 /* for solaris 2.5 and NetBSD 1.3.x */
62 #ifndef HAVE_SOCKLEN_T
63 typedef int socklen_t
;
66 /* solaris and NetBSD 1.3.x again */
67 #if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
68 # define uint32_t u_int32_t
76 typedef enum { T_CONFIG_UNSET
,
85 } config_values_type_t
;
87 typedef enum { T_CONFIG_SCOPE_UNSET
,
88 T_CONFIG_SCOPE_SERVER
,
89 T_CONFIG_SCOPE_CONNECTION
90 } config_scope_type_t
;
96 config_values_type_t type
;
97 config_scope_type_t scope
;
100 typedef enum { DIRECT
, EXTERNAL
} connection_type
;
104 connection_type type
;
119 struct sockaddr_in6 ipv6
;
121 struct sockaddr_in ipv4
;
123 struct sockaddr_un un
;
125 struct sockaddr plain
;
128 /* fcgi_response_header contains ... */
129 #define HTTP_STATUS BV(0)
130 #define HTTP_CONNECTION BV(1)
131 #define HTTP_CONTENT_LENGTH BV(2)
132 #define HTTP_DATE BV(3)
133 #define HTTP_LOCATION BV(4)
134 #define HTTP_TRANSFER_ENCODING BV(5)
138 /* the request-line */
144 http_method_t http_method
;
145 http_version_t http_version
;
147 buffer
*request_line
;
149 /* strings to the header */
150 buffer
*http_host
; /* not alloced */
151 const char *http_range
;
152 const char *http_content_type
;
153 const char *http_if_modified_since
;
154 const char *http_if_none_match
;
159 off_t content_length
; /* returned by strtoll() */
162 /* internal representation */
170 off_t content_length
;
171 int keep_alive
; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
176 HTTP_TRANSFER_ENCODING_IDENTITY
, HTTP_TRANSFER_ENCODING_CHUNKED
181 buffer
*scheme
; /* scheme without colon or slashes ( "http" or "https" ) */
183 /* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
186 /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */
188 buffer
*path_raw
; /* raw path, as sent from client. no urldecoding or path simplifying */
189 buffer
*query
; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
194 buffer
*basedir
; /* path = "(basedir)(.*)" */
196 buffer
*doc_root
; /* path = doc_root + rel_path */
218 buffer
*content_type
;
222 splay_tree
*files
; /* the nodes of the tree are stat_cache_entry's */
224 buffer
*dir_name
; /* for building the dirname from the filename */
226 splay_tree
*dirs
; /* the nodes of the tree are fam_dir_entry */
231 buffer
*hash_key
; /* temp-store for the hash-key */
237 /* virtual-servers */
238 buffer
*document_root
;
240 buffer
*error_handler
;
241 buffer
*error_handler_404
;
243 buffer
*dirlist_encoding
;
244 buffer
*errorfile_prefix
;
246 unsigned short high_precision_timestamps
;
247 unsigned short max_keep_alive_requests
;
248 unsigned short max_keep_alive_idle
;
249 unsigned short max_read_idle
;
250 unsigned short max_write_idle
;
251 unsigned short use_xattr
;
252 unsigned short follow_symlink
;
253 unsigned short range_requests
;
254 unsigned short stream_request_body
;
255 unsigned short stream_response_body
;
256 unsigned short error_intercept
;
260 unsigned short log_file_not_found
;
261 unsigned short log_request_header
;
262 unsigned short log_request_handling
;
263 unsigned short log_response_header
;
264 unsigned short log_condition_handling
;
265 unsigned short log_timeouts
;
269 unsigned short use_ipv6
, set_v6only
; /* set_v6only is only a temporary option */
270 unsigned short defer_accept
;
271 unsigned short ssl_enabled
; /* only interesting for setting up listening sockets. don't use at runtime */
272 unsigned short allow_http11
;
273 unsigned short etag_use_inode
;
274 unsigned short etag_use_mtime
;
275 unsigned short etag_use_size
;
276 unsigned short force_lowercase_filenames
; /* if the FS is case-insensitive, force all files to lower-case */
277 unsigned int http_parseopts
;
278 unsigned int max_request_size
;
281 unsigned short kbytes_per_second
; /* connection kb/s limit */
284 unsigned short global_kbytes_per_second
; /* */
286 off_t global_bytes_per_second_cnt
;
287 /* server-wide traffic-shaper
289 * each context has the counter which is inited once
290 * a second by the global_kbytes_per_second config-var
292 * as soon as global_kbytes_per_second gets below 0
293 * the connected conns are "offline" a little bit
296 * we somehow have to loose our "we are writable" signal
300 off_t
*global_bytes_per_second_cnt_ptr
; /* */
302 #if defined(__FreeBSD__) || defined(__NetBSD__) \
303 || defined(__OpenBSD__) || defined(__DragonFly__)
304 buffer
*bsd_accept_filter
;
309 /* the order of the items should be the same as they are processed
310 * read before write as we use this later */
313 CON_STATE_REQUEST_START
,
315 CON_STATE_REQUEST_END
,
317 CON_STATE_HANDLE_REQUEST
,
318 CON_STATE_RESPONSE_START
,
320 CON_STATE_RESPONSE_END
,
323 } connection_state_t
;
326 /* condition not active at the moment because itself or some
327 * pre-condition depends on data not available yet
331 /* special "unset" for branches not selected due to pre-conditions
332 * not met (but pre-conditions are not "unset" anymore)
336 /* actually evaluated the condition itself */
337 COND_RESULT_FALSE
, /* not active */
338 COND_RESULT_TRUE
, /* active */
342 /* current result (with preconditions) */
343 cond_result_t result
;
344 /* result without preconditions (must never be "skip") */
345 cond_result_t local_result
;
348 buffer
*comp_value
; /* just a pointer */
351 typedef struct connection
{
352 connection_state_t state
;
356 time_t close_timeout_ts
;
357 time_t write_request_ts
;
359 time_t connection_start
;
360 time_t request_start
;
361 struct timespec request_start_hp
;
363 size_t request_count
; /* number of requests handled in this connection */
364 size_t loops_per_request
; /* to catch endless loops in a single request
366 * used by mod_rewrite, mod_fastcgi, ... and others
367 * this is self-protection
370 int fd
; /* the FD for this connection */
371 int fde_ndx
; /* index for the fdevent-handler */
372 int ndx
; /* reverse mapping to server->connection[ndx] */
378 int keep_alive
; /* only request.c can enable it, all other just disable */
379 int keep_alive_idle
; /* remember max_keep_alive_idle from config */
384 chunkqueue
*write_queue
; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
385 chunkqueue
*read_queue
; /* a small queue for low-level read ( HTTP request ) [ mem ] */
386 chunkqueue
*request_content_queue
; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
388 int traffic_limit_reached
;
390 off_t bytes_written
; /* used by mod_accesslog, mod_rrd */
391 off_t bytes_written_cur_second
; /* used by mod_accesslog, mod_rrd */
392 off_t bytes_read
; /* used by mod_accesslog, mod_rrd */
398 buffer
*dst_addr_buf
;
401 buffer
*parse_request
;
402 unsigned int parsed_response
; /* bitfield which contains the important header-fields of the parsed response header */
411 array
*environment
; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
418 connection_type mode
;
420 void **plugin_ctx
; /* plugin connection specific config */
422 specific_config conf
; /* global connection specific config */
423 cond_cache_t
*cond_cache
;
428 int error_handler_saved_status
;
429 http_method_t error_handler_saved_method
;
431 struct server_socket
*srv_socket
; /* reference to the server-socket */
432 int (* network_write
)(struct server
*srv
, struct connection
*con
, chunkqueue
*cq
, off_t max_bytes
);
433 int (* network_read
)(struct server
*srv
, struct connection
*con
, chunkqueue
*cq
, off_t max_bytes
);
436 etag_flags_t etag_flags
;
438 int conditional_is_valid
[COMP_LAST_ELEMENT
];
452 struct in6_addr ipv6
;
455 char b2
[INET6_ADDRSTRLEN
+ 1];
457 } inet_ntop_cache_type
;
465 } realpath_cache_type
;
468 time_t mtime
; /* the key */
469 buffer
*str
; /* a buffer for the string represenation */
482 buffer
*errorlog_file
;
483 unsigned short errorlog_use_syslog
;
484 buffer
*breakagelog_file
;
486 unsigned short dont_daemonize
;
487 unsigned short preflight_check
;
494 buffer
*event_handler
;
497 buffer
*network_backend
;
499 array
*upload_tempdirs
;
500 unsigned int upload_temp_file_size
;
501 unsigned int max_request_field_size
;
503 unsigned short max_worker
;
504 unsigned short max_fds
;
505 unsigned short max_conns
;
507 unsigned short log_request_header_on_error
;
508 unsigned short log_state_handling
;
510 enum { STAT_CACHE_ENGINE_UNSET
,
511 STAT_CACHE_ENGINE_NONE
,
512 STAT_CACHE_ENGINE_SIMPLE
514 , STAT_CACHE_ENGINE_FAM
517 unsigned short enable_cores
;
518 unsigned short reject_expect_100_with_417
;
521 unsigned short http_header_strict
;
522 unsigned short http_host_strict
;
523 unsigned short http_host_normalize
;
524 unsigned short high_precision_timestamps
;
529 typedef struct server_socket
{
534 unsigned short is_ssl
;
545 } server_socket_array
;
547 typedef struct server
{
548 server_socket_array srv_sockets
;
552 enum { ERRORLOG_FILE
, ERRORLOG_FD
, ERRORLOG_SYSLOG
, ERRORLOG_PIPE
} errorlog_mode
;
553 buffer
*errorlog_buf
;
555 fdevents
*ev
, *ev_ins
;
557 buffer_plugin plugins
;
566 int max_fds
; /* max possible fds */
567 int cur_fds
; /* currently used fds */
568 int want_fds
; /* waiting fds */
569 int sockets_disabled
;
574 buffer
*parse_full_path
;
575 buffer
*response_header
;
576 buffer
*response_range
;
579 buffer
*tmp_chunk_len
;
581 buffer
*empty_string
; /* is necessary for cond_match */
583 buffer
*cond_check_buf
;
587 inet_ntop_cache_type inet_ntop_cache
[INET_NTOP_CACHE_MAX
];
589 mtime_cache_type mtime_cache
[FILE_CACHE_MAX
];
595 time_t last_generated_date_ts
;
596 time_t last_generated_debug_ts
;
599 buffer
*ts_debug_str
;
603 array
*config_touched
;
605 array
*config_context
;
606 specific_config
**config_storage
;
608 server_config srvconf
;
610 short int config_deprecated
;
611 short int config_unsupported
;
614 connections
*joblist
;
615 connections
*fdwaitqueue
;
617 stat_cache
*stat_cache
;
620 * The status array can carry all the status information you want
621 * the key to the array is <module-prefix>.<name>
622 * and the values are counters
625 * fastcgi.backends = 10
626 * fastcgi.active-backends = 6
627 * fastcgi.backend.<key>.load = 24
628 * fastcgi.backend.<key>....
630 * fastcgi.backend.<key>.disconnects = ...
634 fdevent_handler_t event_handler
;
636 int (* network_backend_write
)(struct server
*srv
, connection
*con
, int fd
, chunkqueue
*cq
, off_t max_bytes
);
637 handler_t (* request_env
)(struct server
*srv
, connection
*con
);