Commit 6e200304 authored by Brian McCallister's avatar Brian McCallister
Browse files

fix issue with incorrect munging of the lua package path -- LuaPackagePath...

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
parent 0c9e9291
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -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);
+28 −3
Original line number Diff line number Diff line
@@ -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,
+9 −3
Original line number Diff line number Diff line
@@ -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);
+1 −1
Original line number Diff line number Diff line
@@ -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{}