Skip to content

Commit 9563dd1

Browse files
committed
synchronized with meta-lua-module #cc7e764.
1 parent 72e9306 commit 9563dd1

21 files changed

+1532
-636
lines changed

config

Lines changed: 2 additions & 0 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 \
@@ -389,6 +390,7 @@ NGX_ADDON_DEPS="$NGX_ADDON_DEPS \
389390
$ngx_addon_dir/src/ngx_stream_lua_semaphore.h \
390391
$ngx_addon_dir/src/ngx_stream_lua_ssl_certby.h \
391392
$ngx_addon_dir/src/ngx_stream_lua_log_ringbuf.h \
393+
$ngx_addon_dir/src/ngx_stream_lua_input_filters.h \
392394
"
393395

394396
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ ngx_stream_lua_ffi_balancer_set_more_tries(ngx_stream_lua_request_t *r,
648648
int count, char **err)
649649
{
650650
#if (HAS_NGX_STREAM_PROXY_GET_NEXT_UPSTREAM_TRIES_PATCH)
651-
ngx_uint_t max_tries, total;
651+
ngx_uint_t max_tries, total;
652652
#endif
653653
ngx_stream_lua_ctx_t *ctx;
654654
ngx_stream_upstream_t *u;

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_directive.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -748,11 +748,12 @@ ngx_stream_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
748748

749749
found:
750750

751-
ngx_snprintf(out, len, "=%*s(%*s:%d)%Z",
752-
tag_len, tag, cf->conf_file->file.name.data
753-
+ cf->conf_file->file.name.len - p,
754-
p, cf->conf_file->line);
755-
*chunkname_len = len;
751+
p = ngx_snprintf(out, len, "=%*s(%*s:%d)%Z",
752+
tag_len, tag, cf->conf_file->file.name.data
753+
+ cf->conf_file->file.name.len - p,
754+
p, cf->conf_file->line);
755+
756+
*chunkname_len = p - out - 1; /* exclude the trailing '\0' byte */
756757

757758
return out;
758759
}

src/ngx_stream_lua_initworkerby.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "ngx_stream_lua_contentby.h"
2525

2626

27+
2728
static u_char *ngx_stream_lua_log_init_worker_error(ngx_log_t *log,
2829
u_char *buf, size_t len);
2930

@@ -68,6 +69,8 @@ ngx_stream_lua_init_worker(ngx_cycle_t *cycle)
6869
# endif
6970
)
7071
{
72+
/* disable init_worker_by_lua* and destroy lua VM in cache processes */
73+
7174
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, ngx_cycle->log, 0,
7275
"lua close the global Lua VM %p in the "
7376
"cache helper process %P", lmcf->lua, ngx_pid);
@@ -77,9 +80,11 @@ ngx_stream_lua_init_worker(ngx_cycle_t *cycle)
7780

7881
return NGX_OK;
7982
}
83+
84+
8085
#endif /* NGX_WIN32 */
8186

82-
#if NGX_STREAM_LUA_HAVE_SA_RESTART
87+
#if (NGX_STREAM_LUA_HAVE_SA_RESTART)
8388
if (lmcf->set_sa_restart) {
8489
ngx_stream_lua_set_sa_restart(ngx_cycle->log);
8590
}

src/ngx_stream_lua_input_filters.c

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
2+
/*
3+
* !!! DO NOT EDIT DIRECTLY !!!
4+
* This file was automatically generated from the following template:
5+
*
6+
* src/subsys/ngx_subsys_lua_input_filters.c.tt2
7+
*/
8+
9+
10+
/*
11+
* Copyright (C) by OpenResty Inc.
12+
*/
13+
14+
15+
#ifndef DDEBUG
16+
#define DDEBUG 0
17+
#endif
18+
#include "ddebug.h"
19+
20+
21+
#include "ngx_stream_lua_common.h"
22+
23+
24+
ngx_int_t
25+
ngx_stream_lua_read_bytes(ngx_buf_t *src, ngx_chain_t *buf_in,
26+
size_t *rest, ssize_t bytes, ngx_log_t *log)
27+
{
28+
if (bytes == 0) {
29+
return NGX_ERROR;
30+
}
31+
32+
if ((size_t) bytes >= *rest) {
33+
34+
buf_in->buf->last += *rest;
35+
src->pos += *rest;
36+
*rest = 0;
37+
38+
return NGX_OK;
39+
}
40+
41+
/* bytes < *rest */
42+
43+
buf_in->buf->last += bytes;
44+
src->pos += bytes;
45+
*rest -= bytes;
46+
47+
return NGX_AGAIN;
48+
}
49+
50+
51+
ngx_int_t
52+
ngx_stream_lua_read_all(ngx_buf_t *src, ngx_chain_t *buf_in,
53+
ssize_t bytes, ngx_log_t *log)
54+
{
55+
if (bytes == 0) {
56+
return NGX_OK;
57+
}
58+
59+
buf_in->buf->last += bytes;
60+
src->pos += bytes;
61+
62+
return NGX_AGAIN;
63+
}
64+
65+
66+
ngx_int_t
67+
ngx_stream_lua_read_any(ngx_buf_t *src, ngx_chain_t *buf_in, size_t *max,
68+
ssize_t bytes, ngx_log_t *log)
69+
{
70+
if (bytes == 0) {
71+
return NGX_ERROR;
72+
}
73+
74+
if (bytes >= (ssize_t) *max) {
75+
bytes = (ssize_t) *max;
76+
}
77+
78+
buf_in->buf->last += bytes;
79+
src->pos += bytes;
80+
81+
return NGX_OK;
82+
}
83+
84+
85+
ngx_int_t
86+
ngx_stream_lua_read_line(ngx_buf_t *src, ngx_chain_t *buf_in,
87+
ssize_t bytes, ngx_log_t *log)
88+
{
89+
u_char *dst;
90+
u_char c;
91+
#if (NGX_DEBUG)
92+
u_char *begin;
93+
#endif
94+
95+
#if (NGX_DEBUG)
96+
begin = src->pos;
97+
#endif
98+
99+
if (bytes == 0) {
100+
return NGX_ERROR;
101+
}
102+
103+
dd("already read: %p: %.*s", buf_in,
104+
(int) (buf_in->buf->last - buf_in->buf->pos), buf_in->buf->pos);
105+
106+
dd("data read: %.*s", (int) bytes, src->pos);
107+
108+
dst = buf_in->buf->last;
109+
110+
while (bytes--) {
111+
112+
c = *src->pos++;
113+
114+
switch (c) {
115+
case '\n':
116+
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, log, 0,
117+
"stream lua read the final line part: "
118+
"\"%*s\"", src->pos - 1 - begin, begin);
119+
120+
buf_in->buf->last = dst;
121+
122+
dd("read a line: %p: %.*s", buf_in,
123+
(int) (buf_in->buf->last - buf_in->buf->pos), buf_in->buf->pos);
124+
125+
return NGX_OK;
126+
127+
case '\r':
128+
/* ignore it */
129+
break;
130+
131+
default:
132+
*dst++ = c;
133+
break;
134+
}
135+
}
136+
137+
#if (NGX_DEBUG)
138+
ngx_log_debug2(NGX_LOG_DEBUG_STREAM, log, 0,
139+
"stream lua read partial line data: %*s",
140+
dst - begin, begin);
141+
#endif
142+
143+
buf_in->buf->last = dst;
144+
145+
return NGX_AGAIN;
146+
}

src/ngx_stream_lua_input_filters.h

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
/*
3+
* !!! DO NOT EDIT DIRECTLY !!!
4+
* This file was automatically generated from the following template:
5+
*
6+
* src/subsys/ngx_subsys_lua_input_filters.h.tt2
7+
*/
8+
9+
10+
/*
11+
* Copyright (C) by OpenResty Inc.
12+
*/
13+
14+
15+
#ifndef _NGX_STREAM_LUA_INPUT_FILTERS_H_INCLUDED_
16+
#define _NGX_STREAM_LUA_INPUT_FILTERS_H_INCLUDED_
17+
18+
19+
#include "ngx_stream_lua_common.h"
20+
21+
22+
ngx_int_t ngx_stream_lua_read_bytes(ngx_buf_t *src, ngx_chain_t *buf_in,
23+
size_t *rest, ssize_t bytes, ngx_log_t *log);
24+
25+
ngx_int_t ngx_stream_lua_read_all(ngx_buf_t *src, ngx_chain_t *buf_in,
26+
ssize_t bytes, ngx_log_t *log);
27+
28+
ngx_int_t ngx_stream_lua_read_any(ngx_buf_t *src, ngx_chain_t *buf_in,
29+
size_t *max, ssize_t bytes, ngx_log_t *log);
30+
31+
ngx_int_t ngx_stream_lua_read_line(ngx_buf_t *src, ngx_chain_t *buf_in,
32+
ssize_t bytes, ngx_log_t *log);
33+
34+
35+
#endif /* _NGX_STREAM_LUA_INPUT_FILTERS_H_INCLUDED_ */
36+
37+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

0 commit comments

Comments
 (0)