17 #ifdef HAVE_INTTYPES_H
18 # include <inttypes.h>
21 #include "base_decls.h"
26 #include "sys-socket.h"
29 struct fdevents
; /* declaration */
30 struct stat_cache
; /* declaration */
37 # define O_LARGEFILE 0
42 # define SIZE_MAX SIZE_T_MAX
44 # define SIZE_MAX ((size_t)~0)
49 # define SSIZE_MAX ((size_t)~0 >> 1)
53 #include <crt_externs.h>
54 #define environ (* _NSGetEnviron())
56 extern char **environ
;
59 /* for solaris 2.5 and NetBSD 1.3.x */
60 #ifndef HAVE_SOCKLEN_T
61 typedef int socklen_t
;
64 /* solaris and NetBSD 1.3.x again */
65 #if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
66 # define uint32_t u_int32_t
74 typedef enum { T_CONFIG_UNSET
,
83 } config_values_type_t
;
85 typedef enum { T_CONFIG_SCOPE_UNSET
,
86 T_CONFIG_SCOPE_SERVER
,
87 T_CONFIG_SCOPE_CONNECTION
88 } config_scope_type_t
;
94 config_values_type_t type
;
95 config_scope_type_t scope
;
98 typedef enum { DIRECT
, EXTERNAL
} connection_type
;
102 connection_type type
;
109 struct sockaddr_in6 ipv6
;
111 struct sockaddr_in ipv4
;
113 struct sockaddr_un un
;
115 struct sockaddr plain
;
118 /* fcgi_response_header contains ... */
119 #define HTTP_STATUS BV(0)
120 #define HTTP_CONNECTION BV(1)
121 #define HTTP_CONTENT_LENGTH BV(2)
122 #define HTTP_DATE BV(3)
123 #define HTTP_LOCATION BV(4)
124 #define HTTP_TRANSFER_ENCODING BV(5)
125 #define HTTP_CONTENT_LOCATION BV(6)
126 #define HTTP_SET_COOKIE BV(7)
127 #define HTTP_UPGRADE BV(8)
131 /* the request-line */
137 http_method_t http_method
;
138 http_version_t http_version
;
140 buffer
*request_line
;
142 /* strings to the header */
143 buffer
*http_host
; /* not alloced */
144 const char *http_range
;
145 const char *http_content_type
;
146 const char *http_if_modified_since
;
147 const char *http_if_none_match
;
152 off_t content_length
; /* returned by strtoll() */
155 /* internal representation */
163 off_t content_length
;
164 int keep_alive
; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
169 HTTP_TRANSFER_ENCODING_IDENTITY
, HTTP_TRANSFER_ENCODING_CHUNKED
174 buffer
*scheme
; /* scheme without colon or slashes ( "http" or "https" ) */
176 /* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
179 /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */
181 buffer
*path_raw
; /* raw path, as sent from client. no urldecoding or path simplifying */
182 buffer
*query
; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
187 buffer
*basedir
; /* path = "(basedir)(.*)" */
189 buffer
*doc_root
; /* path = doc_root + rel_path */
211 buffer
*content_type
;
217 /* virtual-servers */
218 buffer
*document_root
;
220 buffer
*error_handler
;
221 buffer
*error_handler_404
;
223 buffer
*dirlist_encoding
;
224 buffer
*errorfile_prefix
;
225 buffer
*socket_perms
;
227 unsigned short high_precision_timestamps
;
228 unsigned short max_keep_alive_requests
;
229 unsigned short max_keep_alive_idle
;
230 unsigned short max_read_idle
;
231 unsigned short max_write_idle
;
232 unsigned short use_xattr
;
233 unsigned short follow_symlink
;
234 unsigned short range_requests
;
235 unsigned short stream_request_body
;
236 unsigned short stream_response_body
;
237 unsigned short error_intercept
;
241 unsigned short log_file_not_found
;
242 unsigned short log_request_header
;
243 unsigned short log_request_handling
;
244 unsigned short log_response_header
;
245 unsigned short log_condition_handling
;
246 unsigned short log_timeouts
;
250 unsigned short use_ipv6
, set_v6only
; /* set_v6only is only a temporary option */
251 unsigned short defer_accept
;
252 unsigned short ssl_enabled
; /* only interesting for setting up listening sockets. don't use at runtime */
253 unsigned short allow_http11
;
254 unsigned short etag_use_inode
;
255 unsigned short etag_use_mtime
;
256 unsigned short etag_use_size
;
257 unsigned short force_lowercase_filenames
; /* if the FS is case-insensitive, force all files to lower-case */
258 unsigned int http_parseopts
;
259 unsigned int max_request_size
;
262 unsigned short kbytes_per_second
; /* connection kb/s limit */
265 unsigned short global_kbytes_per_second
; /* */
267 off_t global_bytes_per_second_cnt
;
268 /* server-wide traffic-shaper
270 * each context has the counter which is inited once
271 * a second by the global_kbytes_per_second config-var
273 * as soon as global_kbytes_per_second gets below 0
274 * the connected conns are "offline" a little bit
277 * we somehow have to loose our "we are writable" signal
281 off_t
*global_bytes_per_second_cnt_ptr
; /* */
283 #if defined(__FreeBSD__) || defined(__NetBSD__) \
284 || defined(__OpenBSD__) || defined(__DragonFly__)
285 buffer
*bsd_accept_filter
;
290 /* the order of the items should be the same as they are processed
291 * read before write as we use this later */
294 CON_STATE_REQUEST_START
,
296 CON_STATE_REQUEST_END
,
298 CON_STATE_HANDLE_REQUEST
,
299 CON_STATE_RESPONSE_START
,
301 CON_STATE_RESPONSE_END
,
304 } connection_state_t
;
307 /* condition not active at the moment because itself or some
308 * pre-condition depends on data not available yet
312 /* special "unset" for branches not selected due to pre-conditions
313 * not met (but pre-conditions are not "unset" anymore)
317 /* actually evaluated the condition itself */
318 COND_RESULT_FALSE
, /* not active */
319 COND_RESULT_TRUE
, /* active */
323 /* current result (with preconditions) */
324 cond_result_t result
;
325 /* result without preconditions (must never be "skip") */
326 cond_result_t local_result
;
329 buffer
*comp_value
; /* just a pointer */
333 connection_state_t state
;
337 time_t close_timeout_ts
;
338 time_t write_request_ts
;
340 time_t connection_start
;
341 time_t request_start
;
342 struct timespec request_start_hp
;
344 size_t request_count
; /* number of requests handled in this connection */
345 size_t loops_per_request
; /* to catch endless loops in a single request
347 * used by mod_rewrite, mod_fastcgi, ... and others
348 * this is self-protection
351 int fd
; /* the FD for this connection */
352 int fde_ndx
; /* index for the fdevent-handler */
353 int ndx
; /* reverse mapping to server->connection[ndx] */
359 int keep_alive
; /* only request.c can enable it, all other just disable */
360 int keep_alive_idle
; /* remember max_keep_alive_idle from config */
365 chunkqueue
*write_queue
; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
366 chunkqueue
*read_queue
; /* a small queue for low-level read ( HTTP request ) [ mem ] */
367 chunkqueue
*request_content_queue
; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
369 int traffic_limit_reached
;
371 off_t bytes_written
; /* used by mod_accesslog, mod_rrd */
372 off_t bytes_written_cur_second
; /* used by mod_accesslog, mod_rrd */
373 off_t bytes_read
; /* used by mod_accesslog, mod_rrd */
379 buffer
*dst_addr_buf
;
382 buffer
*parse_request
;
383 unsigned int parsed_response
; /* bitfield which contains the important header-fields of the parsed response header */
392 array
*environment
; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
394 connection_type mode
;
396 void **plugin_ctx
; /* plugin connection specific config */
398 specific_config conf
; /* global connection specific config */
399 cond_cache_t
*cond_cache
;
405 int error_handler_saved_status
;
406 http_method_t error_handler_saved_method
;
408 struct server_socket
*srv_socket
; /* reference to the server-socket */
409 int (* network_write
)(struct server
*srv
, struct connection
*con
, chunkqueue
*cq
, off_t max_bytes
);
410 int (* network_read
)(struct server
*srv
, struct connection
*con
, chunkqueue
*cq
, off_t max_bytes
);
413 etag_flags_t etag_flags
;
415 int conditional_is_valid
[COMP_LAST_ELEMENT
];
429 } realpath_cache_type
;
432 time_t mtime
; /* the key */
433 buffer
*str
; /* a buffer for the string represenation */
446 buffer
*errorlog_file
;
447 unsigned short errorlog_use_syslog
;
448 buffer
*breakagelog_file
;
450 unsigned short dont_daemonize
;
451 unsigned short preflight_check
;
458 buffer
*event_handler
;
461 buffer
*network_backend
;
463 array
*upload_tempdirs
;
464 unsigned int upload_temp_file_size
;
465 unsigned int max_request_field_size
;
467 unsigned short max_worker
;
468 unsigned short max_fds
;
469 unsigned short max_conns
;
471 unsigned short log_request_header_on_error
;
472 unsigned short log_state_handling
;
474 enum { STAT_CACHE_ENGINE_UNSET
,
475 STAT_CACHE_ENGINE_NONE
,
476 STAT_CACHE_ENGINE_SIMPLE
478 , STAT_CACHE_ENGINE_FAM
481 unsigned short enable_cores
;
482 unsigned short reject_expect_100_with_417
;
485 unsigned short http_header_strict
;
486 unsigned short http_host_strict
;
487 unsigned short http_host_normalize
;
488 unsigned short high_precision_timestamps
;
491 buffer
*syslog_facility
;
494 typedef struct server_socket
{
499 unsigned short is_ssl
;
510 } server_socket_array
;
513 server_socket_array srv_sockets
;
517 enum { ERRORLOG_FILE
, ERRORLOG_FD
, ERRORLOG_SYSLOG
, ERRORLOG_PIPE
} errorlog_mode
;
518 buffer
*errorlog_buf
;
522 buffer_plugin plugins
;
531 int max_fds
; /* max possible fds */
532 int cur_fds
; /* currently used fds */
533 int want_fds
; /* waiting fds */
534 int sockets_disabled
;
539 buffer
*parse_full_path
;
540 buffer
*response_header
;
541 buffer
*response_range
;
544 buffer
*tmp_chunk_len
;
546 buffer
*empty_string
; /* is necessary for cond_match */
548 buffer
*cond_check_buf
;
551 mtime_cache_type mtime_cache
[FILE_CACHE_MAX
];
557 time_t last_generated_date_ts
;
558 time_t last_generated_debug_ts
;
561 buffer
*ts_debug_str
;
565 array
*config_touched
;
567 array
*config_context
;
568 specific_config
**config_storage
;
570 server_config srvconf
;
572 short int config_deprecated
;
573 short int config_unsupported
;
576 connections
*joblist
;
577 connections
*fdwaitqueue
;
579 struct stat_cache
*stat_cache
;
582 * The status array can carry all the status information you want
583 * the key to the array is <module-prefix>.<name>
584 * and the values are counters
587 * fastcgi.backends = 10
588 * fastcgi.active-backends = 6
589 * fastcgi.backend.<key>.load = 24
590 * fastcgi.backend.<key>....
592 * fastcgi.backend.<key>.disconnects = ...
598 int (* network_backend_write
)(struct server
*srv
, connection
*con
, int fd
, chunkqueue
*cq
, off_t max_bytes
);
599 handler_t (* request_env
)(struct server
*srv
, connection
*con
);