2222#include <lauxlib.h>
2323
2424
25- #if (NGX_PCRE )
26-
27- #include <pcre.h>
25+ #if defined(NDK ) && NDK
26+ #include <ndk.h>
2827
29- #if (PCRE_MAJOR > 8 ) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21 )
30- # define LUA_HAVE_PCRE_JIT 1
31- #else
32- # define LUA_HAVE_PCRE_JIT 0
28+ typedef struct {
29+ size_t size ;
30+ int ref ;
31+ u_char * key ;
32+ ngx_str_t script ;
33+ } ngx_http_lua_set_var_data_t ;
3334#endif
3435
36+
37+ #ifdef NGX_LUA_USE_ASSERT
38+ #include <assert.h>
39+ # define ngx_http_lua_assert (a ) assert(a)
40+ #else
41+ # define ngx_http_lua_assert (a )
3542#endif
3643
3744
38- #if !defined(nginx_version ) || (nginx_version < 1006000 )
39- #error at least nginx 1.6.0 is required but found an older version
45+ #if (NGX_PCRE )
46+ #include <pcre.h>
47+ # if (PCRE_MAJOR > 8 ) || (PCRE_MAJOR == 8 && PCRE_MINOR >= 21 )
48+ # define LUA_HAVE_PCRE_JIT 1
49+ # else
50+ # define LUA_HAVE_PCRE_JIT 0
51+ # endif
4052#endif
4153
4254
43- #if defined(NDK ) && NDK
44- #include <ndk.h>
55+ #if ! defined(nginx_version ) || ( nginx_version < 1006000 )
56+ # error at least nginx 1.6.0 is required but found an older version
4557#endif
4658
47-
4859#if LUA_VERSION_NUM != 501
4960# error unsupported Lua language version
5061#endif
5162
52-
5363#if !defined(LUAJIT_VERSION_NUM ) || (LUAJIT_VERSION_NUM < 20000 )
5464# error unsupported LuaJIT version
5565#endif
6070#endif
6171
6272#ifndef NGX_HTTP_PERMANENT_REDIRECT
63- # define NGX_HTTP_PERMANENT_REDIRECT 308
73+ # define NGX_HTTP_PERMANENT_REDIRECT 308
6474#endif
6575
6676#ifndef NGX_HAVE_SHA1
6777# if defined(nginx_version ) && (nginx_version >= 1011002 )
68- # define NGX_HAVE_SHA1 1
78+ # define NGX_HAVE_SHA1 1
6979# endif
7080#endif
7181
72-
7382#ifndef MD5_DIGEST_LENGTH
74- #define MD5_DIGEST_LENGTH 16
83+ # define MD5_DIGEST_LENGTH 16
7584#endif
7685
86+ #ifndef NGX_HTTP_LUA_MAX_ARGS
87+ # define NGX_HTTP_LUA_MAX_ARGS 100
88+ #endif
7789
78- #ifdef NGX_LUA_USE_ASSERT
79- # include <assert.h>
80- # define ngx_http_lua_assert (a ) assert(a)
81- #else
82- # define ngx_http_lua_assert (a )
90+ #ifndef NGX_HTTP_LUA_MAX_HEADERS
91+ # define NGX_HTTP_LUA_MAX_HEADERS 100
8392#endif
8493
8594
104113 (NGX_HTTP_LUA_FILE_TAG_LEN + 2 * MD5_DIGEST_LENGTH)
105114
106115
107- #if defined(NDK ) && NDK
108- typedef struct {
109- size_t size ;
110- int ref ;
111- u_char * key ;
112- ngx_str_t script ;
113- } ngx_http_lua_set_var_data_t ;
114- #endif
115-
116-
117- #ifndef NGX_HTTP_LUA_MAX_ARGS
118- #define NGX_HTTP_LUA_MAX_ARGS 100
119- #endif
120-
121-
122- #ifndef NGX_HTTP_LUA_MAX_HEADERS
123- #define NGX_HTTP_LUA_MAX_HEADERS 100
124- #endif
125-
126-
127116/* must be within 16 bit */
128117#define NGX_HTTP_LUA_CONTEXT_SET 0x0001
129118#define NGX_HTTP_LUA_CONTEXT_REWRITE 0x0002
@@ -145,30 +134,38 @@ typedef struct {
145134
146135
147136#if (NGX_PTR_SIZE >= 8 && !defined(_WIN64 ))
148- #define ngx_http_lua_lightudata_mask (ludata ) \
149- ((void *) ((uintptr_t) (&ngx_http_lua_##ludata) & ((1UL << 47) - 1)))
150-
137+ # define ngx_http_lua_lightudata_mask (ludata ) \
138+ ((void *) ((uintptr_t) (&ngx_http_lua_##ludata) & ((1UL << 47) - 1)))
151139#else
152- #define ngx_http_lua_lightudata_mask (ludata ) (&ngx_http_lua_##ludata)
140+ # define ngx_http_lua_lightudata_mask (ludata ) \
141+ (&ngx_http_lua_##ludata)
153142#endif
154143
155144
156- typedef struct ngx_http_lua_main_conf_s ngx_http_lua_main_conf_t ;
157- typedef union ngx_http_lua_srv_conf_u ngx_http_lua_srv_conf_t ;
145+ typedef struct ngx_http_lua_co_ctx_s ngx_http_lua_co_ctx_t ;
158146
147+ typedef struct ngx_http_lua_sema_mm_s ngx_http_lua_sema_mm_t ;
159148
160- typedef struct ngx_http_lua_balancer_peer_data_s
161- ngx_http_lua_balancer_peer_data_t ;
149+ typedef union ngx_http_lua_srv_conf_u ngx_http_lua_srv_conf_t ;
162150
151+ typedef struct ngx_http_lua_main_conf_s ngx_http_lua_main_conf_t ;
163152
164- typedef struct ngx_http_lua_sema_mm_s ngx_http_lua_sema_mm_t ;
153+ typedef struct ngx_http_lua_header_val_s ngx_http_lua_header_val_t ;
154+
155+ typedef struct ngx_http_lua_posted_thread_s ngx_http_lua_posted_thread_t ;
165156
157+ typedef struct ngx_http_lua_balancer_peer_data_s
158+ ngx_http_lua_balancer_peer_data_t ;
166159
167160typedef ngx_int_t (* ngx_http_lua_main_conf_handler_pt )(ngx_log_t * log ,
168161 ngx_http_lua_main_conf_t * lmcf , lua_State * L );
162+
169163typedef ngx_int_t (* ngx_http_lua_srv_conf_handler_pt )(ngx_http_request_t * r ,
170164 ngx_http_lua_srv_conf_t * lscf , lua_State * L );
171165
166+ typedef ngx_int_t (* ngx_http_lua_set_header_pt )(ngx_http_request_t * r ,
167+ ngx_http_lua_header_val_t * hv , ngx_str_t * value );
168+
172169
173170typedef struct {
174171 u_char * package ;
@@ -198,11 +195,9 @@ struct ngx_http_lua_main_conf_s {
198195 ngx_int_t regex_cache_entries ;
199196 ngx_int_t regex_cache_max_entries ;
200197 ngx_int_t regex_match_limit ;
201-
202- #if (LUA_HAVE_PCRE_JIT )
198+ # if (LUA_HAVE_PCRE_JIT )
203199 pcre_jit_stack * jit_stack ;
204- #endif
205-
200+ # endif
206201#endif
207202
208203 ngx_array_t * shm_zones ; /* of ngx_shm_zone_t* */
@@ -298,10 +293,10 @@ union ngx_http_lua_srv_conf_u {
298293#endif
299294
300295 struct {
301- ngx_http_lua_srv_conf_handler_pt handler ;
302- ngx_str_t src ;
303- u_char * src_key ;
304- int src_ref ;
296+ ngx_http_lua_srv_conf_handler_pt handler ;
297+ ngx_str_t src ;
298+ u_char * src_key ;
299+ int src_ref ;
305300 } balancer ;
306301};
307302
@@ -398,7 +393,7 @@ typedef enum {
398393 NGX_HTTP_LUA_USER_CORO_NOP = 0 ,
399394 NGX_HTTP_LUA_USER_CORO_RESUME = 1 ,
400395 NGX_HTTP_LUA_USER_CORO_YIELD = 2 ,
401- NGX_HTTP_LUA_USER_THREAD_RESUME = 3
396+ NGX_HTTP_LUA_USER_THREAD_RESUME = 3 ,
402397} ngx_http_lua_user_coro_op_t ;
403398
404399
@@ -411,21 +406,12 @@ typedef enum {
411406} ngx_http_lua_co_status_t ;
412407
413408
414- typedef struct ngx_http_lua_co_ctx_s ngx_http_lua_co_ctx_t ;
415-
416- typedef struct ngx_http_lua_posted_thread_s ngx_http_lua_posted_thread_t ;
417-
418409struct ngx_http_lua_posted_thread_s {
419410 ngx_http_lua_co_ctx_t * co_ctx ;
420411 ngx_http_lua_posted_thread_t * next ;
421412};
422413
423414
424- enum {
425- NGX_HTTP_LUA_SUBREQ_TRUNCATED = 1
426- };
427-
428-
429415struct ngx_http_lua_co_ctx_s {
430416 void * data ; /* user state for cosockets */
431417
@@ -615,13 +601,6 @@ typedef struct ngx_http_lua_ctx_s {
615601} ngx_http_lua_ctx_t ;
616602
617603
618- typedef struct ngx_http_lua_header_val_s ngx_http_lua_header_val_t ;
619-
620-
621- typedef ngx_int_t (* ngx_http_lua_set_header_pt )(ngx_http_request_t * r ,
622- ngx_http_lua_header_val_t * hv , ngx_str_t * value );
623-
624-
625604struct ngx_http_lua_header_val_s {
626605 ngx_http_complex_value_t value ;
627606 ngx_uint_t hash ;
0 commit comments