Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/ngx_http_lua_balancer.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ ngx_http_lua_balancer_handler_inline(ngx_http_request_t *r,
lscf->balancer.src.len,
&lscf->balancer.src_ref,
lscf->balancer.src_key,
"=balancer_by_lua");
(const char *) lscf->balancer.chunkname);
if (rc != NGX_OK) {
return rc;
}
Expand Down Expand Up @@ -125,6 +125,8 @@ char *
ngx_http_lua_balancer_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
size_t chunkname_len;
u_char *chunkname;
u_char *cache_key = NULL;
u_char *name;
ngx_str_t *value;
Expand Down Expand Up @@ -172,8 +174,16 @@ ngx_http_lua_balancer_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}

chunkname = ngx_http_lua_gen_chunk_name(cf, "balancer_by_lua",
sizeof("balancer_by_lua") - 1,
&chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

/* Don't eval nginx variables for inline lua code */
lscf->balancer.src = value[1];
lscf->balancer.chunkname = chunkname;
}

lscf->balancer.src_key = cache_key;
Expand Down
3 changes: 2 additions & 1 deletion src/ngx_http_lua_bodyfilterby.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ ngx_http_lua_body_filter_inline(ngx_http_request_t *r, ngx_chain_t *in)
llcf->body_filter_src.value.len,
&llcf->body_filter_src_ref,
llcf->body_filter_src_key,
"=body_filter_by_lua");
(const char *)
llcf->body_filter_chunkname);
if (rc != NGX_OK) {
return NGX_ERROR;
}
Expand Down
11 changes: 11 additions & 0 deletions src/ngx_http_lua_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ typedef struct {
size_t size;
int ref;
u_char *key;
u_char *chunkname;
ngx_str_t script;
} ngx_http_lua_set_var_data_t;
#endif
Expand Down Expand Up @@ -233,12 +234,15 @@ struct ngx_http_lua_main_conf_s {

ngx_http_lua_main_conf_handler_pt init_handler;
ngx_str_t init_src;
u_char *init_chunkname;

ngx_http_lua_main_conf_handler_pt init_worker_handler;
ngx_str_t init_worker_src;
u_char *init_worker_chunkname;

ngx_http_lua_main_conf_handler_pt exit_worker_handler;
ngx_str_t exit_worker_src;
u_char *exit_worker_chunkname;

ngx_http_lua_balancer_peer_data_t *balancer_peer_data;
/* neither yielding nor recursion is possible in
Expand Down Expand Up @@ -310,21 +314,25 @@ union ngx_http_lua_srv_conf_u {
ngx_http_lua_srv_conf_handler_pt ssl_cert_handler;
ngx_str_t ssl_cert_src;
u_char *ssl_cert_src_key;
u_char *ssl_cert_chunkname;
int ssl_cert_src_ref;

ngx_http_lua_srv_conf_handler_pt ssl_sess_store_handler;
ngx_str_t ssl_sess_store_src;
u_char *ssl_sess_store_src_key;
u_char *ssl_sess_store_chunkname;
int ssl_sess_store_src_ref;

ngx_http_lua_srv_conf_handler_pt ssl_sess_fetch_handler;
ngx_str_t ssl_sess_fetch_src;
u_char *ssl_sess_fetch_src_key;
u_char *ssl_sess_fetch_chunkname;
int ssl_sess_fetch_src_ref;

ngx_http_lua_srv_conf_handler_pt ssl_client_hello_handler;
ngx_str_t ssl_client_hello_src;
u_char *ssl_client_hello_src_key;
u_char *ssl_client_hello_chunkname;
int ssl_client_hello_src_ref;
} srv;
#endif
Expand All @@ -333,6 +341,7 @@ union ngx_http_lua_srv_conf_u {
ngx_http_lua_srv_conf_handler_pt handler;
ngx_str_t src;
u_char *src_key;
u_char *chunkname;
int src_ref;
} balancer;
};
Expand Down Expand Up @@ -403,13 +412,15 @@ typedef struct {
inline script/script
file path */

u_char *header_filter_chunkname;
u_char *header_filter_src_key;
/* cached key for header_filter_src */
int header_filter_src_ref;


ngx_http_complex_value_t body_filter_src;
u_char *body_filter_src_key;
u_char *body_filter_chunkname;
int body_filter_src_ref;

ngx_msec_t keepalive_timeout;
Expand Down
132 changes: 112 additions & 20 deletions src/ngx_http_lua_directive.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include "ngx_http_lua_log.h"


#define LJ_CHUNKNAME_MAX_LEN 42


typedef struct ngx_http_lua_block_parser_ctx_s
ngx_http_lua_block_parser_ctx_t;

Expand All @@ -43,8 +46,6 @@ typedef struct ngx_http_lua_block_parser_ctx_s
static ngx_int_t ngx_http_lua_set_by_lua_init(ngx_http_request_t *r);
#endif

static u_char *ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag,
size_t tag_len, size_t *chunkname_len);
static ngx_int_t ngx_http_lua_conf_read_lua_token(ngx_conf_t *cf,
ngx_http_lua_block_parser_ctx_t *ctx);
static u_char *ngx_http_lua_strlstrn(u_char *s1, u_char *last, u_char *s2,
Expand Down Expand Up @@ -280,6 +281,8 @@ ngx_http_lua_set_by_lua_block(ngx_conf_t *cf, ngx_command_t *cmd,
char *
ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
{
size_t chunkname_len;
u_char *chunkname;
u_char *cache_key;
ngx_str_t *value;
ngx_str_t target;
Expand Down Expand Up @@ -312,7 +315,15 @@ ngx_http_lua_set_by_lua(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return NGX_CONF_ERROR;
}

chunkname = ngx_http_lua_gen_chunk_name(cf, "set_by_lua",
sizeof("set_by_lua") - 1,
&chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

filter_data->key = cache_key;
filter_data->chunkname = chunkname;
filter_data->ref = LUA_REFNIL;
filter_data->script = value[2];
filter_data->size = filter.size;
Expand Down Expand Up @@ -375,6 +386,7 @@ ngx_http_lua_set_by_lua_file(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
filter_data->key = cache_key;
filter_data->ref = LUA_REFNIL;
filter_data->size = filter.size;
filter_data->chunkname = NULL;

ngx_str_null(&filter_data->script);

Expand Down Expand Up @@ -404,7 +416,8 @@ ngx_http_lua_filter_set_by_lua_inline(ngx_http_request_t *r, ngx_str_t *val,
filter_data->script.data,
filter_data->script.len,
&filter_data->ref,
filter_data->key, "=set_by_lua");
filter_data->key,
(const char *) filter_data->chunkname);
if (rc != NGX_OK) {
return NGX_ERROR;
}
Expand Down Expand Up @@ -912,7 +925,8 @@ char *
ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
u_char *cache_key = NULL;
size_t chunkname_len;
u_char *cache_key = NULL, *chunkname;
ngx_str_t *value;
ngx_http_lua_main_conf_t *lmcf;
ngx_http_lua_loc_conf_t *llcf = conf;
Expand Down Expand Up @@ -947,8 +961,15 @@ ngx_http_lua_header_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}

chunkname = ngx_http_lua_gen_chunk_name(cf, "header_filter_by_lua",
sizeof("header_filter_by_lua") - 1, &chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

/* Don't eval nginx variables for inline lua code */
llcf->header_filter_src.value = value[1];
llcf->header_filter_chunkname = chunkname;

} else {
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
Expand Down Expand Up @@ -1004,7 +1025,8 @@ char *
ngx_http_lua_body_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
void *conf)
{
u_char *cache_key = NULL;
size_t chunkname_len;
u_char *cache_key = NULL, *chunkname;
ngx_str_t *value;
ngx_http_lua_main_conf_t *lmcf;
ngx_http_lua_loc_conf_t *llcf = conf;
Expand Down Expand Up @@ -1039,8 +1061,16 @@ ngx_http_lua_body_filter_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
return NGX_CONF_ERROR;
}

chunkname = ngx_http_lua_gen_chunk_name(cf, "body_filter_by_lua",
sizeof("body_filter_by_lua") - 1, &chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}


/* Don't eval nginx variables for inline lua code */
llcf->body_filter_src.value = value[1];
llcf->body_filter_chunkname = chunkname;

} else {
ngx_memzero(&ccv, sizeof(ngx_http_compile_complex_value_t));
Expand Down Expand Up @@ -1100,6 +1130,8 @@ ngx_http_lua_init_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
u_char *name;
ngx_str_t *value;
ngx_http_lua_main_conf_t *lmcf = conf;
size_t chunkname_len;
u_char *chunkname;

dd("enter");

Expand Down Expand Up @@ -1135,6 +1167,15 @@ ngx_http_lua_init_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,

} else {
lmcf->init_src = value[1];

chunkname = ngx_http_lua_gen_chunk_name(cf, "init_by_lua",
sizeof("init_by_lua") - 1,
&chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

lmcf->init_chunkname = chunkname;
}

return NGX_CONF_OK;
Expand Down Expand Up @@ -1167,6 +1208,8 @@ ngx_http_lua_init_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
u_char *name;
ngx_str_t *value;
ngx_http_lua_main_conf_t *lmcf = conf;
size_t chunkname_len;
u_char *chunkname;

dd("enter");

Expand Down Expand Up @@ -1195,6 +1238,14 @@ ngx_http_lua_init_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,

} else {
lmcf->init_worker_src = value[1];

chunkname = ngx_http_lua_gen_chunk_name(cf, "init_worker_by_lua",
sizeof("init_worker_by_lua") - 1, &chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

lmcf->init_worker_chunkname = chunkname;
}

return NGX_CONF_OK;
Expand Down Expand Up @@ -1227,6 +1278,8 @@ ngx_http_lua_exit_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,
u_char *name;
ngx_str_t *value;
ngx_http_lua_main_conf_t *lmcf = conf;
size_t chunkname_len;
u_char *chunkname;

/* must specify a content handler */
if (cmd->post == NULL) {
Expand All @@ -1253,6 +1306,15 @@ ngx_http_lua_exit_worker_by_lua(ngx_conf_t *cf, ngx_command_t *cmd,

} else {
lmcf->exit_worker_src = value[1];

chunkname = ngx_http_lua_gen_chunk_name(cf, "exit_worker_by_lua",
sizeof("exit_worker_by_lua")- 1,
&chunkname_len);
if (chunkname == NULL) {
return NGX_CONF_ERROR;
}

lmcf->exit_worker_chunkname = chunkname;
}

return NGX_CONF_OK;
Expand Down Expand Up @@ -1296,13 +1358,18 @@ ngx_http_lua_set_by_lua_init(ngx_http_request_t *r)
#endif


static u_char *
u_char *
ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
size_t *chunkname_len)
{
u_char *p, *out;
size_t len;
ngx_uint_t start_line;
ngx_str_t *conf_prefix;
ngx_str_t *filename;
u_char *filename_end;
const char *pre_str = "";
ngx_uint_t start_line_len;

ngx_http_lua_main_conf_t *lmcf;

Expand All @@ -1314,30 +1381,55 @@ ngx_http_lua_gen_chunk_name(ngx_conf_t *cf, const char *tag, size_t tag_len,
return NULL;
}

if (cf->conf_file->file.name.len) {
p = cf->conf_file->file.name.data + cf->conf_file->file.name.len;
while (--p >= cf->conf_file->file.name.data) {
if (*p == '/' || *p == '\\') {
p++;
lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
start_line = lmcf->directive_line > 0
? lmcf->directive_line : cf->conf_file->line;
p = ngx_snprintf(out, len, "%d", start_line);
start_line_len = p - out;

filename = &cf->conf_file->file.name;
filename_end = filename->data + filename->len;
if (filename->len > 0) {
if (filename->len >= 11) {
p = filename_end - 11;
if ((*p == '/' || *p == '\\')
&& ngx_memcmp(p, "/nginx.conf", 11) == 0)
{
p++; /* now p is nginx.conf */
goto found;
}
}

p++;
conf_prefix = &cf->cycle->conf_prefix;
p = filename->data + conf_prefix->len;
if ((conf_prefix->len < filename->len)
&& ngx_memcmp(conf_prefix->data,
filename->data, conf_prefix->len) == 0)
{
/* files in conf_prefix directory, use the relative path */
if (filename_end - p + start_line_len > LJ_CHUNKNAME_MAX_LEN) {
p = filename_end - LJ_CHUNKNAME_MAX_LEN + start_line_len + 3;
pre_str = "...";
}

} else {
p = cf->conf_file->file.name.data;
goto found;
}
}

p = filename->data;

if (filename->len + start_line_len <= LJ_CHUNKNAME_MAX_LEN) {
goto found;
}

p = filename_end - LJ_CHUNKNAME_MAX_LEN + start_line_len + 3;
pre_str = "...";

found:

lmcf = ngx_http_conf_get_module_main_conf(cf, ngx_http_lua_module);
start_line = lmcf->directive_line > 0
? lmcf->directive_line : cf->conf_file->line;

p = ngx_snprintf(out, len, "=%*s(%*s:%d)%Z",
tag_len, tag, cf->conf_file->file.name.data
+ cf->conf_file->file.name.len - p,
p = ngx_snprintf(out, len, "=%*s(%s%*s:%d)%Z",
tag_len, tag, pre_str, filename_end - p,
p, start_line);

*chunkname_len = p - out - 1; /* exclude the trailing '\0' byte */
Expand Down
Loading