.pkg
-```
-
## CI Parity (Reference)
If you want local builds to match CI behavior, use these workflow references:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 699b5f4a70..130de6e537 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,14 +1,34 @@
# Changelog
-## v1.6.14~rc1 - 2026/07/??
+## v1.6.14~rc2 - 2026/07/??
+
+- [PERF] `ui`: make the Reports, Logs, and Home pages fast when many blocked-request reports are stored in Redis: fetch a single report by id from the newest end instead of scanning the whole list, share the Home page aggregation across workers through Redis instead of recomputing it in every worker, cache the Logs line count until the file changes or is rotated, and pause the Reports auto-refresh while the browser tab is in the background. Also honor the `k`/`m` suffix on `METRICS_MAX_BLOCKED_REQUESTS_REDIS` when bounding report reads.
+- [PERF] `ui`: memoize the plugin catalog and rebuild it only when plugins change instead of on every request, cutting the fixed overhead paid on every page load.
+- [BUGFIX] `metrics`: when the metrics memory zone fills up, shed the oldest blocked-request reports instead of silently discarding a worker's whole history, and warn that `METRICS_MEMORY_SIZE` needs raising.
+- [BUGFIX] `metrics`: stop storing the literal string `nil` in Redis for a counter evicted from a worker's LRU mid-sync, which made the `misc`, `blacklist` and `greylist` plugin pages return a 500.
+- [BUGFIX] `ui`: an unreadable counter no longer breaks a whole plugin page, and no longer hides the workers that reported real counts.
+- [BUGFIX] `scheduler`: refresh the job environment in place instead of replacing it on every reload, so jobs stop reading a snapshot of the configuration taken at startup. A DNS-01 service created or edited in the web UI got no certificate until the container was restarted. (Fixes #3755)
+- [BUGFIX] `letsencrypt`: fail the `certbot-new` job when a service cannot get the certificate it asked for instead of reporting success, and write each job's output to `certbot-new.log` and `certbot-renew.log` so the Jobs and Logs pages show why.
+- [BUGFIX] `whitelist`: whitelisting a banned IP now lifts the block on HTTP and stream services, and manually configured `WHITELIST_*` values are honored by the default server and badbehavior checks instead of only the entries downloaded from `WHITELIST_*_URLS`. (Refs #3708)
+- [BUGFIX] `core`: a setting missing from a service's configuration falls back to its global value, and a setting declared by a plugin but absent from the configuration is logged once per minute at warning level instead of at error level on every request. (Refs #3746)
+- [BUGFIX] `autoconf`: a Kubernetes watch that exhausts its retries now backs off and marks the container unhealthy instead of silently restarting forever while reporting healthy, and the Kubernetes manifests give the controller a liveness probe so it gets restarted. (Refs #3750)
+- [BUGFIX] `crowdsec`: enabling CrowdSec on individual services while it stays off globally now works. The bouncer was never initialized in that configuration, so every request logged `attempt to index field 'conf' (a nil value)` and was let through unchecked.
+- [FEATURE] `all-in-one`: add `DISABLE_ONLINE_API`, same name as the official CrowdSec images, to run CrowdSec without registering to the Central API. (Refs #3754)
+- [DOCS] `all-in-one`: document what CrowdSec Central API registration transmits, and correct the parser opt-out variable to `CROWDSEC_DISABLE_PARSERS`.
+- [BUGFIX] `ui`: a form submitted after the session ended now reports that the change was not saved, instead of redirecting to the login page and redrawing the old values as if nothing had happened. (Refs #3751, #3752)
+- [UI] Reports page: document the retention model, a rolling buffer capped per worker that is cleared on restart unless Redis is enabled.
+
+## v1.6.14~rc1 - 2026/07/23
- [BUGFIX] `mtls`: the Scheduler now validates the client CA bundle and CRL, caches them, and distributes them to every instance instead of shipping the raw configured path straight into the NGINX configuration, so a Scheduler-only mount works as documented instead of causing "cannot load certificate" errors on instances that cannot read that path. Adds `MTLS_CA_CERTIFICATE_DATA` and `MTLS_CRL_DATA` to supply either file inline as base64 or plaintext PEM.
+- [BUGFIX] `backup`: support MySQL 9 and MariaDB 12 backup/restore with current authentication, TLS, and privilege defaults while preserving compatibility with older servers; refresh the documented database compatibility matrix, including PostgreSQL 18.
- [BUGFIX] `ui`: fix plugin hook loading and chaining, and purge unavailable PRO plugin pages after license loss.
- [BUGFIX] `letsencrypt`: quarantine broken renewal lineages and persist the cleaned cache before Certbot runs. (Fixes #3733)
-- [UI] Reports and Bans pages: show unknown countries as not applicable, and make exports and bulk actions honor active filters. (Fixes #3683, #3685)
- [FEATURE] `metrics`: buffer reports during Redis OOM events, make list and facet updates atomic, and add the `METRICS_REDIS_TTL` setting.
- [FEATURE] `headers`: deny Chrome built-in AI APIs in the default `PERMISSIONS_POLICY`.
- [FEATURE] `misc`: allow the `QUERY` HTTP method by default in `ALLOWED_METHODS` and bundled service templates.
+- [LINUX] Updated the NGINX version to v1.30.4 for Fedora 43 and 44 now that it is available in their repositories.
+- [UI] Reports and Bans pages: show unknown countries as not applicable, and make exports and bulk actions honor active filters. (Fixes #3683, #3685)
## v1.6.13 - 2026/07/16
diff --git a/README.md b/README.md
index 8bbee4a500..71e917bf00 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-
+
@@ -40,7 +40,7 @@
|
🧩 Templates
|
- 🛡️ Examples
+ 🛡️ Examples
💬 Chat
|
@@ -60,14 +60,14 @@
# BunkerWeb
-
+
BunkerWeb is a next-generation, open-source Web Application Firewall (WAF).
-Being a full-featured web server (based on [NGINX](https://nginx.org/) under the hood), it will protect your web services to make them "secure by default." BunkerWeb integrates seamlessly into your existing environments ([Linux](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#linux), [Docker](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#docker), [Swarm](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#swarm), [Kubernetes](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#kubernetes), …) as a reverse proxy and is fully configurable (don't panic, there is an [awesome web UI](https://docs.bunkerweb.io/1.6.14~rc1/web-ui/?utm_campaign=self&utm_source=github) if you don't like the CLI) to meet your own use cases. In other words, cybersecurity is no longer a hassle.
+Being a full-featured web server (based on [NGINX](https://nginx.org/) under the hood), it will protect your web services to make them "secure by default." BunkerWeb integrates seamlessly into your existing environments ([Linux](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#linux), [Docker](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#docker), [Swarm](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#swarm), [Kubernetes](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#kubernetes), …) as a reverse proxy and is fully configurable (don't panic, there is an [awesome web UI](https://docs.bunkerweb.io/1.6.14~rc2/web-ui/?utm_campaign=self&utm_source=github) if you don't like the CLI) to meet your own use cases. In other words, cybersecurity is no longer a hassle.
-BunkerWeb contains primary [security features](https://docs.bunkerweb.io/1.6.14~rc1/advanced/?utm_campaign=self&utm_source=github#security-tuning) as part of the core but can be easily extended with additional ones thanks to a [plugin system](https://docs.bunkerweb.io/1.6.14~rc1/plugins/?utm_campaign=self&utm_source=github).
+BunkerWeb contains primary [security features](https://docs.bunkerweb.io/1.6.14~rc2/advanced/?utm_campaign=self&utm_source=github#security-tuning) as part of the core but can be easily extended with additional ones thanks to a [plugin system](https://docs.bunkerweb.io/1.6.14~rc2/plugins/?utm_campaign=self&utm_source=github).
## Why BunkerWeb?
@@ -94,7 +94,7 @@ A non-exhaustive list of security features:
- **Block known bad IPs** with external blacklists and DNSBL
- And much more...
-Learn more about the core security features in the [security tuning](https://docs.bunkerweb.io/1.6.14~rc1/advanced/?utm_campaign=self&utm_source=github#security-tuning) section of the documentation.
+Learn more about the core security features in the [security tuning](https://docs.bunkerweb.io/1.6.14~rc2/advanced/?utm_campaign=self&utm_source=github#security-tuning) section of the documentation.
## Demo
@@ -129,13 +129,13 @@ When using BunkerWeb, you have the choice of the version you want to use: open-s
Whether it's enhanced security, an enriched user experience, or technical monitoring, the BunkerWeb PRO version allows you to fully benefit from BunkerWeb and meet your professional needs.
-In the documentation or the user interface, PRO features are annotated with a crown
to distinguish them from those integrated into the open-source version.
+In the documentation or the user interface, PRO features are annotated with a crown
to distinguish them from those integrated into the open-source version.
You can upgrade from the open-source version to the PRO one easily and at any time. The process is straightforward:
- Claim your [free trial on the BunkerWeb panel](https://panel.bunkerweb.io/store/bunkerweb-pro?utm_campaign=self&utm_source=doc) by using the `freetrial` promo code at checkout
- Once connected to the client area, copy your PRO license key
-- Paste your license key into BunkerWeb using the [web UI](https://docs.bunkerweb.io/1.6.14~rc1/web-ui/#upgrade-to-pro) or a [specific setting](https://docs.bunkerweb.io/1.6.14~rc1/features/#pro)
+- Paste your license key into BunkerWeb using the [web UI](https://docs.bunkerweb.io/1.6.14~rc2/web-ui/#upgrade-to-pro) or a [specific setting](https://docs.bunkerweb.io/1.6.14~rc2/features/#pro)
Do not hesitate to visit the [BunkerWeb panel](https://panel.bunkerweb.io/knowledgebase?utm_campaign=self&utm_source=doc) or [contact us](https://panel.bunkerweb.io/contact.php?utm_campaign=self&utm_source=doc) if you have any questions regarding the PRO version.
@@ -168,10 +168,10 @@ Community and social networks:
# Concepts
-
+
-You will find more information about the key concepts of BunkerWeb in the [documentation](https://docs.bunkerweb.io/1.6.14~rc1/concepts/?utm_campaign=self&utm_source=github).
+You will find more information about the key concepts of BunkerWeb in the [documentation](https://docs.bunkerweb.io/1.6.14~rc2/concepts/?utm_campaign=self&utm_source=github).
## Integrations
@@ -179,12 +179,12 @@ The first concept is the integration of BunkerWeb into the target environment. W
The following integrations are officially supported:
-- [Docker](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#docker)
-- [Linux](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#linux)
-- [Docker autoconf](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#docker-autoconf)
-- [Kubernetes](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#kubernetes)
-- [Swarm](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#swarm)
-- [Microsoft Azure](https://docs.bunkerweb.io/1.6.14~rc1/integrations/?utm_campaign=self&utm_source=github#microsoft-azure)
+- [Docker](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#docker)
+- [Linux](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#linux)
+- [Docker autoconf](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#docker-autoconf)
+- [Kubernetes](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#kubernetes)
+- [Swarm](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#swarm)
+- [Microsoft Azure](https://docs.bunkerweb.io/1.6.14~rc2/integrations/?utm_campaign=self&utm_source=github#microsoft-azure)
## Settings
@@ -214,7 +214,7 @@ When multisite mode is enabled, BunkerWeb will serve and protect multiple web ap
## Custom configurations
-Because meeting all the use cases only using the settings is not an option (even with [external plugins](https://docs.bunkerweb.io/1.6.14~rc1/plugins/?utm_campaign=self&utm_source=github)), you can use custom configurations to solve your specific challenges.
+Because meeting all the use cases only using the settings is not an option (even with [external plugins](https://docs.bunkerweb.io/1.6.14~rc2/plugins/?utm_campaign=self&utm_source=github)), you can use custom configurations to solve your specific challenges.
Under the hood, BunkerWeb uses the notorious NGINX web server, that's why you can leverage its configuration system for your specific needs. Custom NGINX configurations can be included in different [contexts](https://docs.nginx.com/nginx/admin-guide/basic-functionality/managing-configuration-files/#contexts) like HTTP or server (all servers and/or specific server block).
@@ -223,7 +223,7 @@ Another core component of BunkerWeb is the ModSecurity Web Application Firewall:
## Database
-
+
The state of the current configuration of BunkerWeb is stored in a backend database which contains the following data:
@@ -252,7 +252,7 @@ In other words, the scheduler is the brain of BunkerWeb.
" CRLF
-"" CRLF
-"" CRLF
-"" CRLF
-"" CRLF
-"" CRLF
-;
-
-
-static u_char ngx_http_msie_refresh_head[] =
-"" CRLF;
-
-
-static char ngx_http_error_301_page[] =
-"" CRLF
-"301 Moved Permanently" CRLF
-"" CRLF
-"301 Moved Permanently
" CRLF
-;
-
-
-static char ngx_http_error_302_page[] =
-"" CRLF
-"302 Found" CRLF
-"" CRLF
-"302 Found
" CRLF
-;
-
-
-static char ngx_http_error_303_page[] =
-"" CRLF
-"303 See Other" CRLF
-"" CRLF
-"303 See Other
" CRLF
-;
-
-
-static char ngx_http_error_307_page[] =
-"" CRLF
-"307 Temporary Redirect" CRLF
-"" CRLF
-"307 Temporary Redirect
" CRLF
-;
-
-
-static char ngx_http_error_308_page[] =
-"" CRLF
-"308 Permanent Redirect" CRLF
-"" CRLF
-"308 Permanent Redirect
" CRLF
-;
-
-
-static char ngx_http_error_400_page[] =
-"" CRLF
-"400 Bad Request" CRLF
-"" CRLF
-"400 Bad Request
" CRLF
-;
-
-
-static char ngx_http_error_401_page[] =
-"" CRLF
-"401 Authorization Required" CRLF
-"" CRLF
-"401 Authorization Required
" CRLF
-;
-
-
-static char ngx_http_error_402_page[] =
-"" CRLF
-"402 Payment Required" CRLF
-"" CRLF
-"402 Payment Required
" CRLF
-;
-
-
-static char ngx_http_error_403_page[] =
-"" CRLF
-"403 Forbidden" CRLF
-"" CRLF
-"403 Forbidden
" CRLF
-;
-
-
-static char ngx_http_error_404_page[] =
-"" CRLF
-"404 Not Found" CRLF
-"" CRLF
-"404 Not Found
" CRLF
-;
-
-
-static char ngx_http_error_405_page[] =
-"" CRLF
-"405 Not Allowed" CRLF
-"" CRLF
-"405 Not Allowed
" CRLF
-;
-
-
-static char ngx_http_error_406_page[] =
-"" CRLF
-"406 Not Acceptable" CRLF
-"" CRLF
-"406 Not Acceptable
" CRLF
-;
-
-
-static char ngx_http_error_407_page[] =
-"" CRLF
-"407 Proxy Authentication Required" CRLF
-"" CRLF
-"407 Proxy Authentication Required
" CRLF
-;
-
-
-static char ngx_http_error_408_page[] =
-"" CRLF
-"408 Request Time-out" CRLF
-"" CRLF
-"408 Request Time-out
" CRLF
-;
-
-
-static char ngx_http_error_409_page[] =
-"" CRLF
-"409 Conflict" CRLF
-"" CRLF
-"409 Conflict
" CRLF
-;
-
-
-static char ngx_http_error_410_page[] =
-"" CRLF
-"410 Gone" CRLF
-"" CRLF
-"410 Gone
" CRLF
-;
-
-
-static char ngx_http_error_411_page[] =
-"" CRLF
-"411 Length Required" CRLF
-"" CRLF
-"411 Length Required
" CRLF
-;
-
-
-static char ngx_http_error_412_page[] =
-"" CRLF
-"412 Precondition Failed" CRLF
-"" CRLF
-"412 Precondition Failed
" CRLF
-;
-
-
-static char ngx_http_error_413_page[] =
-"" CRLF
-"413 Request Entity Too Large" CRLF
-"" CRLF
-"413 Request Entity Too Large
" CRLF
-;
-
-
-static char ngx_http_error_414_page[] =
-"" CRLF
-"414 Request-URI Too Large" CRLF
-"" CRLF
-"414 Request-URI Too Large
" CRLF
-;
-
-
-static char ngx_http_error_415_page[] =
-"" CRLF
-"415 Unsupported Media Type" CRLF
-"" CRLF
-"415 Unsupported Media Type
" CRLF
-;
-
-
-static char ngx_http_error_416_page[] =
-"" CRLF
-"416 Requested Range Not Satisfiable" CRLF
-"" CRLF
-"416 Requested Range Not Satisfiable
" CRLF
-;
-
-
-static char ngx_http_error_421_page[] =
-"" CRLF
-"421 Misdirected Request" CRLF
-"" CRLF
-"421 Misdirected Request
" CRLF
-;
-
-
-static char ngx_http_error_429_page[] =
-"" CRLF
-"429 Too Many Requests" CRLF
-"" CRLF
-"429 Too Many Requests
" CRLF
-;
-
-
-static char ngx_http_error_494_page[] =
-"" CRLF
-"400 Request Header Or Cookie Too Large"
-CRLF
-"" CRLF
-"400 Bad Request
" CRLF
-"Request Header Or Cookie Too Large" CRLF
-;
-
-
-static char ngx_http_error_495_page[] =
-"" CRLF
-"400 The SSL certificate error"
-CRLF
-"" CRLF
-"400 Bad Request
" CRLF
-"The SSL certificate error" CRLF
-;
-
-
-static char ngx_http_error_496_page[] =
-"" CRLF
-"400 No required SSL certificate was sent"
-CRLF
-"" CRLF
-"400 Bad Request
" CRLF
-"No required SSL certificate was sent" CRLF
-;
-
-
-static char ngx_http_error_497_page[] =
-"" CRLF
-"400 The plain HTTP request was sent to HTTPS port"
-CRLF
-"" CRLF
-"400 Bad Request
" CRLF
-"The plain HTTP request was sent to HTTPS port" CRLF
-;
-
-
-static char ngx_http_error_500_page[] =
-"" CRLF
-"500 Internal Server Error" CRLF
-"" CRLF
-"500 Internal Server Error
" CRLF
-;
-
-
-static char ngx_http_error_501_page[] =
-"" CRLF
-"501 Not Implemented" CRLF
-"" CRLF
-"501 Not Implemented
" CRLF
-;
-
-
-static char ngx_http_error_502_page[] =
-"" CRLF
-"502 Bad Gateway" CRLF
-"" CRLF
-"502 Bad Gateway
" CRLF
-;
-
-
-static char ngx_http_error_503_page[] =
-"" CRLF
-"503 Service Temporarily Unavailable" CRLF
-"" CRLF
-"503 Service Temporarily Unavailable
" CRLF
-;
-
-
-static char ngx_http_error_504_page[] =
-"" CRLF
-"504 Gateway Time-out" CRLF
-"" CRLF
-"504 Gateway Time-out
" CRLF
-;
-
-
-static char ngx_http_error_505_page[] =
-"" CRLF
-"505 HTTP Version Not Supported" CRLF
-"" CRLF
-"505 HTTP Version Not Supported
" CRLF
-;
-
-
-static char ngx_http_error_507_page[] =
-"" CRLF
-"507 Insufficient Storage" CRLF
-"" CRLF
-"507 Insufficient Storage
" CRLF
-;
-
-
-static ngx_str_t ngx_http_error_pages[] = {
-
- ngx_null_string, /* 201, 204 */
-
-#define NGX_HTTP_LAST_2XX 202
-#define NGX_HTTP_OFF_3XX (NGX_HTTP_LAST_2XX - 201)
-
- /* ngx_null_string, */ /* 300 */
- ngx_string(ngx_http_error_301_page),
- ngx_string(ngx_http_error_302_page),
- ngx_string(ngx_http_error_303_page),
- ngx_null_string, /* 304 */
- ngx_null_string, /* 305 */
- ngx_null_string, /* 306 */
- ngx_string(ngx_http_error_307_page),
- ngx_string(ngx_http_error_308_page),
-
-#define NGX_HTTP_LAST_3XX 309
-#define NGX_HTTP_OFF_4XX (NGX_HTTP_LAST_3XX - 301 + NGX_HTTP_OFF_3XX)
-
- ngx_string(ngx_http_error_400_page),
- ngx_string(ngx_http_error_401_page),
- ngx_string(ngx_http_error_402_page),
- ngx_string(ngx_http_error_403_page),
- ngx_string(ngx_http_error_404_page),
- ngx_string(ngx_http_error_405_page),
- ngx_string(ngx_http_error_406_page),
- ngx_string(ngx_http_error_407_page),
- ngx_string(ngx_http_error_408_page),
- ngx_string(ngx_http_error_409_page),
- ngx_string(ngx_http_error_410_page),
- ngx_string(ngx_http_error_411_page),
- ngx_string(ngx_http_error_412_page),
- ngx_string(ngx_http_error_413_page),
- ngx_string(ngx_http_error_414_page),
- ngx_string(ngx_http_error_415_page),
- ngx_string(ngx_http_error_416_page),
- ngx_null_string, /* 417 */
- ngx_null_string, /* 418 */
- ngx_null_string, /* 419 */
- ngx_null_string, /* 420 */
- ngx_string(ngx_http_error_421_page),
- ngx_null_string, /* 422 */
- ngx_null_string, /* 423 */
- ngx_null_string, /* 424 */
- ngx_null_string, /* 425 */
- ngx_null_string, /* 426 */
- ngx_null_string, /* 427 */
- ngx_null_string, /* 428 */
- ngx_string(ngx_http_error_429_page),
-
-#define NGX_HTTP_LAST_4XX 430
-#define NGX_HTTP_OFF_5XX (NGX_HTTP_LAST_4XX - 400 + NGX_HTTP_OFF_4XX)
-
- ngx_string(ngx_http_error_494_page), /* 494, request header too large */
- ngx_string(ngx_http_error_495_page), /* 495, https certificate error */
- ngx_string(ngx_http_error_496_page), /* 496, https no certificate */
- ngx_string(ngx_http_error_497_page), /* 497, http to https */
- ngx_string(ngx_http_error_404_page), /* 498, canceled */
- ngx_null_string, /* 499, client has closed connection */
-
- ngx_string(ngx_http_error_500_page),
- ngx_string(ngx_http_error_501_page),
- ngx_string(ngx_http_error_502_page),
- ngx_string(ngx_http_error_503_page),
- ngx_string(ngx_http_error_504_page),
- ngx_string(ngx_http_error_505_page),
- ngx_null_string, /* 506 */
- ngx_string(ngx_http_error_507_page)
-
-#define NGX_HTTP_LAST_5XX 508
-
-};
-
-
-ngx_int_t
-ngx_http_special_response_handler(ngx_http_request_t *r, ngx_int_t error)
-{
- ngx_uint_t i, err;
- ngx_http_err_page_t *err_page;
- ngx_http_core_loc_conf_t *clcf;
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http special response: %i, \"%V?%V\"",
- error, &r->uri, &r->args);
-
- r->err_status = error;
-
- if (r->keepalive) {
- switch (error) {
- case NGX_HTTP_BAD_REQUEST:
- case NGX_HTTP_REQUEST_ENTITY_TOO_LARGE:
- case NGX_HTTP_REQUEST_URI_TOO_LARGE:
- case NGX_HTTP_TO_HTTPS:
- case NGX_HTTPS_CERT_ERROR:
- case NGX_HTTPS_NO_CERT:
- case NGX_HTTP_INTERNAL_SERVER_ERROR:
- case NGX_HTTP_NOT_IMPLEMENTED:
- r->keepalive = 0;
- }
- }
-
- if (r->lingering_close) {
- switch (error) {
- case NGX_HTTP_BAD_REQUEST:
- case NGX_HTTP_TO_HTTPS:
- case NGX_HTTPS_CERT_ERROR:
- case NGX_HTTPS_NO_CERT:
- r->lingering_close = 0;
- }
- }
-
- r->headers_out.content_type.len = 0;
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (!r->error_page && clcf->error_pages && r->uri_changes != 0) {
-
- if (clcf->recursive_error_pages == 0) {
- r->error_page = 1;
- }
-
- err_page = clcf->error_pages->elts;
-
- for (i = 0; i < clcf->error_pages->nelts; i++) {
- if (err_page[i].status == error) {
- return ngx_http_send_error_page(r, &err_page[i]);
- }
- }
- }
-
- r->expect_tested = 1;
-
- if (ngx_http_discard_request_body(r) != NGX_OK) {
- r->keepalive = 0;
- }
-
- if (clcf->msie_refresh
- && r->headers_in.msie
- && (error == NGX_HTTP_MOVED_PERMANENTLY
- || error == NGX_HTTP_MOVED_TEMPORARILY))
- {
- return ngx_http_send_refresh(r);
- }
-
- if (error == NGX_HTTP_CREATED) {
- /* 201 */
- err = 0;
-
- } else if (error == NGX_HTTP_NO_CONTENT) {
- /* 204 */
- err = 0;
-
- } else if (error >= NGX_HTTP_MOVED_PERMANENTLY
- && error < NGX_HTTP_LAST_3XX)
- {
- /* 3XX */
- err = error - NGX_HTTP_MOVED_PERMANENTLY + NGX_HTTP_OFF_3XX;
-
- } else if (error >= NGX_HTTP_BAD_REQUEST
- && error < NGX_HTTP_LAST_4XX)
- {
- /* 4XX */
- err = error - NGX_HTTP_BAD_REQUEST + NGX_HTTP_OFF_4XX;
-
- } else if (error >= NGX_HTTP_NGINX_CODES
- && error < NGX_HTTP_LAST_5XX)
- {
- /* 49X, 5XX */
- err = error - NGX_HTTP_NGINX_CODES + NGX_HTTP_OFF_5XX;
- switch (error) {
- case NGX_HTTP_TO_HTTPS:
- case NGX_HTTPS_CERT_ERROR:
- case NGX_HTTPS_NO_CERT:
- case NGX_HTTP_REQUEST_HEADER_TOO_LARGE:
- r->err_status = NGX_HTTP_BAD_REQUEST;
- }
-
- } else {
- /* unknown code, zero body */
- err = 0;
- }
-
- return ngx_http_send_special_response(r, clcf, err);
-}
-
-
-ngx_int_t
-ngx_http_filter_finalize_request(ngx_http_request_t *r, ngx_module_t *m,
- ngx_int_t error)
-{
- void *ctx;
- ngx_int_t rc;
-
- ngx_http_clean_header(r);
-
- ctx = NULL;
-
- if (m) {
- ctx = r->ctx[m->ctx_index];
- }
-
- /* clear the modules contexts */
- ngx_memzero(r->ctx, sizeof(void *) * ngx_http_max_module);
-
- if (m) {
- r->ctx[m->ctx_index] = ctx;
- }
-
- r->filter_finalize = 1;
-
- rc = ngx_http_special_response_handler(r, error);
-
- /* NGX_ERROR resets any pending data */
-
- switch (rc) {
-
- case NGX_OK:
- case NGX_DONE:
- return NGX_ERROR;
-
- default:
- return rc;
- }
-}
-
-
-void
-ngx_http_clean_header(ngx_http_request_t *r)
-{
- ngx_memzero(&r->headers_out.status,
- sizeof(ngx_http_headers_out_t)
- - offsetof(ngx_http_headers_out_t, status));
-
- r->headers_out.headers.part.nelts = 0;
- r->headers_out.headers.part.next = NULL;
- r->headers_out.headers.last = &r->headers_out.headers.part;
-
- r->headers_out.trailers.part.nelts = 0;
- r->headers_out.trailers.part.next = NULL;
- r->headers_out.trailers.last = &r->headers_out.trailers.part;
-
- r->headers_out.content_length_n = -1;
- r->headers_out.last_modified_time = -1;
-}
-
-
-static ngx_int_t
-ngx_http_send_error_page(ngx_http_request_t *r, ngx_http_err_page_t *err_page)
-{
- ngx_int_t overwrite;
- ngx_str_t uri, args;
- ngx_table_elt_t *location;
- ngx_http_core_loc_conf_t *clcf;
-
- overwrite = err_page->overwrite;
-
- if (overwrite && overwrite != NGX_HTTP_OK) {
- r->expect_tested = 1;
- }
-
- if (overwrite >= 0) {
- r->err_status = overwrite;
- }
-
- if (ngx_http_complex_value(r, &err_page->value, &uri) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (uri.len && uri.data[0] == '/') {
-
- if (err_page->value.lengths) {
- ngx_http_split_args(r, &uri, &args);
-
- } else {
- args = err_page->args;
- }
-
- if (r->method != NGX_HTTP_HEAD) {
- r->method = NGX_HTTP_GET;
- r->method_name = ngx_http_core_get_method;
- }
-
- return ngx_http_internal_redirect(r, &uri, &args);
- }
-
- if (uri.len && uri.data[0] == '@') {
- return ngx_http_named_location(r, &uri);
- }
-
- r->expect_tested = 1;
-
- if (ngx_http_discard_request_body(r) != NGX_OK) {
- r->keepalive = 0;
- }
-
- location = ngx_list_push(&r->headers_out.headers);
-
- if (location == NULL) {
- return NGX_ERROR;
- }
-
- if (overwrite != NGX_HTTP_MOVED_PERMANENTLY
- && overwrite != NGX_HTTP_MOVED_TEMPORARILY
- && overwrite != NGX_HTTP_SEE_OTHER
- && overwrite != NGX_HTTP_TEMPORARY_REDIRECT
- && overwrite != NGX_HTTP_PERMANENT_REDIRECT)
- {
- r->err_status = NGX_HTTP_MOVED_TEMPORARILY;
- }
-
- location->hash = 1;
- location->next = NULL;
- ngx_str_set(&location->key, "Location");
- location->value = uri;
-
- ngx_http_clear_location(r);
-
- r->headers_out.location = location;
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->msie_refresh && r->headers_in.msie) {
- return ngx_http_send_refresh(r);
- }
-
- return ngx_http_send_special_response(r, clcf, r->err_status
- - NGX_HTTP_MOVED_PERMANENTLY
- + NGX_HTTP_OFF_3XX);
-}
-
-
-static ngx_int_t
-ngx_http_send_special_response(ngx_http_request_t *r,
- ngx_http_core_loc_conf_t *clcf, ngx_uint_t err)
-{
- u_char *tail;
- size_t len;
- ngx_int_t rc;
- ngx_buf_t *b;
- ngx_uint_t msie_padding;
- ngx_chain_t out[3];
-
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- len = sizeof(ngx_http_error_full_tail) - 1;
- tail = ngx_http_error_full_tail;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- len = sizeof(ngx_http_error_build_tail) - 1;
- tail = ngx_http_error_build_tail;
-
- } else {
- len = sizeof(ngx_http_error_tail) - 1;
- tail = ngx_http_error_tail;
- }
-
- msie_padding = 0;
-
- if (ngx_http_error_pages[err].len) {
- r->headers_out.content_length_n = ngx_http_error_pages[err].len + len;
- if (clcf->msie_padding
- && (r->headers_in.msie || r->headers_in.chrome)
- && r->http_version >= NGX_HTTP_VERSION_10
- && err >= NGX_HTTP_OFF_4XX)
- {
- r->headers_out.content_length_n +=
- sizeof(ngx_http_msie_padding) - 1;
- msie_padding = 1;
- }
-
- r->headers_out.content_type_len = sizeof("text/html") - 1;
- ngx_str_set(&r->headers_out.content_type, "text/html");
- r->headers_out.content_type_lowcase = NULL;
-
- } else {
- r->headers_out.content_length_n = 0;
- }
-
- if (r->headers_out.content_length) {
- r->headers_out.content_length->hash = 0;
- r->headers_out.content_length = NULL;
- }
-
- ngx_http_clear_accept_ranges(r);
- ngx_http_clear_last_modified(r);
- ngx_http_clear_etag(r);
-
- rc = ngx_http_send_header(r);
-
- if (rc == NGX_ERROR || r->header_only) {
- return rc;
- }
-
- if (ngx_http_error_pages[err].len == 0) {
- return ngx_http_send_special(r, NGX_HTTP_LAST);
- }
-
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->memory = 1;
- b->pos = ngx_http_error_pages[err].data;
- b->last = ngx_http_error_pages[err].data + ngx_http_error_pages[err].len;
-
- out[0].buf = b;
- out[0].next = &out[1];
-
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->memory = 1;
-
- b->pos = tail;
- b->last = tail + len;
-
- out[1].buf = b;
- out[1].next = NULL;
-
- if (msie_padding) {
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->memory = 1;
- b->pos = ngx_http_msie_padding;
- b->last = ngx_http_msie_padding + sizeof(ngx_http_msie_padding) - 1;
-
- out[1].next = &out[2];
- out[2].buf = b;
- out[2].next = NULL;
- }
-
- if (r == r->main) {
- b->last_buf = 1;
- }
-
- b->last_in_chain = 1;
-
- return ngx_http_output_filter(r, &out[0]);
-}
-
-
-static ngx_int_t
-ngx_http_send_refresh(ngx_http_request_t *r)
-{
- u_char *p, *location;
- size_t len, size;
- uintptr_t escape;
- ngx_int_t rc;
- ngx_buf_t *b;
- ngx_chain_t out;
-
- len = r->headers_out.location->value.len;
- location = r->headers_out.location->value.data;
-
- escape = 2 * ngx_escape_uri(NULL, location, len, NGX_ESCAPE_REFRESH);
-
- size = sizeof(ngx_http_msie_refresh_head) - 1
- + escape + len
- + sizeof(ngx_http_msie_refresh_tail) - 1;
-
- r->err_status = NGX_HTTP_OK;
-
- r->headers_out.content_type_len = sizeof("text/html") - 1;
- ngx_str_set(&r->headers_out.content_type, "text/html");
- r->headers_out.content_type_lowcase = NULL;
-
- r->headers_out.location->hash = 0;
- r->headers_out.location = NULL;
-
- r->headers_out.content_length_n = size;
-
- if (r->headers_out.content_length) {
- r->headers_out.content_length->hash = 0;
- r->headers_out.content_length = NULL;
- }
-
- ngx_http_clear_accept_ranges(r);
- ngx_http_clear_last_modified(r);
- ngx_http_clear_etag(r);
-
- rc = ngx_http_send_header(r);
-
- if (rc == NGX_ERROR || r->header_only) {
- return rc;
- }
-
- b = ngx_create_temp_buf(r->pool, size);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- p = ngx_cpymem(b->pos, ngx_http_msie_refresh_head,
- sizeof(ngx_http_msie_refresh_head) - 1);
-
- if (escape == 0) {
- p = ngx_cpymem(p, location, len);
-
- } else {
- p = (u_char *) ngx_escape_uri(p, location, len, NGX_ESCAPE_REFRESH);
- }
-
- b->last = ngx_cpymem(p, ngx_http_msie_refresh_tail,
- sizeof(ngx_http_msie_refresh_tail) - 1);
-
- b->last_buf = (r == r->main) ? 1 : 0;
- b->last_in_chain = 1;
-
- out.buf = b;
- out.next = NULL;
-
- return ngx_http_output_filter(r, &out);
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.c b/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.c
deleted file mode 100644
index b645613693..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.c
+++ /dev/null
@@ -1,7305 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-#if (NGX_HTTP_CACHE)
-static ngx_int_t ngx_http_upstream_cache(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_cache_get(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_http_file_cache_t **cache);
-static ngx_int_t ngx_http_upstream_cache_send(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_cache_background_update(
- ngx_http_request_t *r, ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_cache_status(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_cache_last_modified(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_cache_etag(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-#endif
-
-static void ngx_http_upstream_init_request(ngx_http_request_t *r);
-static void ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx);
-static void ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r);
-static void ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r);
-static void ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
- ngx_event_t *ev);
-static void ngx_http_upstream_connect(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_reinit(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_send_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_uint_t do_write);
-static ngx_int_t ngx_http_upstream_send_request_body(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_uint_t do_write);
-static void ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_read_request_handler(ngx_http_request_t *r);
-static void ngx_http_upstream_process_header(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_process_early_hints(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_early_hints_writer(ngx_http_request_t *r);
-static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_test_connect(ngx_connection_t *c);
-static ngx_int_t ngx_http_upstream_process_headers(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static ngx_int_t ngx_http_upstream_process_trailers(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_send_response(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_upgrade(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_upgraded_read_downstream(ngx_http_request_t *r);
-static void ngx_http_upstream_upgraded_write_downstream(ngx_http_request_t *r);
-static void ngx_http_upstream_upgraded_read_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_upgraded_write_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_process_upgraded(ngx_http_request_t *r,
- ngx_uint_t from_upstream, ngx_uint_t do_write);
-static void
- ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r);
-static void
- ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void
- ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
- ngx_uint_t do_write);
-#if (NGX_THREADS)
-static ngx_int_t ngx_http_upstream_thread_handler(ngx_thread_task_t *task,
- ngx_file_t *file);
-static void ngx_http_upstream_thread_event_handler(ngx_event_t *ev);
-#endif
-static ngx_int_t ngx_http_upstream_output_filter(void *data,
- ngx_chain_t *chain);
-static void ngx_http_upstream_process_downstream(ngx_http_request_t *r);
-static void ngx_http_upstream_process_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_process_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_store(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_dummy_handler(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-static void ngx_http_upstream_next(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_uint_t ft_type);
-static void ngx_http_upstream_cleanup(void *data);
-static void ngx_http_upstream_finalize_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_int_t rc);
-
-static ngx_int_t ngx_http_upstream_process_header_line(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t
- ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_content_length(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_set_cookie(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t
- ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-#if (NGX_HTTP_CACHE)
-static ngx_int_t ngx_http_upstream_process_delta_seconds(u_char *p,
- u_char *last);
-#endif
-static ngx_int_t ngx_http_upstream_ignore_header_line(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_expires(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_accel_expires(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_limit_rate(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_buffering(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_charset(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_connection(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t
- ngx_http_upstream_process_transfer_encoding(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_process_vary(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_copy_header_line(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t
- ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_copy_content_type(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_copy_last_modified(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_rewrite_location(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-static ngx_int_t ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset);
-
-static ngx_int_t ngx_http_upstream_add_variables(ngx_conf_t *cf);
-static ngx_int_t ngx_http_upstream_addr_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_status_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_response_length_variable(
- ngx_http_request_t *r, ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_header_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_trailer_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static char *ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy);
-static char *ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-#if (NGX_HTTP_UPSTREAM_ZONE)
-static char *ngx_http_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-#endif
-
-static ngx_int_t ngx_http_upstream_set_local(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_http_upstream_local_t *local);
-
-static void *ngx_http_upstream_create_main_conf(ngx_conf_t *cf);
-static char *ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf);
-
-#if (NGX_HTTP_SSL)
-static void ngx_http_upstream_ssl_init_connection(ngx_http_request_t *,
- ngx_http_upstream_t *u, ngx_connection_t *c);
-static void ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c);
-static void ngx_http_upstream_ssl_handshake(ngx_http_request_t *,
- ngx_http_upstream_t *u, ngx_connection_t *c);
-static void ngx_http_upstream_ssl_save_session(ngx_connection_t *c);
-static ngx_int_t ngx_http_upstream_ssl_name(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_connection_t *c);
-static ngx_int_t ngx_http_upstream_ssl_certificate(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_connection_t *c);
-#endif
-
-
-static ngx_http_upstream_header_t ngx_http_upstream_headers_in[] = {
-
- { ngx_string("Status"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, status),
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("Content-Type"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, content_type),
- ngx_http_upstream_copy_content_type, 0, 1 },
-
- { ngx_string("Content-Length"),
- ngx_http_upstream_process_content_length, 0,
- ngx_http_upstream_ignore_header_line, 0, 0 },
-
- { ngx_string("Date"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, date),
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, date), 0 },
-
- { ngx_string("Last-Modified"),
- ngx_http_upstream_process_last_modified, 0,
- ngx_http_upstream_copy_last_modified, 0, 0 },
-
- { ngx_string("ETag"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, etag),
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, etag), 0 },
-
- { ngx_string("Server"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, server),
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, server), 0 },
-
- { ngx_string("WWW-Authenticate"),
- ngx_http_upstream_process_multi_header_lines,
- offsetof(ngx_http_upstream_headers_in_t, www_authenticate),
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("Location"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, location),
- ngx_http_upstream_rewrite_location, 0, 0 },
-
- { ngx_string("Refresh"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, refresh),
- ngx_http_upstream_rewrite_refresh, 0, 0 },
-
- { ngx_string("Set-Cookie"),
- ngx_http_upstream_process_set_cookie,
- offsetof(ngx_http_upstream_headers_in_t, set_cookie),
- ngx_http_upstream_rewrite_set_cookie, 0, 1 },
-
- { ngx_string("Content-Disposition"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_copy_header_line, 0, 1 },
-
- { ngx_string("Cache-Control"),
- ngx_http_upstream_process_cache_control, 0,
- ngx_http_upstream_copy_multi_header_lines,
- offsetof(ngx_http_headers_out_t, cache_control), 1 },
-
- { ngx_string("Expires"),
- ngx_http_upstream_process_expires, 0,
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, expires), 1 },
-
- { ngx_string("Accept-Ranges"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_copy_allow_ranges,
- offsetof(ngx_http_headers_out_t, accept_ranges), 1 },
-
- { ngx_string("Content-Range"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, content_range), 0 },
-
- { ngx_string("Connection"),
- ngx_http_upstream_process_connection, 0,
- ngx_http_upstream_ignore_header_line, 0, 0 },
-
- { ngx_string("Keep-Alive"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_ignore_header_line, 0, 0 },
-
- { ngx_string("Vary"),
- ngx_http_upstream_process_vary, 0,
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("Link"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_copy_multi_header_lines,
- offsetof(ngx_http_headers_out_t, link), 0 },
-
- { ngx_string("X-Accel-Expires"),
- ngx_http_upstream_process_accel_expires, 0,
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("X-Accel-Redirect"),
- ngx_http_upstream_process_header_line,
- offsetof(ngx_http_upstream_headers_in_t, x_accel_redirect),
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("X-Accel-Limit-Rate"),
- ngx_http_upstream_process_limit_rate, 0,
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("X-Accel-Buffering"),
- ngx_http_upstream_process_buffering, 0,
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("X-Accel-Charset"),
- ngx_http_upstream_process_charset, 0,
- ngx_http_upstream_copy_header_line, 0, 0 },
-
- { ngx_string("Transfer-Encoding"),
- ngx_http_upstream_process_transfer_encoding, 0,
- ngx_http_upstream_ignore_header_line, 0, 0 },
-
- { ngx_string("Content-Encoding"),
- ngx_http_upstream_ignore_header_line, 0,
- ngx_http_upstream_copy_header_line,
- offsetof(ngx_http_headers_out_t, content_encoding), 0 },
-
- { ngx_null_string, NULL, 0, NULL, 0, 0 }
-};
-
-
-static ngx_command_t ngx_http_upstream_commands[] = {
-
- { ngx_string("upstream"),
- NGX_HTTP_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_TAKE1,
- ngx_http_upstream,
- 0,
- 0,
- NULL },
-
- { ngx_string("server"),
- NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
- ngx_http_upstream_server,
- NGX_HTTP_SRV_CONF_OFFSET,
- 0,
- NULL },
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-
- { ngx_string("resolver"),
- NGX_HTTP_UPS_CONF|NGX_CONF_1MORE,
- ngx_http_upstream_resolver,
- NGX_HTTP_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("resolver_timeout"),
- NGX_HTTP_UPS_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_upstream_srv_conf_t, resolver_timeout),
- NULL },
-
-#endif
-
- ngx_null_command
-};
-
-
-static ngx_http_module_t ngx_http_upstream_module_ctx = {
- ngx_http_upstream_add_variables, /* preconfiguration */
- NULL, /* postconfiguration */
-
- ngx_http_upstream_create_main_conf, /* create main configuration */
- ngx_http_upstream_init_main_conf, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_upstream_module = {
- NGX_MODULE_V1,
- &ngx_http_upstream_module_ctx, /* module context */
- ngx_http_upstream_commands, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_http_variable_t ngx_http_upstream_vars[] = {
-
- { ngx_string("upstream_addr"), NULL,
- ngx_http_upstream_addr_variable, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_status"), NULL,
- ngx_http_upstream_status_variable, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_connect_time"), NULL,
- ngx_http_upstream_response_time_variable, 2,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_header_time"), NULL,
- ngx_http_upstream_response_time_variable, 1,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_response_time"), NULL,
- ngx_http_upstream_response_time_variable, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_response_length"), NULL,
- ngx_http_upstream_response_length_variable, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_bytes_received"), NULL,
- ngx_http_upstream_response_length_variable, 1,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_bytes_sent"), NULL,
- ngx_http_upstream_response_length_variable, 2,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
-#if (NGX_HTTP_CACHE)
-
- { ngx_string("upstream_cache_status"), NULL,
- ngx_http_upstream_cache_status, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("upstream_cache_last_modified"), NULL,
- ngx_http_upstream_cache_last_modified, 0,
- NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
-
- { ngx_string("upstream_cache_etag"), NULL,
- ngx_http_upstream_cache_etag, 0,
- NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_NOHASH, 0 },
-
-#endif
-
- { ngx_string("upstream_http_"), NULL, ngx_http_upstream_header_variable,
- 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("upstream_trailer_"), NULL, ngx_http_upstream_trailer_variable,
- 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("upstream_cookie_"), NULL, ngx_http_upstream_cookie_variable,
- 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
-
- ngx_http_null_variable
-};
-
-
-static ngx_http_upstream_next_t ngx_http_upstream_next_errors[] = {
- { 500, NGX_HTTP_UPSTREAM_FT_HTTP_500 },
- { 502, NGX_HTTP_UPSTREAM_FT_HTTP_502 },
- { 503, NGX_HTTP_UPSTREAM_FT_HTTP_503 },
- { 504, NGX_HTTP_UPSTREAM_FT_HTTP_504 },
- { 403, NGX_HTTP_UPSTREAM_FT_HTTP_403 },
- { 404, NGX_HTTP_UPSTREAM_FT_HTTP_404 },
- { 429, NGX_HTTP_UPSTREAM_FT_HTTP_429 },
- { 0, 0 }
-};
-
-
-ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[] = {
- { ngx_string("GET"), NGX_HTTP_GET },
- { ngx_string("HEAD"), NGX_HTTP_HEAD },
- { ngx_string("POST"), NGX_HTTP_POST },
- { ngx_null_string, 0 }
-};
-
-
-ngx_conf_bitmask_t ngx_http_upstream_ignore_headers_masks[] = {
- { ngx_string("X-Accel-Redirect"), NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT },
- { ngx_string("X-Accel-Expires"), NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES },
- { ngx_string("X-Accel-Limit-Rate"), NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE },
- { ngx_string("X-Accel-Buffering"), NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING },
- { ngx_string("X-Accel-Charset"), NGX_HTTP_UPSTREAM_IGN_XA_CHARSET },
- { ngx_string("Expires"), NGX_HTTP_UPSTREAM_IGN_EXPIRES },
- { ngx_string("Cache-Control"), NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL },
- { ngx_string("Set-Cookie"), NGX_HTTP_UPSTREAM_IGN_SET_COOKIE },
- { ngx_string("Vary"), NGX_HTTP_UPSTREAM_IGN_VARY },
- { ngx_null_string, 0 }
-};
-
-
-ngx_int_t
-ngx_http_upstream_create(ngx_http_request_t *r)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u && u->cleanup) {
- r->main->count++;
- ngx_http_upstream_cleanup(r);
- }
-
- u = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_t));
- if (u == NULL) {
- return NGX_ERROR;
- }
-
- r->upstream = u;
-
- u->peer.log = r->connection->log;
- u->peer.log_error = NGX_ERROR_ERR;
-
-#if (NGX_HTTP_CACHE)
- r->cache = NULL;
-#endif
-
- u->headers_in.content_length_n = -1;
- u->headers_in.last_modified_time = -1;
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_upstream_init(ngx_http_request_t *r)
-{
- ngx_connection_t *c;
-
- c = r->connection;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http init upstream, client timer: %d", c->read->timer_set);
-
-#if (NGX_HTTP_V2)
- if (r->stream) {
- ngx_http_upstream_init_request(r);
- return;
- }
-#endif
-
-#if (NGX_HTTP_V3)
- if (c->quic) {
- ngx_http_upstream_init_request(r);
- return;
- }
-#endif
-
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
- if (ngx_event_flags & NGX_USE_CLEAR_EVENT) {
-
- if (!c->write->active) {
- if (ngx_add_event(c->write, NGX_WRITE_EVENT, NGX_CLEAR_EVENT)
- == NGX_ERROR)
- {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
- }
-
- ngx_http_upstream_init_request(r);
-}
-
-
-static void
-ngx_http_upstream_init_request(ngx_http_request_t *r)
-{
- ngx_str_t *host;
- ngx_uint_t i;
- ngx_resolver_ctx_t *ctx, temp;
- ngx_http_cleanup_t *cln;
- ngx_http_upstream_t *u;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_upstream_srv_conf_t *uscf, **uscfp;
- ngx_http_upstream_main_conf_t *umcf;
-
- if (r->aio) {
- return;
- }
-
- u = r->upstream;
-
-#if (NGX_HTTP_CACHE)
-
- if (u->conf->cache) {
- ngx_int_t rc;
-
- rc = ngx_http_upstream_cache(r, u);
-
- if (rc == NGX_BUSY) {
- r->write_event_handler = ngx_http_upstream_init_request;
- return;
- }
-
- r->write_event_handler = ngx_http_request_empty_handler;
-
- if (rc == NGX_ERROR) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (rc == NGX_OK) {
- rc = ngx_http_upstream_cache_send(r, u);
-
- if (rc == NGX_DONE) {
- return;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_DECLINED;
- r->cached = 0;
- u->buffer.start = NULL;
- u->cache_status = NGX_HTTP_CACHE_MISS;
- u->request_sent = 1;
- }
- }
-
- if (rc != NGX_DECLINED) {
- ngx_http_finalize_request(r, rc);
- return;
- }
- }
-
-#endif
-
- u->store = u->conf->store;
-
- if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
-
- if (r->connection->read->ready) {
- ngx_post_event(r->connection->read, &ngx_posted_events);
-
- } else {
- if (ngx_handle_read_event(r->connection->read, 0) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- r->read_event_handler = ngx_http_upstream_rd_check_broken_connection;
- r->write_event_handler = ngx_http_upstream_wr_check_broken_connection;
- }
-
- if (r->request_body) {
- u->request_bufs = r->request_body->bufs;
- }
-
- if (u->create_request(r) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (ngx_http_upstream_set_local(r, u, u->conf->local) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (u->conf->socket_keepalive) {
- u->peer.so_keepalive = 1;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- u->output.alignment = clcf->directio_alignment;
- u->output.pool = r->pool;
- u->output.bufs.num = 1;
- u->output.bufs.size = clcf->client_body_buffer_size;
-
- if (u->output.output_filter == NULL) {
- u->output.output_filter = ngx_chain_writer;
- u->output.filter_ctx = &u->writer;
- }
-
- u->writer.pool = r->pool;
-
- if (r->upstream_states == NULL) {
-
- r->upstream_states = ngx_array_create(r->pool, 1,
- sizeof(ngx_http_upstream_state_t));
- if (r->upstream_states == NULL) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- } else {
-
- u->state = ngx_array_push(r->upstream_states);
- if (u->state == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
- }
-
- cln = ngx_http_cleanup_add(r, 0);
- if (cln == NULL) {
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- cln->handler = ngx_http_upstream_cleanup;
- cln->data = r;
- u->cleanup = &cln->handler;
-
- if (u->resolved == NULL) {
-
- uscf = u->conf->upstream;
-
- } else {
-
-#if (NGX_HTTP_SSL)
- u->ssl_name = u->resolved->host;
-#endif
-
- host = &u->resolved->host;
-
- umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
-
- uscfp = umcf->upstreams.elts;
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
-
- uscf = uscfp[i];
-
- if (uscf->host.len == host->len
- && ((uscf->port == 0 && u->resolved->no_port)
- || uscf->port == u->resolved->port)
- && ngx_strncasecmp(uscf->host.data, host->data, host->len) == 0)
- {
- goto found;
- }
- }
-
- if (u->resolved->sockaddr) {
-
- if (u->resolved->port == 0
- && u->resolved->sockaddr->sa_family != AF_UNIX)
- {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "no port in upstream \"%V\"", host);
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- ngx_http_upstream_connect(r, u);
-
- return;
- }
-
- if (u->resolved->port == 0) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "no port in upstream \"%V\"", host);
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- temp.name = *host;
-
- ctx = ngx_resolve_start(clcf->resolver, &temp);
- if (ctx == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (ctx == NGX_NO_RESOLVER) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "no resolver defined to resolve %V", host);
-
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
- return;
- }
-
- ctx->name = *host;
- ctx->handler = ngx_http_upstream_resolve_handler;
- ctx->data = r;
- ctx->timeout = clcf->resolver_timeout;
-
- u->resolved->ctx = ctx;
-
- if (ngx_resolve_name(ctx) != NGX_OK) {
- u->resolved->ctx = NULL;
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- return;
- }
-
-found:
-
- if (uscf == NULL) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "no upstream configuration");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->upstream = uscf;
-
-#if (NGX_HTTP_SSL)
- u->ssl_name = uscf->host;
-#endif
-
- if (uscf->peer.init(r, uscf) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->peer.start_time = ngx_current_msec;
-
- if (u->conf->next_upstream_tries
- && u->peer.tries > u->conf->next_upstream_tries)
- {
- u->peer.tries = u->conf->next_upstream_tries;
- }
-
- ngx_http_upstream_connect(r, u);
-}
-
-
-#if (NGX_HTTP_CACHE)
-
-static ngx_int_t
-ngx_http_upstream_cache(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_int_t rc;
- ngx_http_cache_t *c;
- ngx_http_file_cache_t *cache;
-
- c = r->cache;
-
- if (c == NULL) {
-
- if (!(r->method & u->conf->cache_methods)) {
- return NGX_DECLINED;
- }
-
- rc = ngx_http_upstream_cache_get(r, u, &cache);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (r->method == NGX_HTTP_HEAD && u->conf->cache_convert_head) {
- u->method = ngx_http_core_get_method;
- }
-
- if (ngx_http_file_cache_new(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (u->create_key(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- /* TODO: add keys */
-
- ngx_http_file_cache_create_key(r);
-
- if (r->cache->header_start + 256 > u->conf->buffer_size) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "%V_buffer_size %uz is not enough for cache key, "
- "it should be increased to at least %uz",
- &u->conf->module, u->conf->buffer_size,
- ngx_align(r->cache->header_start + 256, 1024));
-
- r->cache = NULL;
- return NGX_DECLINED;
- }
-
- u->cacheable = 1;
-
- c = r->cache;
-
- c->body_start = u->conf->buffer_size;
- c->min_uses = u->conf->cache_min_uses;
- c->file_cache = cache;
-
- switch (ngx_http_test_predicates(r, u->conf->cache_bypass)) {
-
- case NGX_ERROR:
- return NGX_ERROR;
-
- case NGX_DECLINED:
- u->cache_status = NGX_HTTP_CACHE_BYPASS;
- return NGX_DECLINED;
-
- default: /* NGX_OK */
- break;
- }
-
- c->lock = u->conf->cache_lock;
- c->lock_timeout = u->conf->cache_lock_timeout;
- c->lock_age = u->conf->cache_lock_age;
-
- u->cache_status = NGX_HTTP_CACHE_MISS;
- }
-
- rc = ngx_http_file_cache_open(r);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream cache: %i", rc);
-
- switch (rc) {
-
- case NGX_HTTP_CACHE_STALE:
-
- if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
- || c->stale_updating) && !r->background
- && u->conf->cache_background_update)
- {
- if (ngx_http_upstream_cache_background_update(r, u) == NGX_OK) {
- r->cache->background = 1;
- u->cache_status = rc;
- rc = NGX_OK;
-
- } else {
- rc = NGX_ERROR;
- }
- }
-
- break;
-
- case NGX_HTTP_CACHE_UPDATING:
-
- if (((u->conf->cache_use_stale & NGX_HTTP_UPSTREAM_FT_UPDATING)
- || c->stale_updating) && !r->background)
- {
- u->cache_status = rc;
- rc = NGX_OK;
-
- } else {
- rc = NGX_HTTP_CACHE_STALE;
- }
-
- break;
-
- case NGX_OK:
- u->cache_status = NGX_HTTP_CACHE_HIT;
- }
-
- switch (rc) {
-
- case NGX_OK:
-
- return NGX_OK;
-
- case NGX_HTTP_CACHE_STALE:
-
- c->valid_sec = 0;
- c->updating_sec = 0;
- c->error_sec = 0;
-
- u->buffer.start = NULL;
- u->cache_status = NGX_HTTP_CACHE_EXPIRED;
-
- break;
-
- case NGX_DECLINED:
-
- if ((size_t) (u->buffer.end - u->buffer.start) < u->conf->buffer_size) {
- u->buffer.start = NULL;
-
- } else {
- u->buffer.pos = u->buffer.start + c->header_start;
- u->buffer.last = u->buffer.pos;
- }
-
- break;
-
- case NGX_HTTP_CACHE_SCARCE:
-
- u->cacheable = 0;
-
- break;
-
- case NGX_AGAIN:
-
- return NGX_BUSY;
-
- case NGX_ERROR:
-
- return NGX_ERROR;
-
- default:
-
- /* cached NGX_HTTP_BAD_GATEWAY, NGX_HTTP_GATEWAY_TIME_OUT, etc. */
-
- u->cache_status = NGX_HTTP_CACHE_HIT;
-
- return rc;
- }
-
- if (ngx_http_upstream_cache_check_range(r, u) == NGX_DECLINED) {
- u->cacheable = 0;
- }
-
- r->cached = 0;
-
- return NGX_DECLINED;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_get(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_http_file_cache_t **cache)
-{
- ngx_str_t *name, val;
- ngx_uint_t i;
- ngx_http_file_cache_t **caches;
-
- if (u->conf->cache_zone) {
- *cache = u->conf->cache_zone->data;
- return NGX_OK;
- }
-
- if (ngx_http_complex_value(r, u->conf->cache_value, &val) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (val.len == 0
- || (val.len == 3 && ngx_strncmp(val.data, "off", 3) == 0))
- {
- return NGX_DECLINED;
- }
-
- caches = u->caches->elts;
-
- for (i = 0; i < u->caches->nelts; i++) {
- name = &caches[i]->shm_zone->shm.name;
-
- if (name->len == val.len
- && ngx_strncmp(name->data, val.data, val.len) == 0)
- {
- *cache = caches[i];
- return NGX_OK;
- }
- }
-
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "cache \"%V\" not found", &val);
-
- return NGX_ERROR;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_send(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_int_t rc;
- ngx_http_cache_t *c;
-
- r->cached = 1;
- c = r->cache;
-
- if (c->header_start == c->body_start) {
- r->http_version = NGX_HTTP_VERSION_9;
- return ngx_http_cache_send(r);
- }
-
- /* TODO: cache stack */
-
- u->buffer = *c->buf;
- u->buffer.pos += c->header_start;
-
- ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
- u->headers_in.content_length_n = -1;
- u->headers_in.last_modified_time = -1;
-
- if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- rc = u->process_header(r);
-
- if (rc == NGX_OK) {
-
- if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {
- return NGX_DONE;
- }
-
- return ngx_http_cache_send(r);
- }
-
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- if (rc == NGX_AGAIN || rc == NGX_HTTP_UPSTREAM_EARLY_HINTS) {
- rc = NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- /* rc == NGX_HTTP_UPSTREAM_INVALID_HEADER */
-
- ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
- "cache file \"%s\" contains invalid header",
- c->file.name.data);
-
- /* TODO: delete file */
-
- return rc;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_background_update(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_http_request_t *sr;
-
- if (r == r->main) {
- r->preserve_body = 1;
- }
-
- if (ngx_http_subrequest(r, &r->uri, &r->args, &sr, NULL,
- NGX_HTTP_SUBREQUEST_CLONE
- |NGX_HTTP_SUBREQUEST_BACKGROUND)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- sr->header_only = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_check_range(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- off_t offset;
- u_char *p, *start;
- ngx_table_elt_t *h;
-
- h = r->headers_in.range;
-
- if (h == NULL
- || !u->cacheable
- || u->conf->cache_max_range_offset == NGX_MAX_OFF_T_VALUE)
- {
- return NGX_OK;
- }
-
- if (u->conf->cache_max_range_offset == 0) {
- return NGX_DECLINED;
- }
-
- if (h->value.len < 7
- || ngx_strncasecmp(h->value.data, (u_char *) "bytes=", 6) != 0)
- {
- return NGX_OK;
- }
-
- p = h->value.data + 6;
-
- while (*p == ' ') { p++; }
-
- if (*p == '-') {
- return NGX_DECLINED;
- }
-
- start = p;
-
- while (*p >= '0' && *p <= '9') { p++; }
-
- offset = ngx_atoof(start, p - start);
-
- if (offset >= u->conf->cache_max_range_offset) {
- return NGX_DECLINED;
- }
-
- return NGX_OK;
-}
-
-#endif
-
-
-static void
-ngx_http_upstream_resolve_handler(ngx_resolver_ctx_t *ctx)
-{
- ngx_uint_t run_posted;
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_upstream_t *u;
- ngx_http_upstream_resolved_t *ur;
-
- run_posted = ctx->async;
-
- r = ctx->data;
- c = r->connection;
-
- u = r->upstream;
- ur = u->resolved;
-
- ngx_http_set_log_request(c->log, r);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream resolve: \"%V?%V\"", &r->uri, &r->args);
-
- if (ctx->state) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "%V could not be resolved (%i: %s)",
- &ctx->name, ctx->state,
- ngx_resolver_strerror(ctx->state));
-
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
- goto failed;
- }
-
- ur->naddrs = ctx->naddrs;
- ur->addrs = ctx->addrs;
-
-#if (NGX_DEBUG)
- {
- u_char text[NGX_SOCKADDR_STRLEN];
- ngx_str_t addr;
- ngx_uint_t i;
-
- addr.data = text;
-
- for (i = 0; i < ctx->naddrs; i++) {
- addr.len = ngx_sock_ntop(ur->addrs[i].sockaddr, ur->addrs[i].socklen,
- text, NGX_SOCKADDR_STRLEN, 0);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "name was resolved to %V", &addr);
- }
- }
-#endif
-
- if (ngx_http_upstream_create_round_robin_peer(r, ur) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- goto failed;
- }
-
- ngx_resolve_name_done(ctx);
- ur->ctx = NULL;
-
- u->peer.start_time = ngx_current_msec;
-
- if (u->conf->next_upstream_tries
- && u->peer.tries > u->conf->next_upstream_tries)
- {
- u->peer.tries = u->conf->next_upstream_tries;
- }
-
- ngx_http_upstream_connect(r, u);
-
-failed:
-
- if (run_posted) {
- ngx_http_run_posted_requests(c);
- }
-}
-
-
-static void
-ngx_http_upstream_handler(ngx_event_t *ev)
-{
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_upstream_t *u;
-
- c = ev->data;
- r = c->data;
-
- u = r->upstream;
- c = r->connection;
-
- ngx_http_set_log_request(c->log, r);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream request: \"%V?%V\"", &r->uri, &r->args);
-
- if (ev->delayed && ev->timedout) {
- ev->delayed = 0;
- ev->timedout = 0;
- }
-
- if (ev->write) {
- u->write_event_handler(r, u);
-
- } else {
- u->read_event_handler(r, u);
- }
-
- ngx_http_run_posted_requests(c);
-}
-
-
-static void
-ngx_http_upstream_rd_check_broken_connection(ngx_http_request_t *r)
-{
- ngx_http_upstream_check_broken_connection(r, r->connection->read);
-}
-
-
-static void
-ngx_http_upstream_wr_check_broken_connection(ngx_http_request_t *r)
-{
- ngx_http_upstream_check_broken_connection(r, r->connection->write);
-}
-
-
-static void
-ngx_http_upstream_check_broken_connection(ngx_http_request_t *r,
- ngx_event_t *ev)
-{
- int n;
- char buf[1];
- ngx_err_t err;
- ngx_int_t event;
- ngx_connection_t *c;
- ngx_http_upstream_t *u;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, ev->log, 0,
- "http upstream check client, write event:%d, \"%V\"",
- ev->write, &r->uri);
-
- c = r->connection;
- u = r->upstream;
-
- if (c->error) {
- if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
-
- event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
-
- if (ngx_del_event(ev, event, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- if (!u->cacheable) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- }
-
- return;
- }
-
-#if (NGX_HTTP_V2)
- if (r->stream) {
- return;
- }
-#endif
-
-#if (NGX_HTTP_V3)
-
- if (c->quic) {
- if (c->write->error) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- }
-
- return;
- }
-
-#endif
-
-#if (NGX_HAVE_KQUEUE)
-
- if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
-
- if (!ev->pending_eof) {
- return;
- }
-
- ev->eof = 1;
- c->error = 1;
-
- if (ev->kq_errno) {
- ev->error = 1;
- }
-
- if (!u->cacheable && u->peer.connection) {
- ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
- "kevent() reported that client prematurely closed "
- "connection, so upstream connection is closed too");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- return;
- }
-
- ngx_log_error(NGX_LOG_INFO, ev->log, ev->kq_errno,
- "kevent() reported that client prematurely closed "
- "connection");
-
- if (u->peer.connection == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- }
-
- return;
- }
-
-#endif
-
-#if (NGX_HAVE_EPOLLRDHUP)
-
- if ((ngx_event_flags & NGX_USE_EPOLL_EVENT) && ngx_use_epoll_rdhup) {
- socklen_t len;
-
- if (!ev->pending_eof) {
- return;
- }
-
- ev->eof = 1;
- c->error = 1;
-
- err = 0;
- len = sizeof(ngx_err_t);
-
- /*
- * BSDs and Linux return 0 and set a pending error in err
- * Solaris returns -1 and sets errno
- */
-
- if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
- == -1)
- {
- err = ngx_socket_errno;
- }
-
- if (err) {
- ev->error = 1;
- }
-
- if (!u->cacheable && u->peer.connection) {
- ngx_log_error(NGX_LOG_INFO, ev->log, err,
- "epoll_wait() reported that client prematurely closed "
- "connection, so upstream connection is closed too");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- return;
- }
-
- ngx_log_error(NGX_LOG_INFO, ev->log, err,
- "epoll_wait() reported that client prematurely closed "
- "connection");
-
- if (u->peer.connection == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- }
-
- return;
- }
-
-#endif
-
- n = recv(c->fd, buf, 1, MSG_PEEK);
-
- err = ngx_socket_errno;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, ev->log, err,
- "http upstream recv(): %d", n);
-
- if (ev->write && (n >= 0 || err == NGX_EAGAIN)) {
- return;
- }
-
- if ((ngx_event_flags & NGX_USE_LEVEL_EVENT) && ev->active) {
-
- event = ev->write ? NGX_WRITE_EVENT : NGX_READ_EVENT;
-
- if (ngx_del_event(ev, event, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- if (n > 0) {
- return;
- }
-
- if (n == -1) {
- if (err == NGX_EAGAIN) {
- return;
- }
-
- ev->error = 1;
-
- } else { /* n == 0 */
- err = 0;
- }
-
- ev->eof = 1;
- c->error = 1;
-
- if (!u->cacheable && u->peer.connection) {
- ngx_log_error(NGX_LOG_INFO, ev->log, err,
- "client prematurely closed connection, "
- "so upstream connection is closed too");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- return;
- }
-
- ngx_log_error(NGX_LOG_INFO, ev->log, err,
- "client prematurely closed connection");
-
- if (u->peer.connection == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- }
-}
-
-
-static void
-ngx_http_upstream_connect(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- r->connection->log->action = "connecting to upstream";
-
- if (u->state && u->state->response_time == (ngx_msec_t) -1) {
- u->state->response_time = ngx_current_msec - u->start_time;
- }
-
- u->state = ngx_array_push(r->upstream_states);
- if (u->state == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- ngx_memzero(u->state, sizeof(ngx_http_upstream_state_t));
-
- u->start_time = ngx_current_msec;
-
- u->state->response_time = (ngx_msec_t) -1;
- u->state->connect_time = (ngx_msec_t) -1;
- u->state->header_time = (ngx_msec_t) -1;
-
- rc = ngx_event_connect_peer(&u->peer);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream connect: %i", rc);
-
- if (rc == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->state->peer = u->peer.name;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (u->upstream && u->upstream->shm_zone
- && (u->upstream->flags & NGX_HTTP_UPSTREAM_MODIFY))
- {
- u->state->peer = ngx_palloc(r->pool,
- sizeof(ngx_str_t) + u->peer.name->len);
- if (u->state->peer == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->state->peer->len = u->peer.name->len;
- u->state->peer->data = (u_char *) (u->state->peer + 1);
- ngx_memcpy(u->state->peer->data, u->peer.name->data, u->peer.name->len);
-
- u->peer.name = u->state->peer;
- }
-#endif
-
- if (rc == NGX_BUSY) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "no live upstreams");
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_NOLIVE);
- return;
- }
-
- if (rc == NGX_DECLINED) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
- /* rc == NGX_OK || rc == NGX_AGAIN || rc == NGX_DONE */
-
- c = u->peer.connection;
-
- c->requests++;
-
- c->data = r;
-
- c->write->handler = ngx_http_upstream_handler;
- c->read->handler = ngx_http_upstream_handler;
-
- u->write_event_handler = ngx_http_upstream_send_request_handler;
- u->read_event_handler = ngx_http_upstream_process_header;
-
- c->sendfile &= r->connection->sendfile;
- u->output.sendfile = c->sendfile;
-
- if (r->connection->tcp_nopush == NGX_TCP_NOPUSH_DISABLED) {
- c->tcp_nopush = NGX_TCP_NOPUSH_DISABLED;
- }
-
- if (c->pool == NULL) {
-
- /* we need separate pool here to be able to cache SSL connections */
-
- c->pool = ngx_create_pool(128, r->connection->log);
- if (c->pool == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- c->log = r->connection->log;
- c->pool->log = c->log;
- c->read->log = c->log;
- c->write->log = c->log;
-
- /* init or reinit the ngx_output_chain() and ngx_chain_writer() contexts */
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- u->writer.out = NULL;
- u->writer.last = &u->writer.out;
- u->writer.connection = c;
- u->writer.limit = clcf->sendfile_max_chunk;
-
- if (u->request_sent || u->response_received) {
- if (ngx_http_upstream_reinit(r, u) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- if (r->request_body
- && r->request_body->buf
- && r->request_body->temp_file
- && r == r->main)
- {
- /*
- * the r->request_body->buf can be reused for one request only,
- * the subrequests should allocate their own temporary bufs
- */
-
- u->output.free = ngx_alloc_chain_link(r->pool);
- if (u->output.free == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->output.free->buf = r->request_body->buf;
- u->output.free->next = NULL;
- u->output.allocated = 1;
-
- r->request_body->buf->pos = r->request_body->buf->start;
- r->request_body->buf->last = r->request_body->buf->start;
- r->request_body->buf->tag = u->output.tag;
- }
-
- u->request_sent = 0;
- u->request_body_sent = 0;
- u->request_body_blocked = 0;
- u->response_received = 0;
-
- if (rc == NGX_AGAIN) {
- ngx_add_timer(c->write, u->conf->connect_timeout);
- return;
- }
-
-#if (NGX_HTTP_SSL)
-
- if (u->ssl && c->ssl == NULL) {
- ngx_http_upstream_ssl_init_connection(r, u, c);
- return;
- }
-
-#endif
-
- ngx_http_upstream_send_request(r, u, 1);
-}
-
-
-#if (NGX_HTTP_SSL)
-
-static void
-ngx_http_upstream_ssl_init_connection(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_connection_t *c)
-{
- ngx_int_t rc;
- ngx_http_core_loc_conf_t *clcf;
-
- if (ngx_http_upstream_test_connect(c) != NGX_OK) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
- if (ngx_ssl_create_connection(u->conf->ssl, c,
- NGX_SSL_BUFFER|NGX_SSL_CLIENT)
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (u->conf->ssl_server_name || u->conf->ssl_verify) {
- if (ngx_http_upstream_ssl_name(r, u, c) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- if (u->conf->ssl_certificate
- && u->conf->ssl_certificate->value.len
- && (u->conf->ssl_certificate->lengths
- || u->conf->ssl_certificate_key->lengths))
- {
- if (ngx_http_upstream_ssl_certificate(r, u, c) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
-#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
-
- if (u->ssl_alpn_protocol.len) {
- if (SSL_set_alpn_protos(c->ssl->connection, u->ssl_alpn_protocol.data,
- u->ssl_alpn_protocol.len)
- != 0)
- {
- ngx_ssl_error(NGX_LOG_ERR, c->log, 0,
- "SSL_set_alpn_protos() failed");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
-#endif
-
- if (u->conf->ssl_session_reuse) {
- c->ssl->save_session = ngx_http_upstream_ssl_save_session;
-
- if (u->peer.set_session(&u->peer, u->peer.data) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- /* abbreviated SSL handshake may interact badly with Nagle */
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
- }
-
- r->connection->log->action = "SSL handshaking to upstream";
-
- rc = ngx_ssl_handshake(c);
-
- if (rc == NGX_AGAIN) {
-
- if (!c->write->timer_set) {
- ngx_add_timer(c->write, u->conf->connect_timeout);
- }
-
- c->ssl->handler = ngx_http_upstream_ssl_handshake_handler;
- return;
- }
-
- ngx_http_upstream_ssl_handshake(r, u, c);
-}
-
-
-static void
-ngx_http_upstream_ssl_handshake_handler(ngx_connection_t *c)
-{
- ngx_http_request_t *r;
- ngx_http_upstream_t *u;
-
- r = c->data;
-
- u = r->upstream;
- c = r->connection;
-
- ngx_http_set_log_request(c->log, r);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream ssl handshake: \"%V?%V\"",
- &r->uri, &r->args);
-
- ngx_http_upstream_ssl_handshake(r, u, u->peer.connection);
-
- ngx_http_run_posted_requests(c);
-}
-
-
-static void
-ngx_http_upstream_ssl_handshake(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_connection_t *c)
-{
- long rc;
-
- if (c->ssl->handshaked) {
-
- if (u->conf->ssl_verify) {
- rc = SSL_get_verify_result(c->ssl->connection);
-
- if (rc != X509_V_OK) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "upstream SSL certificate verify error: (%l:%s)",
- rc, X509_verify_cert_error_string(rc));
- goto failed;
- }
-
- if (ngx_ssl_check_host(c, &u->ssl_name) != NGX_OK) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "upstream SSL certificate does not match \"%V\"",
- &u->ssl_name);
- goto failed;
- }
- }
-
- if (!c->ssl->sendfile) {
- c->sendfile = 0;
- u->output.sendfile = 0;
- }
-
- c->write->handler = ngx_http_upstream_handler;
- c->read->handler = ngx_http_upstream_handler;
-
- ngx_http_upstream_send_request(r, u, 1);
-
- return;
- }
-
- if (c->write->timedout) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
- return;
- }
-
-failed:
-
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
-}
-
-
-static void
-ngx_http_upstream_ssl_save_session(ngx_connection_t *c)
-{
- ngx_http_request_t *r;
- ngx_http_upstream_t *u;
-
- if (c->idle) {
- return;
- }
-
- r = c->data;
-
- u = r->upstream;
- c = r->connection;
-
- ngx_http_set_log_request(c->log, r);
-
- u->peer.save_session(&u->peer, u->peer.data);
-}
-
-
-static ngx_int_t
-ngx_http_upstream_ssl_name(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_connection_t *c)
-{
- u_char *p, *last;
- ngx_str_t name;
-
- if (u->conf->ssl_name) {
- if (ngx_http_complex_value(r, u->conf->ssl_name, &name) != NGX_OK) {
- return NGX_ERROR;
- }
-
- } else {
- name = u->ssl_name;
- }
-
- if (name.len == 0) {
- goto done;
- }
-
- /*
- * ssl name here may contain port, notably if derived from $proxy_host
- * or $http_host; we have to strip it
- */
-
- p = name.data;
- last = name.data + name.len;
-
- if (*p == '[') {
- p = ngx_strlchr(p, last, ']');
-
- if (p == NULL) {
- p = name.data;
- }
- }
-
- p = ngx_strlchr(p, last, ':');
-
- if (p != NULL) {
- name.len = p - name.data;
- }
-
- if (!u->conf->ssl_server_name) {
- goto done;
- }
-
-#ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME
-
- /* as per RFC 6066, literal IPv4 and IPv6 addresses are not permitted */
-
- if (name.len == 0 || *name.data == '[') {
- goto done;
- }
-
- if (ngx_inet_addr(name.data, name.len) != INADDR_NONE) {
- goto done;
- }
-
- /*
- * SSL_set_tlsext_host_name() needs a null-terminated string,
- * hence we explicitly null-terminate name here
- */
-
- p = ngx_pnalloc(r->pool, name.len + 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- (void) ngx_cpystrn(p, name.data, name.len + 1);
-
- name.data = p;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "upstream SSL server name: \"%s\"", name.data);
-
- if (SSL_set_tlsext_host_name(c->ssl->connection,
- (char *) name.data)
- == 0)
- {
- ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0,
- "SSL_set_tlsext_host_name(\"%s\") failed", name.data);
- return NGX_ERROR;
- }
-
-#endif
-
-done:
-
- u->ssl_name = name;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_ssl_certificate(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_connection_t *c)
-{
- ngx_str_t cert, key;
-
- if (ngx_http_complex_value(r, u->conf->ssl_certificate, &cert)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream ssl cert: \"%s\"", cert.data);
-
- if (*cert.data == '\0') {
- return NGX_OK;
- }
-
- if (ngx_http_complex_value(r, u->conf->ssl_certificate_key, &key)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream ssl key: \"%s\"", key.data);
-
- if (ngx_ssl_connection_certificate(c, r->pool, &cert, &key,
- u->conf->ssl_certificate_cache,
- u->conf->ssl_passwords)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_http_upstream_reinit(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- off_t file_pos;
- ngx_chain_t *cl;
-
- if (u->reinit_request(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- u->early_hints_length = 0;
- u->keepalive = 0;
- u->upgrade = 0;
- u->error = 0;
-
- ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
- u->headers_in.content_length_n = -1;
- u->headers_in.last_modified_time = -1;
-
- if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- /* reinit the request chain */
-
- file_pos = 0;
-
- for (cl = u->request_bufs; cl; cl = cl->next) {
- cl->buf->pos = cl->buf->start;
-
- /* there is at most one file */
-
- if (cl->buf->in_file) {
- cl->buf->file_pos = file_pos;
- file_pos = cl->buf->file_last;
- }
- }
-
- /* reinit the subrequest's ngx_output_chain() context */
-
- if (r->request_body && r->request_body->temp_file
- && r != r->main && u->output.buf)
- {
- u->output.free = ngx_alloc_chain_link(r->pool);
- if (u->output.free == NULL) {
- return NGX_ERROR;
- }
-
- u->output.free->buf = u->output.buf;
- u->output.free->next = NULL;
-
- u->output.buf->pos = u->output.buf->start;
- u->output.buf->last = u->output.buf->start;
- }
-
- u->output.buf = NULL;
- u->output.in = NULL;
- u->output.busy = NULL;
-
- /* reinit u->buffer */
-
- u->buffer.pos = u->buffer.start;
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- u->buffer.pos += r->cache->header_start;
- }
-
-#endif
-
- u->buffer.last = u->buffer.pos;
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_upstream_send_request(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_uint_t do_write)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
-
- c = u->peer.connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream send request");
-
- if (u->state->connect_time == (ngx_msec_t) -1) {
- u->state->connect_time = ngx_current_msec - u->start_time;
- }
-
- if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
- c->log->action = "sending request to upstream";
-
- rc = ngx_http_upstream_send_request_body(r, u, do_write);
-
- if (rc == NGX_ERROR) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
- if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-
- if (rc == NGX_AGAIN) {
- if (!c->write->ready || u->request_body_blocked) {
- ngx_add_timer(c->write, u->conf->send_timeout);
-
- } else if (c->write->timer_set) {
- ngx_del_timer(c->write);
- }
-
- if (ngx_handle_write_event(c->write, u->conf->send_lowat) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (c->write->ready && c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
- if (ngx_tcp_push(c->fd) == -1) {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
- ngx_tcp_push_n " failed");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
- }
-
- if (c->read->ready) {
- ngx_post_event(c->read, &ngx_posted_events);
- }
-
- return;
- }
-
- /* rc == NGX_OK */
-
- if (c->write->timer_set) {
- ngx_del_timer(c->write);
- }
-
- if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
- if (ngx_tcp_push(c->fd) == -1) {
- ngx_log_error(NGX_LOG_CRIT, c->log, ngx_socket_errno,
- ngx_tcp_push_n " failed");
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
- }
-
- if (!u->conf->preserve_output) {
- u->write_event_handler = ngx_http_upstream_dummy_handler;
- }
-
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (!u->request_body_sent) {
- u->request_body_sent = 1;
-
- if (u->header_sent) {
- return;
- }
-
- ngx_add_timer(c->read, u->conf->read_timeout);
-
- if (c->read->ready) {
- ngx_http_upstream_process_header(r, u);
- return;
- }
- }
-}
-
-
-static ngx_int_t
-ngx_http_upstream_send_request_body(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_uint_t do_write)
-{
- ngx_int_t rc;
- ngx_chain_t *out, *cl, *ln;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream send request body");
-
- if (!r->request_body_no_buffering) {
-
- /* buffered request body */
-
- if (!u->request_sent) {
- u->request_sent = 1;
- out = u->request_bufs;
-
- } else {
- out = NULL;
- }
-
- rc = ngx_output_chain(&u->output, out);
-
- if (rc == NGX_AGAIN) {
- u->request_body_blocked = 1;
-
- } else {
- u->request_body_blocked = 0;
- }
-
- return rc;
- }
-
- if (!u->request_sent) {
- u->request_sent = 1;
- out = u->request_bufs;
-
- if (r->request_body->bufs) {
- for (cl = out; cl->next; cl = cl->next) { /* void */ }
- cl->next = r->request_body->bufs;
- r->request_body->bufs = NULL;
- }
-
- c = u->peer.connection;
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
- return NGX_ERROR;
- }
-
- r->read_event_handler = ngx_http_upstream_read_request_handler;
-
- } else {
- out = NULL;
- }
-
- for ( ;; ) {
-
- if (do_write) {
- rc = ngx_output_chain(&u->output, out);
-
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- while (out) {
- ln = out;
- out = out->next;
- ngx_free_chain(r->pool, ln);
- }
-
- if (rc == NGX_AGAIN) {
- u->request_body_blocked = 1;
-
- } else {
- u->request_body_blocked = 0;
- }
-
- if (rc == NGX_OK && !r->reading_body) {
- break;
- }
- }
-
- if (r->reading_body) {
- /* read client request body */
-
- rc = ngx_http_read_unbuffered_request_body(r);
-
- if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
- return rc;
- }
-
- out = r->request_body->bufs;
- r->request_body->bufs = NULL;
- }
-
- /* stop if there is nothing to send */
-
- if (out == NULL) {
- rc = NGX_AGAIN;
- break;
- }
-
- do_write = 1;
- }
-
- if (!r->reading_body) {
- if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
- r->read_event_handler =
- ngx_http_upstream_rd_check_broken_connection;
- }
- }
-
- return rc;
-}
-
-
-static void
-ngx_http_upstream_send_request_handler(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_connection_t *c;
-
- c = u->peer.connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream send request handler");
-
- if (c->write->timedout) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
- return;
- }
-
-#if (NGX_HTTP_SSL)
-
- if (u->ssl && c->ssl == NULL) {
- ngx_http_upstream_ssl_init_connection(r, u, c);
- return;
- }
-
-#endif
-
- if (u->header_sent && !u->conf->preserve_output) {
- u->write_event_handler = ngx_http_upstream_dummy_handler;
-
- (void) ngx_handle_write_event(c->write, 0);
-
- return;
- }
-
- ngx_http_upstream_send_request(r, u, 1);
-}
-
-
-static void
-ngx_http_upstream_read_request_handler(ngx_http_request_t *r)
-{
- ngx_connection_t *c;
- ngx_http_upstream_t *u;
-
- c = r->connection;
- u = r->upstream;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream read request handler");
-
- if (c->read->timedout) {
- c->timedout = 1;
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- ngx_http_upstream_send_request(r, u, 0);
-}
-
-
-static void
-ngx_http_upstream_process_header(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ssize_t n;
- ngx_int_t rc;
- ngx_connection_t *c;
-
- c = u->peer.connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process header");
-
- c->log->action = "reading response header from upstream";
-
- if (c->read->timedout) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_TIMEOUT);
- return;
- }
-
- if (!u->request_sent && ngx_http_upstream_test_connect(c) != NGX_OK) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
- if (u->buffer.start == NULL) {
- u->buffer.start = ngx_palloc(r->pool, u->conf->buffer_size);
- if (u->buffer.start == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- u->buffer.pos = u->buffer.start;
- u->buffer.last = u->buffer.start;
- u->buffer.end = u->buffer.start + u->conf->buffer_size;
- u->buffer.temporary = 1;
-
- u->buffer.tag = u->output.tag;
-
- if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- u->buffer.pos += r->cache->header_start;
- u->buffer.last = u->buffer.pos;
- }
-#endif
- }
-
- for ( ;; ) {
-
- n = c->recv(c, u->buffer.last, u->buffer.end - u->buffer.last);
-
- if (n == NGX_AGAIN) {
-#if 0
- ngx_add_timer(rev, u->read_timeout);
-#endif
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- return;
- }
-
- if (n == 0) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "upstream prematurely closed connection");
- }
-
- if (n == NGX_ERROR || n == 0) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-
-#if (NGX_HTTP_SSL)
- if (u->ssl && c->ssl == NULL) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "upstream prematurely sent response");
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_ERROR);
- return;
- }
-#endif
-
- u->state->bytes_received += n;
-
- u->buffer.last += n;
-
-#if 0
- u->valid_header_in = 0;
-
- u->peer.cached = 0;
-#endif
-
- u->response_received = 1;
-
-again:
-
- rc = u->process_header(r);
-
- if (rc == NGX_AGAIN) {
-
- if (u->buffer.last == u->buffer.end) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "upstream sent too big header");
-
- ngx_http_upstream_next(r, u,
- NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
- return;
- }
-
- continue;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_EARLY_HINTS) {
- rc = ngx_http_upstream_process_early_hints(r, u);
-
- if (rc == NGX_OK) {
- goto again;
- }
- }
-
- break;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- ngx_http_upstream_next(r, u, NGX_HTTP_UPSTREAM_FT_INVALID_HEADER);
- return;
- }
-
- if (rc == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- /* rc == NGX_OK */
-
- u->state->header_time = ngx_current_msec - u->start_time;
-
- if (u->headers_in.status_n >= NGX_HTTP_SPECIAL_RESPONSE) {
-
- if (ngx_http_upstream_test_next(r, u) == NGX_OK) {
- return;
- }
-
- if (ngx_http_upstream_intercept_errors(r, u) == NGX_OK) {
- return;
- }
- }
-
- if (u->peer.notify) {
- u->peer.notify(&u->peer, u->peer.data, NGX_HTTP_UPSTREAM_NOTIFY_HEADER);
- }
-
- if (ngx_http_upstream_process_headers(r, u) != NGX_OK) {
- return;
- }
-
- ngx_http_upstream_send_response(r, u);
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_early_hints(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- u_char *p;
- ngx_uint_t i;
- ngx_list_part_t *part;
- ngx_table_elt_t *h, *ho;
- ngx_connection_t *c;
-
- c = r->connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http upstream early hints");
-
- if (u->conf->pass_early_hints) {
-
- u->early_hints_length += u->buffer.pos - u->buffer.start;
-
- if (u->early_hints_length <= (off_t) u->conf->buffer_size) {
-
- part = &u->headers_in.headers.part;
- h = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- h = part->elts;
- i = 0;
- }
-
- if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,
- h[i].lowcase_key, h[i].key.len))
- {
- continue;
- }
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = h[i];
- }
-
- if (ngx_http_send_early_hints(r) == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- if (c->buffered) {
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- return NGX_ERROR;
- }
-
- r->write_event_handler = ngx_http_upstream_early_hints_writer;
- }
-
- } else {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "upstream sent too big early hints");
- }
- }
-
- ngx_http_clean_header(r);
-
- ngx_memzero(&u->headers_in, sizeof(ngx_http_upstream_headers_in_t));
- u->headers_in.content_length_n = -1;
- u->headers_in.last_modified_time = -1;
-
- if (ngx_list_init(&u->headers_in.headers, r->pool, 8,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- if (ngx_list_init(&u->headers_in.trailers, r->pool, 2,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- p = u->buffer.pos;
-
- u->buffer.pos = u->buffer.start;
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- u->buffer.pos += r->cache->header_start;
- }
-
-#endif
-
- u->buffer.last = ngx_movemem(u->buffer.pos, p, u->buffer.last - p);
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_upstream_early_hints_writer(ngx_http_request_t *r)
-{
- ngx_connection_t *c;
- ngx_http_upstream_t *u;
-
- c = r->connection;
- u = r->upstream;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream early hints writer");
-
- c->log->action = "sending early hints to client";
-
- if (ngx_http_write_filter(r, NULL) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- if (!c->buffered) {
- if (!u->store && !r->post_action && !u->conf->ignore_client_abort) {
- r->write_event_handler =
- ngx_http_upstream_wr_check_broken_connection;
-
- } else {
- r->write_event_handler = ngx_http_request_empty_handler;
- }
- }
-
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- }
-}
-
-
-static ngx_int_t
-ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_msec_t timeout;
- ngx_uint_t status, mask;
- ngx_http_upstream_next_t *un;
-
- status = u->headers_in.status_n;
-
- for (un = ngx_http_upstream_next_errors; un->status; un++) {
-
- if (status != un->status) {
- continue;
- }
-
- timeout = u->conf->next_upstream_timeout;
-
- if (u->request_sent
- && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH)))
- {
- mask = un->mask | NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;
-
- } else {
- mask = un->mask;
- }
-
- if (u->peer.tries > 1
- && ((u->conf->next_upstream & mask) == mask)
- && !(u->request_sent && r->request_body_no_buffering)
- && !(timeout && ngx_current_msec - u->peer.start_time >= timeout))
- {
- ngx_http_upstream_next(r, u, un->mask);
- return NGX_OK;
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && (u->conf->cache_use_stale & un->mask))
- {
- ngx_int_t rc;
-
- rc = u->reinit_request(r);
-
- if (rc != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return NGX_OK;
- }
-
- u->cache_status = NGX_HTTP_CACHE_STALE;
- rc = ngx_http_upstream_cache_send(r, u);
-
- if (rc == NGX_DONE) {
- return NGX_OK;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- ngx_http_upstream_finalize_request(r, u, rc);
- return NGX_OK;
- }
-
-#endif
-
- break;
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (status == NGX_HTTP_NOT_MODIFIED
- && u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && u->conf->cache_revalidate)
- {
- time_t now, valid, updating, error;
- ngx_int_t rc;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream not modified");
-
- now = ngx_time();
-
- valid = r->cache->valid_sec;
- updating = r->cache->updating_sec;
- error = r->cache->error_sec;
-
- rc = u->reinit_request(r);
-
- if (rc != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return NGX_OK;
- }
-
- u->cache_status = NGX_HTTP_CACHE_REVALIDATED;
- rc = ngx_http_upstream_cache_send(r, u);
-
- if (rc == NGX_DONE) {
- return NGX_OK;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- if (valid == 0) {
- valid = r->cache->valid_sec;
- updating = r->cache->updating_sec;
- error = r->cache->error_sec;
- }
-
- if (valid == 0) {
- valid = ngx_http_file_cache_valid(u->conf->cache_valid,
- u->headers_in.status_n);
- if (valid) {
- valid = now + valid;
- }
- }
-
- if (valid) {
- r->cache->valid_sec = valid;
- r->cache->updating_sec = updating;
- r->cache->error_sec = error;
-
- r->cache->date = now;
-
- ngx_http_file_cache_update_header(r);
- }
-
- ngx_http_upstream_finalize_request(r, u, rc);
- return NGX_OK;
- }
-
-#endif
-
- return NGX_DECLINED;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_intercept_errors(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_int_t status;
- ngx_uint_t i;
- ngx_table_elt_t *h, *ho, **ph;
- ngx_http_err_page_t *err_page;
- ngx_http_core_loc_conf_t *clcf;
-
- status = u->headers_in.status_n;
-
- if (status == NGX_HTTP_NOT_FOUND && u->conf->intercept_404) {
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_NOT_FOUND);
- return NGX_OK;
- }
-
- if (!u->conf->intercept_errors) {
- return NGX_DECLINED;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->error_pages == NULL) {
- return NGX_DECLINED;
- }
-
- err_page = clcf->error_pages->elts;
- for (i = 0; i < clcf->error_pages->nelts; i++) {
-
- if (err_page[i].status == status) {
-
- if (status == NGX_HTTP_UNAUTHORIZED
- && u->headers_in.www_authenticate)
- {
- h = u->headers_in.www_authenticate;
- ph = &r->headers_out.www_authenticate;
-
- while (h) {
- ho = ngx_list_push(&r->headers_out.headers);
-
- if (ho == NULL) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_OK;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- *ph = ho;
- ph = &ho->next;
-
- h = h->next;
- }
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
-
- if (u->headers_in.no_cache || u->headers_in.expired) {
- u->cacheable = 0;
- }
-
- if (u->cacheable) {
- time_t valid;
-
- valid = r->cache->valid_sec;
-
- if (valid == 0) {
- valid = ngx_http_file_cache_valid(u->conf->cache_valid,
- status);
- if (valid) {
- r->cache->valid_sec = ngx_time() + valid;
- }
- }
-
- if (valid) {
- r->cache->error = status;
- }
- }
-
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-#endif
- ngx_http_upstream_finalize_request(r, u, status);
-
- return NGX_OK;
- }
- }
-
- return NGX_DECLINED;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_test_connect(ngx_connection_t *c)
-{
- int err;
- socklen_t len;
-
-#if (NGX_HAVE_KQUEUE)
-
- if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
- if (c->write->pending_eof || c->read->pending_eof) {
- if (c->write->pending_eof) {
- err = c->write->kq_errno;
-
- } else {
- err = c->read->kq_errno;
- }
-
- c->log->action = "connecting to upstream";
- (void) ngx_connection_error(c, err,
- "kevent() reported that connect() failed");
- return NGX_ERROR;
- }
-
- } else
-#endif
- {
- err = 0;
- len = sizeof(int);
-
- /*
- * BSDs and Linux return 0 and set a pending error in err
- * Solaris returns -1 and sets errno
- */
-
- if (getsockopt(c->fd, SOL_SOCKET, SO_ERROR, (void *) &err, &len)
- == -1)
- {
- err = ngx_socket_errno;
- }
-
- if (err) {
- c->log->action = "connecting to upstream";
- (void) ngx_connection_error(c, err, "connect() failed");
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_headers(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_str_t uri, args;
- ngx_uint_t i, flags;
- ngx_list_part_t *part;
- ngx_table_elt_t *h;
- ngx_http_upstream_header_t *hh;
- ngx_http_upstream_main_conf_t *umcf;
-
- umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);
-
- if (u->headers_in.no_cache || u->headers_in.expired) {
- u->cacheable = 0;
- }
-
- if (u->headers_in.x_accel_redirect
- && !(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT))
- {
- ngx_http_upstream_finalize_request(r, u, NGX_DECLINED);
-
- part = &u->headers_in.headers.part;
- h = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- h = part->elts;
- i = 0;
- }
-
- if (h[i].hash == 0) {
- continue;
- }
-
- hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,
- h[i].lowcase_key, h[i].key.len);
-
- if (hh && hh->redirect) {
- if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {
- ngx_http_finalize_request(r,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_DONE;
- }
- }
- }
-
- uri = u->headers_in.x_accel_redirect->value;
-
- if (uri.data[0] == '@') {
- ngx_http_named_location(r, &uri);
-
- } else {
- ngx_str_null(&args);
- flags = NGX_HTTP_LOG_UNSAFE;
-
- if (ngx_http_parse_unsafe_uri(r, &uri, &args, &flags) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_NOT_FOUND);
- return NGX_DONE;
- }
-
- if (r->method != NGX_HTTP_HEAD) {
- r->method = NGX_HTTP_GET;
- r->method_name = ngx_http_core_get_method;
- }
-
- ngx_http_internal_redirect(r, &uri, &args);
- }
-
- ngx_http_finalize_request(r, NGX_DONE);
- return NGX_DONE;
- }
-
- part = &u->headers_in.headers.part;
- h = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- h = part->elts;
- i = 0;
- }
-
- if (h[i].hash == 0) {
- continue;
- }
-
- if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,
- h[i].lowcase_key, h[i].key.len))
- {
- continue;
- }
-
- hh = ngx_hash_find(&umcf->headers_in_hash, h[i].hash,
- h[i].lowcase_key, h[i].key.len);
-
- if (hh) {
- if (hh->copy_handler(r, &h[i], hh->conf) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_DONE;
- }
-
- continue;
- }
-
- if (ngx_http_upstream_copy_header_line(r, &h[i], 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_DONE;
- }
- }
-
- if (r->headers_out.server && r->headers_out.server->value.data == NULL) {
- r->headers_out.server->hash = 0;
- }
-
- if (r->headers_out.date && r->headers_out.date->value.data == NULL) {
- r->headers_out.date->hash = 0;
- }
-
- r->headers_out.status = u->headers_in.status_n;
- r->headers_out.status_line = u->headers_in.status_line;
-
- r->headers_out.content_length_n = u->headers_in.content_length_n;
-
- r->disable_not_modified = !u->cacheable;
-
- if (u->conf->force_ranges) {
- r->allow_ranges = 1;
- r->single_range = 1;
-
-#if (NGX_HTTP_CACHE)
- if (r->cached) {
- r->single_range = 0;
- }
-#endif
- }
-
- u->length = -1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_trailers(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_uint_t i;
- ngx_list_part_t *part;
- ngx_table_elt_t *h, *ho;
-
- if (!u->conf->pass_trailers) {
- return NGX_OK;
- }
-
- part = &u->headers_in.trailers.part;
- h = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- h = part->elts;
- i = 0;
- }
-
- if (ngx_hash_find(&u->conf->hide_headers_hash, h[i].hash,
- h[i].lowcase_key, h[i].key.len))
- {
- continue;
- }
-
- ho = ngx_list_push(&r->headers_out.trailers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = h[i];
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_upstream_send_response(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ssize_t n;
- ngx_int_t rc;
- ngx_event_pipe_t *p;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- rc = ngx_http_send_header(r);
-
- if (rc == NGX_ERROR || rc > NGX_OK || r->post_action) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-
- u->header_sent = 1;
-
- if (u->upgrade) {
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-
-#endif
-
- ngx_http_upstream_upgrade(r, u);
- return;
- }
-
- c = r->connection;
-
- if (r->header_only) {
-
- if (!u->buffering) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-
- if (!u->cacheable && !u->store) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-
- u->pipe->downstream_error = 1;
- }
-
- if (r->request_body && r->request_body->temp_file
- && r == r->main && !r->preserve_body
- && !u->conf->preserve_output)
- {
- ngx_pool_run_cleanup_file(r->pool, r->request_body->temp_file->file.fd);
- r->request_body->temp_file->file.fd = NGX_INVALID_FILE;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (!u->buffering) {
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-
-#endif
-
- if (u->input_filter == NULL) {
- u->input_filter_init = ngx_http_upstream_non_buffered_filter_init;
- u->input_filter = ngx_http_upstream_non_buffered_filter;
- u->input_filter_ctx = r;
- }
-
- u->read_event_handler = ngx_http_upstream_process_non_buffered_upstream;
- r->write_event_handler =
- ngx_http_upstream_process_non_buffered_downstream;
-
- r->limit_rate = 0;
- r->limit_rate_set = 1;
-
- if (u->input_filter_init(u->input_filter_ctx) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- n = u->buffer.last - u->buffer.pos;
-
- if (n) {
- u->buffer.last = u->buffer.pos;
-
- u->state->response_length += n;
-
- if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- ngx_http_upstream_process_non_buffered_downstream(r);
-
- } else {
- u->buffer.pos = u->buffer.start;
- u->buffer.last = u->buffer.start;
-
- if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- ngx_http_upstream_process_non_buffered_upstream(r, u);
- }
-
- return;
- }
-
- /* TODO: preallocate event_pipe bufs, look "Content-Length" */
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache && r->cache->file.fd != NGX_INVALID_FILE) {
- ngx_pool_run_cleanup_file(r->pool, r->cache->file.fd);
- r->cache->file.fd = NGX_INVALID_FILE;
- }
-
- switch (ngx_http_test_predicates(r, u->conf->no_cache)) {
-
- case NGX_ERROR:
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
-
- case NGX_DECLINED:
- u->cacheable = 0;
- break;
-
- default: /* NGX_OK */
-
- if (u->cache_status == NGX_HTTP_CACHE_BYPASS) {
-
- /* create cache if previously bypassed */
-
- if (ngx_http_file_cache_create(r) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- break;
- }
-
- if (u->cacheable) {
- time_t now, valid;
-
- now = ngx_time();
-
- valid = r->cache->valid_sec;
-
- if (valid == 0) {
- valid = ngx_http_file_cache_valid(u->conf->cache_valid,
- u->headers_in.status_n);
- if (valid) {
- r->cache->valid_sec = now + valid;
- }
- }
-
- if (valid) {
- r->cache->date = now;
- r->cache->body_start = (u_short) (u->buffer.pos - u->buffer.start);
-
- if (u->headers_in.status_n == NGX_HTTP_OK
- || u->headers_in.status_n == NGX_HTTP_PARTIAL_CONTENT)
- {
- r->cache->last_modified = u->headers_in.last_modified_time;
-
- if (u->headers_in.etag) {
- r->cache->etag = u->headers_in.etag->value;
-
- } else {
- ngx_str_null(&r->cache->etag);
- }
-
- } else {
- r->cache->last_modified = -1;
- ngx_str_null(&r->cache->etag);
- }
-
- if (ngx_http_file_cache_set_header(r, u->buffer.start) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- } else {
- u->cacheable = 0;
- }
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http cacheable: %d", u->cacheable);
-
- if (u->cacheable == 0 && r->cache) {
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-
- if (r->header_only && !u->cacheable && !u->store) {
- ngx_http_upstream_finalize_request(r, u, 0);
- return;
- }
-
-#endif
-
- p = u->pipe;
-
- p->output_filter = ngx_http_upstream_output_filter;
- p->output_ctx = r;
- p->tag = u->output.tag;
- p->bufs = u->conf->bufs;
- p->busy_size = u->conf->busy_buffers_size;
- p->upstream = u->peer.connection;
- p->downstream = c;
- p->pool = r->pool;
- p->log = c->log;
- p->limit_rate = ngx_http_complex_value_size(r, u->conf->limit_rate, 0);
- p->start_sec = ngx_time();
-
- p->cacheable = u->cacheable || u->store;
-
- p->temp_file = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
- if (p->temp_file == NULL) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- p->temp_file->file.fd = NGX_INVALID_FILE;
- p->temp_file->file.log = c->log;
- p->temp_file->path = u->conf->temp_path;
- p->temp_file->pool = r->pool;
-
- if (p->cacheable) {
- p->temp_file->persistent = 1;
-
-#if (NGX_HTTP_CACHE)
- if (r->cache && !r->cache->file_cache->use_temp_path) {
- p->temp_file->path = r->cache->file_cache->path;
- p->temp_file->file.name = r->cache->file.name;
- }
-#endif
-
- } else {
- p->temp_file->log_level = NGX_LOG_WARN;
- p->temp_file->warn = "an upstream response is buffered "
- "to a temporary file";
- }
-
- p->max_temp_file_size = u->conf->max_temp_file_size;
- p->temp_file_write_size = u->conf->temp_file_write_size;
-
-#if (NGX_THREADS)
- if (clcf->aio == NGX_HTTP_AIO_THREADS && clcf->aio_write) {
- p->thread_handler = ngx_http_upstream_thread_handler;
- p->thread_ctx = r;
- }
-#endif
-
- p->preread_bufs = ngx_alloc_chain_link(r->pool);
- if (p->preread_bufs == NULL) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- p->preread_bufs->buf = &u->buffer;
- p->preread_bufs->next = NULL;
- u->buffer.recycled = 1;
-
- p->preread_size = u->buffer.last - u->buffer.pos;
-
- if (u->cacheable) {
-
- p->buf_to_file = ngx_calloc_buf(r->pool);
- if (p->buf_to_file == NULL) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- p->buf_to_file->start = u->buffer.start;
- p->buf_to_file->pos = u->buffer.start;
- p->buf_to_file->last = u->buffer.pos;
- p->buf_to_file->temporary = 1;
- }
-
- if (ngx_event_flags & NGX_USE_IOCP_EVENT) {
- /* the posted aio operation may corrupt a shadow buffer */
- p->single_buf = 1;
- }
-
- /* TODO: p->free_bufs = 0 if use ngx_create_chain_of_bufs() */
- p->free_bufs = 1;
-
- /*
- * event_pipe would do u->buffer.last += p->preread_size
- * as though these bytes were read
- */
- u->buffer.last = u->buffer.pos;
-
- if (u->conf->cyclic_temp_file) {
-
- /*
- * we need to disable the use of sendfile() if we use cyclic temp file
- * because the writing a new data may interfere with sendfile()
- * that uses the same kernel file pages (at least on FreeBSD)
- */
-
- p->cyclic_temp_file = 1;
- c->sendfile = 0;
-
- } else {
- p->cyclic_temp_file = 0;
- }
-
- p->read_timeout = u->conf->read_timeout;
- p->send_timeout = clcf->send_timeout;
- p->send_lowat = clcf->send_lowat;
-
- p->length = -1;
-
- if (u->input_filter_init
- && u->input_filter_init(p->input_ctx) != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- u->read_event_handler = ngx_http_upstream_process_upstream;
- r->write_event_handler = ngx_http_upstream_process_downstream;
-
- ngx_http_upstream_process_upstream(r, u);
-}
-
-
-static void
-ngx_http_upstream_upgrade(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- c = r->connection;
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- /* TODO: prevent upgrade if not requested or not possible */
-
- if (r != r->main) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "connection upgrade in subrequest");
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- r->keepalive = 0;
- c->log->action = "proxying upgraded connection";
-
- u->read_event_handler = ngx_http_upstream_upgraded_read_upstream;
- u->write_event_handler = ngx_http_upstream_upgraded_write_upstream;
- r->read_event_handler = ngx_http_upstream_upgraded_read_downstream;
- r->write_event_handler = ngx_http_upstream_upgraded_write_downstream;
-
- if (clcf->tcp_nodelay) {
-
- if (ngx_tcp_nodelay(c) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (ngx_tcp_nodelay(u->peer.connection) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- if (ngx_http_send_special(r, NGX_HTTP_FLUSH) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (u->peer.connection->read->ready
- || u->buffer.pos != u->buffer.last)
- {
- ngx_post_event(c->read, &ngx_posted_events);
- ngx_http_upstream_process_upgraded(r, 1, 1);
- return;
- }
-
- ngx_http_upstream_process_upgraded(r, 0, 1);
-}
-
-
-static void
-ngx_http_upstream_upgraded_read_downstream(ngx_http_request_t *r)
-{
- ngx_http_upstream_process_upgraded(r, 0, 0);
-}
-
-
-static void
-ngx_http_upstream_upgraded_write_downstream(ngx_http_request_t *r)
-{
- ngx_http_upstream_process_upgraded(r, 1, 1);
-}
-
-
-static void
-ngx_http_upstream_upgraded_read_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_http_upstream_process_upgraded(r, 1, 0);
-}
-
-
-static void
-ngx_http_upstream_upgraded_write_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_http_upstream_process_upgraded(r, 0, 1);
-}
-
-
-static void
-ngx_http_upstream_process_upgraded(ngx_http_request_t *r,
- ngx_uint_t from_upstream, ngx_uint_t do_write)
-{
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_uint_t flags;
- ngx_connection_t *c, *downstream, *upstream, *dst, *src;
- ngx_http_upstream_t *u;
- ngx_http_core_loc_conf_t *clcf;
-
- c = r->connection;
- u = r->upstream;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process upgraded, fu:%ui", from_upstream);
-
- downstream = c;
- upstream = u->peer.connection;
-
- if (downstream->write->timedout) {
- c->timedout = 1;
- ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- if (upstream->read->timedout || upstream->write->timedout) {
- ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);
- return;
- }
-
- if (from_upstream) {
- src = upstream;
- dst = downstream;
- b = &u->buffer;
-
- } else {
- src = downstream;
- dst = upstream;
- b = &u->from_client;
-
- if (r->header_in->last > r->header_in->pos) {
- b = r->header_in;
- b->end = b->last;
- do_write = 1;
- }
-
- if (b->start == NULL) {
- b->start = ngx_palloc(r->pool, u->conf->buffer_size);
- if (b->start == NULL) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- b->pos = b->start;
- b->last = b->start;
- b->end = b->start + u->conf->buffer_size;
- b->temporary = 1;
- b->tag = u->output.tag;
- }
- }
-
- for ( ;; ) {
-
- if (do_write) {
-
- size = b->last - b->pos;
-
- if (size && dst->write->ready) {
-
- n = dst->send(dst, b->pos, size);
-
- if (n == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (n > 0) {
- b->pos += n;
-
- if (b->pos == b->last) {
- b->pos = b->start;
- b->last = b->start;
- }
- }
- }
- }
-
- size = b->end - b->last;
-
- if (size && src->read->ready) {
-
- n = src->recv(src, b->last, size);
-
- if (n == NGX_AGAIN || n == 0) {
- break;
- }
-
- if (n > 0) {
- do_write = 1;
- b->last += n;
-
- if (from_upstream) {
- u->state->bytes_received += n;
- }
-
- continue;
- }
-
- if (n == NGX_ERROR) {
- src->read->eof = 1;
- }
- }
-
- break;
- }
-
- if ((upstream->read->eof && u->buffer.pos == u->buffer.last)
- || (downstream->read->eof && u->from_client.pos == u->from_client.last)
- || (downstream->read->eof && upstream->read->eof))
- {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream upgraded done");
- ngx_http_upstream_finalize_request(r, u, 0);
- return;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (ngx_handle_write_event(upstream->write, u->conf->send_lowat)
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (upstream->write->active && !upstream->write->ready) {
- ngx_add_timer(upstream->write, u->conf->send_timeout);
-
- } else if (upstream->write->timer_set) {
- ngx_del_timer(upstream->write);
- }
-
- if (upstream->read->eof || upstream->read->error) {
- flags = NGX_CLOSE_EVENT;
-
- } else {
- flags = 0;
- }
-
- if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (upstream->read->active && !upstream->read->ready) {
- ngx_add_timer(upstream->read, u->conf->read_timeout);
-
- } else if (upstream->read->timer_set) {
- ngx_del_timer(upstream->read);
- }
-
- if (ngx_handle_write_event(downstream->write, clcf->send_lowat)
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (downstream->read->eof || downstream->read->error) {
- flags = NGX_CLOSE_EVENT;
-
- } else {
- flags = 0;
- }
-
- if (ngx_handle_read_event(downstream->read, flags) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (downstream->write->active && !downstream->write->ready) {
- ngx_add_timer(downstream->write, clcf->send_timeout);
-
- } else if (downstream->write->timer_set) {
- ngx_del_timer(downstream->write);
- }
-}
-
-
-static void
-ngx_http_upstream_process_non_buffered_downstream(ngx_http_request_t *r)
-{
- ngx_event_t *wev;
- ngx_connection_t *c;
- ngx_http_upstream_t *u;
-
- c = r->connection;
- u = r->upstream;
- wev = c->write;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process non buffered downstream");
-
- c->log->action = "sending to client";
-
- if (wev->timedout) {
- c->timedout = 1;
- ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- ngx_http_upstream_process_non_buffered_request(r, 1);
-}
-
-
-static void
-ngx_http_upstream_process_non_buffered_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_connection_t *c;
-
- c = u->peer.connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process non buffered upstream");
-
- c->log->action = "reading upstream";
-
- if (c->read->timedout) {
- ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_GATEWAY_TIME_OUT);
- return;
- }
-
- ngx_http_upstream_process_non_buffered_request(r, 0);
-}
-
-
-static void
-ngx_http_upstream_process_non_buffered_request(ngx_http_request_t *r,
- ngx_uint_t do_write)
-{
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_int_t rc;
- ngx_uint_t flags;
- ngx_connection_t *downstream, *upstream;
- ngx_http_upstream_t *u;
- ngx_http_core_loc_conf_t *clcf;
-
- u = r->upstream;
- downstream = r->connection;
- upstream = u->peer.connection;
-
- b = &u->buffer;
-
- do_write = do_write || u->length == 0;
-
- for ( ;; ) {
-
- if (do_write) {
-
- if (u->out_bufs || u->busy_bufs || downstream->buffered) {
- rc = ngx_http_output_filter(r, u->out_bufs);
-
- if (rc == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- ngx_chain_update_chains(r->pool, &u->free_bufs, &u->busy_bufs,
- &u->out_bufs, u->output.tag);
- }
-
- if (u->busy_bufs == NULL) {
-
- if (u->length == 0
- || (upstream->read->eof && u->length == -1))
- {
- ngx_http_upstream_finalize_request(r, u, 0);
- return;
- }
-
- if (upstream->read->eof) {
- ngx_log_error(NGX_LOG_ERR, upstream->log, 0,
- "upstream prematurely closed connection");
-
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_BAD_GATEWAY);
- return;
- }
-
- if (upstream->read->error || u->error) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_BAD_GATEWAY);
- return;
- }
-
- b->pos = b->start;
- b->last = b->start;
- }
- }
-
- size = b->end - b->last;
-
- if (size && upstream->read->ready) {
-
- n = upstream->recv(upstream, b->last, size);
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- if (n > 0) {
- u->state->bytes_received += n;
- u->state->response_length += n;
-
- if (u->input_filter(u->input_filter_ctx, n) == NGX_ERROR) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- do_write = 1;
-
- continue;
- }
-
- break;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (downstream->data == r) {
- if (ngx_handle_write_event(downstream->write, clcf->send_lowat)
- != NGX_OK)
- {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- if (downstream->write->active && !downstream->write->ready) {
- ngx_add_timer(downstream->write, clcf->send_timeout);
-
- } else if (downstream->write->timer_set) {
- ngx_del_timer(downstream->write);
- }
-
- if (upstream->read->eof || upstream->read->error) {
- flags = NGX_CLOSE_EVENT;
-
- } else {
- flags = 0;
- }
-
- if (ngx_handle_read_event(upstream->read, flags) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
-
- if (upstream->read->active && !upstream->read->ready) {
- ngx_add_timer(upstream->read, u->conf->read_timeout);
-
- } else if (upstream->read->timer_set) {
- ngx_del_timer(upstream->read);
- }
-}
-
-
-ngx_int_t
-ngx_http_upstream_non_buffered_filter_init(void *data)
-{
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes)
-{
- ngx_http_request_t *r = data;
-
- ngx_buf_t *b;
- ngx_chain_t *cl, **ll;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->length == 0) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent more data than specified in "
- "\"Content-Length\" header");
- return NGX_OK;
- }
-
- for (cl = u->out_bufs, ll = &u->out_bufs; cl; cl = cl->next) {
- ll = &cl->next;
- }
-
- cl = ngx_chain_get_free_buf(r->pool, &u->free_bufs);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- *ll = cl;
-
- cl->buf->flush = 1;
- cl->buf->memory = 1;
-
- b = &u->buffer;
-
- cl->buf->pos = b->last;
- b->last += bytes;
- cl->buf->last = b->last;
- cl->buf->tag = u->output.tag;
-
- if (u->length == -1) {
- return NGX_OK;
- }
-
- if (bytes > u->length) {
-
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent more data than specified in "
- "\"Content-Length\" header");
-
- cl->buf->last = cl->buf->pos + u->length;
- u->length = 0;
-
- return NGX_OK;
- }
-
- u->length -= bytes;
-
- return NGX_OK;
-}
-
-
-#if (NGX_THREADS)
-
-static ngx_int_t
-ngx_http_upstream_thread_handler(ngx_thread_task_t *task, ngx_file_t *file)
-{
- ngx_str_t name;
- ngx_event_pipe_t *p;
- ngx_connection_t *c;
- ngx_thread_pool_t *tp;
- ngx_http_request_t *r;
- ngx_http_core_loc_conf_t *clcf;
-
- r = file->thread_ctx;
- p = r->upstream->pipe;
-
- if (r->aio) {
- /*
- * tolerate sendfile() calls if another operation is already
- * running; this can happen due to subrequests, multiple calls
- * of the next body filter from a filter, or in HTTP/2 due to
- * a write event on the main connection
- */
-
- c = r->connection;
-
-#if (NGX_HTTP_V2)
- if (r->stream) {
- c = r->stream->connection->connection;
- }
-#endif
-
- if (task == c->sendfile_task) {
- return NGX_OK;
- }
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- tp = clcf->thread_pool;
-
- if (tp == NULL) {
- if (ngx_http_complex_value(r, clcf->thread_pool_value, &name)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- tp = ngx_thread_pool_get((ngx_cycle_t *) ngx_cycle, &name);
-
- if (tp == NULL) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "thread pool \"%V\" not found", &name);
- return NGX_ERROR;
- }
- }
-
- task->event.data = r;
- task->event.handler = ngx_http_upstream_thread_event_handler;
-
- if (ngx_thread_task_post(tp, task) != NGX_OK) {
- return NGX_ERROR;
- }
-
- r->main->blocked++;
- r->aio = 1;
- p->aio = 1;
-
- ngx_add_timer(&task->event, 60000);
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_upstream_thread_event_handler(ngx_event_t *ev)
-{
- ngx_connection_t *c;
- ngx_http_request_t *r;
-
- r = ev->data;
- c = r->connection;
-
- ngx_http_set_log_request(c->log, r);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream thread: \"%V?%V\"", &r->uri, &r->args);
-
- if (ev->timedout) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "thread operation took too long");
- ev->timedout = 0;
- return;
- }
-
- if (ev->timer_set) {
- ngx_del_timer(ev);
- }
-
- r->main->blocked--;
- r->aio = 0;
-
-#if (NGX_HTTP_V2)
-
- if (r->stream) {
- /*
- * for HTTP/2, update write event to make sure processing will
- * reach the main connection to handle sendfile() in threads
- */
-
- c->write->ready = 1;
- c->write->active = 0;
- }
-
-#endif
-
- if (r->done || r->main->terminated) {
- /*
- * trigger connection event handler if the subrequest was
- * already finalized (this can happen if the handler is used
- * for sendfile() in threads), or if the request was terminated
- */
-
- c->write->handler(c->write);
-
- } else {
- r->write_event_handler(r);
- ngx_http_run_posted_requests(c);
- }
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_http_upstream_output_filter(void *data, ngx_chain_t *chain)
-{
- ngx_int_t rc;
- ngx_event_pipe_t *p;
- ngx_http_request_t *r;
-
- r = data;
- p = r->upstream->pipe;
-
- rc = ngx_http_output_filter(r, chain);
-
- p->aio = r->aio;
-
- return rc;
-}
-
-
-static void
-ngx_http_upstream_process_downstream(ngx_http_request_t *r)
-{
- ngx_event_t *wev;
- ngx_connection_t *c;
- ngx_event_pipe_t *p;
- ngx_http_upstream_t *u;
-
- c = r->connection;
- u = r->upstream;
- p = u->pipe;
- wev = c->write;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process downstream");
-
- c->log->action = "sending to client";
-
-#if (NGX_THREADS)
- p->aio = r->aio;
-#endif
-
- if (wev->timedout) {
-
- p->downstream_error = 1;
- c->timedout = 1;
- ngx_connection_error(c, NGX_ETIMEDOUT, "client timed out");
-
- } else {
-
- if (wev->delayed) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http downstream delayed");
-
- if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- }
-
- return;
- }
-
- if (ngx_event_pipe(p, 1) == NGX_ABORT) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- ngx_http_upstream_process_request(r, u);
-}
-
-
-static void
-ngx_http_upstream_process_upstream(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_event_t *rev;
- ngx_event_pipe_t *p;
- ngx_connection_t *c;
-
- c = u->peer.connection;
- p = u->pipe;
- rev = c->read;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream process upstream");
-
- c->log->action = "reading upstream";
-
- if (rev->timedout) {
-
- p->upstream_error = 1;
- ngx_connection_error(c, NGX_ETIMEDOUT, "upstream timed out");
-
- } else {
-
- if (rev->delayed) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http upstream delayed");
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- }
-
- return;
- }
-
- if (ngx_event_pipe(p, 0) == NGX_ABORT) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- ngx_http_upstream_process_request(r, u);
-}
-
-
-static void
-ngx_http_upstream_process_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u)
-{
- ngx_temp_file_t *tf;
- ngx_event_pipe_t *p;
-
- p = u->pipe;
-
-#if (NGX_THREADS)
-
- if (p->writing && !p->aio) {
-
- /*
- * make sure to call ngx_event_pipe()
- * if there is an incomplete aio write
- */
-
- if (ngx_event_pipe(p, 1) == NGX_ABORT) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- return;
- }
- }
-
- if (p->writing) {
- return;
- }
-
-#endif
-
- if (u->peer.connection) {
-
- if (u->store) {
-
- if (p->upstream_eof || p->upstream_done) {
-
- tf = p->temp_file;
-
- if (u->headers_in.status_n == NGX_HTTP_OK
- && (p->upstream_done || p->length == -1)
- && (u->headers_in.content_length_n == -1
- || u->headers_in.content_length_n == tf->offset))
- {
- ngx_http_upstream_store(r, u);
- }
- }
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (u->cacheable) {
-
- if (p->upstream_done) {
- ngx_http_file_cache_update(r, p->temp_file);
-
- } else if (p->upstream_eof) {
-
- tf = p->temp_file;
-
- if (p->length == -1
- && (u->headers_in.content_length_n == -1
- || u->headers_in.content_length_n
- == tf->offset - (off_t) r->cache->body_start))
- {
- ngx_http_file_cache_update(r, tf);
-
- } else {
- ngx_http_file_cache_free(r->cache, tf);
- }
-
- } else if (p->upstream_error) {
- ngx_http_file_cache_free(r->cache, p->temp_file);
- }
- }
-
-#endif
-
- if (p->upstream_done || p->upstream_eof || p->upstream_error) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream exit: %p", p->out);
-
- if (p->upstream_done
- || (p->upstream_eof && p->length == -1))
- {
- ngx_http_upstream_finalize_request(r, u, 0);
- return;
- }
-
- if (p->upstream_eof) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream prematurely closed connection");
- }
-
- ngx_http_upstream_finalize_request(r, u, NGX_HTTP_BAD_GATEWAY);
- return;
- }
- }
-
- if (p->downstream_error) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream downstream error");
-
- if (!u->cacheable && !u->store && u->peer.connection) {
- ngx_http_upstream_finalize_request(r, u, NGX_ERROR);
- }
- }
-}
-
-
-static void
-ngx_http_upstream_store(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- size_t root;
- time_t lm;
- ngx_str_t path;
- ngx_temp_file_t *tf;
- ngx_ext_rename_file_t ext;
-
- tf = u->pipe->temp_file;
-
- if (tf->file.fd == NGX_INVALID_FILE) {
-
- /* create file for empty 200 response */
-
- tf = ngx_pcalloc(r->pool, sizeof(ngx_temp_file_t));
- if (tf == NULL) {
- return;
- }
-
- tf->file.fd = NGX_INVALID_FILE;
- tf->file.log = r->connection->log;
- tf->path = u->conf->temp_path;
- tf->pool = r->pool;
- tf->persistent = 1;
-
- if (ngx_create_temp_file(&tf->file, tf->path, tf->pool,
- tf->persistent, tf->clean, tf->access)
- != NGX_OK)
- {
- return;
- }
-
- u->pipe->temp_file = tf;
- }
-
- ext.access = u->conf->store_access;
- ext.path_access = u->conf->store_access;
- ext.time = -1;
- ext.create_path = 1;
- ext.delete_file = 1;
- ext.log = r->connection->log;
-
- if (u->headers_in.last_modified) {
-
- lm = ngx_parse_http_time(u->headers_in.last_modified->value.data,
- u->headers_in.last_modified->value.len);
-
- if (lm != NGX_ERROR) {
- ext.time = lm;
- ext.fd = tf->file.fd;
- }
- }
-
- if (u->conf->store_lengths == NULL) {
-
- if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) {
- return;
- }
-
- } else {
- if (ngx_http_script_run(r, &path, u->conf->store_lengths->elts, 0,
- u->conf->store_values->elts)
- == NULL)
- {
- return;
- }
- }
-
- path.len--;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "upstream stores \"%s\" to \"%s\"",
- tf->file.name.data, path.data);
-
- if (path.len == 0) {
- return;
- }
-
- (void) ngx_ext_rename_file(&tf->file.name, &path, &ext);
-
- u->store = 0;
-}
-
-
-static void
-ngx_http_upstream_dummy_handler(ngx_http_request_t *r, ngx_http_upstream_t *u)
-{
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream dummy handler");
-}
-
-
-static void
-ngx_http_upstream_next(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_uint_t ft_type)
-{
- ngx_msec_t timeout;
- ngx_uint_t status, state;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http next upstream, %xi", ft_type);
-
- if (u->peer.sockaddr) {
-
- if (u->peer.connection) {
- u->state->bytes_sent = u->peer.connection->sent;
- }
-
- if (ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_403
- || ft_type == NGX_HTTP_UPSTREAM_FT_HTTP_404)
- {
- state = NGX_PEER_NEXT;
-
- } else {
- state = NGX_PEER_FAILED;
- }
-
- u->peer.free(&u->peer, u->peer.data, state);
- u->peer.sockaddr = NULL;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- u->peer.sid = NULL;
-#endif
- }
-
- if (ft_type == NGX_HTTP_UPSTREAM_FT_TIMEOUT) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, NGX_ETIMEDOUT,
- "upstream timed out");
- }
-
- if (u->peer.cached && ft_type == NGX_HTTP_UPSTREAM_FT_ERROR) {
- /* TODO: inform balancer instead */
- u->peer.tries++;
- }
-
- switch (ft_type) {
-
- case NGX_HTTP_UPSTREAM_FT_TIMEOUT:
- case NGX_HTTP_UPSTREAM_FT_HTTP_504:
- status = NGX_HTTP_GATEWAY_TIME_OUT;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_500:
- status = NGX_HTTP_INTERNAL_SERVER_ERROR;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_503:
- status = NGX_HTTP_SERVICE_UNAVAILABLE;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_403:
- status = NGX_HTTP_FORBIDDEN;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_404:
- status = NGX_HTTP_NOT_FOUND;
- break;
-
- case NGX_HTTP_UPSTREAM_FT_HTTP_429:
- status = NGX_HTTP_TOO_MANY_REQUESTS;
- break;
-
- /*
- * NGX_HTTP_UPSTREAM_FT_BUSY_LOCK and NGX_HTTP_UPSTREAM_FT_MAX_WAITING
- * never reach here
- */
-
- default:
- status = NGX_HTTP_BAD_GATEWAY;
- }
-
- if (r->connection->error) {
- ngx_http_upstream_finalize_request(r, u,
- NGX_HTTP_CLIENT_CLOSED_REQUEST);
- return;
- }
-
- u->state->status = status;
-
- timeout = u->conf->next_upstream_timeout;
-
- if (u->request_sent
- && (r->method & (NGX_HTTP_POST|NGX_HTTP_LOCK|NGX_HTTP_PATCH)))
- {
- ft_type |= NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT;
- }
-
- if (u->peer.tries == 0
- || ((u->conf->next_upstream & ft_type) != ft_type)
- || (u->request_sent && r->request_body_no_buffering)
- || (timeout && ngx_current_msec - u->peer.start_time >= timeout))
- {
-#if (NGX_HTTP_CACHE)
-
- if (u->cache_status == NGX_HTTP_CACHE_EXPIRED
- && ((u->conf->cache_use_stale & ft_type) || r->cache->stale_error))
- {
- ngx_int_t rc;
-
- rc = u->reinit_request(r);
-
- if (rc != NGX_OK) {
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-
- u->cache_status = NGX_HTTP_CACHE_STALE;
- rc = ngx_http_upstream_cache_send(r, u);
-
- if (rc == NGX_DONE) {
- return;
- }
-
- if (rc == NGX_HTTP_UPSTREAM_INVALID_HEADER) {
- rc = NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- ngx_http_upstream_finalize_request(r, u, rc);
- return;
- }
-#endif
-
- ngx_http_upstream_finalize_request(r, u, status);
- return;
- }
-
- if (u->peer.connection) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "close http upstream connection: %d",
- u->peer.connection->fd);
-#if (NGX_HTTP_SSL)
-
- if (u->peer.connection->ssl) {
- u->peer.connection->ssl->no_wait_shutdown = 1;
- u->peer.connection->ssl->no_send_shutdown = 1;
-
- (void) ngx_ssl_shutdown(u->peer.connection);
- }
-#endif
-
- if (u->peer.connection->pool) {
- ngx_destroy_pool(u->peer.connection->pool);
- }
-
- ngx_close_connection(u->peer.connection);
- u->peer.connection = NULL;
- }
-
- ngx_http_upstream_connect(r, u);
-}
-
-
-static void
-ngx_http_upstream_cleanup(void *data)
-{
- ngx_http_request_t *r = data;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "cleanup http upstream request: \"%V\"", &r->uri);
-
- ngx_http_upstream_finalize_request(r, r->upstream, NGX_DONE);
-}
-
-
-static void
-ngx_http_upstream_finalize_request(ngx_http_request_t *r,
- ngx_http_upstream_t *u, ngx_int_t rc)
-{
- ngx_uint_t flush;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "finalize http upstream request: %i", rc);
-
- if (u->cleanup == NULL) {
- /* the request was already finalized */
- ngx_http_finalize_request(r, NGX_DONE);
- return;
- }
-
- *u->cleanup = NULL;
- u->cleanup = NULL;
-
- if (u->resolved && u->resolved->ctx) {
- ngx_resolve_name_done(u->resolved->ctx);
- u->resolved->ctx = NULL;
- }
-
- if (u->state && u->state->response_time == (ngx_msec_t) -1) {
- u->state->response_time = ngx_current_msec - u->start_time;
-
- if (u->pipe && u->pipe->read_length) {
- u->state->bytes_received += u->pipe->read_length
- - u->pipe->preread_size;
- u->state->response_length = u->pipe->read_length;
- }
-
- if (u->peer.connection) {
- u->state->bytes_sent = u->peer.connection->sent;
- }
- }
-
- u->finalize_request(r, rc);
-
- if (u->peer.free && u->peer.sockaddr) {
- u->peer.free(&u->peer, u->peer.data, 0);
- u->peer.sockaddr = NULL;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- u->peer.sid = NULL;
-#endif
- }
-
- if (u->peer.connection) {
-
-#if (NGX_HTTP_SSL)
-
- /* TODO: do not shutdown persistent connection */
-
- if (u->peer.connection->ssl) {
-
- /*
- * We send the "close notify" shutdown alert to the upstream only
- * and do not wait its "close notify" shutdown alert.
- * It is acceptable according to the TLS standard.
- */
-
- u->peer.connection->ssl->no_wait_shutdown = 1;
-
- (void) ngx_ssl_shutdown(u->peer.connection);
- }
-#endif
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "close http upstream connection: %d",
- u->peer.connection->fd);
-
- if (u->peer.connection->pool) {
- ngx_destroy_pool(u->peer.connection->pool);
- }
-
- ngx_close_connection(u->peer.connection);
- }
-
- u->peer.connection = NULL;
-
- if (u->pipe) {
- u->pipe->upstream = NULL;
- }
-
- if (u->pipe && u->pipe->temp_file) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http upstream temp fd: %d",
- u->pipe->temp_file->file.fd);
- }
-
- if (u->store && u->pipe && u->pipe->temp_file
- && u->pipe->temp_file->file.fd != NGX_INVALID_FILE)
- {
- if (ngx_delete_file(u->pipe->temp_file->file.name.data)
- == NGX_FILE_ERROR)
- {
- ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_delete_file_n " \"%s\" failed",
- u->pipe->temp_file->file.name.data);
- }
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cache) {
-
- if (u->cacheable) {
-
- if (rc == NGX_HTTP_BAD_GATEWAY || rc == NGX_HTTP_GATEWAY_TIME_OUT) {
- time_t valid;
-
- valid = ngx_http_file_cache_valid(u->conf->cache_valid, rc);
-
- if (valid) {
- r->cache->valid_sec = ngx_time() + valid;
- r->cache->error = rc;
- }
- }
- }
-
- ngx_http_file_cache_free(r->cache, u->pipe->temp_file);
- }
-
-#endif
-
- r->read_event_handler = ngx_http_block_reading;
-
- if (rc == NGX_DECLINED) {
- return;
- }
-
- r->connection->log->action = "sending to client";
-
- if (!u->header_sent
- || rc == NGX_HTTP_REQUEST_TIME_OUT
- || rc == NGX_HTTP_CLIENT_CLOSED_REQUEST)
- {
- ngx_http_finalize_request(r, rc);
- return;
- }
-
- flush = 0;
-
- if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
- rc = NGX_ERROR;
- flush = 1;
- }
-
- if (r->header_only
- || (u->pipe && u->pipe->downstream_error))
- {
- ngx_http_finalize_request(r, rc);
- return;
- }
-
- if (rc == 0) {
-
- if (ngx_http_upstream_process_trailers(r, u) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_ERROR);
- return;
- }
-
- rc = ngx_http_send_special(r, NGX_HTTP_LAST);
-
- } else if (flush) {
- r->keepalive = 0;
- rc = ngx_http_send_special(r, NGX_HTTP_FLUSH);
- }
-
- ngx_http_finalize_request(r, rc);
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
-
- ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset);
-
- if (*ph) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\", ignored",
- &h->key, &h->value,
- &(*ph)->key, &(*ph)->value);
- h->hash = 0;
- return NGX_OK;
- }
-
- *ph = h;
- h->next = NULL;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_multi_header_lines(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
-
- ph = (ngx_table_elt_t **) ((char *) &r->upstream->headers_in + offset);
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = h;
- h->next = NULL;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_ignore_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_content_length(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.content_length) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\"",
- &h->key, &h->value,
- &u->headers_in.content_length->key,
- &u->headers_in.content_length->value);
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- if (u->headers_in.transfer_encoding) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent \"Content-Length\" and "
- "\"Transfer-Encoding\" headers at the same time");
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- h->next = NULL;
- u->headers_in.content_length = h;
- u->headers_in.content_length_n = ngx_atoof(h->value.data, h->value.len);
-
- if (u->headers_in.content_length_n == NGX_ERROR) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent invalid \"Content-Length\" header: "
- "\"%V: %V\"", &h->key, &h->value);
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_last_modified(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.last_modified) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\", ignored",
- &h->key, &h->value,
- &u->headers_in.last_modified->key,
- &u->headers_in.last_modified->value);
- h->hash = 0;
- return NGX_OK;
- }
-
- h->next = NULL;
- u->headers_in.last_modified = h;
- u->headers_in.last_modified_time = ngx_parse_http_time(h->value.data,
- h->value.len);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
- ph = &u->headers_in.set_cookie;
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = h;
- h->next = NULL;
-
-#if (NGX_HTTP_CACHE)
- if (!(u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_SET_COOKIE)) {
- u->cacheable = 0;
- }
-#endif
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_cache_control(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
- ph = &u->headers_in.cache_control;
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = h;
- h->next = NULL;
-
-#if (NGX_HTTP_CACHE)
- {
- u_char *p, *start, *last;
- ngx_int_t n;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL) {
- return NGX_OK;
- }
-
- if (r->cache == NULL) {
- return NGX_OK;
- }
-
- start = h->value.data;
- last = start + h->value.len;
-
- if (r->cache->valid_sec != 0 && u->headers_in.x_accel_expires != NULL) {
- goto extensions;
- }
-
- if (ngx_strlcasestrn(start, last, (u_char *) "no-cache", 8 - 1) != NULL
- || ngx_strlcasestrn(start, last, (u_char *) "no-store", 8 - 1) != NULL
- || ngx_strlcasestrn(start, last, (u_char *) "private", 7 - 1) != NULL)
- {
- u->headers_in.no_cache = 1;
- return NGX_OK;
- }
-
- p = ngx_strlcasestrn(start, last, (u_char *) "s-maxage=", 9 - 1);
- offset = 9;
-
- if (p == NULL) {
- p = ngx_strlcasestrn(start, last, (u_char *) "max-age=", 8 - 1);
- offset = 8;
- }
-
- if (p) {
- n = ngx_http_upstream_process_delta_seconds(p + offset, last);
-
- if (n == NGX_ERROR) {
- u->cacheable = 0;
- return NGX_OK;
- }
-
- if (n == 0) {
- u->headers_in.no_cache = 1;
- return NGX_OK;
- }
-
- r->cache->valid_sec = ngx_min((ngx_uint_t) ngx_time() + n,
- NGX_MAX_INT_T_VALUE);
- u->headers_in.expired = 0;
- }
-
-extensions:
-
- p = ngx_strlcasestrn(start, last, (u_char *) "stale-while-revalidate=",
- 23 - 1);
-
- if (p) {
- n = ngx_http_upstream_process_delta_seconds(p + 23, last);
-
- if (n == NGX_ERROR) {
- u->cacheable = 0;
- return NGX_OK;
- }
-
- r->cache->updating_sec = n;
- r->cache->error_sec = n;
- }
-
- p = ngx_strlcasestrn(start, last, (u_char *) "stale-if-error=", 15 - 1);
-
- if (p) {
- n = ngx_http_upstream_process_delta_seconds(p + 15, last);
-
- if (n == NGX_ERROR) {
- u->cacheable = 0;
- return NGX_OK;
- }
-
- r->cache->error_sec = n;
- }
- }
-#endif
-
- return NGX_OK;
-}
-
-
-#if (NGX_HTTP_CACHE)
-
-static ngx_int_t
-ngx_http_upstream_process_delta_seconds(u_char *p, u_char *last)
-{
- ngx_int_t n, cutoff, cutlim;
-
- cutoff = NGX_MAX_INT_T_VALUE / 10;
- cutlim = NGX_MAX_INT_T_VALUE % 10;
-
- n = 0;
-
- for ( /* void */ ; p < last; p++) {
- if (*p == ',' || *p == ';' || *p == ' ') {
- break;
- }
-
- if (*p < '0' || *p > '9') {
- return NGX_ERROR;
- }
-
- if (n >= cutoff && (n > cutoff || *p - '0' > cutlim)) {
- n = NGX_MAX_INT_T_VALUE;
- break;
- }
-
- n = n * 10 + (*p - '0');
- }
-
- return n;
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_http_upstream_process_expires(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.expires) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\", ignored",
- &h->key, &h->value,
- &u->headers_in.expires->key,
- &u->headers_in.expires->value);
- h->hash = 0;
- return NGX_OK;
- }
-
- u->headers_in.expires = h;
- h->next = NULL;
-
-#if (NGX_HTTP_CACHE)
- {
- time_t expires;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_EXPIRES) {
- return NGX_OK;
- }
-
- if (r->cache == NULL) {
- return NGX_OK;
- }
-
- if (r->cache->valid_sec != 0) {
- return NGX_OK;
- }
-
- expires = ngx_parse_http_time(h->value.data, h->value.len);
-
- if (expires == NGX_ERROR || expires < ngx_time()) {
- u->headers_in.expired = 1;
- return NGX_OK;
- }
-
- r->cache->valid_sec = expires;
- }
-#endif
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_accel_expires(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.x_accel_expires) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\", ignored",
- &h->key, &h->value,
- &u->headers_in.x_accel_expires->key,
- &u->headers_in.x_accel_expires->value);
- h->hash = 0;
- return NGX_OK;
- }
-
- u->headers_in.x_accel_expires = h;
- h->next = NULL;
-
-#if (NGX_HTTP_CACHE)
- {
- u_char *p;
- size_t len;
- ngx_int_t n;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES) {
- return NGX_OK;
- }
-
- if (r->cache == NULL) {
- return NGX_OK;
- }
-
- len = h->value.len;
- p = h->value.data;
-
- if (p[0] != '@') {
- n = ngx_atoi(p, len);
-
- switch (n) {
- case 0:
- u->cacheable = 0;
- /* fall through */
-
- case NGX_ERROR:
- return NGX_OK;
-
- default:
- r->cache->valid_sec = ngx_time() + n;
- u->headers_in.no_cache = 0;
- u->headers_in.expired = 0;
- return NGX_OK;
- }
- }
-
- p++;
- len--;
-
- n = ngx_atoi(p, len);
-
- if (n != NGX_ERROR) {
- r->cache->valid_sec = n;
- u->headers_in.no_cache = 0;
- u->headers_in.expired = 0;
- }
- }
-#endif
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_limit_rate(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_int_t n;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.x_accel_limit_rate) {
- ngx_log_error(NGX_LOG_WARN, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\", ignored",
- &h->key, &h->value,
- &u->headers_in.x_accel_limit_rate->key,
- &u->headers_in.x_accel_limit_rate->value);
- h->hash = 0;
- return NGX_OK;
- }
-
- u->headers_in.x_accel_limit_rate = h;
- h->next = NULL;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE) {
- return NGX_OK;
- }
-
- n = ngx_atoi(h->value.data, h->value.len);
-
- if (n != NGX_ERROR) {
- r->limit_rate = (size_t) n;
- r->limit_rate_set = 1;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_buffering(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- u_char c0, c1, c2;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING) {
- return NGX_OK;
- }
-
- if (u->conf->change_buffering) {
-
- if (h->value.len == 2) {
- c0 = ngx_tolower(h->value.data[0]);
- c1 = ngx_tolower(h->value.data[1]);
-
- if (c0 == 'n' && c1 == 'o') {
- u->buffering = 0;
- }
-
- } else if (h->value.len == 3) {
- c0 = ngx_tolower(h->value.data[0]);
- c1 = ngx_tolower(h->value.data[1]);
- c2 = ngx_tolower(h->value.data[2]);
-
- if (c0 == 'y' && c1 == 'e' && c2 == 's') {
- u->buffering = 1;
- }
- }
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_charset(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_XA_CHARSET) {
- return NGX_OK;
- }
-
- r->headers_out.override_charset = &h->value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_connection(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
- ph = &u->headers_in.connection;
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = h;
- h->next = NULL;
-
- if (ngx_strlcasestrn(h->value.data, h->value.data + h->value.len,
- (u_char *) "close", 5 - 1)
- != NULL)
- {
- u->headers_in.connection_close = 1;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_transfer_encoding(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_http_upstream_t *u;
-
- u = r->upstream;
-
- if (u->headers_in.transfer_encoding) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent duplicate header line: \"%V: %V\", "
- "previous value: \"%V: %V\"",
- &h->key, &h->value,
- &u->headers_in.transfer_encoding->key,
- &u->headers_in.transfer_encoding->value);
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- if (u->headers_in.content_length) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent \"Content-Length\" and "
- "\"Transfer-Encoding\" headers at the same time");
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- u->headers_in.transfer_encoding = h;
- h->next = NULL;
-
- if (h->value.len == 7
- && ngx_strncasecmp(h->value.data, (u_char *) "chunked", 7) == 0)
- {
- u->headers_in.chunked = 1;
-
- } else {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "upstream sent unknown \"Transfer-Encoding\": \"%V\"",
- &h->value);
- return NGX_HTTP_UPSTREAM_INVALID_HEADER;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_process_vary(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_table_elt_t **ph;
- ngx_http_upstream_t *u;
-
- u = r->upstream;
- ph = &u->headers_in.vary;
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = h;
- h->next = NULL;
-
-#if (NGX_HTTP_CACHE)
- {
- u_char *p;
- size_t len;
- ngx_str_t vary;
-
- if (u->conf->ignore_headers & NGX_HTTP_UPSTREAM_IGN_VARY) {
- return NGX_OK;
- }
-
- if (r->cache == NULL || !u->cacheable) {
- return NGX_OK;
- }
-
- if (h->value.len == 1 && h->value.data[0] == '*') {
- u->cacheable = 0;
- return NGX_OK;
- }
-
- if (u->headers_in.vary->next) {
-
- len = 0;
-
- for (h = u->headers_in.vary; h; h = h->next) {
- len += h->value.len + 2;
- }
-
- len -= 2;
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- vary.len = len;
- vary.data = p;
-
- for (h = u->headers_in.vary; h; h = h->next) {
- p = ngx_copy(p, h->value.data, h->value.len);
-
- if (h->next == NULL) {
- break;
- }
-
- *p++ = ','; *p++ = ' ';
- }
-
- } else {
- vary = h->value;
- }
-
- if (vary.len > NGX_HTTP_CACHE_VARY_LEN) {
- u->cacheable = 0;
- }
-
- r->cache->vary = vary;
- }
-#endif
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_copy_header_line(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t *ho, **ph;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
-
- if (offset) {
- ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset);
- *ph = ho;
- ho->next = NULL;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_copy_multi_header_lines(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_table_elt_t *ho, **ph;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
-
- ph = (ngx_table_elt_t **) ((char *) &r->headers_out + offset);
-
- while (*ph) { ph = &(*ph)->next; }
-
- *ph = ho;
- ho->next = NULL;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_copy_content_type(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- u_char *p, *last;
-
- r->headers_out.content_type_len = h->value.len;
- r->headers_out.content_type = h->value;
- r->headers_out.content_type_lowcase = NULL;
-
- for (p = h->value.data; *p; p++) {
-
- if (*p != ';') {
- continue;
- }
-
- last = p;
-
- while (*++p == ' ') { /* void */ }
-
- if (*p == '\0') {
- return NGX_OK;
- }
-
- if (ngx_strncasecmp(p, (u_char *) "charset=", 8) != 0) {
- continue;
- }
-
- p += 8;
-
- r->headers_out.content_type_len = last - h->value.data;
-
- if (*p == '"') {
- p++;
- }
-
- last = h->value.data + h->value.len;
-
- if (last > p && *(last - 1) == '"') {
- last--;
- }
-
- r->headers_out.charset.len = last - p;
- r->headers_out.charset.data = p;
-
- return NGX_OK;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_copy_last_modified(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_table_elt_t *ho;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- r->headers_out.last_modified = ho;
- r->headers_out.last_modified_time =
- r->upstream->headers_in.last_modified_time;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_rewrite_location(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_int_t rc;
- ngx_table_elt_t *ho;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- if (r->upstream->rewrite_redirect) {
- rc = r->upstream->rewrite_redirect(r, ho, 0);
-
- if (rc == NGX_DECLINED) {
- return NGX_OK;
- }
-
- if (rc == NGX_OK) {
- r->headers_out.location = ho;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "rewritten location: \"%V\"", &ho->value);
- }
-
- return rc;
- }
-
- if (ho->value.data[0] != '/') {
- r->headers_out.location = ho;
- }
-
- /*
- * we do not set r->headers_out.location here to avoid handling
- * relative redirects in ngx_http_header_filter()
- */
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_rewrite_refresh(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- u_char *p;
- ngx_int_t rc;
- ngx_table_elt_t *ho;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- if (r->upstream->rewrite_redirect) {
-
- p = ngx_strcasestrn(ho->value.data, "url=", 4 - 1);
-
- if (p) {
- rc = r->upstream->rewrite_redirect(r, ho, p + 4 - ho->value.data);
-
- } else {
- return NGX_OK;
- }
-
- if (rc == NGX_DECLINED) {
- return NGX_OK;
- }
-
- if (rc == NGX_OK) {
- r->headers_out.refresh = ho;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "rewritten refresh: \"%V\"", &ho->value);
- }
-
- return rc;
- }
-
- r->headers_out.refresh = ho;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_rewrite_set_cookie(ngx_http_request_t *r, ngx_table_elt_t *h,
- ngx_uint_t offset)
-{
- ngx_int_t rc;
- ngx_table_elt_t *ho;
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- if (r->upstream->rewrite_cookie) {
- rc = r->upstream->rewrite_cookie(r, ho);
-
- if (rc == NGX_DECLINED) {
- return NGX_OK;
- }
-
-#if (NGX_DEBUG)
- if (rc == NGX_OK) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "rewritten cookie: \"%V\"", &ho->value);
- }
-#endif
-
- return rc;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_copy_allow_ranges(ngx_http_request_t *r,
- ngx_table_elt_t *h, ngx_uint_t offset)
-{
- ngx_table_elt_t *ho;
-
- if (r->upstream->conf->force_ranges) {
- return NGX_OK;
- }
-
-#if (NGX_HTTP_CACHE)
-
- if (r->cached) {
- r->allow_ranges = 1;
- return NGX_OK;
- }
-
- if (r->upstream->cacheable) {
- r->allow_ranges = 1;
- r->single_range = 1;
- return NGX_OK;
- }
-
-#endif
-
- ho = ngx_list_push(&r->headers_out.headers);
- if (ho == NULL) {
- return NGX_ERROR;
- }
-
- *ho = *h;
- ho->next = NULL;
-
- r->headers_out.accept_ranges = ho;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_add_variables(ngx_conf_t *cf)
-{
- ngx_http_variable_t *var, *v;
-
- for (v = ngx_http_upstream_vars; v->name.len; v++) {
- var = ngx_http_add_variable(cf, &v->name, v->flags);
- if (var == NULL) {
- return NGX_ERROR;
- }
-
- var->get_handler = v->get_handler;
- var->data = v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_addr_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- size_t len;
- ngx_uint_t i;
- ngx_http_upstream_state_t *state;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len = 0;
- state = r->upstream_states->elts;
-
- for (i = 0; i < r->upstream_states->nelts; i++) {
- if (state[i].peer) {
- len += state[i].peer->len + 2;
-
- } else {
- len += 3;
- }
- }
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->data = p;
-
- i = 0;
-
- for ( ;; ) {
- if (state[i].peer) {
- p = ngx_cpymem(p, state[i].peer->data, state[i].peer->len);
- }
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- if (state[i].peer) {
- *p++ = ',';
- *p++ = ' ';
-
- } else {
- *p++ = ' ';
- *p++ = ':';
- *p++ = ' ';
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- continue;
- }
- }
-
- v->len = p - v->data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_status_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- size_t len;
- ngx_uint_t i;
- ngx_http_upstream_state_t *state;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len = r->upstream_states->nelts * (3 + 2);
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->data = p;
-
- i = 0;
- state = r->upstream_states->elts;
-
- for ( ;; ) {
- if (state[i].status) {
- p = ngx_sprintf(p, "%ui", state[i].status);
-
- } else {
- *p++ = '-';
- }
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- if (state[i].peer) {
- *p++ = ',';
- *p++ = ' ';
-
- } else {
- *p++ = ' ';
- *p++ = ':';
- *p++ = ' ';
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- continue;
- }
- }
-
- v->len = p - v->data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_response_time_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- size_t len;
- ngx_uint_t i;
- ngx_msec_int_t ms;
- ngx_http_upstream_state_t *state;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len = r->upstream_states->nelts * (NGX_TIME_T_LEN + 4 + 2);
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->data = p;
-
- i = 0;
- state = r->upstream_states->elts;
-
- for ( ;; ) {
-
- if (data == 1) {
- ms = state[i].header_time;
-
- } else if (data == 2) {
- ms = state[i].connect_time;
-
- } else {
- ms = state[i].response_time;
- }
-
- if (ms != -1) {
- ms = ngx_max(ms, 0);
- p = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000);
-
- } else {
- *p++ = '-';
- }
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- if (state[i].peer) {
- *p++ = ',';
- *p++ = ' ';
-
- } else {
- *p++ = ' ';
- *p++ = ':';
- *p++ = ' ';
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- continue;
- }
- }
-
- v->len = p - v->data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_response_length_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- size_t len;
- ngx_uint_t i;
- ngx_http_upstream_state_t *state;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (r->upstream_states == NULL || r->upstream_states->nelts == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len = r->upstream_states->nelts * (NGX_OFF_T_LEN + 2);
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->data = p;
-
- i = 0;
- state = r->upstream_states->elts;
-
- for ( ;; ) {
-
- if (data == 1) {
- p = ngx_sprintf(p, "%O", state[i].bytes_received);
-
- } else if (data == 2) {
- p = ngx_sprintf(p, "%O", state[i].bytes_sent);
-
- } else {
- p = ngx_sprintf(p, "%O", state[i].response_length);
- }
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- if (state[i].peer) {
- *p++ = ',';
- *p++ = ' ';
-
- } else {
- *p++ = ' ';
- *p++ = ':';
- *p++ = ' ';
-
- if (++i == r->upstream_states->nelts) {
- break;
- }
-
- continue;
- }
- }
-
- v->len = p - v->data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_header_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->upstream == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
- &r->upstream->headers_in.headers.part,
- sizeof("upstream_http_") - 1);
-}
-
-
-static ngx_int_t
-ngx_http_upstream_trailer_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->upstream == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
- &r->upstream->headers_in.trailers.part,
- sizeof("upstream_trailer_") - 1);
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cookie_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t *name = (ngx_str_t *) data;
-
- ngx_str_t cookie, s;
-
- if (r->upstream == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- s.len = name->len - (sizeof("upstream_cookie_") - 1);
- s.data = name->data + sizeof("upstream_cookie_") - 1;
-
- if (ngx_http_parse_set_cookie_lines(r, r->upstream->headers_in.set_cookie,
- &s, &cookie)
- == NULL)
- {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->len = cookie.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = cookie.data;
-
- return NGX_OK;
-}
-
-
-#if (NGX_HTTP_CACHE)
-
-static ngx_int_t
-ngx_http_upstream_cache_status(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t n;
-
- if (r->upstream == NULL || r->upstream->cache_status == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- n = r->upstream->cache_status - 1;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->len = ngx_http_cache_status[n].len;
- v->data = ngx_http_cache_status[n].data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_last_modified(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- if (r->upstream == NULL
- || !r->upstream->conf->cache_revalidate
- || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED
- || r->cache->last_modified == -1)
- {
- v->not_found = 1;
- return NGX_OK;
- }
-
- p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_http_time(p, r->cache->last_modified) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_cache_etag(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->upstream == NULL
- || !r->upstream->conf->cache_revalidate
- || r->upstream->cache_status != NGX_HTTP_CACHE_EXPIRED
- || r->cache->etag.len == 0)
- {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->len = r->cache->etag.len;
- v->data = r->cache->etag.data;
-
- return NGX_OK;
-}
-
-#endif
-
-
-static char *
-ngx_http_upstream(ngx_conf_t *cf, ngx_command_t *cmd, void *dummy)
-{
- char *rv;
- void *mconf;
- ngx_str_t *value;
- ngx_url_t u;
- ngx_uint_t m;
- ngx_conf_t pcf;
- ngx_http_module_t *module;
- ngx_http_conf_ctx_t *ctx, *http_ctx;
- ngx_http_upstream_srv_conf_t *uscf;
-
- ngx_memzero(&u, sizeof(ngx_url_t));
-
- value = cf->args->elts;
- u.host = value[1];
- u.no_resolve = 1;
- u.no_port = 1;
-
- uscf = ngx_http_upstream_add(cf, &u, NGX_HTTP_UPSTREAM_CREATE
- |NGX_HTTP_UPSTREAM_MODIFY
- |NGX_HTTP_UPSTREAM_WEIGHT
- |NGX_HTTP_UPSTREAM_MAX_CONNS
- |NGX_HTTP_UPSTREAM_MAX_FAILS
- |NGX_HTTP_UPSTREAM_FAIL_TIMEOUT
- |NGX_HTTP_UPSTREAM_DOWN
- |NGX_HTTP_UPSTREAM_BACKUP);
- if (uscf == NULL) {
- return NGX_CONF_ERROR;
- }
-
-
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_http_conf_ctx_t));
- if (ctx == NULL) {
- return NGX_CONF_ERROR;
- }
-
- http_ctx = cf->ctx;
- ctx->main_conf = http_ctx->main_conf;
-
- /* the upstream{}'s srv_conf */
-
- ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
- if (ctx->srv_conf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ctx->srv_conf[ngx_http_upstream_module.ctx_index] = uscf;
-
- uscf->srv_conf = ctx->srv_conf;
-
-
- /* the upstream{}'s loc_conf */
-
- ctx->loc_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_http_max_module);
- if (ctx->loc_conf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_HTTP_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
-
- if (module->create_srv_conf) {
- mconf = module->create_srv_conf(cf);
- if (mconf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;
- }
-
- if (module->create_loc_conf) {
- mconf = module->create_loc_conf(cf);
- if (mconf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ctx->loc_conf[cf->cycle->modules[m]->ctx_index] = mconf;
- }
- }
-
- uscf->servers = ngx_array_create(cf->pool, 4,
- sizeof(ngx_http_upstream_server_t));
- if (uscf->servers == NULL) {
- return NGX_CONF_ERROR;
- }
-
-
- /* parse inside upstream{} */
-
- pcf = *cf;
- cf->ctx = ctx;
- cf->cmd_type = NGX_HTTP_UPS_CONF;
-
- rv = ngx_conf_parse(cf, NULL);
-
- *cf = pcf;
-
- if (rv != NGX_CONF_OK) {
- return rv;
- }
-
- if (uscf->servers->nelts == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "no servers are inside upstream");
- return NGX_CONF_ERROR;
- }
-
- return rv;
-}
-
-
-static char *
-ngx_http_upstream_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_upstream_srv_conf_t *uscf = conf;
-
- time_t fail_timeout;
- ngx_str_t *value, s;
- ngx_url_t u;
- ngx_int_t weight, max_conns, max_fails;
- ngx_uint_t i;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- ngx_uint_t resolve;
-#endif
- ngx_http_upstream_server_t *us;
-
- us = ngx_array_push(uscf->servers);
- if (us == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memzero(us, sizeof(ngx_http_upstream_server_t));
-
- value = cf->args->elts;
-
- weight = 1;
- max_conns = 0;
- max_fails = 1;
- fail_timeout = 10;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- resolve = 0;
-#endif
-
- for (i = 2; i < cf->args->nelts; i++) {
-
- if (ngx_strncmp(value[i].data, "weight=", 7) == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_WEIGHT)) {
- goto not_supported;
- }
-
- weight = ngx_atoi(&value[i].data[7], value[i].len - 7);
-
- if (weight == NGX_ERROR || weight == 0) {
- goto invalid;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "max_conns=", 10) == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_CONNS)) {
- goto not_supported;
- }
-
- max_conns = ngx_atoi(&value[i].data[10], value[i].len - 10);
-
- if (max_conns == NGX_ERROR) {
- goto invalid;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "max_fails=", 10) == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_MAX_FAILS)) {
- goto not_supported;
- }
-
- max_fails = ngx_atoi(&value[i].data[10], value[i].len - 10);
-
- if (max_fails == NGX_ERROR) {
- goto invalid;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "fail_timeout=", 13) == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_FAIL_TIMEOUT)) {
- goto not_supported;
- }
-
- s.len = value[i].len - 13;
- s.data = &value[i].data[13];
-
- fail_timeout = ngx_parse_time(&s, 1);
-
- if (fail_timeout == (time_t) NGX_ERROR) {
- goto invalid;
- }
-
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "backup") == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_BACKUP)) {
- goto not_supported;
- }
-
- us->backup = 1;
-
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "down") == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) {
- goto not_supported;
- }
-
- us->down = NGX_HTTP_UPSTREAM_FAILED;
-
- continue;
- }
-
-#if (NGX_HTTP_UPSTREAM_STICKY)
- if (ngx_strcmp(value[i].data, "drain") == 0) {
-
- if (!(uscf->flags & NGX_HTTP_UPSTREAM_DOWN)) {
- goto not_supported;
- }
-
- us->down = NGX_HTTP_UPSTREAM_DRAINING;
-
- continue;
- }
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID)
- if (ngx_strncmp(value[i].data, "route=", 6) == 0) {
-
- us->sid.data = &value[i].data[6];
- us->sid.len = value[i].len - 6;
-
- if (us->sid.len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "route is empty");
- return NGX_CONF_ERROR;
- }
-
- if (us->sid.len > NGX_HTTP_UPSTREAM_SID_LEN) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "route is longer than %d",
- NGX_HTTP_UPSTREAM_SID_LEN);
- return NGX_CONF_ERROR;
- }
-
- continue;
- }
-#endif
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (ngx_strcmp(value[i].data, "resolve") == 0) {
- resolve = 1;
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "service=", 8) == 0) {
-
- us->service.len = value[i].len - 8;
- us->service.data = &value[i].data[8];
-
- if (us->service.len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "service is empty");
- return NGX_CONF_ERROR;
- }
-
- continue;
- }
-#endif
-
- goto invalid;
- }
-
- ngx_memzero(&u, sizeof(ngx_url_t));
-
- u.url = value[1];
- u.default_port = 80;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (resolve) {
- /* resolve at run time */
- u.no_resolve = 1;
- }
-
- if (us->service.len && !resolve) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "service upstream \"%V\" requires "
- "\"resolve\" parameter",
- &u.url);
- return NGX_CONF_ERROR;
- }
-
-#endif
-
- if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
- if (u.err) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "%s in upstream \"%V\"", u.err, &u.url);
- }
-
- return NGX_CONF_ERROR;
- }
-
- us->name = u.url;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-
- if (us->service.len && !u.no_port) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "service upstream \"%V\" may not have port",
- &us->name);
-
- return NGX_CONF_ERROR;
- }
-
- if (us->service.len && u.naddrs) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "service upstream \"%V\" requires domain name",
- &us->name);
-
- return NGX_CONF_ERROR;
- }
-
- if (resolve && u.naddrs == 0) {
- ngx_addr_t *addr;
-
- /* save port */
-
- addr = ngx_pcalloc(cf->pool, sizeof(ngx_addr_t));
- if (addr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- addr->sockaddr = ngx_palloc(cf->pool, u.socklen);
- if (addr->sockaddr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memcpy(addr->sockaddr, &u.sockaddr, u.socklen);
-
- addr->socklen = u.socklen;
-
- us->addrs = addr;
- us->naddrs = 1;
-
- us->host = u.host;
-
- } else {
- us->addrs = u.addrs;
- us->naddrs = u.naddrs;
- }
-
-#else
-
- us->addrs = u.addrs;
- us->naddrs = u.naddrs;
-
-#endif
-
- us->weight = weight;
- us->max_conns = max_conns;
- us->max_fails = max_fails;
- us->fail_timeout = fail_timeout;
-
- return NGX_CONF_OK;
-
-invalid:
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%V\"", &value[i]);
-
- return NGX_CONF_ERROR;
-
-not_supported:
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "balancing method does not support parameter \"%V\"",
- &value[i]);
-
- return NGX_CONF_ERROR;
-}
-
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-
-static char *
-ngx_http_upstream_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_upstream_srv_conf_t *uscf = conf;
-
- ngx_str_t *value;
-
- if (uscf->resolver) {
- return "is duplicate";
- }
-
- value = cf->args->elts;
-
- uscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
- if (uscf->resolver == NULL) {
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-#endif
-
-
-ngx_http_upstream_srv_conf_t *
-ngx_http_upstream_add(ngx_conf_t *cf, ngx_url_t *u, ngx_uint_t flags)
-{
- ngx_uint_t i;
- ngx_http_upstream_server_t *us;
- ngx_http_upstream_srv_conf_t *uscf, **uscfp;
- ngx_http_upstream_main_conf_t *umcf;
-
- if (!(flags & NGX_HTTP_UPSTREAM_CREATE)) {
-
- if (ngx_parse_url(cf->pool, u) != NGX_OK) {
- if (u->err) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "%s in upstream \"%V\"", u->err, &u->url);
- }
-
- return NULL;
- }
- }
-
- umcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_upstream_module);
-
- uscfp = umcf->upstreams.elts;
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
-
- if (uscfp[i]->host.len != u->host.len
- || ngx_strncasecmp(uscfp[i]->host.data, u->host.data, u->host.len)
- != 0)
- {
- continue;
- }
-
- if ((flags & NGX_HTTP_UPSTREAM_CREATE)
- && (uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE))
- {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "duplicate upstream \"%V\"", &u->host);
- return NULL;
- }
-
- if ((uscfp[i]->flags & NGX_HTTP_UPSTREAM_CREATE) && !u->no_port) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "upstream \"%V\" may not have port %d",
- &u->host, u->port);
- return NULL;
- }
-
- if ((flags & NGX_HTTP_UPSTREAM_CREATE) && !uscfp[i]->no_port) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "upstream \"%V\" may not have port %d in %s:%ui",
- &u->host, uscfp[i]->port,
- uscfp[i]->file_name, uscfp[i]->line);
- return NULL;
- }
-
- if (uscfp[i]->port && u->port
- && uscfp[i]->port != u->port)
- {
- continue;
- }
-
- if (flags & NGX_HTTP_UPSTREAM_CREATE) {
- uscfp[i]->flags = flags;
- uscfp[i]->port = 0;
- }
-
- return uscfp[i];
- }
-
- uscf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_srv_conf_t));
- if (uscf == NULL) {
- return NULL;
- }
-
- uscf->flags = flags;
- uscf->host = u->host;
- uscf->file_name = cf->conf_file->file.name.data;
- uscf->line = cf->conf_file->line;
- uscf->port = u->port;
- uscf->no_port = u->no_port;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- uscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
-#endif
-
- if (u->naddrs == 1 && (u->port || u->family == AF_UNIX)) {
- uscf->servers = ngx_array_create(cf->pool, 1,
- sizeof(ngx_http_upstream_server_t));
- if (uscf->servers == NULL) {
- return NULL;
- }
-
- us = ngx_array_push(uscf->servers);
- if (us == NULL) {
- return NULL;
- }
-
- ngx_memzero(us, sizeof(ngx_http_upstream_server_t));
-
- us->addrs = u->addrs;
- us->naddrs = 1;
- }
-
- uscfp = ngx_array_push(&umcf->upstreams);
- if (uscfp == NULL) {
- return NULL;
- }
-
- *uscfp = uscf;
-
- return uscf;
-}
-
-
-char *
-ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
-{
- char *p = conf;
-
- ngx_int_t rc;
- ngx_str_t *value;
- ngx_http_complex_value_t cv;
- ngx_http_upstream_local_t **plocal, *local;
- ngx_http_compile_complex_value_t ccv;
-
- plocal = (ngx_http_upstream_local_t **) (p + cmd->offset);
-
- if (*plocal != NGX_CONF_UNSET_PTR) {
- return "is duplicate";
- }
-
- value = cf->args->elts;
-
- if (cf->args->nelts == 2 && ngx_strcmp(value[1].data, "off") == 0) {
- *plocal = NULL;
- return NGX_CONF_OK;
- }
-
- ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
-
- ccv.cf = cf;
- ccv.value = &value[1];
- ccv.complex_value = &cv;
-
- if (ngx_http_compile_complex_value(&ccv) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- local = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_local_t));
- if (local == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *plocal = local;
-
- if (cv.lengths) {
- local->value = ngx_palloc(cf->pool, sizeof(ngx_http_complex_value_t));
- if (local->value == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *local->value = cv;
-
- } else {
- local->addr = ngx_palloc(cf->pool, sizeof(ngx_addr_t));
- if (local->addr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- rc = ngx_parse_addr_port(cf->pool, local->addr, value[1].data,
- value[1].len);
-
- switch (rc) {
- case NGX_OK:
- local->addr->name = value[1];
- break;
-
- case NGX_DECLINED:
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid address \"%V\"", &value[1]);
- /* fall through */
-
- default:
- return NGX_CONF_ERROR;
- }
- }
-
- if (cf->args->nelts > 2) {
- if (ngx_strcmp(value[2].data, "transparent") == 0) {
-#if (NGX_HAVE_TRANSPARENT_PROXY)
- ngx_core_conf_t *ccf;
-
- ccf = (ngx_core_conf_t *) ngx_get_conf(cf->cycle->conf_ctx,
- ngx_core_module);
-
- ccf->transparent = 1;
- local->transparent = 1;
-#else
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "transparent proxying is not supported "
- "on this platform, ignored");
-#endif
- } else {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%V\"", &value[2]);
- return NGX_CONF_ERROR;
- }
- }
-
- return NGX_CONF_OK;
-}
-
-
-static ngx_int_t
-ngx_http_upstream_set_local(ngx_http_request_t *r, ngx_http_upstream_t *u,
- ngx_http_upstream_local_t *local)
-{
- ngx_int_t rc;
- ngx_str_t val;
- ngx_addr_t *addr;
-
- if (local == NULL) {
- u->peer.local = NULL;
- return NGX_OK;
- }
-
-#if (NGX_HAVE_TRANSPARENT_PROXY)
- u->peer.transparent = local->transparent;
-#endif
-
- if (local->value == NULL) {
- u->peer.local = local->addr;
- return NGX_OK;
- }
-
- if (ngx_http_complex_value(r, local->value, &val) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (val.len == 0) {
- u->peer.local = NULL;
- return NGX_OK;
- }
-
- addr = ngx_palloc(r->pool, sizeof(ngx_addr_t));
- if (addr == NULL) {
- return NGX_ERROR;
- }
-
- rc = ngx_parse_addr_port(r->pool, addr, val.data, val.len);
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- if (rc != NGX_OK) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "invalid local address \"%V\"", &val);
- u->peer.local = NULL;
- return NGX_OK;
- }
-
- addr->name = val;
- u->peer.local = addr;
-
- return NGX_OK;
-}
-
-
-char *
-ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf)
-{
- char *p = conf;
-
- ngx_str_t *value;
- ngx_array_t **a;
- ngx_http_upstream_param_t *param;
-
- a = (ngx_array_t **) (p + cmd->offset);
-
- if (*a == NULL) {
- *a = ngx_array_create(cf->pool, 4, sizeof(ngx_http_upstream_param_t));
- if (*a == NULL) {
- return NGX_CONF_ERROR;
- }
- }
-
- param = ngx_array_push(*a);
- if (param == NULL) {
- return NGX_CONF_ERROR;
- }
-
- value = cf->args->elts;
-
- param->key = value[1];
- param->value = value[2];
- param->skip_empty = 0;
-
- if (cf->args->nelts == 4) {
- if (ngx_strcmp(value[3].data, "if_not_empty") != 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%V\"", &value[3]);
- return NGX_CONF_ERROR;
- }
-
- param->skip_empty = 1;
- }
-
- return NGX_CONF_OK;
-}
-
-
-ngx_int_t
-ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
- ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
- ngx_str_t *default_hide_headers, ngx_hash_init_t *hash)
-{
- ngx_str_t *h;
- ngx_uint_t i, j;
- ngx_array_t hide_headers;
- ngx_hash_key_t *hk;
-
- if (conf->hide_headers == NGX_CONF_UNSET_PTR
- && conf->pass_headers == NGX_CONF_UNSET_PTR)
- {
- conf->hide_headers = prev->hide_headers;
- conf->pass_headers = prev->pass_headers;
-
- conf->hide_headers_hash = prev->hide_headers_hash;
-
- if (conf->hide_headers_hash.buckets) {
- return NGX_OK;
- }
-
- } else {
- if (conf->hide_headers == NGX_CONF_UNSET_PTR) {
- conf->hide_headers = prev->hide_headers;
- }
-
- if (conf->pass_headers == NGX_CONF_UNSET_PTR) {
- conf->pass_headers = prev->pass_headers;
- }
- }
-
- if (ngx_array_init(&hide_headers, cf->temp_pool, 4, sizeof(ngx_hash_key_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- for (h = default_hide_headers; h->len; h++) {
- hk = ngx_array_push(&hide_headers);
- if (hk == NULL) {
- return NGX_ERROR;
- }
-
- hk->key = *h;
- hk->key_hash = ngx_hash_key_lc(h->data, h->len);
- hk->value = (void *) 1;
- }
-
- if (conf->hide_headers != NGX_CONF_UNSET_PTR) {
-
- h = conf->hide_headers->elts;
-
- for (i = 0; i < conf->hide_headers->nelts; i++) {
-
- hk = hide_headers.elts;
-
- for (j = 0; j < hide_headers.nelts; j++) {
- if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {
- goto exist;
- }
- }
-
- hk = ngx_array_push(&hide_headers);
- if (hk == NULL) {
- return NGX_ERROR;
- }
-
- hk->key = h[i];
- hk->key_hash = ngx_hash_key_lc(h[i].data, h[i].len);
- hk->value = (void *) 1;
-
- exist:
-
- continue;
- }
- }
-
- if (conf->pass_headers != NGX_CONF_UNSET_PTR) {
-
- h = conf->pass_headers->elts;
- hk = hide_headers.elts;
-
- for (i = 0; i < conf->pass_headers->nelts; i++) {
- for (j = 0; j < hide_headers.nelts; j++) {
-
- if (hk[j].key.data == NULL) {
- continue;
- }
-
- if (ngx_strcasecmp(h[i].data, hk[j].key.data) == 0) {
- hk[j].key.data = NULL;
- break;
- }
- }
- }
- }
-
- hash->hash = &conf->hide_headers_hash;
- hash->key = ngx_hash_key_lc;
- hash->pool = cf->pool;
- hash->temp_pool = NULL;
-
- if (ngx_hash_init(hash, hide_headers.elts, hide_headers.nelts) != NGX_OK) {
- return NGX_ERROR;
- }
-
- /*
- * special handling to preserve conf->hide_headers_hash
- * in the "http" section to inherit it to all servers
- */
-
- if (prev->hide_headers_hash.buckets == NULL
- && conf->hide_headers == prev->hide_headers
- && conf->pass_headers == prev->pass_headers)
- {
- prev->hide_headers_hash = conf->hide_headers_hash;
- }
-
- return NGX_OK;
-}
-
-
-#if (NGX_HTTP_SSL)
-
-ngx_int_t
-ngx_http_upstream_merge_ssl_passwords(ngx_conf_t *cf,
- ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev)
-{
- ngx_uint_t preserve;
-
- ngx_conf_merge_ptr_value(conf->ssl_passwords, prev->ssl_passwords, NULL);
-
- if (conf->ssl_certificate == NULL
- || conf->ssl_certificate->value.len == 0
- || conf->ssl_certificate_key == NULL)
- {
- return NGX_OK;
- }
-
- if (conf->ssl_certificate->lengths == NULL
- && conf->ssl_certificate_key->lengths == NULL)
- {
- if (conf->ssl_passwords && conf->ssl_passwords->pool == NULL) {
- /* un-preserve empty password list */
- conf->ssl_passwords = NULL;
- }
-
- return NGX_OK;
- }
-
- if (conf->ssl_passwords && conf->ssl_passwords->pool != cf->temp_pool) {
- /* already preserved */
- return NGX_OK;
- }
-
- preserve = (conf->ssl_passwords == prev->ssl_passwords) ? 1 : 0;
-
- conf->ssl_passwords = ngx_ssl_preserve_passwords(cf, conf->ssl_passwords);
- if (conf->ssl_passwords == NULL) {
- return NGX_ERROR;
- }
-
- /*
- * special handling to keep a preserved ssl_passwords copy
- * in the previous configuration to inherit it to all children
- */
-
- if (preserve) {
- prev->ssl_passwords = conf->ssl_passwords;
- }
-
- return NGX_OK;
-}
-
-#endif
-
-
-static void *
-ngx_http_upstream_create_main_conf(ngx_conf_t *cf)
-{
- ngx_http_upstream_main_conf_t *umcf;
-
- umcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_main_conf_t));
- if (umcf == NULL) {
- return NULL;
- }
-
- if (ngx_array_init(&umcf->upstreams, cf->pool, 4,
- sizeof(ngx_http_upstream_srv_conf_t *))
- != NGX_OK)
- {
- return NULL;
- }
-
- return umcf;
-}
-
-
-static char *
-ngx_http_upstream_init_main_conf(ngx_conf_t *cf, void *conf)
-{
- ngx_http_upstream_main_conf_t *umcf = conf;
-
- ngx_uint_t i;
- ngx_array_t headers_in;
- ngx_hash_key_t *hk;
- ngx_hash_init_t hash;
- ngx_http_upstream_init_pt init;
- ngx_http_upstream_header_t *header;
- ngx_http_upstream_srv_conf_t **uscfp;
-
- uscfp = umcf->upstreams.elts;
-
- for (i = 0; i < umcf->upstreams.nelts; i++) {
-
- init = uscfp[i]->peer.init_upstream ? uscfp[i]->peer.init_upstream:
- ngx_http_upstream_init_round_robin;
-
- if (init(cf, uscfp[i]) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- }
-
-
- /* upstream_headers_in_hash */
-
- if (ngx_array_init(&headers_in, cf->temp_pool, 32, sizeof(ngx_hash_key_t))
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- for (header = ngx_http_upstream_headers_in; header->name.len; header++) {
- hk = ngx_array_push(&headers_in);
- if (hk == NULL) {
- return NGX_CONF_ERROR;
- }
-
- hk->key = header->name;
- hk->key_hash = ngx_hash_key_lc(header->name.data, header->name.len);
- hk->value = header;
- }
-
- hash.hash = &umcf->headers_in_hash;
- hash.key = ngx_hash_key_lc;
- hash.max_size = 512;
- hash.bucket_size = ngx_align(64, ngx_cacheline_size);
- hash.name = "upstream_headers_in_hash";
- hash.pool = cf->pool;
- hash.temp_pool = NULL;
-
- if (ngx_hash_init(&hash, headers_in.elts, headers_in.nelts) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.h b/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.h
deleted file mode 100644
index 0d48db7880..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream.h
+++ /dev/null
@@ -1,464 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_UPSTREAM_H_INCLUDED_
-#define _NGX_HTTP_UPSTREAM_H_INCLUDED_
-
-
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-#define NGX_HTTP_UPSTREAM_FT_ERROR 0x00000002
-#define NGX_HTTP_UPSTREAM_FT_TIMEOUT 0x00000004
-#define NGX_HTTP_UPSTREAM_FT_INVALID_HEADER 0x00000008
-#define NGX_HTTP_UPSTREAM_FT_HTTP_500 0x00000010
-#define NGX_HTTP_UPSTREAM_FT_HTTP_502 0x00000020
-#define NGX_HTTP_UPSTREAM_FT_HTTP_503 0x00000040
-#define NGX_HTTP_UPSTREAM_FT_HTTP_504 0x00000080
-#define NGX_HTTP_UPSTREAM_FT_HTTP_403 0x00000100
-#define NGX_HTTP_UPSTREAM_FT_HTTP_404 0x00000200
-#define NGX_HTTP_UPSTREAM_FT_HTTP_429 0x00000400
-#define NGX_HTTP_UPSTREAM_FT_UPDATING 0x00000800
-#define NGX_HTTP_UPSTREAM_FT_BUSY_LOCK 0x00001000
-#define NGX_HTTP_UPSTREAM_FT_MAX_WAITING 0x00002000
-#define NGX_HTTP_UPSTREAM_FT_NON_IDEMPOTENT 0x00004000
-#define NGX_HTTP_UPSTREAM_FT_NOLIVE 0x40000000
-#define NGX_HTTP_UPSTREAM_FT_OFF 0x80000000
-
-#define NGX_HTTP_UPSTREAM_FT_STATUS (NGX_HTTP_UPSTREAM_FT_HTTP_500 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_502 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_503 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_504 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_403 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_404 \
- |NGX_HTTP_UPSTREAM_FT_HTTP_429)
-
-#define NGX_HTTP_UPSTREAM_INVALID_HEADER 40
-#define NGX_HTTP_UPSTREAM_EARLY_HINTS 41
-
-
-#define NGX_HTTP_UPSTREAM_IGN_XA_REDIRECT 0x00000002
-#define NGX_HTTP_UPSTREAM_IGN_XA_EXPIRES 0x00000004
-#define NGX_HTTP_UPSTREAM_IGN_EXPIRES 0x00000008
-#define NGX_HTTP_UPSTREAM_IGN_CACHE_CONTROL 0x00000010
-#define NGX_HTTP_UPSTREAM_IGN_SET_COOKIE 0x00000020
-#define NGX_HTTP_UPSTREAM_IGN_XA_LIMIT_RATE 0x00000040
-#define NGX_HTTP_UPSTREAM_IGN_XA_BUFFERING 0x00000080
-#define NGX_HTTP_UPSTREAM_IGN_XA_CHARSET 0x00000100
-#define NGX_HTTP_UPSTREAM_IGN_VARY 0x00000200
-
-
-#define NGX_HTTP_UPSTREAM_NOTIFY_HEADER 0x1
-
-
-typedef struct {
- ngx_uint_t status;
- ngx_msec_t response_time;
- ngx_msec_t connect_time;
- ngx_msec_t header_time;
- ngx_msec_t queue_time;
- off_t response_length;
- off_t bytes_received;
- off_t bytes_sent;
-
- ngx_str_t *peer;
-} ngx_http_upstream_state_t;
-
-
-typedef struct {
- ngx_hash_t headers_in_hash;
- ngx_array_t upstreams;
- /* ngx_http_upstream_srv_conf_t */
-} ngx_http_upstream_main_conf_t;
-
-typedef struct ngx_http_upstream_srv_conf_s ngx_http_upstream_srv_conf_t;
-
-typedef ngx_int_t (*ngx_http_upstream_init_pt)(ngx_conf_t *cf,
- ngx_http_upstream_srv_conf_t *us);
-typedef ngx_int_t (*ngx_http_upstream_init_peer_pt)(ngx_http_request_t *r,
- ngx_http_upstream_srv_conf_t *us);
-
-
-typedef struct {
- ngx_http_upstream_init_pt init_upstream;
- ngx_http_upstream_init_peer_pt init;
- void *data;
-} ngx_http_upstream_peer_t;
-
-
-typedef struct {
- ngx_str_t name;
- ngx_addr_t *addrs;
- ngx_uint_t naddrs;
- ngx_uint_t weight;
- ngx_uint_t max_conns;
- ngx_uint_t max_fails;
- time_t fail_timeout;
- ngx_msec_t slow_start;
- ngx_uint_t down;
-
- unsigned backup:1;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- ngx_str_t host;
- ngx_str_t service;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID || NGX_COMPAT)
- ngx_str_t sid;
-#endif
-} ngx_http_upstream_server_t;
-
-
-#define NGX_HTTP_UPSTREAM_CREATE 0x0001
-#define NGX_HTTP_UPSTREAM_WEIGHT 0x0002
-#define NGX_HTTP_UPSTREAM_MAX_FAILS 0x0004
-#define NGX_HTTP_UPSTREAM_FAIL_TIMEOUT 0x0008
-#define NGX_HTTP_UPSTREAM_DOWN 0x0010
-#define NGX_HTTP_UPSTREAM_BACKUP 0x0020
-#define NGX_HTTP_UPSTREAM_MODIFY 0x0040
-#define NGX_HTTP_UPSTREAM_MAX_CONNS 0x0100
-
-
-struct ngx_http_upstream_srv_conf_s {
- ngx_http_upstream_peer_t peer;
- void **srv_conf;
-
- ngx_array_t *servers; /* ngx_http_upstream_server_t */
-
- ngx_uint_t flags;
- ngx_str_t host;
- u_char *file_name;
- ngx_uint_t line;
- in_port_t port;
- ngx_uint_t no_port; /* unsigned no_port:1 */
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- ngx_shm_zone_t *shm_zone;
- ngx_resolver_t *resolver;
- ngx_msec_t resolver_timeout;
-#endif
-};
-
-
-typedef struct {
- ngx_addr_t *addr;
- ngx_http_complex_value_t *value;
-#if (NGX_HAVE_TRANSPARENT_PROXY)
- ngx_uint_t transparent; /* unsigned transparent:1; */
-#endif
-} ngx_http_upstream_local_t;
-
-
-typedef struct {
- ngx_http_upstream_srv_conf_t *upstream;
-
- ngx_msec_t connect_timeout;
- ngx_msec_t send_timeout;
- ngx_msec_t read_timeout;
- ngx_msec_t next_upstream_timeout;
-
- size_t send_lowat;
- size_t buffer_size;
- ngx_http_complex_value_t *limit_rate;
-
- size_t busy_buffers_size;
- size_t max_temp_file_size;
- size_t temp_file_write_size;
-
- size_t busy_buffers_size_conf;
- size_t max_temp_file_size_conf;
- size_t temp_file_write_size_conf;
-
- ngx_bufs_t bufs;
-
- ngx_uint_t ignore_headers;
- ngx_uint_t next_upstream;
- ngx_uint_t store_access;
- ngx_uint_t next_upstream_tries;
- ngx_flag_t buffering;
- ngx_flag_t request_buffering;
- ngx_flag_t pass_request_headers;
- ngx_flag_t pass_request_body;
- ngx_flag_t pass_trailers;
- ngx_flag_t pass_early_hints;
-
- ngx_flag_t ignore_client_abort;
- ngx_flag_t intercept_errors;
- ngx_flag_t cyclic_temp_file;
- ngx_flag_t force_ranges;
-
- ngx_path_t *temp_path;
-
- ngx_hash_t hide_headers_hash;
- ngx_array_t *hide_headers;
- ngx_array_t *pass_headers;
-
- ngx_http_upstream_local_t *local;
- ngx_flag_t socket_keepalive;
-
-#if (NGX_HTTP_CACHE)
- ngx_shm_zone_t *cache_zone;
- ngx_http_complex_value_t *cache_value;
-
- ngx_uint_t cache_min_uses;
- ngx_uint_t cache_use_stale;
- ngx_uint_t cache_methods;
-
- off_t cache_max_range_offset;
-
- ngx_flag_t cache_lock;
- ngx_msec_t cache_lock_timeout;
- ngx_msec_t cache_lock_age;
-
- ngx_flag_t cache_revalidate;
- ngx_flag_t cache_convert_head;
- ngx_flag_t cache_background_update;
-
- ngx_array_t *cache_valid;
- ngx_array_t *cache_bypass;
- ngx_array_t *cache_purge;
- ngx_array_t *no_cache;
-#endif
-
- ngx_array_t *store_lengths;
- ngx_array_t *store_values;
-
-#if (NGX_HTTP_CACHE)
- signed cache:2;
-#endif
- signed store:2;
- unsigned intercept_404:1;
- unsigned change_buffering:1;
- unsigned preserve_output:1;
-
-#if (NGX_HTTP_SSL || NGX_COMPAT)
- ngx_ssl_t *ssl;
- ngx_flag_t ssl_session_reuse;
-
- ngx_http_complex_value_t *ssl_name;
- ngx_flag_t ssl_server_name;
- ngx_flag_t ssl_verify;
-
- ngx_http_complex_value_t *ssl_certificate;
- ngx_http_complex_value_t *ssl_certificate_key;
- ngx_ssl_cache_t *ssl_certificate_cache;
- ngx_array_t *ssl_passwords;
-#endif
-
- ngx_str_t module;
-
- NGX_COMPAT_BEGIN(6)
- NGX_COMPAT_END
-} ngx_http_upstream_conf_t;
-
-
-typedef struct {
- ngx_str_t name;
- ngx_http_header_handler_pt handler;
- ngx_uint_t offset;
- ngx_http_header_handler_pt copy_handler;
- ngx_uint_t conf;
- ngx_uint_t redirect; /* unsigned redirect:1; */
-} ngx_http_upstream_header_t;
-
-
-typedef struct {
- ngx_list_t headers;
- ngx_list_t trailers;
-
- ngx_uint_t status_n;
- ngx_str_t status_line;
-
- ngx_table_elt_t *status;
- ngx_table_elt_t *date;
- ngx_table_elt_t *server;
- ngx_table_elt_t *connection;
-
- ngx_table_elt_t *expires;
- ngx_table_elt_t *etag;
- ngx_table_elt_t *x_accel_expires;
- ngx_table_elt_t *x_accel_redirect;
- ngx_table_elt_t *x_accel_limit_rate;
-
- ngx_table_elt_t *content_type;
- ngx_table_elt_t *content_length;
-
- ngx_table_elt_t *last_modified;
- ngx_table_elt_t *location;
- ngx_table_elt_t *refresh;
- ngx_table_elt_t *www_authenticate;
- ngx_table_elt_t *transfer_encoding;
- ngx_table_elt_t *vary;
-
- ngx_table_elt_t *cache_control;
- ngx_table_elt_t *set_cookie;
-
- off_t content_length_n;
- time_t last_modified_time;
-
- unsigned connection_close:1;
- unsigned chunked:1;
- unsigned no_cache:1;
- unsigned expired:1;
-} ngx_http_upstream_headers_in_t;
-
-
-typedef struct {
- ngx_str_t host;
- in_port_t port;
- ngx_uint_t no_port; /* unsigned no_port:1 */
-
- ngx_uint_t naddrs;
- ngx_resolver_addr_t *addrs;
-
- struct sockaddr *sockaddr;
- socklen_t socklen;
- ngx_str_t name;
-
- ngx_resolver_ctx_t *ctx;
-} ngx_http_upstream_resolved_t;
-
-
-typedef void (*ngx_http_upstream_handler_pt)(ngx_http_request_t *r,
- ngx_http_upstream_t *u);
-
-
-struct ngx_http_upstream_s {
- ngx_http_upstream_handler_pt read_event_handler;
- ngx_http_upstream_handler_pt write_event_handler;
-
- ngx_peer_connection_t peer;
-
- ngx_event_pipe_t *pipe;
-
- ngx_chain_t *request_bufs;
-
- ngx_output_chain_ctx_t output;
- ngx_chain_writer_ctx_t writer;
-
- ngx_http_upstream_conf_t *conf;
- ngx_http_upstream_srv_conf_t *upstream;
-#if (NGX_HTTP_CACHE)
- ngx_array_t *caches;
-#endif
-
- ngx_http_upstream_headers_in_t headers_in;
-
- ngx_http_upstream_resolved_t *resolved;
-
- ngx_buf_t from_client;
-
- ngx_buf_t buffer;
- off_t length;
- off_t early_hints_length;
-
- ngx_chain_t *out_bufs;
- ngx_chain_t *busy_bufs;
- ngx_chain_t *free_bufs;
-
- ngx_int_t (*input_filter_init)(void *data);
- ngx_int_t (*input_filter)(void *data, ssize_t bytes);
- void *input_filter_ctx;
-
-#if (NGX_HTTP_CACHE)
- ngx_int_t (*create_key)(ngx_http_request_t *r);
-#endif
- ngx_int_t (*create_request)(ngx_http_request_t *r);
- ngx_int_t (*reinit_request)(ngx_http_request_t *r);
- ngx_int_t (*process_header)(ngx_http_request_t *r);
- void (*abort_request)(ngx_http_request_t *r);
- void (*finalize_request)(ngx_http_request_t *r,
- ngx_int_t rc);
- ngx_int_t (*rewrite_redirect)(ngx_http_request_t *r,
- ngx_table_elt_t *h, size_t prefix);
- ngx_int_t (*rewrite_cookie)(ngx_http_request_t *r,
- ngx_table_elt_t *h);
-
- ngx_msec_t start_time;
-
- ngx_http_upstream_state_t *state;
-
- ngx_str_t method;
- ngx_str_t schema;
- ngx_str_t uri;
-
-#if (NGX_HTTP_SSL || NGX_COMPAT)
- ngx_str_t ssl_name;
- ngx_str_t ssl_alpn_protocol;
-#endif
-
- ngx_http_cleanup_pt *cleanup;
-
- unsigned store:1;
- unsigned cacheable:1;
- unsigned accel:1;
- unsigned ssl:1;
-#if (NGX_HTTP_CACHE)
- unsigned cache_status:3;
-#endif
-
- unsigned buffering:1;
- unsigned keepalive:1;
- unsigned upgrade:1;
- unsigned error:1;
-
- unsigned request_sent:1;
- unsigned request_body_sent:1;
- unsigned request_body_blocked:1;
- unsigned header_sent:1;
- unsigned response_received:1;
-};
-
-
-typedef struct {
- ngx_uint_t status;
- ngx_uint_t mask;
-} ngx_http_upstream_next_t;
-
-
-typedef struct {
- ngx_str_t key;
- ngx_str_t value;
- ngx_uint_t skip_empty;
-} ngx_http_upstream_param_t;
-
-
-ngx_int_t ngx_http_upstream_create(ngx_http_request_t *r);
-void ngx_http_upstream_init(ngx_http_request_t *r);
-ngx_int_t ngx_http_upstream_non_buffered_filter_init(void *data);
-ngx_int_t ngx_http_upstream_non_buffered_filter(void *data, ssize_t bytes);
-ngx_http_upstream_srv_conf_t *ngx_http_upstream_add(ngx_conf_t *cf,
- ngx_url_t *u, ngx_uint_t flags);
-char *ngx_http_upstream_bind_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-char *ngx_http_upstream_param_set_slot(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-ngx_int_t ngx_http_upstream_hide_headers_hash(ngx_conf_t *cf,
- ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev,
- ngx_str_t *default_hide_headers, ngx_hash_init_t *hash);
-#if (NGX_HTTP_SSL)
-ngx_int_t ngx_http_upstream_merge_ssl_passwords(ngx_conf_t *cf,
- ngx_http_upstream_conf_t *conf, ngx_http_upstream_conf_t *prev);
-#endif
-
-
-#define ngx_http_conf_upstream_srv_conf(uscf, module) \
- uscf->srv_conf[module.ctx_index]
-
-
-extern ngx_module_t ngx_http_upstream_module;
-extern ngx_conf_bitmask_t ngx_http_upstream_cache_method_mask[];
-extern ngx_conf_bitmask_t ngx_http_upstream_ignore_headers_masks[];
-
-
-#endif /* _NGX_HTTP_UPSTREAM_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.c b/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.c
deleted file mode 100644
index 4122817672..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.c
+++ /dev/null
@@ -1,1267 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-#define ngx_http_upstream_tries(p) ((p)->tries \
- + ((p)->next ? (p)->next->tries : 0))
-
-
-#if (NGX_HTTP_UPSTREAM_SID)
-static ngx_int_t ngx_http_upstream_create_sid(ngx_conf_t *cf,
- ngx_http_upstream_rr_peer_t *peer, ngx_str_t *route);
-#endif
-
-static ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_peer(
- ngx_http_upstream_rr_peer_data_t *rrp, ngx_peer_connection_t *pc);
-
-#if (NGX_HTTP_SSL)
-
-static ngx_int_t ngx_http_upstream_empty_set_session(ngx_peer_connection_t *pc,
- void *data);
-static void ngx_http_upstream_empty_save_session(ngx_peer_connection_t *pc,
- void *data);
-
-#endif
-
-
-ngx_int_t
-ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
- ngx_http_upstream_srv_conf_t *us)
-{
- ngx_url_t u;
- ngx_uint_t i, j, n, r, w, t;
- ngx_http_upstream_server_t *server;
- ngx_http_upstream_rr_peer_t *peer, **peerp;
- ngx_http_upstream_rr_peers_t *peers, *backup;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- ngx_uint_t resolve;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_upstream_rr_peer_t **rpeerp;
-#endif
-
- us->peer.init = ngx_http_upstream_init_round_robin_peer;
-
- if (us->servers) {
- server = us->servers->elts;
-
- n = 0;
- r = 0;
- w = 0;
- t = 0;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- resolve = 0;
-#endif
-
- for (i = 0; i < us->servers->nelts; i++) {
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (server[i].host.len) {
- resolve = 1;
- }
-#endif
-
- if (server[i].backup) {
- continue;
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (server[i].host.len) {
- r++;
- continue;
- }
-#endif
-
- n += server[i].naddrs;
- w += server[i].naddrs * server[i].weight;
-
- if (!server[i].down) {
- t += server[i].naddrs;
- }
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (us->shm_zone) {
-
- if (resolve && !(us->flags & NGX_HTTP_UPSTREAM_MODIFY)) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "load balancing method does not support"
- " resolving names at run time in"
- " upstream \"%V\" in %s:%ui",
- &us->host, us->file_name, us->line);
- return NGX_ERROR;
- }
-
- clcf = ngx_http_conf_get_module_loc_conf(cf, ngx_http_core_module);
-
- if (us->resolver == NULL) {
- us->resolver = clcf->resolver;
- }
-
- /*
- * Without "resolver_timeout" in http{} the merged value is unset.
- */
- ngx_conf_merge_msec_value(us->resolver_timeout,
- clcf->resolver_timeout, 30000);
-
- if (resolve
- && (us->resolver == NULL
- || us->resolver->connections.nelts == 0))
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no resolver defined to resolve names"
- " at run time in upstream \"%V\" in %s:%ui",
- &us->host, us->file_name, us->line);
- return NGX_ERROR;
- }
-
- } else if (resolve) {
-
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "resolving names at run time requires"
- " upstream \"%V\" in %s:%ui"
- " to be in shared memory",
- &us->host, us->file_name, us->line);
- return NGX_ERROR;
- }
-#endif
-
- if (n + r == 0) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no servers in upstream \"%V\" in %s:%ui",
- &us->host, us->file_name, us->line);
- return NGX_ERROR;
- }
-
- peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
- if (peers == NULL) {
- return NGX_ERROR;
- }
-
- peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t)
- * (n + r));
- if (peer == NULL) {
- return NGX_ERROR;
- }
-
- peers->single = (n == 1);
- peers->number = n;
- peers->weighted = (w != n);
- peers->total_weight = w;
- peers->tries = t;
- peers->name = &us->host;
-
- n = 0;
- peerp = &peers->peer;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- rpeerp = &peers->resolve;
-#endif
-
- for (i = 0; i < us->servers->nelts; i++) {
- if (server[i].backup) {
- continue;
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (server[i].host.len) {
-
- peer[n].host = ngx_pcalloc(cf->pool,
- sizeof(ngx_http_upstream_host_t));
- if (peer[n].host == NULL) {
- return NGX_ERROR;
- }
-
- peer[n].host->name = server[i].host;
- peer[n].host->service = server[i].service;
-
- peer[n].sockaddr = server[i].addrs[0].sockaddr;
- peer[n].socklen = server[i].addrs[0].socklen;
- peer[n].name = server[i].addrs[0].name;
- peer[n].weight = server[i].weight;
- peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
- peer[n].max_conns = server[i].max_conns;
- peer[n].max_fails = server[i].max_fails;
- peer[n].fail_timeout = server[i].fail_timeout;
- peer[n].down = server[i].down;
- peer[n].server = server[i].name;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- if (ngx_http_upstream_create_sid(cf, &peer[n], &server[i].sid)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-#endif
-
- *rpeerp = &peer[n];
- rpeerp = &peer[n].next;
- n++;
-
- continue;
- }
-#endif
-
- for (j = 0; j < server[i].naddrs; j++) {
- peer[n].sockaddr = server[i].addrs[j].sockaddr;
- peer[n].socklen = server[i].addrs[j].socklen;
- peer[n].name = server[i].addrs[j].name;
- peer[n].weight = server[i].weight;
- peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
- peer[n].max_conns = server[i].max_conns;
- peer[n].max_fails = server[i].max_fails;
- peer[n].fail_timeout = server[i].fail_timeout;
- peer[n].down = server[i].down;
- peer[n].server = server[i].name;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- if (ngx_http_upstream_create_sid(cf, &peer[n], &server[i].sid)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-#endif
-
- *peerp = &peer[n];
- peerp = &peer[n].next;
- n++;
- }
- }
-
- us->peer.data = peers;
-
- /* backup servers */
-
- n = 0;
- r = 0;
- w = 0;
- t = 0;
-
- for (i = 0; i < us->servers->nelts; i++) {
- if (!server[i].backup) {
- continue;
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (server[i].host.len) {
- r++;
- continue;
- }
-#endif
-
- n += server[i].naddrs;
- w += server[i].naddrs * server[i].weight;
-
- if (!server[i].down) {
- t += server[i].naddrs;
- }
- }
-
- if (n == 0
-#if (NGX_HTTP_UPSTREAM_ZONE)
- && !resolve
-#endif
- ) {
- return NGX_OK;
- }
-
- if (n + r == 0 && !(us->flags & NGX_HTTP_UPSTREAM_BACKUP)) {
- return NGX_OK;
- }
-
- backup = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
- if (backup == NULL) {
- return NGX_ERROR;
- }
-
- peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t)
- * (n + r));
- if (peer == NULL) {
- return NGX_ERROR;
- }
-
- if (n > 0) {
- peers->single = 0;
- }
-
- backup->single = 0;
- backup->number = n;
- backup->weighted = (w != n);
- backup->total_weight = w;
- backup->tries = t;
- backup->name = &us->host;
-
- n = 0;
- peerp = &backup->peer;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- rpeerp = &backup->resolve;
-#endif
-
- for (i = 0; i < us->servers->nelts; i++) {
- if (!server[i].backup) {
- continue;
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (server[i].host.len) {
-
- peer[n].host = ngx_pcalloc(cf->pool,
- sizeof(ngx_http_upstream_host_t));
- if (peer[n].host == NULL) {
- return NGX_ERROR;
- }
-
- peer[n].host->name = server[i].host;
- peer[n].host->service = server[i].service;
-
- peer[n].sockaddr = server[i].addrs[0].sockaddr;
- peer[n].socklen = server[i].addrs[0].socklen;
- peer[n].name = server[i].addrs[0].name;
- peer[n].weight = server[i].weight;
- peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
- peer[n].max_conns = server[i].max_conns;
- peer[n].max_fails = server[i].max_fails;
- peer[n].fail_timeout = server[i].fail_timeout;
- peer[n].down = server[i].down;
- peer[n].server = server[i].name;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- if (ngx_http_upstream_create_sid(cf, &peer[n], &server[i].sid)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-#endif
-
- *rpeerp = &peer[n];
- rpeerp = &peer[n].next;
- n++;
-
- continue;
- }
-#endif
-
- for (j = 0; j < server[i].naddrs; j++) {
- peer[n].sockaddr = server[i].addrs[j].sockaddr;
- peer[n].socklen = server[i].addrs[j].socklen;
- peer[n].name = server[i].addrs[j].name;
- peer[n].weight = server[i].weight;
- peer[n].effective_weight = server[i].weight;
- peer[n].current_weight = 0;
- peer[n].max_conns = server[i].max_conns;
- peer[n].max_fails = server[i].max_fails;
- peer[n].fail_timeout = server[i].fail_timeout;
- peer[n].down = server[i].down;
- peer[n].server = server[i].name;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- if (ngx_http_upstream_create_sid(cf, &peer[n], &server[i].sid)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-#endif
-
- *peerp = &peer[n];
- peerp = &peer[n].next;
- n++;
- }
- }
-
- peers->next = backup;
-
- return NGX_OK;
- }
-
-
- /* an upstream implicitly defined by proxy_pass, etc. */
-
- if (us->port == 0) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no port in upstream \"%V\" in %s:%ui",
- &us->host, us->file_name, us->line);
- return NGX_ERROR;
- }
-
- ngx_memzero(&u, sizeof(ngx_url_t));
-
- u.host = us->host;
- u.port = us->port;
-
- if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
- if (u.err) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "%s in upstream \"%V\" in %s:%ui",
- u.err, &us->host, us->file_name, us->line);
- }
-
- return NGX_ERROR;
- }
-
- n = u.naddrs;
-
- peers = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peers_t));
- if (peers == NULL) {
- return NGX_ERROR;
- }
-
- peer = ngx_pcalloc(cf->pool, sizeof(ngx_http_upstream_rr_peer_t) * n);
- if (peer == NULL) {
- return NGX_ERROR;
- }
-
- peers->single = (n == 1);
- peers->number = n;
- peers->weighted = 0;
- peers->total_weight = n;
- peers->tries = n;
- peers->name = &us->host;
-
- peerp = &peers->peer;
-
- for (i = 0; i < u.naddrs; i++) {
- peer[i].sockaddr = u.addrs[i].sockaddr;
- peer[i].socklen = u.addrs[i].socklen;
- peer[i].name = u.addrs[i].name;
- peer[i].weight = 1;
- peer[i].effective_weight = 1;
- peer[i].current_weight = 0;
- peer[i].max_conns = 0;
- peer[i].max_fails = 1;
- peer[i].fail_timeout = 10;
- *peerp = &peer[i];
- peerp = &peer[i].next;
- }
-
- us->peer.data = peers;
-
- /* implicitly defined upstream has no backup servers */
-
- return NGX_OK;
-}
-
-
-#if (NGX_HTTP_UPSTREAM_SID)
-
-static ngx_int_t
-ngx_http_upstream_create_sid(ngx_conf_t *cf, ngx_http_upstream_rr_peer_t *peer,
- ngx_str_t *route)
-{
- if (route->len) {
- peer->route = 1;
- peer->sid = *route;
- return NGX_OK;
- }
-
- peer->sid.data = ngx_pnalloc(cf->pool, NGX_HTTP_UPSTREAM_SID_LEN);
- if (peer->sid.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_http_upstream_init_round_robin_sid(peer, NULL);
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_upstream_init_round_robin_sid(ngx_http_upstream_rr_peer_t *peer,
- ngx_str_t *route)
-{
- u_char hash[16];
- ngx_md5_t md5;
-
- if (route && route->len) {
- peer->route = 1;
- peer->sid.len = route->len;
- ngx_memcpy(peer->sid.data, route->data, route->len);
- return;
- }
-
- peer->route = 0;
-
- /* SID is the MD5 hash of a printable socket address */
-
- if (peer->name.len == 0) {
- peer->sid.len = 0;
- return;
- }
-
- ngx_md5_init(&md5);
- ngx_md5_update(&md5, peer->name.data, peer->name.len);
- ngx_md5_final(hash, &md5);
-
- ngx_hex_dump(peer->sid.data, hash, 16);
- peer->sid.len = NGX_HTTP_UPSTREAM_SID_LEN;
-}
-
-#endif
-
-
-ngx_int_t
-ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
- ngx_http_upstream_srv_conf_t *us)
-{
- ngx_uint_t n;
- ngx_http_upstream_rr_peer_data_t *rrp;
-
- rrp = r->upstream->peer.data;
-
- if (rrp == NULL) {
- rrp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_rr_peer_data_t));
- if (rrp == NULL) {
- return NGX_ERROR;
- }
-
- r->upstream->peer.data = rrp;
- }
-
- rrp->peers = us->peer.data;
- rrp->current = NULL;
-
- ngx_http_upstream_rr_peers_rlock(rrp->peers);
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- rrp->config = rrp->peers->config ? *rrp->peers->config : 0;
-#endif
-
- n = rrp->peers->number;
-
- if (rrp->peers->next && rrp->peers->next->number > n) {
- n = rrp->peers->next->number;
- }
-
- r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers);
-
- ngx_http_upstream_rr_peers_unlock(rrp->peers);
-
- if (n <= 8 * sizeof(uintptr_t)) {
- rrp->tried = &rrp->data;
- rrp->data = 0;
-
- } else {
- n = (n + (8 * sizeof(uintptr_t) - 1)) / (8 * sizeof(uintptr_t));
-
- rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t));
- if (rrp->tried == NULL) {
- return NGX_ERROR;
- }
- }
-
- r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer;
- r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer;
-#if (NGX_HTTP_SSL)
- r->upstream->peer.set_session =
- ngx_http_upstream_set_round_robin_peer_session;
- r->upstream->peer.save_session =
- ngx_http_upstream_save_round_robin_peer_session;
-#endif
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
- ngx_http_upstream_resolved_t *ur)
-{
- u_char *p;
- size_t len;
- socklen_t socklen;
- ngx_uint_t i, n;
- struct sockaddr *sockaddr;
- ngx_http_upstream_rr_peer_t *peer, **peerp;
- ngx_http_upstream_rr_peers_t *peers;
- ngx_http_upstream_rr_peer_data_t *rrp;
-
- rrp = r->upstream->peer.data;
-
- if (rrp == NULL) {
- rrp = ngx_palloc(r->pool, sizeof(ngx_http_upstream_rr_peer_data_t));
- if (rrp == NULL) {
- return NGX_ERROR;
- }
-
- r->upstream->peer.data = rrp;
- }
-
- peers = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peers_t));
- if (peers == NULL) {
- return NGX_ERROR;
- }
-
- peer = ngx_pcalloc(r->pool, sizeof(ngx_http_upstream_rr_peer_t)
- * ur->naddrs);
- if (peer == NULL) {
- return NGX_ERROR;
- }
-
- peers->single = (ur->naddrs == 1);
- peers->number = ur->naddrs;
- peers->tries = ur->naddrs;
- peers->name = &ur->host;
-
- if (ur->sockaddr) {
- peer[0].sockaddr = ur->sockaddr;
- peer[0].socklen = ur->socklen;
- peer[0].name = ur->name.data ? ur->name : ur->host;
- peer[0].weight = 1;
- peer[0].effective_weight = 1;
- peer[0].current_weight = 0;
- peer[0].max_conns = 0;
- peer[0].max_fails = 1;
- peer[0].fail_timeout = 10;
- peers->peer = peer;
-
- } else {
- peerp = &peers->peer;
-
- for (i = 0; i < ur->naddrs; i++) {
-
- socklen = ur->addrs[i].socklen;
-
- sockaddr = ngx_palloc(r->pool, socklen);
- if (sockaddr == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(sockaddr, ur->addrs[i].sockaddr, socklen);
- ngx_inet_set_port(sockaddr, ur->port);
-
- p = ngx_pnalloc(r->pool, NGX_SOCKADDR_STRLEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- len = ngx_sock_ntop(sockaddr, socklen, p, NGX_SOCKADDR_STRLEN, 1);
-
- peer[i].sockaddr = sockaddr;
- peer[i].socklen = socklen;
- peer[i].name.len = len;
- peer[i].name.data = p;
- peer[i].weight = 1;
- peer[i].effective_weight = 1;
- peer[i].current_weight = 0;
- peer[i].max_conns = 0;
- peer[i].max_fails = 1;
- peer[i].fail_timeout = 10;
- *peerp = &peer[i];
- peerp = &peer[i].next;
- }
- }
-
- rrp->peers = peers;
- rrp->current = NULL;
- rrp->config = 0;
-
- if (rrp->peers->number <= 8 * sizeof(uintptr_t)) {
- rrp->tried = &rrp->data;
- rrp->data = 0;
-
- } else {
- n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
- / (8 * sizeof(uintptr_t));
-
- rrp->tried = ngx_pcalloc(r->pool, n * sizeof(uintptr_t));
- if (rrp->tried == NULL) {
- return NGX_ERROR;
- }
- }
-
- r->upstream->peer.get = ngx_http_upstream_get_round_robin_peer;
- r->upstream->peer.free = ngx_http_upstream_free_round_robin_peer;
- r->upstream->peer.tries = ngx_http_upstream_tries(rrp->peers);
-#if (NGX_HTTP_SSL)
- r->upstream->peer.set_session = ngx_http_upstream_empty_set_session;
- r->upstream->peer.save_session = ngx_http_upstream_empty_save_session;
-#endif
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
-{
- ngx_http_upstream_rr_peer_data_t *rrp = data;
-
- ngx_int_t rc;
- ngx_uint_t i, n;
- ngx_http_upstream_rr_peer_t *peer;
- ngx_http_upstream_rr_peers_t *peers;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "get rr peer, try: %ui", pc->tries);
-
- pc->cached = 0;
- pc->connection = NULL;
-
- peers = rrp->peers;
- ngx_http_upstream_rr_peers_wlock(peers);
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- if (peers->config && rrp->config != *peers->config) {
- goto busy;
- }
-#endif
-
- if (peers->single) {
-#if (NGX_HTTP_UPSTREAM_SID)
- peer = ngx_http_upstream_get_rr_peer_by_sid(rrp, pc->hint, &i, 0);
-
- if (peer == NULL) {
-#endif
- peer = peers->peer;
-
- if (peer->down) {
- goto failed;
- }
-
- if (peer->max_conns && peer->conns >= peer->max_conns) {
- goto failed;
- }
-#if (NGX_HTTP_UPSTREAM_SID)
- }
-#endif
-
- rrp->current = peer;
- ngx_http_upstream_rr_peer_ref(peers, peer);
-
- } else {
-
- /* there are several peers */
-
- peer = ngx_http_upstream_get_peer(rrp, pc);
-
- if (peer == NULL) {
- goto failed;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "get rr peer, current: %p %i",
- peer, peer->current_weight);
- }
-
- pc->sockaddr = peer->sockaddr;
- pc->socklen = peer->socklen;
- pc->name = &peer->name;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- pc->sid = &peer->sid;
-#endif
-
- peer->conns++;
-
- ngx_http_upstream_rr_peers_unlock(peers);
-
- return NGX_OK;
-
-failed:
-
- if (peers->next) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0, "backup servers");
-
- rrp->peers = peers->next;
-
- n = (rrp->peers->number + (8 * sizeof(uintptr_t) - 1))
- / (8 * sizeof(uintptr_t));
-
- for (i = 0; i < n; i++) {
- rrp->tried[i] = 0;
- }
-
- ngx_http_upstream_rr_peers_unlock(peers);
-
- rc = ngx_http_upstream_get_round_robin_peer(pc, rrp);
-
- if (rc != NGX_BUSY) {
- return rc;
- }
-
- ngx_http_upstream_rr_peers_wlock(peers);
- }
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-busy:
-#endif
-
- ngx_http_upstream_rr_peers_unlock(peers);
-
- pc->name = peers->name;
-
- return NGX_BUSY;
-}
-
-
-static ngx_http_upstream_rr_peer_t *
-ngx_http_upstream_get_peer(ngx_http_upstream_rr_peer_data_t *rrp,
- ngx_peer_connection_t *pc)
-{
- time_t now;
- uintptr_t m;
- ngx_int_t total;
- ngx_uint_t i, n, p;
- ngx_http_upstream_rr_peer_t *peer, *best;
-
-#if (NGX_HTTP_UPSTREAM_SID)
- ngx_int_t low_limit;
- ngx_uint_t st_p;
- ngx_http_upstream_rr_peer_t *st_peer;
-#endif
-
- now = ngx_time();
-
- best = NULL;
- total = 0;
-
-#if (NGX_SUPPRESS_WARN)
- p = 0;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID)
- st_peer = ngx_http_upstream_get_rr_peer_by_sid(rrp, pc->hint, &p, 0);
-
- if (st_peer) {
-
- low_limit = -((ngx_int_t)(rrp->peers->total_weight - st_peer->weight));
-
- /*
- * note: current code accounts only one sticky request in a row, if it
- * is required to account more, multiply low_limit by N below
- */
- if (st_peer->current_weight <= low_limit) {
-
- /* do not update weights if the limit exceeded */
- best = st_peer;
- goto best_chosen;
- }
- /* else: proceed to reweight with existing st_peer */
- }
-
- st_p = p;
-#endif
-
- for (peer = rrp->peers->peer, i = 0;
- peer;
- peer = peer->next, i++)
- {
- n = i / (8 * sizeof(uintptr_t));
- m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
-
- if (rrp->tried[n] & m) {
- continue;
- }
-
- if (peer->down) {
- continue;
- }
-
- if (peer->max_fails
- && peer->fails >= peer->max_fails
- && now - peer->checked <= peer->fail_timeout)
- {
- continue;
- }
-
- if (peer->max_conns && peer->conns >= peer->max_conns) {
- continue;
- }
-
- peer->current_weight += peer->effective_weight;
- total += peer->effective_weight;
-
- if (peer->effective_weight < peer->weight) {
- peer->effective_weight++;
- }
-
- if (best == NULL || peer->current_weight > best->current_weight) {
- best = peer;
- p = i;
- }
- }
-
-#if (NGX_HTTP_UPSTREAM_SID)
- /* prefer peer chosen by sticky to best from RR */
-
- if (st_peer) {
- best = st_peer;
- p = st_p;
- }
-#endif
-
- if (best == NULL) {
- return NULL;
- }
-
- best->current_weight -= total;
-
-#if (NGX_HTTP_UPSTREAM_SID)
-best_chosen:
-#endif
-
- rrp->current = best;
- ngx_http_upstream_rr_peer_ref(rrp->peers, best);
-
- n = p / (8 * sizeof(uintptr_t));
- m = (uintptr_t) 1 << p % (8 * sizeof(uintptr_t));
-
- rrp->tried[n] |= m;
-
- if (now - best->checked > best->fail_timeout) {
- best->checked = now;
- }
-
- return best;
-}
-
-
-#if (NGX_HTTP_UPSTREAM_SID)
-
-ngx_http_upstream_rr_peer_t *
-ngx_http_upstream_get_rr_peer_by_sid(ngx_http_upstream_rr_peer_data_t *rrp,
- ngx_str_t *hint, ngx_uint_t *p, ngx_uint_t lock)
-{
- uintptr_t m;
- ngx_uint_t i, n;
- ngx_http_upstream_rr_peer_t *peer;
-
- if (hint == NULL) {
- return NULL;
- }
-
- for (peer = rrp->peers->peer, i = 0;
- peer;
- peer = peer->next, i++)
- {
-
- if (peer->sid.len == hint->len
- && ngx_memcmp(peer->sid.data, hint->data, hint->len) == 0)
- {
- goto found;
- }
- }
-
- return NULL;
-
-found:
-
- n = i / (8 * sizeof(uintptr_t));
- m = (uintptr_t) 1 << i % (8 * sizeof(uintptr_t));
-
- if (rrp->tried[n] & m) {
- return NULL;
- }
-
- if (lock) {
- ngx_http_upstream_rr_peer_lock(rrp->peers, peer);
- }
-
- if (peer->down
-#if (NGX_HTTP_UPSTREAM_STICKY)
- & ~NGX_HTTP_UPSTREAM_DRAINING
-#endif
- ) {
- goto failed;
- }
-
- if (peer->max_fails
- && peer->fails >= peer->max_fails
- && ngx_time() - peer->checked <= peer->fail_timeout)
- {
- goto failed;
- }
-
- if (peer->max_conns && peer->conns >= peer->max_conns) {
- goto failed;
- }
-
- *p = i;
- return peer;
-
-failed:
-
- if (lock) {
- ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
- }
-
- return NULL;
-}
-
-#endif
-
-
-void
-ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc, void *data,
- ngx_uint_t state)
-{
- ngx_http_upstream_rr_peer_data_t *rrp = data;
-
- time_t now;
- ngx_http_upstream_rr_peer_t *peer;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "free rr peer %ui %ui", pc->tries, state);
-
- /* TODO: NGX_PEER_KEEPALIVE */
-
- peer = rrp->current;
-
- ngx_http_upstream_rr_peers_rlock(rrp->peers);
- ngx_http_upstream_rr_peer_lock(rrp->peers, peer);
-
- if (rrp->peers->single) {
-
- if (peer->fails) {
- peer->fails = 0;
- }
-
- peer->conns--;
-
- if (ngx_http_upstream_rr_peer_unref(rrp->peers, peer) == NGX_OK) {
- ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
- }
-
- ngx_http_upstream_rr_peers_unlock(rrp->peers);
-
- pc->tries = 0;
- return;
- }
-
- if (state & NGX_PEER_FAILED) {
- now = ngx_time();
-
- peer->fails++;
- peer->accessed = now;
- peer->checked = now;
-
- if (peer->max_fails) {
- peer->effective_weight -= peer->weight / peer->max_fails;
-
- if (peer->fails >= peer->max_fails) {
- ngx_log_error(NGX_LOG_WARN, pc->log, 0,
- "upstream server temporarily disabled");
- }
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "free rr peer failed: %p %i",
- peer, peer->effective_weight);
-
- if (peer->effective_weight < 0) {
- peer->effective_weight = 0;
- }
-
- } else {
-
- /* mark peer live if check passed */
-
- if (peer->accessed < peer->checked) {
- peer->fails = 0;
- }
- }
-
- peer->conns--;
-
- if (ngx_http_upstream_rr_peer_unref(rrp->peers, peer) == NGX_OK) {
- ngx_http_upstream_rr_peer_unlock(rrp->peers, peer);
- }
-
- ngx_http_upstream_rr_peers_unlock(rrp->peers);
-
- if (pc->tries) {
- pc->tries--;
- }
-}
-
-
-#if (NGX_HTTP_SSL)
-
-ngx_int_t
-ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
- void *data)
-{
- ngx_http_upstream_rr_peer_data_t *rrp = data;
-
- ngx_int_t rc;
- ngx_ssl_session_t *ssl_session;
- ngx_http_upstream_rr_peer_t *peer;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- int len;
- const u_char *p;
- ngx_http_upstream_rr_peers_t *peers;
-#endif
-
- peer = rrp->current;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- peers = rrp->peers;
-
- if (peers->shpool) {
- ngx_http_upstream_rr_peers_rlock(peers);
- ngx_http_upstream_rr_peer_lock(peers, peer);
-
- if (peer->ssl_session == NULL) {
- ngx_http_upstream_rr_peer_unlock(peers, peer);
- ngx_http_upstream_rr_peers_unlock(peers);
- return NGX_OK;
- }
-
- len = peer->ssl_session_len;
-
- ngx_memcpy(ngx_ssl_session_buffer, peer->ssl_session, len);
-
- ngx_http_upstream_rr_peer_unlock(peers, peer);
- ngx_http_upstream_rr_peers_unlock(peers);
-
- p = ngx_ssl_session_buffer;
- ssl_session = d2i_SSL_SESSION(NULL, &p, len);
-
- rc = ngx_ssl_set_session(pc->connection, ssl_session);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "set session: %p", ssl_session);
-
- ngx_ssl_free_session(ssl_session);
-
- return rc;
- }
-#endif
-
- ssl_session = peer->ssl_session;
-
- rc = ngx_ssl_set_session(pc->connection, ssl_session);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "set session: %p", ssl_session);
-
- return rc;
-}
-
-
-void
-ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
- void *data)
-{
- ngx_http_upstream_rr_peer_data_t *rrp = data;
-
- ngx_ssl_session_t *old_ssl_session, *ssl_session;
- ngx_http_upstream_rr_peer_t *peer;
-#if (NGX_HTTP_UPSTREAM_ZONE)
- int len;
- u_char *p;
- ngx_http_upstream_rr_peers_t *peers;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- peers = rrp->peers;
-
- if (peers->shpool) {
-
- ssl_session = ngx_ssl_get0_session(pc->connection);
-
- if (ssl_session == NULL) {
- return;
- }
-
- len = i2d_SSL_SESSION(ssl_session, NULL);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "save session: %p:%d", ssl_session, len);
-
- /* do not cache too big session */
-
- if (len > NGX_SSL_MAX_SESSION_SIZE) {
- return;
- }
-
- p = ngx_ssl_session_buffer;
- (void) i2d_SSL_SESSION(ssl_session, &p);
-
- peer = rrp->current;
-
- ngx_http_upstream_rr_peers_rlock(peers);
- ngx_http_upstream_rr_peer_lock(peers, peer);
-
- if (len > peer->ssl_session_len) {
- ngx_shmtx_lock(&peers->shpool->mutex);
-
- if (peer->ssl_session) {
- ngx_slab_free_locked(peers->shpool, peer->ssl_session);
- }
-
- peer->ssl_session = ngx_slab_alloc_locked(peers->shpool, len);
-
- ngx_shmtx_unlock(&peers->shpool->mutex);
-
- if (peer->ssl_session == NULL) {
- peer->ssl_session_len = 0;
-
- ngx_http_upstream_rr_peer_unlock(peers, peer);
- ngx_http_upstream_rr_peers_unlock(peers);
- return;
- }
-
- peer->ssl_session_len = len;
- }
-
- ngx_memcpy(peer->ssl_session, ngx_ssl_session_buffer, len);
-
- ngx_http_upstream_rr_peer_unlock(peers, peer);
- ngx_http_upstream_rr_peers_unlock(peers);
-
- return;
- }
-#endif
-
- ssl_session = ngx_ssl_get_session(pc->connection);
-
- if (ssl_session == NULL) {
- return;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "save session: %p", ssl_session);
-
- peer = rrp->current;
-
- old_ssl_session = peer->ssl_session;
- peer->ssl_session = ssl_session;
-
- if (old_ssl_session) {
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, pc->log, 0,
- "old session: %p", old_ssl_session);
-
- ngx_ssl_free_session(old_ssl_session);
- }
-}
-
-
-static ngx_int_t
-ngx_http_upstream_empty_set_session(ngx_peer_connection_t *pc, void *data)
-{
- return NGX_OK;
-}
-
-
-static void
-ngx_http_upstream_empty_save_session(ngx_peer_connection_t *pc, void *data)
-{
- return;
-}
-
-#endif
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.h b/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.h
deleted file mode 100644
index 95c7ae1906..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_upstream_round_robin.h
+++ /dev/null
@@ -1,275 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
-#define _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-#if (NGX_HTTP_UPSTREAM_SID)
-#define NGX_HTTP_UPSTREAM_SID_LEN 32 /* md5 in hex */
-#endif
-
-#define NGX_HTTP_UPSTREAM_FAILED 1
-
-#if (NGX_HTTP_UPSTREAM_STICKY)
-#define NGX_HTTP_UPSTREAM_DRAINING 8
-#endif
-
-
-typedef struct ngx_http_upstream_rr_peers_s ngx_http_upstream_rr_peers_t;
-typedef struct ngx_http_upstream_rr_peer_s ngx_http_upstream_rr_peer_t;
-
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-
-typedef struct {
- ngx_event_t event; /* must be first */
- ngx_uint_t worker;
- ngx_str_t name;
- ngx_str_t service;
- time_t valid;
- ngx_http_upstream_rr_peers_t *peers;
- ngx_http_upstream_rr_peer_t *peer;
-} ngx_http_upstream_host_t;
-
-#endif
-
-
-struct ngx_http_upstream_rr_peer_s {
- struct sockaddr *sockaddr;
- socklen_t socklen;
- ngx_str_t name;
- ngx_str_t server;
-
- ngx_int_t current_weight;
- ngx_int_t effective_weight;
- ngx_int_t weight;
-
- ngx_uint_t conns;
- ngx_uint_t max_conns;
-
- ngx_uint_t fails;
- time_t accessed;
- time_t checked;
-
- ngx_uint_t max_fails;
- time_t fail_timeout;
- ngx_msec_t slow_start;
- ngx_msec_t start_time;
-
- ngx_uint_t down;
-
-#if (NGX_HTTP_SSL || NGX_COMPAT)
- void *ssl_session;
- int ssl_session_len;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID || NGX_COMPAT)
- unsigned route:1;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- unsigned zombie:1;
-
- ngx_atomic_t lock;
- ngx_uint_t refs;
- ngx_http_upstream_host_t *host;
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID || NGX_COMPAT)
- ngx_str_t sid;
-#endif
-
- ngx_http_upstream_rr_peer_t *next;
-
- NGX_COMPAT_BEGIN(13)
- NGX_COMPAT_END
-};
-
-
-struct ngx_http_upstream_rr_peers_s {
- ngx_uint_t number;
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
- ngx_slab_pool_t *shpool;
- ngx_atomic_t rwlock;
- ngx_uint_t *config;
- ngx_http_upstream_rr_peer_t *resolve;
- ngx_http_upstream_rr_peers_t *zone_next;
-#endif
-
- ngx_uint_t total_weight;
- ngx_uint_t tries;
-
- unsigned single:1;
- unsigned weighted:1;
-
- ngx_str_t *name;
-
- ngx_http_upstream_rr_peers_t *next;
-
- ngx_http_upstream_rr_peer_t *peer;
-};
-
-
-#if (NGX_HTTP_UPSTREAM_ZONE)
-
-#define ngx_http_upstream_rr_peers_rlock(peers) \
- \
- if (peers->shpool) { \
- ngx_rwlock_rlock(&peers->rwlock); \
- }
-
-#define ngx_http_upstream_rr_peers_wlock(peers) \
- \
- if (peers->shpool) { \
- ngx_rwlock_wlock(&peers->rwlock); \
- }
-
-#define ngx_http_upstream_rr_peers_unlock(peers) \
- \
- if (peers->shpool) { \
- ngx_rwlock_unlock(&peers->rwlock); \
- }
-
-
-#define ngx_http_upstream_rr_peer_lock(peers, peer) \
- \
- if (peers->shpool) { \
- ngx_rwlock_wlock(&peer->lock); \
- }
-
-#define ngx_http_upstream_rr_peer_unlock(peers, peer) \
- \
- if (peers->shpool) { \
- ngx_rwlock_unlock(&peer->lock); \
- }
-
-
-#define ngx_http_upstream_rr_peer_ref(peers, peer) \
- (peer)->refs++;
-
-
-static ngx_inline void
-ngx_http_upstream_rr_peer_free_locked(ngx_http_upstream_rr_peers_t *peers,
- ngx_http_upstream_rr_peer_t *peer)
-{
- if (peer->refs) {
- peer->zombie = 1;
- return;
- }
-
- ngx_slab_free_locked(peers->shpool, peer->sockaddr);
- ngx_slab_free_locked(peers->shpool, peer->name.data);
-#if (NGX_HTTP_UPSTREAM_SID)
- ngx_slab_free_locked(peers->shpool, peer->sid.data);
-#endif
-
- if (peer->server.data) {
- ngx_slab_free_locked(peers->shpool, peer->server.data);
- }
-
-#if (NGX_HTTP_SSL)
- if (peer->ssl_session) {
- ngx_slab_free_locked(peers->shpool, peer->ssl_session);
- }
-#endif
-
- ngx_slab_free_locked(peers->shpool, peer);
-}
-
-
-static ngx_inline void
-ngx_http_upstream_rr_peer_free(ngx_http_upstream_rr_peers_t *peers,
- ngx_http_upstream_rr_peer_t *peer)
-{
- ngx_shmtx_lock(&peers->shpool->mutex);
- ngx_http_upstream_rr_peer_free_locked(peers, peer);
- ngx_shmtx_unlock(&peers->shpool->mutex);
-}
-
-
-static ngx_inline ngx_int_t
-ngx_http_upstream_rr_peer_unref(ngx_http_upstream_rr_peers_t *peers,
- ngx_http_upstream_rr_peer_t *peer)
-{
- peer->refs--;
-
- if (peers->shpool == NULL) {
- return NGX_OK;
- }
-
- if (peer->refs == 0 && peer->zombie) {
- ngx_http_upstream_rr_peer_free(peers, peer);
- return NGX_DONE;
- }
-
- return NGX_OK;
-}
-
-#else
-
-#define ngx_http_upstream_rr_peers_rlock(peers)
-#define ngx_http_upstream_rr_peers_wlock(peers)
-#define ngx_http_upstream_rr_peers_unlock(peers)
-#define ngx_http_upstream_rr_peer_lock(peers, peer)
-#define ngx_http_upstream_rr_peer_unlock(peers, peer)
-#define ngx_http_upstream_rr_peer_ref(peers, peer)
-#define ngx_http_upstream_rr_peer_unref(peers, peer) NGX_OK
-
-#endif
-
-
-typedef struct {
- ngx_uint_t config;
- ngx_http_upstream_rr_peers_t *peers;
- ngx_http_upstream_rr_peer_t *current;
- uintptr_t *tried;
- uintptr_t data;
-} ngx_http_upstream_rr_peer_data_t;
-
-
-ngx_int_t ngx_http_upstream_init_round_robin(ngx_conf_t *cf,
- ngx_http_upstream_srv_conf_t *us);
-ngx_int_t ngx_http_upstream_init_round_robin_peer(ngx_http_request_t *r,
- ngx_http_upstream_srv_conf_t *us);
-ngx_int_t ngx_http_upstream_create_round_robin_peer(ngx_http_request_t *r,
- ngx_http_upstream_resolved_t *ur);
-ngx_int_t ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc,
- void *data);
-void ngx_http_upstream_free_round_robin_peer(ngx_peer_connection_t *pc,
- void *data, ngx_uint_t state);
-
-#if (NGX_HTTP_SSL)
-ngx_int_t
- ngx_http_upstream_set_round_robin_peer_session(ngx_peer_connection_t *pc,
- void *data);
-void ngx_http_upstream_save_round_robin_peer_session(ngx_peer_connection_t *pc,
- void *data);
-#endif
-
-#if (NGX_HTTP_UPSTREAM_SID)
-
-#define ngx_http_upstream_copy_round_robin_sid(dst, src) \
- ngx_http_upstream_init_round_robin_sid(dst, \
- (src)->route ? &(src)->sid : NULL)
-
-void ngx_http_upstream_init_round_robin_sid(ngx_http_upstream_rr_peer_t *peer,
- ngx_str_t *route);
-ngx_http_upstream_rr_peer_t *ngx_http_upstream_get_rr_peer_by_sid(
- ngx_http_upstream_rr_peer_data_t *rrp, ngx_str_t *hint, ngx_uint_t *p,
- ngx_uint_t lock);
-
-#endif
-
-
-#endif /* _NGX_HTTP_UPSTREAM_ROUND_ROBIN_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.c b/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.c
deleted file mode 100644
index 37cd0d2877..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.c
+++ /dev/null
@@ -1,2890 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-static ngx_http_variable_t *ngx_http_add_prefix_variable(ngx_conf_t *cf,
- ngx_str_t *name, ngx_uint_t flags);
-
-static ngx_int_t ngx_http_variable_request(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-#if 0
-static void ngx_http_variable_request_set(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-#endif
-static ngx_int_t ngx_http_variable_request_get_size(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_header(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static ngx_int_t ngx_http_variable_cookies(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_headers_internal(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data, u_char sep);
-
-static ngx_int_t ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_unknown_trailer_out(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_line(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_cookie(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_argument(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-#if (NGX_HAVE_TCP_INFO)
-static ngx_int_t ngx_http_variable_tcpinfo(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-#endif
-
-static ngx_int_t ngx_http_variable_content_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_host(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_remote_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_remote_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_proxy_protocol_tlv(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_server_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_server_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_scheme(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_https(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_is_request_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static void ngx_http_variable_set_args(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_is_args(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_document_root(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_realpath_root(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_filename(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_server_name(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_method(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_remote_user(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_bytes_sent(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_pipe(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_completion(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_body(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_body_file(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_time(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_request_id(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_status(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static ngx_int_t ngx_http_variable_sent_content_type(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_content_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_location(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_last_modified(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_connection(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_keep_alive(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static void ngx_http_variable_set_limit_rate(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static ngx_int_t ngx_http_variable_connection(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_connection_requests(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_connection_time(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static ngx_int_t ngx_http_variable_nginx_version(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_hostname(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_pid(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_msec(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_time_iso8601(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_variable_time_local(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-/*
- * TODO:
- * Apache CGI: AUTH_TYPE, PATH_INFO (null), PATH_TRANSLATED
- * REMOTE_HOST (null), REMOTE_IDENT (null),
- * SERVER_SOFTWARE
- *
- * Apache SSI: DOCUMENT_NAME, LAST_MODIFIED, USER_NAME (file owner)
- */
-
-/*
- * the $http_host, $http_user_agent, $http_referer, and $http_via
- * variables may be handled by generic
- * ngx_http_variable_unknown_header_in(), but for performance reasons
- * they are handled using dedicated entries
- */
-
-static ngx_http_variable_t ngx_http_core_variables[] = {
-
- { ngx_string("http_host"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.host), 0, 0 },
-
- { ngx_string("http_user_agent"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.user_agent), 0, 0 },
-
- { ngx_string("http_referer"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.referer), 0, 0 },
-
-#if (NGX_HTTP_GZIP)
- { ngx_string("http_via"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.via), 0, 0 },
-#endif
-
-#if (NGX_HTTP_X_FORWARDED_FOR)
- { ngx_string("http_x_forwarded_for"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.x_forwarded_for), 0, 0 },
-#endif
-
- { ngx_string("http_cookie"), NULL, ngx_http_variable_cookies,
- offsetof(ngx_http_request_t, headers_in.cookie), 0, 0 },
-
- { ngx_string("content_length"), NULL, ngx_http_variable_content_length,
- 0, 0, 0 },
-
- { ngx_string("content_type"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_in.content_type), 0, 0 },
-
- { ngx_string("host"), NULL, ngx_http_variable_host, 0, 0, 0 },
-
- { ngx_string("binary_remote_addr"), NULL,
- ngx_http_variable_binary_remote_addr, 0, 0, 0 },
-
- { ngx_string("remote_addr"), NULL, ngx_http_variable_remote_addr, 0, 0, 0 },
-
- { ngx_string("remote_port"), NULL, ngx_http_variable_remote_port, 0, 0, 0 },
-
- { ngx_string("proxy_protocol_addr"), NULL,
- ngx_http_variable_proxy_protocol_addr,
- offsetof(ngx_proxy_protocol_t, src_addr), 0, 0 },
-
- { ngx_string("proxy_protocol_port"), NULL,
- ngx_http_variable_proxy_protocol_port,
- offsetof(ngx_proxy_protocol_t, src_port), 0, 0 },
-
- { ngx_string("proxy_protocol_server_addr"), NULL,
- ngx_http_variable_proxy_protocol_addr,
- offsetof(ngx_proxy_protocol_t, dst_addr), 0, 0 },
-
- { ngx_string("proxy_protocol_server_port"), NULL,
- ngx_http_variable_proxy_protocol_port,
- offsetof(ngx_proxy_protocol_t, dst_port), 0, 0 },
-
- { ngx_string("proxy_protocol_tlv_"), NULL,
- ngx_http_variable_proxy_protocol_tlv,
- 0, NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("server_addr"), NULL, ngx_http_variable_server_addr, 0, 0, 0 },
-
- { ngx_string("server_port"), NULL, ngx_http_variable_server_port, 0, 0, 0 },
-
- { ngx_string("server_protocol"), NULL, ngx_http_variable_request,
- offsetof(ngx_http_request_t, http_protocol), 0, 0 },
-
- { ngx_string("scheme"), NULL, ngx_http_variable_scheme, 0, 0, 0 },
-
- { ngx_string("https"), NULL, ngx_http_variable_https, 0, 0, 0 },
-
- { ngx_string("request_port"), NULL,
- ngx_http_variable_request_port, 0, 0, 0 },
-
- { ngx_string("is_request_port"), NULL,
- ngx_http_variable_is_request_port, 0, 0, 0 },
-
- { ngx_string("request_uri"), NULL, ngx_http_variable_request,
- offsetof(ngx_http_request_t, unparsed_uri), 0, 0 },
-
- { ngx_string("uri"), NULL, ngx_http_variable_request,
- offsetof(ngx_http_request_t, uri),
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("document_uri"), NULL, ngx_http_variable_request,
- offsetof(ngx_http_request_t, uri),
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("request"), NULL, ngx_http_variable_request_line, 0, 0, 0 },
-
- { ngx_string("document_root"), NULL,
- ngx_http_variable_document_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("realpath_root"), NULL,
- ngx_http_variable_realpath_root, 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("query_string"), NULL, ngx_http_variable_request,
- offsetof(ngx_http_request_t, args),
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("args"),
- ngx_http_variable_set_args,
- ngx_http_variable_request,
- offsetof(ngx_http_request_t, args),
- NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("is_args"), NULL, ngx_http_variable_is_args,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("request_filename"), NULL,
- ngx_http_variable_request_filename, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("server_name"), NULL, ngx_http_variable_server_name, 0, 0, 0 },
-
- { ngx_string("request_method"), NULL,
- ngx_http_variable_request_method, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("remote_user"), NULL, ngx_http_variable_remote_user, 0, 0, 0 },
-
- { ngx_string("bytes_sent"), NULL, ngx_http_variable_bytes_sent,
- 0, 0, 0 },
-
- { ngx_string("body_bytes_sent"), NULL, ngx_http_variable_body_bytes_sent,
- 0, 0, 0 },
-
- { ngx_string("pipe"), NULL, ngx_http_variable_pipe,
- 0, 0, 0 },
-
- { ngx_string("request_completion"), NULL,
- ngx_http_variable_request_completion,
- 0, 0, 0 },
-
- { ngx_string("request_body"), NULL,
- ngx_http_variable_request_body,
- 0, 0, 0 },
-
- { ngx_string("request_body_file"), NULL,
- ngx_http_variable_request_body_file,
- 0, 0, 0 },
-
- { ngx_string("request_length"), NULL, ngx_http_variable_request_length,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("request_time"), NULL, ngx_http_variable_request_time,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("request_id"), NULL,
- ngx_http_variable_request_id,
- 0, 0, 0 },
-
- { ngx_string("status"), NULL,
- ngx_http_variable_status, 0,
- NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("sent_http_content_type"), NULL,
- ngx_http_variable_sent_content_type, 0, 0, 0 },
-
- { ngx_string("sent_http_content_length"), NULL,
- ngx_http_variable_sent_content_length, 0, 0, 0 },
-
- { ngx_string("sent_http_location"), NULL,
- ngx_http_variable_sent_location, 0, 0, 0 },
-
- { ngx_string("sent_http_last_modified"), NULL,
- ngx_http_variable_sent_last_modified, 0, 0, 0 },
-
- { ngx_string("sent_http_connection"), NULL,
- ngx_http_variable_sent_connection, 0, 0, 0 },
-
- { ngx_string("sent_http_keep_alive"), NULL,
- ngx_http_variable_sent_keep_alive, 0, 0, 0 },
-
- { ngx_string("sent_http_transfer_encoding"), NULL,
- ngx_http_variable_sent_transfer_encoding, 0, 0, 0 },
-
- { ngx_string("sent_http_cache_control"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_out.cache_control), 0, 0 },
-
- { ngx_string("sent_http_link"), NULL, ngx_http_variable_header,
- offsetof(ngx_http_request_t, headers_out.link), 0, 0 },
-
- { ngx_string("limit_rate"), ngx_http_variable_set_limit_rate,
- ngx_http_variable_request_get_size,
- offsetof(ngx_http_request_t, limit_rate),
- NGX_HTTP_VAR_CHANGEABLE|NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("connection"), NULL,
- ngx_http_variable_connection, 0, 0, 0 },
-
- { ngx_string("connection_requests"), NULL,
- ngx_http_variable_connection_requests, 0, 0, 0 },
-
- { ngx_string("connection_time"), NULL, ngx_http_variable_connection_time,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("nginx_version"), NULL, ngx_http_variable_nginx_version,
- 0, 0, 0 },
-
- { ngx_string("hostname"), NULL, ngx_http_variable_hostname,
- 0, 0, 0 },
-
- { ngx_string("pid"), NULL, ngx_http_variable_pid,
- 0, 0, 0 },
-
- { ngx_string("msec"), NULL, ngx_http_variable_msec,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("time_iso8601"), NULL, ngx_http_variable_time_iso8601,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("time_local"), NULL, ngx_http_variable_time_local,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
-#if (NGX_HAVE_TCP_INFO)
- { ngx_string("tcpinfo_rtt"), NULL, ngx_http_variable_tcpinfo,
- 0, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("tcpinfo_rttvar"), NULL, ngx_http_variable_tcpinfo,
- 1, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("tcpinfo_snd_cwnd"), NULL, ngx_http_variable_tcpinfo,
- 2, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-
- { ngx_string("tcpinfo_rcv_space"), NULL, ngx_http_variable_tcpinfo,
- 3, NGX_HTTP_VAR_NOCACHEABLE, 0 },
-#endif
-
- { ngx_string("http_"), NULL, ngx_http_variable_unknown_header_in,
- 0, NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("sent_http_"), NULL, ngx_http_variable_unknown_header_out,
- 0, NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("sent_trailer_"), NULL, ngx_http_variable_unknown_trailer_out,
- 0, NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("cookie_"), NULL, ngx_http_variable_cookie,
- 0, NGX_HTTP_VAR_PREFIX, 0 },
-
- { ngx_string("arg_"), NULL, ngx_http_variable_argument,
- 0, NGX_HTTP_VAR_NOCACHEABLE|NGX_HTTP_VAR_PREFIX, 0 },
-
- ngx_http_null_variable
-};
-
-
-ngx_http_variable_value_t ngx_http_variable_null_value =
- ngx_http_variable("");
-ngx_http_variable_value_t ngx_http_variable_true_value =
- ngx_http_variable("1");
-
-
-static ngx_uint_t ngx_http_variable_depth = 100;
-
-
-ngx_http_variable_t *
-ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
-{
- ngx_int_t rc;
- ngx_uint_t i;
- ngx_hash_key_t *key;
- ngx_http_variable_t *v;
- ngx_http_core_main_conf_t *cmcf;
-
- if (name->len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid variable name \"$\"");
- return NULL;
- }
-
- if (flags & NGX_HTTP_VAR_PREFIX) {
- return ngx_http_add_prefix_variable(cf, name, flags);
- }
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- key = cmcf->variables_keys->keys.elts;
- for (i = 0; i < cmcf->variables_keys->keys.nelts; i++) {
- if (name->len != key[i].key.len
- || ngx_strncasecmp(name->data, key[i].key.data, name->len) != 0)
- {
- continue;
- }
-
- v = key[i].value;
-
- if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the duplicate \"%V\" variable", name);
- return NULL;
- }
-
- if (!(flags & NGX_HTTP_VAR_WEAK)) {
- v->flags &= ~NGX_HTTP_VAR_WEAK;
- }
-
- return v;
- }
-
- v = ngx_palloc(cf->pool, sizeof(ngx_http_variable_t));
- if (v == NULL) {
- return NULL;
- }
-
- v->name.len = name->len;
- v->name.data = ngx_pnalloc(cf->pool, name->len);
- if (v->name.data == NULL) {
- return NULL;
- }
-
- ngx_strlow(v->name.data, name->data, name->len);
-
- v->set_handler = NULL;
- v->get_handler = NULL;
- v->data = 0;
- v->flags = flags;
- v->index = 0;
-
- rc = ngx_hash_add_key(cmcf->variables_keys, &v->name, v, 0);
-
- if (rc == NGX_ERROR) {
- return NULL;
- }
-
- if (rc == NGX_BUSY) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "conflicting variable name \"%V\"", name);
- return NULL;
- }
-
- return v;
-}
-
-
-static ngx_http_variable_t *
-ngx_http_add_prefix_variable(ngx_conf_t *cf, ngx_str_t *name, ngx_uint_t flags)
-{
- ngx_uint_t i;
- ngx_http_variable_t *v;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- v = cmcf->prefix_variables.elts;
- for (i = 0; i < cmcf->prefix_variables.nelts; i++) {
- if (name->len != v[i].name.len
- || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)
- {
- continue;
- }
-
- v = &v[i];
-
- if (!(v->flags & NGX_HTTP_VAR_CHANGEABLE)) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the duplicate \"%V\" variable", name);
- return NULL;
- }
-
- if (!(flags & NGX_HTTP_VAR_WEAK)) {
- v->flags &= ~NGX_HTTP_VAR_WEAK;
- }
-
- return v;
- }
-
- v = ngx_array_push(&cmcf->prefix_variables);
- if (v == NULL) {
- return NULL;
- }
-
- v->name.len = name->len;
- v->name.data = ngx_pnalloc(cf->pool, name->len);
- if (v->name.data == NULL) {
- return NULL;
- }
-
- ngx_strlow(v->name.data, name->data, name->len);
-
- v->set_handler = NULL;
- v->get_handler = NULL;
- v->data = 0;
- v->flags = flags;
- v->index = 0;
-
- return v;
-}
-
-
-ngx_int_t
-ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name)
-{
- ngx_uint_t i;
- ngx_http_variable_t *v;
- ngx_http_core_main_conf_t *cmcf;
-
- if (name->len == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid variable name \"$\"");
- return NGX_ERROR;
- }
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- v = cmcf->variables.elts;
-
- if (v == NULL) {
- if (ngx_array_init(&cmcf->variables, cf->pool, 4,
- sizeof(ngx_http_variable_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- } else {
- for (i = 0; i < cmcf->variables.nelts; i++) {
- if (name->len != v[i].name.len
- || ngx_strncasecmp(name->data, v[i].name.data, name->len) != 0)
- {
- continue;
- }
-
- return i;
- }
- }
-
- v = ngx_array_push(&cmcf->variables);
- if (v == NULL) {
- return NGX_ERROR;
- }
-
- v->name.len = name->len;
- v->name.data = ngx_pnalloc(cf->pool, name->len);
- if (v->name.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_strlow(v->name.data, name->data, name->len);
-
- v->set_handler = NULL;
- v->get_handler = NULL;
- v->data = 0;
- v->flags = 0;
- v->index = cmcf->variables.nelts - 1;
-
- return v->index;
-}
-
-
-ngx_http_variable_value_t *
-ngx_http_get_indexed_variable(ngx_http_request_t *r, ngx_uint_t index)
-{
- ngx_http_variable_t *v;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- if (cmcf->variables.nelts <= index) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "unknown variable index: %ui", index);
- return NULL;
- }
-
- if (r->variables[index].not_found || r->variables[index].valid) {
- return &r->variables[index];
- }
-
- v = cmcf->variables.elts;
-
- if (ngx_http_variable_depth == 0) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "cycle while evaluating variable \"%V\"",
- &v[index].name);
- return NULL;
- }
-
- ngx_http_variable_depth--;
-
- if (v[index].get_handler(r, &r->variables[index], v[index].data)
- == NGX_OK)
- {
- ngx_http_variable_depth++;
-
- if (v[index].flags & NGX_HTTP_VAR_NOCACHEABLE) {
- r->variables[index].no_cacheable = 1;
- }
-
- return &r->variables[index];
- }
-
- ngx_http_variable_depth++;
-
- r->variables[index].valid = 0;
- r->variables[index].not_found = 1;
-
- return NULL;
-}
-
-
-ngx_http_variable_value_t *
-ngx_http_get_flushed_variable(ngx_http_request_t *r, ngx_uint_t index)
-{
- ngx_http_variable_value_t *v;
-
- v = &r->variables[index];
-
- if (v->valid || v->not_found) {
- if (!v->no_cacheable) {
- return v;
- }
-
- v->valid = 0;
- v->not_found = 0;
- }
-
- return ngx_http_get_indexed_variable(r, index);
-}
-
-
-ngx_http_variable_value_t *
-ngx_http_get_variable(ngx_http_request_t *r, ngx_str_t *name, ngx_uint_t key)
-{
- size_t len;
- ngx_uint_t i, n;
- ngx_http_variable_t *v;
- ngx_http_variable_value_t *vv;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- v = ngx_hash_find(&cmcf->variables_hash, key, name->data, name->len);
-
- if (v) {
- if (v->flags & NGX_HTTP_VAR_INDEXED) {
- return ngx_http_get_flushed_variable(r, v->index);
- }
-
- if (ngx_http_variable_depth == 0) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "cycle while evaluating variable \"%V\"", name);
- return NULL;
- }
-
- ngx_http_variable_depth--;
-
- vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
-
- if (vv && v->get_handler(r, vv, v->data) == NGX_OK) {
- ngx_http_variable_depth++;
- return vv;
- }
-
- ngx_http_variable_depth++;
- return NULL;
- }
-
- vv = ngx_palloc(r->pool, sizeof(ngx_http_variable_value_t));
- if (vv == NULL) {
- return NULL;
- }
-
- len = 0;
-
- v = cmcf->prefix_variables.elts;
- n = cmcf->prefix_variables.nelts;
-
- for (i = 0; i < cmcf->prefix_variables.nelts; i++) {
- if (name->len >= v[i].name.len && name->len > len
- && ngx_strncmp(name->data, v[i].name.data, v[i].name.len) == 0)
- {
- len = v[i].name.len;
- n = i;
- }
- }
-
- if (n != cmcf->prefix_variables.nelts) {
- if (v[n].get_handler(r, vv, (uintptr_t) name) == NGX_OK) {
- return vv;
- }
-
- return NULL;
- }
-
- vv->not_found = 1;
-
- return vv;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- ngx_str_t *s;
-
- s = (ngx_str_t *) ((char *) r + data);
-
- if (s->data) {
- v->len = s->len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = s->data;
-
- } else {
- v->not_found = 1;
- }
-
- return NGX_OK;
-}
-
-
-#if 0
-
-static void
-ngx_http_variable_request_set(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t *s;
-
- s = (ngx_str_t *) ((char *) r + data);
-
- s->len = v->len;
- s->data = v->data;
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_http_variable_request_get_size(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- size_t *sp;
-
- sp = (size_t *) ((char *) r + data);
-
- v->data = ngx_pnalloc(r->pool, NGX_SIZE_T_LEN);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(v->data, "%uz", *sp) - v->data;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_header(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- return ngx_http_variable_headers_internal(r, v, data, ',');
-}
-
-
-static ngx_int_t
-ngx_http_variable_cookies(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- return ngx_http_variable_headers_internal(r, v, data, ';');
-}
-
-
-static ngx_int_t
-ngx_http_variable_headers_internal(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data, u_char sep)
-{
- size_t len;
- u_char *p, *end;
- ngx_table_elt_t *h, *th;
-
- h = *(ngx_table_elt_t **) ((char *) r + data);
-
- len = 0;
-
- for (th = h; th; th = th->next) {
-
- if (th->hash == 0) {
- continue;
- }
-
- len += th->value.len + 2;
- }
-
- if (len == 0) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len -= 2;
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (h->next == NULL) {
- v->len = h->value.len;
- v->data = h->value.data;
-
- return NGX_OK;
- }
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = len;
- v->data = p;
-
- end = p + len;
-
- for (th = h; th; th = th->next) {
-
- if (th->hash == 0) {
- continue;
- }
-
- p = ngx_copy(p, th->value.data, th->value.len);
-
- if (p == end) {
- break;
- }
-
- *p++ = sep; *p++ = ' ';
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_unknown_header_in(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
- &r->headers_in.headers.part,
- sizeof("http_") - 1);
-}
-
-
-static ngx_int_t
-ngx_http_variable_unknown_header_out(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
- &r->headers_out.headers.part,
- sizeof("sent_http_") - 1);
-}
-
-
-static ngx_int_t
-ngx_http_variable_unknown_trailer_out(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- return ngx_http_variable_unknown_header(r, v, (ngx_str_t *) data,
- &r->headers_out.trailers.part,
- sizeof("sent_trailer_") - 1);
-}
-
-
-ngx_int_t
-ngx_http_variable_unknown_header(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, ngx_str_t *var,
- ngx_list_part_t *part, size_t prefix)
-{
- u_char *p, ch;
- size_t len;
- ngx_uint_t i, n;
- ngx_table_elt_t *header, *h, **ph;
-
- ph = &h;
-#if (NGX_SUPPRESS_WARN)
- len = 0;
-#endif
-
- header = part->elts;
-
- for (i = 0; /* void */ ; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- if (header[i].key.len != var->len - prefix) {
- continue;
- }
-
- for (n = 0; n < var->len - prefix; n++) {
- ch = header[i].key.data[n];
-
- if (ch >= 'A' && ch <= 'Z') {
- ch |= 0x20;
-
- } else if (ch == '-') {
- ch = '_';
- }
-
- if (var->data[n + prefix] != ch) {
- break;
- }
- }
-
- if (n != var->len - prefix) {
- continue;
- }
-
- len += header[i].value.len + 2;
-
- *ph = &header[i];
- ph = &header[i].next;
- }
-
- *ph = NULL;
-
- if (h == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- len -= 2;
-
- if (h->next == NULL) {
-
- v->len = h->value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = h->value.data;
-
- return NGX_OK;
- }
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- for ( ;; ) {
-
- p = ngx_copy(p, h->value.data, h->value.len);
-
- if (h->next == NULL) {
- break;
- }
-
- *p++ = ','; *p++ = ' ';
-
- h = h->next;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_line(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p, *s;
-
- s = r->request_line.data;
-
- if (s == NULL) {
- s = r->request_start;
-
- if (s == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- for (p = s; p < r->header_in->last; p++) {
- if (*p == CR || *p == LF) {
- break;
- }
- }
-
- r->request_line.len = p - s;
- r->request_line.data = s;
- }
-
- v->len = r->request_line.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = s;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_cookie(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- ngx_str_t *name = (ngx_str_t *) data;
-
- ngx_str_t cookie, s;
-
- s.len = name->len - (sizeof("cookie_") - 1);
- s.data = name->data + sizeof("cookie_") - 1;
-
- if (ngx_http_parse_cookie_lines(r, r->headers_in.cookie, &s, &cookie)
- == NULL)
- {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->len = cookie.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = cookie.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_argument(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- ngx_str_t *name = (ngx_str_t *) data;
-
- u_char *arg;
- size_t len;
- ngx_str_t value;
-
- len = name->len - (sizeof("arg_") - 1);
- arg = name->data + sizeof("arg_") - 1;
-
- if (len == 0 || ngx_http_arg(r, arg, len, &value) != NGX_OK) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->data = value.data;
- v->len = value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-#if (NGX_HAVE_TCP_INFO)
-
-static ngx_int_t
-ngx_http_variable_tcpinfo(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- struct tcp_info ti;
- socklen_t len;
- uint32_t value;
-
- len = sizeof(struct tcp_info);
- if (getsockopt(r->connection->fd, IPPROTO_TCP, TCP_INFO, &ti, &len) == -1) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->data = ngx_pnalloc(r->pool, NGX_INT32_LEN);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- switch (data) {
- case 0:
- value = ti.tcpi_rtt;
- break;
-
- case 1:
- value = ti.tcpi_rttvar;
- break;
-
- case 2:
- value = ti.tcpi_snd_cwnd;
- break;
-
- case 3:
- value = ti.tcpi_rcv_space;
- break;
-
- /* suppress warning */
- default:
- value = 0;
- break;
- }
-
- v->len = ngx_sprintf(v->data, "%uD", value) - v->data;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_http_variable_content_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- if (r->headers_in.content_length) {
- v->len = r->headers_in.content_length->value.len;
- v->data = r->headers_in.content_length->value.data;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- } else if (r->reading_body) {
- v->not_found = 1;
- v->no_cacheable = 1;
-
- } else if (r->headers_in.content_length_n >= 0) {
- p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%O", r->headers_in.content_length_n) - p;
- v->data = p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- } else if (r->headers_in.chunked) {
- v->not_found = 1;
- v->no_cacheable = 1;
-
- } else {
- v->not_found = 1;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_host(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- ngx_http_core_srv_conf_t *cscf;
-
- if (r->headers_in.server.len) {
- v->len = r->headers_in.server.len;
- v->data = r->headers_in.server.data;
-
- } else {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- v->len = cscf->server_name.len;
- v->data = cscf->server_name.data;
- }
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_binary_remote_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- struct sockaddr_in *sin;
-#if (NGX_HAVE_INET6)
- struct sockaddr_in6 *sin6;
-#endif
-
- switch (r->connection->sockaddr->sa_family) {
-
-#if (NGX_HAVE_INET6)
- case AF_INET6:
- sin6 = (struct sockaddr_in6 *) r->connection->sockaddr;
-
- v->len = sizeof(struct in6_addr);
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = sin6->sin6_addr.s6_addr;
-
- break;
-#endif
-
-#if (NGX_HAVE_UNIX_DOMAIN)
- case AF_UNIX:
-
- v->len = r->connection->addr_text.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->connection->addr_text.data;
-
- break;
-#endif
-
- default: /* AF_INET */
- sin = (struct sockaddr_in *) r->connection->sockaddr;
-
- v->len = sizeof(in_addr_t);
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) &sin->sin_addr;
-
- break;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_remote_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- v->len = r->connection->addr_text.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->connection->addr_text.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_remote_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t port;
-
- v->len = 0;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- port = ngx_inet_get_port(r->connection->sockaddr);
-
- if (port > 0 && port < 65536) {
- v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_proxy_protocol_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t *addr;
- ngx_proxy_protocol_t *pp;
-
- pp = r->connection->proxy_protocol;
- if (pp == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- addr = (ngx_str_t *) ((char *) pp + data);
-
- v->len = addr->len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = addr->data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_proxy_protocol_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t port;
- ngx_proxy_protocol_t *pp;
-
- pp = r->connection->proxy_protocol;
- if (pp == NULL) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->len = 0;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- port = *(in_port_t *) ((char *) pp + data);
-
- if (port > 0 && port < 65536) {
- v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_proxy_protocol_tlv(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t *name = (ngx_str_t *) data;
-
- ngx_int_t rc;
- ngx_str_t tlv, value;
-
- tlv.len = name->len - (sizeof("proxy_protocol_tlv_") - 1);
- tlv.data = name->data + sizeof("proxy_protocol_tlv_") - 1;
-
- rc = ngx_proxy_protocol_get_tlv(r->connection, &tlv, &value);
-
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- if (rc == NGX_DECLINED) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- v->len = value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = value.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_server_addr(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t s;
- u_char addr[NGX_SOCKADDR_STRLEN];
-
- s.len = NGX_SOCKADDR_STRLEN;
- s.data = addr;
-
- if (ngx_connection_local_sockaddr(r->connection, &s, 0) != NGX_OK) {
- return NGX_ERROR;
- }
-
- s.data = ngx_pnalloc(r->pool, s.len);
- if (s.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s.data, addr, s.len);
-
- v->len = s.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = s.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_server_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t port;
-
- v->len = 0;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- if (ngx_connection_local_sockaddr(r->connection, NULL, 0) != NGX_OK) {
- return NGX_ERROR;
- }
-
- v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- port = ngx_inet_get_port(r->connection->local_sockaddr);
-
- if (port > 0 && port < 65536) {
- v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_scheme(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
-#if (NGX_HTTP_SSL)
-
- if (r->connection->ssl) {
- v->len = sizeof("https") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "https";
-
- return NGX_OK;
- }
-
-#endif
-
- v->len = sizeof("http") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "http";
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_https(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
-#if (NGX_HTTP_SSL)
-
- if (r->connection->ssl) {
- v->len = sizeof("on") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "on";
-
- return NGX_OK;
- }
-
-#endif
-
- *v = ngx_http_variable_null_value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t port;
-
- v->len = 0;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- v->data = ngx_pnalloc(r->pool, sizeof("65535") - 1);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- port = r->port;
-
- if (port > 0 && port < 65536) {
- v->len = ngx_sprintf(v->data, "%ui", port) - v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_is_request_port(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->port == 0) {
- *v = ngx_http_variable_null_value;
- return NGX_OK;
- }
-
- v->len = 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) ":";
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_variable_set_args(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- r->args.len = v->len;
- r->args.data = v->data;
- r->valid_unparsed_uri = 0;
-}
-
-
-static ngx_int_t
-ngx_http_variable_is_args(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->args.len == 0) {
- *v = ngx_http_variable_null_value;
- return NGX_OK;
- }
-
- v->len = 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "?";
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_document_root(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t path;
- ngx_http_core_loc_conf_t *clcf;
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->root_lengths == NULL) {
- v->len = clcf->root.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = clcf->root.data;
-
- } else {
- if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 0,
- clcf->root_values->elts)
- == NULL)
- {
- return NGX_ERROR;
- }
-
- if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- v->len = path.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = path.data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_realpath_root(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *real;
- size_t len;
- ngx_str_t path;
- ngx_http_core_loc_conf_t *clcf;
-#if (NGX_HAVE_MAX_PATH)
- u_char buffer[NGX_MAX_PATH];
-#endif
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->root_lengths == NULL) {
- path = clcf->root;
-
- } else {
- if (ngx_http_script_run(r, &path, clcf->root_lengths->elts, 1,
- clcf->root_values->elts)
- == NULL)
- {
- return NGX_ERROR;
- }
-
- path.data[path.len - 1] = '\0';
-
- if (ngx_get_full_name(r->pool, (ngx_str_t *) &ngx_cycle->prefix, &path)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
- }
-
-#if (NGX_HAVE_MAX_PATH)
- real = buffer;
-#else
- real = NULL;
-#endif
-
- real = ngx_realpath(path.data, real);
-
- if (real == NULL) {
- ngx_log_error(NGX_LOG_CRIT, r->connection->log, ngx_errno,
- ngx_realpath_n " \"%s\" failed", path.data);
- return NGX_ERROR;
- }
-
- len = ngx_strlen(real);
-
- v->data = ngx_pnalloc(r->pool, len);
- if (v->data == NULL) {
-#if !(NGX_HAVE_MAX_PATH)
- ngx_free(real);
-#endif
- return NGX_ERROR;
- }
-
- v->len = len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- ngx_memcpy(v->data, real, len);
-
-#if !(NGX_HAVE_MAX_PATH)
- ngx_free(real);
-#endif
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_filename(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- size_t root;
- ngx_str_t path;
-
- if (ngx_http_map_uri_to_path(r, &path, &root, 0) == NULL) {
- return NGX_ERROR;
- }
-
- /* ngx_http_map_uri_to_path() allocates memory for terminating '\0' */
-
- v->len = path.len - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = path.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_server_name(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_http_core_srv_conf_t *cscf;
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- v->len = cscf->server_name.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = cscf->server_name.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_method(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->main->method_name.data) {
- v->len = r->main->method_name.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->main->method_name.data;
-
- } else {
- v->not_found = 1;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_remote_user(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_int_t rc;
-
- rc = ngx_http_auth_basic_user(r);
-
- if (rc == NGX_DECLINED) {
- v->not_found = 1;
- return NGX_OK;
- }
-
- if (rc == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- v->len = r->headers_in.user.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->headers_in.user.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_bytes_sent(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%O", r->connection->sent) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_body_bytes_sent(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- off_t sent;
- u_char *p;
-
- sent = r->connection->sent - r->header_size;
-
- if (sent < 0) {
- sent = 0;
- }
-
- p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%O", sent) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_pipe(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- v->data = (u_char *) (r->pipeline ? "p" : ".");
- v->len = 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_status(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_uint_t status;
-
- v->data = ngx_pnalloc(r->pool, NGX_INT_T_LEN);
- if (v->data == NULL) {
- return NGX_ERROR;
- }
-
- if (r->err_status) {
- status = r->err_status;
-
- } else if (r->headers_out.status) {
- status = r->headers_out.status;
-
- } else if (r->http_version == NGX_HTTP_VERSION_9) {
- status = 9;
-
- } else {
- status = 0;
- }
-
- v->len = ngx_sprintf(v->data, "%03ui", status) - v->data;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_content_type(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->headers_out.content_type.len) {
- v->len = r->headers_out.content_type.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->headers_out.content_type.data;
-
- } else {
- v->not_found = 1;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_content_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- if (r->headers_out.content_length) {
- v->len = r->headers_out.content_length->value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->headers_out.content_length->value.data;
-
- return NGX_OK;
- }
-
- if (r->headers_out.content_length_n >= 0) {
- p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%O", r->headers_out.content_length_n) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
- }
-
- v->not_found = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_location(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_str_t name;
-
- if (r->headers_out.location) {
- v->len = r->headers_out.location->value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->headers_out.location->value.data;
-
- return NGX_OK;
- }
-
- ngx_str_set(&name, "sent_http_location");
-
- return ngx_http_variable_unknown_header(r, v, &name,
- &r->headers_out.headers.part,
- sizeof("sent_http_") - 1);
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_last_modified(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- if (r->headers_out.last_modified) {
- v->len = r->headers_out.last_modified->value.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->headers_out.last_modified->value.data;
-
- return NGX_OK;
- }
-
- if (r->headers_out.last_modified_time >= 0) {
- p = ngx_pnalloc(r->pool, sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_http_time(p, r->headers_out.last_modified_time) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
- }
-
- v->not_found = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_connection(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- size_t len;
- char *p;
-
- if (r->headers_out.status == NGX_HTTP_SWITCHING_PROTOCOLS) {
- len = sizeof("upgrade") - 1;
- p = "upgrade";
-
- } else if (r->keepalive) {
- len = sizeof("keep-alive") - 1;
- p = "keep-alive";
-
- } else {
- len = sizeof("close") - 1;
- p = "close";
- }
-
- v->len = len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_keep_alive(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- ngx_http_core_loc_conf_t *clcf;
-
- if (r->keepalive) {
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->keepalive_header) {
-
- p = ngx_pnalloc(r->pool, sizeof("timeout=") - 1 + NGX_TIME_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "timeout=%T", clcf->keepalive_header) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
- }
- }
-
- v->not_found = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_sent_transfer_encoding(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->chunked) {
- v->len = sizeof("chunked") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "chunked";
-
- } else {
- v->not_found = 1;
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_variable_set_limit_rate(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ssize_t s;
- ngx_str_t val;
-
- val.len = v->len;
- val.data = v->data;
-
- s = ngx_parse_size(&val);
-
- if (s == NGX_ERROR) {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "invalid $limit_rate \"%V\"", &val);
- return;
- }
-
- r->limit_rate = s;
- r->limit_rate_set = 1;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_completion(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->request_complete) {
- v->len = 2;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "OK";
-
- return NGX_OK;
- }
-
- *v = ngx_http_variable_null_value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_body(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- size_t len;
- ngx_buf_t *buf;
- ngx_chain_t *cl;
-
- if (r->request_body == NULL
- || r->request_body->bufs == NULL
- || r->request_body->temp_file)
- {
- v->not_found = 1;
-
- return NGX_OK;
- }
-
- cl = r->request_body->bufs;
- buf = cl->buf;
-
- if (cl->next == NULL) {
- v->len = buf->last - buf->pos;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = buf->pos;
-
- return NGX_OK;
- }
-
- len = buf->last - buf->pos;
- cl = cl->next;
-
- for ( /* void */ ; cl; cl = cl->next) {
- buf = cl->buf;
- len += buf->last - buf->pos;
- }
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->data = p;
- cl = r->request_body->bufs;
-
- for ( /* void */ ; cl; cl = cl->next) {
- buf = cl->buf;
- p = ngx_cpymem(p, buf->pos, buf->last - buf->pos);
- }
-
- v->len = len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_body_file(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- if (r->request_body == NULL || r->request_body->temp_file == NULL) {
- v->not_found = 1;
-
- return NGX_OK;
- }
-
- v->len = r->request_body->temp_file->file.name.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = r->request_body->temp_file->file.name.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_length(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, NGX_OFF_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%O", r->request_length) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_time(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- ngx_time_t *tp;
- ngx_msec_int_t ms;
-
- p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- tp = ngx_timeofday();
-
- ms = (ngx_msec_int_t)
- ((tp->sec - r->start_sec) * 1000 + (tp->msec - r->start_msec));
- ms = ngx_max(ms, 0);
-
- v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_request_id(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *id;
-
-#if (NGX_OPENSSL)
- u_char random_bytes[16];
-#endif
-
- id = ngx_pnalloc(r->pool, 32);
- if (id == NULL) {
- return NGX_ERROR;
- }
-
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
-
- v->len = 32;
- v->data = id;
-
-#if (NGX_OPENSSL)
-
- if (RAND_bytes(random_bytes, 16) == 1) {
- ngx_hex_dump(id, random_bytes, 16);
- return NGX_OK;
- }
-
- ngx_ssl_error(NGX_LOG_ERR, r->connection->log, 0, "RAND_bytes() failed");
-
-#endif
-
- ngx_sprintf(id, "%08xD%08xD%08xD%08xD",
- (uint32_t) ngx_random(), (uint32_t) ngx_random(),
- (uint32_t) ngx_random(), (uint32_t) ngx_random());
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_connection(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, NGX_ATOMIC_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%uA", r->connection->number) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_connection_requests(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, NGX_INT_T_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%ui", r->connection->requests) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_connection_time(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- ngx_msec_int_t ms;
-
- p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ms = ngx_current_msec - r->connection->start_time;
- ms = ngx_max(ms, 0);
-
- v->len = ngx_sprintf(p, "%T.%03M", (time_t) ms / 1000, ms % 1000) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_nginx_version(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- v->len = sizeof(NGINX_VERSION) - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) NGINX_VERSION;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_hostname(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- v->len = ngx_cycle->hostname.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = ngx_cycle->hostname.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_pid(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, NGX_INT64_LEN);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- v->len = ngx_sprintf(p, "%P", ngx_pid) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_msec(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
- ngx_time_t *tp;
-
- p = ngx_pnalloc(r->pool, NGX_TIME_T_LEN + 4);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- tp = ngx_timeofday();
-
- v->len = ngx_sprintf(p, "%T.%03M", tp->sec, tp->msec) - p;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_time_iso8601(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, ngx_cached_http_log_iso8601.len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(p, ngx_cached_http_log_iso8601.data,
- ngx_cached_http_log_iso8601.len);
-
- v->len = ngx_cached_http_log_iso8601.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_variable_time_local(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- u_char *p;
-
- p = ngx_pnalloc(r->pool, ngx_cached_http_log_time.len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(p, ngx_cached_http_log_time.data, ngx_cached_http_log_time.len);
-
- v->len = ngx_cached_http_log_time.len;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = p;
-
- return NGX_OK;
-}
-
-
-void *
-ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map, ngx_str_t *match)
-{
- void *value;
- u_char *low;
- size_t len;
- ngx_uint_t key;
-
- len = match->len;
-
- if (len) {
- low = ngx_pnalloc(r->pool, len);
- if (low == NULL) {
- return NULL;
- }
-
- } else {
- low = NULL;
- }
-
- key = ngx_hash_strlow(low, match->data, len);
-
- value = ngx_hash_find_combined(&map->hash, key, low, len);
- if (value) {
- return value;
- }
-
-#if (NGX_PCRE)
-
- if (len && map->nregex) {
- ngx_int_t n;
- ngx_uint_t i;
- ngx_http_map_regex_t *reg;
-
- reg = map->regex;
-
- for (i = 0; i < map->nregex; i++) {
-
- n = ngx_http_regex_exec(r, reg[i].regex, match);
-
- if (n == NGX_OK) {
- return reg[i].value;
- }
-
- if (n == NGX_DECLINED) {
- continue;
- }
-
- /* NGX_ERROR */
-
- return NULL;
- }
- }
-
-#endif
-
- return NULL;
-}
-
-
-#if (NGX_PCRE)
-
-static ngx_int_t
-ngx_http_variable_not_found(ngx_http_request_t *r, ngx_http_variable_value_t *v,
- uintptr_t data)
-{
- v->not_found = 1;
- return NGX_OK;
-}
-
-
-ngx_http_regex_t *
-ngx_http_regex_compile(ngx_conf_t *cf, ngx_regex_compile_t *rc)
-{
- u_char *p;
- size_t size;
- ngx_str_t name;
- ngx_uint_t i, n;
- ngx_http_variable_t *v;
- ngx_http_regex_t *re;
- ngx_http_regex_variable_t *rv;
- ngx_http_core_main_conf_t *cmcf;
-
- rc->pool = cf->pool;
-
- if (ngx_regex_compile(rc) != NGX_OK) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "%V", &rc->err);
- return NULL;
- }
-
- re = ngx_pcalloc(cf->pool, sizeof(ngx_http_regex_t));
- if (re == NULL) {
- return NULL;
- }
-
- re->regex = rc->regex;
- re->ncaptures = rc->captures;
- re->name = rc->pattern;
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
- cmcf->ncaptures = ngx_max(cmcf->ncaptures, re->ncaptures);
-
- n = (ngx_uint_t) rc->named_captures;
-
- if (n == 0) {
- return re;
- }
-
- rv = ngx_palloc(rc->pool, n * sizeof(ngx_http_regex_variable_t));
- if (rv == NULL) {
- return NULL;
- }
-
- re->variables = rv;
- re->nvariables = n;
-
- size = rc->name_size;
- p = rc->names;
-
- for (i = 0; i < n; i++) {
- rv[i].capture = 2 * ((p[0] << 8) + p[1]);
-
- name.data = &p[2];
- name.len = ngx_strlen(name.data);
-
- v = ngx_http_add_variable(cf, &name, NGX_HTTP_VAR_CHANGEABLE);
- if (v == NULL) {
- return NULL;
- }
-
- rv[i].index = ngx_http_get_variable_index(cf, &name);
- if (rv[i].index == NGX_ERROR) {
- return NULL;
- }
-
- v->get_handler = ngx_http_variable_not_found;
-
- p += size;
- }
-
- return re;
-}
-
-
-ngx_int_t
-ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re, ngx_str_t *s)
-{
- ngx_int_t rc, index;
- ngx_uint_t i, n, len;
- ngx_http_variable_value_t *vv;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- if (re->ncaptures) {
- len = cmcf->ncaptures;
-
- if (r->captures == NULL || r->realloc_captures) {
- r->realloc_captures = 0;
-
- r->captures = ngx_palloc(r->pool, len * sizeof(int));
- if (r->captures == NULL) {
- return NGX_ERROR;
- }
- }
-
- } else {
- len = 0;
- }
-
- rc = ngx_regex_exec(re->regex, s, r->captures, len);
-
- if (rc == NGX_REGEX_NO_MATCHED) {
- return NGX_DECLINED;
- }
-
- if (rc < 0) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- ngx_regex_exec_n " failed: %i on \"%V\" using \"%V\"",
- rc, s, &re->name);
- return NGX_ERROR;
- }
-
- for (i = 0; i < re->nvariables; i++) {
-
- n = re->variables[i].capture;
- index = re->variables[i].index;
- vv = &r->variables[index];
-
- vv->len = r->captures[n + 1] - r->captures[n];
- vv->valid = 1;
- vv->no_cacheable = 0;
- vv->not_found = 0;
- vv->data = &s->data[r->captures[n]];
-
-#if (NGX_DEBUG)
- {
- ngx_http_variable_t *v;
-
- v = cmcf->variables.elts;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http regex set $%V to \"%v\"", &v[index].name, vv);
- }
-#endif
- }
-
- r->ncaptures = rc * 2;
- r->captures_data = s->data;
-
- return NGX_OK;
-}
-
-#endif
-
-
-ngx_int_t
-ngx_http_variables_add_core_vars(ngx_conf_t *cf)
-{
- ngx_http_variable_t *cv, *v;
- ngx_http_core_main_conf_t *cmcf;
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- cmcf->variables_keys = ngx_pcalloc(cf->temp_pool,
- sizeof(ngx_hash_keys_arrays_t));
- if (cmcf->variables_keys == NULL) {
- return NGX_ERROR;
- }
-
- cmcf->variables_keys->pool = cf->pool;
- cmcf->variables_keys->temp_pool = cf->pool;
-
- if (ngx_hash_keys_array_init(cmcf->variables_keys, NGX_HASH_SMALL)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- if (ngx_array_init(&cmcf->prefix_variables, cf->pool, 8,
- sizeof(ngx_http_variable_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- for (cv = ngx_http_core_variables; cv->name.len; cv++) {
- v = ngx_http_add_variable(cf, &cv->name, cv->flags);
- if (v == NULL) {
- return NGX_ERROR;
- }
-
- *v = *cv;
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_variables_init_vars(ngx_conf_t *cf)
-{
- size_t len;
- ngx_uint_t i, n;
- ngx_hash_key_t *key;
- ngx_hash_init_t hash;
- ngx_http_variable_t *v, *av, *pv;
- ngx_http_core_main_conf_t *cmcf;
-
- /* set the handlers for the indexed http variables */
-
- cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module);
-
- v = cmcf->variables.elts;
- pv = cmcf->prefix_variables.elts;
- key = cmcf->variables_keys->keys.elts;
-
- for (i = 0; i < cmcf->variables.nelts; i++) {
-
- for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) {
-
- av = key[n].value;
-
- if (v[i].name.len == key[n].key.len
- && ngx_strncmp(v[i].name.data, key[n].key.data, v[i].name.len)
- == 0)
- {
- v[i].get_handler = av->get_handler;
- v[i].data = av->data;
-
- av->flags |= NGX_HTTP_VAR_INDEXED;
- v[i].flags = av->flags;
-
- av->index = i;
-
- if (av->get_handler == NULL
- || (av->flags & NGX_HTTP_VAR_WEAK))
- {
- break;
- }
-
- goto next;
- }
- }
-
- len = 0;
- av = NULL;
-
- for (n = 0; n < cmcf->prefix_variables.nelts; n++) {
- if (v[i].name.len >= pv[n].name.len && v[i].name.len > len
- && ngx_strncmp(v[i].name.data, pv[n].name.data, pv[n].name.len)
- == 0)
- {
- av = &pv[n];
- len = pv[n].name.len;
- }
- }
-
- if (av) {
- v[i].get_handler = av->get_handler;
- v[i].data = (uintptr_t) &v[i].name;
- v[i].flags = av->flags;
-
- goto next;
- }
-
- if (v[i].get_handler == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unknown \"%V\" variable", &v[i].name);
-
- return NGX_ERROR;
- }
-
- next:
- continue;
- }
-
-
- for (n = 0; n < cmcf->variables_keys->keys.nelts; n++) {
- av = key[n].value;
-
- if (av->flags & NGX_HTTP_VAR_NOHASH) {
- key[n].key.data = NULL;
- }
- }
-
-
- hash.hash = &cmcf->variables_hash;
- hash.key = ngx_hash_key;
- hash.max_size = cmcf->variables_hash_max_size;
- hash.bucket_size = cmcf->variables_hash_bucket_size;
- hash.name = "variables_hash";
- hash.pool = cf->pool;
- hash.temp_pool = NULL;
-
- if (ngx_hash_init(&hash, cmcf->variables_keys->keys.elts,
- cmcf->variables_keys->keys.nelts)
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
- cmcf->variables_keys = NULL;
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.h b/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.h
deleted file mode 100644
index 6a661a2568..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_variables.h
+++ /dev/null
@@ -1,117 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_VARIABLES_H_INCLUDED_
-#define _NGX_HTTP_VARIABLES_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef ngx_variable_value_t ngx_http_variable_value_t;
-
-#define ngx_http_variable(v) { sizeof(v) - 1, 1, 0, 0, 0, (u_char *) v }
-
-typedef struct ngx_http_variable_s ngx_http_variable_t;
-
-typedef void (*ngx_http_set_variable_pt) (ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-typedef ngx_int_t (*ngx_http_get_variable_pt) (ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-
-#define NGX_HTTP_VAR_CHANGEABLE 1
-#define NGX_HTTP_VAR_NOCACHEABLE 2
-#define NGX_HTTP_VAR_INDEXED 4
-#define NGX_HTTP_VAR_NOHASH 8
-#define NGX_HTTP_VAR_WEAK 16
-#define NGX_HTTP_VAR_PREFIX 32
-
-
-struct ngx_http_variable_s {
- ngx_str_t name; /* must be first to build the hash */
- ngx_http_set_variable_pt set_handler;
- ngx_http_get_variable_pt get_handler;
- uintptr_t data;
- ngx_uint_t flags;
- ngx_uint_t index;
-};
-
-#define ngx_http_null_variable { ngx_null_string, NULL, NULL, 0, 0, 0 }
-
-
-ngx_http_variable_t *ngx_http_add_variable(ngx_conf_t *cf, ngx_str_t *name,
- ngx_uint_t flags);
-ngx_int_t ngx_http_get_variable_index(ngx_conf_t *cf, ngx_str_t *name);
-ngx_http_variable_value_t *ngx_http_get_indexed_variable(ngx_http_request_t *r,
- ngx_uint_t index);
-ngx_http_variable_value_t *ngx_http_get_flushed_variable(ngx_http_request_t *r,
- ngx_uint_t index);
-
-ngx_http_variable_value_t *ngx_http_get_variable(ngx_http_request_t *r,
- ngx_str_t *name, ngx_uint_t key);
-
-ngx_int_t ngx_http_variable_unknown_header(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, ngx_str_t *var, ngx_list_part_t *part,
- size_t prefix);
-
-
-#if (NGX_PCRE)
-
-typedef struct {
- ngx_uint_t capture;
- ngx_int_t index;
-} ngx_http_regex_variable_t;
-
-
-typedef struct {
- ngx_regex_t *regex;
- ngx_uint_t ncaptures;
- ngx_http_regex_variable_t *variables;
- ngx_uint_t nvariables;
- ngx_str_t name;
-} ngx_http_regex_t;
-
-
-typedef struct {
- ngx_http_regex_t *regex;
- void *value;
-} ngx_http_map_regex_t;
-
-
-ngx_http_regex_t *ngx_http_regex_compile(ngx_conf_t *cf,
- ngx_regex_compile_t *rc);
-ngx_int_t ngx_http_regex_exec(ngx_http_request_t *r, ngx_http_regex_t *re,
- ngx_str_t *s);
-
-#endif
-
-
-typedef struct {
- ngx_hash_combined_t hash;
-#if (NGX_PCRE)
- ngx_http_map_regex_t *regex;
- ngx_uint_t nregex;
-#endif
-} ngx_http_map_t;
-
-
-void *ngx_http_map_find(ngx_http_request_t *r, ngx_http_map_t *map,
- ngx_str_t *match);
-
-
-ngx_int_t ngx_http_variables_add_core_vars(ngx_conf_t *cf);
-ngx_int_t ngx_http_variables_init_vars(ngx_conf_t *cf);
-
-
-extern ngx_http_variable_value_t ngx_http_variable_null_value;
-extern ngx_http_variable_value_t ngx_http_variable_true_value;
-
-
-#endif /* _NGX_HTTP_VARIABLES_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/ngx_http_write_filter_module.c b/src/deps/src/nginx-1.30.3/src/http/ngx_http_write_filter_module.c
deleted file mode 100644
index 9188ee948d..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/ngx_http_write_filter_module.c
+++ /dev/null
@@ -1,371 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-static ngx_int_t ngx_http_write_filter_init(ngx_conf_t *cf);
-
-
-static ngx_http_module_t ngx_http_write_filter_module_ctx = {
- NULL, /* preconfiguration */
- ngx_http_write_filter_init, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL, /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_write_filter_module = {
- NGX_MODULE_V1,
- &ngx_http_write_filter_module_ctx, /* module context */
- NULL, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-ngx_int_t
-ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in)
-{
- off_t size, sent, nsent, limit;
- ngx_uint_t last, flush, sync;
- ngx_msec_t delay;
- ngx_chain_t *cl, *ln, **ll, *chain;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- c = r->connection;
-
- if (c->error) {
- return NGX_ERROR;
- }
-
- size = 0;
- flush = 0;
- sync = 0;
- last = 0;
- ll = &r->out;
-
- /* find the size, the flush point and the last link of the saved chain */
-
- for (cl = r->out; cl; cl = cl->next) {
- ll = &cl->next;
-
- ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "write old buf t:%d f:%d %p, pos %p, size: %z "
- "file: %O, size: %O",
- cl->buf->temporary, cl->buf->in_file,
- cl->buf->start, cl->buf->pos,
- cl->buf->last - cl->buf->pos,
- cl->buf->file_pos,
- cl->buf->file_last - cl->buf->file_pos);
-
- if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "zero size buf in writer "
- "t:%d r:%d f:%d %p %p-%p %p %O-%O",
- cl->buf->temporary,
- cl->buf->recycled,
- cl->buf->in_file,
- cl->buf->start,
- cl->buf->pos,
- cl->buf->last,
- cl->buf->file,
- cl->buf->file_pos,
- cl->buf->file_last);
-
- ngx_debug_point();
- return NGX_ERROR;
- }
-
- if (ngx_buf_size(cl->buf) < 0) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "negative size buf in writer "
- "t:%d r:%d f:%d %p %p-%p %p %O-%O",
- cl->buf->temporary,
- cl->buf->recycled,
- cl->buf->in_file,
- cl->buf->start,
- cl->buf->pos,
- cl->buf->last,
- cl->buf->file,
- cl->buf->file_pos,
- cl->buf->file_last);
-
- ngx_debug_point();
- return NGX_ERROR;
- }
-
- size += ngx_buf_size(cl->buf);
-
- if (cl->buf->flush || cl->buf->recycled) {
- flush = 1;
- }
-
- if (cl->buf->sync) {
- sync = 1;
- }
-
- if (cl->buf->last_buf) {
- last = 1;
- }
- }
-
- /* add the new chain to the existent one */
-
- for (ln = in; ln; ln = ln->next) {
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = ln->buf;
- *ll = cl;
- ll = &cl->next;
-
- ngx_log_debug7(NGX_LOG_DEBUG_EVENT, c->log, 0,
- "write new buf t:%d f:%d %p, pos %p, size: %z "
- "file: %O, size: %O",
- cl->buf->temporary, cl->buf->in_file,
- cl->buf->start, cl->buf->pos,
- cl->buf->last - cl->buf->pos,
- cl->buf->file_pos,
- cl->buf->file_last - cl->buf->file_pos);
-
- if (ngx_buf_size(cl->buf) == 0 && !ngx_buf_special(cl->buf)) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "zero size buf in writer "
- "t:%d r:%d f:%d %p %p-%p %p %O-%O",
- cl->buf->temporary,
- cl->buf->recycled,
- cl->buf->in_file,
- cl->buf->start,
- cl->buf->pos,
- cl->buf->last,
- cl->buf->file,
- cl->buf->file_pos,
- cl->buf->file_last);
-
- ngx_debug_point();
- return NGX_ERROR;
- }
-
- if (ngx_buf_size(cl->buf) < 0) {
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "negative size buf in writer "
- "t:%d r:%d f:%d %p %p-%p %p %O-%O",
- cl->buf->temporary,
- cl->buf->recycled,
- cl->buf->in_file,
- cl->buf->start,
- cl->buf->pos,
- cl->buf->last,
- cl->buf->file,
- cl->buf->file_pos,
- cl->buf->file_last);
-
- ngx_debug_point();
- return NGX_ERROR;
- }
-
- size += ngx_buf_size(cl->buf);
-
- if (cl->buf->flush || cl->buf->recycled) {
- flush = 1;
- }
-
- if (cl->buf->sync) {
- sync = 1;
- }
-
- if (cl->buf->last_buf) {
- last = 1;
- }
- }
-
- *ll = NULL;
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter: l:%ui f:%ui s:%O", last, flush, size);
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- /*
- * avoid the output if there are no last buf, no flush point,
- * there are the incoming bufs and the size of all bufs
- * is smaller than "postpone_output" directive
- */
-
- if (!last && !flush && in && size < (off_t) clcf->postpone_output) {
- return NGX_OK;
- }
-
- if (c->write->delayed) {
- c->buffered |= NGX_HTTP_WRITE_BUFFERED;
- return NGX_AGAIN;
- }
-
- if (size == 0
- && !(c->buffered & NGX_LOWLEVEL_BUFFERED)
- && !(last && c->need_last_buf)
- && !(flush && c->need_flush_buf))
- {
- if (last || flush || sync) {
- for (cl = r->out; cl; /* void */) {
- ln = cl;
- cl = cl->next;
- ngx_free_chain(r->pool, ln);
- }
-
- r->out = NULL;
- c->buffered &= ~NGX_HTTP_WRITE_BUFFERED;
-
- if (last) {
- r->response_sent = 1;
- }
-
- return NGX_OK;
- }
-
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "the http output chain is empty");
-
- ngx_debug_point();
-
- return NGX_ERROR;
- }
-
- if (!r->limit_rate_set) {
- r->limit_rate = ngx_http_complex_value_size(r, clcf->limit_rate, 0);
- r->limit_rate_set = 1;
- }
-
- if (r->limit_rate) {
-
- if (!r->limit_rate_after_set) {
- r->limit_rate_after = ngx_http_complex_value_size(r,
- clcf->limit_rate_after, 0);
- r->limit_rate_after_set = 1;
- }
-
- limit = (off_t) r->limit_rate * (ngx_time() - r->start_sec + 1)
- - (c->sent - r->limit_rate_after);
-
- if (limit <= 0) {
- c->write->delayed = 1;
- delay = (ngx_msec_t) (- limit * 1000 / r->limit_rate + 1);
- ngx_add_timer(c->write, delay);
-
- c->buffered |= NGX_HTTP_WRITE_BUFFERED;
-
- return NGX_AGAIN;
- }
-
- if (clcf->sendfile_max_chunk
- && (off_t) clcf->sendfile_max_chunk < limit)
- {
- limit = clcf->sendfile_max_chunk;
- }
-
- } else {
- limit = clcf->sendfile_max_chunk;
- }
-
- sent = c->sent;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter limit %O", limit);
-
- chain = c->send_chain(c, r->out, limit);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http write filter %p", chain);
-
- if (chain == NGX_CHAIN_ERROR) {
- c->error = 1;
- return NGX_ERROR;
- }
-
- if (r->limit_rate) {
-
- nsent = c->sent;
-
- if (r->limit_rate_after) {
-
- sent -= r->limit_rate_after;
- if (sent < 0) {
- sent = 0;
- }
-
- nsent -= r->limit_rate_after;
- if (nsent < 0) {
- nsent = 0;
- }
- }
-
- delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate);
-
- if (delay > 0) {
- c->write->delayed = 1;
- ngx_add_timer(c->write, delay);
- }
- }
-
- if (chain && c->write->ready && !c->write->delayed) {
- ngx_post_event(c->write, &ngx_posted_next_events);
- }
-
- for (cl = r->out; cl && cl != chain; /* void */) {
- ln = cl;
- cl = cl->next;
- ngx_free_chain(r->pool, ln);
- }
-
- r->out = chain;
-
- if (chain) {
- c->buffered |= NGX_HTTP_WRITE_BUFFERED;
- return NGX_AGAIN;
- }
-
- c->buffered &= ~NGX_HTTP_WRITE_BUFFERED;
-
- if (last) {
- r->response_sent = 1;
- }
-
- if ((c->buffered & NGX_LOWLEVEL_BUFFERED) && r->postponed == NULL) {
- return NGX_AGAIN;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_write_filter_init(ngx_conf_t *cf)
-{
- ngx_http_top_body_filter = ngx_http_write_filter;
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.c b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.c
deleted file mode 100644
index efe22903fa..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.c
+++ /dev/null
@@ -1,5030 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#include
-#include
-#include
-#include
-
-
-/* errors */
-#define NGX_HTTP_V2_NO_ERROR 0x0
-#define NGX_HTTP_V2_PROTOCOL_ERROR 0x1
-#define NGX_HTTP_V2_INTERNAL_ERROR 0x2
-#define NGX_HTTP_V2_FLOW_CTRL_ERROR 0x3
-#define NGX_HTTP_V2_SETTINGS_TIMEOUT 0x4
-#define NGX_HTTP_V2_STREAM_CLOSED 0x5
-#define NGX_HTTP_V2_SIZE_ERROR 0x6
-#define NGX_HTTP_V2_REFUSED_STREAM 0x7
-#define NGX_HTTP_V2_CANCEL 0x8
-#define NGX_HTTP_V2_COMP_ERROR 0x9
-#define NGX_HTTP_V2_CONNECT_ERROR 0xa
-#define NGX_HTTP_V2_ENHANCE_YOUR_CALM 0xb
-#define NGX_HTTP_V2_INADEQUATE_SECURITY 0xc
-#define NGX_HTTP_V2_HTTP_1_1_REQUIRED 0xd
-
-/* frame sizes */
-#define NGX_HTTP_V2_SETTINGS_ACK_SIZE 0
-#define NGX_HTTP_V2_RST_STREAM_SIZE 4
-#define NGX_HTTP_V2_PRIORITY_SIZE 5
-#define NGX_HTTP_V2_PING_SIZE 8
-#define NGX_HTTP_V2_GOAWAY_SIZE 8
-#define NGX_HTTP_V2_WINDOW_UPDATE_SIZE 4
-
-#define NGX_HTTP_V2_SETTINGS_PARAM_SIZE 6
-
-/* settings fields */
-#define NGX_HTTP_V2_HEADER_TABLE_SIZE_SETTING 0x1
-#define NGX_HTTP_V2_ENABLE_PUSH_SETTING 0x2
-#define NGX_HTTP_V2_MAX_STREAMS_SETTING 0x3
-#define NGX_HTTP_V2_INIT_WINDOW_SIZE_SETTING 0x4
-#define NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING 0x5
-
-#define NGX_HTTP_V2_FRAME_BUFFER_SIZE 24
-
-#define NGX_HTTP_V2_ROOT (void *) -1
-
-
-static void ngx_http_v2_read_handler(ngx_event_t *rev);
-static void ngx_http_v2_write_handler(ngx_event_t *wev);
-static void ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c);
-static void ngx_http_v2_lingering_close(ngx_connection_t *c);
-static void ngx_http_v2_lingering_close_handler(ngx_event_t *rev);
-
-static u_char *ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_head(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_data(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_read_data(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_field_huff(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_field_raw(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_field_skip(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_process_header(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_header_complete(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_handle_continuation(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end, ngx_http_v2_handler_pt handler);
-static u_char *ngx_http_v2_state_priority(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_rst_stream(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_settings(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_push_promise(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_ping(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_goaway(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_window_update(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_continuation(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_complete(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_skip_padded(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_skip(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-static u_char *ngx_http_v2_state_save(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end, ngx_http_v2_handler_pt handler);
-static u_char *ngx_http_v2_state_headers_save(ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end, ngx_http_v2_handler_pt handler);
-static u_char *ngx_http_v2_connection_error(ngx_http_v2_connection_t *h2c,
- ngx_uint_t err);
-
-static ngx_int_t ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c,
- u_char **pos, u_char *end, ngx_uint_t prefix);
-
-static ngx_http_v2_stream_t *ngx_http_v2_create_stream(
- ngx_http_v2_connection_t *h2c);
-static ngx_http_v2_node_t *ngx_http_v2_get_node_by_id(
- ngx_http_v2_connection_t *h2c, ngx_uint_t sid, ngx_uint_t alloc);
-static ngx_http_v2_node_t *ngx_http_v2_get_closed_node(
- ngx_http_v2_connection_t *h2c);
-#define ngx_http_v2_index_size(h2scf) (h2scf->streams_index_mask + 1)
-#define ngx_http_v2_index(h2scf, sid) ((sid >> 1) & h2scf->streams_index_mask)
-
-static ngx_int_t ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c);
-static ngx_int_t ngx_http_v2_settings_frame_handler(
- ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
-static ngx_int_t ngx_http_v2_send_window_update(ngx_http_v2_connection_t *h2c,
- ngx_uint_t sid, size_t window);
-static ngx_int_t ngx_http_v2_send_rst_stream(ngx_http_v2_connection_t *h2c,
- ngx_uint_t sid, ngx_uint_t status);
-static ngx_int_t ngx_http_v2_send_goaway(ngx_http_v2_connection_t *h2c,
- ngx_uint_t status);
-
-static ngx_http_v2_out_frame_t *ngx_http_v2_get_frame(
- ngx_http_v2_connection_t *h2c, size_t length, ngx_uint_t type,
- u_char flags, ngx_uint_t sid);
-static ngx_int_t ngx_http_v2_frame_handler(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame);
-
-static ngx_int_t ngx_http_v2_validate_header(ngx_http_request_t *r,
- ngx_http_v2_header_t *header);
-static ngx_int_t ngx_http_v2_pseudo_header(ngx_http_request_t *r,
- ngx_http_v2_header_t *header);
-static ngx_int_t ngx_http_v2_parse_path(ngx_http_request_t *r,
- ngx_str_t *value);
-static ngx_int_t ngx_http_v2_parse_method(ngx_http_request_t *r,
- ngx_str_t *value);
-static ngx_int_t ngx_http_v2_parse_scheme(ngx_http_request_t *r,
- ngx_str_t *value);
-static ngx_int_t ngx_http_v2_parse_authority(ngx_http_request_t *r,
- ngx_str_t *value);
-static ngx_int_t ngx_http_v2_construct_request_line(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v2_cookie(ngx_http_request_t *r,
- ngx_http_v2_header_t *header);
-static ngx_int_t ngx_http_v2_construct_cookie_header(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v2_construct_host_header(ngx_http_request_t *r);
-static void ngx_http_v2_run_request(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v2_process_request_body(ngx_http_request_t *r,
- u_char *pos, size_t size, ngx_uint_t last, ngx_uint_t flush);
-static ngx_int_t ngx_http_v2_filter_request_body(ngx_http_request_t *r);
-static void ngx_http_v2_read_client_request_body_handler(ngx_http_request_t *r);
-
-static ngx_int_t ngx_http_v2_terminate_stream(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream, ngx_uint_t status);
-static void ngx_http_v2_close_stream_handler(ngx_event_t *ev);
-static void ngx_http_v2_retry_close_stream_handler(ngx_event_t *ev);
-static void ngx_http_v2_handle_connection_handler(ngx_event_t *rev);
-static void ngx_http_v2_idle_handler(ngx_event_t *rev);
-static void ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c,
- ngx_uint_t status);
-
-static ngx_int_t ngx_http_v2_adjust_windows(ngx_http_v2_connection_t *h2c,
- ssize_t delta);
-static void ngx_http_v2_set_dependency(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_node_t *node, ngx_uint_t depend, ngx_uint_t exclusive);
-static void ngx_http_v2_node_children_update(ngx_http_v2_node_t *node);
-
-static void ngx_http_v2_pool_cleanup(void *data);
-
-
-static ngx_http_v2_handler_pt ngx_http_v2_frame_states[] = {
- ngx_http_v2_state_data, /* NGX_HTTP_V2_DATA_FRAME */
- ngx_http_v2_state_headers, /* NGX_HTTP_V2_HEADERS_FRAME */
- ngx_http_v2_state_priority, /* NGX_HTTP_V2_PRIORITY_FRAME */
- ngx_http_v2_state_rst_stream, /* NGX_HTTP_V2_RST_STREAM_FRAME */
- ngx_http_v2_state_settings, /* NGX_HTTP_V2_SETTINGS_FRAME */
- ngx_http_v2_state_push_promise, /* NGX_HTTP_V2_PUSH_PROMISE_FRAME */
- ngx_http_v2_state_ping, /* NGX_HTTP_V2_PING_FRAME */
- ngx_http_v2_state_goaway, /* NGX_HTTP_V2_GOAWAY_FRAME */
- ngx_http_v2_state_window_update, /* NGX_HTTP_V2_WINDOW_UPDATE_FRAME */
- ngx_http_v2_state_continuation /* NGX_HTTP_V2_CONTINUATION_FRAME */
-};
-
-#define NGX_HTTP_V2_FRAME_STATES \
- (sizeof(ngx_http_v2_frame_states) / sizeof(ngx_http_v2_handler_pt))
-
-
-void
-ngx_http_v2_init(ngx_event_t *rev)
-{
- u_char *p, *end;
- ngx_connection_t *c;
- ngx_pool_cleanup_t *cln;
- ngx_http_connection_t *hc;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_v2_main_conf_t *h2mcf;
- ngx_http_v2_connection_t *h2c;
- ngx_http_core_srv_conf_t *cscf;
-
- c = rev->data;
- hc = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "init http2 connection");
-
- c->log->action = "processing HTTP/2 connection";
-
- h2mcf = ngx_http_get_module_main_conf(hc->conf_ctx, ngx_http_v2_module);
-
- if (h2mcf->recv_buffer == NULL) {
- h2mcf->recv_buffer = ngx_palloc(ngx_cycle->pool,
- h2mcf->recv_buffer_size);
- if (h2mcf->recv_buffer == NULL) {
- ngx_http_close_connection(c);
- return;
- }
- }
-
- h2c = ngx_pcalloc(c->pool, sizeof(ngx_http_v2_connection_t));
- if (h2c == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- h2c->connection = c;
- h2c->http_connection = hc;
-
- h2c->send_window = NGX_HTTP_V2_DEFAULT_WINDOW;
- h2c->recv_window = NGX_HTTP_V2_MAX_WINDOW;
-
- h2c->init_window = NGX_HTTP_V2_DEFAULT_WINDOW;
-
- h2c->frame_size = NGX_HTTP_V2_DEFAULT_FRAME_SIZE;
-
- h2scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v2_module);
-
- h2c->priority_limit = ngx_max(h2scf->concurrent_streams, 100);
-
- h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
- if (h2c->pool == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- cln = ngx_pool_cleanup_add(c->pool, 0);
- if (cln == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- cln->handler = ngx_http_v2_pool_cleanup;
- cln->data = h2c;
-
- h2c->streams_index = ngx_pcalloc(c->pool, ngx_http_v2_index_size(h2scf)
- * sizeof(ngx_http_v2_node_t *));
- if (h2c->streams_index == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (ngx_http_v2_send_settings(h2c) == NGX_ERROR) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (ngx_http_v2_send_window_update(h2c, 0, NGX_HTTP_V2_MAX_WINDOW
- - NGX_HTTP_V2_DEFAULT_WINDOW)
- == NGX_ERROR)
- {
- ngx_http_close_connection(c);
- return;
- }
-
- h2c->state.handler = ngx_http_v2_state_preface;
-
- ngx_queue_init(&h2c->waiting);
- ngx_queue_init(&h2c->dependencies);
- ngx_queue_init(&h2c->closed);
-
- c->data = h2c;
-
- if (ngx_exiting) {
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
- return;
- }
-
- rev->handler = ngx_http_v2_read_handler;
- c->write->handler = ngx_http_v2_write_handler;
-
- if (!rev->timer_set) {
- cscf = ngx_http_get_module_srv_conf(hc->conf_ctx,
- ngx_http_core_module);
- ngx_add_timer(rev, cscf->client_header_timeout);
- }
-
- c->idle = 1;
- ngx_reusable_connection(c, 0);
-
- if (c->buffer) {
- p = c->buffer->pos;
- end = c->buffer->last;
-
- do {
- p = h2c->state.handler(h2c, p, end);
-
- if (p == NULL) {
- return;
- }
-
- } while (p != end);
-
- h2c->total_bytes += p - c->buffer->pos;
- c->buffer->pos = p;
- }
-
- ngx_http_v2_read_handler(rev);
-}
-
-
-static void
-ngx_http_v2_read_handler(ngx_event_t *rev)
-{
- u_char *p, *end;
- size_t available;
- ssize_t n;
- ngx_connection_t *c;
- ngx_http_v2_main_conf_t *h2mcf;
- ngx_http_v2_connection_t *h2c;
-
- c = rev->data;
- h2c = c->data;
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- return;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 read handler");
-
- h2c->blocked = 1;
- h2c->new_streams = 0;
-
- if (c->close) {
- c->close = 0;
-
- if (c->error) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- if (!h2c->processing) {
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
- return;
- }
-
- if (!h2c->goaway) {
- h2c->goaway = 1;
-
- if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR)
- == NGX_ERROR)
- {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
- }
-
- h2c->blocked = 0;
-
- return;
- }
-
- h2mcf = ngx_http_get_module_main_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- available = h2mcf->recv_buffer_size - NGX_HTTP_V2_STATE_BUFFER_SIZE;
-
- do {
- p = h2mcf->recv_buffer;
- end = ngx_cpymem(p, h2c->state.buffer, h2c->state.buffer_used);
-
- n = c->recv(c, end, available);
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- if (n == 0 && (h2c->state.incomplete || h2c->processing)) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client prematurely closed connection");
- }
-
- if (n == 0 || n == NGX_ERROR) {
- c->error = 1;
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- end += n;
-
- h2c->state.buffer_used = 0;
- h2c->state.incomplete = 0;
-
- do {
- p = h2c->state.handler(h2c, p, end);
-
- if (p == NULL) {
- return;
- }
-
- } while (p != end);
-
- h2c->total_bytes += n;
-
- if (h2c->total_bytes / 8 > h2c->payload_bytes + 1048576) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "http2 flood detected");
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
- return;
- }
-
- } while (rev->ready);
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- return;
- }
-
- if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- h2c->blocked = 0;
-
- ngx_http_v2_handle_connection(h2c);
-}
-
-
-static void
-ngx_http_v2_write_handler(ngx_event_t *wev)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_v2_connection_t *h2c;
-
- c = wev->data;
- h2c = c->data;
-
- if (wev->timedout) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http2 write event timed out");
- c->error = 1;
- c->timedout = 1;
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 write handler");
-
- if (h2c->last_out == NULL && !c->buffered) {
-
- if (wev->timer_set) {
- ngx_del_timer(wev);
- }
-
- ngx_http_v2_handle_connection(h2c);
- return;
- }
-
- h2c->blocked = 1;
-
- rc = ngx_http_v2_send_output_queue(h2c);
-
- if (rc == NGX_ERROR) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- h2c->blocked = 0;
-
- if (rc == NGX_AGAIN) {
- return;
- }
-
- ngx_http_v2_handle_connection(h2c);
-}
-
-
-ngx_int_t
-ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c)
-{
- int tcp_nodelay;
- ngx_chain_t *cl;
- ngx_event_t *wev;
- ngx_connection_t *c;
- ngx_http_v2_out_frame_t *out, *frame, *fn;
- ngx_http_core_loc_conf_t *clcf;
-
- c = h2c->connection;
- wev = c->write;
-
- if (c->error) {
- goto error;
- }
-
- if (!wev->ready) {
- return NGX_AGAIN;
- }
-
- cl = NULL;
- out = NULL;
-
- for (frame = h2c->last_out; frame; frame = fn) {
- frame->last->next = cl;
- cl = frame->first;
-
- fn = frame->next;
- frame->next = out;
- out = frame;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http2 frame out: %p sid:%ui bl:%d len:%uz",
- out, out->stream ? out->stream->node->id : 0,
- out->blocked, out->length);
- }
-
- cl = c->send_chain(c, cl, 0);
-
- if (cl == NGX_CHAIN_ERROR) {
- goto error;
- }
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
- goto error;
- }
-
- if (c->tcp_nopush == NGX_TCP_NOPUSH_SET) {
- if (ngx_tcp_push(c->fd) == -1) {
- ngx_connection_error(c, ngx_socket_errno, ngx_tcp_push_n " failed");
- goto error;
- }
-
- c->tcp_nopush = NGX_TCP_NOPUSH_UNSET;
- tcp_nodelay = ngx_tcp_nodelay_and_tcp_nopush ? 1 : 0;
-
- } else {
- tcp_nodelay = 1;
- }
-
- if (tcp_nodelay && clcf->tcp_nodelay && ngx_tcp_nodelay(c) != NGX_OK) {
- goto error;
- }
-
- for ( /* void */ ; out; out = fn) {
- fn = out->next;
-
- if (out->handler(h2c, out) != NGX_OK) {
- out->blocked = 1;
- break;
- }
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http2 frame sent: %p sid:%ui bl:%d len:%uz",
- out, out->stream ? out->stream->node->id : 0,
- out->blocked, out->length);
- }
-
- frame = NULL;
-
- for ( /* void */ ; out; out = fn) {
- fn = out->next;
- out->next = frame;
- frame = out;
- }
-
- h2c->last_out = frame;
-
- if (!wev->ready) {
- ngx_add_timer(wev, clcf->send_timeout);
- return NGX_AGAIN;
- }
-
- if (wev->timer_set) {
- ngx_del_timer(wev);
- }
-
- return NGX_OK;
-
-error:
-
- c->error = 1;
-
- if (!h2c->blocked) {
- ngx_post_event(wev, &ngx_posted_events);
- }
-
- return NGX_ERROR;
-}
-
-
-static void
-ngx_http_v2_handle_connection(ngx_http_v2_connection_t *h2c)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
-
- if (h2c->last_out || h2c->processing) {
- return;
- }
-
- c = h2c->connection;
-
- if (c->error) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (c->buffered) {
- h2c->blocked = 1;
-
- rc = ngx_http_v2_send_output_queue(h2c);
-
- h2c->blocked = 0;
-
- if (rc == NGX_ERROR) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (rc == NGX_AGAIN) {
- return;
- }
-
- /* rc == NGX_OK */
- }
-
- if (h2c->goaway) {
- ngx_http_v2_lingering_close(c);
- return;
- }
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if (!c->read->timer_set) {
- ngx_add_timer(c->read, clcf->keepalive_timeout);
- }
-
- ngx_reusable_connection(c, 1);
-
- if (h2c->state.incomplete) {
- return;
- }
-
- ngx_destroy_pool(h2c->pool);
-
- h2c->pool = NULL;
- h2c->free_frames = NULL;
- h2c->frames = 0;
- h2c->free_fake_connections = NULL;
-
-#if (NGX_HTTP_SSL)
- if (c->ssl) {
- ngx_ssl_free_buffer(c);
- }
-#endif
-
- c->destroyed = 1;
-
- c->write->handler = ngx_http_empty_handler;
- c->read->handler = ngx_http_v2_idle_handler;
-
- if (c->write->timer_set) {
- ngx_del_timer(c->write);
- }
-}
-
-
-static void
-ngx_http_v2_lingering_close(ngx_connection_t *c)
-{
- ngx_event_t *rev, *wev;
- ngx_http_v2_connection_t *h2c;
- ngx_http_core_loc_conf_t *clcf;
-
- h2c = c->data;
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if (clcf->lingering_close == NGX_HTTP_LINGERING_OFF) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (h2c->lingering_time == 0) {
- h2c->lingering_time = ngx_time()
- + (time_t) (clcf->lingering_time / 1000);
- }
-
-#if (NGX_HTTP_SSL)
- if (c->ssl) {
- ngx_int_t rc;
-
- rc = ngx_ssl_shutdown(c);
-
- if (rc == NGX_ERROR) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (rc == NGX_AGAIN) {
- c->ssl->handler = ngx_http_v2_lingering_close;
- return;
- }
- }
-#endif
-
- rev = c->read;
- rev->handler = ngx_http_v2_lingering_close_handler;
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
-
- wev = c->write;
- wev->handler = ngx_http_empty_handler;
-
- if (wev->active && (ngx_event_flags & NGX_USE_LEVEL_EVENT)) {
- if (ngx_del_event(wev, NGX_WRITE_EVENT, 0) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
- }
-
- if (ngx_shutdown_socket(c->fd, NGX_WRITE_SHUTDOWN) == -1) {
- ngx_connection_error(c, ngx_socket_errno,
- ngx_shutdown_socket_n " failed");
- ngx_http_close_connection(c);
- return;
- }
-
- c->close = 0;
- ngx_reusable_connection(c, 1);
-
- ngx_add_timer(rev, clcf->lingering_timeout);
-
- if (rev->ready) {
- ngx_http_v2_lingering_close_handler(rev);
- }
-}
-
-
-static void
-ngx_http_v2_lingering_close_handler(ngx_event_t *rev)
-{
- ssize_t n;
- ngx_msec_t timer;
- ngx_connection_t *c;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_v2_connection_t *h2c;
- u_char buffer[NGX_HTTP_LINGERING_BUFFER_SIZE];
-
- c = rev->data;
- h2c = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http2 lingering close handler");
-
- if (rev->timedout || c->close) {
- ngx_http_close_connection(c);
- return;
- }
-
- timer = (ngx_msec_t) h2c->lingering_time - (ngx_msec_t) ngx_time();
- if ((ngx_msec_int_t) timer <= 0) {
- ngx_http_close_connection(c);
- return;
- }
-
- do {
- n = c->recv(c, buffer, NGX_HTTP_LINGERING_BUFFER_SIZE);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "lingering read: %z", n);
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- if (n == NGX_ERROR || n == 0) {
- ngx_http_close_connection(c);
- return;
- }
-
- } while (rev->ready);
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
- timer *= 1000;
-
- if (timer > clcf->lingering_timeout) {
- timer = clcf->lingering_timeout;
- }
-
- ngx_add_timer(rev, timer);
-}
-
-
-static u_char *
-ngx_http_v2_state_preface(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- static const u_char preface[] = NGX_HTTP_V2_PREFACE_START;
-
- if ((size_t) (end - pos) < sizeof(preface) - 1) {
- return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_preface);
- }
-
- if (ngx_memcmp(pos, preface, sizeof(preface) - 1) != 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "invalid connection preface");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- return ngx_http_v2_state_preface_end(h2c, pos + sizeof(preface) - 1, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_preface_end(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- static const u_char preface[] = NGX_HTTP_V2_PREFACE_END;
-
- if ((size_t) (end - pos) < sizeof(preface) - 1) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_preface_end);
- }
-
- if (ngx_memcmp(pos, preface, sizeof(preface) - 1) != 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "invalid connection preface");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 preface verified");
-
- return ngx_http_v2_state_head(h2c, pos + sizeof(preface) - 1, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_head(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end)
-{
- uint32_t head;
- ngx_uint_t type;
-
- if (end - pos < NGX_HTTP_V2_FRAME_HEADER_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_head);
- }
-
- head = ngx_http_v2_parse_uint32(pos);
-
- h2c->state.length = ngx_http_v2_parse_length(head);
- h2c->state.flags = pos[4];
-
- h2c->state.sid = ngx_http_v2_parse_sid(&pos[5]);
-
- pos += NGX_HTTP_V2_FRAME_HEADER_SIZE;
-
- type = ngx_http_v2_parse_type(head);
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 frame type:%ui f:%Xd l:%uz sid:%ui",
- type, h2c->state.flags, h2c->state.length, h2c->state.sid);
-
- if (type >= NGX_HTTP_V2_FRAME_STATES) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent frame with unknown type %ui", type);
- return ngx_http_v2_state_skip(h2c, pos, end);
- }
-
- return ngx_http_v2_frame_states[type](h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_data(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end)
-{
- size_t size;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
-
- size = h2c->state.length;
-
- if (h2c->state.flags & NGX_HTTP_V2_PADDED_FLAG) {
-
- if (h2c->state.length == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent padded DATA frame "
- "with incorrect length: 0");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos == 0) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_data);
- }
-
- h2c->state.padding = *pos++;
-
- if (h2c->state.padding >= size) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent padded DATA frame "
- "with incorrect length: %uz, padding: %uz",
- size, h2c->state.padding);
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- h2c->state.length -= 1 + h2c->state.padding;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 DATA frame");
-
- if (h2c->state.sid == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent DATA frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (size > h2c->recv_window) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client violated connection flow control: "
- "received DATA frame length %uz, available window %uz",
- size, h2c->recv_window);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR);
- }
-
- h2c->recv_window -= size;
-
- if (h2c->recv_window < NGX_HTTP_V2_MAX_WINDOW / 4) {
-
- if (ngx_http_v2_send_window_update(h2c, 0, NGX_HTTP_V2_MAX_WINDOW
- - h2c->recv_window)
- == NGX_ERROR)
- {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h2c->recv_window = NGX_HTTP_V2_MAX_WINDOW;
- }
-
- node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0);
-
- if (node == NULL || node->stream == NULL) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "unknown http2 stream");
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- stream = node->stream;
-
- if (size > stream->recv_window) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client violated flow control for stream %ui: "
- "received DATA frame length %uz, available window %uz",
- node->id, size, stream->recv_window);
-
- if (ngx_http_v2_terminate_stream(h2c, stream,
- NGX_HTTP_V2_FLOW_CTRL_ERROR)
- == NGX_ERROR)
- {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- stream->recv_window -= size;
-
- if (stream->no_flow_control
- && stream->recv_window < NGX_HTTP_V2_MAX_WINDOW / 4)
- {
- if (ngx_http_v2_send_window_update(h2c, node->id,
- NGX_HTTP_V2_MAX_WINDOW
- - stream->recv_window)
- == NGX_ERROR)
- {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- stream->recv_window = NGX_HTTP_V2_MAX_WINDOW;
- }
-
- if (stream->in_closed) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent DATA frame for half-closed stream %ui",
- node->id);
-
- if (ngx_http_v2_terminate_stream(h2c, stream,
- NGX_HTTP_V2_STREAM_CLOSED)
- == NGX_ERROR)
- {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- h2c->state.stream = stream;
-
- return ngx_http_v2_state_read_data(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_read_data(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t size;
- ngx_buf_t *buf;
- ngx_int_t rc;
- ngx_connection_t *fc;
- ngx_http_request_t *r;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
-
- stream = h2c->state.stream;
-
- if (stream == NULL) {
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- if (stream->skip_data) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "skipping http2 DATA frame");
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- r = stream->request;
- fc = r->connection;
-
- if (r->reading_body && !r->request_body_no_buffering) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "skipping http2 DATA frame");
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "skipping http2 DATA frame");
-
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- size = end - pos;
-
- if (size >= h2c->state.length) {
- size = h2c->state.length;
- stream->in_closed = h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG;
- }
-
- h2c->payload_bytes += size;
-
- if (r->request_body) {
- rc = ngx_http_v2_process_request_body(r, pos, size,
- stream->in_closed, 0);
-
- if (rc != NGX_OK && rc != NGX_AGAIN) {
- stream->skip_data = 1;
- ngx_http_finalize_request(r, rc);
- }
-
- ngx_http_run_posted_requests(fc);
-
- } else if (size) {
- buf = stream->preread;
-
- if (buf == NULL) {
- h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
-
- buf = ngx_create_temp_buf(r->pool, h2scf->preread_size);
- if (buf == NULL) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- stream->preread = buf;
- }
-
- if (size > (size_t) (buf->end - buf->last)) {
- ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0,
- "http2 preread buffer overflow");
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- buf->last = ngx_cpymem(buf->last, pos, size);
- }
-
- pos += size;
- h2c->state.length -= size;
-
- if (h2c->state.length) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_read_data);
- }
-
- if (h2c->state.padding) {
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_headers(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t size;
- ngx_uint_t padded, priority, depend, dependency, excl,
- weight;
- ngx_uint_t status;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_core_loc_conf_t *clcf;
-
- padded = h2c->state.flags & NGX_HTTP_V2_PADDED_FLAG;
- priority = h2c->state.flags & NGX_HTTP_V2_PRIORITY_FLAG;
-
- size = 0;
-
- if (padded) {
- size++;
- }
-
- if (priority) {
- size += sizeof(uint32_t) + 1;
- }
-
- if (h2c->state.length < size) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent HEADERS frame with incorrect length %uz",
- h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (h2c->state.length == size) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent HEADERS frame with empty header block");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (h2c->goaway) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "skipping http2 HEADERS frame");
- return ngx_http_v2_state_skip(h2c, pos, end);
- }
-
- if ((size_t) (end - pos) < size) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_headers);
- }
-
- h2c->state.length -= size;
-
- if (padded) {
- h2c->state.padding = *pos++;
-
- if (h2c->state.padding > h2c->state.length) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent padded HEADERS frame "
- "with incorrect length: %uz, padding: %uz",
- h2c->state.length, h2c->state.padding);
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- h2c->state.length -= h2c->state.padding;
- }
-
- depend = 0;
- excl = 0;
- weight = NGX_HTTP_V2_DEFAULT_WEIGHT;
-
- if (priority) {
- dependency = ngx_http_v2_parse_uint32(pos);
-
- depend = dependency & 0x7fffffff;
- excl = dependency >> 31;
- weight = pos[4] + 1;
-
- pos += sizeof(uint32_t) + 1;
- }
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 HEADERS frame sid:%ui "
- "depends on %ui excl:%ui weight:%ui",
- h2c->state.sid, depend, excl, weight);
-
- if (h2c->state.sid % 2 == 0 || h2c->state.sid <= h2c->last_sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent HEADERS frame with incorrect identifier "
- "%ui, the last was %ui", h2c->state.sid, h2c->last_sid);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (depend == h2c->state.sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent HEADERS frame for stream %ui "
- "with incorrect dependency", h2c->state.sid);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- h2c->last_sid = h2c->state.sid;
-
- h2c->state.pool = ngx_create_pool(1024, h2c->connection->log);
- if (h2c->state.pool == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- h2c->state.header_limit = cscf->large_client_header_buffers.size
- * cscf->large_client_header_buffers.num;
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- if (h2c->processing >= h2scf->concurrent_streams) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "concurrent streams exceeded %ui", h2c->processing);
-
- status = NGX_HTTP_V2_REFUSED_STREAM;
- goto rst_stream;
- }
-
- if (h2c->new_streams++ >= 2 * h2scf->concurrent_streams) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent too many streams at once");
-
- status = NGX_HTTP_V2_REFUSED_STREAM;
- goto rst_stream;
- }
-
- if (!h2c->settings_ack
- && !(h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG)
- && h2scf->preread_size < NGX_HTTP_V2_DEFAULT_WINDOW)
- {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent stream with data "
- "before settings were acknowledged");
-
- status = NGX_HTTP_V2_REFUSED_STREAM;
- goto rst_stream;
- }
-
- node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1);
-
- if (node == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- if (node->parent) {
- ngx_queue_remove(&node->reuse);
- h2c->closed_nodes--;
- }
-
- stream = ngx_http_v2_create_stream(h2c);
- if (stream == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h2c->state.stream = stream;
-
- stream->pool = h2c->state.pool;
- h2c->state.keep_pool = 1;
-
- stream->request->request_length = h2c->state.length;
-
- stream->in_closed = h2c->state.flags & NGX_HTTP_V2_END_STREAM_FLAG;
- stream->node = node;
-
- node->stream = stream;
-
- if (priority || node->parent == NULL) {
- node->weight = weight;
- ngx_http_v2_set_dependency(h2c, node, depend, excl);
- }
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if (clcf->keepalive_timeout == 0
- || h2c->connection->requests >= clcf->keepalive_requests
- || ngx_current_msec - h2c->connection->start_time
- > clcf->keepalive_time)
- {
- h2c->goaway = 1;
-
- if (ngx_http_v2_send_goaway(h2c, NGX_HTTP_V2_NO_ERROR) == NGX_ERROR) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
- }
-
- return ngx_http_v2_state_header_block(h2c, pos, end);
-
-rst_stream:
-
- if (h2c->refused_streams++ > ngx_max(h2scf->concurrent_streams, 100)) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent too many refused streams");
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_NO_ERROR);
- }
-
- if (ngx_http_v2_send_rst_stream(h2c, h2c->state.sid, status) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- return ngx_http_v2_state_header_block(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_header_block(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- u_char ch;
- ngx_int_t value;
- ngx_uint_t indexed, size_update, prefix;
-
- if (end - pos < 1) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_header_block);
- }
-
- if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)
- && h2c->state.length < NGX_HTTP_V2_INT_OCTETS)
- {
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_header_block);
- }
-
- size_update = 0;
- indexed = 0;
-
- ch = *pos;
-
- if (ch >= (1 << 7)) {
- /* indexed header field */
- indexed = 1;
- prefix = ngx_http_v2_prefix(7);
-
- } else if (ch >= (1 << 6)) {
- /* literal header field with incremental indexing */
- h2c->state.index = 1;
- prefix = ngx_http_v2_prefix(6);
-
- } else if (ch >= (1 << 5)) {
- /* dynamic table size update */
- size_update = 1;
- prefix = ngx_http_v2_prefix(5);
-
- } else if (ch >= (1 << 4)) {
- /* literal header field never indexed */
- prefix = ngx_http_v2_prefix(4);
-
- } else {
- /* literal header field without indexing */
- prefix = ngx_http_v2_prefix(4);
- }
-
- value = ngx_http_v2_parse_int(h2c, &pos, end, prefix);
-
- if (value < 0) {
- if (value == NGX_AGAIN) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_header_block);
- }
-
- if (value == NGX_DECLINED) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header block with too long %s value",
- size_update ? "size update" : "header index");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header block with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (indexed) {
- if (ngx_http_v2_get_indexed_header(h2c, value, 0) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- return ngx_http_v2_state_process_header(h2c, pos, end);
- }
-
- if (size_update) {
- if (ngx_http_v2_table_size(h2c, value) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- return ngx_http_v2_state_header_complete(h2c, pos, end);
- }
-
- if (value == 0) {
- h2c->state.parse_name = 1;
-
- } else if (ngx_http_v2_get_indexed_header(h2c, value, 1) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- h2c->state.parse_value = 1;
-
- return ngx_http_v2_state_field_len(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_field_len(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t alloc;
- ngx_int_t len;
- ngx_uint_t huff;
- ngx_http_core_srv_conf_t *cscf;
-
- if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)
- && h2c->state.length < NGX_HTTP_V2_INT_OCTETS)
- {
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_field_len);
- }
-
- if (h2c->state.length < 1) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header block with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos < 1) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_field_len);
- }
-
- huff = *pos >> 7;
- len = ngx_http_v2_parse_int(h2c, &pos, end, ngx_http_v2_prefix(7));
-
- if (len < 0) {
- if (len == NGX_AGAIN) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_field_len);
- }
-
- if (len == NGX_DECLINED) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header field with too long length value");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header block with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 %s string, len:%i",
- huff ? "encoded" : "raw", len);
-
- cscf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if ((size_t) len > cscf->large_client_header_buffers.size) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent too large header field");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
- }
-
- h2c->state.field_rest = len;
-
- if (h2c->state.stream == NULL && !h2c->state.index) {
- return ngx_http_v2_state_field_skip(h2c, pos, end);
- }
-
- alloc = (huff ? len * 8 / 5 : len) + 1;
-
- h2c->state.field_start = ngx_pnalloc(h2c->state.pool, alloc);
- if (h2c->state.field_start == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h2c->state.field_end = h2c->state.field_start;
-
- if (huff) {
- return ngx_http_v2_state_field_huff(h2c, pos, end);
- }
-
- return ngx_http_v2_state_field_raw(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_field_huff(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t size;
-
- size = end - pos;
-
- if (size > h2c->state.field_rest) {
- size = h2c->state.field_rest;
- }
-
- if (size > h2c->state.length) {
- size = h2c->state.length;
- }
-
- h2c->state.length -= size;
- h2c->state.field_rest -= size;
-
- if (ngx_http_huff_decode(&h2c->state.field_state, pos, size,
- &h2c->state.field_end,
- h2c->state.field_rest == 0,
- h2c->connection->log)
- != NGX_OK)
- {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent invalid encoded header field");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_COMP_ERROR);
- }
-
- pos += size;
-
- if (h2c->state.field_rest == 0) {
- *h2c->state.field_end = '\0';
- return ngx_http_v2_state_process_header(h2c, pos, end);
- }
-
- if (h2c->state.length) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_field_huff);
- }
-
- if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header field with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_field_huff);
-}
-
-
-static u_char *
-ngx_http_v2_state_field_raw(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t size;
-
- size = end - pos;
-
- if (size > h2c->state.field_rest) {
- size = h2c->state.field_rest;
- }
-
- if (size > h2c->state.length) {
- size = h2c->state.length;
- }
-
- h2c->state.length -= size;
- h2c->state.field_rest -= size;
-
- h2c->state.field_end = ngx_cpymem(h2c->state.field_end, pos, size);
-
- pos += size;
-
- if (h2c->state.field_rest == 0) {
- *h2c->state.field_end = '\0';
- return ngx_http_v2_state_process_header(h2c, pos, end);
- }
-
- if (h2c->state.length) {
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_field_raw);
- }
-
- if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header field with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_field_raw);
-}
-
-
-static u_char *
-ngx_http_v2_state_field_skip(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t size;
-
- size = end - pos;
-
- if (size > h2c->state.field_rest) {
- size = h2c->state.field_rest;
- }
-
- if (size > h2c->state.length) {
- size = h2c->state.length;
- }
-
- h2c->state.length -= size;
- h2c->state.field_rest -= size;
-
- pos += size;
-
- if (h2c->state.field_rest == 0) {
- return ngx_http_v2_state_process_header(h2c, pos, end);
- }
-
- if (h2c->state.length) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_field_skip);
- }
-
- if (h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent header field with incorrect length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_field_skip);
-}
-
-
-static u_char *
-ngx_http_v2_state_process_header(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t len;
- ngx_int_t rc;
- ngx_table_elt_t *h;
- ngx_connection_t *fc;
- ngx_http_header_t *hh;
- ngx_http_request_t *r;
- ngx_http_v2_header_t *header;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_core_main_conf_t *cmcf;
-
- static ngx_str_t cookie = ngx_string("cookie");
-
- header = &h2c->state.header;
-
- if (h2c->state.parse_name) {
- h2c->state.parse_name = 0;
-
- header->name.len = h2c->state.field_end - h2c->state.field_start;
- header->name.data = h2c->state.field_start;
-
- if (header->name.len == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent zero header name length");
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- return ngx_http_v2_state_field_len(h2c, pos, end);
- }
-
- if (h2c->state.parse_value) {
- h2c->state.parse_value = 0;
-
- header->value.len = h2c->state.field_end - h2c->state.field_start;
- header->value.data = h2c->state.field_start;
- }
-
- len = header->name.len + header->value.len;
-
- if (len > h2c->state.header_limit) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent too large header");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
- }
-
- h2c->state.header_limit -= len;
-
- if (h2c->state.index) {
- if (ngx_http_v2_add_header(h2c, header) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h2c->state.index = 0;
- }
-
- if (h2c->state.stream == NULL) {
- return ngx_http_v2_state_header_complete(h2c, pos, end);
- }
-
- r = h2c->state.stream->request;
- fc = r->connection;
-
- /* TODO Optimization: validate headers while parsing. */
- if (ngx_http_v2_validate_header(r, header) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto error;
- }
-
- if (header->name.data[0] == ':') {
- rc = ngx_http_v2_pseudo_header(r, header);
-
- if (rc == NGX_OK) {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http2 header: \":%V: %V\"",
- &header->name, &header->value);
-
- return ngx_http_v2_state_header_complete(h2c, pos, end);
- }
-
- if (rc == NGX_ABORT) {
- goto error;
- }
-
- if (rc == NGX_DECLINED) {
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto error;
- }
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- if (r->invalid_header) {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- if (cscf->ignore_invalid_headers) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid header: \"%V\"", &header->name);
-
- return ngx_http_v2_state_header_complete(h2c, pos, end);
- }
- }
-
- if (header->name.len == cookie.len
- && ngx_memcmp(header->name.data, cookie.data, cookie.len) == 0)
- {
- if (ngx_http_v2_cookie(r, header) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- } else {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- if (r->headers_in.count++ >= cscf->max_headers) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent too many header lines");
- ngx_http_finalize_request(r, NGX_HTTP_REQUEST_HEADER_TOO_LARGE);
- goto error;
- }
-
- h = ngx_list_push(&r->headers_in.headers);
- if (h == NULL) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h->key.len = header->name.len;
- h->key.data = header->name.data;
-
- /*
- * TODO Optimization: precalculate hash
- * and handler for indexed headers.
- */
- h->hash = ngx_hash_key(h->key.data, h->key.len);
-
- h->value.len = header->value.len;
- h->value.data = header->value.data;
-
- h->lowcase_key = h->key.data;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
- h->lowcase_key, h->key.len);
-
- if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
- goto error;
- }
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http2 header: \"%V: %V\"",
- &header->name, &header->value);
-
- return ngx_http_v2_state_header_complete(h2c, pos, end);
-
-error:
-
- h2c->state.stream = NULL;
-
- ngx_http_run_posted_requests(fc);
-
- return ngx_http_v2_state_header_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_header_complete(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_http_v2_stream_t *stream;
-
- if (h2c->state.length) {
- if (end - pos > 0) {
- h2c->state.handler = ngx_http_v2_state_header_block;
- return pos;
- }
-
- return ngx_http_v2_state_headers_save(h2c, pos, end,
- ngx_http_v2_state_header_block);
- }
-
- if (!(h2c->state.flags & NGX_HTTP_V2_END_HEADERS_FLAG)) {
- return ngx_http_v2_handle_continuation(h2c, pos, end,
- ngx_http_v2_state_header_complete);
- }
-
- stream = h2c->state.stream;
-
- if (stream) {
- ngx_http_v2_run_request(stream->request);
- }
-
- if (!h2c->state.keep_pool) {
- ngx_destroy_pool(h2c->state.pool);
- }
-
- h2c->state.pool = NULL;
- h2c->state.keep_pool = 0;
-
- if (h2c->state.padding) {
- return ngx_http_v2_state_skip_padded(h2c, pos, end);
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_handle_continuation(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end, ngx_http_v2_handler_pt handler)
-{
- u_char *p;
- size_t len, skip;
- uint32_t head;
-
- len = h2c->state.length;
-
- if (h2c->state.padding && (size_t) (end - pos) > len) {
- skip = ngx_min(h2c->state.padding, (end - pos) - len);
-
- h2c->state.padding -= skip;
-
- p = pos;
- pos += skip;
- ngx_memmove(pos, p, len);
- }
-
- if ((size_t) (end - pos) < len + NGX_HTTP_V2_FRAME_HEADER_SIZE) {
- return ngx_http_v2_state_headers_save(h2c, pos, end, handler);
- }
-
- p = pos + len;
-
- head = ngx_http_v2_parse_uint32(p);
-
- if (ngx_http_v2_parse_type(head) != NGX_HTTP_V2_CONTINUATION_FRAME) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent inappropriate frame while CONTINUATION was expected");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- h2c->state.flags |= p[4];
-
- if (h2c->state.sid != ngx_http_v2_parse_sid(&p[5])) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent CONTINUATION frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- p = pos;
- pos += NGX_HTTP_V2_FRAME_HEADER_SIZE;
-
- ngx_memcpy(pos, p, len);
-
- len = ngx_http_v2_parse_length(head);
-
- h2c->state.length += len;
-
- if (h2c->state.stream) {
- h2c->state.stream->request->request_length += len;
- }
-
- h2c->state.handler = handler;
- return pos;
-}
-
-
-static u_char *
-ngx_http_v2_state_priority(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_uint_t depend, dependency, excl, weight;
- ngx_http_v2_node_t *node;
-
- if (h2c->state.length != NGX_HTTP_V2_PRIORITY_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PRIORITY frame with incorrect length %uz",
- h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (--h2c->priority_limit == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent too many PRIORITY frames");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_ENHANCE_YOUR_CALM);
- }
-
- if (end - pos < NGX_HTTP_V2_PRIORITY_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_priority);
- }
-
- dependency = ngx_http_v2_parse_uint32(pos);
-
- depend = dependency & 0x7fffffff;
- excl = dependency >> 31;
- weight = pos[4] + 1;
-
- pos += NGX_HTTP_V2_PRIORITY_SIZE;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 PRIORITY frame sid:%ui "
- "depends on %ui excl:%ui weight:%ui",
- h2c->state.sid, depend, excl, weight);
-
- if (h2c->state.sid == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PRIORITY frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (depend == h2c->state.sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PRIORITY frame for stream %ui "
- "with incorrect dependency", h2c->state.sid);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 1);
-
- if (node == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- node->weight = weight;
-
- if (node->stream == NULL) {
- if (node->parent == NULL) {
- h2c->closed_nodes++;
-
- } else {
- ngx_queue_remove(&node->reuse);
- }
-
- ngx_queue_insert_tail(&h2c->closed, &node->reuse);
- }
-
- ngx_http_v2_set_dependency(h2c, node, depend, excl);
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_rst_stream(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_uint_t status;
- ngx_event_t *ev;
- ngx_connection_t *fc;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
-
- if (h2c->state.length != NGX_HTTP_V2_RST_STREAM_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent RST_STREAM frame with incorrect length %uz",
- h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos < NGX_HTTP_V2_RST_STREAM_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_rst_stream);
- }
-
- status = ngx_http_v2_parse_uint32(pos);
-
- pos += NGX_HTTP_V2_RST_STREAM_SIZE;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 RST_STREAM frame, sid:%ui status:%ui",
- h2c->state.sid, status);
-
- if (h2c->state.sid == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent RST_STREAM frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0);
-
- if (node == NULL || node->stream == NULL) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "unknown http2 stream");
-
- return ngx_http_v2_state_complete(h2c, pos, end);
- }
-
- stream = node->stream;
-
- stream->in_closed = 1;
- stream->out_closed = 1;
-
- fc = stream->request->connection;
- fc->error = 1;
-
- switch (status) {
-
- case NGX_HTTP_V2_CANCEL:
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client canceled stream %ui", h2c->state.sid);
- break;
-
- case NGX_HTTP_V2_INTERNAL_ERROR:
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client terminated stream %ui due to internal error",
- h2c->state.sid);
- break;
-
- default:
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client terminated stream %ui with status %ui",
- h2c->state.sid, status);
- break;
- }
-
- ev = fc->read;
- ev->handler(ev);
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_settings(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 SETTINGS frame");
-
- if (h2c->state.sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (h2c->state.flags == NGX_HTTP_V2_ACK_FLAG) {
-
- if (h2c->state.length != 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with the ACK flag "
- "and nonzero length");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- h2c->settings_ack = 1;
-
- return ngx_http_v2_state_complete(h2c, pos, end);
- }
-
- if (h2c->state.length % NGX_HTTP_V2_SETTINGS_PARAM_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with incorrect length %uz",
- h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- return ngx_http_v2_state_settings_params(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_settings_params(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ssize_t window_delta;
- ngx_uint_t id, value;
- ngx_http_v2_out_frame_t *frame;
-
- window_delta = 0;
-
- while (h2c->state.length) {
- if (end - pos < NGX_HTTP_V2_SETTINGS_PARAM_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_settings_params);
- }
-
- h2c->state.length -= NGX_HTTP_V2_SETTINGS_PARAM_SIZE;
-
- id = ngx_http_v2_parse_uint16(pos);
- value = ngx_http_v2_parse_uint32(&pos[2]);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 setting %ui:%ui", id, value);
-
- switch (id) {
-
- case NGX_HTTP_V2_INIT_WINDOW_SIZE_SETTING:
-
- if (value > NGX_HTTP_V2_MAX_WINDOW) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with incorrect "
- "INITIAL_WINDOW_SIZE value %ui", value);
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_FLOW_CTRL_ERROR);
- }
-
- window_delta = value - h2c->init_window;
- break;
-
- case NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING:
-
- if (value > NGX_HTTP_V2_MAX_FRAME_SIZE
- || value < NGX_HTTP_V2_DEFAULT_FRAME_SIZE)
- {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with incorrect "
- "MAX_FRAME_SIZE value %ui", value);
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- h2c->frame_size = value;
- break;
-
- case NGX_HTTP_V2_ENABLE_PUSH_SETTING:
-
- if (value > 1) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent SETTINGS frame with incorrect "
- "ENABLE_PUSH value %ui", value);
-
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- break;
-
- case NGX_HTTP_V2_HEADER_TABLE_SIZE_SETTING:
-
- h2c->table_update = 1;
- break;
-
- default:
- break;
- }
-
- pos += NGX_HTTP_V2_SETTINGS_PARAM_SIZE;
- }
-
- frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_SETTINGS_ACK_SIZE,
- NGX_HTTP_V2_SETTINGS_FRAME,
- NGX_HTTP_V2_ACK_FLAG, 0);
- if (frame == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- ngx_http_v2_queue_ordered_frame(h2c, frame);
-
- if (window_delta) {
- h2c->init_window += window_delta;
-
- if (ngx_http_v2_adjust_windows(h2c, window_delta) != NGX_OK) {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_push_promise(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PUSH_PROMISE frame");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
-}
-
-
-static u_char *
-ngx_http_v2_state_ping(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end)
-{
- ngx_buf_t *buf;
- ngx_http_v2_out_frame_t *frame;
-
- if (h2c->state.length != NGX_HTTP_V2_PING_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PING frame with incorrect length %uz",
- h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos < NGX_HTTP_V2_PING_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_ping);
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 PING frame");
-
- if (h2c->state.sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent PING frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (h2c->state.flags & NGX_HTTP_V2_ACK_FLAG) {
- return ngx_http_v2_state_skip(h2c, pos, end);
- }
-
- frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_PING_SIZE,
- NGX_HTTP_V2_PING_FRAME,
- NGX_HTTP_V2_ACK_FLAG, 0);
- if (frame == NULL) {
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- buf = frame->first->buf;
-
- buf->last = ngx_cpymem(buf->last, pos, NGX_HTTP_V2_PING_SIZE);
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- return ngx_http_v2_state_complete(h2c, pos + NGX_HTTP_V2_PING_SIZE, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_goaway(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
-#if (NGX_DEBUG)
- ngx_uint_t last_sid, error;
-#endif
-
- if (h2c->state.length < NGX_HTTP_V2_GOAWAY_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent GOAWAY frame "
- "with incorrect length %uz", h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos < NGX_HTTP_V2_GOAWAY_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end, ngx_http_v2_state_goaway);
- }
-
- if (h2c->state.sid) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent GOAWAY frame with incorrect identifier");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
-#if (NGX_DEBUG)
- h2c->state.length -= NGX_HTTP_V2_GOAWAY_SIZE;
-
- last_sid = ngx_http_v2_parse_sid(pos);
- error = ngx_http_v2_parse_uint32(&pos[4]);
-
- pos += NGX_HTTP_V2_GOAWAY_SIZE;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 GOAWAY frame: last sid %ui, error %ui",
- last_sid, error);
-#endif
-
- return ngx_http_v2_state_skip(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_window_update(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- size_t window;
- ngx_event_t *wev;
- ngx_queue_t *q;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
-
- if (h2c->state.length != NGX_HTTP_V2_WINDOW_UPDATE_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent WINDOW_UPDATE frame "
- "with incorrect length %uz", h2c->state.length);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_SIZE_ERROR);
- }
-
- if (end - pos < NGX_HTTP_V2_WINDOW_UPDATE_SIZE) {
- return ngx_http_v2_state_save(h2c, pos, end,
- ngx_http_v2_state_window_update);
- }
-
- window = ngx_http_v2_parse_window(pos);
-
- pos += NGX_HTTP_V2_WINDOW_UPDATE_SIZE;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 WINDOW_UPDATE frame sid:%ui window:%uz",
- h2c->state.sid, window);
-
- if (window == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent WINDOW_UPDATE frame "
- "with incorrect window increment 0");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
- }
-
- if (h2c->state.sid) {
- node = ngx_http_v2_get_node_by_id(h2c, h2c->state.sid, 0);
-
- if (node == NULL || node->stream == NULL) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "unknown http2 stream");
-
- return ngx_http_v2_state_complete(h2c, pos, end);
- }
-
- stream = node->stream;
-
- if (window > (size_t) (NGX_HTTP_V2_MAX_WINDOW - stream->send_window)) {
-
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client violated flow control for stream %ui: "
- "received WINDOW_UPDATE frame "
- "with window increment %uz "
- "not allowed for window %z",
- h2c->state.sid, window, stream->send_window);
-
- if (ngx_http_v2_terminate_stream(h2c, stream,
- NGX_HTTP_V2_FLOW_CTRL_ERROR)
- == NGX_ERROR)
- {
- return ngx_http_v2_connection_error(h2c,
- NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
- }
-
- stream->send_window += window;
-
- if (stream->exhausted) {
- stream->exhausted = 0;
-
- wev = stream->request->connection->write;
-
- wev->active = 0;
- wev->ready = 1;
-
- if (!wev->delayed) {
- wev->handler(wev);
- }
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
- }
-
- if (window > NGX_HTTP_V2_MAX_WINDOW - h2c->send_window) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client violated connection flow control: "
- "received WINDOW_UPDATE frame "
- "with window increment %uz "
- "not allowed for window %uz",
- window, h2c->send_window);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_FLOW_CTRL_ERROR);
- }
-
- h2c->send_window += window;
-
- while (!ngx_queue_empty(&h2c->waiting)) {
- q = ngx_queue_head(&h2c->waiting);
-
- ngx_queue_remove(q);
-
- stream = ngx_queue_data(q, ngx_http_v2_stream_t, queue);
-
- stream->waiting = 0;
-
- wev = stream->request->connection->write;
-
- wev->active = 0;
- wev->ready = 1;
-
- if (!wev->delayed) {
- wev->handler(wev);
-
- if (h2c->send_window == 0) {
- break;
- }
- }
- }
-
- return ngx_http_v2_state_complete(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_continuation(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent unexpected CONTINUATION frame");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_PROTOCOL_ERROR);
-}
-
-
-static u_char *
-ngx_http_v2_state_complete(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 frame complete pos:%p end:%p", pos, end);
-
- if (pos > end) {
- ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0,
- "receive buffer overrun");
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- h2c->state.stream = NULL;
- h2c->state.handler = ngx_http_v2_state_head;
-
- return pos;
-}
-
-
-static u_char *
-ngx_http_v2_state_skip_padded(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end)
-{
- h2c->state.length += h2c->state.padding;
- h2c->state.padding = 0;
-
- return ngx_http_v2_state_skip(h2c, pos, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_skip(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end)
-{
- size_t size;
-
- size = end - pos;
-
- if (size < h2c->state.length) {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 frame skip %uz of %uz", size, h2c->state.length);
-
- h2c->state.length -= size;
- return ngx_http_v2_state_save(h2c, end, end, ngx_http_v2_state_skip);
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 frame skip %uz", h2c->state.length);
-
- return ngx_http_v2_state_complete(h2c, pos + h2c->state.length, end);
-}
-
-
-static u_char *
-ngx_http_v2_state_save(ngx_http_v2_connection_t *h2c, u_char *pos, u_char *end,
- ngx_http_v2_handler_pt handler)
-{
- size_t size;
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 frame state save pos:%p end:%p handler:%p",
- pos, end, handler);
-
- size = end - pos;
-
- if (size > NGX_HTTP_V2_STATE_BUFFER_SIZE) {
- ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0,
- "state buffer overflow: %uz bytes required", size);
-
- return ngx_http_v2_connection_error(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- }
-
- ngx_memcpy(h2c->state.buffer, pos, size);
-
- h2c->state.buffer_used = size;
- h2c->state.handler = handler;
- h2c->state.incomplete = 1;
-
- return end;
-}
-
-
-static u_char *
-ngx_http_v2_state_headers_save(ngx_http_v2_connection_t *h2c, u_char *pos,
- u_char *end, ngx_http_v2_handler_pt handler)
-{
- ngx_event_t *rev;
- ngx_http_request_t *r;
- ngx_http_core_srv_conf_t *cscf;
-
- if (h2c->state.stream) {
- r = h2c->state.stream->request;
- rev = r->connection->read;
-
- if (!rev->timer_set) {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
- ngx_add_timer(rev, cscf->client_header_timeout);
- }
- }
-
- return ngx_http_v2_state_save(h2c, pos, end, handler);
-}
-
-
-static u_char *
-ngx_http_v2_connection_error(ngx_http_v2_connection_t *h2c,
- ngx_uint_t err)
-{
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 state connection error");
-
- ngx_http_v2_finalize_connection(h2c, err);
-
- return NULL;
-}
-
-
-static ngx_int_t
-ngx_http_v2_parse_int(ngx_http_v2_connection_t *h2c, u_char **pos, u_char *end,
- ngx_uint_t prefix)
-{
- u_char *start, *p;
- ngx_uint_t value, octet, shift;
-
- start = *pos;
- p = start;
-
- value = *p++ & prefix;
-
- if (value != prefix) {
- if (h2c->state.length == 0) {
- return NGX_ERROR;
- }
-
- h2c->state.length--;
-
- *pos = p;
- return value;
- }
-
- if (end - start > NGX_HTTP_V2_INT_OCTETS) {
- end = start + NGX_HTTP_V2_INT_OCTETS;
- }
-
- for (shift = 0; p != end; shift += 7) {
- octet = *p++;
-
- value += (octet & 0x7f) << shift;
-
- if (octet < 128) {
- if ((size_t) (p - start) > h2c->state.length) {
- return NGX_ERROR;
- }
-
- h2c->state.length -= p - start;
-
- *pos = p;
- return value;
- }
- }
-
- if ((size_t) (end - start) >= h2c->state.length) {
- return NGX_ERROR;
- }
-
- if (end == start + NGX_HTTP_V2_INT_OCTETS) {
- return NGX_DECLINED;
- }
-
- return NGX_AGAIN;
-}
-
-
-static ngx_int_t
-ngx_http_v2_send_settings(ngx_http_v2_connection_t *h2c)
-{
- size_t len;
- ngx_buf_t *buf;
- ngx_chain_t *cl;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_v2_out_frame_t *frame;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 send SETTINGS frame");
-
- frame = ngx_palloc(h2c->pool, sizeof(ngx_http_v2_out_frame_t));
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- cl = ngx_alloc_chain_link(h2c->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- len = NGX_HTTP_V2_SETTINGS_PARAM_SIZE * 3;
-
- buf = ngx_create_temp_buf(h2c->pool, NGX_HTTP_V2_FRAME_HEADER_SIZE + len);
- if (buf == NULL) {
- return NGX_ERROR;
- }
-
- buf->last_buf = 1;
-
- cl->buf = buf;
- cl->next = NULL;
-
- frame->first = cl;
- frame->last = cl;
- frame->handler = ngx_http_v2_settings_frame_handler;
- frame->stream = NULL;
-#if (NGX_DEBUG)
- frame->length = len;
-#endif
- frame->blocked = 0;
-
- buf->last = ngx_http_v2_write_len_and_type(buf->last, len,
- NGX_HTTP_V2_SETTINGS_FRAME);
-
- *buf->last++ = NGX_HTTP_V2_NO_FLAG;
-
- buf->last = ngx_http_v2_write_sid(buf->last, 0);
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
- NGX_HTTP_V2_MAX_STREAMS_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last,
- h2scf->concurrent_streams);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
- NGX_HTTP_V2_INIT_WINDOW_SIZE_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last, h2scf->preread_size);
-
- buf->last = ngx_http_v2_write_uint16(buf->last,
- NGX_HTTP_V2_MAX_FRAME_SIZE_SETTING);
- buf->last = ngx_http_v2_write_uint32(buf->last,
- NGX_HTTP_V2_MAX_FRAME_SIZE);
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_settings_frame_handler(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_buf_t *buf;
-
- buf = frame->first->buf;
-
- if (buf->pos != buf->last) {
- return NGX_AGAIN;
- }
-
- ngx_free_chain(h2c->pool, frame->first);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_send_window_update(ngx_http_v2_connection_t *h2c, ngx_uint_t sid,
- size_t window)
-{
- ngx_buf_t *buf;
- ngx_http_v2_out_frame_t *frame;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 send WINDOW_UPDATE frame sid:%ui, window:%uz",
- sid, window);
-
- frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_WINDOW_UPDATE_SIZE,
- NGX_HTTP_V2_WINDOW_UPDATE_FRAME,
- NGX_HTTP_V2_NO_FLAG, sid);
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- buf = frame->first->buf;
-
- buf->last = ngx_http_v2_write_uint32(buf->last, window);
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_send_rst_stream(ngx_http_v2_connection_t *h2c, ngx_uint_t sid,
- ngx_uint_t status)
-{
- ngx_buf_t *buf;
- ngx_http_v2_out_frame_t *frame;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 send RST_STREAM frame sid:%ui, status:%ui",
- sid, status);
-
- frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_RST_STREAM_SIZE,
- NGX_HTTP_V2_RST_STREAM_FRAME,
- NGX_HTTP_V2_NO_FLAG, sid);
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- buf = frame->first->buf;
-
- buf->last = ngx_http_v2_write_uint32(buf->last, status);
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_send_goaway(ngx_http_v2_connection_t *h2c, ngx_uint_t status)
-{
- ngx_buf_t *buf;
- ngx_http_v2_out_frame_t *frame;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 send GOAWAY frame: last sid %ui, error %ui",
- h2c->last_sid, status);
-
- frame = ngx_http_v2_get_frame(h2c, NGX_HTTP_V2_GOAWAY_SIZE,
- NGX_HTTP_V2_GOAWAY_FRAME,
- NGX_HTTP_V2_NO_FLAG, 0);
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- buf = frame->first->buf;
-
- buf->last = ngx_http_v2_write_sid(buf->last, h2c->last_sid);
- buf->last = ngx_http_v2_write_uint32(buf->last, status);
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- return NGX_OK;
-}
-
-
-static ngx_http_v2_out_frame_t *
-ngx_http_v2_get_frame(ngx_http_v2_connection_t *h2c, size_t length,
- ngx_uint_t type, u_char flags, ngx_uint_t sid)
-{
- ngx_buf_t *buf;
- ngx_pool_t *pool;
- ngx_http_v2_out_frame_t *frame;
-
- frame = h2c->free_frames;
-
- if (frame) {
- h2c->free_frames = frame->next;
-
- buf = frame->first->buf;
- buf->pos = buf->start;
-
- frame->blocked = 0;
-
- } else if (h2c->frames < 10000) {
- pool = h2c->pool ? h2c->pool : h2c->connection->pool;
-
- frame = ngx_pcalloc(pool, sizeof(ngx_http_v2_out_frame_t));
- if (frame == NULL) {
- return NULL;
- }
-
- frame->first = ngx_alloc_chain_link(pool);
- if (frame->first == NULL) {
- return NULL;
- }
-
- buf = ngx_create_temp_buf(pool, NGX_HTTP_V2_FRAME_BUFFER_SIZE);
- if (buf == NULL) {
- return NULL;
- }
-
- buf->last_buf = 1;
-
- frame->first->buf = buf;
- frame->last = frame->first;
-
- frame->handler = ngx_http_v2_frame_handler;
-
- h2c->frames++;
-
- } else {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "http2 flood detected");
-
- h2c->connection->error = 1;
- return NULL;
- }
-
-#if (NGX_DEBUG)
- if (length > NGX_HTTP_V2_FRAME_BUFFER_SIZE - NGX_HTTP_V2_FRAME_HEADER_SIZE)
- {
- ngx_log_error(NGX_LOG_ALERT, h2c->connection->log, 0,
- "requested control frame is too large: %uz", length);
- return NULL;
- }
-#endif
-
- frame->length = length;
-
- buf->last = ngx_http_v2_write_len_and_type(buf->pos, length, type);
-
- *buf->last++ = flags;
-
- buf->last = ngx_http_v2_write_sid(buf->last, sid);
-
- return frame;
-}
-
-
-static ngx_int_t
-ngx_http_v2_frame_handler(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_buf_t *buf;
-
- buf = frame->first->buf;
-
- if (buf->pos != buf->last) {
- return NGX_AGAIN;
- }
-
- frame->next = h2c->free_frames;
- h2c->free_frames = frame;
-
- h2c->total_bytes += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
-
- return NGX_OK;
-}
-
-
-static ngx_http_v2_stream_t *
-ngx_http_v2_create_stream(ngx_http_v2_connection_t *h2c)
-{
- ngx_log_t *log;
- ngx_event_t *rev, *wev;
- ngx_connection_t *fc;
- ngx_http_log_ctx_t *ctx;
- ngx_http_request_t *r;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_core_srv_conf_t *cscf;
-
- fc = h2c->free_fake_connections;
-
- if (fc) {
- h2c->free_fake_connections = fc->data;
-
- rev = fc->read;
- wev = fc->write;
- log = fc->log;
- ctx = log->data;
-
- } else {
- fc = ngx_palloc(h2c->pool, sizeof(ngx_connection_t));
- if (fc == NULL) {
- return NULL;
- }
-
- rev = ngx_palloc(h2c->pool, sizeof(ngx_event_t));
- if (rev == NULL) {
- return NULL;
- }
-
- wev = ngx_palloc(h2c->pool, sizeof(ngx_event_t));
- if (wev == NULL) {
- return NULL;
- }
-
- log = ngx_palloc(h2c->pool, sizeof(ngx_log_t));
- if (log == NULL) {
- return NULL;
- }
-
- ctx = ngx_palloc(h2c->pool, sizeof(ngx_http_log_ctx_t));
- if (ctx == NULL) {
- return NULL;
- }
-
- ctx->connection = fc;
- ctx->request = NULL;
- ctx->current_request = NULL;
- }
-
- ngx_memcpy(log, h2c->connection->log, sizeof(ngx_log_t));
-
- log->data = ctx;
- log->action = "reading client request headers";
-
- ngx_memzero(rev, sizeof(ngx_event_t));
-
- rev->data = fc;
- rev->ready = 1;
- rev->handler = ngx_http_v2_close_stream_handler;
- rev->log = log;
-
- ngx_memcpy(wev, rev, sizeof(ngx_event_t));
-
- wev->write = 1;
-
- ngx_memcpy(fc, h2c->connection, sizeof(ngx_connection_t));
-
- fc->data = h2c->http_connection;
- fc->read = rev;
- fc->write = wev;
- fc->sent = 0;
- fc->log = log;
- fc->buffered = 0;
- fc->sndlowat = 1;
- fc->tcp_nodelay = NGX_TCP_NODELAY_DISABLED;
-
- r = ngx_http_create_request(fc);
- if (r == NULL) {
- return NULL;
- }
-
- ngx_str_set(&r->http_protocol, "HTTP/2.0");
-
- r->http_version = NGX_HTTP_VERSION_20;
- r->valid_location = 1;
-
- fc->data = r;
- h2c->connection->requests++;
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- r->header_in = ngx_create_temp_buf(r->pool,
- cscf->client_header_buffer_size);
- if (r->header_in == NULL) {
- ngx_http_free_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NULL;
- }
-
- if (ngx_list_init(&r->headers_in.headers, r->pool, 20,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- ngx_http_free_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NULL;
- }
-
- r->headers_in.connection_type = NGX_HTTP_CONNECTION_CLOSE;
-
- stream = ngx_pcalloc(r->pool, sizeof(ngx_http_v2_stream_t));
- if (stream == NULL) {
- ngx_http_free_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NULL;
- }
-
- r->stream = stream;
-
- stream->request = r;
- stream->connection = h2c;
-
- h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
-
- stream->send_window = h2c->init_window;
- stream->recv_window = h2scf->preread_size;
-
- h2c->processing++;
-
- h2c->priority_limit += h2scf->concurrent_streams;
-
- if (h2c->connection->read->timer_set) {
- ngx_del_timer(h2c->connection->read);
- }
-
- return stream;
-}
-
-
-static ngx_http_v2_node_t *
-ngx_http_v2_get_node_by_id(ngx_http_v2_connection_t *h2c, ngx_uint_t sid,
- ngx_uint_t alloc)
-{
- ngx_uint_t index;
- ngx_http_v2_node_t *node;
- ngx_http_v2_srv_conf_t *h2scf;
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- index = ngx_http_v2_index(h2scf, sid);
-
- for (node = h2c->streams_index[index]; node; node = node->index) {
-
- if (node->id == sid) {
- return node;
- }
- }
-
- if (!alloc) {
- return NULL;
- }
-
- if (h2c->closed_nodes < 32) {
- node = ngx_pcalloc(h2c->connection->pool, sizeof(ngx_http_v2_node_t));
- if (node == NULL) {
- return NULL;
- }
-
- } else {
- node = ngx_http_v2_get_closed_node(h2c);
- }
-
- node->id = sid;
-
- ngx_queue_init(&node->children);
-
- node->index = h2c->streams_index[index];
- h2c->streams_index[index] = node;
-
- return node;
-}
-
-
-static ngx_http_v2_node_t *
-ngx_http_v2_get_closed_node(ngx_http_v2_connection_t *h2c)
-{
- ngx_uint_t weight;
- ngx_queue_t *q, *children;
- ngx_http_v2_node_t *node, **next, *n, *parent, *child;
- ngx_http_v2_srv_conf_t *h2scf;
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- h2c->closed_nodes--;
-
- q = ngx_queue_head(&h2c->closed);
-
- ngx_queue_remove(q);
-
- node = ngx_queue_data(q, ngx_http_v2_node_t, reuse);
-
- next = &h2c->streams_index[ngx_http_v2_index(h2scf, node->id)];
-
- for ( ;; ) {
- n = *next;
-
- if (n == node) {
- *next = n->index;
- break;
- }
-
- next = &n->index;
- }
-
- ngx_queue_remove(&node->queue);
-
- weight = 0;
-
- for (q = ngx_queue_head(&node->children);
- q != ngx_queue_sentinel(&node->children);
- q = ngx_queue_next(q))
- {
- child = ngx_queue_data(q, ngx_http_v2_node_t, queue);
- weight += child->weight;
- }
-
- parent = node->parent;
-
- for (q = ngx_queue_head(&node->children);
- q != ngx_queue_sentinel(&node->children);
- q = ngx_queue_next(q))
- {
- child = ngx_queue_data(q, ngx_http_v2_node_t, queue);
- child->parent = parent;
- child->weight = node->weight * child->weight / weight;
-
- if (child->weight == 0) {
- child->weight = 1;
- }
- }
-
- if (parent == NGX_HTTP_V2_ROOT) {
- node->rank = 0;
- node->rel_weight = 1.0;
-
- children = &h2c->dependencies;
-
- } else {
- node->rank = parent->rank;
- node->rel_weight = parent->rel_weight;
-
- children = &parent->children;
- }
-
- ngx_http_v2_node_children_update(node);
- ngx_queue_add(children, &node->children);
-
- ngx_memzero(node, sizeof(ngx_http_v2_node_t));
-
- return node;
-}
-
-
-static ngx_int_t
-ngx_http_v2_validate_header(ngx_http_request_t *r, ngx_http_v2_header_t *header)
-{
- u_char ch;
- ngx_uint_t i;
- ngx_http_core_srv_conf_t *cscf;
-
- r->invalid_header = 0;
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- for (i = (header->name.data[0] == ':'); i != header->name.len; i++) {
- ch = header->name.data[i];
-
- if ((ch >= 'a' && ch <= 'z')
- || (ch == '-')
- || (ch >= '0' && ch <= '9')
- || (ch == '_' && cscf->underscores_in_headers))
- {
- continue;
- }
-
- if (ch <= 0x20 || ch == 0x7f || ch == ':'
- || (ch >= 'A' && ch <= 'Z'))
- {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid header name: \"%V\"",
- &header->name);
-
- return NGX_ERROR;
- }
-
- r->invalid_header = 1;
- }
-
- for (i = 0; i != header->value.len; i++) {
- ch = header->value.data[i];
-
- if (ch == '\0' || ch == LF || ch == CR) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent header \"%V\" with "
- "invalid value: \"%V\"",
- &header->name, &header->value);
-
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_pseudo_header(ngx_http_request_t *r, ngx_http_v2_header_t *header)
-{
- header->name.len--;
- header->name.data++;
-
- switch (header->name.len) {
- case 4:
- if (ngx_memcmp(header->name.data, "path", sizeof("path") - 1)
- == 0)
- {
- return ngx_http_v2_parse_path(r, &header->value);
- }
-
- break;
-
- case 6:
- if (ngx_memcmp(header->name.data, "method", sizeof("method") - 1)
- == 0)
- {
- return ngx_http_v2_parse_method(r, &header->value);
- }
-
- if (ngx_memcmp(header->name.data, "scheme", sizeof("scheme") - 1)
- == 0)
- {
- return ngx_http_v2_parse_scheme(r, &header->value);
- }
-
- break;
-
- case 9:
- if (ngx_memcmp(header->name.data, "authority", sizeof("authority") - 1)
- == 0)
- {
- return ngx_http_v2_parse_authority(r, &header->value);
- }
-
- break;
- }
-
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent unknown pseudo-header \":%V\"",
- &header->name);
-
- return NGX_DECLINED;
-}
-
-
-static ngx_int_t
-ngx_http_v2_parse_path(ngx_http_request_t *r, ngx_str_t *value)
-{
- if (r->unparsed_uri.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate :path header");
-
- return NGX_DECLINED;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty :path header");
-
- return NGX_DECLINED;
- }
-
- r->uri_start = value->data;
- r->uri_end = value->data + value->len;
-
- if (ngx_http_parse_uri(r) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid :path header: \"%V\"", value);
-
- return NGX_DECLINED;
- }
-
- if (ngx_http_process_request_uri(r) != NGX_OK) {
- /*
- * request has been finalized already
- * in ngx_http_process_request_uri()
- */
- return NGX_ABORT;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_parse_method(ngx_http_request_t *r, ngx_str_t *value)
-{
- size_t k, len;
- ngx_uint_t n;
- const u_char *p, *m;
-
- /*
- * This array takes less than 256 sequential bytes,
- * and if typical CPU cache line size is 64 bytes,
- * it is prefetched for 4 load operations.
- */
- static const struct {
- u_char len;
- const u_char method[11];
- uint32_t value;
- } tests[] = {
- { 3, "GET", NGX_HTTP_GET },
- { 4, "POST", NGX_HTTP_POST },
- { 4, "HEAD", NGX_HTTP_HEAD },
- { 7, "OPTIONS", NGX_HTTP_OPTIONS },
- { 8, "PROPFIND", NGX_HTTP_PROPFIND },
- { 3, "PUT", NGX_HTTP_PUT },
- { 5, "MKCOL", NGX_HTTP_MKCOL },
- { 6, "DELETE", NGX_HTTP_DELETE },
- { 4, "COPY", NGX_HTTP_COPY },
- { 4, "MOVE", NGX_HTTP_MOVE },
- { 9, "PROPPATCH", NGX_HTTP_PROPPATCH },
- { 4, "LOCK", NGX_HTTP_LOCK },
- { 6, "UNLOCK", NGX_HTTP_UNLOCK },
- { 5, "PATCH", NGX_HTTP_PATCH },
- { 5, "TRACE", NGX_HTTP_TRACE },
- { 7, "CONNECT", NGX_HTTP_CONNECT }
- }, *test;
-
- if (r->method_name.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate :method header");
-
- return NGX_DECLINED;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty :method header");
-
- return NGX_DECLINED;
- }
-
- r->method_name.len = value->len;
- r->method_name.data = value->data;
-
- len = r->method_name.len;
- n = sizeof(tests) / sizeof(tests[0]);
- test = tests;
-
- do {
- if (len == test->len) {
- p = r->method_name.data;
- m = test->method;
- k = len;
-
- do {
- if (*p++ != *m++) {
- goto next;
- }
- } while (--k);
-
- r->method = test->value;
- return NGX_OK;
- }
-
- next:
- test++;
-
- } while (--n);
-
- p = r->method_name.data;
-
- do {
- if ((*p < 'A' || *p > 'Z') && *p != '_' && *p != '-') {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid method: \"%V\"",
- &r->method_name);
-
- return NGX_DECLINED;
- }
-
- p++;
-
- } while (--len);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_parse_scheme(ngx_http_request_t *r, ngx_str_t *value)
-{
- u_char c, ch;
- ngx_uint_t i;
-
- if (r->schema.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate :scheme header");
-
- return NGX_DECLINED;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty :scheme header");
-
- return NGX_DECLINED;
- }
-
- for (i = 0; i < value->len; i++) {
- ch = value->data[i];
-
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'z') {
- continue;
- }
-
- if (((ch >= '0' && ch <= '9') || ch == '+' || ch == '-' || ch == '.')
- && i > 0)
- {
- continue;
- }
-
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid :scheme header: \"%V\"", value);
-
- return NGX_DECLINED;
- }
-
- r->schema = *value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_parse_authority(ngx_http_request_t *r, ngx_str_t *value)
-{
- ngx_int_t rc;
- in_port_t port;
-
- if (r->host_start) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate \":authority\" header");
- return NGX_DECLINED;
- }
-
- r->host_start = value->data;
- r->host_end = value->data + value->len;
-
- rc = ngx_http_validate_host(value, &port, r->pool, 0);
-
- if (rc == NGX_DECLINED) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid \":authority\" header");
- return NGX_DECLINED;
- }
-
- if (rc == NGX_ERROR) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ABORT;
- }
-
- if (ngx_http_set_virtual_server(r, value) == NGX_ERROR) {
- /*
- * request has been finalized already
- * in ngx_http_set_virtual_server()
- */
- return NGX_ABORT;
- }
-
- r->headers_in.server = *value;
- r->port = port;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_construct_request_line(ngx_http_request_t *r)
-{
- u_char *p;
-
- static const u_char ending[] = " HTTP/2.0";
-
- if (r->method_name.len == 0
- || r->schema.len == 0
- || r->unparsed_uri.len == 0)
- {
- if (r->method_name.len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no :method header");
-
- } else if (r->schema.len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no :scheme header");
-
- } else {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no :path header");
- }
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- return NGX_ERROR;
- }
-
- r->request_line.len = r->method_name.len + 1
- + r->unparsed_uri.len
- + sizeof(ending) - 1;
-
- p = ngx_pnalloc(r->pool, r->request_line.len + 1);
- if (p == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- r->request_line.data = p;
-
- p = ngx_cpymem(p, r->method_name.data, r->method_name.len);
-
- *p++ = ' ';
-
- p = ngx_cpymem(p, r->unparsed_uri.data, r->unparsed_uri.len);
-
- ngx_memcpy(p, ending, sizeof(ending));
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http2 request line: \"%V\"", &r->request_line);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_cookie(ngx_http_request_t *r, ngx_http_v2_header_t *header)
-{
- ngx_str_t *val;
- ngx_array_t *cookies;
-
- cookies = r->stream->cookies;
-
- if (cookies == NULL) {
- cookies = ngx_array_create(r->pool, 2, sizeof(ngx_str_t));
- if (cookies == NULL) {
- return NGX_ERROR;
- }
-
- r->stream->cookies = cookies;
- }
-
- val = ngx_array_push(cookies);
- if (val == NULL) {
- return NGX_ERROR;
- }
-
- val->len = header->value.len;
- val->data = header->value.data;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_construct_cookie_header(ngx_http_request_t *r)
-{
- u_char *buf, *p, *end;
- size_t len;
- ngx_str_t *vals;
- ngx_uint_t i;
- ngx_array_t *cookies;
- ngx_table_elt_t *h;
- ngx_http_header_t *hh;
- ngx_http_core_main_conf_t *cmcf;
-
- static ngx_str_t cookie = ngx_string("cookie");
-
- cookies = r->stream->cookies;
-
- if (cookies == NULL) {
- return NGX_OK;
- }
-
- vals = cookies->elts;
-
- i = 0;
- len = 0;
-
- do {
- len += vals[i].len + 2;
- } while (++i != cookies->nelts);
-
- len -= 2;
-
- buf = ngx_pnalloc(r->pool, len + 1);
- if (buf == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- p = buf;
- end = buf + len;
-
- for (i = 0; /* void */ ; i++) {
-
- p = ngx_cpymem(p, vals[i].data, vals[i].len);
-
- if (p == end) {
- *p = '\0';
- break;
- }
-
- *p++ = ';'; *p++ = ' ';
- }
-
- h = ngx_list_push(&r->headers_in.headers);
- if (h == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
- ngx_hash('c', 'o'), 'o'), 'k'), 'i'), 'e');
-
- h->key.len = cookie.len;
- h->key.data = cookie.data;
-
- h->value.len = len;
- h->value.data = buf;
-
- h->lowcase_key = cookie.data;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
- h->lowcase_key, h->key.len);
-
- if (hh == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- if (hh->handler(r, h, hh->offset) != NGX_OK) {
- /*
- * request has been finalized already
- * in ngx_http_process_header_line()
- */
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_construct_host_header(ngx_http_request_t *r)
-{
- ngx_table_elt_t *h;
- ngx_http_header_t *hh;
- ngx_http_core_main_conf_t *cmcf;
-
- static ngx_str_t host = ngx_string("host");
-
- h = ngx_list_push(&r->headers_in.headers);
- if (h == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- h->hash = ngx_hash(ngx_hash(ngx_hash('h', 'o'), 's'), 't');
-
- h->key.len = host.len;
- h->key.data = host.data;
-
- h->value.len = r->host_end - r->host_start;
- h->value.data = r->host_start;
-
- h->lowcase_key = host.data;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
- h->lowcase_key, h->key.len);
-
- if (hh == NULL) {
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- if (hh->handler(r, h, hh->offset) != NGX_OK) {
- /*
- * request has been finalized already
- * in ngx_http_process_host()
- */
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_v2_run_request(ngx_http_request_t *r)
-{
- ngx_str_t host;
- ngx_connection_t *fc;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_v2_connection_t *h2c;
-
- fc = r->connection;
-
- h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
-
- if (!h2scf->enable && !r->http_connection->addr_conf->http2) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client attempted to request the server name "
- "for which the negotiated protocol is disabled");
-
- ngx_http_finalize_request(r, NGX_HTTP_MISDIRECTED_REQUEST);
- goto failed;
- }
-
- if (ngx_http_v2_construct_request_line(r) != NGX_OK) {
- goto failed;
- }
-
- if (ngx_http_v2_construct_cookie_header(r) != NGX_OK) {
- goto failed;
- }
-
- r->http_state = NGX_HTTP_PROCESS_REQUEST_STATE;
-
- if (r->headers_in.server.len == 0) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client sent neither \":authority\" nor \"Host\" header");
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto failed;
- }
-
- if (r->host_end) {
-
- host.len = r->host_end - r->host_start;
- host.data = r->host_start;
-
- if (r->headers_in.host) {
- if (r->headers_in.host->value.len != host.len
- || ngx_memcmp(r->headers_in.host->value.data, host.data,
- host.len)
- != 0)
- {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client sent \":authority\" and \"Host\" headers "
- "with different values");
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto failed;
- }
-
- } else {
- /* compatibility for $http_host */
-
- if (ngx_http_v2_construct_host_header(r) != NGX_OK) {
- goto failed;
- }
- }
- }
-
- if (r->headers_in.content_length) {
- r->headers_in.content_length_n =
- ngx_atoof(r->headers_in.content_length->value.data,
- r->headers_in.content_length->value.len);
-
- if (r->headers_in.content_length_n == NGX_ERROR) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client sent invalid \"Content-Length\" header");
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto failed;
- }
-
- if (r->headers_in.content_length_n > 0 && r->stream->in_closed) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client prematurely closed stream");
-
- r->stream->skip_data = 1;
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- goto failed;
- }
-
- } else if (!r->stream->in_closed) {
- r->headers_in.chunked = 1;
- }
-
- if (r->method == NGX_HTTP_CONNECT) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0, "client sent CONNECT method");
- ngx_http_finalize_request(r, NGX_HTTP_NOT_ALLOWED);
- goto failed;
- }
-
- if (r->method == NGX_HTTP_TRACE) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0, "client sent TRACE method");
- ngx_http_finalize_request(r, NGX_HTTP_NOT_ALLOWED);
- goto failed;
- }
-
- h2c = r->stream->connection;
-
- h2c->payload_bytes += r->request_length;
-
- ngx_http_process_request(r);
-
-failed:
-
- ngx_http_run_posted_requests(fc);
-}
-
-
-ngx_int_t
-ngx_http_v2_read_request_body(ngx_http_request_t *r)
-{
- off_t len;
- size_t size;
- ngx_buf_t *buf;
- ngx_int_t rc;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_v2_connection_t *h2c;
-
- stream = r->stream;
- rb = r->request_body;
-
- if (stream->skip_data) {
- r->request_body_no_buffering = 0;
- rb->post_handler(r);
- return NGX_OK;
- }
-
- rb->rest = 1;
-
- /* set rb->filter_need_buffering */
-
- rc = ngx_http_top_request_body_filter(r, NULL);
-
- if (rc != NGX_OK) {
- stream->skip_data = 1;
- return rc;
- }
-
- h2scf = ngx_http_get_module_srv_conf(r, ngx_http_v2_module);
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- len = r->headers_in.content_length_n;
-
- if (len < 0 || len > (off_t) clcf->client_body_buffer_size) {
- len = clcf->client_body_buffer_size;
-
- } else {
- len++;
- }
-
- if (r->request_body_no_buffering || rb->filter_need_buffering) {
-
- /*
- * We need a room to store data up to the stream's initial window size,
- * at least until this window will be exhausted.
- */
-
- if (len < (off_t) h2scf->preread_size) {
- len = h2scf->preread_size;
- }
-
- if (len > NGX_HTTP_V2_MAX_WINDOW) {
- len = NGX_HTTP_V2_MAX_WINDOW;
- }
- }
-
- rb->buf = ngx_create_temp_buf(r->pool, (size_t) len);
-
- if (rb->buf == NULL) {
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- buf = stream->preread;
-
- if (stream->in_closed) {
- if (!rb->filter_need_buffering) {
- r->request_body_no_buffering = 0;
- }
-
- if (buf) {
- rc = ngx_http_v2_process_request_body(r, buf->pos,
- buf->last - buf->pos, 1, 0);
- ngx_pfree(r->pool, buf->start);
-
- } else {
- rc = ngx_http_v2_process_request_body(r, NULL, 0, 1, 0);
- }
-
- if (rc != NGX_AGAIN) {
- return rc;
- }
-
- r->read_event_handler = ngx_http_v2_read_client_request_body_handler;
- r->write_event_handler = ngx_http_request_empty_handler;
-
- return NGX_AGAIN;
- }
-
- if (buf) {
- rc = ngx_http_v2_process_request_body(r, buf->pos,
- buf->last - buf->pos, 0, 0);
-
- ngx_pfree(r->pool, buf->start);
-
- if (rc != NGX_OK && rc != NGX_AGAIN) {
- stream->skip_data = 1;
- return rc;
- }
- }
-
- if (r->request_body_no_buffering || rb->filter_need_buffering) {
- size = (size_t) len - h2scf->preread_size;
-
- } else {
- stream->no_flow_control = 1;
- size = NGX_HTTP_V2_MAX_WINDOW - stream->recv_window;
- }
-
- if (size) {
- if (ngx_http_v2_send_window_update(stream->connection,
- stream->node->id, size)
- == NGX_ERROR)
- {
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- h2c = stream->connection;
-
- if (!h2c->blocked) {
- if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
- }
-
- stream->recv_window += size;
- }
-
- if (!buf) {
- ngx_add_timer(r->connection->read, clcf->client_body_timeout);
- }
-
- r->read_event_handler = ngx_http_v2_read_client_request_body_handler;
- r->write_event_handler = ngx_http_request_empty_handler;
-
- return NGX_AGAIN;
-}
-
-
-static ngx_int_t
-ngx_http_v2_process_request_body(ngx_http_request_t *r, u_char *pos,
- size_t size, ngx_uint_t last, ngx_uint_t flush)
-{
- size_t n;
- ngx_int_t rc;
- ngx_connection_t *fc;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
-
- fc = r->connection;
- rb = r->request_body;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 process request body");
-
- if (size == 0 && !last && !flush) {
- return NGX_AGAIN;
- }
-
- for ( ;; ) {
- for ( ;; ) {
- if (rb->buf->last == rb->buf->end && size) {
-
- if (r->request_body_no_buffering) {
-
- /* should never happen due to flow control */
-
- ngx_log_error(NGX_LOG_ALERT, fc->log, 0,
- "no space in http2 body buffer");
-
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- /* update chains */
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 body update chains");
-
- rc = ngx_http_v2_filter_request_body(r);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (rb->busy != NULL) {
- ngx_log_error(NGX_LOG_ALERT, fc->log, 0,
- "busy buffers after request body flush");
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- rb->buf->pos = rb->buf->start;
- rb->buf->last = rb->buf->start;
- }
-
- /* copy body data to the buffer */
-
- n = rb->buf->end - rb->buf->last;
-
- if (n > size) {
- n = size;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 request body recv %uz", n);
-
- if (n > 0) {
- rb->buf->last = ngx_cpymem(rb->buf->last, pos, n);
- pos += n;
- size -= n;
- }
-
- if (size == 0 && last) {
- rb->rest = 0;
- }
-
- if (size == 0) {
- break;
- }
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 request body rest %O", rb->rest);
-
- if (flush) {
- rc = ngx_http_v2_filter_request_body(r);
-
- if (rc != NGX_OK) {
- return rc;
- }
- }
-
- if (rb->rest == 0 && rb->last_saved) {
- break;
- }
-
- if (size == 0) {
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- ngx_add_timer(fc->read, clcf->client_body_timeout);
-
- if (!flush) {
- ngx_post_event(fc->read, &ngx_posted_events);
- }
-
- return NGX_AGAIN;
- }
- }
-
- if (fc->read->timer_set) {
- ngx_del_timer(fc->read);
- }
-
- if (r->request_body_no_buffering) {
- if (!flush) {
- ngx_post_event(fc->read, &ngx_posted_events);
- }
-
- return NGX_OK;
- }
-
- if (r->headers_in.chunked) {
- r->headers_in.content_length_n = rb->received;
- }
-
- r->read_event_handler = ngx_http_block_reading;
- rb->post_handler(r);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_filter_request_body(ngx_http_request_t *r)
-{
- ngx_buf_t *b, *buf;
- ngx_int_t rc;
- ngx_chain_t *cl;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
-
- rb = r->request_body;
- buf = rb->buf;
-
- if (buf->pos == buf->last && (rb->rest || rb->last_sent)) {
- cl = NULL;
- goto update;
- }
-
- cl = ngx_chain_get_free_buf(r->pool, &rb->free);
- if (cl == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- b = cl->buf;
-
- ngx_memzero(b, sizeof(ngx_buf_t));
-
- if (buf->pos != buf->last) {
- r->request_length += buf->last - buf->pos;
- rb->received += buf->last - buf->pos;
-
- if (r->headers_in.content_length_n != -1) {
- if (rb->received > r->headers_in.content_length_n) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client intended to send body data "
- "larger than declared");
-
- return NGX_HTTP_BAD_REQUEST;
- }
-
- } else {
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (clcf->client_max_body_size
- && rb->received > clcf->client_max_body_size)
- {
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client intended to send too large chunked body: "
- "%O bytes", rb->received);
-
- return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
- }
- }
-
- b->temporary = 1;
- b->pos = buf->pos;
- b->last = buf->last;
- b->start = b->pos;
- b->end = b->last;
-
- buf->pos = buf->last;
- }
-
- if (!rb->rest) {
- if (r->headers_in.content_length_n != -1
- && r->headers_in.content_length_n != rb->received)
- {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client prematurely closed stream: "
- "only %O out of %O bytes of request body received",
- rb->received, r->headers_in.content_length_n);
-
- return NGX_HTTP_BAD_REQUEST;
- }
-
- b->last_buf = 1;
- rb->last_sent = 1;
- }
-
- b->tag = (ngx_buf_tag_t) &ngx_http_v2_filter_request_body;
- b->flush = r->request_body_no_buffering;
-
-update:
-
- rc = ngx_http_top_request_body_filter(r, cl);
-
- ngx_chain_update_chains(r->pool, &rb->free, &rb->busy, &cl,
- (ngx_buf_tag_t) &ngx_http_v2_filter_request_body);
-
- return rc;
-}
-
-
-static void
-ngx_http_v2_read_client_request_body_handler(ngx_http_request_t *r)
-{
- size_t window;
- ngx_buf_t *buf;
- ngx_int_t rc;
- ngx_connection_t *fc;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_connection_t *h2c;
-
- fc = r->connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 read client request body handler");
-
- if (fc->read->timedout) {
- ngx_log_error(NGX_LOG_INFO, fc->log, NGX_ETIMEDOUT, "client timed out");
-
- fc->timedout = 1;
- r->stream->skip_data = 1;
-
- ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- if (fc->error) {
- ngx_log_error(NGX_LOG_INFO, fc->log, 0,
- "client prematurely closed stream");
-
- r->stream->skip_data = 1;
-
- ngx_http_finalize_request(r, NGX_HTTP_CLIENT_CLOSED_REQUEST);
- return;
- }
-
- rc = ngx_http_v2_process_request_body(r, NULL, 0, r->stream->in_closed, 1);
-
- if (rc != NGX_OK && rc != NGX_AGAIN) {
- r->stream->skip_data = 1;
- ngx_http_finalize_request(r, rc);
- return;
- }
-
- if (rc == NGX_OK) {
- return;
- }
-
- if (r->stream->no_flow_control) {
- return;
- }
-
- if (r->request_body->rest == 0) {
- return;
- }
-
- if (r->request_body->busy != NULL) {
- return;
- }
-
- stream = r->stream;
- h2c = stream->connection;
-
- buf = r->request_body->buf;
-
- buf->pos = buf->start;
- buf->last = buf->start;
-
- window = buf->end - buf->start;
-
- if (h2c->state.stream == stream) {
- window -= h2c->state.length;
- }
-
- if (window <= stream->recv_window) {
- if (window < stream->recv_window) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "http2 negative window update");
-
- stream->skip_data = 1;
-
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- return;
- }
-
- if (ngx_http_v2_send_window_update(h2c, stream->node->id,
- window - stream->recv_window)
- == NGX_ERROR)
- {
- stream->skip_data = 1;
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- stream->recv_window = window;
-
- if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- stream->skip_data = 1;
- ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-}
-
-
-ngx_int_t
-ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r)
-{
- size_t window;
- ngx_buf_t *buf;
- ngx_int_t rc;
- ngx_connection_t *fc;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_connection_t *h2c;
-
- stream = r->stream;
- fc = r->connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 read unbuffered request body");
-
- if (fc->read->timedout) {
- if (stream->recv_window) {
- stream->skip_data = 1;
- fc->timedout = 1;
-
- return NGX_HTTP_REQUEST_TIME_OUT;
- }
-
- fc->read->timedout = 0;
- }
-
- if (fc->error) {
- stream->skip_data = 1;
- return NGX_HTTP_BAD_REQUEST;
- }
-
- rc = ngx_http_v2_process_request_body(r, NULL, 0, r->stream->in_closed, 1);
-
- if (rc != NGX_OK && rc != NGX_AGAIN) {
- stream->skip_data = 1;
- return rc;
- }
-
- if (rc == NGX_OK) {
- return NGX_OK;
- }
-
- if (r->request_body->rest == 0) {
- return NGX_AGAIN;
- }
-
- if (r->request_body->busy != NULL) {
- return NGX_AGAIN;
- }
-
- buf = r->request_body->buf;
-
- buf->pos = buf->start;
- buf->last = buf->start;
-
- window = buf->end - buf->start;
- h2c = stream->connection;
-
- if (h2c->state.stream == stream) {
- window -= h2c->state.length;
- }
-
- if (window <= stream->recv_window) {
- if (window < stream->recv_window) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "http2 negative window update");
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- if (ngx_http_v2_send_window_update(h2c, stream->node->id,
- window - stream->recv_window)
- == NGX_ERROR)
- {
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- if (ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- stream->skip_data = 1;
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- stream->recv_window = window;
-
- return NGX_AGAIN;
-}
-
-
-static ngx_int_t
-ngx_http_v2_terminate_stream(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream, ngx_uint_t status)
-{
- ngx_event_t *rev;
- ngx_connection_t *fc;
-
- if (stream->rst_sent) {
- return NGX_OK;
- }
-
- if (ngx_http_v2_send_rst_stream(h2c, stream->node->id, status)
- == NGX_ERROR)
- {
- return NGX_ERROR;
- }
-
- stream->rst_sent = 1;
- stream->skip_data = 1;
-
- fc = stream->request->connection;
- fc->error = 1;
-
- rev = fc->read;
- rev->handler(rev);
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc)
-{
- ngx_pool_t *pool;
- ngx_event_t *ev;
- ngx_connection_t *fc;
- ngx_http_v2_node_t *node;
- ngx_http_v2_connection_t *h2c;
-
- h2c = stream->connection;
- node = stream->node;
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 close stream %ui, queued %ui, processing %ui",
- node->id, stream->queued, h2c->processing);
-
- fc = stream->request->connection;
-
- if (stream->queued) {
- fc->error = 1;
- fc->write->handler = ngx_http_v2_retry_close_stream_handler;
- fc->read->handler = ngx_http_v2_retry_close_stream_handler;
- return;
- }
-
- if (!stream->rst_sent && !h2c->connection->error) {
-
- if (!stream->out_closed) {
- if (ngx_http_v2_send_rst_stream(h2c, node->id,
- fc->timedout ? NGX_HTTP_V2_PROTOCOL_ERROR
- : NGX_HTTP_V2_INTERNAL_ERROR)
- != NGX_OK)
- {
- h2c->connection->error = 1;
- }
-
- } else if (!stream->in_closed) {
- if (ngx_http_v2_send_rst_stream(h2c, node->id, NGX_HTTP_V2_NO_ERROR)
- != NGX_OK)
- {
- h2c->connection->error = 1;
- }
- }
- }
-
- if (h2c->state.stream == stream) {
- h2c->state.stream = NULL;
- }
-
- node->stream = NULL;
-
- ngx_queue_insert_tail(&h2c->closed, &node->reuse);
- h2c->closed_nodes++;
-
- /*
- * This pool keeps decoded request headers which can be used by log phase
- * handlers in ngx_http_free_request().
- *
- * The pointer is stored into local variable because the stream object
- * will be destroyed after a call to ngx_http_free_request().
- */
- pool = stream->pool;
-
- h2c->frames -= stream->frames;
-
- ngx_http_free_request(stream->request, rc);
-
- if (pool != h2c->state.pool) {
- ngx_destroy_pool(pool);
-
- } else {
- /* pool will be destroyed when the complete header is parsed */
- h2c->state.keep_pool = 0;
- }
-
- ev = fc->read;
-
- if (ev->timer_set) {
- ngx_del_timer(ev);
- }
-
- if (ev->posted) {
- ngx_delete_posted_event(ev);
- }
-
- ev = fc->write;
-
- if (ev->timer_set) {
- ngx_del_timer(ev);
- }
-
- if (ev->posted) {
- ngx_delete_posted_event(ev);
- }
-
- fc->data = h2c->free_fake_connections;
- h2c->free_fake_connections = fc;
-
- h2c->processing--;
-
- if (h2c->processing || h2c->blocked) {
- return;
- }
-
- ev = h2c->connection->read;
-
- ev->handler = ngx_http_v2_handle_connection_handler;
- ngx_post_event(ev, &ngx_posted_events);
-}
-
-
-static void
-ngx_http_v2_close_stream_handler(ngx_event_t *ev)
-{
- ngx_connection_t *fc;
- ngx_http_request_t *r;
-
- fc = ev->data;
- r = fc->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 close stream handler");
-
- if (ev->timedout) {
- ngx_log_error(NGX_LOG_INFO, fc->log, NGX_ETIMEDOUT, "client timed out");
-
- fc->timedout = 1;
-
- ngx_http_v2_close_stream(r->stream, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- ngx_http_v2_close_stream(r->stream, 0);
-}
-
-
-static void
-ngx_http_v2_retry_close_stream_handler(ngx_event_t *ev)
-{
- ngx_connection_t *fc;
- ngx_http_request_t *r;
-
- fc = ev->data;
- r = fc->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 retry close stream handler");
-
- ngx_http_v2_close_stream(r->stream, 0);
-}
-
-
-static void
-ngx_http_v2_handle_connection_handler(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_http_v2_connection_t *h2c;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0,
- "http2 handle connection handler");
-
- c = rev->data;
- h2c = c->data;
-
- if (c->error) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- rev->handler = ngx_http_v2_read_handler;
-
- if (rev->ready) {
- ngx_http_v2_read_handler(rev);
- return;
- }
-
- if (h2c->last_out && ngx_http_v2_send_output_queue(h2c) == NGX_ERROR) {
- ngx_http_v2_finalize_connection(h2c, 0);
- return;
- }
-
- ngx_http_v2_handle_connection(c->data);
-}
-
-
-static void
-ngx_http_v2_idle_handler(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_http_v2_srv_conf_t *h2scf;
- ngx_http_v2_connection_t *h2c;
- ngx_http_core_loc_conf_t *clcf;
-
- c = rev->data;
- h2c = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http2 idle handler");
-
- if (rev->timedout || c->close) {
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
- return;
- }
-
-#if (NGX_HAVE_KQUEUE)
-
- if (ngx_event_flags & NGX_USE_KQUEUE_EVENT) {
- if (rev->pending_eof) {
- c->log->handler = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, rev->kq_errno,
- "kevent() reported that client %V closed "
- "idle connection", &c->addr_text);
-#if (NGX_HTTP_SSL)
- if (c->ssl) {
- c->ssl->no_send_shutdown = 1;
- }
-#endif
- ngx_http_close_connection(c);
- return;
- }
- }
-
-#endif
-
- clcf = ngx_http_get_module_loc_conf(h2c->http_connection->conf_ctx,
- ngx_http_core_module);
-
- if (h2c->idle++ > 10 * clcf->keepalive_requests) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "http2 flood detected");
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_NO_ERROR);
- return;
- }
-
- c->destroyed = 0;
- ngx_reusable_connection(c, 0);
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- h2c->pool = ngx_create_pool(h2scf->pool_size, h2c->connection->log);
- if (h2c->pool == NULL) {
- ngx_http_v2_finalize_connection(h2c, NGX_HTTP_V2_INTERNAL_ERROR);
- return;
- }
-
- c->write->handler = ngx_http_v2_write_handler;
-
- rev->handler = ngx_http_v2_read_handler;
- ngx_http_v2_read_handler(rev);
-}
-
-
-static void
-ngx_http_v2_finalize_connection(ngx_http_v2_connection_t *h2c,
- ngx_uint_t status)
-{
- ngx_uint_t i, size;
- ngx_event_t *ev;
- ngx_connection_t *c, *fc;
- ngx_http_request_t *r;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
-
- c = h2c->connection;
-
- h2c->blocked = 1;
-
- if (!c->error && !h2c->goaway) {
- h2c->goaway = 1;
-
- if (ngx_http_v2_send_goaway(h2c, status) != NGX_ERROR) {
- (void) ngx_http_v2_send_output_queue(h2c);
- }
- }
-
- if (!h2c->processing) {
- goto done;
- }
-
- c->read->handler = ngx_http_empty_handler;
- c->write->handler = ngx_http_empty_handler;
-
- h2c->last_out = NULL;
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- size = ngx_http_v2_index_size(h2scf);
-
- for (i = 0; i < size; i++) {
-
- for (node = h2c->streams_index[i]; node; node = node->index) {
- stream = node->stream;
-
- if (stream == NULL) {
- continue;
- }
-
- stream->waiting = 0;
-
- r = stream->request;
- fc = r->connection;
-
- fc->error = 1;
-
- if (stream->queued) {
- stream->queued = 0;
-
- ev = fc->write;
- ev->active = 0;
- ev->ready = 1;
-
- } else {
- ev = fc->read;
- }
-
- ev->eof = 1;
- ev->handler(ev);
- }
- }
-
- h2c->blocked = 0;
-
- if (h2c->processing) {
- c->error = 1;
- return;
- }
-
-done:
-
- if (c->error) {
- ngx_http_close_connection(c);
- return;
- }
-
- ngx_http_v2_lingering_close(c);
-}
-
-
-static ngx_int_t
-ngx_http_v2_adjust_windows(ngx_http_v2_connection_t *h2c, ssize_t delta)
-{
- ngx_uint_t i, size;
- ngx_event_t *wev;
- ngx_http_v2_node_t *node;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_srv_conf_t *h2scf;
-
- h2scf = ngx_http_get_module_srv_conf(h2c->http_connection->conf_ctx,
- ngx_http_v2_module);
-
- size = ngx_http_v2_index_size(h2scf);
-
- for (i = 0; i < size; i++) {
-
- for (node = h2c->streams_index[i]; node; node = node->index) {
- stream = node->stream;
-
- if (stream == NULL) {
- continue;
- }
-
- if (delta > 0
- && stream->send_window
- > (ssize_t) (NGX_HTTP_V2_MAX_WINDOW - delta))
- {
- if (ngx_http_v2_terminate_stream(h2c, stream,
- NGX_HTTP_V2_FLOW_CTRL_ERROR)
- == NGX_ERROR)
- {
- return NGX_ERROR;
- }
-
- continue;
- }
-
- stream->send_window += delta;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui adjusted window: %z",
- node->id, stream->send_window);
-
- if (stream->send_window > 0 && stream->exhausted) {
- stream->exhausted = 0;
-
- wev = stream->request->connection->write;
-
- wev->active = 0;
- wev->ready = 1;
-
- if (!wev->delayed) {
- wev->handler(wev);
- }
- }
- }
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_v2_set_dependency(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_node_t *node, ngx_uint_t depend, ngx_uint_t exclusive)
-{
- ngx_queue_t *children, *q;
- ngx_http_v2_node_t *parent, *child, *next;
-
- parent = depend ? ngx_http_v2_get_node_by_id(h2c, depend, 0) : NULL;
-
- if (parent == NULL) {
- parent = NGX_HTTP_V2_ROOT;
-
- if (depend != 0) {
- exclusive = 0;
- }
-
- node->rank = 1;
- node->rel_weight = (1.0 / 256) * node->weight;
-
- children = &h2c->dependencies;
-
- } else {
- if (node->parent != NULL) {
-
- for (next = parent->parent;
- next != NGX_HTTP_V2_ROOT && next->rank >= node->rank;
- next = next->parent)
- {
- if (next != node) {
- continue;
- }
-
- ngx_queue_remove(&parent->queue);
- ngx_queue_insert_after(&node->queue, &parent->queue);
-
- parent->parent = node->parent;
-
- if (node->parent == NGX_HTTP_V2_ROOT) {
- parent->rank = 1;
- parent->rel_weight = (1.0 / 256) * parent->weight;
-
- } else {
- parent->rank = node->parent->rank + 1;
- parent->rel_weight = (node->parent->rel_weight / 256)
- * parent->weight;
- }
-
- if (!exclusive) {
- ngx_http_v2_node_children_update(parent);
- }
-
- break;
- }
- }
-
- node->rank = parent->rank + 1;
- node->rel_weight = (parent->rel_weight / 256) * node->weight;
-
- if (parent->stream == NULL) {
- ngx_queue_remove(&parent->reuse);
- ngx_queue_insert_tail(&h2c->closed, &parent->reuse);
- }
-
- children = &parent->children;
- }
-
- if (exclusive) {
- for (q = ngx_queue_head(children);
- q != ngx_queue_sentinel(children);
- q = ngx_queue_next(q))
- {
- child = ngx_queue_data(q, ngx_http_v2_node_t, queue);
- child->parent = node;
- }
-
- ngx_queue_add(&node->children, children);
- ngx_queue_init(children);
- }
-
- if (node->parent != NULL) {
- ngx_queue_remove(&node->queue);
- }
-
- ngx_queue_insert_tail(children, &node->queue);
-
- node->parent = parent;
-
- ngx_http_v2_node_children_update(node);
-}
-
-
-static void
-ngx_http_v2_node_children_update(ngx_http_v2_node_t *node)
-{
- ngx_queue_t *q;
- ngx_http_v2_node_t *child;
-
- for (q = ngx_queue_head(&node->children);
- q != ngx_queue_sentinel(&node->children);
- q = ngx_queue_next(q))
- {
- child = ngx_queue_data(q, ngx_http_v2_node_t, queue);
-
- child->rank = node->rank + 1;
- child->rel_weight = (node->rel_weight / 256) * child->weight;
-
- ngx_http_v2_node_children_update(child);
- }
-}
-
-
-static void
-ngx_http_v2_pool_cleanup(void *data)
-{
- ngx_http_v2_connection_t *h2c = data;
-
- if (h2c->state.pool) {
- ngx_destroy_pool(h2c->state.pool);
- }
-
- if (h2c->pool) {
- ngx_destroy_pool(h2c->pool);
- }
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.h b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.h
deleted file mode 100644
index 9605c8a23d..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2.h
+++ /dev/null
@@ -1,423 +0,0 @@
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#ifndef _NGX_HTTP_V2_H_INCLUDED_
-#define _NGX_HTTP_V2_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-#define NGX_HTTP_V2_ALPN_PROTO "\x02h2"
-
-#define NGX_HTTP_V2_STATE_BUFFER_SIZE 16
-
-#define NGX_HTTP_V2_DEFAULT_FRAME_SIZE (1 << 14)
-#define NGX_HTTP_V2_MAX_FRAME_SIZE ((1 << 24) - 1)
-
-#define NGX_HTTP_V2_INT_OCTETS 4
-#define NGX_HTTP_V2_MAX_FIELD \
- (127 + (1 << (NGX_HTTP_V2_INT_OCTETS - 1) * 7) - 1)
-
-#define NGX_HTTP_V2_FRAME_HEADER_SIZE 9
-
-/* frame types */
-#define NGX_HTTP_V2_DATA_FRAME 0x0
-#define NGX_HTTP_V2_HEADERS_FRAME 0x1
-#define NGX_HTTP_V2_PRIORITY_FRAME 0x2
-#define NGX_HTTP_V2_RST_STREAM_FRAME 0x3
-#define NGX_HTTP_V2_SETTINGS_FRAME 0x4
-#define NGX_HTTP_V2_PUSH_PROMISE_FRAME 0x5
-#define NGX_HTTP_V2_PING_FRAME 0x6
-#define NGX_HTTP_V2_GOAWAY_FRAME 0x7
-#define NGX_HTTP_V2_WINDOW_UPDATE_FRAME 0x8
-#define NGX_HTTP_V2_CONTINUATION_FRAME 0x9
-
-/* frame flags */
-#define NGX_HTTP_V2_NO_FLAG 0x00
-#define NGX_HTTP_V2_ACK_FLAG 0x01
-#define NGX_HTTP_V2_END_STREAM_FLAG 0x01
-#define NGX_HTTP_V2_END_HEADERS_FLAG 0x04
-#define NGX_HTTP_V2_PADDED_FLAG 0x08
-#define NGX_HTTP_V2_PRIORITY_FLAG 0x20
-
-#define NGX_HTTP_V2_MAX_WINDOW ((1U << 31) - 1)
-#define NGX_HTTP_V2_DEFAULT_WINDOW 65535
-
-#define NGX_HTTP_V2_DEFAULT_WEIGHT 16
-
-
-typedef struct ngx_http_v2_connection_s ngx_http_v2_connection_t;
-typedef struct ngx_http_v2_node_s ngx_http_v2_node_t;
-typedef struct ngx_http_v2_out_frame_s ngx_http_v2_out_frame_t;
-
-
-typedef u_char *(*ngx_http_v2_handler_pt) (ngx_http_v2_connection_t *h2c,
- u_char *pos, u_char *end);
-
-
-typedef struct {
- ngx_flag_t enable;
- size_t pool_size;
- ngx_uint_t concurrent_streams;
- size_t preread_size;
- ngx_uint_t streams_index_mask;
-} ngx_http_v2_srv_conf_t;
-
-
-typedef struct {
- ngx_str_t name;
- ngx_str_t value;
-} ngx_http_v2_header_t;
-
-
-typedef struct {
- ngx_uint_t sid;
- size_t length;
- size_t padding;
- unsigned flags:8;
-
- unsigned incomplete:1;
- unsigned keep_pool:1;
-
- /* HPACK */
- unsigned parse_name:1;
- unsigned parse_value:1;
- unsigned index:1;
- ngx_http_v2_header_t header;
- size_t header_limit;
- u_char field_state;
- u_char *field_start;
- u_char *field_end;
- size_t field_rest;
- ngx_pool_t *pool;
-
- ngx_http_v2_stream_t *stream;
-
- u_char buffer[NGX_HTTP_V2_STATE_BUFFER_SIZE];
- size_t buffer_used;
- ngx_http_v2_handler_pt handler;
-} ngx_http_v2_state_t;
-
-
-
-typedef struct {
- ngx_http_v2_header_t **entries;
-
- ngx_uint_t added;
- ngx_uint_t deleted;
- ngx_uint_t reused;
- ngx_uint_t allocated;
-
- size_t size;
- size_t free;
- u_char *storage;
- u_char *pos;
-} ngx_http_v2_hpack_t;
-
-
-struct ngx_http_v2_connection_s {
- ngx_connection_t *connection;
- ngx_http_connection_t *http_connection;
-
- off_t total_bytes;
- off_t payload_bytes;
-
- ngx_uint_t processing;
- ngx_uint_t frames;
- ngx_uint_t idle;
- ngx_uint_t new_streams;
- ngx_uint_t refused_streams;
- ngx_uint_t priority_limit;
-
- size_t send_window;
- size_t recv_window;
- size_t init_window;
-
- size_t frame_size;
-
- ngx_queue_t waiting;
-
- ngx_http_v2_state_t state;
-
- ngx_http_v2_hpack_t hpack;
-
- ngx_pool_t *pool;
-
- ngx_http_v2_out_frame_t *free_frames;
- ngx_connection_t *free_fake_connections;
-
- ngx_http_v2_node_t **streams_index;
-
- ngx_http_v2_out_frame_t *last_out;
-
- ngx_queue_t dependencies;
- ngx_queue_t closed;
-
- ngx_uint_t closed_nodes;
- ngx_uint_t last_sid;
-
- time_t lingering_time;
-
- unsigned settings_ack:1;
- unsigned table_update:1;
- unsigned blocked:1;
- unsigned goaway:1;
-};
-
-
-struct ngx_http_v2_node_s {
- ngx_uint_t id;
- ngx_http_v2_node_t *index;
- ngx_http_v2_node_t *parent;
- ngx_queue_t queue;
- ngx_queue_t children;
- ngx_queue_t reuse;
- ngx_uint_t rank;
- ngx_uint_t weight;
- double rel_weight;
- ngx_http_v2_stream_t *stream;
-};
-
-
-struct ngx_http_v2_stream_s {
- ngx_http_request_t *request;
- ngx_http_v2_connection_t *connection;
- ngx_http_v2_node_t *node;
-
- ngx_uint_t queued;
-
- /*
- * A change to SETTINGS_INITIAL_WINDOW_SIZE could cause the
- * send_window to become negative, hence it's signed.
- */
- ssize_t send_window;
- size_t recv_window;
-
- ngx_buf_t *preread;
-
- ngx_uint_t frames;
-
- ngx_http_v2_out_frame_t *free_frames;
- ngx_chain_t *free_frame_headers;
- ngx_chain_t *free_bufs;
-
- ngx_queue_t queue;
-
- ngx_array_t *cookies;
-
- ngx_pool_t *pool;
-
- unsigned initialized:1;
- unsigned waiting:1;
- unsigned blocked:1;
- unsigned exhausted:1;
- unsigned in_closed:1;
- unsigned out_closed:1;
- unsigned rst_sent:1;
- unsigned no_flow_control:1;
- unsigned skip_data:1;
-};
-
-
-struct ngx_http_v2_out_frame_s {
- ngx_http_v2_out_frame_t *next;
- ngx_chain_t *first;
- ngx_chain_t *last;
- ngx_int_t (*handler)(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame);
-
- ngx_http_v2_stream_t *stream;
- size_t length;
-
- unsigned blocked:1;
- unsigned fin:1;
-};
-
-
-static ngx_inline void
-ngx_http_v2_queue_frame(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_http_v2_out_frame_t **out;
-
- for (out = &h2c->last_out; *out; out = &(*out)->next) {
-
- if ((*out)->blocked || (*out)->stream == NULL) {
- break;
- }
-
- if ((*out)->stream->node->rank < frame->stream->node->rank
- || ((*out)->stream->node->rank == frame->stream->node->rank
- && (*out)->stream->node->rel_weight
- >= frame->stream->node->rel_weight))
- {
- break;
- }
- }
-
- frame->next = *out;
- *out = frame;
-}
-
-
-static ngx_inline void
-ngx_http_v2_queue_blocked_frame(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_http_v2_out_frame_t **out;
-
- for (out = &h2c->last_out; *out; out = &(*out)->next) {
-
- if ((*out)->blocked || (*out)->stream == NULL) {
- break;
- }
- }
-
- frame->next = *out;
- *out = frame;
-}
-
-
-static ngx_inline void
-ngx_http_v2_queue_ordered_frame(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- frame->next = h2c->last_out;
- h2c->last_out = frame;
-}
-
-
-void ngx_http_v2_init(ngx_event_t *rev);
-
-ngx_int_t ngx_http_v2_read_request_body(ngx_http_request_t *r);
-ngx_int_t ngx_http_v2_read_unbuffered_request_body(ngx_http_request_t *r);
-
-void ngx_http_v2_close_stream(ngx_http_v2_stream_t *stream, ngx_int_t rc);
-
-ngx_int_t ngx_http_v2_send_output_queue(ngx_http_v2_connection_t *h2c);
-
-
-ngx_str_t *ngx_http_v2_get_static_name(ngx_uint_t index);
-ngx_str_t *ngx_http_v2_get_static_value(ngx_uint_t index);
-
-ngx_int_t ngx_http_v2_get_indexed_header(ngx_http_v2_connection_t *h2c,
- ngx_uint_t index, ngx_uint_t name_only);
-ngx_int_t ngx_http_v2_add_header(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_header_t *header);
-ngx_int_t ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size);
-
-
-#define ngx_http_v2_prefix(bits) ((1 << (bits)) - 1)
-
-
-#if (NGX_HAVE_NONALIGNED)
-
-#define ngx_http_v2_parse_uint16(p) ntohs(*(uint16_t *) (p))
-#define ngx_http_v2_parse_uint32(p) ntohl(*(uint32_t *) (p))
-
-#else
-
-#define ngx_http_v2_parse_uint16(p) ((p)[0] << 8 | (p)[1])
-#define ngx_http_v2_parse_uint32(p) \
- ((uint32_t) (p)[0] << 24 | (p)[1] << 16 | (p)[2] << 8 | (p)[3])
-
-#endif
-
-#define ngx_http_v2_parse_length(p) ((p) >> 8)
-#define ngx_http_v2_parse_type(p) ((p) & 0xff)
-#define ngx_http_v2_parse_sid(p) (ngx_http_v2_parse_uint32(p) & 0x7fffffff)
-#define ngx_http_v2_parse_window(p) (ngx_http_v2_parse_uint32(p) & 0x7fffffff)
-
-
-#define ngx_http_v2_write_uint16_aligned(p, s) \
- (*(uint16_t *) (p) = htons((uint16_t) (s)), (p) + sizeof(uint16_t))
-#define ngx_http_v2_write_uint32_aligned(p, s) \
- (*(uint32_t *) (p) = htonl((uint32_t) (s)), (p) + sizeof(uint32_t))
-
-#if (NGX_HAVE_NONALIGNED)
-
-#define ngx_http_v2_write_uint16 ngx_http_v2_write_uint16_aligned
-#define ngx_http_v2_write_uint32 ngx_http_v2_write_uint32_aligned
-
-#else
-
-#define ngx_http_v2_write_uint16(p, s) \
- ((p)[0] = (u_char) ((s) >> 8), \
- (p)[1] = (u_char) (s), \
- (p) + sizeof(uint16_t))
-
-#define ngx_http_v2_write_uint32(p, s) \
- ((p)[0] = (u_char) ((s) >> 24), \
- (p)[1] = (u_char) ((s) >> 16), \
- (p)[2] = (u_char) ((s) >> 8), \
- (p)[3] = (u_char) (s), \
- (p) + sizeof(uint32_t))
-
-#endif
-
-#define ngx_http_v2_write_len_and_type(p, l, t) \
- ngx_http_v2_write_uint32_aligned(p, (l) << 8 | (t))
-
-#define ngx_http_v2_write_sid ngx_http_v2_write_uint32
-
-
-#define ngx_http_v2_indexed(i) (128 + (i))
-#define ngx_http_v2_inc_indexed(i) (64 + (i))
-
-#define ngx_http_v2_write_name(dst, src, len, tmp) \
- ngx_http_v2_string_encode(dst, src, len, tmp, 1)
-#define ngx_http_v2_write_value(dst, src, len, tmp) \
- ngx_http_v2_string_encode(dst, src, len, tmp, 0)
-
-#define NGX_HTTP_V2_ENCODE_RAW 0
-#define NGX_HTTP_V2_ENCODE_HUFF 0x80
-
-#define NGX_HTTP_V2_AUTHORITY_INDEX 1
-
-#define NGX_HTTP_V2_METHOD_INDEX 2
-#define NGX_HTTP_V2_METHOD_GET_INDEX 2
-#define NGX_HTTP_V2_METHOD_POST_INDEX 3
-
-#define NGX_HTTP_V2_PATH_INDEX 4
-#define NGX_HTTP_V2_PATH_ROOT_INDEX 4
-
-#define NGX_HTTP_V2_SCHEME_HTTP_INDEX 6
-#define NGX_HTTP_V2_SCHEME_HTTPS_INDEX 7
-
-#define NGX_HTTP_V2_STATUS_INDEX 8
-#define NGX_HTTP_V2_STATUS_200_INDEX 8
-#define NGX_HTTP_V2_STATUS_204_INDEX 9
-#define NGX_HTTP_V2_STATUS_206_INDEX 10
-#define NGX_HTTP_V2_STATUS_304_INDEX 11
-#define NGX_HTTP_V2_STATUS_400_INDEX 12
-#define NGX_HTTP_V2_STATUS_404_INDEX 13
-#define NGX_HTTP_V2_STATUS_500_INDEX 14
-
-#define NGX_HTTP_V2_CONTENT_LENGTH_INDEX 28
-#define NGX_HTTP_V2_CONTENT_TYPE_INDEX 31
-#define NGX_HTTP_V2_DATE_INDEX 33
-#define NGX_HTTP_V2_LAST_MODIFIED_INDEX 44
-#define NGX_HTTP_V2_LOCATION_INDEX 46
-#define NGX_HTTP_V2_SERVER_INDEX 54
-#define NGX_HTTP_V2_VARY_INDEX 59
-
-#define NGX_HTTP_V2_PREFACE_START "PRI * HTTP/2.0\r\n"
-#define NGX_HTTP_V2_PREFACE_END "\r\nSM\r\n\r\n"
-#define NGX_HTTP_V2_PREFACE NGX_HTTP_V2_PREFACE_START \
- NGX_HTTP_V2_PREFACE_END
-
-
-u_char *ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len,
- u_char *tmp, ngx_uint_t lower);
-
-
-extern ngx_module_t ngx_http_v2_module;
-
-
-#endif /* _NGX_HTTP_V2_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_encode.c b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_encode.c
deleted file mode 100644
index 8798aa9ae2..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_encode.c
+++ /dev/null
@@ -1,62 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#include
-#include
-#include
-
-
-static u_char *ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix,
- ngx_uint_t value);
-
-
-u_char *
-ngx_http_v2_string_encode(u_char *dst, u_char *src, size_t len, u_char *tmp,
- ngx_uint_t lower)
-{
- size_t hlen;
-
- hlen = ngx_http_huff_encode(src, len, tmp, lower);
-
- if (hlen > 0) {
- *dst = NGX_HTTP_V2_ENCODE_HUFF;
- dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), hlen);
- return ngx_cpymem(dst, tmp, hlen);
- }
-
- *dst = NGX_HTTP_V2_ENCODE_RAW;
- dst = ngx_http_v2_write_int(dst, ngx_http_v2_prefix(7), len);
-
- if (lower) {
- ngx_strlow(dst, src, len);
- return dst + len;
- }
-
- return ngx_cpymem(dst, src, len);
-}
-
-
-static u_char *
-ngx_http_v2_write_int(u_char *pos, ngx_uint_t prefix, ngx_uint_t value)
-{
- if (value < prefix) {
- *pos++ |= value;
- return pos;
- }
-
- *pos++ |= prefix;
- value -= prefix;
-
- while (value >= 128) {
- *pos++ = value % 128 + 128;
- value /= 128;
- }
-
- *pos++ = (u_char) value;
-
- return pos;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_filter_module.c b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_filter_module.c
deleted file mode 100644
index 6b73b1e687..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_filter_module.c
+++ /dev/null
@@ -1,1769 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- * Copyright (C) Ruslan Ermilov
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-/*
- * This returns precise number of octets for values in range 0..253
- * and estimate number for the rest, but not smaller than required.
- */
-
-#define ngx_http_v2_integer_octets(v) (1 + (v) / 127)
-
-#define ngx_http_v2_literal_size(h) \
- (ngx_http_v2_integer_octets(sizeof(h) - 1) + sizeof(h) - 1)
-
-
-#define NGX_HTTP_V2_NO_TRAILERS (ngx_http_v2_out_frame_t *) -1
-
-
-static ngx_int_t ngx_http_v2_header_filter(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v2_early_hints_filter(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v2_init_stream(ngx_http_request_t *r);
-
-static ngx_http_v2_out_frame_t *ngx_http_v2_create_headers_frame(
- ngx_http_request_t *r, u_char *pos, u_char *end, ngx_uint_t fin,
- ngx_uint_t flush);
-static ngx_http_v2_out_frame_t *ngx_http_v2_create_trailers_frame(
- ngx_http_request_t *r);
-
-static ngx_chain_t *ngx_http_v2_send_chain(ngx_connection_t *fc,
- ngx_chain_t *in, off_t limit);
-
-static ngx_chain_t *ngx_http_v2_filter_get_shadow(
- ngx_http_v2_stream_t *stream, ngx_buf_t *buf, off_t offset, off_t size);
-static ngx_http_v2_out_frame_t *ngx_http_v2_filter_get_data_frame(
- ngx_http_v2_stream_t *stream, size_t len, ngx_chain_t *first,
- ngx_chain_t *last);
-
-static ngx_inline ngx_int_t ngx_http_v2_flow_control(
- ngx_http_v2_connection_t *h2c, ngx_http_v2_stream_t *stream);
-static void ngx_http_v2_waiting_queue(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream);
-
-static ngx_inline ngx_int_t ngx_http_v2_filter_send(
- ngx_connection_t *fc, ngx_http_v2_stream_t *stream);
-
-static ngx_int_t ngx_http_v2_headers_frame_handler(
- ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
-static ngx_int_t ngx_http_v2_data_frame_handler(
- ngx_http_v2_connection_t *h2c, ngx_http_v2_out_frame_t *frame);
-static ngx_inline void ngx_http_v2_handle_frame(
- ngx_http_v2_stream_t *stream, ngx_http_v2_out_frame_t *frame);
-static ngx_inline void ngx_http_v2_handle_stream(
- ngx_http_v2_connection_t *h2c, ngx_http_v2_stream_t *stream);
-
-static void ngx_http_v2_filter_cleanup(void *data);
-
-static ngx_int_t ngx_http_v2_filter_init(ngx_conf_t *cf);
-
-
-static ngx_http_module_t ngx_http_v2_filter_module_ctx = {
- NULL, /* preconfiguration */
- ngx_http_v2_filter_init, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_v2_filter_module = {
- NGX_MODULE_V1,
- &ngx_http_v2_filter_module_ctx, /* module context */
- NULL, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
-static ngx_http_output_header_filter_pt ngx_http_next_early_hints_filter;
-
-
-static ngx_int_t
-ngx_http_v2_header_filter(ngx_http_request_t *r)
-{
- u_char status, *pos, *start, *p, *tmp;
- size_t len, tmp_len;
- ngx_str_t host, location;
- ngx_uint_t i, port, fin;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_connection_t *fc;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_out_frame_t *frame;
- ngx_http_v2_connection_t *h2c;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
- u_char addr[NGX_SOCKADDR_STRLEN];
-
- static const u_char nginx[5] = { 0x84, 0xaa, 0x63, 0x55, 0xe7 };
-#if (NGX_HTTP_GZIP)
- static const u_char accept_encoding[12] = {
- 0x8b, 0x84, 0x84, 0x2d, 0x69, 0x5b, 0x05, 0x44, 0x3c, 0x86, 0xaa, 0x6f
- };
-#endif
-
- static size_t nginx_ver_len = ngx_http_v2_literal_size(NGINX_VER);
- static u_char nginx_ver[ngx_http_v2_literal_size(NGINX_VER)];
-
- static size_t nginx_ver_build_len =
- ngx_http_v2_literal_size(NGINX_VER_BUILD);
- static u_char nginx_ver_build[ngx_http_v2_literal_size(NGINX_VER_BUILD)];
-
- stream = r->stream;
-
- if (!stream) {
- return ngx_http_next_header_filter(r);
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http2 header filter");
-
- if (r->header_sent) {
- return NGX_OK;
- }
-
- r->header_sent = 1;
-
- if (r != r->main) {
- return NGX_OK;
- }
-
- fc = r->connection;
-
- if (fc->error) {
- return NGX_ERROR;
- }
-
- if (r->method == NGX_HTTP_HEAD) {
- r->header_only = 1;
- }
-
- switch (r->headers_out.status) {
-
- case NGX_HTTP_OK:
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_200_INDEX);
- break;
-
- case NGX_HTTP_NO_CONTENT:
- r->header_only = 1;
-
- ngx_str_null(&r->headers_out.content_type);
-
- r->headers_out.content_length = NULL;
- r->headers_out.content_length_n = -1;
-
- r->headers_out.last_modified_time = -1;
- r->headers_out.last_modified = NULL;
-
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_204_INDEX);
- break;
-
- case NGX_HTTP_PARTIAL_CONTENT:
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_206_INDEX);
- break;
-
- case NGX_HTTP_NOT_MODIFIED:
- r->header_only = 1;
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_304_INDEX);
- break;
-
- default:
- r->headers_out.last_modified_time = -1;
- r->headers_out.last_modified = NULL;
-
- switch (r->headers_out.status) {
-
- case NGX_HTTP_BAD_REQUEST:
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_400_INDEX);
- break;
-
- case NGX_HTTP_NOT_FOUND:
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_404_INDEX);
- break;
-
- case NGX_HTTP_INTERNAL_SERVER_ERROR:
- status = ngx_http_v2_indexed(NGX_HTTP_V2_STATUS_500_INDEX);
- break;
-
- default:
- status = 0;
- }
- }
-
- h2c = stream->connection;
-
- len = h2c->table_update ? 1 : 0;
-
- len += status ? 1 : 1 + ngx_http_v2_literal_size("418");
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (r->headers_out.server == NULL) {
-
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- len += 1 + nginx_ver_len;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- len += 1 + nginx_ver_build_len;
-
- } else {
- len += 1 + sizeof(nginx);
- }
- }
-
- if (r->headers_out.date == NULL) {
- len += 1 + ngx_http_v2_literal_size("Wed, 31 Dec 1986 18:00:00 GMT");
- }
-
- if (r->headers_out.content_type.len) {
- len += 1 + NGX_HTTP_V2_INT_OCTETS + r->headers_out.content_type.len;
-
- if (r->headers_out.content_type_len == r->headers_out.content_type.len
- && r->headers_out.charset.len)
- {
- len += sizeof("; charset=") - 1 + r->headers_out.charset.len;
- }
- }
-
- if (r->headers_out.content_length == NULL
- && r->headers_out.content_length_n >= 0)
- {
- len += 1 + ngx_http_v2_integer_octets(NGX_OFF_T_LEN) + NGX_OFF_T_LEN;
- }
-
- if (r->headers_out.last_modified == NULL
- && r->headers_out.last_modified_time != -1)
- {
- len += 1 + ngx_http_v2_literal_size("Wed, 31 Dec 1986 18:00:00 GMT");
- }
-
- if (r->headers_out.location && r->headers_out.location->value.len) {
-
- if (r->headers_out.location->value.data[0] == '/'
- && clcf->absolute_redirect)
- {
- if (clcf->server_name_in_redirect) {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
- host = cscf->server_name;
-
- } else if (r->headers_in.server.len) {
- host = r->headers_in.server;
-
- } else {
- host.len = NGX_SOCKADDR_STRLEN;
- host.data = addr;
-
- if (ngx_connection_local_sockaddr(fc, &host, 0) != NGX_OK) {
- return NGX_ERROR;
- }
- }
-
- port = ngx_inet_get_port(fc->local_sockaddr);
-
- location.len = sizeof("https://") - 1 + host.len
- + r->headers_out.location->value.len;
-
- if (clcf->port_in_redirect) {
-
-#if (NGX_HTTP_SSL)
- if (fc->ssl)
- port = (port == 443) ? 0 : port;
- else
-#endif
- port = (port == 80) ? 0 : port;
-
- } else {
- port = 0;
- }
-
- if (port) {
- location.len += sizeof(":65535") - 1;
- }
-
- location.data = ngx_pnalloc(r->pool, location.len);
- if (location.data == NULL) {
- return NGX_ERROR;
- }
-
- p = ngx_cpymem(location.data, "http", sizeof("http") - 1);
-
-#if (NGX_HTTP_SSL)
- if (fc->ssl) {
- *p++ = 's';
- }
-#endif
-
- *p++ = ':'; *p++ = '/'; *p++ = '/';
- p = ngx_cpymem(p, host.data, host.len);
-
- if (port) {
- p = ngx_sprintf(p, ":%ui", port);
- }
-
- p = ngx_cpymem(p, r->headers_out.location->value.data,
- r->headers_out.location->value.len);
-
- /* update r->headers_out.location->value for possible logging */
-
- r->headers_out.location->value.len = p - location.data;
- r->headers_out.location->value.data = location.data;
- ngx_str_set(&r->headers_out.location->key, "Location");
- }
-
- r->headers_out.location->hash = 0;
-
- len += 1 + NGX_HTTP_V2_INT_OCTETS + r->headers_out.location->value.len;
- }
-
- tmp_len = len;
-
-#if (NGX_HTTP_GZIP)
- if (r->gzip_vary) {
- if (clcf->gzip_vary) {
- len += 1 + sizeof(accept_encoding);
-
- } else {
- r->gzip_vary = 0;
- }
- }
-#endif
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- if (header[i].key.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response header name: \"%V\"",
- &header[i].key);
- return NGX_ERROR;
- }
-
- if (header[i].value.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response header value: \"%V: %V\"",
- &header[i].key, &header[i].value);
- return NGX_ERROR;
- }
-
- len += 1 + NGX_HTTP_V2_INT_OCTETS + header[i].key.len
- + NGX_HTTP_V2_INT_OCTETS + header[i].value.len;
-
- if (header[i].key.len > tmp_len) {
- tmp_len = header[i].key.len;
- }
-
- if (header[i].value.len > tmp_len) {
- tmp_len = header[i].value.len;
- }
- }
-
- tmp = ngx_palloc(r->pool, tmp_len);
- pos = ngx_pnalloc(r->pool, len);
-
- if (pos == NULL || tmp == NULL) {
- return NGX_ERROR;
- }
-
- start = pos;
-
- if (h2c->table_update) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 table size update: 0");
- *pos++ = (1 << 5) | 0;
- h2c->table_update = 0;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \":status: %03ui\"",
- r->headers_out.status);
-
- if (status) {
- *pos++ = status;
-
- } else {
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX);
- *pos++ = NGX_HTTP_V2_ENCODE_RAW | 3;
- pos = ngx_sprintf(pos, "%03ui", r->headers_out.status);
- }
-
- if (r->headers_out.server == NULL) {
-
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"server: %s\"",
- NGINX_VER);
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"server: %s\"",
- NGINX_VER_BUILD);
-
- } else {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"server: nginx\"");
- }
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_SERVER_INDEX);
-
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- if (nginx_ver[0] == '\0') {
- p = ngx_http_v2_write_value(nginx_ver, (u_char *) NGINX_VER,
- sizeof(NGINX_VER) - 1, tmp);
- nginx_ver_len = p - nginx_ver;
- }
-
- pos = ngx_cpymem(pos, nginx_ver, nginx_ver_len);
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- if (nginx_ver_build[0] == '\0') {
- p = ngx_http_v2_write_value(nginx_ver_build,
- (u_char *) NGINX_VER_BUILD,
- sizeof(NGINX_VER_BUILD) - 1, tmp);
- nginx_ver_build_len = p - nginx_ver_build;
- }
-
- pos = ngx_cpymem(pos, nginx_ver_build, nginx_ver_build_len);
-
- } else {
- pos = ngx_cpymem(pos, nginx, sizeof(nginx));
- }
- }
-
- if (r->headers_out.date == NULL) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"date: %V\"",
- &ngx_cached_http_time);
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_DATE_INDEX);
- pos = ngx_http_v2_write_value(pos, ngx_cached_http_time.data,
- ngx_cached_http_time.len, tmp);
- }
-
- if (r->headers_out.content_type.len) {
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_TYPE_INDEX);
-
- if (r->headers_out.content_type_len == r->headers_out.content_type.len
- && r->headers_out.charset.len)
- {
- len = r->headers_out.content_type.len + sizeof("; charset=") - 1
- + r->headers_out.charset.len;
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- p = ngx_cpymem(p, r->headers_out.content_type.data,
- r->headers_out.content_type.len);
-
- p = ngx_cpymem(p, "; charset=", sizeof("; charset=") - 1);
-
- p = ngx_cpymem(p, r->headers_out.charset.data,
- r->headers_out.charset.len);
-
- /* updated r->headers_out.content_type is also needed for logging */
-
- r->headers_out.content_type.len = len;
- r->headers_out.content_type.data = p - len;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"content-type: %V\"",
- &r->headers_out.content_type);
-
- pos = ngx_http_v2_write_value(pos, r->headers_out.content_type.data,
- r->headers_out.content_type.len, tmp);
- }
-
- if (r->headers_out.content_length == NULL
- && r->headers_out.content_length_n >= 0)
- {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"content-length: %O\"",
- r->headers_out.content_length_n);
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_CONTENT_LENGTH_INDEX);
-
- p = pos;
- pos = ngx_sprintf(pos + 1, "%O", r->headers_out.content_length_n);
- *p = NGX_HTTP_V2_ENCODE_RAW | (u_char) (pos - p - 1);
- }
-
- if (r->headers_out.last_modified == NULL
- && r->headers_out.last_modified_time != -1)
- {
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LAST_MODIFIED_INDEX);
-
- ngx_http_time(pos, r->headers_out.last_modified_time);
- len = sizeof("Wed, 31 Dec 1986 18:00:00 GMT") - 1;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"last-modified: %*s\"",
- len, pos);
-
- /*
- * Date will always be encoded using huffman in the temporary buffer,
- * so it's safe here to use src and dst pointing to the same address.
- */
- pos = ngx_http_v2_write_value(pos, pos, len, tmp);
- }
-
- if (r->headers_out.location && r->headers_out.location->value.len) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"location: %V\"",
- &r->headers_out.location->value);
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_LOCATION_INDEX);
- pos = ngx_http_v2_write_value(pos, r->headers_out.location->value.data,
- r->headers_out.location->value.len, tmp);
- }
-
-#if (NGX_HTTP_GZIP)
- if (r->gzip_vary) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"vary: Accept-Encoding\"");
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_VARY_INDEX);
- pos = ngx_cpymem(pos, accept_encoding, sizeof(accept_encoding));
- }
-#endif
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
-#if (NGX_DEBUG)
- if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) {
- ngx_strlow(tmp, header[i].key.data, header[i].key.len);
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"%*s: %V\"",
- header[i].key.len, tmp, &header[i].value);
- }
-#endif
-
- *pos++ = 0;
-
- pos = ngx_http_v2_write_name(pos, header[i].key.data,
- header[i].key.len, tmp);
-
- pos = ngx_http_v2_write_value(pos, header[i].value.data,
- header[i].value.len, tmp);
- }
-
- fin = r->header_only
- || (r->headers_out.content_length_n == 0 && !r->expect_trailers);
-
- frame = ngx_http_v2_create_headers_frame(r, start, pos, fin, 0);
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- stream->queued++;
-
- if (ngx_http_v2_init_stream(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- return ngx_http_v2_filter_send(fc, stream);
-}
-
-
-static ngx_int_t
-ngx_http_v2_early_hints_filter(ngx_http_request_t *r)
-{
- u_char *pos, *start, *tmp;
- size_t len, tmp_len;
- ngx_uint_t i;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_connection_t *fc;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_out_frame_t *frame;
- ngx_http_v2_connection_t *h2c;
-
- stream = r->stream;
-
- if (!stream) {
- return ngx_http_next_early_hints_filter(r);
- }
-
- if (r != r->main) {
- return NGX_OK;
- }
-
- fc = r->connection;
-
- if (fc->error) {
- return NGX_ERROR;
- }
-
- len = 0;
- tmp_len = 0;
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- if (header[i].key.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response header name: \"%V\"",
- &header[i].key);
- return NGX_ERROR;
- }
-
- if (header[i].value.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response header value: \"%V: %V\"",
- &header[i].key, &header[i].value);
- return NGX_ERROR;
- }
-
- len += 1 + NGX_HTTP_V2_INT_OCTETS + header[i].key.len
- + NGX_HTTP_V2_INT_OCTETS + header[i].value.len;
-
- if (header[i].key.len > tmp_len) {
- tmp_len = header[i].key.len;
- }
-
- if (header[i].value.len > tmp_len) {
- tmp_len = header[i].value.len;
- }
- }
-
- if (len == 0) {
- return NGX_OK;
- }
-
- h2c = stream->connection;
-
- len += h2c->table_update ? 1 : 0;
- len += 1 + ngx_http_v2_literal_size("418");
-
- tmp = ngx_palloc(r->pool, tmp_len);
- pos = ngx_pnalloc(r->pool, len);
-
- if (pos == NULL || tmp == NULL) {
- return NGX_ERROR;
- }
-
- start = pos;
-
- if (h2c->table_update) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 table size update: 0");
- *pos++ = (1 << 5) | 0;
- h2c->table_update = 0;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \":status: %03ui\"",
- (ngx_uint_t) NGX_HTTP_EARLY_HINTS);
-
- *pos++ = ngx_http_v2_inc_indexed(NGX_HTTP_V2_STATUS_INDEX);
- *pos++ = NGX_HTTP_V2_ENCODE_RAW | 3;
- pos = ngx_sprintf(pos, "%03ui", (ngx_uint_t) NGX_HTTP_EARLY_HINTS);
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
-#if (NGX_DEBUG)
- if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) {
- ngx_strlow(tmp, header[i].key.data, header[i].key.len);
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output header: \"%*s: %V\"",
- header[i].key.len, tmp, &header[i].value);
- }
-#endif
-
- *pos++ = 0;
-
- pos = ngx_http_v2_write_name(pos, header[i].key.data,
- header[i].key.len, tmp);
-
- pos = ngx_http_v2_write_value(pos, header[i].value.data,
- header[i].value.len, tmp);
- }
-
- frame = ngx_http_v2_create_headers_frame(r, start, pos, 0, 1);
- if (frame == NULL) {
- return NGX_ERROR;
- }
-
- ngx_http_v2_queue_blocked_frame(h2c, frame);
-
- stream->queued++;
-
- if (ngx_http_v2_init_stream(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- return ngx_http_v2_filter_send(fc, stream);
-}
-
-
-static ngx_int_t
-ngx_http_v2_init_stream(ngx_http_request_t *r)
-{
- ngx_connection_t *fc;
- ngx_http_cleanup_t *cln;
- ngx_http_v2_stream_t *stream;
-
- stream = r->stream;
- fc = r->connection;
-
- if (stream->initialized) {
- return NGX_OK;
- }
-
- stream->initialized = 1;
-
- cln = ngx_http_cleanup_add(r, 0);
- if (cln == NULL) {
- return NGX_ERROR;
- }
-
- cln->handler = ngx_http_v2_filter_cleanup;
- cln->data = stream;
-
- fc->send_chain = ngx_http_v2_send_chain;
- fc->need_last_buf = 1;
- fc->need_flush_buf = 1;
-
- return NGX_OK;
-}
-
-
-static ngx_http_v2_out_frame_t *
-ngx_http_v2_create_headers_frame(ngx_http_request_t *r, u_char *pos,
- u_char *end, ngx_uint_t fin, ngx_uint_t flush)
-{
- u_char type, flags;
- size_t rest, frame_size;
- ngx_buf_t *b;
- ngx_chain_t *cl, **ll;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_out_frame_t *frame;
-
- stream = r->stream;
- rest = end - pos;
-
- frame = ngx_palloc(r->pool, sizeof(ngx_http_v2_out_frame_t));
- if (frame == NULL) {
- return NULL;
- }
-
- frame->handler = ngx_http_v2_headers_frame_handler;
- frame->stream = stream;
- frame->length = rest;
- frame->blocked = 1;
- frame->fin = fin;
-
- ll = &frame->first;
-
- type = NGX_HTTP_V2_HEADERS_FRAME;
- flags = fin ? NGX_HTTP_V2_END_STREAM_FLAG : NGX_HTTP_V2_NO_FLAG;
- frame_size = stream->connection->frame_size;
-
- for ( ;; ) {
- if (rest <= frame_size) {
- frame_size = rest;
- flags |= NGX_HTTP_V2_END_HEADERS_FLAG;
- }
-
- b = ngx_create_temp_buf(r->pool, NGX_HTTP_V2_FRAME_HEADER_SIZE);
- if (b == NULL) {
- return NULL;
- }
-
- b->last = ngx_http_v2_write_len_and_type(b->last, frame_size, type);
- *b->last++ = flags;
- b->last = ngx_http_v2_write_sid(b->last, stream->node->id);
-
- b->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NULL;
- }
-
- cl->buf = b;
-
- *ll = cl;
- ll = &cl->next;
-
- b = ngx_calloc_buf(r->pool);
- if (b == NULL) {
- return NULL;
- }
-
- b->pos = pos;
-
- pos += frame_size;
-
- b->last = pos;
- b->start = b->pos;
- b->end = b->last;
- b->temporary = 1;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NULL;
- }
-
- cl->buf = b;
-
- *ll = cl;
- ll = &cl->next;
-
- rest -= frame_size;
-
- if (rest) {
- frame->length += NGX_HTTP_V2_FRAME_HEADER_SIZE;
-
- type = NGX_HTTP_V2_CONTINUATION_FRAME;
- flags = NGX_HTTP_V2_NO_FLAG;
- continue;
- }
-
- b->last_buf = fin;
- b->flush = flush;
- cl->next = NULL;
- frame->last = cl;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http2:%ui create HEADERS frame %p: len:%uz fin:%ui",
- stream->node->id, frame, frame->length, fin);
-
- return frame;
- }
-}
-
-
-static ngx_http_v2_out_frame_t *
-ngx_http_v2_create_trailers_frame(ngx_http_request_t *r)
-{
- u_char *pos, *start, *tmp;
- size_t len, tmp_len;
- ngx_uint_t i;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_connection_t *fc;
-
- fc = r->connection;
- len = 0;
- tmp_len = 0;
-
- part = &r->headers_out.trailers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- if (header[i].key.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response trailer name: \"%V\"",
- &header[i].key);
- return NULL;
- }
-
- if (header[i].value.len > NGX_HTTP_V2_MAX_FIELD) {
- ngx_log_error(NGX_LOG_CRIT, fc->log, 0,
- "too long response trailer value: \"%V: %V\"",
- &header[i].key, &header[i].value);
- return NULL;
- }
-
- len += 1 + NGX_HTTP_V2_INT_OCTETS + header[i].key.len
- + NGX_HTTP_V2_INT_OCTETS + header[i].value.len;
-
- if (header[i].key.len > tmp_len) {
- tmp_len = header[i].key.len;
- }
-
- if (header[i].value.len > tmp_len) {
- tmp_len = header[i].value.len;
- }
- }
-
- if (len == 0) {
- return NGX_HTTP_V2_NO_TRAILERS;
- }
-
- tmp = ngx_palloc(r->pool, tmp_len);
- pos = ngx_pnalloc(r->pool, len);
-
- if (pos == NULL || tmp == NULL) {
- return NULL;
- }
-
- start = pos;
-
- part = &r->headers_out.trailers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
-#if (NGX_DEBUG)
- if (fc->log->log_level & NGX_LOG_DEBUG_HTTP) {
- ngx_strlow(tmp, header[i].key.data, header[i].key.len);
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 output trailer: \"%*s: %V\"",
- header[i].key.len, tmp, &header[i].value);
- }
-#endif
-
- *pos++ = 0;
-
- pos = ngx_http_v2_write_name(pos, header[i].key.data,
- header[i].key.len, tmp);
-
- pos = ngx_http_v2_write_value(pos, header[i].value.data,
- header[i].value.len, tmp);
- }
-
- return ngx_http_v2_create_headers_frame(r, start, pos, 1, 0);
-}
-
-
-static ngx_chain_t *
-ngx_http_v2_send_chain(ngx_connection_t *fc, ngx_chain_t *in, off_t limit)
-{
- off_t size, offset;
- size_t rest, frame_size;
- ngx_chain_t *cl, *out, **ln;
- ngx_http_request_t *r;
- ngx_http_v2_stream_t *stream;
- ngx_http_v2_loc_conf_t *h2lcf;
- ngx_http_v2_out_frame_t *frame, *trailers;
- ngx_http_v2_connection_t *h2c;
-
- r = fc->data;
- stream = r->stream;
-
-#if (NGX_SUPPRESS_WARN)
- size = 0;
-#endif
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, fc->log, 0,
- "http2 send chain: %p", in);
-
- while (in) {
- size = ngx_buf_size(in->buf);
-
- if (size || in->buf->last_buf) {
- break;
- }
-
- in = in->next;
- }
-
- if (in == NULL || stream->out_closed) {
-
- if (size) {
- ngx_log_error(NGX_LOG_ERR, fc->log, 0,
- "output on closed stream");
- return NGX_CHAIN_ERROR;
- }
-
- if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) {
- return NGX_CHAIN_ERROR;
- }
-
- return NULL;
- }
-
- h2c = stream->connection;
-
- if (size && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) {
-
- if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) {
- return NGX_CHAIN_ERROR;
- }
-
- if (ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) {
- fc->write->active = 1;
- fc->write->ready = 0;
- return in;
- }
- }
-
- if (in->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) {
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- cl->buf = in->buf;
- in->buf = cl->buf->shadow;
-
- offset = ngx_buf_in_memory(in->buf)
- ? (cl->buf->pos - in->buf->pos)
- : (cl->buf->file_pos - in->buf->file_pos);
-
- cl->next = stream->free_bufs;
- stream->free_bufs = cl;
-
- } else {
- offset = 0;
- }
-
- if (limit == 0 || limit > (off_t) h2c->send_window) {
- limit = h2c->send_window;
- }
-
- if (limit > stream->send_window) {
- limit = (stream->send_window > 0) ? stream->send_window : 0;
- }
-
- h2lcf = ngx_http_get_module_loc_conf(r, ngx_http_v2_module);
-
- frame_size = (h2lcf->chunk_size < h2c->frame_size)
- ? h2lcf->chunk_size : h2c->frame_size;
-
- trailers = NGX_HTTP_V2_NO_TRAILERS;
-
-#if (NGX_SUPPRESS_WARN)
- cl = NULL;
-#endif
-
- for ( ;; ) {
- if ((off_t) frame_size > limit) {
- frame_size = (size_t) limit;
- }
-
- ln = &out;
- rest = frame_size;
-
- while ((off_t) rest >= size) {
-
- if (offset) {
- cl = ngx_http_v2_filter_get_shadow(stream, in->buf,
- offset, size);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- offset = 0;
-
- } else {
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- cl->buf = in->buf;
- }
-
- *ln = cl;
- ln = &cl->next;
-
- rest -= (size_t) size;
- in = in->next;
-
- if (in == NULL) {
- frame_size -= rest;
- rest = 0;
- break;
- }
-
- size = ngx_buf_size(in->buf);
- }
-
- if (rest) {
- cl = ngx_http_v2_filter_get_shadow(stream, in->buf, offset, rest);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- cl->buf->flush = 0;
- cl->buf->last_buf = 0;
-
- *ln = cl;
-
- offset += rest;
- size -= rest;
- }
-
- if (cl->buf->last_buf) {
- trailers = ngx_http_v2_create_trailers_frame(r);
- if (trailers == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- if (trailers != NGX_HTTP_V2_NO_TRAILERS) {
- cl->buf->last_buf = 0;
- }
- }
-
- if (frame_size || cl->buf->last_buf) {
- frame = ngx_http_v2_filter_get_data_frame(stream, frame_size,
- out, cl);
- if (frame == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- ngx_http_v2_queue_frame(h2c, frame);
-
- h2c->send_window -= frame_size;
-
- stream->send_window -= frame_size;
- stream->queued++;
- }
-
- if (in == NULL) {
-
- if (trailers != NGX_HTTP_V2_NO_TRAILERS) {
- ngx_http_v2_queue_frame(h2c, trailers);
- stream->queued++;
- }
-
- break;
- }
-
- limit -= frame_size;
-
- if (limit == 0) {
- break;
- }
- }
-
- if (offset) {
- cl = ngx_http_v2_filter_get_shadow(stream, in->buf, offset, size);
- if (cl == NULL) {
- return NGX_CHAIN_ERROR;
- }
-
- in->buf = cl->buf;
- ngx_free_chain(r->pool, cl);
- }
-
- if (ngx_http_v2_filter_send(fc, stream) == NGX_ERROR) {
- return NGX_CHAIN_ERROR;
- }
-
- if (in && ngx_http_v2_flow_control(h2c, stream) == NGX_DECLINED) {
- fc->write->active = 1;
- fc->write->ready = 0;
- }
-
- return in;
-}
-
-
-static ngx_chain_t *
-ngx_http_v2_filter_get_shadow(ngx_http_v2_stream_t *stream, ngx_buf_t *buf,
- off_t offset, off_t size)
-{
- ngx_buf_t *chunk;
- ngx_chain_t *cl;
-
- cl = ngx_chain_get_free_buf(stream->request->pool, &stream->free_bufs);
- if (cl == NULL) {
- return NULL;
- }
-
- chunk = cl->buf;
-
- ngx_memcpy(chunk, buf, sizeof(ngx_buf_t));
-
- chunk->tag = (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow;
- chunk->shadow = buf;
-
- if (ngx_buf_in_memory(chunk)) {
- chunk->pos += offset;
- chunk->last = chunk->pos + size;
- }
-
- if (chunk->in_file) {
- chunk->file_pos += offset;
- chunk->file_last = chunk->file_pos + size;
- }
-
- return cl;
-}
-
-
-static ngx_http_v2_out_frame_t *
-ngx_http_v2_filter_get_data_frame(ngx_http_v2_stream_t *stream,
- size_t len, ngx_chain_t *first, ngx_chain_t *last)
-{
- u_char flags;
- ngx_buf_t *buf;
- ngx_chain_t *cl;
- ngx_http_v2_out_frame_t *frame;
- ngx_http_v2_connection_t *h2c;
-
- frame = stream->free_frames;
- h2c = stream->connection;
-
- if (frame) {
- stream->free_frames = frame->next;
-
- } else if (h2c->frames < 10000) {
- frame = ngx_palloc(stream->request->pool,
- sizeof(ngx_http_v2_out_frame_t));
- if (frame == NULL) {
- return NULL;
- }
-
- stream->frames++;
- h2c->frames++;
-
- } else {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "http2 flood detected");
-
- h2c->connection->error = 1;
- return NULL;
- }
-
- flags = last->buf->last_buf ? NGX_HTTP_V2_END_STREAM_FLAG : 0;
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, stream->request->connection->log, 0,
- "http2:%ui create DATA frame %p: len:%uz flags:%ui",
- stream->node->id, frame, len, (ngx_uint_t) flags);
-
- cl = ngx_chain_get_free_buf(stream->request->pool,
- &stream->free_frame_headers);
- if (cl == NULL) {
- return NULL;
- }
-
- buf = cl->buf;
-
- if (buf->start == NULL) {
- buf->start = ngx_palloc(stream->request->pool,
- NGX_HTTP_V2_FRAME_HEADER_SIZE);
- if (buf->start == NULL) {
- return NULL;
- }
-
- buf->end = buf->start + NGX_HTTP_V2_FRAME_HEADER_SIZE;
- buf->last = buf->end;
-
- buf->tag = (ngx_buf_tag_t) &ngx_http_v2_module;
- buf->memory = 1;
- }
-
- buf->pos = buf->start;
- buf->last = buf->pos;
-
- buf->last = ngx_http_v2_write_len_and_type(buf->last, len,
- NGX_HTTP_V2_DATA_FRAME);
- *buf->last++ = flags;
-
- buf->last = ngx_http_v2_write_sid(buf->last, stream->node->id);
-
- cl->next = first;
- first = cl;
-
- last->buf->flush = 1;
-
- frame->first = first;
- frame->last = last;
- frame->handler = ngx_http_v2_data_frame_handler;
- frame->stream = stream;
- frame->length = len;
- frame->blocked = 0;
- frame->fin = last->buf->last_buf;
-
- return frame;
-}
-
-
-static ngx_inline ngx_int_t
-ngx_http_v2_flow_control(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream)
-{
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui windows: conn:%uz stream:%z",
- stream->node->id, h2c->send_window, stream->send_window);
-
- if (stream->send_window <= 0) {
- stream->exhausted = 1;
- return NGX_DECLINED;
- }
-
- if (h2c->send_window == 0) {
- ngx_http_v2_waiting_queue(h2c, stream);
- return NGX_DECLINED;
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_v2_waiting_queue(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream)
-{
- ngx_queue_t *q;
- ngx_http_v2_stream_t *s;
-
- if (stream->waiting) {
- return;
- }
-
- stream->waiting = 1;
-
- for (q = ngx_queue_last(&h2c->waiting);
- q != ngx_queue_sentinel(&h2c->waiting);
- q = ngx_queue_prev(q))
- {
- s = ngx_queue_data(q, ngx_http_v2_stream_t, queue);
-
- if (s->node->rank < stream->node->rank
- || (s->node->rank == stream->node->rank
- && s->node->rel_weight >= stream->node->rel_weight))
- {
- break;
- }
- }
-
- ngx_queue_insert_after(q, &stream->queue);
-}
-
-
-static ngx_inline ngx_int_t
-ngx_http_v2_filter_send(ngx_connection_t *fc, ngx_http_v2_stream_t *stream)
-{
- ngx_connection_t *c;
-
- c = stream->connection->connection;
-
- if (stream->queued == 0 && !c->buffered) {
- fc->buffered &= ~NGX_HTTP_V2_BUFFERED;
- return NGX_OK;
- }
-
- stream->blocked = 1;
-
- if (ngx_http_v2_send_output_queue(stream->connection) == NGX_ERROR) {
- fc->error = 1;
- return NGX_ERROR;
- }
-
- stream->blocked = 0;
-
- if (stream->queued) {
- fc->buffered |= NGX_HTTP_V2_BUFFERED;
- fc->write->active = 1;
- fc->write->ready = 0;
- return NGX_AGAIN;
- }
-
- fc->buffered &= ~NGX_HTTP_V2_BUFFERED;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_headers_frame_handler(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_chain_t *cl, *ln;
- ngx_http_v2_stream_t *stream;
-
- stream = frame->stream;
- cl = frame->first;
-
- for ( ;; ) {
- if (cl->buf->pos != cl->buf->last) {
- frame->first = cl;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui HEADERS frame %p was sent partially",
- stream->node->id, frame);
-
- return NGX_AGAIN;
- }
-
- ln = cl->next;
-
- if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
- cl->next = stream->free_frame_headers;
- stream->free_frame_headers = cl;
-
- } else {
- cl->next = stream->free_bufs;
- stream->free_bufs = cl;
- }
-
- if (cl == frame->last) {
- break;
- }
-
- cl = ln;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui HEADERS frame %p was sent",
- stream->node->id, frame);
-
- stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE
- + frame->length;
-
- h2c->payload_bytes += frame->length;
-
- ngx_http_v2_handle_frame(stream, frame);
-
- ngx_http_v2_handle_stream(h2c, stream);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_data_frame_handler(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_buf_t *buf;
- ngx_chain_t *cl, *ln;
- ngx_http_v2_stream_t *stream;
-
- stream = frame->stream;
- cl = frame->first;
-
- if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_module) {
-
- if (cl->buf->pos != cl->buf->last) {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui DATA frame %p was sent partially",
- stream->node->id, frame);
-
- return NGX_AGAIN;
- }
-
- ln = cl->next;
-
- cl->next = stream->free_frame_headers;
- stream->free_frame_headers = cl;
-
- if (cl == frame->last) {
- goto done;
- }
-
- cl = ln;
- }
-
- for ( ;; ) {
- if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) {
- buf = cl->buf->shadow;
-
- if (ngx_buf_in_memory(buf)) {
- buf->pos = cl->buf->pos;
- }
-
- if (buf->in_file) {
- buf->file_pos = cl->buf->file_pos;
- }
- }
-
- if (ngx_buf_size(cl->buf) != 0) {
-
- if (cl != frame->first) {
- frame->first = cl;
- ngx_http_v2_handle_stream(h2c, stream);
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui DATA frame %p was sent partially",
- stream->node->id, frame);
-
- return NGX_AGAIN;
- }
-
- ln = cl->next;
-
- if (cl->buf->tag == (ngx_buf_tag_t) &ngx_http_v2_filter_get_shadow) {
- cl->next = stream->free_bufs;
- stream->free_bufs = cl;
-
- } else {
- ngx_free_chain(stream->request->pool, cl);
- }
-
- if (cl == frame->last) {
- goto done;
- }
-
- cl = ln;
- }
-
-done:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2:%ui DATA frame %p was sent",
- stream->node->id, frame);
-
- stream->request->header_size += NGX_HTTP_V2_FRAME_HEADER_SIZE;
-
- h2c->payload_bytes += frame->length;
-
- ngx_http_v2_handle_frame(stream, frame);
-
- ngx_http_v2_handle_stream(h2c, stream);
-
- return NGX_OK;
-}
-
-
-static ngx_inline void
-ngx_http_v2_handle_frame(ngx_http_v2_stream_t *stream,
- ngx_http_v2_out_frame_t *frame)
-{
- ngx_http_request_t *r;
- ngx_http_v2_connection_t *h2c;
-
- r = stream->request;
-
- r->connection->sent += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
-
- h2c = stream->connection;
-
- h2c->total_bytes += NGX_HTTP_V2_FRAME_HEADER_SIZE + frame->length;
-
- if (frame->fin) {
- stream->out_closed = 1;
- }
-
- frame->next = stream->free_frames;
- stream->free_frames = frame;
-
- stream->queued--;
-}
-
-
-static ngx_inline void
-ngx_http_v2_handle_stream(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_stream_t *stream)
-{
- ngx_event_t *wev;
- ngx_connection_t *fc;
-
- if (stream->waiting || stream->blocked) {
- return;
- }
-
- fc = stream->request->connection;
-
- if (!fc->error && stream->exhausted) {
- return;
- }
-
- wev = fc->write;
-
- wev->active = 0;
- wev->ready = 1;
-
- if (!fc->error && wev->delayed) {
- return;
- }
-
- ngx_post_event(wev, &ngx_posted_events);
-}
-
-
-static void
-ngx_http_v2_filter_cleanup(void *data)
-{
- ngx_http_v2_stream_t *stream = data;
-
- size_t window;
- ngx_event_t *wev;
- ngx_queue_t *q;
- ngx_http_v2_out_frame_t *frame, **fn;
- ngx_http_v2_connection_t *h2c;
-
- if (stream->waiting) {
- stream->waiting = 0;
- ngx_queue_remove(&stream->queue);
- }
-
- if (stream->queued == 0) {
- return;
- }
-
- window = 0;
- h2c = stream->connection;
- fn = &h2c->last_out;
-
- for ( ;; ) {
- frame = *fn;
-
- if (frame == NULL) {
- break;
- }
-
- if (frame->stream == stream && !frame->blocked) {
- *fn = frame->next;
-
- window += frame->length;
-
- if (--stream->queued == 0) {
- break;
- }
-
- continue;
- }
-
- fn = &frame->next;
- }
-
- if (h2c->send_window == 0 && window) {
-
- while (!ngx_queue_empty(&h2c->waiting)) {
- q = ngx_queue_head(&h2c->waiting);
-
- ngx_queue_remove(q);
-
- stream = ngx_queue_data(q, ngx_http_v2_stream_t, queue);
-
- stream->waiting = 0;
-
- wev = stream->request->connection->write;
-
- wev->active = 0;
- wev->ready = 1;
-
- if (!wev->delayed) {
- ngx_post_event(wev, &ngx_posted_events);
- }
- }
- }
-
- h2c->send_window += window;
-}
-
-
-static ngx_int_t
-ngx_http_v2_filter_init(ngx_conf_t *cf)
-{
- ngx_http_next_header_filter = ngx_http_top_header_filter;
- ngx_http_top_header_filter = ngx_http_v2_header_filter;
-
- ngx_http_next_early_hints_filter = ngx_http_top_early_hints_filter;
- ngx_http_top_early_hints_filter = ngx_http_v2_early_hints_filter;
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.c b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.c
deleted file mode 100644
index d64488c20b..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.c
+++ /dev/null
@@ -1,498 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#include
-#include
-#include
-#include
-
-
-static ngx_int_t ngx_http_v2_add_variables(ngx_conf_t *cf);
-
-static ngx_int_t ngx_http_v2_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-
-static ngx_int_t ngx_http_v2_module_init(ngx_cycle_t *cycle);
-
-static void *ngx_http_v2_create_main_conf(ngx_conf_t *cf);
-static char *ngx_http_v2_init_main_conf(ngx_conf_t *cf, void *conf);
-static void *ngx_http_v2_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_http_v2_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-static void *ngx_http_v2_create_loc_conf(ngx_conf_t *cf);
-static char *ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-static char *ngx_http_v2_recv_buffer_size(ngx_conf_t *cf, void *post,
- void *data);
-static char *ngx_http_v2_pool_size(ngx_conf_t *cf, void *post, void *data);
-static char *ngx_http_v2_preread_size(ngx_conf_t *cf, void *post, void *data);
-static char *ngx_http_v2_streams_index_mask(ngx_conf_t *cf, void *post,
- void *data);
-static char *ngx_http_v2_chunk_size(ngx_conf_t *cf, void *post, void *data);
-static char *ngx_http_v2_obsolete(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-
-
-static ngx_conf_deprecated_t ngx_http_v2_recv_timeout_deprecated = {
- ngx_conf_deprecated, "http2_recv_timeout", "client_header_timeout"
-};
-
-static ngx_conf_deprecated_t ngx_http_v2_idle_timeout_deprecated = {
- ngx_conf_deprecated, "http2_idle_timeout", "keepalive_timeout"
-};
-
-static ngx_conf_deprecated_t ngx_http_v2_max_requests_deprecated = {
- ngx_conf_deprecated, "http2_max_requests", "keepalive_requests"
-};
-
-static ngx_conf_deprecated_t ngx_http_v2_max_field_size_deprecated = {
- ngx_conf_deprecated, "http2_max_field_size", "large_client_header_buffers"
-};
-
-static ngx_conf_deprecated_t ngx_http_v2_max_header_size_deprecated = {
- ngx_conf_deprecated, "http2_max_header_size", "large_client_header_buffers"
-};
-
-
-static ngx_conf_post_t ngx_http_v2_recv_buffer_size_post =
- { ngx_http_v2_recv_buffer_size };
-static ngx_conf_post_t ngx_http_v2_pool_size_post =
- { ngx_http_v2_pool_size };
-static ngx_conf_post_t ngx_http_v2_preread_size_post =
- { ngx_http_v2_preread_size };
-static ngx_conf_post_t ngx_http_v2_streams_index_mask_post =
- { ngx_http_v2_streams_index_mask };
-static ngx_conf_post_t ngx_http_v2_chunk_size_post =
- { ngx_http_v2_chunk_size };
-
-
-static ngx_command_t ngx_http_v2_commands[] = {
-
- { ngx_string("http2"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v2_srv_conf_t, enable),
- NULL },
-
- { ngx_string("http2_recv_buffer_size"),
- NGX_HTTP_MAIN_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_MAIN_CONF_OFFSET,
- offsetof(ngx_http_v2_main_conf_t, recv_buffer_size),
- &ngx_http_v2_recv_buffer_size_post },
-
- { ngx_string("http2_pool_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v2_srv_conf_t, pool_size),
- &ngx_http_v2_pool_size_post },
-
- { ngx_string("http2_max_concurrent_streams"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v2_srv_conf_t, concurrent_streams),
- NULL },
-
- { ngx_string("http2_max_concurrent_pushes"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- NULL },
-
- { ngx_string("http2_max_requests"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- &ngx_http_v2_max_requests_deprecated },
-
- { ngx_string("http2_max_field_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- &ngx_http_v2_max_field_size_deprecated },
-
- { ngx_string("http2_max_header_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- &ngx_http_v2_max_header_size_deprecated },
-
- { ngx_string("http2_body_preread_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v2_srv_conf_t, preread_size),
- &ngx_http_v2_preread_size_post },
-
- { ngx_string("http2_streams_index_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v2_srv_conf_t, streams_index_mask),
- &ngx_http_v2_streams_index_mask_post },
-
- { ngx_string("http2_recv_timeout"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- &ngx_http_v2_recv_timeout_deprecated },
-
- { ngx_string("http2_idle_timeout"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- &ngx_http_v2_idle_timeout_deprecated },
-
- { ngx_string("http2_chunk_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_LOC_CONF_OFFSET,
- offsetof(ngx_http_v2_loc_conf_t, chunk_size),
- &ngx_http_v2_chunk_size_post },
-
- { ngx_string("http2_push_preload"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_FLAG,
- ngx_http_v2_obsolete,
- 0,
- 0,
- NULL },
-
- { ngx_string("http2_push"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_HTTP_LOC_CONF|NGX_CONF_TAKE1,
- ngx_http_v2_obsolete,
- 0,
- 0,
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_http_module_t ngx_http_v2_module_ctx = {
- ngx_http_v2_add_variables, /* preconfiguration */
- NULL, /* postconfiguration */
-
- ngx_http_v2_create_main_conf, /* create main configuration */
- ngx_http_v2_init_main_conf, /* init main configuration */
-
- ngx_http_v2_create_srv_conf, /* create server configuration */
- ngx_http_v2_merge_srv_conf, /* merge server configuration */
-
- ngx_http_v2_create_loc_conf, /* create location configuration */
- ngx_http_v2_merge_loc_conf /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_v2_module = {
- NGX_MODULE_V1,
- &ngx_http_v2_module_ctx, /* module context */
- ngx_http_v2_commands, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- ngx_http_v2_module_init, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_http_variable_t ngx_http_v2_vars[] = {
-
- { ngx_string("http2"), NULL,
- ngx_http_v2_variable, 0, 0, 0 },
-
- ngx_http_null_variable
-};
-
-
-static ngx_int_t
-ngx_http_v2_add_variables(ngx_conf_t *cf)
-{
- ngx_http_variable_t *var, *v;
-
- for (v = ngx_http_v2_vars; v->name.len; v++) {
- var = ngx_http_add_variable(cf, &v->name, v->flags);
- if (var == NULL) {
- return NGX_ERROR;
- }
-
- var->get_handler = v->get_handler;
- var->data = v->data;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
-
- if (r->stream) {
-#if (NGX_HTTP_SSL)
-
- if (r->connection->ssl) {
- v->len = sizeof("h2") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "h2";
-
- return NGX_OK;
- }
-
-#endif
- v->len = sizeof("h2c") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "h2c";
-
- return NGX_OK;
- }
-
- *v = ngx_http_variable_null_value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_module_init(ngx_cycle_t *cycle)
-{
- return NGX_OK;
-}
-
-
-static void *
-ngx_http_v2_create_main_conf(ngx_conf_t *cf)
-{
- ngx_http_v2_main_conf_t *h2mcf;
-
- h2mcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v2_main_conf_t));
- if (h2mcf == NULL) {
- return NULL;
- }
-
- h2mcf->recv_buffer_size = NGX_CONF_UNSET_SIZE;
-
- return h2mcf;
-}
-
-
-static char *
-ngx_http_v2_init_main_conf(ngx_conf_t *cf, void *conf)
-{
- ngx_http_v2_main_conf_t *h2mcf = conf;
-
- ngx_conf_init_size_value(h2mcf->recv_buffer_size, 256 * 1024);
-
- return NGX_CONF_OK;
-}
-
-
-static void *
-ngx_http_v2_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_http_v2_srv_conf_t *h2scf;
-
- h2scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v2_srv_conf_t));
- if (h2scf == NULL) {
- return NULL;
- }
-
- h2scf->enable = NGX_CONF_UNSET;
-
- h2scf->pool_size = NGX_CONF_UNSET_SIZE;
-
- h2scf->concurrent_streams = NGX_CONF_UNSET_UINT;
-
- h2scf->preread_size = NGX_CONF_UNSET_SIZE;
-
- h2scf->streams_index_mask = NGX_CONF_UNSET_UINT;
-
- return h2scf;
-}
-
-
-static char *
-ngx_http_v2_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_http_v2_srv_conf_t *prev = parent;
- ngx_http_v2_srv_conf_t *conf = child;
-
- ngx_conf_merge_value(conf->enable, prev->enable, 0);
-
- ngx_conf_merge_size_value(conf->pool_size, prev->pool_size, 4096);
-
- ngx_conf_merge_uint_value(conf->concurrent_streams,
- prev->concurrent_streams, 128);
-
- ngx_conf_merge_size_value(conf->preread_size, prev->preread_size, 65536);
-
- ngx_conf_merge_uint_value(conf->streams_index_mask,
- prev->streams_index_mask, 32 - 1);
-
- return NGX_CONF_OK;
-}
-
-
-static void *
-ngx_http_v2_create_loc_conf(ngx_conf_t *cf)
-{
- ngx_http_v2_loc_conf_t *h2lcf;
-
- h2lcf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v2_loc_conf_t));
- if (h2lcf == NULL) {
- return NULL;
- }
-
- h2lcf->chunk_size = NGX_CONF_UNSET_SIZE;
-
- return h2lcf;
-}
-
-
-static char *
-ngx_http_v2_merge_loc_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_http_v2_loc_conf_t *prev = parent;
- ngx_http_v2_loc_conf_t *conf = child;
-
- ngx_conf_merge_size_value(conf->chunk_size, prev->chunk_size, 8 * 1024);
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_recv_buffer_size(ngx_conf_t *cf, void *post, void *data)
-{
- size_t *sp = data;
-
- if (*sp <= NGX_HTTP_V2_STATE_BUFFER_SIZE) {
- return "value is too small";
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_pool_size(ngx_conf_t *cf, void *post, void *data)
-{
- size_t *sp = data;
-
- if (*sp < NGX_MIN_POOL_SIZE) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the pool size must be no less than %uz",
- NGX_MIN_POOL_SIZE);
-
- return NGX_CONF_ERROR;
- }
-
- if (*sp % NGX_POOL_ALIGNMENT) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the pool size must be a multiple of %uz",
- NGX_POOL_ALIGNMENT);
-
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_preread_size(ngx_conf_t *cf, void *post, void *data)
-{
- size_t *sp = data;
-
- if (*sp > NGX_HTTP_V2_MAX_WINDOW) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the maximum body preread buffer size is %uz",
- NGX_HTTP_V2_MAX_WINDOW);
-
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_streams_index_mask(ngx_conf_t *cf, void *post, void *data)
-{
- ngx_uint_t *np = data;
-
- ngx_uint_t mask;
-
- mask = *np - 1;
-
- if (*np == 0 || (*np & mask)) {
- return "must be a power of two";
- }
-
- *np = mask;
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_chunk_size(ngx_conf_t *cf, void *post, void *data)
-{
- size_t *sp = data;
-
- if (*sp == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the http2 chunk size cannot be zero");
-
- return NGX_CONF_ERROR;
- }
-
- if (*sp > NGX_HTTP_V2_MAX_FRAME_SIZE) {
- *sp = NGX_HTTP_V2_MAX_FRAME_SIZE;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_v2_obsolete(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_conf_deprecated_t *d = cmd->post;
-
- if (d) {
- ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
- "the \"%s\" directive is obsolete, "
- "use the \"%s\" directive instead",
- d->old_name, d->new_name);
-
- } else {
- ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
- "the \"%V\" directive is obsolete, ignored",
- &cmd->name);
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.h b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.h
deleted file mode 100644
index 07a595cfdd..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_module.h
+++ /dev/null
@@ -1,28 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#ifndef _NGX_HTTP_V2_MODULE_H_INCLUDED_
-#define _NGX_HTTP_V2_MODULE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- size_t recv_buffer_size;
- u_char *recv_buffer;
-} ngx_http_v2_main_conf_t;
-
-
-typedef struct {
- size_t chunk_size;
-} ngx_http_v2_loc_conf_t;
-
-
-#endif /* _NGX_HTTP_V2_MODULE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_table.c b/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_table.c
deleted file mode 100644
index 7d49803fdb..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v2/ngx_http_v2_table.c
+++ /dev/null
@@ -1,363 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Valentin V. Bartenev
- */
-
-
-#include
-#include
-#include
-
-
-#define NGX_HTTP_V2_TABLE_SIZE 4096
-
-
-static ngx_int_t ngx_http_v2_table_account(ngx_http_v2_connection_t *h2c,
- size_t size);
-
-
-static ngx_http_v2_header_t ngx_http_v2_static_table[] = {
- { ngx_string(":authority"), ngx_string("") },
- { ngx_string(":method"), ngx_string("GET") },
- { ngx_string(":method"), ngx_string("POST") },
- { ngx_string(":path"), ngx_string("/") },
- { ngx_string(":path"), ngx_string("/index.html") },
- { ngx_string(":scheme"), ngx_string("http") },
- { ngx_string(":scheme"), ngx_string("https") },
- { ngx_string(":status"), ngx_string("200") },
- { ngx_string(":status"), ngx_string("204") },
- { ngx_string(":status"), ngx_string("206") },
- { ngx_string(":status"), ngx_string("304") },
- { ngx_string(":status"), ngx_string("400") },
- { ngx_string(":status"), ngx_string("404") },
- { ngx_string(":status"), ngx_string("500") },
- { ngx_string("accept-charset"), ngx_string("") },
- { ngx_string("accept-encoding"), ngx_string("gzip, deflate") },
- { ngx_string("accept-language"), ngx_string("") },
- { ngx_string("accept-ranges"), ngx_string("") },
- { ngx_string("accept"), ngx_string("") },
- { ngx_string("access-control-allow-origin"), ngx_string("") },
- { ngx_string("age"), ngx_string("") },
- { ngx_string("allow"), ngx_string("") },
- { ngx_string("authorization"), ngx_string("") },
- { ngx_string("cache-control"), ngx_string("") },
- { ngx_string("content-disposition"), ngx_string("") },
- { ngx_string("content-encoding"), ngx_string("") },
- { ngx_string("content-language"), ngx_string("") },
- { ngx_string("content-length"), ngx_string("") },
- { ngx_string("content-location"), ngx_string("") },
- { ngx_string("content-range"), ngx_string("") },
- { ngx_string("content-type"), ngx_string("") },
- { ngx_string("cookie"), ngx_string("") },
- { ngx_string("date"), ngx_string("") },
- { ngx_string("etag"), ngx_string("") },
- { ngx_string("expect"), ngx_string("") },
- { ngx_string("expires"), ngx_string("") },
- { ngx_string("from"), ngx_string("") },
- { ngx_string("host"), ngx_string("") },
- { ngx_string("if-match"), ngx_string("") },
- { ngx_string("if-modified-since"), ngx_string("") },
- { ngx_string("if-none-match"), ngx_string("") },
- { ngx_string("if-range"), ngx_string("") },
- { ngx_string("if-unmodified-since"), ngx_string("") },
- { ngx_string("last-modified"), ngx_string("") },
- { ngx_string("link"), ngx_string("") },
- { ngx_string("location"), ngx_string("") },
- { ngx_string("max-forwards"), ngx_string("") },
- { ngx_string("proxy-authenticate"), ngx_string("") },
- { ngx_string("proxy-authorization"), ngx_string("") },
- { ngx_string("range"), ngx_string("") },
- { ngx_string("referer"), ngx_string("") },
- { ngx_string("refresh"), ngx_string("") },
- { ngx_string("retry-after"), ngx_string("") },
- { ngx_string("server"), ngx_string("") },
- { ngx_string("set-cookie"), ngx_string("") },
- { ngx_string("strict-transport-security"), ngx_string("") },
- { ngx_string("transfer-encoding"), ngx_string("") },
- { ngx_string("user-agent"), ngx_string("") },
- { ngx_string("vary"), ngx_string("") },
- { ngx_string("via"), ngx_string("") },
- { ngx_string("www-authenticate"), ngx_string("") },
-};
-
-#define NGX_HTTP_V2_STATIC_TABLE_ENTRIES \
- (sizeof(ngx_http_v2_static_table) \
- / sizeof(ngx_http_v2_header_t))
-
-
-ngx_str_t *
-ngx_http_v2_get_static_name(ngx_uint_t index)
-{
- return &ngx_http_v2_static_table[index - 1].name;
-}
-
-
-ngx_str_t *
-ngx_http_v2_get_static_value(ngx_uint_t index)
-{
- return &ngx_http_v2_static_table[index - 1].value;
-}
-
-
-ngx_int_t
-ngx_http_v2_get_indexed_header(ngx_http_v2_connection_t *h2c, ngx_uint_t index,
- ngx_uint_t name_only)
-{
- u_char *p;
- size_t rest;
- ngx_http_v2_header_t *entry;
-
- if (index == 0) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent invalid hpack table index 0");
- return NGX_ERROR;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 get indexed %s: %ui",
- name_only ? "name" : "header", index);
-
- index--;
-
- if (index < NGX_HTTP_V2_STATIC_TABLE_ENTRIES) {
- h2c->state.header = ngx_http_v2_static_table[index];
- return NGX_OK;
- }
-
- index -= NGX_HTTP_V2_STATIC_TABLE_ENTRIES;
-
- if (index < h2c->hpack.added - h2c->hpack.deleted) {
- index = (h2c->hpack.added - index - 1) % h2c->hpack.allocated;
- entry = h2c->hpack.entries[index];
-
- p = ngx_pnalloc(h2c->state.pool, entry->name.len + 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- h2c->state.header.name.len = entry->name.len;
- h2c->state.header.name.data = p;
-
- rest = h2c->hpack.storage + NGX_HTTP_V2_TABLE_SIZE - entry->name.data;
-
- if (entry->name.len > rest) {
- p = ngx_cpymem(p, entry->name.data, rest);
- p = ngx_cpymem(p, h2c->hpack.storage, entry->name.len - rest);
-
- } else {
- p = ngx_cpymem(p, entry->name.data, entry->name.len);
- }
-
- *p = '\0';
-
- if (name_only) {
- return NGX_OK;
- }
-
- p = ngx_pnalloc(h2c->state.pool, entry->value.len + 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- h2c->state.header.value.len = entry->value.len;
- h2c->state.header.value.data = p;
-
- rest = h2c->hpack.storage + NGX_HTTP_V2_TABLE_SIZE - entry->value.data;
-
- if (entry->value.len > rest) {
- p = ngx_cpymem(p, entry->value.data, rest);
- p = ngx_cpymem(p, h2c->hpack.storage, entry->value.len - rest);
-
- } else {
- p = ngx_cpymem(p, entry->value.data, entry->value.len);
- }
-
- *p = '\0';
-
- return NGX_OK;
- }
-
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent out of bound hpack table index: %ui", index);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v2_add_header(ngx_http_v2_connection_t *h2c,
- ngx_http_v2_header_t *header)
-{
- size_t avail;
- ngx_uint_t index;
- ngx_http_v2_header_t *entry, **entries;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 table add: \"%V: %V\"",
- &header->name, &header->value);
-
- if (h2c->hpack.entries == NULL) {
- h2c->hpack.allocated = 64;
- h2c->hpack.size = NGX_HTTP_V2_TABLE_SIZE;
- h2c->hpack.free = NGX_HTTP_V2_TABLE_SIZE;
-
- h2c->hpack.entries = ngx_palloc(h2c->connection->pool,
- sizeof(ngx_http_v2_header_t *)
- * h2c->hpack.allocated);
- if (h2c->hpack.entries == NULL) {
- return NGX_ERROR;
- }
-
- h2c->hpack.storage = ngx_palloc(h2c->connection->pool,
- h2c->hpack.free);
- if (h2c->hpack.storage == NULL) {
- return NGX_ERROR;
- }
-
- h2c->hpack.pos = h2c->hpack.storage;
- }
-
- if (ngx_http_v2_table_account(h2c, header->name.len + header->value.len)
- != NGX_OK)
- {
- return NGX_OK;
- }
-
- if (h2c->hpack.reused == h2c->hpack.deleted) {
- entry = ngx_palloc(h2c->connection->pool, sizeof(ngx_http_v2_header_t));
- if (entry == NULL) {
- return NGX_ERROR;
- }
-
- } else {
- entry = h2c->hpack.entries[h2c->hpack.reused++ % h2c->hpack.allocated];
- }
-
- avail = h2c->hpack.storage + NGX_HTTP_V2_TABLE_SIZE - h2c->hpack.pos;
-
- entry->name.len = header->name.len;
- entry->name.data = h2c->hpack.pos;
-
- if (avail >= header->name.len) {
- h2c->hpack.pos = ngx_cpymem(h2c->hpack.pos, header->name.data,
- header->name.len);
- } else {
- ngx_memcpy(h2c->hpack.pos, header->name.data, avail);
- h2c->hpack.pos = ngx_cpymem(h2c->hpack.storage,
- header->name.data + avail,
- header->name.len - avail);
- avail = NGX_HTTP_V2_TABLE_SIZE;
- }
-
- avail -= header->name.len;
-
- entry->value.len = header->value.len;
- entry->value.data = h2c->hpack.pos;
-
- if (avail >= header->value.len) {
- h2c->hpack.pos = ngx_cpymem(h2c->hpack.pos, header->value.data,
- header->value.len);
- } else {
- ngx_memcpy(h2c->hpack.pos, header->value.data, avail);
- h2c->hpack.pos = ngx_cpymem(h2c->hpack.storage,
- header->value.data + avail,
- header->value.len - avail);
- }
-
- if (h2c->hpack.allocated == h2c->hpack.added - h2c->hpack.deleted) {
-
- entries = ngx_palloc(h2c->connection->pool,
- sizeof(ngx_http_v2_header_t *)
- * (h2c->hpack.allocated + 64));
- if (entries == NULL) {
- return NGX_ERROR;
- }
-
- index = h2c->hpack.deleted % h2c->hpack.allocated;
-
- ngx_memcpy(entries, &h2c->hpack.entries[index],
- (h2c->hpack.allocated - index)
- * sizeof(ngx_http_v2_header_t *));
-
- ngx_memcpy(&entries[h2c->hpack.allocated - index], h2c->hpack.entries,
- index * sizeof(ngx_http_v2_header_t *));
-
- (void) ngx_pfree(h2c->connection->pool, h2c->hpack.entries);
-
- h2c->hpack.entries = entries;
-
- h2c->hpack.added = h2c->hpack.allocated;
- h2c->hpack.deleted = 0;
- h2c->hpack.reused = 0;
- h2c->hpack.allocated += 64;
- }
-
- h2c->hpack.entries[h2c->hpack.added++ % h2c->hpack.allocated] = entry;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v2_table_account(ngx_http_v2_connection_t *h2c, size_t size)
-{
- ngx_http_v2_header_t *entry;
-
- size += 32;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 table account: %uz free:%uz",
- size, h2c->hpack.free);
-
- if (size <= h2c->hpack.free) {
- h2c->hpack.free -= size;
- return NGX_OK;
- }
-
- if (size > h2c->hpack.size) {
- h2c->hpack.deleted = h2c->hpack.added;
- h2c->hpack.free = h2c->hpack.size;
- return NGX_DECLINED;
- }
-
- do {
- entry = h2c->hpack.entries[h2c->hpack.deleted++ % h2c->hpack.allocated];
- h2c->hpack.free += 32 + entry->name.len + entry->value.len;
- } while (size > h2c->hpack.free);
-
- h2c->hpack.free -= size;
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v2_table_size(ngx_http_v2_connection_t *h2c, size_t size)
-{
- ssize_t needed;
- ngx_http_v2_header_t *entry;
-
- if (size > NGX_HTTP_V2_TABLE_SIZE) {
- ngx_log_error(NGX_LOG_INFO, h2c->connection->log, 0,
- "client sent invalid table size update: %uz", size);
-
- return NGX_ERROR;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0,
- "http2 new hpack table size: %uz was:%uz",
- size, h2c->hpack.size);
-
- needed = h2c->hpack.size - size;
-
- while (needed > (ssize_t) h2c->hpack.free) {
- entry = h2c->hpack.entries[h2c->hpack.deleted++ % h2c->hpack.allocated];
- h2c->hpack.free += 32 + entry->name.len + entry->value.len;
- }
-
- h2c->hpack.size = size;
- h2c->hpack.free -= needed;
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.c
deleted file mode 100644
index d8597ec5c7..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.c
+++ /dev/null
@@ -1,111 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-static void ngx_http_v3_keepalive_handler(ngx_event_t *ev);
-static void ngx_http_v3_cleanup_session(void *data);
-
-
-ngx_int_t
-ngx_http_v3_init_session(ngx_connection_t *c)
-{
- ngx_pool_cleanup_t *cln;
- ngx_http_connection_t *hc;
- ngx_http_v3_session_t *h3c;
-
- hc = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init session");
-
- h3c = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_session_t));
- if (h3c == NULL) {
- goto failed;
- }
-
- h3c->http_connection = hc;
-
- ngx_queue_init(&h3c->blocked);
-
- h3c->keepalive.log = c->log;
- h3c->keepalive.data = c;
- h3c->keepalive.handler = ngx_http_v3_keepalive_handler;
-
- h3c->table.send_insert_count.log = c->log;
- h3c->table.send_insert_count.data = c;
- h3c->table.send_insert_count.handler = ngx_http_v3_inc_insert_count_handler;
-
- cln = ngx_pool_cleanup_add(c->pool, 0);
- if (cln == NULL) {
- goto failed;
- }
-
- cln->handler = ngx_http_v3_cleanup_session;
- cln->data = h3c;
-
- c->data = h3c;
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to create http3 session");
- return NGX_ERROR;
-}
-
-
-static void
-ngx_http_v3_keepalive_handler(ngx_event_t *ev)
-{
- ngx_connection_t *c;
-
- c = ev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 keepalive handler");
-
- ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "keepalive timeout");
-}
-
-
-static void
-ngx_http_v3_cleanup_session(void *data)
-{
- ngx_http_v3_session_t *h3c = data;
-
- ngx_http_v3_cleanup_table(h3c);
-
- if (h3c->keepalive.timer_set) {
- ngx_del_timer(&h3c->keepalive);
- }
-
- if (h3c->table.send_insert_count.posted) {
- ngx_delete_posted_event(&h3c->table.send_insert_count);
- }
-}
-
-
-ngx_int_t
-ngx_http_v3_check_flood(ngx_connection_t *c)
-{
- ngx_http_v3_session_t *h3c;
-
- h3c = ngx_http_v3_get_session(c);
-
- if (h3c->total_bytes / 8 > h3c->payload_bytes + 1048576) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "http3 flood detected");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "HTTP/3 flood detected");
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.h b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.h
deleted file mode 100644
index 8fd212c1f0..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3.h
+++ /dev/null
@@ -1,160 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_V3_H_INCLUDED_
-#define _NGX_HTTP_V3_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-
-#define NGX_HTTP_V3_ALPN_PROTO "\x02h3"
-#define NGX_HTTP_V3_HQ_ALPN_PROTO "\x0Ahq-interop"
-#define NGX_HTTP_V3_HQ_PROTO "hq-interop"
-
-#define NGX_HTTP_V3_VARLEN_INT_LEN 8
-#define NGX_HTTP_V3_PREFIX_INT_LEN 11
-
-#define NGX_HTTP_V3_STREAM_CONTROL 0x00
-#define NGX_HTTP_V3_STREAM_PUSH 0x01
-#define NGX_HTTP_V3_STREAM_ENCODER 0x02
-#define NGX_HTTP_V3_STREAM_DECODER 0x03
-
-#define NGX_HTTP_V3_FRAME_DATA 0x00
-#define NGX_HTTP_V3_FRAME_HEADERS 0x01
-#define NGX_HTTP_V3_FRAME_CANCEL_PUSH 0x03
-#define NGX_HTTP_V3_FRAME_SETTINGS 0x04
-#define NGX_HTTP_V3_FRAME_PUSH_PROMISE 0x05
-#define NGX_HTTP_V3_FRAME_GOAWAY 0x07
-#define NGX_HTTP_V3_FRAME_MAX_PUSH_ID 0x0d
-
-#define NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY 0x01
-#define NGX_HTTP_V3_PARAM_MAX_FIELD_SECTION_SIZE 0x06
-#define NGX_HTTP_V3_PARAM_BLOCKED_STREAMS 0x07
-
-#define NGX_HTTP_V3_MAX_TABLE_CAPACITY 4096
-
-#define NGX_HTTP_V3_STREAM_CLIENT_CONTROL 0
-#define NGX_HTTP_V3_STREAM_SERVER_CONTROL 1
-#define NGX_HTTP_V3_STREAM_CLIENT_ENCODER 2
-#define NGX_HTTP_V3_STREAM_SERVER_ENCODER 3
-#define NGX_HTTP_V3_STREAM_CLIENT_DECODER 4
-#define NGX_HTTP_V3_STREAM_SERVER_DECODER 5
-#define NGX_HTTP_V3_MAX_KNOWN_STREAM 6
-#define NGX_HTTP_V3_MAX_UNI_STREAMS 3
-
-/* HTTP/3 errors */
-#define NGX_HTTP_V3_ERR_NO_ERROR 0x100
-#define NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR 0x101
-#define NGX_HTTP_V3_ERR_INTERNAL_ERROR 0x102
-#define NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR 0x103
-#define NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM 0x104
-#define NGX_HTTP_V3_ERR_FRAME_UNEXPECTED 0x105
-#define NGX_HTTP_V3_ERR_FRAME_ERROR 0x106
-#define NGX_HTTP_V3_ERR_EXCESSIVE_LOAD 0x107
-#define NGX_HTTP_V3_ERR_ID_ERROR 0x108
-#define NGX_HTTP_V3_ERR_SETTINGS_ERROR 0x109
-#define NGX_HTTP_V3_ERR_MISSING_SETTINGS 0x10a
-#define NGX_HTTP_V3_ERR_REQUEST_REJECTED 0x10b
-#define NGX_HTTP_V3_ERR_REQUEST_CANCELLED 0x10c
-#define NGX_HTTP_V3_ERR_REQUEST_INCOMPLETE 0x10d
-#define NGX_HTTP_V3_ERR_CONNECT_ERROR 0x10f
-#define NGX_HTTP_V3_ERR_VERSION_FALLBACK 0x110
-
-/* QPACK errors */
-#define NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED 0x200
-#define NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR 0x201
-#define NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR 0x202
-
-
-#define ngx_http_v3_get_session(c) \
- ((ngx_http_v3_session_t *) ((c)->quic ? (c)->quic->parent->data \
- : (c)->data))
-
-#define ngx_http_quic_get_connection(c) \
- (ngx_http_v3_get_session(c)->http_connection)
-
-#define ngx_http_v3_get_module_loc_conf(c, module) \
- ngx_http_get_module_loc_conf(ngx_http_quic_get_connection(c)->conf_ctx, \
- module)
-
-#define ngx_http_v3_get_module_srv_conf(c, module) \
- ngx_http_get_module_srv_conf(ngx_http_quic_get_connection(c)->conf_ctx, \
- module)
-
-#define ngx_http_v3_finalize_connection(c, code, reason) \
- ngx_quic_finalize_connection((c)->quic ? (c)->quic->parent : (c), \
- code, reason)
-
-#define ngx_http_v3_shutdown_connection(c, code, reason) \
- ngx_quic_shutdown_connection((c)->quic ? (c)->quic->parent : (c), \
- code, reason)
-
-
-typedef struct {
- ngx_flag_t enable;
- ngx_flag_t enable_hq;
- size_t max_table_capacity;
- ngx_uint_t max_blocked_streams;
- ngx_uint_t max_concurrent_streams;
- ngx_quic_conf_t quic;
-} ngx_http_v3_srv_conf_t;
-
-
-struct ngx_http_v3_parse_s {
- size_t header_limit;
- ngx_http_v3_parse_headers_t headers;
- ngx_http_v3_parse_data_t body;
- ngx_array_t *cookies;
-};
-
-
-struct ngx_http_v3_session_s {
- ngx_http_connection_t *http_connection;
-
- ngx_http_v3_dynamic_table_t table;
-
- ngx_event_t keepalive;
- ngx_uint_t nrequests;
-
- ngx_queue_t blocked;
- ngx_uint_t nblocked;
-
- uint64_t next_request_id;
-
- off_t total_bytes;
- off_t payload_bytes;
-
- unsigned goaway:1;
- unsigned hq:1;
-
- ngx_connection_t *known_streams[NGX_HTTP_V3_MAX_KNOWN_STREAM];
-};
-
-
-void ngx_http_v3_init_stream(ngx_connection_t *c);
-void ngx_http_v3_reset_stream(ngx_connection_t *c);
-ngx_int_t ngx_http_v3_init_session(ngx_connection_t *c);
-ngx_int_t ngx_http_v3_check_flood(ngx_connection_t *c);
-ngx_int_t ngx_http_v3_init(ngx_connection_t *c);
-void ngx_http_v3_shutdown(ngx_connection_t *c);
-
-ngx_int_t ngx_http_v3_read_request_body(ngx_http_request_t *r);
-ngx_int_t ngx_http_v3_read_unbuffered_request_body(ngx_http_request_t *r);
-
-
-extern ngx_module_t ngx_http_v3_module;
-
-
-#endif /* _NGX_HTTP_V3_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.c
deleted file mode 100644
index fb089c4132..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.c
+++ /dev/null
@@ -1,304 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-uintptr_t
-ngx_http_v3_encode_varlen_int(u_char *p, uint64_t value)
-{
- if (value <= 63) {
- if (p == NULL) {
- return 1;
- }
-
- *p++ = value;
- return (uintptr_t) p;
- }
-
- if (value <= 16383) {
- if (p == NULL) {
- return 2;
- }
-
- *p++ = 0x40 | (value >> 8);
- *p++ = value;
- return (uintptr_t) p;
- }
-
- if (value <= 1073741823) {
- if (p == NULL) {
- return 4;
- }
-
- *p++ = 0x80 | (value >> 24);
- *p++ = (value >> 16);
- *p++ = (value >> 8);
- *p++ = value;
- return (uintptr_t) p;
- }
-
- if (p == NULL) {
- return 8;
- }
-
- *p++ = 0xc0 | (value >> 56);
- *p++ = (value >> 48);
- *p++ = (value >> 40);
- *p++ = (value >> 32);
- *p++ = (value >> 24);
- *p++ = (value >> 16);
- *p++ = (value >> 8);
- *p++ = value;
- return (uintptr_t) p;
-}
-
-
-uintptr_t
-ngx_http_v3_encode_prefix_int(u_char *p, uint64_t value, ngx_uint_t prefix)
-{
- ngx_uint_t thresh, n;
-
- thresh = (1 << prefix) - 1;
-
- if (value < thresh) {
- if (p == NULL) {
- return 1;
- }
-
- *p++ |= value;
- return (uintptr_t) p;
- }
-
- value -= thresh;
-
- if (p == NULL) {
- for (n = 2; value >= 128; n++) {
- value >>= 7;
- }
-
- return n;
- }
-
- *p++ |= thresh;
-
- while (value >= 128) {
- *p++ = 0x80 | value;
- value >>= 7;
- }
-
- *p++ = value;
-
- return (uintptr_t) p;
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_section_prefix(u_char *p, ngx_uint_t insert_count,
- ngx_uint_t sign, ngx_uint_t delta_base)
-{
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, insert_count, 8)
- + ngx_http_v3_encode_prefix_int(NULL, delta_base, 7);
- }
-
- *p = 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, insert_count, 8);
-
- *p = sign ? 0x80 : 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, delta_base, 7);
-
- return (uintptr_t) p;
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_ri(u_char *p, ngx_uint_t dynamic, ngx_uint_t index)
-{
- /* Indexed Field Line */
-
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, index, 6);
- }
-
- *p = dynamic ? 0x80 : 0xc0;
-
- return ngx_http_v3_encode_prefix_int(p, index, 6);
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_lri(u_char *p, ngx_uint_t dynamic, ngx_uint_t index,
- u_char *data, size_t len)
-{
- size_t hlen;
- u_char *p1, *p2;
-
- /* Literal Field Line With Name Reference */
-
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, index, 4)
- + ngx_http_v3_encode_prefix_int(NULL, len, 7)
- + len;
- }
-
- *p = dynamic ? 0x40 : 0x50;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, index, 4);
-
- p1 = p;
- *p = 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, len, 7);
-
- if (data) {
- p2 = p;
- hlen = ngx_http_huff_encode(data, len, p, 0);
-
- if (hlen) {
- p = p1;
- *p = 0x80;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, hlen, 7);
-
- if (p != p2) {
- ngx_memmove(p, p2, hlen);
- }
-
- p += hlen;
-
- } else {
- p = ngx_cpymem(p, data, len);
- }
- }
-
- return (uintptr_t) p;
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_l(u_char *p, ngx_str_t *name, ngx_str_t *value)
-{
- size_t hlen;
- u_char *p1, *p2;
-
- /* Literal Field Line With Literal Name */
-
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, name->len, 3)
- + name->len
- + ngx_http_v3_encode_prefix_int(NULL, value->len, 7)
- + value->len;
- }
-
- p1 = p;
- *p = 0x20;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, name->len, 3);
-
- p2 = p;
- hlen = ngx_http_huff_encode(name->data, name->len, p, 1);
-
- if (hlen) {
- p = p1;
- *p = 0x28;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, hlen, 3);
-
- if (p != p2) {
- ngx_memmove(p, p2, hlen);
- }
-
- p += hlen;
-
- } else {
- ngx_strlow(p, name->data, name->len);
- p += name->len;
- }
-
- p1 = p;
- *p = 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, value->len, 7);
-
- p2 = p;
- hlen = ngx_http_huff_encode(value->data, value->len, p, 0);
-
- if (hlen) {
- p = p1;
- *p = 0x80;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, hlen, 7);
-
- if (p != p2) {
- ngx_memmove(p, p2, hlen);
- }
-
- p += hlen;
-
- } else {
- p = ngx_cpymem(p, value->data, value->len);
- }
-
- return (uintptr_t) p;
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_pbi(u_char *p, ngx_uint_t index)
-{
- /* Indexed Field Line With Post-Base Index */
-
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, index, 4);
- }
-
- *p = 0x10;
-
- return ngx_http_v3_encode_prefix_int(p, index, 4);
-}
-
-
-uintptr_t
-ngx_http_v3_encode_field_lpbi(u_char *p, ngx_uint_t index, u_char *data,
- size_t len)
-{
- size_t hlen;
- u_char *p1, *p2;
-
- /* Literal Field Line With Post-Base Name Reference */
-
- if (p == NULL) {
- return ngx_http_v3_encode_prefix_int(NULL, index, 3)
- + ngx_http_v3_encode_prefix_int(NULL, len, 7)
- + len;
- }
-
- *p = 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, index, 3);
-
- p1 = p;
- *p = 0;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, len, 7);
-
- if (data) {
- p2 = p;
- hlen = ngx_http_huff_encode(data, len, p, 0);
-
- if (hlen) {
- p = p1;
- *p = 0x80;
- p = (u_char *) ngx_http_v3_encode_prefix_int(p, hlen, 7);
-
- if (p != p2) {
- ngx_memmove(p, p2, hlen);
- }
-
- p += hlen;
-
- } else {
- p = ngx_cpymem(p, data, len);
- }
- }
-
- return (uintptr_t) p;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.h b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.h
deleted file mode 100644
index fca376da5e..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_encode.h
+++ /dev/null
@@ -1,34 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_V3_ENCODE_H_INCLUDED_
-#define _NGX_HTTP_V3_ENCODE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-uintptr_t ngx_http_v3_encode_varlen_int(u_char *p, uint64_t value);
-uintptr_t ngx_http_v3_encode_prefix_int(u_char *p, uint64_t value,
- ngx_uint_t prefix);
-
-uintptr_t ngx_http_v3_encode_field_section_prefix(u_char *p,
- ngx_uint_t insert_count, ngx_uint_t sign, ngx_uint_t delta_base);
-uintptr_t ngx_http_v3_encode_field_ri(u_char *p, ngx_uint_t dynamic,
- ngx_uint_t index);
-uintptr_t ngx_http_v3_encode_field_lri(u_char *p, ngx_uint_t dynamic,
- ngx_uint_t index, u_char *data, size_t len);
-uintptr_t ngx_http_v3_encode_field_l(u_char *p, ngx_str_t *name,
- ngx_str_t *value);
-uintptr_t ngx_http_v3_encode_field_pbi(u_char *p, ngx_uint_t index);
-uintptr_t ngx_http_v3_encode_field_lpbi(u_char *p, ngx_uint_t index,
- u_char *data, size_t len);
-
-
-#endif /* _NGX_HTTP_V3_ENCODE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_filter_module.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_filter_module.c
deleted file mode 100644
index e3f15368f1..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_filter_module.c
+++ /dev/null
@@ -1,1002 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-/* static table indices */
-#define NGX_HTTP_V3_HEADER_AUTHORITY 0
-#define NGX_HTTP_V3_HEADER_PATH_ROOT 1
-#define NGX_HTTP_V3_HEADER_CONTENT_LENGTH_ZERO 4
-#define NGX_HTTP_V3_HEADER_DATE 6
-#define NGX_HTTP_V3_HEADER_LAST_MODIFIED 10
-#define NGX_HTTP_V3_HEADER_LOCATION 12
-#define NGX_HTTP_V3_HEADER_METHOD_GET 17
-#define NGX_HTTP_V3_HEADER_SCHEME_HTTP 22
-#define NGX_HTTP_V3_HEADER_SCHEME_HTTPS 23
-#define NGX_HTTP_V3_HEADER_STATUS_103 24
-#define NGX_HTTP_V3_HEADER_STATUS_200 25
-#define NGX_HTTP_V3_HEADER_ACCEPT_ENCODING 31
-#define NGX_HTTP_V3_HEADER_CONTENT_TYPE_TEXT_PLAIN 53
-#define NGX_HTTP_V3_HEADER_VARY_ACCEPT_ENCODING 59
-#define NGX_HTTP_V3_HEADER_ACCEPT_LANGUAGE 72
-#define NGX_HTTP_V3_HEADER_SERVER 92
-#define NGX_HTTP_V3_HEADER_USER_AGENT 95
-
-
-typedef struct {
- ngx_chain_t *free;
- ngx_chain_t *busy;
-} ngx_http_v3_filter_ctx_t;
-
-
-static ngx_int_t ngx_http_v3_header_filter(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_early_hints_filter(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in);
-static ngx_chain_t *ngx_http_v3_create_trailers(ngx_http_request_t *r,
- ngx_http_v3_filter_ctx_t *ctx);
-static ngx_int_t ngx_http_v3_filter_init(ngx_conf_t *cf);
-
-
-static ngx_http_module_t ngx_http_v3_filter_module_ctx = {
- NULL, /* preconfiguration */
- ngx_http_v3_filter_init, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- NULL, /* create server configuration */
- NULL, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_v3_filter_module = {
- NGX_MODULE_V1,
- &ngx_http_v3_filter_module_ctx, /* module context */
- NULL, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_http_output_header_filter_pt ngx_http_next_header_filter;
-static ngx_http_output_header_filter_pt ngx_http_next_early_hints_filter;
-static ngx_http_output_body_filter_pt ngx_http_next_body_filter;
-
-
-static ngx_int_t
-ngx_http_v3_header_filter(ngx_http_request_t *r)
-{
- u_char *p;
- size_t len, n;
- ngx_buf_t *b;
- ngx_str_t host, location;
- ngx_uint_t i, port;
- ngx_chain_t *out, *hl, *cl, **ll;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_connection_t *c;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_filter_ctx_t *ctx;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
- u_char addr[NGX_SOCKADDR_STRLEN];
-
- if (r->http_version != NGX_HTTP_VERSION_30) {
- return ngx_http_next_header_filter(r);
- }
-
- if (r->header_sent) {
- return NGX_OK;
- }
-
- r->header_sent = 1;
-
- if (r != r->main) {
- return NGX_OK;
- }
-
- h3c = ngx_http_v3_get_session(r->connection);
-
- if (r->method == NGX_HTTP_HEAD) {
- r->header_only = 1;
- }
-
- if (r->headers_out.last_modified_time != -1) {
- if (r->headers_out.status != NGX_HTTP_OK
- && r->headers_out.status != NGX_HTTP_PARTIAL_CONTENT
- && r->headers_out.status != NGX_HTTP_NOT_MODIFIED)
- {
- r->headers_out.last_modified_time = -1;
- r->headers_out.last_modified = NULL;
- }
- }
-
- if (r->headers_out.status == NGX_HTTP_NO_CONTENT) {
- r->header_only = 1;
- ngx_str_null(&r->headers_out.content_type);
- r->headers_out.last_modified_time = -1;
- r->headers_out.last_modified = NULL;
- r->headers_out.content_length = NULL;
- r->headers_out.content_length_n = -1;
- }
-
- if (r->headers_out.status == NGX_HTTP_NOT_MODIFIED) {
- r->header_only = 1;
- }
-
- c = r->connection;
-
- out = NULL;
- ll = &out;
-
- len = ngx_http_v3_encode_field_section_prefix(NULL, 0, 0, 0);
-
- if (r->headers_out.status == NGX_HTTP_OK) {
- len += ngx_http_v3_encode_field_ri(NULL, 0,
- NGX_HTTP_V3_HEADER_STATUS_200);
-
- } else {
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_STATUS_200,
- NULL, 3);
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- if (r->headers_out.server == NULL) {
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- n = sizeof(NGINX_VER) - 1;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- n = sizeof(NGINX_VER_BUILD) - 1;
-
- } else {
- n = sizeof("nginx") - 1;
- }
-
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_SERVER,
- NULL, n);
- }
-
- if (r->headers_out.date == NULL) {
- len += ngx_http_v3_encode_field_lri(NULL, 0, NGX_HTTP_V3_HEADER_DATE,
- NULL, ngx_cached_http_time.len);
- }
-
- if (r->headers_out.content_type.len) {
- n = r->headers_out.content_type.len;
-
- if (r->headers_out.content_type_len == r->headers_out.content_type.len
- && r->headers_out.charset.len)
- {
- n += sizeof("; charset=") - 1 + r->headers_out.charset.len;
- }
-
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_CONTENT_TYPE_TEXT_PLAIN,
- NULL, n);
- }
-
- if (r->headers_out.content_length == NULL) {
- if (r->headers_out.content_length_n > 0) {
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_CONTENT_LENGTH_ZERO,
- NULL, NGX_OFF_T_LEN);
-
- } else if (r->headers_out.content_length_n == 0) {
- len += ngx_http_v3_encode_field_ri(NULL, 0,
- NGX_HTTP_V3_HEADER_CONTENT_LENGTH_ZERO);
- }
- }
-
- if (r->headers_out.last_modified == NULL
- && r->headers_out.last_modified_time != -1)
- {
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_LAST_MODIFIED, NULL,
- sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1);
- }
-
- if (r->headers_out.location && r->headers_out.location->value.len) {
-
- if (r->headers_out.location->value.data[0] == '/'
- && clcf->absolute_redirect)
- {
- if (clcf->server_name_in_redirect) {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
- host = cscf->server_name;
-
- } else if (r->headers_in.server.len) {
- host = r->headers_in.server;
-
- } else {
- host.len = NGX_SOCKADDR_STRLEN;
- host.data = addr;
-
- if (ngx_connection_local_sockaddr(c, &host, 0) != NGX_OK) {
- return NGX_ERROR;
- }
- }
-
- port = ngx_inet_get_port(c->local_sockaddr);
-
- location.len = sizeof("https://") - 1 + host.len
- + r->headers_out.location->value.len;
-
- if (clcf->port_in_redirect) {
- port = (port == 443) ? 0 : port;
-
- } else {
- port = 0;
- }
-
- if (port) {
- location.len += sizeof(":65535") - 1;
- }
-
- location.data = ngx_pnalloc(r->pool, location.len);
- if (location.data == NULL) {
- return NGX_ERROR;
- }
-
- p = ngx_cpymem(location.data, "https://", sizeof("https://") - 1);
- p = ngx_cpymem(p, host.data, host.len);
-
- if (port) {
- p = ngx_sprintf(p, ":%ui", port);
- }
-
- p = ngx_cpymem(p, r->headers_out.location->value.data,
- r->headers_out.location->value.len);
-
- /* update r->headers_out.location->value for possible logging */
-
- r->headers_out.location->value.len = p - location.data;
- r->headers_out.location->value.data = location.data;
- ngx_str_set(&r->headers_out.location->key, "Location");
- }
-
- r->headers_out.location->hash = 0;
-
- len += ngx_http_v3_encode_field_lri(NULL, 0,
- NGX_HTTP_V3_HEADER_LOCATION, NULL,
- r->headers_out.location->value.len);
- }
-
-#if (NGX_HTTP_GZIP)
- if (r->gzip_vary) {
- if (clcf->gzip_vary) {
- len += ngx_http_v3_encode_field_ri(NULL, 0,
- NGX_HTTP_V3_HEADER_VARY_ACCEPT_ENCODING);
-
- } else {
- r->gzip_vary = 0;
- }
- }
-#endif
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- len += ngx_http_v3_encode_field_l(NULL, &header[i].key,
- &header[i].value);
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 header len:%uz", len);
-
- b = ngx_create_temp_buf(r->pool, len);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_field_section_prefix(b->last,
- 0, 0, 0);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \":status: %03ui\"",
- r->headers_out.status);
-
- if (r->headers_out.status == NGX_HTTP_OK) {
- b->last = (u_char *) ngx_http_v3_encode_field_ri(b->last, 0,
- NGX_HTTP_V3_HEADER_STATUS_200);
-
- } else {
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_STATUS_200,
- NULL, 3);
- b->last = ngx_sprintf(b->last, "%03ui", r->headers_out.status);
- }
-
- if (r->headers_out.server == NULL) {
- if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_ON) {
- p = (u_char *) NGINX_VER;
- n = sizeof(NGINX_VER) - 1;
-
- } else if (clcf->server_tokens == NGX_HTTP_SERVER_TOKENS_BUILD) {
- p = (u_char *) NGINX_VER_BUILD;
- n = sizeof(NGINX_VER_BUILD) - 1;
-
- } else {
- p = (u_char *) "nginx";
- n = sizeof("nginx") - 1;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"server: %*s\"", n, p);
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_SERVER,
- p, n);
- }
-
- if (r->headers_out.date == NULL) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"date: %V\"",
- &ngx_cached_http_time);
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_DATE,
- ngx_cached_http_time.data,
- ngx_cached_http_time.len);
- }
-
- if (r->headers_out.content_type.len) {
- if (r->headers_out.content_type_len == r->headers_out.content_type.len
- && r->headers_out.charset.len)
- {
- n = r->headers_out.content_type.len + sizeof("; charset=") - 1
- + r->headers_out.charset.len;
-
- p = ngx_pnalloc(r->pool, n);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- p = ngx_cpymem(p, r->headers_out.content_type.data,
- r->headers_out.content_type.len);
-
- p = ngx_cpymem(p, "; charset=", sizeof("; charset=") - 1);
-
- p = ngx_cpymem(p, r->headers_out.charset.data,
- r->headers_out.charset.len);
-
- /* updated r->headers_out.content_type is also needed for logging */
-
- r->headers_out.content_type.len = n;
- r->headers_out.content_type.data = p - n;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"content-type: %V\"",
- &r->headers_out.content_type);
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_CONTENT_TYPE_TEXT_PLAIN,
- r->headers_out.content_type.data,
- r->headers_out.content_type.len);
- }
-
- if (r->headers_out.content_length == NULL
- && r->headers_out.content_length_n >= 0)
- {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"content-length: %O\"",
- r->headers_out.content_length_n);
-
- if (r->headers_out.content_length_n > 0) {
- p = ngx_sprintf(b->last, "%O", r->headers_out.content_length_n);
- n = p - b->last;
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_CONTENT_LENGTH_ZERO,
- NULL, n);
-
- b->last = ngx_sprintf(b->last, "%O",
- r->headers_out.content_length_n);
-
- } else {
- b->last = (u_char *) ngx_http_v3_encode_field_ri(b->last, 0,
- NGX_HTTP_V3_HEADER_CONTENT_LENGTH_ZERO);
- }
- }
-
- if (r->headers_out.last_modified == NULL
- && r->headers_out.last_modified_time != -1)
- {
- n = sizeof("Mon, 28 Sep 1970 06:00:00 GMT") - 1;
-
- p = ngx_pnalloc(r->pool, n);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_http_time(p, r->headers_out.last_modified_time);
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"last-modified: %*s\"", n, p);
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_LAST_MODIFIED,
- p, n);
- }
-
- if (r->headers_out.location && r->headers_out.location->value.len) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"location: %V\"",
- &r->headers_out.location->value);
-
- b->last = (u_char *) ngx_http_v3_encode_field_lri(b->last, 0,
- NGX_HTTP_V3_HEADER_LOCATION,
- r->headers_out.location->value.data,
- r->headers_out.location->value.len);
- }
-
-#if (NGX_HTTP_GZIP)
- if (r->gzip_vary) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"vary: Accept-Encoding\"");
-
- b->last = (u_char *) ngx_http_v3_encode_field_ri(b->last, 0,
- NGX_HTTP_V3_HEADER_VARY_ACCEPT_ENCODING);
- }
-#endif
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 output header: \"%V: %V\"",
- &header[i].key, &header[i].value);
-
- b->last = (u_char *) ngx_http_v3_encode_field_l(b->last,
- &header[i].key,
- &header[i].value);
- }
-
- if (r->header_only) {
- b->last_buf = 1;
- }
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
- cl->next = NULL;
-
- n = b->last - b->pos;
-
- h3c->payload_bytes += n;
-
- len = ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_FRAME_HEADERS)
- + ngx_http_v3_encode_varlen_int(NULL, n);
-
- b = ngx_create_temp_buf(r->pool, len);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last,
- NGX_HTTP_V3_FRAME_HEADERS);
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, n);
-
- hl = ngx_alloc_chain_link(r->pool);
- if (hl == NULL) {
- return NGX_ERROR;
- }
-
- hl->buf = b;
- hl->next = cl;
-
- *ll = hl;
- ll = &cl->next;
-
- if (r->headers_out.content_length_n >= 0
- && !r->header_only && !r->expect_trailers)
- {
- len = ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_FRAME_DATA)
- + ngx_http_v3_encode_varlen_int(NULL,
- r->headers_out.content_length_n);
-
- b = ngx_create_temp_buf(r->pool, len);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last,
- NGX_HTTP_V3_FRAME_DATA);
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last,
- r->headers_out.content_length_n);
-
- h3c->payload_bytes += r->headers_out.content_length_n;
- h3c->total_bytes += r->headers_out.content_length_n;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
- cl->next = NULL;
-
- *ll = cl;
-
- } else {
- ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_v3_filter_ctx_t));
- if (ctx == NULL) {
- return NGX_ERROR;
- }
-
- ngx_http_set_ctx(r, ctx, ngx_http_v3_filter_module);
- }
-
- for (cl = out; cl; cl = cl->next) {
- h3c->total_bytes += cl->buf->last - cl->buf->pos;
- r->header_size += cl->buf->last - cl->buf->pos;
- }
-
- return ngx_http_write_filter(r, out);
-}
-
-
-static ngx_int_t
-ngx_http_v3_early_hints_filter(ngx_http_request_t *r)
-{
- size_t len, n;
- ngx_buf_t *b;
- ngx_uint_t i;
- ngx_chain_t *out, *hl, *cl;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_http_v3_session_t *h3c;
-
- if (r->http_version != NGX_HTTP_VERSION_30) {
- return ngx_http_next_early_hints_filter(r);
- }
-
- if (r != r->main) {
- return NGX_OK;
- }
-
- len = 0;
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- len += ngx_http_v3_encode_field_l(NULL, &header[i].key,
- &header[i].value);
- }
-
- if (len == 0) {
- return NGX_OK;
- }
-
- len += ngx_http_v3_encode_field_section_prefix(NULL, 0, 0, 0);
-
- len += ngx_http_v3_encode_field_ri(NULL, 0, NGX_HTTP_V3_HEADER_STATUS_103);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 header len:%uz", len);
-
- b = ngx_create_temp_buf(r->pool, len);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_field_section_prefix(b->last,
- 0, 0, 0);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 output header: \":status: %03ui\"",
- (ngx_uint_t) NGX_HTTP_EARLY_HINTS);
-
- b->last = (u_char *) ngx_http_v3_encode_field_ri(b->last, 0,
- NGX_HTTP_V3_HEADER_STATUS_103);
-
- part = &r->headers_out.headers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 output header: \"%V: %V\"",
- &header[i].key, &header[i].value);
-
- b->last = (u_char *) ngx_http_v3_encode_field_l(b->last,
- &header[i].key,
- &header[i].value);
- }
-
- b->flush = 1;
-
- cl = ngx_alloc_chain_link(r->pool);
- if (cl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf = b;
- cl->next = NULL;
-
- n = b->last - b->pos;
-
- h3c = ngx_http_v3_get_session(r->connection);
- h3c->payload_bytes += n;
-
- len = ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_FRAME_HEADERS)
- + ngx_http_v3_encode_varlen_int(NULL, n);
-
- b = ngx_create_temp_buf(r->pool, len);
- if (b == NULL) {
- return NGX_ERROR;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last,
- NGX_HTTP_V3_FRAME_HEADERS);
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, n);
-
- hl = ngx_alloc_chain_link(r->pool);
- if (hl == NULL) {
- return NGX_ERROR;
- }
-
- hl->buf = b;
- hl->next = cl;
-
- out = hl;
-
- for (cl = out; cl; cl = cl->next) {
- h3c->total_bytes += cl->buf->last - cl->buf->pos;
- r->header_size += cl->buf->last - cl->buf->pos;
- }
-
- return ngx_http_write_filter(r, out);
-}
-
-
-static ngx_int_t
-ngx_http_v3_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
-{
- u_char *chunk;
- off_t size;
- ngx_int_t rc;
- ngx_buf_t *b;
- ngx_chain_t *out, *cl, *tl, **ll;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_filter_ctx_t *ctx;
-
- if (in == NULL) {
- return ngx_http_next_body_filter(r, in);
- }
-
- ctx = ngx_http_get_module_ctx(r, ngx_http_v3_filter_module);
- if (ctx == NULL) {
- return ngx_http_next_body_filter(r, in);
- }
-
- h3c = ngx_http_v3_get_session(r->connection);
-
- out = NULL;
- ll = &out;
-
- size = 0;
- cl = in;
-
- for ( ;; ) {
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 chunk: %O", ngx_buf_size(cl->buf));
-
- size += ngx_buf_size(cl->buf);
-
- if (cl->buf->flush
- || cl->buf->sync
- || ngx_buf_in_memory(cl->buf)
- || cl->buf->in_file)
- {
- tl = ngx_alloc_chain_link(r->pool);
- if (tl == NULL) {
- return NGX_ERROR;
- }
-
- tl->buf = cl->buf;
- *ll = tl;
- ll = &tl->next;
- }
-
- if (cl->next == NULL) {
- break;
- }
-
- cl = cl->next;
- }
-
- if (size) {
- tl = ngx_chain_get_free_buf(r->pool, &ctx->free);
- if (tl == NULL) {
- return NGX_ERROR;
- }
-
- b = tl->buf;
- chunk = b->start;
-
- if (chunk == NULL) {
- chunk = ngx_palloc(r->pool, NGX_HTTP_V3_VARLEN_INT_LEN * 2);
- if (chunk == NULL) {
- return NGX_ERROR;
- }
-
- b->start = chunk;
- b->end = chunk + NGX_HTTP_V3_VARLEN_INT_LEN * 2;
- }
-
- b->tag = (ngx_buf_tag_t) &ngx_http_v3_filter_module;
- b->memory = 0;
- b->temporary = 1;
- b->pos = chunk;
-
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(chunk,
- NGX_HTTP_V3_FRAME_DATA);
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, size);
-
- tl->next = out;
- out = tl;
-
- h3c->payload_bytes += size;
- }
-
- if (cl->buf->last_buf) {
- tl = ngx_http_v3_create_trailers(r, ctx);
- if (tl == NULL) {
- return NGX_ERROR;
- }
-
- cl->buf->last_buf = 0;
-
- *ll = tl;
-
- } else {
- *ll = NULL;
- }
-
- for (cl = out; cl; cl = cl->next) {
- h3c->total_bytes += cl->buf->last - cl->buf->pos;
- }
-
- rc = ngx_http_next_body_filter(r, out);
-
- ngx_chain_update_chains(r->pool, &ctx->free, &ctx->busy, &out,
- (ngx_buf_tag_t) &ngx_http_v3_filter_module);
-
- return rc;
-}
-
-
-static ngx_chain_t *
-ngx_http_v3_create_trailers(ngx_http_request_t *r,
- ngx_http_v3_filter_ctx_t *ctx)
-{
- size_t len, n;
- u_char *p;
- ngx_buf_t *b;
- ngx_uint_t i;
- ngx_chain_t *cl, *hl;
- ngx_list_part_t *part;
- ngx_table_elt_t *header;
- ngx_http_v3_session_t *h3c;
-
- h3c = ngx_http_v3_get_session(r->connection);
-
- len = 0;
-
- part = &r->headers_out.trailers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- len += ngx_http_v3_encode_field_l(NULL, &header[i].key,
- &header[i].value);
- }
-
- cl = ngx_chain_get_free_buf(r->pool, &ctx->free);
- if (cl == NULL) {
- return NULL;
- }
-
- b = cl->buf;
-
- b->tag = (ngx_buf_tag_t) &ngx_http_v3_filter_module;
- b->memory = 0;
- b->last_buf = 1;
-
- if (len == 0) {
- b->temporary = 0;
- b->pos = b->last = NULL;
- return cl;
- }
-
- b->temporary = 1;
-
- len += ngx_http_v3_encode_field_section_prefix(NULL, 0, 0, 0);
-
- b->pos = ngx_palloc(r->pool, len);
- if (b->pos == NULL) {
- return NULL;
- }
-
- b->last = (u_char *) ngx_http_v3_encode_field_section_prefix(b->pos,
- 0, 0, 0);
-
- part = &r->headers_out.trailers.part;
- header = part->elts;
-
- for (i = 0; /* void */; i++) {
-
- if (i >= part->nelts) {
- if (part->next == NULL) {
- break;
- }
-
- part = part->next;
- header = part->elts;
- i = 0;
- }
-
- if (header[i].hash == 0) {
- continue;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 output trailer: \"%V: %V\"",
- &header[i].key, &header[i].value);
-
- b->last = (u_char *) ngx_http_v3_encode_field_l(b->last,
- &header[i].key,
- &header[i].value);
- }
-
- n = b->last - b->pos;
-
- h3c->payload_bytes += n;
-
- hl = ngx_chain_get_free_buf(r->pool, &ctx->free);
- if (hl == NULL) {
- return NULL;
- }
-
- b = hl->buf;
- p = b->start;
-
- if (p == NULL) {
- p = ngx_palloc(r->pool, NGX_HTTP_V3_VARLEN_INT_LEN * 2);
- if (p == NULL) {
- return NULL;
- }
-
- b->start = p;
- b->end = p + NGX_HTTP_V3_VARLEN_INT_LEN * 2;
- }
-
- b->tag = (ngx_buf_tag_t) &ngx_http_v3_filter_module;
- b->memory = 0;
- b->temporary = 1;
- b->pos = p;
-
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(p,
- NGX_HTTP_V3_FRAME_HEADERS);
- b->last = (u_char *) ngx_http_v3_encode_varlen_int(b->last, n);
-
- hl->next = cl;
-
- return hl;
-}
-
-
-static ngx_int_t
-ngx_http_v3_filter_init(ngx_conf_t *cf)
-{
- ngx_http_next_header_filter = ngx_http_top_header_filter;
- ngx_http_top_header_filter = ngx_http_v3_header_filter;
-
- ngx_http_next_early_hints_filter = ngx_http_top_early_hints_filter;
- ngx_http_top_early_hints_filter = ngx_http_v3_early_hints_filter;
-
- ngx_http_next_body_filter = ngx_http_top_body_filter;
- ngx_http_top_body_filter = ngx_http_v3_body_filter;
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_module.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_module.c
deleted file mode 100644
index 139bd65f3d..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_module.c
+++ /dev/null
@@ -1,393 +0,0 @@
-
-/*
- * Copyright (C) Nginx, Inc.
- * Copyright (C) Roman Arutyunyan
- */
-
-
-#include
-#include
-#include
-
-
-static ngx_int_t ngx_http_v3_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data);
-static ngx_int_t ngx_http_v3_add_variables(ngx_conf_t *cf);
-static void *ngx_http_v3_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-static char *ngx_http_quic_host_key(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-
-
-static ngx_command_t ngx_http_v3_commands[] = {
-
- { ngx_string("http3"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, enable),
- NULL },
-
- { ngx_string("http3_hq"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, enable_hq),
- NULL },
-
- { ngx_string("http3_max_concurrent_streams"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, max_concurrent_streams),
- NULL },
-
- { ngx_string("http3_stream_buffer_size"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, quic.stream_buffer_size),
- NULL },
-
- { ngx_string("quic_retry"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, quic.retry),
- NULL },
-
- { ngx_string("quic_gso"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, quic.gso_enabled),
- NULL },
-
- { ngx_string("quic_host_key"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_http_quic_host_key,
- NGX_HTTP_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("quic_active_connection_id_limit"),
- NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_HTTP_SRV_CONF_OFFSET,
- offsetof(ngx_http_v3_srv_conf_t, quic.active_connection_id_limit),
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_http_module_t ngx_http_v3_module_ctx = {
- ngx_http_v3_add_variables, /* preconfiguration */
- NULL, /* postconfiguration */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_http_v3_create_srv_conf, /* create server configuration */
- ngx_http_v3_merge_srv_conf, /* merge server configuration */
-
- NULL, /* create location configuration */
- NULL /* merge location configuration */
-};
-
-
-ngx_module_t ngx_http_v3_module = {
- NGX_MODULE_V1,
- &ngx_http_v3_module_ctx, /* module context */
- ngx_http_v3_commands, /* module directives */
- NGX_HTTP_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_http_variable_t ngx_http_v3_vars[] = {
-
- { ngx_string("http3"), NULL, ngx_http_v3_variable, 0, 0, 0 },
-
- ngx_http_null_variable
-};
-
-static ngx_str_t ngx_http_quic_salt = ngx_string("ngx_quic");
-
-
-static ngx_int_t
-ngx_http_v3_variable(ngx_http_request_t *r,
- ngx_http_variable_value_t *v, uintptr_t data)
-{
- ngx_http_v3_session_t *h3c;
-
- if (r->connection->quic) {
- h3c = ngx_http_v3_get_session(r->connection);
-
- if (h3c->hq) {
- v->len = sizeof("hq") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "hq";
-
- return NGX_OK;
- }
-
- v->len = sizeof("h3") - 1;
- v->valid = 1;
- v->no_cacheable = 0;
- v->not_found = 0;
- v->data = (u_char *) "h3";
-
- return NGX_OK;
- }
-
- *v = ngx_http_variable_null_value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_add_variables(ngx_conf_t *cf)
-{
- ngx_http_variable_t *var, *v;
-
- for (v = ngx_http_v3_vars; v->name.len; v++) {
- var = ngx_http_add_variable(cf, &v->name, v->flags);
- if (var == NULL) {
- return NGX_ERROR;
- }
-
- var->get_handler = v->get_handler;
- var->data = v->data;
- }
-
- return NGX_OK;
-}
-
-
-static void *
-ngx_http_v3_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_http_v3_srv_conf_t *h3scf;
-
- h3scf = ngx_pcalloc(cf->pool, sizeof(ngx_http_v3_srv_conf_t));
- if (h3scf == NULL) {
- return NULL;
- }
-
- /*
- * set by ngx_pcalloc():
- *
- * h3scf->quic.host_key = { 0, NULL }
- * h3scf->quic.stream_reject_code_uni = 0;
- * h3scf->quic.disable_active_migration = 0;
- * h3scf->quic.idle_timeout = 0;
- * h3scf->max_blocked_streams = 0;
- */
-
- h3scf->enable = NGX_CONF_UNSET;
- h3scf->enable_hq = NGX_CONF_UNSET;
- h3scf->max_table_capacity = NGX_HTTP_V3_MAX_TABLE_CAPACITY;
- h3scf->max_concurrent_streams = NGX_CONF_UNSET_UINT;
-
- h3scf->quic.stream_buffer_size = NGX_CONF_UNSET_SIZE;
- h3scf->quic.max_concurrent_streams_bidi = NGX_CONF_UNSET_UINT;
- h3scf->quic.max_concurrent_streams_uni = NGX_HTTP_V3_MAX_UNI_STREAMS;
- h3scf->quic.retry = NGX_CONF_UNSET;
- h3scf->quic.gso_enabled = NGX_CONF_UNSET;
- h3scf->quic.stream_close_code = NGX_HTTP_V3_ERR_NO_ERROR;
- h3scf->quic.stream_reject_code_bidi = NGX_HTTP_V3_ERR_REQUEST_REJECTED;
- h3scf->quic.active_connection_id_limit = NGX_CONF_UNSET_UINT;
-
- h3scf->quic.init = ngx_http_v3_init;
- h3scf->quic.shutdown = ngx_http_v3_shutdown;
-
- return h3scf;
-}
-
-
-static char *
-ngx_http_v3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_http_v3_srv_conf_t *prev = parent;
- ngx_http_v3_srv_conf_t *conf = child;
-
- ngx_http_ssl_srv_conf_t *sscf;
- ngx_http_core_srv_conf_t *cscf;
-
- ngx_conf_merge_value(conf->enable, prev->enable, 1);
-
- ngx_conf_merge_value(conf->enable_hq, prev->enable_hq, 0);
-
- ngx_conf_merge_uint_value(conf->max_concurrent_streams,
- prev->max_concurrent_streams, 128);
-
- conf->max_blocked_streams = conf->max_concurrent_streams;
-
- ngx_conf_merge_size_value(conf->quic.stream_buffer_size,
- prev->quic.stream_buffer_size,
- 65536);
-
- conf->quic.max_concurrent_streams_bidi = conf->max_concurrent_streams;
-
- ngx_conf_merge_value(conf->quic.retry, prev->quic.retry, 0);
- ngx_conf_merge_value(conf->quic.gso_enabled, prev->quic.gso_enabled, 0);
-
- ngx_conf_merge_str_value(conf->quic.host_key, prev->quic.host_key, "");
-
- ngx_conf_merge_uint_value(conf->quic.active_connection_id_limit,
- prev->quic.active_connection_id_limit,
- 2);
-
- if (conf->quic.host_key.len == 0) {
-
- conf->quic.host_key.len = NGX_QUIC_DEFAULT_HOST_KEY_LEN;
- conf->quic.host_key.data = ngx_palloc(cf->pool,
- conf->quic.host_key.len);
- if (conf->quic.host_key.data == NULL) {
- return NGX_CONF_ERROR;
- }
-
- if (RAND_bytes(conf->quic.host_key.data, NGX_QUIC_DEFAULT_HOST_KEY_LEN)
- <= 0)
- {
- return NGX_CONF_ERROR;
- }
- }
-
- if (ngx_quic_derive_key(cf->log, "av_token_key",
- &conf->quic.host_key, &ngx_http_quic_salt,
- conf->quic.av_token_key, NGX_QUIC_AV_KEY_LEN)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_quic_derive_key(cf->log, "sr_token_key",
- &conf->quic.host_key, &ngx_http_quic_salt,
- conf->quic.sr_token_key, NGX_QUIC_SR_KEY_LEN)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- cscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_core_module);
- conf->quic.handshake_timeout = cscf->client_header_timeout;
-
- sscf = ngx_http_conf_get_module_srv_conf(cf, ngx_http_ssl_module);
- conf->quic.ssl = &sscf->ssl;
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_http_quic_host_key(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_http_v3_srv_conf_t *h3scf = conf;
-
- u_char *buf;
- size_t size;
- ssize_t n;
- ngx_str_t *value;
- ngx_file_t file;
- ngx_file_info_t fi;
- ngx_quic_conf_t *qcf;
-
- qcf = &h3scf->quic;
-
- if (qcf->host_key.len) {
- return "is duplicate";
- }
-
- buf = NULL;
-#if (NGX_SUPPRESS_WARN)
- size = 0;
-#endif
-
- value = cf->args->elts;
-
- if (ngx_conf_full_name(cf->cycle, &value[1], 1) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memzero(&file, sizeof(ngx_file_t));
- file.name = value[1];
- file.log = cf->log;
-
- file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0);
-
- if (file.fd == NGX_INVALID_FILE) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, ngx_errno,
- ngx_open_file_n " \"%V\" failed", &file.name);
- return NGX_CONF_ERROR;
- }
-
- if (ngx_fd_info(file.fd, &fi) == NGX_FILE_ERROR) {
- ngx_conf_log_error(NGX_LOG_CRIT, cf, ngx_errno,
- ngx_fd_info_n " \"%V\" failed", &file.name);
- goto failed;
- }
-
- size = ngx_file_size(&fi);
-
- if (size == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "\"%V\" zero key size", &file.name);
- goto failed;
- }
-
- buf = ngx_pnalloc(cf->pool, size);
- if (buf == NULL) {
- goto failed;
- }
-
- n = ngx_read_file(&file, buf, size, 0);
-
- if (n == NGX_ERROR) {
- ngx_conf_log_error(NGX_LOG_CRIT, cf, ngx_errno,
- ngx_read_file_n " \"%V\" failed", &file.name);
- goto failed;
- }
-
- if ((size_t) n != size) {
- ngx_conf_log_error(NGX_LOG_CRIT, cf, 0,
- ngx_read_file_n " \"%V\" returned only "
- "%z bytes instead of %uz", &file.name, n, size);
- goto failed;
- }
-
- qcf->host_key.data = buf;
- qcf->host_key.len = n;
-
- if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
- ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
- ngx_close_file_n " \"%V\" failed", &file.name);
- }
-
- return NGX_CONF_OK;
-
-failed:
-
- if (ngx_close_file(file.fd) == NGX_FILE_ERROR) {
- ngx_log_error(NGX_LOG_ALERT, cf->log, ngx_errno,
- ngx_close_file_n " \"%V\" failed", &file.name);
- }
-
- if (buf) {
- ngx_explicit_memzero(buf, size);
- }
-
- return NGX_CONF_ERROR;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.c
deleted file mode 100644
index bcbf0dbe12..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.c
+++ /dev/null
@@ -1,1942 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-#define ngx_http_v3_is_v2_frame(type) \
- ((type) == 0x02 || (type) == 0x06 || (type) == 0x08 || (type) == 0x09)
-
-
-static void ngx_http_v3_parse_start_local(ngx_buf_t *b, ngx_buf_t *loc,
- ngx_uint_t n);
-static void ngx_http_v3_parse_end_local(ngx_buf_t *b, ngx_buf_t *loc,
- ngx_uint_t *n);
-static ngx_int_t ngx_http_v3_parse_skip(ngx_buf_t *b, ngx_uint_t *length);
-
-static ngx_int_t ngx_http_v3_parse_varlen_int(ngx_connection_t *c,
- ngx_http_v3_parse_varlen_int_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_prefix_int(ngx_connection_t *c,
- ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, ngx_buf_t *b);
-
-static ngx_int_t ngx_http_v3_parse_field_section_prefix(ngx_connection_t *c,
- ngx_http_v3_parse_field_section_prefix_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_rep(ngx_connection_t *c,
- ngx_http_v3_parse_field_rep_t *st, ngx_uint_t base, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_literal(ngx_connection_t *c,
- ngx_http_v3_parse_literal_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_ri(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_lri(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_l(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_pbi(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_lpbi(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-
-static ngx_int_t ngx_http_v3_parse_control(ngx_connection_t *c,
- ngx_http_v3_parse_control_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_settings(ngx_connection_t *c,
- ngx_http_v3_parse_settings_t *st, ngx_buf_t *b);
-
-static ngx_int_t ngx_http_v3_parse_encoder(ngx_connection_t *c,
- ngx_http_v3_parse_encoder_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_inr(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-static ngx_int_t ngx_http_v3_parse_field_iln(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b);
-
-static ngx_int_t ngx_http_v3_parse_decoder(ngx_connection_t *c,
- ngx_http_v3_parse_decoder_t *st, ngx_buf_t *b);
-
-static ngx_int_t ngx_http_v3_parse_lookup(ngx_connection_t *c,
- ngx_uint_t dynamic, ngx_uint_t index, ngx_str_t *name, ngx_str_t *value);
-
-
-static void
-ngx_http_v3_parse_start_local(ngx_buf_t *b, ngx_buf_t *loc, ngx_uint_t n)
-{
- *loc = *b;
-
- if ((size_t) (loc->last - loc->pos) > n) {
- loc->last = loc->pos + n;
- }
-}
-
-
-static void
-ngx_http_v3_parse_end_local(ngx_buf_t *b, ngx_buf_t *loc, ngx_uint_t *pn)
-{
- *pn -= loc->pos - b->pos;
- b->pos = loc->pos;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_skip(ngx_buf_t *b, ngx_uint_t *length)
-{
- if ((size_t) (b->last - b->pos) < *length) {
- *length -= b->last - b->pos;
- b->pos = b->last;
- return NGX_AGAIN;
- }
-
- b->pos += *length;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_varlen_int(ngx_connection_t *c,
- ngx_http_v3_parse_varlen_int_t *st, ngx_buf_t *b)
-{
- u_char ch;
- enum {
- sw_start = 0,
- sw_length_2,
- sw_length_3,
- sw_length_4,
- sw_length_5,
- sw_length_6,
- sw_length_7,
- sw_length_8
- };
-
- for ( ;; ) {
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos++;
-
- switch (st->state) {
-
- case sw_start:
-
- st->value = ch;
- if (st->value & 0xc0) {
- st->state = sw_length_2;
- break;
- }
-
- goto done;
-
- case sw_length_2:
-
- st->value = (st->value << 8) + ch;
- if ((st->value & 0xc000) == 0x4000) {
- st->value &= 0x3fff;
- goto done;
- }
-
- st->state = sw_length_3;
- break;
-
- case sw_length_4:
-
- st->value = (st->value << 8) + ch;
- if ((st->value & 0xc0000000) == 0x80000000) {
- st->value &= 0x3fffffff;
- goto done;
- }
-
- st->state = sw_length_5;
- break;
-
- case sw_length_3:
- case sw_length_5:
- case sw_length_6:
- case sw_length_7:
-
- st->value = (st->value << 8) + ch;
- st->state++;
- break;
-
- case sw_length_8:
-
- st->value = (st->value << 8) + ch;
- st->value &= 0x3fffffffffffffff;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse varlen int %uL", st->value);
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_prefix_int(ngx_connection_t *c,
- ngx_http_v3_parse_prefix_int_t *st, ngx_uint_t prefix, ngx_buf_t *b)
-{
- u_char ch;
- ngx_uint_t mask;
- enum {
- sw_start = 0,
- sw_value
- };
-
- for ( ;; ) {
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos++;
-
- switch (st->state) {
-
- case sw_start:
-
- mask = (1 << prefix) - 1;
- st->value = ch & mask;
-
- if (st->value != mask) {
- goto done;
- }
-
- st->shift = 0;
- st->state = sw_value;
- break;
-
- case sw_value:
-
- st->value += (uint64_t) (ch & 0x7f) << st->shift;
-
- if (st->shift == 56
- && ((ch & 0x80) || (st->value & 0xc000000000000000)))
- {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client exceeded integer size limit");
- return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD;
- }
-
- if (ch & 0x80) {
- st->shift += 7;
- break;
- }
-
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse prefix int %uL", st->value);
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-ngx_int_t
-ngx_http_v3_parse_headers(ngx_connection_t *c, ngx_http_v3_parse_headers_t *st,
- ngx_buf_t *b)
-{
- ngx_buf_t loc;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_type,
- sw_length,
- sw_skip,
- sw_prefix,
- sw_verify,
- sw_field_rep,
- sw_done
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse headers");
-
- st->state = sw_type;
-
- /* fall through */
-
- case sw_type:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->type = st->vlint.value;
-
- if (ngx_http_v3_is_v2_frame(st->type)
- || st->type == NGX_HTTP_V3_FRAME_DATA
- || st->type == NGX_HTTP_V3_FRAME_GOAWAY
- || st->type == NGX_HTTP_V3_FRAME_SETTINGS
- || st->type == NGX_HTTP_V3_FRAME_MAX_PUSH_ID
- || st->type == NGX_HTTP_V3_FRAME_CANCEL_PUSH
- || st->type == NGX_HTTP_V3_FRAME_PUSH_PROMISE)
- {
- return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED;
- }
-
- st->state = sw_length;
- break;
-
- case sw_length:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->length = st->vlint.value;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse headers type:%ui, len:%ui",
- st->type, st->length);
-
- if (st->type != NGX_HTTP_V3_FRAME_HEADERS) {
- st->state = st->length > 0 ? sw_skip : sw_type;
- break;
- }
-
- if (st->length == 0) {
- return NGX_HTTP_V3_ERR_FRAME_ERROR;
- }
-
- st->state = sw_prefix;
- break;
-
- case sw_skip:
-
- rc = ngx_http_v3_parse_skip(b, &st->length);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_type;
- break;
-
- case sw_prefix:
-
- ngx_http_v3_parse_start_local(b, &loc, st->length);
-
- rc = ngx_http_v3_parse_field_section_prefix(c, &st->prefix, &loc);
-
- ngx_http_v3_parse_end_local(b, &loc, &st->length);
-
- if (st->length == 0 && rc == NGX_AGAIN) {
- return NGX_HTTP_V3_ERR_FRAME_ERROR;
- }
-
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_verify;
- break;
-
- case sw_verify:
-
- rc = ngx_http_v3_check_insert_count(c, st->prefix.insert_count);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_field_rep;
-
- /* fall through */
-
- case sw_field_rep:
-
- ngx_http_v3_parse_start_local(b, &loc, st->length);
-
- rc = ngx_http_v3_parse_field_rep(c, &st->field_rep, st->prefix.base,
- &loc);
-
- ngx_http_v3_parse_end_local(b, &loc, &st->length);
-
- if (st->length == 0 && rc == NGX_AGAIN) {
- return NGX_HTTP_V3_ERR_FRAME_ERROR;
- }
-
- if (rc != NGX_DONE) {
- return rc;
- }
-
- if (st->length == 0) {
- goto done;
- }
-
- return NGX_OK;
- }
- }
-
-done:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse headers done");
-
- if (st->prefix.insert_count > 0) {
- if (ngx_http_v3_send_ack_section(c, c->quic->id) != NGX_OK) {
- return NGX_ERROR;
- }
-
- ngx_http_v3_ack_insert_count(c, st->prefix.insert_count);
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_section_prefix(ngx_connection_t *c,
- ngx_http_v3_parse_field_section_prefix_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_req_insert_count,
- sw_delta_base,
- sw_read_delta_base
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field section prefix");
-
- st->state = sw_req_insert_count;
-
- /* fall through */
-
- case sw_req_insert_count:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 8, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->insert_count = st->pint.value;
- st->state = sw_delta_base;
- break;
-
- case sw_delta_base:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->sign = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_delta_base;
-
- /* fall through */
-
- case sw_read_delta_base:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->delta_base = st->pint.value;
- goto done;
- }
- }
-
-done:
-
- rc = ngx_http_v3_decode_insert_count(c, &st->insert_count);
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (st->sign) {
- if (st->insert_count <= st->delta_base) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client sent negative base");
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- st->base = st->insert_count - st->delta_base - 1;
-
- } else {
- st->base = st->insert_count + st->delta_base;
- }
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field section prefix done "
- "insert_count:%ui, sign:%ui, delta_base:%ui, base:%ui",
- st->insert_count, st->sign, st->delta_base, st->base);
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_rep(ngx_connection_t *c,
- ngx_http_v3_parse_field_rep_t *st, ngx_uint_t base, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_field_ri,
- sw_field_lri,
- sw_field_l,
- sw_field_pbi,
- sw_field_lpbi
- };
-
- if (st->state == sw_start) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field representation");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- ngx_memzero(&st->field, sizeof(ngx_http_v3_parse_field_t));
-
- st->field.base = base;
-
- if (ch & 0x80) {
- /* Indexed Field Line */
-
- st->state = sw_field_ri;
-
- } else if (ch & 0x40) {
- /* Literal Field Line With Name Reference */
-
- st->state = sw_field_lri;
-
- } else if (ch & 0x20) {
- /* Literal Field Line With Literal Name */
-
- st->state = sw_field_l;
-
- } else if (ch & 0x10) {
- /* Indexed Field Line With Post-Base Index */
-
- st->state = sw_field_pbi;
-
- } else {
- /* Literal Field Line With Post-Base Name Reference */
-
- st->state = sw_field_lpbi;
- }
- }
-
- switch (st->state) {
-
- case sw_field_ri:
- rc = ngx_http_v3_parse_field_ri(c, &st->field, b);
- break;
-
- case sw_field_lri:
- rc = ngx_http_v3_parse_field_lri(c, &st->field, b);
- break;
-
- case sw_field_l:
- rc = ngx_http_v3_parse_field_l(c, &st->field, b);
- break;
-
- case sw_field_pbi:
- rc = ngx_http_v3_parse_field_pbi(c, &st->field, b);
- break;
-
- case sw_field_lpbi:
- rc = ngx_http_v3_parse_field_lpbi(c, &st->field, b);
- break;
-
- default:
- rc = NGX_OK;
- }
-
- if (rc != NGX_DONE) {
- return rc;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field representation done");
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_literal(ngx_connection_t *c, ngx_http_v3_parse_literal_t *st,
- ngx_buf_t *b)
-{
- u_char ch;
- ngx_uint_t n;
- ngx_http_core_srv_conf_t *cscf;
- enum {
- sw_start = 0,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse literal huff:%ui, len:%ui",
- st->huffman, st->length);
-
- n = st->length;
-
- cscf = ngx_http_v3_get_module_srv_conf(c, ngx_http_core_module);
-
- if (n > cscf->large_client_header_buffers.size) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent too large field line");
- return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD;
- }
-
- if (st->huffman) {
- if (n > NGX_MAX_INT_T_VALUE / 8) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent too large field line");
- return NGX_HTTP_V3_ERR_EXCESSIVE_LOAD;
- }
-
- n = n * 8 / 5;
- st->huffstate = 0;
- }
-
- st->last = ngx_pnalloc(c->pool, n + 1);
- if (st->last == NULL) {
- return NGX_ERROR;
- }
-
- st->value.data = st->last;
- st->state = sw_value;
-
- /* fall through */
-
- case sw_value:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos++;
-
- if (st->huffman) {
- if (ngx_http_huff_decode(&st->huffstate, &ch, 1, &st->last,
- st->length == 1, c->log)
- != NGX_OK)
- {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid encoded field line");
- return NGX_ERROR;
- }
-
- } else {
- *st->last++ = ch;
- }
-
- if (--st->length) {
- break;
- }
-
- st->value.len = st->last - st->value.data;
- *st->last = '\0';
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse literal done \"%V\"", &st->value);
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_ri(ngx_connection_t *c, ngx_http_v3_parse_field_t *st,
- ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_index
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field ri");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->dynamic = (ch & 0x40) ? 0 : 1;
- st->state = sw_index;
-
- /* fall through */
-
- case sw_index:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->index = st->pint.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field ri done %s%ui]",
- st->dynamic ? "dynamic[-" : "static[", st->index);
-
- if (st->dynamic) {
- st->index = st->base - st->index - 1;
- }
-
- rc = ngx_http_v3_parse_lookup(c, st->dynamic, st->index, &st->name,
- &st->value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_lri(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_index,
- sw_value_len,
- sw_read_value_len,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field lri");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->dynamic = (ch & 0x10) ? 0 : 1;
- st->state = sw_index;
-
- /* fall through */
-
- case sw_index:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->index = st->pint.value;
- st->state = sw_value_len;
- break;
-
- case sw_value_len:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_value_len;
-
- /* fall through */
-
- case sw_read_value_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- st->value.data = (u_char *) "";
- goto done;
- }
-
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->value = st->literal.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field lri done %s%ui] \"%V\"",
- st->dynamic ? "dynamic[-" : "static[",
- st->index, &st->value);
-
- if (st->dynamic) {
- st->index = st->base - st->index - 1;
- }
-
- rc = ngx_http_v3_parse_lookup(c, st->dynamic, st->index, &st->name, NULL);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_l(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_name_len,
- sw_name,
- sw_value_len,
- sw_read_value_len,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field l");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x08) ? 1 : 0;
- st->state = sw_name_len;
-
- /* fall through */
-
- case sw_name_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- return NGX_ERROR;
- }
-
- st->state = sw_name;
- break;
-
- case sw_name:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->name = st->literal.value;
- st->state = sw_value_len;
- break;
-
- case sw_value_len:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_value_len;
-
- /* fall through */
-
- case sw_read_value_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- st->value.data = (u_char *) "";
- goto done;
- }
-
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->value = st->literal.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field l done \"%V\" \"%V\"",
- &st->name, &st->value);
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_pbi(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_index
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field pbi");
-
- st->state = sw_index;
-
- /* fall through */
-
- case sw_index:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 4, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->index = st->pint.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field pbi done dynamic[+%ui]", st->index);
-
- rc = ngx_http_v3_parse_lookup(c, 1, st->base + st->index, &st->name,
- &st->value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_lpbi(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_index,
- sw_value_len,
- sw_read_value_len,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field lpbi");
-
- st->state = sw_index;
-
- /* fall through */
-
- case sw_index:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 3, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->index = st->pint.value;
- st->state = sw_value_len;
- break;
-
- case sw_value_len:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_value_len;
-
- /* fall through */
-
- case sw_read_value_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- st->value.data = (u_char *) "";
- goto done;
- }
-
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->value = st->literal.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field lpbi done dynamic[+%ui] \"%V\"",
- st->index, &st->value);
-
- rc = ngx_http_v3_parse_lookup(c, 1, st->base + st->index, &st->name, NULL);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_lookup(ngx_connection_t *c, ngx_uint_t dynamic,
- ngx_uint_t index, ngx_str_t *name, ngx_str_t *value)
-{
- u_char *p;
-
- if (!dynamic) {
- if (ngx_http_v3_lookup_static(c, index, name, value) != NGX_OK) {
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- return NGX_OK;
- }
-
- if (ngx_http_v3_lookup(c, index, name, value) != NGX_OK) {
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- if (name) {
- p = ngx_pnalloc(c->pool, name->len + 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(p, name->data, name->len);
- p[name->len] = '\0';
- name->data = p;
- }
-
- if (value) {
- p = ngx_pnalloc(c->pool, value->len + 1);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(p, value->data, value->len);
- p[value->len] = '\0';
- value->data = p;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_control(ngx_connection_t *c, ngx_http_v3_parse_control_t *st,
- ngx_buf_t *b)
-{
- ngx_buf_t loc;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_first_type,
- sw_type,
- sw_length,
- sw_settings,
- sw_skip
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse control");
-
- st->state = sw_first_type;
-
- /* fall through */
-
- case sw_first_type:
- case sw_type:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->type = st->vlint.value;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse frame type:%ui", st->type);
-
- if (st->state == sw_first_type
- && st->type != NGX_HTTP_V3_FRAME_SETTINGS)
- {
- return NGX_HTTP_V3_ERR_MISSING_SETTINGS;
- }
-
- if (st->state != sw_first_type
- && st->type == NGX_HTTP_V3_FRAME_SETTINGS)
- {
- return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED;
- }
-
- if (ngx_http_v3_is_v2_frame(st->type)
- || st->type == NGX_HTTP_V3_FRAME_DATA
- || st->type == NGX_HTTP_V3_FRAME_HEADERS
- || st->type == NGX_HTTP_V3_FRAME_PUSH_PROMISE)
- {
- return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED;
- }
-
- if (st->type == NGX_HTTP_V3_FRAME_CANCEL_PUSH) {
- return NGX_HTTP_V3_ERR_ID_ERROR;
- }
-
- st->state = sw_length;
- break;
-
- case sw_length:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse frame len:%uL", st->vlint.value);
-
- st->length = st->vlint.value;
- if (st->length == 0) {
- st->state = sw_type;
- break;
- }
-
- switch (st->type) {
-
- case NGX_HTTP_V3_FRAME_SETTINGS:
- st->state = sw_settings;
- break;
-
- default:
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse skip unknown frame");
- st->state = sw_skip;
- }
-
- break;
-
- case sw_settings:
-
- ngx_http_v3_parse_start_local(b, &loc, st->length);
-
- rc = ngx_http_v3_parse_settings(c, &st->settings, &loc);
-
- ngx_http_v3_parse_end_local(b, &loc, &st->length);
-
- if (st->length == 0 && rc == NGX_AGAIN) {
- return NGX_HTTP_V3_ERR_SETTINGS_ERROR;
- }
-
- if (rc != NGX_DONE) {
- return rc;
- }
-
- if (st->length == 0) {
- st->state = sw_type;
- }
-
- break;
-
- case sw_skip:
-
- rc = ngx_http_v3_parse_skip(b, &st->length);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_type;
- break;
- }
- }
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_settings(ngx_connection_t *c,
- ngx_http_v3_parse_settings_t *st, ngx_buf_t *b)
-{
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_id,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse settings");
-
- st->state = sw_id;
-
- /* fall through */
-
- case sw_id:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->id = st->vlint.value;
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- if (ngx_http_v3_set_param(c, st->id, st->vlint.value) != NGX_OK) {
- return NGX_HTTP_V3_ERR_SETTINGS_ERROR;
- }
-
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse settings done");
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_encoder(ngx_connection_t *c, ngx_http_v3_parse_encoder_t *st,
- ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_inr,
- sw_iln,
- sw_capacity,
- sw_duplicate
- };
-
- for ( ;; ) {
-
- if (st->state == sw_start) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse encoder instruction");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- if (ch & 0x80) {
- /* Insert With Name Reference */
-
- st->state = sw_inr;
-
- } else if (ch & 0x40) {
- /* Insert With Literal Name */
-
- st->state = sw_iln;
-
- } else if (ch & 0x20) {
- /* Set Dynamic Table Capacity */
-
- st->state = sw_capacity;
-
- } else {
- /* Duplicate */
-
- st->state = sw_duplicate;
- }
- }
-
- switch (st->state) {
-
- case sw_inr:
-
- rc = ngx_http_v3_parse_field_inr(c, &st->field, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_start;
- break;
-
- case sw_iln:
-
- rc = ngx_http_v3_parse_field_iln(c, &st->field, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_start;
- break;
-
- case sw_capacity:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_set_capacity(c, st->pint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- break;
-
- default: /* sw_duplicate */
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_duplicate(c, st->pint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- break;
- }
- }
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_inr(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_name_index,
- sw_value_len,
- sw_read_value_len,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field inr");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->dynamic = (ch & 0x40) ? 0 : 1;
- st->state = sw_name_index;
-
- /* fall through */
-
- case sw_name_index:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->index = st->pint.value;
- st->state = sw_value_len;
- break;
-
- case sw_value_len:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_value_len;
-
- /* fall through */
-
- case sw_read_value_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- st->value.len = 0;
- goto done;
- }
-
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->value = st->literal.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field inr done %s[%ui] \"%V\"",
- st->dynamic ? "dynamic" : "static",
- st->index, &st->value);
-
- rc = ngx_http_v3_ref_insert(c, st->dynamic, st->index, &st->value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_field_iln(ngx_connection_t *c,
- ngx_http_v3_parse_field_t *st, ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_name_len,
- sw_name,
- sw_value_len,
- sw_read_value_len,
- sw_value
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field iln");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x20) ? 1 : 0;
- st->state = sw_name_len;
-
- /* fall through */
-
- case sw_name_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 5, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- return NGX_ERROR;
- }
-
- st->state = sw_name;
- break;
-
- case sw_name:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->name = st->literal.value;
- st->state = sw_value_len;
- break;
-
- case sw_value_len:
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- st->literal.huffman = (ch & 0x80) ? 1 : 0;
- st->state = sw_read_value_len;
-
- /* fall through */
-
- case sw_read_value_len:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->literal.length = st->pint.value;
- if (st->literal.length == 0) {
- st->value.len = 0;
- goto done;
- }
-
- st->state = sw_value;
- break;
-
- case sw_value:
-
- rc = ngx_http_v3_parse_literal(c, &st->literal, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->value = st->literal.value;
- goto done;
- }
- }
-
-done:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse field iln done \"%V\":\"%V\"",
- &st->name, &st->value);
-
- rc = ngx_http_v3_insert(c, &st->name, &st->value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_http_v3_parse_decoder(ngx_connection_t *c, ngx_http_v3_parse_decoder_t *st,
- ngx_buf_t *b)
-{
- u_char ch;
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_ack_section,
- sw_cancel_stream,
- sw_inc_insert_count
- };
-
- for ( ;; ) {
-
- if (st->state == sw_start) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse decoder instruction");
-
- if (b->pos == b->last) {
- return NGX_AGAIN;
- }
-
- ch = *b->pos;
-
- if (ch & 0x80) {
- /* Section Acknowledgment */
-
- st->state = sw_ack_section;
-
- } else if (ch & 0x40) {
- /* Stream Cancellation */
-
- st->state = sw_cancel_stream;
-
- } else {
- /* Insert Count Increment */
-
- st->state = sw_inc_insert_count;
- }
- }
-
- switch (st->state) {
-
- case sw_ack_section:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 7, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_ack_section(c, st->pint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- break;
-
- case sw_cancel_stream:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_cancel_stream(c, st->pint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- break;
-
- case sw_inc_insert_count:
-
- rc = ngx_http_v3_parse_prefix_int(c, &st->pint, 6, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_inc_insert_count(c, st->pint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- st->state = sw_start;
- break;
- }
- }
-}
-
-
-ngx_int_t
-ngx_http_v3_parse_data(ngx_connection_t *c, ngx_http_v3_parse_data_t *st,
- ngx_buf_t *b)
-{
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_type,
- sw_length,
- sw_skip
- };
-
- for ( ;; ) {
-
- switch (st->state) {
-
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data");
-
- st->state = sw_type;
-
- /* fall through */
-
- case sw_type:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->type = st->vlint.value;
-
- if (st->type == NGX_HTTP_V3_FRAME_HEADERS) {
- /* trailers */
- goto done;
- }
-
- if (ngx_http_v3_is_v2_frame(st->type)
- || st->type == NGX_HTTP_V3_FRAME_GOAWAY
- || st->type == NGX_HTTP_V3_FRAME_SETTINGS
- || st->type == NGX_HTTP_V3_FRAME_MAX_PUSH_ID
- || st->type == NGX_HTTP_V3_FRAME_CANCEL_PUSH
- || st->type == NGX_HTTP_V3_FRAME_PUSH_PROMISE)
- {
- return NGX_HTTP_V3_ERR_FRAME_UNEXPECTED;
- }
-
- st->state = sw_length;
- break;
-
- case sw_length:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->length = st->vlint.value;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 parse data type:%ui, len:%ui",
- st->type, st->length);
-
- if (st->type != NGX_HTTP_V3_FRAME_DATA && st->length > 0) {
- st->state = sw_skip;
- break;
- }
-
- st->state = sw_type;
- return NGX_OK;
-
- case sw_skip:
-
- rc = ngx_http_v3_parse_skip(b, &st->length);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- st->state = sw_type;
- break;
- }
- }
-
-done:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse data done");
-
- st->state = sw_start;
- return NGX_DONE;
-}
-
-
-ngx_int_t
-ngx_http_v3_parse_uni(ngx_connection_t *c, ngx_http_v3_parse_uni_t *st,
- ngx_buf_t *b)
-{
- ngx_int_t rc;
- enum {
- sw_start = 0,
- sw_type,
- sw_control,
- sw_encoder,
- sw_decoder,
- sw_unknown
- };
-
- for ( ;; ) {
-
- switch (st->state) {
- case sw_start:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 parse uni");
-
- st->state = sw_type;
-
- /* fall through */
-
- case sw_type:
-
- rc = ngx_http_v3_parse_varlen_int(c, &st->vlint, b);
- if (rc != NGX_DONE) {
- return rc;
- }
-
- rc = ngx_http_v3_register_uni_stream(c, st->vlint.value);
- if (rc != NGX_OK) {
- return rc;
- }
-
- switch (st->vlint.value) {
- case NGX_HTTP_V3_STREAM_CONTROL:
- st->state = sw_control;
- break;
-
- case NGX_HTTP_V3_STREAM_ENCODER:
- st->state = sw_encoder;
- break;
-
- case NGX_HTTP_V3_STREAM_DECODER:
- st->state = sw_decoder;
- break;
-
- default:
- st->state = sw_unknown;
- }
-
- break;
-
- case sw_control:
-
- return ngx_http_v3_parse_control(c, &st->u.control, b);
-
- case sw_encoder:
-
- return ngx_http_v3_parse_encoder(c, &st->u.encoder, b);
-
- case sw_decoder:
-
- return ngx_http_v3_parse_decoder(c, &st->u.decoder, b);
-
- case sw_unknown:
-
- b->pos = b->last;
- return NGX_AGAIN;
- }
- }
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.h b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.h
deleted file mode 100644
index ba004db5df..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_parse.h
+++ /dev/null
@@ -1,146 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_V3_PARSE_H_INCLUDED_
-#define _NGX_HTTP_V3_PARSE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_uint_t state;
- uint64_t value;
-} ngx_http_v3_parse_varlen_int_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t shift;
- uint64_t value;
-} ngx_http_v3_parse_prefix_int_t;
-
-
-typedef struct {
- ngx_uint_t state;
- uint64_t id;
- ngx_http_v3_parse_varlen_int_t vlint;
-} ngx_http_v3_parse_settings_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t insert_count;
- ngx_uint_t delta_base;
- ngx_uint_t sign;
- ngx_uint_t base;
- ngx_http_v3_parse_prefix_int_t pint;
-} ngx_http_v3_parse_field_section_prefix_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t length;
- ngx_uint_t huffman;
- ngx_str_t value;
- u_char *last;
- u_char huffstate;
-} ngx_http_v3_parse_literal_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t index;
- ngx_uint_t base;
- ngx_uint_t dynamic;
-
- ngx_str_t name;
- ngx_str_t value;
-
- ngx_http_v3_parse_prefix_int_t pint;
- ngx_http_v3_parse_literal_t literal;
-} ngx_http_v3_parse_field_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_http_v3_parse_field_t field;
-} ngx_http_v3_parse_field_rep_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t type;
- ngx_uint_t length;
- ngx_http_v3_parse_varlen_int_t vlint;
- ngx_http_v3_parse_field_section_prefix_t prefix;
- ngx_http_v3_parse_field_rep_t field_rep;
-} ngx_http_v3_parse_headers_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_http_v3_parse_field_t field;
- ngx_http_v3_parse_prefix_int_t pint;
-} ngx_http_v3_parse_encoder_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_http_v3_parse_prefix_int_t pint;
-} ngx_http_v3_parse_decoder_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t type;
- ngx_uint_t length;
- ngx_http_v3_parse_varlen_int_t vlint;
- ngx_http_v3_parse_settings_t settings;
-} ngx_http_v3_parse_control_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_http_v3_parse_varlen_int_t vlint;
- union {
- ngx_http_v3_parse_encoder_t encoder;
- ngx_http_v3_parse_decoder_t decoder;
- ngx_http_v3_parse_control_t control;
- } u;
-} ngx_http_v3_parse_uni_t;
-
-
-typedef struct {
- ngx_uint_t state;
- ngx_uint_t type;
- ngx_uint_t length;
- ngx_http_v3_parse_varlen_int_t vlint;
-} ngx_http_v3_parse_data_t;
-
-
-/*
- * Parse functions return codes:
- * NGX_DONE - parsing done
- * NGX_OK - sub-element done
- * NGX_AGAIN - more data expected
- * NGX_BUSY - waiting for external event
- * NGX_ERROR - internal error
- * NGX_HTTP_V3_ERROR_XXX - HTTP/3 or QPACK error
- */
-
-ngx_int_t ngx_http_v3_parse_headers(ngx_connection_t *c,
- ngx_http_v3_parse_headers_t *st, ngx_buf_t *b);
-ngx_int_t ngx_http_v3_parse_data(ngx_connection_t *c,
- ngx_http_v3_parse_data_t *st, ngx_buf_t *b);
-ngx_int_t ngx_http_v3_parse_uni(ngx_connection_t *c,
- ngx_http_v3_parse_uni_t *st, ngx_buf_t *b);
-
-
-#endif /* _NGX_HTTP_V3_PARSE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_request.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_request.c
deleted file mode 100644
index 7bb61311d9..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_request.c
+++ /dev/null
@@ -1,1741 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-static void ngx_http_v3_init_request_stream(ngx_connection_t *c);
-static void ngx_http_v3_wait_request_handler(ngx_event_t *rev);
-static void ngx_http_v3_cleanup_connection(void *data);
-static void ngx_http_v3_cleanup_request(void *data);
-static void ngx_http_v3_process_request(ngx_event_t *rev);
-static ngx_int_t ngx_http_v3_process_header(ngx_http_request_t *r,
- ngx_str_t *name, ngx_str_t *value);
-static ngx_int_t ngx_http_v3_validate_header(ngx_http_request_t *r,
- ngx_str_t *name, ngx_str_t *value);
-static ngx_int_t ngx_http_v3_process_pseudo_header(ngx_http_request_t *r,
- ngx_str_t *name, ngx_str_t *value);
-static ngx_int_t ngx_http_v3_init_pseudo_headers(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_process_request_header(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_cookie(ngx_http_request_t *r, ngx_str_t *value);
-static ngx_int_t ngx_http_v3_construct_cookie_header(ngx_http_request_t *r);
-static void ngx_http_v3_read_client_request_body_handler(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_do_read_client_request_body(ngx_http_request_t *r);
-static ngx_int_t ngx_http_v3_request_body_filter(ngx_http_request_t *r,
- ngx_chain_t *in);
-
-
-static const struct {
- ngx_str_t name;
- ngx_uint_t method;
-} ngx_http_v3_methods[] = {
-
- { ngx_string("GET"), NGX_HTTP_GET },
- { ngx_string("POST"), NGX_HTTP_POST },
- { ngx_string("HEAD"), NGX_HTTP_HEAD },
- { ngx_string("OPTIONS"), NGX_HTTP_OPTIONS },
- { ngx_string("PROPFIND"), NGX_HTTP_PROPFIND },
- { ngx_string("PUT"), NGX_HTTP_PUT },
- { ngx_string("MKCOL"), NGX_HTTP_MKCOL },
- { ngx_string("DELETE"), NGX_HTTP_DELETE },
- { ngx_string("COPY"), NGX_HTTP_COPY },
- { ngx_string("MOVE"), NGX_HTTP_MOVE },
- { ngx_string("PROPPATCH"), NGX_HTTP_PROPPATCH },
- { ngx_string("LOCK"), NGX_HTTP_LOCK },
- { ngx_string("UNLOCK"), NGX_HTTP_UNLOCK },
- { ngx_string("PATCH"), NGX_HTTP_PATCH },
- { ngx_string("TRACE"), NGX_HTTP_TRACE },
- { ngx_string("CONNECT"), NGX_HTTP_CONNECT }
-};
-
-
-void
-ngx_http_v3_init_stream(ngx_connection_t *c)
-{
- ngx_http_connection_t *hc, *phc;
- ngx_http_v3_srv_conf_t *h3scf;
- ngx_http_core_loc_conf_t *clcf;
-
- hc = c->data;
-
- hc->ssl = 1;
-
- clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
-
- if (c->quic == NULL) {
- h3scf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_v3_module);
- h3scf->quic.idle_timeout = clcf->keepalive_timeout;
-
- ngx_quic_run(c, &h3scf->quic);
- return;
- }
-
- phc = ngx_http_quic_get_connection(c);
-
- if (phc->ssl_servername) {
- hc->ssl_servername = phc->ssl_servername;
-#if (NGX_PCRE)
- hc->ssl_servername_regex = phc->ssl_servername_regex;
-#endif
- hc->conf_ctx = phc->conf_ctx;
-
- ngx_set_connection_log(c, clcf->error_log);
- }
-
- if (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) {
- ngx_http_v3_init_uni_stream(c);
-
- } else {
- ngx_http_v3_init_request_stream(c);
- }
-}
-
-
-ngx_int_t
-ngx_http_v3_init(ngx_connection_t *c)
-{
- unsigned int len;
- const unsigned char *data;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_srv_conf_t *h3scf;
- ngx_http_core_loc_conf_t *clcf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init");
-
- if (ngx_http_v3_init_session(c) != NGX_OK) {
- return NGX_ERROR;
- }
-
- h3c = ngx_http_v3_get_session(c);
- clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
- ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
-
- h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
-
- if (h3scf->enable_hq) {
- if (!h3scf->enable) {
- h3c->hq = 1;
- return NGX_OK;
- }
-
- SSL_get0_alpn_selected(c->ssl->connection, &data, &len);
-
- if (len == sizeof(NGX_HTTP_V3_HQ_PROTO) - 1
- && ngx_strncmp(data, NGX_HTTP_V3_HQ_PROTO, len) == 0)
- {
- h3c->hq = 1;
- return NGX_OK;
- }
- }
-
- if (ngx_http_v3_send_settings(c) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (h3scf->max_table_capacity > 0) {
- if (ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER) == NULL) {
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_v3_shutdown(ngx_connection_t *c)
-{
- ngx_http_v3_session_t *h3c;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 shutdown");
-
- h3c = ngx_http_v3_get_session(c);
-
- if (h3c == NULL) {
- ngx_quic_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "connection shutdown");
- return;
- }
-
- if (!h3c->goaway) {
- h3c->goaway = 1;
-
- if (!h3c->hq) {
- (void) ngx_http_v3_send_goaway(c, h3c->next_request_id);
- }
-
- ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "connection shutdown");
- }
-}
-
-
-static void
-ngx_http_v3_init_request_stream(ngx_connection_t *c)
-{
- uint64_t n;
- ngx_event_t *rev;
- ngx_pool_cleanup_t *cln;
- ngx_http_connection_t *hc;
- ngx_http_v3_session_t *h3c;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init request stream");
-
-#if (NGX_STAT_STUB)
- (void) ngx_atomic_fetch_add(ngx_stat_active, 1);
-#endif
-
- hc = c->data;
-
- clcf = ngx_http_get_module_loc_conf(hc->conf_ctx, ngx_http_core_module);
-
- n = c->quic->id >> 2;
-
- if (n >= clcf->keepalive_requests * 2) {
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "too many requests per connection");
- ngx_http_close_connection(c);
- return;
- }
-
- h3c = ngx_http_v3_get_session(c);
-
- if (h3c->goaway) {
- c->close = 1;
- ngx_http_close_connection(c);
- return;
- }
-
- h3c->next_request_id = c->quic->id + 0x04;
-
- if (n + 1 == clcf->keepalive_requests
- || ngx_current_msec - c->start_time > clcf->keepalive_time)
- {
- h3c->goaway = 1;
-
- if (!h3c->hq) {
- if (ngx_http_v3_send_goaway(c, h3c->next_request_id) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
- }
-
- ngx_http_v3_shutdown_connection(c, NGX_HTTP_V3_ERR_NO_ERROR,
- "reached maximum number of requests");
- }
-
- cln = ngx_pool_cleanup_add(c->pool, 0);
- if (cln == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- cln->handler = ngx_http_v3_cleanup_connection;
- cln->data = c;
-
- h3c->nrequests++;
-
- if (h3c->keepalive.timer_set) {
- ngx_del_timer(&h3c->keepalive);
- }
-
- rev = c->read;
-
- if (!h3c->hq) {
- rev->handler = ngx_http_v3_wait_request_handler;
- c->write->handler = ngx_http_empty_handler;
- }
-
- if (rev->ready) {
- rev->handler(rev);
- return;
- }
-
- cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);
-
- ngx_add_timer(rev, cscf->client_header_timeout);
- ngx_reusable_connection(c, 1);
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
-}
-
-
-static void
-ngx_http_v3_wait_request_handler(ngx_event_t *rev)
-{
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_connection_t *c;
- ngx_pool_cleanup_t *cln;
- ngx_http_request_t *r;
- ngx_http_connection_t *hc;
- ngx_http_core_srv_conf_t *cscf;
-
- c = rev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 wait request handler");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_http_close_connection(c);
- return;
- }
-
- if (c->close) {
- ngx_http_close_connection(c);
- return;
- }
-
- hc = c->data;
- cscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_core_module);
-
- size = cscf->client_header_buffer_size;
-
- b = c->buffer;
-
- if (b == NULL) {
- b = ngx_create_temp_buf(c->pool, size);
- if (b == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- c->buffer = b;
-
- } else if (b->start == NULL) {
-
- b->start = ngx_palloc(c->pool, size);
- if (b->start == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- b->pos = b->start;
- b->last = b->start;
- b->end = b->last + size;
- }
-
- n = c->recv(c, b->last, size);
-
- if (n == NGX_AGAIN) {
-
- if (!rev->timer_set) {
- ngx_add_timer(rev, cscf->client_header_timeout);
- ngx_reusable_connection(c, 1);
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_connection(c);
- return;
- }
-
- /*
- * We are trying to not hold c->buffer's memory for an idle connection.
- */
-
- if (ngx_pfree(c->pool, b->start) == NGX_OK) {
- b->start = NULL;
- }
-
- return;
- }
-
- if (n == NGX_ERROR) {
- ngx_http_close_connection(c);
- return;
- }
-
- if (n == 0) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client closed connection");
- ngx_http_close_connection(c);
- return;
- }
-
- b->last += n;
-
- c->log->action = "reading client request";
-
- ngx_reusable_connection(c, 0);
-
- r = ngx_http_create_request(c);
- if (r == NULL) {
- ngx_http_close_connection(c);
- return;
- }
-
- r->http_version = NGX_HTTP_VERSION_30;
-
- r->v3_parse = ngx_pcalloc(r->pool, sizeof(ngx_http_v3_parse_t));
- if (r->v3_parse == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- r->v3_parse->header_limit = cscf->large_client_header_buffers.size
- * cscf->large_client_header_buffers.num;
-
- c->data = r;
- c->requests = (c->quic->id >> 2) + 1;
-
- cln = ngx_pool_cleanup_add(r->pool, 0);
- if (cln == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return;
- }
-
- cln->handler = ngx_http_v3_cleanup_request;
- cln->data = r;
-
- rev->handler = ngx_http_v3_process_request;
- ngx_http_v3_process_request(rev);
-}
-
-
-void
-ngx_http_v3_reset_stream(ngx_connection_t *c)
-{
- ngx_http_v3_session_t *h3c;
-
- h3c = ngx_http_v3_get_session(c);
-
- if (!c->read->eof && !h3c->hq
- && h3c->known_streams[NGX_HTTP_V3_STREAM_SERVER_DECODER]
- && (c->quic->id & NGX_QUIC_STREAM_UNIDIRECTIONAL) == 0)
- {
- (void) ngx_http_v3_send_cancel_stream(c, c->quic->id);
- }
-
- if (c->timedout) {
- ngx_quic_reset_stream(c, NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR);
-
- } else if (c->close) {
- ngx_quic_reset_stream(c, NGX_HTTP_V3_ERR_REQUEST_REJECTED);
-
- } else if (c->requests == 0 || c->error) {
- ngx_quic_reset_stream(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR);
- }
-}
-
-
-static void
-ngx_http_v3_cleanup_connection(void *data)
-{
- ngx_connection_t *c = data;
-
- ngx_http_v3_session_t *h3c;
- ngx_http_core_loc_conf_t *clcf;
-
- h3c = ngx_http_v3_get_session(c);
-
- if (--h3c->nrequests == 0) {
- clcf = ngx_http_v3_get_module_loc_conf(c, ngx_http_core_module);
- ngx_add_timer(&h3c->keepalive, clcf->keepalive_timeout);
- }
-}
-
-
-static void
-ngx_http_v3_cleanup_request(void *data)
-{
- ngx_http_request_t *r = data;
-
- if (!r->response_sent) {
- r->connection->error = 1;
- }
-}
-
-
-static void
-ngx_http_v3_process_request(ngx_event_t *rev)
-{
- u_char *p;
- ssize_t n;
- ngx_buf_t *b;
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_request_t *r;
- ngx_http_v3_session_t *h3c;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_v3_parse_headers_t *st;
-
- c = rev->data;
- r = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, rev->log, 0, "http3 process request");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_http_close_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- h3c = ngx_http_v3_get_session(c);
-
- st = &r->v3_parse->headers;
-
- b = r->header_in;
-
- for ( ;; ) {
-
- if (b->pos == b->last) {
-
- if (rev->ready) {
- n = c->recv(c, b->start, b->end - b->start);
-
- } else {
- n = NGX_AGAIN;
- }
-
- if (n == NGX_AGAIN) {
- if (!rev->timer_set) {
- cscf = ngx_http_get_module_srv_conf(r,
- ngx_http_core_module);
- ngx_add_timer(rev, cscf->client_header_timeout);
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- }
-
- break;
- }
-
- if (n == 0) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client prematurely closed connection");
- }
-
- if (n == 0 || n == NGX_ERROR) {
- c->error = 1;
- c->log->action = "reading client request";
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- break;
- }
-
- b->pos = b->start;
- b->last = b->start + n;
- }
-
- p = b->pos;
-
- rc = ngx_http_v3_parse_headers(c, st, b);
-
- if (rc > 0) {
- ngx_quic_reset_stream(c, rc);
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client sent invalid header");
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- break;
- }
-
- if (rc == NGX_ERROR) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- break;
- }
-
- r->request_length += b->pos - p;
- h3c->total_bytes += b->pos - p;
-
- if (ngx_http_v3_check_flood(c) != NGX_OK) {
- ngx_http_close_request(r, NGX_HTTP_CLOSE);
- break;
- }
-
- if (rc == NGX_BUSY) {
- if (rev->error) {
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- break;
- }
-
- if (!rev->timer_set) {
- cscf = ngx_http_get_module_srv_conf(r,
- ngx_http_core_module);
- ngx_add_timer(rev, cscf->client_header_timeout);
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- }
-
- break;
- }
-
- if (rc == NGX_AGAIN) {
- continue;
- }
-
- /* rc == NGX_OK || rc == NGX_DONE */
-
- h3c->payload_bytes += ngx_http_v3_encode_field_l(NULL,
- &st->field_rep.field.name,
- &st->field_rep.field.value);
-
- if (ngx_http_v3_process_header(r, &st->field_rep.field.name,
- &st->field_rep.field.value)
- != NGX_OK)
- {
- break;
- }
-
- if (rc == NGX_DONE) {
- if (ngx_http_v3_process_request_header(r) != NGX_OK) {
- break;
- }
-
- ngx_http_process_request(r);
- break;
- }
- }
-
- ngx_http_run_posted_requests(c);
-
- return;
-}
-
-
-static ngx_int_t
-ngx_http_v3_process_header(ngx_http_request_t *r, ngx_str_t *name,
- ngx_str_t *value)
-{
- size_t len;
- ngx_table_elt_t *h;
- ngx_http_header_t *hh;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_core_main_conf_t *cmcf;
-
- static ngx_str_t cookie = ngx_string("cookie");
-
- len = name->len + value->len;
-
- if (len > r->v3_parse->header_limit) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent too large header");
- ngx_http_finalize_request(r, NGX_HTTP_REQUEST_HEADER_TOO_LARGE);
- return NGX_ERROR;
- }
-
- r->v3_parse->header_limit -= len;
-
- if (ngx_http_v3_validate_header(r, name, value) != NGX_OK) {
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- return NGX_ERROR;
- }
-
- if (r->invalid_header) {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- if (cscf->ignore_invalid_headers) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid header: \"%V\"", name);
-
- return NGX_OK;
- }
- }
-
- if (name->len && name->data[0] == ':') {
- return ngx_http_v3_process_pseudo_header(r, name, value);
- }
-
- if (ngx_http_v3_init_pseudo_headers(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (name->len == cookie.len
- && ngx_memcmp(name->data, cookie.data, cookie.len) == 0)
- {
- if (ngx_http_v3_cookie(r, value) != NGX_OK) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- } else {
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- if (r->headers_in.count++ >= cscf->max_headers) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent too many header lines");
- ngx_http_finalize_request(r, NGX_HTTP_REQUEST_HEADER_TOO_LARGE);
- return NGX_ERROR;
- }
-
- h = ngx_list_push(&r->headers_in.headers);
- if (h == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- h->key = *name;
- h->value = *value;
- h->lowcase_key = h->key.data;
- h->hash = ngx_hash_key(h->key.data, h->key.len);
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
- h->lowcase_key, h->key.len);
-
- if (hh && hh->handler(r, h, hh->offset) != NGX_OK) {
- return NGX_ERROR;
- }
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 header: \"%V: %V\"", name, value);
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_validate_header(ngx_http_request_t *r, ngx_str_t *name,
- ngx_str_t *value)
-{
- u_char ch;
- ngx_uint_t i;
- ngx_http_core_srv_conf_t *cscf;
-
- r->invalid_header = 0;
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- for (i = (name->data[0] == ':'); i != name->len; i++) {
- ch = name->data[i];
-
- if ((ch >= 'a' && ch <= 'z')
- || (ch == '-')
- || (ch >= '0' && ch <= '9')
- || (ch == '_' && cscf->underscores_in_headers))
- {
- continue;
- }
-
- if (ch <= 0x20 || ch == 0x7f || ch == ':'
- || (ch >= 'A' && ch <= 'Z'))
- {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid header name: \"%V\"", name);
-
- return NGX_ERROR;
- }
-
- r->invalid_header = 1;
- }
-
- for (i = 0; i != value->len; i++) {
- ch = value->data[i];
-
- if (ch == '\0' || ch == LF || ch == CR) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent header \"%V\" with "
- "invalid value: \"%V\"", name, value);
-
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_process_pseudo_header(ngx_http_request_t *r, ngx_str_t *name,
- ngx_str_t *value)
-{
- u_char ch, c;
- ngx_uint_t i;
-
- if (r->request_line.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent out of order pseudo-headers");
- goto failed;
- }
-
- if (name->len == 7 && ngx_strncmp(name->data, ":method", 7) == 0) {
-
- if (r->method_name.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate \":method\" header");
- goto failed;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty \":method\" header");
- goto failed;
- }
-
- r->method_name = *value;
-
- for (i = 0; i < sizeof(ngx_http_v3_methods)
- / sizeof(ngx_http_v3_methods[0]); i++)
- {
- if (value->len == ngx_http_v3_methods[i].name.len
- && ngx_strncmp(value->data,
- ngx_http_v3_methods[i].name.data, value->len)
- == 0)
- {
- r->method = ngx_http_v3_methods[i].method;
- break;
- }
- }
-
- for (i = 0; i < value->len; i++) {
- ch = value->data[i];
-
- if ((ch < 'A' || ch > 'Z') && ch != '_' && ch != '-') {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid method: \"%V\"", value);
- goto failed;
- }
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 method \"%V\" %ui", value, r->method);
- return NGX_OK;
- }
-
- if (name->len == 5 && ngx_strncmp(name->data, ":path", 5) == 0) {
-
- if (r->uri_start) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate \":path\" header");
- goto failed;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty \":path\" header");
- goto failed;
- }
-
- r->uri_start = value->data;
- r->uri_end = value->data + value->len;
-
- if (ngx_http_parse_uri(r) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid \":path\" header: \"%V\"",
- value);
- goto failed;
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 path \"%V\"", value);
- return NGX_OK;
- }
-
- if (name->len == 7 && ngx_strncmp(name->data, ":scheme", 7) == 0) {
-
- if (r->schema.len) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate \":scheme\" header");
- goto failed;
- }
-
- if (value->len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent empty \":scheme\" header");
- goto failed;
- }
-
- for (i = 0; i < value->len; i++) {
- ch = value->data[i];
-
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'z') {
- continue;
- }
-
- if (((ch >= '0' && ch <= '9')
- || ch == '+' || ch == '-' || ch == '.')
- && i > 0)
- {
- continue;
- }
-
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid \":scheme\" header: \"%V\"",
- value);
- goto failed;
- }
-
- r->schema = *value;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 schema \"%V\"", value);
- return NGX_OK;
- }
-
- if (name->len == 10 && ngx_strncmp(name->data, ":authority", 10) == 0) {
-
- if (r->host_start) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent duplicate \":authority\" header");
- goto failed;
- }
-
- r->host_start = value->data;
- r->host_end = value->data + value->len;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 authority \"%V\"", value);
- return NGX_OK;
- }
-
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent unknown pseudo-header \"%V\"", name);
-
-failed:
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- return NGX_ERROR;
-}
-
-
-static ngx_int_t
-ngx_http_v3_init_pseudo_headers(ngx_http_request_t *r)
-{
- size_t len;
- u_char *p;
- ngx_int_t rc;
- ngx_str_t host;
- in_port_t port;
-
- if (r->request_line.len) {
- return NGX_OK;
- }
-
- if (r->method_name.len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no \":method\" header");
- goto failed;
- }
-
- if (r->schema.len == 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no \":scheme\" header");
- goto failed;
- }
-
- if (r->uri_start == NULL) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent no \":path\" header");
- goto failed;
- }
-
- len = r->method_name.len + 1
- + (r->uri_end - r->uri_start) + 1
- + sizeof("HTTP/3.0") - 1;
-
- p = ngx_pnalloc(r->pool, len);
- if (p == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- r->request_line.data = p;
-
- p = ngx_cpymem(p, r->method_name.data, r->method_name.len);
- *p++ = ' ';
- p = ngx_cpymem(p, r->uri_start, r->uri_end - r->uri_start);
- *p++ = ' ';
- p = ngx_cpymem(p, "HTTP/3.0", sizeof("HTTP/3.0") - 1);
-
- r->request_line.len = p - r->request_line.data;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 request line: \"%V\"", &r->request_line);
-
- ngx_str_set(&r->http_protocol, "HTTP/3.0");
-
- if (ngx_http_process_request_uri(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (r->host_end) {
-
- host.len = r->host_end - r->host_start;
- host.data = r->host_start;
-
- rc = ngx_http_validate_host(&host, &port, r->pool, 0);
-
- if (rc == NGX_DECLINED) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent invalid \":authority\" header");
- goto failed;
- }
-
- if (rc == NGX_ERROR) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- if (ngx_http_set_virtual_server(r, &host) == NGX_ERROR) {
- return NGX_ERROR;
- }
-
- r->headers_in.server = host;
- r->port = port;
- }
-
- if (ngx_list_init(&r->headers_in.headers, r->pool, 20,
- sizeof(ngx_table_elt_t))
- != NGX_OK)
- {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- return NGX_ERROR;
-}
-
-
-static ngx_int_t
-ngx_http_v3_process_request_header(ngx_http_request_t *r)
-{
- ssize_t n;
- ngx_buf_t *b;
- ngx_str_t host;
- ngx_connection_t *c;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_srv_conf_t *h3scf;
-
- c = r->connection;
-
- if (ngx_http_v3_init_pseudo_headers(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- h3c = ngx_http_v3_get_session(c);
- h3scf = ngx_http_get_module_srv_conf(r, ngx_http_v3_module);
-
- if ((h3c->hq && !h3scf->enable_hq) || (!h3c->hq && !h3scf->enable)) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client attempted to request the server name "
- "for which the negotiated protocol is disabled");
- ngx_http_finalize_request(r, NGX_HTTP_MISDIRECTED_REQUEST);
- return NGX_ERROR;
- }
-
- if (ngx_http_v3_construct_cookie_header(r) != NGX_OK) {
- return NGX_ERROR;
- }
-
- if (r->headers_in.server.len == 0) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent neither \":authority\" nor \"Host\" header");
- goto failed;
- }
-
- if (r->headers_in.host && r->host_end) {
-
- host.len = r->host_end - r->host_start;
- host.data = r->host_start;
-
- if (r->headers_in.host->value.len != host.len
- || ngx_memcmp(r->headers_in.host->value.data, host.data, host.len)
- != 0)
- {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent \":authority\" and \"Host\" headers "
- "with different values");
- goto failed;
- }
- }
-
- if (r->headers_in.content_length) {
- r->headers_in.content_length_n =
- ngx_atoof(r->headers_in.content_length->value.data,
- r->headers_in.content_length->value.len);
-
- if (r->headers_in.content_length_n == NGX_ERROR) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid \"Content-Length\" header");
- goto failed;
- }
-
- } else {
- b = r->header_in;
- n = b->last - b->pos;
-
- if (n == 0) {
- n = c->recv(c, b->start, b->end - b->start);
-
- if (n == NGX_ERROR) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- if (n > 0) {
- b->pos = b->start;
- b->last = b->start + n;
- }
- }
-
- if (n != 0) {
- r->headers_in.chunked = 1;
- }
- }
-
- if (r->method == NGX_HTTP_CONNECT) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client sent CONNECT method");
- ngx_http_finalize_request(r, NGX_HTTP_NOT_ALLOWED);
- return NGX_ERROR;
- }
-
- if (r->method == NGX_HTTP_TRACE) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client sent TRACE method");
- ngx_http_finalize_request(r, NGX_HTTP_NOT_ALLOWED);
- return NGX_ERROR;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
- return NGX_ERROR;
-}
-
-
-static ngx_int_t
-ngx_http_v3_cookie(ngx_http_request_t *r, ngx_str_t *value)
-{
- ngx_str_t *val;
- ngx_array_t *cookies;
-
- cookies = r->v3_parse->cookies;
-
- if (cookies == NULL) {
- cookies = ngx_array_create(r->pool, 2, sizeof(ngx_str_t));
- if (cookies == NULL) {
- return NGX_ERROR;
- }
-
- r->v3_parse->cookies = cookies;
- }
-
- val = ngx_array_push(cookies);
- if (val == NULL) {
- return NGX_ERROR;
- }
-
- *val = *value;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_construct_cookie_header(ngx_http_request_t *r)
-{
- u_char *buf, *p, *end;
- size_t len;
- ngx_str_t *vals;
- ngx_uint_t i;
- ngx_array_t *cookies;
- ngx_table_elt_t *h;
- ngx_http_header_t *hh;
- ngx_http_core_main_conf_t *cmcf;
-
- static ngx_str_t cookie = ngx_string("cookie");
-
- cookies = r->v3_parse->cookies;
-
- if (cookies == NULL) {
- return NGX_OK;
- }
-
- vals = cookies->elts;
-
- i = 0;
- len = 0;
-
- do {
- len += vals[i].len + 2;
- } while (++i != cookies->nelts);
-
- len -= 2;
-
- buf = ngx_pnalloc(r->pool, len + 1);
- if (buf == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- p = buf;
- end = buf + len;
-
- for (i = 0; /* void */ ; i++) {
-
- p = ngx_cpymem(p, vals[i].data, vals[i].len);
-
- if (p == end) {
- *p = '\0';
- break;
- }
-
- *p++ = ';'; *p++ = ' ';
- }
-
- h = ngx_list_push(&r->headers_in.headers);
- if (h == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- h->hash = ngx_hash(ngx_hash(ngx_hash(ngx_hash(
- ngx_hash('c', 'o'), 'o'), 'k'), 'i'), 'e');
-
- h->key.len = cookie.len;
- h->key.data = cookie.data;
-
- h->value.len = len;
- h->value.data = buf;
-
- h->lowcase_key = cookie.data;
-
- cmcf = ngx_http_get_module_main_conf(r, ngx_http_core_module);
-
- hh = ngx_hash_find(&cmcf->headers_in_hash, h->hash,
- h->lowcase_key, h->key.len);
-
- if (hh == NULL) {
- ngx_http_close_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
- return NGX_ERROR;
- }
-
- if (hh->handler(r, h, hh->offset) != NGX_OK) {
- /*
- * request has been finalized already
- * in ngx_http_process_header_line()
- */
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_read_request_body(ngx_http_request_t *r)
-{
- size_t preread;
- ngx_int_t rc;
- ngx_chain_t *cl, out;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
-
- rb = r->request_body;
-
- preread = r->header_in->last - r->header_in->pos;
-
- if (preread) {
-
- /* there is the pre-read part of the request body */
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 client request body preread %uz", preread);
-
- out.buf = r->header_in;
- out.next = NULL;
- cl = &out;
-
- } else {
- cl = NULL;
- }
-
- rc = ngx_http_v3_request_body_filter(r, cl);
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (rb->rest == 0 && rb->last_saved) {
- /* the whole request body was pre-read */
- r->request_body_no_buffering = 0;
- rb->post_handler(r);
- return NGX_OK;
- }
-
- if (rb->rest < 0) {
- ngx_log_error(NGX_LOG_ALERT, r->connection->log, 0,
- "negative request body rest");
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- rb->buf = ngx_create_temp_buf(r->pool, clcf->client_body_buffer_size);
- if (rb->buf == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- r->read_event_handler = ngx_http_v3_read_client_request_body_handler;
- r->write_event_handler = ngx_http_request_empty_handler;
-
- return ngx_http_v3_do_read_client_request_body(r);
-}
-
-
-static void
-ngx_http_v3_read_client_request_body_handler(ngx_http_request_t *r)
-{
- ngx_int_t rc;
-
- if (r->connection->read->timedout) {
- r->connection->timedout = 1;
- ngx_http_finalize_request(r, NGX_HTTP_REQUEST_TIME_OUT);
- return;
- }
-
- rc = ngx_http_v3_do_read_client_request_body(r);
-
- if (rc >= NGX_HTTP_SPECIAL_RESPONSE) {
- ngx_http_finalize_request(r, rc);
- }
-}
-
-
-ngx_int_t
-ngx_http_v3_read_unbuffered_request_body(ngx_http_request_t *r)
-{
- ngx_int_t rc;
-
- if (r->connection->read->timedout) {
- r->connection->timedout = 1;
- return NGX_HTTP_REQUEST_TIME_OUT;
- }
-
- rc = ngx_http_v3_do_read_client_request_body(r);
-
- if (rc == NGX_OK) {
- r->reading_body = 0;
- }
-
- return rc;
-}
-
-
-static ngx_int_t
-ngx_http_v3_do_read_client_request_body(ngx_http_request_t *r)
-{
- off_t rest;
- size_t size;
- ssize_t n;
- ngx_int_t rc;
- ngx_uint_t flush;
- ngx_chain_t out;
- ngx_connection_t *c;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
-
- c = r->connection;
- rb = r->request_body;
- flush = 1;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 read client request body");
-
- for ( ;; ) {
- for ( ;; ) {
- if (rb->rest == 0) {
- break;
- }
-
- if (rb->buf->last == rb->buf->end) {
-
- /* update chains */
-
- rc = ngx_http_v3_request_body_filter(r, NULL);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (rb->busy != NULL) {
- if (r->request_body_no_buffering) {
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- if (rb->filter_need_buffering) {
- clcf = ngx_http_get_module_loc_conf(r,
- ngx_http_core_module);
- ngx_add_timer(c->read, clcf->client_body_timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- ngx_log_error(NGX_LOG_ALERT, c->log, 0,
- "busy buffers after request body flush");
-
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- flush = 0;
- rb->buf->pos = rb->buf->start;
- rb->buf->last = rb->buf->start;
- }
-
- size = rb->buf->end - rb->buf->last;
- rest = rb->rest - (rb->buf->last - rb->buf->pos);
-
- if ((off_t) size > rest) {
- size = (size_t) rest;
- }
-
- if (size == 0) {
- break;
- }
-
- n = c->recv(c, rb->buf->last, size);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 client request body recv %z", n);
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- if (n == 0) {
- rb->buf->last_buf = 1;
- }
-
- if (n == NGX_ERROR) {
- c->error = 1;
- return NGX_HTTP_BAD_REQUEST;
- }
-
- rb->buf->last += n;
-
- /* pass buffer to request body filter chain */
-
- flush = 0;
- out.buf = rb->buf;
- out.next = NULL;
-
- rc = ngx_http_v3_request_body_filter(r, &out);
-
- if (rc != NGX_OK) {
- return rc;
- }
-
- if (rb->rest == 0) {
- break;
- }
-
- if (rb->buf->last < rb->buf->end) {
- break;
- }
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 client request body rest %O", rb->rest);
-
- if (flush) {
- rc = ngx_http_v3_request_body_filter(r, NULL);
-
- if (rc != NGX_OK) {
- return rc;
- }
- }
-
- if (rb->rest == 0 && rb->last_saved) {
- break;
- }
-
- if (!c->read->ready || rb->rest == 0) {
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
- ngx_add_timer(c->read, clcf->client_body_timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- return NGX_AGAIN;
- }
- }
-
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
- if (!r->request_body_no_buffering) {
- r->read_event_handler = ngx_http_block_reading;
- rb->post_handler(r);
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_http_v3_request_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
-{
- off_t max;
- size_t size;
- u_char *p;
- ngx_int_t rc;
- ngx_buf_t *b;
- ngx_uint_t last;
- ngx_chain_t *cl, *out, *tl, **ll;
- ngx_http_v3_session_t *h3c;
- ngx_http_request_body_t *rb;
- ngx_http_core_loc_conf_t *clcf;
- ngx_http_core_srv_conf_t *cscf;
- ngx_http_v3_parse_data_t *st;
-
- rb = r->request_body;
- st = &r->v3_parse->body;
-
- h3c = ngx_http_v3_get_session(r->connection);
-
- if (rb->rest == -1) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
- "http3 request body filter");
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- rb->rest = cscf->large_client_header_buffers.size;
- }
-
- clcf = ngx_http_get_module_loc_conf(r, ngx_http_core_module);
-
- max = r->headers_in.content_length_n;
-
- if (max == -1 && clcf->client_max_body_size) {
- max = clcf->client_max_body_size;
- }
-
- out = NULL;
- ll = &out;
- last = 0;
-
- for (cl = in; cl; cl = cl->next) {
-
- ngx_log_debug7(NGX_LOG_DEBUG_EVENT, r->connection->log, 0,
- "http3 body buf "
- "t:%d f:%d %p, pos %p, size: %z file: %O, size: %O",
- cl->buf->temporary, cl->buf->in_file,
- cl->buf->start, cl->buf->pos,
- cl->buf->last - cl->buf->pos,
- cl->buf->file_pos,
- cl->buf->file_last - cl->buf->file_pos);
-
- if (cl->buf->last_buf) {
- last = 1;
- }
-
- b = NULL;
-
- while (cl->buf->pos < cl->buf->last) {
-
- if (st->length == 0) {
- p = cl->buf->pos;
-
- rc = ngx_http_v3_parse_data(r->connection, st, cl->buf);
-
- r->request_length += cl->buf->pos - p;
- h3c->total_bytes += cl->buf->pos - p;
-
- if (ngx_http_v3_check_flood(r->connection) != NGX_OK) {
- return NGX_HTTP_CLOSE;
- }
-
- if (rc == NGX_AGAIN) {
- continue;
- }
-
- if (rc == NGX_DONE) {
- last = 1;
- goto done;
- }
-
- if (rc > 0) {
- ngx_quic_reset_stream(r->connection, rc);
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client sent invalid body");
- return NGX_HTTP_BAD_REQUEST;
- }
-
- if (rc == NGX_ERROR) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- /* rc == NGX_OK */
-
- if (max != -1 && (uint64_t) (max - rb->received) < st->length) {
-
- if (r->headers_in.content_length_n != -1) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client intended to send body data "
- "larger than declared");
-
- return NGX_HTTP_BAD_REQUEST;
- }
-
- ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
- "client intended to send too large "
- "body: %O+%ui bytes",
- rb->received, st->length);
-
- return NGX_HTTP_REQUEST_ENTITY_TOO_LARGE;
- }
-
- continue;
- }
-
- if (b
- && st->length <= 128
- && (uint64_t) (cl->buf->last - cl->buf->pos) >= st->length)
- {
- rb->received += st->length;
- r->request_length += st->length;
- h3c->total_bytes += st->length;
- h3c->payload_bytes += st->length;
-
- if (st->length < 8) {
-
- while (st->length) {
- *b->last++ = *cl->buf->pos++;
- st->length--;
- }
-
- } else {
- ngx_memmove(b->last, cl->buf->pos, st->length);
- b->last += st->length;
- cl->buf->pos += st->length;
- st->length = 0;
- }
-
- continue;
- }
-
- tl = ngx_chain_get_free_buf(r->pool, &rb->free);
- if (tl == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- b = tl->buf;
-
- ngx_memzero(b, sizeof(ngx_buf_t));
-
- b->temporary = 1;
- b->tag = (ngx_buf_tag_t) &ngx_http_read_client_request_body;
- b->start = cl->buf->pos;
- b->pos = cl->buf->pos;
- b->last = cl->buf->last;
- b->end = cl->buf->end;
- b->flush = r->request_body_no_buffering;
-
- *ll = tl;
- ll = &tl->next;
-
- size = cl->buf->last - cl->buf->pos;
-
- if (size > st->length) {
- cl->buf->pos += (size_t) st->length;
- rb->received += st->length;
- r->request_length += st->length;
- h3c->total_bytes += st->length;
- h3c->payload_bytes += st->length;
- st->length = 0;
-
- } else {
- st->length -= size;
- rb->received += size;
- r->request_length += size;
- h3c->total_bytes += size;
- h3c->payload_bytes += size;
- cl->buf->pos = cl->buf->last;
- }
-
- b->last = cl->buf->pos;
- }
- }
-
-done:
-
- if (last) {
-
- if (st->length > 0) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client prematurely closed stream");
- r->connection->error = 1;
- return NGX_HTTP_BAD_REQUEST;
- }
-
- if (r->headers_in.content_length_n == -1) {
- r->headers_in.content_length_n = rb->received;
-
- } else if (r->headers_in.content_length_n != rb->received) {
- ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
- "client sent less body data than expected: "
- "%O out of %O bytes of request body received",
- rb->received, r->headers_in.content_length_n);
- return NGX_HTTP_BAD_REQUEST;
- }
-
- rb->rest = 0;
-
- tl = ngx_chain_get_free_buf(r->pool, &rb->free);
- if (tl == NULL) {
- return NGX_HTTP_INTERNAL_SERVER_ERROR;
- }
-
- b = tl->buf;
-
- ngx_memzero(b, sizeof(ngx_buf_t));
-
- b->last_buf = 1;
-
- *ll = tl;
-
- } else {
-
- /* set rb->rest, amount of data we want to see next time */
-
- cscf = ngx_http_get_module_srv_conf(r, ngx_http_core_module);
-
- rb->rest = (off_t) cscf->large_client_header_buffers.size;
- }
-
- rc = ngx_http_top_request_body_filter(r, out);
-
- ngx_chain_update_chains(r->pool, &rb->free, &rb->busy, &out,
- (ngx_buf_tag_t) &ngx_http_read_client_request_body);
-
- return rc;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.c
deleted file mode 100644
index 428e7326b9..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.c
+++ /dev/null
@@ -1,715 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-#define ngx_http_v3_table_entry_size(n, v) ((n)->len + (v)->len + 32)
-
-
-static ngx_int_t ngx_http_v3_evict(ngx_connection_t *c, size_t target);
-static void ngx_http_v3_unblock(void *data);
-static ngx_int_t ngx_http_v3_new_entry(ngx_connection_t *c);
-
-
-typedef struct {
- ngx_queue_t queue;
- ngx_connection_t *connection;
- ngx_uint_t *nblocked;
-} ngx_http_v3_block_t;
-
-
-static ngx_http_v3_field_t ngx_http_v3_static_table[] = {
-
- { ngx_string(":authority"), ngx_string("") },
- { ngx_string(":path"), ngx_string("/") },
- { ngx_string("age"), ngx_string("0") },
- { ngx_string("content-disposition"), ngx_string("") },
- { ngx_string("content-length"), ngx_string("0") },
- { ngx_string("cookie"), ngx_string("") },
- { ngx_string("date"), ngx_string("") },
- { ngx_string("etag"), ngx_string("") },
- { ngx_string("if-modified-since"), ngx_string("") },
- { ngx_string("if-none-match"), ngx_string("") },
- { ngx_string("last-modified"), ngx_string("") },
- { ngx_string("link"), ngx_string("") },
- { ngx_string("location"), ngx_string("") },
- { ngx_string("referer"), ngx_string("") },
- { ngx_string("set-cookie"), ngx_string("") },
- { ngx_string(":method"), ngx_string("CONNECT") },
- { ngx_string(":method"), ngx_string("DELETE") },
- { ngx_string(":method"), ngx_string("GET") },
- { ngx_string(":method"), ngx_string("HEAD") },
- { ngx_string(":method"), ngx_string("OPTIONS") },
- { ngx_string(":method"), ngx_string("POST") },
- { ngx_string(":method"), ngx_string("PUT") },
- { ngx_string(":scheme"), ngx_string("http") },
- { ngx_string(":scheme"), ngx_string("https") },
- { ngx_string(":status"), ngx_string("103") },
- { ngx_string(":status"), ngx_string("200") },
- { ngx_string(":status"), ngx_string("304") },
- { ngx_string(":status"), ngx_string("404") },
- { ngx_string(":status"), ngx_string("503") },
- { ngx_string("accept"), ngx_string("*/*") },
- { ngx_string("accept"),
- ngx_string("application/dns-message") },
- { ngx_string("accept-encoding"), ngx_string("gzip, deflate, br") },
- { ngx_string("accept-ranges"), ngx_string("bytes") },
- { ngx_string("access-control-allow-headers"),
- ngx_string("cache-control") },
- { ngx_string("access-control-allow-headers"),
- ngx_string("content-type") },
- { ngx_string("access-control-allow-origin"),
- ngx_string("*") },
- { ngx_string("cache-control"), ngx_string("max-age=0") },
- { ngx_string("cache-control"), ngx_string("max-age=2592000") },
- { ngx_string("cache-control"), ngx_string("max-age=604800") },
- { ngx_string("cache-control"), ngx_string("no-cache") },
- { ngx_string("cache-control"), ngx_string("no-store") },
- { ngx_string("cache-control"),
- ngx_string("public, max-age=31536000") },
- { ngx_string("content-encoding"), ngx_string("br") },
- { ngx_string("content-encoding"), ngx_string("gzip") },
- { ngx_string("content-type"),
- ngx_string("application/dns-message") },
- { ngx_string("content-type"),
- ngx_string("application/javascript") },
- { ngx_string("content-type"), ngx_string("application/json") },
- { ngx_string("content-type"),
- ngx_string("application/x-www-form-urlencoded") },
- { ngx_string("content-type"), ngx_string("image/gif") },
- { ngx_string("content-type"), ngx_string("image/jpeg") },
- { ngx_string("content-type"), ngx_string("image/png") },
- { ngx_string("content-type"), ngx_string("text/css") },
- { ngx_string("content-type"),
- ngx_string("text/html;charset=utf-8") },
- { ngx_string("content-type"), ngx_string("text/plain") },
- { ngx_string("content-type"),
- ngx_string("text/plain;charset=utf-8") },
- { ngx_string("range"), ngx_string("bytes=0-") },
- { ngx_string("strict-transport-security"),
- ngx_string("max-age=31536000") },
- { ngx_string("strict-transport-security"),
- ngx_string("max-age=31536000;includesubdomains") },
- { ngx_string("strict-transport-security"),
- ngx_string("max-age=31536000;includesubdomains;preload") },
- { ngx_string("vary"), ngx_string("accept-encoding") },
- { ngx_string("vary"), ngx_string("origin") },
- { ngx_string("x-content-type-options"),
- ngx_string("nosniff") },
- { ngx_string("x-xss-protection"), ngx_string("1;mode=block") },
- { ngx_string(":status"), ngx_string("100") },
- { ngx_string(":status"), ngx_string("204") },
- { ngx_string(":status"), ngx_string("206") },
- { ngx_string(":status"), ngx_string("302") },
- { ngx_string(":status"), ngx_string("400") },
- { ngx_string(":status"), ngx_string("403") },
- { ngx_string(":status"), ngx_string("421") },
- { ngx_string(":status"), ngx_string("425") },
- { ngx_string(":status"), ngx_string("500") },
- { ngx_string("accept-language"), ngx_string("") },
- { ngx_string("access-control-allow-credentials"),
- ngx_string("FALSE") },
- { ngx_string("access-control-allow-credentials"),
- ngx_string("TRUE") },
- { ngx_string("access-control-allow-headers"),
- ngx_string("*") },
- { ngx_string("access-control-allow-methods"),
- ngx_string("get") },
- { ngx_string("access-control-allow-methods"),
- ngx_string("get, post, options") },
- { ngx_string("access-control-allow-methods"),
- ngx_string("options") },
- { ngx_string("access-control-expose-headers"),
- ngx_string("content-length") },
- { ngx_string("access-control-request-headers"),
- ngx_string("content-type") },
- { ngx_string("access-control-request-method"),
- ngx_string("get") },
- { ngx_string("access-control-request-method"),
- ngx_string("post") },
- { ngx_string("alt-svc"), ngx_string("clear") },
- { ngx_string("authorization"), ngx_string("") },
- { ngx_string("content-security-policy"),
- ngx_string("script-src 'none';object-src 'none';base-uri 'none'") },
- { ngx_string("early-data"), ngx_string("1") },
- { ngx_string("expect-ct"), ngx_string("") },
- { ngx_string("forwarded"), ngx_string("") },
- { ngx_string("if-range"), ngx_string("") },
- { ngx_string("origin"), ngx_string("") },
- { ngx_string("purpose"), ngx_string("prefetch") },
- { ngx_string("server"), ngx_string("") },
- { ngx_string("timing-allow-origin"), ngx_string("*") },
- { ngx_string("upgrade-insecure-requests"),
- ngx_string("1") },
- { ngx_string("user-agent"), ngx_string("") },
- { ngx_string("x-forwarded-for"), ngx_string("") },
- { ngx_string("x-frame-options"), ngx_string("deny") },
- { ngx_string("x-frame-options"), ngx_string("sameorigin") }
-};
-
-
-ngx_int_t
-ngx_http_v3_ref_insert(ngx_connection_t *c, ngx_uint_t dynamic,
- ngx_uint_t index, ngx_str_t *value)
-{
- ngx_str_t name;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- if (dynamic) {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 ref insert dynamic[%ui] \"%V\"", index, value);
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (dt->base + dt->nelts <= index) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- index = dt->base + dt->nelts - 1 - index;
-
- if (ngx_http_v3_lookup(c, index, &name, NULL) != NGX_OK) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- } else {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 ref insert static[%ui] \"%V\"", index, value);
-
- if (ngx_http_v3_lookup_static(c, index, &name, NULL) != NGX_OK) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
- }
-
- return ngx_http_v3_insert(c, &name, value);
-}
-
-
-ngx_int_t
-ngx_http_v3_insert(ngx_connection_t *c, ngx_str_t *name, ngx_str_t *value)
-{
- u_char *p;
- size_t size;
- ngx_http_v3_field_t *field;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- size = ngx_http_v3_table_entry_size(name, value);
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (size > dt->capacity) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "not enough dynamic table capacity");
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 insert [%ui] \"%V\":\"%V\", size:%uz",
- dt->base + dt->nelts, name, value, size);
-
- p = ngx_alloc(sizeof(ngx_http_v3_field_t) + name->len + value->len,
- c->log);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- field = (ngx_http_v3_field_t *) p;
-
- field->name.data = p + sizeof(ngx_http_v3_field_t);
- field->name.len = name->len;
- field->value.data = ngx_cpymem(field->name.data, name->data, name->len);
- field->value.len = value->len;
- ngx_memcpy(field->value.data, value->data, value->len);
-
- dt->elts[dt->nelts++] = field;
- dt->size += size;
-
- dt->insert_count++;
-
- if (ngx_http_v3_evict(c, dt->capacity) != NGX_OK) {
- return NGX_ERROR;
- }
-
- ngx_post_event(&dt->send_insert_count, &ngx_posted_events);
-
- if (ngx_http_v3_new_entry(c) != NGX_OK) {
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_v3_inc_insert_count_handler(ngx_event_t *ev)
-{
- ngx_connection_t *c;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- c = ev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 inc insert count handler");
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (dt->insert_count > dt->ack_insert_count) {
- if (ngx_http_v3_send_inc_insert_count(c,
- dt->insert_count - dt->ack_insert_count)
- != NGX_OK)
- {
- return;
- }
-
- dt->ack_insert_count = dt->insert_count;
- }
-}
-
-
-ngx_int_t
-ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity)
-{
- ngx_uint_t max, prev_max;
- ngx_http_v3_field_t **elts;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_srv_conf_t *h3scf;
- ngx_http_v3_dynamic_table_t *dt;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 set capacity %ui", capacity);
-
- h3c = ngx_http_v3_get_session(c);
- h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
-
- if (capacity > h3scf->max_table_capacity) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client exceeded http3_max_table_capacity limit");
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- if (ngx_http_v3_evict(c, capacity) != NGX_OK) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- dt = &h3c->table;
- max = capacity / 32;
- prev_max = dt->capacity / 32;
-
- if (max > prev_max) {
- elts = ngx_alloc((max + 1) * sizeof(void *), c->log);
- if (elts == NULL) {
- return NGX_ERROR;
- }
-
- if (dt->elts) {
- ngx_memcpy(elts, dt->elts, dt->nelts * sizeof(void *));
- ngx_free(dt->elts);
- }
-
- dt->elts = elts;
- }
-
- dt->capacity = capacity;
-
- return NGX_OK;
-}
-
-
-void
-ngx_http_v3_cleanup_table(ngx_http_v3_session_t *h3c)
-{
- ngx_uint_t n;
- ngx_http_v3_dynamic_table_t *dt;
-
- dt = &h3c->table;
-
- if (dt->elts == NULL) {
- return;
- }
-
- for (n = 0; n < dt->nelts; n++) {
- ngx_free(dt->elts[n]);
- }
-
- ngx_free(dt->elts);
-}
-
-
-static ngx_int_t
-ngx_http_v3_evict(ngx_connection_t *c, size_t target)
-{
- size_t size;
- ngx_uint_t n;
- ngx_http_v3_field_t *field;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
- n = 0;
-
- while (dt->size > target) {
- field = dt->elts[n++];
- size = ngx_http_v3_table_entry_size(&field->name, &field->value);
-
- ngx_log_debug4(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 evict [%ui] \"%V\":\"%V\" size:%uz",
- dt->base, &field->name, &field->value, size);
-
- ngx_free(field);
- dt->size -= size;
- }
-
- if (n) {
- dt->nelts -= n;
- dt->base += n;
- ngx_memmove(dt->elts, &dt->elts[n], dt->nelts * sizeof(void *));
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_duplicate(ngx_connection_t *c, ngx_uint_t index)
-{
- ngx_str_t name, value;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 duplicate %ui", index);
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (dt->base + dt->nelts <= index) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- index = dt->base + dt->nelts - 1 - index;
-
- if (ngx_http_v3_lookup(c, index, &name, &value) != NGX_OK) {
- return NGX_HTTP_V3_ERR_ENCODER_STREAM_ERROR;
- }
-
- return ngx_http_v3_insert(c, &name, &value);
-}
-
-
-ngx_int_t
-ngx_http_v3_ack_section(ngx_connection_t *c, ngx_uint_t stream_id)
-{
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 ack section %ui", stream_id);
-
- /* we do not use dynamic tables */
-
- return NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc)
-{
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 increment insert count %ui", inc);
-
- /* we do not use dynamic tables */
-
- return NGX_HTTP_V3_ERR_DECODER_STREAM_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_lookup_static(ngx_connection_t *c, ngx_uint_t index,
- ngx_str_t *name, ngx_str_t *value)
-{
- ngx_uint_t nelts;
- ngx_http_v3_field_t *field;
-
- nelts = sizeof(ngx_http_v3_static_table)
- / sizeof(ngx_http_v3_static_table[0]);
-
- if (index >= nelts) {
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 static[%ui] lookup out of bounds: %ui",
- index, nelts);
- return NGX_ERROR;
- }
-
- field = &ngx_http_v3_static_table[index];
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 static[%ui] lookup \"%V\":\"%V\"",
- index, &field->name, &field->value);
-
- if (name) {
- *name = field->name;
- }
-
- if (value) {
- *value = field->value;
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_lookup(ngx_connection_t *c, ngx_uint_t index, ngx_str_t *name,
- ngx_str_t *value)
-{
- ngx_http_v3_field_t *field;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (index < dt->base || index - dt->base >= dt->nelts) {
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 dynamic[%ui] lookup out of bounds: [%ui,%ui]",
- index, dt->base, dt->base + dt->nelts);
- return NGX_ERROR;
- }
-
- field = dt->elts[index - dt->base];
-
- ngx_log_debug3(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 dynamic[%ui] lookup \"%V\":\"%V\"",
- index, &field->name, &field->value);
-
- if (name) {
- *name = field->name;
- }
-
- if (value) {
- *value = field->value;
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_decode_insert_count(ngx_connection_t *c, ngx_uint_t *insert_count)
-{
- ngx_uint_t max_entries, full_range, max_value,
- max_wrapped, req_insert_count;
- ngx_http_v3_srv_conf_t *h3scf;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- /* QPACK 4.5.1.1. Required Insert Count */
-
- if (*insert_count == 0) {
- return NGX_OK;
- }
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
-
- max_entries = h3scf->max_table_capacity / 32;
- full_range = 2 * max_entries;
-
- if (*insert_count > full_range) {
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- max_value = dt->base + dt->nelts + max_entries;
- max_wrapped = (max_value / full_range) * full_range;
- req_insert_count = max_wrapped + *insert_count - 1;
-
- if (req_insert_count > max_value) {
- if (req_insert_count <= full_range) {
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- req_insert_count -= full_range;
- }
-
- if (req_insert_count == 0) {
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 decode insert_count %ui -> %ui",
- *insert_count, req_insert_count);
-
- *insert_count = req_insert_count;
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_check_insert_count(ngx_connection_t *c, ngx_uint_t insert_count)
-{
- size_t n;
- ngx_pool_cleanup_t *cln;
- ngx_http_v3_block_t *block;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_srv_conf_t *h3scf;
- ngx_http_v3_dynamic_table_t *dt;
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- n = dt->base + dt->nelts;
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 check insert count req:%ui, have:%ui",
- insert_count, n);
-
- if (n >= insert_count) {
- return NGX_OK;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 block stream");
-
- block = NULL;
-
- for (cln = c->pool->cleanup; cln; cln = cln->next) {
- if (cln->handler == ngx_http_v3_unblock) {
- block = cln->data;
- break;
- }
- }
-
- if (block == NULL) {
- cln = ngx_pool_cleanup_add(c->pool, sizeof(ngx_http_v3_block_t));
- if (cln == NULL) {
- return NGX_ERROR;
- }
-
- cln->handler = ngx_http_v3_unblock;
-
- block = cln->data;
- block->queue.prev = NULL;
- block->connection = c;
- block->nblocked = &h3c->nblocked;
- }
-
- if (block->queue.prev == NULL) {
- h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
-
- if (h3c->nblocked == h3scf->max_blocked_streams) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client exceeded http3_max_blocked_streams limit");
-
- ngx_http_v3_finalize_connection(c,
- NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED,
- "too many blocked streams");
- return NGX_HTTP_V3_ERR_DECOMPRESSION_FAILED;
- }
-
- h3c->nblocked++;
- ngx_queue_insert_tail(&h3c->blocked, &block->queue);
- }
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 blocked:%ui", h3c->nblocked);
-
- return NGX_BUSY;
-}
-
-
-void
-ngx_http_v3_ack_insert_count(ngx_connection_t *c, uint64_t insert_count)
-{
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_dynamic_table_t *dt;
-
- h3c = ngx_http_v3_get_session(c);
- dt = &h3c->table;
-
- if (dt->ack_insert_count < insert_count) {
- dt->ack_insert_count = insert_count;
- }
-}
-
-
-static void
-ngx_http_v3_unblock(void *data)
-{
- ngx_http_v3_block_t *block = data;
-
- if (block->queue.prev) {
- ngx_queue_remove(&block->queue);
- block->queue.prev = NULL;
- (*block->nblocked)--;
- }
-}
-
-
-static ngx_int_t
-ngx_http_v3_new_entry(ngx_connection_t *c)
-{
- ngx_queue_t *q;
- ngx_connection_t *bc;
- ngx_http_v3_block_t *block;
- ngx_http_v3_session_t *h3c;
-
- h3c = ngx_http_v3_get_session(c);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 new dynamic entry, blocked:%ui", h3c->nblocked);
-
- while (!ngx_queue_empty(&h3c->blocked)) {
- q = ngx_queue_head(&h3c->blocked);
- block = (ngx_http_v3_block_t *) q;
- bc = block->connection;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, bc->log, 0, "http3 unblock stream");
-
- ngx_http_v3_unblock(block);
- ngx_post_event(bc->read, &ngx_posted_events);
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_http_v3_set_param(ngx_connection_t *c, uint64_t id, uint64_t value)
-{
- switch (id) {
-
- case NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY:
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 param QPACK_MAX_TABLE_CAPACITY:%uL", value);
- break;
-
- case NGX_HTTP_V3_PARAM_MAX_FIELD_SECTION_SIZE:
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 param SETTINGS_MAX_FIELD_SECTION_SIZE:%uL",
- value);
- break;
-
- case NGX_HTTP_V3_PARAM_BLOCKED_STREAMS:
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 param QPACK_BLOCKED_STREAMS:%uL", value);
- break;
-
- default:
-
- ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 param #%uL:%uL", id, value);
- }
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.h b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.h
deleted file mode 100644
index 1c2fb17b9c..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_table.h
+++ /dev/null
@@ -1,58 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_V3_TABLE_H_INCLUDED_
-#define _NGX_HTTP_V3_TABLE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_str_t name;
- ngx_str_t value;
-} ngx_http_v3_field_t;
-
-
-typedef struct {
- ngx_http_v3_field_t **elts;
- ngx_uint_t nelts;
- ngx_uint_t base;
- size_t size;
- size_t capacity;
- uint64_t insert_count;
- uint64_t ack_insert_count;
- ngx_event_t send_insert_count;
-} ngx_http_v3_dynamic_table_t;
-
-
-void ngx_http_v3_inc_insert_count_handler(ngx_event_t *ev);
-void ngx_http_v3_cleanup_table(ngx_http_v3_session_t *h3c);
-ngx_int_t ngx_http_v3_ref_insert(ngx_connection_t *c, ngx_uint_t dynamic,
- ngx_uint_t index, ngx_str_t *value);
-ngx_int_t ngx_http_v3_insert(ngx_connection_t *c, ngx_str_t *name,
- ngx_str_t *value);
-ngx_int_t ngx_http_v3_set_capacity(ngx_connection_t *c, ngx_uint_t capacity);
-ngx_int_t ngx_http_v3_duplicate(ngx_connection_t *c, ngx_uint_t index);
-ngx_int_t ngx_http_v3_ack_section(ngx_connection_t *c, ngx_uint_t stream_id);
-ngx_int_t ngx_http_v3_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc);
-ngx_int_t ngx_http_v3_lookup_static(ngx_connection_t *c, ngx_uint_t index,
- ngx_str_t *name, ngx_str_t *value);
-ngx_int_t ngx_http_v3_lookup(ngx_connection_t *c, ngx_uint_t index,
- ngx_str_t *name, ngx_str_t *value);
-ngx_int_t ngx_http_v3_decode_insert_count(ngx_connection_t *c,
- ngx_uint_t *insert_count);
-ngx_int_t ngx_http_v3_check_insert_count(ngx_connection_t *c,
- ngx_uint_t insert_count);
-void ngx_http_v3_ack_insert_count(ngx_connection_t *c, uint64_t insert_count);
-ngx_int_t ngx_http_v3_set_param(ngx_connection_t *c, uint64_t id,
- uint64_t value);
-
-
-#endif /* _NGX_HTTP_V3_TABLE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.c b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.c
deleted file mode 100644
index 302064b8b2..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.c
+++ /dev/null
@@ -1,622 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_http_v3_parse_uni_t parse;
- ngx_int_t index;
-} ngx_http_v3_uni_stream_t;
-
-
-static void ngx_http_v3_close_uni_stream(ngx_connection_t *c);
-static void ngx_http_v3_uni_read_handler(ngx_event_t *rev);
-static void ngx_http_v3_uni_dummy_read_handler(ngx_event_t *wev);
-static void ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev);
-
-
-void
-ngx_http_v3_init_uni_stream(ngx_connection_t *c)
-{
- uint64_t n;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_uni_stream_t *us;
-
- h3c = ngx_http_v3_get_session(c);
- if (h3c->hq) {
- ngx_http_v3_finalize_connection(c,
- NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR,
- "uni stream in hq mode");
- c->data = NULL;
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 init uni stream");
-
- n = c->quic->id >> 2;
-
- if (n >= NGX_HTTP_V3_MAX_UNI_STREAMS) {
- ngx_http_v3_finalize_connection(c,
- NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR,
- "reached maximum number of uni streams");
- c->data = NULL;
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- ngx_quic_cancelable_stream(c);
-
- us = ngx_pcalloc(c->pool, sizeof(ngx_http_v3_uni_stream_t));
- if (us == NULL) {
- ngx_http_v3_finalize_connection(c,
- NGX_HTTP_V3_ERR_INTERNAL_ERROR,
- "memory allocation error");
- c->data = NULL;
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- us->index = -1;
-
- c->data = us;
-
- c->read->handler = ngx_http_v3_uni_read_handler;
- c->write->handler = ngx_http_v3_uni_dummy_write_handler;
-
- ngx_http_v3_uni_read_handler(c->read);
-}
-
-
-static void
-ngx_http_v3_close_uni_stream(ngx_connection_t *c)
-{
- ngx_pool_t *pool;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_uni_stream_t *us;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 close stream");
-
- us = c->data;
-
- if (us && us->index >= 0) {
- h3c = ngx_http_v3_get_session(c);
- h3c->known_streams[us->index] = NULL;
- }
-
- c->destroyed = 1;
-
- pool = c->pool;
-
- ngx_close_connection(c);
-
- ngx_destroy_pool(pool);
-}
-
-
-ngx_int_t
-ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type)
-{
- ngx_int_t index;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_uni_stream_t *us;
-
- h3c = ngx_http_v3_get_session(c);
-
- switch (type) {
-
- case NGX_HTTP_V3_STREAM_ENCODER:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 encoder stream");
- index = NGX_HTTP_V3_STREAM_CLIENT_ENCODER;
- break;
-
- case NGX_HTTP_V3_STREAM_DECODER:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 decoder stream");
- index = NGX_HTTP_V3_STREAM_CLIENT_DECODER;
- break;
-
- case NGX_HTTP_V3_STREAM_CONTROL:
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 control stream");
- index = NGX_HTTP_V3_STREAM_CLIENT_CONTROL;
-
- break;
-
- default:
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 stream 0x%02xL", type);
-
- if (h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_ENCODER] == NULL
- || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_DECODER] == NULL
- || h3c->known_streams[NGX_HTTP_V3_STREAM_CLIENT_CONTROL] == NULL)
- {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "missing mandatory stream");
- return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR;
- }
-
- index = -1;
- }
-
- if (index >= 0) {
- if (h3c->known_streams[index]) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "stream exists");
- return NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR;
- }
-
- h3c->known_streams[index] = c;
-
- us = c->data;
- us->index = index;
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_http_v3_uni_read_handler(ngx_event_t *rev)
-{
- u_char buf[128];
- ssize_t n;
- ngx_buf_t b;
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_uni_stream_t *us;
-
- c = rev->data;
- us = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read handler");
-
- if (c->close) {
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- ngx_memzero(&b, sizeof(ngx_buf_t));
-
- while (rev->ready) {
-
- n = c->recv(c, buf, sizeof(buf));
-
- if (n == NGX_ERROR) {
- rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;
- goto failed;
- }
-
- if (n == 0) {
- if (us->index >= 0) {
- rc = NGX_HTTP_V3_ERR_CLOSED_CRITICAL_STREAM;
- goto failed;
- }
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 read eof");
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- if (n == NGX_AGAIN) {
- break;
- }
-
- b.pos = buf;
- b.last = buf + n;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (ngx_http_v3_check_flood(c) != NGX_OK) {
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- rc = ngx_http_v3_parse_uni(c, &us->parse, &b);
-
- if (rc == NGX_DONE) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 read done");
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- if (rc > 0) {
- goto failed;
- }
-
- if (rc != NGX_AGAIN) {
- rc = NGX_HTTP_V3_ERR_GENERAL_PROTOCOL_ERROR;
- goto failed;
- }
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- rc = NGX_HTTP_V3_ERR_INTERNAL_ERROR;
- goto failed;
- }
-
- return;
-
-failed:
-
- ngx_http_v3_finalize_connection(c, rc, "stream error");
- ngx_http_v3_close_uni_stream(c);
-}
-
-
-static void
-ngx_http_v3_uni_dummy_read_handler(ngx_event_t *rev)
-{
- u_char ch;
- ngx_connection_t *c;
-
- c = rev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy read handler");
-
- if (c->close) {
- ngx_http_v3_close_uni_stream(c);
- return;
- }
-
- if (rev->ready) {
- if (c->recv(c, &ch, 1) != 0) {
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_NO_ERROR, NULL);
- ngx_http_v3_close_uni_stream(c);
- return;
- }
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
- NULL);
- ngx_http_v3_close_uni_stream(c);
- }
-}
-
-
-static void
-ngx_http_v3_uni_dummy_write_handler(ngx_event_t *wev)
-{
- ngx_connection_t *c;
-
- c = wev->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 dummy write handler");
-
- if (ngx_handle_write_event(wev, 0) != NGX_OK) {
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_INTERNAL_ERROR,
- NULL);
- ngx_http_v3_close_uni_stream(c);
- }
-}
-
-
-ngx_connection_t *
-ngx_http_v3_get_uni_stream(ngx_connection_t *c, ngx_uint_t type)
-{
- u_char buf[NGX_HTTP_V3_VARLEN_INT_LEN];
- size_t n;
- ngx_int_t index;
- ngx_connection_t *sc;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_uni_stream_t *us;
-
- switch (type) {
- case NGX_HTTP_V3_STREAM_ENCODER:
- index = NGX_HTTP_V3_STREAM_SERVER_ENCODER;
- break;
- case NGX_HTTP_V3_STREAM_DECODER:
- index = NGX_HTTP_V3_STREAM_SERVER_DECODER;
- break;
- case NGX_HTTP_V3_STREAM_CONTROL:
- index = NGX_HTTP_V3_STREAM_SERVER_CONTROL;
- break;
- default:
- index = -1;
- }
-
- h3c = ngx_http_v3_get_session(c);
-
- if (index >= 0) {
- if (h3c->known_streams[index]) {
- return h3c->known_streams[index];
- }
- }
-
- sc = ngx_quic_open_stream(c, 0);
- if (sc == NULL) {
- goto failed;
- }
-
- ngx_quic_cancelable_stream(sc);
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 create uni stream, type:%ui", type);
-
- us = ngx_pcalloc(sc->pool, sizeof(ngx_http_v3_uni_stream_t));
- if (us == NULL) {
- goto failed;
- }
-
- us->index = index;
-
- sc->data = us;
-
- sc->read->handler = ngx_http_v3_uni_dummy_read_handler;
- sc->write->handler = ngx_http_v3_uni_dummy_write_handler;
-
- if (index >= 0) {
- h3c->known_streams[index] = sc;
- }
-
- n = (u_char *) ngx_http_v3_encode_varlen_int(buf, type) - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (sc->send(sc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- ngx_post_event(sc->read, &ngx_posted_events);
-
- return sc;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to create server stream");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_STREAM_CREATION_ERROR,
- "failed to create server stream");
- if (sc) {
- ngx_http_v3_close_uni_stream(sc);
- }
-
- return NULL;
-}
-
-
-ngx_int_t
-ngx_http_v3_send_settings(ngx_connection_t *c)
-{
- u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 6];
- size_t n;
- ngx_connection_t *cc;
- ngx_http_v3_session_t *h3c;
- ngx_http_v3_srv_conf_t *h3scf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send settings");
-
- cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL);
- if (cc == NULL) {
- return NGX_ERROR;
- }
-
- h3scf = ngx_http_v3_get_module_srv_conf(c, ngx_http_v3_module);
-
- n = ngx_http_v3_encode_varlen_int(NULL,
- NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY);
- n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_table_capacity);
- n += ngx_http_v3_encode_varlen_int(NULL, NGX_HTTP_V3_PARAM_BLOCKED_STREAMS);
- n += ngx_http_v3_encode_varlen_int(NULL, h3scf->max_blocked_streams);
-
- p = (u_char *) ngx_http_v3_encode_varlen_int(buf,
- NGX_HTTP_V3_FRAME_SETTINGS);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p, n);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p,
- NGX_HTTP_V3_PARAM_MAX_TABLE_CAPACITY);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_table_capacity);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p,
- NGX_HTTP_V3_PARAM_BLOCKED_STREAMS);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p, h3scf->max_blocked_streams);
- n = p - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (cc->send(cc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send settings");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "failed to send settings");
- ngx_http_v3_close_uni_stream(cc);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id)
-{
- u_char *p, buf[NGX_HTTP_V3_VARLEN_INT_LEN * 3];
- size_t n;
- ngx_connection_t *cc;
- ngx_http_v3_session_t *h3c;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, "http3 send goaway %uL", id);
-
- cc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_CONTROL);
- if (cc == NULL) {
- return NGX_ERROR;
- }
-
- n = ngx_http_v3_encode_varlen_int(NULL, id);
- p = (u_char *) ngx_http_v3_encode_varlen_int(buf, NGX_HTTP_V3_FRAME_GOAWAY);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p, n);
- p = (u_char *) ngx_http_v3_encode_varlen_int(p, id);
- n = p - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (cc->send(cc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send goaway");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "failed to send goaway");
- ngx_http_v3_close_uni_stream(cc);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_send_ack_section(ngx_connection_t *c, ngx_uint_t stream_id)
-{
- u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN];
- size_t n;
- ngx_connection_t *dc;
- ngx_http_v3_session_t *h3c;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 send section acknowledgement %ui", stream_id);
-
- dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER);
- if (dc == NULL) {
- return NGX_ERROR;
- }
-
- buf[0] = 0x80;
- n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 7) - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (dc->send(dc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "failed to send section acknowledgement");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "failed to send section acknowledgement");
- ngx_http_v3_close_uni_stream(dc);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_send_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id)
-{
- u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN];
- size_t n;
- ngx_connection_t *dc;
- ngx_http_v3_session_t *h3c;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 send stream cancellation %ui", stream_id);
-
- dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER);
- if (dc == NULL) {
- return NGX_ERROR;
- }
-
- buf[0] = 0x40;
- n = (u_char *) ngx_http_v3_encode_prefix_int(buf, stream_id, 6) - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (dc->send(dc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0, "failed to send stream cancellation");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "failed to send stream cancellation");
- ngx_http_v3_close_uni_stream(dc);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_send_inc_insert_count(ngx_connection_t *c, ngx_uint_t inc)
-{
- u_char buf[NGX_HTTP_V3_PREFIX_INT_LEN];
- size_t n;
- ngx_connection_t *dc;
- ngx_http_v3_session_t *h3c;
-
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 send insert count increment %ui", inc);
-
- dc = ngx_http_v3_get_uni_stream(c, NGX_HTTP_V3_STREAM_DECODER);
- if (dc == NULL) {
- return NGX_ERROR;
- }
-
- buf[0] = 0;
- n = (u_char *) ngx_http_v3_encode_prefix_int(buf, inc, 6) - buf;
-
- h3c = ngx_http_v3_get_session(c);
- h3c->total_bytes += n;
-
- if (dc->send(dc, buf, n) != (ssize_t) n) {
- goto failed;
- }
-
- return NGX_OK;
-
-failed:
-
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "failed to send insert count increment");
-
- ngx_http_v3_finalize_connection(c, NGX_HTTP_V3_ERR_EXCESSIVE_LOAD,
- "failed to send insert count increment");
- ngx_http_v3_close_uni_stream(dc);
-
- return NGX_ERROR;
-}
-
-
-ngx_int_t
-ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id)
-{
- ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
- "http3 cancel stream %ui", stream_id);
-
- /* we do not use dynamic tables */
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.h b/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.h
deleted file mode 100644
index 2805894697..0000000000
--- a/src/deps/src/nginx-1.30.3/src/http/v3/ngx_http_v3_uni.h
+++ /dev/null
@@ -1,34 +0,0 @@
-
-/*
- * Copyright (C) Roman Arutyunyan
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_HTTP_V3_UNI_H_INCLUDED_
-#define _NGX_HTTP_V3_UNI_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-void ngx_http_v3_init_uni_stream(ngx_connection_t *c);
-ngx_int_t ngx_http_v3_register_uni_stream(ngx_connection_t *c, uint64_t type);
-
-ngx_int_t ngx_http_v3_cancel_stream(ngx_connection_t *c, ngx_uint_t stream_id);
-
-ngx_connection_t *ngx_http_v3_get_uni_stream(ngx_connection_t *c,
- ngx_uint_t type);
-ngx_int_t ngx_http_v3_send_settings(ngx_connection_t *c);
-ngx_int_t ngx_http_v3_send_goaway(ngx_connection_t *c, uint64_t id);
-ngx_int_t ngx_http_v3_send_ack_section(ngx_connection_t *c,
- ngx_uint_t stream_id);
-ngx_int_t ngx_http_v3_send_cancel_stream(ngx_connection_t *c,
- ngx_uint_t stream_id);
-ngx_int_t ngx_http_v3_send_inc_insert_count(ngx_connection_t *c,
- ngx_uint_t inc);
-
-
-#endif /* _NGX_HTTP_V3_UNI_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.c
deleted file mode 100644
index cc34cb3659..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.c
+++ /dev/null
@@ -1,485 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-static char *ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-static ngx_int_t ngx_mail_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
- ngx_mail_listen_t *listen);
-static char *ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports);
-static ngx_int_t ngx_mail_add_addrs(ngx_conf_t *cf, ngx_mail_port_t *mport,
- ngx_mail_conf_addr_t *addr);
-#if (NGX_HAVE_INET6)
-static ngx_int_t ngx_mail_add_addrs6(ngx_conf_t *cf, ngx_mail_port_t *mport,
- ngx_mail_conf_addr_t *addr);
-#endif
-static ngx_int_t ngx_mail_cmp_conf_addrs(const void *one, const void *two);
-
-
-ngx_uint_t ngx_mail_max_module;
-
-
-static ngx_command_t ngx_mail_commands[] = {
-
- { ngx_string("mail"),
- NGX_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
- ngx_mail_block,
- 0,
- 0,
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_core_module_t ngx_mail_module_ctx = {
- ngx_string("mail"),
- NULL,
- NULL
-};
-
-
-ngx_module_t ngx_mail_module = {
- NGX_MODULE_V1,
- &ngx_mail_module_ctx, /* module context */
- ngx_mail_commands, /* module directives */
- NGX_CORE_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static char *
-ngx_mail_block(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- char *rv;
- ngx_uint_t i, m, mi, s;
- ngx_conf_t pcf;
- ngx_array_t ports;
- ngx_mail_listen_t *listen;
- ngx_mail_module_t *module;
- ngx_mail_conf_ctx_t *ctx;
- ngx_mail_core_srv_conf_t **cscfp;
- ngx_mail_core_main_conf_t *cmcf;
-
- if (*(ngx_mail_conf_ctx_t **) conf) {
- return "is duplicate";
- }
-
- /* the main mail context */
-
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t));
- if (ctx == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *(ngx_mail_conf_ctx_t **) conf = ctx;
-
- /* count the number of the mail modules and set up their indices */
-
- ngx_mail_max_module = ngx_count_modules(cf->cycle, NGX_MAIL_MODULE);
-
-
- /* the mail main_conf context, it is the same in the all mail contexts */
-
- ctx->main_conf = ngx_pcalloc(cf->pool,
- sizeof(void *) * ngx_mail_max_module);
- if (ctx->main_conf == NULL) {
- return NGX_CONF_ERROR;
- }
-
-
- /*
- * the mail null srv_conf context, it is used to merge
- * the server{}s' srv_conf's
- */
-
- ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module);
- if (ctx->srv_conf == NULL) {
- return NGX_CONF_ERROR;
- }
-
-
- /*
- * create the main_conf's and the null srv_conf's of the all mail modules
- */
-
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
- mi = cf->cycle->modules[m]->ctx_index;
-
- if (module->create_main_conf) {
- ctx->main_conf[mi] = module->create_main_conf(cf);
- if (ctx->main_conf[mi] == NULL) {
- return NGX_CONF_ERROR;
- }
- }
-
- if (module->create_srv_conf) {
- ctx->srv_conf[mi] = module->create_srv_conf(cf);
- if (ctx->srv_conf[mi] == NULL) {
- return NGX_CONF_ERROR;
- }
- }
- }
-
-
- /* parse inside the mail{} block */
-
- pcf = *cf;
- cf->ctx = ctx;
-
- cf->module_type = NGX_MAIL_MODULE;
- cf->cmd_type = NGX_MAIL_MAIN_CONF;
- rv = ngx_conf_parse(cf, NULL);
-
- if (rv != NGX_CONF_OK) {
- *cf = pcf;
- return rv;
- }
-
-
- /* init mail{} main_conf's, merge the server{}s' srv_conf's */
-
- cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index];
- cscfp = cmcf->servers.elts;
-
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
- mi = cf->cycle->modules[m]->ctx_index;
-
- /* init mail{} main_conf's */
-
- cf->ctx = ctx;
-
- if (module->init_main_conf) {
- rv = module->init_main_conf(cf, ctx->main_conf[mi]);
- if (rv != NGX_CONF_OK) {
- *cf = pcf;
- return rv;
- }
- }
-
- for (s = 0; s < cmcf->servers.nelts; s++) {
-
- /* merge the server{}s' srv_conf's */
-
- cf->ctx = cscfp[s]->ctx;
-
- if (module->merge_srv_conf) {
- rv = module->merge_srv_conf(cf,
- ctx->srv_conf[mi],
- cscfp[s]->ctx->srv_conf[mi]);
- if (rv != NGX_CONF_OK) {
- *cf = pcf;
- return rv;
- }
- }
- }
- }
-
- *cf = pcf;
-
-
- if (ngx_array_init(&ports, cf->temp_pool, 4, sizeof(ngx_mail_conf_port_t))
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- listen = cmcf->listen.elts;
-
- for (i = 0; i < cmcf->listen.nelts; i++) {
- if (ngx_mail_add_ports(cf, &ports, &listen[i]) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- }
-
- return ngx_mail_optimize_servers(cf, &ports);
-}
-
-
-static ngx_int_t
-ngx_mail_add_ports(ngx_conf_t *cf, ngx_array_t *ports,
- ngx_mail_listen_t *listen)
-{
- in_port_t p;
- ngx_uint_t i;
- struct sockaddr *sa;
- ngx_mail_conf_port_t *port;
- ngx_mail_conf_addr_t *addr;
-
- sa = listen->sockaddr;
- p = ngx_inet_get_port(sa);
-
- port = ports->elts;
- for (i = 0; i < ports->nelts; i++) {
- if (p == port[i].port && sa->sa_family == port[i].family) {
-
- /* a port is already in the port list */
-
- port = &port[i];
- goto found;
- }
- }
-
- /* add a port to the port list */
-
- port = ngx_array_push(ports);
- if (port == NULL) {
- return NGX_ERROR;
- }
-
- port->family = sa->sa_family;
- port->port = p;
-
- if (ngx_array_init(&port->addrs, cf->temp_pool, 2,
- sizeof(ngx_mail_conf_addr_t))
- != NGX_OK)
- {
- return NGX_ERROR;
- }
-
-found:
-
- addr = ngx_array_push(&port->addrs);
- if (addr == NULL) {
- return NGX_ERROR;
- }
-
- addr->opt = *listen;
-
- return NGX_OK;
-}
-
-
-static char *
-ngx_mail_optimize_servers(ngx_conf_t *cf, ngx_array_t *ports)
-{
- ngx_uint_t i, p, last, bind_wildcard;
- ngx_listening_t *ls;
- ngx_mail_port_t *mport;
- ngx_mail_conf_port_t *port;
- ngx_mail_conf_addr_t *addr;
- ngx_mail_core_srv_conf_t *cscf;
-
- port = ports->elts;
- for (p = 0; p < ports->nelts; p++) {
-
- ngx_sort(port[p].addrs.elts, (size_t) port[p].addrs.nelts,
- sizeof(ngx_mail_conf_addr_t), ngx_mail_cmp_conf_addrs);
-
- addr = port[p].addrs.elts;
- last = port[p].addrs.nelts;
-
- /*
- * if there is the binding to the "*:port" then we need to bind()
- * to the "*:port" only and ignore the other bindings
- */
-
- if (addr[last - 1].opt.wildcard) {
- addr[last - 1].opt.bind = 1;
- bind_wildcard = 1;
-
- } else {
- bind_wildcard = 0;
- }
-
- i = 0;
-
- while (i < last) {
-
- if (bind_wildcard && !addr[i].opt.bind) {
- i++;
- continue;
- }
-
- ls = ngx_create_listening(cf, addr[i].opt.sockaddr,
- addr[i].opt.socklen);
- if (ls == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ls->addr_ntop = 1;
- ls->handler = ngx_mail_init_connection;
- ls->pool_size = 256;
-
- cscf = addr->opt.ctx->srv_conf[ngx_mail_core_module.ctx_index];
-
- ls->logp = cscf->error_log;
- ls->log.data = &ls->addr_text;
- ls->log.handler = ngx_accept_log_error;
-
- ls->protocol = addr[i].opt.protocol;
- ls->backlog = addr[i].opt.backlog;
- ls->rcvbuf = addr[i].opt.rcvbuf;
- ls->sndbuf = addr[i].opt.sndbuf;
-
- ls->keepalive = addr[i].opt.so_keepalive;
-#if (NGX_HAVE_KEEPALIVE_TUNABLE)
- ls->keepidle = addr[i].opt.tcp_keepidle;
- ls->keepintvl = addr[i].opt.tcp_keepintvl;
- ls->keepcnt = addr[i].opt.tcp_keepcnt;
-#endif
-
-#if (NGX_HAVE_INET6)
- ls->ipv6only = addr[i].opt.ipv6only;
-#endif
-
- mport = ngx_palloc(cf->pool, sizeof(ngx_mail_port_t));
- if (mport == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ls->servers = mport;
-
- mport->naddrs = i + 1;
-
- switch (ls->sockaddr->sa_family) {
-#if (NGX_HAVE_INET6)
- case AF_INET6:
- if (ngx_mail_add_addrs6(cf, mport, addr) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- break;
-#endif
- default: /* AF_INET */
- if (ngx_mail_add_addrs(cf, mport, addr) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- break;
- }
-
- addr++;
- last--;
- }
- }
-
- return NGX_CONF_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_add_addrs(ngx_conf_t *cf, ngx_mail_port_t *mport,
- ngx_mail_conf_addr_t *addr)
-{
- ngx_uint_t i;
- ngx_mail_in_addr_t *addrs;
- struct sockaddr_in *sin;
-
- mport->addrs = ngx_pcalloc(cf->pool,
- mport->naddrs * sizeof(ngx_mail_in_addr_t));
- if (mport->addrs == NULL) {
- return NGX_ERROR;
- }
-
- addrs = mport->addrs;
-
- for (i = 0; i < mport->naddrs; i++) {
-
- sin = (struct sockaddr_in *) addr[i].opt.sockaddr;
- addrs[i].addr = sin->sin_addr.s_addr;
-
- addrs[i].conf.ctx = addr[i].opt.ctx;
-#if (NGX_MAIL_SSL)
- addrs[i].conf.ssl = addr[i].opt.ssl;
-#endif
- addrs[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
- addrs[i].conf.addr_text = addr[i].opt.addr_text;
- }
-
- return NGX_OK;
-}
-
-
-#if (NGX_HAVE_INET6)
-
-static ngx_int_t
-ngx_mail_add_addrs6(ngx_conf_t *cf, ngx_mail_port_t *mport,
- ngx_mail_conf_addr_t *addr)
-{
- ngx_uint_t i;
- ngx_mail_in6_addr_t *addrs6;
- struct sockaddr_in6 *sin6;
-
- mport->addrs = ngx_pcalloc(cf->pool,
- mport->naddrs * sizeof(ngx_mail_in6_addr_t));
- if (mport->addrs == NULL) {
- return NGX_ERROR;
- }
-
- addrs6 = mport->addrs;
-
- for (i = 0; i < mport->naddrs; i++) {
-
- sin6 = (struct sockaddr_in6 *) addr[i].opt.sockaddr;
- addrs6[i].addr6 = sin6->sin6_addr;
-
- addrs6[i].conf.ctx = addr[i].opt.ctx;
-#if (NGX_MAIL_SSL)
- addrs6[i].conf.ssl = addr[i].opt.ssl;
-#endif
- addrs6[i].conf.proxy_protocol = addr[i].opt.proxy_protocol;
- addrs6[i].conf.addr_text = addr[i].opt.addr_text;
- }
-
- return NGX_OK;
-}
-
-#endif
-
-
-static ngx_int_t
-ngx_mail_cmp_conf_addrs(const void *one, const void *two)
-{
- ngx_mail_conf_addr_t *first, *second;
-
- first = (ngx_mail_conf_addr_t *) one;
- second = (ngx_mail_conf_addr_t *) two;
-
- if (first->opt.wildcard) {
- /* a wildcard must be the last resort, shift it to the end */
- return 1;
- }
-
- if (second->opt.wildcard) {
- /* a wildcard must be the last resort, shift it to the end */
- return -1;
- }
-
- if (first->opt.bind && !second->opt.bind) {
- /* shift explicit bind()ed addresses to the start */
- return -1;
- }
-
- if (!first->opt.bind && second->opt.bind) {
- /* shift explicit bind()ed addresses to the start */
- return 1;
- }
-
- /* do not sort by default */
-
- return 0;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.h b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.h
deleted file mode 100644
index 221faf67d5..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail.h
+++ /dev/null
@@ -1,425 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_MAIL_H_INCLUDED_
-#define _NGX_MAIL_H_INCLUDED_
-
-
-#include
-#include
-#include
-#include
-
-#if (NGX_MAIL_SSL)
-#include
-#endif
-
-
-
-typedef struct {
- void **main_conf;
- void **srv_conf;
-} ngx_mail_conf_ctx_t;
-
-
-typedef struct {
- struct sockaddr *sockaddr;
- socklen_t socklen;
- ngx_str_t addr_text;
-
- /* server ctx */
- ngx_mail_conf_ctx_t *ctx;
-
- unsigned bind:1;
- unsigned wildcard:1;
- unsigned ssl:1;
-#if (NGX_HAVE_INET6)
- unsigned ipv6only:1;
-#endif
- unsigned so_keepalive:2;
- unsigned proxy_protocol:1;
-#if (NGX_HAVE_KEEPALIVE_TUNABLE)
- int tcp_keepidle;
- int tcp_keepintvl;
- int tcp_keepcnt;
-#endif
- int protocol;
- int backlog;
- int rcvbuf;
- int sndbuf;
-} ngx_mail_listen_t;
-
-
-typedef struct {
- ngx_mail_conf_ctx_t *ctx;
- ngx_str_t addr_text;
- unsigned ssl:1;
- unsigned proxy_protocol:1;
-} ngx_mail_addr_conf_t;
-
-typedef struct {
- in_addr_t addr;
- ngx_mail_addr_conf_t conf;
-} ngx_mail_in_addr_t;
-
-
-#if (NGX_HAVE_INET6)
-
-typedef struct {
- struct in6_addr addr6;
- ngx_mail_addr_conf_t conf;
-} ngx_mail_in6_addr_t;
-
-#endif
-
-
-typedef struct {
- /* ngx_mail_in_addr_t or ngx_mail_in6_addr_t */
- void *addrs;
- ngx_uint_t naddrs;
-} ngx_mail_port_t;
-
-
-typedef struct {
- int family;
- in_port_t port;
- ngx_array_t addrs; /* array of ngx_mail_conf_addr_t */
-} ngx_mail_conf_port_t;
-
-
-typedef struct {
- ngx_mail_listen_t opt;
-} ngx_mail_conf_addr_t;
-
-
-typedef struct {
- ngx_array_t servers; /* ngx_mail_core_srv_conf_t */
- ngx_array_t listen; /* ngx_mail_listen_t */
-} ngx_mail_core_main_conf_t;
-
-
-#define NGX_MAIL_POP3_PROTOCOL 0
-#define NGX_MAIL_IMAP_PROTOCOL 1
-#define NGX_MAIL_SMTP_PROTOCOL 2
-
-
-typedef struct ngx_mail_protocol_s ngx_mail_protocol_t;
-
-
-typedef struct {
- ngx_mail_protocol_t *protocol;
-
- ngx_msec_t timeout;
- ngx_msec_t resolver_timeout;
-
- ngx_uint_t max_errors;
-
- ngx_str_t server_name;
-
- u_char *file_name;
- ngx_uint_t line;
-
- ngx_resolver_t *resolver;
- ngx_log_t *error_log;
-
- /* server ctx */
- ngx_mail_conf_ctx_t *ctx;
-
- ngx_uint_t listen; /* unsigned listen:1; */
-} ngx_mail_core_srv_conf_t;
-
-
-typedef enum {
- ngx_pop3_start = 0,
- ngx_pop3_user,
- ngx_pop3_passwd,
- ngx_pop3_auth_login_username,
- ngx_pop3_auth_login_password,
- ngx_pop3_auth_plain,
- ngx_pop3_auth_cram_md5,
- ngx_pop3_auth_external
-} ngx_pop3_state_e;
-
-
-typedef enum {
- ngx_imap_start = 0,
- ngx_imap_auth_login_username,
- ngx_imap_auth_login_password,
- ngx_imap_auth_plain,
- ngx_imap_auth_cram_md5,
- ngx_imap_auth_external,
- ngx_imap_login,
- ngx_imap_user,
- ngx_imap_passwd
-} ngx_imap_state_e;
-
-
-typedef enum {
- ngx_smtp_start = 0,
- ngx_smtp_auth_login_username,
- ngx_smtp_auth_login_password,
- ngx_smtp_auth_plain,
- ngx_smtp_auth_cram_md5,
- ngx_smtp_auth_external,
- ngx_smtp_helo,
- ngx_smtp_helo_xclient,
- ngx_smtp_helo_auth,
- ngx_smtp_helo_from,
- ngx_smtp_xclient,
- ngx_smtp_xclient_from,
- ngx_smtp_xclient_helo,
- ngx_smtp_xclient_auth,
- ngx_smtp_from,
- ngx_smtp_to
-} ngx_smtp_state_e;
-
-
-typedef struct {
- ngx_peer_connection_t upstream;
- ngx_buf_t *buffer;
- ngx_uint_t proxy_protocol; /* unsigned proxy_protocol:1; */
-} ngx_mail_proxy_ctx_t;
-
-
-typedef struct {
- uint32_t signature; /* "MAIL" */
-
- ngx_connection_t *connection;
-
- ngx_str_t out;
- ngx_buf_t *buffer;
-
- void **ctx;
- void **main_conf;
- void **srv_conf;
-
- ngx_resolver_ctx_t *resolver_ctx;
-
- ngx_mail_proxy_ctx_t *proxy;
-
- ngx_uint_t mail_state;
-
- unsigned ssl:1;
- unsigned protocol:3;
- unsigned blocked:1;
- unsigned quit:1;
- unsigned quoted:1;
- unsigned backslash:1;
- unsigned no_sync_literal:1;
- unsigned starttls:1;
- unsigned esmtp:1;
- unsigned auth_method:3;
- unsigned auth_wait:1;
-
- ngx_str_t login;
- ngx_str_t passwd;
-
- ngx_str_t salt;
- ngx_str_t tag;
- ngx_str_t tagged_line;
- ngx_str_t text;
-
- ngx_str_t *addr_text;
- ngx_str_t host;
- ngx_str_t smtp_helo;
- ngx_str_t smtp_from;
- ngx_str_t smtp_to;
-
- ngx_str_t cmd;
-
- ngx_uint_t command;
- ngx_array_t args;
-
- ngx_uint_t errors;
- ngx_uint_t login_attempt;
-
- /* used to parse POP3/IMAP/SMTP command */
-
- ngx_uint_t state;
- u_char *tag_start;
- u_char *cmd_start;
- u_char *arg_start;
- ngx_uint_t literal_len;
-} ngx_mail_session_t;
-
-
-typedef struct {
- ngx_str_t *client;
- ngx_mail_session_t *session;
-} ngx_mail_log_ctx_t;
-
-
-#define NGX_POP3_USER 1
-#define NGX_POP3_PASS 2
-#define NGX_POP3_CAPA 3
-#define NGX_POP3_QUIT 4
-#define NGX_POP3_NOOP 5
-#define NGX_POP3_STLS 6
-#define NGX_POP3_APOP 7
-#define NGX_POP3_AUTH 8
-#define NGX_POP3_STAT 9
-#define NGX_POP3_LIST 10
-#define NGX_POP3_RETR 11
-#define NGX_POP3_DELE 12
-#define NGX_POP3_RSET 13
-#define NGX_POP3_TOP 14
-#define NGX_POP3_UIDL 15
-
-
-#define NGX_IMAP_LOGIN 1
-#define NGX_IMAP_LOGOUT 2
-#define NGX_IMAP_CAPABILITY 3
-#define NGX_IMAP_NOOP 4
-#define NGX_IMAP_STARTTLS 5
-
-#define NGX_IMAP_NEXT 6
-
-#define NGX_IMAP_AUTHENTICATE 7
-
-
-#define NGX_SMTP_HELO 1
-#define NGX_SMTP_EHLO 2
-#define NGX_SMTP_AUTH 3
-#define NGX_SMTP_QUIT 4
-#define NGX_SMTP_NOOP 5
-#define NGX_SMTP_MAIL 6
-#define NGX_SMTP_RSET 7
-#define NGX_SMTP_RCPT 8
-#define NGX_SMTP_DATA 9
-#define NGX_SMTP_VRFY 10
-#define NGX_SMTP_EXPN 11
-#define NGX_SMTP_HELP 12
-#define NGX_SMTP_STARTTLS 13
-
-
-#define NGX_MAIL_AUTH_PLAIN 0
-#define NGX_MAIL_AUTH_LOGIN 1
-#define NGX_MAIL_AUTH_LOGIN_USERNAME 2
-#define NGX_MAIL_AUTH_APOP 3
-#define NGX_MAIL_AUTH_CRAM_MD5 4
-#define NGX_MAIL_AUTH_EXTERNAL 5
-#define NGX_MAIL_AUTH_NONE 6
-
-
-#define NGX_MAIL_AUTH_PLAIN_ENABLED 0x0002
-#define NGX_MAIL_AUTH_LOGIN_ENABLED 0x0004
-#define NGX_MAIL_AUTH_APOP_ENABLED 0x0008
-#define NGX_MAIL_AUTH_CRAM_MD5_ENABLED 0x0010
-#define NGX_MAIL_AUTH_EXTERNAL_ENABLED 0x0020
-#define NGX_MAIL_AUTH_NONE_ENABLED 0x0040
-
-
-#define NGX_MAIL_PARSE_INVALID_COMMAND 20
-
-
-typedef void (*ngx_mail_init_session_pt)(ngx_mail_session_t *s,
- ngx_connection_t *c);
-typedef void (*ngx_mail_init_protocol_pt)(ngx_event_t *rev);
-typedef void (*ngx_mail_auth_state_pt)(ngx_event_t *rev);
-typedef ngx_int_t (*ngx_mail_parse_command_pt)(ngx_mail_session_t *s);
-
-
-struct ngx_mail_protocol_s {
- ngx_str_t name;
- ngx_str_t alpn;
- in_port_t port[4];
- ngx_uint_t type;
-
- ngx_mail_init_session_pt init_session;
- ngx_mail_init_protocol_pt init_protocol;
- ngx_mail_parse_command_pt parse_command;
- ngx_mail_auth_state_pt auth_state;
-
- ngx_str_t internal_server_error;
- ngx_str_t cert_error;
- ngx_str_t no_cert;
-};
-
-
-typedef struct {
- ngx_mail_protocol_t *protocol;
-
- void *(*create_main_conf)(ngx_conf_t *cf);
- char *(*init_main_conf)(ngx_conf_t *cf, void *conf);
-
- void *(*create_srv_conf)(ngx_conf_t *cf);
- char *(*merge_srv_conf)(ngx_conf_t *cf, void *prev,
- void *conf);
-} ngx_mail_module_t;
-
-
-#define NGX_MAIL_MODULE 0x4C49414D /* "MAIL" */
-
-#define NGX_MAIL_MAIN_CONF 0x02000000
-#define NGX_MAIL_SRV_CONF 0x04000000
-
-
-#define NGX_MAIL_MAIN_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, main_conf)
-#define NGX_MAIL_SRV_CONF_OFFSET offsetof(ngx_mail_conf_ctx_t, srv_conf)
-
-
-#define ngx_mail_get_module_ctx(s, module) (s)->ctx[module.ctx_index]
-#define ngx_mail_set_ctx(s, c, module) s->ctx[module.ctx_index] = c;
-#define ngx_mail_delete_ctx(s, module) s->ctx[module.ctx_index] = NULL;
-
-
-#define ngx_mail_get_module_main_conf(s, module) \
- (s)->main_conf[module.ctx_index]
-#define ngx_mail_get_module_srv_conf(s, module) (s)->srv_conf[module.ctx_index]
-
-#define ngx_mail_conf_get_module_main_conf(cf, module) \
- ((ngx_mail_conf_ctx_t *) cf->ctx)->main_conf[module.ctx_index]
-#define ngx_mail_conf_get_module_srv_conf(cf, module) \
- ((ngx_mail_conf_ctx_t *) cf->ctx)->srv_conf[module.ctx_index]
-
-
-#if (NGX_MAIL_SSL)
-void ngx_mail_starttls_handler(ngx_event_t *rev);
-ngx_int_t ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c);
-#endif
-
-
-void ngx_mail_init_connection(ngx_connection_t *c);
-
-ngx_int_t ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_mail_core_srv_conf_t *cscf);
-ngx_int_t ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_uint_t n);
-ngx_int_t ngx_mail_auth_login_username(ngx_mail_session_t *s,
- ngx_connection_t *c, ngx_uint_t n);
-ngx_int_t ngx_mail_auth_login_password(ngx_mail_session_t *s,
- ngx_connection_t *c);
-ngx_int_t ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s,
- ngx_connection_t *c, char *prefix, size_t len);
-ngx_int_t ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c);
-ngx_int_t ngx_mail_auth_external(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_uint_t n);
-ngx_int_t ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c);
-
-void ngx_mail_send(ngx_event_t *wev);
-ngx_int_t ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_close_connection(ngx_connection_t *c);
-void ngx_mail_session_internal_server_error(ngx_mail_session_t *s);
-u_char *ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len);
-
-
-char *ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-
-
-/* STUB */
-void ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_addr_t *peer);
-void ngx_mail_auth_http_init(ngx_mail_session_t *s);
-ngx_int_t ngx_mail_realip_handler(ngx_mail_session_t *s);
-/**/
-
-
-extern ngx_uint_t ngx_mail_max_module;
-extern ngx_module_t ngx_mail_core_module;
-
-
-#endif /* _NGX_MAIL_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_auth_http_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_auth_http_module.c
deleted file mode 100644
index 3e5095a2d2..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_auth_http_module.c
+++ /dev/null
@@ -1,1662 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_addr_t *peer;
-
- ngx_msec_t timeout;
- ngx_flag_t pass_client_cert;
-
- ngx_str_t host_header;
- ngx_str_t uri;
- ngx_str_t header;
-
- ngx_array_t *headers;
-
- u_char *file;
- ngx_uint_t line;
-} ngx_mail_auth_http_conf_t;
-
-
-typedef struct ngx_mail_auth_http_ctx_s ngx_mail_auth_http_ctx_t;
-
-typedef void (*ngx_mail_auth_http_handler_pt)(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx);
-
-struct ngx_mail_auth_http_ctx_s {
- ngx_buf_t *request;
- ngx_buf_t *response;
- ngx_peer_connection_t peer;
-
- ngx_mail_auth_http_handler_pt handler;
-
- ngx_uint_t state;
-
- u_char *header_name_start;
- u_char *header_name_end;
- u_char *header_start;
- u_char *header_end;
-
- ngx_str_t addr;
- ngx_str_t port;
- ngx_str_t err;
- ngx_str_t errmsg;
- ngx_str_t errcode;
-
- time_t sleep;
-
- ngx_pool_t *pool;
-};
-
-
-static void ngx_mail_auth_http_write_handler(ngx_event_t *wev);
-static void ngx_mail_auth_http_read_handler(ngx_event_t *rev);
-static void ngx_mail_auth_http_ignore_status_line(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx);
-static void ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx);
-static void ngx_mail_auth_sleep_handler(ngx_event_t *rev);
-static ngx_int_t ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx);
-static void ngx_mail_auth_http_block_read(ngx_event_t *rev);
-static void ngx_mail_auth_http_dummy_handler(ngx_event_t *ev);
-static ngx_buf_t *ngx_mail_auth_http_create_request(ngx_mail_session_t *s,
- ngx_pool_t *pool, ngx_mail_auth_http_conf_t *ahcf);
-static ngx_int_t ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text,
- ngx_str_t *escaped);
-
-static void *ngx_mail_auth_http_create_conf(ngx_conf_t *cf);
-static char *ngx_mail_auth_http_merge_conf(ngx_conf_t *cf, void *parent,
- void *child);
-static char *ngx_mail_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
-static char *ngx_mail_auth_http_header(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-
-
-static ngx_command_t ngx_mail_auth_http_commands[] = {
-
- { ngx_string("auth_http"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_mail_auth_http,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("auth_http_timeout"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_auth_http_conf_t, timeout),
- NULL },
-
- { ngx_string("auth_http_header"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE2,
- ngx_mail_auth_http_header,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("auth_http_pass_client_cert"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_auth_http_conf_t, pass_client_cert),
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_auth_http_module_ctx = {
- NULL, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_auth_http_create_conf, /* create server configuration */
- ngx_mail_auth_http_merge_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_auth_http_module = {
- NGX_MODULE_V1,
- &ngx_mail_auth_http_module_ctx, /* module context */
- ngx_mail_auth_http_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_str_t ngx_mail_auth_http_method[] = {
- ngx_string("plain"),
- ngx_string("plain"),
- ngx_string("plain"),
- ngx_string("apop"),
- ngx_string("cram-md5"),
- ngx_string("external"),
- ngx_string("none")
-};
-
-static ngx_str_t ngx_mail_smtp_errcode = ngx_string("535 5.7.0");
-
-
-void
-ngx_mail_auth_http_init(ngx_mail_session_t *s)
-{
- ngx_int_t rc;
- ngx_pool_t *pool;
- ngx_mail_auth_http_ctx_t *ctx;
- ngx_mail_auth_http_conf_t *ahcf;
-
- s->connection->log->action = "in http auth state";
-
- pool = ngx_create_pool(2048, s->connection->log);
- if (pool == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ctx = ngx_pcalloc(pool, sizeof(ngx_mail_auth_http_ctx_t));
- if (ctx == NULL) {
- ngx_destroy_pool(pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ctx->pool = pool;
-
- ahcf = ngx_mail_get_module_srv_conf(s, ngx_mail_auth_http_module);
-
- ctx->request = ngx_mail_auth_http_create_request(s, pool, ahcf);
- if (ctx->request == NULL) {
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_mail_set_ctx(s, ctx, ngx_mail_auth_http_module);
-
- ctx->peer.sockaddr = ahcf->peer->sockaddr;
- ctx->peer.socklen = ahcf->peer->socklen;
- ctx->peer.name = &ahcf->peer->name;
- ctx->peer.get = ngx_event_get_peer;
- ctx->peer.log = s->connection->log;
- ctx->peer.log_error = NGX_ERROR_ERR;
-
- rc = ngx_event_connect_peer(&ctx->peer);
-
- if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
- if (ctx->peer.connection) {
- ngx_close_connection(ctx->peer.connection);
- }
-
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ctx->peer.connection->data = s;
- ctx->peer.connection->pool = s->connection->pool;
-
- s->connection->read->handler = ngx_mail_auth_http_block_read;
- ctx->peer.connection->read->handler = ngx_mail_auth_http_read_handler;
- ctx->peer.connection->write->handler = ngx_mail_auth_http_write_handler;
-
- ctx->handler = ngx_mail_auth_http_ignore_status_line;
-
- ngx_add_timer(ctx->peer.connection->read, ahcf->timeout);
- ngx_add_timer(ctx->peer.connection->write, ahcf->timeout);
-
- if (rc == NGX_OK) {
- ngx_mail_auth_http_write_handler(ctx->peer.connection->write);
- return;
- }
-}
-
-
-static void
-ngx_mail_auth_http_write_handler(ngx_event_t *wev)
-{
- ssize_t n, size;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_auth_http_ctx_t *ctx;
- ngx_mail_auth_http_conf_t *ahcf;
-
- c = wev->data;
- s = c->data;
-
- ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0,
- "mail auth http write handler");
-
- if (wev->timedout) {
- ngx_log_error(NGX_LOG_ERR, wev->log, NGX_ETIMEDOUT,
- "auth http server %V timed out", ctx->peer.name);
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- size = ctx->request->last - ctx->request->pos;
-
- n = ngx_send(c, ctx->request->pos, size);
-
- if (n == NGX_ERROR) {
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- if (n > 0) {
- ctx->request->pos += n;
-
- if (n == size) {
- wev->handler = ngx_mail_auth_http_dummy_handler;
-
- if (wev->timer_set) {
- ngx_del_timer(wev);
- }
-
- if (ngx_handle_write_event(wev, 0) != NGX_OK) {
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- }
-
- return;
- }
- }
-
- if (!wev->timer_set) {
- ahcf = ngx_mail_get_module_srv_conf(s, ngx_mail_auth_http_module);
- ngx_add_timer(wev, ahcf->timeout);
- }
-}
-
-
-static void
-ngx_mail_auth_http_read_handler(ngx_event_t *rev)
-{
- ssize_t n, size;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_auth_http_ctx_t *ctx;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail auth http read handler");
-
- ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_ERR, rev->log, NGX_ETIMEDOUT,
- "auth http server %V timed out", ctx->peer.name);
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- if (ctx->response == NULL) {
- ctx->response = ngx_create_temp_buf(ctx->pool, 1024);
- if (ctx->response == NULL) {
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
- }
-
- size = ctx->response->end - ctx->response->last;
-
- n = ngx_recv(c, ctx->response->pos, size);
-
- if (n > 0) {
- ctx->response->last += n;
-
- ctx->handler(s, ctx);
- return;
- }
-
- if (n == NGX_AGAIN) {
- return;
- }
-
- ngx_close_connection(c);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
-}
-
-
-static void
-ngx_mail_auth_http_ignore_status_line(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx)
-{
- u_char *p, ch;
- enum {
- sw_start = 0,
- sw_H,
- sw_HT,
- sw_HTT,
- sw_HTTP,
- sw_skip,
- sw_almost_done
- } state;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail auth http process status line");
-
- state = ctx->state;
-
- for (p = ctx->response->pos; p < ctx->response->last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* "HTTP/" */
- case sw_start:
- if (ch == 'H') {
- state = sw_H;
- break;
- }
- goto next;
-
- case sw_H:
- if (ch == 'T') {
- state = sw_HT;
- break;
- }
- goto next;
-
- case sw_HT:
- if (ch == 'T') {
- state = sw_HTT;
- break;
- }
- goto next;
-
- case sw_HTT:
- if (ch == 'P') {
- state = sw_HTTP;
- break;
- }
- goto next;
-
- case sw_HTTP:
- if (ch == '/') {
- state = sw_skip;
- break;
- }
- goto next;
-
- /* any text until end of line */
- case sw_skip:
- switch (ch) {
- case CR:
- state = sw_almost_done;
-
- break;
- case LF:
- goto done;
- }
- break;
-
- /* end of status line */
- case sw_almost_done:
- if (ch == LF) {
- goto done;
- }
-
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V sent invalid response",
- ctx->peer.name);
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
- }
-
- ctx->response->pos = p;
- ctx->state = state;
-
- return;
-
-next:
-
- p = ctx->response->start - 1;
-
-done:
-
- ctx->response->pos = p + 1;
- ctx->state = 0;
- ctx->handler = ngx_mail_auth_http_process_headers;
- ctx->handler(s, ctx);
-}
-
-
-static void
-ngx_mail_auth_http_process_headers(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx)
-{
- u_char *p;
- time_t timer;
- size_t len, size;
- ngx_int_t rc, port, n;
- ngx_addr_t *peer;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail auth http process headers");
-
- for ( ;; ) {
- rc = ngx_mail_auth_http_parse_header_line(s, ctx);
-
- if (rc == NGX_OK) {
-
-#if (NGX_DEBUG)
- {
- ngx_str_t key, value;
-
- key.len = ctx->header_name_end - ctx->header_name_start;
- key.data = ctx->header_name_start;
- value.len = ctx->header_end - ctx->header_start;
- value.data = ctx->header_start;
-
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail auth http header: \"%V: %V\"",
- &key, &value);
- }
-#endif
-
- len = ctx->header_name_end - ctx->header_name_start;
-
- if (len == sizeof("Auth-Status") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Status",
- sizeof("Auth-Status") - 1)
- == 0)
- {
- len = ctx->header_end - ctx->header_start;
-
- if (len == 2
- && ctx->header_start[0] == 'O'
- && ctx->header_start[1] == 'K')
- {
- continue;
- }
-
- if (len == 4
- && ctx->header_start[0] == 'W'
- && ctx->header_start[1] == 'A'
- && ctx->header_start[2] == 'I'
- && ctx->header_start[3] == 'T')
- {
- s->auth_wait = 1;
- continue;
- }
-
- ctx->errmsg.len = len;
- ctx->errmsg.data = ctx->header_start;
-
- switch (s->protocol) {
-
- case NGX_MAIL_POP3_PROTOCOL:
- size = sizeof("-ERR ") - 1 + len + sizeof(CRLF) - 1;
- break;
-
- case NGX_MAIL_IMAP_PROTOCOL:
- size = s->tag.len + sizeof("NO ") - 1 + len
- + sizeof(CRLF) - 1;
- break;
-
- default: /* NGX_MAIL_SMTP_PROTOCOL */
- ctx->err = ctx->errmsg;
- continue;
- }
-
- p = ngx_pnalloc(s->connection->pool, size);
- if (p == NULL) {
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ctx->err.data = p;
-
- switch (s->protocol) {
-
- case NGX_MAIL_POP3_PROTOCOL:
- *p++ = '-'; *p++ = 'E'; *p++ = 'R'; *p++ = 'R'; *p++ = ' ';
- break;
-
- case NGX_MAIL_IMAP_PROTOCOL:
- p = ngx_cpymem(p, s->tag.data, s->tag.len);
- *p++ = 'N'; *p++ = 'O'; *p++ = ' ';
- break;
-
- default: /* NGX_MAIL_SMTP_PROTOCOL */
- break;
- }
-
- p = ngx_cpymem(p, ctx->header_start, len);
- *p++ = CR; *p++ = LF;
-
- ctx->err.len = p - ctx->err.data;
-
- continue;
- }
-
- if (len == sizeof("Auth-Server") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Server",
- sizeof("Auth-Server") - 1)
- == 0)
- {
- ctx->addr.len = ctx->header_end - ctx->header_start;
- ctx->addr.data = ctx->header_start;
-
- continue;
- }
-
- if (len == sizeof("Auth-Port") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Port",
- sizeof("Auth-Port") - 1)
- == 0)
- {
- ctx->port.len = ctx->header_end - ctx->header_start;
- ctx->port.data = ctx->header_start;
-
- continue;
- }
-
- if (len == sizeof("Auth-User") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-User",
- sizeof("Auth-User") - 1)
- == 0)
- {
- s->login.len = ctx->header_end - ctx->header_start;
-
- s->login.data = ngx_pnalloc(s->connection->pool, s->login.len);
- if (s->login.data == NULL) {
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_memcpy(s->login.data, ctx->header_start, s->login.len);
-
- continue;
- }
-
- if (len == sizeof("Auth-Pass") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Pass",
- sizeof("Auth-Pass") - 1)
- == 0)
- {
- s->passwd.len = ctx->header_end - ctx->header_start;
-
- s->passwd.data = ngx_pnalloc(s->connection->pool,
- s->passwd.len);
- if (s->passwd.data == NULL) {
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_memcpy(s->passwd.data, ctx->header_start, s->passwd.len);
-
- continue;
- }
-
- if (len == sizeof("Auth-Wait") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Wait",
- sizeof("Auth-Wait") - 1)
- == 0)
- {
- n = ngx_atoi(ctx->header_start,
- ctx->header_end - ctx->header_start);
-
- if (n != NGX_ERROR) {
- ctx->sleep = n;
- }
-
- continue;
- }
-
- if (len == sizeof("Auth-Error-Code") - 1
- && ngx_strncasecmp(ctx->header_name_start,
- (u_char *) "Auth-Error-Code",
- sizeof("Auth-Error-Code") - 1)
- == 0)
- {
- ctx->errcode.len = ctx->header_end - ctx->header_start;
-
- ctx->errcode.data = ngx_pnalloc(s->connection->pool,
- ctx->errcode.len);
- if (ctx->errcode.data == NULL) {
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_memcpy(ctx->errcode.data, ctx->header_start,
- ctx->errcode.len);
-
- continue;
- }
-
- /* ignore other headers */
-
- continue;
- }
-
- if (rc == NGX_DONE) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail auth http header done");
-
- ngx_close_connection(ctx->peer.connection);
-
- if (ctx->err.len) {
-
- ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
- "client login failed: \"%V\"", &ctx->errmsg);
-
- if (s->protocol == NGX_MAIL_SMTP_PROTOCOL) {
-
- if (ctx->errcode.len == 0) {
- ctx->errcode = ngx_mail_smtp_errcode;
- }
-
- ctx->err.len = ctx->errcode.len + ctx->errmsg.len
- + sizeof(" " CRLF) - 1;
-
- p = ngx_pnalloc(s->connection->pool, ctx->err.len);
- if (p == NULL) {
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ctx->err.data = p;
-
- p = ngx_cpymem(p, ctx->errcode.data, ctx->errcode.len);
- *p++ = ' ';
- p = ngx_cpymem(p, ctx->errmsg.data, ctx->errmsg.len);
- *p++ = CR; *p = LF;
- }
-
- s->out = ctx->err;
- timer = ctx->sleep;
-
- ngx_destroy_pool(ctx->pool);
-
- if (timer == 0) {
- s->quit = 1;
- ngx_mail_send(s->connection->write);
- return;
- }
-
- ngx_add_timer(s->connection->read, (ngx_msec_t) (timer * 1000));
-
- s->connection->read->handler = ngx_mail_auth_sleep_handler;
-
- return;
- }
-
- if (s->auth_wait) {
- timer = ctx->sleep;
-
- ngx_destroy_pool(ctx->pool);
-
- if (timer == 0) {
- ngx_mail_auth_http_init(s);
- return;
- }
-
- ngx_add_timer(s->connection->read, (ngx_msec_t) (timer * 1000));
-
- s->connection->read->handler = ngx_mail_auth_sleep_handler;
-
- return;
- }
-
- if (ctx->addr.len == 0 || ctx->port.len == 0) {
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V did not send server or port",
- ctx->peer.name);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- if (s->passwd.data == NULL
- && s->protocol != NGX_MAIL_SMTP_PROTOCOL)
- {
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V did not send password",
- ctx->peer.name);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- peer = ngx_pcalloc(s->connection->pool, sizeof(ngx_addr_t));
- if (peer == NULL) {
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- rc = ngx_parse_addr(s->connection->pool, peer,
- ctx->addr.data, ctx->addr.len);
-
- switch (rc) {
- case NGX_OK:
- break;
-
- case NGX_DECLINED:
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V sent invalid server "
- "address:\"%V\"",
- ctx->peer.name, &ctx->addr);
- /* fall through */
-
- default:
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- port = ngx_atoi(ctx->port.data, ctx->port.len);
- if (port == NGX_ERROR || port < 1 || port > 65535) {
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V sent invalid server "
- "port:\"%V\"",
- ctx->peer.name, &ctx->port);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_inet_set_port(peer->sockaddr, (in_port_t) port);
-
- len = ctx->addr.len + 1 + ctx->port.len;
-
- peer->name.len = len;
-
- peer->name.data = ngx_pnalloc(s->connection->pool, len);
- if (peer->name.data == NULL) {
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- len = ctx->addr.len;
-
- ngx_memcpy(peer->name.data, ctx->addr.data, len);
-
- peer->name.data[len++] = ':';
-
- ngx_memcpy(peer->name.data + len, ctx->port.data, ctx->port.len);
-
- ngx_destroy_pool(ctx->pool);
- ngx_mail_proxy_init(s, peer);
-
- return;
- }
-
- if (rc == NGX_AGAIN ) {
- return;
- }
-
- /* rc == NGX_ERROR */
-
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "auth http server %V sent invalid header in response",
- ctx->peer.name);
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
-
- return;
- }
-}
-
-
-static void
-ngx_mail_auth_sleep_handler(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail auth sleep handler");
-
- c = rev->data;
- s = c->data;
-
- if (rev->timedout) {
-
- rev->timedout = 0;
-
- if (s->auth_wait) {
- s->auth_wait = 0;
- ngx_mail_auth_http_init(s);
- return;
- }
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- rev->handler = cscf->protocol->auth_state;
-
- s->mail_state = 0;
- s->auth_method = NGX_MAIL_AUTH_PLAIN;
-
- c->log->action = "in auth state";
-
- ngx_mail_send(c->write);
-
- if (c->destroyed) {
- return;
- }
-
- ngx_add_timer(rev, cscf->timeout);
-
- if (rev->ready) {
- rev->handler(rev);
- return;
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- return;
- }
-
- if (rev->active) {
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
- }
-}
-
-
-static ngx_int_t
-ngx_mail_auth_http_parse_header_line(ngx_mail_session_t *s,
- ngx_mail_auth_http_ctx_t *ctx)
-{
- u_char c, ch, *p;
- enum {
- sw_start = 0,
- sw_name,
- sw_space_before_value,
- sw_value,
- sw_space_after_value,
- sw_almost_done,
- sw_header_almost_done
- } state;
-
- state = ctx->state;
-
- for (p = ctx->response->pos; p < ctx->response->last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* first char */
- case sw_start:
-
- switch (ch) {
- case CR:
- ctx->header_end = p;
- state = sw_header_almost_done;
- break;
- case LF:
- ctx->header_end = p;
- goto header_done;
- default:
- state = sw_name;
- ctx->header_name_start = p;
-
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'z') {
- break;
- }
-
- if (ch >= '0' && ch <= '9') {
- break;
- }
-
- return NGX_ERROR;
- }
- break;
-
- /* header name */
- case sw_name:
- c = (u_char) (ch | 0x20);
- if (c >= 'a' && c <= 'z') {
- break;
- }
-
- if (ch == ':') {
- ctx->header_name_end = p;
- state = sw_space_before_value;
- break;
- }
-
- if (ch == '-') {
- break;
- }
-
- if (ch >= '0' && ch <= '9') {
- break;
- }
-
- if (ch == CR) {
- ctx->header_name_end = p;
- ctx->header_start = p;
- ctx->header_end = p;
- state = sw_almost_done;
- break;
- }
-
- if (ch == LF) {
- ctx->header_name_end = p;
- ctx->header_start = p;
- ctx->header_end = p;
- goto done;
- }
-
- return NGX_ERROR;
-
- /* space* before header value */
- case sw_space_before_value:
- switch (ch) {
- case ' ':
- break;
- case CR:
- ctx->header_start = p;
- ctx->header_end = p;
- state = sw_almost_done;
- break;
- case LF:
- ctx->header_start = p;
- ctx->header_end = p;
- goto done;
- default:
- ctx->header_start = p;
- state = sw_value;
- break;
- }
- break;
-
- /* header value */
- case sw_value:
- switch (ch) {
- case ' ':
- ctx->header_end = p;
- state = sw_space_after_value;
- break;
- case CR:
- ctx->header_end = p;
- state = sw_almost_done;
- break;
- case LF:
- ctx->header_end = p;
- goto done;
- }
- break;
-
- /* space* before end of header line */
- case sw_space_after_value:
- switch (ch) {
- case ' ':
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- default:
- state = sw_value;
- break;
- }
- break;
-
- /* end of header line */
- case sw_almost_done:
- switch (ch) {
- case LF:
- goto done;
- default:
- return NGX_ERROR;
- }
-
- /* end of header */
- case sw_header_almost_done:
- switch (ch) {
- case LF:
- goto header_done;
- default:
- return NGX_ERROR;
- }
- }
- }
-
- ctx->response->pos = p;
- ctx->state = state;
-
- return NGX_AGAIN;
-
-done:
-
- ctx->response->pos = p + 1;
- ctx->state = sw_start;
-
- return NGX_OK;
-
-header_done:
-
- ctx->response->pos = p + 1;
- ctx->state = sw_start;
-
- return NGX_DONE;
-}
-
-
-static void
-ngx_mail_auth_http_block_read(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_auth_http_ctx_t *ctx;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail auth http block read");
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- c = rev->data;
- s = c->data;
-
- ctx = ngx_mail_get_module_ctx(s, ngx_mail_auth_http_module);
-
- ngx_close_connection(ctx->peer.connection);
- ngx_destroy_pool(ctx->pool);
- ngx_mail_session_internal_server_error(s);
- }
-}
-
-
-static void
-ngx_mail_auth_http_dummy_handler(ngx_event_t *ev)
-{
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, ev->log, 0,
- "mail auth http dummy handler");
-}
-
-
-static ngx_buf_t *
-ngx_mail_auth_http_create_request(ngx_mail_session_t *s, ngx_pool_t *pool,
- ngx_mail_auth_http_conf_t *ahcf)
-{
- size_t len;
- ngx_buf_t *b;
- ngx_str_t login, passwd;
- ngx_connection_t *c;
-#if (NGX_MAIL_SSL)
- ngx_str_t protocol, cipher, verify, subject, issuer,
- serial, fingerprint, raw_cert, cert;
- ngx_mail_ssl_conf_t *sslcf;
-#endif
- ngx_mail_core_srv_conf_t *cscf;
-
- if (ngx_mail_auth_http_escape(pool, &s->login, &login) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_mail_auth_http_escape(pool, &s->passwd, &passwd) != NGX_OK) {
- return NULL;
- }
-
- c = s->connection;
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl) {
-
- if (ngx_ssl_get_protocol(c, pool, &protocol) != NGX_OK) {
- return NULL;
- }
-
- protocol.len = ngx_strlen(protocol.data);
-
- if (ngx_ssl_get_cipher_name(c, pool, &cipher) != NGX_OK) {
- return NULL;
- }
-
- cipher.len = ngx_strlen(cipher.data);
-
- } else {
- ngx_str_null(&protocol);
- ngx_str_null(&cipher);
- }
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (c->ssl && sslcf->verify) {
-
- /* certificate details */
-
- if (ngx_ssl_get_client_verify(c, pool, &verify) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_ssl_get_subject_dn(c, pool, &subject) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_ssl_get_issuer_dn(c, pool, &issuer) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_ssl_get_serial_number(c, pool, &serial) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_ssl_get_fingerprint(c, pool, &fingerprint) != NGX_OK) {
- return NULL;
- }
-
- if (ahcf->pass_client_cert) {
-
- /* certificate itself, if configured */
-
- if (ngx_ssl_get_raw_certificate(c, pool, &raw_cert) != NGX_OK) {
- return NULL;
- }
-
- if (ngx_mail_auth_http_escape(pool, &raw_cert, &cert) != NGX_OK) {
- return NULL;
- }
-
- } else {
- ngx_str_null(&cert);
- }
-
- } else {
- ngx_str_null(&verify);
- ngx_str_null(&subject);
- ngx_str_null(&issuer);
- ngx_str_null(&serial);
- ngx_str_null(&fingerprint);
- ngx_str_null(&cert);
- }
-
-#endif
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- len = sizeof("GET ") - 1 + ahcf->uri.len + sizeof(" HTTP/1.0" CRLF) - 1
- + sizeof("Host: ") - 1 + ahcf->host_header.len + sizeof(CRLF) - 1
- + sizeof("Auth-Method: ") - 1
- + ngx_mail_auth_http_method[s->auth_method].len
- + sizeof(CRLF) - 1
- + sizeof("Auth-User: ") - 1 + login.len + sizeof(CRLF) - 1
- + sizeof("Auth-Pass: ") - 1 + passwd.len + sizeof(CRLF) - 1
- + sizeof("Auth-Salt: ") - 1 + s->salt.len
- + sizeof("Auth-Protocol: ") - 1 + cscf->protocol->name.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-Login-Attempt: ") - 1 + NGX_INT_T_LEN
- + sizeof(CRLF) - 1
- + sizeof("Client-IP: ") - 1 + s->connection->addr_text.len
- + sizeof(CRLF) - 1
- + sizeof("Client-Host: ") - 1 + s->host.len + sizeof(CRLF) - 1
- + ahcf->header.len
- + sizeof(CRLF) - 1;
-
- if (c->proxy_protocol) {
- len += sizeof("Proxy-Protocol-Addr: ") - 1
- + c->proxy_protocol->src_addr.len + sizeof(CRLF) - 1
- + sizeof("Proxy-Protocol-Port: ") - 1
- + sizeof("65535") - 1 + sizeof(CRLF) - 1
- + sizeof("Proxy-Protocol-Server-Addr: ") - 1
- + c->proxy_protocol->dst_addr.len + sizeof(CRLF) - 1
- + sizeof("Proxy-Protocol-Server-Port: ") - 1
- + sizeof("65535") - 1 + sizeof(CRLF) - 1;
- }
-
- if (s->auth_method == NGX_MAIL_AUTH_NONE) {
- len += sizeof("Auth-SMTP-Helo: ") - 1 + s->smtp_helo.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SMTP-From: ") - 1 + s->smtp_from.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SMTP-To: ") - 1 + s->smtp_to.len
- + sizeof(CRLF) - 1;
- }
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl) {
- len += sizeof("Auth-SSL: on" CRLF) - 1
- + sizeof("Auth-SSL-Protocol: ") - 1 + protocol.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Cipher: ") - 1 + cipher.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Verify: ") - 1 + verify.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Subject: ") - 1 + subject.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Issuer: ") - 1 + issuer.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Serial: ") - 1 + serial.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Fingerprint: ") - 1 + fingerprint.len
- + sizeof(CRLF) - 1
- + sizeof("Auth-SSL-Cert: ") - 1 + cert.len
- + sizeof(CRLF) - 1;
- }
-
-#endif
-
- b = ngx_create_temp_buf(pool, len);
- if (b == NULL) {
- return NULL;
- }
-
- b->last = ngx_cpymem(b->last, "GET ", sizeof("GET ") - 1);
- b->last = ngx_copy(b->last, ahcf->uri.data, ahcf->uri.len);
- b->last = ngx_cpymem(b->last, " HTTP/1.0" CRLF,
- sizeof(" HTTP/1.0" CRLF) - 1);
-
- b->last = ngx_cpymem(b->last, "Host: ", sizeof("Host: ") - 1);
- b->last = ngx_copy(b->last, ahcf->host_header.data,
- ahcf->host_header.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_cpymem(b->last, "Auth-Method: ",
- sizeof("Auth-Method: ") - 1);
- b->last = ngx_cpymem(b->last,
- ngx_mail_auth_http_method[s->auth_method].data,
- ngx_mail_auth_http_method[s->auth_method].len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_cpymem(b->last, "Auth-User: ", sizeof("Auth-User: ") - 1);
- b->last = ngx_copy(b->last, login.data, login.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_cpymem(b->last, "Auth-Pass: ", sizeof("Auth-Pass: ") - 1);
- b->last = ngx_copy(b->last, passwd.data, passwd.len);
- *b->last++ = CR; *b->last++ = LF;
-
- if ((s->auth_method == NGX_MAIL_AUTH_APOP
- || s->auth_method == NGX_MAIL_AUTH_CRAM_MD5)
- && s->salt.len)
- {
- b->last = ngx_cpymem(b->last, "Auth-Salt: ", sizeof("Auth-Salt: ") - 1);
- b->last = ngx_copy(b->last, s->salt.data, s->salt.len);
-
- ngx_str_null(&s->passwd);
- }
-
- b->last = ngx_cpymem(b->last, "Auth-Protocol: ",
- sizeof("Auth-Protocol: ") - 1);
- b->last = ngx_cpymem(b->last, cscf->protocol->name.data,
- cscf->protocol->name.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_sprintf(b->last, "Auth-Login-Attempt: %ui" CRLF,
- s->login_attempt);
-
- b->last = ngx_cpymem(b->last, "Client-IP: ", sizeof("Client-IP: ") - 1);
- b->last = ngx_copy(b->last, s->connection->addr_text.data,
- s->connection->addr_text.len);
- *b->last++ = CR; *b->last++ = LF;
-
- if (s->host.len) {
- b->last = ngx_cpymem(b->last, "Client-Host: ",
- sizeof("Client-Host: ") - 1);
- b->last = ngx_copy(b->last, s->host.data, s->host.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (c->proxy_protocol) {
- b->last = ngx_cpymem(b->last, "Proxy-Protocol-Addr: ",
- sizeof("Proxy-Protocol-Addr: ") - 1);
- b->last = ngx_copy(b->last, c->proxy_protocol->src_addr.data,
- c->proxy_protocol->src_addr.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_sprintf(b->last, "Proxy-Protocol-Port: %d" CRLF,
- c->proxy_protocol->src_port);
-
- b->last = ngx_cpymem(b->last, "Proxy-Protocol-Server-Addr: ",
- sizeof("Proxy-Protocol-Server-Addr: ") - 1);
- b->last = ngx_copy(b->last, c->proxy_protocol->dst_addr.data,
- c->proxy_protocol->dst_addr.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_sprintf(b->last, "Proxy-Protocol-Server-Port: %d" CRLF,
- c->proxy_protocol->dst_port);
- }
-
- if (s->auth_method == NGX_MAIL_AUTH_NONE) {
-
- /* HELO, MAIL FROM, and RCPT TO can't contain CRLF, no need to escape */
-
- b->last = ngx_cpymem(b->last, "Auth-SMTP-Helo: ",
- sizeof("Auth-SMTP-Helo: ") - 1);
- b->last = ngx_copy(b->last, s->smtp_helo.data, s->smtp_helo.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_cpymem(b->last, "Auth-SMTP-From: ",
- sizeof("Auth-SMTP-From: ") - 1);
- b->last = ngx_copy(b->last, s->smtp_from.data, s->smtp_from.len);
- *b->last++ = CR; *b->last++ = LF;
-
- b->last = ngx_cpymem(b->last, "Auth-SMTP-To: ",
- sizeof("Auth-SMTP-To: ") - 1);
- b->last = ngx_copy(b->last, s->smtp_to.data, s->smtp_to.len);
- *b->last++ = CR; *b->last++ = LF;
-
- }
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl) {
- b->last = ngx_cpymem(b->last, "Auth-SSL: on" CRLF,
- sizeof("Auth-SSL: on" CRLF) - 1);
-
- if (protocol.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Protocol: ",
- sizeof("Auth-SSL-Protocol: ") - 1);
- b->last = ngx_copy(b->last, protocol.data, protocol.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (cipher.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Cipher: ",
- sizeof("Auth-SSL-Cipher: ") - 1);
- b->last = ngx_copy(b->last, cipher.data, cipher.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (verify.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Verify: ",
- sizeof("Auth-SSL-Verify: ") - 1);
- b->last = ngx_copy(b->last, verify.data, verify.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (subject.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Subject: ",
- sizeof("Auth-SSL-Subject: ") - 1);
- b->last = ngx_copy(b->last, subject.data, subject.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (issuer.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Issuer: ",
- sizeof("Auth-SSL-Issuer: ") - 1);
- b->last = ngx_copy(b->last, issuer.data, issuer.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (serial.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Serial: ",
- sizeof("Auth-SSL-Serial: ") - 1);
- b->last = ngx_copy(b->last, serial.data, serial.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (fingerprint.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Fingerprint: ",
- sizeof("Auth-SSL-Fingerprint: ") - 1);
- b->last = ngx_copy(b->last, fingerprint.data, fingerprint.len);
- *b->last++ = CR; *b->last++ = LF;
- }
-
- if (cert.len) {
- b->last = ngx_cpymem(b->last, "Auth-SSL-Cert: ",
- sizeof("Auth-SSL-Cert: ") - 1);
- b->last = ngx_copy(b->last, cert.data, cert.len);
- *b->last++ = CR; *b->last++ = LF;
- }
- }
-
-#endif
-
- if (ahcf->header.len) {
- b->last = ngx_copy(b->last, ahcf->header.data, ahcf->header.len);
- }
-
- /* add "\r\n" at the header end */
- *b->last++ = CR; *b->last++ = LF;
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail auth http header:%N\"%*s\"",
- (size_t) (b->last - b->pos), b->pos);
-#endif
-
- return b;
-}
-
-
-static ngx_int_t
-ngx_mail_auth_http_escape(ngx_pool_t *pool, ngx_str_t *text, ngx_str_t *escaped)
-{
- u_char *p;
- uintptr_t n;
-
- n = ngx_escape_uri(NULL, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
-
- if (n == 0) {
- *escaped = *text;
- return NGX_OK;
- }
-
- escaped->len = text->len + n * 2;
-
- p = ngx_pnalloc(pool, escaped->len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- (void) ngx_escape_uri(p, text->data, text->len, NGX_ESCAPE_MAIL_AUTH);
-
- escaped->data = p;
-
- return NGX_OK;
-}
-
-
-static void *
-ngx_mail_auth_http_create_conf(ngx_conf_t *cf)
-{
- ngx_mail_auth_http_conf_t *ahcf;
-
- ahcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_auth_http_conf_t));
- if (ahcf == NULL) {
- return NULL;
- }
-
- ahcf->timeout = NGX_CONF_UNSET_MSEC;
- ahcf->pass_client_cert = NGX_CONF_UNSET;
-
- ahcf->file = cf->conf_file->file.name.data;
- ahcf->line = cf->conf_file->line;
-
- return ahcf;
-}
-
-
-static char *
-ngx_mail_auth_http_merge_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_auth_http_conf_t *prev = parent;
- ngx_mail_auth_http_conf_t *conf = child;
-
- u_char *p;
- size_t len;
- ngx_uint_t i;
- ngx_table_elt_t *header;
-
- if (conf->peer == NULL) {
- conf->peer = prev->peer;
- conf->host_header = prev->host_header;
- conf->uri = prev->uri;
-
- if (conf->peer == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no \"auth_http\" is defined for server in %s:%ui",
- conf->file, conf->line);
-
- return NGX_CONF_ERROR;
- }
- }
-
- ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
-
- ngx_conf_merge_value(conf->pass_client_cert, prev->pass_client_cert, 0);
-
- if (conf->headers == NULL) {
- conf->headers = prev->headers;
- conf->header = prev->header;
- }
-
- if (conf->headers && conf->header.len == 0) {
- len = 0;
- header = conf->headers->elts;
- for (i = 0; i < conf->headers->nelts; i++) {
- len += header[i].key.len + 2 + header[i].value.len + 2;
- }
-
- p = ngx_pnalloc(cf->pool, len);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->header.len = len;
- conf->header.data = p;
-
- for (i = 0; i < conf->headers->nelts; i++) {
- p = ngx_cpymem(p, header[i].key.data, header[i].key.len);
- *p++ = ':'; *p++ = ' ';
- p = ngx_cpymem(p, header[i].value.data, header[i].value.len);
- *p++ = CR; *p++ = LF;
- }
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_auth_http(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_auth_http_conf_t *ahcf = conf;
-
- ngx_str_t *value;
- ngx_url_t u;
-
- value = cf->args->elts;
-
- ngx_memzero(&u, sizeof(ngx_url_t));
-
- u.url = value[1];
- u.default_port = 80;
- u.uri_part = 1;
-
- if (ngx_strncmp(u.url.data, "http://", 7) == 0) {
- u.url.len -= 7;
- u.url.data += 7;
- }
-
- if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
- if (u.err) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "%s in auth_http \"%V\"", u.err, &u.url);
- }
-
- return NGX_CONF_ERROR;
- }
-
- ahcf->peer = u.addrs;
-
- if (u.family != AF_UNIX) {
- ahcf->host_header = u.host;
-
- } else {
- ngx_str_set(&ahcf->host_header, "localhost");
- }
-
- ahcf->uri = u.uri;
-
- if (ahcf->uri.len == 0) {
- ngx_str_set(&ahcf->uri, "/");
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_auth_http_header(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_auth_http_conf_t *ahcf = conf;
-
- ngx_str_t *value;
- ngx_table_elt_t *header;
-
- if (ahcf->headers == NULL) {
- ahcf->headers = ngx_array_create(cf->pool, 1, sizeof(ngx_table_elt_t));
- if (ahcf->headers == NULL) {
- return NGX_CONF_ERROR;
- }
- }
-
- header = ngx_array_push(ahcf->headers);
- if (header == NULL) {
- return NGX_CONF_ERROR;
- }
-
- value = cf->args->elts;
-
- header->key = value[1];
- header->value = value[2];
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_core_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_core_module.c
deleted file mode 100644
index 5532ceeb1b..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_core_module.c
+++ /dev/null
@@ -1,728 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-static void *ngx_mail_core_create_main_conf(ngx_conf_t *cf);
-static void *ngx_mail_core_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-static char *ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-
-
-static ngx_command_t ngx_mail_core_commands[] = {
-
- { ngx_string("server"),
- NGX_MAIL_MAIN_CONF|NGX_CONF_BLOCK|NGX_CONF_NOARGS,
- ngx_mail_core_server,
- 0,
- 0,
- NULL },
-
- { ngx_string("listen"),
- NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_core_listen,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("protocol"),
- NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_mail_core_protocol,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("timeout"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_core_srv_conf_t, timeout),
- NULL },
-
- { ngx_string("server_name"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_core_srv_conf_t, server_name),
- NULL },
-
- { ngx_string("error_log"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_core_error_log,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("resolver"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_core_resolver,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("resolver_timeout"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_core_srv_conf_t, resolver_timeout),
- NULL },
-
- { ngx_string("max_errors"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_core_srv_conf_t, max_errors),
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_core_module_ctx = {
- NULL, /* protocol */
-
- ngx_mail_core_create_main_conf, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_core_create_srv_conf, /* create server configuration */
- ngx_mail_core_merge_srv_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_core_module = {
- NGX_MODULE_V1,
- &ngx_mail_core_module_ctx, /* module context */
- ngx_mail_core_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static void *
-ngx_mail_core_create_main_conf(ngx_conf_t *cf)
-{
- ngx_mail_core_main_conf_t *cmcf;
-
- cmcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_main_conf_t));
- if (cmcf == NULL) {
- return NULL;
- }
-
- if (ngx_array_init(&cmcf->servers, cf->pool, 4,
- sizeof(ngx_mail_core_srv_conf_t *))
- != NGX_OK)
- {
- return NULL;
- }
-
- if (ngx_array_init(&cmcf->listen, cf->pool, 4, sizeof(ngx_mail_listen_t))
- != NGX_OK)
- {
- return NULL;
- }
-
- return cmcf;
-}
-
-
-static void *
-ngx_mail_core_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_mail_core_srv_conf_t *cscf;
-
- cscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_core_srv_conf_t));
- if (cscf == NULL) {
- return NULL;
- }
-
- /*
- * set by ngx_pcalloc():
- *
- * cscf->protocol = NULL;
- * cscf->error_log = NULL;
- */
-
- cscf->timeout = NGX_CONF_UNSET_MSEC;
- cscf->resolver_timeout = NGX_CONF_UNSET_MSEC;
-
- cscf->max_errors = NGX_CONF_UNSET_UINT;
-
- cscf->resolver = NGX_CONF_UNSET_PTR;
-
- cscf->file_name = cf->conf_file->file.name.data;
- cscf->line = cf->conf_file->line;
-
- return cscf;
-}
-
-
-static char *
-ngx_mail_core_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_core_srv_conf_t *prev = parent;
- ngx_mail_core_srv_conf_t *conf = child;
-
- ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
- ngx_conf_merge_msec_value(conf->resolver_timeout, prev->resolver_timeout,
- 30000);
-
- ngx_conf_merge_uint_value(conf->max_errors, prev->max_errors, 5);
-
- ngx_conf_merge_str_value(conf->server_name, prev->server_name, "");
-
- if (conf->server_name.len == 0) {
- conf->server_name = cf->cycle->hostname;
- }
-
- if (conf->protocol == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "unknown mail protocol for server in %s:%ui",
- conf->file_name, conf->line);
- return NGX_CONF_ERROR;
- }
-
- if (conf->error_log == NULL) {
- if (prev->error_log) {
- conf->error_log = prev->error_log;
- } else {
- conf->error_log = &cf->cycle->new_log;
- }
- }
-
- ngx_conf_merge_ptr_value(conf->resolver, prev->resolver, NULL);
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_core_server(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- char *rv;
- void *mconf;
- ngx_uint_t m;
- ngx_conf_t pcf;
- ngx_mail_module_t *module;
- ngx_mail_conf_ctx_t *ctx, *mail_ctx;
- ngx_mail_core_srv_conf_t *cscf, **cscfp;
- ngx_mail_core_main_conf_t *cmcf;
-
- ctx = ngx_pcalloc(cf->pool, sizeof(ngx_mail_conf_ctx_t));
- if (ctx == NULL) {
- return NGX_CONF_ERROR;
- }
-
- mail_ctx = cf->ctx;
- ctx->main_conf = mail_ctx->main_conf;
-
- /* the server{}'s srv_conf */
-
- ctx->srv_conf = ngx_pcalloc(cf->pool, sizeof(void *) * ngx_mail_max_module);
- if (ctx->srv_conf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
-
- if (module->create_srv_conf) {
- mconf = module->create_srv_conf(cf);
- if (mconf == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ctx->srv_conf[cf->cycle->modules[m]->ctx_index] = mconf;
- }
- }
-
- /* the server configuration context */
-
- cscf = ctx->srv_conf[ngx_mail_core_module.ctx_index];
- cscf->ctx = ctx;
-
- cmcf = ctx->main_conf[ngx_mail_core_module.ctx_index];
-
- cscfp = ngx_array_push(&cmcf->servers);
- if (cscfp == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *cscfp = cscf;
-
-
- /* parse inside server{} */
-
- pcf = *cf;
- cf->ctx = ctx;
- cf->cmd_type = NGX_MAIL_SRV_CONF;
-
- rv = ngx_conf_parse(cf, NULL);
-
- *cf = pcf;
-
- if (rv == NGX_CONF_OK && !cscf->listen) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no \"listen\" is defined for server in %s:%ui",
- cscf->file_name, cscf->line);
- return NGX_CONF_ERROR;
- }
-
- return rv;
-}
-
-
-static char *
-ngx_mail_core_listen(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_core_srv_conf_t *cscf = conf;
-
- ngx_str_t *value, size;
- ngx_url_t u;
- ngx_uint_t i, n, m;
- ngx_mail_listen_t *ls, *als, *nls;
- ngx_mail_module_t *module;
- ngx_mail_core_main_conf_t *cmcf;
-
- cscf->listen = 1;
-
- value = cf->args->elts;
-
- ngx_memzero(&u, sizeof(ngx_url_t));
-
- u.url = value[1];
- u.listen = 1;
-
- if (ngx_parse_url(cf->pool, &u) != NGX_OK) {
- if (u.err) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "%s in \"%V\" of the \"listen\" directive",
- u.err, &u.url);
- }
-
- return NGX_CONF_ERROR;
- }
-
- cmcf = ngx_mail_conf_get_module_main_conf(cf, ngx_mail_core_module);
-
- ls = ngx_array_push(&cmcf->listen);
- if (ls == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memzero(ls, sizeof(ngx_mail_listen_t));
-
- ls->backlog = NGX_LISTEN_BACKLOG;
- ls->rcvbuf = -1;
- ls->sndbuf = -1;
- ls->ctx = cf->ctx;
-
-#if (NGX_HAVE_INET6)
- ls->ipv6only = 1;
-#endif
-
- if (cscf->protocol == NULL) {
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
-
- if (module->protocol == NULL) {
- continue;
- }
-
- for (i = 0; module->protocol->port[i]; i++) {
- if (module->protocol->port[i] == u.port) {
- cscf->protocol = module->protocol;
- break;
- }
- }
- }
- }
-
- for (i = 2; i < cf->args->nelts; i++) {
-
- if (ngx_strcmp(value[i].data, "bind") == 0) {
- ls->bind = 1;
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "backlog=", 8) == 0) {
- ls->backlog = ngx_atoi(value[i].data + 8, value[i].len - 8);
- ls->bind = 1;
-
- if (ls->backlog == NGX_ERROR || ls->backlog == 0) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid backlog \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "rcvbuf=", 7) == 0) {
- size.len = value[i].len - 7;
- size.data = value[i].data + 7;
-
- ls->rcvbuf = ngx_parse_size(&size);
- ls->bind = 1;
-
- if (ls->rcvbuf == NGX_ERROR) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid rcvbuf \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "sndbuf=", 7) == 0) {
- size.len = value[i].len - 7;
- size.data = value[i].data + 7;
-
- ls->sndbuf = ngx_parse_size(&size);
- ls->bind = 1;
-
- if (ls->sndbuf == NGX_ERROR) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid sndbuf \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- continue;
- }
-
- if (ngx_strncmp(value[i].data, "ipv6only=o", 10) == 0) {
-#if (NGX_HAVE_INET6 && defined IPV6_V6ONLY)
- if (ngx_strcmp(&value[i].data[10], "n") == 0) {
- ls->ipv6only = 1;
-
- } else if (ngx_strcmp(&value[i].data[10], "ff") == 0) {
- ls->ipv6only = 0;
-
- } else {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid ipv6only flags \"%s\"",
- &value[i].data[9]);
- return NGX_CONF_ERROR;
- }
-
- ls->bind = 1;
- continue;
-#else
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "ipv6only is not supported "
- "on this platform");
- return NGX_CONF_ERROR;
-#endif
- }
-
- if (ngx_strcmp(value[i].data, "multipath") == 0) {
-#ifdef IPPROTO_MPTCP
- ls->protocol = IPPROTO_MPTCP;
- ls->bind = 1;
-#else
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "multipath is not supported "
- "on this platform, ignored");
-#endif
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "ssl") == 0) {
-#if (NGX_MAIL_SSL)
- ngx_mail_ssl_conf_t *sslcf;
-
- sslcf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_ssl_module);
-
- sslcf->listen = 1;
- sslcf->file = cf->conf_file->file.name.data;
- sslcf->line = cf->conf_file->line;
-
- ls->ssl = 1;
-
- continue;
-#else
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the \"ssl\" parameter requires "
- "ngx_mail_ssl_module");
- return NGX_CONF_ERROR;
-#endif
- }
-
- if (ngx_strncmp(value[i].data, "so_keepalive=", 13) == 0) {
-
- if (ngx_strcmp(&value[i].data[13], "on") == 0) {
- ls->so_keepalive = 1;
-
- } else if (ngx_strcmp(&value[i].data[13], "off") == 0) {
- ls->so_keepalive = 2;
-
- } else {
-
-#if (NGX_HAVE_KEEPALIVE_TUNABLE)
- u_char *p, *end;
- ngx_str_t s;
-
- end = value[i].data + value[i].len;
- s.data = value[i].data + 13;
-
- p = ngx_strlchr(s.data, end, ':');
- if (p == NULL) {
- p = end;
- }
-
- if (p > s.data) {
- s.len = p - s.data;
-
- ls->tcp_keepidle = ngx_parse_time(&s, 1);
- if (ls->tcp_keepidle == (time_t) NGX_ERROR) {
- goto invalid_so_keepalive;
- }
- }
-
- s.data = (p < end) ? (p + 1) : end;
-
- p = ngx_strlchr(s.data, end, ':');
- if (p == NULL) {
- p = end;
- }
-
- if (p > s.data) {
- s.len = p - s.data;
-
- ls->tcp_keepintvl = ngx_parse_time(&s, 1);
- if (ls->tcp_keepintvl == (time_t) NGX_ERROR) {
- goto invalid_so_keepalive;
- }
- }
-
- s.data = (p < end) ? (p + 1) : end;
-
- if (s.data < end) {
- s.len = end - s.data;
-
- ls->tcp_keepcnt = ngx_atoi(s.data, s.len);
- if (ls->tcp_keepcnt == NGX_ERROR) {
- goto invalid_so_keepalive;
- }
- }
-
- if (ls->tcp_keepidle == 0 && ls->tcp_keepintvl == 0
- && ls->tcp_keepcnt == 0)
- {
- goto invalid_so_keepalive;
- }
-
- ls->so_keepalive = 1;
-
-#else
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "the \"so_keepalive\" parameter accepts "
- "only \"on\" or \"off\" on this platform");
- return NGX_CONF_ERROR;
-
-#endif
- }
-
- ls->bind = 1;
-
- continue;
-
-#if (NGX_HAVE_KEEPALIVE_TUNABLE)
- invalid_so_keepalive:
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid so_keepalive value: \"%s\"",
- &value[i].data[13]);
- return NGX_CONF_ERROR;
-#endif
- }
-
- if (ngx_strcmp(value[i].data, "proxy_protocol") == 0) {
- ls->proxy_protocol = 1;
- continue;
- }
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid parameter \"%V\"", &value[i]);
- return NGX_CONF_ERROR;
- }
-
- for (n = 0; n < u.naddrs; n++) {
-
- for (i = 0; i < n; i++) {
- if (ngx_cmp_sockaddr(u.addrs[n].sockaddr, u.addrs[n].socklen,
- u.addrs[i].sockaddr, u.addrs[i].socklen, 1)
- == NGX_OK)
- {
- goto next;
- }
- }
-
- if (n != 0) {
- nls = ngx_array_push(&cmcf->listen);
- if (nls == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *nls = *ls;
-
- } else {
- nls = ls;
- }
-
- nls->sockaddr = u.addrs[n].sockaddr;
- nls->socklen = u.addrs[n].socklen;
- nls->addr_text = u.addrs[n].name;
- nls->wildcard = ngx_inet_wildcard(nls->sockaddr);
-
- als = cmcf->listen.elts;
-
- for (i = 0; i < cmcf->listen.nelts - 1; i++) {
-
- if (ngx_cmp_sockaddr(als[i].sockaddr, als[i].socklen,
- nls->sockaddr, nls->socklen, 1)
- != NGX_OK)
- {
- continue;
- }
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "duplicate \"%V\" address and port pair",
- &nls->addr_text);
- return NGX_CONF_ERROR;
- }
-
- next:
- continue;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_core_protocol(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_core_srv_conf_t *cscf = conf;
-
- ngx_str_t *value;
- ngx_uint_t m;
- ngx_mail_module_t *module;
-
- value = cf->args->elts;
-
- for (m = 0; cf->cycle->modules[m]; m++) {
- if (cf->cycle->modules[m]->type != NGX_MAIL_MODULE) {
- continue;
- }
-
- module = cf->cycle->modules[m]->ctx;
-
- if (module->protocol
- && ngx_strcmp(module->protocol->name.data, value[1].data) == 0)
- {
- cscf->protocol = module->protocol;
-
- return NGX_CONF_OK;
- }
- }
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "unknown protocol \"%V\"", &value[1]);
- return NGX_CONF_ERROR;
-}
-
-
-static char *
-ngx_mail_core_error_log(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_core_srv_conf_t *cscf = conf;
-
- return ngx_log_set_log(cf, &cscf->error_log);
-}
-
-
-static char *
-ngx_mail_core_resolver(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_core_srv_conf_t *cscf = conf;
-
- ngx_str_t *value;
-
- value = cf->args->elts;
-
- if (cscf->resolver != NGX_CONF_UNSET_PTR) {
- return "is duplicate";
- }
-
- if (ngx_strcmp(value[1].data, "off") == 0) {
- cscf->resolver = NULL;
- return NGX_CONF_OK;
- }
-
- cscf->resolver = ngx_resolver_create(cf, &value[1], cf->args->nelts - 1);
- if (cscf->resolver == NULL) {
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-char *
-ngx_mail_capabilities(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- char *p = conf;
-
- ngx_str_t *c, *value;
- ngx_uint_t i;
- ngx_array_t *a;
-
- a = (ngx_array_t *) (p + cmd->offset);
-
- value = cf->args->elts;
-
- for (i = 1; i < cf->args->nelts; i++) {
- c = ngx_array_push(a);
- if (c == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *c = value[i];
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_handler.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_handler.c
deleted file mode 100644
index a88e6c2873..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_handler.c
+++ /dev/null
@@ -1,1022 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-
-
-static void ngx_mail_proxy_protocol_handler(ngx_event_t *rev);
-static void ngx_mail_init_session_handler(ngx_event_t *rev);
-static void ngx_mail_init_session(ngx_connection_t *c);
-
-#if (NGX_MAIL_SSL)
-static void ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c);
-static void ngx_mail_ssl_handshake_handler(ngx_connection_t *c);
-static ngx_int_t ngx_mail_verify_cert(ngx_mail_session_t *s,
- ngx_connection_t *c);
-#endif
-
-
-void
-ngx_mail_init_connection(ngx_connection_t *c)
-{
- size_t len;
- ngx_uint_t i;
- ngx_event_t *rev;
- ngx_mail_port_t *port;
- struct sockaddr *sa;
- struct sockaddr_in *sin;
- ngx_mail_log_ctx_t *ctx;
- ngx_mail_in_addr_t *addr;
- ngx_mail_session_t *s;
- ngx_mail_addr_conf_t *addr_conf;
- ngx_mail_core_srv_conf_t *cscf;
- u_char text[NGX_SOCKADDR_STRLEN];
-#if (NGX_HAVE_INET6)
- struct sockaddr_in6 *sin6;
- ngx_mail_in6_addr_t *addr6;
-#endif
-
-
- /* find the server configuration for the address:port */
-
- port = c->listening->servers;
-
- if (port->naddrs > 1) {
-
- /*
- * There are several addresses on this port and one of them
- * is the "*:port" wildcard so getsockname() is needed to determine
- * the server address.
- *
- * AcceptEx() already gave this address.
- */
-
- if (ngx_connection_local_sockaddr(c, NULL, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- sa = c->local_sockaddr;
-
- switch (sa->sa_family) {
-
-#if (NGX_HAVE_INET6)
- case AF_INET6:
- sin6 = (struct sockaddr_in6 *) sa;
-
- addr6 = port->addrs;
-
- /* the last address is "*" */
-
- for (i = 0; i < port->naddrs - 1; i++) {
- if (ngx_memcmp(&addr6[i].addr6, &sin6->sin6_addr, 16) == 0) {
- break;
- }
- }
-
- addr_conf = &addr6[i].conf;
-
- break;
-#endif
-
- default: /* AF_INET */
- sin = (struct sockaddr_in *) sa;
-
- addr = port->addrs;
-
- /* the last address is "*" */
-
- for (i = 0; i < port->naddrs - 1; i++) {
- if (addr[i].addr == sin->sin_addr.s_addr) {
- break;
- }
- }
-
- addr_conf = &addr[i].conf;
-
- break;
- }
-
- } else {
- switch (c->local_sockaddr->sa_family) {
-
-#if (NGX_HAVE_INET6)
- case AF_INET6:
- addr6 = port->addrs;
- addr_conf = &addr6[0].conf;
- break;
-#endif
-
- default: /* AF_INET */
- addr = port->addrs;
- addr_conf = &addr[0].conf;
- break;
- }
- }
-
- s = ngx_pcalloc(c->pool, sizeof(ngx_mail_session_t));
- if (s == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
-
- s->signature = NGX_MAIL_MODULE;
-
- s->main_conf = addr_conf->ctx->main_conf;
- s->srv_conf = addr_conf->ctx->srv_conf;
-
-#if (NGX_MAIL_SSL)
- s->ssl = addr_conf->ssl;
-#endif
-
- s->addr_text = &addr_conf->addr_text;
-
- c->data = s;
- s->connection = c;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- ngx_set_connection_log(c, cscf->error_log);
-
- len = ngx_sock_ntop(c->sockaddr, c->socklen, text, NGX_SOCKADDR_STRLEN, 1);
-
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "*%uA client %*s connected to %V",
- c->number, len, text, s->addr_text);
-
- ctx = ngx_palloc(c->pool, sizeof(ngx_mail_log_ctx_t));
- if (ctx == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
-
- ctx->client = &c->addr_text;
- ctx->session = s;
-
- c->log->connection = c->number;
- c->log->handler = ngx_mail_log_error;
- c->log->data = ctx;
- c->log->action = "sending client greeting line";
-
- c->log_error = NGX_ERROR_INFO;
-
- rev = c->read;
- rev->handler = ngx_mail_init_session_handler;
-
- if (addr_conf->proxy_protocol) {
- c->log->action = "reading PROXY protocol";
-
- rev->handler = ngx_mail_proxy_protocol_handler;
-
- if (!rev->ready) {
- ngx_add_timer(rev, cscf->timeout);
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- return;
- }
- }
-
- if (ngx_use_accept_mutex) {
- ngx_post_event(rev, &ngx_posted_events);
- return;
- }
-
- rev->handler(rev);
-}
-
-
-static void
-ngx_mail_proxy_protocol_handler(ngx_event_t *rev)
-{
- u_char *p, buf[NGX_PROXY_PROTOCOL_MAX_HEADER];
- size_t size;
- ssize_t n;
- ngx_err_t err;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail PROXY protocol handler");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- n = recv(c->fd, (char *) buf, sizeof(buf), MSG_PEEK);
-
- err = ngx_socket_errno;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "recv(): %z", n);
-
- if (n == -1) {
- if (err == NGX_EAGAIN) {
- rev->ready = 0;
-
- if (!rev->timer_set) {
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
- ngx_add_timer(rev, cscf->timeout);
- }
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- return;
- }
-
- ngx_connection_error(c, err, "recv() failed");
-
- ngx_mail_close_connection(c);
- return;
- }
-
- p = ngx_proxy_protocol_read(c, buf, buf + n);
-
- if (p == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
-
- size = p - buf;
-
- if (c->recv(c, buf, size) != (ssize_t) size) {
- ngx_mail_close_connection(c);
- return;
- }
-
- if (ngx_mail_realip_handler(s) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- ngx_mail_init_session_handler(rev);
-}
-
-
-static void
-ngx_mail_init_session_handler(ngx_event_t *rev)
-{
- ngx_connection_t *c;
-
- c = rev->data;
-
-#if (NGX_MAIL_SSL)
- {
- ngx_mail_session_t *s;
- ngx_mail_ssl_conf_t *sslcf;
-
- s = c->data;
-
- if (s->ssl) {
- c->log->action = "SSL handshaking";
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- ngx_mail_ssl_init_connection(&sslcf->ssl, c);
- return;
- }
-
- }
-#endif
-
- ngx_mail_init_session(c);
-}
-
-
-#if (NGX_MAIL_SSL)
-
-void
-ngx_mail_starttls_handler(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_ssl_conf_t *sslcf;
-
- c = rev->data;
- s = c->data;
- s->starttls = 1;
-
- c->log->action = "in starttls state";
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- ngx_mail_ssl_init_connection(&sslcf->ssl, c);
-}
-
-
-static void
-ngx_mail_ssl_init_connection(ngx_ssl_t *ssl, ngx_connection_t *c)
-{
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- if (ngx_ssl_create_connection(ssl, c, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- if (ngx_ssl_handshake(c) == NGX_AGAIN) {
-
- s = c->data;
-
- if (!c->read->timer_set) {
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
- ngx_add_timer(c->read, cscf->timeout);
- }
-
- c->ssl->handler = ngx_mail_ssl_handshake_handler;
-
- return;
- }
-
- ngx_mail_ssl_handshake_handler(c);
-}
-
-
-static void
-ngx_mail_ssl_handshake_handler(ngx_connection_t *c)
-{
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- if (c->ssl->handshaked) {
-
- s = c->data;
-
- if (ngx_mail_verify_cert(s, c) != NGX_OK) {
- return;
- }
-
- if (s->starttls) {
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- c->read->handler = cscf->protocol->init_protocol;
- c->write->handler = ngx_mail_send;
-
- cscf->protocol->init_protocol(c->read);
-
- return;
- }
-
- c->read->ready = 0;
-
- ngx_mail_init_session(c);
- return;
- }
-
- ngx_mail_close_connection(c);
-}
-
-
-static ngx_int_t
-ngx_mail_verify_cert(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- long rc;
- X509 *cert;
- ngx_mail_ssl_conf_t *sslcf;
- ngx_mail_core_srv_conf_t *cscf;
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (!sslcf->verify) {
- return NGX_OK;
- }
-
- rc = SSL_get_verify_result(c->ssl->connection);
-
- if (rc != X509_V_OK
- && (sslcf->verify != 3 || !ngx_ssl_verify_error_optional(rc)))
- {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client SSL certificate verify error: (%l:%s)",
- rc, X509_verify_cert_error_string(rc));
-
- ngx_ssl_remove_cached_session(c->ssl->session_ctx,
- (SSL_get0_session(c->ssl->connection)));
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- s->out = cscf->protocol->cert_error;
- s->quit = 1;
-
- c->write->handler = ngx_mail_send;
-
- ngx_mail_send(s->connection->write);
- return NGX_ERROR;
- }
-
- if (sslcf->verify == 1) {
- cert = SSL_get_peer_certificate(c->ssl->connection);
-
- if (cert == NULL) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent no required SSL certificate");
-
- ngx_ssl_remove_cached_session(c->ssl->session_ctx,
- (SSL_get0_session(c->ssl->connection)));
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- s->out = cscf->protocol->no_cert;
- s->quit = 1;
-
- c->write->handler = ngx_mail_send;
-
- ngx_mail_send(s->connection->write);
- return NGX_ERROR;
- }
-
- X509_free(cert);
- }
-
- return NGX_OK;
-}
-
-#endif
-
-
-static void
-ngx_mail_init_session(ngx_connection_t *c)
-{
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- s = c->data;
-
- c->log->action = "sending client greeting line";
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- s->protocol = cscf->protocol->type;
-
- s->ctx = ngx_pcalloc(c->pool, sizeof(void *) * ngx_mail_max_module);
- if (s->ctx == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- c->write->handler = ngx_mail_send;
-
- cscf->protocol->init_session(s, c);
-}
-
-
-ngx_int_t
-ngx_mail_salt(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_mail_core_srv_conf_t *cscf)
-{
- s->salt.data = ngx_pnalloc(c->pool,
- sizeof(" <18446744073709551616.@>" CRLF) - 1
- + NGX_TIME_T_LEN
- + cscf->server_name.len);
- if (s->salt.data == NULL) {
- return NGX_ERROR;
- }
-
- s->salt.len = ngx_sprintf(s->salt.data, "<%ul.%T@%V>" CRLF,
- ngx_random(), ngx_time(), &cscf->server_name)
- - s->salt.data;
-
- return NGX_OK;
-}
-
-
-#if (NGX_MAIL_SSL)
-
-ngx_int_t
-ngx_mail_starttls_only(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_mail_ssl_conf_t *sslcf;
-
- if (c->ssl) {
- return 0;
- }
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
- return 1;
- }
-
- return 0;
-}
-
-#endif
-
-
-ngx_int_t
-ngx_mail_auth_plain(ngx_mail_session_t *s, ngx_connection_t *c, ngx_uint_t n)
-{
- u_char *p, *pos, *last;
- ngx_str_t *arg, plain;
-
- arg = s->args.elts;
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth plain: \"%V\"", &arg[n]);
-#endif
-
- plain.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
- if (plain.data == NULL) {
- return NGX_ERROR;
- }
-
- if (ngx_decode_base64(&plain, &arg[n]) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid base64 encoding in AUTH PLAIN command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- p = plain.data;
- last = p + plain.len;
-
- while (p < last && *p++) { /* void */ }
-
- if (p == last) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid login in AUTH PLAIN command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- pos = p;
-
- while (p < last && *p) { p++; }
-
- if (p == last) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid password in AUTH PLAIN command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->login.len = p++ - pos;
- s->login.data = pos;
-
- s->passwd.len = last - p;
- s->passwd.data = p;
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth plain: \"%V\" \"%V\"", &s->login, &s->passwd);
-#endif
-
- return NGX_DONE;
-}
-
-
-ngx_int_t
-ngx_mail_auth_login_username(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_uint_t n)
-{
- ngx_str_t *arg, login;
-
- arg = s->args.elts;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth login username: \"%V\"", &arg[n]);
-
- login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
- if (login.data == NULL) {
- return NGX_ERROR;
- }
-
- if (ngx_decode_base64(&login, &arg[n]) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid base64 encoding in AUTH LOGIN command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->login = login;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth login username: \"%V\"", &s->login);
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_mail_auth_login_password(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg, passwd;
-
- arg = s->args.elts;
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth login password: \"%V\"", &arg[0]);
-#endif
-
- passwd.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len));
- if (passwd.data == NULL) {
- return NGX_ERROR;
- }
-
- if (ngx_decode_base64(&passwd, &arg[0]) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid base64 encoding in AUTH LOGIN command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->passwd = passwd;
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth login password: \"%V\"", &s->passwd);
-#endif
-
- return NGX_DONE;
-}
-
-
-ngx_int_t
-ngx_mail_auth_cram_md5_salt(ngx_mail_session_t *s, ngx_connection_t *c,
- char *prefix, size_t len)
-{
- u_char *p;
- ngx_str_t salt;
- ngx_uint_t n;
-
- p = ngx_pnalloc(c->pool, len + ngx_base64_encoded_length(s->salt.len) + 2);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- salt.data = ngx_cpymem(p, prefix, len);
- s->salt.len -= 2;
-
- ngx_encode_base64(&salt, &s->salt);
-
- s->salt.len += 2;
- n = len + salt.len;
- p[n++] = CR; p[n++] = LF;
-
- s->out.len = n;
- s->out.data = p;
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_mail_auth_cram_md5(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- u_char *p, *last;
- ngx_str_t *arg, login;
-
- arg = s->args.elts;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth cram-md5: \"%V\"", &arg[0]);
-
- login.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[0].len));
- if (login.data == NULL) {
- return NGX_ERROR;
- }
-
- if (ngx_decode_base64(&login, &arg[0]) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid base64 encoding in AUTH CRAM-MD5 command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->login = login;
-
- p = s->login.data;
- last = p + s->login.len;
-
- while (p < last) {
- if (*p++ == ' ') {
- s->login.len = p - s->login.data - 1;
- s->passwd.len = last - p;
- s->passwd.data = p;
- break;
- }
- }
-
- if (s->passwd.len != 32) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid CRAM-MD5 hash in AUTH CRAM-MD5 command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth cram-md5: \"%V\" \"%V\"", &s->login, &s->passwd);
-
- s->auth_method = NGX_MAIL_AUTH_CRAM_MD5;
-
- return NGX_DONE;
-}
-
-
-ngx_int_t
-ngx_mail_auth_external(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_uint_t n)
-{
- ngx_str_t *arg, external;
-
- arg = s->args.elts;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth external: \"%V\"", &arg[n]);
-
- external.data = ngx_pnalloc(c->pool, ngx_base64_decoded_length(arg[n].len));
- if (external.data == NULL) {
- return NGX_ERROR;
- }
-
- if (ngx_decode_base64(&external, &arg[n]) != NGX_OK) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent invalid base64 encoding in AUTH EXTERNAL command");
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->login.len = external.len;
- s->login.data = external.data;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "mail auth external: \"%V\"", &s->login);
-
- s->auth_method = NGX_MAIL_AUTH_EXTERNAL;
-
- return NGX_DONE;
-}
-
-
-void
-ngx_mail_send(ngx_event_t *wev)
-{
- ngx_int_t n;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-
- c = wev->data;
- s = c->data;
-
- if (wev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- if (s->out.len == 0) {
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- return;
- }
-
- n = c->send(c, s->out.data, s->out.len);
-
- if (n > 0) {
- s->out.data += n;
- s->out.len -= n;
-
- if (s->out.len != 0) {
- goto again;
- }
-
- if (wev->timer_set) {
- ngx_del_timer(wev);
- }
-
- if (s->quit) {
- ngx_mail_close_connection(c);
- return;
- }
-
- if (s->blocked) {
- c->read->handler(c->read);
- }
-
- return;
- }
-
- if (n == NGX_ERROR) {
- ngx_mail_close_connection(c);
- return;
- }
-
- /* n == NGX_AGAIN */
-
-again:
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- ngx_add_timer(c->write, cscf->timeout);
-
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-}
-
-
-ngx_int_t
-ngx_mail_read_command(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ssize_t n;
- ngx_int_t rc;
- ngx_str_t l;
- ngx_mail_core_srv_conf_t *cscf;
-
- if (s->buffer->last < s->buffer->end) {
-
- n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
-
- if (n == NGX_ERROR || n == 0) {
- ngx_mail_close_connection(c);
- return NGX_ERROR;
- }
-
- if (n > 0) {
- s->buffer->last += n;
- }
-
- if (n == NGX_AGAIN) {
- if (s->buffer->pos == s->buffer->last) {
- return NGX_AGAIN;
- }
- }
- }
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- rc = cscf->protocol->parse_command(s);
-
- if (rc == NGX_AGAIN) {
-
- if (s->buffer->last < s->buffer->end) {
- return rc;
- }
-
- l.len = s->buffer->last - s->buffer->start;
- l.data = s->buffer->start;
-
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent too long command \"%V\"", &l);
-
- s->quit = 1;
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (rc == NGX_MAIL_PARSE_INVALID_COMMAND) {
-
- s->errors++;
-
- if (s->errors >= cscf->max_errors) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0,
- "client sent too many invalid commands");
- s->quit = 1;
- }
-
- return rc;
- }
-
- if (rc == NGX_IMAP_NEXT) {
- return rc;
- }
-
- if (rc == NGX_ERROR) {
- ngx_mail_close_connection(c);
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-void
-ngx_mail_auth(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- s->args.nelts = 0;
-
- if (s->buffer->pos == s->buffer->last) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- }
-
- s->state = 0;
-
- if (c->read->timer_set) {
- ngx_del_timer(c->read);
- }
-
- s->login_attempt++;
-
- ngx_mail_auth_http_init(s);
-}
-
-
-void
-ngx_mail_session_internal_server_error(ngx_mail_session_t *s)
-{
- ngx_mail_core_srv_conf_t *cscf;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- s->out = cscf->protocol->internal_server_error;
- s->quit = 1;
-
- ngx_mail_send(s->connection->write);
-}
-
-
-void
-ngx_mail_close_connection(ngx_connection_t *c)
-{
- ngx_pool_t *pool;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "close mail connection: %d", c->fd);
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl) {
- if (ngx_ssl_shutdown(c) == NGX_AGAIN) {
- c->ssl->handler = ngx_mail_close_connection;
- return;
- }
- }
-
-#endif
-
-#if (NGX_STAT_STUB)
- (void) ngx_atomic_fetch_add(ngx_stat_active, -1);
-#endif
-
- c->destroyed = 1;
-
- pool = c->pool;
-
- ngx_close_connection(c);
-
- ngx_destroy_pool(pool);
-}
-
-
-u_char *
-ngx_mail_log_error(ngx_log_t *log, u_char *buf, size_t len)
-{
- u_char *p;
- ngx_mail_session_t *s;
- ngx_mail_log_ctx_t *ctx;
-
- if (log->action) {
- p = ngx_snprintf(buf, len, " while %s", log->action);
- len -= p - buf;
- buf = p;
- }
-
- ctx = log->data;
-
- p = ngx_snprintf(buf, len, ", client: %V", ctx->client);
- len -= p - buf;
- buf = p;
-
- s = ctx->session;
-
- if (s == NULL) {
- return p;
- }
-
- p = ngx_snprintf(buf, len, "%s, server: %V",
- s->starttls ? " using starttls" : "",
- s->addr_text);
- len -= p - buf;
- buf = p;
-
- if (s->login.len) {
- p = ngx_snprintf(buf, len, ", login: \"%V\"", &s->login);
- len -= p - buf;
- buf = p;
- }
-
- if (s->proxy == NULL) {
- return p;
- }
-
- p = ngx_snprintf(buf, len, ", upstream: %V", s->proxy->upstream.name);
-
- return p;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_handler.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_handler.c
deleted file mode 100644
index 291e87a4de..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_handler.c
+++ /dev/null
@@ -1,477 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static ngx_int_t ngx_mail_imap_login(ngx_mail_session_t *s,
- ngx_connection_t *c);
-static ngx_int_t ngx_mail_imap_authenticate(ngx_mail_session_t *s,
- ngx_connection_t *c);
-static ngx_int_t ngx_mail_imap_capability(ngx_mail_session_t *s,
- ngx_connection_t *c);
-static ngx_int_t ngx_mail_imap_starttls(ngx_mail_session_t *s,
- ngx_connection_t *c);
-
-
-static u_char imap_greeting[] = "* OK IMAP4 ready" CRLF;
-static u_char imap_star[] = "* ";
-static u_char imap_ok[] = "OK completed" CRLF;
-static u_char imap_next[] = "+ OK" CRLF;
-static u_char imap_plain_next[] = "+ " CRLF;
-static u_char imap_username[] = "+ VXNlcm5hbWU6" CRLF;
-static u_char imap_password[] = "+ UGFzc3dvcmQ6" CRLF;
-static u_char imap_bye[] = "* BYE" CRLF;
-static u_char imap_invalid_command[] = "BAD invalid command" CRLF;
-
-
-void
-ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_mail_core_srv_conf_t *cscf;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- ngx_str_set(&s->out, imap_greeting);
-
- c->read->handler = ngx_mail_imap_init_protocol;
-
- ngx_add_timer(c->read, cscf->timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- ngx_mail_send(c->write);
-}
-
-
-void
-ngx_mail_imap_init_protocol(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_imap_srv_conf_t *iscf;
-
- c = rev->data;
-
- c->log->action = "in auth state";
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- s = c->data;
-
- if (s->buffer == NULL) {
- if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t))
- == NGX_ERROR)
- {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module);
-
- s->buffer = ngx_create_temp_buf(c->pool, iscf->client_buffer_size);
- if (s->buffer == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
- }
-
- s->mail_state = ngx_imap_start;
- c->read->handler = ngx_mail_imap_auth_state;
-
- ngx_mail_imap_auth_state(rev);
-}
-
-
-void
-ngx_mail_imap_auth_state(ngx_event_t *rev)
-{
- u_char *p;
- ngx_int_t rc;
- ngx_uint_t tag;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth state");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- if (s->out.len) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap send handler busy");
- s->blocked = 1;
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- return;
- }
-
- s->blocked = 0;
-
- rc = ngx_mail_read_command(s, c);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- return;
- }
-
- tag = 1;
- s->text.len = 0;
- ngx_str_set(&s->out, imap_ok);
-
- if (rc == NGX_OK) {
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0, "imap auth command: %i",
- s->command);
-
- switch (s->mail_state) {
-
- case ngx_imap_start:
-
- switch (s->command) {
-
- case NGX_IMAP_LOGIN:
- rc = ngx_mail_imap_login(s, c);
- break;
-
- case NGX_IMAP_AUTHENTICATE:
- rc = ngx_mail_imap_authenticate(s, c);
- tag = (rc != NGX_OK);
- break;
-
- case NGX_IMAP_CAPABILITY:
- rc = ngx_mail_imap_capability(s, c);
- break;
-
- case NGX_IMAP_LOGOUT:
- s->quit = 1;
- ngx_str_set(&s->text, imap_bye);
- break;
-
- case NGX_IMAP_NOOP:
- break;
-
- case NGX_IMAP_STARTTLS:
- rc = ngx_mail_imap_starttls(s, c);
- break;
-
- default:
- rc = NGX_MAIL_PARSE_INVALID_COMMAND;
- break;
- }
-
- break;
-
- case ngx_imap_auth_login_username:
- rc = ngx_mail_auth_login_username(s, c, 0);
-
- tag = 0;
- ngx_str_set(&s->out, imap_password);
- s->mail_state = ngx_imap_auth_login_password;
-
- break;
-
- case ngx_imap_auth_login_password:
- rc = ngx_mail_auth_login_password(s, c);
- break;
-
- case ngx_imap_auth_plain:
- rc = ngx_mail_auth_plain(s, c, 0);
- break;
-
- case ngx_imap_auth_cram_md5:
- rc = ngx_mail_auth_cram_md5(s, c);
- break;
-
- case ngx_imap_auth_external:
- rc = ngx_mail_auth_external(s, c, 0);
- break;
- }
-
- } else if (rc == NGX_IMAP_NEXT) {
- tag = 0;
- ngx_str_set(&s->out, imap_next);
- }
-
- if (s->buffer->pos < s->buffer->last) {
- s->blocked = 1;
- }
-
- switch (rc) {
-
- case NGX_DONE:
- ngx_mail_auth(s, c);
- return;
-
- case NGX_ERROR:
- ngx_mail_session_internal_server_error(s);
- return;
-
- case NGX_MAIL_PARSE_INVALID_COMMAND:
- s->state = 0;
- ngx_str_set(&s->out, imap_invalid_command);
- s->mail_state = ngx_imap_start;
- break;
- }
-
- if (tag) {
- if (s->tag.len == 0) {
- ngx_str_set(&s->tag, imap_star);
- }
-
- if (s->tagged_line.len < s->tag.len + s->text.len + s->out.len) {
- s->tagged_line.len = s->tag.len + s->text.len + s->out.len;
- s->tagged_line.data = ngx_pnalloc(c->pool, s->tagged_line.len);
- if (s->tagged_line.data == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
- }
-
- p = s->tagged_line.data;
-
- if (s->text.len) {
- p = ngx_cpymem(p, s->text.data, s->text.len);
- }
-
- p = ngx_cpymem(p, s->tag.data, s->tag.len);
- ngx_memcpy(p, s->out.data, s->out.len);
-
- s->out.len = s->text.len + s->tag.len + s->out.len;
- s->out.data = s->tagged_line.data;
- }
-
- if (rc != NGX_IMAP_NEXT) {
- s->args.nelts = 0;
-
- if (s->state) {
- /* preserve tag */
- s->arg_start = s->buffer->pos;
-
- } else {
- if (s->buffer->pos == s->buffer->last) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- }
-
- s->tag.len = 0;
- }
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_mail_send(c->write);
-}
-
-
-static ngx_int_t
-ngx_mail_imap_login(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- arg = s->args.elts;
-
- if (s->args.nelts != 2 || arg[0].len == 0) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- s->login.len = arg[0].len;
- s->login.data = ngx_pnalloc(c->pool, s->login.len);
- if (s->login.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->login.data, arg[0].data, s->login.len);
-
- s->passwd.len = arg[1].len;
- s->passwd.data = ngx_pnalloc(c->pool, s->passwd.len);
- if (s->passwd.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len);
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "imap login:\"%V\" passwd:\"%V\"",
- &s->login, &s->passwd);
-#else
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "imap login:\"%V\"", &s->login);
-#endif
-
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_mail_imap_authenticate(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_int_t rc;
- ngx_mail_core_srv_conf_t *cscf;
- ngx_mail_imap_srv_conf_t *iscf;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module);
-
- rc = ngx_mail_auth_parse(s, c);
-
- switch (rc) {
-
- case NGX_MAIL_AUTH_LOGIN:
-
- ngx_str_set(&s->out, imap_username);
- s->mail_state = ngx_imap_auth_login_username;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_LOGIN_USERNAME:
-
- ngx_str_set(&s->out, imap_password);
- s->mail_state = ngx_imap_auth_login_password;
-
- return ngx_mail_auth_login_username(s, c, 1);
-
- case NGX_MAIL_AUTH_PLAIN:
-
- ngx_str_set(&s->out, imap_plain_next);
- s->mail_state = ngx_imap_auth_plain;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_CRAM_MD5:
-
- if (!(iscf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (s->salt.data == NULL) {
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
- return NGX_ERROR;
- }
- }
-
- if (ngx_mail_auth_cram_md5_salt(s, c, "+ ", 2) == NGX_OK) {
- s->mail_state = ngx_imap_auth_cram_md5;
- return NGX_OK;
- }
-
- return NGX_ERROR;
-
- case NGX_MAIL_AUTH_EXTERNAL:
-
- if (!(iscf->auth_methods & NGX_MAIL_AUTH_EXTERNAL_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- ngx_str_set(&s->out, imap_username);
- s->mail_state = ngx_imap_auth_external;
-
- return NGX_OK;
- }
-
- return rc;
-}
-
-
-static ngx_int_t
-ngx_mail_imap_capability(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_mail_imap_srv_conf_t *iscf;
-
- iscf = ngx_mail_get_module_srv_conf(s, ngx_mail_imap_module);
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl == NULL) {
- ngx_mail_ssl_conf_t *sslcf;
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
- s->text = iscf->starttls_capability;
- return NGX_OK;
- }
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
- s->text = iscf->starttls_only_capability;
- return NGX_OK;
- }
- }
-#endif
-
- s->text = iscf->capability;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_imap_starttls(ngx_mail_session_t *s, ngx_connection_t *c)
-{
-#if (NGX_MAIL_SSL)
- ngx_mail_ssl_conf_t *sslcf;
-
- if (c->ssl == NULL) {
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
- if (sslcf->starttls) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- c->read->handler = ngx_mail_starttls_handler;
- return NGX_OK;
- }
- }
-
-#endif
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.c
deleted file mode 100644
index 02c684cd4b..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.c
+++ /dev/null
@@ -1,258 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static void *ngx_mail_imap_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_mail_imap_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-
-static ngx_str_t ngx_mail_imap_default_capabilities[] = {
- ngx_string("IMAP4"),
- ngx_string("IMAP4rev1"),
- ngx_string("UIDPLUS"),
- ngx_null_string
-};
-
-
-static ngx_conf_bitmask_t ngx_mail_imap_auth_methods[] = {
- { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
- { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
- { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
- { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED },
- { ngx_null_string, 0 }
-};
-
-
-static ngx_str_t ngx_mail_imap_auth_methods_names[] = {
- ngx_string("AUTH=PLAIN"),
- ngx_string("AUTH=LOGIN"),
- ngx_null_string, /* APOP */
- ngx_string("AUTH=CRAM-MD5"),
- ngx_string("AUTH=EXTERNAL"),
- ngx_null_string /* NONE */
-};
-
-
-static ngx_mail_protocol_t ngx_mail_imap_protocol = {
- ngx_string("imap"),
- ngx_string("\x04imap"),
- { 143, 993, 0, 0 },
- NGX_MAIL_IMAP_PROTOCOL,
-
- ngx_mail_imap_init_session,
- ngx_mail_imap_init_protocol,
- ngx_mail_imap_parse_command,
- ngx_mail_imap_auth_state,
-
- ngx_string("* BAD internal server error" CRLF),
- ngx_string("* BYE SSL certificate error" CRLF),
- ngx_string("* BYE No required SSL certificate" CRLF)
-};
-
-
-static ngx_command_t ngx_mail_imap_commands[] = {
-
- { ngx_string("imap_client_buffer"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_imap_srv_conf_t, client_buffer_size),
- NULL },
-
- { ngx_string("imap_capabilities"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_capabilities,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_imap_srv_conf_t, capabilities),
- NULL },
-
- { ngx_string("imap_auth"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_imap_srv_conf_t, auth_methods),
- &ngx_mail_imap_auth_methods },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_imap_module_ctx = {
- &ngx_mail_imap_protocol, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_imap_create_srv_conf, /* create server configuration */
- ngx_mail_imap_merge_srv_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_imap_module = {
- NGX_MODULE_V1,
- &ngx_mail_imap_module_ctx, /* module context */
- ngx_mail_imap_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static void *
-ngx_mail_imap_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_mail_imap_srv_conf_t *iscf;
-
- iscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_imap_srv_conf_t));
- if (iscf == NULL) {
- return NULL;
- }
-
- iscf->client_buffer_size = NGX_CONF_UNSET_SIZE;
-
- if (ngx_array_init(&iscf->capabilities, cf->pool, 4, sizeof(ngx_str_t))
- != NGX_OK)
- {
- return NULL;
- }
-
- return iscf;
-}
-
-
-static char *
-ngx_mail_imap_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_imap_srv_conf_t *prev = parent;
- ngx_mail_imap_srv_conf_t *conf = child;
-
- u_char *p, *auth;
- size_t size;
- ngx_str_t *c, *d;
- ngx_uint_t i, m;
-
- ngx_conf_merge_size_value(conf->client_buffer_size,
- prev->client_buffer_size,
- (size_t) ngx_pagesize);
-
- ngx_conf_merge_bitmask_value(conf->auth_methods,
- prev->auth_methods,
- (NGX_CONF_BITMASK_SET
- |NGX_MAIL_AUTH_PLAIN_ENABLED));
-
-
- if (conf->capabilities.nelts == 0) {
- conf->capabilities = prev->capabilities;
- }
-
- if (conf->capabilities.nelts == 0) {
-
- for (d = ngx_mail_imap_default_capabilities; d->len; d++) {
- c = ngx_array_push(&conf->capabilities);
- if (c == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *c = *d;
- }
- }
-
- size = sizeof("* CAPABILITY" CRLF) - 1;
-
- c = conf->capabilities.elts;
- for (i = 0; i < conf->capabilities.nelts; i++) {
- size += 1 + c[i].len;
- }
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (m & conf->auth_methods) {
- size += 1 + ngx_mail_imap_auth_methods_names[i].len;
- }
- }
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->capability.len = size;
- conf->capability.data = p;
-
- p = ngx_cpymem(p, "* CAPABILITY", sizeof("* CAPABILITY") - 1);
-
- for (i = 0; i < conf->capabilities.nelts; i++) {
- *p++ = ' ';
- p = ngx_cpymem(p, c[i].data, c[i].len);
- }
-
- auth = p;
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (m & conf->auth_methods) {
- *p++ = ' ';
- p = ngx_cpymem(p, ngx_mail_imap_auth_methods_names[i].data,
- ngx_mail_imap_auth_methods_names[i].len);
- }
- }
-
- *p++ = CR; *p = LF;
-
-
- size += sizeof(" STARTTLS") - 1;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_capability.len = size;
- conf->starttls_capability.data = p;
-
- p = ngx_cpymem(p, conf->capability.data,
- conf->capability.len - (sizeof(CRLF) - 1));
- p = ngx_cpymem(p, " STARTTLS", sizeof(" STARTTLS") - 1);
- *p++ = CR; *p = LF;
-
-
- size = (auth - conf->capability.data) + sizeof(CRLF) - 1
- + sizeof(" STARTTLS LOGINDISABLED") - 1;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_only_capability.len = size;
- conf->starttls_only_capability.data = p;
-
- p = ngx_cpymem(p, conf->capability.data,
- auth - conf->capability.data);
- p = ngx_cpymem(p, " STARTTLS LOGINDISABLED",
- sizeof(" STARTTLS LOGINDISABLED") - 1);
- *p++ = CR; *p = LF;
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.h b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.h
deleted file mode 100644
index 131b44597f..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_imap_module.h
+++ /dev/null
@@ -1,39 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_MAIL_IMAP_MODULE_H_INCLUDED_
-#define _NGX_MAIL_IMAP_MODULE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- size_t client_buffer_size;
-
- ngx_str_t capability;
- ngx_str_t starttls_capability;
- ngx_str_t starttls_only_capability;
-
- ngx_uint_t auth_methods;
-
- ngx_array_t capabilities;
-} ngx_mail_imap_srv_conf_t;
-
-
-void ngx_mail_imap_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_imap_init_protocol(ngx_event_t *rev);
-void ngx_mail_imap_auth_state(ngx_event_t *rev);
-ngx_int_t ngx_mail_imap_parse_command(ngx_mail_session_t *s);
-
-
-extern ngx_module_t ngx_mail_imap_module;
-
-
-#endif /* _NGX_MAIL_IMAP_MODULE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_parse.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_parse.c
deleted file mode 100644
index 227b63abb2..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_parse.c
+++ /dev/null
@@ -1,974 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-ngx_int_t
-ngx_mail_pop3_parse_command(ngx_mail_session_t *s)
-{
- u_char ch, *p, *c, c0, c1, c2, c3;
- ngx_str_t *arg;
- enum {
- sw_start = 0,
- sw_command,
- sw_invalid,
- sw_spaces_before_argument,
- sw_argument,
- sw_almost_done
- } state;
-
- state = s->state;
-
- for (p = s->buffer->pos; p < s->buffer->last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* POP3 command */
- case sw_start:
- s->cmd_start = p;
- state = sw_command;
-
- /* fall through */
-
- case sw_command:
- if (ch == ' ' || ch == CR || ch == LF) {
- c = s->cmd_start;
-
- if (p - c == 4) {
-
- c0 = ngx_toupper(c[0]);
- c1 = ngx_toupper(c[1]);
- c2 = ngx_toupper(c[2]);
- c3 = ngx_toupper(c[3]);
-
- if (c0 == 'U' && c1 == 'S' && c2 == 'E' && c3 == 'R')
- {
- s->command = NGX_POP3_USER;
-
- } else if (c0 == 'P' && c1 == 'A' && c2 == 'S' && c3 == 'S')
- {
- s->command = NGX_POP3_PASS;
-
- } else if (c0 == 'A' && c1 == 'P' && c2 == 'O' && c3 == 'P')
- {
- s->command = NGX_POP3_APOP;
-
- } else if (c0 == 'Q' && c1 == 'U' && c2 == 'I' && c3 == 'T')
- {
- s->command = NGX_POP3_QUIT;
-
- } else if (c0 == 'C' && c1 == 'A' && c2 == 'P' && c3 == 'A')
- {
- s->command = NGX_POP3_CAPA;
-
- } else if (c0 == 'A' && c1 == 'U' && c2 == 'T' && c3 == 'H')
- {
- s->command = NGX_POP3_AUTH;
-
- } else if (c0 == 'N' && c1 == 'O' && c2 == 'O' && c3 == 'P')
- {
- s->command = NGX_POP3_NOOP;
-#if (NGX_MAIL_SSL)
- } else if (c0 == 'S' && c1 == 'T' && c2 == 'L' && c3 == 'S')
- {
- s->command = NGX_POP3_STLS;
-#endif
- } else {
- goto invalid;
- }
-
- } else {
- goto invalid;
- }
-
- s->cmd.data = s->cmd_start;
- s->cmd.len = p - s->cmd_start;
-
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
- }
-
- if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z')) {
- goto invalid;
- }
-
- break;
-
- case sw_invalid:
- goto invalid;
-
- case sw_spaces_before_argument:
- switch (ch) {
- case ' ':
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- default:
- if (s->args.nelts <= 2) {
- state = sw_argument;
- s->arg_start = p;
- break;
- }
- goto invalid;
- }
- break;
-
- case sw_argument:
- switch (ch) {
-
- case ' ':
-
- /*
- * the space should be considered as part of the at username
- * or password, but not of argument in other commands
- */
-
- if (s->command == NGX_POP3_USER
- || s->command == NGX_POP3_PASS)
- {
- break;
- }
-
- /* fall through */
-
- case CR:
- case LF:
- arg = ngx_array_push(&s->args);
- if (arg == NULL) {
- return NGX_ERROR;
- }
- arg->len = p - s->arg_start;
- arg->data = s->arg_start;
- s->arg_start = NULL;
-
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
-
- default:
- break;
- }
- break;
-
- case sw_almost_done:
- switch (ch) {
- case LF:
- goto done;
- default:
- goto invalid;
- }
- }
- }
-
- s->buffer->pos = p;
- s->state = state;
-
- return NGX_AGAIN;
-
-done:
-
- s->buffer->pos = p + 1;
- s->state = (s->command != NGX_POP3_AUTH) ? sw_start : sw_argument;
-
- return NGX_OK;
-
-invalid:
-
- s->state = sw_invalid;
-
- /* skip invalid command till LF */
-
- for ( /* void */ ; p < s->buffer->last; p++) {
- if (*p == LF) {
- s->state = sw_start;
- s->buffer->pos = p + 1;
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
- }
-
- s->buffer->pos = p;
-
- return NGX_AGAIN;
-}
-
-
-ngx_int_t
-ngx_mail_imap_parse_command(ngx_mail_session_t *s)
-{
- u_char ch, *p, *c, *dst, *src, *end;
- ngx_str_t *arg;
- enum {
- sw_start = 0,
- sw_tag,
- sw_invalid,
- sw_spaces_before_command,
- sw_command,
- sw_spaces_before_argument,
- sw_argument,
- sw_backslash,
- sw_literal,
- sw_no_sync_literal_argument,
- sw_start_literal_argument,
- sw_literal_argument,
- sw_end_literal_argument,
- sw_almost_done
- } state;
-
- state = s->state;
-
- for (p = s->buffer->pos; p < s->buffer->last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* IMAP tag */
- case sw_start:
- s->tag_start = p;
- state = sw_tag;
-
- /* fall through */
-
- case sw_tag:
- switch (ch) {
- case ' ':
- s->tag.len = p - s->tag_start + 1;
- s->tag.data = s->tag_start;
- state = sw_spaces_before_command;
- break;
- case CR:
- case LF:
- goto invalid;
- default:
- if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z')
- && (ch < '0' || ch > '9') && ch != '-' && ch != '.'
- && ch != '_')
- {
- goto invalid;
- }
- if (p - s->tag_start > 31) {
- goto invalid;
- }
- break;
- }
- break;
-
- case sw_invalid:
- goto invalid;
-
- case sw_spaces_before_command:
- switch (ch) {
- case ' ':
- break;
- case CR:
- case LF:
- goto invalid;
- default:
- s->cmd_start = p;
- state = sw_command;
- break;
- }
- break;
-
- case sw_command:
- if (ch == ' ' || ch == CR || ch == LF) {
-
- c = s->cmd_start;
-
- switch (p - c) {
-
- case 4:
- if ((c[0] == 'N' || c[0] == 'n')
- && (c[1] == 'O'|| c[1] == 'o')
- && (c[2] == 'O'|| c[2] == 'o')
- && (c[3] == 'P'|| c[3] == 'p'))
- {
- s->command = NGX_IMAP_NOOP;
-
- } else {
- goto invalid;
- }
- break;
-
- case 5:
- if ((c[0] == 'L'|| c[0] == 'l')
- && (c[1] == 'O'|| c[1] == 'o')
- && (c[2] == 'G'|| c[2] == 'g')
- && (c[3] == 'I'|| c[3] == 'i')
- && (c[4] == 'N'|| c[4] == 'n'))
- {
- s->command = NGX_IMAP_LOGIN;
-
- } else {
- goto invalid;
- }
- break;
-
- case 6:
- if ((c[0] == 'L'|| c[0] == 'l')
- && (c[1] == 'O'|| c[1] == 'o')
- && (c[2] == 'G'|| c[2] == 'g')
- && (c[3] == 'O'|| c[3] == 'o')
- && (c[4] == 'U'|| c[4] == 'u')
- && (c[5] == 'T'|| c[5] == 't'))
- {
- s->command = NGX_IMAP_LOGOUT;
-
- } else {
- goto invalid;
- }
- break;
-
-#if (NGX_MAIL_SSL)
- case 8:
- if ((c[0] == 'S'|| c[0] == 's')
- && (c[1] == 'T'|| c[1] == 't')
- && (c[2] == 'A'|| c[2] == 'a')
- && (c[3] == 'R'|| c[3] == 'r')
- && (c[4] == 'T'|| c[4] == 't')
- && (c[5] == 'T'|| c[5] == 't')
- && (c[6] == 'L'|| c[6] == 'l')
- && (c[7] == 'S'|| c[7] == 's'))
- {
- s->command = NGX_IMAP_STARTTLS;
-
- } else {
- goto invalid;
- }
- break;
-#endif
-
- case 10:
- if ((c[0] == 'C'|| c[0] == 'c')
- && (c[1] == 'A'|| c[1] == 'a')
- && (c[2] == 'P'|| c[2] == 'p')
- && (c[3] == 'A'|| c[3] == 'a')
- && (c[4] == 'B'|| c[4] == 'b')
- && (c[5] == 'I'|| c[5] == 'i')
- && (c[6] == 'L'|| c[6] == 'l')
- && (c[7] == 'I'|| c[7] == 'i')
- && (c[8] == 'T'|| c[8] == 't')
- && (c[9] == 'Y'|| c[9] == 'y'))
- {
- s->command = NGX_IMAP_CAPABILITY;
-
- } else {
- goto invalid;
- }
- break;
-
- case 12:
- if ((c[0] == 'A'|| c[0] == 'a')
- && (c[1] == 'U'|| c[1] == 'u')
- && (c[2] == 'T'|| c[2] == 't')
- && (c[3] == 'H'|| c[3] == 'h')
- && (c[4] == 'E'|| c[4] == 'e')
- && (c[5] == 'N'|| c[5] == 'n')
- && (c[6] == 'T'|| c[6] == 't')
- && (c[7] == 'I'|| c[7] == 'i')
- && (c[8] == 'C'|| c[8] == 'c')
- && (c[9] == 'A'|| c[9] == 'a')
- && (c[10] == 'T'|| c[10] == 't')
- && (c[11] == 'E'|| c[11] == 'e'))
- {
- s->command = NGX_IMAP_AUTHENTICATE;
-
- } else {
- goto invalid;
- }
- break;
-
- default:
- goto invalid;
- }
-
- s->cmd.data = s->cmd_start;
- s->cmd.len = p - s->cmd_start;
-
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
- }
-
- if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z')) {
- goto invalid;
- }
-
- break;
-
- case sw_spaces_before_argument:
- switch (ch) {
- case ' ':
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- case '"':
- if (s->args.nelts <= 2) {
- s->quoted = 1;
- s->arg_start = p + 1;
- state = sw_argument;
- break;
- }
- goto invalid;
- case '{':
- if (s->args.nelts <= 2) {
- state = sw_literal;
- break;
- }
- goto invalid;
- default:
- if (s->args.nelts <= 2) {
- s->arg_start = p;
- state = sw_argument;
- break;
- }
- goto invalid;
- }
- break;
-
- case sw_argument:
- if (ch == ' ' && s->quoted) {
- break;
- }
-
- switch (ch) {
- case '"':
- if (!s->quoted) {
- break;
- }
- s->quoted = 0;
- /* fall through */
- case ' ':
- case CR:
- case LF:
- arg = ngx_array_push(&s->args);
- if (arg == NULL) {
- return NGX_ERROR;
- }
- arg->len = p - s->arg_start;
- arg->data = s->arg_start;
-
- if (s->backslash) {
- dst = s->arg_start;
- end = p;
-
- for (src = dst; src < end; dst++) {
- *dst = *src;
- if (*src++ == '\\') {
- *dst = *src++;
- }
- }
-
- arg->len = dst - s->arg_start;
- s->backslash = 0;
- }
-
- s->arg_start = NULL;
-
- switch (ch) {
- case '"':
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
- case '\\':
- if (s->quoted) {
- s->backslash = 1;
- state = sw_backslash;
- }
- break;
- }
- break;
-
- case sw_backslash:
- switch (ch) {
- case CR:
- case LF:
- goto invalid;
- default:
- state = sw_argument;
- }
- break;
-
- case sw_literal:
- if (s->literal_len > NGX_MAX_SIZE_T_VALUE / 10) {
- goto invalid;
- }
- if (ch >= '0' && ch <= '9') {
- s->literal_len = s->literal_len * 10 + (ch - '0');
- break;
- }
- if (ch == '}') {
- state = sw_start_literal_argument;
- break;
- }
- if (ch == '+') {
- state = sw_no_sync_literal_argument;
- break;
- }
- goto invalid;
-
- case sw_no_sync_literal_argument:
- if (ch == '}') {
- s->no_sync_literal = 1;
- state = sw_start_literal_argument;
- break;
- }
- goto invalid;
-
- case sw_start_literal_argument:
- switch (ch) {
- case CR:
- break;
- case LF:
- s->buffer->pos = p + 1;
- s->arg_start = p + 1;
- if (s->no_sync_literal == 0) {
- s->state = sw_literal_argument;
- return NGX_IMAP_NEXT;
- }
- state = sw_literal_argument;
- s->no_sync_literal = 0;
- break;
- default:
- goto invalid;
- }
- break;
-
- case sw_literal_argument:
- if (s->literal_len && --s->literal_len) {
- break;
- }
-
- arg = ngx_array_push(&s->args);
- if (arg == NULL) {
- return NGX_ERROR;
- }
- arg->len = p + 1 - s->arg_start;
- arg->data = s->arg_start;
- s->arg_start = NULL;
- state = sw_end_literal_argument;
-
- break;
-
- case sw_end_literal_argument:
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- default:
- goto invalid;
- }
- break;
-
- case sw_almost_done:
- switch (ch) {
- case LF:
- goto done;
- default:
- goto invalid;
- }
- }
- }
-
- s->buffer->pos = p;
- s->state = state;
-
- return NGX_AGAIN;
-
-done:
-
- s->buffer->pos = p + 1;
- s->state = (s->command != NGX_IMAP_AUTHENTICATE) ? sw_start : sw_argument;
-
- return NGX_OK;
-
-invalid:
-
- s->state = sw_invalid;
- s->quoted = 0;
- s->backslash = 0;
- s->no_sync_literal = 0;
- s->literal_len = 0;
-
- /* skip invalid command till LF */
-
- for ( /* void */ ; p < s->buffer->last; p++) {
- if (*p == LF) {
- s->state = sw_start;
- s->buffer->pos = p + 1;
-
- /* detect non-synchronizing literals */
-
- if ((size_t) (p - s->buffer->start) > sizeof("{1+}") - 1) {
- p--;
-
- if (*p == CR) {
- p--;
- }
-
- if (*p == '}' && *(p - 1) == '+') {
- s->quit = 1;
- }
- }
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
- }
-
- s->buffer->pos = p;
-
- return NGX_AGAIN;
-}
-
-
-ngx_int_t
-ngx_mail_smtp_parse_command(ngx_mail_session_t *s)
-{
- u_char ch, *p, *c, c0, c1, c2, c3;
- ngx_str_t *arg;
- enum {
- sw_start = 0,
- sw_command,
- sw_invalid,
- sw_spaces_before_argument,
- sw_argument,
- sw_almost_done
- } state;
-
- state = s->state;
-
- for (p = s->buffer->pos; p < s->buffer->last; p++) {
- ch = *p;
-
- switch (state) {
-
- /* SMTP command */
- case sw_start:
- s->cmd_start = p;
- state = sw_command;
-
- /* fall through */
-
- case sw_command:
- if (ch == ' ' || ch == CR || ch == LF) {
- c = s->cmd_start;
-
- if (p - c == 4) {
-
- c0 = ngx_toupper(c[0]);
- c1 = ngx_toupper(c[1]);
- c2 = ngx_toupper(c[2]);
- c3 = ngx_toupper(c[3]);
-
- if (c0 == 'H' && c1 == 'E' && c2 == 'L' && c3 == 'O')
- {
- s->command = NGX_SMTP_HELO;
-
- } else if (c0 == 'E' && c1 == 'H' && c2 == 'L' && c3 == 'O')
- {
- s->command = NGX_SMTP_EHLO;
-
- } else if (c0 == 'Q' && c1 == 'U' && c2 == 'I' && c3 == 'T')
- {
- s->command = NGX_SMTP_QUIT;
-
- } else if (c0 == 'A' && c1 == 'U' && c2 == 'T' && c3 == 'H')
- {
- s->command = NGX_SMTP_AUTH;
-
- } else if (c0 == 'N' && c1 == 'O' && c2 == 'O' && c3 == 'P')
- {
- s->command = NGX_SMTP_NOOP;
-
- } else if (c0 == 'M' && c1 == 'A' && c2 == 'I' && c3 == 'L')
- {
- s->command = NGX_SMTP_MAIL;
-
- } else if (c0 == 'R' && c1 == 'S' && c2 == 'E' && c3 == 'T')
- {
- s->command = NGX_SMTP_RSET;
-
- } else if (c0 == 'R' && c1 == 'C' && c2 == 'P' && c3 == 'T')
- {
- s->command = NGX_SMTP_RCPT;
-
- } else if (c0 == 'V' && c1 == 'R' && c2 == 'F' && c3 == 'Y')
- {
- s->command = NGX_SMTP_VRFY;
-
- } else if (c0 == 'E' && c1 == 'X' && c2 == 'P' && c3 == 'N')
- {
- s->command = NGX_SMTP_EXPN;
-
- } else if (c0 == 'H' && c1 == 'E' && c2 == 'L' && c3 == 'P')
- {
- s->command = NGX_SMTP_HELP;
-
- } else {
- goto invalid;
- }
-#if (NGX_MAIL_SSL)
- } else if (p - c == 8) {
-
- if ((c[0] == 'S'|| c[0] == 's')
- && (c[1] == 'T'|| c[1] == 't')
- && (c[2] == 'A'|| c[2] == 'a')
- && (c[3] == 'R'|| c[3] == 'r')
- && (c[4] == 'T'|| c[4] == 't')
- && (c[5] == 'T'|| c[5] == 't')
- && (c[6] == 'L'|| c[6] == 'l')
- && (c[7] == 'S'|| c[7] == 's'))
- {
- s->command = NGX_SMTP_STARTTLS;
-
- } else {
- goto invalid;
- }
-#endif
- } else {
- goto invalid;
- }
-
- s->cmd.data = s->cmd_start;
- s->cmd.len = p - s->cmd_start;
-
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
- }
-
- if ((ch < 'A' || ch > 'Z') && (ch < 'a' || ch > 'z')) {
- goto invalid;
- }
-
- break;
-
- case sw_invalid:
- goto invalid;
-
- case sw_spaces_before_argument:
- switch (ch) {
- case ' ':
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- default:
- if (s->args.nelts <= 10) {
- state = sw_argument;
- s->arg_start = p;
- break;
- }
- goto invalid;
- }
- break;
-
- case sw_argument:
- switch (ch) {
- case ' ':
- case CR:
- case LF:
- arg = ngx_array_push(&s->args);
- if (arg == NULL) {
- return NGX_ERROR;
- }
- arg->len = p - s->arg_start;
- arg->data = s->arg_start;
- s->arg_start = NULL;
-
- switch (ch) {
- case ' ':
- state = sw_spaces_before_argument;
- break;
- case CR:
- state = sw_almost_done;
- break;
- case LF:
- goto done;
- }
- break;
-
- default:
- break;
- }
- break;
-
- case sw_almost_done:
- switch (ch) {
- case LF:
- goto done;
- default:
- goto invalid;
- }
- }
- }
-
- s->buffer->pos = p;
- s->state = state;
-
- return NGX_AGAIN;
-
-done:
-
- s->buffer->pos = p + 1;
- s->state = (s->command != NGX_SMTP_AUTH) ? sw_start : sw_argument;
-
- return NGX_OK;
-
-invalid:
-
- s->state = sw_invalid;
-
- /* skip invalid command till LF */
-
- for ( /* void */ ; p < s->buffer->last; p++) {
- if (*p == LF) {
- s->state = sw_start;
- s->buffer->pos = p + 1;
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
- }
-
- s->buffer->pos = p;
-
- return NGX_AGAIN;
-}
-
-
-ngx_int_t
-ngx_mail_auth_parse(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- if (s->args.nelts == 0) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- arg = s->args.elts;
-
- if (arg[0].len == 5) {
-
- if (ngx_strncasecmp(arg[0].data, (u_char *) "LOGIN", 5) == 0) {
-
- if (s->args.nelts == 1) {
- return NGX_MAIL_AUTH_LOGIN;
- }
-
- if (s->args.nelts == 2) {
- return NGX_MAIL_AUTH_LOGIN_USERNAME;
- }
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (ngx_strncasecmp(arg[0].data, (u_char *) "PLAIN", 5) == 0) {
-
- if (s->args.nelts == 1) {
- return NGX_MAIL_AUTH_PLAIN;
- }
-
- if (s->args.nelts == 2) {
- return ngx_mail_auth_plain(s, c, 1);
- }
- }
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (arg[0].len == 8) {
-
- if (ngx_strncasecmp(arg[0].data, (u_char *) "CRAM-MD5", 8) == 0) {
-
- if (s->args.nelts != 1) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- return NGX_MAIL_AUTH_CRAM_MD5;
- }
-
- if (ngx_strncasecmp(arg[0].data, (u_char *) "EXTERNAL", 8) == 0) {
-
- if (s->args.nelts == 1) {
- return NGX_MAIL_AUTH_EXTERNAL;
- }
-
- if (s->args.nelts == 2) {
- return ngx_mail_auth_external(s, c, 1);
- }
- }
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_handler.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_handler.c
deleted file mode 100644
index 226e7419bd..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_handler.c
+++ /dev/null
@@ -1,544 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static ngx_int_t ngx_mail_pop3_user(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_pop3_pass(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_pop3_capa(ngx_mail_session_t *s, ngx_connection_t *c,
- ngx_int_t stls);
-static ngx_int_t ngx_mail_pop3_stls(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_pop3_apop(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_pop3_auth(ngx_mail_session_t *s, ngx_connection_t *c);
-
-
-static u_char pop3_greeting[] = "+OK POP3 ready" CRLF;
-static u_char pop3_ok[] = "+OK" CRLF;
-static u_char pop3_next[] = "+ " CRLF;
-static u_char pop3_username[] = "+ VXNlcm5hbWU6" CRLF;
-static u_char pop3_password[] = "+ UGFzc3dvcmQ6" CRLF;
-static u_char pop3_invalid_command[] = "-ERR invalid command" CRLF;
-
-
-void
-ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- u_char *p;
- ngx_mail_core_srv_conf_t *cscf;
- ngx_mail_pop3_srv_conf_t *pscf;
-
- pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module);
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- if (pscf->auth_methods
- & (NGX_MAIL_AUTH_APOP_ENABLED|NGX_MAIL_AUTH_CRAM_MD5_ENABLED))
- {
- if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- s->out.data = ngx_pnalloc(c->pool, sizeof(pop3_greeting) + s->salt.len);
- if (s->out.data == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(s->out.data, pop3_greeting, sizeof(pop3_greeting) - 3);
- *p++ = ' ';
- p = ngx_cpymem(p, s->salt.data, s->salt.len);
-
- s->out.len = p - s->out.data;
-
- } else {
- ngx_str_set(&s->out, pop3_greeting);
- }
-
- c->read->handler = ngx_mail_pop3_init_protocol;
-
- ngx_add_timer(c->read, cscf->timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- ngx_mail_send(c->write);
-}
-
-
-void
-ngx_mail_pop3_init_protocol(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- c = rev->data;
-
- c->log->action = "in auth state";
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- s = c->data;
-
- if (s->buffer == NULL) {
- if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t))
- == NGX_ERROR)
- {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- s->buffer = ngx_create_temp_buf(c->pool, 128);
- if (s->buffer == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
- }
-
- s->mail_state = ngx_pop3_start;
- c->read->handler = ngx_mail_pop3_auth_state;
-
- ngx_mail_pop3_auth_state(rev);
-}
-
-
-void
-ngx_mail_pop3_auth_state(ngx_event_t *rev)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "pop3 auth state");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- if (s->out.len) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "pop3 send handler busy");
- s->blocked = 1;
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- return;
- }
-
- s->blocked = 0;
-
- rc = ngx_mail_read_command(s, c);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- return;
- }
-
- ngx_str_set(&s->out, pop3_ok);
-
- if (rc == NGX_OK) {
- switch (s->mail_state) {
-
- case ngx_pop3_start:
-
- switch (s->command) {
-
- case NGX_POP3_USER:
- rc = ngx_mail_pop3_user(s, c);
- break;
-
- case NGX_POP3_CAPA:
- rc = ngx_mail_pop3_capa(s, c, 1);
- break;
-
- case NGX_POP3_APOP:
- rc = ngx_mail_pop3_apop(s, c);
- break;
-
- case NGX_POP3_AUTH:
- rc = ngx_mail_pop3_auth(s, c);
- break;
-
- case NGX_POP3_QUIT:
- s->quit = 1;
- break;
-
- case NGX_POP3_NOOP:
- break;
-
- case NGX_POP3_STLS:
- rc = ngx_mail_pop3_stls(s, c);
- break;
-
- default:
- rc = NGX_MAIL_PARSE_INVALID_COMMAND;
- break;
- }
-
- break;
-
- case ngx_pop3_user:
-
- switch (s->command) {
-
- case NGX_POP3_PASS:
- rc = ngx_mail_pop3_pass(s, c);
- break;
-
- case NGX_POP3_CAPA:
- rc = ngx_mail_pop3_capa(s, c, 0);
- break;
-
- case NGX_POP3_QUIT:
- s->quit = 1;
- break;
-
- case NGX_POP3_NOOP:
- break;
-
- default:
- rc = NGX_MAIL_PARSE_INVALID_COMMAND;
- break;
- }
-
- break;
-
- /* suppress warnings */
- case ngx_pop3_passwd:
- break;
-
- case ngx_pop3_auth_login_username:
- rc = ngx_mail_auth_login_username(s, c, 0);
-
- ngx_str_set(&s->out, pop3_password);
- s->mail_state = ngx_pop3_auth_login_password;
- break;
-
- case ngx_pop3_auth_login_password:
- rc = ngx_mail_auth_login_password(s, c);
- break;
-
- case ngx_pop3_auth_plain:
- rc = ngx_mail_auth_plain(s, c, 0);
- break;
-
- case ngx_pop3_auth_cram_md5:
- rc = ngx_mail_auth_cram_md5(s, c);
- break;
-
- case ngx_pop3_auth_external:
- rc = ngx_mail_auth_external(s, c, 0);
- break;
- }
- }
-
- if (s->buffer->pos < s->buffer->last) {
- s->blocked = 1;
- }
-
- switch (rc) {
-
- case NGX_DONE:
- ngx_mail_auth(s, c);
- return;
-
- case NGX_ERROR:
- ngx_mail_session_internal_server_error(s);
- return;
-
- case NGX_MAIL_PARSE_INVALID_COMMAND:
- s->mail_state = ngx_pop3_start;
- s->state = 0;
-
- ngx_str_set(&s->out, pop3_invalid_command);
-
- /* fall through */
-
- case NGX_OK:
-
- s->args.nelts = 0;
-
- if (s->buffer->pos == s->buffer->last) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- }
-
- if (s->state) {
- s->arg_start = s->buffer->pos;
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_mail_send(c->write);
- }
-}
-
-static ngx_int_t
-ngx_mail_pop3_user(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- if (s->args.nelts != 1) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- arg = s->args.elts;
- s->login.len = arg[0].len;
- s->login.data = ngx_pnalloc(c->pool, s->login.len);
- if (s->login.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->login.data, arg[0].data, s->login.len);
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "pop3 login: \"%V\"", &s->login);
-
- s->mail_state = ngx_pop3_user;
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_pop3_pass(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
-
- if (s->args.nelts != 1) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- arg = s->args.elts;
- s->passwd.len = arg[0].len;
- s->passwd.data = ngx_pnalloc(c->pool, s->passwd.len);
- if (s->passwd.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->passwd.data, arg[0].data, s->passwd.len);
-
-#if (NGX_DEBUG_MAIL_PASSWD)
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "pop3 passwd: \"%V\"", &s->passwd);
-#endif
-
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_mail_pop3_capa(ngx_mail_session_t *s, ngx_connection_t *c, ngx_int_t stls)
-{
- ngx_mail_pop3_srv_conf_t *pscf;
-
- pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module);
-
-#if (NGX_MAIL_SSL)
-
- if (stls && c->ssl == NULL) {
- ngx_mail_ssl_conf_t *sslcf;
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
- s->out = pscf->starttls_capability;
- return NGX_OK;
- }
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
- s->out = pscf->starttls_only_capability;
- return NGX_OK;
- }
- }
-
-#endif
-
- s->out = pscf->capability;
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_pop3_stls(ngx_mail_session_t *s, ngx_connection_t *c)
-{
-#if (NGX_MAIL_SSL)
- ngx_mail_ssl_conf_t *sslcf;
-
- if (c->ssl == NULL) {
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
- if (sslcf->starttls) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- c->read->handler = ngx_mail_starttls_handler;
- return NGX_OK;
- }
- }
-
-#endif
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
-}
-
-
-static ngx_int_t
-ngx_mail_pop3_apop(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
- ngx_mail_pop3_srv_conf_t *pscf;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- if (s->args.nelts != 2) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module);
-
- if (!(pscf->auth_methods & NGX_MAIL_AUTH_APOP_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- arg = s->args.elts;
-
- s->login.len = arg[0].len;
- s->login.data = ngx_pnalloc(c->pool, s->login.len);
- if (s->login.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->login.data, arg[0].data, s->login.len);
-
- s->passwd.len = arg[1].len;
- s->passwd.data = ngx_pnalloc(c->pool, s->passwd.len);
- if (s->passwd.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->passwd.data, arg[1].data, s->passwd.len);
-
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "pop3 apop: \"%V\" \"%V\"", &s->login, &s->passwd);
-
- s->auth_method = NGX_MAIL_AUTH_APOP;
-
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_mail_pop3_auth(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_int_t rc;
- ngx_mail_pop3_srv_conf_t *pscf;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- pscf = ngx_mail_get_module_srv_conf(s, ngx_mail_pop3_module);
-
- if (s->args.nelts == 0) {
- s->out = pscf->auth_capability;
- s->state = 0;
-
- return NGX_OK;
- }
-
- rc = ngx_mail_auth_parse(s, c);
-
- switch (rc) {
-
- case NGX_MAIL_AUTH_LOGIN:
-
- ngx_str_set(&s->out, pop3_username);
- s->mail_state = ngx_pop3_auth_login_username;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_LOGIN_USERNAME:
-
- ngx_str_set(&s->out, pop3_password);
- s->mail_state = ngx_pop3_auth_login_password;
-
- return ngx_mail_auth_login_username(s, c, 1);
-
- case NGX_MAIL_AUTH_PLAIN:
-
- ngx_str_set(&s->out, pop3_next);
- s->mail_state = ngx_pop3_auth_plain;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_CRAM_MD5:
-
- if (!(pscf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (ngx_mail_auth_cram_md5_salt(s, c, "+ ", 2) == NGX_OK) {
- s->mail_state = ngx_pop3_auth_cram_md5;
- return NGX_OK;
- }
-
- return NGX_ERROR;
-
- case NGX_MAIL_AUTH_EXTERNAL:
-
- if (!(pscf->auth_methods & NGX_MAIL_AUTH_EXTERNAL_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- ngx_str_set(&s->out, pop3_username);
- s->mail_state = ngx_pop3_auth_external;
-
- return NGX_OK;
- }
-
- return rc;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.c
deleted file mode 100644
index a257b5a702..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.c
+++ /dev/null
@@ -1,323 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static void *ngx_mail_pop3_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-
-static ngx_str_t ngx_mail_pop3_default_capabilities[] = {
- ngx_string("TOP"),
- ngx_string("USER"),
- ngx_string("UIDL"),
- ngx_null_string
-};
-
-
-static ngx_conf_bitmask_t ngx_mail_pop3_auth_methods[] = {
- { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
- { ngx_string("apop"), NGX_MAIL_AUTH_APOP_ENABLED },
- { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
- { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED },
- { ngx_null_string, 0 }
-};
-
-
-static ngx_str_t ngx_mail_pop3_auth_methods_names[] = {
- ngx_string("PLAIN"),
- ngx_string("LOGIN"),
- ngx_null_string, /* APOP */
- ngx_string("CRAM-MD5"),
- ngx_string("EXTERNAL"),
- ngx_null_string /* NONE */
-};
-
-
-static ngx_mail_protocol_t ngx_mail_pop3_protocol = {
- ngx_string("pop3"),
- ngx_string("\x04pop3"),
- { 110, 995, 0, 0 },
- NGX_MAIL_POP3_PROTOCOL,
-
- ngx_mail_pop3_init_session,
- ngx_mail_pop3_init_protocol,
- ngx_mail_pop3_parse_command,
- ngx_mail_pop3_auth_state,
-
- ngx_string("-ERR internal server error" CRLF),
- ngx_string("-ERR SSL certificate error" CRLF),
- ngx_string("-ERR No required SSL certificate" CRLF)
-};
-
-
-static ngx_command_t ngx_mail_pop3_commands[] = {
-
- { ngx_string("pop3_capabilities"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_capabilities,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_pop3_srv_conf_t, capabilities),
- NULL },
-
- { ngx_string("pop3_auth"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_pop3_srv_conf_t, auth_methods),
- &ngx_mail_pop3_auth_methods },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_pop3_module_ctx = {
- &ngx_mail_pop3_protocol, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_pop3_create_srv_conf, /* create server configuration */
- ngx_mail_pop3_merge_srv_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_pop3_module = {
- NGX_MODULE_V1,
- &ngx_mail_pop3_module_ctx, /* module context */
- ngx_mail_pop3_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static void *
-ngx_mail_pop3_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_mail_pop3_srv_conf_t *pscf;
-
- pscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_pop3_srv_conf_t));
- if (pscf == NULL) {
- return NULL;
- }
-
- if (ngx_array_init(&pscf->capabilities, cf->pool, 4, sizeof(ngx_str_t))
- != NGX_OK)
- {
- return NULL;
- }
-
- return pscf;
-}
-
-
-static char *
-ngx_mail_pop3_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_pop3_srv_conf_t *prev = parent;
- ngx_mail_pop3_srv_conf_t *conf = child;
-
- u_char *p;
- size_t size, stls_only_size;
- ngx_str_t *c, *d;
- ngx_uint_t i, m;
-
- ngx_conf_merge_bitmask_value(conf->auth_methods,
- prev->auth_methods,
- (NGX_CONF_BITMASK_SET
- |NGX_MAIL_AUTH_PLAIN_ENABLED));
-
- if (conf->auth_methods & NGX_MAIL_AUTH_PLAIN_ENABLED) {
- conf->auth_methods |= NGX_MAIL_AUTH_LOGIN_ENABLED;
- }
-
- if (conf->capabilities.nelts == 0) {
- conf->capabilities = prev->capabilities;
- }
-
- if (conf->capabilities.nelts == 0) {
-
- for (d = ngx_mail_pop3_default_capabilities; d->len; d++) {
- c = ngx_array_push(&conf->capabilities);
- if (c == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *c = *d;
- }
- }
-
- size = sizeof("+OK Capability list follows" CRLF) - 1
- + sizeof("." CRLF) - 1;
-
- stls_only_size = size + sizeof("STLS" CRLF) - 1;
-
- c = conf->capabilities.elts;
- for (i = 0; i < conf->capabilities.nelts; i++) {
- size += c[i].len + sizeof(CRLF) - 1;
-
- if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) {
- continue;
- }
-
- stls_only_size += c[i].len + sizeof(CRLF) - 1;
- }
-
- size += sizeof("SASL") - 1 + sizeof(CRLF) - 1;
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (ngx_mail_pop3_auth_methods_names[i].len == 0) {
- continue;
- }
-
- if (m & conf->auth_methods) {
- size += 1 + ngx_mail_pop3_auth_methods_names[i].len;
- }
- }
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->capability.len = size;
- conf->capability.data = p;
-
- p = ngx_cpymem(p, "+OK Capability list follows" CRLF,
- sizeof("+OK Capability list follows" CRLF) - 1);
-
- for (i = 0; i < conf->capabilities.nelts; i++) {
- p = ngx_cpymem(p, c[i].data, c[i].len);
- *p++ = CR; *p++ = LF;
- }
-
- p = ngx_cpymem(p, "SASL", sizeof("SASL") - 1);
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (ngx_mail_pop3_auth_methods_names[i].len == 0) {
- continue;
- }
-
- if (m & conf->auth_methods) {
- *p++ = ' ';
- p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data,
- ngx_mail_pop3_auth_methods_names[i].len);
- }
- }
-
- *p++ = CR; *p++ = LF;
-
- *p++ = '.'; *p++ = CR; *p = LF;
-
-
- size += sizeof("STLS" CRLF) - 1;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_capability.len = size;
- conf->starttls_capability.data = p;
-
- p = ngx_cpymem(p, conf->capability.data,
- conf->capability.len - (sizeof("." CRLF) - 1));
-
- p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1);
- *p++ = '.'; *p++ = CR; *p = LF;
-
-
- size = sizeof("+OK methods supported:" CRLF) - 1
- + sizeof("." CRLF) - 1;
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (ngx_mail_pop3_auth_methods_names[i].len == 0) {
- continue;
- }
-
- if (m & conf->auth_methods) {
- size += ngx_mail_pop3_auth_methods_names[i].len
- + sizeof(CRLF) - 1;
- }
- }
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->auth_capability.data = p;
- conf->auth_capability.len = size;
-
- p = ngx_cpymem(p, "+OK methods supported:" CRLF,
- sizeof("+OK methods supported:" CRLF) - 1);
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (ngx_mail_pop3_auth_methods_names[i].len == 0) {
- continue;
- }
-
- if (m & conf->auth_methods) {
- p = ngx_cpymem(p, ngx_mail_pop3_auth_methods_names[i].data,
- ngx_mail_pop3_auth_methods_names[i].len);
- *p++ = CR; *p++ = LF;
- }
- }
-
- *p++ = '.'; *p++ = CR; *p = LF;
-
-
- p = ngx_pnalloc(cf->pool, stls_only_size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_only_capability.len = stls_only_size;
- conf->starttls_only_capability.data = p;
-
- p = ngx_cpymem(p, "+OK Capability list follows" CRLF,
- sizeof("+OK Capability list follows" CRLF) - 1);
-
- for (i = 0; i < conf->capabilities.nelts; i++) {
- if (ngx_strcasecmp(c[i].data, (u_char *) "USER") == 0) {
- continue;
- }
-
- p = ngx_cpymem(p, c[i].data, c[i].len);
- *p++ = CR; *p++ = LF;
- }
-
- p = ngx_cpymem(p, "STLS" CRLF, sizeof("STLS" CRLF) - 1);
- *p++ = '.'; *p++ = CR; *p = LF;
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.h b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.h
deleted file mode 100644
index 86947a7725..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_pop3_module.h
+++ /dev/null
@@ -1,38 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_MAIL_POP3_MODULE_H_INCLUDED_
-#define _NGX_MAIL_POP3_MODULE_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_str_t capability;
- ngx_str_t starttls_capability;
- ngx_str_t starttls_only_capability;
- ngx_str_t auth_capability;
-
- ngx_uint_t auth_methods;
-
- ngx_array_t capabilities;
-} ngx_mail_pop3_srv_conf_t;
-
-
-void ngx_mail_pop3_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_pop3_init_protocol(ngx_event_t *rev);
-void ngx_mail_pop3_auth_state(ngx_event_t *rev);
-ngx_int_t ngx_mail_pop3_parse_command(ngx_mail_session_t *s);
-
-
-extern ngx_module_t ngx_mail_pop3_module;
-
-
-#endif /* _NGX_MAIL_POP3_MODULE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_proxy_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_proxy_module.c
deleted file mode 100644
index 84a7f61a4a..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_proxy_module.c
+++ /dev/null
@@ -1,1411 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_flag_t enable;
- ngx_flag_t pass_error_message;
- ngx_flag_t xclient;
- ngx_flag_t smtp_auth;
- ngx_flag_t proxy_protocol;
- size_t buffer_size;
- ngx_msec_t timeout;
-} ngx_mail_proxy_conf_t;
-
-
-static void ngx_mail_proxy_block_read(ngx_event_t *rev);
-static void ngx_mail_proxy_pop3_handler(ngx_event_t *rev);
-static void ngx_mail_proxy_imap_handler(ngx_event_t *rev);
-static void ngx_mail_proxy_smtp_handler(ngx_event_t *rev);
-static void ngx_mail_proxy_write_handler(ngx_event_t *wev);
-static ngx_int_t ngx_mail_proxy_send_proxy_protocol(ngx_mail_session_t *s);
-static ngx_int_t ngx_mail_proxy_read_response(ngx_mail_session_t *s,
- ngx_uint_t state);
-static void ngx_mail_proxy_handler(ngx_event_t *ev);
-static void ngx_mail_proxy_upstream_error(ngx_mail_session_t *s);
-static void ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s);
-static void ngx_mail_proxy_close_session(ngx_mail_session_t *s);
-static void *ngx_mail_proxy_create_conf(ngx_conf_t *cf);
-static char *ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-
-static ngx_command_t ngx_mail_proxy_commands[] = {
-
- { ngx_string("proxy"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, enable),
- NULL },
-
- { ngx_string("proxy_buffer"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, buffer_size),
- NULL },
-
- { ngx_string("proxy_timeout"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, timeout),
- NULL },
-
- { ngx_string("proxy_pass_error_message"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, pass_error_message),
- NULL },
-
- { ngx_string("xclient"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, xclient),
- NULL },
-
- { ngx_string("proxy_smtp_auth"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, smtp_auth),
- NULL },
-
- { ngx_string("proxy_protocol"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_proxy_conf_t, proxy_protocol),
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_proxy_module_ctx = {
- NULL, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_proxy_create_conf, /* create server configuration */
- ngx_mail_proxy_merge_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_proxy_module = {
- NGX_MODULE_V1,
- &ngx_mail_proxy_module_ctx, /* module context */
- ngx_mail_proxy_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static u_char smtp_auth_ok[] = "235 2.0.0 OK" CRLF;
-
-
-void
-ngx_mail_proxy_init(ngx_mail_session_t *s, ngx_addr_t *peer)
-{
- ngx_int_t rc;
- ngx_mail_proxy_ctx_t *p;
- ngx_mail_proxy_conf_t *pcf;
- ngx_mail_core_srv_conf_t *cscf;
-
- s->connection->log->action = "connecting to upstream";
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- p = ngx_pcalloc(s->connection->pool, sizeof(ngx_mail_proxy_ctx_t));
- if (p == NULL) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- s->proxy = p;
-
- p->upstream.sockaddr = peer->sockaddr;
- p->upstream.socklen = peer->socklen;
- p->upstream.name = &peer->name;
- p->upstream.get = ngx_event_get_peer;
- p->upstream.log = s->connection->log;
- p->upstream.log_error = NGX_ERROR_ERR;
-
- rc = ngx_event_connect_peer(&p->upstream);
-
- if (rc == NGX_ERROR || rc == NGX_BUSY || rc == NGX_DECLINED) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- ngx_add_timer(p->upstream.connection->read, cscf->timeout);
-
- p->upstream.connection->data = s;
- p->upstream.connection->pool = s->connection->pool;
-
- s->connection->read->handler = ngx_mail_proxy_block_read;
- p->upstream.connection->write->handler = ngx_mail_proxy_write_handler;
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
-
- s->proxy->buffer = ngx_create_temp_buf(s->connection->pool,
- pcf->buffer_size);
- if (s->proxy->buffer == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- s->proxy->proxy_protocol = pcf->proxy_protocol;
-
- s->out.len = 0;
-
- switch (s->protocol) {
-
- case NGX_MAIL_POP3_PROTOCOL:
- p->upstream.connection->read->handler = ngx_mail_proxy_pop3_handler;
- s->mail_state = ngx_pop3_start;
- break;
-
- case NGX_MAIL_IMAP_PROTOCOL:
- p->upstream.connection->read->handler = ngx_mail_proxy_imap_handler;
- s->mail_state = ngx_imap_start;
- break;
-
- default: /* NGX_MAIL_SMTP_PROTOCOL */
- p->upstream.connection->read->handler = ngx_mail_proxy_smtp_handler;
- s->mail_state = ngx_smtp_start;
- break;
- }
-
- if (rc == NGX_AGAIN) {
- return;
- }
-
- ngx_mail_proxy_write_handler(p->upstream.connection->write);
-}
-
-
-static void
-ngx_mail_proxy_block_read(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy block read");
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
- c = rev->data;
- s = c->data;
-
- ngx_mail_proxy_close_session(s);
- }
-}
-
-
-static void
-ngx_mail_proxy_pop3_handler(ngx_event_t *rev)
-{
- u_char *p;
- ngx_int_t rc;
- ngx_str_t line;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_proxy_conf_t *pcf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy pop3 auth handler");
-
- c = rev->data;
- s = c->data;
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
- "upstream timed out");
- c->timedout = 1;
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (s->proxy->proxy_protocol) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy pop3 busy");
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- rc = ngx_mail_proxy_read_response(s, 0);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- ngx_mail_proxy_upstream_error(s);
- return;
- }
-
- switch (s->mail_state) {
-
- case ngx_pop3_start:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user");
-
- s->connection->log->action = "sending user name to upstream";
-
- line.len = sizeof("USER ") - 1 + s->login.len + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, "USER ", sizeof("USER ") - 1);
- p = ngx_cpymem(p, s->login.data, s->login.len);
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_pop3_user;
- break;
-
- case ngx_pop3_user:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send pass");
-
- s->connection->log->action = "sending password to upstream";
-
- line.len = sizeof("PASS ") - 1 + s->passwd.len + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, "PASS ", sizeof("PASS ") - 1);
- p = ngx_cpymem(p, s->passwd.data, s->passwd.len);
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_pop3_passwd;
- break;
-
- case ngx_pop3_passwd:
- s->connection->read->handler = ngx_mail_proxy_handler;
- s->connection->write->handler = ngx_mail_proxy_handler;
- rev->handler = ngx_mail_proxy_handler;
- c->write->handler = ngx_mail_proxy_handler;
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
- ngx_add_timer(s->connection->read, pcf->timeout);
- ngx_del_timer(c->read);
-
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
-
- if (s->buffer->pos < s->buffer->last
- || s->connection->read->ready)
- {
- ngx_post_event(c->write, &ngx_posted_events);
- }
-
- ngx_mail_proxy_handler(s->connection->write);
-
- return;
-
- default:
-#if (NGX_SUPPRESS_WARN)
- ngx_str_null(&line);
-#endif
- break;
- }
-
- if (c->send(c, line.data, line.len) < (ssize_t) line.len) {
- /*
- * we treat the incomplete sending as NGX_ERROR
- * because it is very strange here
- */
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- s->proxy->buffer->pos = s->proxy->buffer->start;
- s->proxy->buffer->last = s->proxy->buffer->start;
-}
-
-
-static void
-ngx_mail_proxy_imap_handler(ngx_event_t *rev)
-{
- u_char *p;
- ngx_int_t rc;
- ngx_str_t line;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_proxy_conf_t *pcf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy imap auth handler");
-
- c = rev->data;
- s = c->data;
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
- "upstream timed out");
- c->timedout = 1;
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (s->proxy->proxy_protocol) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy imap busy");
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- rc = ngx_mail_proxy_read_response(s, s->mail_state);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- ngx_mail_proxy_upstream_error(s);
- return;
- }
-
- switch (s->mail_state) {
-
- case ngx_imap_start:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send login");
-
- s->connection->log->action = "sending LOGIN command to upstream";
-
- line.len = s->tag.len + sizeof("LOGIN ") - 1
- + 1 + NGX_SIZE_T_LEN + 1 + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- line.len = ngx_sprintf(line.data, "%VLOGIN {%uz}" CRLF,
- &s->tag, s->login.len)
- - line.data;
-
- s->mail_state = ngx_imap_login;
- break;
-
- case ngx_imap_login:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send user");
-
- s->connection->log->action = "sending user name to upstream";
-
- line.len = s->login.len + 1 + 1 + NGX_SIZE_T_LEN + 1 + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- line.len = ngx_sprintf(line.data, "%V {%uz}" CRLF,
- &s->login, s->passwd.len)
- - line.data;
-
- s->mail_state = ngx_imap_user;
- break;
-
- case ngx_imap_user:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send passwd");
-
- s->connection->log->action = "sending password to upstream";
-
- line.len = s->passwd.len + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, s->passwd.data, s->passwd.len);
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_imap_passwd;
- break;
-
- case ngx_imap_passwd:
- s->connection->read->handler = ngx_mail_proxy_handler;
- s->connection->write->handler = ngx_mail_proxy_handler;
- rev->handler = ngx_mail_proxy_handler;
- c->write->handler = ngx_mail_proxy_handler;
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
- ngx_add_timer(s->connection->read, pcf->timeout);
- ngx_del_timer(c->read);
-
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
-
- if (s->buffer->pos < s->buffer->last
- || s->connection->read->ready)
- {
- ngx_post_event(c->write, &ngx_posted_events);
- }
-
- ngx_mail_proxy_handler(s->connection->write);
-
- return;
-
- default:
-#if (NGX_SUPPRESS_WARN)
- ngx_str_null(&line);
-#endif
- break;
- }
-
- if (c->send(c, line.data, line.len) < (ssize_t) line.len) {
- /*
- * we treat the incomplete sending as NGX_ERROR
- * because it is very strange here
- */
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- s->proxy->buffer->pos = s->proxy->buffer->start;
- s->proxy->buffer->last = s->proxy->buffer->start;
-}
-
-
-static void
-ngx_mail_proxy_smtp_handler(ngx_event_t *rev)
-{
- u_char *p;
- ngx_int_t rc;
- ngx_str_t line, auth, encoded;
- ngx_buf_t *b;
- uintptr_t n;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_proxy_conf_t *pcf;
- ngx_mail_core_srv_conf_t *cscf;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy smtp auth handler");
-
- c = rev->data;
- s = c->data;
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
- "upstream timed out");
- c->timedout = 1;
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (s->proxy->proxy_protocol) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "mail proxy smtp busy");
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- rc = ngx_mail_proxy_read_response(s, s->mail_state);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- ngx_mail_proxy_upstream_error(s);
- return;
- }
-
- switch (s->mail_state) {
-
- case ngx_smtp_start:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0, "mail proxy send ehlo");
-
- s->connection->log->action = "sending HELO/EHLO to upstream";
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- line.len = sizeof("HELO ") - 1 + cscf->server_name.len + 2;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
-
- p = ngx_cpymem(line.data,
- ((s->esmtp || pcf->xclient) ? "EHLO " : "HELO "),
- sizeof("HELO ") - 1);
-
- p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
- *p++ = CR; *p = LF;
-
- if (pcf->xclient) {
- s->mail_state = ngx_smtp_helo_xclient;
-
- } else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
- s->mail_state = ngx_smtp_helo_from;
-
- } else if (pcf->smtp_auth) {
- s->mail_state = ngx_smtp_helo_auth;
-
- } else {
- s->mail_state = ngx_smtp_helo;
- }
-
- break;
-
- case ngx_smtp_helo_xclient:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send xclient");
-
- s->connection->log->action = "sending XCLIENT to upstream";
-
- line.len = sizeof("XCLIENT ADDR= LOGIN= NAME="
- CRLF) - 1
- + s->connection->addr_text.len + s->login.len + s->host.len;
-
- n = ngx_escape_uri(NULL, s->login.data, s->login.len,
- NGX_ESCAPE_MAIL_XTEXT);
- line.len += n * 2;
-
-#if (NGX_HAVE_INET6)
- if (s->connection->sockaddr->sa_family == AF_INET6) {
- line.len += sizeof("IPV6:") - 1;
- }
-#endif
-
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, "XCLIENT ADDR=", sizeof("XCLIENT ADDR=") - 1);
-
-#if (NGX_HAVE_INET6)
- if (s->connection->sockaddr->sa_family == AF_INET6) {
- p = ngx_cpymem(p, "IPV6:", sizeof("IPV6:") - 1);
- }
-#endif
-
- p = ngx_copy(p, s->connection->addr_text.data,
- s->connection->addr_text.len);
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
-
- if (s->login.len && !pcf->smtp_auth) {
- p = ngx_cpymem(p, " LOGIN=", sizeof(" LOGIN=") - 1);
-
- if (n == 0) {
- p = ngx_copy(p, s->login.data, s->login.len);
-
- } else {
- p = (u_char *) ngx_escape_uri(p, s->login.data, s->login.len,
- NGX_ESCAPE_MAIL_XTEXT);
- }
- }
-
- p = ngx_cpymem(p, " NAME=", sizeof(" NAME=") - 1);
- p = ngx_copy(p, s->host.data, s->host.len);
-
- *p++ = CR; *p++ = LF;
-
- line.len = p - line.data;
-
- if (s->smtp_helo.len) {
- s->mail_state = ngx_smtp_xclient_helo;
-
- } else if (s->auth_method == NGX_MAIL_AUTH_NONE) {
- s->mail_state = ngx_smtp_xclient_from;
-
- } else if (pcf->smtp_auth) {
- s->mail_state = ngx_smtp_xclient_auth;
-
- } else {
- s->mail_state = ngx_smtp_xclient;
- }
-
- break;
-
- case ngx_smtp_xclient_helo:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send client ehlo");
-
- s->connection->log->action = "sending client HELO/EHLO to upstream";
-
- line.len = sizeof("HELO " CRLF) - 1 + s->smtp_helo.len;
-
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- line.len = ngx_sprintf(line.data,
- ((s->esmtp) ? "EHLO %V" CRLF : "HELO %V" CRLF),
- &s->smtp_helo)
- - line.data;
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
-
- if (s->auth_method == NGX_MAIL_AUTH_NONE) {
- s->mail_state = ngx_smtp_helo_from;
-
- } else if (pcf->smtp_auth) {
- s->mail_state = ngx_smtp_helo_auth;
-
- } else {
- s->mail_state = ngx_smtp_helo;
- }
-
- break;
-
- case ngx_smtp_helo_auth:
- case ngx_smtp_xclient_auth:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send auth");
-
- s->connection->log->action = "sending AUTH to upstream";
-
- if (s->passwd.data == NULL) {
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "no password available");
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- auth.len = 1 + s->login.len + 1 + s->passwd.len;
- auth.data = ngx_pnalloc(c->pool, auth.len);
- if (auth.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- auth.len = ngx_sprintf(auth.data, "%Z%V%Z%V", &s->login, &s->passwd)
- - auth.data;
-
- line.len = sizeof("AUTH PLAIN " CRLF) - 1
- + ngx_base64_encoded_length(auth.len);
-
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- encoded.data = ngx_cpymem(line.data, "AUTH PLAIN ",
- sizeof("AUTH PLAIN ") - 1);
-
- ngx_encode_base64(&encoded, &auth);
-
- p = encoded.data + encoded.len;
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_smtp_auth_plain;
-
- break;
-
- case ngx_smtp_helo_from:
- case ngx_smtp_xclient_from:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send mail from");
-
- s->connection->log->action = "sending MAIL FROM to upstream";
-
- line.len = s->smtp_from.len + sizeof(CRLF) - 1;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, s->smtp_from.data, s->smtp_from.len);
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_smtp_from;
-
- break;
-
- case ngx_smtp_from:
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, rev->log, 0,
- "mail proxy send rcpt to");
-
- s->connection->log->action = "sending RCPT TO to upstream";
-
- line.len = s->smtp_to.len + sizeof(CRLF) - 1;
- line.data = ngx_pnalloc(c->pool, line.len);
- if (line.data == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- p = ngx_cpymem(line.data, s->smtp_to.data, s->smtp_to.len);
- *p++ = CR; *p = LF;
-
- s->mail_state = ngx_smtp_to;
-
- break;
-
- case ngx_smtp_helo:
- case ngx_smtp_xclient:
- case ngx_smtp_auth_plain:
- case ngx_smtp_to:
-
- b = s->proxy->buffer;
-
- if (s->auth_method == NGX_MAIL_AUTH_NONE) {
- b->pos = b->start;
-
- } else {
- ngx_memcpy(b->start, smtp_auth_ok, sizeof(smtp_auth_ok) - 1);
- b->last = b->start + sizeof(smtp_auth_ok) - 1;
- }
-
- s->connection->read->handler = ngx_mail_proxy_handler;
- s->connection->write->handler = ngx_mail_proxy_handler;
- rev->handler = ngx_mail_proxy_handler;
- c->write->handler = ngx_mail_proxy_handler;
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
- ngx_add_timer(s->connection->read, pcf->timeout);
- ngx_del_timer(c->read);
-
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "client logged in");
-
- if (s->buffer->pos < s->buffer->last
- || s->connection->read->ready)
- {
- ngx_post_event(c->write, &ngx_posted_events);
- }
-
- ngx_mail_proxy_handler(s->connection->write);
-
- return;
-
- default:
-#if (NGX_SUPPRESS_WARN)
- ngx_str_null(&line);
-#endif
- break;
- }
-
- if (c->send(c, line.data, line.len) < (ssize_t) line.len) {
- /*
- * we treat the incomplete sending as NGX_ERROR
- * because it is very strange here
- */
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return;
- }
-
- s->proxy->buffer->pos = s->proxy->buffer->start;
- s->proxy->buffer->last = s->proxy->buffer->start;
-}
-
-
-static void
-ngx_mail_proxy_write_handler(ngx_event_t *wev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, wev->log, 0, "mail proxy write handler");
-
- c = wev->data;
- s = c->data;
-
- if (s->proxy->proxy_protocol) {
- if (ngx_mail_proxy_send_proxy_protocol(s) != NGX_OK) {
- return;
- }
-
- s->proxy->proxy_protocol = 0;
- }
-
- if (ngx_handle_write_event(wev, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- }
-
- if (c->read->ready) {
- ngx_post_event(c->read, &ngx_posted_events);
- }
-}
-
-
-static ngx_int_t
-ngx_mail_proxy_send_proxy_protocol(ngx_mail_session_t *s)
-{
- u_char *p;
- ssize_t n, size;
- ngx_connection_t *c;
- u_char buf[NGX_PROXY_PROTOCOL_V1_MAX_HEADER];
-
- s->connection->log->action = "sending PROXY protocol header to upstream";
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "mail proxy send PROXY protocol header");
-
- p = ngx_proxy_protocol_write(s->connection, buf,
- buf + NGX_PROXY_PROTOCOL_V1_MAX_HEADER);
- if (p == NULL) {
- ngx_mail_proxy_internal_server_error(s);
- return NGX_ERROR;
- }
-
- c = s->proxy->upstream.connection;
-
- size = p - buf;
-
- n = c->send(c, buf, size);
-
- if (n == NGX_AGAIN) {
- if (ngx_handle_write_event(c->write, 0) != NGX_OK) {
- ngx_mail_proxy_internal_server_error(s);
- return NGX_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- if (n == NGX_ERROR) {
- ngx_mail_proxy_internal_server_error(s);
- return NGX_ERROR;
- }
-
- if (n != size) {
-
- /*
- * PROXY protocol specification:
- * The sender must always ensure that the header
- * is sent at once, so that the transport layer
- * maintains atomicity along the path to the receiver.
- */
-
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "could not send PROXY protocol header at once");
-
- ngx_mail_proxy_internal_server_error(s);
-
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_proxy_read_response(ngx_mail_session_t *s, ngx_uint_t state)
-{
- u_char *p, *m;
- ssize_t n;
- ngx_buf_t *b;
- ngx_mail_proxy_conf_t *pcf;
-
- s->connection->log->action = "reading response from upstream";
-
- b = s->proxy->buffer;
-
- n = s->proxy->upstream.connection->recv(s->proxy->upstream.connection,
- b->last, b->end - b->last);
-
- if (n == NGX_ERROR || n == 0) {
- return NGX_ERROR;
- }
-
- if (n == NGX_AGAIN) {
- return NGX_AGAIN;
- }
-
- b->last += n;
-
- if (b->last - b->pos < 4) {
- return NGX_AGAIN;
- }
-
- if (*(b->last - 2) != CR || *(b->last - 1) != LF) {
- if (b->last == b->end) {
- *(b->last - 1) = '\0';
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "upstream sent too long response line: \"%s\"",
- b->pos);
- return NGX_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- p = b->pos;
-
- switch (s->protocol) {
-
- case NGX_MAIL_POP3_PROTOCOL:
- if (p[0] == '+' && p[1] == 'O' && p[2] == 'K') {
- return NGX_OK;
- }
- break;
-
- case NGX_MAIL_IMAP_PROTOCOL:
- switch (state) {
-
- case ngx_imap_start:
- if (p[0] == '*' && p[1] == ' ' && p[2] == 'O' && p[3] == 'K') {
- return NGX_OK;
- }
- break;
-
- case ngx_imap_login:
- case ngx_imap_user:
- if (p[0] == '+') {
- return NGX_OK;
- }
- break;
-
- case ngx_imap_passwd:
-
- /*
- * untagged CAPABILITY response (draft-crispin-imapv-16),
- * known to be sent by SmarterMail and Gmail
- */
-
- if (p[0] == '*' && p[1] == ' ') {
- p += 2;
-
- while (p < b->last - 1) {
- if (p[0] == CR && p[1] == LF) {
- p += 2;
- break;
- }
-
- p++;
- }
-
- if (b->last - p < 4) {
- return NGX_AGAIN;
- }
- }
-
- if (ngx_strncmp(p, s->tag.data, s->tag.len) == 0) {
- p += s->tag.len;
- if (p[0] == 'O' && p[1] == 'K') {
- return NGX_OK;
- }
- }
-
- break;
- }
-
- break;
-
- default: /* NGX_MAIL_SMTP_PROTOCOL */
-
- if (p[3] == '-') {
- /* multiline reply, check if we got last line */
-
- m = b->last - (sizeof(CRLF "200" CRLF) - 1);
-
- while (m > p) {
- if (m[0] == CR && m[1] == LF) {
- break;
- }
-
- m--;
- }
-
- if (m <= p || m[5] == '-') {
- return NGX_AGAIN;
- }
- }
-
- switch (state) {
-
- case ngx_smtp_start:
- if (p[0] == '2' && p[1] == '2' && p[2] == '0') {
- return NGX_OK;
- }
- break;
-
- case ngx_smtp_helo:
- case ngx_smtp_helo_xclient:
- case ngx_smtp_helo_from:
- case ngx_smtp_helo_auth:
- case ngx_smtp_from:
- if (p[0] == '2' && p[1] == '5' && p[2] == '0') {
- return NGX_OK;
- }
- break;
-
- case ngx_smtp_xclient:
- case ngx_smtp_xclient_from:
- case ngx_smtp_xclient_helo:
- case ngx_smtp_xclient_auth:
- if (p[0] == '2' && (p[1] == '2' || p[1] == '5') && p[2] == '0') {
- return NGX_OK;
- }
- break;
-
- case ngx_smtp_auth_plain:
- if (p[0] == '2' && p[1] == '3' && p[2] == '5') {
- return NGX_OK;
- }
- break;
-
- case ngx_smtp_to:
- return NGX_OK;
- }
-
- break;
- }
-
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
-
- if (pcf->pass_error_message == 0) {
- *(b->last - 2) = '\0';
- ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
- "upstream sent invalid response: \"%s\"", p);
- return NGX_ERROR;
- }
-
- s->out.len = b->last - p - 2;
- s->out.data = p;
-
- ngx_log_error(NGX_LOG_INFO, s->connection->log, 0,
- "upstream sent invalid response: \"%V\"", &s->out);
-
- s->out.len = b->last - b->pos;
- s->out.data = b->pos;
-
- return NGX_ERROR;
-}
-
-
-static void
-ngx_mail_proxy_handler(ngx_event_t *ev)
-{
- char *action, *recv_action, *send_action;
- size_t size;
- ssize_t n;
- ngx_buf_t *b;
- ngx_uint_t do_write;
- ngx_connection_t *c, *src, *dst;
- ngx_mail_session_t *s;
- ngx_mail_proxy_conf_t *pcf;
-
- c = ev->data;
- s = c->data;
-
- if (ev->timedout || c->close) {
- c->log->action = "proxying";
-
- if (c->close) {
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout");
-
- } else if (c == s->connection) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
- "client timed out");
- c->timedout = 1;
-
- } else {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
- "upstream timed out");
- }
-
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (c == s->connection) {
- if (ev->write) {
- recv_action = "proxying and reading from upstream";
- send_action = "proxying and sending to client";
- src = s->proxy->upstream.connection;
- dst = c;
- b = s->proxy->buffer;
-
- } else {
- recv_action = "proxying and reading from client";
- send_action = "proxying and sending to upstream";
- src = c;
- dst = s->proxy->upstream.connection;
- b = s->buffer;
- }
-
- } else {
- if (ev->write) {
- recv_action = "proxying and reading from client";
- send_action = "proxying and sending to upstream";
- src = s->connection;
- dst = c;
- b = s->buffer;
-
- } else {
- recv_action = "proxying and reading from upstream";
- send_action = "proxying and sending to client";
- src = c;
- dst = s->connection;
- b = s->proxy->buffer;
- }
- }
-
- do_write = ev->write ? 1 : 0;
-
- ngx_log_debug3(NGX_LOG_DEBUG_MAIL, ev->log, 0,
- "mail proxy handler: %ui, #%d > #%d",
- do_write, src->fd, dst->fd);
-
- for ( ;; ) {
-
- if (do_write) {
-
- size = b->last - b->pos;
-
- if (size && dst->write->ready) {
- c->log->action = send_action;
-
- n = dst->send(dst, b->pos, size);
-
- if (n == NGX_ERROR) {
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (n > 0) {
- b->pos += n;
-
- if (b->pos == b->last) {
- b->pos = b->start;
- b->last = b->start;
- }
- }
- }
- }
-
- size = b->end - b->last;
-
- if (size && src->read->ready) {
- c->log->action = recv_action;
-
- n = src->recv(src, b->last, size);
-
- if (n == NGX_AGAIN || n == 0) {
- break;
- }
-
- if (n > 0) {
- do_write = 1;
- b->last += n;
-
- continue;
- }
-
- if (n == NGX_ERROR) {
- src->read->eof = 1;
- }
- }
-
- break;
- }
-
- c->log->action = "proxying";
-
- if ((s->connection->read->eof && s->buffer->pos == s->buffer->last)
- || (s->proxy->upstream.connection->read->eof
- && s->proxy->buffer->pos == s->proxy->buffer->last)
- || (s->connection->read->eof
- && s->proxy->upstream.connection->read->eof))
- {
- action = c->log->action;
- c->log->action = NULL;
- ngx_log_error(NGX_LOG_INFO, c->log, 0, "proxied session done");
- c->log->action = action;
-
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (ngx_handle_write_event(dst->write, 0) != NGX_OK) {
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (ngx_handle_read_event(dst->read, 0) != NGX_OK) {
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (ngx_handle_write_event(src->write, 0) != NGX_OK) {
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (ngx_handle_read_event(src->read, 0) != NGX_OK) {
- ngx_mail_proxy_close_session(s);
- return;
- }
-
- if (c == s->connection) {
- pcf = ngx_mail_get_module_srv_conf(s, ngx_mail_proxy_module);
- ngx_add_timer(c->read, pcf->timeout);
- }
-}
-
-
-static void
-ngx_mail_proxy_upstream_error(ngx_mail_session_t *s)
-{
- if (s->proxy->upstream.connection) {
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "close mail proxy connection: %d",
- s->proxy->upstream.connection->fd);
-
- ngx_close_connection(s->proxy->upstream.connection);
- }
-
- if (s->out.len == 0) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- s->quit = 1;
- ngx_mail_send(s->connection->write);
-}
-
-
-static void
-ngx_mail_proxy_internal_server_error(ngx_mail_session_t *s)
-{
- if (s->proxy->upstream.connection) {
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "close mail proxy connection: %d",
- s->proxy->upstream.connection->fd);
-
- ngx_close_connection(s->proxy->upstream.connection);
- }
-
- ngx_mail_session_internal_server_error(s);
-}
-
-
-static void
-ngx_mail_proxy_close_session(ngx_mail_session_t *s)
-{
- if (s->proxy->upstream.connection) {
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, s->connection->log, 0,
- "close mail proxy connection: %d",
- s->proxy->upstream.connection->fd);
-
- ngx_close_connection(s->proxy->upstream.connection);
- }
-
- ngx_mail_close_connection(s->connection);
-}
-
-
-static void *
-ngx_mail_proxy_create_conf(ngx_conf_t *cf)
-{
- ngx_mail_proxy_conf_t *pcf;
-
- pcf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_proxy_conf_t));
- if (pcf == NULL) {
- return NULL;
- }
-
- pcf->enable = NGX_CONF_UNSET;
- pcf->pass_error_message = NGX_CONF_UNSET;
- pcf->xclient = NGX_CONF_UNSET;
- pcf->smtp_auth = NGX_CONF_UNSET;
- pcf->proxy_protocol = NGX_CONF_UNSET;
- pcf->buffer_size = NGX_CONF_UNSET_SIZE;
- pcf->timeout = NGX_CONF_UNSET_MSEC;
-
- return pcf;
-}
-
-
-static char *
-ngx_mail_proxy_merge_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_proxy_conf_t *prev = parent;
- ngx_mail_proxy_conf_t *conf = child;
-
- ngx_conf_merge_value(conf->enable, prev->enable, 0);
- ngx_conf_merge_value(conf->pass_error_message, prev->pass_error_message, 0);
- ngx_conf_merge_value(conf->xclient, prev->xclient, 1);
- ngx_conf_merge_value(conf->smtp_auth, prev->smtp_auth, 0);
- ngx_conf_merge_value(conf->proxy_protocol, prev->proxy_protocol, 0);
- ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size,
- (size_t) ngx_pagesize);
- ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 24 * 60 * 60000);
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_realip_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_realip_module.c
deleted file mode 100644
index c93d7d33c1..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_realip_module.c
+++ /dev/null
@@ -1,269 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_array_t *from; /* array of ngx_cidr_t */
-} ngx_mail_realip_srv_conf_t;
-
-
-static ngx_int_t ngx_mail_realip_set_addr(ngx_mail_session_t *s,
- ngx_addr_t *addr);
-static char *ngx_mail_realip_from(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static void *ngx_mail_realip_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_mail_realip_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-
-static ngx_command_t ngx_mail_realip_commands[] = {
-
- { ngx_string("set_real_ip_from"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_mail_realip_from,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_realip_module_ctx = {
- NULL, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_realip_create_srv_conf, /* create server configuration */
- ngx_mail_realip_merge_srv_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_realip_module = {
- NGX_MODULE_V1,
- &ngx_mail_realip_module_ctx, /* module context */
- ngx_mail_realip_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-ngx_int_t
-ngx_mail_realip_handler(ngx_mail_session_t *s)
-{
- ngx_addr_t addr;
- ngx_connection_t *c;
- ngx_mail_realip_srv_conf_t *rscf;
-
- rscf = ngx_mail_get_module_srv_conf(s, ngx_mail_realip_module);
-
- if (rscf->from == NULL) {
- return NGX_OK;
- }
-
- c = s->connection;
-
- if (c->proxy_protocol == NULL) {
- return NGX_OK;
- }
-
- if (ngx_cidr_match(c->sockaddr, rscf->from) != NGX_OK) {
- return NGX_OK;
- }
-
- if (ngx_parse_addr(c->pool, &addr, c->proxy_protocol->src_addr.data,
- c->proxy_protocol->src_addr.len)
- != NGX_OK)
- {
- return NGX_OK;
- }
-
- ngx_inet_set_port(addr.sockaddr, c->proxy_protocol->src_port);
-
- return ngx_mail_realip_set_addr(s, &addr);
-}
-
-
-static ngx_int_t
-ngx_mail_realip_set_addr(ngx_mail_session_t *s, ngx_addr_t *addr)
-{
- size_t len;
- u_char *p;
- u_char text[NGX_SOCKADDR_STRLEN];
- ngx_connection_t *c;
-
- c = s->connection;
-
- len = ngx_sock_ntop(addr->sockaddr, addr->socklen, text,
- NGX_SOCKADDR_STRLEN, 0);
- if (len == 0) {
- return NGX_ERROR;
- }
-
- p = ngx_pnalloc(c->pool, len);
- if (p == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(p, text, len);
-
- c->sockaddr = addr->sockaddr;
- c->socklen = addr->socklen;
- c->addr_text.len = len;
- c->addr_text.data = p;
-
- return NGX_OK;
-}
-
-
-static char *
-ngx_mail_realip_from(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_realip_srv_conf_t *rscf = conf;
-
- ngx_int_t rc;
- ngx_str_t *value;
- ngx_url_t u;
- ngx_cidr_t c, *cidr;
- ngx_uint_t i;
- struct sockaddr_in *sin;
-#if (NGX_HAVE_INET6)
- struct sockaddr_in6 *sin6;
-#endif
-
- value = cf->args->elts;
-
- if (rscf->from == NULL) {
- rscf->from = ngx_array_create(cf->pool, 2,
- sizeof(ngx_cidr_t));
- if (rscf->from == NULL) {
- return NGX_CONF_ERROR;
- }
- }
-
-#if (NGX_HAVE_UNIX_DOMAIN)
-
- if (ngx_strcmp(value[1].data, "unix:") == 0) {
- cidr = ngx_array_push(rscf->from);
- if (cidr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- cidr->family = AF_UNIX;
- return NGX_CONF_OK;
- }
-
-#endif
-
- rc = ngx_ptocidr(&value[1], &c);
-
- if (rc != NGX_ERROR) {
- if (rc == NGX_DONE) {
- ngx_conf_log_error(NGX_LOG_WARN, cf, 0,
- "low address bits of %V are meaningless",
- &value[1]);
- }
-
- cidr = ngx_array_push(rscf->from);
- if (cidr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- *cidr = c;
-
- return NGX_CONF_OK;
- }
-
- ngx_memzero(&u, sizeof(ngx_url_t));
- u.host = value[1];
-
- if (ngx_inet_resolve_host(cf->pool, &u) != NGX_OK) {
- if (u.err) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "%s in set_real_ip_from \"%V\"",
- u.err, &u.host);
- }
-
- return NGX_CONF_ERROR;
- }
-
- cidr = ngx_array_push_n(rscf->from, u.naddrs);
- if (cidr == NULL) {
- return NGX_CONF_ERROR;
- }
-
- ngx_memzero(cidr, u.naddrs * sizeof(ngx_cidr_t));
-
- for (i = 0; i < u.naddrs; i++) {
- cidr[i].family = u.addrs[i].sockaddr->sa_family;
-
- switch (cidr[i].family) {
-
-#if (NGX_HAVE_INET6)
- case AF_INET6:
- sin6 = (struct sockaddr_in6 *) u.addrs[i].sockaddr;
- cidr[i].u.in6.addr = sin6->sin6_addr;
- ngx_memset(cidr[i].u.in6.mask.s6_addr, 0xff, 16);
- break;
-#endif
-
- default: /* AF_INET */
- sin = (struct sockaddr_in *) u.addrs[i].sockaddr;
- cidr[i].u.in.addr = sin->sin_addr.s_addr;
- cidr[i].u.in.mask = 0xffffffff;
- break;
- }
- }
-
- return NGX_CONF_OK;
-}
-
-
-static void *
-ngx_mail_realip_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_mail_realip_srv_conf_t *conf;
-
- conf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_realip_srv_conf_t));
- if (conf == NULL) {
- return NULL;
- }
-
- /*
- * set by ngx_pcalloc():
- *
- * conf->from = NULL;
- */
-
- return conf;
-}
-
-
-static char *
-ngx_mail_realip_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_realip_srv_conf_t *prev = parent;
- ngx_mail_realip_srv_conf_t *conf = child;
-
- if (conf->from == NULL) {
- conf->from = prev->from;
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_handler.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_handler.c
deleted file mode 100644
index 97bbd70631..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_handler.c
+++ /dev/null
@@ -1,983 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static void ngx_mail_smtp_resolve_addr_handler(ngx_resolver_ctx_t *ctx);
-static ngx_int_t ngx_mail_smtp_validate_host(ngx_str_t *name);
-static void ngx_mail_smtp_resolve_name(ngx_event_t *rev);
-static void ngx_mail_smtp_resolve_name_handler(ngx_resolver_ctx_t *ctx);
-static void ngx_mail_smtp_block_reading(ngx_event_t *rev);
-static void ngx_mail_smtp_greeting(ngx_mail_session_t *s, ngx_connection_t *c);
-static void ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev);
-static ngx_int_t ngx_mail_smtp_create_buffer(ngx_mail_session_t *s,
- ngx_connection_t *c);
-
-static ngx_int_t ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_smtp_starttls(ngx_mail_session_t *s,
- ngx_connection_t *c);
-static ngx_int_t ngx_mail_smtp_rset(ngx_mail_session_t *s, ngx_connection_t *c);
-static ngx_int_t ngx_mail_smtp_rcpt(ngx_mail_session_t *s, ngx_connection_t *c);
-
-static ngx_int_t ngx_mail_smtp_discard_command(ngx_mail_session_t *s,
- ngx_connection_t *c, char *err);
-static void ngx_mail_smtp_log_rejected_command(ngx_mail_session_t *s,
- ngx_connection_t *c, char *err);
-
-
-static u_char smtp_ok[] = "250 2.0.0 OK" CRLF;
-static u_char smtp_bye[] = "221 2.0.0 Bye" CRLF;
-static u_char smtp_starttls[] = "220 2.0.0 Start TLS" CRLF;
-static u_char smtp_next[] = "334 " CRLF;
-static u_char smtp_username[] = "334 VXNlcm5hbWU6" CRLF;
-static u_char smtp_password[] = "334 UGFzc3dvcmQ6" CRLF;
-static u_char smtp_invalid_command[] = "500 5.5.1 Invalid command" CRLF;
-static u_char smtp_invalid_pipelining[] =
- "503 5.5.0 Improper use of SMTP command pipelining" CRLF;
-static u_char smtp_invalid_argument[] = "501 5.5.4 Invalid argument" CRLF;
-static u_char smtp_auth_required[] = "530 5.7.1 Authentication required" CRLF;
-static u_char smtp_bad_sequence[] = "503 5.5.1 Bad sequence of commands" CRLF;
-
-
-static ngx_str_t smtp_unavailable = ngx_string("[UNAVAILABLE]");
-static ngx_str_t smtp_tempunavail = ngx_string("[TEMPUNAVAIL]");
-
-
-void
-ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_resolver_ctx_t *ctx;
- ngx_mail_core_srv_conf_t *cscf;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- if (cscf->resolver == NULL) {
- s->host = smtp_unavailable;
- ngx_mail_smtp_greeting(s, c);
- return;
- }
-
-#if (NGX_HAVE_UNIX_DOMAIN)
- if (c->sockaddr->sa_family == AF_UNIX) {
- s->host = smtp_tempunavail;
- ngx_mail_smtp_greeting(s, c);
- return;
- }
-#endif
-
- c->log->action = "in resolving client address";
-
- ctx = ngx_resolve_start(cscf->resolver, NULL);
- if (ctx == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
-
- ctx->addr.sockaddr = c->sockaddr;
- ctx->addr.socklen = c->socklen;
- ctx->handler = ngx_mail_smtp_resolve_addr_handler;
- ctx->data = s;
- ctx->timeout = cscf->resolver_timeout;
-
- s->resolver_ctx = ctx;
- c->read->handler = ngx_mail_smtp_block_reading;
-
- if (ngx_resolve_addr(ctx) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-}
-
-
-static void
-ngx_mail_smtp_resolve_addr_handler(ngx_resolver_ctx_t *ctx)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- s = ctx->data;
- c = s->connection;
-
- if (ctx->state) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "%V could not be resolved (%i: %s)",
- &c->addr_text, ctx->state,
- ngx_resolver_strerror(ctx->state));
-
- if (ctx->state == NGX_RESOLVE_NXDOMAIN) {
- s->host = smtp_unavailable;
-
- } else {
- s->host = smtp_tempunavail;
- }
-
- ngx_resolve_addr_done(ctx);
-
- ngx_mail_smtp_greeting(s, s->connection);
-
- return;
- }
-
- if (ngx_mail_smtp_validate_host(&ctx->name) != NGX_OK) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "%V resolved to invalid host name \"%V\"",
- &c->addr_text, &ctx->name);
-
- s->host = smtp_tempunavail;
-
- ngx_resolve_addr_done(ctx);
-
- ngx_mail_smtp_greeting(s, s->connection);
-
- return;
- }
-
- c->log->action = "in resolving client hostname";
-
- s->host.data = ngx_pstrdup(c->pool, &ctx->name);
- if (s->host.data == NULL) {
- ngx_resolve_addr_done(ctx);
- ngx_mail_close_connection(c);
- return;
- }
-
- s->host.len = ctx->name.len;
-
- ngx_resolve_addr_done(ctx);
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "address resolved: %V", &s->host);
-
- c->read->handler = ngx_mail_smtp_resolve_name;
-
- ngx_post_event(c->read, &ngx_posted_events);
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_validate_host(ngx_str_t *name)
-{
- u_char ch;
- ngx_uint_t i;
-
- if (name->len == 0) {
- return NGX_DECLINED;
- }
-
- for (i = 0; i < name->len; i++) {
- ch = name->data[i];
-
- /* allow only characters from RFC 1034, Section 3.5 */
-
- if ((ch >= 'a' && ch <= 'z')
- || (ch >= 'A' && ch <= 'Z')
- || (ch >= '0' && ch <= '9')
- || ch == '-' || ch == '.')
- {
- continue;
- }
-
- return NGX_DECLINED;
- }
-
- return NGX_OK;
-}
-
-
-static void
-ngx_mail_smtp_resolve_name(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_resolver_ctx_t *ctx;
- ngx_mail_core_srv_conf_t *cscf;
-
- c = rev->data;
- s = c->data;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- ctx = ngx_resolve_start(cscf->resolver, NULL);
- if (ctx == NULL) {
- ngx_mail_close_connection(c);
- return;
- }
-
- ctx->name = s->host;
- ctx->handler = ngx_mail_smtp_resolve_name_handler;
- ctx->data = s;
- ctx->timeout = cscf->resolver_timeout;
-
- s->resolver_ctx = ctx;
- c->read->handler = ngx_mail_smtp_block_reading;
-
- if (ngx_resolve_name(ctx) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-}
-
-
-static void
-ngx_mail_smtp_resolve_name_handler(ngx_resolver_ctx_t *ctx)
-{
- ngx_uint_t i;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- s = ctx->data;
- c = s->connection;
-
- if (ctx->state) {
- ngx_log_error(NGX_LOG_ERR, c->log, 0,
- "\"%V\" could not be resolved (%i: %s)",
- &ctx->name, ctx->state,
- ngx_resolver_strerror(ctx->state));
-
- if (ctx->state == NGX_RESOLVE_NXDOMAIN) {
- s->host = smtp_unavailable;
-
- } else {
- s->host = smtp_tempunavail;
- }
-
- } else {
-
-#if (NGX_DEBUG)
- {
- u_char text[NGX_SOCKADDR_STRLEN];
- ngx_str_t addr;
-
- addr.data = text;
-
- for (i = 0; i < ctx->naddrs; i++) {
- addr.len = ngx_sock_ntop(ctx->addrs[i].sockaddr,
- ctx->addrs[i].socklen,
- text, NGX_SOCKADDR_STRLEN, 0);
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "name was resolved to %V", &addr);
- }
- }
-#endif
-
- for (i = 0; i < ctx->naddrs; i++) {
- if (ngx_cmp_sockaddr(ctx->addrs[i].sockaddr, ctx->addrs[i].socklen,
- c->sockaddr, c->socklen, 0)
- == NGX_OK)
- {
- goto found;
- }
- }
-
- s->host = smtp_unavailable;
- }
-
-found:
-
- ngx_resolve_name_done(ctx);
-
- ngx_mail_smtp_greeting(s, c);
-}
-
-
-static void
-ngx_mail_smtp_block_reading(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_resolver_ctx_t *ctx;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "smtp reading blocked");
-
- if (ngx_handle_read_event(rev, 0) != NGX_OK) {
-
- if (s->resolver_ctx) {
- ctx = s->resolver_ctx;
-
- if (ctx->handler == ngx_mail_smtp_resolve_addr_handler) {
- ngx_resolve_addr_done(ctx);
-
- } else if (ctx->handler == ngx_mail_smtp_resolve_name_handler) {
- ngx_resolve_name_done(ctx);
- }
-
- s->resolver_ctx = NULL;
- }
-
- ngx_mail_close_connection(c);
- }
-}
-
-
-static void
-ngx_mail_smtp_greeting(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_msec_t timeout;
- ngx_mail_core_srv_conf_t *cscf;
- ngx_mail_smtp_srv_conf_t *sscf;
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "smtp greeting for \"%V\"", &s->host);
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- timeout = sscf->greeting_delay ? sscf->greeting_delay : cscf->timeout;
- ngx_add_timer(c->read, timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- }
-
- if (c->read->ready) {
- ngx_post_event(c->read, &ngx_posted_events);
- }
-
- if (sscf->greeting_delay) {
- c->read->handler = ngx_mail_smtp_invalid_pipelining;
- return;
- }
-
- c->read->handler = ngx_mail_smtp_init_protocol;
-
- s->out = sscf->greeting;
-
- ngx_mail_send(c->write);
-}
-
-
-static void
-ngx_mail_smtp_invalid_pipelining(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
- ngx_mail_smtp_srv_conf_t *sscf;
-
- c = rev->data;
- s = c->data;
-
- c->log->action = "in delay pipelining state";
-
- if (rev->timedout) {
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "delay greeting");
-
- rev->timedout = 0;
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- c->read->handler = ngx_mail_smtp_init_protocol;
-
- ngx_add_timer(c->read, cscf->timeout);
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- s->out = sscf->greeting;
-
- } else {
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "invalid pipelining");
-
- if (s->buffer == NULL) {
- if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
- return;
- }
- }
-
- if (ngx_mail_smtp_discard_command(s, c,
- "client was rejected before greeting: \"%V\"")
- != NGX_OK)
- {
- return;
- }
-
- ngx_str_set(&s->out, smtp_invalid_pipelining);
- s->quit = 1;
- }
-
- ngx_mail_send(c->write);
-}
-
-
-void
-ngx_mail_smtp_init_protocol(ngx_event_t *rev)
-{
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- c = rev->data;
-
- c->log->action = "in auth state";
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- s = c->data;
-
- if (s->buffer == NULL) {
- if (ngx_mail_smtp_create_buffer(s, c) != NGX_OK) {
- return;
- }
- }
-
- s->mail_state = ngx_smtp_start;
- c->read->handler = ngx_mail_smtp_auth_state;
-
- ngx_mail_smtp_auth_state(rev);
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_create_buffer(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_mail_smtp_srv_conf_t *sscf;
-
- if (ngx_array_init(&s->args, c->pool, 2, sizeof(ngx_str_t)) == NGX_ERROR) {
- ngx_mail_session_internal_server_error(s);
- return NGX_ERROR;
- }
-
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- s->buffer = ngx_create_temp_buf(c->pool, sscf->client_buffer_size);
- if (s->buffer == NULL) {
- ngx_mail_session_internal_server_error(s);
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-void
-ngx_mail_smtp_auth_state(ngx_event_t *rev)
-{
- ngx_int_t rc;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
-
- c = rev->data;
- s = c->data;
-
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "smtp auth state");
-
- if (rev->timedout) {
- ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out");
- c->timedout = 1;
- ngx_mail_close_connection(c);
- return;
- }
-
- if (s->out.len) {
- ngx_log_debug0(NGX_LOG_DEBUG_MAIL, c->log, 0, "smtp send handler busy");
- s->blocked = 1;
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_close_connection(c);
- return;
- }
-
- return;
- }
-
- s->blocked = 0;
-
- rc = ngx_mail_read_command(s, c);
-
- if (rc == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- return;
- }
-
- if (rc == NGX_ERROR) {
- return;
- }
-
- ngx_str_set(&s->out, smtp_ok);
-
- if (rc == NGX_OK) {
- switch (s->mail_state) {
-
- case ngx_smtp_start:
-
- switch (s->command) {
-
- case NGX_SMTP_HELO:
- case NGX_SMTP_EHLO:
- rc = ngx_mail_smtp_helo(s, c);
- break;
-
- case NGX_SMTP_AUTH:
- rc = ngx_mail_smtp_auth(s, c);
- break;
-
- case NGX_SMTP_QUIT:
- s->quit = 1;
- ngx_str_set(&s->out, smtp_bye);
- break;
-
- case NGX_SMTP_MAIL:
- rc = ngx_mail_smtp_mail(s, c);
- break;
-
- case NGX_SMTP_RCPT:
- rc = ngx_mail_smtp_rcpt(s, c);
- break;
-
- case NGX_SMTP_RSET:
- rc = ngx_mail_smtp_rset(s, c);
- break;
-
- case NGX_SMTP_NOOP:
- break;
-
- case NGX_SMTP_STARTTLS:
- rc = ngx_mail_smtp_starttls(s, c);
- ngx_str_set(&s->out, smtp_starttls);
- break;
-
- default:
- rc = NGX_MAIL_PARSE_INVALID_COMMAND;
- break;
- }
-
- break;
-
- case ngx_smtp_auth_login_username:
- rc = ngx_mail_auth_login_username(s, c, 0);
-
- ngx_str_set(&s->out, smtp_password);
- s->mail_state = ngx_smtp_auth_login_password;
- break;
-
- case ngx_smtp_auth_login_password:
- rc = ngx_mail_auth_login_password(s, c);
- break;
-
- case ngx_smtp_auth_plain:
- rc = ngx_mail_auth_plain(s, c, 0);
- break;
-
- case ngx_smtp_auth_cram_md5:
- rc = ngx_mail_auth_cram_md5(s, c);
- break;
-
- case ngx_smtp_auth_external:
- rc = ngx_mail_auth_external(s, c, 0);
- break;
- }
- }
-
- if (s->buffer->pos < s->buffer->last) {
- s->blocked = 1;
- }
-
- switch (rc) {
-
- case NGX_DONE:
- ngx_mail_auth(s, c);
- return;
-
- case NGX_ERROR:
- ngx_mail_session_internal_server_error(s);
- return;
-
- case NGX_MAIL_PARSE_INVALID_COMMAND:
- s->mail_state = ngx_smtp_start;
- s->state = 0;
- ngx_str_set(&s->out, smtp_invalid_command);
-
- /* fall through */
-
- case NGX_OK:
- s->args.nelts = 0;
-
- if (s->buffer->pos == s->buffer->last) {
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
- }
-
- if (s->state) {
- s->arg_start = s->buffer->pos;
- }
-
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return;
- }
-
- ngx_mail_send(c->write);
- }
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_helo(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg;
- ngx_mail_smtp_srv_conf_t *sscf;
-
- if (s->args.nelts != 1) {
- ngx_str_set(&s->out, smtp_invalid_argument);
- s->state = 0;
- return NGX_OK;
- }
-
- arg = s->args.elts;
-
- s->smtp_helo.len = arg[0].len;
-
- s->smtp_helo.data = ngx_pnalloc(c->pool, arg[0].len);
- if (s->smtp_helo.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->smtp_helo.data, arg[0].data, arg[0].len);
-
- ngx_str_null(&s->smtp_from);
- ngx_str_null(&s->smtp_to);
-
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- if (s->command == NGX_SMTP_HELO) {
- s->out = sscf->server_name;
-
- } else {
- s->esmtp = 1;
-
-#if (NGX_MAIL_SSL)
-
- if (c->ssl == NULL) {
- ngx_mail_ssl_conf_t *sslcf;
-
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ON) {
- s->out = sscf->starttls_capability;
- return NGX_OK;
- }
-
- if (sslcf->starttls == NGX_MAIL_STARTTLS_ONLY) {
- s->out = sscf->starttls_only_capability;
- return NGX_OK;
- }
- }
-#endif
-
- s->out = sscf->capability;
- }
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_auth(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_int_t rc;
- ngx_mail_core_srv_conf_t *cscf;
- ngx_mail_smtp_srv_conf_t *sscf;
-
-#if (NGX_MAIL_SSL)
- if (ngx_mail_starttls_only(s, c)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-#endif
-
- if (s->args.nelts == 0) {
- ngx_str_set(&s->out, smtp_invalid_argument);
- s->state = 0;
- return NGX_OK;
- }
-
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- rc = ngx_mail_auth_parse(s, c);
-
- switch (rc) {
-
- case NGX_MAIL_AUTH_LOGIN:
-
- ngx_str_set(&s->out, smtp_username);
- s->mail_state = ngx_smtp_auth_login_username;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_LOGIN_USERNAME:
-
- ngx_str_set(&s->out, smtp_password);
- s->mail_state = ngx_smtp_auth_login_password;
-
- return ngx_mail_auth_login_username(s, c, 1);
-
- case NGX_MAIL_AUTH_PLAIN:
-
- ngx_str_set(&s->out, smtp_next);
- s->mail_state = ngx_smtp_auth_plain;
-
- return NGX_OK;
-
- case NGX_MAIL_AUTH_CRAM_MD5:
-
- if (!(sscf->auth_methods & NGX_MAIL_AUTH_CRAM_MD5_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- if (s->salt.data == NULL) {
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- if (ngx_mail_salt(s, c, cscf) != NGX_OK) {
- return NGX_ERROR;
- }
- }
-
- if (ngx_mail_auth_cram_md5_salt(s, c, "334 ", 4) == NGX_OK) {
- s->mail_state = ngx_smtp_auth_cram_md5;
- return NGX_OK;
- }
-
- return NGX_ERROR;
-
- case NGX_MAIL_AUTH_EXTERNAL:
-
- if (!(sscf->auth_methods & NGX_MAIL_AUTH_EXTERNAL_ENABLED)) {
- return NGX_MAIL_PARSE_INVALID_COMMAND;
- }
-
- ngx_str_set(&s->out, smtp_username);
- s->mail_state = ngx_smtp_auth_external;
-
- return NGX_OK;
- }
-
- return rc;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_mail(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg, cmd;
- ngx_mail_smtp_srv_conf_t *sscf;
-
- sscf = ngx_mail_get_module_srv_conf(s, ngx_mail_smtp_module);
-
- if (!(sscf->auth_methods & NGX_MAIL_AUTH_NONE_ENABLED)) {
- ngx_mail_smtp_log_rejected_command(s, c, "client was rejected: \"%V\"");
- ngx_str_set(&s->out, smtp_auth_required);
- return NGX_OK;
- }
-
- /* auth none */
-
- if (s->smtp_from.len) {
- ngx_str_set(&s->out, smtp_bad_sequence);
- return NGX_OK;
- }
-
- if (s->args.nelts == 0) {
- ngx_str_set(&s->out, smtp_invalid_argument);
- return NGX_OK;
- }
-
- arg = s->args.elts;
- arg += s->args.nelts - 1;
-
- cmd.len = arg->data + arg->len - s->cmd.data;
- cmd.data = s->cmd.data;
-
- s->smtp_from.len = cmd.len;
-
- s->smtp_from.data = ngx_pnalloc(c->pool, cmd.len);
- if (s->smtp_from.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->smtp_from.data, cmd.data, cmd.len);
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "smtp mail from:\"%V\"", &s->smtp_from);
-
- ngx_str_set(&s->out, smtp_ok);
-
- ngx_str_null(&s->login);
- ngx_str_null(&s->passwd);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_rcpt(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_t *arg, cmd;
-
- if (s->smtp_from.len == 0) {
- ngx_str_set(&s->out, smtp_bad_sequence);
- return NGX_OK;
- }
-
- if (s->args.nelts == 0) {
- ngx_str_set(&s->out, smtp_invalid_argument);
- return NGX_OK;
- }
-
- arg = s->args.elts;
- arg += s->args.nelts - 1;
-
- cmd.len = arg->data + arg->len - s->cmd.data;
- cmd.data = s->cmd.data;
-
- s->smtp_to.len = cmd.len;
-
- s->smtp_to.data = ngx_pnalloc(c->pool, cmd.len);
- if (s->smtp_to.data == NULL) {
- return NGX_ERROR;
- }
-
- ngx_memcpy(s->smtp_to.data, cmd.data, cmd.len);
-
- ngx_log_debug1(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "smtp rcpt to:\"%V\"", &s->smtp_to);
-
- s->auth_method = NGX_MAIL_AUTH_NONE;
-
- return NGX_DONE;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_rset(ngx_mail_session_t *s, ngx_connection_t *c)
-{
- ngx_str_null(&s->smtp_from);
- ngx_str_null(&s->smtp_to);
- ngx_str_set(&s->out, smtp_ok);
-
- return NGX_OK;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_starttls(ngx_mail_session_t *s, ngx_connection_t *c)
-{
-#if (NGX_MAIL_SSL)
- ngx_mail_ssl_conf_t *sslcf;
-
- if (c->ssl == NULL) {
- sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module);
- if (sslcf->starttls) {
-
- /*
- * RFC3207 requires us to discard any knowledge
- * obtained from client before STARTTLS.
- */
-
- ngx_str_null(&s->smtp_helo);
- ngx_str_null(&s->smtp_from);
- ngx_str_null(&s->smtp_to);
-
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
-
- c->read->handler = ngx_mail_starttls_handler;
- return NGX_OK;
- }
- }
-
-#endif
-
- return NGX_MAIL_PARSE_INVALID_COMMAND;
-}
-
-
-static ngx_int_t
-ngx_mail_smtp_discard_command(ngx_mail_session_t *s, ngx_connection_t *c,
- char *err)
-{
- ssize_t n;
-
- n = c->recv(c, s->buffer->last, s->buffer->end - s->buffer->last);
-
- if (n == NGX_ERROR || n == 0) {
- ngx_mail_close_connection(c);
- return NGX_ERROR;
- }
-
- if (n > 0) {
- s->buffer->last += n;
- }
-
- if (n == NGX_AGAIN) {
- if (ngx_handle_read_event(c->read, 0) != NGX_OK) {
- ngx_mail_session_internal_server_error(s);
- return NGX_ERROR;
- }
-
- return NGX_AGAIN;
- }
-
- ngx_mail_smtp_log_rejected_command(s, c, err);
-
- s->buffer->pos = s->buffer->start;
- s->buffer->last = s->buffer->start;
-
- return NGX_OK;
-}
-
-
-static void
-ngx_mail_smtp_log_rejected_command(ngx_mail_session_t *s, ngx_connection_t *c,
- char *err)
-{
- u_char ch;
- ngx_str_t cmd;
- ngx_uint_t i;
-
- if (c->log->log_level < NGX_LOG_INFO) {
- return;
- }
-
- cmd.len = s->buffer->last - s->buffer->start;
- cmd.data = s->buffer->start;
-
- for (i = 0; i < cmd.len; i++) {
- ch = cmd.data[i];
-
- if (ch != CR && ch != LF) {
- continue;
- }
-
- cmd.data[i] = '_';
- }
-
- cmd.len = i;
-
- ngx_log_error(NGX_LOG_INFO, c->log, 0, err, &cmd);
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.c
deleted file mode 100644
index 0e05fdc034..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.c
+++ /dev/null
@@ -1,312 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-#include
-#include
-
-
-static void *ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf);
-static char *ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent,
- void *child);
-
-
-static ngx_conf_bitmask_t ngx_mail_smtp_auth_methods[] = {
- { ngx_string("plain"), NGX_MAIL_AUTH_PLAIN_ENABLED },
- { ngx_string("login"), NGX_MAIL_AUTH_LOGIN_ENABLED },
- { ngx_string("cram-md5"), NGX_MAIL_AUTH_CRAM_MD5_ENABLED },
- { ngx_string("external"), NGX_MAIL_AUTH_EXTERNAL_ENABLED },
- { ngx_string("none"), NGX_MAIL_AUTH_NONE_ENABLED },
- { ngx_null_string, 0 }
-};
-
-
-static ngx_str_t ngx_mail_smtp_auth_methods_names[] = {
- ngx_string("PLAIN"),
- ngx_string("LOGIN"),
- ngx_null_string, /* APOP */
- ngx_string("CRAM-MD5"),
- ngx_string("EXTERNAL"),
- ngx_null_string /* NONE */
-};
-
-
-static ngx_mail_protocol_t ngx_mail_smtp_protocol = {
- ngx_string("smtp"),
- ngx_string("\x04smtp"),
- { 25, 465, 587, 0 },
- NGX_MAIL_SMTP_PROTOCOL,
-
- ngx_mail_smtp_init_session,
- ngx_mail_smtp_init_protocol,
- ngx_mail_smtp_parse_command,
- ngx_mail_smtp_auth_state,
-
- ngx_string("451 4.3.2 Internal server error" CRLF),
- ngx_string("421 4.7.1 SSL certificate error" CRLF),
- ngx_string("421 4.7.1 No required SSL certificate" CRLF)
-};
-
-
-static ngx_command_t ngx_mail_smtp_commands[] = {
-
- { ngx_string("smtp_client_buffer"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_size_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_smtp_srv_conf_t, client_buffer_size),
- NULL },
-
- { ngx_string("smtp_greeting_delay"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_msec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_smtp_srv_conf_t, greeting_delay),
- NULL },
-
- { ngx_string("smtp_capabilities"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_mail_capabilities,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_smtp_srv_conf_t, capabilities),
- NULL },
-
- { ngx_string("smtp_auth"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_smtp_srv_conf_t, auth_methods),
- &ngx_mail_smtp_auth_methods },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_smtp_module_ctx = {
- &ngx_mail_smtp_protocol, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_smtp_create_srv_conf, /* create server configuration */
- ngx_mail_smtp_merge_srv_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_smtp_module = {
- NGX_MODULE_V1,
- &ngx_mail_smtp_module_ctx, /* module context */
- ngx_mail_smtp_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static void *
-ngx_mail_smtp_create_srv_conf(ngx_conf_t *cf)
-{
- ngx_mail_smtp_srv_conf_t *sscf;
-
- sscf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_smtp_srv_conf_t));
- if (sscf == NULL) {
- return NULL;
- }
-
- sscf->client_buffer_size = NGX_CONF_UNSET_SIZE;
- sscf->greeting_delay = NGX_CONF_UNSET_MSEC;
-
- if (ngx_array_init(&sscf->capabilities, cf->pool, 4, sizeof(ngx_str_t))
- != NGX_OK)
- {
- return NULL;
- }
-
- return sscf;
-}
-
-
-static char *
-ngx_mail_smtp_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_smtp_srv_conf_t *prev = parent;
- ngx_mail_smtp_srv_conf_t *conf = child;
-
- u_char *p, *auth, *last;
- size_t size;
- ngx_str_t *c;
- ngx_uint_t i, m, auth_enabled;
- ngx_mail_core_srv_conf_t *cscf;
-
- ngx_conf_merge_size_value(conf->client_buffer_size,
- prev->client_buffer_size,
- (size_t) ngx_pagesize);
-
- ngx_conf_merge_msec_value(conf->greeting_delay,
- prev->greeting_delay, 0);
-
- ngx_conf_merge_bitmask_value(conf->auth_methods,
- prev->auth_methods,
- (NGX_CONF_BITMASK_SET
- |NGX_MAIL_AUTH_PLAIN_ENABLED
- |NGX_MAIL_AUTH_LOGIN_ENABLED));
-
-
- cscf = ngx_mail_conf_get_module_srv_conf(cf, ngx_mail_core_module);
-
- size = sizeof("220 ESMTP ready" CRLF) - 1 + cscf->server_name.len;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->greeting.len = size;
- conf->greeting.data = p;
-
- *p++ = '2'; *p++ = '2'; *p++ = '0'; *p++ = ' ';
- p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
- ngx_memcpy(p, " ESMTP ready" CRLF, sizeof(" ESMTP ready" CRLF) - 1);
-
-
- size = sizeof("250 " CRLF) - 1 + cscf->server_name.len;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->server_name.len = size;
- conf->server_name.data = p;
-
- *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' ';
- p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
- *p++ = CR; *p = LF;
-
-
- if (conf->capabilities.nelts == 0) {
- conf->capabilities = prev->capabilities;
- }
-
- size = sizeof("250-") - 1 + cscf->server_name.len + sizeof(CRLF) - 1;
-
- c = conf->capabilities.elts;
- for (i = 0; i < conf->capabilities.nelts; i++) {
- size += sizeof("250 ") - 1 + c[i].len + sizeof(CRLF) - 1;
- }
-
- auth_enabled = 0;
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (m & conf->auth_methods) {
- size += 1 + ngx_mail_smtp_auth_methods_names[i].len;
- auth_enabled = 1;
- }
- }
-
- if (auth_enabled) {
- size += sizeof("250 AUTH") - 1 + sizeof(CRLF) - 1;
- }
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->capability.len = size;
- conf->capability.data = p;
-
- last = p;
-
- *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-';
- p = ngx_cpymem(p, cscf->server_name.data, cscf->server_name.len);
- *p++ = CR; *p++ = LF;
-
- for (i = 0; i < conf->capabilities.nelts; i++) {
- last = p;
- *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = '-';
- p = ngx_cpymem(p, c[i].data, c[i].len);
- *p++ = CR; *p++ = LF;
- }
-
- auth = p;
-
- if (auth_enabled) {
- last = p;
-
- *p++ = '2'; *p++ = '5'; *p++ = '0'; *p++ = ' ';
- *p++ = 'A'; *p++ = 'U'; *p++ = 'T'; *p++ = 'H';
-
- for (m = NGX_MAIL_AUTH_PLAIN_ENABLED, i = 0;
- m <= NGX_MAIL_AUTH_EXTERNAL_ENABLED;
- m <<= 1, i++)
- {
- if (m & conf->auth_methods) {
- *p++ = ' ';
- p = ngx_cpymem(p, ngx_mail_smtp_auth_methods_names[i].data,
- ngx_mail_smtp_auth_methods_names[i].len);
- }
- }
-
- *p++ = CR; *p = LF;
-
- } else {
- last[3] = ' ';
- }
-
- size += sizeof("250 STARTTLS" CRLF) - 1;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_capability.len = size;
- conf->starttls_capability.data = p;
-
- p = ngx_cpymem(p, conf->capability.data, conf->capability.len);
-
- ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1);
-
- p = conf->starttls_capability.data
- + (last - conf->capability.data) + 3;
- *p = '-';
-
- size = (auth - conf->capability.data)
- + sizeof("250 STARTTLS" CRLF) - 1;
-
- p = ngx_pnalloc(cf->pool, size);
- if (p == NULL) {
- return NGX_CONF_ERROR;
- }
-
- conf->starttls_only_capability.len = size;
- conf->starttls_only_capability.data = p;
-
- p = ngx_cpymem(p, conf->capability.data, auth - conf->capability.data);
-
- ngx_memcpy(p, "250 STARTTLS" CRLF, sizeof("250 STARTTLS" CRLF) - 1);
-
- if (last < auth) {
- p = conf->starttls_only_capability.data
- + (last - conf->capability.data) + 3;
- *p = '-';
- }
-
- return NGX_CONF_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.h b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.h
deleted file mode 100644
index 04ffab60ad..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_smtp_module.h
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_MAIL_SMTP_MODULE_H_INCLUDED_
-#define _NGX_MAIL_SMTP_MODULE_H_INCLUDED_
-
-
-#include
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_msec_t greeting_delay;
-
- size_t client_buffer_size;
-
- ngx_str_t capability;
- ngx_str_t starttls_capability;
- ngx_str_t starttls_only_capability;
-
- ngx_str_t server_name;
- ngx_str_t greeting;
-
- ngx_uint_t auth_methods;
-
- ngx_array_t capabilities;
-} ngx_mail_smtp_srv_conf_t;
-
-
-void ngx_mail_smtp_init_session(ngx_mail_session_t *s, ngx_connection_t *c);
-void ngx_mail_smtp_init_protocol(ngx_event_t *rev);
-void ngx_mail_smtp_auth_state(ngx_event_t *rev);
-ngx_int_t ngx_mail_smtp_parse_command(ngx_mail_session_t *s);
-
-
-extern ngx_module_t ngx_mail_smtp_module;
-
-
-#endif /* _NGX_MAIL_SMTP_MODULE_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.c b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.c
deleted file mode 100644
index 079d0e7734..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.c
+++ /dev/null
@@ -1,714 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-#define NGX_DEFAULT_CIPHERS "HIGH:!aNULL:!MD5"
-#define NGX_DEFAULT_ECDH_CURVE "auto"
-
-
-#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
-static int ngx_mail_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn,
- const unsigned char **out, unsigned char *outlen,
- const unsigned char *in, unsigned int inlen, void *arg);
-#endif
-
-static void *ngx_mail_ssl_create_conf(ngx_conf_t *cf);
-static char *ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child);
-
-static char *ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-static char *ngx_mail_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd,
- void *conf);
-
-static char *ngx_mail_ssl_conf_command_check(ngx_conf_t *cf, void *post,
- void *data);
-
-
-static ngx_conf_enum_t ngx_mail_starttls_state[] = {
- { ngx_string("off"), NGX_MAIL_STARTTLS_OFF },
- { ngx_string("on"), NGX_MAIL_STARTTLS_ON },
- { ngx_string("only"), NGX_MAIL_STARTTLS_ONLY },
- { ngx_null_string, 0 }
-};
-
-
-
-static ngx_conf_bitmask_t ngx_mail_ssl_protocols[] = {
- { ngx_string("SSLv2"), NGX_SSL_SSLv2 },
- { ngx_string("SSLv3"), NGX_SSL_SSLv3 },
- { ngx_string("TLSv1"), NGX_SSL_TLSv1 },
- { ngx_string("TLSv1.1"), NGX_SSL_TLSv1_1 },
- { ngx_string("TLSv1.2"), NGX_SSL_TLSv1_2 },
- { ngx_string("TLSv1.3"), NGX_SSL_TLSv1_3 },
- { ngx_null_string, 0 }
-};
-
-
-static ngx_conf_enum_t ngx_mail_ssl_verify[] = {
- { ngx_string("off"), 0 },
- { ngx_string("on"), 1 },
- { ngx_string("optional"), 2 },
- { ngx_string("optional_no_ca"), 3 },
- { ngx_null_string, 0 }
-};
-
-
-static ngx_conf_post_t ngx_mail_ssl_conf_command_post =
- { ngx_mail_ssl_conf_command_check };
-
-
-static ngx_command_t ngx_mail_ssl_commands[] = {
-
- { ngx_string("starttls"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_mail_ssl_starttls,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, starttls),
- ngx_mail_starttls_state },
-
- { ngx_string("ssl_certificate"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_array_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, certificates),
- NULL },
-
- { ngx_string("ssl_certificate_key"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_array_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, certificate_keys),
- NULL },
-
- { ngx_string("ssl_password_file"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_mail_ssl_password_file,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("ssl_certificate_compression"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, certificate_compression),
- NULL },
-
- { ngx_string("ssl_dhparam"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, dhparam),
- NULL },
-
- { ngx_string("ssl_ecdh_curve"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, ecdh_curve),
- NULL },
-
- { ngx_string("ssl_protocols"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_1MORE,
- ngx_conf_set_bitmask_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, protocols),
- &ngx_mail_ssl_protocols },
-
- { ngx_string("ssl_ciphers"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, ciphers),
- NULL },
-
- { ngx_string("ssl_prefer_server_ciphers"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, prefer_server_ciphers),
- NULL },
-
- { ngx_string("ssl_session_cache"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE12,
- ngx_mail_ssl_session_cache,
- NGX_MAIL_SRV_CONF_OFFSET,
- 0,
- NULL },
-
- { ngx_string("ssl_session_tickets"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_FLAG,
- ngx_conf_set_flag_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, session_tickets),
- NULL },
-
- { ngx_string("ssl_session_ticket_key"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_array_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, session_ticket_keys),
- NULL },
-
- { ngx_string("ssl_session_timeout"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_sec_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, session_timeout),
- NULL },
-
- { ngx_string("ssl_verify_client"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_enum_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, verify),
- &ngx_mail_ssl_verify },
-
- { ngx_string("ssl_verify_depth"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_num_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, verify_depth),
- NULL },
-
- { ngx_string("ssl_client_certificate"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, client_certificate),
- NULL },
-
- { ngx_string("ssl_trusted_certificate"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, trusted_certificate),
- NULL },
-
- { ngx_string("ssl_crl"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, crl),
- NULL },
-
- { ngx_string("ssl_conf_command"),
- NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE2,
- ngx_conf_set_keyval_slot,
- NGX_MAIL_SRV_CONF_OFFSET,
- offsetof(ngx_mail_ssl_conf_t, conf_commands),
- &ngx_mail_ssl_conf_command_post },
-
- ngx_null_command
-};
-
-
-static ngx_mail_module_t ngx_mail_ssl_module_ctx = {
- NULL, /* protocol */
-
- NULL, /* create main configuration */
- NULL, /* init main configuration */
-
- ngx_mail_ssl_create_conf, /* create server configuration */
- ngx_mail_ssl_merge_conf /* merge server configuration */
-};
-
-
-ngx_module_t ngx_mail_ssl_module = {
- NGX_MODULE_V1,
- &ngx_mail_ssl_module_ctx, /* module context */
- ngx_mail_ssl_commands, /* module directives */
- NGX_MAIL_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- NULL, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static ngx_str_t ngx_mail_ssl_sess_id_ctx = ngx_string("MAIL");
-
-
-#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
-
-static int
-ngx_mail_ssl_alpn_select(ngx_ssl_conn_t *ssl_conn, const unsigned char **out,
- unsigned char *outlen, const unsigned char *in, unsigned int inlen,
- void *arg)
-{
- unsigned int srvlen;
- unsigned char *srv;
- ngx_connection_t *c;
- ngx_mail_session_t *s;
- ngx_mail_core_srv_conf_t *cscf;
-#if (NGX_DEBUG)
- unsigned int i;
-#endif
-
- c = ngx_ssl_get_connection(ssl_conn);
- s = c->data;
-
-#if (NGX_DEBUG)
- for (i = 0; i < inlen; i += in[i] + 1) {
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "SSL ALPN supported by client: %*s",
- (size_t) in[i], &in[i + 1]);
- }
-#endif
-
- cscf = ngx_mail_get_module_srv_conf(s, ngx_mail_core_module);
-
- srv = cscf->protocol->alpn.data;
- srvlen = cscf->protocol->alpn.len;
-
- if (SSL_select_next_proto((unsigned char **) out, outlen, srv, srvlen,
- in, inlen)
- != OPENSSL_NPN_NEGOTIATED)
- {
- return SSL_TLSEXT_ERR_ALERT_FATAL;
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_MAIL, c->log, 0,
- "SSL ALPN selected: %*s", (size_t) *outlen, *out);
-
- return SSL_TLSEXT_ERR_OK;
-}
-
-#endif
-
-
-static void *
-ngx_mail_ssl_create_conf(ngx_conf_t *cf)
-{
- ngx_mail_ssl_conf_t *scf;
-
- scf = ngx_pcalloc(cf->pool, sizeof(ngx_mail_ssl_conf_t));
- if (scf == NULL) {
- return NULL;
- }
-
- /*
- * set by ngx_pcalloc():
- *
- * scf->listen = 0;
- * scf->protocols = 0;
- * scf->dhparam = { 0, NULL };
- * scf->ecdh_curve = { 0, NULL };
- * scf->client_certificate = { 0, NULL };
- * scf->trusted_certificate = { 0, NULL };
- * scf->crl = { 0, NULL };
- * scf->ciphers = { 0, NULL };
- * scf->shm_zone = NULL;
- */
-
- scf->starttls = NGX_CONF_UNSET_UINT;
- scf->certificates = NGX_CONF_UNSET_PTR;
- scf->certificate_keys = NGX_CONF_UNSET_PTR;
- scf->passwords = NGX_CONF_UNSET_PTR;
- scf->conf_commands = NGX_CONF_UNSET_PTR;
- scf->prefer_server_ciphers = NGX_CONF_UNSET;
- scf->certificate_compression = NGX_CONF_UNSET;
- scf->verify = NGX_CONF_UNSET_UINT;
- scf->verify_depth = NGX_CONF_UNSET_UINT;
- scf->builtin_session_cache = NGX_CONF_UNSET;
- scf->session_timeout = NGX_CONF_UNSET;
- scf->session_tickets = NGX_CONF_UNSET;
- scf->session_ticket_keys = NGX_CONF_UNSET_PTR;
-
- return scf;
-}
-
-
-static char *
-ngx_mail_ssl_merge_conf(ngx_conf_t *cf, void *parent, void *child)
-{
- ngx_mail_ssl_conf_t *prev = parent;
- ngx_mail_ssl_conf_t *conf = child;
-
- char *mode;
- ngx_pool_cleanup_t *cln;
-
- ngx_conf_merge_uint_value(conf->starttls, prev->starttls,
- NGX_MAIL_STARTTLS_OFF);
-
- ngx_conf_merge_value(conf->session_timeout,
- prev->session_timeout, 300);
-
- ngx_conf_merge_value(conf->prefer_server_ciphers,
- prev->prefer_server_ciphers, 0);
-
- ngx_conf_merge_value(conf->certificate_compression,
- prev->certificate_compression, 0);
-
- ngx_conf_merge_bitmask_value(conf->protocols, prev->protocols,
- (NGX_CONF_BITMASK_SET|NGX_SSL_DEFAULT_PROTOCOLS));
-
- ngx_conf_merge_uint_value(conf->verify, prev->verify, 0);
- ngx_conf_merge_uint_value(conf->verify_depth, prev->verify_depth, 1);
-
- ngx_conf_merge_ptr_value(conf->certificates, prev->certificates, NULL);
- ngx_conf_merge_ptr_value(conf->certificate_keys, prev->certificate_keys,
- NULL);
-
- ngx_conf_merge_ptr_value(conf->passwords, prev->passwords, NULL);
-
- ngx_conf_merge_str_value(conf->dhparam, prev->dhparam, "");
-
- ngx_conf_merge_str_value(conf->ecdh_curve, prev->ecdh_curve,
- NGX_DEFAULT_ECDH_CURVE);
-
- ngx_conf_merge_str_value(conf->client_certificate,
- prev->client_certificate, "");
- ngx_conf_merge_str_value(conf->trusted_certificate,
- prev->trusted_certificate, "");
- ngx_conf_merge_str_value(conf->crl, prev->crl, "");
-
- ngx_conf_merge_str_value(conf->ciphers, prev->ciphers, NGX_DEFAULT_CIPHERS);
-
- ngx_conf_merge_ptr_value(conf->conf_commands, prev->conf_commands, NULL);
-
-
- conf->ssl.log = cf->log;
-
- if (conf->listen) {
- mode = "listen ... ssl";
-
- } else if (conf->starttls != NGX_MAIL_STARTTLS_OFF) {
- mode = "starttls";
-
- } else {
- return NGX_CONF_OK;
- }
-
- if (conf->file == NULL) {
- conf->file = prev->file;
- conf->line = prev->line;
- }
-
- if (conf->certificates == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no \"ssl_certificate\" is defined for "
- "the \"%s\" directive in %s:%ui",
- mode, conf->file, conf->line);
- return NGX_CONF_ERROR;
- }
-
- if (conf->certificate_keys == NULL) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no \"ssl_certificate_key\" is defined for "
- "the \"%s\" directive in %s:%ui",
- mode, conf->file, conf->line);
- return NGX_CONF_ERROR;
- }
-
- if (conf->certificate_keys->nelts < conf->certificates->nelts) {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no \"ssl_certificate_key\" is defined "
- "for certificate \"%V\" and "
- "the \"%s\" directive in %s:%ui",
- ((ngx_str_t *) conf->certificates->elts)
- + conf->certificates->nelts - 1,
- mode, conf->file, conf->line);
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_create(&conf->ssl, conf->protocols, NULL) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- cln = ngx_pool_cleanup_add(cf->pool, 0);
- if (cln == NULL) {
- ngx_ssl_cleanup_ctx(&conf->ssl);
- return NGX_CONF_ERROR;
- }
-
- cln->handler = ngx_ssl_cleanup_ctx;
- cln->data = &conf->ssl;
-
-#ifdef TLSEXT_TYPE_application_layer_protocol_negotiation
- SSL_CTX_set_alpn_select_cb(conf->ssl.ctx, ngx_mail_ssl_alpn_select, NULL);
-#endif
-
- if (ngx_ssl_ciphers(cf, &conf->ssl, &conf->ciphers,
- conf->prefer_server_ciphers)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_certificates(cf, &conf->ssl, conf->certificates,
- conf->certificate_keys, conf->passwords)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_certificate_compression(cf, &conf->ssl,
- conf->certificate_compression)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (conf->verify) {
-
- if (conf->verify != 3
- && conf->client_certificate.len == 0
- && conf->trusted_certificate.len == 0)
- {
- ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
- "no ssl_client_certificate or "
- "ssl_trusted_certificate for ssl_verify_client");
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_client_certificate(cf, &conf->ssl,
- &conf->client_certificate,
- conf->verify_depth)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_trusted_certificate(cf, &conf->ssl,
- &conf->trusted_certificate,
- conf->verify_depth)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_crl(cf, &conf->ssl, &conf->crl) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
- }
-
- if (ngx_ssl_dhparam(cf, &conf->ssl, &conf->dhparam) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_ecdh_curve(cf, &conf->ssl, &conf->ecdh_curve) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- ngx_conf_merge_value(conf->builtin_session_cache,
- prev->builtin_session_cache, NGX_SSL_NONE_SCACHE);
-
- if (conf->shm_zone == NULL) {
- conf->shm_zone = prev->shm_zone;
- }
-
- if (ngx_ssl_session_cache(&conf->ssl, &ngx_mail_ssl_sess_id_ctx,
- conf->certificates, conf->builtin_session_cache,
- conf->shm_zone, conf->session_timeout)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- ngx_conf_merge_value(conf->session_tickets,
- prev->session_tickets, 1);
-
-#ifdef SSL_OP_NO_TICKET
- if (!conf->session_tickets) {
- SSL_CTX_set_options(conf->ssl.ctx, SSL_OP_NO_TICKET);
- }
-#endif
-
- ngx_conf_merge_ptr_value(conf->session_ticket_keys,
- prev->session_ticket_keys, NULL);
-
- if (ngx_ssl_session_ticket_keys(cf, &conf->ssl, conf->session_ticket_keys)
- != NGX_OK)
- {
- return NGX_CONF_ERROR;
- }
-
- if (ngx_ssl_conf_commands(cf, &conf->ssl, conf->conf_commands) != NGX_OK) {
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_ssl_starttls(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_ssl_conf_t *scf = conf;
-
- char *rv;
-
- rv = ngx_conf_set_enum_slot(cf, cmd, conf);
-
- if (rv != NGX_CONF_OK) {
- return rv;
- }
-
- if (!scf->listen) {
- scf->file = cf->conf_file->file.name.data;
- scf->line = cf->conf_file->line;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_ssl_password_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_ssl_conf_t *scf = conf;
-
- ngx_str_t *value;
-
- if (scf->passwords != NGX_CONF_UNSET_PTR) {
- return "is duplicate";
- }
-
- value = cf->args->elts;
-
- scf->passwords = ngx_ssl_read_password_file(cf, &value[1]);
-
- if (scf->passwords == NULL) {
- return NGX_CONF_ERROR;
- }
-
- return NGX_CONF_OK;
-}
-
-
-static char *
-ngx_mail_ssl_session_cache(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
-{
- ngx_mail_ssl_conf_t *scf = conf;
-
- size_t len;
- ngx_str_t *value, name, size;
- ngx_int_t n;
- ngx_uint_t i, j;
-
- value = cf->args->elts;
-
- for (i = 1; i < cf->args->nelts; i++) {
-
- if (ngx_strcmp(value[i].data, "off") == 0) {
- scf->builtin_session_cache = NGX_SSL_NO_SCACHE;
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "none") == 0) {
- scf->builtin_session_cache = NGX_SSL_NONE_SCACHE;
- continue;
- }
-
- if (ngx_strcmp(value[i].data, "builtin") == 0) {
- scf->builtin_session_cache = NGX_SSL_DFLT_BUILTIN_SCACHE;
- continue;
- }
-
- if (value[i].len > sizeof("builtin:") - 1
- && ngx_strncmp(value[i].data, "builtin:", sizeof("builtin:") - 1)
- == 0)
- {
- n = ngx_atoi(value[i].data + sizeof("builtin:") - 1,
- value[i].len - (sizeof("builtin:") - 1));
-
- if (n == NGX_ERROR) {
- goto invalid;
- }
-
- scf->builtin_session_cache = n;
-
- continue;
- }
-
- if (value[i].len > sizeof("shared:") - 1
- && ngx_strncmp(value[i].data, "shared:", sizeof("shared:") - 1)
- == 0)
- {
- len = 0;
-
- for (j = sizeof("shared:") - 1; j < value[i].len; j++) {
- if (value[i].data[j] == ':') {
- break;
- }
-
- len++;
- }
-
- if (len == 0 || j == value[i].len) {
- goto invalid;
- }
-
- name.len = len;
- name.data = value[i].data + sizeof("shared:") - 1;
-
- size.len = value[i].len - j - 1;
- size.data = name.data + len + 1;
-
- n = ngx_parse_size(&size);
-
- if (n == NGX_ERROR) {
- goto invalid;
- }
-
- if (n < (ngx_int_t) (8 * ngx_pagesize)) {
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "session cache \"%V\" is too small",
- &value[i]);
-
- return NGX_CONF_ERROR;
- }
-
- scf->shm_zone = ngx_shared_memory_add(cf, &name, n,
- &ngx_mail_ssl_module);
- if (scf->shm_zone == NULL) {
- return NGX_CONF_ERROR;
- }
-
- scf->shm_zone->init = ngx_ssl_session_cache_init;
-
- continue;
- }
-
- goto invalid;
- }
-
- if (scf->shm_zone && scf->builtin_session_cache == NGX_CONF_UNSET) {
- scf->builtin_session_cache = NGX_SSL_NO_BUILTIN_SCACHE;
- }
-
- return NGX_CONF_OK;
-
-invalid:
-
- ngx_conf_log_error(NGX_LOG_EMERG, cf, 0,
- "invalid session cache \"%V\"", &value[i]);
-
- return NGX_CONF_ERROR;
-}
-
-
-static char *
-ngx_mail_ssl_conf_command_check(ngx_conf_t *cf, void *post, void *data)
-{
-#ifndef SSL_CONF_FLAG_FILE
- return "is not supported on this platform";
-#else
- return NGX_CONF_OK;
-#endif
-}
diff --git a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.h b/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.h
deleted file mode 100644
index a0e9a173a7..0000000000
--- a/src/deps/src/nginx-1.30.3/src/mail/ngx_mail_ssl_module.h
+++ /dev/null
@@ -1,66 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_MAIL_SSL_H_INCLUDED_
-#define _NGX_MAIL_SSL_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-#define NGX_MAIL_STARTTLS_OFF 0
-#define NGX_MAIL_STARTTLS_ON 1
-#define NGX_MAIL_STARTTLS_ONLY 2
-
-
-typedef struct {
- ngx_flag_t prefer_server_ciphers;
- ngx_flag_t certificate_compression;
-
- ngx_ssl_t ssl;
-
- ngx_uint_t starttls;
- ngx_uint_t listen;
- ngx_uint_t protocols;
-
- ngx_uint_t verify;
- ngx_uint_t verify_depth;
-
- ssize_t builtin_session_cache;
-
- time_t session_timeout;
-
- ngx_array_t *certificates;
- ngx_array_t *certificate_keys;
-
- ngx_str_t dhparam;
- ngx_str_t ecdh_curve;
- ngx_str_t client_certificate;
- ngx_str_t trusted_certificate;
- ngx_str_t crl;
-
- ngx_str_t ciphers;
-
- ngx_array_t *passwords;
- ngx_array_t *conf_commands;
-
- ngx_shm_zone_t *shm_zone;
-
- ngx_flag_t session_tickets;
- ngx_array_t *session_ticket_keys;
-
- u_char *file;
- ngx_uint_t line;
-} ngx_mail_ssl_conf_t;
-
-
-extern ngx_module_t ngx_mail_ssl_module;
-
-
-#endif /* _NGX_MAIL_SSL_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/misc/ngx_cpp_test_module.cpp b/src/deps/src/nginx-1.30.3/src/misc/ngx_cpp_test_module.cpp
deleted file mode 100644
index 002640990f..0000000000
--- a/src/deps/src/nginx-1.30.3/src/misc/ngx_cpp_test_module.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-
-// stub module to test header files' C++ compatibility
-
-extern "C" {
- #include
- #include
- #include
- #include
- #include
-
- #include
-
- #include
- #include
- #include
- #include
-
- #include
-}
-
-// nginx header files should go before other, because they define 64-bit off_t
-// #include
-
-
-void ngx_cpp_test_handler(void *data);
-
-void
-ngx_cpp_test_handler(void *data)
-{
- return;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/misc/ngx_google_perftools_module.c b/src/deps/src/nginx-1.30.3/src/misc/ngx_google_perftools_module.c
deleted file mode 100644
index 381f3d105f..0000000000
--- a/src/deps/src/nginx-1.30.3/src/misc/ngx_google_perftools_module.c
+++ /dev/null
@@ -1,126 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-
-/*
- * declare Profiler interface here because
- * is C++ header file
- */
-
-int ProfilerStart(u_char* fname);
-void ProfilerStop(void);
-void ProfilerRegisterThread(void);
-
-
-static void *ngx_google_perftools_create_conf(ngx_cycle_t *cycle);
-static ngx_int_t ngx_google_perftools_worker(ngx_cycle_t *cycle);
-
-
-typedef struct {
- ngx_str_t profiles;
-} ngx_google_perftools_conf_t;
-
-
-static ngx_command_t ngx_google_perftools_commands[] = {
-
- { ngx_string("google_perftools_profiles"),
- NGX_MAIN_CONF|NGX_DIRECT_CONF|NGX_CONF_TAKE1,
- ngx_conf_set_str_slot,
- 0,
- offsetof(ngx_google_perftools_conf_t, profiles),
- NULL },
-
- ngx_null_command
-};
-
-
-static ngx_core_module_t ngx_google_perftools_module_ctx = {
- ngx_string("google_perftools"),
- ngx_google_perftools_create_conf,
- NULL
-};
-
-
-ngx_module_t ngx_google_perftools_module = {
- NGX_MODULE_V1,
- &ngx_google_perftools_module_ctx, /* module context */
- ngx_google_perftools_commands, /* module directives */
- NGX_CORE_MODULE, /* module type */
- NULL, /* init master */
- NULL, /* init module */
- ngx_google_perftools_worker, /* init process */
- NULL, /* init thread */
- NULL, /* exit thread */
- NULL, /* exit process */
- NULL, /* exit master */
- NGX_MODULE_V1_PADDING
-};
-
-
-static void *
-ngx_google_perftools_create_conf(ngx_cycle_t *cycle)
-{
- ngx_google_perftools_conf_t *gptcf;
-
- gptcf = ngx_pcalloc(cycle->pool, sizeof(ngx_google_perftools_conf_t));
- if (gptcf == NULL) {
- return NULL;
- }
-
- /*
- * set by ngx_pcalloc()
- *
- * gptcf->profiles = { 0, NULL };
- */
-
- return gptcf;
-}
-
-
-static ngx_int_t
-ngx_google_perftools_worker(ngx_cycle_t *cycle)
-{
- u_char *profile;
- ngx_google_perftools_conf_t *gptcf;
-
- gptcf = (ngx_google_perftools_conf_t *)
- ngx_get_conf(cycle->conf_ctx, ngx_google_perftools_module);
-
- if (gptcf->profiles.len == 0) {
- return NGX_OK;
- }
-
- profile = ngx_alloc(gptcf->profiles.len + NGX_INT_T_LEN + 2, cycle->log);
- if (profile == NULL) {
- return NGX_OK;
- }
-
- if (getenv("CPUPROFILE")) {
- /* disable inherited Profiler enabled in master process */
- ProfilerStop();
- }
-
- ngx_sprintf(profile, "%V.%d%Z", &gptcf->profiles, ngx_pid);
-
- if (ProfilerStart(profile)) {
- /* start ITIMER_PROF timer */
- ProfilerRegisterThread();
-
- } else {
- ngx_log_error(NGX_LOG_CRIT, cycle->log, ngx_errno,
- "ProfilerStart(%s) failed", profile);
- }
-
- ngx_free(profile);
-
- return NGX_OK;
-}
-
-
-/* ProfilerStop() is called on Profiler destruction */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.c b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.c
deleted file mode 100644
index 5c2f787025..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.c
+++ /dev/null
@@ -1,90 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-
-
-ngx_uint_t ngx_pagesize;
-ngx_uint_t ngx_pagesize_shift;
-ngx_uint_t ngx_cacheline_size;
-
-
-void *
-ngx_alloc(size_t size, ngx_log_t *log)
-{
- void *p;
-
- p = malloc(size);
- if (p == NULL) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "malloc(%uz) failed", size);
- }
-
- ngx_log_debug2(NGX_LOG_DEBUG_ALLOC, log, 0, "malloc: %p:%uz", p, size);
-
- return p;
-}
-
-
-void *
-ngx_calloc(size_t size, ngx_log_t *log)
-{
- void *p;
-
- p = ngx_alloc(size, log);
-
- if (p) {
- ngx_memzero(p, size);
- }
-
- return p;
-}
-
-
-#if (NGX_HAVE_POSIX_MEMALIGN)
-
-void *
-ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
-{
- void *p;
- int err;
-
- err = posix_memalign(&p, alignment, size);
-
- if (err) {
- ngx_log_error(NGX_LOG_EMERG, log, err,
- "posix_memalign(%uz, %uz) failed", alignment, size);
- p = NULL;
- }
-
- ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, log, 0,
- "posix_memalign: %p:%uz @%uz", p, size, alignment);
-
- return p;
-}
-
-#elif (NGX_HAVE_MEMALIGN)
-
-void *
-ngx_memalign(size_t alignment, size_t size, ngx_log_t *log)
-{
- void *p;
-
- p = memalign(alignment, size);
- if (p == NULL) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "memalign(%uz, %uz) failed", alignment, size);
- }
-
- ngx_log_debug3(NGX_LOG_DEBUG_ALLOC, log, 0,
- "memalign: %p:%uz @%uz", p, size, alignment);
-
- return p;
-}
-
-#endif
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.h b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.h
deleted file mode 100644
index 655db257f4..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_alloc.h
+++ /dev/null
@@ -1,45 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_ALLOC_H_INCLUDED_
-#define _NGX_ALLOC_H_INCLUDED_
-
-
-#include
-#include
-
-
-void *ngx_alloc(size_t size, ngx_log_t *log);
-void *ngx_calloc(size_t size, ngx_log_t *log);
-
-#define ngx_free free
-
-
-/*
- * Linux has memalign() or posix_memalign()
- * Solaris has memalign()
- * FreeBSD 7.0 has posix_memalign(), besides, early version's malloc()
- * aligns allocations bigger than page size at the page boundary
- */
-
-#if (NGX_HAVE_POSIX_MEMALIGN || NGX_HAVE_MEMALIGN)
-
-void *ngx_memalign(size_t alignment, size_t size, ngx_log_t *log);
-
-#else
-
-#define ngx_memalign(alignment, size, log) ngx_alloc(size, log)
-
-#endif
-
-
-extern ngx_uint_t ngx_pagesize;
-extern ngx_uint_t ngx_pagesize_shift;
-extern ngx_uint_t ngx_cacheline_size;
-
-
-#endif /* _NGX_ALLOC_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_atomic.h b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_atomic.h
deleted file mode 100644
index fcab2d6a0c..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_atomic.h
+++ /dev/null
@@ -1,313 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_ATOMIC_H_INCLUDED_
-#define _NGX_ATOMIC_H_INCLUDED_
-
-
-#include
-#include
-
-
-#if (NGX_HAVE_LIBATOMIC)
-
-#define AO_REQUIRE_CAS
-#include
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-typedef long ngx_atomic_int_t;
-typedef AO_t ngx_atomic_uint_t;
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-
-#if (NGX_PTR_SIZE == 8)
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-#else
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-#endif
-
-#define ngx_atomic_cmp_set(lock, old, new) \
- AO_compare_and_swap(lock, old, new)
-#define ngx_atomic_fetch_add(value, add) \
- AO_fetch_and_add(value, add)
-#define ngx_memory_barrier() AO_nop()
-#define ngx_cpu_pause()
-
-
-#elif (NGX_HAVE_GCC_ATOMIC)
-
-/* GCC 4.1 builtin atomic operations */
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-typedef long ngx_atomic_int_t;
-typedef unsigned long ngx_atomic_uint_t;
-
-#if (NGX_PTR_SIZE == 8)
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-#else
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-#endif
-
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-
-
-#define ngx_atomic_cmp_set(lock, old, set) \
- __sync_bool_compare_and_swap(lock, old, set)
-
-#define ngx_atomic_fetch_add(value, add) \
- __sync_fetch_and_add(value, add)
-
-#define ngx_memory_barrier() __sync_synchronize()
-
-#if ( __i386__ || __i386 || __amd64__ || __amd64 )
-#define ngx_cpu_pause() __asm__ ("pause")
-#else
-#define ngx_cpu_pause()
-#endif
-
-
-#elif (NGX_DARWIN_ATOMIC)
-
-/*
- * use Darwin 8 atomic(3) and barrier(3) operations
- * optimized at run-time for UP and SMP
- */
-
-#include
-
-/* "bool" conflicts with perl's CORE/handy.h */
-#if 0
-#undef bool
-#endif
-
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#if (NGX_PTR_SIZE == 8)
-
-typedef int64_t ngx_atomic_int_t;
-typedef uint64_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-
-#define ngx_atomic_cmp_set(lock, old, new) \
- OSAtomicCompareAndSwap64Barrier(old, new, (int64_t *) lock)
-
-#define ngx_atomic_fetch_add(value, add) \
- (OSAtomicAdd64(add, (int64_t *) value) - add)
-
-#else
-
-typedef int32_t ngx_atomic_int_t;
-typedef uint32_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-
-#define ngx_atomic_cmp_set(lock, old, new) \
- OSAtomicCompareAndSwap32Barrier(old, new, (int32_t *) lock)
-
-#define ngx_atomic_fetch_add(value, add) \
- (OSAtomicAdd32(add, (int32_t *) value) - add)
-
-#endif
-
-#define ngx_memory_barrier() OSMemoryBarrier()
-
-#define ngx_cpu_pause()
-
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-
-
-#elif ( __i386__ || __i386 )
-
-typedef int32_t ngx_atomic_int_t;
-typedef uint32_t ngx_atomic_uint_t;
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-
-
-#if ( __SUNPRO_C )
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-ngx_atomic_uint_t
-ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
- ngx_atomic_uint_t set);
-
-ngx_atomic_int_t
-ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add);
-
-/*
- * Sun Studio 12 exits with segmentation fault on '__asm ("pause")',
- * so ngx_cpu_pause is declared in src/os/unix/ngx_sunpro_x86.il
- */
-
-void
-ngx_cpu_pause(void);
-
-/* the code in src/os/unix/ngx_sunpro_x86.il */
-
-#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile")
-
-
-#else /* ( __GNUC__ || __INTEL_COMPILER ) */
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#include "ngx_gcc_atomic_x86.h"
-
-#endif
-
-
-#elif ( __amd64__ || __amd64 )
-
-typedef int64_t ngx_atomic_int_t;
-typedef uint64_t ngx_atomic_uint_t;
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-
-
-#if ( __SUNPRO_C )
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-ngx_atomic_uint_t
-ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
- ngx_atomic_uint_t set);
-
-ngx_atomic_int_t
-ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add);
-
-/*
- * Sun Studio 12 exits with segmentation fault on '__asm ("pause")',
- * so ngx_cpu_pause is declared in src/os/unix/ngx_sunpro_amd64.il
- */
-
-void
-ngx_cpu_pause(void);
-
-/* the code in src/os/unix/ngx_sunpro_amd64.il */
-
-#define ngx_memory_barrier() __asm (".volatile"); __asm (".nonvolatile")
-
-
-#else /* ( __GNUC__ || __INTEL_COMPILER ) */
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#include "ngx_gcc_atomic_amd64.h"
-
-#endif
-
-
-#elif ( __sparc__ || __sparc || __sparcv9 )
-
-#if (NGX_PTR_SIZE == 8)
-
-typedef int64_t ngx_atomic_int_t;
-typedef uint64_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-
-#else
-
-typedef int32_t ngx_atomic_int_t;
-typedef uint32_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-
-#endif
-
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-
-
-#if ( __SUNPRO_C )
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#include "ngx_sunpro_atomic_sparc64.h"
-
-
-#else /* ( __GNUC__ || __INTEL_COMPILER ) */
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#include "ngx_gcc_atomic_sparc64.h"
-
-#endif
-
-
-#elif ( __powerpc__ || __POWERPC__ )
-
-#define NGX_HAVE_ATOMIC_OPS 1
-
-#if (NGX_PTR_SIZE == 8)
-
-typedef int64_t ngx_atomic_int_t;
-typedef uint64_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-9223372036854775808") - 1)
-
-#else
-
-typedef int32_t ngx_atomic_int_t;
-typedef uint32_t ngx_atomic_uint_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-
-#endif
-
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-
-
-#include "ngx_gcc_atomic_ppc.h"
-
-#endif
-
-
-#if !(NGX_HAVE_ATOMIC_OPS)
-
-#define NGX_HAVE_ATOMIC_OPS 0
-
-typedef int32_t ngx_atomic_int_t;
-typedef uint32_t ngx_atomic_uint_t;
-typedef volatile ngx_atomic_uint_t ngx_atomic_t;
-#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
-
-
-static ngx_inline ngx_atomic_uint_t
-ngx_atomic_cmp_set(ngx_atomic_t *lock, ngx_atomic_uint_t old,
- ngx_atomic_uint_t set)
-{
- if (*lock == old) {
- *lock = set;
- return 1;
- }
-
- return 0;
-}
-
-
-static ngx_inline ngx_atomic_int_t
-ngx_atomic_fetch_add(ngx_atomic_t *value, ngx_atomic_int_t add)
-{
- ngx_atomic_int_t old;
-
- old = *value;
- *value += add;
-
- return old;
-}
-
-#define ngx_memory_barrier()
-#define ngx_cpu_pause()
-
-#endif
-
-
-void ngx_spinlock(ngx_atomic_t *lock, ngx_atomic_int_t value, ngx_uint_t spin);
-
-#define ngx_trylock(lock) (*(lock) == 0 && ngx_atomic_cmp_set(lock, 0, 1))
-#define ngx_unlock(lock) *(lock) = 0
-
-
-#endif /* _NGX_ATOMIC_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.c b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.c
deleted file mode 100644
index 1efa0667cb..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.c
+++ /dev/null
@@ -1,253 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-#include
-
-
-ngx_int_t
-ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
- ngx_log_t *log)
-{
- ssize_t n;
- ngx_err_t err;
- struct iovec iov[1];
- struct msghdr msg;
-
-#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
-
- union {
- struct cmsghdr cm;
- char space[CMSG_SPACE(sizeof(int))];
- } cmsg;
-
- if (ch->fd == -1) {
- msg.msg_control = NULL;
- msg.msg_controllen = 0;
-
- } else {
- msg.msg_control = (caddr_t) &cmsg;
- msg.msg_controllen = sizeof(cmsg);
-
- ngx_memzero(&cmsg, sizeof(cmsg));
-
- cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
- cmsg.cm.cmsg_level = SOL_SOCKET;
- cmsg.cm.cmsg_type = SCM_RIGHTS;
-
- /*
- * We have to use ngx_memcpy() instead of simple
- * *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
- * because some gcc 4.4 with -O2/3/s optimization issues the warning:
- * dereferencing type-punned pointer will break strict-aliasing rules
- *
- * Fortunately, gcc with -O1 compiles this ngx_memcpy()
- * in the same simple assignment as in the code above
- */
-
- ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int));
- }
-
- msg.msg_flags = 0;
-
-#else
-
- if (ch->fd == -1) {
- msg.msg_accrights = NULL;
- msg.msg_accrightslen = 0;
-
- } else {
- msg.msg_accrights = (caddr_t) &ch->fd;
- msg.msg_accrightslen = sizeof(int);
- }
-
-#endif
-
- iov[0].iov_base = (char *) ch;
- iov[0].iov_len = size;
-
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
-
- n = sendmsg(s, &msg, 0);
-
- if (n == -1) {
- err = ngx_errno;
- if (err == NGX_EAGAIN) {
- return NGX_AGAIN;
- }
-
- ngx_log_error(NGX_LOG_ALERT, log, err, "sendmsg() failed");
- return NGX_ERROR;
- }
-
- return NGX_OK;
-}
-
-
-ngx_int_t
-ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, ngx_log_t *log)
-{
- ssize_t n;
- ngx_err_t err;
- struct iovec iov[1];
- struct msghdr msg;
-
-#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
- union {
- struct cmsghdr cm;
- char space[CMSG_SPACE(sizeof(int))];
- } cmsg;
-#else
- int fd;
-#endif
-
- iov[0].iov_base = (char *) ch;
- iov[0].iov_len = size;
-
- msg.msg_name = NULL;
- msg.msg_namelen = 0;
- msg.msg_iov = iov;
- msg.msg_iovlen = 1;
-
-#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
- msg.msg_control = (caddr_t) &cmsg;
- msg.msg_controllen = sizeof(cmsg);
-#else
- msg.msg_accrights = (caddr_t) &fd;
- msg.msg_accrightslen = sizeof(int);
-#endif
-
- n = recvmsg(s, &msg, 0);
-
- if (n == -1) {
- err = ngx_errno;
- if (err == NGX_EAGAIN) {
- return NGX_AGAIN;
- }
-
- ngx_log_error(NGX_LOG_ALERT, log, err, "recvmsg() failed");
- return NGX_ERROR;
- }
-
- if (n == 0) {
- ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "recvmsg() returned zero");
- return NGX_ERROR;
- }
-
- if ((size_t) n < sizeof(ngx_channel_t)) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() returned not enough data: %z", n);
- return NGX_ERROR;
- }
-
-#if (NGX_HAVE_MSGHDR_MSG_CONTROL)
-
- if (ch->command == NGX_CMD_OPEN_CHANNEL) {
-
- if (cmsg.cm.cmsg_len < (socklen_t) CMSG_LEN(sizeof(int))) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() returned too small ancillary data");
- return NGX_ERROR;
- }
-
- if (cmsg.cm.cmsg_level != SOL_SOCKET || cmsg.cm.cmsg_type != SCM_RIGHTS)
- {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() returned invalid ancillary data "
- "level %d or type %d",
- cmsg.cm.cmsg_level, cmsg.cm.cmsg_type);
- return NGX_ERROR;
- }
-
- /* ch->fd = *(int *) CMSG_DATA(&cmsg.cm); */
-
- ngx_memcpy(&ch->fd, CMSG_DATA(&cmsg.cm), sizeof(int));
- }
-
- if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() truncated data");
- }
-
-#else
-
- if (ch->command == NGX_CMD_OPEN_CHANNEL) {
- if (msg.msg_accrightslen != sizeof(int)) {
- ngx_log_error(NGX_LOG_ALERT, log, 0,
- "recvmsg() returned no ancillary data");
- return NGX_ERROR;
- }
-
- ch->fd = fd;
- }
-
-#endif
-
- return n;
-}
-
-
-ngx_int_t
-ngx_add_channel_event(ngx_cycle_t *cycle, ngx_fd_t fd, ngx_int_t event,
- ngx_event_handler_pt handler)
-{
- ngx_event_t *ev, *rev, *wev;
- ngx_connection_t *c;
-
- c = ngx_get_connection(fd, cycle->log);
-
- if (c == NULL) {
- return NGX_ERROR;
- }
-
- c->pool = cycle->pool;
-
- rev = c->read;
- wev = c->write;
-
- rev->log = cycle->log;
- wev->log = cycle->log;
-
- rev->channel = 1;
- wev->channel = 1;
-
- ev = (event == NGX_READ_EVENT) ? rev : wev;
-
- ev->handler = handler;
-
- if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {
- if (ngx_add_conn(c) == NGX_ERROR) {
- ngx_free_connection(c);
- return NGX_ERROR;
- }
-
- } else {
- if (ngx_add_event(ev, event, 0) == NGX_ERROR) {
- ngx_free_connection(c);
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
-
-
-void
-ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log)
-{
- if (close(fd[0]) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() channel failed");
- }
-
- if (close(fd[1]) == -1) {
- ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() channel failed");
- }
-}
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.h b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.h
deleted file mode 100644
index 362cc649aa..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_channel.h
+++ /dev/null
@@ -1,34 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_CHANNEL_H_INCLUDED_
-#define _NGX_CHANNEL_H_INCLUDED_
-
-
-#include
-#include
-#include
-
-
-typedef struct {
- ngx_uint_t command;
- ngx_pid_t pid;
- ngx_int_t slot;
- ngx_fd_t fd;
-} ngx_channel_t;
-
-
-ngx_int_t ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
- ngx_log_t *log);
-ngx_int_t ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
- ngx_log_t *log);
-ngx_int_t ngx_add_channel_event(ngx_cycle_t *cycle, ngx_fd_t fd,
- ngx_int_t event, ngx_event_handler_pt handler);
-void ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log);
-
-
-#endif /* _NGX_CHANNEL_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_daemon.c b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_daemon.c
deleted file mode 100644
index 385c49b6c3..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_daemon.c
+++ /dev/null
@@ -1,71 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include
-
-
-ngx_int_t
-ngx_daemon(ngx_log_t *log)
-{
- int fd;
-
- switch (fork()) {
- case -1:
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "fork() failed");
- return NGX_ERROR;
-
- case 0:
- break;
-
- default:
- exit(0);
- }
-
- ngx_parent = ngx_pid;
- ngx_pid = ngx_getpid();
-
- if (setsid() == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "setsid() failed");
- return NGX_ERROR;
- }
-
- umask(0);
-
- fd = open("/dev/null", O_RDWR);
- if (fd == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno,
- "open(\"/dev/null\") failed");
- return NGX_ERROR;
- }
-
- if (dup2(fd, STDIN_FILENO) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDIN) failed");
- return NGX_ERROR;
- }
-
- if (dup2(fd, STDOUT_FILENO) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDOUT) failed");
- return NGX_ERROR;
- }
-
-#if 0
- if (dup2(fd, STDERR_FILENO) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "dup2(STDERR) failed");
- return NGX_ERROR;
- }
-#endif
-
- if (fd > STDERR_FILENO) {
- if (close(fd) == -1) {
- ngx_log_error(NGX_LOG_EMERG, log, ngx_errno, "close() failed");
- return NGX_ERROR;
- }
- }
-
- return NGX_OK;
-}
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin.h b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin.h
deleted file mode 100644
index 4d01b26ea5..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin.h
+++ /dev/null
@@ -1,23 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_DARWIN_H_INCLUDED_
-#define _NGX_DARWIN_H_INCLUDED_
-
-
-void ngx_debug_init(void);
-ngx_chain_t *ngx_darwin_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in,
- off_t limit);
-
-extern int ngx_darwin_kern_osreldate;
-extern int ngx_darwin_hw_ncpu;
-extern u_long ngx_darwin_net_inet_tcp_sendspace;
-
-extern ngx_uint_t ngx_debug_malloc;
-
-
-#endif /* _NGX_DARWIN_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_config.h b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_config.h
deleted file mode 100644
index 0dfe633741..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_config.h
+++ /dev/null
@@ -1,100 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#ifndef _NGX_DARWIN_CONFIG_H_INCLUDED_
-#define _NGX_DARWIN_CONFIG_H_INCLUDED_
-
-
-#define __APPLE_USE_RFC_3542 /* IPV6_PKTINFO */
-
-
-#include
-#include
-#include
-#include
-#include
-#include /* offsetof() */
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include /* statfs() */
-
-#include /* FIONBIO */
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include
-#include
-
-#include
-#include
-#include /* TCP_NODELAY */
-#include
-#include
-#include
-
-#include
-#include
-
-#include
-
-
-#ifndef IOV_MAX
-#define IOV_MAX 64
-#endif
-
-
-#include
-
-
-#if (NGX_HAVE_POSIX_SEM)
-#include
-#endif
-
-
-#if (NGX_HAVE_POLL)
-#include
-#endif
-
-
-#if (NGX_HAVE_KQUEUE)
-#include
-#endif
-
-
-#define NGX_LISTEN_BACKLOG -1
-
-
-#ifndef NGX_HAVE_INHERITED_NONBLOCK
-#define NGX_HAVE_INHERITED_NONBLOCK 1
-#endif
-
-
-#ifndef NGX_HAVE_CASELESS_FILESYSTEM
-#define NGX_HAVE_CASELESS_FILESYSTEM 1
-#endif
-
-
-#define NGX_HAVE_OS_SPECIFIC_INIT 1
-#define NGX_HAVE_DEBUG_MALLOC 1
-
-
-extern char **environ;
-
-
-#endif /* _NGX_DARWIN_CONFIG_H_INCLUDED_ */
diff --git a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_init.c b/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_init.c
deleted file mode 100644
index 70748ee57a..0000000000
--- a/src/deps/src/nginx-1.30.3/src/os/unix/ngx_darwin_init.c
+++ /dev/null
@@ -1,204 +0,0 @@
-
-/*
- * Copyright (C) Igor Sysoev
- * Copyright (C) Nginx, Inc.
- */
-
-
-#include
-#include