1 #ifndef _BASE_H_ 2 #define _BASE_H_ 3 #include "first.h" 4 5 #include "sys-time.h" 6 7 #include "base_decls.h" 8 #include "buffer.h" 9 #include "array.h" 10 #include "chunk.h" 11 #include "http_kv.h" 12 #include "request.h" 13 #include "sock_addr.h" 14 15 struct fdevents; /* declaration */ 16 struct server_socket; /* declaration */ 17 18 19 struct connection { 20 21 request_st request; 22 h2con *h2; 23 24 int fd; /* the FD for this connection */ 25 fdnode *fdn; /* fdevent (fdnode *) object */ 26 connection *jqnext; 27 28 /* fd states */ 29 signed char is_readable; 30 signed char is_writable; 31 char is_ssl_sock; 32 char traffic_limit_reached; 33 uint16_t revents_err; 34 uint16_t proto_default_port; 35 36 chunkqueue *write_queue; /* a large queue for low-level write ( HTTP response ) [ file, mem ] */ 37 chunkqueue *read_queue; /* a small queue for low-level read ( HTTP request ) [ mem ] */ 38 39 off_t bytes_written; /* used by mod_accesslog, mod_rrd */ 40 off_t bytes_written_cur_second; /* used by mod_accesslog, mod_rrd */ 41 off_t bytes_read; /* used by mod_accesslog, mod_rrd */ 42 43 int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes); 44 int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes); 45 handler_t (* reqbody_read)(struct request_st *r); 46 47 server *srv; 48 void *plugin_slots; 49 void **plugin_ctx; /* plugin connection specific config */ 50 void *config_data_base; 51 52 sock_addr dst_addr; 53 buffer dst_addr_buf; 54 const struct server_socket *srv_socket; /* reference to the server-socket */ 55 56 /* timestamps */ 57 unix_time64_t read_idle_ts; 58 unix_time64_t close_timeout_ts; 59 unix_time64_t write_request_ts; 60 unix_time64_t connection_start; 61 62 uint32_t request_count; /* number of requests handled in this connection */ 63 int keep_alive_idle; /* remember max_keep_alive_idle from config */ 64 65 connection *next; 66 connection *prev; 67 }; 68 69 /* log_con_jqueue is in log.c to be defined in shared object */ 70 #define joblist_append(con) connection_jq_append(con) 71 extern connection *log_con_jqueue; 72 static inline void connection_jq_append(connection * const restrict con); 73 static inline void connection_jq_append(connection * const restrict con) 74 { 75 if (!con->jqnext) { 76 con->jqnext = log_con_jqueue; 77 log_con_jqueue = con; 78 } 79 } 80 81 typedef struct { 82 /*(used sparsely, if at all, after config at startup)*/ 83 84 uint32_t max_request_field_size; 85 unsigned char log_request_header_on_error; 86 unsigned char http_header_strict; 87 unsigned char http_host_strict; 88 unsigned char http_host_normalize; 89 unsigned char http_method_get_body; 90 unsigned char high_precision_timestamps; 91 unsigned char h2proto; 92 unsigned char absolute_dir_redirect; 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 uint8_t is_ssl; 131 uint8_t srv_token_colon; 132 unsigned short sidx; 133 134 fdnode *fdn; 135 server *srv; 136 buffer *srv_token; 137 } server_socket; 138 139 typedef struct { 140 server_socket **ptr; 141 142 uint32_t size; 143 uint32_t used; 144 } server_socket_array; 145 146 struct server { 147 void *plugin_slots; 148 array *config_context; 149 int config_captures; 150 151 struct fdevents *ev; 152 int (* network_backend_write)(int fd, chunkqueue *cq, off_t max_bytes, log_error_st *errh); 153 handler_t (* request_env)(request_st *r); 154 155 /* buffers */ 156 buffer *tmp_buf; 157 158 /* counters */ 159 int con_opened; 160 int con_read; 161 int con_written; 162 int con_closed; 163 164 int max_fds; /* max possible fds */ 165 int max_fds_lowat;/* low watermark */ 166 int max_fds_hiwat;/* high watermark */ 167 int cur_fds; /* currently used fds */ 168 int sockets_disabled; 169 170 uint32_t lim_conns; 171 connection *conns; 172 connection *conns_pool; 173 174 log_error_st *errh; 175 176 unix_time64_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 struct { void *ptr; uint32_t used; uint32_t size; } plugins; 187 188 unix_time64_t startup_ts; 189 unix_time64_t graceful_expire_ts; 190 191 uid_t uid; 192 gid_t gid; 193 pid_t pid; 194 int stdin_fd; 195 196 char **argv; 197 #ifdef HAVE_PCRE2_H 198 void *match_data; /*(shared and reused)*/ 199 #endif 200 }; 201 202 203 #endif 204