16
#ifdef HAVE_INTTYPES_H
17
# include <inttypes.h>
26
#include "sys-socket.h"
27
#include "splaytree.h"
30
#if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H
32
# include <openssl/ssl.h>
44
# define O_LARGEFILE 0
49
# define SIZE_MAX SIZE_T_MAX
51
# define SIZE_MAX ((size_t)~0)
56
# define SSIZE_MAX ((size_t)~0 >> 1)
60
#include <crt_externs.h>
61
#define environ (* _NSGetEnviron())
63
extern char **environ;
66
/* for solaris 2.5 and NetBSD 1.3.x */
67
#ifndef HAVE_SOCKLEN_T
68
typedef int socklen_t;
71
/* solaris and NetBSD 1.3.x again */
72
#if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
73
# define uint32_t u_int32_t
83
typedef enum { T_CONFIG_UNSET,
90
} config_values_type_t;
92
typedef enum { T_CONFIG_SCOPE_UNSET,
93
T_CONFIG_SCOPE_SERVER,
94
T_CONFIG_SCOPE_CONNECTION
95
} config_scope_type_t;
101
config_values_type_t type;
102
config_scope_type_t scope;
105
typedef enum { DIRECT, EXTERNAL } connection_type;
109
connection_type type;
124
struct sockaddr_in6 ipv6;
126
struct sockaddr_in ipv4;
128
struct sockaddr_un un;
130
struct sockaddr plain;
133
/* fcgi_response_header contains ... */
134
#define HTTP_STATUS BV(0)
135
#define HTTP_CONNECTION BV(1)
136
#define HTTP_CONTENT_LENGTH BV(2)
137
#define HTTP_DATE BV(3)
138
#define HTTP_LOCATION BV(4)
142
/* the request-line */
148
http_method_t http_method;
149
http_version_t http_version;
151
buffer *request_line;
153
/* strings to the header */
154
buffer *http_host; /* not alloced */
155
const char *http_range;
156
const char *http_content_type;
157
const char *http_if_modified_since;
158
const char *http_if_none_match;
163
size_t content_length; /* returned by strtoul() */
165
/* internal representation */
173
off_t content_length;
174
int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
179
HTTP_TRANSFER_ENCODING_IDENTITY, HTTP_TRANSFER_ENCODING_CHUNKED
193
buffer *basedir; /* path = "(basedir)(.*)" */
195
buffer *doc_root; /* path = doc_root + rel_path */
214
buffer *content_type;
218
splay_tree *files; /* the nodes of the tree are stat_cache_entry's */
220
buffer *dir_name; /* for building the dirname from the filename */
222
splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */
232
/* virtual-servers */
233
buffer *document_root;
235
buffer *error_handler;
237
buffer *dirlist_encoding;
238
buffer *errorfile_prefix;
240
unsigned short max_keep_alive_requests;
241
unsigned short max_keep_alive_idle;
242
unsigned short max_read_idle;
243
unsigned short max_write_idle;
244
unsigned short use_xattr;
245
unsigned short follow_symlink;
246
unsigned short range_requests;
250
unsigned short log_file_not_found;
251
unsigned short log_request_header;
252
unsigned short log_request_handling;
253
unsigned short log_response_header;
254
unsigned short log_condition_handling;
260
unsigned short use_ipv6;
261
unsigned short is_ssl;
262
unsigned short allow_http11;
263
unsigned short force_lower_case; /* if the FS is case-insensitive, force all files to lower-case */
264
unsigned short max_request_size;
266
unsigned short kbytes_per_second; /* connection kb/s limit */
269
unsigned short global_kbytes_per_second; /* */
271
off_t global_bytes_per_second_cnt;
272
/* server-wide traffic-shaper
274
* each context has the counter which is inited once
275
* a second by the global_kbytes_per_second config-var
277
* as soon as global_kbytes_per_second gets below 0
278
* the connected conns are "offline" a little bit
281
* we somehow have to loose our "we are writable" signal
285
off_t *global_bytes_per_second_cnt_ptr; /* */
292
typedef enum { CON_STATE_CONNECT, CON_STATE_REQUEST_START, CON_STATE_READ, CON_STATE_REQUEST_END, CON_STATE_READ_POST, CON_STATE_HANDLE_REQUEST, CON_STATE_RESPONSE_START, CON_STATE_WRITE, CON_STATE_RESPONSE_END, CON_STATE_ERROR, CON_STATE_CLOSE } connection_state_t;
294
typedef enum { COND_RESULT_UNSET, COND_RESULT_FALSE, COND_RESULT_TRUE } cond_result_t;
296
cond_result_t result;
299
buffer *comp_value; /* just a pointer */
303
connection_state_t state;
307
time_t close_timeout_ts;
308
time_t write_request_ts;
310
time_t connection_start;
311
time_t request_start;
313
struct timeval start_tv;
315
size_t request_count; /* number of requests handled in this connection */
316
size_t loops_per_request; /* to catch endless loops in a single request
318
* used by mod_rewrite, mod_fastcgi, ... and others
319
* this is self-protection
322
int fd; /* the FD for this connection */
323
int fde_ndx; /* index for the fdevent-handler */
324
int ndx; /* reverse mapping to server->connection[ndx] */
330
int keep_alive; /* only request.c can enable it, all other just disable */
335
chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
336
chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */
337
chunkqueue *request_content_queue; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
339
int traffic_limit_reached;
341
off_t bytes_written; /* used by mod_accesslog, mod_rrd */
342
off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
343
off_t bytes_read; /* used by mod_accesslog, mod_rrd */
349
buffer *dst_addr_buf;
352
buffer *parse_request;
353
unsigned int parsed_response; /* bitfield which contains the important header-fields of the parsed response header */
363
array *environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
370
connection_type mode;
372
void **plugin_ctx; /* plugin connection specific config */
374
specific_config conf; /* global connection specific config */
375
cond_cache_t *cond_cache;
380
buffer *error_handler;
381
int error_handler_saved_status;
382
int in_error_handler;
384
void *srv_socket; /* reference to the server-socket (typecast to server_socket) */
402
struct in6_addr ipv6;
405
char b2[INET6_ADDRSTRLEN + 1];
407
} inet_ntop_cache_type;
415
} realpath_cache_type;
418
time_t mtime; /* the key */
419
buffer *str; /* a buffer for the string represenation */
432
buffer *errorlog_file;
433
unsigned short errorlog_use_syslog;
435
unsigned short dont_daemonize;
442
buffer *event_handler;
445
buffer *network_backend;
447
array *upload_tempdirs;
449
unsigned short max_worker;
450
unsigned short max_fds;
451
unsigned short max_conns;
452
unsigned short max_request_size;
454
unsigned short log_request_header_on_error;
455
unsigned short log_state_handling;
457
enum { STAT_CACHE_ENGINE_UNSET,
458
STAT_CACHE_ENGINE_NONE,
459
STAT_CACHE_ENGINE_SIMPLE,
460
STAT_CACHE_ENGINE_FAM
471
unsigned short use_ipv6;
472
unsigned short is_ssl;
486
} server_socket_array;
488
typedef struct server {
489
server_socket_array srv_sockets;
493
enum { ERRORLOG_STDERR, ERRORLOG_FILE, ERRORLOG_SYSLOG } errorlog_mode;
494
buffer *errorlog_buf;
496
fdevents *ev, *ev_ins;
498
buffer_plugin plugins;
509
int max_fds; /* max possible fds */
510
int cur_fds; /* currently used fds */
511
int want_fds; /* waiting fds */
512
int sockets_disabled;
517
buffer *parse_full_path;
518
buffer *response_header;
519
buffer *response_range;
522
buffer *tmp_chunk_len;
524
buffer *empty_string; /* is necessary for cond_match */
526
buffer *cond_check_buf;
530
inet_ntop_cache_type inet_ntop_cache[INET_NTOP_CACHE_MAX];
532
mtime_cache_type mtime_cache[FILE_CACHE_MAX];
538
time_t last_generated_date_ts;
539
time_t last_generated_debug_ts;
542
buffer *ts_debug_str;
547
array *config_touched;
549
array *config_context;
550
specific_config **config_storage;
552
server_config srvconf;
554
int config_deprecated;
557
connections *joblist;
558
connections *fdwaitqueue;
560
stat_cache *stat_cache;
562
fdevent_handler_t event_handler;
564
int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq);
565
int (* network_backend_read)(struct server *srv, connection *con, int fd, chunkqueue *cq);
567
int (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);
568
int (* network_ssl_backend_read)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq);