diff --git a/modules/lua/lua_apr.c b/modules/lua/lua_apr.c index c3b4fb753d..304378cf89 100644 --- a/modules/lua/lua_apr.c +++ b/modules/lua/lua_apr.c @@ -34,8 +34,9 @@ apr_table_t *check_apr_table(lua_State *L, int index) { + apr_table_t *t; luaL_checkudata(L, index, "Apr.Table"); - apr_table_t *t = (apr_table_t *) lua_unboxpointer(L, index); + t = (apr_table_t *) lua_unboxpointer(L, index); return t; } diff --git a/modules/lua/lua_config.c b/modules/lua/lua_config.c index 858ae0aafd..6f62c7b88c 100644 --- a/modules/lua/lua_config.c +++ b/modules/lua/lua_config.c @@ -20,15 +20,17 @@ static apl_dir_cfg *check_dir_config(lua_State *L, int index) { + apl_dir_cfg *cfg; luaL_checkudata(L, index, "Apache2.DirConfig"); - apl_dir_cfg *cfg = (apl_dir_cfg *) lua_unboxpointer(L, index); + cfg = (apl_dir_cfg *) lua_unboxpointer(L, index); return cfg; } static cmd_parms *check_cmd_parms(lua_State *L, int index) { + cmd_parms *cmd; luaL_checkudata(L, index, "Apache2.CommandParameters"); - cmd_parms *cmd = (cmd_parms *) lua_unboxpointer(L, index); + cmd = (cmd_parms *) lua_unboxpointer(L, index); return cmd; } diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 7717fbd3c1..4c129c40e2 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -92,8 +92,9 @@ void rstack_dump(lua_State *L, request_rec *r, const char *msg) */ static request_rec *apl_check_request_rec(lua_State *L, int index) { + request_rec *r; luaL_checkudata(L, index, "Apache2.Request"); - request_rec *r = (request_rec *) lua_unboxpointer(L, index); + r = (request_rec *) lua_unboxpointer(L, index); return r; } @@ -102,6 +103,7 @@ static request_rec *apl_check_request_rec(lua_State *L, int index) static int req_aprtable2luatable_cb(void *l, const char *key, const char *value) { + int t; lua_State *L = (lua_State *) l; /* [table, table] */ /* rstack_dump(L, RRR, "start of cb"); */ /* L is [table, table] */ @@ -109,7 +111,7 @@ static int req_aprtable2luatable_cb(void *l, const char *key, lua_getfield(L, -1, key); /* [VALUE, table, table] */ /* rstack_dump(L, RRR, "after getfield"); */ - int t = lua_type(L, -1); + t = lua_type(L, -1); switch (t) { case LUA_TNIL: case LUA_TNONE:{ @@ -149,10 +151,10 @@ static int req_aprtable2luatable_cb(void *l, const char *key, /* r:parseargs() returning a lua table */ static int req_parseargs(lua_State *L) { + apr_table_t *form_table; request_rec *r = apl_check_request_rec(L, 1); lua_newtable(L); lua_newtable(L); /* [table, table] */ - apr_table_t *form_table; ap_args_to_table(r, &form_table); apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL); return 2; /* [table, table>] */ diff --git a/modules/lua/lua_vmprep.c b/modules/lua/lua_vmprep.c index e3cf24240f..96037e27c5 100644 --- a/modules/lua/lua_vmprep.c +++ b/modules/lua/lua_vmprep.c @@ -26,10 +26,11 @@ static void pstack_dump(lua_State *L, apr_pool_t *r, int level, const char *msg) { - ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg); - int i; int top = lua_gettop(L); + + ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg); + for (i = 1; i <= top; i++) { int t = lua_type(L, i); switch (t) { @@ -235,19 +236,25 @@ static void munge_path(lua_State *L, apr_pool_t *pool, apr_array_header_t *paths, const char *file) { + const char *current; + const char *parent_dir; + const char *pattern; + const char *modified; + char *part; + int i; + lua_getglobal(L, "package"); lua_getfield(L, -1, field); - const char *current = lua_tostring(L, -1); - const char *parent_dir = ap_make_dirstr_parent(pool, file); - const char *pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL); + current = lua_tostring(L, -1); + parent_dir = ap_make_dirstr_parent(pool, file); + pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL); luaL_gsub(L, current, rep_pat, pattern); lua_setfield(L, -3, field); lua_getfield(L, -2, field); - const char *modified = lua_tostring(L, -1); + modified = lua_tostring(L, -1); lua_pop(L, 2); - char *part = apr_pstrdup(pool, modified); - int i; + part = apr_pstrdup(pool, modified); for (i = 0; i < paths->nelts; i++) { const char *new_path = ((const char **) paths->elts)[i]; part = apr_pstrcat(pool, part, ";", new_path, NULL); @@ -272,12 +279,14 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool, /* not available, so create */ L = luaL_newstate(); luaL_openlibs(L); - if (package_paths) + if (package_paths) { munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool, package_paths, spec->file); - if (package_cpaths) + } + if (package_cpaths) { munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool, package_cpaths, spec->file); + } if (cb) { cb(L, lifecycle_pool, btn); diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index cd262caee1..5a391a3e8b 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -39,12 +39,13 @@ APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_request, */ static void report_lua_error(lua_State *L, request_rec *r) { + const char *lua_response; r->status = 500; r->content_type = "text/html"; ap_rputs("Error!\n", r); ap_rputs("

", r); - const char *lua_response = lua_tostring(L, -1); + lua_response = lua_tostring(L, -1); ap_rputs(lua_response, r); ap_rputs("

\n", r); @@ -107,10 +108,14 @@ static int lua_handler(request_rec *r) apl_dir_cfg *dcfg = ap_get_module_config(r->per_dir_config, &lua_module); if (!r->header_only) { + lua_State *L; + const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config, + &lua_module); apl_request_cfg *rcfg = ap_get_module_config(r->request_config, &lua_module); mapped_request_details *d = rcfg->mapped_request_details; apl_vm_spec *spec = NULL; + if (!d) { d = apr_palloc(r->pool, sizeof(mapped_request_details)); spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec)); @@ -121,16 +126,15 @@ static int lua_handler(request_rec *r) d->spec = spec; d->function_name = "handle"; } + ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "request details scope:%u, cache:%u", d->spec->scope, d->spec->code_cache_style); - const apl_dir_cfg *cfg = - ap_get_module_config(r->per_dir_config, &lua_module); - lua_State *L = apl_get_lua_state(r->pool, - d->spec, - cfg->package_paths, - cfg->package_cpaths, - &lua_open_callback, NULL); + L = apl_get_lua_state(r->pool, + d->spec, + cfg->package_paths, + cfg->package_cpaths, + &lua_open_callback, NULL); ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!"); if (!L) { @@ -154,22 +158,24 @@ static int lua_handler(request_rec *r) */ static int apl_alias_munger(request_rec *r) { + apl_vm_spec *spec; + apl_request_cfg *rcfg = ap_get_module_config(r->request_config, + &lua_module); const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config, &lua_module); - int i; ap_regmatch_t matches[AP_MAX_REG_MATCH]; for (i = 0; i < cfg->mapped_handlers->nelts; i++) { const apl_mapped_handler_spec *cnd = - ((const apl_mapped_handler_spec **) cfg->mapped_handlers-> - elts)[i]; + ((const apl_mapped_handler_spec **) cfg->mapped_handlers->elts)[i]; + if (OK == ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH, matches, 0)) { r->handler = "lua-script"; - apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec)); + spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec)); spec->file = ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH, matches); @@ -191,8 +197,6 @@ static int apl_alias_munger(request_rec *r) /* now do replacement on method name where? */ r->filename = apr_pstrdup(r->pool, spec->file); - apl_request_cfg *rcfg = - ap_get_module_config(r->request_config, &lua_module); rcfg->mapped_request_details = d; return OK; } @@ -206,6 +210,8 @@ static int apl_alias_munger(request_rec *r) static int lua_request_rec_hook_harness(request_rec *r, const char *name) { + lua_State *L; + apl_vm_spec *spec; apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config, &lua_module); const apl_dir_cfg *cfg = @@ -223,7 +229,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name) if (hook_spec == NULL) { continue; } - apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec)); + spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec)); spec->file = hook_spec->file_name; spec->code_cache_style = hook_spec->code_cache_style; @@ -234,11 +240,11 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name) apr_filepath_merge(&spec->file, server_cfg->root_path, spec->file, APR_FILEPATH_NOTRELATIVE, r->pool); - lua_State *L = apl_get_lua_state(r->pool, - spec, - cfg->package_paths, - cfg->package_cpaths, - &lua_open_callback, NULL); + L = apl_get_lua_state(r->pool, + spec, + cfg->package_paths, + cfg->package_cpaths, + &lua_open_callback, NULL); @@ -446,6 +452,7 @@ static const char *register_named_block_function_hook(const char *name, lua_State *lvm; char *tmp; int rv; + ap_directive_t **current; apr_snprintf(buf, sizeof(buf), "%u", cmd->config_file->line_number); spec->file_name = @@ -491,7 +498,7 @@ static const char *register_named_block_function_hook(const char *name, lua_close(lvm); } - ap_directive_t **current = mconfig; + current = mconfig; /* Here, we have to replace our current config node for the next pass */ if (!*current) { @@ -520,6 +527,7 @@ static const char *register_named_file_function_hook(const char *name, const char *file, const char *function) { + apl_mapped_handler_spec *spec; apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg; apr_array_header_t *hook_specs = @@ -531,8 +539,7 @@ static const char *register_named_file_function_hook(const char *name, APR_HASH_KEY_STRING, hook_specs); } - apl_mapped_handler_spec *spec = - apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec)); + spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec)); spec->file_name = apr_pstrdup(cmd->pool, file); spec->function_name = apr_pstrdup(cmd->pool, function); spec->scope = cfg->vm_scope; @@ -823,10 +830,9 @@ static const char *lua_map_handler(cmd_parms *cmd, void *_cfg, const char *function) { apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg; - + apr_status_t rv; const char *function_name; function_name = function ? function : "handle"; - apr_status_t rv; rv = apl_lua_map_handler(cfg, file, function_name, path, "once"); if (rv != APR_SUCCESS) { return apr_psprintf(cmd->pool,