Skip to content

Commit 44f68b9

Browse files
committed
synchronized with meta-lua-nginx-module #dcedde8.
1 parent e94dd3f commit 44f68b9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2203
-5406
lines changed

config

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ NGX_ADDON_SRCS="$NGX_ADDON_SRCS \
344344
$ngx_addon_dir/src/ngx_stream_lua_semaphore.c \
345345
$ngx_addon_dir/src/ngx_stream_lua_ssl_certby.c \
346346
$ngx_addon_dir/src/ngx_stream_lua_log_ringbuf.c \
347+
$ngx_addon_dir/src/ngx_stream_lua_input_filters.c \
347348
"
348349

349350
NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
@@ -362,20 +363,16 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
362363
$ngx_addon_dir/src/ngx_stream_lua_output.h \
363364
$ngx_addon_dir/src/ngx_stream_lua_consts.h \
364365
$ngx_addon_dir/src/ngx_stream_lua_log.h \
365-
$ngx_addon_dir/src/ngx_stream_lua_time.h \
366366
$ngx_addon_dir/src/ngx_stream_lua_string.h \
367367
$ngx_addon_dir/src/ngx_stream_lua_control.h \
368368
$ngx_addon_dir/src/ngx_stream_lua_sleep.h \
369369
$ngx_addon_dir/src/ngx_stream_lua_phase.h \
370370
$ngx_addon_dir/src/ngx_stream_lua_ctx.h \
371-
$ngx_addon_dir/src/ngx_stream_lua_regex.h \
372371
$ngx_addon_dir/src/ngx_stream_lua_script.h \
373372
$ngx_addon_dir/src/ngx_stream_lua_shdict.h \
374-
$ngx_addon_dir/src/ngx_stream_lua_variable.h \
375373
$ngx_addon_dir/src/ngx_stream_lua_timer.h \
376374
$ngx_addon_dir/src/ngx_stream_lua_config.h \
377375
$ngx_addon_dir/src/api/ngx_stream_lua_api.h \
378-
$ngx_addon_dir/src/ngx_stream_lua_worker.h \
379376
$ngx_addon_dir/src/ngx_stream_lua_misc.h \
380377
$ngx_addon_dir/src/ngx_stream_lua_initby.h \
381378
$ngx_addon_dir/src/ngx_stream_lua_initworkerby.h \
@@ -389,6 +386,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
389386
$ngx_addon_dir/src/ngx_stream_lua_semaphore.h \
390387
$ngx_addon_dir/src/ngx_stream_lua_ssl_certby.h \
391388
$ngx_addon_dir/src/ngx_stream_lua_log_ringbuf.h \
389+
$ngx_addon_dir/src/ngx_stream_lua_input_filters.h \
392390
"
393391

394392
ngx_feature="export symbols by default (-E)"

src/api/ngx_stream_lua_api.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ typedef struct {
4444
} ngx_stream_lua_value_t;
4545

4646

47+
typedef struct {
48+
int len;
49+
/* this padding hole on 64-bit systems is expected */
50+
u_char *data;
51+
} ngx_stream_lua_ffi_str_t;
52+
53+
4754
lua_State *ngx_stream_lua_get_global_state(ngx_conf_t *cf);
4855

4956
ngx_stream_lua_request_t *ngx_stream_lua_get_request(lua_State *L);
@@ -54,7 +61,8 @@ ngx_int_t ngx_stream_lua_add_package_preload(ngx_conf_t *cf,
5461
ngx_int_t ngx_stream_lua_shared_dict_get(ngx_shm_zone_t *shm_zone,
5562
u_char *key_data, size_t key_len, ngx_stream_lua_value_t *value);
5663

57-
ngx_shm_zone_t *ngx_stream_lua_find_zone(u_char *name_data, size_t name_len);
64+
ngx_shm_zone_t *ngx_stream_lua_find_zone(u_char *name_data,
65+
size_t name_len);
5866

5967
ngx_shm_zone_t *ngx_stream_lua_shared_memory_add(ngx_conf_t *cf,
6068
ngx_str_t *name, size_t size, void *tag);

src/ngx_stream_lua_api.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ ngx_stream_lua_add_package_preload(ngx_conf_t *cf, const char *package,
9393

9494

9595
ngx_shm_zone_t *
96-
ngx_stream_lua_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name, size_t size,
97-
void *tag)
96+
ngx_stream_lua_shared_memory_add(ngx_conf_t *cf, ngx_str_t *name,
97+
size_t size, void *tag)
9898
{
9999
ngx_stream_lua_main_conf_t *lmcf;
100100
ngx_stream_lua_shm_zone_ctx_t *ctx;

src/ngx_stream_lua_args.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ ngx_stream_lua_parse_args(lua_State *L, u_char *buf, u_char *last, int max)
104104
}
105105

106106
if (max > 0 && ++count == max) {
107-
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
108-
"lua hit query args limit %d", max);
107+
lua_pushliteral(L, "truncated");
109108

110-
return 1;
109+
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
110+
"stream lua hit query args limit %d",
111+
max);
112+
return 2;
111113
}
112114

113115
} else {

src/ngx_stream_lua_balancer.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,6 @@ ngx_stream_lua_balancer_save_session(ngx_peer_connection_t *pc, void *data)
505505
#endif
506506

507507

508-
509508
int
510509
ngx_stream_lua_ffi_balancer_set_current_peer(ngx_stream_lua_request_t *r,
511510
const u_char *addr, size_t addr_len, int port, char **err)
@@ -648,7 +647,7 @@ ngx_stream_lua_ffi_balancer_set_more_tries(ngx_stream_lua_request_t *r,
648647
int count, char **err)
649648
{
650649
#if (HAS_NGX_STREAM_PROXY_GET_NEXT_UPSTREAM_TRIES_PATCH)
651-
ngx_uint_t max_tries, total;
650+
ngx_uint_t max_tries, total;
652651
#endif
653652
ngx_stream_lua_ctx_t *ctx;
654653
ngx_stream_upstream_t *u;
@@ -752,3 +751,5 @@ ngx_stream_lua_ffi_balancer_get_last_failure(ngx_stream_lua_request_t *r,
752751
return bp->last_peer_state;
753752
}
754753

754+
755+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_stream_lua_cache.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ ngx_stream_lua_cache_loadbuffer(ngx_log_t *log, lua_State *L,
164164

165165
n = lua_gettop(L);
166166

167-
dd("XXX cache key: [%s]", cache_key);
167+
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, log, 0,
168+
"looking up Lua code cache with key '%s'", cache_key);
168169

169170
rc = ngx_stream_lua_cache_load_code(log, L, (char *) cache_key);
170171
if (rc == NGX_OK) {
@@ -248,7 +249,8 @@ ngx_stream_lua_cache_loadfile(ngx_log_t *log, lua_State *L,
248249
dd("CACHE file key already pre-calculated");
249250
}
250251

251-
dd("XXX cache key for file: [%s]", cache_key);
252+
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, log, 0,
253+
"looking up Lua code cache with key '%s'", cache_key);
252254

253255
rc = ngx_stream_lua_cache_load_code(log, L, (char *) cache_key);
254256
if (rc == NGX_OK) {

src/ngx_stream_lua_common.h

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
#define _NGX_STREAM_LUA_COMMON_H_INCLUDED_
1818

1919

20-
#ifndef NGX_LUA_NO_FFI_API
21-
#define NGX_LUA_NO_FFI_API
22-
#endif
23-
24-
2520
#include <nginx.h>
2621
#include <ngx_core.h>
2722
#include <ngx_stream.h>
@@ -51,7 +46,7 @@
5146
#endif
5247

5348

54-
#if !defined(nginx_version) || (nginx_version < 1013006)
49+
#if !defined(nginx_version) || nginx_version < 1013006
5550
#error at least nginx 1.13.6 is required but found an older version
5651
#endif
5752

@@ -63,13 +58,20 @@
6358
#endif
6459

6560

61+
#if !defined(LUAJIT_VERSION_NUM) || (LUAJIT_VERSION_NUM < 20000)
62+
# error unsupported LuaJIT version
63+
#endif
64+
65+
6666
#if (!defined OPENSSL_NO_OCSP && defined SSL_CTRL_SET_TLSEXT_STATUS_REQ_CB)
6767
# define NGX_STREAM_LUA_USE_OCSP 1
6868
#endif
6969

7070

71+
72+
7173
#ifndef NGX_HAVE_SHA1
72-
# if (nginx_version >= 1011002)
74+
# if defined(nginx_version) && nginx_version >= 1011002
7375
# define NGX_HAVE_SHA1 1
7476
# endif
7577
#endif
@@ -129,10 +131,8 @@
129131
#define NGX_STREAM_LUA_CONTEXT_SSL_CERT 0x0040
130132

131133

132-
#ifndef NGX_LUA_NO_FFI_API
133134
#define NGX_STREAM_LUA_FFI_NO_REQ_CTX -100
134135
#define NGX_STREAM_LUA_FFI_BAD_CONTEXT -101
135-
#endif
136136

137137

138138
#if (NGX_PTR_SIZE >= 8 && !defined(_WIN64))
@@ -178,8 +178,6 @@ struct ngx_stream_lua_main_conf_s {
178178
ngx_cycle_t *cycle;
179179
ngx_pool_t *pool;
180180

181-
ngx_flag_t load_resty_core;
182-
183181
ngx_int_t max_pending_timers;
184182
ngx_int_t pending_timers;
185183

@@ -389,6 +387,13 @@ struct ngx_stream_lua_co_ctx_s {
389387
the ngx.thread.spawn()
390388
call */
391389
unsigned sem_resume_status:1;
390+
391+
unsigned is_wrap:1; /* set when creating coroutines via
392+
coroutine.wrap */
393+
394+
unsigned propagate_error:1; /* set when propagating an error
395+
from a coroutine to its
396+
parent */
392397
};
393398

394399

src/ngx_stream_lua_control.c

Lines changed: 6 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,13 @@
2626

2727

2828

29-
static int ngx_stream_lua_ngx_exit(lua_State *L);
3029
static int ngx_stream_lua_on_abort(lua_State *L);
3130

3231

3332
void
3433
ngx_stream_lua_inject_control_api(ngx_log_t *log, lua_State *L)
3534
{
3635

37-
/* ngx.exit */
38-
39-
lua_pushcfunction(L, ngx_stream_lua_ngx_exit);
40-
lua_setfield(L, -2, "exit");
41-
4236
/* ngx.on_abort */
4337

4438
lua_pushcfunction(L, ngx_stream_lua_on_abort);
@@ -48,75 +42,6 @@ ngx_stream_lua_inject_control_api(ngx_log_t *log, lua_State *L)
4842

4943

5044

51-
static int
52-
ngx_stream_lua_ngx_exit(lua_State *L)
53-
{
54-
ngx_int_t rc;
55-
ngx_stream_lua_request_t *r;
56-
ngx_stream_lua_ctx_t *ctx;
57-
58-
if (lua_gettop(L) != 1) {
59-
return luaL_error(L, "expecting one argument");
60-
}
61-
62-
r = ngx_stream_lua_get_req(L);
63-
if (r == NULL) {
64-
return luaL_error(L, "no request object found");
65-
}
66-
67-
ctx = ngx_stream_lua_get_module_ctx(r, ngx_stream_lua_module);
68-
if (ctx == NULL) {
69-
return luaL_error(L, "no request ctx found");
70-
}
71-
72-
ngx_stream_lua_check_context(L, ctx, NGX_STREAM_LUA_CONTEXT_CONTENT
73-
| NGX_STREAM_LUA_CONTEXT_TIMER
74-
| NGX_STREAM_LUA_CONTEXT_BALANCER
75-
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
76-
| NGX_STREAM_LUA_CONTEXT_PREREAD
77-
);
78-
79-
rc = (ngx_int_t) luaL_checkinteger(L, 1);
80-
81-
if (ctx->context & NGX_STREAM_LUA_CONTEXT_SSL_CERT)
82-
{
83-
84-
#if (NGX_STREAM_SSL)
85-
86-
ctx->exit_code = rc;
87-
ctx->exited = 1;
88-
89-
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
90-
"lua exit with code %i", rc);
91-
92-
93-
return lua_yield(L, 0);
94-
95-
#else
96-
97-
return luaL_error(L, "no SSL support");
98-
99-
#endif
100-
}
101-
102-
103-
dd("setting exit code: %d", (int) rc);
104-
105-
ctx->exit_code = rc;
106-
ctx->exited = 1;
107-
108-
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
109-
"lua exit with code %i", ctx->exit_code);
110-
111-
if (ctx->context & NGX_STREAM_LUA_CONTEXT_BALANCER) {
112-
return 0;
113-
}
114-
115-
dd("calling yield");
116-
return lua_yield(L, 0);
117-
}
118-
119-
12045
static int
12146
ngx_stream_lua_on_abort(lua_State *L)
12247
{
@@ -175,7 +100,6 @@ ngx_stream_lua_on_abort(lua_State *L)
175100
}
176101

177102

178-
#ifndef NGX_LUA_NO_FFI_API
179103
int
180104
ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
181105
size_t *errlen)
@@ -188,24 +112,19 @@ ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
188112
return NGX_ERROR;
189113
}
190114

191-
if (ngx_stream_lua_ffi_check_context(ctx, NGX_STREAM_LUA_CONTEXT_REWRITE
192-
| NGX_STREAM_LUA_CONTEXT_ACCESS
193-
| NGX_STREAM_LUA_CONTEXT_CONTENT
115+
116+
if (ngx_stream_lua_ffi_check_context(ctx, NGX_STREAM_LUA_CONTEXT_CONTENT
194117
| NGX_STREAM_LUA_CONTEXT_TIMER
195-
| NGX_STREAM_LUA_CONTEXT_HEADER_FILTER
196118
| NGX_STREAM_LUA_CONTEXT_BALANCER
197119
| NGX_STREAM_LUA_CONTEXT_SSL_CERT
198-
| NGX_STREAM_LUA_CONTEXT_SSL_SESS_STORE
199-
| NGX_STREAM_LUA_CONTEXT_SSL_SESS_FETCH,
120+
| NGX_STREAM_LUA_CONTEXT_PREREAD,
200121
err, errlen)
201122
!= NGX_OK)
202123
{
203124
return NGX_ERROR;
204125
}
205126

206-
if (ctx->context & (NGX_STREAM_LUA_CONTEXT_SSL_CERT
207-
| NGX_STREAM_LUA_CONTEXT_SSL_SESS_STORE
208-
| NGX_STREAM_LUA_CONTEXT_SSL_SESS_FETCH))
127+
if (ctx->context & NGX_STREAM_LUA_CONTEXT_SSL_CERT)
209128
{
210129

211130
#if (NGX_STREAM_SSL)
@@ -216,9 +135,6 @@ ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
216135
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
217136
"lua exit with code %d", status);
218137

219-
if (ctx->context == NGX_STREAM_LUA_CONTEXT_SSL_SESS_STORE) {
220-
return NGX_DONE;
221-
}
222138

223139
return NGX_OK;
224140

@@ -236,14 +152,12 @@ ngx_stream_lua_ffi_exit(ngx_stream_lua_request_t *r, int status, u_char *err,
236152
ngx_log_debug1(NGX_LOG_DEBUG_STREAM, r->connection->log, 0,
237153
"lua exit with code %i", ctx->exit_code);
238154

239-
if (ctx->context & (NGX_STREAM_LUA_CONTEXT_HEADER_FILTER
240-
| NGX_STREAM_LUA_CONTEXT_BALANCER))
241-
{
155+
if (ctx->context & NGX_STREAM_LUA_CONTEXT_BALANCER) {
242156
return NGX_DONE;
243157
}
244158

245159
return NGX_OK;
246160
}
247-
#endif /* NGX_LUA_NO_FFI_API */
161+
248162

249163
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

0 commit comments

Comments
 (0)