mirror of
https://github.com/bunkerity/bunkerweb
synced 2026-05-24 09:28:37 +00:00
Merge commit '28b42bd4009801a4ff079d2ad03306d095e866f1' into dev
This commit is contained in:
commit
32f111b535
38 changed files with 1215 additions and 216 deletions
22
src/deps/src/stream-lua-nginx-module/.travis.yml
vendored
22
src/deps/src/stream-lua-nginx-module/.travis.yml
vendored
|
|
@ -29,9 +29,13 @@ env:
|
|||
- LUAJIT_INC=$LUAJIT_PREFIX/include/luajit-2.1
|
||||
- LUA_INCLUDE_DIR=$LUAJIT_INC
|
||||
- PCRE_VER=8.45
|
||||
- PCRE2_VER=10.37
|
||||
- PCRE_PREFIX=/opt/pcre
|
||||
- PCRE2_PREFIX=/opt/pcre2
|
||||
- PCRE_LIB=$PCRE_PREFIX/lib
|
||||
- PCRE2_LIB=$PCRE2_PREFIX/lib
|
||||
- PCRE_INC=$PCRE_PREFIX/include
|
||||
- PCRE2_INC=$PCRE2_PREFIX/include
|
||||
- OPENSSL_PREFIX=/opt/ssl
|
||||
- OPENSSL_LIB=$OPENSSL_PREFIX/lib
|
||||
- OPENSSL_INC=$OPENSSL_PREFIX/include
|
||||
|
|
@ -39,8 +43,9 @@ env:
|
|||
- NGX_BUILD_JOBS=$JOBS
|
||||
- TEST_NGINX_SLEEP=0.006
|
||||
matrix:
|
||||
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.0l
|
||||
- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.1s
|
||||
#- NGINX_VERSION=1.21.4 OPENSSL_VER=1.1.12
|
||||
- NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1w
|
||||
- NGINX_VERSION=1.25.1 OPENSSL_VER=1.1.1w USE_PCRE2=Y
|
||||
|
||||
services:
|
||||
- memcache
|
||||
|
|
@ -49,7 +54,8 @@ services:
|
|||
install:
|
||||
- sudo apt update
|
||||
- sudo apt install --only-upgrade ca-certificates
|
||||
- if [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache/ https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi
|
||||
- if [ "$USE_PCRE2" != "Y" ] && [ ! -f download-cache/pcre-$PCRE_VER.tar.gz ]; then wget -P download-cache/ https://downloads.sourceforge.net/project/pcre/pcre/${PCRE_VER}/pcre-${PCRE_VER}.tar.gz; fi
|
||||
- if [ "$USE_PCRE2" = "Y" ] && [ ! -f download-cache/pcre2-$PCRE2_VER.tar.gz ]; then wget -P download-cache https://downloads.sourceforge.net/project/pcre/pcre2/${PCRE2_VER}/pcre2-${PCRE2_VER}.tar.gz; fi
|
||||
- if [ ! -f download-cache/openssl-$OPENSSL_VER.tar.gz ]; then wget -P download-cache https://www.openssl.org/source/openssl-$OPENSSL_VER.tar.gz || wget -P download-cache https://www.openssl.org/source/old/${OPENSSL_VER//[a-z]/}/openssl-$OPENSSL_VER.tar.gz; fi
|
||||
- git clone https://github.com/openresty/openresty-devel-utils.git
|
||||
- git clone https://github.com/openresty/lua-cjson.git
|
||||
|
|
@ -73,12 +79,8 @@ script:
|
|||
- sudo ip addr add 10.254.254.1/24 dev lo
|
||||
- sudo ip addr add 10.254.254.2/24 dev lo
|
||||
- sudo ip route add prohibit 0.0.0.1/32
|
||||
- tar zxf download-cache/pcre-$PCRE_VER.tar.gz
|
||||
- cd pcre-$PCRE_VER/
|
||||
- ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1)
|
||||
- make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1)
|
||||
- sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1)
|
||||
- cd ..
|
||||
- if [ "$USE_PCRE2" != "Y" ]; then tar zxf download-cache/pcre-$PCRE_VER.tar.gz; cd pcre-$PCRE_VER/; ./configure --prefix=$PCRE_PREFIX --enable-jit --enable-utf --enable-unicode-properties > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
|
||||
- if [ "$USE_PCRE2" = "Y" ]; then tar zxf download-cache/pcre2-$PCRE2_VER.tar.gz; cd pcre2-$PCRE2_VER/; ./configure --prefix=$PCRE2_PREFIX --enable-jit --enable-utf > build.log 2>&1 || (cat build.log && exit 1); make -j$JOBS > build.log 2>&1 || (cat build.log && exit 1); sudo PATH=$PATH make install > build.log 2>&1 || (cat build.log && exit 1); cd ..; fi
|
||||
- cd luajit2
|
||||
- make -j$JOBS CCDEBUG=-g Q= PREFIX=$LUAJIT_PREFIX CC=$CC XCFLAGS='-DLUA_USE_APICHECK -DLUA_USE_ASSERT' > build.log 2>&1 || (cat build.log && exit 1)
|
||||
- sudo make install PREFIX=$LUAJIT_PREFIX > build.log 2>&1 || (cat build.log && exit 1)
|
||||
|
|
@ -101,4 +103,4 @@ script:
|
|||
- export TEST_NGINX_RESOLVER=8.8.4.4
|
||||
- dig +short @$TEST_NGINX_RESOLVER openresty.org || exit 0
|
||||
- dig +short @$TEST_NGINX_RESOLVER agentzh.org || exit 0
|
||||
- prove -I. -r t
|
||||
- prove -I. -Itest-nginx/lib -r t
|
||||
|
|
|
|||
24
src/deps/src/stream-lua-nginx-module/LICENSE
vendored
Normal file
24
src/deps/src/stream-lua-nginx-module/LICENSE
vendored
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2023, OpenResty
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
|
@ -41,8 +41,8 @@ Version
|
|||
=======
|
||||
|
||||
This document describes ngx_stream_lua
|
||||
[v0.0.8](https://github.com/openresty/stream-lua-nginx-module/tags), which was released
|
||||
on 2 July, 2020.
|
||||
[v0.0.13](https://github.com/openresty/stream-lua-nginx-module/tags), which was released
|
||||
on 21 May, 2023.
|
||||
|
||||
Synopsis
|
||||
========
|
||||
|
|
@ -160,6 +160,8 @@ behavior.
|
|||
* [lua_ssl_ciphers](https://github.com/openresty/lua-nginx-module#lua_ssl_ciphers)
|
||||
* [lua_ssl_crl](https://github.com/openresty/lua-nginx-module#lua_ssl_crl)
|
||||
* [lua_ssl_protocols](https://github.com/openresty/lua-nginx-module#lua_ssl_protocols)
|
||||
* [lua_ssl_certificate](https://github.com/openresty/lua-nginx-module#lua_ssl_certificate)
|
||||
* [lua_ssl_certificate_key](https://github.com/openresty/lua-nginx-module#lua_ssl_certificate_key)
|
||||
* [lua_ssl_trusted_certificate](https://github.com/openresty/lua-nginx-module#lua_ssl_trusted_certificate)
|
||||
* [lua_ssl_verify_depth](https://github.com/openresty/lua-nginx-module#lua_ssl_verify_depth)
|
||||
* [lua_ssl_conf_command](https://github.com/openresty/lua-nginx-module#lua_ssl_conf_command)
|
||||
|
|
@ -539,6 +541,8 @@ Nginx Compatibility
|
|||
|
||||
The latest version of this module is compatible with the following versions of Nginx:
|
||||
|
||||
* 1.25.x (last tested: 1.25.1)
|
||||
* 1.21.x (last tested: 1.21.4)
|
||||
* 1.19.x (last tested: 1.19.3)
|
||||
* 1.17.x (last tested: 1.17.8)
|
||||
* 1.15.x (last tested: 1.15.8)
|
||||
|
|
|
|||
2
src/deps/src/stream-lua-nginx-module/config
vendored
2
src/deps/src/stream-lua-nginx-module/config
vendored
|
|
@ -405,7 +405,7 @@ fi
|
|||
|
||||
# ----------------------------------------
|
||||
|
||||
if [ $USE_PCRE = YES -o $PCRE != NONE ] && [ $PCRE != NO -a $PCRE != YES ]; then
|
||||
if [ $USE_PCRE = YES -o $PCRE != NONE ] && [ $PCRE != NO -a $PCRE != YES ] && [ $PCRE2 != YES ]; then
|
||||
# force pcre_version symbol to be required when PCRE is statically linked
|
||||
case "$NGX_PLATFORM" in
|
||||
Darwin:*)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
/* Public API for other Nginx modules */
|
||||
|
||||
|
||||
#define ngx_stream_lua_version 13
|
||||
#define ngx_stream_lua_version 14
|
||||
|
||||
|
||||
typedef struct {
|
||||
|
|
|
|||
|
|
@ -36,15 +36,18 @@
|
|||
|
||||
|
||||
#if (NGX_PCRE)
|
||||
# if (NGX_PCRE2)
|
||||
# define LUA_HAVE_PCRE_JIT 1
|
||||
# else
|
||||
|
||||
#include <pcre.h>
|
||||
|
||||
#if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
|
||||
# define LUA_HAVE_PCRE_JIT 1
|
||||
#else
|
||||
# define LUA_HAVE_PCRE_JIT 0
|
||||
#endif
|
||||
|
||||
# if (PCRE_MAJOR > 8) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21)
|
||||
# define LUA_HAVE_PCRE_JIT 1
|
||||
# else
|
||||
# define LUA_HAVE_PCRE_JIT 0
|
||||
# endif
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -193,11 +196,14 @@ struct ngx_stream_lua_main_conf_s {
|
|||
ngx_int_t regex_cache_entries;
|
||||
ngx_int_t regex_cache_max_entries;
|
||||
ngx_int_t regex_match_limit;
|
||||
|
||||
#if (LUA_HAVE_PCRE_JIT)
|
||||
pcre_jit_stack *jit_stack;
|
||||
#endif
|
||||
|
||||
#if (LUA_HAVE_PCRE_JIT)
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_jit_stack *jit_stack;
|
||||
#else
|
||||
pcre_jit_stack *jit_stack;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
ngx_array_t *shm_zones; /* of ngx_shm_zone_t* */
|
||||
|
|
@ -245,6 +251,8 @@ struct ngx_stream_lua_main_conf_s {
|
|||
struct ngx_stream_lua_srv_conf_s {
|
||||
#if (NGX_STREAM_SSL)
|
||||
ngx_ssl_t *ssl; /* shared by SSL cosockets */
|
||||
ngx_array_t *ssl_certificates;
|
||||
ngx_array_t *ssl_certificate_keys;
|
||||
ngx_uint_t ssl_protocols;
|
||||
ngx_str_t ssl_ciphers;
|
||||
ngx_uint_t ssl_verify_depth;
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ ngx_stream_lua_content_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
|
|||
ctx->cur_co_ctx->co_top = 1;
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);
|
||||
|
||||
/* {{{ register request cleanup hooks */
|
||||
if (ctx->cleanup == NULL) {
|
||||
cln = ngx_stream_lua_cleanup_add(r, 0);
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ ngx_stream_lua_coroutine_create_helper(lua_State *L,
|
|||
|
||||
#ifdef OPENRESTY_LUAJIT
|
||||
ngx_stream_lua_set_req(co, r);
|
||||
ngx_stream_lua_attach_co_ctx_to_L(co, coctx);
|
||||
#else
|
||||
/* make new coroutine share globals of the parent coroutine.
|
||||
* NOTE: globals don't have to be separated! */
|
||||
|
|
|
|||
|
|
@ -56,6 +56,9 @@ static char *ngx_stream_lua_ssl_conf_command_check(ngx_conf_t *cf, void *post,
|
|||
#endif
|
||||
static char *ngx_stream_lua_malloc_trim(ngx_conf_t *cf, ngx_command_t *cmd,
|
||||
void *conf);
|
||||
#if (NGX_PCRE2)
|
||||
extern void ngx_stream_lua_regex_cleanup(void *data);
|
||||
#endif
|
||||
|
||||
|
||||
static ngx_conf_post_t ngx_stream_lua_lowat_post =
|
||||
|
|
@ -422,6 +425,20 @@ static ngx_command_t ngx_stream_lua_cmds[] = {
|
|||
offsetof(ngx_stream_lua_srv_conf_t, ssl_verify_depth),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("lua_ssl_certificate"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_lua_srv_conf_t, ssl_certificates),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("lua_ssl_certificate_key"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_array_slot,
|
||||
NGX_STREAM_SRV_CONF_OFFSET,
|
||||
offsetof(ngx_stream_lua_srv_conf_t, ssl_certificate_keys),
|
||||
NULL },
|
||||
|
||||
{ ngx_string("lua_ssl_trusted_certificate"),
|
||||
NGX_STREAM_MAIN_CONF|NGX_STREAM_SRV_CONF|NGX_CONF_TAKE1,
|
||||
ngx_conf_set_str_slot,
|
||||
|
|
@ -563,7 +580,16 @@ ngx_stream_lua_init(ngx_conf_t *cf)
|
|||
cln->data = lmcf;
|
||||
cln->handler = ngx_stream_lua_sema_mm_cleanup;
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
/* add the cleanup of pcre2 regex */
|
||||
cln = ngx_pool_cleanup_add(cf->pool, 0);
|
||||
if (cln == NULL) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
cln->data = lmcf;
|
||||
cln->handler = ngx_stream_lua_regex_cleanup;
|
||||
#endif
|
||||
|
||||
if (lmcf->lua == NULL) {
|
||||
dd("initializing lua vm");
|
||||
|
|
@ -579,6 +605,15 @@ ngx_stream_lua_init(ngx_conf_t *cf)
|
|||
"the OpenResty releases from https://openresty.org/"
|
||||
"en/download.html)");
|
||||
}
|
||||
#else
|
||||
# if !defined(HAVE_LUA_EXDATA2)
|
||||
ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
|
||||
"detected an old version of OpenResty's LuaJIT missing "
|
||||
"the exdata2 API and thus the "
|
||||
"performance will be compromised; please upgrade to the "
|
||||
"latest version of OpenResty's LuaJIT: "
|
||||
"https://github.com/openresty/luajit2");
|
||||
# endif
|
||||
#endif
|
||||
|
||||
|
||||
|
|
@ -814,6 +849,8 @@ ngx_stream_lua_create_srv_conf(ngx_conf_t *cf)
|
|||
|
||||
#if (NGX_STREAM_SSL)
|
||||
conf->ssl_verify_depth = NGX_CONF_UNSET_UINT;
|
||||
conf->ssl_certificates = NGX_CONF_UNSET_PTR;
|
||||
conf->ssl_certificate_keys = NGX_CONF_UNSET_PTR;
|
||||
#endif
|
||||
|
||||
return conf;
|
||||
|
|
@ -926,6 +963,10 @@ ngx_stream_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
|
||||
ngx_conf_merge_uint_value(conf->ssl_verify_depth,
|
||||
prev->ssl_verify_depth, 1);
|
||||
ngx_conf_merge_ptr_value(conf->ssl_certificates,
|
||||
prev->ssl_certificates, NULL);
|
||||
ngx_conf_merge_ptr_value(conf->ssl_certificate_keys,
|
||||
prev->ssl_certificate_keys, NULL);
|
||||
ngx_conf_merge_str_value(conf->ssl_trusted_certificate,
|
||||
prev->ssl_trusted_certificate, "");
|
||||
ngx_conf_merge_str_value(conf->ssl_crl, prev->ssl_crl, "");
|
||||
|
|
@ -973,6 +1014,13 @@ ngx_stream_lua_merge_srv_conf(ngx_conf_t *cf, void *parent, void *child)
|
|||
conf->preread_chunkname = prev->preread_chunkname;
|
||||
}
|
||||
|
||||
if (conf->log_src.value.len == 0) {
|
||||
conf->log_src = prev->log_src;
|
||||
conf->log_handler = prev->log_handler;
|
||||
conf->log_src_key = prev->log_src_key;
|
||||
conf->log_chunkname = prev->log_chunkname;
|
||||
}
|
||||
|
||||
return NGX_CONF_OK;
|
||||
}
|
||||
|
||||
|
|
@ -993,6 +1041,20 @@ ngx_stream_lua_set_ssl(ngx_conf_t *cf, ngx_stream_lua_srv_conf_t *lscf)
|
|||
|
||||
lscf->ssl->log = cf->log;
|
||||
|
||||
if (lscf->ssl_certificates) {
|
||||
if (lscf->ssl_certificate_keys == NULL
|
||||
|| lscf->ssl_certificate_keys->nelts
|
||||
< lscf->ssl_certificates->nelts)
|
||||
{
|
||||
ngx_log_error(NGX_LOG_EMERG, cf->log, 0,
|
||||
"no \"lua_ssl_certificate_key\" is defined "
|
||||
"for certificate \"%V\"",
|
||||
((ngx_str_t *) lscf->ssl_certificates->elts)
|
||||
+ lscf->ssl_certificates->nelts - 1);
|
||||
return NGX_ERROR;
|
||||
}
|
||||
}
|
||||
|
||||
if (ngx_ssl_create(lscf->ssl, lscf->ssl_protocols, NULL) != NGX_OK) {
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
|
@ -1015,6 +1077,16 @@ ngx_stream_lua_set_ssl(ngx_conf_t *cf, ngx_stream_lua_srv_conf_t *lscf)
|
|||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (lscf->ssl_certificates
|
||||
&& ngx_ssl_certificates(cf, lscf->ssl,
|
||||
lscf->ssl_certificates,
|
||||
lscf->ssl_certificate_keys,
|
||||
NULL)
|
||||
!= NGX_OK)
|
||||
{
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
if (lscf->ssl_trusted_certificate.len
|
||||
&& ngx_ssl_trusted_certificate(cf, lscf->ssl,
|
||||
&lscf->ssl_trusted_certificate,
|
||||
|
|
|
|||
|
|
@ -26,14 +26,59 @@
|
|||
|
||||
static ngx_pool_t *ngx_stream_lua_pcre_pool = NULL;
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
static ngx_uint_t ngx_regex_direct_alloc;
|
||||
#else
|
||||
static void *(*old_pcre_malloc)(size_t);
|
||||
static void (*old_pcre_free)(void *ptr);
|
||||
#endif
|
||||
|
||||
|
||||
/* XXX: work-around to nginx regex subsystem, must init a memory pool
|
||||
* to use PCRE functions. As PCRE still has memory-leaking problems,
|
||||
* and nginx overwrote pcre_malloc/free hooks with its own static
|
||||
* functions, so nobody else can reuse nginx regex subsystem... */
|
||||
#if (NGX_PCRE2)
|
||||
|
||||
void *
|
||||
ngx_stream_lua_pcre_malloc(size_t size, void *data)
|
||||
{
|
||||
dd("lua pcre pool is %p", ngx_stream_lua_pcre_pool);
|
||||
|
||||
if (ngx_stream_lua_pcre_pool) {
|
||||
return ngx_palloc(ngx_stream_lua_pcre_pool, size);
|
||||
}
|
||||
|
||||
if (ngx_regex_direct_alloc) {
|
||||
return ngx_alloc(size, ngx_cycle->log);
|
||||
}
|
||||
|
||||
fprintf(stderr, "error: lua pcre malloc failed due to empty pcre pool");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_stream_lua_pcre_free(void *ptr, void *data)
|
||||
{
|
||||
dd("lua pcre pool is %p", ngx_stream_lua_pcre_pool);
|
||||
|
||||
if (ngx_stream_lua_pcre_pool) {
|
||||
ngx_pfree(ngx_stream_lua_pcre_pool, ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
if (ngx_regex_direct_alloc) {
|
||||
ngx_free(ptr);
|
||||
return;
|
||||
}
|
||||
|
||||
fprintf(stderr, "error: lua pcre free failed due to empty pcre pool");
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void *
|
||||
ngx_stream_lua_pcre_malloc(size_t size)
|
||||
{
|
||||
|
|
@ -62,6 +107,41 @@ ngx_stream_lua_pcre_free(void *ptr)
|
|||
fprintf(stderr, "error: lua pcre free failed due to empty pcre pool");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
|
||||
ngx_pool_t *
|
||||
ngx_stream_lua_pcre_malloc_init(ngx_pool_t *pool)
|
||||
{
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
dd("lua pcre pool was %p", ngx_stream_lua_pcre_pool);
|
||||
|
||||
ngx_regex_direct_alloc = (pool == NULL) ? 1 : 0;
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_pool;
|
||||
ngx_stream_lua_pcre_pool = pool;
|
||||
|
||||
dd("lua pcre pool is %p", ngx_stream_lua_pcre_pool);
|
||||
|
||||
return old_pool;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ngx_stream_lua_pcre_malloc_done(ngx_pool_t *old_pool)
|
||||
{
|
||||
dd("lua pcre pool was %p", ngx_stream_lua_pcre_pool);
|
||||
|
||||
ngx_stream_lua_pcre_pool = old_pool;
|
||||
ngx_regex_direct_alloc = 0;
|
||||
|
||||
dd("lua pcre pool is %p", ngx_stream_lua_pcre_pool);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
ngx_pool_t *
|
||||
ngx_stream_lua_pcre_malloc_init(ngx_pool_t *pool)
|
||||
|
|
@ -109,6 +189,7 @@ ngx_stream_lua_pcre_malloc_done(ngx_pool_t *old_pool)
|
|||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* NGX_PCRE */
|
||||
|
||||
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
|
||||
|
|
|
|||
|
|
@ -23,6 +23,11 @@
|
|||
#if (NGX_PCRE)
|
||||
ngx_pool_t *ngx_stream_lua_pcre_malloc_init(ngx_pool_t *pool);
|
||||
void ngx_stream_lua_pcre_malloc_done(ngx_pool_t *old_pool);
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
void *ngx_stream_lua_pcre_malloc(size_t size, void *data);
|
||||
void ngx_stream_lua_pcre_free(void *ptr, void *data);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -247,6 +247,8 @@ ngx_stream_lua_preread_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
|
|||
ctx->cur_co_ctx->co_top = 1;
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);
|
||||
|
||||
/* }}} */
|
||||
|
||||
/* {{{ register request cleanup hooks */
|
||||
|
|
|
|||
|
|
@ -25,13 +25,24 @@
|
|||
#include "ngx_stream_lua_util.h"
|
||||
|
||||
|
||||
#if (PCRE_MAJOR >= 6)
|
||||
#if (PCRE_MAJOR >= 6 || NGX_PCRE2)
|
||||
# define LUA_HAVE_PCRE_DFA 1
|
||||
#else
|
||||
# define LUA_HAVE_PCRE_DFA 0
|
||||
#endif
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
static pcre2_compile_context *ngx_regex_compile_context;
|
||||
static pcre2_match_context *ngx_regex_match_context;
|
||||
static pcre2_match_data *ngx_regex_match_data;
|
||||
static ngx_uint_t ngx_regex_match_data_size = 0;
|
||||
|
||||
#define PCRE2_VERSION_SIZE 64
|
||||
static char ngx_pcre2_version[PCRE2_VERSION_SIZE];
|
||||
#endif
|
||||
|
||||
|
||||
#define NGX_LUA_RE_MODE_DFA (1<<1)
|
||||
#define NGX_LUA_RE_MODE_JIT (1<<2)
|
||||
#define NGX_LUA_RE_NO_UTF8_CHECK (1<<4)
|
||||
|
|
@ -50,8 +61,17 @@ typedef struct {
|
|||
int ncaptures;
|
||||
int *captures;
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_code *regex;
|
||||
/*
|
||||
* pcre2 doesn't use pcre_extra any more,
|
||||
* just for keeping same memory layout in the lua ffi cdef
|
||||
*/
|
||||
void *regex_sd;
|
||||
#else
|
||||
pcre *regex;
|
||||
pcre_extra *regex_sd;
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_complex_value_t *replace;
|
||||
|
||||
|
|
@ -65,7 +85,11 @@ typedef struct {
|
|||
ngx_pool_t *pool;
|
||||
ngx_int_t options;
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_code *regex;
|
||||
#else
|
||||
pcre *regex;
|
||||
#endif
|
||||
int captures;
|
||||
ngx_str_t err;
|
||||
} ngx_stream_lua_regex_compile_t;
|
||||
|
|
@ -74,8 +98,12 @@ typedef struct {
|
|||
typedef struct {
|
||||
ngx_stream_lua_request_t *request;
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_code *regex;
|
||||
#else
|
||||
pcre *regex;
|
||||
pcre_extra *regex_sd;
|
||||
#endif
|
||||
int ncaptures;
|
||||
int *captures;
|
||||
int captures_len;
|
||||
|
|
@ -83,8 +111,6 @@ typedef struct {
|
|||
} ngx_stream_lua_regex_ctx_t;
|
||||
|
||||
|
||||
static void ngx_stream_lua_regex_free_study_data(ngx_pool_t *pool,
|
||||
pcre_extra *sd);
|
||||
static ngx_int_t ngx_stream_lua_regex_compile(
|
||||
ngx_stream_lua_regex_compile_t *rc);
|
||||
|
||||
|
|
@ -102,22 +128,157 @@ static ngx_int_t ngx_stream_lua_regex_compile(
|
|||
|
||||
|
||||
static void
|
||||
ngx_stream_lua_regex_free_study_data(ngx_pool_t *pool, pcre_extra *sd)
|
||||
ngx_stream_lua_regex_free_study_data(ngx_pool_t *pool,
|
||||
ngx_stream_lua_regex_t *re)
|
||||
{
|
||||
ngx_pool_t *old_pool;
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
#if (NGX_PCRE2)
|
||||
if (re && re->regex) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
|
||||
#if LUA_HAVE_PCRE_JIT
|
||||
pcre_free_study(sd);
|
||||
pcre2_code_free(re->regex);
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
re->regex = NULL;
|
||||
}
|
||||
#else
|
||||
pcre_free(sd);
|
||||
if (re && re->regex_sd) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
#if LUA_HAVE_PCRE_JIT
|
||||
pcre_free_study(re->regex_sd);
|
||||
#else
|
||||
pcre_free(re->regex_sd);
|
||||
#endif
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
re->regex_sd = NULL;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
static ngx_int_t
|
||||
ngx_stream_lua_regex_compile(ngx_stream_lua_regex_compile_t *rc)
|
||||
{
|
||||
int n, errcode;
|
||||
char *p;
|
||||
size_t erroff;
|
||||
u_char errstr[128];
|
||||
pcre2_code *re;
|
||||
ngx_pool_t *old_pool;
|
||||
pcre2_general_context *gctx;
|
||||
pcre2_compile_context *cctx;
|
||||
|
||||
ngx_stream_lua_main_conf_t *lmcf;
|
||||
|
||||
if (ngx_regex_compile_context == NULL) {
|
||||
/*
|
||||
* Allocate a compile context if not yet allocated. This uses
|
||||
* direct allocations from heap, so the result can be cached
|
||||
* even at runtime.
|
||||
*/
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(NULL);
|
||||
|
||||
gctx = pcre2_general_context_create(ngx_stream_lua_pcre_malloc,
|
||||
ngx_stream_lua_pcre_free,
|
||||
NULL);
|
||||
if (gctx == NULL) {
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
goto nomem;
|
||||
}
|
||||
|
||||
cctx = pcre2_compile_context_create(gctx);
|
||||
if (cctx == NULL) {
|
||||
pcre2_general_context_free(gctx);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
goto nomem;
|
||||
}
|
||||
|
||||
ngx_regex_compile_context = cctx;
|
||||
|
||||
ngx_regex_match_context = pcre2_match_context_create(gctx);
|
||||
if (ngx_regex_match_context == NULL) {
|
||||
pcre2_general_context_free(gctx);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
goto nomem;
|
||||
}
|
||||
|
||||
lmcf = ngx_stream_cycle_get_module_main_conf(ngx_cycle,
|
||||
ngx_stream_lua_module);
|
||||
if (lmcf && lmcf->regex_match_limit > 0) {
|
||||
pcre2_set_match_limit(ngx_regex_match_context,
|
||||
lmcf->regex_match_limit);
|
||||
}
|
||||
|
||||
pcre2_general_context_free(gctx);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(rc->pool);
|
||||
|
||||
re = pcre2_compile(rc->pattern.data,
|
||||
rc->pattern.len, rc->options,
|
||||
&errcode, &erroff, ngx_regex_compile_context);
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
if (re == NULL) {
|
||||
pcre2_get_error_message(errcode, errstr, 128);
|
||||
|
||||
if ((size_t) erroff == rc->pattern.len) {
|
||||
rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
|
||||
"pcre2_compile() failed: %s in \"%V\"",
|
||||
errstr, &rc->pattern)
|
||||
- rc->err.data;
|
||||
|
||||
} else {
|
||||
rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
|
||||
"pcre2_compile() failed: %s in "
|
||||
"\"%V\" at \"%s\"", errstr, &rc->pattern,
|
||||
rc->pattern.data + erroff)
|
||||
- rc->err.data;
|
||||
}
|
||||
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
rc->regex = re;
|
||||
|
||||
n = pcre2_pattern_info(re, PCRE2_INFO_CAPTURECOUNT, &rc->captures);
|
||||
if (n < 0) {
|
||||
p = "pcre2_pattern_info(\"%V\", PCRE_INFO_CAPTURECOUNT) failed: %d";
|
||||
goto failed;
|
||||
}
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
ngx_log_debug3(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre2_compile: pattern[%V], options 0x%08Xd, ncaptures %d",
|
||||
&rc->pattern, rc->options, rc->captures);
|
||||
#endif
|
||||
|
||||
return NGX_OK;
|
||||
|
||||
failed:
|
||||
|
||||
rc->err.len = ngx_snprintf(rc->err.data, rc->err.len, p, &rc->pattern, n)
|
||||
- rc->err.data;
|
||||
return NGX_ERROR;
|
||||
|
||||
nomem:
|
||||
|
||||
rc->err.len = ngx_snprintf(rc->err.data, rc->err.len,
|
||||
"regex \"%V\" compilation failed: no memory",
|
||||
&rc->pattern)
|
||||
- rc->err.data;
|
||||
return NGX_ERROR;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static ngx_int_t
|
||||
ngx_stream_lua_regex_compile(ngx_stream_lua_regex_compile_t *rc)
|
||||
{
|
||||
|
|
@ -170,13 +331,14 @@ failed:
|
|||
- rc->err.data;
|
||||
return NGX_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ngx_int_t
|
||||
ngx_stream_lua_ffi_set_jit_stack_size(int size, u_char *errstr,
|
||||
size_t *errstr_size)
|
||||
{
|
||||
#if LUA_HAVE_PCRE_JIT
|
||||
#if (LUA_HAVE_PCRE_JIT)
|
||||
|
||||
ngx_stream_lua_main_conf_t *lmcf;
|
||||
ngx_pool_t *pool, *old_pool;
|
||||
|
|
@ -195,15 +357,24 @@ ngx_stream_lua_ffi_set_jit_stack_size(int size, u_char *errstr,
|
|||
if (lmcf->jit_stack) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_jit_stack_free(lmcf->jit_stack);
|
||||
#else
|
||||
pcre_jit_stack_free(lmcf->jit_stack);
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
lmcf->jit_stack = pcre2_jit_stack_create(NGX_LUA_RE_MIN_JIT_STACK_SIZE,
|
||||
size, NULL);
|
||||
#else
|
||||
lmcf->jit_stack = pcre_jit_stack_alloc(NGX_LUA_RE_MIN_JIT_STACK_SIZE,
|
||||
size);
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
|
|
@ -222,25 +393,163 @@ ngx_stream_lua_ffi_set_jit_stack_size(int size, u_char *errstr,
|
|||
"no pcre jit support found") - errstr;
|
||||
return NGX_ERROR;
|
||||
|
||||
#endif /* LUA_HAVE_PCRE_JIT */
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
static void
|
||||
ngx_stream_lua_regex_jit_compile(ngx_stream_lua_regex_t *re, int flags,
|
||||
ngx_pool_t *pool, ngx_stream_lua_main_conf_t *lmcf,
|
||||
ngx_stream_lua_regex_compile_t *re_comp)
|
||||
{
|
||||
ngx_int_t ret;
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
if (flags & NGX_LUA_RE_MODE_JIT) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
ret = pcre2_jit_compile(re_comp->regex, PCRE2_JIT_COMPLETE);
|
||||
|
||||
if (ret != 0) {
|
||||
ngx_log_error(NGX_LOG_INFO, ngx_cycle->log, 0,
|
||||
"pcre2_jit_compile() failed: %d in \"%V\", "
|
||||
"ignored",
|
||||
ret, &re_comp->pattern);
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
|
||||
} else {
|
||||
ngx_log_debug0(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre2 JIT compiled successfully");
|
||||
# endif /* !(NGX_DEBUG) */
|
||||
}
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
}
|
||||
|
||||
if (lmcf && lmcf->jit_stack) {
|
||||
pcre2_jit_stack_assign(ngx_regex_match_context, NULL,
|
||||
lmcf->jit_stack);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
static void
|
||||
ngx_stream_lua_regex_jit_compile(ngx_stream_lua_regex_t *re, int flags,
|
||||
ngx_pool_t *pool, ngx_stream_lua_main_conf_t *lmcf,
|
||||
ngx_stream_lua_regex_compile_t *re_comp)
|
||||
{
|
||||
const char *msg;
|
||||
pcre_extra *sd = NULL;
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
|
||||
#if (LUA_HAVE_PCRE_JIT)
|
||||
if (flags & NGX_LUA_RE_MODE_JIT) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
sd = pcre_study(re_comp->regex, PCRE_STUDY_JIT_COMPILE, &msg);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
# if (NGX_DEBUG)
|
||||
if (msg != NULL) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre study failed with PCRE_STUDY_JIT_COMPILE: "
|
||||
"%s (%p)", msg, sd);
|
||||
}
|
||||
|
||||
if (sd != NULL) {
|
||||
int jitted;
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
|
||||
pcre_fullinfo(re_comp->regex, sd, PCRE_INFO_JIT, &jitted);
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre JIT compiling result: %d", jitted);
|
||||
}
|
||||
# endif /* !(NGX_DEBUG) */
|
||||
|
||||
} else {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
sd = pcre_study(re_comp->regex, 0, &msg);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
if (sd && lmcf && lmcf->jit_stack) {
|
||||
pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack);
|
||||
}
|
||||
|
||||
if (sd
|
||||
&& lmcf && lmcf->regex_match_limit > 0
|
||||
&& !(flags & NGX_LUA_RE_MODE_DFA))
|
||||
{
|
||||
sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
|
||||
sd->match_limit = lmcf->regex_match_limit;
|
||||
}
|
||||
|
||||
#endif /* LUA_HAVE_PCRE_JIT */
|
||||
|
||||
re->regex_sd = sd;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
void
|
||||
ngx_stream_lua_regex_cleanup(void *data)
|
||||
{
|
||||
ngx_pool_t *old_pool;
|
||||
ngx_stream_lua_main_conf_t *lmcf;
|
||||
|
||||
lmcf = data;
|
||||
|
||||
if (ngx_regex_compile_context) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(NULL);
|
||||
pcre2_compile_context_free(ngx_regex_compile_context);
|
||||
ngx_regex_compile_context = NULL;
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
if (lmcf && lmcf->jit_stack) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(NULL);
|
||||
|
||||
pcre2_jit_stack_free(lmcf->jit_stack);
|
||||
lmcf->jit_stack = NULL;
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
if (ngx_regex_match_data) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(NULL);
|
||||
pcre2_match_data_free(ngx_regex_match_data);
|
||||
ngx_regex_match_data = NULL;
|
||||
ngx_regex_match_data_size = 0;
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
ngx_stream_lua_regex_t *
|
||||
ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
|
||||
int flags, int pcre_opts, u_char *errstr,
|
||||
size_t errstr_size)
|
||||
{
|
||||
int *cap = NULL, ovecsize;
|
||||
u_char *p;
|
||||
ngx_int_t rc;
|
||||
const char *msg;
|
||||
ngx_pool_t *pool, *old_pool;
|
||||
pcre_extra *sd = NULL;
|
||||
|
||||
ngx_stream_lua_regex_t *re;
|
||||
ngx_stream_lua_main_conf_t *lmcf;
|
||||
ngx_stream_lua_regex_compile_t re_comp;
|
||||
int *cap = NULL, ovecsize;
|
||||
u_char *p;
|
||||
ngx_int_t rc;
|
||||
const char *msg;
|
||||
ngx_pool_t *pool, *old_pool;
|
||||
ngx_stream_lua_regex_t *re = NULL;
|
||||
ngx_stream_lua_main_conf_t *lmcf;
|
||||
ngx_stream_lua_regex_compile_t re_comp;
|
||||
|
||||
pool = ngx_create_pool(512, ngx_cycle->log);
|
||||
if (pool == NULL) {
|
||||
|
|
@ -259,6 +568,8 @@ ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
|
|||
}
|
||||
|
||||
re->pool = pool;
|
||||
re->regex = NULL;
|
||||
re->regex_sd = NULL;
|
||||
|
||||
re_comp.options = pcre_opts;
|
||||
re_comp.pattern.data = (u_char *) pat;
|
||||
|
|
@ -280,54 +591,7 @@ ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
|
|||
lmcf = ngx_stream_cycle_get_module_main_conf(ngx_cycle,
|
||||
ngx_stream_lua_module);
|
||||
|
||||
#if (LUA_HAVE_PCRE_JIT)
|
||||
|
||||
if (flags & NGX_LUA_RE_MODE_JIT) {
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
sd = pcre_study(re_comp.regex, PCRE_STUDY_JIT_COMPILE, &msg);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
# if (NGX_DEBUG)
|
||||
if (msg != NULL) {
|
||||
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre study failed with PCRE_STUDY_JIT_COMPILE: "
|
||||
"%s (%p)", msg, sd);
|
||||
}
|
||||
|
||||
if (sd != NULL) {
|
||||
int jitted;
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
|
||||
pcre_fullinfo(re_comp.regex, sd, PCRE_INFO_JIT, &jitted);
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre JIT compiling result: %d", jitted);
|
||||
}
|
||||
# endif /* !(NGX_DEBUG) */
|
||||
|
||||
} else {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(pool);
|
||||
sd = pcre_study(re_comp.regex, 0, &msg);
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
}
|
||||
|
||||
if (sd && lmcf->jit_stack) {
|
||||
pcre_assign_jit_stack(sd, NULL, lmcf->jit_stack);
|
||||
}
|
||||
|
||||
#endif /* LUA_HAVE_PCRE_JIT */
|
||||
|
||||
if (sd
|
||||
&& lmcf && lmcf->regex_match_limit > 0
|
||||
&& !(flags & NGX_LUA_RE_MODE_DFA))
|
||||
{
|
||||
sd->flags |= PCRE_EXTRA_MATCH_LIMIT;
|
||||
sd->match_limit = lmcf->regex_match_limit;
|
||||
}
|
||||
ngx_stream_lua_regex_jit_compile(re, flags, pool, lmcf, &re_comp);
|
||||
|
||||
if (flags & NGX_LUA_RE_MODE_DFA) {
|
||||
ovecsize = 2;
|
||||
|
|
@ -345,6 +609,31 @@ ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
|
|||
goto error;
|
||||
}
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMECOUNT,
|
||||
&re->name_count) < 0)
|
||||
{
|
||||
msg = "cannot acquire named subpattern count";
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (re->name_count > 0) {
|
||||
if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMEENTRYSIZE,
|
||||
&re->name_entry_size) != 0)
|
||||
{
|
||||
msg = "cannot acquire named subpattern entry size";
|
||||
goto error;
|
||||
}
|
||||
|
||||
if (pcre2_pattern_info(re_comp.regex, PCRE2_INFO_NAMETABLE,
|
||||
&re->name_table) != 0)
|
||||
{
|
||||
msg = "cannot acquire named subpattern table";
|
||||
goto error;
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
if (pcre_fullinfo(re_comp.regex, NULL, PCRE_INFO_NAMECOUNT,
|
||||
&re->name_count) != 0)
|
||||
{
|
||||
|
|
@ -367,9 +656,9 @@ ngx_stream_lua_ffi_compile_regex(const unsigned char *pat, size_t pat_len,
|
|||
goto error;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
re->regex = re_comp.regex;
|
||||
re->regex_sd = sd;
|
||||
re->ncaptures = re_comp.captures;
|
||||
re->captures = cap;
|
||||
re->replace = NULL;
|
||||
|
|
@ -385,9 +674,7 @@ error:
|
|||
p = ngx_snprintf(errstr, errstr_size - 1, "%s", msg);
|
||||
*p = '\0';
|
||||
|
||||
if (sd) {
|
||||
ngx_stream_lua_regex_free_study_data(pool, sd);
|
||||
}
|
||||
ngx_stream_lua_regex_free_study_data(pool, re);
|
||||
|
||||
if (pool) {
|
||||
ngx_destroy_pool(pool);
|
||||
|
|
@ -397,6 +684,102 @@ error:
|
|||
}
|
||||
|
||||
|
||||
#if (NGX_PCRE2)
|
||||
int
|
||||
ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
|
||||
const u_char *s, size_t len, int pos)
|
||||
{
|
||||
int rc, exec_opts = 0;
|
||||
size_t *ov;
|
||||
ngx_uint_t ovecsize, n, i;
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
if (flags & NGX_LUA_RE_MODE_DFA) {
|
||||
ovecsize = 2;
|
||||
re->ncaptures = 0;
|
||||
|
||||
} else {
|
||||
ovecsize = (re->ncaptures + 1) * 3;
|
||||
}
|
||||
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(NULL);
|
||||
|
||||
if (ngx_regex_match_data == NULL
|
||||
|| ovecsize > ngx_regex_match_data_size)
|
||||
{
|
||||
/*
|
||||
* Allocate a match data if not yet allocated or smaller than
|
||||
* needed.
|
||||
*/
|
||||
|
||||
if (ngx_regex_match_data) {
|
||||
pcre2_match_data_free(ngx_regex_match_data);
|
||||
}
|
||||
|
||||
ngx_regex_match_data_size = ovecsize;
|
||||
ngx_regex_match_data = pcre2_match_data_create(ovecsize / 3, NULL);
|
||||
|
||||
if (ngx_regex_match_data == NULL) {
|
||||
rc = PCRE2_ERROR_NOMEMORY;
|
||||
goto failed;
|
||||
}
|
||||
}
|
||||
|
||||
if (flags & NGX_LUA_RE_NO_UTF8_CHECK) {
|
||||
exec_opts = PCRE2_NO_UTF_CHECK;
|
||||
|
||||
} else {
|
||||
exec_opts = 0;
|
||||
}
|
||||
|
||||
if (flags & NGX_LUA_RE_MODE_DFA) {
|
||||
int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
|
||||
rc = pcre2_dfa_match(re->regex, s, len, pos, exec_opts,
|
||||
ngx_regex_match_data, ngx_regex_match_context,
|
||||
ws, sizeof(ws) / sizeof(ws[0]));
|
||||
|
||||
} else {
|
||||
rc = pcre2_match(re->regex, s, len, pos, exec_opts,
|
||||
ngx_regex_match_data, ngx_regex_match_context);
|
||||
}
|
||||
|
||||
if (rc < 0) {
|
||||
#if (NGX_DEBUG)
|
||||
ngx_log_debug4(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre2_match failed: flags 0x%05Xd, options 0x%08Xd, rc %d, "
|
||||
"ovecsize %ui", flags, exec_opts, rc, ovecsize);
|
||||
#endif
|
||||
|
||||
goto failed;
|
||||
}
|
||||
|
||||
n = pcre2_get_ovector_count(ngx_regex_match_data);
|
||||
ov = pcre2_get_ovector_pointer(ngx_regex_match_data);
|
||||
|
||||
#if (NGX_DEBUG)
|
||||
ngx_log_debug5(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
|
||||
"pcre2_match: flags 0x%05Xd, options 0x%08Xd, rc %d, "
|
||||
"n %ui, ovecsize %ui", flags, exec_opts, rc, n, ovecsize);
|
||||
#endif
|
||||
|
||||
if (!(flags & NGX_LUA_RE_MODE_DFA) && n > ovecsize / 3) {
|
||||
n = ovecsize / 3;
|
||||
}
|
||||
|
||||
for (i = 0; i < n; i++) {
|
||||
re->captures[i * 2] = ov[i * 2];
|
||||
re->captures[i * 2 + 1] = ov[i * 2 + 1];
|
||||
}
|
||||
|
||||
failed:
|
||||
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
int
|
||||
ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
|
||||
const u_char *s, size_t len, int pos)
|
||||
|
|
@ -433,7 +816,7 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
|
|||
int ws[NGX_LUA_RE_DFA_MODE_WORKSPACE_COUNT];
|
||||
rc = ngx_stream_lua_regex_dfa_exec(re->regex, sd, &subj,
|
||||
(int) pos, cap, ovecsize, ws,
|
||||
sizeof(ws)/sizeof(ws[0]), exec_opts);
|
||||
sizeof(ws) / sizeof(ws[0]), exec_opts);
|
||||
|
||||
#else
|
||||
|
||||
|
|
@ -449,28 +832,19 @@ ngx_stream_lua_ffi_exec_regex(ngx_stream_lua_regex_t *re, int flags,
|
|||
return rc;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void
|
||||
ngx_stream_lua_ffi_destroy_regex(ngx_stream_lua_regex_t *re)
|
||||
{
|
||||
ngx_pool_t *old_pool;
|
||||
|
||||
dd("destroy regex called");
|
||||
|
||||
if (re == NULL || re->pool == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (re->regex_sd) {
|
||||
old_pool = ngx_stream_lua_pcre_malloc_init(re->pool);
|
||||
#if LUA_HAVE_PCRE_JIT
|
||||
pcre_free_study(re->regex_sd);
|
||||
#else
|
||||
pcre_free(re->regex_sd);
|
||||
#endif
|
||||
ngx_stream_lua_pcre_malloc_done(old_pool);
|
||||
re->regex_sd = NULL;
|
||||
}
|
||||
ngx_stream_lua_regex_free_study_data(re->pool, re);
|
||||
|
||||
ngx_destroy_pool(re->pool);
|
||||
}
|
||||
|
|
@ -598,7 +972,13 @@ ngx_stream_lua_ffi_max_regex_cache_size(void)
|
|||
const char *
|
||||
ngx_stream_lua_ffi_pcre_version(void)
|
||||
{
|
||||
#if (NGX_PCRE2)
|
||||
pcre2_config(PCRE2_CONFIG_VERSION, ngx_pcre2_version);
|
||||
|
||||
return ngx_pcre2_version;
|
||||
#else
|
||||
return pcre_version();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -3185,6 +3185,25 @@ ngx_stream_lua_socket_tcp_shutdown(lua_State *L)
|
|||
return luaL_error(L, "no request found");
|
||||
}
|
||||
|
||||
if (u == NULL
|
||||
|| u->peer.connection == NULL
|
||||
|| (u->read_closed && u->write_closed))
|
||||
{
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "closed");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (u->write_closed) {
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "already shutdown");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (u->request != r) {
|
||||
return luaL_error(L, "bad request");
|
||||
}
|
||||
|
||||
ctx = ngx_stream_lua_get_module_ctx(r, ngx_stream_lua_module);
|
||||
if (ctx == NULL) {
|
||||
ngx_stream_lua_socket_handle_write_error(r, u,
|
||||
|
|
@ -3212,25 +3231,6 @@ ngx_stream_lua_socket_tcp_shutdown(lua_State *L)
|
|||
ctx->eof = 1;
|
||||
}
|
||||
|
||||
if (u == NULL
|
||||
|| u->peer.connection == NULL
|
||||
|| (u->read_closed && u->write_closed))
|
||||
{
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "closed");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (u->write_closed) {
|
||||
lua_pushnil(L);
|
||||
lua_pushliteral(L, "already shutdown");
|
||||
return 2;
|
||||
}
|
||||
|
||||
if (u->request != r) {
|
||||
return luaL_error(L, "bad request");
|
||||
}
|
||||
|
||||
ngx_stream_lua_socket_check_busy_connecting(r, u, L);
|
||||
ngx_stream_lua_socket_check_busy_writing(r, u, L);
|
||||
|
||||
|
|
|
|||
|
|
@ -517,6 +517,8 @@ ngx_stream_lua_ssl_cert_by_chunk(lua_State *L, ngx_stream_lua_request_t *r)
|
|||
ctx->cur_co_ctx->co_top = 1;
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);
|
||||
|
||||
/* register request cleanup hooks */
|
||||
if (ctx->cleanup == NULL) {
|
||||
cln = ngx_stream_lua_cleanup_add(r, 0);
|
||||
|
|
|
|||
|
|
@ -503,6 +503,8 @@ ngx_stream_lua_ssl_client_hello_by_chunk(lua_State *L,
|
|||
ctx->cur_co_ctx->co_top = 1;
|
||||
#endif
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(co, ctx->cur_co_ctx);
|
||||
|
||||
/* register request cleanup hooks */
|
||||
if (ctx->cleanup == NULL) {
|
||||
cln = ngx_stream_lua_cleanup_add(r, 0);
|
||||
|
|
|
|||
|
|
@ -694,6 +694,8 @@ ngx_stream_lua_timer_handler(ngx_event_t *ev)
|
|||
/* save the request in coroutine globals table */
|
||||
ngx_stream_lua_set_req(tctx.co, r);
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(tctx.co, ctx->cur_co_ctx);
|
||||
|
||||
lmcf->running_timers++;
|
||||
|
||||
lua_pushboolean(tctx.co, tctx.premature);
|
||||
|
|
@ -917,7 +919,7 @@ ngx_stream_lua_abort_pending_timers(ngx_event_t *ev)
|
|||
next = cur->parent;
|
||||
|
||||
} else {
|
||||
/* not reacheable */
|
||||
/* not reachable */
|
||||
next = NULL;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -105,6 +105,8 @@ ngx_stream_lua_uthread_spawn(lua_State *L)
|
|||
coctx->parent_co_ctx = ctx->cur_co_ctx;
|
||||
ctx->cur_co_ctx = coctx;
|
||||
|
||||
ngx_stream_lua_attach_co_ctx_to_L(coctx->co, coctx);
|
||||
|
||||
ngx_stream_lua_probe_user_thread_spawn(r, L, coctx->co);
|
||||
|
||||
dd("yielding with arg %s, top=%d, index-1:%s", luaL_typename(L, -1),
|
||||
|
|
@ -282,7 +284,7 @@ ngx_stream_lua_uthread_kill(lua_State *L)
|
|||
return 1;
|
||||
}
|
||||
|
||||
/* not reacheable */
|
||||
/* not reachable */
|
||||
}
|
||||
|
||||
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */
|
||||
|
|
|
|||
|
|
@ -2590,6 +2590,9 @@ ngx_stream_lua_traceback(lua_State *L)
|
|||
ngx_stream_lua_co_ctx_t *
|
||||
ngx_stream_lua_get_co_ctx(lua_State *L, ngx_stream_lua_ctx_t *ctx)
|
||||
{
|
||||
#ifdef HAVE_LUA_EXDATA2
|
||||
return (ngx_stream_lua_co_ctx_t *) lua_getexdata2(L);
|
||||
#else
|
||||
ngx_uint_t i;
|
||||
ngx_list_part_t *part;
|
||||
|
||||
|
|
@ -2626,6 +2629,7 @@ ngx_stream_lua_get_co_ctx(lua_State *L, ngx_stream_lua_ctx_t *ctx)
|
|||
}
|
||||
|
||||
return NULL;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -191,6 +191,16 @@ ngx_int_t ngx_stream_lua_open_and_stat_file(u_char *name,
|
|||
ngx_chain_t *ngx_stream_lua_chain_get_free_buf(ngx_log_t *log, ngx_pool_t *p,
|
||||
ngx_chain_t **free, size_t len);
|
||||
|
||||
|
||||
static ngx_inline void
|
||||
ngx_stream_lua_attach_co_ctx_to_L(lua_State *L, ngx_stream_lua_co_ctx_t *coctx)
|
||||
{
|
||||
#ifdef HAVE_LUA_EXDATA2
|
||||
lua_setexdata2(L, (void *) coctx);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
#ifndef OPENRESTY_LUAJIT
|
||||
void ngx_stream_lua_create_new_globals_table(lua_State *L, int narr, int nrec);
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -287,8 +287,11 @@ he
|
|||
end
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -505,8 +508,11 @@ regex: (?:>[\w\s]*</?\w{2,}>)
|
|||
end
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "([0-9]+"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile\(\) failed: missing closing parenthesis in \"\([0-9]+\"\n"
|
||||
:
|
||||
"error: pcre_compile\(\) failed: missing \) in \"\([0-9]+\"\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
@ -745,8 +751,11 @@ nil
|
|||
ngx.say("not matched")
|
||||
end
|
||||
}
|
||||
--- stream_response_like chop
|
||||
^error: pcre_exec\(\) failed: -10$
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre_exec\(\) failed: -4\n"
|
||||
:
|
||||
"error: pcre_exec\(\) failed: -10\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
@ -844,8 +853,14 @@ if not res then
|
|||
return
|
||||
end
|
||||
|
||||
--- stream_response
|
||||
error: pcre_exec() failed: -8
|
||||
--- stream_response eval
|
||||
# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
|
||||
# but PCRE2 replaces this with pcre2_set_match_limit interface,
|
||||
# which has different effects.
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"failed to match\n"
|
||||
:
|
||||
"error: pcre_exec() failed: -8\n"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -568,8 +568,11 @@ not matched!
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -601,8 +604,11 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("not matched")
|
||||
end
|
||||
}
|
||||
--- stream_response_like chop
|
||||
error: pcre_exec\(\) failed: -10
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre_exec\(\) failed: -4\n"
|
||||
:
|
||||
"error: pcre_exec\(\) failed: -10\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
@ -708,8 +714,14 @@ if not res then
|
|||
return
|
||||
end
|
||||
|
||||
--- stream_response
|
||||
error: pcre_exec() failed: -8
|
||||
--- stream_response eval
|
||||
# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
|
||||
# but PCRE2 replaces this with pcre2_set_match_limit interface,
|
||||
# which has different effects.
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"failed to match\n"
|
||||
:
|
||||
"error: pcre_exec() failed: -8\n"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
24
src/deps/src/stream-lua-nginx-module/t/036-sub.t
vendored
24
src/deps/src/stream-lua-nginx-module/t/036-sub.t
vendored
|
|
@ -372,8 +372,11 @@ a [b c] [b] [c] [] [] d
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -394,8 +397,11 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response_like chop
|
||||
error: pcre_exec\(\) failed: -10
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre_exec\(\) failed: -4\n"
|
||||
:
|
||||
"error: pcre_exec\(\) failed: -10\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
@ -486,8 +492,14 @@ if err then
|
|||
end
|
||||
ngx.say("sub: ", cnt)
|
||||
|
||||
--- stream_response
|
||||
error: pcre_exec() failed: -8
|
||||
--- stream_response eval
|
||||
# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
|
||||
# but PCRE2 replaces this with pcre2_set_match_limit interface,
|
||||
# which has different effects.
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"sub: 0\n"
|
||||
:
|
||||
"error: pcre_exec() failed: -8\n"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -327,8 +327,11 @@ n: 1
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response_like chop
|
||||
error: pcre_exec\(\) failed: -10
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre_exec\(\) failed: -4\n"
|
||||
:
|
||||
"error: pcre_exec\(\) failed: -10\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
@ -423,8 +426,14 @@ if err then
|
|||
end
|
||||
ngx.say("gsub: ", cnt)
|
||||
|
||||
--- stream_response
|
||||
error: pcre_exec() failed: -8
|
||||
--- stream_response eval
|
||||
# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
|
||||
# but PCRE2 replaces this with pcre2_set_match_limit interface,
|
||||
# which has different effects.
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"gsub: 0\n"
|
||||
:
|
||||
"error: pcre_exec() failed: -8\n"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -238,8 +238,11 @@ he
|
|||
end
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,11 @@ __DATA__
|
|||
}
|
||||
--- stream_response
|
||||
1234
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -45,8 +48,11 @@ pcre JIT compiling result: 1
|
|||
}
|
||||
--- stream_response
|
||||
not matched!
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,9 +70,15 @@ pcre JIT compiling result: 1
|
|||
1234
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -85,9 +97,15 @@ qr/pcre JIT compiling result: \d+/
|
|||
not matched!
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -108,8 +126,11 @@ qr/pcre JIT compiling result: \d+/
|
|||
end
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -146,8 +167,15 @@ if not res then
|
|||
return
|
||||
end
|
||||
|
||||
--- stream_response
|
||||
error: pcre_exec() failed: -8
|
||||
--- stream_response eval
|
||||
# lua_regex_match_limit uses pcre_extra->match_limit in the PCRE,
|
||||
# but PCRE2 replaces this with pcre2_set_match_limit interface,
|
||||
# which has different effects.
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
# PCRE2_ERROR_MATCHLIMIT (-47)
|
||||
"error: pcre_exec() failed: -47\n"
|
||||
:
|
||||
"error: pcre_exec() failed: -8\n"
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,11 @@ __DATA__
|
|||
--- stream_response
|
||||
hello
|
||||
world
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -52,8 +55,11 @@ pcre JIT compiling result: 1
|
|||
nil
|
||||
nil
|
||||
nil
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -65,8 +71,11 @@ pcre JIT compiling result: 1
|
|||
}
|
||||
--- stream_response
|
||||
done
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -83,8 +92,11 @@ pcre JIT compiling result: 1
|
|||
}
|
||||
--- stream_response
|
||||
hello
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -104,9 +116,15 @@ hello
|
|||
world
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -130,9 +148,15 @@ nil
|
|||
nil
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -147,9 +171,15 @@ qr/pcre JIT compiling result: \d+/
|
|||
done
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -169,9 +199,15 @@ qr/pcre JIT compiling result: \d+/
|
|||
hello
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -186,7 +222,10 @@ qr/pcre JIT compiling result: \d+/
|
|||
end
|
||||
ngx.say("success")
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
|
|||
|
|
@ -171,8 +171,11 @@ hello
|
|||
end
|
||||
ngx.say("success")
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,11 @@ __DATA__
|
|||
}
|
||||
--- stream_response
|
||||
hello, world 5678: 1
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -45,8 +48,11 @@ pcre JIT compiling result: 1
|
|||
}
|
||||
--- stream_response
|
||||
hello, world: 0
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,9 +70,15 @@ pcre JIT compiling result: 1
|
|||
hello, world 5678: 1
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -85,9 +97,15 @@ qr/pcre JIT compiling result: \d+/
|
|||
hello, world: 0
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -102,8 +120,11 @@ qr/pcre JIT compiling result: \d+/
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -119,7 +140,10 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
|
|||
|
|
@ -87,8 +87,11 @@ hello, world: 0
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -105,8 +108,11 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
|
|||
|
|
@ -28,8 +28,11 @@ __DATA__
|
|||
}
|
||||
--- stream_response
|
||||
hello, world world: 2
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -45,8 +48,11 @@ pcre JIT compiling result: 1
|
|||
}
|
||||
--- stream_response
|
||||
hello, world: 0
|
||||
--- error_log
|
||||
pcre JIT compiling result: 1
|
||||
--- error_log eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully\n"
|
||||
:
|
||||
"pcre JIT compiling result: 1\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,9 +70,15 @@ pcre JIT compiling result: 1
|
|||
hello, world world: 2
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -85,9 +97,15 @@ qr/pcre JIT compiling result: \d+/
|
|||
hello, world: 0
|
||||
|
||||
--- grep_error_log eval
|
||||
qr/pcre JIT compiling result: \d+/
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"pcre2 JIT compiled successfully"
|
||||
:
|
||||
"pcre JIT compiling result: 1"
|
||||
|
||||
--- grep_error_log_out eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
["pcre2 JIT compiled successfully\n", ""]
|
||||
:
|
||||
["pcre JIT compiling result: 1\n", ""]
|
||||
|
||||
|
||||
|
|
@ -102,8 +120,11 @@ qr/pcre JIT compiling result: \d+/
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -119,7 +140,10 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
|
|||
|
|
@ -87,8 +87,11 @@ hello, world: 0
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
|
||||
|
||||
|
||||
|
|
@ -102,8 +105,11 @@ error: pcre_compile() failed: missing ) in "(abc"
|
|||
ngx.say("error: ", err)
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use Test::Nginx::Socket::Lua::Stream;
|
|||
|
||||
repeat_each(2);
|
||||
|
||||
plan tests => repeat_each() * 219;
|
||||
plan tests => repeat_each() * 221;
|
||||
|
||||
our $HtmlDir = html_dir;
|
||||
|
||||
|
|
@ -3526,3 +3526,22 @@ orld
|
|||
[error]
|
||||
--- error_log
|
||||
lua tcp socket calling receiveany() method to read at most 7 bytes
|
||||
|
||||
|
||||
|
||||
=== TEST 67: shutdown on a not connected socket correctly throws error
|
||||
--- stream_server_config
|
||||
lua_socket_connect_timeout 1s;
|
||||
resolver $TEST_NGINX_RESOLVER ipv6=off;
|
||||
resolver_timeout 3s;
|
||||
|
||||
content_by_lua_block {
|
||||
local sock = ngx.socket.tcp()
|
||||
|
||||
local ok, err = sock:shutdown('send')
|
||||
ngx.log(ngx.ERR, 'shutdown on a not connected socket: ', err)
|
||||
|
||||
}
|
||||
|
||||
--- error_log
|
||||
shutdown on a not connected socket: closed
|
||||
|
|
|
|||
|
|
@ -363,3 +363,17 @@ log handler
|
|||
ok
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
||||
|
||||
=== TEST 21: log_by_lua in stream level
|
||||
--- stream_config
|
||||
log_by_lua_block { ngx.log(ngx.ERR, "Hello from log_by_lua stream level: ", ngx.var.protocol) }
|
||||
--- stream_server_config
|
||||
content_by_lua_block {
|
||||
ngx.say('hello')
|
||||
}
|
||||
--- stream_response
|
||||
hello
|
||||
--- error_log
|
||||
Hello from log_by_lua stream level: TCP
|
||||
|
|
|
|||
|
|
@ -301,8 +301,11 @@ matched: he
|
|||
end
|
||||
end
|
||||
}
|
||||
--- stream_response
|
||||
error: pcre_compile() failed: missing ) in "(abc"
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre2_compile() failed: missing closing parenthesis in \"(abc\"\n"
|
||||
:
|
||||
"error: pcre_compile() failed: missing ) in \"(abc\"\n"
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
||||
|
|
@ -480,8 +483,11 @@ matched: hello, 1234
|
|||
ngx.say("not matched")
|
||||
end
|
||||
}
|
||||
--- stream_response_like chop
|
||||
^error: pcre_exec\(\) failed: -10$
|
||||
--- stream_response eval
|
||||
$Test::Nginx::Util::PcreVersion == 2 ?
|
||||
"error: pcre_exec\(\) failed: -4\n"
|
||||
:
|
||||
"error: pcre_exec\(\) failed: -10\n"
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
|
|
|
|||
117
src/deps/src/stream-lua-nginx-module/t/163-ssl-two-verification.t
vendored
Normal file
117
src/deps/src/stream-lua-nginx-module/t/163-ssl-two-verification.t
vendored
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
# vim:set ft= ts=4 sw=4 et fdm=marker:
|
||||
|
||||
use Test::Nginx::Socket::Lua::Stream;
|
||||
|
||||
repeat_each(3);
|
||||
|
||||
# All these tests need to have new openssl
|
||||
my $NginxBinary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
|
||||
my $openssl_version = eval { `$NginxBinary -V 2>&1` };
|
||||
|
||||
if ($openssl_version =~ m/built with OpenSSL (0\S*|1\.0\S*|1\.1\.0\S*)/) {
|
||||
plan(skip_all => "too old OpenSSL, need 1.1.1, was $1");
|
||||
} else {
|
||||
plan tests => repeat_each() * (blocks() * 7);
|
||||
}
|
||||
|
||||
$ENV{TEST_NGINX_HTML_DIR} ||= html_dir();
|
||||
$ENV{TEST_NGINX_MEMCACHED_PORT} ||= 11211;
|
||||
|
||||
#log_level 'warn';
|
||||
log_level 'debug';
|
||||
|
||||
no_long_string();
|
||||
#no_diff();
|
||||
|
||||
run_tests();
|
||||
|
||||
__DATA__
|
||||
|
||||
=== TEST 1: simple logging
|
||||
--- stream_config
|
||||
server {
|
||||
listen unix:$TEST_NGINX_HTML_DIR/nginx.sock ssl;
|
||||
#listen 127.0.0.1:4433 ssl;
|
||||
ssl_client_hello_by_lua_block { print("ssl client hello by lua is running!") }
|
||||
ssl_certificate ../../cert/test.crt;
|
||||
ssl_certificate_key ../../cert/test.key;
|
||||
#ssl_trusted_certificate ../../cert/test.crt;
|
||||
ssl_client_certificate ../../cert/test.crt;
|
||||
ssl_verify_client on;
|
||||
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
|
||||
|
||||
log_by_lua_block {
|
||||
ngx.log(ngx.INFO, "ssl_client_s_dn: ", ngx.var.ssl_client_s_dn)
|
||||
}
|
||||
return 'it works!\n';
|
||||
}
|
||||
--- stream_server_config
|
||||
lua_ssl_certificate ../../cert/test.crt;
|
||||
lua_ssl_certificate_key ../../cert/test.key;
|
||||
lua_ssl_trusted_certificate ../../cert/test.crt;
|
||||
|
||||
content_by_lua_block {
|
||||
do
|
||||
local sock = ngx.socket.tcp()
|
||||
|
||||
sock:settimeout(2000)
|
||||
|
||||
local ok, err = sock:connect("unix:$TEST_NGINX_HTML_DIR/nginx.sock")
|
||||
-- local ok, err = sock:connect("127.0.0.1", 4433)
|
||||
if not ok then
|
||||
ngx.say("failed to connect: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("connected: ", ok)
|
||||
|
||||
local sess, err = sock:sslhandshake(nil, "test.com", true)
|
||||
if not sess then
|
||||
ngx.say("failed to do SSL handshake: ", err)
|
||||
return
|
||||
end
|
||||
|
||||
ngx.say("ssl handshake: ", type(sess))
|
||||
|
||||
while true do
|
||||
local line, err = sock:receive()
|
||||
if not line then
|
||||
-- ngx.say("failed to receive response status line: ", err)
|
||||
break
|
||||
end
|
||||
|
||||
ngx.say("received: ", line)
|
||||
end
|
||||
|
||||
local ok, err = sock:close()
|
||||
ngx.say("close: ", ok, " ", err)
|
||||
end -- do
|
||||
-- collectgarbage()
|
||||
}
|
||||
|
||||
--- stream_response
|
||||
connected: 1
|
||||
ssl handshake: userdata
|
||||
received: it works!
|
||||
close: 1 nil
|
||||
|
||||
--- error_log
|
||||
lua ssl server name: "test.com"
|
||||
ssl_client_s_dn: emailAddress=agentzh@gmail.com,CN=test.com,OU=OpenResty,O=OpenResty,L=San Francisco,ST=California,C=US
|
||||
|
||||
--- no_error_log
|
||||
[error]
|
||||
[alert]
|
||||
--- grep_error_log eval: qr/ssl_client_hello_by_lua:.*?,|\bssl client hello: connection reusable: \d+|\breusable connection: \d+/
|
||||
--- grep_error_log_out eval
|
||||
qr/reusable connection: 1
|
||||
reusable connection: 0
|
||||
ssl client hello: connection reusable: 0
|
||||
reusable connection: 0
|
||||
ssl_client_hello_by_lua:1: ssl client hello by lua is running!,
|
||||
reusable connection: 0
|
||||
reusable connection: 0
|
||||
reusable connection: 0
|
||||
reusable connection: 0
|
||||
reusable connection: 0
|
||||
/
|
||||
|
|
@ -10,12 +10,30 @@ version=$1
|
|||
force=$2
|
||||
home=~
|
||||
|
||||
add_http3_module=--with-http_v3_module
|
||||
answer=`$root/util/ver-ge "$NGINX_VERSION" 1.25.1`
|
||||
if [ "$OPENSSL_VER" = "1.1.0l" ] || [ "$answer" = "N" ]; then
|
||||
add_http3_module=""
|
||||
fi
|
||||
|
||||
disable_pcre2=--without-pcre2
|
||||
answer=`$root/util/ver-ge "$NGINX_VERSION" 1.25.1`
|
||||
if [ "$answer" = "N" ] || [ "$USE_PCRE2" = "Y" ]; then
|
||||
disable_pcre2=""
|
||||
fi
|
||||
if [ "$USE_PCRE2" = "Y" ]; then
|
||||
PCRE_INC=$PCRE2_INC
|
||||
PCRE_LIB=$PCRE2_LIB
|
||||
fi
|
||||
|
||||
#--add-module=$root/../stream-echo-nginx-module \
|
||||
ngx-build $force $version \
|
||||
--with-cc-opt="-DNGX_LUA_USE_ASSERT -I$PCRE_INC -I$OPENSSL_INC" \
|
||||
--with-ld-opt="-L$PCRE_LIB -L$OPENSSL_LIB -Wl,-rpath,$PCRE_LIB:$LIBDRIZZLE_LIB:$OPENSSL_LIB" \
|
||||
--with-http_stub_status_module \
|
||||
--with-http_image_filter_module \
|
||||
$add_http3_module \
|
||||
$disable_pcre2 \
|
||||
--with-http_ssl_module \
|
||||
--without-mail_pop3_module \
|
||||
--without-mail_imap_module \
|
||||
|
|
|
|||
41
src/deps/src/stream-lua-nginx-module/util/ver-ge
vendored
Executable file
41
src/deps/src/stream-lua-nginx-module/util/ver-ge
vendored
Executable file
|
|
@ -0,0 +1,41 @@
|
|||
#!/usr/bin/env perl
|
||||
|
||||
use strict;
|
||||
use warnings;
|
||||
|
||||
sub usage {
|
||||
die "Usage: $0 <ver1> <ver2>\n";
|
||||
}
|
||||
|
||||
my $a = shift or usage();
|
||||
my $b = shift or usage();
|
||||
|
||||
my @as = split /\./, $a;
|
||||
my @bs = split /\./, $b;
|
||||
|
||||
my $n = @as > @bs ? scalar(@as) : scalar(@bs);
|
||||
|
||||
for (my $i = 0; $i < $n; $i++) {
|
||||
my $x = $as[$i];
|
||||
my $y = $bs[$i];
|
||||
|
||||
if (!defined $x) {
|
||||
$x = 0;
|
||||
}
|
||||
|
||||
if (!defined $y) {
|
||||
$y = 0;
|
||||
}
|
||||
|
||||
if ($x > $y) {
|
||||
print "Y\n";
|
||||
exit;
|
||||
|
||||
} elsif ($x < $y) {
|
||||
print "N\n";
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
print "Y\n";
|
||||
|
||||
Loading…
Reference in a new issue