mirror of
https://github.com/apache/httpd.git
synced 2025-08-08 15:02:10 +03:00
Change apl_get_lua_state to take a apl_vm_spec instead of a filename, and to
load the bytecode if it is present, rather than the file, as this gets the inline config file blocks hooks working again. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728531 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -258,7 +258,7 @@ static void munge_path(lua_State *L,
|
|||||||
}
|
}
|
||||||
|
|
||||||
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
|
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
|
||||||
char *file,
|
apl_vm_spec *spec,
|
||||||
apr_array_header_t *package_paths,
|
apr_array_header_t *package_paths,
|
||||||
apr_array_header_t *package_cpaths,
|
apr_array_header_t *package_cpaths,
|
||||||
apl_lua_state_open_callback cb, void *btn)
|
apl_lua_state_open_callback cb, void *btn)
|
||||||
@@ -267,29 +267,37 @@ lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
|
|||||||
lua_State *L;
|
lua_State *L;
|
||||||
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
|
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
|
||||||
"obtaining lua_State");
|
"obtaining lua_State");
|
||||||
if (!apr_pool_userdata_get((void **) &L, file, lifecycle_pool)) {
|
if (!apr_pool_userdata_get((void **) &L, spec->file, lifecycle_pool)) {
|
||||||
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
|
ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
|
||||||
"creating lua_State with file %s", file);
|
"creating lua_State with file %s", spec->file);
|
||||||
/* not available, so create */
|
/* not available, so create */
|
||||||
L = luaL_newstate();
|
L = luaL_newstate();
|
||||||
luaL_openlibs(L);
|
luaL_openlibs(L);
|
||||||
if (package_paths)
|
if (package_paths)
|
||||||
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
|
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
|
||||||
package_paths, file);
|
package_paths, spec->file);
|
||||||
if (package_cpaths)
|
if (package_cpaths)
|
||||||
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
|
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
|
||||||
package_cpaths, file);
|
package_cpaths, spec->file);
|
||||||
|
|
||||||
if (cb) {
|
if (cb) {
|
||||||
cb(L, lifecycle_pool, btn);
|
cb(L, lifecycle_pool, btn);
|
||||||
}
|
}
|
||||||
|
|
||||||
luaL_loadfile(L, file);
|
apr_pool_userdata_set(L, spec->file, &cleanup_lua, lifecycle_pool);
|
||||||
lua_pcall(L, 0, LUA_MULTRET, 0);
|
|
||||||
apr_pool_userdata_set(L, file, &cleanup_lua, lifecycle_pool);
|
if (spec->bytecode && spec->bytecode_len > 0) {
|
||||||
|
luaL_loadbuffer(L, spec->bytecode, spec->bytecode_len, spec->file);
|
||||||
|
lua_pcall(L, 0, LUA_MULTRET, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
luaL_loadfile(L, spec->file);
|
||||||
|
lua_pcall(L, 0, LUA_MULTRET, 0);
|
||||||
|
}
|
||||||
|
|
||||||
lua_pushlightuserdata(L, lifecycle_pool);
|
lua_pushlightuserdata(L, lifecycle_pool);
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
|
lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Wombat.pool");
|
||||||
}
|
}
|
||||||
|
|
||||||
return L;
|
return L;
|
||||||
}
|
}
|
||||||
|
@@ -65,6 +65,10 @@ typedef struct
|
|||||||
/* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
|
/* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
|
||||||
apr_pool_t *pool;
|
apr_pool_t *pool;
|
||||||
|
|
||||||
|
/* Pre-compiled Lua Byte code to load directly. If bytecode_len is >0,
|
||||||
|
* the file part of this structure is ignored for loading purposes, but
|
||||||
|
* it is used for error messages.
|
||||||
|
*/
|
||||||
const char *bytecode;
|
const char *bytecode;
|
||||||
apr_size_t bytecode_len;
|
apr_size_t bytecode_len;
|
||||||
} apl_vm_spec;
|
} apl_vm_spec;
|
||||||
@@ -127,7 +131,7 @@ typedef void (*apl_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
|
|||||||
* @ctx a baton passed to cb
|
* @ctx a baton passed to cb
|
||||||
*/
|
*/
|
||||||
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
|
lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
|
||||||
char *file,
|
apl_vm_spec *spec,
|
||||||
apr_array_header_t *package_paths,
|
apr_array_header_t *package_paths,
|
||||||
apr_array_header_t *package_cpaths,
|
apr_array_header_t *package_cpaths,
|
||||||
apl_lua_state_open_callback cb, void *btn);
|
apl_lua_state_open_callback cb, void *btn);
|
||||||
|
@@ -127,7 +127,7 @@ static int lua_handler(request_rec *r)
|
|||||||
const apl_dir_cfg *cfg =
|
const apl_dir_cfg *cfg =
|
||||||
ap_get_module_config(r->per_dir_config, &lua_module);
|
ap_get_module_config(r->per_dir_config, &lua_module);
|
||||||
lua_State *L = apl_get_lua_state(r->pool,
|
lua_State *L = apl_get_lua_state(r->pool,
|
||||||
d->spec->file,
|
d->spec,
|
||||||
cfg->package_paths,
|
cfg->package_paths,
|
||||||
cfg->package_cpaths,
|
cfg->package_cpaths,
|
||||||
&lua_open_callback, NULL);
|
&lua_open_callback, NULL);
|
||||||
@@ -206,8 +206,8 @@ static int apl_alias_munger(request_rec *r)
|
|||||||
|
|
||||||
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
|
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
|
||||||
{
|
{
|
||||||
char *fixed_filename;
|
apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
|
||||||
|
&lua_module);
|
||||||
const apl_dir_cfg *cfg =
|
const apl_dir_cfg *cfg =
|
||||||
(apl_dir_cfg *) ap_get_module_config(r->per_dir_config,
|
(apl_dir_cfg *) ap_get_module_config(r->per_dir_config,
|
||||||
&lua_module);
|
&lua_module);
|
||||||
@@ -216,10 +216,13 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
|
|||||||
if (hook_specs) {
|
if (hook_specs) {
|
||||||
int i;
|
int i;
|
||||||
for (i = 0; i < hook_specs->nelts; i++) {
|
for (i = 0; i < hook_specs->nelts; i++) {
|
||||||
|
char *fixed_filename = NULL;
|
||||||
apl_mapped_handler_spec *hook_spec =
|
apl_mapped_handler_spec *hook_spec =
|
||||||
((apl_mapped_handler_spec **) hook_specs->elts)[i];
|
((apl_mapped_handler_spec **) hook_specs->elts)[i];
|
||||||
if (hook_spec == NULL)
|
|
||||||
|
if (hook_spec == NULL) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
|
apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
|
||||||
|
|
||||||
spec->file = hook_spec->file_name;
|
spec->file = hook_spec->file_name;
|
||||||
@@ -229,20 +232,10 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name)
|
|||||||
spec->bytecode_len = hook_spec->bytecode_len;
|
spec->bytecode_len = hook_spec->bytecode_len;
|
||||||
spec->pool = r->pool;
|
spec->pool = r->pool;
|
||||||
|
|
||||||
/*
|
apr_filepath_merge(&spec->file, server_cfg->root_path,
|
||||||
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->file,
|
|
||||||
cfg->package_paths,
|
|
||||||
cfg->package_cpaths,
|
|
||||||
&lua_open_callback, NULL);
|
|
||||||
*/
|
|
||||||
apl_server_cfg *server_cfg =
|
|
||||||
ap_get_module_config(r->server->module_config, &lua_module);
|
|
||||||
apr_filepath_merge(&fixed_filename, server_cfg->root_path,
|
|
||||||
spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
|
spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
|
||||||
lua_State *L = apl_get_lua_state(r->pool,
|
lua_State *L = apl_get_lua_state(r->pool,
|
||||||
fixed_filename,
|
spec,
|
||||||
cfg->package_paths,
|
cfg->package_paths,
|
||||||
cfg->package_cpaths,
|
cfg->package_cpaths,
|
||||||
&lua_open_callback, NULL);
|
&lua_open_callback, NULL);
|
||||||
|
Reference in New Issue
Block a user