forked from openresty/lua-nginx-module
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathngx_http_lua_util.h
More file actions
180 lines (117 loc) · 5.95 KB
/
Copy pathngx_http_lua_util.h
File metadata and controls
180 lines (117 loc) · 5.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
/* vim:set ft=c ts=4 sw=4 et fdm=marker: */
#ifndef NGX_HTTP_LUA_UTIL_H
#define NGX_HTTP_LUA_UTIL_H
#include "ngx_http_lua_common.h"
#ifndef NGX_UNESCAPE_URI_COMPONENT
#define NGX_UNESCAPE_URI_COMPONENT 0
#endif
/* char whose address we use as the key in Lua vm registry for
* user code cache table */
extern char ngx_http_lua_code_cache_key;
/* char whose address we use as the key in Lua vm registry for
* all the "ngx.ctx" tables */
extern char ngx_http_lua_ctx_tables_key;
/* char whose address we use as the key in Lua vm registry for
* regex cache table */
extern char ngx_http_lua_regex_cache_key;
/* char whose address we use as the key in Lua vm registry for
* socket connection pool table */
extern char ngx_http_lua_socket_pool_key;
/* char whose address we use as the key for the nginx request pointer */
extern char ngx_http_lua_request_key;
/* char whose address we use as the key for the nginx config logger */
extern char ngx_http_lua_cf_log_key;
/* char whose address we use as the key for the coroutine parent relationship */
extern char ngx_http_lua_coroutine_parents_key;
/* coroutine anchoring table key in Lua VM registry */
extern char ngx_http_lua_coroutines_key;
/* key to the metatable for ngx.req.get_headers() */
extern char ngx_http_lua_req_get_headers_metatable_key;
#ifndef ngx_str_set
#define ngx_str_set(str, text) \
(str)->len = sizeof(text) - 1; (str)->data = (u_char *) text
#endif
#define ngx_http_lua_context_name(c) \
((c) == NGX_HTTP_LUA_CONTEXT_SET ? "set_by_lua*" \
: (c) == NGX_HTTP_LUA_CONTEXT_REWRITE ? "rewrite_by_lua*" \
: (c) == NGX_HTTP_LUA_CONTEXT_ACCESS ? "access_by_lua*" \
: (c) == NGX_HTTP_LUA_CONTEXT_CONTENT ? "content_by_lua*" \
: (c) == NGX_HTTP_LUA_CONTEXT_LOG ? "log_by_lua*" \
: (c) == NGX_HTTP_LUA_CONTEXT_HEADER_FILTER ? "header_filter_by_lua*" \
: "(unknown)")
#define ngx_http_lua_check_context(L, ctx, flags) \
if (!((ctx)->context & (flags))) { \
return luaL_error(L, "API disabled in the context of %s", \
ngx_http_lua_context_name((ctx)->context)); \
}
lua_State * ngx_http_lua_new_state(ngx_conf_t *cf,
ngx_http_lua_main_conf_t *lmcf);
lua_State * ngx_http_lua_new_thread(ngx_http_request_t *r, lua_State *l,
int *ref);
u_char * ngx_http_lua_rebase_path(ngx_pool_t *pool, u_char *src, size_t len);
ngx_int_t ngx_http_lua_send_header_if_needed(ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx);
ngx_int_t ngx_http_lua_send_chain_link(ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx, ngx_chain_t *cl);
void ngx_http_lua_discard_bufs(ngx_pool_t *pool, ngx_chain_t *in);
ngx_int_t ngx_http_lua_add_copy_chain(ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx, ngx_chain_t **chain, ngx_chain_t *in);
void ngx_http_lua_reset_ctx(ngx_http_request_t *r, lua_State *L,
ngx_http_lua_ctx_t *ctx);
void ngx_http_lua_generic_phase_post_read(ngx_http_request_t *r);
void ngx_http_lua_request_cleanup(void *data);
ngx_int_t ngx_http_lua_run_thread(lua_State *L, ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx, int nret);
ngx_int_t ngx_http_lua_wev_handler(ngx_http_request_t *r);
u_char * ngx_http_lua_digest_hex(u_char *dest, const u_char *buf,
int buf_len);
void ngx_http_lua_set_multi_value_table(lua_State *L, int index);
void ngx_http_lua_unescape_uri(u_char **dst, u_char **src, size_t size,
ngx_uint_t type);
uintptr_t ngx_http_lua_escape_uri(u_char *dst, u_char *src,
size_t size, ngx_uint_t type);
void ngx_http_lua_inject_req_api(ngx_log_t *log, lua_State *L);
void ngx_http_lua_process_args_option(ngx_http_request_t *r,
lua_State *L, int table, ngx_str_t *args);
ngx_int_t ngx_http_lua_open_and_stat_file(u_char *name,
ngx_open_file_info_t *of, ngx_log_t *log);
ngx_chain_t * ngx_http_lua_chains_get_free_buf(ngx_log_t *log, ngx_pool_t *p,
ngx_chain_t **free, size_t len, ngx_buf_tag_t tag);
void ngx_http_lua_create_new_global_table(lua_State *L, int narr, int nrec);
int ngx_http_lua_traceback(lua_State *L);
ngx_http_lua_co_ctx_t * ngx_http_lua_get_co_ctx(lua_State *L,
ngx_http_lua_ctx_t *ctx);
ngx_http_lua_co_ctx_t * ngx_http_lua_create_co_ctx(ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx);
ngx_int_t ngx_http_lua_run_posted_threads(ngx_connection_t *c, lua_State *L,
ngx_http_request_t *r, ngx_http_lua_ctx_t *ctx);
ngx_int_t ngx_http_lua_post_thread(ngx_http_request_t *r,
ngx_http_lua_ctx_t *ctx, ngx_http_lua_co_ctx_t *coctx);
void ngx_http_lua_del_thread(ngx_http_request_t *r, lua_State *L,
ngx_http_lua_ctx_t *ctx, ngx_http_lua_co_ctx_t *coctx);
void ngx_http_lua_rd_check_broken_connection(ngx_http_request_t *r);
ngx_int_t ngx_http_lua_test_expect(ngx_http_request_t *r);
ngx_int_t ngx_http_lua_check_broken_connection(ngx_http_request_t *r,
ngx_event_t *ev);
#define ngx_http_lua_check_if_abortable(L, ctx) \
if ((ctx)->no_abort) { \
return luaL_error(L, "attempt to abort with pending subrequests"); \
}
#define ngx_http_lua_init_ctx(ctx) \
ngx_memzero(ctx, sizeof(ngx_http_lua_ctx_t)); \
ctx->ctx_ref = LUA_NOREF; \
ctx->entry_co_ctx.co_ref = LUA_NOREF; \
ctx->resume_handler = ngx_http_lua_wev_handler;
static ngx_inline ngx_http_lua_ctx_t *
ngx_http_lua_create_ctx(ngx_http_request_t *r)
{
ngx_http_lua_ctx_t *ctx;
ctx = ngx_palloc(r->pool, sizeof(ngx_http_lua_ctx_t));
if (ctx == NULL) {
return NULL;
}
ngx_http_lua_init_ctx(ctx);
ngx_http_set_ctx(r, ctx, ngx_http_lua_module);
return ctx;
}
#endif /* NGX_HTTP_LUA_UTIL_H */