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