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_cur_second; /* used by rate-limiting and mod_status */ 40 41 int (* network_write)(struct connection *con, chunkqueue *cq, off_t max_bytes); 42 int (* network_read)(struct connection *con, chunkqueue *cq, off_t max_bytes); 43 handler_t (* reqbody_read)(struct request_st *r); 44 45 server *srv; 46 void *plugin_slots; 47 void **plugin_ctx; /* plugin connection specific config */ 48 void *config_data_base; 49 50 sock_addr dst_addr; 51 buffer dst_addr_buf; 52 const struct server_socket *srv_socket; /* reference to the server-socket */ 53 54 /* timestamps */ 55 unix_time64_t read_idle_ts; 56 unix_time64_t close_timeout_ts; 57 unix_time64_t write_request_ts; 58 unix_time64_t connection_start; 59 60 uint32_t request_count; /* number of requests handled in this connection */ 61 int keep_alive_idle; /* remember max_keep_alive_idle from config */ 62 63 connection *next; 64 connection *prev; 65 }; 66 67 /* log_con_jqueue is in log.c to be defined in shared object */ 68 #define joblist_append(con) connection_jq_append(con) 69 extern connection *log_con_jqueue; 70 static inline void connection_jq_append(connection * const restrict con); 71 static inline void connection_jq_append(connection * const restrict con) 72 { 73 if (!con->jqnext) { 74 con->jqnext = log_con_jqueue; 75 log_con_jqueue = con; 76 } 77 } 78 79 typedef struct { 80 /*(used sparsely, if at all, after config at startup)*/ 81 82 uint32_t max_request_field_size; 83 unsigned char log_request_header_on_error; 84 unsigned char http_header_strict; 85 unsigned char http_host_strict; 86 unsigned char http_host_normalize; 87 unsigned char http_method_get_body; 88 unsigned char high_precision_timestamps; 89 unsigned char h2proto; 90 unsigned char absolute_dir_redirect; 91 unsigned short http_url_normalize; 92 93 unsigned short max_worker; 94 unsigned short max_fds; 95 unsigned short max_conns; 96 unsigned short port; 97 98 unsigned int upload_temp_file_size; 99 array *upload_tempdirs; 100 101 unsigned char dont_daemonize; 102 unsigned char preflight_check; 103 unsigned char enable_cores; 104 unsigned char compat_module_load; 105 unsigned char config_deprecated; 106 unsigned char config_unsupported; 107 unsigned char systemd_socket_activation; 108 unsigned char errorlog_use_syslog; 109 const buffer *syslog_facility; 110 const buffer *bindhost; 111 const buffer *changeroot; 112 const buffer *username; 113 const buffer *groupname; 114 const buffer *network_backend; 115 const array *feature_flags; 116 const char *event_handler; 117 const char *modules_dir; 118 buffer *pid_file; 119 array *modules; 120 array *config_touched; 121 array empty_array; 122 } server_config; 123 124 typedef struct server_socket { 125 sock_addr addr; 126 int fd; 127 128 uint8_t is_ssl; 129 uint8_t srv_token_colon; 130 unsigned short sidx; 131 132 fdnode *fdn; 133 server *srv; 134 buffer *srv_token; 135 } server_socket; 136 137 typedef struct { 138 server_socket **ptr; 139 140 uint32_t size; 141 uint32_t used; 142 } server_socket_array; 143 144 struct server { 145 void *plugin_slots; 146 array *config_context; 147 int config_captures; 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 int max_fds; /* max possible fds */ 157 int max_fds_lowat;/* low watermark */ 158 int max_fds_hiwat;/* high watermark */ 159 int cur_fds; /* currently used fds */ 160 int sockets_disabled; 161 162 uint32_t lim_conns; 163 connection *conns; 164 connection *conns_pool; 165 166 log_error_st *errh; 167 168 unix_time64_t loadts; 169 double loadavg[3]; 170 171 /* members used at start-up or rarely used */ 172 173 handler_t (* plugins_request_reset)(request_st *r);/*(for cgi.local-redir)*/ 174 175 server_config srvconf; 176 void *config_data_base; 177 178 server_socket_array srv_sockets; 179 server_socket_array srv_sockets_inherited; 180 struct { void *ptr; uint32_t used; uint32_t size; } plugins; 181 182 unix_time64_t startup_ts; 183 unix_time64_t graceful_expire_ts; 184 185 uid_t uid; 186 gid_t gid; 187 pid_t pid; 188 int stdin_fd; 189 190 const buffer *default_server_tag; 191 char **argv; 192 #ifdef HAVE_PCRE2_H 193 void *match_data; /*(shared and reused)*/ 194 #endif 195 }; 196 197 198 #endif 199