Welcome! Log In Create A New Profile

Advanced

[njs] Fixed deprecation warnings introduced in beaff2c39864.

Dmitry Volyntsev
August 03, 2022 01:18AM
details: https://hg.nginx.org/njs/rev/bb7a3a0017b2
branches:
changeset: 1919:bb7a3a0017b2
user: Dmitry Volyntsev <xeioex@nginx.com>
date: Tue Aug 02 20:40:20 2022 -0700
description:
Fixed deprecation warnings introduced in beaff2c39864.

Previously, deprecated and non-deprecated properties shared
a common handler.

diffstat:

nginx/ngx_http_js_module.c | 24 ++++++++++++++++--------
nginx/ngx_js.h | 9 ++++++---
2 files changed, 22 insertions(+), 11 deletions(-)

diffs (119 lines):

diff -r beaff2c39864 -r bb7a3a0017b2 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c Mon Jul 25 18:40:24 2022 -0700
+++ b/nginx/ngx_http_js_module.c Tue Aug 02 20:40:20 2022 -0700
@@ -501,7 +501,7 @@ static njs_external_t ngx_http_js_ext_r
.name.string = njs_str("requestBody"),
.u.property = {
.handler = ngx_http_js_ext_get_request_body,
- .magic32 = NGX_JS_STRING,
+ .magic32 = NGX_JS_STRING | NGX_JS_DEPRECATED,
}
},

@@ -537,7 +537,7 @@ static njs_external_t ngx_http_js_ext_r
.name.string = njs_str("responseBody"),
.u.property = {
.handler = ngx_http_js_ext_get_response_body,
- .magic32 = NGX_JS_STRING,
+ .magic32 = NGX_JS_STRING | NGX_JS_DEPRECATED,
}
},

@@ -2565,6 +2565,7 @@ ngx_http_js_ext_get_request_body(njs_vm_
{
u_char *p, *body;
size_t len;
+ uint32_t buffer_type;
ngx_buf_t *buf;
njs_int_t ret;
njs_value_t *request_body;
@@ -2572,7 +2573,9 @@ ngx_http_js_ext_get_request_body(njs_vm_
ngx_http_js_ctx_t *ctx;
ngx_http_request_t *r;

- njs_deprecated(vm, "r.requestBody");
+ if (njs_vm_prop_magic32(prop) & NGX_JS_DEPRECATED) {
+ njs_deprecated(vm, "r.requestBody");
+ }

r = njs_vm_external(vm, ngx_http_js_request_proto_id, value);
if (r == NULL) {
@@ -2582,9 +2585,10 @@ ngx_http_js_ext_get_request_body(njs_vm_

ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
request_body = (njs_value_t *) &ctx->request_body;
+ buffer_type = ngx_js_buffer_type(njs_vm_prop_magic32(prop));

if (!njs_value_is_null(request_body)) {
- if ((njs_vm_prop_magic32(prop) == NGX_JS_BUFFER)
+ if ((buffer_type == NGX_JS_BUFFER)
== (uint32_t) njs_value_is_buffer(request_body))
{
njs_value_assign(retval, request_body);
@@ -2636,7 +2640,7 @@ ngx_http_js_ext_get_request_body(njs_vm_

done:

- ret = ngx_js_prop(vm, njs_vm_prop_magic32(prop), request_body, body, len);
+ ret = ngx_js_prop(vm, buffer_type, request_body, body, len);
if (ret != NJS_OK) {
return NJS_ERROR;
}
@@ -3412,13 +3416,16 @@ ngx_http_js_ext_get_response_body(njs_vm
{
size_t len;
u_char *p;
+ uint32_t buffer_type;
njs_int_t ret;
ngx_buf_t *b;
njs_value_t *response_body;
ngx_http_js_ctx_t *ctx;
ngx_http_request_t *r;

- njs_deprecated(vm, "r.responseBody");
+ if (njs_vm_prop_magic32(prop) & NGX_JS_DEPRECATED) {
+ njs_deprecated(vm, "r.responseBody");
+ }

r = njs_vm_external(vm, ngx_http_js_request_proto_id, value);
if (r == NULL) {
@@ -3428,9 +3435,10 @@ ngx_http_js_ext_get_response_body(njs_vm

ctx = ngx_http_get_module_ctx(r, ngx_http_js_module);
response_body = (njs_value_t *) &ctx->response_body;
+ buffer_type = ngx_js_buffer_type(njs_vm_prop_magic32(prop));

if (!njs_value_is_null(response_body)) {
- if ((njs_vm_prop_magic32(prop) == NGX_JS_BUFFER)
+ if ((buffer_type == NGX_JS_BUFFER)
== (uint32_t) njs_value_is_buffer(response_body))
{
njs_value_assign(retval, response_body);
@@ -3457,7 +3465,7 @@ ngx_http_js_ext_get_response_body(njs_vm
ngx_memcpy(p, b->pos, len);
}

- ret = ngx_js_prop(vm, njs_vm_prop_magic32(prop), response_body, p, len);
+ ret = ngx_js_prop(vm, buffer_type, response_body, p, len);
if (ret != NJS_OK) {
return NJS_ERROR;
}
diff -r beaff2c39864 -r bb7a3a0017b2 nginx/ngx_js.h
--- a/nginx/ngx_js.h Mon Jul 25 18:40:24 2022 -0700
+++ b/nginx/ngx_js.h Tue Aug 02 20:40:20 2022 -0700
@@ -15,9 +15,12 @@
#include <njs.h>


-#define NGX_JS_UNSET 0
-#define NGX_JS_STRING 1
-#define NGX_JS_BUFFER 2
+#define NGX_JS_UNSET 0
+#define NGX_JS_DEPRECATED 1
+#define NGX_JS_STRING 2
+#define NGX_JS_BUFFER 4
+
+#define ngx_js_buffer_type(btype) ((btype) & ~NGX_JS_DEPRECATED)


typedef ngx_pool_t *(*ngx_external_pool_pt)(njs_vm_t *vm, njs_external_ptr_t e);
_______________________________________________
nginx-devel mailing list -- nginx-devel@nginx.org
To unsubscribe send an email to nginx-devel-leave@nginx.org
Subject Author Views Posted

[njs] Fixed deprecation warnings introduced in beaff2c39864.

Dmitry Volyntsev 226 August 03, 2022 01:18AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 100
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready