| 1 | /* |
| 2 | * libwebsockets - small server side websockets and web server implementation |
| 3 | * |
| 4 | * Copyright (C) 2010 - 2021 Andy Green <andy@warmcat.com> |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | * of this software and associated documentation files (the "Software"), to |
| 8 | * deal in the Software without restriction, including without limitation the |
| 9 | * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
| 10 | * sell copies of the Software, and to permit persons to whom the Software is |
| 11 | * furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice shall be included in |
| 14 | * all copies or substantial portions of the Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 21 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 22 | * IN THE SOFTWARE. |
| 23 | */ |
| 24 | |
| 25 | /*! \defgroup context-and-vhost context and vhost related functions |
| 26 | * ##Context and Vhost releated functions |
| 27 | * \ingroup lwsapi |
| 28 | * |
| 29 | * |
| 30 | * LWS requires that there is one context, in which you may define multiple |
| 31 | * vhosts. Each vhost is a virtual host, with either its own listen port |
| 32 | * or sharing an existing one. Each vhost has its own SSL context that can |
| 33 | * be set up individually or left disabled. |
| 34 | * |
| 35 | * If you don't care about multiple "site" support, you can ignore it and |
| 36 | * lws will create a single default vhost at context creation time. |
| 37 | */ |
| 38 | ///@{ |
| 39 | |
| 40 | /* |
| 41 | * NOTE: These public enums are part of the abi. If you want to add one, |
| 42 | * add it at where specified so existing users are unaffected. |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | #define LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT ((1ll << 1) | \ |
| 47 | (1ll << 12)) |
| 48 | /**< (VH) Don't allow the connection unless the client has a |
| 49 | * client cert that we recognize; provides |
| 50 | * LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT */ |
| 51 | #define LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME (1ll << 2) |
| 52 | /**< (CTX) Don't try to get the server's hostname */ |
| 53 | #define LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT ((1ll << 3) | \ |
| 54 | (1ll << 12)) |
| 55 | /**< (VH) Allow non-SSL (plaintext) connections on the same |
| 56 | * port as SSL is listening. If combined with |
| 57 | * LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS it will try to |
| 58 | * force http connections on an https listener (eg, http://x.com:443) to |
| 59 | * redirect to an explicit https connection (eg, https://x.com) |
| 60 | */ |
| 61 | #define LWS_SERVER_OPTION_LIBEV (1ll << 4) |
| 62 | /**< (CTX) Use libev event loop */ |
| 63 | #define LWS_SERVER_OPTION_DISABLE_IPV6 (1ll << 5) |
| 64 | /**< (VH) Disable IPV6 support */ |
| 65 | #define LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS (1ll << 6) |
| 66 | /**< (VH) Don't load OS CA certs, you will need to load your |
| 67 | * own CA cert(s) */ |
| 68 | #define LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED (1ll << 7) |
| 69 | /**< (VH) Accept connections with no valid Cert (eg, selfsigned) */ |
| 70 | #define LWS_SERVER_OPTION_VALIDATE_UTF8 (1ll << 8) |
| 71 | /**< (VH) Check UT-8 correctness */ |
| 72 | #define LWS_SERVER_OPTION_SSL_ECDH ((1ll << 9) | \ |
| 73 | (1ll << 12)) |
| 74 | /**< (VH) initialize ECDH ciphers */ |
| 75 | #define LWS_SERVER_OPTION_LIBUV (1ll << 10) |
| 76 | /**< (CTX) Use libuv event loop */ |
| 77 | #define LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS ((1ll << 11) |\ |
| 78 | (1ll << 12)) |
| 79 | /**< (VH) Use an http redirect to force the client to ask for https. |
| 80 | * Notice if your http server issues the STS header and the client has |
| 81 | * ever seen that, the client will fail the http connection before it |
| 82 | * can actually do the redirect. |
| 83 | * |
| 84 | * Combine with LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS to handle, eg, |
| 85 | * http://x.com:443 -> https://x.com |
| 86 | * |
| 87 | * (deprecated: use mount redirection) */ |
| 88 | #define LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT (1ll << 12) |
| 89 | /**< (CTX) Initialize the SSL library at all */ |
| 90 | #define LWS_SERVER_OPTION_EXPLICIT_VHOSTS (1ll << 13) |
| 91 | /**< (CTX) Only create the context when calling context |
| 92 | * create api, implies user code will create its own vhosts */ |
| 93 | #define LWS_SERVER_OPTION_UNIX_SOCK (1ll << 14) |
| 94 | /**< (VH) Use Unix socket */ |
| 95 | #define LWS_SERVER_OPTION_STS (1ll << 15) |
| 96 | /**< (VH) Send Strict Transport Security header, making |
| 97 | * clients subsequently go to https even if user asked for http */ |
| 98 | #define LWS_SERVER_OPTION_IPV6_V6ONLY_MODIFY (1ll << 16) |
| 99 | /**< (VH) Enable LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE to take effect */ |
| 100 | #define LWS_SERVER_OPTION_IPV6_V6ONLY_VALUE (1ll << 17) |
| 101 | /**< (VH) if set, only ipv6 allowed on the vhost */ |
| 102 | #define LWS_SERVER_OPTION_UV_NO_SIGSEGV_SIGFPE_SPIN (1ll << 18) |
| 103 | /**< (CTX) Libuv only: Do not spin on SIGSEGV / SIGFPE. A segfault |
| 104 | * normally makes the lib spin so you can attach a debugger to it |
| 105 | * even if it happened without a debugger in place. You can disable |
| 106 | * that by giving this option. |
| 107 | */ |
| 108 | #define LWS_SERVER_OPTION_JUST_USE_RAW_ORIGIN (1ll << 19) |
| 109 | /**< For backwards-compatibility reasons, by default |
| 110 | * lws prepends "http://" to the origin you give in the client |
| 111 | * connection info struct. If you give this flag when you create |
| 112 | * the context, only the string you give in the client connect |
| 113 | * info for .origin (if any) will be used directly. |
| 114 | */ |
| 115 | #define LWS_SERVER_OPTION_FALLBACK_TO_RAW /* use below name */ (1ll << 20) |
| 116 | #define LWS_SERVER_OPTION_FALLBACK_TO_APPLY_LISTEN_ACCEPT_CONFIG (1ll << 20) |
| 117 | /**< (VH) if invalid http is coming in the first line, then abandon |
| 118 | * trying to treat the connection as http, and belatedly apply the |
| 119 | * .listen_accept_role / .listen_accept_protocol info struct members to |
| 120 | * the connection. If they are NULL, for backwards-compatibility the |
| 121 | * connection is bound to "raw-skt" role, and in order of priority: |
| 122 | * 1) the vh protocol with a pvo named "raw", 2) the vh protocol with a |
| 123 | * pvo named "default", or 3) protocols[0]. |
| 124 | * |
| 125 | * Must be combined with LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT |
| 126 | * to work with a socket listening with tls. |
| 127 | */ |
| 128 | |
| 129 | #define LWS_SERVER_OPTION_LIBEVENT (1ll << 21) |
| 130 | /**< (CTX) Use libevent event loop */ |
| 131 | |
| 132 | #define LWS_SERVER_OPTION_ONLY_RAW /* Use below name instead */ (1ll << 22) |
| 133 | #define LWS_SERVER_OPTION_ADOPT_APPLY_LISTEN_ACCEPT_CONFIG (1ll << 22) |
| 134 | /**< (VH) All connections to this vhost / port are bound to the |
| 135 | * role and protocol given in .listen_accept_role / |
| 136 | * .listen_accept_protocol. |
| 137 | * |
| 138 | * If those explicit user-controlled names are NULL, for backwards- |
| 139 | * compatibility the connection is bound to "raw-skt" role, and in order |
| 140 | * of priority: 1) the vh protocol with a pvo named "raw", 2) the vh |
| 141 | * protocol with a pvo named "default", or 3) protocols[0]. |
| 142 | * |
| 143 | * It's much preferred to specify the role + protocol using the |
| 144 | * .listen_accept_role and .listen_accept_protocol in the info struct. |
| 145 | */ |
| 146 | #define LWS_SERVER_OPTION_ALLOW_LISTEN_SHARE (1ll << 23) |
| 147 | /**< (VH) Set to allow multiple listen sockets on one interface + |
| 148 | * address + port. The default is to strictly allow only one |
| 149 | * listen socket at a time. This is automatically selected if you |
| 150 | * have multiple service threads. Linux only. |
| 151 | */ |
| 152 | #define LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX (1ll << 24) |
| 153 | /**< (VH) Force setting up the vhost SSL_CTX, even though the user |
| 154 | * code doesn't explicitly provide a cert in the info struct. It |
| 155 | * implies the user code is going to provide a cert at the |
| 156 | * LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS callback, which |
| 157 | * provides the vhost SSL_CTX * in the user parameter. |
| 158 | */ |
| 159 | #define LWS_SERVER_OPTION_SKIP_PROTOCOL_INIT (1ll << 25) |
| 160 | /**< (VH) You probably don't want this. It forces this vhost to not |
| 161 | * call LWS_CALLBACK_PROTOCOL_INIT on its protocols. It's used in the |
| 162 | * special case of a temporary vhost bound to a single protocol. |
| 163 | */ |
| 164 | #define LWS_SERVER_OPTION_IGNORE_MISSING_CERT (1ll << 26) |
| 165 | /**< (VH) Don't fail if the vhost TLS cert or key are missing, just |
| 166 | * continue. The vhost won't be able to serve anything, but if for |
| 167 | * example the ACME plugin was configured to fetch a cert, this lets |
| 168 | * you bootstrap your vhost from having no cert to start with. |
| 169 | */ |
| 170 | #define LWS_SERVER_OPTION_VHOST_UPG_STRICT_HOST_CHECK (1ll << 27) |
| 171 | /**< (VH) On this vhost, if the connection is being upgraded, insist |
| 172 | * that there's a Host: header and that the contents match the vhost |
| 173 | * name + port (443 / 80 are assumed if no :port given based on if the |
| 174 | * connection is using TLS). |
| 175 | * |
| 176 | * By default, without this flag, on upgrade lws just checks that the |
| 177 | * Host: header was given without checking the contents... this is to |
| 178 | * allow lax hostname mappings like localhost / 127.0.0.1, and CNAME |
| 179 | * mappings like www.mysite.com / mysite.com |
| 180 | */ |
| 181 | #define (1ll << 28) |
| 182 | /**< (VH) Send lws default HTTP headers recommended by Mozilla |
| 183 | * Observatory for security. This is a helper option that sends canned |
| 184 | * headers on each http response enabling a VERY strict Content Security |
| 185 | * Policy. The policy is so strict, for example it won't let the page |
| 186 | * run its own inline JS nor show images or take CSS from a different |
| 187 | * server. In many cases your JS only comes from your server as do the |
| 188 | * image sources and CSS, so that is what you want... attackers hoping |
| 189 | * to inject JS into your DOM are completely out of luck since even if |
| 190 | * they succeed, it will be rejected for execution by the browser |
| 191 | * according to the strict CSP. In other cases you have to deviate from |
| 192 | * the complete strictness, in which case don't use this flag: use the |
| 193 | * .headers member in the vhost init described in struct |
| 194 | * lws_context_creation_info instead to send the adapted headers |
| 195 | * yourself. |
| 196 | */ |
| 197 | |
| 198 | #define LWS_SERVER_OPTION_ALLOW_HTTP_ON_HTTPS_LISTENER (1ll << 29) |
| 199 | /**< (VH) If you really want to allow HTTP connections on a tls |
| 200 | * listener, you can do it with this combined with |
| 201 | * LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT. But this is allowing |
| 202 | * accidental loss of the security assurances provided by tls depending |
| 203 | * on the client using http when he meant https... it's not |
| 204 | * recommended. |
| 205 | */ |
| 206 | #define LWS_SERVER_OPTION_FAIL_UPON_UNABLE_TO_BIND (1ll << 30) |
| 207 | /**< (VH) When instantiating a new vhost and the specified port is |
| 208 | * already in use, a null value shall be return to signal the error. |
| 209 | */ |
| 210 | |
| 211 | #define LWS_SERVER_OPTION_H2_JUST_FIX_WINDOW_UPDATE_OVERFLOW (1ll << 31) |
| 212 | /**< (VH) Indicates the connections using this vhost should ignore |
| 213 | * h2 WINDOW_UPDATE from broken peers and fix them up */ |
| 214 | |
| 215 | #define LWS_SERVER_OPTION_VH_H2_HALF_CLOSED_LONG_POLL (1ll << 32) |
| 216 | /**< (VH) Tell the vhost to treat half-closed remote clients as |
| 217 | * entered into an immortal (ie, not subject to normal timeouts) long |
| 218 | * poll mode. |
| 219 | */ |
| 220 | |
| 221 | #define LWS_SERVER_OPTION_GLIB (1ll << 33) |
| 222 | /**< (CTX) Use glib event loop */ |
| 223 | |
| 224 | #define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE (1ll << 34) |
| 225 | /**< (VH) Tell the vhost to treat plain text http connections as |
| 226 | * H2 with prior knowledge (no upgrade request involved) |
| 227 | */ |
| 228 | |
| 229 | #define LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES (1ll << 35) |
| 230 | /**< (CTX) Disable lws_system state, eg, because we are a secure streams |
| 231 | * proxy client that is not trying to track system state by itself. */ |
| 232 | |
| 233 | #define LWS_SERVER_OPTION_SS_PROXY (1ll << 36) |
| 234 | /**< (VH) We are being a SS Proxy listen socket for the vhost */ |
| 235 | |
| 236 | #define LWS_SERVER_OPTION_SDEVENT (1ll << 37) |
| 237 | /**< (CTX) Use sd-event loop */ |
| 238 | |
| 239 | #define LWS_SERVER_OPTION_ULOOP (1ll << 38) |
| 240 | /**< (CTX) Use libubox / uloop event loop */ |
| 241 | |
| 242 | #define LWS_SERVER_OPTION_DISABLE_TLS_SESSION_CACHE (1ll << 39) |
| 243 | /**< (VHOST) Disallow use of client tls caching (on by default) */ |
| 244 | |
| 245 | |
| 246 | /****** add new things just above ---^ ******/ |
| 247 | |
| 248 | |
| 249 | #define lws_check_opt(c, f) ((((uint64_t)c) & ((uint64_t)f)) == ((uint64_t)f)) |
| 250 | |
| 251 | struct lws_plat_file_ops; |
| 252 | struct lws_ss_policy; |
| 253 | struct lws_ss_plugin; |
| 254 | struct lws_metric_policy; |
| 255 | struct lws_sss_ops; |
| 256 | |
| 257 | typedef int (*lws_context_ready_cb_t)(struct lws_context *context); |
| 258 | |
| 259 | #if defined(LWS_WITH_NETWORK) |
| 260 | typedef int (*lws_peer_limits_notify_t)(struct lws_context *ctx, |
| 261 | lws_sockfd_type sockfd, |
| 262 | lws_sockaddr46 *sa46); |
| 263 | #endif |
| 264 | |
| 265 | /** struct lws_context_creation_info - parameters to create context and /or vhost with |
| 266 | * |
| 267 | * This is also used to create vhosts.... if LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
| 268 | * is not given, then for backwards compatibility one vhost is created at |
| 269 | * context-creation time using the info from this struct. |
| 270 | * |
| 271 | * If LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, then no vhosts are created |
| 272 | * at the same time as the context, they are expected to be created afterwards. |
| 273 | */ |
| 274 | struct lws_context_creation_info { |
| 275 | #if defined(LWS_WITH_NETWORK) |
| 276 | const char *iface; |
| 277 | /**< VHOST: NULL to bind the listen socket to all interfaces, or the |
| 278 | * interface name, eg, "eth2" |
| 279 | * If options specifies LWS_SERVER_OPTION_UNIX_SOCK, this member is |
| 280 | * the pathname of a UNIX domain socket. you can use the UNIX domain |
| 281 | * sockets in abstract namespace, by prepending an at symbol to the |
| 282 | * socket name. */ |
| 283 | const struct lws_protocols *protocols; |
| 284 | /**< VHOST: Array of structures listing supported protocols and a |
| 285 | * protocol-specific callback for each one. The list is ended with an |
| 286 | * entry that has a NULL callback pointer. SEE ALSO .pprotocols below, |
| 287 | * which gives an alternative way to provide an array of pointers to |
| 288 | * protocol structs. */ |
| 289 | #if defined(LWS_ROLE_WS) |
| 290 | const struct lws_extension *extensions; |
| 291 | /**< VHOST: NULL or array of lws_extension structs listing the |
| 292 | * extensions this context supports. */ |
| 293 | #endif |
| 294 | #if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2) |
| 295 | const struct lws_token_limits *token_limits; |
| 296 | /**< CONTEXT: NULL or struct lws_token_limits pointer which is |
| 297 | * initialized with a token length limit for each possible WSI_TOKEN_ */ |
| 298 | const char *http_proxy_address; |
| 299 | /**< VHOST: If non-NULL, attempts to proxy via the given address. |
| 300 | * If proxy auth is required, use format |
| 301 | * "username:password\@server:port" */ |
| 302 | const struct lws_protocol_vhost_options *; |
| 303 | /**< VHOST: pointer to optional linked list of per-vhost |
| 304 | * canned headers that are added to server responses */ |
| 305 | |
| 306 | const struct lws_protocol_vhost_options *reject_service_keywords; |
| 307 | /**< CONTEXT: Optional list of keywords and rejection codes + text. |
| 308 | * |
| 309 | * The keywords are checked for existing in the user agent string. |
| 310 | * |
| 311 | * Eg, "badrobot" "404 Not Found" |
| 312 | */ |
| 313 | const struct lws_protocol_vhost_options *pvo; |
| 314 | /**< VHOST: pointer to optional linked list of per-vhost |
| 315 | * options made accessible to protocols */ |
| 316 | const char *log_filepath; |
| 317 | /**< VHOST: filepath to append logs to... this is opened before |
| 318 | * any dropping of initial privileges */ |
| 319 | const struct lws_http_mount *mounts; |
| 320 | /**< VHOST: optional linked list of mounts for this vhost */ |
| 321 | const char *server_string; |
| 322 | /**< CONTEXT: string used in HTTP headers to identify server |
| 323 | * software, if NULL, "libwebsockets". */ |
| 324 | |
| 325 | const char *error_document_404; |
| 326 | /**< VHOST: If non-NULL, when asked to serve a non-existent file, |
| 327 | * lws attempts to server this url path instead. Eg, |
| 328 | * "/404.html" */ |
| 329 | int port; |
| 330 | /**< VHOST: Port to listen on. Use CONTEXT_PORT_NO_LISTEN to suppress |
| 331 | * listening for a client. Use CONTEXT_PORT_NO_LISTEN_SERVER if you are |
| 332 | * writing a server but you are using \ref sock-adopt instead of the |
| 333 | * built-in listener. |
| 334 | * |
| 335 | * You can also set port to 0, in which case the kernel will pick |
| 336 | * a random port that is not already in use. You can find out what |
| 337 | * port the vhost is listening on using lws_get_vhost_listen_port() |
| 338 | * |
| 339 | * If options specifies LWS_SERVER_OPTION_UNIX_SOCK, you should set |
| 340 | * port to 0 */ |
| 341 | |
| 342 | unsigned int http_proxy_port; |
| 343 | /**< VHOST: If http_proxy_address was non-NULL, uses this port */ |
| 344 | unsigned int ; |
| 345 | /**< CONTEXT: if max_http_header_data is 0 and this |
| 346 | * is nonzero, this will be used in place of the default. It's |
| 347 | * like this for compatibility with the original short version, |
| 348 | * this is unsigned int length. */ |
| 349 | unsigned int ; |
| 350 | /**< CONTEXT: if max_http_header_pool is 0 and this |
| 351 | * is nonzero, this will be used in place of the default. It's |
| 352 | * like this for compatibility with the original short version: |
| 353 | * this is unsigned int length. */ |
| 354 | |
| 355 | int keepalive_timeout; |
| 356 | /**< VHOST: (default = 0 = 5s, 31s for http/2) seconds to allow remote |
| 357 | * client to hold on to an idle HTTP/1.1 connection. Timeout lifetime |
| 358 | * applied to idle h2 network connections */ |
| 359 | uint32_t http2_settings[7]; |
| 360 | /**< VHOST: if http2_settings[0] is nonzero, the values given in |
| 361 | * http2_settings[1]..[6] are used instead of the lws |
| 362 | * platform default values. |
| 363 | * Just leave all at 0 if you don't care. |
| 364 | */ |
| 365 | |
| 366 | unsigned short ; |
| 367 | /**< CONTEXT: The max amount of header payload that can be handled |
| 368 | * in an http request (unrecognized header payload is dropped) */ |
| 369 | unsigned short ; |
| 370 | /**< CONTEXT: The max number of connections with http headers that |
| 371 | * can be processed simultaneously (the corresponding memory is |
| 372 | * allocated and deallocated dynamically as needed). If the pool is |
| 373 | * fully busy new incoming connections must wait for accept until one |
| 374 | * becomes free. 0 = allow as many ah as number of availble fds for |
| 375 | * the process */ |
| 376 | |
| 377 | #endif |
| 378 | |
| 379 | #if defined(LWS_WITH_TLS) |
| 380 | const char *ssl_private_key_password; |
| 381 | /**< VHOST: NULL or the passphrase needed for the private key. (For |
| 382 | * backwards compatibility, this can also be used to pass the client |
| 383 | * cert passphrase when setting up a vhost client SSL context, but it is |
| 384 | * preferred to use .client_ssl_private_key_password for that.) */ |
| 385 | const char *ssl_cert_filepath; |
| 386 | /**< VHOST: If libwebsockets was compiled to use ssl, and you want |
| 387 | * to listen using SSL, set to the filepath to fetch the |
| 388 | * server cert from, otherwise NULL for unencrypted. (For backwards |
| 389 | * compatibility, this can also be used to pass the client certificate |
| 390 | * when setting up a vhost client SSL context, but it is preferred to |
| 391 | * use .client_ssl_cert_filepath for that.) |
| 392 | * |
| 393 | * Notice you can alternatively set a single DER or PEM from a memory |
| 394 | * buffer as the vhost tls cert using \p server_ssl_cert_mem and |
| 395 | * \p server_ssl_cert_mem_len. |
| 396 | */ |
| 397 | const char *ssl_private_key_filepath; |
| 398 | /**< VHOST: filepath to private key if wanting SSL mode; |
| 399 | * this should not be set to NULL when ssl_cert_filepath is set. |
| 400 | * |
| 401 | * Alteratively, the certificate and private key can both be set in |
| 402 | * the OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS callback directly via |
| 403 | * openSSL library calls. This requires that |
| 404 | * LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX is set in the vhost info options |
| 405 | * to force initializtion of the SSL_CTX context. |
| 406 | * |
| 407 | * (For backwards compatibility, this can also be used |
| 408 | * to pass the client cert private key filepath when setting up a |
| 409 | * vhost client SSL context, but it is preferred to use |
| 410 | * .client_ssl_private_key_filepath for that.) |
| 411 | * |
| 412 | * Notice you can alternatively set a DER or PEM private key from a |
| 413 | * memory buffer as the vhost tls private key using |
| 414 | * \p server_ssl_private_key_mem and \p server_ssl_private_key_mem_len. |
| 415 | */ |
| 416 | const char *ssl_ca_filepath; |
| 417 | /**< VHOST: CA certificate filepath or NULL. (For backwards |
| 418 | * compatibility, this can also be used to pass the client CA |
| 419 | * filepath when setting up a vhost client SSL context, |
| 420 | * but it is preferred to use .client_ssl_ca_filepath for that.) |
| 421 | * |
| 422 | * Notice you can alternatively set a DER or PEM CA cert from a memory |
| 423 | * buffer using \p server_ssl_ca_mem and \p server_ssl_ca_mem_len. |
| 424 | */ |
| 425 | const char *ssl_cipher_list; |
| 426 | /**< VHOST: List of valid ciphers to use ON TLS1.2 AND LOWER ONLY (eg, |
| 427 | * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" |
| 428 | * or you can leave it as NULL to get "DEFAULT" (For backwards |
| 429 | * compatibility, this can also be used to pass the client cipher |
| 430 | * list when setting up a vhost client SSL context, |
| 431 | * but it is preferred to use .client_ssl_cipher_list for that.) |
| 432 | * SEE .tls1_3_plus_cipher_list and .client_tls_1_3_plus_cipher_list |
| 433 | * for the equivalent for tls1.3. |
| 434 | */ |
| 435 | const char *ecdh_curve; |
| 436 | /**< VHOST: if NULL, defaults to initializing server with |
| 437 | * "prime256v1" */ |
| 438 | const char *tls1_3_plus_cipher_list; |
| 439 | /**< VHOST: List of valid ciphers to use for incoming server connections |
| 440 | * ON TLS1.3 AND ABOVE (eg, "TLS_CHACHA20_POLY1305_SHA256" on this vhost |
| 441 | * or you can leave it as NULL to get "DEFAULT". |
| 442 | * SEE .client_tls_1_3_plus_cipher_list to do the same on the vhost |
| 443 | * client SSL_CTX. |
| 444 | */ |
| 445 | |
| 446 | const void *server_ssl_cert_mem; |
| 447 | /**< VHOST: Alternative for \p ssl_cert_filepath that allows setting |
| 448 | * from memory instead of from a file. At most one of |
| 449 | * \p ssl_cert_filepath or \p server_ssl_cert_mem should be non-NULL. */ |
| 450 | const void *server_ssl_private_key_mem; |
| 451 | /**< VHOST: Alternative for \p ssl_private_key_filepath allowing |
| 452 | * init from a private key in memory instead of a file. At most one |
| 453 | * of \p ssl_private_key_filepath or \p server_ssl_private_key_mem |
| 454 | * should be non-NULL. */ |
| 455 | const void *server_ssl_ca_mem; |
| 456 | /**< VHOST: Alternative for \p ssl_ca_filepath allowing |
| 457 | * init from a CA cert in memory instead of a file. At most one |
| 458 | * of \p ssl_ca_filepath or \p server_ssl_ca_mem should be non-NULL. */ |
| 459 | |
| 460 | long ssl_options_set; |
| 461 | /**< VHOST: Any bits set here will be set as server SSL options */ |
| 462 | long ssl_options_clear; |
| 463 | /**< VHOST: Any bits set here will be cleared as server SSL options */ |
| 464 | int simultaneous_ssl_restriction; |
| 465 | /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL sessions |
| 466 | * possible.*/ |
| 467 | int simultaneous_ssl_handshake_restriction; |
| 468 | /**< CONTEXT: 0 (no limit) or limit of simultaneous SSL handshakes ongoing */ |
| 469 | int ssl_info_event_mask; |
| 470 | /**< VHOST: mask of ssl events to be reported on LWS_CALLBACK_SSL_INFO |
| 471 | * callback for connections on this vhost. The mask values are of |
| 472 | * the form SSL_CB_ALERT, defined in openssl/ssl.h. The default of |
| 473 | * 0 means no info events will be reported. |
| 474 | */ |
| 475 | unsigned int server_ssl_cert_mem_len; |
| 476 | /**< VHOST: Server SSL context init: length of server_ssl_cert_mem in |
| 477 | * bytes */ |
| 478 | unsigned int server_ssl_private_key_mem_len; |
| 479 | /**< VHOST: length of \p server_ssl_private_key_mem in memory */ |
| 480 | unsigned int server_ssl_ca_mem_len; |
| 481 | /**< VHOST: length of \p server_ssl_ca_mem in memory */ |
| 482 | |
| 483 | const char *alpn; |
| 484 | /**< CONTEXT: If non-NULL, default list of advertised alpn, comma- |
| 485 | * separated |
| 486 | * |
| 487 | * VHOST: If non-NULL, per-vhost list of advertised alpn, comma- |
| 488 | * separated |
| 489 | */ |
| 490 | |
| 491 | |
| 492 | #if defined(LWS_WITH_CLIENT) |
| 493 | const char *client_ssl_private_key_password; |
| 494 | /**< VHOST: Client SSL context init: NULL or the passphrase needed |
| 495 | * for the private key */ |
| 496 | const char *client_ssl_cert_filepath; |
| 497 | /**< VHOST: Client SSL context init: The certificate the client |
| 498 | * should present to the peer on connection */ |
| 499 | const void *client_ssl_cert_mem; |
| 500 | /**< VHOST: Client SSL context init: client certificate memory buffer or |
| 501 | * NULL... use this to load client cert from memory instead of file */ |
| 502 | unsigned int client_ssl_cert_mem_len; |
| 503 | /**< VHOST: Client SSL context init: length of client_ssl_cert_mem in |
| 504 | * bytes */ |
| 505 | const char *client_ssl_private_key_filepath; |
| 506 | /**< VHOST: Client SSL context init: filepath to client private key |
| 507 | * if this is set to NULL but client_ssl_cert_filepath is set, you |
| 508 | * can handle the LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS |
| 509 | * callback of protocols[0] to allow setting of the private key directly |
| 510 | * via tls library calls */ |
| 511 | const void *client_ssl_key_mem; |
| 512 | /**< VHOST: Client SSL context init: client key memory buffer or |
| 513 | * NULL... use this to load client key from memory instead of file */ |
| 514 | const char *client_ssl_ca_filepath; |
| 515 | /**< VHOST: Client SSL context init: CA certificate filepath or NULL */ |
| 516 | const void *client_ssl_ca_mem; |
| 517 | /**< VHOST: Client SSL context init: CA certificate memory buffer or |
| 518 | * NULL... use this to load CA cert from memory instead of file */ |
| 519 | |
| 520 | const char *client_ssl_cipher_list; |
| 521 | /**< VHOST: Client SSL context init: List of valid ciphers to use (eg, |
| 522 | * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aNULL" |
| 523 | * or you can leave it as NULL to get "DEFAULT" */ |
| 524 | const char *client_tls_1_3_plus_cipher_list; |
| 525 | /**< VHOST: List of valid ciphers to use for outgoing client connections |
| 526 | * ON TLS1.3 AND ABOVE on this vhost (eg, |
| 527 | * "TLS_CHACHA20_POLY1305_SHA256") or you can leave it as NULL to get |
| 528 | * "DEFAULT". |
| 529 | */ |
| 530 | |
| 531 | long ssl_client_options_set; |
| 532 | /**< VHOST: Any bits set here will be set as CLIENT SSL options */ |
| 533 | long ssl_client_options_clear; |
| 534 | /**< VHOST: Any bits set here will be cleared as CLIENT SSL options */ |
| 535 | |
| 536 | |
| 537 | unsigned int client_ssl_ca_mem_len; |
| 538 | /**< VHOST: Client SSL context init: length of client_ssl_ca_mem in |
| 539 | * bytes */ |
| 540 | unsigned int client_ssl_key_mem_len; |
| 541 | /**< VHOST: Client SSL context init: length of client_ssl_key_mem in |
| 542 | * bytes */ |
| 543 | |
| 544 | #endif |
| 545 | |
| 546 | #if !defined(LWS_WITH_MBEDTLS) |
| 547 | SSL_CTX *provided_client_ssl_ctx; |
| 548 | /**< CONTEXT: If non-null, swap out libwebsockets ssl |
| 549 | * implementation for the one provided by provided_ssl_ctx. |
| 550 | * Libwebsockets no longer is responsible for freeing the context |
| 551 | * if this option is selected. */ |
| 552 | #else /* WITH_MBEDTLS */ |
| 553 | const char *mbedtls_client_preload_filepath; |
| 554 | /**< CONTEXT: If NULL, no effect. Otherwise it should point to a |
| 555 | * filepath where every created client SSL_CTX is preloaded from the |
| 556 | * system trust bundle. |
| 557 | * |
| 558 | * This sets a processwide variable that affects all contexts. |
| 559 | * |
| 560 | * Requires that the mbedtls provides mbedtls_x509_crt_parse_file(), |
| 561 | * else disabled. |
| 562 | */ |
| 563 | #endif |
| 564 | #endif |
| 565 | |
| 566 | int ka_time; |
| 567 | /**< CONTEXT: 0 for no TCP keepalive, otherwise apply this keepalive |
| 568 | * timeout to all libwebsocket sockets, client or server */ |
| 569 | int ka_probes; |
| 570 | /**< CONTEXT: if ka_time was nonzero, after the timeout expires how many |
| 571 | * times to try to get a response from the peer before giving up |
| 572 | * and killing the connection */ |
| 573 | int ka_interval; |
| 574 | /**< CONTEXT: if ka_time was nonzero, how long to wait before each ka_probes |
| 575 | * attempt */ |
| 576 | unsigned int timeout_secs; |
| 577 | /**< VHOST: various processes involving network roundtrips in the |
| 578 | * library are protected from hanging forever by timeouts. If |
| 579 | * nonzero, this member lets you set the timeout used in seconds. |
| 580 | * Otherwise a default timeout is used. */ |
| 581 | unsigned int connect_timeout_secs; |
| 582 | /**< VHOST: client connections have this long to find a working server |
| 583 | * from the DNS results, or the whole connection times out. If zero, |
| 584 | * a default timeout is used */ |
| 585 | int bind_iface; |
| 586 | /**< VHOST: nonzero to strictly bind sockets to the interface name in |
| 587 | * .iface (eg, "eth2"), using SO_BIND_TO_DEVICE. |
| 588 | * |
| 589 | * Requires SO_BINDTODEVICE support from your OS and CAP_NET_RAW |
| 590 | * capability. |
| 591 | * |
| 592 | * Notice that common things like access network interface IP from |
| 593 | * your local machine use your lo / loopback interface and will be |
| 594 | * disallowed by this. |
| 595 | */ |
| 596 | unsigned int timeout_secs_ah_idle; |
| 597 | /**< VHOST: seconds to allow a client to hold an ah without using it. |
| 598 | * 0 defaults to 10s. */ |
| 599 | #endif /* WITH_NETWORK */ |
| 600 | |
| 601 | #if defined(LWS_WITH_TLS_SESSIONS) |
| 602 | uint32_t tls_session_timeout; |
| 603 | /**< VHOST: seconds until timeout/ttl for newly created sessions. |
| 604 | * 0 means default timeout (defined per protocol, usually 300s). */ |
| 605 | uint32_t tls_session_cache_max; |
| 606 | /**< VHOST: 0 for default limit of 10, or the maximum number of |
| 607 | * client tls sessions we are willing to cache */ |
| 608 | #endif |
| 609 | |
| 610 | gid_t gid; |
| 611 | /**< CONTEXT: group id to change to after setting listen socket, |
| 612 | * or -1. See also .username below. */ |
| 613 | uid_t uid; |
| 614 | /**< CONTEXT: user id to change to after setting listen socket, |
| 615 | * or -1. See also .groupname below. */ |
| 616 | uint64_t options; |
| 617 | /**< VHOST + CONTEXT: 0, or LWS_SERVER_OPTION_... bitfields */ |
| 618 | void *user; |
| 619 | /**< VHOST + CONTEXT: optional user pointer that will be associated |
| 620 | * with the context when creating the context (and can be retrieved by |
| 621 | * lws_context_user(context), or with the vhost when creating the vhost |
| 622 | * (and can be retrieved by lws_vhost_user(vhost)). You will need to |
| 623 | * use LWS_SERVER_OPTION_EXPLICIT_VHOSTS and create the vhost separately |
| 624 | * if you care about giving the context and vhost different user pointer |
| 625 | * values. |
| 626 | */ |
| 627 | unsigned int count_threads; |
| 628 | /**< CONTEXT: how many contexts to create in an array, 0 = 1 */ |
| 629 | unsigned int fd_limit_per_thread; |
| 630 | /**< CONTEXT: nonzero means restrict each service thread to this |
| 631 | * many fds, 0 means the default which is divide the process fd |
| 632 | * limit by the number of threads. |
| 633 | * |
| 634 | * Note if this is nonzero, and fd_limit_per_thread multiplied by the |
| 635 | * number of service threads is less than the process ulimit, then lws |
| 636 | * restricts internal lookup table allocation to the smaller size, and |
| 637 | * switches to a less efficient lookup scheme. You should use this to |
| 638 | * trade off speed against memory usage if you know the lws context |
| 639 | * will only use a handful of fds. |
| 640 | * |
| 641 | * Bear in mind lws may use some fds internally, for example for the |
| 642 | * cancel pipe, so you may need to allow for some extras for normal |
| 643 | * operation. |
| 644 | */ |
| 645 | const char *vhost_name; |
| 646 | /**< VHOST: name of vhost, must match external DNS name used to |
| 647 | * access the site, like "warmcat.com" as it's used to match |
| 648 | * Host: header and / or SNI name for SSL. |
| 649 | * CONTEXT: NULL, or the name to associate with the context for |
| 650 | * context-specific logging |
| 651 | */ |
| 652 | #if defined(LWS_WITH_PLUGINS) |
| 653 | const char * const *plugin_dirs; |
| 654 | /**< CONTEXT: NULL, or NULL-terminated array of directories to |
| 655 | * scan for lws protocol plugins at context creation time */ |
| 656 | #endif |
| 657 | void *external_baggage_free_on_destroy; |
| 658 | /**< CONTEXT: NULL, or pointer to something externally malloc'd, that |
| 659 | * should be freed when the context is destroyed. This allows you to |
| 660 | * automatically sync the freeing action to the context destruction |
| 661 | * action, so there is no need for an external free() if the context |
| 662 | * succeeded to create. |
| 663 | */ |
| 664 | |
| 665 | |
| 666 | unsigned int pt_serv_buf_size; |
| 667 | /**< CONTEXT: 0 = default of 4096. This buffer is used by |
| 668 | * various service related features including file serving, it |
| 669 | * defines the max chunk of file that can be sent at once. |
| 670 | * At the risk of lws having to buffer failed large sends, it |
| 671 | * can be increased to, eg, 128KiB to improve throughput. */ |
| 672 | #if defined(LWS_WITH_FILE_OPS) |
| 673 | const struct lws_plat_file_ops *fops; |
| 674 | /**< CONTEXT: NULL, or pointer to an array of fops structs, terminated |
| 675 | * by a sentinel with NULL .open. |
| 676 | * |
| 677 | * If NULL, lws provides just the platform file operations struct for |
| 678 | * backwards compatibility. |
| 679 | */ |
| 680 | #endif |
| 681 | |
| 682 | #if defined(LWS_WITH_SOCKS5) |
| 683 | const char *socks_proxy_address; |
| 684 | /**< VHOST: If non-NULL, attempts to proxy via the given address. |
| 685 | * If proxy auth is required, use format |
| 686 | * "username:password\@server:port" */ |
| 687 | unsigned int socks_proxy_port; |
| 688 | /**< VHOST: If socks_proxy_address was non-NULL, uses this port |
| 689 | * if nonzero, otherwise requires "server:port" in .socks_proxy_address |
| 690 | */ |
| 691 | #endif |
| 692 | |
| 693 | #if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP) |
| 694 | cap_value_t caps[4]; |
| 695 | /**< CONTEXT: array holding Linux capabilities you want to |
| 696 | * continue to be available to the server after it transitions |
| 697 | * to a noprivileged user. Usually none are needed but for, eg, |
| 698 | * .bind_iface, CAP_NET_RAW is required. This gives you a way |
| 699 | * to still have the capability but drop root. |
| 700 | */ |
| 701 | char count_caps; |
| 702 | /**< CONTEXT: count of Linux capabilities in .caps[]. 0 means |
| 703 | * no capabilities will be inherited from root (the default) */ |
| 704 | #endif |
| 705 | void **foreign_loops; |
| 706 | /**< CONTEXT: This is ignored if the context is not being started with |
| 707 | * an event loop, ie, .options has a flag like |
| 708 | * LWS_SERVER_OPTION_LIBUV. |
| 709 | * |
| 710 | * NULL indicates lws should start its own even loop for |
| 711 | * each service thread, and deal with closing the loops |
| 712 | * when the context is destroyed. |
| 713 | * |
| 714 | * Non-NULL means it points to an array of external |
| 715 | * ("foreign") event loops that are to be used in turn for |
| 716 | * each service thread. In the default case of 1 service |
| 717 | * thread, it can just point to one foreign event loop. |
| 718 | */ |
| 719 | void (*signal_cb)(void *event_lib_handle, int signum); |
| 720 | /**< CONTEXT: NULL: default signal handling. Otherwise this receives |
| 721 | * the signal handler callback. event_lib_handle is the |
| 722 | * native event library signal handle, eg uv_signal_t * |
| 723 | * for libuv. |
| 724 | */ |
| 725 | struct lws_context **pcontext; |
| 726 | /**< CONTEXT: if non-NULL, at the end of context destroy processing, |
| 727 | * the pointer pointed to by pcontext is written with NULL. You can |
| 728 | * use this to let foreign event loops know that lws context destruction |
| 729 | * is fully completed. |
| 730 | */ |
| 731 | void (*finalize)(struct lws_vhost *vh, void *arg); |
| 732 | /**< VHOST: NULL, or pointer to function that will be called back |
| 733 | * when the vhost is just about to be freed. The arg parameter |
| 734 | * will be set to whatever finalize_arg is below. |
| 735 | */ |
| 736 | void *finalize_arg; |
| 737 | /**< VHOST: opaque pointer lws ignores but passes to the finalize |
| 738 | * callback. If you don't care, leave it NULL. |
| 739 | */ |
| 740 | const char *listen_accept_role; |
| 741 | /**< VHOST: NULL for default, or force accepted incoming connections to |
| 742 | * bind to this role. Uses the role names from their ops struct, eg, |
| 743 | * "raw-skt". |
| 744 | */ |
| 745 | const char *listen_accept_protocol; |
| 746 | /**< VHOST: NULL for default, or force accepted incoming connections to |
| 747 | * bind to this vhost protocol name. |
| 748 | */ |
| 749 | const struct lws_protocols **pprotocols; |
| 750 | /**< VHOST: NULL: use .protocols, otherwise ignore .protocols and use |
| 751 | * this array of pointers to protocols structs. The end of the array |
| 752 | * is marked by a NULL pointer. |
| 753 | * |
| 754 | * This is preferred over .protocols, because it allows the protocol |
| 755 | * struct to be opaquely defined elsewhere, with just a pointer to it |
| 756 | * needed to create the context with it. .protocols requires also |
| 757 | * the type of the user data to be known so its size can be given. |
| 758 | */ |
| 759 | |
| 760 | const char *username; /**< CONTEXT: string username for post-init |
| 761 | * permissions. Like .uid but takes a string username. */ |
| 762 | const char *groupname; /**< CONTEXT: string groupname for post-init |
| 763 | * permissions. Like .gid but takes a string groupname. */ |
| 764 | const char *unix_socket_perms; /**< VHOST: if your vhost is listening |
| 765 | * on a unix socket, you can give a "username:groupname" string here |
| 766 | * to control the owner:group it's created with. It's always created |
| 767 | * with 0660 mode. */ |
| 768 | const lws_system_ops_t *system_ops; |
| 769 | /**< CONTEXT: hook up lws_system_ apis to system-specific |
| 770 | * implementations */ |
| 771 | const lws_retry_bo_t *retry_and_idle_policy; |
| 772 | /**< VHOST: optional retry and idle policy to apply to this vhost. |
| 773 | * Currently only the idle parts are applied to the connections. |
| 774 | */ |
| 775 | #if defined(LWS_WITH_SYS_STATE) |
| 776 | lws_state_notify_link_t * const *register_notifier_list; |
| 777 | /**< CONTEXT: NULL, or pointer to an array of notifiers that should |
| 778 | * be registered during context creation, so they can see state change |
| 779 | * events from very early on. The array should end with a NULL. */ |
| 780 | #endif |
| 781 | #if defined(LWS_WITH_SECURE_STREAMS) |
| 782 | #if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY) |
| 783 | const struct lws_ss_policy *pss_policies; /**< CONTEXT: point to first |
| 784 | * in a linked-list of streamtype policies prepared by user code */ |
| 785 | #else |
| 786 | const char *pss_policies_json; /**< CONTEXT: point to a string |
| 787 | * containing a JSON description of the secure streams policies. Set |
| 788 | * to NULL if not using Secure Streams. |
| 789 | * If the platform supports files and the string does not begin with |
| 790 | * '{', lws treats the string as a filepath to open to get the JSON |
| 791 | * policy. |
| 792 | */ |
| 793 | #endif |
| 794 | const struct lws_ss_plugin **pss_plugins; /**< CONTEXT: point to an array |
| 795 | * of pointers to plugin structs here, terminated with a NULL ptr. |
| 796 | * Set to NULL if not using Secure Streams. */ |
| 797 | const char *ss_proxy_bind; /**< CONTEXT: NULL, or: ss_proxy_port == 0: |
| 798 | * point to a string giving the Unix Domain Socket address to use (start |
| 799 | * with @ for abstract namespace), ss_proxy_port nonzero: set the |
| 800 | * network interface address (not name, it's ambiguous for ipv4/6) to |
| 801 | * bind the tcp connection to the proxy to */ |
| 802 | const char *ss_proxy_address; /**< CONTEXT: NULL, or if ss_proxy_port |
| 803 | * nonzero: the tcp address of the ss proxy to connect to */ |
| 804 | uint16_t ss_proxy_port; /* 0 = if connecting to ss proxy, do it via a |
| 805 | * Unix Domain Socket, "+@proxy.ss.lws" if ss_proxy_bind is NULL else |
| 806 | * the socket path given in ss_proxy_bind (start it with a + or +@); |
| 807 | * nonzero means connect via a tcp socket to the tcp address in |
| 808 | * ss_proxy_bind and the given port */ |
| 809 | const struct lws_transport_proxy_ops *txp_ops_ssproxy; /**< CONTEXT: NULL, or |
| 810 | * custom sss transport ops used for ss proxy communication. NULL means |
| 811 | * to use the default wsi-based proxy server */ |
| 812 | const void *txp_ssproxy_info; /**< CONTEXT: NULL, or extra transport- |
| 813 | * specifi creation info to be used at \p txp_ops_ssproxy creation */ |
| 814 | const struct lws_transport_client_ops *txp_ops_sspc; /**< CONTEXT: NULL, or |
| 815 | * custom sss transport ops used for ss client communication to the ss |
| 816 | * proxy. NULL means to use the default wsi-based client support */ |
| 817 | #endif |
| 818 | |
| 819 | #if defined(LWS_WITH_SECURE_STREAMS_PROXY_API) |
| 820 | #endif |
| 821 | |
| 822 | int rlimit_nofile; |
| 823 | /**< 0 = inherit the initial ulimit for files / sockets from the startup |
| 824 | * environment. Nonzero = try to set the limit for this process. |
| 825 | */ |
| 826 | #if defined(LWS_WITH_PEER_LIMITS) |
| 827 | lws_peer_limits_notify_t pl_notify_cb; |
| 828 | /**< CONTEXT: NULL, or a callback to receive notifications each time a |
| 829 | * connection is being dropped because of peer limits. |
| 830 | * |
| 831 | * The callback provides the context, and an lws_sockaddr46 with the |
| 832 | * peer address and port. |
| 833 | */ |
| 834 | unsigned short ip_limit_ah; |
| 835 | /**< CONTEXT: max number of ah a single IP may use simultaneously |
| 836 | * 0 is no limit. This is a soft limit: if the limit is |
| 837 | * reached, connections from that IP will wait in the ah |
| 838 | * waiting list and not be able to acquire an ah until |
| 839 | * a connection belonging to the IP relinquishes one it |
| 840 | * already has. |
| 841 | */ |
| 842 | unsigned short ip_limit_wsi; |
| 843 | /**< CONTEXT: max number of wsi a single IP may use simultaneously. |
| 844 | * 0 is no limit. This is a hard limit, connections from |
| 845 | * the same IP will simply be dropped once it acquires the |
| 846 | * amount of simultaneous wsi / accepted connections |
| 847 | * given here. |
| 848 | */ |
| 849 | |
| 850 | #endif /* PEER_LIMITS */ |
| 851 | |
| 852 | #if defined(LWS_WITH_SYS_FAULT_INJECTION) |
| 853 | lws_fi_ctx_t fic; |
| 854 | /**< CONTEXT | VHOST: attach external Fault Injection context to the |
| 855 | * lws_context or vhost. If creating the context + default vhost in |
| 856 | * one step, only the context binds to \p fi. When creating a vhost |
| 857 | * otherwise this can bind to the vhost so the faults can be injected |
| 858 | * from the start. |
| 859 | */ |
| 860 | #endif |
| 861 | |
| 862 | #if defined(LWS_WITH_SYS_SMD) |
| 863 | lws_smd_notification_cb_t early_smd_cb; |
| 864 | /**< CONTEXT: NULL, or an smd notification callback that will be registered |
| 865 | * immediately after the smd in the context is initialized. This ensures |
| 866 | * you can get all notifications without having to intercept the event loop |
| 867 | * creation, eg, when using an event library. Other callbacks can be |
| 868 | * registered later manually without problems. |
| 869 | */ |
| 870 | void *early_smd_opaque; |
| 871 | lws_smd_class_t early_smd_class_filter; |
| 872 | lws_usec_t smd_ttl_us; |
| 873 | /**< CONTEXT: SMD messages older than this many us are removed from the |
| 874 | * queue and destroyed even if not fully delivered yet. If zero, |
| 875 | * defaults to 2 seconds (5 second for FREERTOS). |
| 876 | */ |
| 877 | uint16_t smd_queue_depth; |
| 878 | /**< CONTEXT: Maximum queue depth, If zero defaults to 40 |
| 879 | * (20 for FREERTOS) */ |
| 880 | #endif |
| 881 | |
| 882 | #if defined(LWS_WITH_SYS_METRICS) |
| 883 | const struct lws_metric_policy *metrics_policies; |
| 884 | /**< CONTEXT: non-SS policy metrics policies */ |
| 885 | const char *metrics_prefix; |
| 886 | /**< CONTEXT: prefix for this context's metrics, used to distinguish |
| 887 | * metrics pooled from different processes / applications, so, eg what |
| 888 | * would be "cpu.svc" if this is NULL becomes "myapp.cpu.svc" is this is |
| 889 | * set to "myapp". Policies are applied using the name with the prefix, |
| 890 | * if present. |
| 891 | */ |
| 892 | #endif |
| 893 | |
| 894 | int fo_listen_queue; |
| 895 | /**< VHOST: 0 = no TCP_FASTOPEN, nonzero = enable TCP_FASTOPEN if the |
| 896 | * platform supports it, with the given queue length for the listen |
| 897 | * socket. |
| 898 | */ |
| 899 | |
| 900 | const struct lws_plugin_evlib *event_lib_custom; |
| 901 | /**< CONTEXT: If non-NULL, override event library selection so it uses |
| 902 | * this custom event library implementation, instead of default internal |
| 903 | * loop. Don't set any other event lib context creation flags in that |
| 904 | * case. it will be used automatically. This is useful for integration |
| 905 | * where an existing application is using its own handrolled event loop |
| 906 | * instead of an event library, it provides a way to allow lws to use |
| 907 | * the custom event loop natively as if it were an "event library". |
| 908 | */ |
| 909 | |
| 910 | #if defined(LWS_WITH_TLS_JIT_TRUST) |
| 911 | size_t jitt_cache_max_footprint; |
| 912 | /**< CONTEXT: 0 for no limit, else max bytes used by JIT Trust cache... |
| 913 | * LRU items are evicted to keep under this limit */ |
| 914 | int vh_idle_grace_ms; |
| 915 | /**< CONTEXT: 0 for default of 5000ms, or number of ms JIT Trust vhosts |
| 916 | * are allowed to live without active connections using them. */ |
| 917 | #endif |
| 918 | |
| 919 | lws_log_cx_t *log_cx; |
| 920 | /**< CONTEXT: NULL to use the default, process-scope logging context, |
| 921 | * else a specific logging context to associate with this context */ |
| 922 | |
| 923 | #if defined(LWS_WITH_CACHE_NSCOOKIEJAR) && defined(LWS_WITH_CLIENT) |
| 924 | const char *http_nsc_filepath; |
| 925 | /**< CONTEXT: Filepath to use for http netscape cookiejar file */ |
| 926 | |
| 927 | size_t ; |
| 928 | /**< CONTEXT: 0, or limit in bytes for heap usage of memory cookie |
| 929 | * cache */ |
| 930 | size_t http_nsc_heap_max_items; |
| 931 | /**< CONTEXT: 0, or the max number of items allowed in the cookie cache |
| 932 | * before destroying lru items to keep it under the limit */ |
| 933 | size_t http_nsc_heap_max_payload; |
| 934 | /**< CONTEXT: 0, or the maximum size of a single cookie we are able to |
| 935 | * handle */ |
| 936 | #endif |
| 937 | |
| 938 | #if defined(LWS_WITH_SYS_ASYNC_DNS) |
| 939 | const char **async_dns_servers; |
| 940 | /**< CONTEXT: NULL, or a pointer to an array of strings containing the |
| 941 | * numeric IP like "8.8.8.8" or "2001:4860:4860::8888" for a list of DNS |
| 942 | * server to forcibly add. If given, the list of strings must be |
| 943 | * terminated with a NULL. |
| 944 | */ |
| 945 | #endif |
| 946 | |
| 947 | #if defined(WIN32) |
| 948 | unsigned int win32_connect_check_interval_usec; |
| 949 | /**< CONTEXT: win32 needs client connection status checking at intervals |
| 950 | * to work reliably. This sets the interval in us, up to 999999. By |
| 951 | * default, it's 500us. |
| 952 | */ |
| 953 | #endif |
| 954 | |
| 955 | int default_loglevel; |
| 956 | /**< CONTEXT: 0 for LLL_USER, LLL_ERR, LLL_WARN, LLL_NOTICE enabled by default when |
| 957 | * using lws_cmdline_option_handle_builtin(), else set to the LLL_ flags you want |
| 958 | * to be the default before calling lws_cmdline_option_handle_builtin(). Your |
| 959 | * selected default loglevel can then be cleanly overridden using -d 1039 etc |
| 960 | * commandline switch */ |
| 961 | |
| 962 | lws_sockfd_type vh_listen_sockfd; |
| 963 | /**< VHOST: 0 for normal vhost listen socket fd creation, if any. |
| 964 | * Nonzero to force the selection of an already-existing fd for the |
| 965 | * vhost's listen socket, which is already prepared. This is intended |
| 966 | * for an external process having chosen the fd, which cannot then be |
| 967 | * zero. |
| 968 | */ |
| 969 | |
| 970 | #if defined(LWS_WITH_NETWORK) |
| 971 | const char *wol_if; |
| 972 | /**< CONTEXT: NULL, or interface name to bind outgoing WOL packet to */ |
| 973 | #endif |
| 974 | |
| 975 | /* Add new things just above here ---^ |
| 976 | * This is part of the ABI, don't needlessly break compatibility |
| 977 | * |
| 978 | * The below is to ensure later library versions with new |
| 979 | * members added above will see 0 (default) even if the app |
| 980 | * was not built against the newer headers. |
| 981 | */ |
| 982 | |
| 983 | void *_unused[2]; /**< dummy */ |
| 984 | }; |
| 985 | |
| 986 | /** |
| 987 | * lws_create_context() - Create the websocket handler |
| 988 | * \param info: pointer to struct with parameters |
| 989 | * |
| 990 | * This function creates the listening socket (if serving) and takes care |
| 991 | * of all initialization in one step. |
| 992 | * |
| 993 | * If option LWS_SERVER_OPTION_EXPLICIT_VHOSTS is given, no vhost is |
| 994 | * created; you're expected to create your own vhosts afterwards using |
| 995 | * lws_create_vhost(). Otherwise a vhost named "default" is also created |
| 996 | * using the information in the vhost-related members, for compatibility. |
| 997 | * |
| 998 | * After initialization, it returns a struct lws_context * that |
| 999 | * represents this server. After calling, user code needs to take care |
| 1000 | * of calling lws_service() with the context pointer to get the |
| 1001 | * server's sockets serviced. This must be done in the same process |
| 1002 | * context as the initialization call. |
| 1003 | * |
| 1004 | * The protocol callback functions are called for a handful of events |
| 1005 | * including http requests coming in, websocket connections becoming |
| 1006 | * established, and data arriving; it's also called periodically to allow |
| 1007 | * async transmission. |
| 1008 | * |
| 1009 | * HTTP requests are sent always to the FIRST protocol in protocol, since |
| 1010 | * at that time websocket protocol has not been negotiated. Other |
| 1011 | * protocols after the first one never see any HTTP callback activity. |
| 1012 | * |
| 1013 | * The server created is a simple http server by default; part of the |
| 1014 | * websocket standard is upgrading this http connection to a websocket one. |
| 1015 | * |
| 1016 | * This allows the same server to provide files like scripts and favicon / |
| 1017 | * images or whatever over http and dynamic data over websockets all in |
| 1018 | * one place; they're all handled in the user callback. |
| 1019 | */ |
| 1020 | LWS_VISIBLE LWS_EXTERN struct lws_context * |
| 1021 | lws_create_context(const struct lws_context_creation_info *info); |
| 1022 | |
| 1023 | |
| 1024 | /** |
| 1025 | * lws_context_destroy() - Destroy the websocket context |
| 1026 | * \param context: Websocket context |
| 1027 | * |
| 1028 | * This function closes any active connections and then frees the |
| 1029 | * context. After calling this, any further use of the context is |
| 1030 | * undefined. |
| 1031 | */ |
| 1032 | LWS_VISIBLE LWS_EXTERN void |
| 1033 | lws_context_destroy(struct lws_context *context); |
| 1034 | |
| 1035 | typedef int (*lws_reload_func)(void); |
| 1036 | |
| 1037 | /** |
| 1038 | * lws_context_deprecate() - Deprecate the websocket context |
| 1039 | * |
| 1040 | * \param context: Websocket context |
| 1041 | * \param cb: Callback notified when old context listen sockets are closed |
| 1042 | * |
| 1043 | * This function is used on an existing context before superceding it |
| 1044 | * with a new context. |
| 1045 | * |
| 1046 | * It closes any listen sockets in the context, so new connections are |
| 1047 | * not possible. |
| 1048 | * |
| 1049 | * And it marks the context to be deleted when the number of active |
| 1050 | * connections into it falls to zero. |
| 1051 | * |
| 1052 | * This is aimed at allowing seamless configuration reloads. |
| 1053 | * |
| 1054 | * The callback cb will be called after the listen sockets are actually |
| 1055 | * closed and may be reopened. In the callback the new context should be |
| 1056 | * configured and created. (With libuv, socket close happens async after |
| 1057 | * more loop events). |
| 1058 | */ |
| 1059 | LWS_VISIBLE LWS_EXTERN void |
| 1060 | lws_context_deprecate(struct lws_context *context, lws_reload_func cb); |
| 1061 | |
| 1062 | LWS_VISIBLE LWS_EXTERN int |
| 1063 | lws_context_is_deprecated(struct lws_context *context); |
| 1064 | |
| 1065 | /** |
| 1066 | * lws_set_proxy() - Setups proxy to lws_context. |
| 1067 | * \param vhost: pointer to struct lws_vhost you want set proxy for |
| 1068 | * \param proxy: pointer to c string containing proxy in format address:port |
| 1069 | * |
| 1070 | * Returns 0 if proxy string was parsed and proxy was setup. |
| 1071 | * Returns -1 if proxy is NULL or has incorrect format. |
| 1072 | * |
| 1073 | * This is only required if your OS does not provide the http_proxy |
| 1074 | * environment variable (eg, OSX) |
| 1075 | * |
| 1076 | * IMPORTANT! You should call this function right after creation of the |
| 1077 | * lws_context and before call to connect. If you call this |
| 1078 | * function after connect behavior is undefined. |
| 1079 | * This function will override proxy settings made on lws_context |
| 1080 | * creation with genenv() call. |
| 1081 | */ |
| 1082 | LWS_VISIBLE LWS_EXTERN int |
| 1083 | lws_set_proxy(struct lws_vhost *vhost, const char *proxy); |
| 1084 | |
| 1085 | /** |
| 1086 | * lws_set_socks() - Setup socks to lws_context. |
| 1087 | * \param vhost: pointer to struct lws_vhost you want set socks for |
| 1088 | * \param socks: pointer to c string containing socks in format address:port |
| 1089 | * |
| 1090 | * Returns 0 if socks string was parsed and socks was setup. |
| 1091 | * Returns -1 if socks is NULL or has incorrect format. |
| 1092 | * |
| 1093 | * This is only required if your OS does not provide the socks_proxy |
| 1094 | * environment variable (eg, OSX) |
| 1095 | * |
| 1096 | * IMPORTANT! You should call this function right after creation of the |
| 1097 | * lws_context and before call to connect. If you call this |
| 1098 | * function after connect behavior is undefined. |
| 1099 | * This function will override proxy settings made on lws_context |
| 1100 | * creation with genenv() call. |
| 1101 | */ |
| 1102 | LWS_VISIBLE LWS_EXTERN int |
| 1103 | lws_set_socks(struct lws_vhost *vhost, const char *socks); |
| 1104 | |
| 1105 | struct lws_vhost; |
| 1106 | |
| 1107 | /** |
| 1108 | * lws_create_vhost() - Create a vhost (virtual server context) |
| 1109 | * \param context: pointer to result of lws_create_context() |
| 1110 | * \param info: pointer to struct with parameters |
| 1111 | * |
| 1112 | * This function creates a virtual server (vhost) using the vhost-related |
| 1113 | * members of the info struct. You can create many vhosts inside one context |
| 1114 | * if you created the context with the option LWS_SERVER_OPTION_EXPLICIT_VHOSTS |
| 1115 | */ |
| 1116 | LWS_VISIBLE LWS_EXTERN struct lws_vhost * |
| 1117 | lws_create_vhost(struct lws_context *context, |
| 1118 | const struct lws_context_creation_info *info); |
| 1119 | |
| 1120 | /** |
| 1121 | * lws_vhost_destroy() - Destroy a vhost (virtual server context) |
| 1122 | * |
| 1123 | * \param vh: pointer to result of lws_create_vhost() |
| 1124 | * |
| 1125 | * This function destroys a vhost. Normally, if you just want to exit, |
| 1126 | * then lws_destroy_context() will take care of everything. If you want |
| 1127 | * to destroy an individual vhost and all connections and allocations, you |
| 1128 | * can do it with this. |
| 1129 | * |
| 1130 | * If the vhost has a listen sockets shared by other vhosts, it will be given |
| 1131 | * to one of the vhosts sharing it rather than closed. |
| 1132 | * |
| 1133 | * The vhost close is staged according to the needs of the event loop, and if |
| 1134 | * there are multiple service threads. At the point the vhost itself if |
| 1135 | * about to be freed, if you provided a finalize callback and optional arg at |
| 1136 | * vhost creation time, it will be called just before the vhost is freed. |
| 1137 | */ |
| 1138 | LWS_VISIBLE LWS_EXTERN void |
| 1139 | lws_vhost_destroy(struct lws_vhost *vh); |
| 1140 | |
| 1141 | /** |
| 1142 | * lwsws_get_config_globals() - Parse a JSON server config file |
| 1143 | * \param info: pointer to struct with parameters |
| 1144 | * \param d: filepath of the config file |
| 1145 | * \param config_strings: storage for the config strings extracted from JSON, |
| 1146 | * the pointer is incremented as strings are stored |
| 1147 | * \param len: pointer to the remaining length left in config_strings |
| 1148 | * the value is decremented as strings are stored |
| 1149 | * |
| 1150 | * This function prepares a n lws_context_creation_info struct with global |
| 1151 | * settings from a file d. |
| 1152 | * |
| 1153 | * Requires CMake option LWS_WITH_LEJP_CONF to have been enabled |
| 1154 | */ |
| 1155 | LWS_VISIBLE LWS_EXTERN int |
| 1156 | lwsws_get_config_globals(struct lws_context_creation_info *info, const char *d, |
| 1157 | char **config_strings, int *len); |
| 1158 | |
| 1159 | /** |
| 1160 | * lwsws_get_config_vhosts() - Create vhosts from a JSON server config file |
| 1161 | * \param context: pointer to result of lws_create_context() |
| 1162 | * \param info: pointer to struct with parameters |
| 1163 | * \param d: filepath of the config file |
| 1164 | * \param config_strings: storage for the config strings extracted from JSON, |
| 1165 | * the pointer is incremented as strings are stored |
| 1166 | * \param len: pointer to the remaining length left in config_strings |
| 1167 | * the value is decremented as strings are stored |
| 1168 | * |
| 1169 | * This function creates vhosts into a context according to the settings in |
| 1170 | *JSON files found in directory d. |
| 1171 | * |
| 1172 | * Requires CMake option LWS_WITH_LEJP_CONF to have been enabled |
| 1173 | */ |
| 1174 | LWS_VISIBLE LWS_EXTERN int |
| 1175 | lwsws_get_config_vhosts(struct lws_context *context, |
| 1176 | struct lws_context_creation_info *info, const char *d, |
| 1177 | char **config_strings, int *len); |
| 1178 | |
| 1179 | /** |
| 1180 | * lws_get_vhost() - return the vhost a wsi belongs to |
| 1181 | * |
| 1182 | * \param wsi: which connection |
| 1183 | */ |
| 1184 | LWS_VISIBLE LWS_EXTERN struct lws_vhost * |
| 1185 | lws_get_vhost(struct lws *wsi); |
| 1186 | |
| 1187 | /** |
| 1188 | * lws_get_vhost_name() - returns the name of a vhost |
| 1189 | * |
| 1190 | * \param vhost: which vhost |
| 1191 | */ |
| 1192 | LWS_VISIBLE LWS_EXTERN const char * |
| 1193 | lws_get_vhost_name(struct lws_vhost *vhost); |
| 1194 | |
| 1195 | /** |
| 1196 | * lws_get_vhost_by_name() - returns the vhost with the requested name, or NULL |
| 1197 | * |
| 1198 | * \param context: the lws_context to look in |
| 1199 | * \param name: vhost name we are looking for |
| 1200 | * |
| 1201 | * Returns NULL, or the vhost with the name \p name |
| 1202 | */ |
| 1203 | LWS_VISIBLE LWS_EXTERN struct lws_vhost * |
| 1204 | lws_get_vhost_by_name(struct lws_context *context, const char *name); |
| 1205 | |
| 1206 | /** |
| 1207 | * lws_get_vhost_port() - returns the port a vhost listens on, or -1 |
| 1208 | * |
| 1209 | * \param vhost: which vhost |
| 1210 | */ |
| 1211 | LWS_VISIBLE LWS_EXTERN int |
| 1212 | lws_get_vhost_port(struct lws_vhost *vhost); |
| 1213 | |
| 1214 | /** |
| 1215 | * lws_get_vhost_user() - returns the user pointer for the vhost |
| 1216 | * |
| 1217 | * \param vhost: which vhost |
| 1218 | */ |
| 1219 | LWS_VISIBLE LWS_EXTERN void * |
| 1220 | lws_get_vhost_user(struct lws_vhost *vhost); |
| 1221 | |
| 1222 | /** |
| 1223 | * lws_get_vhost_iface() - returns the binding for the vhost listen socket |
| 1224 | * |
| 1225 | * \param vhost: which vhost |
| 1226 | */ |
| 1227 | LWS_VISIBLE LWS_EXTERN const char * |
| 1228 | lws_get_vhost_iface(struct lws_vhost *vhost); |
| 1229 | |
| 1230 | /** |
| 1231 | * lws_vhost_user() - get the user data associated with the vhost |
| 1232 | * \param vhost: Websocket vhost |
| 1233 | * |
| 1234 | * This returns the optional user pointer that can be attached to |
| 1235 | * a vhost when it was created. Lws never dereferences this pointer, it only |
| 1236 | * sets it when the vhost is created, and returns it using this api. |
| 1237 | */ |
| 1238 | LWS_VISIBLE LWS_EXTERN void * |
| 1239 | lws_vhost_user(struct lws_vhost *vhost); |
| 1240 | |
| 1241 | /** |
| 1242 | * lws_context_user() - get the user data associated with the context |
| 1243 | * \param context: Websocket context |
| 1244 | * |
| 1245 | * This returns the optional user allocation that can be attached to |
| 1246 | * the context the sockets live in at context_create time. It's a way |
| 1247 | * to let all sockets serviced in the same context share data without |
| 1248 | * using globals statics in the user code. |
| 1249 | */ |
| 1250 | LWS_VISIBLE LWS_EXTERN void * |
| 1251 | lws_context_user(struct lws_context *context); |
| 1252 | |
| 1253 | LWS_VISIBLE LWS_EXTERN const char * |
| 1254 | lws_vh_tag(struct lws_vhost *vh); |
| 1255 | |
| 1256 | LWS_VISIBLE LWS_EXTERN void |
| 1257 | _lws_context_info_defaults(struct lws_context_creation_info *info, |
| 1258 | const char *sspol); |
| 1259 | |
| 1260 | LWS_VISIBLE LWS_EXTERN void |
| 1261 | lws_default_loop_exit(struct lws_context *cx); |
| 1262 | |
| 1263 | LWS_VISIBLE LWS_EXTERN void |
| 1264 | lws_context_default_loop_run_destroy(struct lws_context *cx); |
| 1265 | |
| 1266 | LWS_VISIBLE LWS_EXTERN int |
| 1267 | lws_cmdline_passfail(int argc, const char **argv, int actual); |
| 1268 | |
| 1269 | /** |
| 1270 | * lws_systemd_inherited_fd() - prepare vhost creation info for systemd exported fd if any |
| 1271 | * |
| 1272 | * \param index: 0+ index of exported fd |
| 1273 | * \param info: info struct to be prepared with related info, if any |
| 1274 | * |
| 1275 | * Returns 0 and points info to the related fd, aligning the other information |
| 1276 | * to the type of fd and port it is bound to, or returns nonzero if no such |
| 1277 | * inherited fd. |
| 1278 | */ |
| 1279 | LWS_VISIBLE LWS_EXTERN int |
| 1280 | lws_systemd_inherited_fd(unsigned int index, |
| 1281 | struct lws_context_creation_info *info); |
| 1282 | |
| 1283 | /** |
| 1284 | * lws_context_is_being_destroyed() - find out if context is being destroyed |
| 1285 | * |
| 1286 | * \param context: the struct lws_context pointer |
| 1287 | * |
| 1288 | * Returns nonzero if the context has had lws_context_destroy() called on it... |
| 1289 | * when using event library loops the destroy process can be asynchronous. In |
| 1290 | * the special case of libuv foreign loops, the failure to create the context |
| 1291 | * may have to do work on the foreign loop to reverse the partial creation, |
| 1292 | * meaning a failed context create cannot unpick what it did and return NULL. |
| 1293 | * |
| 1294 | * In that condition, a valid context that is already started the destroy |
| 1295 | * process is returned, and this test api will return nonzero as a way to |
| 1296 | * find out the create is in the middle of failing. |
| 1297 | */ |
| 1298 | LWS_VISIBLE LWS_EXTERN int |
| 1299 | lws_context_is_being_destroyed(struct lws_context *context); |
| 1300 | |
| 1301 | /*! \defgroup vhost-mounts Vhost mounts and options |
| 1302 | * \ingroup context-and-vhost-creation |
| 1303 | * |
| 1304 | * ##Vhost mounts and options |
| 1305 | */ |
| 1306 | ///@{ |
| 1307 | /** struct lws_protocol_vhost_options - linked list of per-vhost protocol |
| 1308 | * name=value options |
| 1309 | * |
| 1310 | * This provides a general way to attach a linked-list of name=value pairs, |
| 1311 | * which can also have an optional child link-list using the options member. |
| 1312 | */ |
| 1313 | struct lws_protocol_vhost_options { |
| 1314 | const struct lws_protocol_vhost_options *next; /**< linked list */ |
| 1315 | const struct lws_protocol_vhost_options *options; /**< child linked-list of more options for this node */ |
| 1316 | const char *name; /**< name of name=value pair */ |
| 1317 | const char *value; /**< value of name=value pair */ |
| 1318 | }; |
| 1319 | |
| 1320 | /** enum lws_mount_protocols |
| 1321 | * This specifies the mount protocol for a mountpoint, whether it is to be |
| 1322 | * served from a filesystem, or it is a cgi etc. |
| 1323 | */ |
| 1324 | enum lws_mount_protocols { |
| 1325 | LWSMPRO_HTTP = 0, /**< http reverse proxy */ |
| 1326 | LWSMPRO_HTTPS = 1, /**< https reverse proxy */ |
| 1327 | LWSMPRO_FILE = 2, /**< serve from filesystem directory */ |
| 1328 | LWSMPRO_CGI = 3, /**< pass to CGI to handle */ |
| 1329 | LWSMPRO_REDIR_HTTP = 4, /**< redirect to http:// url */ |
| 1330 | LWSMPRO_REDIR_HTTPS = 5, /**< redirect to https:// url */ |
| 1331 | LWSMPRO_CALLBACK = 6, /**< handle by named protocol's callback */ |
| 1332 | LWSMPRO_NO_MOUNT = 7, /**< matches fall back to no match processing */ |
| 1333 | }; |
| 1334 | |
| 1335 | /** enum lws_authentication_mode |
| 1336 | * This specifies the authentication mode of the mount. The basic_auth_login_file mount parameter |
| 1337 | * is ignored unless LWSAUTHM_DEFAULT is set. |
| 1338 | */ |
| 1339 | enum lws_authentication_mode { |
| 1340 | LWSAUTHM_DEFAULT = 0, /**< default authenticate only if basic_auth_login_file is provided */ |
| 1341 | LWSAUTHM_BASIC_AUTH_CALLBACK = 1 << 28 /**< Basic auth with a custom verifier */ |
| 1342 | }; |
| 1343 | |
| 1344 | /** The authentication mode is stored in the top 4 bits of lws_http_mount.auth_mask */ |
| 1345 | #define AUTH_MODE_MASK 0xF0000000 |
| 1346 | |
| 1347 | /** struct lws_http_mount |
| 1348 | * |
| 1349 | * arguments for mounting something in a vhost's url namespace |
| 1350 | */ |
| 1351 | struct lws_http_mount { |
| 1352 | const struct lws_http_mount *mount_next; |
| 1353 | /**< pointer to next struct lws_http_mount */ |
| 1354 | const char *mountpoint; |
| 1355 | /**< mountpoint in http pathspace, eg, "/" */ |
| 1356 | const char *origin; |
| 1357 | /**< path to be mounted, eg, "/var/www/warmcat.com" */ |
| 1358 | const char *def; |
| 1359 | /**< default target, eg, "index.html" */ |
| 1360 | const char *protocol; |
| 1361 | /**<"protocol-name" to handle mount */ |
| 1362 | |
| 1363 | const struct lws_protocol_vhost_options *cgienv; |
| 1364 | /**< optional linked-list of cgi options. These are created |
| 1365 | * as environment variables for the cgi process |
| 1366 | */ |
| 1367 | const struct lws_protocol_vhost_options *; |
| 1368 | /**< optional linked-list of mimetype mappings */ |
| 1369 | const struct lws_protocol_vhost_options *interpret; |
| 1370 | /**< optional linked-list of files to be interpreted */ |
| 1371 | |
| 1372 | int cgi_timeout; |
| 1373 | /**< seconds cgi is allowed to live, if cgi://mount type */ |
| 1374 | int cache_max_age; |
| 1375 | /**< max-age for reuse of client cache of files, seconds */ |
| 1376 | unsigned int auth_mask; |
| 1377 | /**< bits set here must be set for authorized client session */ |
| 1378 | |
| 1379 | unsigned int cache_reusable:1; /**< set if client cache may reuse this */ |
| 1380 | unsigned int cache_revalidate:1; /**< set if client cache should revalidate on use */ |
| 1381 | unsigned int cache_intermediaries:1; /**< set if intermediaries are allowed to cache */ |
| 1382 | unsigned int cache_no:1; /**< set if client should check cache always*/ |
| 1383 | |
| 1384 | unsigned char origin_protocol; /**< one of enum lws_mount_protocols */ |
| 1385 | unsigned char mountpoint_len; /**< length of mountpoint string */ |
| 1386 | |
| 1387 | const char *basic_auth_login_file; |
| 1388 | /**<NULL, or filepath to use to check basic auth logins against. (requires LWSAUTHM_DEFAULT) */ |
| 1389 | |
| 1390 | const char *cgi_chroot_path; |
| 1391 | /**< NULL, or chroot patch for child cgi process */ |
| 1392 | |
| 1393 | const char *cgi_wd; |
| 1394 | /**< working directory to cd to after fork of a cgi process, |
| 1395 | * NULL defaults to /tmp |
| 1396 | */ |
| 1397 | |
| 1398 | const struct lws_protocol_vhost_options *; |
| 1399 | /**< NULL, or pointer to optional linked list of |
| 1400 | * canned headers that are added to server responses. |
| 1401 | * If given, these override the headers given at |
| 1402 | * the vhost and are used instead of those when |
| 1403 | * the mountpoint matches. This allows to control, |
| 1404 | * eg, CSP on a per-mount basis. |
| 1405 | */ |
| 1406 | unsigned int keepalive_timeout; |
| 1407 | /**< 0 or seconds http stream should stay alive while |
| 1408 | * idle. 0 means use the vhost value for keepalive_timeout. |
| 1409 | */ |
| 1410 | |
| 1411 | /* Add new things just above here ---^ |
| 1412 | * This is part of the ABI, don't needlessly break compatibility |
| 1413 | */ |
| 1414 | }; |
| 1415 | |
| 1416 | LWS_VISIBLE LWS_EXTERN void |
| 1417 | lws_vhost_set_mounts(struct lws_vhost *v, const struct lws_http_mount *mounts); |
| 1418 | |
| 1419 | ///@} |
| 1420 | ///@} |
| 1421 | |