From 1cedf45414053ec05869ac0546cbd9330c8ed0eb Mon Sep 17 00:00:00 2001 From: Brian McCallister Date: Thu, 10 Nov 2011 18:48:50 +0000 Subject: [PATCH] fix issue with incorrect munging of the lua package path -- LuaPackagePath directives were not working git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1200475 13f79535-47bb-0310-9956-ffa450edef68 --- modules/lua/lua_config.c | 1 - modules/lua/lua_vmprep.c | 31 ++++++++++++++++++++++++++++--- modules/lua/mod_lua.c | 12 +++++++++--- modules/lua/test/test.lua | 2 +- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/modules/lua/lua_config.c b/modules/lua/lua_config.c index 8a967dc5f2..68899a897d 100644 --- a/modules/lua/lua_config.c +++ b/modules/lua/lua_config.c @@ -155,7 +155,6 @@ static const struct luaL_Reg cfg_methods[] = { }; - static int cmd_foo(lua_State *L) { cmd_parms *cmd = check_cmd_parms(L, 1); diff --git a/modules/lua/lua_vmprep.c b/modules/lua/lua_vmprep.c index fb730cfe24..65fcd6ffca 100644 --- a/modules/lua/lua_vmprep.c +++ b/modules/lua/lua_vmprep.c @@ -245,6 +245,23 @@ static apr_status_t cleanup_lua(void *l) return APR_SUCCESS; } +/* + munge_path(L, + "path", + "?.lua", + "./?.lua", + lifecycle_pool, + spec->package_paths, + spec->file); +*/ +/** + * field -> "path" or "cpath" + * sub_pat -> "?.lua" + * rep_pat -> "./?.lua" + * pool -> lifecycle pool for allocations + * paths -> things to add + * file -> ??? + */ static void munge_path(lua_State *L, const char *field, const char *sub_pat, @@ -261,17 +278,22 @@ static void munge_path(lua_State *L, lua_getglobal(L, "package"); lua_getfield(L, -1, field); + 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); modified = lua_tostring(L, -1); + + lua_pop(L, 2); - part = apr_pstrcat(pool, modified, apr_array_pstrcat(pool, paths, ';'), + part = apr_pstrcat(pool, modified, ";", apr_array_pstrcat(pool, paths, ';'), NULL); + lua_pushstring(L, part); lua_setfield(L, -2, field); lua_pop(L, 1); /* pop "package" off the stack */ @@ -308,8 +330,11 @@ static apr_status_t vm_construct(void **vm, void *params, apr_pool_t *lifecycle_ #endif luaL_openlibs(L); if (spec->package_paths) { - munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool, - spec->package_paths, spec->file); + munge_path(L, + "path", "?.lua", "./?.lua", + lifecycle_pool, + spec->package_paths, + spec->file); } if (spec->package_cpaths) { munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool, diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c index a3adf4a5d0..fd55972eaf 100644 --- a/modules/lua/mod_lua.c +++ b/modules/lua/mod_lua.c @@ -863,16 +863,22 @@ static const char *register_quick_block(cmd_parms *cmd, void *_cfg, -static const char *register_package_helper(cmd_parms *cmd, const char *arg, +static const char *register_package_helper(cmd_parms *cmd, + const char *arg, apr_array_header_t *dir_array) { apr_status_t rv; ap_lua_server_cfg *server_cfg = ap_get_module_config(cmd->server->module_config, &lua_module); + char *fixed_filename; - rv = apr_filepath_merge(&fixed_filename, server_cfg->root_path, arg, - APR_FILEPATH_NOTRELATIVE, cmd->pool); + rv = apr_filepath_merge(&fixed_filename, + server_cfg->root_path, + arg, + APR_FILEPATH_NOTRELATIVE, + cmd->pool); + if (rv != APR_SUCCESS) { return apr_psprintf(cmd->pool, "Unable to build full path to file, %s", arg); diff --git a/modules/lua/test/test.lua b/modules/lua/test/test.lua index 59ef00aec8..25da4d9dad 100755 --- a/modules/lua/test/test.lua +++ b/modules/lua/test/test.lua @@ -18,7 +18,7 @@ local mu = require "moonunit" local http = require "helpers" -http.base_url = "http://localhost:8000" +http.base_url = "http://localhost:8008" local test = mu.TestCase:new{} -- 2.40.0