aboutsummaryrefslogtreecommitdiff
path: root/src/stream/ngx_stream_script.c
diff options
context:
space:
mode:
authorRuslan Ermilov <ru@nginx.com>2019-04-24 16:38:51 +0300
committerRuslan Ermilov <ru@nginx.com>2019-04-24 16:38:51 +0300
commit2ace7fc3e683fcfa44ff9c355face60983db7eae (patch)
treef02d592ebc883346884f35a1438acdcb765e4840 /src/stream/ngx_stream_script.c
parent2eb2a93d8a3ad17eb25b2220ffe1f54d09b3fc4c (diff)
downloadnginx-2ace7fc3e683fcfa44ff9c355face60983db7eae.tar.gz
nginx-2ace7fc3e683fcfa44ff9c355face60983db7eae.zip
Added ngx_http_set_complex_value_size_slot().
If a complex value is expected to be of type size_t, and the compiled value is constant, the constant size_t value is remembered at compile time. The value is accessed through ngx_http_complex_value_size() which either returns the remembered constant or evaluates the expression and parses it as size_t.
Diffstat (limited to 'src/stream/ngx_stream_script.c')
-rw-r--r--src/stream/ngx_stream_script.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/src/stream/ngx_stream_script.c b/src/stream/ngx_stream_script.c
index b00e7086f..a15f772b5 100644
--- a/src/stream/ngx_stream_script.c
+++ b/src/stream/ngx_stream_script.c
@@ -105,6 +105,37 @@ ngx_stream_complex_value(ngx_stream_session_t *s,
}
+size_t
+ngx_stream_complex_value_size(ngx_stream_session_t *s,
+ ngx_stream_complex_value_t *val, size_t default_value)
+{
+ size_t size;
+ ngx_str_t value;
+
+ if (val == NULL) {
+ return default_value;
+ }
+
+ if (val->lengths == NULL) {
+ return val->u.size;
+ }
+
+ if (ngx_stream_complex_value(s, val, &value) != NGX_OK) {
+ return default_value;
+ }
+
+ size = ngx_parse_size(&value);
+
+ if (size == (size_t) NGX_ERROR) {
+ ngx_log_error(NGX_LOG_ERR, s->connection->log, 0,
+ "invalid size \"%V\"", &value);
+ return default_value;
+ }
+
+ return size;
+}
+
+
ngx_int_t
ngx_stream_compile_complex_value(ngx_stream_compile_complex_value_t *ccv)
{
@@ -246,6 +277,36 @@ ngx_stream_set_complex_value_slot(ngx_conf_t *cf, ngx_command_t *cmd,
}
+char *
+ngx_stream_set_complex_value_size_slot(ngx_conf_t *cf, ngx_command_t *cmd,
+ void *conf)
+{
+ char *p = conf;
+
+ char *rv;
+ ngx_stream_complex_value_t *cv;
+
+ rv = ngx_stream_set_complex_value_slot(cf, cmd, conf);
+
+ if (rv != NGX_CONF_OK) {
+ return rv;
+ }
+
+ cv = *(ngx_stream_complex_value_t **) (p + cmd->offset);
+
+ if (cv->lengths) {
+ return NGX_CONF_OK;
+ }
+
+ cv->u.size = ngx_parse_size(&cv->value);
+ if (cv->u.size == (size_t) NGX_ERROR) {
+ return "invalid value";
+ }
+
+ return NGX_CONF_OK;
+}
+
+
ngx_uint_t
ngx_stream_script_variables_count(ngx_str_t *value)
{