From i at lvht.net Mon Apr 2 00:28:20 2018 From: i at lvht.net (Haitao Lv) Date: Mon, 2 Apr 2018 08:28:20 +0800 Subject: [PATCH] HTTP/2: make http2 server support http1 In-Reply-To: References: <20180305191459.GR89840@mdounin.ru> <9195D529-BCBA-4D20-8CB0-28683145D1E3@lvht.net> <1583421.Ry823iCY5n@vbart-workstation> Message-ID: <27CC686B-F25D-40D3-BFC0-D55CAB8BB834@lvht.net> Any body is here? > On Mar 21, 2018, at 11:36, Haitao Lv wrote: > > Thank you for reviewing. > > And here is the patch that fix the breaking PROXY protocol functionality. > > Sorry for disturbing. > > diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c > index 2db7a627..9f1b8544 100644 > --- a/src/http/ngx_http_request.c > +++ b/src/http/ngx_http_request.c > @@ -17,6 +17,10 @@ static ssize_t ngx_http_read_request_header(ngx_http_request_t *r); > static ngx_int_t ngx_http_alloc_large_header_buffer(ngx_http_request_t *r, > ngx_uint_t request_line); > > +#if (NGX_HTTP_V2) > +static void ngx_http_wait_v2_preface_handler(ngx_event_t *rev); > +#endif > + > static ngx_int_t ngx_http_process_header_line(ngx_http_request_t *r, > ngx_table_elt_t *h, ngx_uint_t offset); > static ngx_int_t ngx_http_process_unique_header_line(ngx_http_request_t *r, > @@ -325,7 +329,7 @@ ngx_http_init_connection(ngx_connection_t *c) > > #if (NGX_HTTP_V2) > if (hc->addr_conf->http2) { > - rev->handler = ngx_http_v2_init; > + rev->handler = ngx_http_wait_v2_preface_handler; > } > #endif > > @@ -381,6 +385,131 @@ ngx_http_init_connection(ngx_connection_t *c) > } > > > +#if (NGX_HTTP_V2) > +static void > +ngx_http_wait_v2_preface_handler(ngx_event_t *rev) > +{ > + size_t size; > + ssize_t n; > + u_char *p; > + ngx_buf_t *b; > + ngx_connection_t *c; > + ngx_http_connection_t *hc; > + static const u_char preface[] = "PRI"; > + > + c = rev->data; > + hc = c->data; > + > + size = sizeof(preface) - 1; > + > + if (hc->proxy_protocol) { > + size += NGX_PROXY_PROTOCOL_MAX_HEADER; > + } > + > + ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, > + "http wait h2 preface handler"); > + > + if (rev->timedout) { > + ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT, "client timed out"); > + ngx_http_close_connection(c); > + return; > + } > + > + if (c->close) { > + ngx_http_close_connection(c); > + return; > + } > + > + 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, b->end - b->last); > + > + if (n == NGX_AGAIN) { > + > + if (!rev->timer_set) { > + ngx_add_timer(rev, c->listening->post_accept_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; > + > + if (hc->proxy_protocol) { > + hc->proxy_protocol = 0; > + > + p = ngx_proxy_protocol_read(c, b->pos, b->last); > + > + if (p == NULL) { > + ngx_http_close_connection(c); > + return; > + } > + > + b->pos = p; > + } > + > + if (b->last >= b->pos + sizeof(preface) - 1) { > + /* b will be freed in ngx_http_v2_init/ngx_http_wait_request_handler */ > + > + if (ngx_strncmp(b->pos, preface, sizeof(preface) - 1) == 0) { > + ngx_http_v2_init(rev); > + } else { > + rev->handler = ngx_http_wait_request_handler; > + ngx_http_wait_request_handler(rev); > + } > + } > +} > +#endif > + > + > static void > ngx_http_wait_request_handler(ngx_event_t *rev) > { > @@ -393,6 +522,7 @@ ngx_http_wait_request_handler(ngx_event_t *rev) > ngx_http_core_srv_conf_t *cscf; > > c = rev->data; > + n = NGX_AGAIN; > > ngx_log_debug0(NGX_LOG_DEBUG_HTTP, c->log, 0, "http wait request handler"); > > @@ -434,9 +564,27 @@ ngx_http_wait_request_handler(ngx_event_t *rev) > b->pos = b->start; > b->last = b->start; > b->end = b->last + size; > + } else { > + > + p = ngx_palloc(c->pool, size); > + if (p == NULL) { > + ngx_http_close_connection(c); > + return; > + } > + > + n = b->last - b->pos; > + ngx_memcpy(p, b->pos, n); > + ngx_pfree(c->pool, b->start); > + > + b->start = p; > + b->pos = b->start; > + b->last = b->start + n; > + b->end = b->last + size; > } > > - n = c->recv(c, b->last, size); > + if (n == NGX_AGAIN) { > + n = c->recv(c, b->last, size); > + } > > if (n == NGX_AGAIN) { > > diff --git a/src/http/v2/ngx_http_v2.c b/src/http/v2/ngx_http_v2.c > index 77ebb847..6724b662 100644 > --- a/src/http/v2/ngx_http_v2.c > +++ b/src/http/v2/ngx_http_v2.c > @@ -229,6 +229,8 @@ static ngx_http_v2_parse_header_t ngx_http_v2_parse_headers[] = { > void > ngx_http_v2_init(ngx_event_t *rev) > { > + size_t size; > + ngx_buf_t *b; > ngx_connection_t *c; > ngx_pool_cleanup_t *cln; > ngx_http_connection_t *hc; > @@ -260,6 +262,23 @@ ngx_http_v2_init(ngx_event_t *rev) > return; > } > > + b = c->buffer; > + > + if (b != NULL) { > + size = b->last - b->pos; > + > + if (size > h2mcf->recv_buffer_size) { > + size = h2mcf->recv_buffer_size; > + } > + > + ngx_memcpy(h2mcf->recv_buffer, b->pos, size); > + h2c->state.buffer_used = size; > + > + ngx_pfree(c->pool, b->start); > + ngx_pfree(c->pool, b); > + c->buffer = NULL; > + } > + > h2c->connection = c; > h2c->http_connection = hc; > > @@ -379,13 +398,15 @@ ngx_http_v2_read_handler(ngx_event_t *rev) > h2mcf = ngx_http_get_module_main_conf(h2c->http_connection->conf_ctx, > ngx_http_v2_module); > > - available = h2mcf->recv_buffer_size - 2 * NGX_HTTP_V2_STATE_BUFFER_SIZE; > + available = h2mcf->recv_buffer_size - h2c->state.buffer_used - 2 * NGX_HTTP_V2_STATE_BUFFER_SIZE; > > do { > p = h2mcf->recv_buffer; > > - ngx_memcpy(p, h2c->state.buffer, NGX_HTTP_V2_STATE_BUFFER_SIZE); > end = p + h2c->state.buffer_used; > + if (h2c->state.buffer_used == 0) { > + ngx_memcpy(p, h2c->state.buffer, NGX_HTTP_V2_STATE_BUFFER_SIZE); > + } > > n = c->recv(c, end, available); > > > >> On Mar 21, 2018, at 00:02, Valentin V. Bartenev wrote: >> >> On Thursday 08 March 2018 08:42:27 Haitao Lv wrote: >>> Sorry for disturbing. But I have to fix a buffer overflow bug. >>> Here is the latest patch. >>> >>> Sorry. But please make your comments. Thank you. >> [..] >> >> There's no way for this patch to be accepted as it breaks PROXY protocol >> functionality. >> >> wbr, Valentin V. Bartenev >> >> _______________________________________________ >> nginx-devel mailing list >> nginx-devel at nginx.org >> http://mailman.nginx.org/mailman/listinfo/nginx-devel > > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel From xeioex at nginx.com Mon Apr 2 13:46:02 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 02 Apr 2018 13:46:02 +0000 Subject: [njs] Fixed the version of njs. Message-ID: details: http://hg.nginx.org/njs/rev/75d291c00c1f branches: changeset: 479:75d291c00c1f user: Dmitry Volyntsev date: Mon Apr 02 14:12:00 2018 +0300 description: Fixed the version of njs. The version in the code should be above the latest tag version. diffstat: njs/njscript.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 7a7160de8098 -r 75d291c00c1f njs/njscript.h --- a/njs/njscript.h Fri Mar 30 20:11:10 2018 +0300 +++ b/njs/njscript.h Mon Apr 02 14:12:00 2018 +0300 @@ -9,7 +9,7 @@ #ifndef _NJSCRIPT_H_INCLUDED_ #define _NJSCRIPT_H_INCLUDED_ -#define NJS_VERSION "0.1.15" +#define NJS_VERSION "0.2.0" typedef intptr_t njs_ret_t; From xeioex at nginx.com Mon Apr 2 14:13:04 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 02 Apr 2018 14:13:04 +0000 Subject: [njs] Added base64url encoding for crypto hash and HMAC digests. Message-ID: details: http://hg.nginx.org/njs/rev/4af5bd887b3f branches: changeset: 480:4af5bd887b3f user: Dmitry Volyntsev date: Mon Apr 02 17:12:52 2018 +0300 description: Added base64url encoding for crypto hash and HMAC digests. diffstat: njs/njs_crypto.c | 5 +++++ njs/test/njs_unit_test.c | 8 ++++++++ 2 files changed, 13 insertions(+), 0 deletions(-) diffs (40 lines): diff -r 75d291c00c1f -r 4af5bd887b3f njs/njs_crypto.c --- a/njs/njs_crypto.c Mon Apr 02 14:12:00 2018 +0300 +++ b/njs/njs_crypto.c Mon Apr 02 17:12:52 2018 +0300 @@ -127,6 +127,11 @@ static njs_crypto_enc_t njs_encodings[] }, { + nxt_string("base64url"), + njs_string_base64url + }, + + { nxt_null_string, NULL } diff -r 75d291c00c1f -r 4af5bd887b3f njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Mon Apr 02 14:12:00 2018 +0300 +++ b/njs/test/njs_unit_test.c Mon Apr 02 17:12:52 2018 +0300 @@ -9088,6 +9088,10 @@ static njs_unit_test_t njs_test[] = nxt_string("BtlFlCqiamG+GMPiK/GbvKjdK10=") }, { nxt_string("var h = require('crypto').createHash('sha1');" + "h.update('AB').digest('base64url')"), + nxt_string("BtlFlCqiamG-GMPiK_GbvKjdK10") }, + + { nxt_string("var h = require('crypto').createHash('sha1');" "h.update('AB').digest().toString('base64')"), nxt_string("BtlFlCqiamG+GMPiK/GbvKjdK10=") }, @@ -9166,6 +9170,10 @@ static njs_unit_test_t njs_test[] = nxt_string("rcYOA0WcS6589OttlzAAPpSQsi8=") }, { nxt_string("var h = require('crypto').createHmac('sha1', 'secret key');" + "h.update('AB').digest('base64url')"), + nxt_string("rcYOA0WcS6589OttlzAAPpSQsi8") }, + + { nxt_string("var h = require('crypto').createHmac('sha1', 'secret key');" "h.update('AB').digest().toString('base64')"), nxt_string("rcYOA0WcS6589OttlzAAPpSQsi8=") }, From arut at nginx.com Mon Apr 2 15:02:41 2018 From: arut at nginx.com (Roman Arutyunyan) Date: Mon, 02 Apr 2018 15:02:41 +0000 Subject: [njs] HTTP response return() method. Message-ID: details: http://hg.nginx.org/njs/rev/92b532d27d8d branches: changeset: 481:92b532d27d8d user: Roman Arutyunyan date: Mon Apr 02 18:01:34 2018 +0300 description: HTTP response return() method. The method is a shortcut for finalizing an HTTP request and is similar to nginx return directive. res.return(code[, text]): code - numeric status code. text - response body or redirect URI (for 3xx responses). diffstat: nginx/ngx_http_js_module.c | 93 +++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 91 insertions(+), 2 deletions(-) diffs (138 lines): diff -r 4af5bd887b3f -r 92b532d27d8d nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Mon Apr 02 17:12:52 2018 +0300 +++ b/nginx/ngx_http_js_module.c Mon Apr 02 18:01:34 2018 +0300 @@ -33,6 +33,7 @@ typedef struct { ngx_log_t *log; njs_opaque_value_t args[2]; ngx_uint_t done; + ngx_int_t status; } ngx_http_js_ctx_t; @@ -89,6 +90,8 @@ static njs_ret_t ngx_http_js_ext_send(nj nxt_uint_t nargs, njs_index_t unused); static njs_ret_t ngx_http_js_ext_finish(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); +static njs_ret_t ngx_http_js_ext_return(njs_vm_t *vm, njs_value_t *args, + nxt_uint_t nargs, njs_index_t unused); static njs_ret_t ngx_http_js_ext_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); @@ -290,6 +293,18 @@ static njs_external_t ngx_http_js_ext_r NULL, ngx_http_js_ext_finish, 0 }, + + { nxt_string("return"), + NJS_EXTERN_METHOD, + NULL, + 0, + NULL, + NULL, + NULL, + NULL, + NULL, + ngx_http_js_ext_return, + 0 }, }; @@ -658,7 +673,7 @@ ngx_http_js_content_event_handler(ngx_ht return; } - ngx_http_finalize_request(r, NGX_OK); + ngx_http_finalize_request(r, ctx->status); } @@ -676,7 +691,7 @@ ngx_http_js_content_write_event_handler( ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); if (!njs_vm_pending(ctx->vm)) { - ngx_http_finalize_request(r, NGX_OK); + ngx_http_finalize_request(r, ctx->status); return; } @@ -1252,6 +1267,80 @@ ngx_http_js_ext_finish(njs_vm_t *vm, njs static njs_ret_t +ngx_http_js_ext_return(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, + njs_index_t unused) +{ + nxt_str_t text; + ngx_int_t status; + const char *description; + njs_value_t *value; + ngx_http_js_ctx_t *ctx; + ngx_http_request_t *r; + ngx_http_complex_value_t cv; + + if (nargs < 2) { + description = "too few arguments"; + goto exception; + } + + value = njs_argument(args, 1); + if (!njs_value_is_number(value)) { + description = "code is not a number"; + goto exception; + } + + status = njs_value_number(value); + + if (status < 0 || status > 999) { + description = "code is out of range"; + goto exception; + } + + if (nargs < 3) { + text.start = NULL; + text.length = 0; + + } else { + if (njs_vm_value_to_ext_string(vm, &text, njs_argument(args, 2), 0) + == NJS_ERROR) + { + description = "failed to convert text"; + goto exception; + } + } + + r = njs_value_data(njs_argument(args, 0)); + + ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); + + if (status < NGX_HTTP_BAD_REQUEST || text.length) { + ngx_memzero(&cv, sizeof(ngx_http_complex_value_t)); + + cv.value.data = text.start; + cv.value.len = text.length; + + ctx->status = ngx_http_send_response(r, status, NULL, &cv); + + if (ctx->status == NGX_ERROR) { + description = "failed to send response"; + goto exception; + } + + } else { + ctx->status = status; + } + + return NJS_OK; + +exception: + + njs_value_error_set(vm, njs_vm_retval(vm), description, NULL); + + return NJS_ERROR; +} + + +static njs_ret_t ngx_http_js_ext_log(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { From ru at nginx.com Mon Apr 2 16:14:02 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Mon, 02 Apr 2018 16:14:02 +0000 Subject: [nginx] Core: revised the PROXY protocol v2 code. Message-ID: details: http://hg.nginx.org/nginx/rev/63e91f263a49 branches: changeset: 7253:63e91f263a49 user: Ruslan Ermilov date: Mon Apr 02 18:40:04 2018 +0300 description: Core: revised the PROXY protocol v2 code. - use normal prefixes for types and macros - removed some macros and types - revised debug messages - removed useless check of ngx_sock_ntop() returning 0 - removed special processing of AF_UNSPEC diffstat: src/core/ngx_proxy_protocol.c | 154 ++++++++++++++++++----------------------- 1 files changed, 69 insertions(+), 85 deletions(-) diffs (271 lines): diff -r 7bdab16c55f1 -r 63e91f263a49 src/core/ngx_proxy_protocol.c --- a/src/core/ngx_proxy_protocol.c Tue Mar 27 18:39:38 2018 +0300 +++ b/src/core/ngx_proxy_protocol.c Mon Apr 02 18:40:04 2018 +0300 @@ -9,54 +9,40 @@ #include -#define NGX_PP_V2_SIGLEN 12 -#define NGX_PP_V2_CMD_PROXY 1 -#define NGX_PP_V2_STREAM 1 - -#define NGX_PP_V2_AF_UNSPEC 0 -#define NGX_PP_V2_AF_INET 1 -#define NGX_PP_V2_AF_INET6 2 +#define NGX_PROXY_PROTOCOL_AF_INET 1 +#define NGX_PROXY_PROTOCOL_AF_INET6 2 -#define ngx_pp_v2_get_u16(p) ((p)[0] << 8 | (p)[1]) +#define ngx_proxy_protocol_parse_uint16(p) ((p)[0] << 8 | (p)[1]) typedef struct { - u_char signature[NGX_PP_V2_SIGLEN]; - u_char ver_cmd; - u_char family_transport; - u_char len[2]; -} ngx_pp_v2_header_t; + u_char signature[12]; + u_char version_command; + u_char family_transport; + u_char len[2]; +} ngx_proxy_protocol_header_t; typedef struct { - u_char src[4]; - u_char dst[4]; - u_char sport[2]; - u_char dport[2]; -} ngx_pp_v2_inet_addrs_t; + u_char s_addr[4]; + u_char d_addr[4]; + u_char s_port[2]; + u_char d_port[2]; +} ngx_proxy_protocol_inet_addrs_t; typedef struct { - u_char src[16]; - u_char dst[16]; - u_char sport[2]; - u_char dport[2]; -} ngx_pp_v2_inet6_addrs_t; - - -typedef union { - ngx_pp_v2_inet_addrs_t inet; - ngx_pp_v2_inet6_addrs_t inet6; -} ngx_pp_v2_addrs_t; + u_char s_addr[16]; + u_char d_addr[16]; + u_char s_port[2]; + u_char d_port[2]; +} ngx_proxy_protocol_inet6_addrs_t; static u_char *ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last); -static const u_char ngx_pp_v2_signature[NGX_PP_V2_SIGLEN] = - { 0x0d, 0x0a, 0x0d, 0x0a, 0x00, 0x0d, 0x0a, 0x51, 0x55, 0x49, 0x54, 0x0a }; - u_char * ngx_proxy_protocol_read(ngx_connection_t *c, u_char *buf, u_char *last) @@ -65,11 +51,13 @@ ngx_proxy_protocol_read(ngx_connection_t u_char ch, *p, *addr, *port; ngx_int_t n; + static const u_char signature[] = "\r\n\r\n\0\r\nQUIT\n"; + p = buf; len = last - buf; - if (len >= sizeof(ngx_pp_v2_header_t) - && memcmp(p, ngx_pp_v2_signature, NGX_PP_V2_SIGLEN) == 0) + if (len >= sizeof(ngx_proxy_protocol_header_t) + && memcmp(p, signature, sizeof(signature) - 1) == 0) { return ngx_proxy_protocol_v2_read(c, buf, last); } @@ -227,28 +215,30 @@ ngx_proxy_protocol_write(ngx_connection_ static u_char * ngx_proxy_protocol_v2_read(ngx_connection_t *c, u_char *buf, u_char *last) { - u_char *end; - size_t len; - socklen_t socklen; - ngx_str_t *name; - ngx_uint_t ver, cmd, family, transport; - ngx_sockaddr_t sockaddr; - ngx_pp_v2_addrs_t *addrs; - ngx_pp_v2_header_t *hdr; + u_char *end; + size_t len; + socklen_t socklen; + ngx_uint_t version, command, family, transport; + ngx_sockaddr_t sockaddr; + ngx_proxy_protocol_header_t *header; + ngx_proxy_protocol_inet_addrs_t *inet; +#if (NGX_HAVE_INET6) + ngx_proxy_protocol_inet6_addrs_t *inet6; +#endif - hdr = (ngx_pp_v2_header_t *) buf; + header = (ngx_proxy_protocol_header_t *) buf; - buf += sizeof(ngx_pp_v2_header_t); + buf += sizeof(ngx_proxy_protocol_header_t); - ver = hdr->ver_cmd >> 4; + version = header->version_command >> 4; - if (ver != 2) { + if (version != 2) { ngx_log_error(NGX_LOG_ERR, c->log, 0, - "unsupported PROXY protocol version: %ui", ver); + "unknown PROXY protocol version: %ui", version); return NULL; } - len = ngx_pp_v2_get_u16(hdr->len); + len = ngx_proxy_protocol_parse_uint16(header->len); if ((size_t) (last - buf) < len) { ngx_log_error(NGX_LOG_ERR, c->log, 0, "header is too large"); @@ -257,102 +247,96 @@ ngx_proxy_protocol_v2_read(ngx_connectio end = buf + len; - cmd = hdr->ver_cmd & 0x0f; + command = header->version_command & 0x0f; - if (cmd != NGX_PP_V2_CMD_PROXY) { + /* only PROXY is supported */ + if (command != 1) { ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 unsupported command 0x%xi", cmd); + "PROXY protocol v2 unsupported command %ui", command); return end; } - transport = hdr->family_transport & 0x0f; + transport = header->family_transport & 0x0f; - if (transport != NGX_PP_V2_STREAM) { + /* only STREAM is supported */ + if (transport != 1) { ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 unsupported transport 0x%xi", + "PROXY protocol v2 unsupported transport %ui", transport); return end; } - family = hdr->family_transport >> 4; - - addrs = (ngx_pp_v2_addrs_t *) buf; + family = header->family_transport >> 4; switch (family) { - case NGX_PP_V2_AF_UNSPEC: - ngx_log_debug0(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 AF_UNSPEC ignored"); - return end; + case NGX_PROXY_PROTOCOL_AF_INET: - case NGX_PP_V2_AF_INET: - - if ((size_t) (end - buf) < sizeof(ngx_pp_v2_inet_addrs_t)) { + if ((size_t) (end - buf) < sizeof(ngx_proxy_protocol_inet_addrs_t)) { return NULL; } + inet = (ngx_proxy_protocol_inet_addrs_t *) buf; + sockaddr.sockaddr_in.sin_family = AF_INET; sockaddr.sockaddr_in.sin_port = 0; - memcpy(&sockaddr.sockaddr_in.sin_addr, addrs->inet.src, 4); + memcpy(&sockaddr.sockaddr_in.sin_addr, inet->s_addr, 4); - c->proxy_protocol_port = ngx_pp_v2_get_u16(addrs->inet.sport); + c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(inet->s_port); socklen = sizeof(struct sockaddr_in); - buf += sizeof(ngx_pp_v2_inet_addrs_t); + buf += sizeof(ngx_proxy_protocol_inet_addrs_t); break; #if (NGX_HAVE_INET6) - case NGX_PP_V2_AF_INET6: + case NGX_PROXY_PROTOCOL_AF_INET6: - if ((size_t) (end - buf) < sizeof(ngx_pp_v2_inet6_addrs_t)) { + if ((size_t) (end - buf) < sizeof(ngx_proxy_protocol_inet6_addrs_t)) { return NULL; } + inet6 = (ngx_proxy_protocol_inet6_addrs_t *) buf; + sockaddr.sockaddr_in6.sin6_family = AF_INET6; sockaddr.sockaddr_in6.sin6_port = 0; - memcpy(&sockaddr.sockaddr_in6.sin6_addr, addrs->inet6.src, 16); + memcpy(&sockaddr.sockaddr_in6.sin6_addr, inet6->s_addr, 16); - c->proxy_protocol_port = ngx_pp_v2_get_u16(addrs->inet6.sport); + c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(inet6->s_port); socklen = sizeof(struct sockaddr_in6); - buf += sizeof(ngx_pp_v2_inet6_addrs_t); + buf += sizeof(ngx_proxy_protocol_inet6_addrs_t); break; #endif default: - ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 unsupported address family 0x%xi", + "PROXY protocol v2 unsupported address family %ui", family); return end; } - name = &c->proxy_protocol_addr; - - name->data = ngx_pnalloc(c->pool, NGX_SOCKADDR_STRLEN); - if (name->data == NULL) { + c->proxy_protocol_addr.data = ngx_pnalloc(c->pool, NGX_SOCKADDR_STRLEN); + if (c->proxy_protocol_addr.data == NULL) { return NULL; } - name->len = ngx_sock_ntop(&sockaddr.sockaddr, socklen, name->data, - NGX_SOCKADDR_STRLEN, 0); - if (name->len == 0) { - return NULL; - } + c->proxy_protocol_addr.len = ngx_sock_ntop(&sockaddr.sockaddr, socklen, + c->proxy_protocol_addr.data, + NGX_SOCKADDR_STRLEN, 0); ngx_log_debug2(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 address: %V %d", name, + "PROXY protocol v2 address: %V %d", &c->proxy_protocol_addr, c->proxy_protocol_port); if (buf < end) { ngx_log_debug1(NGX_LOG_DEBUG_CORE, c->log, 0, - "PROXY protocol v2 %z bytes tlv ignored", end - buf); + "PROXY protocol v2 %z bytes of tlv ignored", end - buf); } return end; From vl at nginx.com Mon Apr 2 18:37:45 2018 From: vl at nginx.com (Vladimir Homutov) Date: Mon, 02 Apr 2018 18:37:45 +0000 Subject: [nginx] Core: fixed build, broken by 63e91f263a49. Message-ID: details: http://hg.nginx.org/nginx/rev/1fd992589ffe branches: changeset: 7254:1fd992589ffe user: Vladimir Homutov date: Mon Apr 02 20:38:43 2018 +0300 description: Core: fixed build, broken by 63e91f263a49. Both Solaris and Windows define "s_addr" as a macro. diffstat: src/core/ngx_proxy_protocol.c | 32 ++++++++++++++++---------------- 1 files changed, 16 insertions(+), 16 deletions(-) diffs (76 lines): diff -r 63e91f263a49 -r 1fd992589ffe src/core/ngx_proxy_protocol.c --- a/src/core/ngx_proxy_protocol.c Mon Apr 02 18:40:04 2018 +0300 +++ b/src/core/ngx_proxy_protocol.c Mon Apr 02 20:38:43 2018 +0300 @@ -25,18 +25,18 @@ typedef struct { typedef struct { - u_char s_addr[4]; - u_char d_addr[4]; - u_char s_port[2]; - u_char d_port[2]; + u_char src_addr[4]; + u_char dst_addr[4]; + u_char src_port[2]; + u_char dst_port[2]; } ngx_proxy_protocol_inet_addrs_t; typedef struct { - u_char s_addr[16]; - u_char d_addr[16]; - u_char s_port[2]; - u_char d_port[2]; + u_char src_addr[16]; + u_char dst_addr[16]; + u_char src_port[2]; + u_char dst_port[2]; } ngx_proxy_protocol_inet6_addrs_t; @@ -221,9 +221,9 @@ ngx_proxy_protocol_v2_read(ngx_connectio ngx_uint_t version, command, family, transport; ngx_sockaddr_t sockaddr; ngx_proxy_protocol_header_t *header; - ngx_proxy_protocol_inet_addrs_t *inet; + ngx_proxy_protocol_inet_addrs_t *in; #if (NGX_HAVE_INET6) - ngx_proxy_protocol_inet6_addrs_t *inet6; + ngx_proxy_protocol_inet6_addrs_t *in6; #endif header = (ngx_proxy_protocol_header_t *) buf; @@ -276,13 +276,13 @@ ngx_proxy_protocol_v2_read(ngx_connectio return NULL; } - inet = (ngx_proxy_protocol_inet_addrs_t *) buf; + in = (ngx_proxy_protocol_inet_addrs_t *) buf; sockaddr.sockaddr_in.sin_family = AF_INET; sockaddr.sockaddr_in.sin_port = 0; - memcpy(&sockaddr.sockaddr_in.sin_addr, inet->s_addr, 4); + memcpy(&sockaddr.sockaddr_in.sin_addr, in->src_addr, 4); - c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(inet->s_port); + c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(in->src_port); socklen = sizeof(struct sockaddr_in); @@ -298,13 +298,13 @@ ngx_proxy_protocol_v2_read(ngx_connectio return NULL; } - inet6 = (ngx_proxy_protocol_inet6_addrs_t *) buf; + in6 = (ngx_proxy_protocol_inet6_addrs_t *) buf; sockaddr.sockaddr_in6.sin6_family = AF_INET6; sockaddr.sockaddr_in6.sin6_port = 0; - memcpy(&sockaddr.sockaddr_in6.sin6_addr, inet6->s_addr, 16); + memcpy(&sockaddr.sockaddr_in6.sin6_addr, in6->src_addr, 16); - c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(inet6->s_port); + c->proxy_protocol_port = ngx_proxy_protocol_parse_uint16(in6->src_port); socklen = sizeof(struct sockaddr_in6); From mdounin at mdounin.ru Tue Apr 3 00:43:28 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 03 Apr 2018 00:43:28 +0000 Subject: [nginx] Upstream: fixed ngx_http_upstream_test_next() conditions. Message-ID: details: http://hg.nginx.org/nginx/rev/4db4fe3bdeda branches: changeset: 7255:4db4fe3bdeda user: Maxim Dounin date: Tue Apr 03 02:43:18 2018 +0300 description: Upstream: fixed ngx_http_upstream_test_next() conditions. Previously, ngx_http_upstream_test_next() used an outdated condition on whether it will be possible to switch to a different server or not. It did not take into account restrictions on non-idempotent requests, requests with non-buffered request body, and the next upstream timeout. For such requests, switching to the next upstream server was rejected later in ngx_http_upstream_next(), resulting in nginx own error page being returned instead of the original upstream response. diffstat: src/http/ngx_http_upstream.c | 20 ++++++++++++++++++-- 1 files changed, 18 insertions(+), 2 deletions(-) diffs (37 lines): diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2389,7 +2389,8 @@ ngx_http_upstream_process_header(ngx_htt static ngx_int_t ngx_http_upstream_test_next(ngx_http_request_t *r, ngx_http_upstream_t *u) { - ngx_uint_t status; + ngx_msec_t timeout; + ngx_uint_t status, mask; ngx_http_upstream_next_t *un; status = u->headers_in.status_n; @@ -2400,7 +2401,22 @@ ngx_http_upstream_test_next(ngx_http_req continue; } - if (u->peer.tries > 1 && (u->conf->next_upstream & un->mask)) { + 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; } From mdounin at mdounin.ru Tue Apr 3 00:55:40 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 03 Apr 2018 00:55:40 +0000 Subject: [nginx] Updated OpenSSL and PCRE used for win32 builds. Message-ID: details: http://hg.nginx.org/nginx/rev/a7a277490ae7 branches: changeset: 7256:a7a277490ae7 user: Maxim Dounin date: Tue Apr 03 03:54:09 2018 +0300 description: Updated OpenSSL and PCRE used for win32 builds. diffstat: misc/GNUmakefile | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (15 lines): diff --git a/misc/GNUmakefile b/misc/GNUmakefile --- a/misc/GNUmakefile +++ b/misc/GNUmakefile @@ -6,9 +6,9 @@ TEMP = tmp CC = cl OBJS = objs.msvc8 -OPENSSL = openssl-1.0.2n +OPENSSL = openssl-1.0.2o ZLIB = zlib-1.2.11 -PCRE = pcre-8.41 +PCRE = pcre-8.42 release: export From xeioex at nginx.com Tue Apr 3 10:57:19 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 10:57:19 +0000 Subject: [njs] Added global njs object. Message-ID: details: http://hg.nginx.org/njs/rev/a191987786fd branches: changeset: 482:a191987786fd user: Dmitry Volyntsev date: Tue Apr 03 13:56:54 2018 +0300 description: Added global njs object. diffstat: njs/njs_builtin.c | 19 +++++++++++++++++++ njs/njs_generator.c | 1 + njs/njs_lexer_keyword.c | 1 + njs/njs_parser.c | 1 + njs/njs_parser.h | 1 + njs/njs_vm.h | 1 + njs/test/njs_expect_test.exp | 5 +++++ njs/test/njs_unit_test.c | 3 +++ 8 files changed, 32 insertions(+), 0 deletions(-) diffs (119 lines): diff -r 92b532d27d8d -r a191987786fd njs/njs_builtin.c --- a/njs/njs_builtin.c Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_builtin.c Tue Apr 03 13:56:54 2018 +0300 @@ -50,9 +50,11 @@ static nxt_array_t *njs_vm_expression_co nxt_str_t *expression); static nxt_array_t *njs_object_completions(njs_vm_t *vm, njs_object_t *object); +const njs_object_init_t njs_njs_object_init; const njs_object_init_t *njs_object_init[] = { NULL, /* global this */ + &njs_njs_object_init, /* global njs object */ &njs_math_object_init, /* Math */ &njs_json_object_init, /* JSON */ }; @@ -1086,3 +1088,20 @@ njs_builtin_match_native_function(njs_vm return NXT_DECLINED; } + + +static const njs_object_prop_t njs_njs_object_properties[] = +{ + { + .type = NJS_PROPERTY, + .name = njs_string("version"), + .value = njs_string(NJS_VERSION), + }, +}; + + +const njs_object_init_t njs_njs_object_init = { + nxt_string("njs"), + njs_njs_object_properties, + nxt_nitems(njs_njs_object_properties), +}; diff -r 92b532d27d8d -r a191987786fd njs/njs_generator.c --- a/njs/njs_generator.c Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_generator.c Tue Apr 03 13:56:54 2018 +0300 @@ -307,6 +307,7 @@ njs_generator(njs_vm_t *vm, njs_parser_t return njs_generate_name(vm, parser, node); case NJS_TOKEN_GLOBAL_THIS: + case NJS_TOKEN_NJS: case NJS_TOKEN_MATH: case NJS_TOKEN_JSON: case NJS_TOKEN_EVAL: diff -r 92b532d27d8d -r a191987786fd njs/njs_lexer_keyword.c --- a/njs/njs_lexer_keyword.c Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_lexer_keyword.c Tue Apr 03 13:56:54 2018 +0300 @@ -68,6 +68,7 @@ static const njs_keyword_t njs_keywords /* Builtin objects. */ { nxt_string("this"), NJS_TOKEN_THIS, 0 }, + { nxt_string("njs"), NJS_TOKEN_NJS, 0 }, { nxt_string("Math"), NJS_TOKEN_MATH, 0 }, { nxt_string("JSON"), NJS_TOKEN_JSON, 0 }, diff -r 92b532d27d8d -r a191987786fd njs/njs_parser.c --- a/njs/njs_parser.c Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_parser.c Tue Apr 03 13:56:54 2018 +0300 @@ -1989,6 +1989,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa /* Fall through. */ + case NJS_TOKEN_NJS: case NJS_TOKEN_MATH: case NJS_TOKEN_JSON: return njs_parser_builtin_object(vm, parser, node); diff -r 92b532d27d8d -r a191987786fd njs/njs_parser.h --- a/njs/njs_parser.h Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_parser.h Tue Apr 03 13:56:54 2018 +0300 @@ -165,6 +165,7 @@ typedef enum { #define NJS_TOKEN_FIRST_OBJECT NJS_TOKEN_GLOBAL_THIS NJS_TOKEN_GLOBAL_THIS, + NJS_TOKEN_NJS, NJS_TOKEN_MATH, NJS_TOKEN_JSON, diff -r 92b532d27d8d -r a191987786fd njs/njs_vm.h --- a/njs/njs_vm.h Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/njs_vm.h Tue Apr 03 13:56:54 2018 +0300 @@ -870,6 +870,7 @@ enum njs_constructor_e { enum njs_object_e { NJS_OBJECT_THIS = 0, + NJS_OBJECT_NJS, NJS_OBJECT_MATH, NJS_OBJECT_JSON, #define NJS_OBJECT_MAX (NJS_OBJECT_JSON + 1) diff -r 92b532d27d8d -r a191987786fd njs/test/njs_expect_test.exp --- a/njs/test/njs_expect_test.exp Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/test/njs_expect_test.exp Tue Apr 03 13:56:54 2018 +0300 @@ -23,6 +23,11 @@ type console.help() for more information expect eof } +njs_test { + {"njs.version\r\n" + "njs.version\r\n\*\.\*\.\*"} +} + # simple multi line interation njs_test { {"var a = 1\r\n" diff -r 92b532d27d8d -r a191987786fd njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Mon Apr 02 18:01:34 2018 +0300 +++ b/njs/test/njs_unit_test.c Tue Apr 03 13:56:54 2018 +0300 @@ -5741,6 +5741,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("this"), nxt_string("[object Object]") }, + { nxt_string("njs"), + nxt_string("[object Object]") }, + { nxt_string("var o = Object(); o"), nxt_string("[object Object]") }, From xeioex at nginx.com Tue Apr 3 10:58:47 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 10:58:47 +0000 Subject: [njs] Version 0.2.0. Message-ID: details: http://hg.nginx.org/njs/rev/ddd1b2c9c64b branches: changeset: 483:ddd1b2c9c64b user: Dmitry Volyntsev date: Tue Apr 03 13:57:42 2018 +0300 description: Version 0.2.0. diffstat: CHANGES | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-) diffs (28 lines): diff -r a191987786fd -r ddd1b2c9c64b CHANGES --- a/CHANGES Tue Apr 03 13:56:54 2018 +0300 +++ b/CHANGES Tue Apr 03 13:57:42 2018 +0300 @@ -1,3 +1,24 @@ + +Changes with nJScript 0.2.0 3 Apr 2018 + + *) Feature: reporting njs version by CLI. + + *) Feature: textual description for type converting exceptions. + + *) Feature: setTimeout() and clearTimeout() methods. + + *) Feature: Byte string to hex, base64, base64url encodings. + + *) Feature: Node.js style crypto methods. + + *) Feature: HTTP and stream warn() and error() methods. + + *) Feature: HTTP subrequest() method. + + *) Feature: HTTP return() method. + + *) Bugfix: miscellaneous bugs have been fixed in the core and + interactive shell. Changes with nJScript 0.1.15 20 Nov 2017 From xeioex at nginx.com Tue Apr 3 10:58:47 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 10:58:47 +0000 Subject: [njs] Added tag 0.2.0 for changeset ddd1b2c9c64b Message-ID: details: http://hg.nginx.org/njs/rev/81fa04d45e9a branches: changeset: 484:81fa04d45e9a user: Dmitry Volyntsev date: Tue Apr 03 13:58:34 2018 +0300 description: Added tag 0.2.0 for changeset ddd1b2c9c64b diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff -r ddd1b2c9c64b -r 81fa04d45e9a .hgtags --- a/.hgtags Tue Apr 03 13:57:42 2018 +0300 +++ b/.hgtags Tue Apr 03 13:58:34 2018 +0300 @@ -14,3 +14,4 @@ c07b060396be3622ca97b037a86076b61b850847 d548b78eb881ca799aa6fc8ba459d076f7db5ac8 0.1.13 d89d06dc638e78f8635c0bfbcd02469ac1a08748 0.1.14 215ca47b9167d513fd58ac88de97659377e45275 0.1.15 +ddd1b2c9c64b2d459e9c399554dfaadcaabcc364 0.2.0 From xeioex at nginx.com Tue Apr 3 11:53:53 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 11:53:53 +0000 Subject: [njs] Version bump. Message-ID: details: http://hg.nginx.org/njs/rev/2516949f7ff4 branches: changeset: 485:2516949f7ff4 user: Dmitry Volyntsev date: Tue Apr 03 14:01:06 2018 +0300 description: Version bump. diffstat: njs/njscript.h | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 81fa04d45e9a -r 2516949f7ff4 njs/njscript.h --- a/njs/njscript.h Tue Apr 03 13:58:34 2018 +0300 +++ b/njs/njscript.h Tue Apr 03 14:01:06 2018 +0300 @@ -9,7 +9,7 @@ #ifndef _NJSCRIPT_H_INCLUDED_ #define _NJSCRIPT_H_INCLUDED_ -#define NJS_VERSION "0.2.0" +#define NJS_VERSION "0.2.1" typedef intptr_t njs_ret_t; From xeioex at nginx.com Tue Apr 3 11:53:53 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 11:53:53 +0000 Subject: [njs] 2018 year. Message-ID: details: http://hg.nginx.org/njs/rev/08b637d9a099 branches: changeset: 486:08b637d9a099 user: Dmitry Volyntsev date: Tue Apr 03 14:51:22 2018 +0300 description: 2018 year. diffstat: LICENSE | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diffs (13 lines): diff -r 2516949f7ff4 -r 08b637d9a099 LICENSE --- a/LICENSE Tue Apr 03 14:01:06 2018 +0300 +++ b/LICENSE Tue Apr 03 14:51:22 2018 +0300 @@ -1,6 +1,7 @@ /* - * Copyright (C) 2015-2017 Igor Sysoev - * Copyright (C) 2015-2017 NGINX, Inc. + * Copyright (C) 2015-2018 Igor Sysoev + * Copyright (C) 2017-2018 Dmitry Volynsev + * Copyright (C) 2015-2018 NGINX, Inc. * All rights reserved. * * Redistribution and use in source and binary forms, with or without From mdounin at mdounin.ru Tue Apr 3 14:42:53 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 03 Apr 2018 14:42:53 +0000 Subject: [nginx] nginx-1.13.11-RELEASE Message-ID: details: http://hg.nginx.org/nginx/rev/64179f242cb5 branches: changeset: 7257:64179f242cb5 user: Maxim Dounin date: Tue Apr 03 17:38:09 2018 +0300 description: nginx-1.13.11-RELEASE diffstat: docs/xml/nginx/changes.xml | 36 ++++++++++++++++++++++++++++++++++++ 1 files changed, 36 insertions(+), 0 deletions(-) diffs (46 lines): diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml --- a/docs/xml/nginx/changes.xml +++ b/docs/xml/nginx/changes.xml @@ -5,6 +5,42 @@ + + + + +???????? proxy_protocol ????????? listen +?????? ???????????? ???????? PROXY ?????? 2. + + +the "proxy_protocol" parameter of the "listen" directive +now supports the PROXY protocol version 2. + + + + + +nginx ?? ????????? ? OpenSSL 1.1.1 ?????????? ?? Linux. + + +nginx could not be built with OpenSSL 1.1.1 statically on Linux. + + + + + +? ?????????? http_404, http_500 ? ?? ???????? +????????? proxy_next_upstream. + + +in the "http_404", "http_500", etc. parameters +of the "proxy_next_upstream" directive. + + + + + + From mdounin at mdounin.ru Tue Apr 3 14:42:55 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 03 Apr 2018 14:42:55 +0000 Subject: [nginx] release-1.13.11 tag Message-ID: details: http://hg.nginx.org/nginx/rev/d4cc2edb4ff8 branches: changeset: 7258:d4cc2edb4ff8 user: Maxim Dounin date: Tue Apr 03 17:38:10 2018 +0300 description: release-1.13.11 tag diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -423,3 +423,4 @@ 47cca243d0ed39bf5dcb9859184affc958b79b6f 20ca4bcff108d3e66977f4d97508637093492287 release-1.13.8 fb1212c7eca4c5328fe17d6cd95b010c67336aac release-1.13.9 31c929e16910c38492581ef474e72fa67c28f124 release-1.13.10 +64179f242cb55fc206bca59de9bfdc4cf5ebcec7 release-1.13.11 From igor at sysoev.ru Tue Apr 3 14:56:29 2018 From: igor at sysoev.ru (Igor Sysoev) Date: Tue, 03 Apr 2018 14:56:29 +0000 Subject: [njs] Small optimizations. Message-ID: details: http://hg.nginx.org/njs/rev/addefc71957b branches: changeset: 488:addefc71957b user: Igor Sysoev date: Tue Apr 03 17:55:08 2018 +0300 description: Small optimizations. diffstat: njs/njs_parser_expression.c | 25 +++++++++++-------------- 1 files changed, 11 insertions(+), 14 deletions(-) diffs (63 lines): diff -r 671d9dd1ffeb -r addefc71957b njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Apr 03 17:55:04 2018 +0300 +++ b/njs/njs_parser_expression.c Tue Apr 03 17:55:08 2018 +0300 @@ -762,19 +762,16 @@ njs_parser_unary_expression(njs_vm_t *vm return NJS_TOKEN_ILLEGAL; } - if (token == NJS_TOKEN_UNARY_PLUS - && parser->node->token == NJS_TOKEN_NUMBER) - { + node = parser->node; + + if (token == NJS_TOKEN_UNARY_PLUS && node->token == NJS_TOKEN_NUMBER) { /* Skip the unary plus of number. */ return next; } - if (token == NJS_TOKEN_UNARY_NEGATION - && parser->node->token == NJS_TOKEN_NUMBER) - { + if (token == NJS_TOKEN_UNARY_NEGATION && node->token == NJS_TOKEN_NUMBER) { + /* Optimization of common negative number. */ - - node = parser->node; num = -node->u.value.data.u.number; node->u.value.data.u.number = num; node->u.value.data.truth = njs_is_number_true(num); @@ -784,11 +781,11 @@ njs_parser_unary_expression(njs_vm_t *vm if (token == NJS_TOKEN_DELETE) { - switch (parser->node->token) { + switch (node->token) { case NJS_TOKEN_PROPERTY: - parser->node->token = NJS_TOKEN_PROPERTY_DELETE; - parser->node->u.operation = njs_vmcode_property_delete; + node->token = NJS_TOKEN_PROPERTY_DELETE; + node->u.operation = njs_vmcode_property_delete; parser->code_size += sizeof(njs_vmcode_3addr_t); return next; @@ -805,8 +802,8 @@ njs_parser_unary_expression(njs_vm_t *vm } } - if (token == NJS_TOKEN_TYPEOF && parser->node->token == NJS_TOKEN_NAME) { - parser->node->reference = NJS_TYPEOF; + if (token == NJS_TOKEN_TYPEOF && node->token == NJS_TOKEN_NAME) { + node->reference = NJS_TYPEOF; } node = njs_parser_node_alloc(vm); @@ -876,7 +873,7 @@ njs_parser_inc_dec_expression(njs_vm_t * node->left = parser->node; parser->node = node; - parser->code_size += (parser->node->token == NJS_TOKEN_NAME) ? + parser->code_size += (node->token == NJS_TOKEN_NAME) ? sizeof(njs_vmcode_3addr_t): sizeof(njs_vmcode_prop_get_t) + sizeof(njs_vmcode_3addr_t) From igor at sysoev.ru Tue Apr 3 14:56:30 2018 From: igor at sysoev.ru (Igor Sysoev) Date: Tue, 03 Apr 2018 14:56:30 +0000 Subject: [njs] Style fixes. Message-ID: details: http://hg.nginx.org/njs/rev/39374a5d6cda branches: changeset: 489:39374a5d6cda user: Igor Sysoev date: Tue Apr 03 17:55:23 2018 +0300 description: Style fixes. diffstat: njs/njs_parser.h | 4 ++-- njs/njs_parser_expression.c | 20 ++++++++++---------- njs/njs_vm.c | 4 +--- 3 files changed, 13 insertions(+), 15 deletions(-) diffs (66 lines): diff -r addefc71957b -r 39374a5d6cda njs/njs_parser.h --- a/njs/njs_parser.h Tue Apr 03 17:55:08 2018 +0300 +++ b/njs/njs_parser.h Tue Apr 03 17:55:23 2018 +0300 @@ -389,9 +389,9 @@ nxt_bool_t njs_parser_has_side_effect(nj u_char *njs_parser_trace_handler(nxt_trace_t *trace, nxt_trace_data_t *td, u_char *start); void njs_parser_syntax_error(njs_vm_t *vm, njs_parser_t *parser, - const char* fmt, ...); + const char* fmt, ...); void njs_parser_ref_error(njs_vm_t *vm, njs_parser_t *parser, const char* fmt, - ...); + ...); nxt_int_t njs_generate_scope(njs_vm_t *vm, njs_parser_t *parser, njs_parser_node_t *node); diff -r addefc71957b -r 39374a5d6cda njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Apr 03 17:55:08 2018 +0300 +++ b/njs/njs_parser_expression.c Tue Apr 03 17:55:23 2018 +0300 @@ -873,11 +873,11 @@ njs_parser_inc_dec_expression(njs_vm_t * node->left = parser->node; parser->node = node; - parser->code_size += (node->token == NJS_TOKEN_NAME) ? - sizeof(njs_vmcode_3addr_t): - sizeof(njs_vmcode_prop_get_t) - + sizeof(njs_vmcode_3addr_t) - + sizeof(njs_vmcode_prop_set_t); + parser->code_size += (token == NJS_TOKEN_NAME) + ? sizeof(njs_vmcode_3addr_t) + : sizeof(njs_vmcode_prop_get_t) + + sizeof(njs_vmcode_3addr_t) + + sizeof(njs_vmcode_prop_set_t); return next; } @@ -929,11 +929,11 @@ njs_parser_post_inc_dec_expression(njs_v node->left = parser->node; parser->node = node; - parser->code_size += (parser->node->token == NJS_TOKEN_NAME) ? - sizeof(njs_vmcode_3addr_t): - sizeof(njs_vmcode_prop_get_t) - + sizeof(njs_vmcode_3addr_t) - + sizeof(njs_vmcode_prop_set_t); + parser->code_size += (token == NJS_TOKEN_NAME) + ? sizeof(njs_vmcode_3addr_t) + : sizeof(njs_vmcode_prop_get_t) + + sizeof(njs_vmcode_3addr_t) + + sizeof(njs_vmcode_prop_set_t); return njs_parser_token(parser); } diff -r addefc71957b -r 39374a5d6cda njs/njs_vm.c --- a/njs/njs_vm.c Tue Apr 03 17:55:08 2018 +0300 +++ b/njs/njs_vm.c Tue Apr 03 17:55:23 2018 +0300 @@ -2394,9 +2394,7 @@ njs_vmcode_method_frame(njs_vm_t *vm, nj break; case NXT_ERROR: - - /* An exception was set in njs_property_query(). */ - + /* An exception was set in njs_property_query(). */ return NXT_ERROR; default: From igor at sysoev.ru Tue Apr 3 14:56:29 2018 From: igor at sysoev.ru (Igor Sysoev) Date: Tue, 03 Apr 2018 14:56:29 +0000 Subject: [njs] The typeof operation did not work in functions. Message-ID: details: http://hg.nginx.org/njs/rev/671d9dd1ffeb branches: changeset: 487:671d9dd1ffeb user: Igor Sysoev date: Tue Apr 03 17:55:04 2018 +0300 description: The typeof operation did not work in functions. diffstat: njs/njs_parser.c | 14 +++++++------- njs/njs_parser.h | 8 ++++---- njs/njs_parser_expression.c | 4 ++++ njs/njs_variable.c | 9 ++++++--- njs/njs_variable.h | 7 +++++++ njs/test/njs_unit_test.c | 3 +++ 6 files changed, 31 insertions(+), 14 deletions(-) diffs (169 lines): diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser.c --- a/njs/njs_parser.c Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/njs_parser.c Tue Apr 03 17:55:04 2018 +0300 @@ -483,7 +483,7 @@ njs_parser_function_declaration(njs_vm_t return NJS_TOKEN_ERROR; } - ret = njs_variable_reference(vm, parser, node, 0); + ret = njs_variable_reference(vm, parser, node, NJS_DECLARATION); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -857,7 +857,7 @@ njs_parser_var_statement(njs_vm_t *vm, n name->token = NJS_TOKEN_NAME; - ret = njs_variable_reference(vm, parser, name, 0); + ret = njs_variable_reference(vm, parser, name, NJS_DECLARATION); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -1342,7 +1342,7 @@ njs_parser_for_var_statement(njs_vm_t *v name->token = NJS_TOKEN_NAME; - ret = njs_variable_reference(vm, parser, name, 0); + ret = njs_variable_reference(vm, parser, name, NJS_DECLARATION); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -1634,7 +1634,7 @@ njs_parser_try_statement(njs_vm_t *vm, n node->token = NJS_TOKEN_NAME; - ret = njs_variable_reference(vm, parser, node, 0); + ret = njs_variable_reference(vm, parser, node, NJS_DECLARATION); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -1852,7 +1852,7 @@ njs_parser_terminal(njs_vm_t *vm, njs_pa break; } - ret = njs_variable_reference(vm, parser, node, 1); + ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -2106,7 +2106,7 @@ njs_parser_builtin_object(njs_vm_t *vm, var->value.type = NJS_OBJECT; var->value.data.truth = 1; - ret = njs_variable_reference(vm, parser, node, 1); + ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } @@ -2139,7 +2139,7 @@ njs_parser_builtin_function(njs_vm_t *vm var->value.type = NJS_FUNCTION; var->value.data.truth = 1; - ret = njs_variable_reference(vm, parser, node, 1); + ret = njs_variable_reference(vm, parser, node, NJS_REFERENCE); if (nxt_slow_path(ret != NXT_OK)) { return NJS_TOKEN_ERROR; } diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser.h --- a/njs/njs_parser.h Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/njs_parser.h Tue Apr 03 17:55:04 2018 +0300 @@ -255,9 +255,9 @@ typedef struct njs_parser_node_s njs_ struct njs_parser_node_s { njs_token_t token:16; - uint8_t ctor:1; /* 1 bit */ - uint8_t temporary; /* 1 bit */ - uint8_t reference; /* 1 bit */ + uint8_t ctor:1; + njs_variable_reference_t reference:2; + uint8_t temporary; /* 1 bit */ uint32_t token_line; uint32_t variable_name_hash; @@ -381,7 +381,7 @@ njs_token_t njs_parser_property_token(nj njs_token_t njs_parser_token(njs_parser_t *parser); nxt_int_t njs_parser_string_create(njs_vm_t *vm, njs_value_t *value); njs_ret_t njs_variable_reference(njs_vm_t *vm, njs_parser_t *parser, - njs_parser_node_t *node, nxt_bool_t reference); + njs_parser_node_t *node, njs_variable_reference_t reference); njs_variable_t *njs_variable_get(njs_vm_t *vm, njs_parser_node_t *node); njs_index_t njs_variable_typeof(njs_vm_t *vm, njs_parser_node_t *node); njs_index_t njs_variable_index(njs_vm_t *vm, njs_parser_node_t *node); diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/njs_parser_expression.c Tue Apr 03 17:55:04 2018 +0300 @@ -805,6 +805,10 @@ njs_parser_unary_expression(njs_vm_t *vm } } + if (token == NJS_TOKEN_TYPEOF && parser->node->token == NJS_TOKEN_NAME) { + parser->node->reference = NJS_TYPEOF; + } + node = njs_parser_node_alloc(vm); if (nxt_slow_path(node == NULL)) { return NJS_TOKEN_ERROR; diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_variable.c --- a/njs/njs_variable.c Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/njs_variable.c Tue Apr 03 17:55:04 2018 +0300 @@ -193,7 +193,7 @@ const nxt_lvlhsh_proto_t njs_reference_ njs_ret_t njs_variable_reference(njs_vm_t *vm, njs_parser_t *parser, - njs_parser_node_t *node, nxt_bool_t reference) + njs_parser_node_t *node, njs_variable_reference_t reference) { njs_ret_t ret; nxt_lvlhsh_query_t lhq; @@ -277,8 +277,11 @@ njs_variables_scope_resolve(njs_vm_t *vm } var = njs_variable_get(vm, node); + if (nxt_slow_path(var == NULL)) { - return NXT_ERROR; + if (node->reference != NJS_TYPEOF) { + return NXT_ERROR; + } } } } @@ -397,7 +400,7 @@ njs_variable_get(njs_vm_t *vm, njs_parse var->argument = index; } - if (node->reference && var->type <= NJS_VARIABLE_LET) { + if (node->reference != NJS_DECLARATION && var->type <= NJS_VARIABLE_LET) { goto not_found; } diff -r 08b637d9a099 -r 671d9dd1ffeb njs/njs_variable.h --- a/njs/njs_variable.h Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/njs_variable.h Tue Apr 03 17:55:04 2018 +0300 @@ -18,6 +18,13 @@ typedef enum { } njs_variable_type_t; +typedef enum { + NJS_DECLARATION = 0, + NJS_REFERENCE, + NJS_TYPEOF, +} njs_variable_reference_t; + + typedef struct { nxt_str_t name; diff -r 08b637d9a099 -r 671d9dd1ffeb njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Tue Apr 03 14:51:22 2018 +0300 +++ b/njs/test/njs_unit_test.c Tue Apr 03 17:55:04 2018 +0300 @@ -2318,6 +2318,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = 5; typeof a"), nxt_string("number") }, + { nxt_string("function f() { return typeof a } ; f()"), + nxt_string("undefined") }, + { nxt_string("typeof a; a"), nxt_string("ReferenceError: \"a\" is not defined in 1") }, From igor at sysoev.ru Tue Apr 3 14:56:30 2018 From: igor at sysoev.ru (Igor Sysoev) Date: Tue, 03 Apr 2018 14:56:30 +0000 Subject: [njs] Exact values for default switch case expressions. Message-ID: details: http://hg.nginx.org/njs/rev/641b3189d658 branches: changeset: 490:641b3189d658 user: Igor Sysoev date: Tue Apr 03 17:55:56 2018 +0300 description: Exact values for default switch case expressions. diffstat: njs/njs_lexer.c | 3 ++- njs/njs_string.c | 6 ++++-- njs/njs_string.h | 3 ++- njs/njs_vm.c | 20 +++++++++++--------- 4 files changed, 19 insertions(+), 13 deletions(-) diffs (111 lines): diff -r 39374a5d6cda -r 641b3189d658 njs/njs_lexer.c --- a/njs/njs_lexer.c Tue Apr 03 17:55:23 2018 +0300 +++ b/njs/njs_lexer.c Tue Apr 03 17:55:56 2018 +0300 @@ -427,7 +427,8 @@ njs_lexer_next_token(njs_lexer_t *lexer) lexer->text.length = lexer->start - lexer->text.start; return token; - default: /* NJS_TOKEN_ILLEGAL */ + case NJS_TOKEN_ILLEGAL: + default: lexer->start--; return token; } diff -r 39374a5d6cda -r 641b3189d658 njs/njs_string.c --- a/njs/njs_string.c Tue Apr 03 17:55:23 2018 +0300 +++ b/njs/njs_string.c Tue Apr 03 17:55:56 2018 +0300 @@ -2137,7 +2137,8 @@ njs_string_prototype_search(njs_vm_t *vm goto done; - default: /* NJS_VOID */ + case NJS_VOID: + default: goto done; } @@ -2452,7 +2453,8 @@ njs_string_prototype_split(njs_vm_t *vm, goto done; - default: /* NJS_VOID */ + case NJS_VOID: + default: break; } } diff -r 39374a5d6cda -r 641b3189d658 njs/njs_string.h --- a/njs/njs_string.h Tue Apr 03 17:55:23 2018 +0300 +++ b/njs/njs_string.h Tue Apr 03 17:55:56 2018 +0300 @@ -112,7 +112,8 @@ njs_string_length(njs_utf8_t utf8, u_cha case NJS_STRING_ASCII: return size; - default: /* NJS_STRING_UTF8 */ + case NJS_STRING_UTF8: + default: length = nxt_utf8_length(start, size); return (length >= 0) ? length : 0; diff -r 39374a5d6cda -r 641b3189d658 njs/njs_vm.c --- a/njs/njs_vm.c Tue Apr 03 17:55:23 2018 +0300 +++ b/njs/njs_vm.c Tue Apr 03 17:55:56 2018 +0300 @@ -649,9 +649,9 @@ njs_vmcode_property_get(njs_vm_t *vm, nj return sizeof(njs_vmcode_prop_get_t); + case NJS_TRAP_PROPERTY: + case NXT_ERROR: default: - /* NJS_TRAP_PROPERTY */ - /* NXT_ERROR */ return ret; } @@ -760,9 +760,9 @@ njs_vmcode_property_set(njs_vm_t *vm, nj return sizeof(njs_vmcode_prop_set_t); + case NJS_TRAP_PROPERTY: + case NXT_ERROR: default: - /* NJS_TRAP_PROPERTY */ - /* NXT_ERROR */ return ret; } @@ -844,9 +844,9 @@ njs_vmcode_property_in(njs_vm_t *vm, njs break; + case NJS_TRAP_PROPERTY: + case NXT_ERROR: default: - /* NJS_TRAP_PROPERTY */ - /* NXT_ERROR */ return ret; } @@ -946,9 +946,9 @@ njs_vmcode_property_delete(njs_vm_t *vm, break; + case NJS_TRAP_PROPERTY: + case NXT_ERROR: default: - /* NJS_TRAP_PROPERTY */ - /* NXT_ERROR */ return ret; } @@ -1059,7 +1059,9 @@ njs_property_query(njs_vm_t *vm, njs_pro obj = NULL; break; - default: /* NJS_VOID, NJS_NULL. */ + case NJS_VOID: + case NJS_NULL: + default: if (nxt_fast_path(njs_is_primitive(property))) { ret = njs_primitive_value_to_string(vm, &pq->value, property); From xeioex at nginx.com Tue Apr 3 16:49:08 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Tue, 03 Apr 2018 16:49:08 +0000 Subject: [njs] Fixed surname spelling. Message-ID: details: http://hg.nginx.org/njs/rev/c64c3f5b6328 branches: changeset: 491:c64c3f5b6328 user: Dmitry Volyntsev date: Tue Apr 03 19:47:57 2018 +0300 description: Fixed surname spelling. diffstat: LICENSE | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (11 lines): diff -r 641b3189d658 -r c64c3f5b6328 LICENSE --- a/LICENSE Tue Apr 03 17:55:56 2018 +0300 +++ b/LICENSE Tue Apr 03 19:47:57 2018 +0300 @@ -1,6 +1,6 @@ /* * Copyright (C) 2015-2018 Igor Sysoev - * Copyright (C) 2017-2018 Dmitry Volynsev + * Copyright (C) 2017-2018 Dmitry Volyntsev * Copyright (C) 2015-2018 NGINX, Inc. * All rights reserved. * From igor at sysoev.ru Wed Apr 4 13:22:26 2018 From: igor at sysoev.ru (Igor Sysoev) Date: Wed, 04 Apr 2018 13:22:26 +0000 Subject: [njs] Using correct code size addition. Message-ID: details: http://hg.nginx.org/njs/rev/5fd1cb826b96 branches: changeset: 492:5fd1cb826b96 user: Igor Sysoev date: Wed Apr 04 16:21:09 2018 +0300 description: Using correct code size addition. Found by Clang Static Analyzer. diffstat: njs/njs_parser_expression.c | 22 ++++++++++------------ 1 files changed, 10 insertions(+), 12 deletions(-) diffs (53 lines): diff -r c64c3f5b6328 -r 5fd1cb826b96 njs/njs_parser_expression.c --- a/njs/njs_parser_expression.c Tue Apr 03 19:47:57 2018 +0300 +++ b/njs/njs_parser_expression.c Wed Apr 04 16:21:09 2018 +0300 @@ -862,6 +862,11 @@ njs_parser_inc_dec_expression(njs_vm_t * return NJS_TOKEN_ILLEGAL; } + parser->code_size += (parser->node->token == NJS_TOKEN_NAME) + ? sizeof(njs_vmcode_3addr_t) + : sizeof(njs_vmcode_3addr_t) + + sizeof(njs_vmcode_prop_set_t); + node = njs_parser_node_alloc(vm); if (nxt_slow_path(node == NULL)) { return NJS_TOKEN_ERROR; @@ -873,12 +878,6 @@ njs_parser_inc_dec_expression(njs_vm_t * node->left = parser->node; parser->node = node; - parser->code_size += (token == NJS_TOKEN_NAME) - ? sizeof(njs_vmcode_3addr_t) - : sizeof(njs_vmcode_prop_get_t) - + sizeof(njs_vmcode_3addr_t) - + sizeof(njs_vmcode_prop_set_t); - return next; } @@ -918,6 +917,11 @@ njs_parser_post_inc_dec_expression(njs_v return NJS_TOKEN_ILLEGAL; } + parser->code_size += (parser->node->token == NJS_TOKEN_NAME) + ? sizeof(njs_vmcode_3addr_t) + : sizeof(njs_vmcode_3addr_t) + + sizeof(njs_vmcode_prop_set_t); + node = njs_parser_node_alloc(vm); if (nxt_slow_path(node == NULL)) { return NJS_TOKEN_ERROR; @@ -929,12 +933,6 @@ njs_parser_post_inc_dec_expression(njs_v node->left = parser->node; parser->node = node; - parser->code_size += (token == NJS_TOKEN_NAME) - ? sizeof(njs_vmcode_3addr_t) - : sizeof(njs_vmcode_prop_get_t) - + sizeof(njs_vmcode_3addr_t) - + sizeof(njs_vmcode_prop_set_t); - return njs_parser_token(parser); } From spacewanderlzx at gmail.com Thu Apr 5 04:37:19 2018 From: spacewanderlzx at gmail.com (Zexuan Luo) Date: Thu, 5 Apr 2018 12:37:19 +0800 Subject: [PATCH] Improved code readablity of ngx_cache_manager_process_cycle. Message-ID: # HG changeset patch # User spacewander # Date 1522902794 -28800 # Thu Apr 05 12:33:14 2018 +0800 # Branch ident # Node ID e0834ca20c9c68c4f0728f85efb3651732134ee2 # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 Improved code readablity of ngx_cache_manager_process_cycle. diff -r d4cc2edb4ff8 -r e0834ca20c9c src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c Tue Apr 03 17:38:10 2018 +0300 +++ b/src/os/unix/ngx_process_cycle.c Thu Apr 05 12:33:14 2018 +0800 @@ -1128,7 +1128,7 @@ { ngx_cache_manager_ctx_t *ctx = data; - void *ident[4]; + u_char ident[offsetof(ngx_connection_t, fd) + sizeof(ngx_socket_t)]; ngx_event_t ev; /* @@ -1148,7 +1148,7 @@ ev.handler = ctx->handler; ev.data = ident; ev.log = cycle->log; - ident[3] = (void *) -1; + *(ngx_socket_t *)(ident + offsetof(ngx_connection_t, fd)) = -1; ngx_use_accept_mutex = 0; From gmm at csdoc.com Thu Apr 5 07:53:56 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Thu, 5 Apr 2018 10:53:56 +0300 Subject: [PATCH] Contrib: remove obsoleted script geo2nginx.pl. Message-ID: <620666a0-b7e5-f8d0-8b75-9fbe1d112d72@csdoc.com> # HG changeset patch # User Gena Makhomed # Date 1522914140 -10800 # Thu Apr 05 10:42:20 2018 +0300 # Node ID 4f14c557c910f88960dbccf6bd3268eb69b31029 # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 Contrib: remove obsoleted script geo2nginx.pl. GeoLite Legacy Databases no more updated by MaxMind starting from 01 Apr 2018, see for more details: https://dev.maxmind.com/geoip/legacy/geolite/ All users need to switch to the GeoLite2 Free Databases, see https://dev.maxmind.com/geoip/geoip2/geolite2/ fro details. GeoLite2 Databases has different format and requires different convertor. diff -r d4cc2edb4ff8 -r 4f14c557c910 contrib/README --- a/contrib/README Tue Apr 03 17:38:10 2018 +0300 +++ b/contrib/README Thu Apr 05 10:42:20 2018 +0300 @@ -1,21 +1,14 @@ -geo2nginx.pl by Andrei Nigmatulin +unicode2nginx by Maxim Dounin - The perl script to convert CSV geoip database ( free download - at http://www.maxmind.com/app/geoip_country ) to format, suitable - for use by the ngx_http_geo_module. + The perl script to convert unicode mappings ( available + at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx + configuration file format. + Two generated full maps for windows-1251 and koi8-r. -unicode2nginx by Maxim Dounin +vim by Evan Miller - The perl script to convert unicode mappings ( available - at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx - configuration file format. - Two generated full maps for windows-1251 and koi8-r. + Syntax highlighting of nginx configuration for vim, to be + placed into ~/.vim/. - -vim by Evan Miller - - Syntax highlighting of nginx configuration for vim, to be - placed into ~/.vim/. - diff -r d4cc2edb4ff8 -r 4f14c557c910 contrib/geo2nginx.pl --- a/contrib/geo2nginx.pl Tue Apr 03 17:38:10 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#!/usr/bin/perl -w - -# (c) Andrei Nigmatulin, 2005 -# -# this script provided "as is", without any warranties. use it at your own risk. -# -# special thanx to Andrew Sitnikov for perl port -# -# this script converts CSV geoip database (free download at http://www.maxmind.com/app/geoip_country) -# to format, suitable for use with nginx_http_geo module (http://sysoev.ru/nginx) -# -# for example, line with ip range -# -# "62.16.68.0","62.16.127.255","1041253376","1041268735","RU","Russian Federation" -# -# will be converted to four subnetworks: -# -# 62.16.68.0/22 RU; -# 62.16.72.0/21 RU; -# 62.16.80.0/20 RU; -# 62.16.96.0/19 RU; - - -use warnings; -use strict; - -while( ){ - if (/"[^"]+","[^"]+","([^"]+)","([^"]+)","([^"]+)"/){ - print_subnets($1, $2, $3); - } -} - -sub print_subnets { - my ($a1, $a2, $c) = @_; - my $l; - while ($a1 <= $a2) { - for ($l = 0; ($a1 & (1 << $l)) == 0 && ($a1 + ((1 << ($l + 1)) - 1)) <= $a2; $l++){}; - print long2ip($a1) . "/" . (32 - $l) . " " . $c . ";\n"; - $a1 += (1 << $l); - } -} - -sub long2ip { - my $ip = shift; - - my $str = 0; - - $str = ($ip & 255); - - $ip >>= 8; - $str = ($ip & 255).".$str"; - - $ip >>= 8; - $str = ($ip & 255).".$str"; - - $ip >>= 8; - $str = ($ip & 255).".$str"; -} From gmm at csdoc.com Thu Apr 5 07:54:54 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Thu, 5 Apr 2018 10:54:54 +0300 Subject: [PATCH] Contrib: vim syntax, update 3rd party module directives. Message-ID: # HG changeset patch # User Gena Makhomed # Date 1522914365 -10800 # Thu Apr 05 10:46:05 2018 +0300 # Node ID 463bb400efc9d3d6f3b5b314eedf2321e379e4dd # Parent 4f14c557c910f88960dbccf6bd3268eb69b31029 Contrib: vim syntax, update 3rd party module directives. diff -r 4f14c557c910 -r 463bb400efc9 contrib/vim/syntax/nginx.vim --- a/contrib/vim/syntax/nginx.vim Thu Apr 05 10:42:20 2018 +0300 +++ b/contrib/vim/syntax/nginx.vim Thu Apr 05 10:46:05 2018 +0300 @@ -1355,6 +1355,10 @@ " https://www.phusionpassenger.com/library/config/nginx/reference/ syn keyword ngxDirectiveThirdParty contained passenger_abort_on_startup_error syn keyword ngxDirectiveThirdParty contained passenger_abort_websockets_on_process_shutdown +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_auth_type +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_password +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_url +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_username syn keyword ngxDirectiveThirdParty contained passenger_app_env syn keyword ngxDirectiveThirdParty contained passenger_app_file_descriptor_ulimit syn keyword ngxDirectiveThirdParty contained passenger_app_group_name @@ -1375,6 +1379,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_default_user syn keyword ngxDirectiveThirdParty contained passenger_disable_security_update_check syn keyword ngxDirectiveThirdParty contained passenger_document_root +syn keyword ngxDirectiveThirdParty contained passenger_dump_config_manifest syn keyword ngxDirectiveThirdParty contained passenger_enabled syn keyword ngxDirectiveThirdParty contained passenger_env_var syn keyword ngxDirectiveThirdParty contained passenger_file_descriptor_log_file @@ -1402,6 +1407,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_memory_limit syn keyword ngxDirectiveThirdParty contained passenger_meteor_app_settings syn keyword ngxDirectiveThirdParty contained passenger_min_instances +syn keyword ngxDirectiveThirdParty contained passenger_monitor_log_file syn keyword ngxDirectiveThirdParty contained passenger_nodejs syn keyword ngxDirectiveThirdParty contained passenger_pass_header syn keyword ngxDirectiveThirdParty contained passenger_pool_idle_time From gmm at csdoc.com Thu Apr 5 08:05:12 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Thu, 5 Apr 2018 11:05:12 +0300 Subject: [PATCH] Contrib: remove obsoleted script geo2nginx.pl. In-Reply-To: <620666a0-b7e5-f8d0-8b75-9fbe1d112d72@csdoc.com> References: <620666a0-b7e5-f8d0-8b75-9fbe1d112d72@csdoc.com> Message-ID: <85267c33-58a7-5472-0da1-c21cd4d313b6@csdoc.com> On 05.04.2018 10:53, Gena Makhomed wrote: > # HG changeset patch > # User Gena Makhomed > # Date 1522914140 -10800 > #????? Thu Apr 05 10:42:20 2018 +0300 > # Node ID 4f14c557c910f88960dbccf6bd3268eb69b31029 > # Parent? d4cc2edb4ff8391d0c7419e91e6fcc988c510654 > Contrib: remove obsoleted script geo2nginx.pl. In attach original file contrib-convertor.patch without tabs converted to spaces by mail client. -- Best regards, Gena -------------- next part -------------- # HG changeset patch # User Gena Makhomed # Date 1522914140 -10800 # Thu Apr 05 10:42:20 2018 +0300 # Node ID 4f14c557c910f88960dbccf6bd3268eb69b31029 # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 Contrib: remove obsoleted script geo2nginx.pl. GeoLite Legacy Databases no more updated by MaxMind starting from 01 Apr 2018, see for more details: https://dev.maxmind.com/geoip/legacy/geolite/ All users need to switch to the GeoLite2 Free Databases, see https://dev.maxmind.com/geoip/geoip2/geolite2/ fro details. GeoLite2 Databases has different format and requires different convertor. diff -r d4cc2edb4ff8 -r 4f14c557c910 contrib/README --- a/contrib/README Tue Apr 03 17:38:10 2018 +0300 +++ b/contrib/README Thu Apr 05 10:42:20 2018 +0300 @@ -1,21 +1,14 @@ -geo2nginx.pl by Andrei Nigmatulin +unicode2nginx by Maxim Dounin - The perl script to convert CSV geoip database ( free download - at http://www.maxmind.com/app/geoip_country ) to format, suitable - for use by the ngx_http_geo_module. + The perl script to convert unicode mappings ( available + at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx + configuration file format. + Two generated full maps for windows-1251 and koi8-r. -unicode2nginx by Maxim Dounin +vim by Evan Miller - The perl script to convert unicode mappings ( available - at http://www.unicode.org/Public/MAPPINGS/ ) to the nginx - configuration file format. - Two generated full maps for windows-1251 and koi8-r. + Syntax highlighting of nginx configuration for vim, to be + placed into ~/.vim/. - -vim by Evan Miller - - Syntax highlighting of nginx configuration for vim, to be - placed into ~/.vim/. - diff -r d4cc2edb4ff8 -r 4f14c557c910 contrib/geo2nginx.pl --- a/contrib/geo2nginx.pl Tue Apr 03 17:38:10 2018 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,58 +0,0 @@ -#!/usr/bin/perl -w - -# (c) Andrei Nigmatulin, 2005 -# -# this script provided "as is", without any warranties. use it at your own risk. -# -# special thanx to Andrew Sitnikov for perl port -# -# this script converts CSV geoip database (free download at http://www.maxmind.com/app/geoip_country) -# to format, suitable for use with nginx_http_geo module (http://sysoev.ru/nginx) -# -# for example, line with ip range -# -# "62.16.68.0","62.16.127.255","1041253376","1041268735","RU","Russian Federation" -# -# will be converted to four subnetworks: -# -# 62.16.68.0/22 RU; -# 62.16.72.0/21 RU; -# 62.16.80.0/20 RU; -# 62.16.96.0/19 RU; - - -use warnings; -use strict; - -while( ){ - if (/"[^"]+","[^"]+","([^"]+)","([^"]+)","([^"]+)"/){ - print_subnets($1, $2, $3); - } -} - -sub print_subnets { - my ($a1, $a2, $c) = @_; - my $l; - while ($a1 <= $a2) { - for ($l = 0; ($a1 & (1 << $l)) == 0 && ($a1 + ((1 << ($l + 1)) - 1)) <= $a2; $l++){}; - print long2ip($a1) . "/" . (32 - $l) . " " . $c . ";\n"; - $a1 += (1 << $l); - } -} - -sub long2ip { - my $ip = shift; - - my $str = 0; - - $str = ($ip & 255); - - $ip >>= 8; - $str = ($ip & 255).".$str"; - - $ip >>= 8; - $str = ($ip & 255).".$str"; - - $ip >>= 8; - $str = ($ip & 255).".$str"; -} From ru at nginx.com Thu Apr 5 11:12:04 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Thu, 5 Apr 2018 14:12:04 +0300 Subject: [PATCH] Improved code readablity of ngx_cache_manager_process_cycle. In-Reply-To: References: Message-ID: <20180405111204.GD77378@lo0.su> On Thu, Apr 05, 2018 at 12:37:19PM +0800, Zexuan Luo wrote: > # HG changeset patch > # User spacewander > # Date 1522902794 -28800 > # Thu Apr 05 12:33:14 2018 +0800 > # Branch ident > # Node ID e0834ca20c9c68c4f0728f85efb3651732134ee2 > # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 > Improved code readablity of ngx_cache_manager_process_cycle. > > diff -r d4cc2edb4ff8 -r e0834ca20c9c src/os/unix/ngx_process_cycle.c > --- a/src/os/unix/ngx_process_cycle.c Tue Apr 03 17:38:10 2018 +0300 > +++ b/src/os/unix/ngx_process_cycle.c Thu Apr 05 12:33:14 2018 +0800 > @@ -1128,7 +1128,7 @@ > { > ngx_cache_manager_ctx_t *ctx = data; > > - void *ident[4]; > + u_char ident[offsetof(ngx_connection_t, fd) + > sizeof(ngx_socket_t)]; > ngx_event_t ev; > > /* > @@ -1148,7 +1148,7 @@ > ev.handler = ctx->handler; > ev.data = ident; > ev.log = cycle->log; > - ident[3] = (void *) -1; > + *(ngx_socket_t *)(ident + offsetof(ngx_connection_t, fd)) = -1; > > ngx_use_accept_mutex = 0; How's this instead? A similar comment also exists in ngx_resolver.h. diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c --- a/src/os/unix/ngx_process_cycle.c +++ b/src/os/unix/ngx_process_cycle.c @@ -1128,8 +1128,10 @@ ngx_cache_manager_process_cycle(ngx_cycl { ngx_cache_manager_ctx_t *ctx = data; - void *ident[4]; - ngx_event_t ev; + /* event ident must be after 3 pointers as in ngx_connection_t */ + void *ident[4]; + ngx_event_t ev; + ngx_connection_t *c; /* * Set correct process type since closing listening Unix domain socket @@ -1144,11 +1146,13 @@ ngx_cache_manager_process_cycle(ngx_cycl ngx_worker_process_init(cycle, -1); + c = (ngx_connection_t *) ident; + c->fd = (ngx_socket_t) -1; + ngx_memzero(&ev, sizeof(ngx_event_t)); ev.handler = ctx->handler; - ev.data = ident; + ev.data = c; ev.log = cycle->log; - ident[3] = (void *) -1; ngx_use_accept_mutex = 0; From xeioex at nginx.com Thu Apr 5 11:51:03 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 05 Apr 2018 11:51:03 +0000 Subject: [njs] Added njs_value_is_valid_number(). Message-ID: details: http://hg.nginx.org/njs/rev/67edba3688e4 branches: changeset: 493:67edba3688e4 user: Dmitry Volyntsev date: Thu Apr 05 14:50:45 2018 +0300 description: Added njs_value_is_valid_number(). diffstat: njs/njs_vm.c | 9 +++++++++ njs/njscript.h | 1 + 2 files changed, 10 insertions(+), 0 deletions(-) diffs (30 lines): diff -r 5fd1cb826b96 -r 67edba3688e4 njs/njs_vm.c --- a/njs/njs_vm.c Wed Apr 04 16:21:09 2018 +0300 +++ b/njs/njs_vm.c Thu Apr 05 14:50:45 2018 +0300 @@ -3751,6 +3751,15 @@ njs_value_is_number(njs_value_t *value) nxt_noinline nxt_int_t +njs_value_is_valid_number(njs_value_t *value) +{ + return njs_is_number(value) + && !isnan(value->data.u.number) + && !isinf(value->data.u.number); +} + + +nxt_noinline nxt_int_t njs_value_is_string(njs_value_t *value) { return njs_is_string(value); diff -r 5fd1cb826b96 -r 67edba3688e4 njs/njscript.h --- a/njs/njscript.h Wed Apr 04 16:21:09 2018 +0300 +++ b/njs/njscript.h Thu Apr 05 14:50:45 2018 +0300 @@ -191,6 +191,7 @@ NXT_EXPORT njs_function_t *njs_value_fun NXT_EXPORT nxt_int_t njs_value_is_void(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_boolean(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_number(njs_value_t *value); +NXT_EXPORT nxt_int_t njs_value_is_valid_number(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_string(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_object(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_function(njs_value_t *value); From xeioex at nginx.com Thu Apr 5 11:51:03 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 05 Apr 2018 11:51:03 +0000 Subject: [njs] Checking the number argument of HTTP return() method is valid. Message-ID: details: http://hg.nginx.org/njs/rev/9d5914cc9100 branches: changeset: 494:9d5914cc9100 user: Dmitry Volyntsev date: Thu Apr 05 14:50:45 2018 +0300 description: Checking the number argument of HTTP return() method is valid. diffstat: nginx/ngx_http_js_module.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 67edba3688e4 -r 9d5914cc9100 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Thu Apr 05 14:50:45 2018 +0300 +++ b/nginx/ngx_http_js_module.c Thu Apr 05 14:50:45 2018 +0300 @@ -1284,7 +1284,7 @@ ngx_http_js_ext_return(njs_vm_t *vm, njs } value = njs_argument(args, 1); - if (!njs_value_is_number(value)) { + if (!njs_value_is_valid_number(value)) { description = "code is not a number"; goto exception; } From mdounin at mdounin.ru Thu Apr 5 13:34:53 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 5 Apr 2018 16:34:53 +0300 Subject: [PATCH] Improved code readablity of ngx_cache_manager_process_cycle. In-Reply-To: <20180405111204.GD77378@lo0.su> References: <20180405111204.GD77378@lo0.su> Message-ID: <20180405133453.GP77253@mdounin.ru> Hello! On Thu, Apr 05, 2018 at 02:12:04PM +0300, Ruslan Ermilov wrote: > On Thu, Apr 05, 2018 at 12:37:19PM +0800, Zexuan Luo wrote: > > # HG changeset patch > > # User spacewander > > # Date 1522902794 -28800 > > # Thu Apr 05 12:33:14 2018 +0800 > > # Branch ident > > # Node ID e0834ca20c9c68c4f0728f85efb3651732134ee2 > > # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 > > Improved code readablity of ngx_cache_manager_process_cycle. > > > > diff -r d4cc2edb4ff8 -r e0834ca20c9c src/os/unix/ngx_process_cycle.c > > --- a/src/os/unix/ngx_process_cycle.c Tue Apr 03 17:38:10 2018 +0300 > > +++ b/src/os/unix/ngx_process_cycle.c Thu Apr 05 12:33:14 2018 +0800 > > @@ -1128,7 +1128,7 @@ > > { > > ngx_cache_manager_ctx_t *ctx = data; > > > > - void *ident[4]; > > + u_char ident[offsetof(ngx_connection_t, fd) + > > sizeof(ngx_socket_t)]; > > ngx_event_t ev; > > > > /* > > @@ -1148,7 +1148,7 @@ > > ev.handler = ctx->handler; > > ev.data = ident; > > ev.log = cycle->log; > > - ident[3] = (void *) -1; > > + *(ngx_socket_t *)(ident + offsetof(ngx_connection_t, fd)) = -1; > > > > ngx_use_accept_mutex = 0; > > How's this instead? A similar comment also exists in ngx_resolver.h. > > diff --git a/src/os/unix/ngx_process_cycle.c b/src/os/unix/ngx_process_cycle.c > --- a/src/os/unix/ngx_process_cycle.c > +++ b/src/os/unix/ngx_process_cycle.c > @@ -1128,8 +1128,10 @@ ngx_cache_manager_process_cycle(ngx_cycl > { > ngx_cache_manager_ctx_t *ctx = data; > > - void *ident[4]; > - ngx_event_t ev; > + /* event ident must be after 3 pointers as in ngx_connection_t */ > + void *ident[4]; > + ngx_event_t ev; > + ngx_connection_t *c; > > /* > * Set correct process type since closing listening Unix domain socket > @@ -1144,11 +1146,13 @@ ngx_cache_manager_process_cycle(ngx_cycl > > ngx_worker_process_init(cycle, -1); > > + c = (ngx_connection_t *) ident; > + c->fd = (ngx_socket_t) -1; > + > ngx_memzero(&ev, sizeof(ngx_event_t)); > ev.handler = ctx->handler; > - ev.data = ident; > + ev.data = c; > ev.log = cycle->log; > - ident[3] = (void *) -1; > > ngx_use_accept_mutex = 0; Both variants seems to be awful compared to what we have now. -- Maxim Dounin http://mdounin.ru/ From mdounin at mdounin.ru Thu Apr 5 13:58:24 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 05 Apr 2018 13:58:24 +0000 Subject: [nginx] Version bump. Message-ID: details: http://hg.nginx.org/nginx/rev/8ce771bf9260 branches: changeset: 7259:8ce771bf9260 user: Maxim Dounin date: Thu Apr 05 16:53:27 2018 +0300 description: Version bump. diffstat: src/core/nginx.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -9,8 +9,8 @@ #define _NGINX_H_INCLUDED_ -#define nginx_version 1013011 -#define NGINX_VERSION "1.13.11" +#define nginx_version 1013012 +#define NGINX_VERSION "1.13.12" #define NGINX_VER "nginx/" NGINX_VERSION #ifdef NGX_BUILD From mdounin at mdounin.ru Thu Apr 5 13:58:26 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 05 Apr 2018 13:58:26 +0000 Subject: [nginx] Upstream: fixed u->conf->preserve_output (ticket #1519). Message-ID: details: http://hg.nginx.org/nginx/rev/08f114ed5449 branches: changeset: 7260:08f114ed5449 user: Maxim Dounin date: Thu Apr 05 16:56:12 2018 +0300 description: Upstream: fixed u->conf->preserve_output (ticket #1519). Previously, ngx_http_upstream_process_header() might be called after we've finished reading response headers and switched to a different read event handler, leading to errors with gRPC proxying. Additionally, the u->conf->read_timeout timer might be re-armed during reading response headers (while this is expected to be a single timeout on reading the whole response header). diffstat: src/http/ngx_http_upstream.c | 20 +++++++++++++------- 1 files changed, 13 insertions(+), 7 deletions(-) diffs (37 lines): diff --git a/src/http/ngx_http_upstream.c b/src/http/ngx_http_upstream.c --- a/src/http/ngx_http_upstream.c +++ b/src/http/ngx_http_upstream.c @@ -2013,8 +2013,6 @@ ngx_http_upstream_send_request(ngx_http_ /* rc == NGX_OK */ - u->request_body_sent = 1; - if (c->write->timer_set) { ngx_del_timer(c->write); } @@ -2041,11 +2039,19 @@ ngx_http_upstream_send_request(ngx_http_ return; } - ngx_add_timer(c->read, u->conf->read_timeout); - - if (c->read->ready) { - ngx_http_upstream_process_header(r, u); - 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; + } } } From mdounin at mdounin.ru Thu Apr 5 14:50:39 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 5 Apr 2018 17:50:39 +0300 Subject: [PATCH] Contrib: remove obsoleted script geo2nginx.pl. In-Reply-To: <620666a0-b7e5-f8d0-8b75-9fbe1d112d72@csdoc.com> References: <620666a0-b7e5-f8d0-8b75-9fbe1d112d72@csdoc.com> Message-ID: <20180405145038.GT77253@mdounin.ru> Hello! On Thu, Apr 05, 2018 at 10:53:56AM +0300, Gena Makhomed wrote: > # HG changeset patch > # User Gena Makhomed > # Date 1522914140 -10800 > # Thu Apr 05 10:42:20 2018 +0300 > # Node ID 4f14c557c910f88960dbccf6bd3268eb69b31029 > # Parent d4cc2edb4ff8391d0c7419e91e6fcc988c510654 > Contrib: remove obsoleted script geo2nginx.pl. > > GeoLite Legacy Databases no more updated by MaxMind > starting from 01 Apr 2018, see for more details: > https://dev.maxmind.com/geoip/legacy/geolite/ > > All users need to switch to the GeoLite2 Free Databases, > see https://dev.maxmind.com/geoip/geoip2/geolite2/ fro details. > GeoLite2 Databases has different format and requires different convertor. No, thanks. Databases in releavant format are still available for download, so the script in question still can be used directly. Also these databases are expected to be available for "redistribution license customers" for unspecified period of time. Moreover, even if there will be no databases in the format in question available anywhere in the world, the script itself can be a good starting point for a converter for any format which uses IP address ranges. -- Maxim Dounin http://mdounin.ru/ From Neil.Craig at bbc.co.uk Thu Apr 5 15:35:01 2018 From: Neil.Craig at bbc.co.uk (Neil Craig) Date: Thu, 5 Apr 2018 15:35:01 +0000 Subject: Adding OpenSSL ciphersuites at compile time Message-ID: Hi I build a customised nginx binary for my project, this is statically compiled against openssl (via ?with-openssl). Does anyone know if it?s possible to add a configure option to enable specific ciphersuites? The OpenSSL docs are here: https://wiki.openssl.org/index.php/Compilation_and_Installation And these say that you can set a configure option of ?enable-? if compiling OpenSSL directly. Is there some way I can tell the nginx build to do that? Cheers Neil ---------------------------- http://www.bbc.co.uk This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this. --------------------- -------------- next part -------------- An HTML attachment was scrubbed... URL: From teward at dark-net.net Thu Apr 5 15:56:07 2018 From: teward at dark-net.net (Thomas Ward) Date: Thu, 5 Apr 2018 11:56:07 -0400 Subject: Adding OpenSSL ciphersuites at compile time In-Reply-To: References: Message-ID: If I remember correctly, the available cipher suites to NGINX are based on what's compiled into the underlying SSL libraries that NGINX builds against.? So if the underlying OpenSSL has access to ChaCha ciphers in its ciphers that're compiled into it, then NGINX can utilize those ChaCha ciphers. I don't believe there's explicit NGINX compile-time configuration options to enable ciphers at runtime, as this is dependent on the OpenSSL libraries statically built into your binaries, and therefore whatever OpenSSL cipher suites are enabled in it.? You can then enable/disable the individual ciphers to be 'offered' by NGINX the `ssl_ciphers` configuration parameter [1] to use ciphers that might not be in the default cipherstring (which is "HIGH:!aNULL:!MD5" for reference), though, which is the 'standard' way to define what cipher suites should/shouldn't be used for SSL in the nginx instance when it's running and serving SSL connections.? Consider, though, that any ciphers you put in the cipherstring will only be usable if the underlying SSL libraries (statically compiled in or not) support those ciphers that are defined in the cipher string. Thomas [1]: http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_ciphers On 04/05/2018 11:35 AM, Neil Craig wrote: > Hi > > I build a customised nginx binary for my project, this is statically > compiled against openssl (via ?with-openssl). Does anyone know if it?s > possible to add a configure option to enable specific ciphersuites? > The OpenSSL docs are here: > > https://wiki.openssl.org/index.php/Compilation_and_Installation > > And these say that you can set a configure option of > ?enable-? if compiling OpenSSL directly. Is there some > way I can tell the nginx build to do that? > > Cheers > Neil > > ? > > ---------------------------- > > http://www.bbc.co.uk > This e-mail (and any attachments) is confidential and may contain > personal views which are not the views of the BBC unless specifically > stated. > If you have received it in error, please delete it from your system. > Do not use, copy or disclose the information in any way nor act in > reliance on it and notify the sender immediately. > Please note that the BBC monitors e-mails sent or received. > Further communication will signify your consent to this. > > --------------------- > > > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: From xeioex at nginx.com Thu Apr 5 16:43:35 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 05 Apr 2018 16:43:35 +0000 Subject: [njs] Fixed crypto update() method after digest() is called. Message-ID: details: http://hg.nginx.org/njs/rev/4f3424b390bd branches: changeset: 495:4f3424b390bd user: Dmitry Volyntsev date: Thu Apr 05 19:06:35 2018 +0300 description: Fixed crypto update() method after digest() is called. diffstat: njs/njs_crypto.c | 12 ++++++++++++ njs/test/njs_unit_test.c | 12 ++++++++++++ 2 files changed, 24 insertions(+), 0 deletions(-) diffs (58 lines): diff -r 9d5914cc9100 -r 4f3424b390bd njs/njs_crypto.c --- a/njs/njs_crypto.c Thu Apr 05 14:50:45 2018 +0300 +++ b/njs/njs_crypto.c Thu Apr 05 19:06:35 2018 +0300 @@ -243,6 +243,12 @@ njs_hash_prototype_update(njs_vm_t *vm, njs_string_get(&args[1], &data); dgst = njs_value_data(&hash->value); + + if (nxt_slow_path(dgst->alg == NULL)) { + njs_error(vm, "Digest already called", NULL); + return NJS_ERROR; + } + dgst->alg->update(&dgst->u, data.start, data.length); vm->retval = args[0]; @@ -504,6 +510,12 @@ njs_hmac_prototype_update(njs_vm_t *vm, njs_string_get(&args[1], &data); ctx = njs_value_data(&hmac->value); + + if (nxt_slow_path(ctx->alg == NULL)) { + njs_error(vm, "Digest already called", NULL); + return NJS_ERROR; + } + ctx->alg->update(&ctx->u, data.start, data.length); vm->retval = args[0]; diff -r 9d5914cc9100 -r 4f3424b390bd njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 05 14:50:45 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 05 19:06:35 2018 +0300 @@ -9142,6 +9142,10 @@ static njs_unit_test_t njs_test[] = "h.update('A').digest('hex'); h.digest('hex')"), nxt_string("Error: Digest already called") }, + { nxt_string("var h = require('crypto').createHash('sha1');" + "h.update('A').digest('hex'); h.update('B')"), + nxt_string("Error: Digest already called") }, + /* require('crypto').createHash() */ { nxt_string("require('crypto').createHmac('sha1', '')"), @@ -9239,6 +9243,14 @@ static njs_unit_test_t njs_test[] = { nxt_string("var h = require('crypto').createHmac('sha1', [])"), nxt_string("TypeError: key must be a string") }, + { nxt_string("var h = require('crypto').createHmac('sha1', 'secret key');" + "h.update('A').digest('hex'); h.digest('hex')"), + nxt_string("Error: Digest already called") }, + + { nxt_string("var h = require('crypto').createHmac('sha1', 'secret key');" + "h.update('A').digest('hex'); h.update('B')"), + nxt_string("Error: Digest already called") }, + /* setTimeout(). */ { nxt_string("setTimeout()"), From Neil.Craig at bbc.co.uk Thu Apr 5 18:39:45 2018 From: Neil.Craig at bbc.co.uk (Neil Craig) Date: Thu, 5 Apr 2018 18:39:45 +0000 Subject: Adding OpenSSL ciphersuites at compile time In-Reply-To: References: Message-ID: Hi Thomas Thanks for your reply. What you outline is essentially what I want to do ? I am statically compiling nginx against a specific openssl version and I want to be able to re-enable 3DES ciphersuites which are disabled in openssl 1.1.0+ (we have some audience demographics in e.g. Rural India and North Africa, a reasonable proportion of whom use very old mobile handsets). So?what I would like to be able to do is to add something to my configure for nginx which would trigger the same behaviour as if I were adding ?enable-? when configuring openssl. Hopefully that makes a bit more sense now :-). Cheers Neil Craig Lead Technical Architect BBC Design + Engineering | OTG Broadcast Centre, London W12 7TQ | BC4 A3 [cid:1470E654-D8D0-4A53-A0B0-628531702DD6] From: Thomas Ward > Date: Thursday, 5 April 2018 at 16:56 To: "nginx-devel at nginx.org" >, Neil Craig > Subject: Re: Adding OpenSSL ciphersuites at compile time If I remember correctly, the available cipher suites to NGINX are based on what's compiled into the underlying SSL libraries that NGINX builds against. So if the underlying OpenSSL has access to ChaCha ciphers in its ciphers that're compiled into it, then NGINX can utilize those ChaCha ciphers. I don't believe there's explicit NGINX compile-time configuration options to enable ciphers at runtime, as this is dependent on the OpenSSL libraries statically built into your binaries, and therefore whatever OpenSSL cipher suites are enabled in it. You can then enable/disable the individual ciphers to be 'offered' by NGINX the `ssl_ciphers` configuration parameter [1] to use ciphers that might not be in the default cipherstring (which is "HIGH:!aNULL:!MD5" for reference), though, which is the 'standard' way to define what cipher suites should/shouldn't be used for SSL in the nginx instance when it's running and serving SSL connections. Consider, though, that any ciphers you put in the cipherstring will only be usable if the underlying SSL libraries (statically compiled in or not) support those ciphers that are defined in the cipher string. Thomas [1]: http://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_ciphers On 04/05/2018 11:35 AM, Neil Craig wrote: Hi I build a customised nginx binary for my project, this is statically compiled against openssl (via ?with-openssl). Does anyone know if it?s possible to add a configure option to enable specific ciphersuites? The OpenSSL docs are here: https://wiki.openssl.org/index.php/Compilation_and_Installation And these say that you can set a configure option of ?enable-? if compiling OpenSSL directly. Is there some way I can tell the nginx build to do that? Cheers Neil ---------------------------- http://www.bbc.co.uk This e-mail (and any attachments) is confidential and may contain personal views which are not the views of the BBC unless specifically stated. If you have received it in error, please delete it from your system. Do not use, copy or disclose the information in any way nor act in reliance on it and notify the sender immediately. Please note that the BBC monitors e-mails sent or received. Further communication will signify your consent to this. --------------------- _______________________________________________ nginx-devel mailing list nginx-devel at nginx.orghttp://mailman.nginx.org/mailman/listinfo/nginx-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: BBC-DAndE[2][6].png Type: image/png Size: 1914 bytes Desc: BBC-DAndE[2][6].png URL: From mdounin at mdounin.ru Thu Apr 5 18:52:25 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 5 Apr 2018 21:52:25 +0300 Subject: Adding OpenSSL ciphersuites at compile time In-Reply-To: References: Message-ID: <20180405185225.GW77253@mdounin.ru> Hello! On Thu, Apr 05, 2018 at 06:39:45PM +0000, Neil Craig wrote: > Hi Thomas > > Thanks for your reply. What you outline is essentially what I > want to do ? I am statically compiling nginx against a specific > openssl version and I want to be able to re-enable 3DES > ciphersuites which are disabled in openssl 1.1.0+ (we have some > audience demographics in e.g. Rural India and North Africa, a > reasonable proportion of whom use very old mobile handsets). > > So?what I would like to be able to do is to add something to my > configure for nginx which would trigger the same behaviour as if > I were adding ?enable-? when configuring openssl. > > Hopefully that makes a bit more sense now :-). You can specify additional OpenSSL config options using the --with-openssl-opt configure option. $ ./configure --help | grep openssl --with-openssl=DIR set path to OpenSSL library sources --with-openssl-opt=OPTIONS set additional build options for OpenSSL -- Maxim Dounin http://mdounin.ru/ From Neil.Craig at bbc.co.uk Thu Apr 5 18:54:27 2018 From: Neil.Craig at bbc.co.uk (Neil Craig) Date: Thu, 5 Apr 2018 18:54:27 +0000 Subject: Adding OpenSSL ciphersuites at compile time In-Reply-To: <20180405185225.GW77253@mdounin.ru> References: <20180405185225.GW77253@mdounin.ru> Message-ID: Awesome, that?s exactly what I am looking for, thanks Maxim - much appreciated! Neil Craig Lead Technical Architect BBC Design + Engineering | OTG Broadcast Centre, London W12 7TQ | BC4 A3 On 05/04/2018, 19:52, "nginx-devel on behalf of Maxim Dounin" wrote: >Hello! > >On Thu, Apr 05, 2018 at 06:39:45PM +0000, Neil Craig wrote: > >> Hi Thomas >> >> Thanks for your reply. What you outline is essentially what I >> want to do ? I am statically compiling nginx against a specific >> openssl version and I want to be able to re-enable 3DES >> ciphersuites which are disabled in openssl 1.1.0+ (we have some >> audience demographics in e.g. Rural India and North Africa, a >> reasonable proportion of whom use very old mobile handsets). >> >> So?what I would like to be able to do is to add something to my >> configure for nginx which would trigger the same behaviour as if >> I were adding ?enable-? when configuring openssl. >> >> Hopefully that makes a bit more sense now :-). > >You can specify additional OpenSSL config options using >the --with-openssl-opt configure option. > >$ ./configure --help | grep openssl > --with-openssl=DIR set path to OpenSSL library sources > --with-openssl-opt=OPTIONS set additional build options for >OpenSSL > >-- >Maxim Dounin >http://mdounin.ru/ >_______________________________________________ >nginx-devel mailing list >nginx-devel at nginx.org >http://mailman.nginx.org/mailman/listinfo/nginx-devel From xeioex at nginx.com Mon Apr 9 18:02:48 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 09 Apr 2018 18:02:48 +0000 Subject: [njs] Added shortcuts for creating errors from the outside of a VM. Message-ID: details: http://hg.nginx.org/njs/rev/4466799a4231 branches: changeset: 496:4466799a4231 user: Dmitry Volyntsev date: Mon Apr 09 21:02:10 2018 +0300 description: Added shortcuts for creating errors from the outside of a VM. njs_vm_error(), njs_vm_memory_error(). diffstat: njs/njscript.c | 7 +++++++ njs/njscript.h | 5 +++++ 2 files changed, 12 insertions(+), 0 deletions(-) diffs (39 lines): diff -r 4f3424b390bd -r 4466799a4231 njs/njscript.c --- a/njs/njscript.c Thu Apr 05 19:06:35 2018 +0300 +++ b/njs/njscript.c Mon Apr 09 21:02:10 2018 +0300 @@ -682,6 +682,13 @@ njs_vm_retval_set(njs_vm_t *vm, njs_opaq } +nxt_noinline void +njs_vm_memory_error(njs_vm_t *vm) +{ + njs_set_memory_error(vm, &vm->retval); +} + + njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *retval) { if (vm->top_frame == NULL) { diff -r 4f3424b390bd -r 4466799a4231 njs/njscript.h --- a/njs/njscript.h Thu Apr 05 19:06:35 2018 +0300 +++ b/njs/njscript.h Mon Apr 09 21:02:10 2018 +0300 @@ -29,6 +29,9 @@ typedef struct { #define njs_argument(args, n) \ (njs_value_t *) ((u_char *) args + n * 16) +#define njs_vm_error(vm, fmt, ...) \ + njs_value_error_set(vm, njs_vm_retval(vm), fmt, ##__VA_ARGS__) + typedef njs_ret_t (*njs_extern_get_t)(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data); @@ -176,6 +179,8 @@ NXT_EXPORT njs_ret_t njs_vm_value_to_ext NXT_EXPORT njs_ret_t njs_vm_retval_to_ext_string(njs_vm_t *vm, nxt_str_t *retval); +NXT_EXPORT void njs_vm_memory_error(njs_vm_t *vm); + NXT_EXPORT void njs_value_void_set(njs_value_t *value); NXT_EXPORT void njs_value_boolean_set(njs_value_t *value, int yn); NXT_EXPORT void njs_value_number_set(njs_value_t *value, double num); From xeioex at nginx.com Mon Apr 9 18:02:48 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Mon, 09 Apr 2018 18:02:48 +0000 Subject: [njs] HTTP request body getter. Message-ID: details: http://hg.nginx.org/njs/rev/b7bfe96ce113 branches: changeset: 497:b7bfe96ce113 user: Dmitry Volyntsev date: Mon Apr 09 21:02:11 2018 +0300 description: HTTP request body getter. Returns the client request body. diffstat: nginx/ngx_http_js_module.c | 102 +++++++++++++++++++++++++++++++++++++++++++- njs/njs_vm.c | 7 +++ njs/njscript.h | 4 + 3 files changed, 109 insertions(+), 4 deletions(-) diffs (192 lines): diff -r 4466799a4231 -r b7bfe96ce113 nginx/ngx_http_js_module.c --- a/nginx/ngx_http_js_module.c Mon Apr 09 21:02:10 2018 +0300 +++ b/nginx/ngx_http_js_module.c Mon Apr 09 21:02:11 2018 +0300 @@ -34,6 +34,7 @@ typedef struct { njs_opaque_value_t args[2]; ngx_uint_t done; ngx_int_t status; + njs_opaque_value_t request_body; } ngx_http_js_ctx_t; @@ -106,6 +107,8 @@ static njs_ret_t ngx_http_js_ext_get_htt njs_value_t *value, void *obj, uintptr_t data); static njs_ret_t ngx_http_js_ext_get_remote_address(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data); +static njs_ret_t ngx_http_js_ext_get_request_body(njs_vm_t *vm, + njs_value_t *value, void *obj, uintptr_t data); static njs_ret_t ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data); static njs_ret_t ngx_http_js_ext_foreach_header_in(njs_vm_t *vm, void *obj, @@ -129,8 +132,8 @@ static ngx_int_t ngx_http_js_subrequest_ void *data, ngx_int_t rc); static njs_ret_t ngx_http_js_ext_get_parent(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data); -static njs_ret_t ngx_http_js_ext_get_body(njs_vm_t *vm, njs_value_t *value, - void *obj, uintptr_t data); +static njs_ret_t ngx_http_js_ext_get_reply_body(njs_vm_t *vm, + njs_value_t *value, void *obj, uintptr_t data); static njs_host_event_t ngx_http_js_set_timer(njs_external_ptr_t external, uint64_t delay, njs_vm_event_t vm_event); @@ -358,6 +361,18 @@ static njs_external_t ngx_http_js_ext_r NULL, 0 }, + { nxt_string("body"), + NJS_EXTERN_PROPERTY, + NULL, + 0, + ngx_http_js_ext_get_request_body, + NULL, + NULL, + NULL, + NULL, + NULL, + 0 }, + { nxt_string("headers"), NJS_EXTERN_OBJECT, NULL, @@ -546,7 +561,7 @@ static njs_external_t ngx_http_js_ext_r NJS_EXTERN_PROPERTY, NULL, 0, - ngx_http_js_ext_get_body, + ngx_http_js_ext_get_reply_body, NULL, NULL, NULL, @@ -1436,6 +1451,85 @@ ngx_http_js_ext_get_remote_address(njs_v static njs_ret_t +ngx_http_js_ext_get_request_body(njs_vm_t *vm, njs_value_t *value, void *obj, + uintptr_t data) +{ + u_char *p, *body; + size_t len; + ngx_buf_t *buf; + njs_ret_t ret; + njs_value_t *request_body; + ngx_chain_t *cl; + ngx_http_js_ctx_t *ctx; + ngx_http_request_t *r; + + r = (ngx_http_request_t *) obj; + + ctx = ngx_http_get_module_ctx(r, ngx_http_js_module); + request_body = (njs_value_t *) &ctx->request_body; + + if (!njs_value_is_null(request_body)) { + njs_value_assign(value, request_body); + return NJS_OK; + } + + if (r->request_body == NULL || r->request_body->bufs == NULL) { + njs_vm_error(vm, "request body is unavailable"); + return NJS_ERROR; + } + + if (r->request_body->temp_file) { + njs_vm_error(vm, "request body is in a file"); + return NJS_ERROR; + } + + cl = r->request_body->bufs; + buf = cl->buf; + + if (cl->next == NULL) { + len = buf->last - buf->pos; + body = buf->pos; + + goto done; + } + + 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) { + njs_vm_memory_error(vm); + return NJS_ERROR; + } + + body = 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); + } + +done: + + ret = njs_string_create(vm, request_body, body, len, 0); + + if (ret != NXT_OK) { + return NJS_ERROR; + } + + njs_value_assign(value, request_body); + + return NJS_OK; +} + + +static njs_ret_t ngx_http_js_ext_get_header_in(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data) { @@ -1939,7 +2033,7 @@ ngx_http_js_ext_get_parent(njs_vm_t *vm, static njs_ret_t -ngx_http_js_ext_get_body(njs_vm_t *vm, njs_value_t *value, void *obj, +ngx_http_js_ext_get_reply_body(njs_vm_t *vm, njs_value_t *value, void *obj, uintptr_t data) { size_t len; diff -r 4466799a4231 -r b7bfe96ce113 njs/njs_vm.c --- a/njs/njs_vm.c Mon Apr 09 21:02:10 2018 +0300 +++ b/njs/njs_vm.c Mon Apr 09 21:02:11 2018 +0300 @@ -3730,6 +3730,13 @@ njs_value_function(njs_value_t *value) nxt_noinline nxt_int_t +njs_value_is_null(njs_value_t *value) +{ + return njs_is_null(value); +} + + +nxt_noinline nxt_int_t njs_value_is_void(njs_value_t *value) { return njs_is_void(value); diff -r 4466799a4231 -r b7bfe96ce113 njs/njscript.h --- a/njs/njscript.h Mon Apr 09 21:02:10 2018 +0300 +++ b/njs/njscript.h Mon Apr 09 21:02:11 2018 +0300 @@ -29,6 +29,9 @@ typedef struct { #define njs_argument(args, n) \ (njs_value_t *) ((u_char *) args + n * 16) +#define njs_value_assign(dst, src) \ + *((njs_opaque_value_t *) dst) = *((njs_opaque_value_t *) src); + #define njs_vm_error(vm, fmt, ...) \ njs_value_error_set(vm, njs_vm_retval(vm), fmt, ##__VA_ARGS__) @@ -193,6 +196,7 @@ NXT_EXPORT double njs_value_number(njs_v NXT_EXPORT void *njs_value_data(njs_value_t *value); NXT_EXPORT njs_function_t *njs_value_function(njs_value_t *value); +NXT_EXPORT nxt_int_t njs_value_is_null(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_void(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_boolean(njs_value_t *value); NXT_EXPORT nxt_int_t njs_value_is_number(njs_value_t *value); From mdounin at mdounin.ru Tue Apr 10 14:14:50 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 10 Apr 2018 14:14:50 +0000 Subject: [nginx] nginx-1.13.12-RELEASE Message-ID: details: http://hg.nginx.org/nginx/rev/051e5fa03b92 branches: changeset: 7261:051e5fa03b92 user: Maxim Dounin date: Tue Apr 10 17:11:09 2018 +0300 description: nginx-1.13.12-RELEASE diffstat: docs/xml/nginx/changes.xml | 16 ++++++++++++++++ 1 files changed, 16 insertions(+), 0 deletions(-) diffs (26 lines): diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml --- a/docs/xml/nginx/changes.xml +++ b/docs/xml/nginx/changes.xml @@ -5,6 +5,22 @@ + + + + +??? ???????? ???????? ?????? +?????????? ? gRPC-????????? ????? ?????????? ???????????. + + +connections with gRPC backends might be closed unexpectedly +when returning a large response. + + + + + + From mdounin at mdounin.ru Tue Apr 10 14:14:52 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 10 Apr 2018 14:14:52 +0000 Subject: [nginx] release-1.13.12 tag Message-ID: details: http://hg.nginx.org/nginx/rev/1ad1cdfe7409 branches: changeset: 7262:1ad1cdfe7409 user: Maxim Dounin date: Tue Apr 10 17:11:10 2018 +0300 description: release-1.13.12 tag diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -424,3 +424,4 @@ 20ca4bcff108d3e66977f4d97508637093492287 fb1212c7eca4c5328fe17d6cd95b010c67336aac release-1.13.9 31c929e16910c38492581ef474e72fa67c28f124 release-1.13.10 64179f242cb55fc206bca59de9bfdc4cf5ebcec7 release-1.13.11 +051e5fa03b92b8a564f6b12debd483d267391e82 release-1.13.12 From gmm at csdoc.com Tue Apr 10 15:28:36 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Tue, 10 Apr 2018 18:28:36 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. Message-ID: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> # HG changeset patch # User Gena Makhomed # Date 1523373890 -10800 # Tue Apr 10 18:24:50 2018 +0300 # Node ID 739582ed66b790646c463b3abe5f51a94043cd41 # Parent 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 Contrib: vim syntax, update core and 3rd party module directives. diff -r 1ad1cdfe7409 -r 739582ed66b7 contrib/vim/syntax/nginx.vim --- a/contrib/vim/syntax/nginx.vim Tue Apr 10 17:11:10 2018 +0300 +++ b/contrib/vim/syntax/nginx.vim Tue Apr 10 18:24:50 2018 +0300 @@ -119,6 +119,9 @@ syn keyword ngxDirectiveDeprecated contained spdy_recv_timeout syn keyword ngxDirectiveDeprecated contained spdy_streams_index_size syn keyword ngxDirectiveDeprecated contained upstream_conf +syn keyword ngxDirectiveDeprecated contained status +syn keyword ngxDirectiveDeprecated contained status_format +syn keyword ngxDirectiveDeprecated contained status_zone syn keyword ngxDirective contained absolute_redirect syn keyword ngxDirective contained accept_mutex @@ -136,6 +139,7 @@ syn keyword ngxDirective contained allow syn keyword ngxDirective contained ancient_browser syn keyword ngxDirective contained ancient_browser_value +syn keyword ngxDirective contained api syn keyword ngxDirective contained auth_basic syn keyword ngxDirective contained auth_basic_user_file syn keyword ngxDirective contained auth_http @@ -143,7 +147,10 @@ syn keyword ngxDirective contained auth_http_pass_client_cert syn keyword ngxDirective contained auth_http_timeout syn keyword ngxDirective contained auth_jwt +syn keyword ngxDirective contained auth_jwt_claim_set +syn keyword ngxDirective contained auth_jwt_header_set syn keyword ngxDirective contained auth_jwt_key_file +syn keyword ngxDirective contained auth_jwt_leeway syn keyword ngxDirective contained auth_request syn keyword ngxDirective contained auth_request_set syn keyword ngxDirective contained autoindex @@ -330,6 +337,8 @@ syn keyword ngxDirective contained keepalive_disable syn keyword ngxDirective contained keepalive_requests syn keyword ngxDirective contained keepalive_timeout +syn keyword ngxDirective contained keyval +syn keyword ngxDirective contained keyval_zone syn keyword ngxDirective contained kqueue_changes syn keyword ngxDirective contained kqueue_events syn keyword ngxDirective contained large_client_header_buffers @@ -593,9 +602,6 @@ syn keyword ngxDirective contained ssl_verify_depth syn keyword ngxDirective contained starttls syn keyword ngxDirective contained state -syn keyword ngxDirective contained status -syn keyword ngxDirective contained status_format -syn keyword ngxDirective contained status_zone syn keyword ngxDirective contained sticky syn keyword ngxDirective contained sticky_cookie_insert syn keyword ngxDirective contained stub_status @@ -701,6 +707,25 @@ syn keyword ngxDirective contained xslt_stylesheet syn keyword ngxDirective contained xslt_types syn keyword ngxDirective contained zone +syn keyword ngxDirective contained zone_sync +syn keyword ngxDirective contained zone_sync_buffers +syn keyword ngxDirective contained zone_sync_connect_retry_interval +syn keyword ngxDirective contained zone_sync_connect_timeout +syn keyword ngxDirective contained zone_sync_interval +syn keyword ngxDirective contained zone_sync_recv_buffer_size +syn keyword ngxDirective contained zone_sync_server +syn keyword ngxDirective contained zone_sync_ssl +syn keyword ngxDirective contained zone_sync_ssl_certificate +syn keyword ngxDirective contained zone_sync_ssl_certificate_key +syn keyword ngxDirective contained zone_sync_ssl_ciphers +syn keyword ngxDirective contained zone_sync_ssl_crl +syn keyword ngxDirective contained zone_sync_ssl_password_file +syn keyword ngxDirective contained zone_sync_ssl_protocols +syn keyword ngxDirective contained zone_sync_ssl_trusted_certificate +syn keyword ngxDirective contained zone_sync_ssl_verify +syn keyword ngxDirective contained zone_sync_ssl_verify_depth +syn keyword ngxDirective contained zone_sync_timeout + " 3rd party modules list taken from " https://github.com/freebsd/freebsd-ports/blob/master/www/nginx-devel/Makefile @@ -1355,6 +1380,10 @@ " https://www.phusionpassenger.com/library/config/nginx/reference/ syn keyword ngxDirectiveThirdParty contained passenger_abort_on_startup_error syn keyword ngxDirectiveThirdParty contained passenger_abort_websockets_on_process_shutdown +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_auth_type +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_password +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_url +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_username syn keyword ngxDirectiveThirdParty contained passenger_app_env syn keyword ngxDirectiveThirdParty contained passenger_app_file_descriptor_ulimit syn keyword ngxDirectiveThirdParty contained passenger_app_group_name @@ -1375,6 +1404,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_default_user syn keyword ngxDirectiveThirdParty contained passenger_disable_security_update_check syn keyword ngxDirectiveThirdParty contained passenger_document_root +syn keyword ngxDirectiveThirdParty contained passenger_dump_config_manifest syn keyword ngxDirectiveThirdParty contained passenger_enabled syn keyword ngxDirectiveThirdParty contained passenger_env_var syn keyword ngxDirectiveThirdParty contained passenger_file_descriptor_log_file @@ -1402,6 +1432,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_memory_limit syn keyword ngxDirectiveThirdParty contained passenger_meteor_app_settings syn keyword ngxDirectiveThirdParty contained passenger_min_instances +syn keyword ngxDirectiveThirdParty contained passenger_monitor_log_file syn keyword ngxDirectiveThirdParty contained passenger_nodejs syn keyword ngxDirectiveThirdParty contained passenger_pass_header syn keyword ngxDirectiveThirdParty contained passenger_pool_idle_time From ru at nginx.com Tue Apr 10 16:23:41 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Tue, 10 Apr 2018 19:23:41 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. In-Reply-To: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> References: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> Message-ID: <20180410162341.GD64199@lo0.su> On Tue, Apr 10, 2018 at 06:28:36PM +0300, Gena Makhomed wrote: > # HG changeset patch > # User Gena Makhomed > # Date 1523373890 -10800 > # Tue Apr 10 18:24:50 2018 +0300 > # Node ID 739582ed66b790646c463b3abe5f51a94043cd41 > # Parent 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 > Contrib: vim syntax, update core and 3rd party module directives. > > diff -r 1ad1cdfe7409 -r 739582ed66b7 contrib/vim/syntax/nginx.vim > --- a/contrib/vim/syntax/nginx.vim Tue Apr 10 17:11:10 2018 +0300 > +++ b/contrib/vim/syntax/nginx.vim Tue Apr 10 18:24:50 2018 +0300 > @@ -119,6 +119,9 @@ > syn keyword ngxDirectiveDeprecated contained spdy_recv_timeout > syn keyword ngxDirectiveDeprecated contained spdy_streams_index_size > syn keyword ngxDirectiveDeprecated contained upstream_conf > +syn keyword ngxDirectiveDeprecated contained status > +syn keyword ngxDirectiveDeprecated contained status_format > +syn keyword ngxDirectiveDeprecated contained status_zone The status_zone directive is not deprecated despite the fact that it's currently documented in the deprecated status module. This directive will be moved to http and stream core modules. > syn keyword ngxDirective contained absolute_redirect > syn keyword ngxDirective contained accept_mutex > @@ -136,6 +139,7 @@ > syn keyword ngxDirective contained allow > syn keyword ngxDirective contained ancient_browser > syn keyword ngxDirective contained ancient_browser_value > +syn keyword ngxDirective contained api > syn keyword ngxDirective contained auth_basic > syn keyword ngxDirective contained auth_basic_user_file > syn keyword ngxDirective contained auth_http > @@ -143,7 +147,10 @@ > syn keyword ngxDirective contained auth_http_pass_client_cert > syn keyword ngxDirective contained auth_http_timeout > syn keyword ngxDirective contained auth_jwt > +syn keyword ngxDirective contained auth_jwt_claim_set > +syn keyword ngxDirective contained auth_jwt_header_set > syn keyword ngxDirective contained auth_jwt_key_file > +syn keyword ngxDirective contained auth_jwt_leeway > syn keyword ngxDirective contained auth_request > syn keyword ngxDirective contained auth_request_set > syn keyword ngxDirective contained autoindex > @@ -330,6 +337,8 @@ > syn keyword ngxDirective contained keepalive_disable > syn keyword ngxDirective contained keepalive_requests > syn keyword ngxDirective contained keepalive_timeout > +syn keyword ngxDirective contained keyval > +syn keyword ngxDirective contained keyval_zone > syn keyword ngxDirective contained kqueue_changes > syn keyword ngxDirective contained kqueue_events > syn keyword ngxDirective contained large_client_header_buffers > @@ -593,9 +602,6 @@ > syn keyword ngxDirective contained ssl_verify_depth > syn keyword ngxDirective contained starttls > syn keyword ngxDirective contained state > -syn keyword ngxDirective contained status > -syn keyword ngxDirective contained status_format > -syn keyword ngxDirective contained status_zone > syn keyword ngxDirective contained sticky > syn keyword ngxDirective contained sticky_cookie_insert > syn keyword ngxDirective contained stub_status > @@ -701,6 +707,25 @@ > syn keyword ngxDirective contained xslt_stylesheet > syn keyword ngxDirective contained xslt_types > syn keyword ngxDirective contained zone > +syn keyword ngxDirective contained zone_sync > +syn keyword ngxDirective contained zone_sync_buffers > +syn keyword ngxDirective contained zone_sync_connect_retry_interval > +syn keyword ngxDirective contained zone_sync_connect_timeout > +syn keyword ngxDirective contained zone_sync_interval > +syn keyword ngxDirective contained zone_sync_recv_buffer_size > +syn keyword ngxDirective contained zone_sync_server > +syn keyword ngxDirective contained zone_sync_ssl > +syn keyword ngxDirective contained zone_sync_ssl_certificate > +syn keyword ngxDirective contained zone_sync_ssl_certificate_key > +syn keyword ngxDirective contained zone_sync_ssl_ciphers > +syn keyword ngxDirective contained zone_sync_ssl_crl > +syn keyword ngxDirective contained zone_sync_ssl_password_file > +syn keyword ngxDirective contained zone_sync_ssl_protocols > +syn keyword ngxDirective contained zone_sync_ssl_trusted_certificate > +syn keyword ngxDirective contained zone_sync_ssl_verify > +syn keyword ngxDirective contained zone_sync_ssl_verify_depth > +syn keyword ngxDirective contained zone_sync_timeout > + > > " 3rd party modules list taken from > " > https://github.com/freebsd/freebsd-ports/blob/master/www/nginx-devel/Makefile > @@ -1355,6 +1380,10 @@ > " https://www.phusionpassenger.com/library/config/nginx/reference/ > syn keyword ngxDirectiveThirdParty contained > passenger_abort_on_startup_error > syn keyword ngxDirectiveThirdParty contained > passenger_abort_websockets_on_process_shutdown > +syn keyword ngxDirectiveThirdParty contained > passenger_admin_panel_auth_type > +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_password > +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_url > +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_username > syn keyword ngxDirectiveThirdParty contained passenger_app_env > syn keyword ngxDirectiveThirdParty contained > passenger_app_file_descriptor_ulimit > syn keyword ngxDirectiveThirdParty contained passenger_app_group_name > @@ -1375,6 +1404,7 @@ > syn keyword ngxDirectiveThirdParty contained passenger_default_user > syn keyword ngxDirectiveThirdParty contained > passenger_disable_security_update_check > syn keyword ngxDirectiveThirdParty contained passenger_document_root > +syn keyword ngxDirectiveThirdParty contained passenger_dump_config_manifest > syn keyword ngxDirectiveThirdParty contained passenger_enabled > syn keyword ngxDirectiveThirdParty contained passenger_env_var > syn keyword ngxDirectiveThirdParty contained > passenger_file_descriptor_log_file > @@ -1402,6 +1432,7 @@ > syn keyword ngxDirectiveThirdParty contained passenger_memory_limit > syn keyword ngxDirectiveThirdParty contained passenger_meteor_app_settings > syn keyword ngxDirectiveThirdParty contained passenger_min_instances > +syn keyword ngxDirectiveThirdParty contained passenger_monitor_log_file > syn keyword ngxDirectiveThirdParty contained passenger_nodejs > syn keyword ngxDirectiveThirdParty contained passenger_pass_header > syn keyword ngxDirectiveThirdParty contained passenger_pool_idle_time > > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > -- Ruslan Ermilov Assume stupidity not malice From gmm at csdoc.com Tue Apr 10 17:47:50 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Tue, 10 Apr 2018 20:47:50 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. Message-ID: # HG changeset patch # User Gena Makhomed # Date 1523382230 -10800 # Tue Apr 10 20:43:50 2018 +0300 # Node ID 4049f2a9bc4e8de556f659769ea061f5b1b244e1 # Parent 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 Contrib: vim syntax, update core and 3rd party module directives. diff -r 1ad1cdfe7409 -r 4049f2a9bc4e contrib/vim/syntax/nginx.vim --- a/contrib/vim/syntax/nginx.vim Tue Apr 10 17:11:10 2018 +0300 +++ b/contrib/vim/syntax/nginx.vim Tue Apr 10 20:43:50 2018 +0300 @@ -119,6 +119,8 @@ syn keyword ngxDirectiveDeprecated contained spdy_recv_timeout syn keyword ngxDirectiveDeprecated contained spdy_streams_index_size syn keyword ngxDirectiveDeprecated contained upstream_conf +syn keyword ngxDirectiveDeprecated contained status +syn keyword ngxDirectiveDeprecated contained status_format syn keyword ngxDirective contained absolute_redirect syn keyword ngxDirective contained accept_mutex @@ -136,6 +138,7 @@ syn keyword ngxDirective contained allow syn keyword ngxDirective contained ancient_browser syn keyword ngxDirective contained ancient_browser_value +syn keyword ngxDirective contained api syn keyword ngxDirective contained auth_basic syn keyword ngxDirective contained auth_basic_user_file syn keyword ngxDirective contained auth_http @@ -143,7 +146,10 @@ syn keyword ngxDirective contained auth_http_pass_client_cert syn keyword ngxDirective contained auth_http_timeout syn keyword ngxDirective contained auth_jwt +syn keyword ngxDirective contained auth_jwt_claim_set +syn keyword ngxDirective contained auth_jwt_header_set syn keyword ngxDirective contained auth_jwt_key_file +syn keyword ngxDirective contained auth_jwt_leeway syn keyword ngxDirective contained auth_request syn keyword ngxDirective contained auth_request_set syn keyword ngxDirective contained autoindex @@ -330,6 +336,8 @@ syn keyword ngxDirective contained keepalive_disable syn keyword ngxDirective contained keepalive_requests syn keyword ngxDirective contained keepalive_timeout +syn keyword ngxDirective contained keyval +syn keyword ngxDirective contained keyval_zone syn keyword ngxDirective contained kqueue_changes syn keyword ngxDirective contained kqueue_events syn keyword ngxDirective contained large_client_header_buffers @@ -593,8 +601,6 @@ syn keyword ngxDirective contained ssl_verify_depth syn keyword ngxDirective contained starttls syn keyword ngxDirective contained state -syn keyword ngxDirective contained status -syn keyword ngxDirective contained status_format syn keyword ngxDirective contained status_zone syn keyword ngxDirective contained sticky syn keyword ngxDirective contained sticky_cookie_insert @@ -701,6 +707,24 @@ syn keyword ngxDirective contained xslt_stylesheet syn keyword ngxDirective contained xslt_types syn keyword ngxDirective contained zone +syn keyword ngxDirective contained zone_sync +syn keyword ngxDirective contained zone_sync_buffers +syn keyword ngxDirective contained zone_sync_connect_retry_interval +syn keyword ngxDirective contained zone_sync_connect_timeout +syn keyword ngxDirective contained zone_sync_interval +syn keyword ngxDirective contained zone_sync_recv_buffer_size +syn keyword ngxDirective contained zone_sync_server +syn keyword ngxDirective contained zone_sync_ssl +syn keyword ngxDirective contained zone_sync_ssl_certificate +syn keyword ngxDirective contained zone_sync_ssl_certificate_key +syn keyword ngxDirective contained zone_sync_ssl_ciphers +syn keyword ngxDirective contained zone_sync_ssl_crl +syn keyword ngxDirective contained zone_sync_ssl_password_file +syn keyword ngxDirective contained zone_sync_ssl_protocols +syn keyword ngxDirective contained zone_sync_ssl_trusted_certificate +syn keyword ngxDirective contained zone_sync_ssl_verify +syn keyword ngxDirective contained zone_sync_ssl_verify_depth +syn keyword ngxDirective contained zone_sync_timeout " 3rd party modules list taken from " https://github.com/freebsd/freebsd-ports/blob/master/www/nginx-devel/Makefile @@ -1355,6 +1379,10 @@ " https://www.phusionpassenger.com/library/config/nginx/reference/ syn keyword ngxDirectiveThirdParty contained passenger_abort_on_startup_error syn keyword ngxDirectiveThirdParty contained passenger_abort_websockets_on_process_shutdown +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_auth_type +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_password +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_url +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_username syn keyword ngxDirectiveThirdParty contained passenger_app_env syn keyword ngxDirectiveThirdParty contained passenger_app_file_descriptor_ulimit syn keyword ngxDirectiveThirdParty contained passenger_app_group_name @@ -1375,6 +1403,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_default_user syn keyword ngxDirectiveThirdParty contained passenger_disable_security_update_check syn keyword ngxDirectiveThirdParty contained passenger_document_root +syn keyword ngxDirectiveThirdParty contained passenger_dump_config_manifest syn keyword ngxDirectiveThirdParty contained passenger_enabled syn keyword ngxDirectiveThirdParty contained passenger_env_var syn keyword ngxDirectiveThirdParty contained passenger_file_descriptor_log_file @@ -1402,6 +1431,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_memory_limit syn keyword ngxDirectiveThirdParty contained passenger_meteor_app_settings syn keyword ngxDirectiveThirdParty contained passenger_min_instances +syn keyword ngxDirectiveThirdParty contained passenger_monitor_log_file syn keyword ngxDirectiveThirdParty contained passenger_nodejs syn keyword ngxDirectiveThirdParty contained passenger_pass_header syn keyword ngxDirectiveThirdParty contained passenger_pool_idle_time From gmm at csdoc.com Tue Apr 10 17:58:46 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Tue, 10 Apr 2018 20:58:46 +0300 Subject: nginx documentation In-Reply-To: <20180410162341.GD64199@lo0.su> References: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> <20180410162341.GD64199@lo0.su> Message-ID: <235511bc-c189-4efd-997f-3703550f577d@csdoc.com> On 10.04.2018 19:23, Ruslan Ermilov wrote: >> +syn keyword ngxDirectiveDeprecated contained status >> +syn keyword ngxDirectiveDeprecated contained status_format >> +syn keyword ngxDirectiveDeprecated contained status_zone > The status_zone directive is not deprecated despite the fact > that it's currently documented in the deprecated status module. > This directive will be moved to http and stream core modules. Ok, I update patch accordingly and send new version to mail list. One more question: Directive limit_zone still exists in nginx documentation, but this directive was removed from nginx in version 1.7.6, long time ago. This is the only one directive, which is removed from nginx, but still exists in nginx documentation on site nginx.org. May be it is good idea to remove directive "limit_zone" from nginx documentation too? -- Best regards, Gena From suconghou at gmail.com Wed Apr 11 02:49:30 2018 From: suconghou at gmail.com (=?UTF-8?B?6IuP6IGq5Y6a?=) Date: Wed, 11 Apr 2018 10:49:30 +0800 Subject: add $host variable in stream module Message-ID: according to the stream_processing http://nginx.org/en/docs/stream/stream_processing.html#preread_phase stream module can preread buffers from tcp , and these data can be used in ngx_stream_ssl_preread_module and other modules > if we set ssl_preread on , it is assumed as https connections , ngx_stream_ssl_preread_module will analyze the data , so we can get $ssl_preread_server_name variable which is very useful in sni proxy what I want is another directive which assume the connection is http , and some other module like ngx_stream_ssl_preread_module will analyze the data and get the variable $host. If we can get the variable $host,$request_uri,$args in stream module just like in http module, we can do more powerful things, it is also more effective than http module in some case. what we should do is not difficult just like parser some http headers. I really want these can be add in nginx . thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From yar at nginx.com Wed Apr 11 12:56:28 2018 From: yar at nginx.com (Yaroslav Zhuravlev) Date: Wed, 11 Apr 2018 15:56:28 +0300 Subject: nginx documentation In-Reply-To: <235511bc-c189-4efd-997f-3703550f577d@csdoc.com> References: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> <20180410162341.GD64199@lo0.su> <235511bc-c189-4efd-997f-3703550f577d@csdoc.com> Message-ID: [...] > > One more question: > > Directive limit_zone still exists in nginx documentation, but this > directive was removed from nginx in version 1.7.6, long time ago. > > This is the only one directive, which is removed from nginx, > but still exists in nginx documentation on site nginx.org. > > May be it is good idea to remove directive > "limit_zone" from nginx documentation too? Hello! http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html#limit_zone The directive description does not contradict the code and current behavior: "This directive was made obsolete in version 1.1.8 and was removed in version 1.7.6". so there?s no need of removing it. Best regards, yar From gmm at csdoc.com Wed Apr 11 13:30:45 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Wed, 11 Apr 2018 16:30:45 +0300 Subject: nginx documentation In-Reply-To: References: <13c25c30-7e8c-323d-2b72-5ddcffe247f1@csdoc.com> <20180410162341.GD64199@lo0.su> <235511bc-c189-4efd-997f-3703550f577d@csdoc.com> Message-ID: <22ecbf47-d07a-bdca-6618-9268505d7bb5@csdoc.com> On 11.04.2018 15:56, Yaroslav Zhuravlev wrote: >> Directive limit_zone still exists in nginx documentation, but this >> directive was removed from nginx in version 1.7.6, long time ago. >> >> This is the only one directive, which is removed from nginx, >> but still exists in nginx documentation on site nginx.org. >> >> May be it is good idea to remove directive >> "limit_zone" from nginx documentation too? > http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html#limit_zone > > The directive description does not contradict the code and current behavior: > "This directive was made obsolete in version 1.1.8 and was removed in version 1.7.6". > so there?s no need of removing it. "limit_zone" is the only one directive, which is removed from nginx code, but still exists in nginx documentation. Directive limit_zone was removed from nginx in 2014. Now 2018 year. Does any reasons exists for keeping description of this removed directive in documentation? -- Best regards, Gena From xeioex at nginx.com Wed Apr 11 14:32:00 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Wed, 11 Apr 2018 14:32:00 +0000 Subject: [njs] README: added github as a way to report issues and send patches. Message-ID: details: http://hg.nginx.org/njs/rev/35486fa8c8b5 branches: changeset: 498:35486fa8c8b5 user: Dmitry Volyntsev date: Wed Apr 11 17:31:53 2018 +0300 description: README: added github as a way to report issues and send patches. diffstat: README | 9 +++++++-- 1 files changed, 7 insertions(+), 2 deletions(-) diffs (19 lines): diff -r b7bfe96ce113 -r 35486fa8c8b5 README --- a/README Mon Apr 09 21:02:11 2018 +0300 +++ b/README Wed Apr 11 17:31:53 2018 +0300 @@ -4,8 +4,13 @@ The documentation is available online: http://nginx.org/en/docs/http/ngx_http_js_module.html http://nginx.org/en/docs/stream/ngx_stream_js_module.html -Please report your experiences to the NGINX development mailing list -nginx-devel at nginx.org (http://mailman.nginx.org/mailman/listinfo/nginx-devel). +Please ask questions, report issues, and send patches to the mailing list: + + nginx-devel at nginx.org (http://mailman.nginx.org/mailman/listinfo/nginx-devel) + +or via Github: + + https://github.com/nginx/njs -- NGINX, Inc., http://nginx.com From ajithc1861 at gmail.com Fri Apr 13 16:15:39 2018 From: ajithc1861 at gmail.com (Ajith C) Date: Fri, 13 Apr 2018 21:45:39 +0530 Subject: Upstream module development Message-ID: <5AA81F36-6D43-4BF8-8792-AD779B1DAA4A@gmail.com> Hi, Now I am writing a Nginx module to communicate with an upstream server (LDAP) . I had coded both the create_request and process_header callback functions. But the problem is, I don?t want to talk with the upstream for for all the requests but only for the requests with some special parameters. For example: if a request arrives like http://www.example.com/connect?value=yes , then I want to talk to the upstream to generate the response for the client But if URI is http://www.example.com/connect?value=no , then I don?t want to connect to upstream and I need to create my own response to send back to client. What should I do? Please help. Thank you -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Tue Apr 17 15:34:05 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 17 Apr 2018 15:34:05 +0000 Subject: [nginx] Stable branch. Message-ID: details: http://hg.nginx.org/nginx/rev/5d536f7c04fd branches: stable-1.14 changeset: 7263:5d536f7c04fd user: Maxim Dounin date: Tue Apr 17 16:30:10 2018 +0300 description: Stable branch. diffstat: src/core/nginx.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -9,8 +9,8 @@ #define _NGINX_H_INCLUDED_ -#define nginx_version 1013012 -#define NGINX_VERSION "1.13.12" +#define nginx_version 1014000 +#define NGINX_VERSION "1.14.0" #define NGINX_VER "nginx/" NGINX_VERSION #ifdef NGX_BUILD From mdounin at mdounin.ru Tue Apr 17 15:34:07 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 17 Apr 2018 15:34:07 +0000 Subject: [nginx] nginx-1.14.0-RELEASE Message-ID: details: http://hg.nginx.org/nginx/rev/588054867fef branches: stable-1.14 changeset: 7264:588054867fef user: Maxim Dounin date: Tue Apr 17 18:22:35 2018 +0300 description: nginx-1.14.0-RELEASE diffstat: docs/xml/nginx/changes.xml | 14 ++++++++++++++ 1 files changed, 14 insertions(+), 0 deletions(-) diffs (24 lines): diff --git a/docs/xml/nginx/changes.xml b/docs/xml/nginx/changes.xml --- a/docs/xml/nginx/changes.xml +++ b/docs/xml/nginx/changes.xml @@ -5,6 +5,20 @@ + + + + +?????????? ????? 1.14.x. + + +1.14.x stable branch. + + + + + + From mdounin at mdounin.ru Tue Apr 17 15:34:09 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 17 Apr 2018 15:34:09 +0000 Subject: [nginx] release-1.14.0 tag Message-ID: details: http://hg.nginx.org/nginx/rev/3226d650cdc2 branches: stable-1.14 changeset: 7265:3226d650cdc2 user: Maxim Dounin date: Tue Apr 17 18:22:36 2018 +0300 description: release-1.14.0 tag diffstat: .hgtags | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diffs (8 lines): diff --git a/.hgtags b/.hgtags --- a/.hgtags +++ b/.hgtags @@ -425,3 +425,4 @@ fb1212c7eca4c5328fe17d6cd95b010c67336aac 31c929e16910c38492581ef474e72fa67c28f124 release-1.13.10 64179f242cb55fc206bca59de9bfdc4cf5ebcec7 release-1.13.11 051e5fa03b92b8a564f6b12debd483d267391e82 release-1.13.12 +588054867fef65d3dc38df1ffefcade02a88f140 release-1.14.0 From mdounin at mdounin.ru Wed Apr 18 13:24:25 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 18 Apr 2018 13:24:25 +0000 Subject: [nginx] Version bump. Message-ID: details: http://hg.nginx.org/nginx/rev/1076268364ba branches: changeset: 7266:1076268364ba user: Maxim Dounin date: Wed Apr 18 16:09:08 2018 +0300 description: Version bump. diffstat: src/core/nginx.h | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (14 lines): diff --git a/src/core/nginx.h b/src/core/nginx.h --- a/src/core/nginx.h +++ b/src/core/nginx.h @@ -9,8 +9,8 @@ #define _NGINX_H_INCLUDED_ -#define nginx_version 1013012 -#define NGINX_VERSION "1.13.12" +#define nginx_version 1015000 +#define NGINX_VERSION "1.15.0" #define NGINX_VER "nginx/" NGINX_VERSION #ifdef NGX_BUILD From mdounin at mdounin.ru Wed Apr 18 13:24:26 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 18 Apr 2018 13:24:26 +0000 Subject: [nginx] Cache: fixed cache valid slot to reject incorrect statuses. Message-ID: details: http://hg.nginx.org/nginx/rev/7c614ef3c6ea branches: changeset: 7267:7c614ef3c6ea user: Maxim Dounin date: Wed Apr 18 16:11:41 2018 +0300 description: Cache: fixed cache valid slot to reject incorrect statuses. Previously, result of ngx_atoi() was assigned to an ngx_uint_t variable, and errors reported by ngx_atoi() became positive, so the following check in "status < 100" failed to catch them. This resulted in the configurations like "proxy_cache_valid 2xx 30s" being accepted as correct, while they in fact do nothing. Changing type to ngx_int_t fixes this, and such configurations are now properly rejected. diffstat: src/http/ngx_http_file_cache.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diffs (13 lines): diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c --- a/src/http/ngx_http_file_cache.c +++ b/src/http/ngx_http_file_cache.c @@ -2620,7 +2620,8 @@ ngx_http_file_cache_valid_set_slot(ngx_c time_t valid; ngx_str_t *value; - ngx_uint_t i, n, status; + ngx_int_t status; + ngx_uint_t i, n; ngx_array_t **a; ngx_http_cache_valid_t *v; static ngx_uint_t statuses[] = { 200, 301, 302 }; From dndx at idndx.com Thu Apr 19 05:59:41 2018 From: dndx at idndx.com (Datong Sun) Date: Wed, 18 Apr 2018 22:59:41 -0700 Subject: [PATCH] Stream: use correct action message when running stream log phase. Message-ID: # HG changeset patch # User Datong Sun # Date 1524117436 25200 # Wed Apr 18 22:57:16 2018 -0700 # Node ID 883ccb0f25cc567938fd0fb4fb0a5ff814c40984 # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd Stream: use correct action message when running stream log phase. Previously when executing the log handlers in stream subsystem, the logger action was not being set correctly and results in error messages generated while executing the log handlers to have strange suffixes (such as "while returning text" when ngx_stream_return_module was used as content handler). This commit ensures those suffixes will have more meaningful contents in them. diff -r 7c614ef3c6ea -r 883ccb0f25cc src/stream/ngx_stream_handler.c --- a/src/stream/ngx_stream_handler.c Wed Apr 18 16:11:41 2018 +0300 +++ b/src/stream/ngx_stream_handler.c Wed Apr 18 22:57:16 2018 -0700 @@ -301,8 +301,12 @@ s->status = rc; + s->connection->log->action = "logging session"; + ngx_stream_log_session(s); + s->connection->log->action = "closing session"; + ngx_stream_close_connection(s->connection); } Thanks, -- Datong Sun dndx at idndx.com From xeioex at nginx.com Fri Apr 20 13:42:37 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 20 Apr 2018 13:42:37 +0000 Subject: [njs] Fixed JSON.stringify() for arrays with empty cells. Message-ID: details: http://hg.nginx.org/njs/rev/cb7115e9fa1e branches: changeset: 499:cb7115e9fa1e user: Dmitry Volyntsev date: Fri Apr 20 16:42:08 2018 +0300 description: Fixed JSON.stringify() for arrays with empty cells. diffstat: njs/njs_json.c | 1 + njs/test/njs_unit_test.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-) diffs (24 lines): diff -r 35486fa8c8b5 -r cb7115e9fa1e njs/njs_json.c --- a/njs/njs_json.c Wed Apr 11 17:31:53 2018 +0300 +++ b/njs/njs_json.c Fri Apr 20 16:42:08 2018 +0300 @@ -1719,6 +1719,7 @@ njs_json_append_value(njs_json_stringify case NJS_VOID: case NJS_NULL: + case NJS_INVALID: case NJS_FUNCTION: return njs_json_buf_append(stringify, "null", 4); diff -r 35486fa8c8b5 -r cb7115e9fa1e njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Wed Apr 11 17:31:53 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 20 16:42:08 2018 +0300 @@ -8673,6 +8673,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("JSON.stringify([])"), nxt_string("[]") }, + { nxt_string("var a = [1]; a[2] = 'x'; JSON.stringify(a)"), + nxt_string("[1,null,\"x\"]") }, + { nxt_string("JSON.stringify({a:\"b\",c:19,e:null,t:true,f:false})"), nxt_string("{\"a\":\"b\",\"c\":19,\"e\":null,\"t\":true,\"f\":false}") }, From xeioex at nginx.com Fri Apr 20 13:42:37 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 20 Apr 2018 13:42:37 +0000 Subject: [njs] Fixed exception type for unsupported types in JSON.stringify(). Message-ID: details: http://hg.nginx.org/njs/rev/28d75187de15 branches: changeset: 500:28d75187de15 user: Dmitry Volyntsev date: Fri Apr 20 16:42:10 2018 +0300 description: Fixed exception type for unsupported types in JSON.stringify(). diffstat: njs/njs_json.c | 4 ++++ njs/test/njs_unit_test.c | 3 +++ 2 files changed, 7 insertions(+), 0 deletions(-) diffs (27 lines): diff -r cb7115e9fa1e -r 28d75187de15 njs/njs_json.c --- a/njs/njs_json.c Fri Apr 20 16:42:08 2018 +0300 +++ b/njs/njs_json.c Fri Apr 20 16:42:10 2018 +0300 @@ -1184,6 +1184,10 @@ njs_json_parse_exception(njs_json_parse_ state->written = 1; \ ret = njs_json_append_value(stringify, value); \ if (nxt_slow_path(ret != NXT_OK)) { \ + if (ret == NXT_DECLINED) { \ + return NXT_ERROR; \ + } \ + \ goto memory_error; \ } diff -r cb7115e9fa1e -r 28d75187de15 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Apr 20 16:42:08 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 20 16:42:10 2018 +0300 @@ -8708,6 +8708,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("var e = URIError('e'); e.foo = 'E'; JSON.stringify(e)"), nxt_string("{\"foo\":\"E\"}") }, + { nxt_string("JSON.stringify($r)"), + nxt_string("TypeError: Non-serializable object") }, + /* Ignoring named properties of an array. */ { nxt_string("var a = [1,2]; a.a = 1;" From xeioex at nginx.com Fri Apr 20 13:42:37 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 20 Apr 2018 13:42:37 +0000 Subject: [njs] Making native getters into universal property handlers. Message-ID: details: http://hg.nginx.org/njs/rev/a65deb4c2e03 branches: changeset: 501:a65deb4c2e03 user: Dmitry Volyntsev date: Fri Apr 20 16:42:10 2018 +0300 description: Making native getters into universal property handlers. diffstat: njs/njs_array.c | 10 ++++---- njs/njs_boolean.c | 8 +++--- njs/njs_builtin.c | 4 +- njs/njs_date.c | 8 +++--- njs/njs_error.c | 38 ++++++++++++++++---------------- njs/njs_function.c | 6 ++-- njs/njs_function.h | 2 +- njs/njs_math.c | 4 +- njs/njs_number.c | 8 +++--- njs/njs_object.c | 22 +++++++++--------- njs/njs_object.h | 9 +++---- njs/njs_regexp.c | 34 +++++++++++++++--------------- njs/njs_string.c | 14 ++++++------ njs/njs_vm.c | 54 +++++++++++++++++++++++++++++++++++++++++++++-- njs/njs_vm.h | 15 ++++++++---- njs/test/njs_unit_test.c | 6 +++++ 16 files changed, 150 insertions(+), 92 deletions(-) diffs (720 lines): diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_array.c --- a/njs/njs_array.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_array.c Fri Apr 20 16:42:10 2018 +0300 @@ -351,9 +351,9 @@ static const njs_object_prop_t njs_arra /* Array.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, /* Array.isArray(). */ @@ -382,7 +382,7 @@ const njs_object_init_t njs_array_const static njs_ret_t njs_array_prototype_length(njs_vm_t *vm, njs_value_t *array, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_value_number_set(retval, array->data.u.array->length); @@ -2057,9 +2057,9 @@ njs_array_prototype_sort_continuation(nj static const njs_object_prop_t njs_array_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("length"), - .value = njs_native_getter(njs_array_prototype_length), + .value = njs_prop_handler(njs_array_prototype_length), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_boolean.c --- a/njs/njs_boolean.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_boolean.c Fri Apr 20 16:42:10 2018 +0300 @@ -71,9 +71,9 @@ static const njs_object_prop_t njs_bool /* Boolean.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -140,9 +140,9 @@ njs_boolean_prototype_to_string(njs_vm_t static const njs_object_prop_t njs_boolean_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_primitive_prototype_get_proto), + .value = njs_prop_handler(njs_primitive_prototype_get_proto), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_builtin.c --- a/njs/njs_builtin.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_builtin.c Fri Apr 20 16:42:10 2018 +0300 @@ -246,9 +246,9 @@ njs_builtin_objects_create(njs_vm_t *vm) }; static const njs_object_prop_t function_prototype_property = { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_function_prototype_create), + .value = njs_prop_handler(njs_function_prototype_create), }; ret = njs_object_hash_create(vm, &vm->shared->function_prototype_hash, diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_date.c --- a/njs/njs_date.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_date.c Fri Apr 20 16:42:10 2018 +0300 @@ -905,9 +905,9 @@ static const njs_object_prop_t njs_date /* Date.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, { @@ -1931,9 +1931,9 @@ njs_date_prototype_to_json_continuation( static const njs_object_prop_t njs_date_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_primitive_prototype_get_proto), + .value = njs_prop_handler(njs_primitive_prototype_get_proto), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_error.c --- a/njs/njs_error.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_error.c Fri Apr 20 16:42:10 2018 +0300 @@ -192,9 +192,9 @@ static const njs_object_prop_t njs_erro /* Error.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -232,9 +232,9 @@ static const njs_object_prop_t njs_eval /* EvalError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -272,9 +272,9 @@ static const njs_object_prop_t njs_inte /* InternalError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -312,9 +312,9 @@ static const njs_object_prop_t njs_rang /* RangeError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -352,9 +352,9 @@ static const njs_object_prop_t njs_refe /* ReferenceError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -392,9 +392,9 @@ static const njs_object_prop_t njs_synt /* SyntaxError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -432,9 +432,9 @@ static const njs_object_prop_t njs_type /* TypeError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -472,9 +472,9 @@ static const njs_object_prop_t njs_uri_ /* URIError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -533,7 +533,7 @@ njs_memory_error_constructor(njs_vm_t *v static njs_ret_t njs_memory_error_prototype_create(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { int32_t index; njs_value_t *proto; @@ -574,9 +574,9 @@ static const njs_object_prop_t njs_memo /* MemoryError.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_memory_error_prototype_create), + .value = njs_prop_handler(njs_memory_error_prototype_create), }, }; diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_function.c --- a/njs/njs_function.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_function.c Fri Apr 20 16:42:10 2018 +0300 @@ -419,7 +419,7 @@ njs_function_call(njs_vm_t *vm, njs_inde njs_ret_t njs_function_prototype_create(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_value_t *proto; @@ -495,9 +495,9 @@ static const njs_object_prop_t njs_func /* Function.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_function.h --- a/njs/njs_function.h Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_function.h Fri Apr 20 16:42:10 2018 +0300 @@ -147,7 +147,7 @@ njs_function_t *njs_function_alloc(njs_v njs_function_t *njs_function_value_copy(njs_vm_t *vm, njs_value_t *value); njs_native_frame_t *njs_function_frame_alloc(njs_vm_t *vm, size_t size); njs_ret_t njs_function_prototype_create(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval); + njs_value_t *setval, njs_value_t *retval); njs_value_t *njs_function_property_prototype_create(njs_vm_t *vm, njs_value_t *value); njs_ret_t njs_function_constructor(njs_vm_t *vm, njs_value_t *args, diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_math.c --- a/njs/njs_math.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_math.c Fri Apr 20 16:42:10 2018 +0300 @@ -822,9 +822,9 @@ static const njs_object_prop_t njs_math }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_object_prototype_get_proto), + .value = njs_prop_handler(njs_object_prototype_get_proto), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_number.c --- a/njs/njs_number.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_number.c Fri Apr 20 16:42:10 2018 +0300 @@ -463,9 +463,9 @@ static const njs_object_prop_t njs_numb /* Number.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, /* ES6. */ @@ -707,9 +707,9 @@ njs_number_to_string_radix(njs_vm_t *vm, static const njs_object_prop_t njs_number_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_primitive_prototype_get_proto), + .value = njs_prop_handler(njs_primitive_prototype_get_proto), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_object.c --- a/njs/njs_object.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_object.c Fri Apr 20 16:42:10 2018 +0300 @@ -740,7 +740,7 @@ njs_object_get_prototype_of(njs_vm_t *vm njs_index_t unused) { if (nargs > 1 && njs_is_object(&args[1])) { - njs_object_prototype_get_proto(vm, &args[1], &vm->retval); + njs_object_prototype_get_proto(vm, &args[1], NULL, &vm->retval); return NXT_OK; } @@ -971,7 +971,7 @@ njs_object_is_extensible(njs_vm_t *vm, n njs_ret_t njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { nxt_uint_t index; njs_object_t *proto; @@ -1004,7 +1004,7 @@ njs_primitive_prototype_get_proto(njs_vm njs_ret_t njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { int32_t index; njs_value_t *proto; @@ -1088,9 +1088,9 @@ static const njs_object_prop_t njs_obje /* Object.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, /* Object.create(). */ @@ -1202,7 +1202,7 @@ const njs_object_init_t njs_object_cons njs_ret_t njs_object_prototype_get_proto(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_object_t *proto; @@ -1229,7 +1229,7 @@ njs_object_prototype_get_proto(njs_vm_t static njs_ret_t njs_object_prototype_create_constructor(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { int32_t index; njs_value_t *cons; @@ -1521,15 +1521,15 @@ njs_object_prototype_is_prototype_of(njs static const njs_object_prop_t njs_object_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_object_prototype_get_proto), + .value = njs_prop_handler(njs_object_prototype_get_proto), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("constructor"), - .value = njs_native_getter(njs_object_prototype_create_constructor), + .value = njs_prop_handler(njs_object_prototype_create_constructor), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_object.h --- a/njs/njs_object.h Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_object.h Fri Apr 20 16:42:10 2018 +0300 @@ -13,8 +13,7 @@ typedef enum { NJS_GETTER, NJS_SETTER, NJS_METHOD, - NJS_NATIVE_GETTER, - NJS_NATIVE_SETTER, + NJS_PROPERTY_HANDLER, NJS_WHITEOUT, } njs_object_property_type_t; @@ -52,13 +51,13 @@ njs_ret_t njs_object_constructor(njs_vm_ njs_object_prop_t *njs_object_prop_alloc(njs_vm_t *vm, const njs_value_t *name, const njs_value_t *value, uint8_t attributes); njs_ret_t njs_primitive_prototype_get_proto(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval); + njs_value_t *setval, njs_value_t *retval); njs_ret_t njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval); + njs_value_t *setval, njs_value_t *retval); njs_value_t *njs_property_prototype_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, njs_object_t *prototype); njs_ret_t njs_object_prototype_get_proto(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval); + njs_value_t *setval, njs_value_t *retval); njs_value_t *njs_property_constructor_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, njs_value_t *constructor); njs_ret_t njs_object_prototype_to_string(njs_vm_t *vm, njs_value_t *args, diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_regexp.c --- a/njs/njs_regexp.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_regexp.c Fri Apr 20 16:42:10 2018 +0300 @@ -464,7 +464,7 @@ njs_regexp_alloc(njs_vm_t *vm, njs_regex static njs_ret_t njs_regexp_prototype_last_index(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { uint32_t index; njs_regexp_t *regexp; @@ -485,7 +485,7 @@ njs_regexp_prototype_last_index(njs_vm_t static njs_ret_t njs_regexp_prototype_global(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_regexp_pattern_t *pattern; @@ -499,7 +499,7 @@ njs_regexp_prototype_global(njs_vm_t *vm static njs_ret_t njs_regexp_prototype_ignore_case(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_regexp_pattern_t *pattern; @@ -513,7 +513,7 @@ njs_regexp_prototype_ignore_case(njs_vm_ static njs_ret_t njs_regexp_prototype_multiline(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { njs_regexp_pattern_t *pattern; @@ -527,7 +527,7 @@ njs_regexp_prototype_multiline(njs_vm_t static njs_ret_t njs_regexp_prototype_source(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { u_char *source; int32_t length; @@ -824,9 +824,9 @@ static const njs_object_prop_t njs_rege /* RegExp.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, }; @@ -841,33 +841,33 @@ const njs_object_init_t njs_regexp_cons static const njs_object_prop_t njs_regexp_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("lastIndex"), - .value = njs_native_getter(njs_regexp_prototype_last_index), + .value = njs_prop_handler(njs_regexp_prototype_last_index), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("global"), - .value = njs_native_getter(njs_regexp_prototype_global), + .value = njs_prop_handler(njs_regexp_prototype_global), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("ignoreCase"), - .value = njs_native_getter(njs_regexp_prototype_ignore_case), + .value = njs_prop_handler(njs_regexp_prototype_ignore_case), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("multiline"), - .value = njs_native_getter(njs_regexp_prototype_multiline), + .value = njs_prop_handler(njs_regexp_prototype_multiline), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("source"), - .value = njs_native_getter(njs_regexp_prototype_source), + .value = njs_prop_handler(njs_regexp_prototype_source), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_string.c --- a/njs/njs_string.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_string.c Fri Apr 20 16:42:10 2018 +0300 @@ -570,9 +570,9 @@ static const njs_object_prop_t njs_stri /* String.prototype. */ { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("prototype"), - .value = njs_native_getter(njs_object_prototype_create), + .value = njs_prop_handler(njs_object_prototype_create), }, /* String.fromCharCode(). */ @@ -600,7 +600,7 @@ const njs_object_init_t njs_string_cons static njs_ret_t njs_string_prototype_length(njs_vm_t *vm, njs_value_t *value, - njs_value_t *retval) + njs_value_t *setval, njs_value_t *retval) { size_t size; uintptr_t length; @@ -3348,15 +3348,15 @@ njs_string_to_c_string(njs_vm_t *vm, njs static const njs_object_prop_t njs_string_prototype_properties[] = { { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("__proto__"), - .value = njs_native_getter(njs_primitive_prototype_get_proto), + .value = njs_prop_handler(njs_primitive_prototype_get_proto), }, { - .type = NJS_NATIVE_GETTER, + .type = NJS_PROPERTY_HANDLER, .name = njs_string("length"), - .value = njs_native_getter(njs_string_prototype_length), + .value = njs_prop_handler(njs_string_prototype_length), }, { diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_vm.c --- a/njs/njs_vm.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_vm.c Fri Apr 20 16:42:10 2018 +0300 @@ -54,7 +54,7 @@ typedef struct { nxt_lvlhsh_query_t lhq; - /* scratch is used to get the value of an NJS_NATIVE_GETTER property. */ + /* scratch is used to get the value of an NJS_PROPERTY_HANDLER property. */ njs_object_prop_t scratch; njs_value_t value; @@ -82,6 +82,8 @@ static njs_ret_t njs_array_property_quer njs_property_query_t *pq, njs_value_t *object, uint32_t index); static njs_ret_t njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *value, njs_object_t *object); +static njs_ret_t njs_object_query_prop_handler(njs_property_query_t *pq, + njs_object_t *object); static njs_ret_t njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq); static nxt_noinline njs_ret_t njs_values_equal(const njs_value_t *val1, @@ -695,6 +697,17 @@ njs_vmcode_property_set(njs_vm_t *vm, nj case NXT_OK: prop = pq.lhq.value; + + if (prop->type == NJS_PROPERTY_HANDLER) { + ret = prop->value.data.u.prop_handler(vm, object, value, + &vm->retval); + if (nxt_slow_path(ret != NXT_OK)) { + return ret; + } + + return sizeof(njs_vmcode_prop_set_t); + } + break; case NXT_DECLINED: @@ -1153,6 +1166,13 @@ njs_object_property_query(njs_vm_t *vm, pq->lhq.proto = &njs_object_hash_proto; + if (pq->query == NJS_PROPERTY_QUERY_SET) { + ret = njs_object_query_prop_handler(pq, object); + if (ret == NXT_OK) { + return ret; + } + } + do { pq->prototype = object; @@ -1183,10 +1203,11 @@ njs_object_property_query(njs_vm_t *vm, if (pq->query == NJS_PROPERTY_QUERY_GET) { prop = pq->lhq.value; - if (prop->type == NJS_NATIVE_GETTER) { + if (prop->type == NJS_PROPERTY_HANDLER) { pq->scratch = *prop; prop = &pq->scratch; - ret = prop->value.data.u.getter(vm, value, &prop->value); + ret = prop->value.data.u.prop_handler(vm, value, NULL, + &prop->value); if (nxt_fast_path(ret == NXT_OK)) { prop->type = NJS_PROPERTY; @@ -1220,6 +1241,33 @@ njs_object_property_query(njs_vm_t *vm, static njs_ret_t +njs_object_query_prop_handler(njs_property_query_t *pq, njs_object_t *object) +{ + njs_ret_t ret; + njs_object_prop_t *prop; + + do { + pq->prototype = object; + + ret = nxt_lvlhsh_find(&object->shared_hash, &pq->lhq); + + if (ret == NXT_OK) { + prop = pq->lhq.value; + + if (prop->type == NJS_PROPERTY_HANDLER) { + return NXT_OK; + } + } + + object = object->__proto__; + + } while (object != NULL); + + return NXT_DECLINED; +} + + +static njs_ret_t njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq) { njs_function_t *function; diff -r 28d75187de15 -r a65deb4c2e03 njs/njs_vm.h --- a/njs/njs_vm.h Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_vm.h Fri Apr 20 16:42:10 2018 +0300 @@ -118,8 +118,13 @@ typedef enum { typedef struct njs_parser_s njs_parser_t; -typedef njs_ret_t (*njs_getter_t) (njs_vm_t *vm, njs_value_t *obj, - njs_value_t *retval); +/* + * njs_prop_handler_t operates as a property getter and/or setter. + * The handler receives NULL setval if it is invoked in GET context and + * non-null otherwise. + */ +typedef njs_ret_t (*njs_prop_handler_t) (njs_vm_t *vm, njs_value_t *value, + njs_value_t *setval, njs_value_t *retval); typedef njs_ret_t (*njs_function_native_t) (njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t retval); @@ -177,7 +182,7 @@ union njs_value_s { njs_function_lambda_t *lambda; njs_regexp_t *regexp; njs_date_t *date; - njs_getter_t getter; + njs_prop_handler_t prop_handler; njs_value_t *value; njs_property_next_t *next; void *data; @@ -374,11 +379,11 @@ typedef union { } -#define njs_native_getter(_getter) { \ +#define njs_prop_handler(_handler) { \ .data = { \ .type = NJS_INVALID, \ .truth = 1, \ - .u = { .getter = _getter } \ + .u = { .prop_handler = _handler } \ } \ } diff -r 28d75187de15 -r a65deb4c2e03 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 20 16:42:10 2018 +0300 @@ -5792,6 +5792,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("({}).__proto__ === Object.prototype"), nxt_string("true") }, + { nxt_string("({}).__proto__ = 1"), + nxt_string("1") }, + + { nxt_string("var o = {}; o.__proto__ = 1; o.__proto__"), + nxt_string("[object Object]") }, + { nxt_string("({}).__proto__.constructor === Object"), nxt_string("true") }, From xeioex at nginx.com Fri Apr 20 13:42:38 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 20 Apr 2018 13:42:38 +0000 Subject: [njs] Added array length setter. Message-ID: details: http://hg.nginx.org/njs/rev/7f75ccba396e branches: changeset: 502:7f75ccba396e user: Dmitry Volyntsev date: Fri Apr 20 16:42:12 2018 +0300 description: Added array length setter. This fixes #1 issue on GitHub. diffstat: njs/njs_array.c | 49 ++++++++++++++++++++++++++++++++++++++++++----- njs/test/njs_unit_test.c | 35 ++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 6 deletions(-) diffs (106 lines): diff -r a65deb4c2e03 -r 7f75ccba396e njs/njs_array.c --- a/njs/njs_array.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/njs_array.c Fri Apr 20 16:42:12 2018 +0300 @@ -381,14 +381,51 @@ const njs_object_init_t njs_array_const static njs_ret_t -njs_array_prototype_length(njs_vm_t *vm, njs_value_t *array, +njs_array_prototype_length(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval, njs_value_t *retval) { - njs_value_number_set(retval, array->data.u.array->length); - - njs_release(vm, array); - - return NXT_OK; + double num; + int32_t size; + uint32_t length; + njs_ret_t ret; + njs_value_t *val; + njs_array_t *array; + + array = value->data.u.array; + + if (setval != NULL) { + num = setval->data.u.number; + length = (uint32_t) num; + + if ((double) length != num) { + njs_range_error(vm, "Invalid array length", NULL); + return NJS_ERROR; + } + + size = (int32_t) (length - array->length); + + if (size > 0) { + ret = njs_array_expand(vm, array, 0, size); + if (nxt_slow_path(ret != NXT_OK)) { + njs_memory_error(vm); + return NJS_ERROR; + } + + val = &array->start[array->length]; + + do { + njs_set_invalid(val); + val++; + size--; + } while (size != 0); + } + + array->length = length; + } + + njs_value_number_set(retval, array->length); + + return NJS_OK; } diff -r a65deb4c2e03 -r 7f75ccba396e njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Fri Apr 20 16:42:10 2018 +0300 +++ b/njs/test/njs_unit_test.c Fri Apr 20 16:42:12 2018 +0300 @@ -2700,6 +2700,41 @@ static njs_unit_test_t njs_test[] = { nxt_string("var a = [1,2]; a.length"), nxt_string("2") }, + /* Array.length setter */ + + { nxt_string("[].length = {}"), + nxt_string("RangeError: Invalid array length") }, + + { nxt_string("[].length = 2**32"), + nxt_string("RangeError: Invalid array length") }, + + { nxt_string("[].length = -1"), + nxt_string("RangeError: Invalid array length") }, + + { nxt_string("var a = []; a.length = 0; JSON.stringify(a)"), + nxt_string("[]") }, + + { nxt_string("var a = []; a.length = 1; JSON.stringify(a)"), + nxt_string("[null]") }, + + { nxt_string("var a = [1]; a.length = 1; JSON.stringify(a)"), + nxt_string("[1]") }, + + { nxt_string("var a = [1]; a.length = 2; JSON.stringify(a)"), + nxt_string("[1,null]") }, + + { nxt_string("var a = [1]; a.length = 4; a.length = 0; JSON.stringify(a)"), + nxt_string("[]") }, + + { nxt_string("var a = [1,2,3]; a.length = 2; JSON.stringify(a)"), + nxt_string("[1,2]") }, + + { nxt_string("var a = [1,2,3]; a.length = 3; a"), + nxt_string("1,2,3") }, + + { nxt_string("var a = [1,2,3]; a.length = 16; a"), + nxt_string("1,2,3,,,,,,,,,,,,,") }, + { nxt_string("var a = [1,2,3]; a.join()"), nxt_string("1,2,3") }, From vl at nginx.com Mon Apr 23 13:52:40 2018 From: vl at nginx.com (Vladimir Homutov) Date: Mon, 23 Apr 2018 16:52:40 +0300 Subject: nginx development guide In-Reply-To: <20170213093825.GA27852@vlpc.nginx.com> References: <20170213093825.GA27852@vlpc.nginx.com> Message-ID: <857532c0-3011-f807-0b3a-87e290aed544@nginx.com> 13.02.2017 12:38, Vladimir Homutov ?????: > Hello all! > > We are glad to share with first results of our ongoing efforts to create > documentation for nginx developers: the development guide document [1]. > > The guide is not yet 100% complete and more parts to follow. > > Of course, your feedback is welcome. > > [1] http://nginx.org/en/docs/dev/development_guide.html > _______________________________________________ Since then, development guide was updated with examples section: http://nginx.org/en/docs/dev/development_guide.html#examples and a code style description: http://nginx.org/en/docs/dev/development_guide.html#code_style From gmm at csdoc.com Tue Apr 24 08:20:47 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Tue, 24 Apr 2018 11:20:47 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. Message-ID: # HG changeset patch # User Gena Makhomed # Date 1523382230 -10800 # Tue Apr 10 20:43:50 2018 +0300 # Node ID 4049f2a9bc4e8de556f659769ea061f5b1b244e1 # Parent 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 Contrib: vim syntax, update core and 3rd party module directives. diff -r 1ad1cdfe7409 -r 4049f2a9bc4e contrib/vim/syntax/nginx.vim --- a/contrib/vim/syntax/nginx.vim Tue Apr 10 17:11:10 2018 +0300 +++ b/contrib/vim/syntax/nginx.vim Tue Apr 10 20:43:50 2018 +0300 @@ -119,6 +119,8 @@ syn keyword ngxDirectiveDeprecated contained spdy_recv_timeout syn keyword ngxDirectiveDeprecated contained spdy_streams_index_size syn keyword ngxDirectiveDeprecated contained upstream_conf +syn keyword ngxDirectiveDeprecated contained status +syn keyword ngxDirectiveDeprecated contained status_format syn keyword ngxDirective contained absolute_redirect syn keyword ngxDirective contained accept_mutex @@ -136,6 +138,7 @@ syn keyword ngxDirective contained allow syn keyword ngxDirective contained ancient_browser syn keyword ngxDirective contained ancient_browser_value +syn keyword ngxDirective contained api syn keyword ngxDirective contained auth_basic syn keyword ngxDirective contained auth_basic_user_file syn keyword ngxDirective contained auth_http @@ -143,7 +146,10 @@ syn keyword ngxDirective contained auth_http_pass_client_cert syn keyword ngxDirective contained auth_http_timeout syn keyword ngxDirective contained auth_jwt +syn keyword ngxDirective contained auth_jwt_claim_set +syn keyword ngxDirective contained auth_jwt_header_set syn keyword ngxDirective contained auth_jwt_key_file +syn keyword ngxDirective contained auth_jwt_leeway syn keyword ngxDirective contained auth_request syn keyword ngxDirective contained auth_request_set syn keyword ngxDirective contained autoindex @@ -330,6 +336,8 @@ syn keyword ngxDirective contained keepalive_disable syn keyword ngxDirective contained keepalive_requests syn keyword ngxDirective contained keepalive_timeout +syn keyword ngxDirective contained keyval +syn keyword ngxDirective contained keyval_zone syn keyword ngxDirective contained kqueue_changes syn keyword ngxDirective contained kqueue_events syn keyword ngxDirective contained large_client_header_buffers @@ -593,8 +601,6 @@ syn keyword ngxDirective contained ssl_verify_depth syn keyword ngxDirective contained starttls syn keyword ngxDirective contained state -syn keyword ngxDirective contained status -syn keyword ngxDirective contained status_format syn keyword ngxDirective contained status_zone syn keyword ngxDirective contained sticky syn keyword ngxDirective contained sticky_cookie_insert @@ -701,6 +707,24 @@ syn keyword ngxDirective contained xslt_stylesheet syn keyword ngxDirective contained xslt_types syn keyword ngxDirective contained zone +syn keyword ngxDirective contained zone_sync +syn keyword ngxDirective contained zone_sync_buffers +syn keyword ngxDirective contained zone_sync_connect_retry_interval +syn keyword ngxDirective contained zone_sync_connect_timeout +syn keyword ngxDirective contained zone_sync_interval +syn keyword ngxDirective contained zone_sync_recv_buffer_size +syn keyword ngxDirective contained zone_sync_server +syn keyword ngxDirective contained zone_sync_ssl +syn keyword ngxDirective contained zone_sync_ssl_certificate +syn keyword ngxDirective contained zone_sync_ssl_certificate_key +syn keyword ngxDirective contained zone_sync_ssl_ciphers +syn keyword ngxDirective contained zone_sync_ssl_crl +syn keyword ngxDirective contained zone_sync_ssl_password_file +syn keyword ngxDirective contained zone_sync_ssl_protocols +syn keyword ngxDirective contained zone_sync_ssl_trusted_certificate +syn keyword ngxDirective contained zone_sync_ssl_verify +syn keyword ngxDirective contained zone_sync_ssl_verify_depth +syn keyword ngxDirective contained zone_sync_timeout " 3rd party modules list taken from " https://github.com/freebsd/freebsd-ports/blob/master/www/nginx-devel/Makefile @@ -1355,6 +1379,10 @@ " https://www.phusionpassenger.com/library/config/nginx/reference/ syn keyword ngxDirectiveThirdParty contained passenger_abort_on_startup_error syn keyword ngxDirectiveThirdParty contained passenger_abort_websockets_on_process_shutdown +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_auth_type +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_password +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_url +syn keyword ngxDirectiveThirdParty contained passenger_admin_panel_username syn keyword ngxDirectiveThirdParty contained passenger_app_env syn keyword ngxDirectiveThirdParty contained passenger_app_file_descriptor_ulimit syn keyword ngxDirectiveThirdParty contained passenger_app_group_name @@ -1375,6 +1403,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_default_user syn keyword ngxDirectiveThirdParty contained passenger_disable_security_update_check syn keyword ngxDirectiveThirdParty contained passenger_document_root +syn keyword ngxDirectiveThirdParty contained passenger_dump_config_manifest syn keyword ngxDirectiveThirdParty contained passenger_enabled syn keyword ngxDirectiveThirdParty contained passenger_env_var syn keyword ngxDirectiveThirdParty contained passenger_file_descriptor_log_file @@ -1402,6 +1431,7 @@ syn keyword ngxDirectiveThirdParty contained passenger_memory_limit syn keyword ngxDirectiveThirdParty contained passenger_meteor_app_settings syn keyword ngxDirectiveThirdParty contained passenger_min_instances +syn keyword ngxDirectiveThirdParty contained passenger_monitor_log_file syn keyword ngxDirectiveThirdParty contained passenger_nodejs syn keyword ngxDirectiveThirdParty contained passenger_pass_header syn keyword ngxDirectiveThirdParty contained passenger_pool_idle_time From gmm at csdoc.com Tue Apr 24 08:29:18 2018 From: gmm at csdoc.com (Gena Makhomed) Date: Tue, 24 Apr 2018 11:29:18 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. In-Reply-To: References: Message-ID: On 10.04.2018 20:47, Gena Makhomed wrote: > # HG changeset patch > # User Gena Makhomed > # Date 1523382230 -10800 > #????? Tue Apr 10 20:43:50 2018 +0300 > # Node ID 4049f2a9bc4e8de556f659769ea061f5b1b244e1 > # Parent? 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 > Contrib: vim syntax, update core and 3rd party module directives. Maxim, can you please review this patch? -- Best regards, Gena From fangpeng1986 at gmail.com Tue Apr 24 08:33:15 2018 From: fangpeng1986 at gmail.com (Peng Fang) Date: Tue, 24 Apr 2018 16:33:15 +0800 Subject: fix style broken by 3a8a53c0c42f Message-ID: # HG changeset patch # User peng fang # Date 1524558323 -28800 # Node ID 5b84c8dc4cf5e909673adc24e044a7644da7f8d5 # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd Style. Fix style broken by 3a8a53c0c42f. diff -r 7c614ef3c6ea -r 5b84c8dc4cf5 src/http/ngx_http_cache.h --- a/src/http/ngx_http_cache.h Wed Apr 18 16:11:41 2018 +0300 +++ b/src/http/ngx_http_cache.h Tue Apr 24 16:25:23 2018 +0800 @@ -191,7 +191,7 @@ ngx_int_t ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char *buf); void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t *tf); void ngx_http_file_cache_update_header(ngx_http_request_t *r); -ngx_int_t ngx_http_cache_send(ngx_http_request_t *); +ngx_int_t ngx_http_cache_send(ngx_http_request_t *r); void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf); time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t status); -------------- next part -------------- An HTML attachment was scrubbed... URL: From ru at nginx.com Tue Apr 24 09:02:14 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Tue, 24 Apr 2018 12:02:14 +0300 Subject: fix style broken by 3a8a53c0c42f In-Reply-To: References: Message-ID: <20180424090214.GB21889@lo0.su> Hi, On Tue, Apr 24, 2018 at 04:33:15PM +0800, Peng Fang wrote: > # HG changeset patch > # User peng fang > # Date 1524558323 -28800 > # Node ID 5b84c8dc4cf5e909673adc24e044a7644da7f8d5 > # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd > Style. > > Fix style broken by 3a8a53c0c42f. > > diff -r 7c614ef3c6ea -r 5b84c8dc4cf5 src/http/ngx_http_cache.h > --- a/src/http/ngx_http_cache.h Wed Apr 18 16:11:41 2018 +0300 > +++ b/src/http/ngx_http_cache.h Tue Apr 24 16:25:23 2018 +0800 > @@ -191,7 +191,7 @@ > ngx_int_t ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char > *buf); > void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t > *tf); > void ngx_http_file_cache_update_header(ngx_http_request_t *r); > -ngx_int_t ngx_http_cache_send(ngx_http_request_t *); > +ngx_int_t ngx_http_cache_send(ngx_http_request_t *r); > void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t *tf); > time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t > status); Thanks for your patch. It is incomplete: diff --git a/src/http/modules/ngx_http_ssi_filter_module.h b/src/http/modules/ngx_http_ssi_filter_module.h --- a/src/http/modules/ngx_http_ssi_filter_module.h +++ b/src/http/modules/ngx_http_ssi_filter_module.h @@ -85,7 +85,7 @@ typedef struct { typedef ngx_int_t (*ngx_http_ssi_command_pt) (ngx_http_request_t *r, - ngx_http_ssi_ctx_t *ctx, ngx_str_t **); + ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); typedef struct { diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h --- a/src/http/ngx_http.h +++ b/src/http/ngx_http.h @@ -159,7 +159,7 @@ ngx_int_t ngx_http_set_default_types(ngx ngx_str_t *default_type); #if (NGX_HTTP_DEGRADATION) -ngx_uint_t ngx_http_degraded(ngx_http_request_t *); +ngx_uint_t ngx_http_degraded(ngx_http_request_t *r); #endif The patch above shows another style issue within nginx: $ grep -r 'typedef.*pt)(' src | wc -l 54 $ grep -r 'typedef.*pt) (' src | wc -l 26 Note that nginx code now has a lot of violations of its own code style. Please DO NOT send us style fixing patches, we won't commit them just for the sake of fixing style. Only do so if you notice the style violation while working on the code, then you MAY send the style fixing patch as a preparatory one in the patch series. From fangpeng1986 at gmail.com Tue Apr 24 09:06:31 2018 From: fangpeng1986 at gmail.com (Peng Fang) Date: Tue, 24 Apr 2018 17:06:31 +0800 Subject: fix style broken by 3a8a53c0c42f In-Reply-To: <20180424090214.GB21889@lo0.su> References: <20180424090214.GB21889@lo0.su> Message-ID: OK ,thanks for your explanation. 2018-04-24 17:02 GMT+08:00 Ruslan Ermilov : > Hi, > > On Tue, Apr 24, 2018 at 04:33:15PM +0800, Peng Fang wrote: > > # HG changeset patch > > # User peng fang > > # Date 1524558323 -28800 > > # Node ID 5b84c8dc4cf5e909673adc24e044a7644da7f8d5 > > # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd > > Style. > > > > Fix style broken by 3a8a53c0c42f. > > > > diff -r 7c614ef3c6ea -r 5b84c8dc4cf5 src/http/ngx_http_cache.h > > --- a/src/http/ngx_http_cache.h Wed Apr 18 16:11:41 2018 +0300 > > +++ b/src/http/ngx_http_cache.h Tue Apr 24 16:25:23 2018 +0800 > > @@ -191,7 +191,7 @@ > > ngx_int_t ngx_http_file_cache_set_header(ngx_http_request_t *r, u_char > > *buf); > > void ngx_http_file_cache_update(ngx_http_request_t *r, ngx_temp_file_t > > *tf); > > void ngx_http_file_cache_update_header(ngx_http_request_t *r); > > -ngx_int_t ngx_http_cache_send(ngx_http_request_t *); > > +ngx_int_t ngx_http_cache_send(ngx_http_request_t *r); > > void ngx_http_file_cache_free(ngx_http_cache_t *c, ngx_temp_file_t > *tf); > > time_t ngx_http_file_cache_valid(ngx_array_t *cache_valid, ngx_uint_t > > status); > > Thanks for your patch. It is incomplete: > > diff --git a/src/http/modules/ngx_http_ssi_filter_module.h > b/src/http/modules/ngx_http_ssi_filter_module.h > --- a/src/http/modules/ngx_http_ssi_filter_module.h > +++ b/src/http/modules/ngx_http_ssi_filter_module.h > @@ -85,7 +85,7 @@ typedef struct { > > > typedef ngx_int_t (*ngx_http_ssi_command_pt) (ngx_http_request_t *r, > - ngx_http_ssi_ctx_t *ctx, ngx_str_t **); > + ngx_http_ssi_ctx_t *ctx, ngx_str_t **params); > > > typedef struct { > diff --git a/src/http/ngx_http.h b/src/http/ngx_http.h > --- a/src/http/ngx_http.h > +++ b/src/http/ngx_http.h > @@ -159,7 +159,7 @@ ngx_int_t ngx_http_set_default_types(ngx > ngx_str_t *default_type); > > #if (NGX_HTTP_DEGRADATION) > -ngx_uint_t ngx_http_degraded(ngx_http_request_t *); > +ngx_uint_t ngx_http_degraded(ngx_http_request_t *r); > #endif > > > The patch above shows another style issue within nginx: > > $ grep -r 'typedef.*pt)(' src | wc -l > 54 > $ grep -r 'typedef.*pt) (' src | wc -l > 26 > > Note that nginx code now has a lot of violations of its own > code style. > > Please DO NOT send us style fixing patches, we won't commit > them just for the sake of fixing style. Only do so if you > notice the style violation while working on the code, then > you MAY send the style fixing patch as a preparatory one in > the patch series. > _______________________________________________ > nginx-devel mailing list > nginx-devel at nginx.org > http://mailman.nginx.org/mailman/listinfo/nginx-devel > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mdounin at mdounin.ru Tue Apr 24 12:56:20 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 24 Apr 2018 12:56:20 +0000 Subject: [nginx] Mail: fixed error message about missing ssl_certificate_key. Message-ID: details: http://hg.nginx.org/nginx/rev/0d8c72ff62dd branches: changeset: 7268:0d8c72ff62dd user: Maxim Dounin date: Tue Apr 24 15:28:58 2018 +0300 description: Mail: fixed error message about missing ssl_certificate_key. In 51e1f047d15d, the "ssl" directive name was incorrectly hardcoded in the error message shown when there are some SSL keys defined, but not for all certificates. Right approach is to use the "mode" variable, which can be either "ssl" or "starttls". diffstat: src/mail/ngx_mail_ssl_module.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (16 lines): diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c --- a/src/mail/ngx_mail_ssl_module.c +++ b/src/mail/ngx_mail_ssl_module.c @@ -350,10 +350,10 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, ngx_log_error(NGX_LOG_EMERG, cf->log, 0, "no \"ssl_certificate_key\" is defined " "for certificate \"%V\" and " - "the \"ssl\" directive in %s:%ui", + "the \"%s\" directive in %s:%ui", ((ngx_str_t *) conf->certificates->elts) + conf->certificates->nelts - 1, - conf->file, conf->line); + mode, conf->file, conf->line); return NGX_CONF_ERROR; } From mdounin at mdounin.ru Tue Apr 24 12:56:21 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 24 Apr 2018 12:56:21 +0000 Subject: [nginx] SSL: detect "listen ... ssl" without certificates (ticket #178). Message-ID: details: http://hg.nginx.org/nginx/rev/7f955d3b9a0d branches: changeset: 7269:7f955d3b9a0d user: Maxim Dounin date: Tue Apr 24 15:29:01 2018 +0300 description: SSL: detect "listen ... ssl" without certificates (ticket #178). In mail and stream modules, no certificate provided is a fatal condition, much like with the "ssl" and "starttls" directives. In http, "listen ... ssl" can be used in a non-default server without certificates as long as there is a certificate in the default one, so missing certificate is only fatal for default servers. diffstat: src/http/modules/ngx_http_ssl_module.c | 33 ++++++++++++- src/http/ngx_http_core_module.c | 3 + src/http/ngx_http_core_module.h | 3 + src/http/ngx_http_request.c | 13 +---- src/mail/ngx_mail_core_module.c | 9 +++ src/mail/ngx_mail_handler.c | 18 +------ src/mail/ngx_mail_ssl_module.c | 86 ++++++++++++++------------------- src/mail/ngx_mail_ssl_module.h | 1 + src/stream/ngx_stream_core_module.c | 10 +++ src/stream/ngx_stream_ssl_module.c | 36 +++++++++----- src/stream/ngx_stream_ssl_module.h | 4 + 11 files changed, 123 insertions(+), 93 deletions(-) diffs (406 lines): diff --git a/src/http/modules/ngx_http_ssl_module.c b/src/http/modules/ngx_http_ssl_module.c --- a/src/http/modules/ngx_http_ssl_module.c +++ b/src/http/modules/ngx_http_ssl_module.c @@ -966,10 +966,12 @@ invalid: static ngx_int_t ngx_http_ssl_init(ngx_conf_t *cf) { - ngx_uint_t s; + ngx_uint_t a, p, s; + ngx_http_conf_addr_t *addr; + ngx_http_conf_port_t *port; ngx_http_ssl_srv_conf_t *sscf; ngx_http_core_loc_conf_t *clcf; - ngx_http_core_srv_conf_t **cscfp; + ngx_http_core_srv_conf_t **cscfp, *cscf; ngx_http_core_main_conf_t *cmcf; cmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_core_module); @@ -993,5 +995,32 @@ ngx_http_ssl_init(ngx_conf_t *cf) } } + if (cmcf->ports == NULL) { + return NGX_OK; + } + + port = cmcf->ports->elts; + for (p = 0; p < cmcf->ports->nelts; p++) { + + addr = port[p].addrs.elts; + for (a = 0; a < port[p].addrs.nelts; a++) { + + if (!addr[a].opt.ssl) { + continue; + } + + cscf = addr[a].default_server; + sscf = cscf->ctx->srv_conf[ngx_http_ssl_module.ctx_index]; + + if (sscf->certificates == NULL) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"ssl_certificate\" is defined for " + "the \"listen ... ssl\" directive in %s:%ui", + cscf->file_name, cscf->line); + return NGX_ERROR; + } + } + } + return NGX_OK; } diff --git a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c --- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -3256,6 +3256,9 @@ ngx_http_core_create_srv_conf(ngx_conf_t cscf->merge_slashes = NGX_CONF_UNSET; cscf->underscores_in_headers = NGX_CONF_UNSET; + cscf->file_name = cf->conf_file->file.name.data; + cscf->line = cf->conf_file->line; + return cscf; } diff --git a/src/http/ngx_http_core_module.h b/src/http/ngx_http_core_module.h --- a/src/http/ngx_http_core_module.h +++ b/src/http/ngx_http_core_module.h @@ -184,6 +184,9 @@ typedef struct { /* server ctx */ ngx_http_conf_ctx_t *ctx; + u_char *file_name; + ngx_uint_t line; + ngx_str_t server_name; size_t connection_pool_size; diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c --- a/src/http/ngx_http_request.c +++ b/src/http/ngx_http_request.c @@ -336,19 +336,8 @@ ngx_http_init_connection(ngx_connection_ sscf = ngx_http_get_module_srv_conf(hc->conf_ctx, ngx_http_ssl_module); if (sscf->enable || hc->addr_conf->ssl) { - + hc->ssl = 1; c->log->action = "SSL handshaking"; - - if (hc->addr_conf->ssl && sscf->ssl.ctx == NULL) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no \"ssl_certificate\" is defined " - "in server listening on SSL port"); - ngx_http_close_connection(c); - return; - } - - hc->ssl = 1; - rev->handler = ngx_http_ssl_handshake; } } diff --git a/src/mail/ngx_mail_core_module.c b/src/mail/ngx_mail_core_module.c --- a/src/mail/ngx_mail_core_module.c +++ b/src/mail/ngx_mail_core_module.c @@ -474,7 +474,16 @@ ngx_mail_core_listen(ngx_conf_t *cf, ngx 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, diff --git a/src/mail/ngx_mail_handler.c b/src/mail/ngx_mail_handler.c --- a/src/mail/ngx_mail_handler.c +++ b/src/mail/ngx_mail_handler.c @@ -165,29 +165,13 @@ ngx_mail_init_connection(ngx_connection_ sslcf = ngx_mail_get_module_srv_conf(s, ngx_mail_ssl_module); - if (sslcf->enable) { + if (sslcf->enable || addr_conf->ssl) { c->log->action = "SSL handshaking"; ngx_mail_ssl_init_connection(&sslcf->ssl, c); return; } - if (addr_conf->ssl) { - - c->log->action = "SSL handshaking"; - - if (sslcf->ssl.ctx == NULL) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no \"ssl_certificate\" is defined " - "in server listening on SSL port"); - ngx_mail_close_connection(c); - return; - } - - ngx_mail_ssl_init_connection(&sslcf->ssl, c); - return; - } - } #endif diff --git a/src/mail/ngx_mail_ssl_module.c b/src/mail/ngx_mail_ssl_module.c --- a/src/mail/ngx_mail_ssl_module.c +++ b/src/mail/ngx_mail_ssl_module.c @@ -238,6 +238,7 @@ ngx_mail_ssl_create_conf(ngx_conf_t *cf) /* * set by ngx_pcalloc(): * + * scf->listen = 0; * scf->protocols = 0; * scf->dhparam = { 0, NULL }; * scf->ecdh_curve = { 0, NULL }; @@ -313,14 +314,17 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, conf->ssl.log = cf->log; - if (conf->enable) { + if (conf->listen) { + mode = "listen ... ssl"; + + } else if (conf->enable) { mode = "ssl"; } else if (conf->starttls != NGX_MAIL_STARTTLS_OFF) { mode = "starttls"; } else { - mode = ""; + return NGX_CONF_OK; } if (conf->file == NULL) { @@ -328,51 +332,31 @@ ngx_mail_ssl_merge_conf(ngx_conf_t *cf, conf->line = prev->line; } - if (*mode) { - - 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->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->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; - } - - } else { + 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->certificates == NULL) { - return NGX_CONF_OK; - } - - if (conf->certificate_keys == NULL - || 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\"", - ((ngx_str_t *) conf->certificates->elts) - + conf->certificates->nelts - 1); - 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) { @@ -494,8 +478,10 @@ ngx_mail_ssl_enable(ngx_conf_t *cf, ngx_ return NGX_CONF_ERROR; } - scf->file = cf->conf_file->file.name.data; - scf->line = cf->conf_file->line; + if (!scf->listen) { + scf->file = cf->conf_file->file.name.data; + scf->line = cf->conf_file->line; + } return NGX_CONF_OK; } @@ -520,8 +506,10 @@ ngx_mail_ssl_starttls(ngx_conf_t *cf, ng return NGX_CONF_ERROR; } - scf->file = cf->conf_file->file.name.data; - scf->line = cf->conf_file->line; + if (!scf->listen) { + scf->file = cf->conf_file->file.name.data; + scf->line = cf->conf_file->line; + } return NGX_CONF_OK; } diff --git a/src/mail/ngx_mail_ssl_module.h b/src/mail/ngx_mail_ssl_module.h --- a/src/mail/ngx_mail_ssl_module.h +++ b/src/mail/ngx_mail_ssl_module.h @@ -26,6 +26,7 @@ typedef struct { ngx_ssl_t ssl; ngx_uint_t starttls; + ngx_uint_t listen; ngx_uint_t protocols; ngx_uint_t verify; diff --git a/src/stream/ngx_stream_core_module.c b/src/stream/ngx_stream_core_module.c --- a/src/stream/ngx_stream_core_module.c +++ b/src/stream/ngx_stream_core_module.c @@ -734,7 +734,17 @@ ngx_stream_core_listen(ngx_conf_t *cf, n if (ngx_strcmp(value[i].data, "ssl") == 0) { #if (NGX_STREAM_SSL) + ngx_stream_ssl_conf_t *sslcf; + + sslcf = ngx_stream_conf_get_module_srv_conf(cf, + ngx_stream_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, diff --git a/src/stream/ngx_stream_ssl_module.c b/src/stream/ngx_stream_ssl_module.c --- a/src/stream/ngx_stream_ssl_module.c +++ b/src/stream/ngx_stream_ssl_module.c @@ -304,13 +304,6 @@ ngx_stream_ssl_handler(ngx_stream_sessio if (c->ssl == NULL) { c->log->action = "SSL handshaking"; - if (sslcf->ssl.ctx == NULL) { - ngx_log_error(NGX_LOG_ERR, c->log, 0, - "no \"ssl_certificate\" is defined " - "in server listening on SSL port"); - return NGX_ERROR; - } - rv = ngx_stream_ssl_init_connection(&sslcf->ssl, c); if (rv != NGX_OK) { @@ -510,6 +503,7 @@ ngx_stream_ssl_create_conf(ngx_conf_t *c /* * set by ngx_pcalloc(): * + * scf->listen = 0; * scf->protocols = 0; * scf->dhparam = { 0, NULL }; * scf->ecdh_curve = { 0, NULL }; @@ -582,18 +576,34 @@ ngx_stream_ssl_merge_conf(ngx_conf_t *cf conf->ssl.log = cf->log; - if (conf->certificates == NULL) { + if (!conf->listen) { return NGX_CONF_OK; } - if (conf->certificate_keys == NULL - || conf->certificate_keys->nelts < conf->certificates->nelts) - { + if (conf->certificates == NULL) { + ngx_log_error(NGX_LOG_EMERG, cf->log, 0, + "no \"ssl_certificate\" is defined for " + "the \"listen ... ssl\" directive in %s:%ui", + 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 \"listen ... ssl\" directive in %s:%ui", + 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\"", + "for certificate \"%V\" and " + "the \"listen ... ssl\" directive in %s:%ui", ((ngx_str_t *) conf->certificates->elts) - + conf->certificates->nelts - 1); + + conf->certificates->nelts - 1, + conf->file, conf->line); return NGX_CONF_ERROR; } diff --git a/src/stream/ngx_stream_ssl_module.h b/src/stream/ngx_stream_ssl_module.h --- a/src/stream/ngx_stream_ssl_module.h +++ b/src/stream/ngx_stream_ssl_module.h @@ -21,6 +21,7 @@ typedef struct { ngx_ssl_t ssl; + ngx_uint_t listen; ngx_uint_t protocols; ngx_uint_t verify; @@ -47,6 +48,9 @@ typedef struct { ngx_flag_t session_tickets; ngx_array_t *session_ticket_keys; + + u_char *file; + ngx_uint_t line; } ngx_stream_ssl_conf_t; From agile6v at agile6v.com Tue Apr 24 16:47:13 2018 From: agile6v at agile6v.com (=?ISO-8859-1?B?YWdpbGU2dg==?=) Date: Wed, 25 Apr 2018 00:47:13 +0800 Subject: [PATCH] The auto parameter of the worker_processes supports to detect the container environment. Message-ID: # HG changeset patch # User Agile6v # Date 1524585905 -28800 # Wed Apr 25 00:05:05 2018 +0800 # Node ID 89793df28d1bcf2baf00e389e6806d32d7435886 # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd The auto parameter of the worker_processes supports to detect the container environment. Docker mounts cgroup information into container starting with version 1.8, so it is possible to determine the appropriate number of CPUs based on the cgroup information in the container. Refer to JDK related implementation: https://bugs.openjdk.java.net/browse/JDK-8146115 diff -r 7c614ef3c6ea -r 89793df28d1b auto/sources --- a/auto/sources Wed Apr 18 16:11:41 2018 +0300 +++ b/auto/sources Wed Apr 25 00:05:05 2018 +0800 @@ -192,8 +192,8 @@ FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c FREEBSD_SENDFILE_SRCS=src/os/unix/ngx_freebsd_sendfile_chain.c -LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h" -LINUX_SRCS=src/os/unix/ngx_linux_init.c +LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h src/os/unix/ngx_container.h" +LINUX_SRCS="src/os/unix/ngx_linux_init.c src/os/unix/ngx_container.c" LINUX_SENDFILE_SRCS=src/os/unix/ngx_linux_sendfile_chain.c diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_container.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/os/unix/ngx_container.c Wed Apr 25 00:05:05 2018 +0800 @@ -0,0 +1,418 @@ + +/* + * Copyright (C) agile6v + * Copyright (C) Xiaomi, Inc. + */ + +#include +#include + +#define NGX_BUFFER_SIZE 8192 +#define PER_CPU_SHARES 1024 + +typedef struct { + ngx_str_t root; + ngx_str_t path; + ngx_str_t mount_point; +} cgroup_subsystem_info; + +static cgroup_subsystem_info cpu_subsystem; + +static ngx_str_t proc_cgroup_file = ngx_string("/proc/self/cgroup"); +static ngx_str_t proc_mount_file = ngx_string("/proc/self/mountinfo"); +static ngx_str_t cpu_cfs_period = ngx_string("/cpu.cfs_period_us"); +static ngx_str_t cpu_cfs_quota = ngx_string("/cpu.cfs_quota_us"); +static ngx_str_t cpu_cfs_shares = ngx_string("/cpu.shares"); + +static float ngx_ceilf(float x) +{ + long r = x; + + if (r < 0) { + return r; + } else { + return (r + ((r < x) ? 1 : 0)); + } +} + + +static ngx_int_t +ngx_set_subsystem_path(cgroup_subsystem_info *subsystem_info, + ngx_str_t *cgroup_path, ngx_pool_t *pool) +{ + u_char *p; + ngx_uint_t len; + + if (subsystem_info->root.len != 0 && cgroup_path->data != NULL) { + if (ngx_strcmp(subsystem_info->root.data, "/") == 0) { + len = subsystem_info->mount_point.len; + if (ngx_strcmp(cgroup_path->data, "/") != 0) { + len += cgroup_path->len; + } + + if (len > NGX_MAX_PATH) { + ngx_log_error(NGX_LOG_WARN, pool->log, 0, + "the length of the cgroup path exceeds the maximum " \ + "length of the path (%d) ", NGX_MAX_PATH); + return NGX_ERROR; + } + + p = ngx_palloc(pool, len + 1); + if (p == NULL) { + return NGX_ERROR; + } + + subsystem_info->path.data = p; + subsystem_info->path.len = len; + + if (ngx_strcmp(cgroup_path->data, "/") != 0) { + p = ngx_sprintf(p, "%V%V", + &subsystem_info->mount_point, + cgroup_path); + } else { + p = ngx_sprintf(p, "%V", &subsystem_info->mount_point); + } + + *p = '\0'; + } else if (ngx_strcmp(subsystem_info->root.data, + cgroup_path->data) == 0) + { + subsystem_info->path = subsystem_info->mount_point; + } + } + + return NGX_OK; +} + + +static ngx_int_t +ngx_read_proc_file(ngx_str_t *filename, ngx_str_t *buf, ngx_pool_t *pool) +{ + ngx_int_t ret; + ngx_uint_t i; + size_t size; + ssize_t n; + ngx_file_t file; + + ngx_memzero(&file, sizeof(ngx_file_t)); + + file.name = *filename; + file.log = pool->log; + file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); + if (file.fd == NGX_INVALID_FILE) { + return NGX_ERROR; + } + + ret = NGX_OK; + + // Typically this file will not be too big, then try to read all data + for (i = 1; i <= 5; i++) { + size = NGX_BUFFER_SIZE * i; + buf->data = ngx_palloc(pool, size); + if (buf->data == NULL) { + ret = NGX_ERROR; + break; + } + + n = ngx_read_file(&file, buf->data, size, 0); + if (n == NGX_ERROR) { + ret = NGX_ERROR; + break; + } + + buf->len = n; + + if (buf->len < size) { + break; + } + } + + if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, file.log, ngx_errno, + ngx_close_file_n " \"%s\" failed", file.name); + return NGX_ERROR; + } + + return ret; +} + + +/* + * refers to http://man7.org/linux/man-pages/man7/cgroups.7.html + */ +ngx_int_t +ngx_parse_cgroup_file(ngx_pool_t *pool) +{ + ngx_int_t ret; + ngx_str_t buf; + ngx_str_t fields[3]; + ngx_uint_t i, index; + u_char *start, *end, end_of_line; + + ret = ngx_read_proc_file(&proc_cgroup_file, &buf, pool); + if (ret == NGX_ERROR) { + return ret; + } + + index = 0; + start = end = buf.data; + + for (i = 0; i < buf.len; i++) { + if (*end == ':' || *end == '\n') { + end_of_line = (*end == '\n') ? 1 : 0; + *end = '\0'; + + fields[index].data = start; + fields[index].len = end - start; + + if (end_of_line) { + index = 0; + if (ngx_strstr(fields[1].data, "cpu,cpuacct") != NULL) { + ret = ngx_set_subsystem_path(&cpu_subsystem, &fields[2], pool); + if (ret == NGX_ERROR) { + return ret; + } + } + } else { + index++; + } + + start = end + 1; + } + + end++; + } + + return NGX_OK; +} + + +/* + * refers to http://man7.org/linux/man-pages/man5/proc.5.html + */ +ngx_int_t +ngx_parse_mount_info_file(ngx_pool_t *pool) +{ + ngx_str_t buf; + ngx_str_t fields[11]; + ngx_int_t ret; + ngx_uint_t i, index, fs_type_index; + u_char *start, *end, end_of_line; + + ret = ngx_read_proc_file(&proc_mount_file, &buf, pool); + if (ret == NGX_ERROR) { + return ret; + } + + fs_type_index = index = 0; + start = end = buf.data; + + for (i = 0; i < buf.len; i++) { + if (*end == ' ' || *end == '\n') { + end_of_line = (*end == '\n') ? 1 : 0; + *end = '\0'; + + fields[index].data = start; + fields[index].len = end - start; + + if (fields[index].len == 1 && *fields[index].data == '-') { + fs_type_index = index + 1; + } + + if (end_of_line) { + index = 0; + if (fields[fs_type_index].len == 6 + && ngx_strcmp(fields[fs_type_index].data, "cgroup") == 0 + && ngx_strstr(fields[4].data, "cpu,cpuacct") != NULL) + { + cpu_subsystem.root = fields[3]; + cpu_subsystem.mount_point = fields[4]; + } + } else { + index++; + } + + start = end + 1; + } + + end++; + } + + return NGX_OK; +} + + +static ngx_int_t +ngx_read_subsystem_info(cgroup_subsystem_info *subsystem, + ngx_str_t *filename, ngx_log_t *log, ngx_int_t *value) +{ + ngx_file_t file; + ngx_int_t ret; + ngx_str_t full_path; + ssize_t n; + u_char *p; + u_char sign = 0; + u_char buf[NGX_MAX_PATH + 1]; + + if (subsystem->path.data == NULL || subsystem->path.len == 0) { + return NGX_DONE; + } + + if ((subsystem->path.len + filename->len) > NGX_MAX_PATH) { + return NGX_DONE; + } + + full_path.data = buf; + full_path.len = NGX_MAX_PATH; + + ngx_memzero(&file, sizeof(ngx_file_t)); + + p = ngx_sprintf(full_path.data, "%V%V", &subsystem->path, filename); + *p = '\0'; + full_path.len = p - full_path.data; + + file.name = full_path; + file.log = log; + file.fd = ngx_open_file(file.name.data, NGX_FILE_RDONLY, NGX_FILE_OPEN, 0); + if (file.fd == NGX_INVALID_FILE) { + return NGX_ERROR; + } + + n = ngx_read_file(&file, buf, NGX_BUFFER_SIZE, 0); + if (n == NGX_ERROR) { + return n; + } + + if (ngx_close_file(file.fd) == NGX_FILE_ERROR) { + ngx_log_error(NGX_LOG_ALERT, file.log, ngx_errno, + ngx_close_file_n " \"%s\" failed", file.name); + return NGX_ERROR; + } + + n = (n > 0) ? n - 1 : n; // remove linefeed + if (n == 0) { + return NGX_DONE; + } + + p = buf; + if (*p == '-') { + sign = 1; + p++; + n--; + } + + ret = ngx_atoi(p, n); + if (ret == NGX_ERROR) { + return NGX_DONE; + } + + if (sign) { + *value = -ret; + } else { + *value = ret; + } + + return NGX_OK; +} + + +static ngx_int_t +ngx_get_active_processor_count(ngx_log_t *log) { + ngx_int_t quota_count = 0, share_count = 0; + ngx_int_t cpu_count, limit_count; + ngx_int_t ret, quota, period, shares; + ngx_cpuset_t cpu_affinity; + + ret = ngx_getaffinity(&cpu_affinity, log); + if (ret == NGX_ERROR) { + return ret; + } + + cpu_count = limit_count = ret; + + ngx_log_error(NGX_LOG_INFO, log, 0, + "active processor count: %d", cpu_count); + + ret = ngx_read_subsystem_info(&cpu_subsystem, + &cpu_cfs_shares, log, &shares); + if (ret == NGX_DONE || ret == NGX_ERROR) { + return ret; + } + + ret = ngx_read_subsystem_info(&cpu_subsystem, + &cpu_cfs_quota, log, "a); + if (ret == NGX_DONE || ret == NGX_ERROR) { + return ret; + } + + ret = ngx_read_subsystem_info(&cpu_subsystem, + &cpu_cfs_period, log, &period); + if (ret == NGX_DONE || ret == NGX_ERROR) { + return ret; + } + + ngx_log_error(NGX_LOG_INFO, log, 0, + "cgroup cpu subsystem: quota=%d, period=%d, shares=%d", + quota, period, shares); + + if (shares == PER_CPU_SHARES) { + shares = -1; + } + + if (quota > -1 && period > 0) { + quota_count = ngx_ceilf((float) quota / (float) period); + } + + if (shares > -1) { + share_count = ngx_ceilf((float) shares / (float) PER_CPU_SHARES); + } + + if (quota_count != 0 && share_count != 0) { + limit_count = ngx_min(quota_count, share_count); + } else if (quota_count != 0) { + limit_count = quota_count; + } else if (share_count != 0) { + limit_count = share_count; + } + + return ngx_min(cpu_count, limit_count); +} + + +ngx_int_t +ngx_container_init(ngx_log_t *log) +{ + ngx_pool_t *pool; + ngx_int_t ret; + + pool = ngx_create_pool(NGX_DEFAULT_POOL_SIZE, log); + if (pool == NULL) { + return NGX_ERROR; + } + + pool->log = log; + + do { + ret = ngx_parse_mount_info_file(pool); + if (ret != NGX_OK) { + break; + } + + ret = ngx_parse_cgroup_file(pool); + if (ret != NGX_OK) { + break; + } + + if (cpu_subsystem.path.data == NULL || cpu_subsystem.path.len == 0) { + ret = NGX_DONE; + break; + } + + ret = ngx_get_active_processor_count(log); + + } while (0); + + ngx_destroy_pool(pool); + + return ret; +} diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_container.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/os/unix/ngx_container.h Wed Apr 25 00:05:05 2018 +0800 @@ -0,0 +1,12 @@ + +/* + * Copyright (C) agile6v + * Copyright (C) Xiaomi, Inc. + */ + +#ifndef _NGX_CONTAINER_H_INCLUDED_ +#define _NGX_CONTAINER_H_INCLUDED_ + +ngx_int_t ngx_container_init(ngx_log_t *log); + +#endif /* _NGX_CONTAINER_H_INCLUDED_ */ diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_linux_init.c --- a/src/os/unix/ngx_linux_init.c Wed Apr 18 16:11:41 2018 +0300 +++ b/src/os/unix/ngx_linux_init.c Wed Apr 25 00:05:05 2018 +0800 @@ -7,12 +7,12 @@ #include #include +#include u_char ngx_linux_kern_ostype[50]; u_char ngx_linux_kern_osrelease[50]; - static ngx_os_io_t ngx_linux_io = { ngx_unix_recv, ngx_readv_chain, @@ -33,6 +33,7 @@ ngx_int_t ngx_os_specific_init(ngx_log_t *log) { + ngx_int_t ret; struct utsname u; if (uname(&u) == -1) { @@ -48,6 +49,13 @@ ngx_os_io = ngx_linux_io; + ret = ngx_container_init(log); + if (ret == NGX_ERROR) { + return ret; + } else if (ret > NGX_OK) { + ngx_ncpu = ret; + } + return NGX_OK; } diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_setaffinity.c --- a/src/os/unix/ngx_setaffinity.c Wed Apr 18 16:11:41 2018 +0300 +++ b/src/os/unix/ngx_setaffinity.c Wed Apr 25 00:05:05 2018 +0800 @@ -30,6 +30,12 @@ } } +ngx_int_t +ngx_getaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log) +{ + return 0; +} + #elif (NGX_HAVE_SCHED_SETAFFINITY) void @@ -50,4 +56,16 @@ } } +ngx_int_t +ngx_getaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log) +{ + if (sched_getaffinity(0, sizeof(ngx_cpuset_t), cpu_affinity) == -1) { + ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, + "sched_getaffinity() failed"); + return NGX_ERROR; + } + + return CPU_COUNT(cpu_affinity); +} + #endif diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_setaffinity.h --- a/src/os/unix/ngx_setaffinity.h Wed Apr 18 16:11:41 2018 +0300 +++ b/src/os/unix/ngx_setaffinity.h Wed Apr 25 00:05:05 2018 +0800 @@ -23,12 +23,15 @@ #endif +ngx_int_t ngx_getaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log); void ngx_setaffinity(ngx_cpuset_t *cpu_affinity, ngx_log_t *log); #else #define ngx_setaffinity(cpu_affinity, log) +#define ngx_getaffinity(cpu_affinity, log) + typedef uint64_t ngx_cpuset_t; #endif -------------- next part -------------- An HTML attachment was scrubbed... URL: -------------- next part -------------- A non-text attachment was scrubbed... Name: nginx.patch Type: application/octet-stream Size: 14579 bytes Desc: not available URL: From mdounin at mdounin.ru Tue Apr 24 17:00:10 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Tue, 24 Apr 2018 20:00:10 +0300 Subject: [PATCH] The auto parameter of the worker_processes supports to detect the container environment. In-Reply-To: References: Message-ID: <20180424170010.GM1606@mdounin.ru> Hello! On Wed, Apr 25, 2018 at 12:47:13AM +0800, agile6v wrote: > # HG changeset patch > # User Agile6v > # Date 1524585905 -28800 > # Wed Apr 25 00:05:05 2018 +0800 > # Node ID 89793df28d1bcf2baf00e389e6806d32d7435886 > # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd > The auto parameter of the worker_processes supports to detect the container environment. > > > Docker mounts cgroup information into container starting with version 1.8, > so it is possible to determine the appropriate number of CPUs based on the > cgroup information in the container. Refer to JDK related implementation: > https://bugs.openjdk.java.net/browse/JDK-8146115 > > > diff -r 7c614ef3c6ea -r 89793df28d1b auto/sources > --- a/auto/sources Wed Apr 18 16:11:41 2018 +0300 > +++ b/auto/sources Wed Apr 25 00:05:05 2018 +0800 > @@ -192,8 +192,8 @@ > FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c > FREEBSD_SENDFILE_SRCS=src/os/unix/ngx_freebsd_sendfile_chain.c > > -LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h" > -LINUX_SRCS=src/os/unix/ngx_linux_init.c > +LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h src/os/unix/ngx_container.h" > +LINUX_SRCS="src/os/unix/ngx_linux_init.c src/os/unix/ngx_container.c" > LINUX_SENDFILE_SRCS=src/os/unix/ngx_linux_sendfile_chain.c > > > diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_container.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/src/os/unix/ngx_container.c Wed Apr 25 00:05:05 2018 +0800 > @@ -0,0 +1,418 @@ > + > +/* > + * Copyright (C) agile6v > + * Copyright (C) Xiaomi, Inc. > + */ > + > +#include > +#include > + > +#define NGX_BUFFER_SIZE 8192 > +#define PER_CPU_SHARES 1024 > + > +typedef struct { > + ngx_str_t root; > + ngx_str_t path; > + ngx_str_t mount_point; > +} cgroup_subsystem_info; > + > +static cgroup_subsystem_info cpu_subsystem; > + > +static ngx_str_t proc_cgroup_file = ngx_string("/proc/self/cgroup"); > +static ngx_str_t proc_mount_file = ngx_string("/proc/self/mountinfo"); > +static ngx_str_t cpu_cfs_period = ngx_string("/cpu.cfs_period_us"); > +static ngx_str_t cpu_cfs_quota = ngx_string("/cpu.cfs_quota_us"); > +static ngx_str_t cpu_cfs_shares = ngx_string("/cpu.shares"); [...] 400+ lines of code to obtain a number which is expected to be directly available via the sysconf(_SC_NPROCESSORS_ONLN) call might be a bit too many. Thank you for your effort, but no. -- Maxim Dounin http://mdounin.ru/ From agile6v at agile6v.com Tue Apr 24 17:35:48 2018 From: agile6v at agile6v.com (=?gb18030?B?YWdpbGU2dg==?=) Date: Wed, 25 Apr 2018 01:35:48 +0800 Subject: [PATCH] The auto parameter of the worker_processes supports todetect the container environment. In-Reply-To: <20180424170010.GM1606@mdounin.ru> References: <20180424170010.GM1606@mdounin.ru> Message-ID: Hi?Maxim This feature is not a much needed, but it can reduce the cost of manual configuration. If there is a better implementation that can solve this problem, we are also very much looking forward to it. I hope you can think again. Thanks. Regards, Agile6v ------------------ Original ------------------ From: "Maxim Dounin";; Date: Apr 25, 2018 To: "nginx-devel"; Subject: Re: [PATCH] The auto parameter of the worker_processes supports todetect the container environment. Hello! On Wed, Apr 25, 2018 at 12:47:13AM +0800, agile6v wrote: > # HG changeset patch > # User Agile6v > # Date 1524585905 -28800 > # Wed Apr 25 00:05:05 2018 +0800 > # Node ID 89793df28d1bcf2baf00e389e6806d32d7435886 > # Parent 7c614ef3c6ea330c62630d5065f961a27d0f82cd > The auto parameter of the worker_processes supports to detect the container environment. > > > Docker mounts cgroup information into container starting with version 1.8, > so it is possible to determine the appropriate number of CPUs based on the > cgroup information in the container. Refer to JDK related implementation: > https://bugs.openjdk.java.net/browse/JDK-8146115 > > > diff -r 7c614ef3c6ea -r 89793df28d1b auto/sources > --- a/auto/sources Wed Apr 18 16:11:41 2018 +0300 > +++ b/auto/sources Wed Apr 25 00:05:05 2018 +0800 > @@ -192,8 +192,8 @@ > FREEBSD_SRCS=src/os/unix/ngx_freebsd_init.c > FREEBSD_SENDFILE_SRCS=src/os/unix/ngx_freebsd_sendfile_chain.c > > -LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h" > -LINUX_SRCS=src/os/unix/ngx_linux_init.c > +LINUX_DEPS="src/os/unix/ngx_linux_config.h src/os/unix/ngx_linux.h src/os/unix/ngx_container.h" > +LINUX_SRCS="src/os/unix/ngx_linux_init.c src/os/unix/ngx_container.c" > LINUX_SENDFILE_SRCS=src/os/unix/ngx_linux_sendfile_chain.c > > > diff -r 7c614ef3c6ea -r 89793df28d1b src/os/unix/ngx_container.c > --- /dev/null Thu Jan 01 00:00:00 1970 +0000 > +++ b/src/os/unix/ngx_container.c Wed Apr 25 00:05:05 2018 +0800 > @@ -0,0 +1,418 @@ > + > +/* > + * Copyright (C) agile6v > + * Copyright (C) Xiaomi, Inc. > + */ > + > +#include > +#include > + > +#define NGX_BUFFER_SIZE 8192 > +#define PER_CPU_SHARES 1024 > + > +typedef struct { > + ngx_str_t root; > + ngx_str_t path; > + ngx_str_t mount_point; > +} cgroup_subsystem_info; > + > +static cgroup_subsystem_info cpu_subsystem; > + > +static ngx_str_t proc_cgroup_file = ngx_string("/proc/self/cgroup"); > +static ngx_str_t proc_mount_file = ngx_string("/proc/self/mountinfo"); > +static ngx_str_t cpu_cfs_period = ngx_string("/cpu.cfs_period_us"); > +static ngx_str_t cpu_cfs_quota = ngx_string("/cpu.cfs_quota_us"); > +static ngx_str_t cpu_cfs_shares = ngx_string("/cpu.shares"); [...] 400+ lines of code to obtain a number which is expected to be directly available via the sysconf(_SC_NPROCESSORS_ONLN) call might be a bit too many. Thank you for your effort, but no. -- Maxim Dounin http://mdounin.ru/ _______________________________________________ nginx-devel mailing list nginx-devel at nginx.org http://mailman.nginx.org/mailman/listinfo/nginx-devel -------------- next part -------------- An HTML attachment was scrubbed... URL: From sorin.v.manole at gmail.com Wed Apr 25 08:10:21 2018 From: sorin.v.manole at gmail.com (Sorin Manole) Date: Wed, 25 Apr 2018 11:10:21 +0300 Subject: IP_TRANSPARENT missing from glib Message-ID: Hello, On some systems the IP_TRANSPARENT feature is available, but the constant is not defined in glilb. Can you consider supporting this setup by defining the constant in nginx itself if missing from glib? https://unix.stackexchange.com/questions/58431/ip-transparent-missing-from-glibc-headers Thanks. From arut at nginx.com Wed Apr 25 11:01:24 2018 From: arut at nginx.com (Roman Arutyunyan) Date: Wed, 25 Apr 2018 14:01:24 +0300 Subject: IP_TRANSPARENT missing from glib In-Reply-To: References: Message-ID: <20180425110124.GF38831@Romans-MacBook-Air.local> Hi, On Wed, Apr 25, 2018 at 11:10:21AM +0300, Sorin Manole wrote: > Hello, > > On some systems the IP_TRANSPARENT feature is available, but the > constant is not defined in glilb. > Can you consider supporting this setup by defining the constant in > nginx itself if missing from glib? > > https://unix.stackexchange.com/questions/58431/ip-transparent-missing-from-glibc-headers If you want to build nginx on such a system, you can add the parameter '--with-cc-opt=-DIP_TRANSPARENT=19' when configuring nginx. -- Roman Arutyunyan From mdounin at mdounin.ru Wed Apr 25 11:59:09 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Wed, 25 Apr 2018 14:59:09 +0300 Subject: [PATCH] Contrib: vim syntax, update core and 3rd party module directives. In-Reply-To: References: Message-ID: <20180425115909.GP1606@mdounin.ru> Hello! On Tue, Apr 24, 2018 at 11:29:18AM +0300, Gena Makhomed wrote: > On 10.04.2018 20:47, Gena Makhomed wrote: > > > # HG changeset patch > > # User Gena Makhomed > > # Date 1523382230 -10800 > > #????? Tue Apr 10 20:43:50 2018 +0300 > > # Node ID 4049f2a9bc4e8de556f659769ea061f5b1b244e1 > > # Parent? 1ad1cdfe7409db7feec0d9c4f715d46175da1ca5 > > Contrib: vim syntax, update core and 3rd party module directives. > > Maxim, can you please review this patch? It might be a good idea to reduce frequency of such updates. -- Maxim Dounin http://mdounin.ru/ From ru at nginx.com Wed Apr 25 12:00:51 2018 From: ru at nginx.com (Ruslan Ermilov) Date: Wed, 25 Apr 2018 12:00:51 +0000 Subject: [nginx] SSL: deprecated the "ssl" directive. Message-ID: details: http://hg.nginx.org/nginx/rev/46c0c7ef4913 branches: changeset: 7270:46c0c7ef4913 user: Ruslan Ermilov date: Wed Apr 25 14:57:24 2018 +0300 description: SSL: deprecated the "ssl" directive. diffstat: src/http/modules/ngx_http_ssl_module.c | 7 ++++++- src/mail/ngx_mail_ssl_module.c | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diffs (48 lines): diff -r 7f955d3b9a0d -r 46c0c7ef4913 src/http/modules/ngx_http_ssl_module.c --- a/src/http/modules/ngx_http_ssl_module.c Tue Apr 24 15:29:01 2018 +0300 +++ b/src/http/modules/ngx_http_ssl_module.c Wed Apr 25 14:57:24 2018 +0300 @@ -71,6 +71,11 @@ static ngx_conf_enum_t ngx_http_ssl_ver }; +static ngx_conf_deprecated_t ngx_http_ssl_deprecated = { + ngx_conf_deprecated, "ssl", "listen ... ssl" +}; + + static ngx_command_t ngx_http_ssl_commands[] = { { ngx_string("ssl"), @@ -78,7 +83,7 @@ static ngx_command_t ngx_http_ssl_comma ngx_http_ssl_enable, NGX_HTTP_SRV_CONF_OFFSET, offsetof(ngx_http_ssl_srv_conf_t, enable), - NULL }, + &ngx_http_ssl_deprecated }, { ngx_string("ssl_certificate"), NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_TAKE1, diff -r 7f955d3b9a0d -r 46c0c7ef4913 src/mail/ngx_mail_ssl_module.c --- a/src/mail/ngx_mail_ssl_module.c Tue Apr 24 15:29:01 2018 +0300 +++ b/src/mail/ngx_mail_ssl_module.c Wed Apr 25 14:57:24 2018 +0300 @@ -56,6 +56,11 @@ static ngx_conf_enum_t ngx_mail_ssl_ver }; +static ngx_conf_deprecated_t ngx_mail_ssl_deprecated = { + ngx_conf_deprecated, "ssl", "listen ... ssl" +}; + + static ngx_command_t ngx_mail_ssl_commands[] = { { ngx_string("ssl"), @@ -63,7 +68,7 @@ static ngx_command_t ngx_mail_ssl_comma ngx_mail_ssl_enable, NGX_MAIL_SRV_CONF_OFFSET, offsetof(ngx_mail_ssl_conf_t, enable), - NULL }, + &ngx_mail_ssl_deprecated }, { ngx_string("starttls"), NGX_MAIL_MAIN_CONF|NGX_MAIL_SRV_CONF|NGX_CONF_TAKE1, From ansasaki at redhat.com Wed Apr 25 15:52:45 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Wed, 25 Apr 2018 11:52:45 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <880184530.22674327.1524671270225.JavaMail.zimbra@redhat.com> Message-ID: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1524670310 -7200 # Wed Apr 25 17:31:50 2018 +0200 # Node ID f916a804d526c1acb493c7c4e5c114d947e0eed1 # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 SSL: Add ENGINE_init() calls before using engines. It is necessary to call ENGINE_init() before using a OpenSSL engine to get the engine functional reference. diff -r 46c0c7ef4913 -r f916a804d526 src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/event/ngx_event_openssl.c Wed Apr 25 17:31:50 2018 +0200 @@ -527,27 +527,44 @@ return NGX_ERROR; } + if (!ENGINE_init(engine)) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "ENGINE_init(\"%s\") failed", p); + ENGINE_free(engine); + return NGX_ERROR; + } + *last++ = ':'; pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); if (pkey == NULL) { ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, - "ENGINE_load_private_key(\"%s\") failed", last); + "ENGINE_load_private_key(\"%s\", %s, %d, %d) failed", + p, last, 0, 0); ENGINE_free(engine); return NGX_ERROR; } - ENGINE_free(engine); + if (!ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS)) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "ENGINE_set_default(\"%s\", %s) failed", + p, "ENGINE_METHOD_PKEY_METHS"); + EVP_PKEY_free(pkey); + ENGINE_free(engine); + return NGX_ERROR; + } if (SSL_CTX_use_PrivateKey(ssl->ctx, pkey) == 0) { ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, - "SSL_CTX_use_PrivateKey(\"%s\") failed", last); + "SSL_CTX_use_PrivateKey() failed trying to use %s", + key->data); EVP_PKEY_free(pkey); return NGX_ERROR; } EVP_PKEY_free(pkey); + ENGINE_free(engine); return NGX_OK; @@ -4215,13 +4232,18 @@ return NGX_CONF_ERROR; } - if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { - ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, - "ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) failed", + if (!ENGINE_init(engine)) { + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, "ENGINE_init(\"%V\") failed", &value[1]); - ENGINE_free(engine); - + return NGX_CONF_ERROR; + } + + if (ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS) == 0) { + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, + "ENGINE_set_default(\"%V\", %s) failed", + &value[1], "ENGINE_METHOD_PKEY_METHS"); + ENGINE_free(engine); return NGX_CONF_ERROR; } From ansasaki at redhat.com Wed Apr 25 16:10:28 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Wed, 25 Apr 2018 12:10:28 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> Message-ID: <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> Hello, Following there is a test using the engine_pkcs11 [0] and softhsm [1]. The key is referenced in the device using PKCS#11 URI [2]. The test was based on an existing test, ssl_engine_keys.t [0] https://github.com/OpenSC/libp11 [1] https://github.com/opendnssec/SoftHSMv2 [2] https://tools.ietf.org/html/rfc7512 Best regards, Anderson # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1524668496 -7200 # Wed Apr 25 17:01:36 2018 +0200 # Node ID 84d417fa2dda58b027184ca3e34479e1aa7cbd9c # Parent d6daf03478adb5fe7523eab0b87c9372261422d7 Tests: Add a SSL test using PKCS#11 URI. The test run a nginx instance with ssl enabled using a PKCS#11 URI to reference a key from a device. diff -r d6daf03478ad -r 84d417fa2dda ssl_pkcs11_uri.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ssl_pkcs11_uri.t Wed Apr 25 17:01:36 2018 +0200 @@ -0,0 +1,172 @@ +#!/usr/bin/perl + +# (C) Sergey Kandaurov +# (C) Nginx, Inc. + +# Tests for http ssl module, loading "engine:pkcs11:" keys. + +############################################################################### + +use warnings; +use strict; + +use Test::More; + +BEGIN { use FindBin; chdir($FindBin::Bin); } + +use lib 'lib'; +use Test::Nginx; + +############################################################################### + +select STDERR; $| = 1; +select STDOUT; $| = 1; + +plan(skip_all => 'win32') if $^O eq 'MSWin32'; + +plan(skip_all => 'may not work, leaves coredump') + unless $ENV{TEST_NGINX_UNSAFE}; + +my $t = Test::Nginx->new()->has(qw/http proxy http_ssl/)->has_daemon('openssl') + ->has_daemon('softhsm2-util')->has_daemon('pkcs11-tool')->plan(1); + +$t->write_file_expand('nginx.conf', <<'EOF'); + +%%TEST_GLOBALS%% + +daemon off; + +events { +} + +http { + %%TEST_GLOBALS_HTTP%% + + server { + listen 127.0.0.1:8081 ssl; + listen 127.0.0.1:8080; + server_name localhost; + + ssl_certificate_key "engine:pkcs11:pkcs11:token=NginxZero;object=nx_key_0;type=private;pin-value=1234"; + ssl_certificate localhost.crt; + + location / { + # index index.html by default + } + location /proxy { + proxy_pass https://127.0.0.1:8081/; + } + } +} + +EOF + +# Create a OpenSSL configuration file +my $module_path = `find /usr -name *libsofthsm*.so 2>/dev/null | head -n 1 | \ + tr -d "\n"`; +my $dynamic_path = `find /usr -name *pkcs11*.so 2>/dev/null | grep engine | \ + head -n 1 | tr -d "\n"`; + +$t->write_file('openssl.conf', <testdir(); + +# Test if OpenSSL is already configured with the engine pkcs11 +# If not, create a local configuration +my $openssl_config; +eval "openssl engine -t pkcs11"; +if ($? == 0) { + $openssl_config = ""; +} else { + $openssl_config = "-config $d/openssl.conf"; +} + +# Configure SoftHSM to create a local database for the keys +$t->write_file('softhsm.conf', <>$d/openssl.out 2>&1") == 0 + or exit($?); + + system('pkcs11-tool --module=' + . "$module_path -p 1234 -l -k -d 0 -a nx_key_0 --key-type rsa:1024 " + . ">>$d/openssl.out 2>&1") == 0 + or exit($?); + + system('openssl req -x509 -new -engine pkcs11 ' + . "$openssl_config -subj \"/CN=$name\" " + . "-out $d/$name.crt -keyform engine " + . '-key "pkcs11:token=NginxZero;object=nx_key_0;type=private' + . ';pin-value=1234" ' + . ">>$d/openssl.out 2>&1") == 0 + or exit($?); +} + +$t->run(); + +$t->write_file('index.html', ''); + +############################################################################### + +like(http_get('/proxy', socket => get_ssl_socket()), qr/200 OK/, 'https'); + +############################################################################### +# +sub get_ssl_socket { + my $s; + + eval { + local $SIG{ALRM} = sub { die "timeout\n" }; + local $SIG{PIPE} = sub { die "sigpipe\n" }; + alarm(2); + $s = IO::Socket::SSL->new( + Proto => 'tcp', + PeerAddr => 'localhost:', + PeerPort => 8081, + SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE(), + SSL_error_trap => sub { die $_[1] } + ); + alarm(0); + }; + alarm(0); + + if ($@) { + log_in("died: $@"); + return undef; + } + + return $s; +} + +############################################################################### From pdn at cryptopro.ru Wed Apr 25 16:40:56 2018 From: pdn at cryptopro.ru (=?koi8-r?B?8Mne1czJziDkzcnU0snKIO7Jy8/MwcXXyd4=?=) Date: Wed, 25 Apr 2018 16:40:56 +0000 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com>, <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> Message-ID: <1524674456485.3120@cryptopro.ru> Typically engines initialize themselves in bind(), if not, they are initialized by openssl.cnf ("default_algorithms"), why use "init = 0" in your openssl config and rely this openssl engine stuff to nginx? From ansasaki at redhat.com Wed Apr 25 17:48:41 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Wed, 25 Apr 2018 13:48:41 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1524674456485.3120@cryptopro.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> Message-ID: <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> Hello, > Typically engines initialize themselves in bind(), if not, they are > initialized by openssl.cnf ("default_algorithms"), why use "init = 0" in > your openssl config and rely this openssl engine stuff to nginx? Following the OpenSSL documentation, the application is responsible for initializing the engines. Some engines, like the engine_pkcs11, rely on this and expects an explicit call to ENGINE_init(). The engines which initialize themselves, as far as I know, are actually doing a workaround to avoid the problem with non-compliant applications. In the specific case of engine_pkcs11, setting the "init" and "default_algorithms" in openssl.cnf do not initialize the engine. It would be interesting for nginx to follow the OpenSSL documentation and be compatible with more engines. For the specific case of the engine_pkcs11, it is interesting to support it because it allows using PKCS#11 URIs transparently. There were efforts in the past ([0], [1], [2]) to improve the support for PKCS#11 integration with nginx. [0] http://mailman.nginx.org/pipermail/nginx-devel/2014-November/006188.html [1] http://mailman.nginx.org/pipermail/nginx-devel/2015-April/006786.html [2] http://mailman.nginx.org/pipermail/nginx-devel/2015-June/007074.html Best regards, Anderson From pdn at cryptopro.ru Wed Apr 25 19:58:18 2018 From: pdn at cryptopro.ru (=?koi8-r?B?8Mne1czJziDkzcnU0snKIO7Jy8/MwcXXyd4=?=) Date: Wed, 25 Apr 2018 19:58:18 +0000 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru>, <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> Message-ID: <1524686298341.78540@cryptopro.ru> The original patch was tested on the same setup: http://mailman.nginx.org/pipermail/nginx-devel/2014-October/006151.html Do you insist that it does not work in the current state? From mdounin at mdounin.ru Thu Apr 26 13:32:08 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Thu, 26 Apr 2018 16:32:08 +0300 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> References: <880184530.22674327.1524671270225.JavaMail.zimbra@redhat.com> <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> Message-ID: <20180426133207.GT1606@mdounin.ru> Hello! On Wed, Apr 25, 2018 at 11:52:45AM -0400, Anderson Sasaki wrote: > # HG changeset patch > # User Anderson Toshiyuki Sasaki > # Date 1524670310 -7200 > # Wed Apr 25 17:31:50 2018 +0200 > # Node ID f916a804d526c1acb493c7c4e5c114d947e0eed1 > # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 > SSL: Add ENGINE_init() calls before using engines. > It is necessary to call ENGINE_init() before using a OpenSSL engine > to get the engine functional reference. > > diff -r 46c0c7ef4913 -r f916a804d526 src/event/ngx_event_openssl.c > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > +++ b/src/event/ngx_event_openssl.c Wed Apr 25 17:31:50 2018 +0200 > @@ -527,27 +527,44 @@ > return NGX_ERROR; > } > > + if (!ENGINE_init(engine)) { > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > + "ENGINE_init(\"%s\") failed", p); > + ENGINE_free(engine); > + return NGX_ERROR; > + } > + > *last++ = ':'; > > pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); > > if (pkey == NULL) { > ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > - "ENGINE_load_private_key(\"%s\") failed", last); > + "ENGINE_load_private_key(\"%s\", %s, %d, %d) failed", > + p, last, 0, 0); > ENGINE_free(engine); > return NGX_ERROR; > } > > - ENGINE_free(engine); > + if (!ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS)) { > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > + "ENGINE_set_default(\"%s\", %s) failed", > + p, "ENGINE_METHOD_PKEY_METHS"); > + EVP_PKEY_free(pkey); > + ENGINE_free(engine); > + return NGX_ERROR; > + } Apart from the ENGINE_init() discussion you are having with Dmirty, the patch seems to contain various unrelated changes, including logging changes and the ENGINE_set_default() call quoted above. If you really think these changes are needed, you may want to either submit these changes separately (or document why these changes should be in the ENGINE_init() patch in the commit log, if you really think these changes should be an integral part of the ENGINE_init() patch). [...] > @@ -4215,13 +4232,18 @@ > return NGX_CONF_ERROR; > } > > - if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { > - ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, > - "ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) failed", > + if (!ENGINE_init(engine)) { > + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, "ENGINE_init(\"%V\") failed", > &value[1]); > - > ENGINE_free(engine); > - > + return NGX_CONF_ERROR; > + } > + > + if (ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS) == 0) { > + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, > + "ENGINE_set_default(\"%V\", %s) failed", > + &value[1], "ENGINE_METHOD_PKEY_METHS"); > + ENGINE_free(engine); > return NGX_CONF_ERROR; > } Note well that the change in the ENGINE_set_default() arguments here seems to be simply wrong. -- Maxim Dounin http://mdounin.ru/ From xeioex at nginx.com Thu Apr 26 16:11:37 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 16:11:37 +0000 Subject: [njs] Adding const qualifiers to njs_number_dec_parse() and friends. Message-ID: details: http://hg.nginx.org/njs/rev/29eee021e03e branches: changeset: 503:29eee021e03e user: Dmitry Volyntsev date: Thu Apr 26 19:11:28 2018 +0300 description: Adding const qualifiers to njs_number_dec_parse() and friends. The functions which call njs_number_dec_parse() and friends are changed accordingly. diffstat: njs/njs_json.c | 90 ++++++++++++++++++++++++++++++------------------------- njs/njs_lexer.c | 9 +++- njs/njs_number.c | 37 ++++++++++++---------- njs/njs_number.h | 11 +++--- njs/njs_parser.c | 7 ++- njs/njs_string.c | 20 ++++++------ njs/njs_string.h | 6 +- 7 files changed, 98 insertions(+), 82 deletions(-) diffs (424 lines): diff -r 7f75ccba396e -r 29eee021e03e njs/njs_json.c --- a/njs/njs_json.c Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_json.c Thu Apr 26 19:11:28 2018 +0300 @@ -32,8 +32,8 @@ typedef struct { njs_vm_t *vm; nxt_mem_cache_pool_t *pool; nxt_uint_t depth; - u_char *start; - u_char *end; + const u_char *start; + const u_char *end; } njs_json_parse_ctx_t; @@ -110,18 +110,19 @@ typedef struct { } njs_json_stringify_t; -static u_char *njs_json_parse_value(njs_json_parse_ctx_t *ctx, - njs_value_t *value, u_char *p); -static u_char *njs_json_parse_object(njs_json_parse_ctx_t *ctx, - njs_value_t *value, u_char *p); -static u_char *njs_json_parse_array(njs_json_parse_ctx_t *ctx, - njs_value_t *value, u_char *p); -static u_char *njs_json_parse_string(njs_json_parse_ctx_t *ctx, - njs_value_t *value, u_char *p); -static u_char *njs_json_parse_number(njs_json_parse_ctx_t *ctx, - njs_value_t *value, u_char *p); +static const u_char *njs_json_parse_value(njs_json_parse_ctx_t *ctx, + njs_value_t *value, const u_char *p); +static const u_char *njs_json_parse_object(njs_json_parse_ctx_t *ctx, + njs_value_t *value, const u_char *p); +static const u_char *njs_json_parse_array(njs_json_parse_ctx_t *ctx, + njs_value_t *value, const u_char *p); +static const u_char *njs_json_parse_string(njs_json_parse_ctx_t *ctx, + njs_value_t *value, const u_char *p); +static const u_char *njs_json_parse_number(njs_json_parse_ctx_t *ctx, + njs_value_t *value, const u_char *p); nxt_inline uint32_t njs_json_unicode(const u_char *p); -static u_char *njs_json_skip_space(u_char *start, u_char *end); +static const u_char *njs_json_skip_space(const u_char *start, + const u_char *end); static njs_ret_t njs_json_parse_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); @@ -131,7 +132,7 @@ static njs_json_state_t *njs_json_push_p njs_json_parse_t *parse, njs_value_t *value); static njs_json_state_t *njs_json_pop_parse_state(njs_json_parse_t *parse); static void njs_json_parse_exception(njs_json_parse_ctx_t *ctx, - const char* msg, u_char *pos); + const char* msg, const u_char *pos); static njs_ret_t njs_json_stringify_continuation(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); @@ -179,8 +180,8 @@ static njs_ret_t njs_json_parse(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - u_char *p, *end; njs_value_t arg, *value, *wrapper; + const u_char *p, *end; njs_json_parse_t *parse; njs_string_prop_t string; njs_json_parse_ctx_t ctx; @@ -348,8 +349,9 @@ memory_error: } -static u_char * -njs_json_parse_value(njs_json_parse_ctx_t *ctx, njs_value_t *value, u_char *p) +static const u_char * +njs_json_parse_value(njs_json_parse_ctx_t *ctx, njs_value_t *value, + const u_char *p) { switch (*p) { case '{': @@ -401,8 +403,9 @@ error: } -static u_char * -njs_json_parse_object(njs_json_parse_ctx_t *ctx, njs_value_t *value, u_char *p) +static const u_char * +njs_json_parse_object(njs_json_parse_ctx_t *ctx, njs_value_t *value, + const u_char *p) { nxt_int_t ret; njs_object_t *object; @@ -533,8 +536,9 @@ memory_error: } -static u_char * -njs_json_parse_array(njs_json_parse_ctx_t *ctx, njs_value_t *value, u_char *p) +static const u_char * +njs_json_parse_array(njs_json_parse_ctx_t *ctx, njs_value_t *value, + const u_char *p) { nxt_int_t ret; njs_array_t *array; @@ -621,14 +625,16 @@ error_end: } -static u_char * -njs_json_parse_string(njs_json_parse_ctx_t *ctx, njs_value_t *value, u_char *p) +static const u_char * +njs_json_parse_string(njs_json_parse_ctx_t *ctx, njs_value_t *value, + const u_char *p) { - u_char *s, ch, *last, *start; - size_t size, surplus; - ssize_t length; - uint32_t utf, utf_low; - njs_ret_t ret; + u_char ch, *s, *dst; + size_t size, surplus; + ssize_t length; + uint32_t utf, utf_low; + njs_ret_t ret; + const u_char *start, *last; enum { sw_usual = 0, @@ -734,13 +740,13 @@ njs_json_parse_string(njs_json_parse_ctx if (surplus != 0) { p = start; - start = nxt_mem_cache_alloc(ctx->pool, size); + dst = nxt_mem_cache_alloc(ctx->pool, size); if (nxt_slow_path(start == NULL)) { njs_memory_error(ctx->vm);; return NULL; } - s = start; + s = dst; do { ch = *p++; @@ -811,7 +817,8 @@ njs_json_parse_string(njs_json_parse_ctx } while (p != last); - size = s - start; + size = s - dst; + start = dst; } length = nxt_utf8_length(start, size); @@ -819,7 +826,7 @@ njs_json_parse_string(njs_json_parse_ctx length = 0; } - ret = njs_string_create(ctx->vm, value, start, size, length); + ret = njs_string_create(ctx->vm, value, (u_char *) start, size, length); if (nxt_slow_path(ret != NXT_OK)) { njs_memory_error(ctx->vm); return NULL; @@ -829,12 +836,13 @@ njs_json_parse_string(njs_json_parse_ctx } -static u_char * -njs_json_parse_number(njs_json_parse_ctx_t *ctx, njs_value_t *value, u_char *p) +static const u_char * +njs_json_parse_number(njs_json_parse_ctx_t *ctx, njs_value_t *value, + const u_char *p) { - u_char *start; - double num; - nxt_int_t sign; + double num; + nxt_int_t sign; + const u_char *start; sign = 1; @@ -888,10 +896,10 @@ njs_json_unicode(const u_char *p) } -static u_char * -njs_json_skip_space(u_char *start, u_char *end) +static const u_char * +njs_json_skip_space(const u_char *start, const u_char *end) { - u_char *p; + const u_char *p; for (p = start; nxt_fast_path(p != end); p++) { @@ -1130,7 +1138,7 @@ njs_json_pop_parse_state(njs_json_parse_ static void njs_json_parse_exception(njs_json_parse_ctx_t *ctx, const char* msg, - u_char *pos) + const u_char *pos) { ssize_t length; diff -r 7f75ccba396e -r 29eee021e03e njs/njs_lexer.c --- a/njs/njs_lexer.c Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_lexer.c Thu Apr 26 19:11:28 2018 +0300 @@ -556,7 +556,8 @@ njs_lexer_number(njs_lexer_t *lexer) } lexer->start = p; - lexer->number = njs_number_hex_parse(&lexer->start, lexer->end); + lexer->number = njs_number_hex_parse((const u_char **) &lexer->start, + lexer->end); return NJS_TOKEN_NUMBER; } @@ -571,7 +572,8 @@ njs_lexer_number(njs_lexer_t *lexer) } lexer->start = p; - lexer->number = njs_number_oct_parse(&lexer->start, lexer->end); + lexer->number = njs_number_oct_parse((const u_char **) &lexer->start, + lexer->end); p = lexer->start; if (p < lexer->end && (*p == '8' || *p == '9')) { @@ -589,7 +591,8 @@ njs_lexer_number(njs_lexer_t *lexer) } lexer->start = p - 1; - lexer->number = njs_number_dec_parse(&lexer->start, lexer->end); + lexer->number = njs_number_dec_parse((const u_char **) &lexer->start, + lexer->end); return NJS_TOKEN_NUMBER; } diff -r 7f75ccba396e -r 29eee021e03e njs/njs_number.c --- a/njs/njs_number.c Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_number.c Thu Apr 26 19:11:28 2018 +0300 @@ -39,7 +39,7 @@ static njs_ret_t njs_number_to_string_ra uint32_t -njs_value_to_index(njs_value_t *value) +njs_value_to_index(const njs_value_t *value) { double num; njs_array_t *array; @@ -79,11 +79,12 @@ njs_value_to_index(njs_value_t *value) double -njs_number_dec_parse(u_char **start, u_char *end) +njs_number_dec_parse(const u_char **start, const u_char *end) { - u_char c, *e, *p; - double num, frac, scale, exponent; - nxt_bool_t minus; + u_char c; + double num, frac, scale, exponent; + nxt_bool_t minus; + const u_char *e, *p; p = *start; @@ -169,10 +170,11 @@ njs_number_dec_parse(u_char **start, u_c uint64_t -njs_number_oct_parse(u_char **start, u_char *end) +njs_number_oct_parse(const u_char **start, const u_char *end) { - u_char c, *p; - uint64_t num; + u_char c; + uint64_t num; + const u_char *p; p = *start; @@ -197,10 +199,11 @@ njs_number_oct_parse(u_char **start, u_c uint64_t -njs_number_hex_parse(u_char **start, u_char *end) +njs_number_hex_parse(const u_char **start, const u_char *end) { - u_char c, *p; - uint64_t num; + u_char c; + uint64_t num; + const u_char *p; p = *start; @@ -234,12 +237,12 @@ njs_number_hex_parse(u_char **start, u_c int64_t -njs_number_radix_parse(u_char **start, u_char *end, uint8_t radix) +njs_number_radix_parse(const u_char **start, const u_char *end, uint8_t radix) { - u_char *p; - uint8_t d; - int64_t num; - uint64_t n; + uint8_t d; + int64_t num; + uint64_t n; + const u_char *p; static const int8_t digits[256] nxt_aligned(32) = @@ -780,11 +783,11 @@ njs_number_parse_int(njs_vm_t *vm, njs_v njs_index_t unused) { double num; - u_char *p, *end; int64_t n; uint8_t radix; nxt_str_t string; nxt_bool_t minus, test_prefix; + const u_char *p, *end; num = NAN; diff -r 7f75ccba396e -r 29eee021e03e njs/njs_number.h --- a/njs/njs_number.h Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_number.h Thu Apr 26 19:11:28 2018 +0300 @@ -11,11 +11,12 @@ #include -uint32_t njs_value_to_index(njs_value_t *value); -double njs_number_dec_parse(u_char **start, u_char *end); -uint64_t njs_number_oct_parse(u_char **start, u_char *end); -uint64_t njs_number_hex_parse(u_char **start, u_char *end); -int64_t njs_number_radix_parse(u_char **start, u_char *end, uint8_t radix); +uint32_t njs_value_to_index(const njs_value_t *value); +double njs_number_dec_parse(const u_char **start, const u_char *end); +uint64_t njs_number_oct_parse(const u_char **start, const u_char *end); +uint64_t njs_number_hex_parse(const u_char **start, const u_char *end); +int64_t njs_number_radix_parse(const u_char **start, const u_char *end, + uint8_t radix); njs_ret_t njs_number_to_string(njs_vm_t *vm, njs_value_t *string, const njs_value_t *number); size_t njs_num_to_buf(double num, u_char *buf, size_t size); diff -r 7f75ccba396e -r 29eee021e03e njs/njs_parser.c --- a/njs/njs_parser.c Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_parser.c Thu Apr 26 19:11:28 2018 +0300 @@ -2379,9 +2379,10 @@ static njs_token_t njs_parser_escape_string_create(njs_vm_t *vm, njs_parser_t *parser, njs_value_t *value) { - u_char c, *p, *start, *dst, *src, *end, *hex_end; - size_t size, length, hex_length; - uint64_t u; + u_char c, *start, *dst; + size_t size,length, hex_length; + uint64_t u; + const u_char *p, *src, *end, *hex_end; start = NULL; dst = NULL; diff -r 7f75ccba396e -r 29eee021e03e njs/njs_string.c --- a/njs/njs_string.c Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_string.c Thu Apr 26 19:11:28 2018 +0300 @@ -3183,12 +3183,12 @@ njs_primitive_value_to_string(njs_vm_t * double -njs_string_to_number(njs_value_t *value, nxt_bool_t parse_float) +njs_string_to_number(const njs_value_t *value, nxt_bool_t parse_float) { - u_char *p, *start, *end; - double num; - size_t size; - nxt_bool_t minus; + double num; + size_t size; + nxt_bool_t minus; + const u_char *p, *start, *end; const size_t infinity = sizeof("Infinity") - 1; @@ -3265,11 +3265,11 @@ njs_string_to_number(njs_value_t *value, double -njs_string_to_index(njs_value_t *value) +njs_string_to_index(const njs_value_t *value) { - u_char *p, *end; - double num; - size_t size; + double num; + size_t size; + const u_char *p, *end; size = value->short_string.size; @@ -3305,7 +3305,7 @@ njs_string_to_index(njs_value_t *value) * is returned as is, otherwise the new copy is allocated with * the terminating zero byte. */ -u_char * +const u_char * njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value) { u_char *p, *data, *start; diff -r 7f75ccba396e -r 29eee021e03e njs/njs_string.h --- a/njs/njs_string.h Fri Apr 20 16:42:12 2018 +0300 +++ b/njs/njs_string.h Thu Apr 26 19:11:28 2018 +0300 @@ -147,9 +147,9 @@ nxt_noinline uint32_t njs_string_index(n void njs_string_offset_map_init(const u_char *start, size_t size); njs_ret_t njs_primitive_value_to_string(njs_vm_t *vm, njs_value_t *dst, const njs_value_t *src); -double njs_string_to_index(njs_value_t *value); -double njs_string_to_number(njs_value_t *value, nxt_bool_t parse_float); -u_char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value); +double njs_string_to_index(const njs_value_t *value); +double njs_string_to_number(const njs_value_t *value, nxt_bool_t parse_float); +const u_char *njs_string_to_c_string(njs_vm_t *vm, njs_value_t *value); njs_ret_t njs_string_encode_uri(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused); njs_ret_t njs_string_encode_uri_component(njs_vm_t *vm, njs_value_t *args, From xeioex at nginx.com Thu Apr 26 16:11:37 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 16:11:37 +0000 Subject: [njs] Fixed handling of undefined arguments of functions. Message-ID: details: http://hg.nginx.org/njs/rev/7e4b13d45b30 branches: changeset: 504:7e4b13d45b30 user: Dmitry Volyntsev date: Thu Apr 26 19:11:28 2018 +0300 description: Fixed handling of undefined arguments of functions. This fixes #7 issue on GitHub. diffstat: njs/njs_array.c | 4 +- njs/njs_function.h | 3 + njs/njs_object.c | 282 ++++++++++++++++++++++++++-------------------- njs/njs_object.h | 4 +- njs/test/njs_unit_test.c | 9 +- 5 files changed, 174 insertions(+), 128 deletions(-) diffs (707 lines): diff -r 29eee021e03e -r 7e4b13d45b30 njs/njs_array.c --- a/njs/njs_array.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_array.c Thu Apr 26 19:11:28 2018 +0300 @@ -1628,7 +1628,7 @@ njs_array_prototype_find_apply(njs_vm_t /* GC: array elt, array */ - value = (nargs > 2) ? &args[2] : &njs_value_void; + value = njs_arg(args, nargs, 2); arguments[0] = *value; n = iter->index; @@ -1847,7 +1847,7 @@ njs_array_iterator_apply(njs_vm_t *vm, n /* GC: array elt, array */ - value = (nargs > 2) ? &args[2] : &njs_value_void; + value = njs_arg(args, nargs, 2); arguments[0] = *value; n = iter->index; diff -r 29eee021e03e -r 7e4b13d45b30 njs/njs_function.h --- a/njs/njs_function.h Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_function.h Thu Apr 26 19:11:28 2018 +0300 @@ -40,6 +40,9 @@ struct njs_function_lambda_s { }; +#define njs_arg(args, nargs, n) \ + ((n < nargs) ? &(args)[n] : &njs_value_void) + /* The frame size must be aligned to njs_value_t. */ #define NJS_NATIVE_FRAME_SIZE \ nxt_align_size(sizeof(njs_native_frame_t), sizeof(njs_value_t)) diff -r 29eee021e03e -r 7e4b13d45b30 njs/njs_object.c --- a/njs/njs_object.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_object.c Thu Apr 26 19:11:28 2018 +0300 @@ -28,7 +28,7 @@ static nxt_int_t njs_object_hash_test(nxt_lvlhsh_query_t *lhq, void *data); static njs_ret_t njs_define_property(njs_vm_t *vm, njs_object_t *object, - njs_value_t *name, njs_object_t *descriptor); + const njs_value_t *name, const njs_object_t *descriptor); nxt_noinline njs_object_t * @@ -201,7 +201,8 @@ njs_object_prop_alloc(njs_vm_t *vm, cons nxt_noinline njs_object_prop_t * -njs_object_property(njs_vm_t *vm, njs_object_t *object, nxt_lvlhsh_query_t *lhq) +njs_object_property(njs_vm_t *vm, const njs_object_t *object, + nxt_lvlhsh_query_t *lhq) { nxt_int_t ret; @@ -232,13 +233,14 @@ njs_ret_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - nxt_uint_t type; - njs_value_t *value; - njs_object_t *object; + nxt_uint_t type; + njs_object_t *object; + const njs_value_t *value; type = NJS_OBJECT; + value = njs_arg(args, nargs, 1); - if (nargs == 1 || njs_is_null_or_void(&args[1])) { + if (njs_is_null_or_void(value)) { object = njs_object_alloc(vm); if (nxt_slow_path(object == NULL)) { @@ -246,7 +248,6 @@ njs_object_constructor(njs_vm_t *vm, njs } } else { - value = &args[1]; if (njs_is_object(value)) { object = value->data.u.object; @@ -283,34 +284,35 @@ static njs_ret_t njs_object_create(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - njs_object_t *object; + njs_object_t *object; + const njs_value_t *value; - if (nargs > 1) { + value = njs_arg(args, nargs, 1); - if (njs_is_object(&args[1]) || njs_is_null(&args[1])) { + if (njs_is_object(value) || njs_is_null(value)) { - object = njs_object_alloc(vm); - if (nxt_slow_path(object == NULL)) { - return NXT_ERROR; - } + object = njs_object_alloc(vm); + if (nxt_slow_path(object == NULL)) { + return NXT_ERROR; + } - if (!njs_is_null(&args[1])) { - /* GC */ - object->__proto__ = args[1].data.u.object; + if (!njs_is_null(value)) { + /* GC */ + object->__proto__ = value->data.u.object; - } else { - object->__proto__ = NULL; - } + } else { + object->__proto__ = NULL; + } - vm->retval.data.u.object = object; - vm->retval.type = NJS_OBJECT; - vm->retval.data.truth = 1; + vm->retval.data.u.object = object; + vm->retval.type = NJS_OBJECT; + vm->retval.data.truth = 1; - return NXT_OK; - } + return NXT_OK; } - njs_type_error(vm, "too few arguments", NULL); + njs_type_error(vm, "prototype may only be an object or null: %s", + njs_type_string(value->type)); return NXT_ERROR; } @@ -320,16 +322,19 @@ static njs_ret_t njs_object_keys(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - njs_array_t *keys; + njs_array_t *keys; + const njs_value_t *value; - if (nargs < 2 || !njs_is_object(&args[1])) { + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { njs_type_error(vm, "cannot convert %s argument to object", - (nargs >= 2) ? njs_type_string(args[1].type) : "null"); + njs_type_string(value->type)); return NXT_ERROR; } - keys = njs_object_keys_array(vm, &args[1]); + keys = njs_object_keys_array(vm, value); if (keys == NULL) { njs_memory_error(vm); return NXT_ERROR; @@ -343,7 +348,7 @@ njs_object_keys(njs_vm_t *vm, njs_value_ } njs_array_t* -njs_object_keys_array(njs_vm_t *vm, njs_value_t *object) +njs_object_keys_array(njs_vm_t *vm, const njs_value_t *object) { size_t size; uint32_t i, n, keys_length, array_length; @@ -427,33 +432,38 @@ njs_object_define_property(njs_vm_t *vm, njs_index_t unused) { nxt_int_t ret; - const char *type; + const njs_value_t *value, *name, *descriptor; + + value = njs_arg(args, nargs, 1); - if (nargs < 4 || !njs_is_object(&args[1]) || !njs_is_object(&args[3])) { - if (nargs < 2 || !njs_is_object(&args[1])) { - type = (nargs > 1) ? njs_type_string(args[1].type) : "null"; - njs_type_error(vm, "cannot convert %s argument to object", type); - - } else { - njs_type_error(vm, "descriptor is not an object", NULL); - } - + if (!njs_is_object(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); return NXT_ERROR; } - if (!args[1].data.u.object->extensible) { + if (!value->data.u.object->extensible) { njs_type_error(vm, "object is not extensible", NULL); return NXT_ERROR; } - ret = njs_define_property(vm, args[1].data.u.object, &args[2], - args[3].data.u.object); + descriptor = njs_arg(args, nargs, 3); + + if (!njs_is_object(descriptor)){ + njs_type_error(vm, "descriptor is not an object", NULL); + return NXT_ERROR; + } + + name = njs_arg(args, nargs, 2); + + ret = njs_define_property(vm, value->data.u.object, name, + descriptor->data.u.object); if (nxt_slow_path(ret != NXT_OK)) { return NXT_ERROR; } - vm->retval = args[1]; + vm->retval = *value; return NXT_OK; } @@ -464,33 +474,37 @@ njs_object_define_properties(njs_vm_t *v njs_index_t unused) { nxt_int_t ret; - const char *type; nxt_lvlhsh_t *hash; njs_object_t *object; nxt_lvlhsh_each_t lhe; njs_object_prop_t *prop; + const njs_value_t *value, *descriptor; - if (nargs < 3 || !njs_is_object(&args[1]) || !njs_is_object(&args[2])) { - if (nargs < 2 || !njs_is_object(&args[1])) { - type = (nargs > 1) ? njs_type_string(args[1].type) : "null"; - njs_type_error(vm, "cannot convert %s argument to object", type); + value = njs_arg(args, nargs, 1); - } else { - njs_type_error(vm, "descriptor is not an object", NULL); - } + if (!njs_is_object(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); return NXT_ERROR; } - if (!args[1].data.u.object->extensible) { + if (!value->data.u.object->extensible) { njs_type_error(vm, "object is not extensible", NULL); return NXT_ERROR; } + descriptor = njs_arg(args, nargs, 2); + + if (!njs_is_object(descriptor)) { + njs_type_error(vm, "descriptor is not an object", NULL); + return NXT_ERROR; + } + nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); - object = args[1].data.u.object; - hash = &args[2].data.u.object->hash; + object = value->data.u.object; + hash = &descriptor->data.u.object->hash; for ( ;; ) { prop = nxt_lvlhsh_each(hash, &lhe); @@ -509,15 +523,15 @@ njs_object_define_properties(njs_vm_t *v } } - vm->retval = args[1]; + vm->retval = *value; return NXT_OK; } static njs_ret_t -njs_define_property(njs_vm_t *vm, njs_object_t *object, njs_value_t *name, - njs_object_t *descriptor) +njs_define_property(njs_vm_t *vm, njs_object_t *object, const njs_value_t *name, + const njs_object_t *descriptor) { nxt_int_t ret; njs_object_prop_t *prop, *pr; @@ -606,29 +620,31 @@ njs_object_get_own_property_descriptor(n { uint32_t index; nxt_int_t ret; - const char *type; njs_array_t *array; njs_object_t *descriptor; njs_object_prop_t *pr, *prop, array_prop; - const njs_value_t *value; + const njs_value_t *value, *property, *setval; nxt_lvlhsh_query_t lhq; - if (nargs < 3 || !njs_is_object(&args[1])) { - type = (nargs > 1) ? njs_type_string(args[1].type) : "null"; - njs_type_error(vm, "cannot convert %s argument to object", type); + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); return NXT_ERROR; } prop = NULL; + property = njs_arg(args, nargs, 2); - if (njs_is_array(&args[1])) { - array = args[1].data.u.array; - index = njs_string_to_index(&args[2]); + if (njs_is_array(value)) { + array = value->data.u.array; + index = njs_string_to_index(property); if (index < array->length && njs_is_valid(&array->start[index])) { prop = &array_prop; - array_prop.name = args[2]; + array_prop.name = *property; array_prop.value = array->start[index]; array_prop.configurable = 1; @@ -640,10 +656,10 @@ njs_object_get_own_property_descriptor(n lhq.proto = &njs_object_hash_proto; if (prop == NULL) { - njs_string_get(&args[2], &lhq.key); + njs_string_get(property, &lhq.key); lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); - ret = nxt_lvlhsh_find(&args[1].data.u.object->hash, &lhq); + ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); if (ret != NXT_OK) { vm->retval = njs_string_void; @@ -679,9 +695,9 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("configurable"); lhq.key_hash = NJS_CONFIGURABLE_HASH; - value = (prop->configurable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->configurable == 1) ? &njs_string_true : &njs_string_false; - pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, value, 1); + pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { return NXT_ERROR; } @@ -696,9 +712,9 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("enumerable"); lhq.key_hash = NJS_ENUMERABLE_HASH; - value = (prop->enumerable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->enumerable == 1) ? &njs_string_true : &njs_string_false; - pr = njs_object_prop_alloc(vm, &njs_object_enumerable_string, value, 1); + pr = njs_object_prop_alloc(vm, &njs_object_enumerable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { return NXT_ERROR; } @@ -713,9 +729,9 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("writable"); lhq.key_hash = NJS_WRITABABLE_HASH; - value = (prop->writable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->writable == 1) ? &njs_string_true : &njs_string_false; - pr = njs_object_prop_alloc(vm, &njs_object_writable_string, value, 1); + pr = njs_object_prop_alloc(vm, &njs_object_writable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { return NXT_ERROR; } @@ -739,13 +755,19 @@ static njs_ret_t njs_object_get_prototype_of(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - if (nargs > 1 && njs_is_object(&args[1])) { - njs_object_prototype_get_proto(vm, &args[1], NULL, &vm->retval); + const njs_value_t *value; + + value = njs_arg(args, nargs, 1); + + if (njs_is_object(value)) { + njs_object_prototype_get_proto(vm, (njs_value_t *) value, NULL, + &vm->retval); return NXT_OK; } njs_type_error(vm, "cannot convert %s argument to object", - (nargs > 1) ? njs_type_string(args[1].type) : "null"); + njs_type_string(value->type)); + return NXT_ERROR; } @@ -758,13 +780,16 @@ njs_object_freeze(njs_vm_t *vm, njs_valu njs_object_t *object; njs_object_prop_t *prop; nxt_lvlhsh_each_t lhe; + const njs_value_t *value; - if (nargs < 2 || !njs_is_object(&args[1])) { + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { vm->retval = njs_value_void; return NXT_OK; } - object = args[1].data.u.object; + object = value->data.u.object; object->extensible = 0; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); @@ -782,7 +807,7 @@ njs_object_freeze(njs_vm_t *vm, njs_valu prop->configurable = 0; } - vm->retval = args[1]; + vm->retval = *value; return NXT_OK; } @@ -796,16 +821,18 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v njs_object_t *object; njs_object_prop_t *prop; nxt_lvlhsh_each_t lhe; - const njs_value_t *retval; + const njs_value_t *value, *retval; - if (nargs < 2 || !njs_is_object(&args[1])) { + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { vm->retval = njs_string_true; return NXT_OK; } retval = &njs_string_false; - object = args[1].data.u.object; + object = value->data.u.object; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); hash = &object->hash; @@ -842,17 +869,18 @@ njs_object_seal(njs_vm_t *vm, njs_value_ { nxt_lvlhsh_t *hash; njs_object_t *object; - const njs_value_t *retval; + const njs_value_t *value; njs_object_prop_t *prop; nxt_lvlhsh_each_t lhe; - if (nargs < 2 || !njs_is_object(&args[1])) { - retval = (nargs < 2) ? &njs_value_void : &args[1]; - vm->retval = *retval; + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { + vm->retval = *value; return NXT_OK; } - object = args[1].data.u.object; + object = value->data.u.object; object->extensible = 0; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); @@ -869,7 +897,7 @@ njs_object_seal(njs_vm_t *vm, njs_value_ prop->configurable = 0; } - vm->retval = args[1]; + vm->retval = *value; return NXT_OK; } @@ -883,16 +911,18 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v njs_object_t *object; njs_object_prop_t *prop; nxt_lvlhsh_each_t lhe; - const njs_value_t *retval; + const njs_value_t *value, *retval; - if (nargs < 2 || !njs_is_object(&args[1])) { + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { vm->retval = njs_string_true; return NXT_OK; } retval = &njs_string_false; - object = args[1].data.u.object; + object = value->data.u.object; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); hash = &object->hash; @@ -927,17 +957,18 @@ static njs_ret_t njs_object_prevent_extensions(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - const njs_value_t *retval; + const njs_value_t *value; - if (nargs < 2 || !njs_is_object(&args[1])) { - retval = (nargs < 2) ? &njs_value_void : &args[1]; - vm->retval = *retval; + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { + vm->retval = *value; return NXT_OK; } args[1].data.u.object->extensible = 0; - vm->retval = args[1]; + vm->retval = *value; return NXT_OK; } @@ -947,15 +978,17 @@ static njs_ret_t njs_object_is_extensible(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - const njs_value_t *retval; + const njs_value_t *value, *retval; - if (nargs < 2 || !njs_is_object(&args[1])) { + value = njs_arg(args, nargs, 1); + + if (!njs_is_object(value)) { vm->retval = njs_string_false; return NXT_OK; } - retval = args[1].data.u.object->extensible ? &njs_string_true - : &njs_string_false; + retval = value->data.u.object->extensible ? &njs_string_true + : &njs_string_false; vm->retval = *retval; @@ -1006,9 +1039,9 @@ njs_ret_t njs_object_prototype_create(njs_vm_t *vm, njs_value_t *value, njs_value_t *setval, njs_value_t *retval) { - int32_t index; - njs_value_t *proto; - njs_function_t *function; + int32_t index; + njs_function_t *function; + const njs_value_t *proto; proto = NULL; function = value->data.u.function; @@ -1020,7 +1053,7 @@ njs_object_prototype_create(njs_vm_t *vm } if (proto == NULL) { - proto = (njs_value_t *) &njs_value_void; + proto = &njs_value_void; } *retval = *proto; @@ -1372,6 +1405,7 @@ njs_object_prototype_to_string(njs_vm_t { int32_t index; njs_object_t *object; + const njs_value_t *value; njs_object_prototype_t *prototype; static const njs_value_t *class_name[] = { @@ -1414,10 +1448,11 @@ njs_object_prototype_to_string(njs_vm_t &njs_object_object_value_string, }; - index = args[0].type; + value = &args[0]; + index = value->type; - if (njs_is_object(&args[0])) { - object = args[0].data.u.object; + if (njs_is_object(value)) { + object = value->data.u.object; do { prototype = (njs_object_prototype_t *) object; @@ -1452,16 +1487,19 @@ njs_object_prototype_has_own_property(nj uint32_t index; nxt_int_t ret; njs_array_t *array; - const njs_value_t *retval; + const njs_value_t *value, *prop, *retval; nxt_lvlhsh_query_t lhq; retval = &njs_string_false; + value = &args[0]; - if (nargs > 1 && njs_is_object(&args[0])) { + if (njs_is_object(value)) { - if (njs_is_array(&args[0])) { - array = args[0].data.u.array; - index = njs_string_to_index(&args[1]); + prop = njs_arg(args, nargs, 1); + + if (njs_is_array(value)) { + array = value->data.u.array; + index = njs_string_to_index(prop); if (index < array->length && njs_is_valid(&array->start[index])) { retval = &njs_string_true; @@ -1469,11 +1507,11 @@ njs_object_prototype_has_own_property(nj } } - njs_string_get(&args[1], &lhq.key); + njs_string_get(prop, &lhq.key); lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); lhq.proto = &njs_object_hash_proto; - ret = nxt_lvlhsh_find(&args[0].data.u.object->hash, &lhq); + ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); if (ret == NXT_OK) { retval = &njs_string_true; @@ -1493,13 +1531,15 @@ njs_object_prototype_is_prototype_of(njs nxt_uint_t nargs, njs_index_t unused) { njs_object_t *object, *proto; - const njs_value_t *retval; + const njs_value_t *value, *obj, *retval; retval = &njs_string_false; + value = &args[0]; + obj = njs_arg(args, nargs, 1); - if (nargs > 1 && njs_is_object(&args[0]) && njs_is_object(&args[1])) { - proto = args[0].data.u.object; - object = args[1].data.u.object; + if (njs_is_object(value) && njs_is_object(obj)) { + proto = value->data.u.object; + object = obj->data.u.object; do { object = object->__proto__; diff -r 29eee021e03e -r 7e4b13d45b30 njs/njs_object.h --- a/njs/njs_object.h Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_object.h Thu Apr 26 19:11:28 2018 +0300 @@ -41,8 +41,8 @@ njs_object_t *njs_object_alloc(njs_vm_t njs_object_t *njs_object_value_copy(njs_vm_t *vm, njs_value_t *value); njs_object_t *njs_object_value_alloc(njs_vm_t *vm, const njs_value_t *value, nxt_uint_t type); -njs_array_t *njs_object_keys_array(njs_vm_t *vm, njs_value_t *object); -njs_object_prop_t *njs_object_property(njs_vm_t *vm, njs_object_t *obj, +njs_array_t *njs_object_keys_array(njs_vm_t *vm, const njs_value_t *object); +njs_object_prop_t *njs_object_property(njs_vm_t *vm, const njs_object_t *obj, nxt_lvlhsh_query_t *lhq); nxt_int_t njs_object_hash_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, const njs_object_prop_t *prop, nxt_uint_t n); diff -r 29eee021e03e -r 7e4b13d45b30 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 19:11:28 2018 +0300 @@ -6366,7 +6366,10 @@ static njs_unit_test_t njs_test[] = nxt_string("false") }, { nxt_string("Object.create()"), - nxt_string("TypeError: too few arguments") }, + nxt_string("TypeError: prototype may only be an object or null: void") }, + + { nxt_string("Object.create(1)"), + nxt_string("TypeError: prototype may only be an object or null: number") }, { nxt_string("var o = {a:1, b:2, c:3};" "Object.keys(o)"), @@ -6382,7 +6385,7 @@ static njs_unit_test_t njs_test[] = nxt_string("1,3,one") }, { nxt_string("Object.keys()"), - nxt_string("TypeError: cannot convert null argument to object") }, + nxt_string("TypeError: cannot convert void argument to object") }, { nxt_string("Object.keys('a')"), nxt_string("TypeError: cannot convert string argument to object") }, @@ -6443,7 +6446,7 @@ static njs_unit_test_t njs_test[] = nxt_string("2") }, { nxt_string("var o = {}; Object.defineProperty()"), - nxt_string("TypeError: cannot convert null argument to object") }, + nxt_string("TypeError: cannot convert void argument to object") }, { nxt_string("var o = {}; Object.defineProperty(o)"), nxt_string("TypeError: descriptor is not an object") }, From xeioex at nginx.com Thu Apr 26 16:11:38 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 16:11:38 +0000 Subject: [njs] Fixed return value type for boolean functions. Message-ID: details: http://hg.nginx.org/njs/rev/e7878051e75d branches: changeset: 505:e7878051e75d user: Dmitry Volyntsev date: Thu Apr 26 19:11:29 2018 +0300 description: Fixed return value type for boolean functions. Previously, the functions returned "true" and "false" strings. diffstat: njs/njs_array.c | 4 ++-- njs/njs_object.c | 34 +++++++++++++++++----------------- njs/test/njs_unit_test.c | 6 ++++++ 3 files changed, 25 insertions(+), 19 deletions(-) diffs (172 lines): diff -r 7e4b13d45b30 -r e7878051e75d njs/njs_array.c --- a/njs/njs_array.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_array.c Thu Apr 26 19:11:29 2018 +0300 @@ -295,10 +295,10 @@ njs_array_is_array(njs_vm_t *vm, njs_val const njs_value_t *value; if (nargs > 1 && njs_is_array(&args[1])) { - value = &njs_string_true; + value = &njs_value_true; } else { - value = &njs_string_false; + value = &njs_value_false; } vm->retval = *value; diff -r 7e4b13d45b30 -r e7878051e75d njs/njs_object.c --- a/njs/njs_object.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/njs_object.c Thu Apr 26 19:11:29 2018 +0300 @@ -695,7 +695,7 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("configurable"); lhq.key_hash = NJS_CONFIGURABLE_HASH; - setval = (prop->configurable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->configurable == 1) ? &njs_value_true : &njs_value_false; pr = njs_object_prop_alloc(vm, &njs_object_configurable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { @@ -712,7 +712,7 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("enumerable"); lhq.key_hash = NJS_ENUMERABLE_HASH; - setval = (prop->enumerable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->enumerable == 1) ? &njs_value_true : &njs_value_false; pr = njs_object_prop_alloc(vm, &njs_object_enumerable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { @@ -729,7 +729,7 @@ njs_object_get_own_property_descriptor(n lhq.key = nxt_string_value("writable"); lhq.key_hash = NJS_WRITABABLE_HASH; - setval = (prop->writable == 1) ? &njs_string_true : &njs_string_false; + setval = (prop->writable == 1) ? &njs_value_true : &njs_value_false; pr = njs_object_prop_alloc(vm, &njs_object_writable_string, setval, 1); if (nxt_slow_path(pr == NULL)) { @@ -826,11 +826,11 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v value = njs_arg(args, nargs, 1); if (!njs_is_object(value)) { - vm->retval = njs_string_true; + vm->retval = njs_value_true; return NXT_OK; } - retval = &njs_string_false; + retval = &njs_value_false; object = value->data.u.object; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); @@ -853,7 +853,7 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v } } - retval = &njs_string_true; + retval = &njs_value_true; done: @@ -916,11 +916,11 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v value = njs_arg(args, nargs, 1); if (!njs_is_object(value)) { - vm->retval = njs_string_true; + vm->retval = njs_value_true; return NXT_OK; } - retval = &njs_string_false; + retval = &njs_value_false; object = value->data.u.object; nxt_lvlhsh_each_init(&lhe, &njs_object_hash_proto); @@ -943,7 +943,7 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v } } - retval = &njs_string_true; + retval = &njs_value_true; done: @@ -983,12 +983,12 @@ njs_object_is_extensible(njs_vm_t *vm, n value = njs_arg(args, nargs, 1); if (!njs_is_object(value)) { - vm->retval = njs_string_false; + vm->retval = njs_value_false; return NXT_OK; } - retval = value->data.u.object->extensible ? &njs_string_true - : &njs_string_false; + retval = value->data.u.object->extensible ? &njs_value_true + : &njs_value_false; vm->retval = *retval; @@ -1490,7 +1490,7 @@ njs_object_prototype_has_own_property(nj const njs_value_t *value, *prop, *retval; nxt_lvlhsh_query_t lhq; - retval = &njs_string_false; + retval = &njs_value_false; value = &args[0]; if (njs_is_object(value)) { @@ -1502,7 +1502,7 @@ njs_object_prototype_has_own_property(nj index = njs_string_to_index(prop); if (index < array->length && njs_is_valid(&array->start[index])) { - retval = &njs_string_true; + retval = &njs_value_true; goto done; } } @@ -1514,7 +1514,7 @@ njs_object_prototype_has_own_property(nj ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); if (ret == NXT_OK) { - retval = &njs_string_true; + retval = &njs_value_true; } } @@ -1533,7 +1533,7 @@ njs_object_prototype_is_prototype_of(njs njs_object_t *object, *proto; const njs_value_t *value, *obj, *retval; - retval = &njs_string_false; + retval = &njs_value_false; value = &args[0]; obj = njs_arg(args, nargs, 1); @@ -1545,7 +1545,7 @@ njs_object_prototype_is_prototype_of(njs object = object->__proto__; if (object == proto) { - retval = &njs_string_true; + retval = &njs_value_true; break; } diff -r 7e4b13d45b30 -r e7878051e75d njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:11:28 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 19:11:29 2018 +0300 @@ -2852,9 +2852,15 @@ static njs_unit_test_t njs_test[] = { nxt_string("Array.isArray(1)"), nxt_string("false") }, + { nxt_string("Array.isArray(1) ? 'true' : 'false'"), + nxt_string("false") }, + { nxt_string("Array.isArray([])"), nxt_string("true") }, + { nxt_string("Array.isArray([]) ? 'true' : 'false'"), + nxt_string("true") }, + { nxt_string("Array.of()"), nxt_string("") }, From xeioex at nginx.com Thu Apr 26 16:21:46 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 16:21:46 +0000 Subject: [njs] Improved variable names in Object.isPrototypeOf(). Message-ID: details: http://hg.nginx.org/njs/rev/eb2caababd77 branches: changeset: 506:eb2caababd77 user: Dmitry Volyntsev date: Thu Apr 26 19:20:04 2018 +0300 description: Improved variable names in Object.isPrototypeOf(). diffstat: njs/njs_object.c | 12 ++++++------ 1 files changed, 6 insertions(+), 6 deletions(-) diffs (25 lines): diff -r e7878051e75d -r eb2caababd77 njs/njs_object.c --- a/njs/njs_object.c Thu Apr 26 19:11:29 2018 +0300 +++ b/njs/njs_object.c Thu Apr 26 19:20:04 2018 +0300 @@ -1531,15 +1531,15 @@ njs_object_prototype_is_prototype_of(njs nxt_uint_t nargs, njs_index_t unused) { njs_object_t *object, *proto; - const njs_value_t *value, *obj, *retval; + const njs_value_t *prototype, *value, *retval; retval = &njs_value_false; - value = &args[0]; - obj = njs_arg(args, nargs, 1); + prototype = &args[0]; + value = njs_arg(args, nargs, 1); - if (njs_is_object(value) && njs_is_object(obj)) { - proto = value->data.u.object; - object = obj->data.u.object; + if (njs_is_object(prototype) && njs_is_object(value)) { + proto = prototype->data.u.object; + object = value->data.u.object; do { object = object->__proto__; From ansasaki at redhat.com Thu Apr 26 16:37:33 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Thu, 26 Apr 2018 12:37:33 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1524686298341.78540@cryptopro.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> Message-ID: <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> Hello, > The original patch was tested on the same setup: > http://mailman.nginx.org/pipermail/nginx-devel/2014-October/006151.html > > Do you insist that it does not work in the current state? Yes, the problem is that the automatic initialization only take place for the default engines, which have to be configured through the configuration file. For the engines that are used ad-hoc, the ENGINE_init() have to be called explicitly. In my opinion it would be better to have nginx working with engines in both scenarios. And is not a problem to call ENGINE_init() from multiple places, since the API takes care of this case. From ansasaki at redhat.com Thu Apr 26 16:55:04 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Thu, 26 Apr 2018 12:55:04 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <20180426133207.GT1606@mdounin.ru> References: <880184530.22674327.1524671270225.JavaMail.zimbra@redhat.com> <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <20180426133207.GT1606@mdounin.ru> Message-ID: <1627320434.23013279.1524761704322.JavaMail.zimbra@redhat.com> Hello, Thank you for your feedback. > > # HG changeset patch > > # User Anderson Toshiyuki Sasaki > > # Date 1524670310 -7200 > > # Wed Apr 25 17:31:50 2018 +0200 > > # Node ID f916a804d526c1acb493c7c4e5c114d947e0eed1 > > # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 > > SSL: Add ENGINE_init() calls before using engines. > > It is necessary to call ENGINE_init() before using a OpenSSL engine > > to get the engine functional reference. > > > > diff -r 46c0c7ef4913 -r f916a804d526 src/event/ngx_event_openssl.c > > --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 > > +++ b/src/event/ngx_event_openssl.c Wed Apr 25 17:31:50 2018 +0200 > > @@ -527,27 +527,44 @@ > > return NGX_ERROR; > > } > > > > + if (!ENGINE_init(engine)) { > > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > > + "ENGINE_init(\"%s\") failed", p); > > + ENGINE_free(engine); > > + return NGX_ERROR; > > + } > > + > > *last++ = ':'; > > > > pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); > > > > if (pkey == NULL) { > > ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > > - "ENGINE_load_private_key(\"%s\") failed", last); > > + "ENGINE_load_private_key(\"%s\", %s, %d, %d) > > failed", > > + p, last, 0, 0); > > ENGINE_free(engine); > > return NGX_ERROR; > > } > > > > - ENGINE_free(engine); > > + if (!ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS)) { > > + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, > > + "ENGINE_set_default(\"%s\", %s) failed", > > + p, "ENGINE_METHOD_PKEY_METHS"); > > + EVP_PKEY_free(pkey); > > + ENGINE_free(engine); > > + return NGX_ERROR; > > + } > > Apart from the ENGINE_init() discussion you are having with > Dmirty, the patch seems to contain various unrelated changes, > including logging changes and the ENGINE_set_default() call quoted > above. I agree that I could avoid changing the log messages. I will remove theses changes from the patch. > > If you really think these changes are needed, you may want to > either submit these changes separately (or document why these > changes should be in the ENGINE_init() patch in the commit log, if > you really think these changes should be an integral part of the > ENGINE_init() patch). I will separate the changes in different patches. > > [...] > > > @@ -4215,13 +4232,18 @@ > > return NGX_CONF_ERROR; > > } > > > > - if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { > > - ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, > > - "ENGINE_set_default(\"%V\", ENGINE_METHOD_ALL) > > failed", > > + if (!ENGINE_init(engine)) { > > + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, "ENGINE_init(\"%V\") > > failed", > > &value[1]); > > - > > ENGINE_free(engine); > > - > > + return NGX_CONF_ERROR; > > + } > > + > > + if (ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS) == 0) { > > + ngx_ssl_error(NGX_LOG_EMERG, cf->log, 0, > > + "ENGINE_set_default(\"%V\", %s) failed", > > + &value[1], "ENGINE_METHOD_PKEY_METHS"); > > + ENGINE_free(engine); > > return NGX_CONF_ERROR; > > } > > Note well that the change in the ENGINE_set_default() arguments > here seems to be simply wrong. Here (and above in the other call to ENGINE_set_default()) I set the engine as the default choice only for private key operations. Otherwise any call to the OpenSSL API will be handled to the engine. This could be the intention or not. Anyway, I will separate these changes from the essential patch. Best Regards, Anderson From xeioex at nginx.com Thu Apr 26 17:36:53 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:53 +0000 Subject: [njs] Fixed handling of missing arg of Object.getOwnPropertyDescriptor(). Message-ID: details: http://hg.nginx.org/njs/rev/ee72fc2329bf branches: changeset: 507:ee72fc2329bf user: Dmitry Volyntsev date: Thu Apr 26 19:24:55 2018 +0300 description: Fixed handling of missing arg of Object.getOwnPropertyDescriptor(). This fixes #5 issue on GitHub. diffstat: njs/njs_object.c | 15 ++++++++++----- njs/test/njs_unit_test.c | 8 +++++++- 2 files changed, 17 insertions(+), 6 deletions(-) diffs (57 lines): diff -r eb2caababd77 -r ee72fc2329bf njs/njs_object.c --- a/njs/njs_object.c Thu Apr 26 19:20:04 2018 +0300 +++ b/njs/njs_object.c Thu Apr 26 19:24:55 2018 +0300 @@ -629,9 +629,14 @@ njs_object_get_own_property_descriptor(n value = njs_arg(args, nargs, 1); if (!njs_is_object(value)) { - njs_type_error(vm, "cannot convert %s argument to object", - njs_type_string(value->type)); - return NXT_ERROR; + if (njs_is_null_or_void(value)) { + njs_type_error(vm, "cannot convert %s argument to object", + njs_type_string(value->type)); + return NXT_ERROR; + } + + vm->retval = njs_value_void; + return NXT_OK; } prop = NULL; @@ -662,7 +667,7 @@ njs_object_get_own_property_descriptor(n ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); if (ret != NXT_OK) { - vm->retval = njs_string_void; + vm->retval = njs_value_void; return NXT_OK; } @@ -1164,7 +1169,7 @@ static const njs_object_prop_t njs_obje .type = NJS_METHOD, .name = njs_long_string("getOwnPropertyDescriptor"), .value = njs_native_function(njs_object_get_own_property_descriptor, 0, - NJS_SKIP_ARG, NJS_OBJECT_ARG, + NJS_SKIP_ARG, NJS_SKIP_ARG, NJS_STRING_ARG), }, diff -r eb2caababd77 -r ee72fc2329bf njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:20:04 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 19:24:55 2018 +0300 @@ -6603,7 +6603,13 @@ static njs_unit_test_t njs_test[] = nxt_string("undefined") }, { nxt_string("Object.getOwnPropertyDescriptor(1, '0')"), - nxt_string("TypeError: cannot convert number argument to object") }, + nxt_string("undefined") }, + + { nxt_string("Object.getOwnPropertyDescriptor()"), + nxt_string("TypeError: cannot convert void argument to object") }, + + { nxt_string("Object.getOwnPropertyDescriptor(undefined)"), + nxt_string("TypeError: cannot convert void argument to object") }, { nxt_string("Object.defineProperty(Object.freeze({}), 'b', {})"), nxt_string("TypeError: object is not extensible") }, From xeioex at nginx.com Thu Apr 26 17:36:53 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:53 +0000 Subject: [njs] Fixed handling of props in Object.getOwnPropertyDescriptor(). Message-ID: details: http://hg.nginx.org/njs/rev/cba7742a0a65 branches: changeset: 508:cba7742a0a65 user: Dmitry Volyntsev date: Thu Apr 26 19:53:16 2018 +0300 description: Fixed handling of props in Object.getOwnPropertyDescriptor(). njs_property_query() is moved to njs_object.c without changes. diffstat: njs/njs_object.c | 338 +++++++++++++++++++++++++++++++++++++++++++++- njs/njs_object.h | 16 ++ njs/njs_vm.c | 333 ---------------------------------------------- njs/njs_vm.h | 18 ++ njs/test/njs_unit_test.c | 9 + 5 files changed, 368 insertions(+), 346 deletions(-) diffs (843 lines): diff -r ee72fc2329bf -r cba7742a0a65 njs/njs_object.c --- a/njs/njs_object.c Thu Apr 26 19:24:55 2018 +0300 +++ b/njs/njs_object.c Thu Apr 26 19:53:16 2018 +0300 @@ -19,7 +19,9 @@ #include #include #include +#include #include +#include #include #include #include @@ -27,6 +29,12 @@ static nxt_int_t njs_object_hash_test(nxt_lvlhsh_query_t *lhq, void *data); +static njs_ret_t njs_object_property_query(njs_vm_t *vm, + njs_property_query_t *pq, njs_value_t *value, njs_object_t *object); +static njs_ret_t njs_array_property_query(njs_vm_t *vm, + njs_property_query_t *pq, njs_value_t *object, uint32_t index); +static njs_ret_t njs_object_query_prop_handler(njs_property_query_t *pq, + njs_object_t *object); static njs_ret_t njs_define_property(njs_vm_t *vm, njs_object_t *object, const njs_value_t *name, const njs_object_t *descriptor); @@ -229,6 +237,301 @@ njs_object_property(njs_vm_t *vm, const } +/* + * The njs_property_query() returns values + * NXT_OK property has been found in object, + * NXT_DECLINED property was not found in object, + * NJS_PRIMITIVE_VALUE property operation was applied to a numeric + * or boolean value, + * NJS_STRING_VALUE property operation was applied to a string, + * NJS_ARRAY_VALUE object is array, + * NJS_EXTERNAL_VALUE object is external entity, + * NJS_TRAP_PROPERTY the property trap must be called, + * NXT_ERROR exception has been thrown. + */ + +njs_ret_t +njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object, + njs_value_t *property) +{ + uint32_t index; + uint32_t (*hash)(const void *, size_t); + njs_ret_t ret; + njs_object_t *obj; + njs_function_t *function; + const njs_extern_t *ext_proto; + + hash = nxt_djb_hash; + + switch (object->type) { + + case NJS_BOOLEAN: + case NJS_NUMBER: + if (pq->query != NJS_PROPERTY_QUERY_GET) { + return NJS_PRIMITIVE_VALUE; + } + + index = njs_primitive_prototype_index(object->type); + obj = &vm->prototypes[index].object; + break; + + case NJS_STRING: + if (pq->query == NJS_PROPERTY_QUERY_DELETE) { + return NXT_DECLINED; + } + + obj = &vm->prototypes[NJS_PROTOTYPE_STRING].object; + break; + + case NJS_ARRAY: + if (nxt_fast_path(!njs_is_null_or_void_or_boolean(property))) { + + if (nxt_fast_path(njs_is_primitive(property))) { + index = njs_value_to_index(property); + + if (nxt_fast_path(index < NJS_ARRAY_MAX_LENGTH)) { + return njs_array_property_query(vm, pq, object, index); + } + + } else { + return NJS_TRAP_PROPERTY; + } + } + + /* Fall through. */ + + case NJS_OBJECT: + case NJS_OBJECT_BOOLEAN: + case NJS_OBJECT_NUMBER: + case NJS_OBJECT_STRING: + case NJS_REGEXP: + case NJS_DATE: + case NJS_OBJECT_ERROR: + case NJS_OBJECT_EVAL_ERROR: + case NJS_OBJECT_INTERNAL_ERROR: + case NJS_OBJECT_RANGE_ERROR: + case NJS_OBJECT_REF_ERROR: + case NJS_OBJECT_SYNTAX_ERROR: + case NJS_OBJECT_TYPE_ERROR: + case NJS_OBJECT_URI_ERROR: + case NJS_OBJECT_VALUE: + obj = object->data.u.object; + break; + + case NJS_FUNCTION: + function = njs_function_value_copy(vm, object); + if (nxt_slow_path(function == NULL)) { + return NXT_ERROR; + } + + obj = &function->object; + break; + + case NJS_EXTERNAL: + ext_proto = object->external.proto; + + if (ext_proto->type == NJS_EXTERN_CASELESS_OBJECT) { + hash = nxt_djb_hash_lowcase; + } + + obj = NULL; + break; + + case NJS_VOID: + case NJS_NULL: + default: + if (nxt_fast_path(njs_is_primitive(property))) { + + ret = njs_primitive_value_to_string(vm, &pq->value, property); + + if (nxt_fast_path(ret == NXT_OK)) { + njs_string_get(&pq->value, &pq->lhq.key); + njs_type_error(vm, "cannot get property '%.*s' of undefined", + (int) pq->lhq.key.length, pq->lhq.key.start); + return NXT_ERROR; + } + } + + njs_type_error(vm, "cannot get property 'unknown' of undefined", NULL); + + return NXT_ERROR; + } + + if (nxt_fast_path(njs_is_primitive(property))) { + + ret = njs_primitive_value_to_string(vm, &pq->value, property); + + if (nxt_fast_path(ret == NXT_OK)) { + + njs_string_get(&pq->value, &pq->lhq.key); + pq->lhq.key_hash = hash(pq->lhq.key.start, pq->lhq.key.length); + + if (obj == NULL) { + pq->lhq.proto = &njs_extern_hash_proto; + + return NJS_EXTERNAL_VALUE; + } + + return njs_object_property_query(vm, pq, object, obj); + } + + return ret; + } + + return NJS_TRAP_PROPERTY; +} + + +njs_ret_t +njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq, + njs_value_t *value, njs_object_t *object) +{ + njs_ret_t ret; + njs_object_prop_t *prop; + + pq->lhq.proto = &njs_object_hash_proto; + + if (pq->query == NJS_PROPERTY_QUERY_SET) { + ret = njs_object_query_prop_handler(pq, object); + if (ret == NXT_OK) { + return ret; + } + } + + do { + pq->prototype = object; + + ret = nxt_lvlhsh_find(&object->hash, &pq->lhq); + + if (ret == NXT_OK) { + prop = pq->lhq.value; + + if (prop->type != NJS_WHITEOUT) { + pq->shared = 0; + + return ret; + } + + goto next; + } + + if (pq->query > NJS_PROPERTY_QUERY_IN) { + /* NXT_DECLINED */ + return ret; + } + + ret = nxt_lvlhsh_find(&object->shared_hash, &pq->lhq); + + if (ret == NXT_OK) { + pq->shared = 1; + + if (pq->query == NJS_PROPERTY_QUERY_GET) { + prop = pq->lhq.value; + + if (prop->type == NJS_PROPERTY_HANDLER) { + pq->scratch = *prop; + prop = &pq->scratch; + ret = prop->value.data.u.prop_handler(vm, value, NULL, + &prop->value); + + if (nxt_fast_path(ret == NXT_OK)) { + prop->type = NJS_PROPERTY; + pq->lhq.value = prop; + } + } + } + + return ret; + } + + if (pq->query > NJS_PROPERTY_QUERY_IN) { + /* NXT_DECLINED */ + return ret; + } + + next: + + object = object->__proto__; + + } while (object != NULL); + + if (njs_is_string(value)) { + return NJS_STRING_VALUE; + } + + /* NXT_DECLINED */ + + return ret; +} + + +static njs_ret_t +njs_array_property_query(njs_vm_t *vm, njs_property_query_t *pq, + njs_value_t *object, uint32_t index) +{ + uint32_t size; + njs_ret_t ret; + njs_value_t *value; + njs_array_t *array; + + array = object->data.u.array; + + if (index >= array->length) { + if (pq->query != NJS_PROPERTY_QUERY_SET) { + return NXT_DECLINED; + } + + size = index - array->length; + + ret = njs_array_expand(vm, array, 0, size + 1); + if (nxt_slow_path(ret != NXT_OK)) { + return ret; + } + + value = &array->start[array->length]; + + while (size != 0) { + njs_set_invalid(value); + value++; + size--; + } + + array->length = index + 1; + } + + pq->lhq.value = &array->start[index]; + + return NJS_ARRAY_VALUE; +} + + +static njs_ret_t +njs_object_query_prop_handler(njs_property_query_t *pq, njs_object_t *object) +{ + njs_ret_t ret; + njs_object_prop_t *prop; + + do { + pq->prototype = object; + + ret = nxt_lvlhsh_find(&object->shared_hash, &pq->lhq); + + if (ret == NXT_OK) { + prop = pq->lhq.value; + + if (prop->type == NJS_PROPERTY_HANDLER) { + return NXT_OK; + } + } + + object = object->__proto__; + + } while (object != NULL); + + return NXT_DECLINED; +} + + njs_ret_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) @@ -618,13 +921,15 @@ static njs_ret_t njs_object_get_own_property_descriptor(njs_vm_t *vm, njs_value_t *args, nxt_uint_t nargs, njs_index_t unused) { - uint32_t index; - nxt_int_t ret; - njs_array_t *array; - njs_object_t *descriptor; - njs_object_prop_t *pr, *prop, array_prop; - const njs_value_t *value, *property, *setval; - nxt_lvlhsh_query_t lhq; + double num; + uint32_t index; + nxt_int_t ret; + njs_array_t *array; + njs_object_t *descriptor; + njs_object_prop_t *pr, *prop, array_prop; + const njs_value_t *value, *property, *setval; + nxt_lvlhsh_query_t lhq; + njs_property_query_t pq; value = njs_arg(args, nargs, 1); @@ -644,9 +949,13 @@ njs_object_get_own_property_descriptor(n if (njs_is_array(value)) { array = value->data.u.array; - index = njs_string_to_index(property); + num = njs_string_to_index(property); + index = num; - if (index < array->length && njs_is_valid(&array->start[index])) { + if ((double) index == num + && index < array->length + && njs_is_valid(&array->start[index])) + { prop = &array_prop; array_prop.name = *property; @@ -661,17 +970,19 @@ njs_object_get_own_property_descriptor(n lhq.proto = &njs_object_hash_proto; if (prop == NULL) { - njs_string_get(property, &lhq.key); - lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); + pq.query = NJS_PROPERTY_QUERY_GET; + pq.lhq.key.length = 0; + pq.lhq.key.start = NULL; - ret = nxt_lvlhsh_find(&value->data.u.object->hash, &lhq); + ret = njs_property_query(vm, &pq, (njs_value_t *) value, + (njs_value_t *) property); if (ret != NXT_OK) { vm->retval = njs_value_void; return NXT_OK; } - prop = lhq.value; + prop = pq.lhq.value; } descriptor = njs_object_alloc(vm); @@ -681,6 +992,7 @@ njs_object_get_own_property_descriptor(n lhq.replace = 0; lhq.pool = vm->mem_cache_pool; + lhq.proto = &njs_object_hash_proto; lhq.key = nxt_string_value("value"); lhq.key_hash = NJS_VALUE_HASH; diff -r ee72fc2329bf -r cba7742a0a65 njs/njs_object.h --- a/njs/njs_object.h Thu Apr 26 19:24:55 2018 +0300 +++ b/njs/njs_object.h Thu Apr 26 19:53:16 2018 +0300 @@ -30,6 +30,20 @@ typedef struct { } njs_object_prop_t; +typedef struct { + nxt_lvlhsh_query_t lhq; + + /* scratch is used to get the value of an NJS_PROPERTY_HANDLER property. */ + njs_object_prop_t scratch; + + njs_value_t value; + njs_object_t *prototype; + uint8_t query; + uint8_t shared; +} njs_property_query_t; + + + struct njs_object_init_s { nxt_str_t name; const njs_object_prop_t *properties; @@ -44,6 +58,8 @@ njs_object_t *njs_object_value_alloc(njs njs_array_t *njs_object_keys_array(njs_vm_t *vm, const njs_value_t *object); njs_object_prop_t *njs_object_property(njs_vm_t *vm, const njs_object_t *obj, nxt_lvlhsh_query_t *lhq); +njs_ret_t njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, + njs_value_t *object, njs_value_t *property); nxt_int_t njs_object_hash_create(njs_vm_t *vm, nxt_lvlhsh_t *hash, const njs_object_prop_t *prop, nxt_uint_t n); njs_ret_t njs_object_constructor(njs_vm_t *vm, njs_value_t *args, diff -r ee72fc2329bf -r cba7742a0a65 njs/njs_vm.c --- a/njs/njs_vm.c Thu Apr 26 19:24:55 2018 +0300 +++ b/njs/njs_vm.c Thu Apr 26 19:53:16 2018 +0300 @@ -33,36 +33,6 @@ #include -/* The values must be greater than NXT_OK. */ -#define NJS_PRIMITIVE_VALUE 1 -#define NJS_STRING_VALUE 2 -#define NJS_ARRAY_VALUE 3 -#define NJS_EXTERNAL_VALUE 4 - - -/* - * NJS_PROPERTY_QUERY_GET must be less or equal to NJS_PROPERTY_QUERY_IN, - * NJS_PROPERTY_QUERY_SET and NJS_PROPERTY_QUERY_DELETE must be greater - * than NJS_PROPERTY_QUERY_IN. - */ -#define NJS_PROPERTY_QUERY_GET 0 -#define NJS_PROPERTY_QUERY_IN 1 -#define NJS_PROPERTY_QUERY_SET 2 -#define NJS_PROPERTY_QUERY_DELETE 3 - - -typedef struct { - nxt_lvlhsh_query_t lhq; - - /* scratch is used to get the value of an NJS_PROPERTY_HANDLER property. */ - njs_object_prop_t scratch; - - njs_value_t value; - njs_object_t *prototype; - uint8_t query; - uint8_t shared; -} njs_property_query_t; - struct njs_property_next_s { int32_t index; @@ -76,14 +46,6 @@ struct njs_property_next_s { * and should fit in CPU L1 instruction cache. */ -static nxt_noinline njs_ret_t njs_property_query(njs_vm_t *vm, - njs_property_query_t *pq, njs_value_t *object, njs_value_t *property); -static njs_ret_t njs_array_property_query(njs_vm_t *vm, - njs_property_query_t *pq, njs_value_t *object, uint32_t index); -static njs_ret_t njs_object_property_query(njs_vm_t *vm, - njs_property_query_t *pq, njs_value_t *value, njs_object_t *object); -static njs_ret_t njs_object_query_prop_handler(njs_property_query_t *pq, - njs_object_t *object); static njs_ret_t njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq); static nxt_noinline njs_ret_t njs_values_equal(const njs_value_t *val1, @@ -972,301 +934,6 @@ njs_vmcode_property_delete(njs_vm_t *vm, } -/* - * The njs_property_query() returns values - * NXT_OK property has been found in object, - * NXT_DECLINED property was not found in object, - * NJS_PRIMITIVE_VALUE property operation was applied to a numeric - * or boolean value, - * NJS_STRING_VALUE property operation was applied to a string, - * NJS_ARRAY_VALUE object is array, - * NJS_EXTERNAL_VALUE object is external entity, - * NJS_TRAP_PROPERTY the property trap must be called, - * NXT_ERROR exception has been thrown. - */ - -static nxt_noinline njs_ret_t -njs_property_query(njs_vm_t *vm, njs_property_query_t *pq, njs_value_t *object, - njs_value_t *property) -{ - uint32_t index; - uint32_t (*hash)(const void *, size_t); - njs_ret_t ret; - njs_object_t *obj; - njs_function_t *function; - const njs_extern_t *ext_proto; - - hash = nxt_djb_hash; - - switch (object->type) { - - case NJS_BOOLEAN: - case NJS_NUMBER: - if (pq->query != NJS_PROPERTY_QUERY_GET) { - return NJS_PRIMITIVE_VALUE; - } - - index = njs_primitive_prototype_index(object->type); - obj = &vm->prototypes[index].object; - break; - - case NJS_STRING: - if (pq->query == NJS_PROPERTY_QUERY_DELETE) { - return NXT_DECLINED; - } - - obj = &vm->prototypes[NJS_PROTOTYPE_STRING].object; - break; - - case NJS_ARRAY: - if (nxt_fast_path(!njs_is_null_or_void_or_boolean(property))) { - - if (nxt_fast_path(njs_is_primitive(property))) { - index = njs_value_to_index(property); - - if (nxt_fast_path(index < NJS_ARRAY_MAX_LENGTH)) { - return njs_array_property_query(vm, pq, object, index); - } - - } else { - return NJS_TRAP_PROPERTY; - } - } - - /* Fall through. */ - - case NJS_OBJECT: - case NJS_OBJECT_BOOLEAN: - case NJS_OBJECT_NUMBER: - case NJS_OBJECT_STRING: - case NJS_REGEXP: - case NJS_DATE: - case NJS_OBJECT_ERROR: - case NJS_OBJECT_EVAL_ERROR: - case NJS_OBJECT_INTERNAL_ERROR: - case NJS_OBJECT_RANGE_ERROR: - case NJS_OBJECT_REF_ERROR: - case NJS_OBJECT_SYNTAX_ERROR: - case NJS_OBJECT_TYPE_ERROR: - case NJS_OBJECT_URI_ERROR: - case NJS_OBJECT_VALUE: - obj = object->data.u.object; - break; - - case NJS_FUNCTION: - function = njs_function_value_copy(vm, object); - if (nxt_slow_path(function == NULL)) { - return NXT_ERROR; - } - - obj = &function->object; - break; - - case NJS_EXTERNAL: - ext_proto = object->external.proto; - - if (ext_proto->type == NJS_EXTERN_CASELESS_OBJECT) { - hash = nxt_djb_hash_lowcase; - } - - obj = NULL; - break; - - case NJS_VOID: - case NJS_NULL: - default: - if (nxt_fast_path(njs_is_primitive(property))) { - - ret = njs_primitive_value_to_string(vm, &pq->value, property); - - if (nxt_fast_path(ret == NXT_OK)) { - njs_string_get(&pq->value, &pq->lhq.key); - njs_type_error(vm, "cannot get property '%.*s' of undefined", - (int) pq->lhq.key.length, pq->lhq.key.start); - return NXT_ERROR; - } - } - - njs_type_error(vm, "cannot get property 'unknown' of undefined", NULL); - - return NXT_ERROR; - } - - if (nxt_fast_path(njs_is_primitive(property))) { - - ret = njs_primitive_value_to_string(vm, &pq->value, property); - - if (nxt_fast_path(ret == NXT_OK)) { - - njs_string_get(&pq->value, &pq->lhq.key); - pq->lhq.key_hash = hash(pq->lhq.key.start, pq->lhq.key.length); - - if (obj == NULL) { - pq->lhq.proto = &njs_extern_hash_proto; - - return NJS_EXTERNAL_VALUE; - } - - return njs_object_property_query(vm, pq, object, obj); - } - - return ret; - } - - return NJS_TRAP_PROPERTY; -} - - -static njs_ret_t -njs_array_property_query(njs_vm_t *vm, njs_property_query_t *pq, - njs_value_t *object, uint32_t index) -{ - uint32_t size; - njs_ret_t ret; - njs_value_t *value; - njs_array_t *array; - - array = object->data.u.array; - - if (index >= array->length) { - if (pq->query != NJS_PROPERTY_QUERY_SET) { - return NXT_DECLINED; - } - - size = index - array->length; - - ret = njs_array_expand(vm, array, 0, size + 1); - if (nxt_slow_path(ret != NXT_OK)) { - return ret; - } - - value = &array->start[array->length]; - - while (size != 0) { - njs_set_invalid(value); - value++; - size--; - } - - array->length = index + 1; - } - - pq->lhq.value = &array->start[index]; - - return NJS_ARRAY_VALUE; -} - - -static njs_ret_t -njs_object_property_query(njs_vm_t *vm, njs_property_query_t *pq, - njs_value_t *value, njs_object_t *object) -{ - njs_ret_t ret; - njs_object_prop_t *prop; - - pq->lhq.proto = &njs_object_hash_proto; - - if (pq->query == NJS_PROPERTY_QUERY_SET) { - ret = njs_object_query_prop_handler(pq, object); - if (ret == NXT_OK) { - return ret; - } - } - - do { - pq->prototype = object; - - ret = nxt_lvlhsh_find(&object->hash, &pq->lhq); - - if (ret == NXT_OK) { - prop = pq->lhq.value; - - if (prop->type != NJS_WHITEOUT) { - pq->shared = 0; - - return ret; - } - - goto next; - } - - if (pq->query > NJS_PROPERTY_QUERY_IN) { - /* NXT_DECLINED */ - return ret; - } - - ret = nxt_lvlhsh_find(&object->shared_hash, &pq->lhq); - - if (ret == NXT_OK) { - pq->shared = 1; - - if (pq->query == NJS_PROPERTY_QUERY_GET) { - prop = pq->lhq.value; - - if (prop->type == NJS_PROPERTY_HANDLER) { - pq->scratch = *prop; - prop = &pq->scratch; - ret = prop->value.data.u.prop_handler(vm, value, NULL, - &prop->value); - - if (nxt_fast_path(ret == NXT_OK)) { - prop->type = NJS_PROPERTY; - pq->lhq.value = prop; - } - } - } - - return ret; - } - - if (pq->query > NJS_PROPERTY_QUERY_IN) { - /* NXT_DECLINED */ - return ret; - } - - next: - - object = object->__proto__; - - } while (object != NULL); - - if (njs_is_string(value)) { - return NJS_STRING_VALUE; - } - - /* NXT_DECLINED */ - - return ret; -} - - -static njs_ret_t -njs_object_query_prop_handler(njs_property_query_t *pq, njs_object_t *object) -{ - njs_ret_t ret; - njs_object_prop_t *prop; - - do { - pq->prototype = object; - - ret = nxt_lvlhsh_find(&object->shared_hash, &pq->lhq); - - if (ret == NXT_OK) { - prop = pq->lhq.value; - - if (prop->type == NJS_PROPERTY_HANDLER) { - return NXT_OK; - } - } - - object = object->__proto__; - - } while (object != NULL); - - return NXT_DECLINED; -} - - static njs_ret_t njs_method_private_copy(njs_vm_t *vm, njs_property_query_t *pq) { diff -r ee72fc2329bf -r cba7742a0a65 njs/njs_vm.h --- a/njs/njs_vm.h Thu Apr 26 19:24:55 2018 +0300 +++ b/njs/njs_vm.h Thu Apr 26 19:53:16 2018 +0300 @@ -49,6 +49,24 @@ #define NJS_APPLIED NXT_DONE +/* The values must be greater than NXT_OK. */ +#define NJS_PRIMITIVE_VALUE 1 +#define NJS_STRING_VALUE 2 +#define NJS_ARRAY_VALUE 3 +#define NJS_EXTERNAL_VALUE 4 + + +/* + * NJS_PROPERTY_QUERY_GET must be less or equal to NJS_PROPERTY_QUERY_IN, + * NJS_PROPERTY_QUERY_SET and NJS_PROPERTY_QUERY_DELETE must be greater + * than NJS_PROPERTY_QUERY_IN. + */ +#define NJS_PROPERTY_QUERY_GET 0 +#define NJS_PROPERTY_QUERY_IN 1 +#define NJS_PROPERTY_QUERY_SET 2 +#define NJS_PROPERTY_QUERY_DELETE 3 + + /* * The order of the enum is used in njs_vmcode_typeof() * and njs_object_prototype_to_string(). diff -r ee72fc2329bf -r cba7742a0a65 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:24:55 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 19:53:16 2018 +0300 @@ -6596,6 +6596,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.getOwnPropertyDescriptor([3,4], 1).value"), nxt_string("4") }, + { nxt_string("Object.getOwnPropertyDescriptor([], 'length').value"), + nxt_string("0") }, + { nxt_string("Object.getOwnPropertyDescriptor([3,4], '3')"), nxt_string("undefined") }, @@ -6611,6 +6614,12 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.getOwnPropertyDescriptor(undefined)"), nxt_string("TypeError: cannot convert void argument to object") }, + { nxt_string("var o = {}; o[void 0] = 'a'; Object.getOwnPropertyDescriptor(o).value"), + nxt_string("a") }, + + { nxt_string("var o = {}; o[void 0] = 'a'; Object.getOwnPropertyDescriptor(o, undefined).value"), + nxt_string("a") }, + { nxt_string("Object.defineProperty(Object.freeze({}), 'b', {})"), nxt_string("TypeError: object is not extensible") }, From xeioex at nginx.com Thu Apr 26 17:36:53 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:53 +0000 Subject: [njs] Fixed the writeable flag of Array.length property. Message-ID: details: http://hg.nginx.org/njs/rev/1305b1701099 branches: changeset: 509:1305b1701099 user: Dmitry Volyntsev date: Thu Apr 26 19:58:26 2018 +0300 description: Fixed the writeable flag of Array.length property. This fixes #6 issue on GitHub. diffstat: njs/njs_array.c | 1 + njs/test/njs_unit_test.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-) diffs (24 lines): diff -r cba7742a0a65 -r 1305b1701099 njs/njs_array.c --- a/njs/njs_array.c Thu Apr 26 19:53:16 2018 +0300 +++ b/njs/njs_array.c Thu Apr 26 19:58:26 2018 +0300 @@ -2097,6 +2097,7 @@ static const njs_object_prop_t njs_arra .type = NJS_PROPERTY_HANDLER, .name = njs_string("length"), .value = njs_prop_handler(njs_array_prototype_length), + .writable = 1 }, { diff -r cba7742a0a65 -r 1305b1701099 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:53:16 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 19:58:26 2018 +0300 @@ -6599,6 +6599,9 @@ static njs_unit_test_t njs_test[] = { nxt_string("Object.getOwnPropertyDescriptor([], 'length').value"), nxt_string("0") }, + { nxt_string("JSON.stringify(Object.getOwnPropertyDescriptor([3,4], 'length'))"), + nxt_string("{\"value\":2,\"configurable\":false,\"enumerable\":false,\"writable\":true}") }, + { nxt_string("Object.getOwnPropertyDescriptor([3,4], '3')"), nxt_string("undefined") }, From xeioex at nginx.com Thu Apr 26 17:36:54 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:54 +0000 Subject: [njs] Fixed unit tests exit code. Message-ID: details: http://hg.nginx.org/njs/rev/4e647f0bf155 branches: changeset: 510:4e647f0bf155 user: Dmitry Volyntsev date: Thu Apr 26 20:21:44 2018 +0300 description: Fixed unit tests exit code. Previously, 0 was returned regardless of failures. diffstat: njs/test/njs_unit_test.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r 1305b1701099 -r 4e647f0bf155 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 19:58:26 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 20:21:44 2018 +0300 @@ -9878,7 +9878,7 @@ done: printf("njs unit tests passed\n"); } - return NXT_OK; + return rc; } From xeioex at nginx.com Thu Apr 26 17:36:54 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:54 +0000 Subject: [njs] Fixed return value type of clearTimeout(). Message-ID: details: http://hg.nginx.org/njs/rev/5776906c23da branches: changeset: 511:5776906c23da user: Dmitry Volyntsev date: Thu Apr 26 20:21:46 2018 +0300 description: Fixed return value type of clearTimeout(). Previously, the function may return the "undefined" string. diffstat: njs/njs_time.c | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diffs (21 lines): diff -r 4e647f0bf155 -r 5776906c23da njs/njs_time.c --- a/njs/njs_time.c Thu Apr 26 20:21:44 2018 +0300 +++ b/njs/njs_time.c Thu Apr 26 20:21:46 2018 +0300 @@ -103,7 +103,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu nxt_lvlhsh_query_t lhq; if (nxt_fast_path(nargs < 2) || !njs_is_number(&args[1])) { - vm->retval = njs_string_void; + vm->retval = njs_value_void; return NJS_OK; } @@ -120,7 +120,7 @@ njs_clear_timeout(njs_vm_t *vm, njs_valu njs_del_event(vm, event, NJS_EVENT_RELEASE | NJS_EVENT_DELETE); } - vm->retval = njs_string_void; + vm->retval = njs_value_void; return NJS_OK; } From xeioex at nginx.com Thu Apr 26 17:36:55 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Thu, 26 Apr 2018 17:36:55 +0000 Subject: [njs] Fixed njs_vm_external_bind(). Message-ID: details: http://hg.nginx.org/njs/rev/ea220019d249 branches: changeset: 512:ea220019d249 user: Dmitry Volyntsev date: Thu Apr 26 20:22:04 2018 +0300 description: Fixed njs_vm_external_bind(). Previously, it could result in misaligned values being returned. diffstat: njs/njs_builtin.c | 2 +- njs/njs_extern.c | 7 ++++--- njs/njs_extern.h | 2 +- njs/test/njs_unit_test.c | 16 ++++++---------- 4 files changed, 12 insertions(+), 15 deletions(-) diffs (106 lines): diff -r 5776906c23da -r ea220019d249 njs/njs_builtin.c --- a/njs/njs_builtin.c Thu Apr 26 20:21:46 2018 +0300 +++ b/njs/njs_builtin.c Thu Apr 26 20:22:04 2018 +0300 @@ -675,7 +675,7 @@ njs_builtin_completions(njs_vm_t *vm, si break; } - ext_proto = ev->value->external.proto; + ext_proto = ev->value.external.proto; nxt_lvlhsh_each_init(&lhe_prop, &njs_extern_hash_proto); diff -r 5776906c23da -r ea220019d249 njs/njs_extern.c --- a/njs/njs_extern.c Thu Apr 26 20:21:46 2018 +0300 +++ b/njs/njs_extern.c Thu Apr 26 20:22:04 2018 +0300 @@ -210,13 +210,14 @@ njs_vm_external_bind(njs_vm_t *vm, const return NXT_ERROR; } - ev = nxt_mem_cache_alloc(vm->mem_cache_pool, sizeof(njs_extern_value_t)); + ev = nxt_mem_cache_align(vm->mem_cache_pool, sizeof(njs_value_t), + sizeof(njs_extern_value_t)); if (nxt_slow_path(ev == NULL)) { return NXT_ERROR; } + ev->value = *value; ev->name = *var_name; - ev->value = value; lhq.key = *var_name; lhq.key_hash = nxt_djb_hash(lhq.key.start, lhq.key.length); @@ -246,7 +247,7 @@ njs_parser_external(njs_vm_t *vm, njs_pa if (nxt_lvlhsh_find(&vm->externals_hash, &lhq) == NXT_OK) { ev = (njs_extern_value_t *) lhq.value; - return ev->value; + return &ev->value; } return NULL; diff -r 5776906c23da -r ea220019d249 njs/njs_extern.h --- a/njs/njs_extern.h Thu Apr 26 20:21:46 2018 +0300 +++ b/njs/njs_extern.h Thu Apr 26 20:22:04 2018 +0300 @@ -33,8 +33,8 @@ struct njs_extern_s { typedef struct { + njs_value_t value; nxt_str_t name; - njs_value_t *value; } njs_extern_value_t; diff -r 5776906c23da -r ea220019d249 njs/test/njs_unit_test.c --- a/njs/test/njs_unit_test.c Thu Apr 26 20:21:46 2018 +0300 +++ b/njs/test/njs_unit_test.c Thu Apr 26 20:22:04 2018 +0300 @@ -9384,6 +9384,8 @@ typedef struct { uint32_t a; nxt_mem_cache_pool_t *mem_cache_pool; const njs_extern_t *proto; + + njs_opaque_value_t value; } njs_unit_test_req_t; @@ -9719,7 +9721,6 @@ njs_externals_init(njs_vm_t *vm) nxt_int_t ret; nxt_uint_t i; const njs_extern_t *proto; - njs_opaque_value_t *values; njs_unit_test_req_t *requests; proto = njs_vm_external_prototype(vm, &nxt_test_external[0]); @@ -9728,13 +9729,6 @@ njs_externals_init(njs_vm_t *vm) return NXT_ERROR; } - values = nxt_mem_cache_zalloc(vm->mem_cache_pool, - nxt_nitems(nxt_test_requests) - * sizeof(njs_opaque_value_t)); - if (values == NULL) { - return NXT_ERROR; - } - requests = nxt_mem_cache_zalloc(vm->mem_cache_pool, nxt_nitems(nxt_test_requests) * sizeof(njs_unit_test_req_t)); @@ -9748,13 +9742,15 @@ njs_externals_init(njs_vm_t *vm) requests[i].mem_cache_pool = vm->mem_cache_pool; requests[i].proto = proto; - ret = njs_vm_external_create(vm, &values[i], proto, &requests[i]); + ret = njs_vm_external_create(vm, &requests[i].value, proto, + &requests[i]); if (ret != NXT_OK) { printf("njs_vm_external_create() failed\n"); return NXT_ERROR; } - ret = njs_vm_external_bind(vm, &nxt_test_requests[i].name, &values[i]); + ret = njs_vm_external_bind(vm, &nxt_test_requests[i].name, + &requests[i].value); if (ret != NXT_OK) { printf("njs_vm_external_bind() failed\n"); return NXT_ERROR; From pdn at cryptopro.ru Thu Apr 26 19:31:37 2018 From: pdn at cryptopro.ru (=?koi8-r?B?8Mne1czJziDkzcnU0snKIO7Jy8/MwcXXyd4=?=) Date: Thu, 26 Apr 2018 19:31:37 +0000 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru>, <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> Message-ID: <1524771096966.89645@cryptopro.ru> > In my opinion it would be better to have nginx working with engines in both scenarios. > And is not a problem to call ENGINE_init() from multiple places, since the API takes care of this case. I'll check these statements in your next patch, but for now it seems an odd functionality to me, because we have openssl config and even nginx ssl_engine directive for that. From xeioex at nginx.com Fri Apr 27 11:20:54 2018 From: xeioex at nginx.com (Dmitry Volyntsev) Date: Fri, 27 Apr 2018 11:20:54 +0000 Subject: [njs] Fixed incorrect pointer check in njs_json_parse_string(). Message-ID: details: http://hg.nginx.org/njs/rev/809a919a2f5a branches: changeset: 513:809a919a2f5a user: Dmitry Volyntsev date: Fri Apr 27 14:19:45 2018 +0300 description: Fixed incorrect pointer check in njs_json_parse_string(). Found by Coverity (CID 1435161, 1435162). The bug appeared in 29eee021e03e. diffstat: njs/njs_json.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diffs (12 lines): diff -r ea220019d249 -r 809a919a2f5a njs/njs_json.c --- a/njs/njs_json.c Thu Apr 26 20:22:04 2018 +0300 +++ b/njs/njs_json.c Fri Apr 27 14:19:45 2018 +0300 @@ -741,7 +741,7 @@ njs_json_parse_string(njs_json_parse_ctx p = start; dst = nxt_mem_cache_alloc(ctx->pool, size); - if (nxt_slow_path(start == NULL)) { + if (nxt_slow_path(dst == NULL)) { njs_memory_error(ctx->vm);; return NULL; } From mdounin at mdounin.ru Fri Apr 27 13:40:17 2018 From: mdounin at mdounin.ru (Maxim Dounin) Date: Fri, 27 Apr 2018 16:40:17 +0300 Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <1524771096966.89645@cryptopro.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> Message-ID: <20180427134017.GB32137@mdounin.ru> Hello! On Thu, Apr 26, 2018 at 07:31:37PM +0000, ??????? ??????? ?????????? wrote: > > In my opinion it would be better to have nginx working with engines in both scenarios. > > And is not a problem to call ENGINE_init() from multiple places, since the API takes care of this case. > > I'll check these statements in your next patch, but for now it > seems an odd functionality to me, because we have openssl config > and even nginx ssl_engine directive for that. Note that the "ssl_engine" directive is not to initialize engines, but rather to register an engine as the default one for operations it supports. It is designed to make it possible to work with various SSL accelerators. -- Maxim Dounin http://mdounin.ru/ From ansasaki at redhat.com Fri Apr 27 15:27:57 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Fri, 27 Apr 2018 11:27:57 -0400 (EDT) Subject: [PATCH] SSL: Add ENGINE_init() calls before using engines. In-Reply-To: <20180427134017.GB32137@mdounin.ru> References: <1302749118.22675127.1524671565091.JavaMail.zimbra@redhat.com> <767709022.22685028.1524672628427.JavaMail.zimbra@redhat.com> <1524674456485.3120@cryptopro.ru> <1609950830.22732156.1524678521554.JavaMail.zimbra@redhat.com> <1524686298341.78540@cryptopro.ru> <290808958.23009513.1524760653461.JavaMail.zimbra@redhat.com> <1524771096966.89645@cryptopro.ru> <20180427134017.GB32137@mdounin.ru> Message-ID: <1115169087.23375772.1524842877109.JavaMail.zimbra@redhat.com> Hello, > > > In my opinion it would be better to have nginx working with engines in > > > both scenarios. > > > And is not a problem to call ENGINE_init() from multiple places, since > > > the API takes care of this case. > > > > I'll check these statements in your next patch, but for now it > > seems an odd functionality to me, because we have openssl config > > and even nginx ssl_engine directive for that. > > Note that the "ssl_engine" directive is not to initialize engines, > but rather to register an engine as the default one for operations it > supports. It is designed to make it possible to work with various > SSL accelerators. I believe this patch does not affect the "ssl_engine" directive anymore. I removed everything I could to make the patch minimal. And changed the log message to be more specific. I will send the other changes in a new thread. The patch follows: # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1524841096 -7200 # Fri Apr 27 16:58:16 2018 +0200 # Node ID f5b0a791092224ff5d3eaf4da9a95e6018e7235f # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 SSL: Add ENGINE_init() call before loading key. It is necessary to call ENGINE_init() before using an OpenSSL engine to get the engine functional reference. Without this, when ENGINE_load_private_key() is called, the engine is still unitialized. diff -r 46c0c7ef4913 -r f5b0a7910922 src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/event/ngx_event_openssl.c Fri Apr 27 16:58:16 2018 +0200 @@ -527,6 +527,13 @@ return NGX_ERROR; } + if (!ENGINE_init(engine)) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "ENGINE_init(engine) failed"); + ENGINE_free(engine); + return NGX_ERROR; + } + *last++ = ':'; pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); From ansasaki at redhat.com Mon Apr 30 10:05:56 2018 From: ansasaki at redhat.com (Anderson Sasaki) Date: Mon, 30 Apr 2018 06:05:56 -0400 (EDT) Subject: [PATCH] SSL: Set engine passed in ssl_certificate_key as default In-Reply-To: <1233714625.23671766.1525081737233.JavaMail.zimbra@redhat.com> Message-ID: <1403375514.23673252.1525082756399.JavaMail.zimbra@redhat.com> Hello, Following there are two patches, one adding the call to set the engine as default for all methods and the other restricting the engine to be the default only for PKEY methods. For me makes sense to have the engine as default only for PKEY methods. Best Regards, Anderson # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1525082320 -7200 # Mon Apr 30 11:58:40 2018 +0200 # Node ID 07278e8f9b731a7b78b62c6f1826f71967d31fd7 # Parent 46c0c7ef4913011f3f1e073f9ac880b07b1a8154 SSL: Set engine passed in ssl_certificate_key as default Set the engine as the default OpenSSL engine. diff -r 46c0c7ef4913 -r 07278e8f9b73 src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c Wed Apr 25 14:57:24 2018 +0300 +++ b/src/event/ngx_event_openssl.c Mon Apr 30 11:58:40 2018 +0200 @@ -527,6 +527,14 @@ return NGX_ERROR; } + if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { + ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, + "ENGINE_set_default(engine, ENGINE_METHOD_ALL) " + "failed"); + ENGINE_free(engine); + return NGX_ERROR; + } + *last++ = ':'; pkey = ENGINE_load_private_key(engine, (char *) last, 0, 0); # HG changeset patch # User Anderson Toshiyuki Sasaki # Date 1525082330 -7200 # Mon Apr 30 11:58:50 2018 +0200 # Node ID 5573a6df976204207445f78ee1e0d047a60f6511 # Parent 07278e8f9b731a7b78b62c6f1826f71967d31fd7 SSL: Set default engine only for PKEY methods Set the engine passed in ssl_certificate_key directive as default only for PKEY methods. diff -r 07278e8f9b73 -r 5573a6df9762 src/event/ngx_event_openssl.c --- a/src/event/ngx_event_openssl.c Mon Apr 30 11:58:40 2018 +0200 +++ b/src/event/ngx_event_openssl.c Mon Apr 30 11:58:50 2018 +0200 @@ -527,10 +527,10 @@ return NGX_ERROR; } - if (ENGINE_set_default(engine, ENGINE_METHOD_ALL) == 0) { + if (ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS) == 0) { ngx_ssl_error(NGX_LOG_EMERG, ssl->log, 0, - "ENGINE_set_default(engine, ENGINE_METHOD_ALL) " - "failed"); + "ENGINE_set_default(engine, ENGINE_METHOD_PKEY_METHS)" + " failed"); ENGINE_free(engine); return NGX_ERROR; }