Re: [PATCH] SSL: Add ENGINE_init() calls before using engines.

2018-04-26 Thread Пичулин Дмитрий Николаевич
> 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.
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed njs_vm_external_bind().

2018-04-26 Thread Dmitry Volyntsev
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(_prop, _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(>externals_hash, ) == NXT_OK) {
 ev = (njs_extern_value_t *) lhq.value;
-return ev->value;
+return >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_tvalue;
 } njs_unit_test_req_t;
 
 
@@ -9719,7 +9721,6 @@ njs_externals_init(njs_vm_t *vm)
 nxt_int_tret;
 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, _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, [i], proto, [i]);
+ret = njs_vm_external_create(vm, [i].value, proto,
+ [i]);
 if (ret != NXT_OK) {
 printf("njs_vm_external_create() failed\n");
 return NXT_ERROR;
 }
 
-ret = njs_vm_external_bind(vm, _test_requests[i].name, [i]);
+ret = njs_vm_external_bind(vm, _test_requests[i].name,
+   [i].value);
 if (ret != NXT_OK) {
 printf("njs_vm_external_bind() failed\n");
 return NXT_ERROR;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed return value type of clearTimeout().

2018-04-26 Thread Dmitry Volyntsev
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.cThu Apr 26 20:21:44 2018 +0300
+++ b/njs/njs_time.cThu 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([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;
 }
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed unit tests exit code.

2018-04-26 Thread Dmitry Volyntsev
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;
 }
 
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed the writeable flag of Array.length property.

2018-04-26 Thread Dmitry Volyntsev
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") },
 
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed handling of missing arg of Object.getOwnPropertyDescriptor().

2018-04-26 Thread Dmitry Volyntsev
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(>data.u.object->hash, );
 
 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") },
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed handling of props in Object.getOwnPropertyDescriptor().

2018-04-26 Thread Dmitry Volyntsev
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_PROPERTYthe property trap must be called,
+ *   NXT_ERRORexception 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_tindex;
+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 = >prototypes[index].object;
+break;
+
+case NJS_STRING:
+if (pq->query == NJS_PROPERTY_QUERY_DELETE) {
+return NXT_DECLINED;
+}
+
+obj = >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 = >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, >value, property);
+
+if (nxt_fast_path(ret == NXT_OK)) {
+njs_string_get(>value, >lhq.key);
+njs_type_error(vm, "cannot get property '%.*s' of undefined",
+   (int) pq->lhq.key.length, pq->lhq.key.start);
+return 

Re: [PATCH] SSL: Add ENGINE_init() calls before using engines.

2018-04-26 Thread Anderson Sasaki
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",
> >[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",
> > +  [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
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


Re: [PATCH] SSL: Add ENGINE_init() calls before using engines.

2018-04-26 Thread Anderson Sasaki
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.
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Improved variable names in Object.isPrototypeOf().

2018-04-26 Thread Dmitry Volyntsev
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 = _value_false;
-value = [0];
-obj = njs_arg(args, nargs, 1);
+prototype = [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__;
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel


[njs] Fixed return value type for boolean functions.

2018-04-26 Thread Dmitry Volyntsev
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([1])) {
-value = _string_true;
+value = _value_true;
 
 } else {
-value = _string_false;
+value = _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) ? _string_true : _string_false;
+setval = (prop->configurable == 1) ? _value_true : _value_false;
 
 pr = njs_object_prop_alloc(vm, _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) ? _string_true : _string_false;
+setval = (prop->enumerable == 1) ? _value_true : _value_false;
 
 pr = njs_object_prop_alloc(vm, _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) ? _string_true : _string_false;
+setval = (prop->writable == 1) ? _value_true : _value_false;
 
 pr = njs_object_prop_alloc(vm, _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 = _string_false;
+retval = _value_false;
 
 object = value->data.u.object;
 nxt_lvlhsh_each_init(, _object_hash_proto);
@@ -853,7 +853,7 @@ njs_object_is_frozen(njs_vm_t *vm, njs_v
 }
 }
 
-retval = _string_true;
+retval = _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 = _string_false;
+retval = _value_false;
 
 object = value->data.u.object;
 nxt_lvlhsh_each_init(, _object_hash_proto);
@@ -943,7 +943,7 @@ njs_object_is_sealed(njs_vm_t *vm, njs_v
 }
 }
 
-retval = _string_true;
+retval = _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 ? _string_true
-  : _string_false;
+retval = value->data.u.object->extensible ? _value_true
+  : _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 = _string_false;
+retval = _value_false;
 value = [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(>start[index])) {
-retval = _string_true;
+retval = _value_true;
 goto done;
 }
 }
@@ -1514,7 +1514,7 @@ njs_object_prototype_has_own_property(nj
 ret = nxt_lvlhsh_find(>data.u.object->hash, );
 
 if (ret == NXT_OK) {
-retval = _string_true;
+retval = _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 = _string_false;
+

[njs] Adding const qualifiers to njs_number_dec_parse() and friends.

2018-04-26 Thread Dmitry Volyntsev
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.cFri Apr 20 16:42:12 2018 +0300
+++ b/njs/njs_json.cThu 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_tret;
 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_tutf, utf_low;
-njs_ret_t   ret;
+u_charch, *s, *dst;
+size_tsize, surplus;
+ssize_t   length;
+uint32_t  utf, utf_low;
+njs_ret_t ret;
+const u_char  *start, *last;

[njs] Fixed handling of undefined arguments of functions.

2018-04-26 Thread Dmitry Volyntsev
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) ? [2] : _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) ? [2] : _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.hThu Apr 26 19:11:28 2018 +0300
+++ b/njs/njs_function.hThu 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] : _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_ttype;
-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([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 = [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([1]) || njs_is_null([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([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, 

Re: [PATCH] SSL: Add ENGINE_init() calls before using engines.

2018-04-26 Thread Maxim Dounin
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",
>[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",
> +  [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/
___
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel