Skip to content

Commit 947fa00

Browse files
committed
change: retired the old CFunction API when newer FFI implementations are available.
1 parent 60736e6 commit 947fa00

Some content is hidden

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

43 files changed

+325
-5332
lines changed

config

-6
Original file line numberDiff line numberDiff line change
@@ -278,17 +278,14 @@ HTTP_LUA_DEPS=" \
278278
$ngx_addon_dir/src/ngx_http_lua_subrequest.h \
279279
$ngx_addon_dir/src/ngx_http_lua_ndk.h \
280280
$ngx_addon_dir/src/ngx_http_lua_control.h \
281-
$ngx_addon_dir/src/ngx_http_lua_time.h \
282281
$ngx_addon_dir/src/ngx_http_lua_string.h \
283282
$ngx_addon_dir/src/ngx_http_lua_misc.h \
284-
$ngx_addon_dir/src/ngx_http_lua_variable.h \
285283
$ngx_addon_dir/src/ngx_http_lua_output.h \
286284
$ngx_addon_dir/src/ngx_http_lua_headers.h \
287285
$ngx_addon_dir/src/ngx_http_lua_uri.h \
288286
$ngx_addon_dir/src/ngx_http_lua_req_body.h \
289287
$ngx_addon_dir/src/ngx_http_lua_args.h \
290288
$ngx_addon_dir/src/ngx_http_lua_ctx.h \
291-
$ngx_addon_dir/src/ngx_http_lua_regex.h \
292289
$ngx_addon_dir/src/ngx_http_lua_common.h \
293290
$ngx_addon_dir/src/ngx_http_lua_directive.h \
294291
$ngx_addon_dir/src/ngx_http_lua_headers_out.h \
@@ -316,13 +313,10 @@ HTTP_LUA_DEPS=" \
316313
$ngx_addon_dir/src/ngx_http_lua_initby.h \
317314
$ngx_addon_dir/src/ngx_http_lua_initworkerby.h \
318315
$ngx_addon_dir/src/ngx_http_lua_socket_udp.h \
319-
$ngx_addon_dir/src/ngx_http_lua_req_method.h \
320-
$ngx_addon_dir/src/ngx_http_lua_phase.h \
321316
$ngx_addon_dir/src/ngx_http_lua_probe.h \
322317
$ngx_addon_dir/src/ngx_http_lua_uthread.h \
323318
$ngx_addon_dir/src/ngx_http_lua_timer.h \
324319
$ngx_addon_dir/src/ngx_http_lua_config.h \
325-
$ngx_addon_dir/src/ngx_http_lua_worker.h \
326320
$ngx_addon_dir/src/ngx_http_lua_ssl_certby.h \
327321
$ngx_addon_dir/src/ngx_http_lua_lex.h \
328322
$ngx_addon_dir/src/ngx_http_lua_balancer.h \

src/ngx_http_lua_args.c

-67
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717

1818
static int ngx_http_lua_ngx_req_set_uri_args(lua_State *L);
19-
static int ngx_http_lua_ngx_req_get_uri_args(lua_State *L);
2019
static int ngx_http_lua_ngx_req_get_post_args(lua_State *L);
2120

2221

@@ -80,64 +79,6 @@ ngx_http_lua_ngx_req_set_uri_args(lua_State *L)
8079
}
8180

8281

83-
static int
84-
ngx_http_lua_ngx_req_get_uri_args(lua_State *L)
85-
{
86-
ngx_http_request_t *r;
87-
u_char *buf;
88-
u_char *last;
89-
int retval;
90-
int n;
91-
int max;
92-
93-
n = lua_gettop(L);
94-
95-
if (n != 0 && n != 1) {
96-
return luaL_error(L, "expecting 0 or 1 arguments but seen %d", n);
97-
}
98-
99-
if (n == 1) {
100-
max = luaL_checkinteger(L, 1);
101-
lua_pop(L, 1);
102-
103-
} else {
104-
max = NGX_HTTP_LUA_MAX_ARGS;
105-
}
106-
107-
r = ngx_http_lua_get_req(L);
108-
if (r == NULL) {
109-
return luaL_error(L, "no request object found");
110-
}
111-
112-
ngx_http_lua_check_fake_request(L, r);
113-
114-
if (r->args.len == 0) {
115-
lua_createtable(L, 0, 0);
116-
return 1;
117-
}
118-
119-
/* we copy r->args over to buf to simplify
120-
* unescaping query arg keys and values */
121-
122-
buf = ngx_palloc(r->pool, r->args.len);
123-
if (buf == NULL) {
124-
return luaL_error(L, "no memory");
125-
}
126-
127-
lua_createtable(L, 0, 4);
128-
129-
ngx_memcpy(buf, r->args.data, r->args.len);
130-
131-
last = buf + r->args.len;
132-
133-
retval = ngx_http_lua_parse_args(L, buf, last, max);
134-
135-
ngx_pfree(r->pool, buf);
136-
137-
return retval;
138-
}
139-
140-
14182
static int
14283
ngx_http_lua_ngx_req_get_post_args(lua_State *L)
14384
{
@@ -368,18 +309,11 @@ ngx_http_lua_inject_req_args_api(lua_State *L)
368309
lua_pushcfunction(L, ngx_http_lua_ngx_req_set_uri_args);
369310
lua_setfield(L, -2, "set_uri_args");
370311

371-
lua_pushcfunction(L, ngx_http_lua_ngx_req_get_uri_args);
372-
lua_setfield(L, -2, "get_uri_args");
373-
374-
lua_pushcfunction(L, ngx_http_lua_ngx_req_get_uri_args);
375-
lua_setfield(L, -2, "get_query_args"); /* deprecated */
376-
377312
lua_pushcfunction(L, ngx_http_lua_ngx_req_get_post_args);
378313
lua_setfield(L, -2, "get_post_args");
379314
}
380315

381316

382-
#ifndef NGX_LUA_NO_FFI_API
383317
size_t
384318
ngx_http_lua_ffi_req_get_querystring_len(ngx_http_request_t *r)
385319
{
@@ -549,7 +483,6 @@ ngx_http_lua_ffi_req_get_uri_args(ngx_http_request_t *r, u_char *buf,
549483

550484
return i;
551485
}
552-
#endif /* NGX_LUA_NO_FFI_API */
553486

554487

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

src/ngx_http_lua_balancer.c

+2-3
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,6 @@ ngx_http_lua_balancer_save_session(ngx_peer_connection_t *pc, void *data)
457457
#endif
458458

459459

460-
#ifndef NGX_LUA_NO_FFI_API
461-
462460
int
463461
ngx_http_lua_ffi_balancer_set_current_peer(ngx_http_request_t *r,
464462
const u_char *addr, size_t addr_len, int port, char **err)
@@ -754,4 +752,5 @@ ngx_http_lua_ffi_balancer_get_last_failure(ngx_http_request_t *r,
754752
return bp->last_peer_state;
755753
}
756754

757-
#endif /* NGX_LUA_NO_FFI_API */
755+
756+
/* vi:set ft=c ts=4 sw=4 et fdm=marker: */

src/ngx_http_lua_bodyfilterby.c

-3
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,9 @@
1515
#include "ngx_http_lua_exception.h"
1616
#include "ngx_http_lua_util.h"
1717
#include "ngx_http_lua_pcrefix.h"
18-
#include "ngx_http_lua_time.h"
1918
#include "ngx_http_lua_log.h"
20-
#include "ngx_http_lua_regex.h"
2119
#include "ngx_http_lua_cache.h"
2220
#include "ngx_http_lua_headers.h"
23-
#include "ngx_http_lua_variable.h"
2421
#include "ngx_http_lua_string.h"
2522
#include "ngx_http_lua_misc.h"
2623
#include "ngx_http_lua_consts.h"

src/ngx_http_lua_common.h

-2
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,8 @@ typedef struct {
140140
#define NGX_HTTP_LUA_CONTEXT_SSL_SESS_FETCH 0x1000
141141

142142

143-
#ifndef NGX_LUA_NO_FFI_API
144143
#define NGX_HTTP_LUA_FFI_NO_REQ_CTX -100
145144
#define NGX_HTTP_LUA_FFI_BAD_CONTEXT -101
146-
#endif
147145

148146

149147
#if (NGX_PTR_SIZE >= 8 && !defined(_WIN64))

src/ngx_http_lua_control.c

+1-113
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818

1919
static int ngx_http_lua_ngx_exec(lua_State *L);
2020
static int ngx_http_lua_ngx_redirect(lua_State *L);
21-
static int ngx_http_lua_ngx_exit(lua_State *L);
2221
static int ngx_http_lua_on_abort(lua_State *L);
2322

2423

@@ -35,14 +34,6 @@ ngx_http_lua_inject_control_api(ngx_log_t *log, lua_State *L)
3534
lua_pushcfunction(L, ngx_http_lua_ngx_exec);
3635
lua_setfield(L, -2, "exec");
3736

38-
lua_pushcfunction(L, ngx_http_lua_ngx_exit);
39-
lua_setfield(L, -2, "throw_error"); /* deprecated */
40-
41-
/* ngx.exit */
42-
43-
lua_pushcfunction(L, ngx_http_lua_ngx_exit);
44-
lua_setfield(L, -2, "exit");
45-
4637
/* ngx.on_abort */
4738

4839
lua_pushcfunction(L, ngx_http_lua_on_abort);
@@ -297,108 +288,6 @@ ngx_http_lua_ngx_redirect(lua_State *L)
297288
}
298289

299290

300-
static int
301-
ngx_http_lua_ngx_exit(lua_State *L)
302-
{
303-
ngx_int_t rc;
304-
ngx_http_request_t *r;
305-
ngx_http_lua_ctx_t *ctx;
306-
307-
if (lua_gettop(L) != 1) {
308-
return luaL_error(L, "expecting one argument");
309-
}
310-
311-
r = ngx_http_lua_get_req(L);
312-
if (r == NULL) {
313-
return luaL_error(L, "no request object found");
314-
}
315-
316-
ctx = ngx_http_get_module_ctx(r, ngx_http_lua_module);
317-
if (ctx == NULL) {
318-
return luaL_error(L, "no request ctx found");
319-
}
320-
321-
ngx_http_lua_check_context(L, ctx, NGX_HTTP_LUA_CONTEXT_REWRITE
322-
| NGX_HTTP_LUA_CONTEXT_ACCESS
323-
| NGX_HTTP_LUA_CONTEXT_CONTENT
324-
| NGX_HTTP_LUA_CONTEXT_TIMER
325-
| NGX_HTTP_LUA_CONTEXT_HEADER_FILTER
326-
| NGX_HTTP_LUA_CONTEXT_BALANCER
327-
| NGX_HTTP_LUA_CONTEXT_SSL_CERT
328-
| NGX_HTTP_LUA_CONTEXT_SSL_SESS_STORE
329-
| NGX_HTTP_LUA_CONTEXT_SSL_SESS_FETCH);
330-
331-
rc = (ngx_int_t) luaL_checkinteger(L, 1);
332-
333-
if (ctx->context & (NGX_HTTP_LUA_CONTEXT_SSL_CERT
334-
| NGX_HTTP_LUA_CONTEXT_SSL_SESS_STORE
335-
| NGX_HTTP_LUA_CONTEXT_SSL_SESS_FETCH))
336-
{
337-
338-
#if (NGX_HTTP_SSL)
339-
340-
ctx->exit_code = rc;
341-
ctx->exited = 1;
342-
343-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
344-
"lua exit with code %i", rc);
345-
346-
if (ctx->context == NGX_HTTP_LUA_CONTEXT_SSL_SESS_STORE) {
347-
return 0;
348-
}
349-
350-
return lua_yield(L, 0);
351-
352-
#else
353-
354-
return luaL_error(L, "no SSL support");
355-
356-
#endif
357-
}
358-
359-
if (ctx->no_abort
360-
&& rc != NGX_ERROR
361-
&& rc != NGX_HTTP_CLOSE
362-
&& rc != NGX_HTTP_REQUEST_TIME_OUT
363-
&& rc != NGX_HTTP_CLIENT_CLOSED_REQUEST)
364-
{
365-
return luaL_error(L, "attempt to abort with pending subrequests");
366-
}
367-
368-
if ((r->header_sent || ctx->header_sent)
369-
&& rc >= NGX_HTTP_SPECIAL_RESPONSE
370-
&& rc != NGX_HTTP_REQUEST_TIME_OUT
371-
&& rc != NGX_HTTP_CLIENT_CLOSED_REQUEST
372-
&& rc != NGX_HTTP_CLOSE)
373-
{
374-
if (rc != (ngx_int_t) r->headers_out.status) {
375-
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0, "attempt to "
376-
"set status %i via ngx.exit after sending out the "
377-
"response status %ui", rc, r->headers_out.status);
378-
}
379-
380-
rc = NGX_HTTP_OK;
381-
}
382-
383-
dd("setting exit code: %d", (int) rc);
384-
385-
ctx->exit_code = rc;
386-
ctx->exited = 1;
387-
388-
ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0,
389-
"lua exit with code %i", ctx->exit_code);
390-
391-
if (ctx->context & (NGX_HTTP_LUA_CONTEXT_HEADER_FILTER
392-
| NGX_HTTP_LUA_CONTEXT_BALANCER))
393-
{
394-
return 0;
395-
}
396-
397-
dd("calling yield");
398-
return lua_yield(L, 0);
399-
}
400-
401-
402291
static int
403292
ngx_http_lua_on_abort(lua_State *L)
404293
{
@@ -457,7 +346,6 @@ ngx_http_lua_on_abort(lua_State *L)
457346
}
458347

459348

460-
#ifndef NGX_LUA_NO_FFI_API
461349
int
462350
ngx_http_lua_ffi_exit(ngx_http_request_t *r, int status, u_char *err,
463351
size_t *errlen)
@@ -553,6 +441,6 @@ ngx_http_lua_ffi_exit(ngx_http_request_t *r, int status, u_char *err,
553441

554442
return NGX_OK;
555443
}
556-
#endif /* NGX_LUA_NO_FFI_API */
444+
557445

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

0 commit comments

Comments
 (0)