Annotation of embedaddon/lighttpd/src/base.h, revision 1.1.1.3
1.1 misho 1: #ifndef _BASE_H_
2: #define _BASE_H_
1.1.1.3 ! misho 3: #include "first.h"
1.1 misho 4:
5: #include "settings.h"
6:
7: #include <sys/types.h>
8: #include <sys/time.h>
9: #include <sys/stat.h>
10:
11: #include <limits.h>
12:
13: #ifdef HAVE_STDINT_H
14: # include <stdint.h>
15: #endif
16:
17: #ifdef HAVE_INTTYPES_H
18: # include <inttypes.h>
19: #endif
20:
21: #include "buffer.h"
22: #include "array.h"
23: #include "chunk.h"
24: #include "keyvalue.h"
25: #include "fdevent.h"
26: #include "sys-socket.h"
27: #include "splaytree.h"
28: #include "etag.h"
29:
30:
31: #if defined HAVE_LIBSSL && defined HAVE_OPENSSL_SSL_H
32: # define USE_OPENSSL
1.1.1.3 ! misho 33: # include <openssl/opensslconf.h>
! 34: # ifndef USE_OPENSSL_KERBEROS
! 35: # ifndef OPENSSL_NO_KRB5
! 36: # define OPENSSL_NO_KRB5
! 37: # endif
! 38: # endif
1.1 misho 39: # include <openssl/ssl.h>
40: # if ! defined OPENSSL_NO_TLSEXT && ! defined SSL_CTRL_SET_TLSEXT_HOSTNAME
41: # define OPENSSL_NO_TLSEXT
42: # endif
43: #endif
44:
45: #ifdef HAVE_FAM_H
46: # include <fam.h>
47: #endif
48:
49: #ifndef O_BINARY
50: # define O_BINARY 0
51: #endif
52:
53: #ifndef O_LARGEFILE
54: # define O_LARGEFILE 0
55: #endif
56:
57: #ifndef SIZE_MAX
58: # ifdef SIZE_T_MAX
59: # define SIZE_MAX SIZE_T_MAX
60: # else
61: # define SIZE_MAX ((size_t)~0)
62: # endif
63: #endif
64:
65: #ifndef SSIZE_MAX
66: # define SSIZE_MAX ((size_t)~0 >> 1)
67: #endif
68:
69: #ifdef __APPLE__
70: #include <crt_externs.h>
71: #define environ (* _NSGetEnviron())
72: #else
73: extern char **environ;
74: #endif
75:
76: /* for solaris 2.5 and NetBSD 1.3.x */
77: #ifndef HAVE_SOCKLEN_T
78: typedef int socklen_t;
79: #endif
80:
81: /* solaris and NetBSD 1.3.x again */
82: #if (!defined(HAVE_STDINT_H)) && (!defined(HAVE_INTTYPES_H)) && (!defined(uint32_t))
83: # define uint32_t u_int32_t
84: #endif
85:
86:
87: #ifndef SHUT_WR
88: # define SHUT_WR 1
89: #endif
90:
91: typedef enum { T_CONFIG_UNSET,
92: T_CONFIG_STRING,
93: T_CONFIG_SHORT,
94: T_CONFIG_INT,
95: T_CONFIG_BOOLEAN,
96: T_CONFIG_ARRAY,
97: T_CONFIG_LOCAL,
98: T_CONFIG_DEPRECATED,
99: T_CONFIG_UNSUPPORTED
100: } config_values_type_t;
101:
102: typedef enum { T_CONFIG_SCOPE_UNSET,
103: T_CONFIG_SCOPE_SERVER,
104: T_CONFIG_SCOPE_CONNECTION
105: } config_scope_type_t;
106:
107: typedef struct {
108: const char *key;
109: void *destination;
110:
111: config_values_type_t type;
112: config_scope_type_t scope;
113: } config_values_t;
114:
115: typedef enum { DIRECT, EXTERNAL } connection_type;
116:
117: typedef struct {
118: char *key;
119: connection_type type;
120: char *value;
121: } request_handler;
122:
123: typedef struct {
124: char *key;
125: char *host;
126: unsigned short port;
127: int used;
128: short factor;
129: } fcgi_connections;
130:
131:
132: typedef union {
133: #ifdef HAVE_IPV6
134: struct sockaddr_in6 ipv6;
135: #endif
136: struct sockaddr_in ipv4;
137: #ifdef HAVE_SYS_UN_H
138: struct sockaddr_un un;
139: #endif
140: struct sockaddr plain;
141: } sock_addr;
142:
143: /* fcgi_response_header contains ... */
144: #define HTTP_STATUS BV(0)
145: #define HTTP_CONNECTION BV(1)
146: #define HTTP_CONTENT_LENGTH BV(2)
147: #define HTTP_DATE BV(3)
148: #define HTTP_LOCATION BV(4)
149:
150: typedef struct {
151: /** HEADER */
152: /* the request-line */
153: buffer *request;
154: buffer *uri;
155:
156: buffer *orig_uri;
157:
158: http_method_t http_method;
159: http_version_t http_version;
160:
161: buffer *request_line;
162:
163: /* strings to the header */
164: buffer *http_host; /* not alloced */
165: const char *http_range;
166: const char *http_content_type;
167: const char *http_if_modified_since;
168: const char *http_if_none_match;
169:
170: array *headers;
171:
172: /* CONTENT */
173: size_t content_length; /* returned by strtoul() */
174:
175: /* internal representation */
176: int accept_encoding;
177:
178: /* internal */
179: buffer *pathinfo;
180: } request;
181:
182: typedef struct {
183: off_t content_length;
184: int keep_alive; /* used by the subrequests in proxy, cgi and fcgi to say the subrequest was keep-alive or not */
185:
186: array *headers;
187:
188: enum {
189: HTTP_TRANSFER_ENCODING_IDENTITY, HTTP_TRANSFER_ENCODING_CHUNKED
190: } transfer_encoding;
191: } response;
192:
193: typedef struct {
194: buffer *scheme; /* scheme without colon or slashes ( "http" or "https" ) */
195:
196: /* authority with optional portnumber ("site.name" or "site.name:8080" ) NOTE: without "username:password@" */
197: buffer *authority;
198:
199: /* path including leading slash ("/" or "/index.html") - urldecoded, and sanitized ( buffer_path_simplify() && buffer_urldecode_path() ) */
200: buffer *path;
201: buffer *path_raw; /* raw path, as sent from client. no urldecoding or path simplifying */
202: buffer *query; /* querystring ( everything after "?", ie: in "/index.php?foo=1", query is "foo=1" ) */
203: } request_uri;
204:
205: typedef struct {
206: buffer *path;
207: buffer *basedir; /* path = "(basedir)(.*)" */
208:
209: buffer *doc_root; /* path = doc_root + rel_path */
210: buffer *rel_path;
211:
212: buffer *etag;
213: } physical;
214:
215: typedef struct {
216: buffer *name;
217: buffer *etag;
218:
219: struct stat st;
220:
221: time_t stat_ts;
222:
223: #ifdef HAVE_LSTAT
224: char is_symlink;
225: #endif
226:
227: #ifdef HAVE_FAM_H
228: int dir_version;
229: #endif
230:
231: buffer *content_type;
232: } stat_cache_entry;
233:
234: typedef struct {
235: splay_tree *files; /* the nodes of the tree are stat_cache_entry's */
236:
237: buffer *dir_name; /* for building the dirname from the filename */
238: #ifdef HAVE_FAM_H
239: splay_tree *dirs; /* the nodes of the tree are fam_dir_entry */
240:
1.1.1.2 misho 241: FAMConnection fam;
1.1 misho 242: int fam_fcce_ndx;
243: #endif
244: buffer *hash_key; /* temp-store for the hash-key */
245: } stat_cache;
246:
247: typedef struct {
248: array *mimetypes;
249:
250: /* virtual-servers */
251: buffer *document_root;
252: buffer *server_name;
253: buffer *error_handler;
1.1.1.3 ! misho 254: buffer *error_handler_404;
1.1 misho 255: buffer *server_tag;
256: buffer *dirlist_encoding;
257: buffer *errorfile_prefix;
258:
1.1.1.3 ! misho 259: unsigned short high_precision_timestamps;
1.1 misho 260: unsigned short max_keep_alive_requests;
261: unsigned short max_keep_alive_idle;
262: unsigned short max_read_idle;
263: unsigned short max_write_idle;
264: unsigned short use_xattr;
265: unsigned short follow_symlink;
266: unsigned short range_requests;
1.1.1.3 ! misho 267: unsigned short stream_request_body;
! 268: unsigned short stream_response_body;
1.1 misho 269:
270: /* debug */
271:
272: unsigned short log_file_not_found;
273: unsigned short log_request_header;
274: unsigned short log_request_handling;
275: unsigned short log_response_header;
276: unsigned short log_condition_handling;
277: unsigned short log_ssl_noise;
278: unsigned short log_timeouts;
279:
280:
281: /* server wide */
282: buffer *ssl_pemfile;
283: buffer *ssl_ca_file;
284: buffer *ssl_cipher_list;
285: buffer *ssl_dh_file;
286: buffer *ssl_ec_curve;
287: unsigned short ssl_honor_cipher_order; /* determine SSL cipher in server-preferred order, not client-order */
288: unsigned short ssl_empty_fragments; /* whether to not set SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS */
289: unsigned short ssl_use_sslv2;
290: unsigned short ssl_use_sslv3;
291: unsigned short ssl_verifyclient;
292: unsigned short ssl_verifyclient_enforce;
293: unsigned short ssl_verifyclient_depth;
294: buffer *ssl_verifyclient_username;
295: unsigned short ssl_verifyclient_export_cert;
296: unsigned short ssl_disable_client_renegotiation;
297:
298: unsigned short use_ipv6, set_v6only; /* set_v6only is only a temporary option */
299: unsigned short defer_accept;
300: unsigned short ssl_enabled; /* only interesting for setting up listening sockets. don't use at runtime */
301: unsigned short allow_http11;
302: unsigned short etag_use_inode;
303: unsigned short etag_use_mtime;
304: unsigned short etag_use_size;
305: unsigned short force_lowercase_filenames; /* if the FS is case-insensitive, force all files to lower-case */
1.1.1.3 ! misho 306: unsigned int http_parseopts;
1.1 misho 307: unsigned int max_request_size;
1.1.1.3 ! misho 308: int listen_backlog;
1.1 misho 309:
310: unsigned short kbytes_per_second; /* connection kb/s limit */
311:
312: /* configside */
313: unsigned short global_kbytes_per_second; /* */
314:
315: off_t global_bytes_per_second_cnt;
316: /* server-wide traffic-shaper
317: *
318: * each context has the counter which is inited once
319: * a second by the global_kbytes_per_second config-var
320: *
321: * as soon as global_kbytes_per_second gets below 0
322: * the connected conns are "offline" a little bit
323: *
324: * the problem:
325: * we somehow have to loose our "we are writable" signal
326: * on the way.
327: *
328: */
329: off_t *global_bytes_per_second_cnt_ptr; /* */
330:
1.1.1.3 ! misho 331: #if defined(__FreeBSD__) || defined(__NetBSD__) \
! 332: || defined(__OpenBSD__) || defined(__DragonflyBSD__)
! 333: buffer *bsd_accept_filter;
! 334: #endif
! 335:
1.1 misho 336: #ifdef USE_OPENSSL
1.1.1.2 misho 337: SSL_CTX *ssl_ctx; /* not patched */
338: /* SNI per host: with COMP_SERVER_SOCKET, COMP_HTTP_SCHEME, COMP_HTTP_HOST */
339: EVP_PKEY *ssl_pemfile_pkey;
340: X509 *ssl_pemfile_x509;
341: STACK_OF(X509_NAME) *ssl_ca_file_cert_names;
1.1 misho 342: #endif
343: } specific_config;
344:
345: /* the order of the items should be the same as they are processed
346: * read before write as we use this later */
347: typedef enum {
348: CON_STATE_CONNECT,
349: CON_STATE_REQUEST_START,
350: CON_STATE_READ,
351: CON_STATE_REQUEST_END,
352: CON_STATE_READ_POST,
353: CON_STATE_HANDLE_REQUEST,
354: CON_STATE_RESPONSE_START,
355: CON_STATE_WRITE,
356: CON_STATE_RESPONSE_END,
357: CON_STATE_ERROR,
358: CON_STATE_CLOSE
359: } connection_state_t;
360:
1.1.1.3 ! misho 361: typedef enum {
! 362: /* condition not active at the moment because itself or some
! 363: * pre-condition depends on data not available yet
! 364: */
! 365: COND_RESULT_UNSET,
! 366:
! 367: /* special "unset" for branches not selected due to pre-conditions
! 368: * not met (but pre-conditions are not "unset" anymore)
! 369: */
! 370: COND_RESULT_SKIP,
! 371:
! 372: /* actually evaluated the condition itself */
! 373: COND_RESULT_FALSE, /* not active */
! 374: COND_RESULT_TRUE, /* active */
! 375: } cond_result_t;
! 376:
1.1 misho 377: typedef struct {
1.1.1.3 ! misho 378: /* current result (with preconditions) */
1.1 misho 379: cond_result_t result;
1.1.1.3 ! misho 380: /* result without preconditions (must never be "skip") */
! 381: cond_result_t local_result;
1.1 misho 382: int patterncount;
383: int matches[3 * 10];
384: buffer *comp_value; /* just a pointer */
385: } cond_cache_t;
386:
387: typedef struct {
388: connection_state_t state;
389:
390: /* timestamps */
391: time_t read_idle_ts;
392: time_t close_timeout_ts;
393: time_t write_request_ts;
394:
395: time_t connection_start;
396: time_t request_start;
1.1.1.3 ! misho 397: struct timespec request_start_hp;
1.1 misho 398:
399: size_t request_count; /* number of requests handled in this connection */
400: size_t loops_per_request; /* to catch endless loops in a single request
401: *
402: * used by mod_rewrite, mod_fastcgi, ... and others
403: * this is self-protection
404: */
405:
406: int fd; /* the FD for this connection */
407: int fde_ndx; /* index for the fdevent-handler */
408: int ndx; /* reverse mapping to server->connection[ndx] */
409:
410: /* fd states */
411: int is_readable;
412: int is_writable;
413:
414: int keep_alive; /* only request.c can enable it, all other just disable */
415: int keep_alive_idle; /* remember max_keep_alive_idle from config */
416:
417: int file_started;
418: int file_finished;
419:
420: chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
421: chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */
422: chunkqueue *request_content_queue; /* takes request-content into tempfile if necessary [ tempfile, mem ]*/
423:
424: int traffic_limit_reached;
425:
426: off_t bytes_written; /* used by mod_accesslog, mod_rrd */
427: off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
428: off_t bytes_read; /* used by mod_accesslog, mod_rrd */
429: off_t bytes_header;
430:
431: int http_status;
432:
433: sock_addr dst_addr;
434: buffer *dst_addr_buf;
435:
436: /* request */
437: buffer *parse_request;
438: unsigned int parsed_response; /* bitfield which contains the important header-fields of the parsed response header */
439:
440: request request;
441: request_uri uri;
442: physical physical;
443: response response;
444:
445: size_t header_len;
446:
447: array *environment; /* used to pass lighttpd internal stuff to the FastCGI/CGI apps, setenv does that */
448:
449: /* response */
450: int got_response;
451:
452: int in_joblist;
453:
454: connection_type mode;
455:
456: void **plugin_ctx; /* plugin connection specific config */
457:
458: specific_config conf; /* global connection specific config */
459: cond_cache_t *cond_cache;
460:
461: buffer *server_name;
462:
463: /* error-handler */
464: int error_handler_saved_status;
1.1.1.3 ! misho 465: http_method_t error_handler_saved_method;
1.1 misho 466:
467: struct server_socket *srv_socket; /* reference to the server-socket */
468:
469: #ifdef USE_OPENSSL
470: SSL *ssl;
471: # ifndef OPENSSL_NO_TLSEXT
472: buffer *tlsext_server_name;
473: # endif
474: unsigned int renegotiations; /* count of SSL_CB_HANDSHAKE_START */
475: #endif
476: /* etag handling */
477: etag_flags_t etag_flags;
478:
479: int conditional_is_valid[COMP_LAST_ELEMENT];
480: } connection;
481:
482: typedef struct {
483: connection **ptr;
484: size_t size;
485: size_t used;
486: } connections;
487:
488:
489: #ifdef HAVE_IPV6
490: typedef struct {
491: int family;
492: union {
493: struct in6_addr ipv6;
494: struct in_addr ipv4;
495: } addr;
496: char b2[INET6_ADDRSTRLEN + 1];
497: time_t ts;
498: } inet_ntop_cache_type;
499: #endif
500:
501:
502: typedef struct {
503: buffer *uri;
504: time_t mtime;
505: int http_status;
506: } realpath_cache_type;
507:
508: typedef struct {
509: time_t mtime; /* the key */
510: buffer *str; /* a buffer for the string represenation */
511: } mtime_cache_type;
512:
513: typedef struct {
514: void *ptr;
515: size_t used;
516: size_t size;
517: } buffer_plugin;
518:
519: typedef struct {
520: unsigned short port;
521: buffer *bindhost;
522:
523: buffer *errorlog_file;
524: unsigned short errorlog_use_syslog;
525: buffer *breakagelog_file;
526:
527: unsigned short dont_daemonize;
1.1.1.3 ! misho 528: unsigned short preflight_check;
1.1 misho 529: buffer *changeroot;
530: buffer *username;
531: buffer *groupname;
532:
533: buffer *pid_file;
534:
535: buffer *event_handler;
536:
537: buffer *modules_dir;
538: buffer *network_backend;
539: array *modules;
540: array *upload_tempdirs;
1.1.1.3 ! misho 541: unsigned int upload_temp_file_size;
1.1 misho 542:
543: unsigned short max_worker;
544: unsigned short max_fds;
545: unsigned short max_conns;
546:
547: unsigned short log_request_header_on_error;
548: unsigned short log_state_handling;
549:
550: enum { STAT_CACHE_ENGINE_UNSET,
551: STAT_CACHE_ENGINE_NONE,
552: STAT_CACHE_ENGINE_SIMPLE
553: #ifdef HAVE_FAM_H
554: , STAT_CACHE_ENGINE_FAM
555: #endif
556: } stat_cache_engine;
557: unsigned short enable_cores;
558: unsigned short reject_expect_100_with_417;
1.1.1.3 ! misho 559: buffer *xattr_name;
! 560:
! 561: unsigned short http_header_strict;
! 562: unsigned short http_host_strict;
! 563: unsigned short http_host_normalize;
! 564: unsigned short high_precision_timestamps;
1.1 misho 565: } server_config;
566:
567: typedef struct server_socket {
568: sock_addr addr;
569: int fd;
570: int fde_ndx;
571:
572: unsigned short is_ssl;
573:
574: buffer *srv_token;
575:
576: #ifdef USE_OPENSSL
577: SSL_CTX *ssl_ctx;
578: #endif
579: } server_socket;
580:
581: typedef struct {
582: server_socket **ptr;
583:
584: size_t size;
585: size_t used;
586: } server_socket_array;
587:
588: typedef struct server {
589: server_socket_array srv_sockets;
590:
591: /* the errorlog */
592: int errorlog_fd;
593: enum { ERRORLOG_FILE, ERRORLOG_FD, ERRORLOG_SYSLOG, ERRORLOG_PIPE } errorlog_mode;
594: buffer *errorlog_buf;
595:
596: fdevents *ev, *ev_ins;
597:
598: buffer_plugin plugins;
599: void *plugin_slots;
600:
601: /* counters */
602: int con_opened;
603: int con_read;
604: int con_written;
605: int con_closed;
606:
607: int ssl_is_init;
608:
609: int max_fds; /* max possible fds */
610: int cur_fds; /* currently used fds */
611: int want_fds; /* waiting fds */
612: int sockets_disabled;
613:
614: size_t max_conns;
615:
616: /* buffers */
617: buffer *parse_full_path;
618: buffer *response_header;
619: buffer *response_range;
620: buffer *tmp_buf;
621:
622: buffer *tmp_chunk_len;
623:
624: buffer *empty_string; /* is necessary for cond_match */
625:
626: buffer *cond_check_buf;
627:
628: /* caches */
629: #ifdef HAVE_IPV6
630: inet_ntop_cache_type inet_ntop_cache[INET_NTOP_CACHE_MAX];
631: #endif
632: mtime_cache_type mtime_cache[FILE_CACHE_MAX];
633:
634: array *split_vals;
635:
636: /* Timestamps */
637: time_t cur_ts;
638: time_t last_generated_date_ts;
639: time_t last_generated_debug_ts;
640: time_t startup_ts;
641:
642: char entropy[8]; /* from /dev/[u]random if possible, otherwise rand() */
643: char is_real_entropy; /* whether entropy is from /dev/[u]random */
644:
645: buffer *ts_debug_str;
646: buffer *ts_date_str;
647:
648: /* config-file */
649: array *config_touched;
650:
651: array *config_context;
652: specific_config **config_storage;
653:
654: server_config srvconf;
655:
656: short int config_deprecated;
657: short int config_unsupported;
658:
659: connections *conns;
660: connections *joblist;
661: connections *fdwaitqueue;
662:
663: stat_cache *stat_cache;
664:
665: /**
666: * The status array can carry all the status information you want
667: * the key to the array is <module-prefix>.<name>
668: * and the values are counters
669: *
670: * example:
671: * fastcgi.backends = 10
672: * fastcgi.active-backends = 6
673: * fastcgi.backend.<key>.load = 24
674: * fastcgi.backend.<key>....
675: *
676: * fastcgi.backend.<key>.disconnects = ...
677: */
678: array *status;
679:
680: fdevent_handler_t event_handler;
681:
682: int (* network_backend_write)(struct server *srv, connection *con, int fd, chunkqueue *cq, off_t max_bytes);
683: #ifdef USE_OPENSSL
684: int (* network_ssl_backend_write)(struct server *srv, connection *con, SSL *ssl, chunkqueue *cq, off_t max_bytes);
685: #endif
686:
687: uid_t uid;
688: gid_t gid;
689: } server;
690:
691:
692: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>