[njs] Modules: js_merge_conf is moved to shared library.

Vadim Zhestikov v.zhestikov at f5.com
Tue Sep 27 18:30:32 UTC 2022


details:   https://hg.nginx.org/njs/rev/43e35b05fd1b
branches:  
changeset: 1965:43e35b05fd1b
user:      Vadim Zhestikov <v.zhestikov at f5.com>
date:      Tue Sep 27 10:56:54 2022 -0700
description:
Modules: js_merge_conf is moved to shared library.

diffstat:

 nginx/ngx_http_js_module.c   |  88 +-------------------------------------------
 nginx/ngx_js.c               |  87 +++++++++++++++++++++++++++++++++++++++++++
 nginx/ngx_js.h               |  21 +++++++++-
 nginx/ngx_stream_js_module.c |  89 +-------------------------------------------
 4 files changed, 109 insertions(+), 176 deletions(-)

diffs (374 lines):

diff -r b92fa931a0f2 -r 43e35b05fd1b nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Tue Sep 27 09:32:56 2022 -0700
+++ b/nginx/ngx_http_js_module.c	Tue Sep 27 10:56:54 2022 -0700
@@ -19,15 +19,6 @@ typedef struct {
     ngx_str_t              header_filter;
     ngx_str_t              body_filter;
     ngx_uint_t             buffer_type;
-
-#if (NGX_HTTP_SSL)
-    ngx_ssl_t             *ssl;
-    ngx_str_t              ssl_ciphers;
-    ngx_uint_t             ssl_protocols;
-    ngx_flag_t             ssl_verify;
-    ngx_int_t              ssl_verify_depth;
-    ngx_str_t              ssl_trusted_certificate;
-#endif
 } ngx_http_js_loc_conf_t;
 
 
@@ -260,9 +251,6 @@ static void *ngx_http_js_create_loc_conf
 static char *ngx_http_js_merge_loc_conf(ngx_conf_t *cf, void *parent,
     void *child);
 
-#if (NGX_HTTP_SSL)
-static char * ngx_http_js_set_ssl(ngx_conf_t *cf, ngx_http_js_loc_conf_t *jlcf);
-#endif
 static ngx_ssl_t *ngx_http_js_ssl(njs_vm_t *vm, ngx_http_request_t *r);
 static ngx_flag_t ngx_http_js_ssl_verify(njs_vm_t *vm, ngx_http_request_t *r);
 
@@ -4419,84 +4407,10 @@ ngx_http_js_merge_loc_conf(ngx_conf_t *c
     ngx_conf_merge_uint_value(conf->buffer_type, prev->buffer_type,
                               NGX_JS_STRING);
 
-    ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
-    ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384);
-    ngx_conf_merge_size_value(conf->max_response_body_size,
-                              prev->max_response_body_size, 1048576);
-
-    if (ngx_js_merge_vm(cf, (ngx_js_conf_t *) conf, (ngx_js_conf_t *) prev,
-                        ngx_http_js_init_conf_vm)
-        != NGX_OK)
-    {
-        return NGX_CONF_ERROR;
-    }
-
-#if (NGX_HTTP_SSL)
-    ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT");
-
-    ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
-                                 (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
-                                  |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
-
-    ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 1);
-    ngx_conf_merge_value(conf->ssl_verify_depth, prev->ssl_verify_depth, 100);
-
-    ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
-                             prev->ssl_trusted_certificate, "");
-
-    return ngx_http_js_set_ssl(cf, conf);
-#else
-    return NGX_CONF_OK;
-#endif
+    return ngx_js_merge_conf(cf, parent, child, ngx_http_js_init_conf_vm);
 }
 
 
-#if (NGX_HTTP_SSL)
-
-static char *
-ngx_http_js_set_ssl(ngx_conf_t *cf, ngx_http_js_loc_conf_t *jlcf)
-{
-    ngx_ssl_t           *ssl;
-    ngx_pool_cleanup_t  *cln;
-
-    ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
-    if (ssl == NULL) {
-        return NGX_CONF_ERROR;
-    }
-
-    jlcf->ssl = ssl;
-    ssl->log = cf->log;
-
-    if (ngx_ssl_create(ssl, jlcf->ssl_protocols, NULL) != NGX_OK) {
-        return NGX_CONF_ERROR;
-    }
-
-    cln = ngx_pool_cleanup_add(cf->pool, 0);
-    if (cln == NULL) {
-        ngx_ssl_cleanup_ctx(ssl);
-        return NGX_CONF_ERROR;
-    }
-
-    cln->handler = ngx_ssl_cleanup_ctx;
-    cln->data = ssl;
-
-    if (ngx_ssl_ciphers(NULL, ssl, &jlcf->ssl_ciphers, 0) != NGX_OK) {
-        return NGX_CONF_ERROR;
-    }
-
-    if (ngx_ssl_trusted_certificate(cf, ssl, &jlcf->ssl_trusted_certificate,
-                                    jlcf->ssl_verify_depth)
-        != NGX_OK)
-    {
-        return NGX_CONF_ERROR;
-    }
-
-    return NGX_CONF_OK;
-}
-
-#endif
-
-
 static ngx_ssl_t *
 ngx_http_js_ssl(njs_vm_t *vm, ngx_http_request_t *r)
 {
diff -r b92fa931a0f2 -r 43e35b05fd1b nginx/ngx_js.c
--- a/nginx/ngx_js.c	Tue Sep 27 09:32:56 2022 -0700
+++ b/nginx/ngx_js.c	Tue Sep 27 10:56:54 2022 -0700
@@ -1039,3 +1039,90 @@ ngx_js_create_conf(ngx_conf_t *cf, size_
 
     return conf;
 }
+
+
+#if defined(NGX_HTTP_SSL) || defined(NGX_STREAM_SSL)
+
+static char *
+ngx_js_set_ssl(ngx_conf_t *cf, ngx_js_conf_t *conf)
+{
+    ngx_ssl_t           *ssl;
+    ngx_pool_cleanup_t  *cln;
+
+    ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
+    if (ssl == NULL) {
+        return NGX_CONF_ERROR;
+    }
+
+    conf->ssl = ssl;
+    ssl->log = cf->log;
+
+    if (ngx_ssl_create(ssl, conf->ssl_protocols, NULL) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
+    cln = ngx_pool_cleanup_add(cf->pool, 0);
+    if (cln == NULL) {
+        ngx_ssl_cleanup_ctx(ssl);
+        return NGX_CONF_ERROR;
+    }
+
+    cln->handler = ngx_ssl_cleanup_ctx;
+    cln->data = ssl;
+
+    if (ngx_ssl_ciphers(NULL, ssl, &conf->ssl_ciphers, 0) != NGX_OK) {
+        return NGX_CONF_ERROR;
+    }
+
+    if (ngx_ssl_trusted_certificate(cf, ssl, &conf->ssl_trusted_certificate,
+                                    conf->ssl_verify_depth)
+        != NGX_OK)
+    {
+        return NGX_CONF_ERROR;
+    }
+
+    return NGX_CONF_OK;
+}
+
+#endif
+
+
+char *
+ngx_js_merge_conf(ngx_conf_t *cf, void *parent, void *child,
+  ngx_int_t (*init_vm)(ngx_conf_t *cf, ngx_js_conf_t *conf))
+{
+    ngx_js_conf_t *prev = parent;
+    ngx_js_conf_t *conf = child;
+
+    ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
+    ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384);
+    ngx_conf_merge_size_value(conf->max_response_body_size,
+                              prev->max_response_body_size, 1048576);
+
+    if (ngx_js_merge_vm(cf, (ngx_js_conf_t *) conf, (ngx_js_conf_t *) prev,
+                        init_vm)
+        != NGX_OK)
+    {
+        return NGX_CONF_ERROR;
+    }
+
+#if defined(NGX_HTTP_SSL) || defined(NGX_STREAM_SSL)
+    ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers,
+                             "DEFAULT");
+
+    ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
+                             (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
+                              |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
+
+    ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 1);
+    ngx_conf_merge_value(conf->ssl_verify_depth, prev->ssl_verify_depth,
+                         100);
+
+    ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
+                         prev->ssl_trusted_certificate, "");
+
+    return ngx_js_set_ssl(cf, conf);
+#else
+    return NGX_CONF_OK;
+#endif
+}
diff -r b92fa931a0f2 -r 43e35b05fd1b nginx/ngx_js.h
--- a/nginx/ngx_js.h	Tue Sep 27 09:32:56 2022 -0700
+++ b/nginx/ngx_js.h	Tue Sep 27 10:56:54 2022 -0700
@@ -50,7 +50,7 @@ typedef struct {
 } ngx_js_named_path_t;
 
 
-#define NGX_JS_COMMON_CONF                                                    \
+#define _NGX_JS_COMMON_CONF                                                   \
     njs_vm_t              *vm;                                                \
     ngx_array_t           *imports;                                           \
     ngx_array_t           *paths;                                             \
@@ -62,6 +62,23 @@ typedef struct {
     size_t                 max_response_body_size;                            \
     ngx_msec_t             timeout
 
+
+#if defined(NGX_HTTP_SSL) || defined(NGX_STREAM_SSL)
+#define NGX_JS_COMMON_CONF                                                    \
+    _NGX_JS_COMMON_CONF;                                                      \
+                                                                              \
+    ngx_ssl_t             *ssl;                                               \
+    ngx_str_t              ssl_ciphers;                                       \
+    ngx_uint_t             ssl_protocols;                                     \
+    ngx_flag_t             ssl_verify;                                        \
+    ngx_int_t              ssl_verify_depth;                                  \
+    ngx_str_t              ssl_trusted_certificate
+
+#else
+#define NGX_JS_COMMON_CONF _NGX_JS_COMMON_CONF
+#endif
+
+
 typedef struct {
     NGX_JS_COMMON_CONF;
 } ngx_js_conf_t;
@@ -113,6 +130,8 @@ ngx_int_t ngx_js_init_conf_vm(ngx_conf_t
     njs_vm_opt_t *options,
     ngx_int_t (*externals_init)(ngx_conf_t *cf, ngx_js_conf_t *conf));
 ngx_js_conf_t *ngx_js_create_conf(ngx_conf_t *cf, size_t size);
+char * ngx_js_merge_conf(ngx_conf_t *cf, void *parent, void *child,
+   ngx_int_t (*init_vm)(ngx_conf_t *cf, ngx_js_conf_t *conf));
 
 njs_int_t ngx_js_ext_string(njs_vm_t *vm, njs_object_prop_t *prop,
     njs_value_t *value, njs_value_t *setval, njs_value_t *retval);
diff -r b92fa931a0f2 -r 43e35b05fd1b nginx/ngx_stream_js_module.c
--- a/nginx/ngx_stream_js_module.c	Tue Sep 27 09:32:56 2022 -0700
+++ b/nginx/ngx_stream_js_module.c	Tue Sep 27 10:56:54 2022 -0700
@@ -18,15 +18,6 @@ typedef struct {
     ngx_str_t              access;
     ngx_str_t              preread;
     ngx_str_t              filter;
-
-#if (NGX_STREAM_SSL)
-    ngx_ssl_t             *ssl;
-    ngx_str_t              ssl_ciphers;
-    ngx_flag_t             ssl_verify;
-    ngx_uint_t             ssl_protocols;
-    ngx_int_t              ssl_verify_depth;
-    ngx_str_t              ssl_trusted_certificate;
-#endif
 } ngx_stream_js_srv_conf_t;
 
 
@@ -133,10 +124,6 @@ static char *ngx_stream_js_merge_srv_con
     void *child);
 static ngx_int_t ngx_stream_js_init(ngx_conf_t *cf);
 
-#if (NGX_STREAM_SSL)
-static char * ngx_stream_js_set_ssl(ngx_conf_t *cf,
-    ngx_stream_js_srv_conf_t *jscf);
-#endif
 static ngx_ssl_t *ngx_stream_js_ssl(njs_vm_t *vm, ngx_stream_session_t *s);
 static ngx_flag_t ngx_stream_js_ssl_verify(njs_vm_t *vm,
     ngx_stream_session_t *s);
@@ -1847,35 +1834,7 @@ ngx_stream_js_merge_srv_conf(ngx_conf_t 
     ngx_conf_merge_str_value(conf->preread, prev->preread, "");
     ngx_conf_merge_str_value(conf->filter, prev->filter, "");
 
-    ngx_conf_merge_msec_value(conf->timeout, prev->timeout, 60000);
-    ngx_conf_merge_size_value(conf->buffer_size, prev->buffer_size, 16384);
-    ngx_conf_merge_size_value(conf->max_response_body_size,
-                              prev->max_response_body_size, 1048576);
-
-    if (ngx_js_merge_vm(cf, (ngx_js_conf_t *) conf, (ngx_js_conf_t *) prev,
-                        ngx_stream_js_init_conf_vm)
-        != NGX_OK)
-    {
-        return NGX_CONF_ERROR;
-    }
-
-#if (NGX_STREAM_SSL)
-    ngx_conf_merge_str_value(conf->ssl_ciphers, prev->ssl_ciphers, "DEFAULT");
-
-    ngx_conf_merge_bitmask_value(conf->ssl_protocols, prev->ssl_protocols,
-                                 (NGX_CONF_BITMASK_SET|NGX_SSL_TLSv1
-                                  |NGX_SSL_TLSv1_1|NGX_SSL_TLSv1_2));
-
-    ngx_conf_merge_value(conf->ssl_verify, prev->ssl_verify, 1);
-    ngx_conf_merge_value(conf->ssl_verify_depth, prev->ssl_verify_depth, 100);
-
-    ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
-                             prev->ssl_trusted_certificate, "");
-
-    return ngx_stream_js_set_ssl(cf, conf);
-#else
-    return NGX_CONF_OK;
-#endif
+    return ngx_js_merge_conf(cf, parent, child, ngx_stream_js_init_conf_vm);
 }
 
 
@@ -1908,52 +1867,6 @@ ngx_stream_js_init(ngx_conf_t *cf)
 }
 
 
-#if (NGX_STREAM_SSL)
-
-static char *
-ngx_stream_js_set_ssl(ngx_conf_t *cf, ngx_stream_js_srv_conf_t *jscf)
-{
-    ngx_ssl_t           *ssl;
-    ngx_pool_cleanup_t  *cln;
-
-    ssl = ngx_pcalloc(cf->pool, sizeof(ngx_ssl_t));
-    if (ssl == NULL) {
-        return NGX_CONF_ERROR;
-    }
-
-    jscf->ssl = ssl;
-    ssl->log = cf->log;
-
-    if (ngx_ssl_create(ssl, jscf->ssl_protocols, NULL) != NGX_OK) {
-        return NGX_CONF_ERROR;
-    }
-
-    cln = ngx_pool_cleanup_add(cf->pool, 0);
-    if (cln == NULL) {
-        ngx_ssl_cleanup_ctx(ssl);
-        return NGX_CONF_ERROR;
-    }
-
-    cln->handler = ngx_ssl_cleanup_ctx;
-    cln->data = ssl;
-
-    if (ngx_ssl_ciphers(NULL, ssl, &jscf->ssl_ciphers, 0) != NGX_OK) {
-        return NGX_CONF_ERROR;
-    }
-
-    if (ngx_ssl_trusted_certificate(cf, ssl, &jscf->ssl_trusted_certificate,
-                                    jscf->ssl_verify_depth)
-        != NGX_OK)
-    {
-        return NGX_CONF_ERROR;
-    }
-
-    return NGX_CONF_OK;
-}
-
-#endif
-
-
 static ngx_ssl_t *
 ngx_stream_js_ssl(njs_vm_t *vm, ngx_stream_session_t *s)
 {



More information about the nginx-devel mailing list