xref: /lighttpd1.4/src/base.h (revision 34709192)
1 #ifndef _BASE_H_
2 #define _BASE_H_
3 #include "first.h"
4 
5 #include <sys/types.h>
6 #include <sys/time.h>
7 
8 #if defined(__APPLE__) && defined(__MACH__)
9 #if __ENVIRONMENT_MAC_OS_X_VERSION_MIN_REQUIRED__ < 1050
10 #include <time.h>
11 #endif
12 #endif
13 
14 #include "base_decls.h"
15 #include "buffer.h"
16 #include "array.h"
17 #include "chunk.h"
18 #include "http_kv.h"
19 #include "request.h"
20 #include "sock_addr.h"
21 
22 struct fdevents;        /* declaration */
23 
24 
25 struct connection {
26 
27 	request_st request;
28 
29 	int fd;                      /* the FD for this connection */
30 	int ndx;                     /* reverse mapping to server->connection[ndx] */
31 	fdnode *fdn;                 /* fdevent (fdnode *) object */
32 
33 	/* fd states */
34 	signed char is_readable;
35 	signed char is_writable;
36 	char is_ssl_sock;
37 	char traffic_limit_reached;
38 
39 	chunkqueue *write_queue;      /* a large queue for low-level write ( HTTP response ) [ file, mem ] */
40 	chunkqueue *read_queue;       /* a small queue for low-level read ( HTTP request ) [ mem ] */
41 
42 	off_t bytes_written;          /* used by mod_accesslog, mod_rrd */
43 	off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */
44 	off_t bytes_read;             /* used by mod_accesslog, mod_rrd */
45 
46 	int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes);
47 	int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes);
48 
49 	server *srv;
50 	void *plugin_slots;
51 	void **plugin_ctx;           /* plugin connection specific config */
52 	void *config_data_base;
53 
54 	sock_addr dst_addr;
55 	buffer *dst_addr_buf;
56 	struct server_socket *srv_socket;   /* reference to the server-socket */
57 
58 	/* timestamps */
59 	time_t read_idle_ts;
60 	time_t close_timeout_ts;
61 	time_t write_request_ts;
62 
63 	time_t connection_start;
64 	uint32_t request_count;      /* number of requests handled in this connection */
65 	int keep_alive_idle;         /* remember max_keep_alive_idle from config */
66 
67 	uint16_t proto_default_port;
68 };
69 
70 typedef struct {
71 	connection **ptr;
72 	uint32_t size;
73 	uint32_t used;
74 } connections;
75 
76 typedef struct {
77 	void *ptr;
78 	uint32_t used;
79 	uint32_t size;
80 } buffer_plugin;
81 
82 typedef struct {
83 	/*(used sparsely, if at all, after config at startup)*/
84 
85 	uint32_t max_request_field_size;
86 	unsigned char log_state_handling;
87 	unsigned char log_request_header_on_error;
88 	unsigned char http_header_strict;
89 	unsigned char http_host_strict;
90 	unsigned char http_host_normalize;
91 	unsigned char http_method_get_body;
92 	unsigned char high_precision_timestamps;
93 	unsigned short http_url_normalize;
94 
95 	unsigned short max_worker;
96 	unsigned short max_fds;
97 	unsigned short max_conns;
98 	unsigned short port;
99 
100 	unsigned int upload_temp_file_size;
101 	array *upload_tempdirs;
102 
103 	unsigned char dont_daemonize;
104 	unsigned char preflight_check;
105 	unsigned char enable_cores;
106 	unsigned char compat_module_load;
107 	unsigned char config_deprecated;
108 	unsigned char config_unsupported;
109 	unsigned char systemd_socket_activation;
110 	unsigned char errorlog_use_syslog;
111 	const buffer *syslog_facility;
112 	const buffer *bindhost;
113 	const buffer *changeroot;
114 	const buffer *username;
115 	const buffer *groupname;
116 	const buffer *network_backend;
117 	const array *feature_flags;
118 	const char *event_handler;
119 	buffer *pid_file;
120 	buffer *modules_dir;
121 	array *modules;
122 	array *config_touched;
123 	array empty_array;
124 } server_config;
125 
126 typedef struct server_socket {
127 	sock_addr addr;
128 	int       fd;
129 
130 	unsigned short is_ssl;
131 	unsigned short sidx;
132 
133 	fdnode *fdn;
134 	server *srv;
135 	buffer *srv_token;
136 } server_socket;
137 
138 typedef struct {
139 	server_socket **ptr;
140 
141 	uint32_t size;
142 	uint32_t used;
143 } server_socket_array;
144 
145 struct server {
146 	void *plugin_slots;
147 	array *config_context;
148 
149 	struct fdevents *ev;
150 	int (* network_backend_write)(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh);
151 	handler_t (* request_env)(request_st *r);
152 
153 	/* buffers */
154 	buffer *tmp_buf;
155 
156 	connections conns;
157 	connections joblist;
158 	connections fdwaitqueue;
159 
160 	/* counters */
161 	int con_opened;
162 	int con_read;
163 	int con_written;
164 	int con_closed;
165 
166 	int max_fds;    /* max possible fds */
167 	int max_fds_lowat;/* low  watermark */
168 	int max_fds_hiwat;/* high watermark */
169 	int cur_fds;    /* currently used fds */
170 	int sockets_disabled;
171 
172 	uint32_t max_conns;
173 
174 	log_error_st *errh;
175 
176 	time_t loadts;
177 	double loadavg[3];
178 
179 	/* members used at start-up or rarely used */
180 
181 	server_config srvconf;
182 	void *config_data_base;
183 
184 	server_socket_array srv_sockets;
185 	server_socket_array srv_sockets_inherited;
186 	buffer_plugin plugins;
187 
188 	time_t startup_ts;
189 
190 	uid_t uid;
191 	gid_t gid;
192 	pid_t pid;
193 	int stdin_fd;
194 };
195 
196 
197 #endif
198