parent_dir = ap_make_dirstr_parent(pool, file);
- ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, NULL, "parent_dir %s", parent_dir);
-
pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
- ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, NULL, "pattern %s", pattern);
+
luaL_gsub(L, current, rep_pat, pattern);
lua_setfield(L, -3, field);
lua_getfield(L, -2, field);
modified = lua_tostring(L, -1);
- ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, NULL, "modified %s", modified);
+
lua_pop(L, 2);
part = apr_pstrcat(pool, modified, ";", apr_array_pstrcat(pool, paths, ';'),
NULL);
- ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, NULL, "part %s", part);
+
lua_pushstring(L, part);
lua_setfield(L, -2, field);
lua_pop(L, 1); /* pop "package" off the stack */
return apr_reslist_destroy(data);
}
+/**
+ * Function used to create a lua_State instance bound into the web
+ * server in the appropriate scope.
+ */
AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
ap_lua_vm_spec *spec)
{
lua_State *L = NULL;
- if (spec->scope == APL_SCOPE_SERVER) {
+ /*
+ if (spec->scope == AP_LUA_SCOPE_SERVER) {
apr_reslist_t *reslist;
if (apr_pool_userdata_get((void **)&reslist,
apr_pool_userdata_set(L, spec->file, vm_release, lifecycle_pool);
}
} else {
- if (apr_pool_userdata_get((void **)&L, spec->file,
- lifecycle_pool) == APR_SUCCESS) {
-
- if(L==NULL) {
- ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool,
- "creating lua_State with file %s", spec->file);
- /* not available, so create */
-
- if(!vm_construct((void **)&L, spec, lifecycle_pool))
- apr_pool_userdata_set(L, spec->file, cleanup_lua,
- lifecycle_pool);
- }
+ */
+ if (apr_pool_userdata_get((void **)&L, spec->file,
+ lifecycle_pool) == APR_SUCCESS) {
+
+ if(L==NULL) {
+ ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool,
+ "creating lua_State with file %s", spec->file);
+ /* not available, so create */
+
+ if(!vm_construct((void **)&L, spec, lifecycle_pool)) {
+ apr_pool_userdata_set(L,
+ spec->file,
+ cleanup_lua,
+ lifecycle_pool);
}
+ }
}
+ /*}*/
return L;
}
#ifndef VMPREP_H
#define VMPREP_H
-#define APL_CODE_CACHE_STAT 1
-#define APL_CODE_CACHE_FOREVER 2
-#define APL_CODE_CACHE_NEVER 3
+#define AP_LUA_SCOPE_ONCE 1
+#define AP_LUA_SCOPE_REQUEST 2
+#define AP_LUA_SCOPE_CONN 3
+#define AP_LUA_SCOPE_SERVER 4
-#define APL_SCOPE_ONCE 1
-#define APL_SCOPE_REQUEST 2
-#define APL_SCOPE_CONN 3
-#define APL_SCOPE_SERVER 4
-
-
-/**
- * the ap_lua_?getvm family of functions is used to create and/or obtain
- * a handle to a lua state. If there is not an extant vm matching the
- * spec then a new one is created.
- */
-/* lua_State* ap_lua_rgetvm(request_rec *r, ap_lua_vm_spec *spec); */
-
-/* returns NULL if the spec requires a request scope */
-/* lua_State* ap_lua_cgetvm(conn_rec *r, ap_lua_vm_spec *spec);*/
-
-/* returns NULL if the spec requires a request scope or conn scope */
-/* lua_State* ap_lua_sgetvm(server_rec *r, ap_lua_vm_spec *spec); */
typedef void (*ap_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
void *ctx);
*/
typedef struct
{
-
/* NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG */
apr_array_header_t *package_paths;
apr_array_header_t *package_cpaths;
/* name of base file to load in the vm */
char *file;
- /* APL_CODE_CACHE_STAT | APL_CODE_CACHE_FOREVER | APL_CODE_CACHE_NEVER */
- int code_cache_style;
-
/* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_SERVER */
int scope;
- unsigned int vm_server_pool_min;
- unsigned int vm_server_pool_max;
+ unsigned int vm_server_pool_min;
+ unsigned int vm_server_pool_max;
+
+ ap_lua_state_open_callback cb;
+ void* cb_arg;
- ap_lua_state_open_callback cb;
- void* cb_arg;
/* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
apr_pool_t *pool;
typedef struct
{
- int code_cache_style;
char *function_name;
char *file_name;
int scope;
apr_size_t bytecode_len;
} ap_lua_mapped_handler_spec;
-typedef struct
-{
- apr_pool_t *pool;
- apr_hash_t *compiled_files;
- apr_thread_rwlock_t *compiled_files_lock;
-} ap_lua_code_cache;
-
/* remove and make static once out of mod_wombat.c */
AP_LUA_DECLARE(void) ap_lua_openlibs(lua_State *L);
return OK;
}
-/*
-static apr_status_t luahood(ap_filter_t *f, apr_bucket_brigade *bb) {
- apr_bucket* b;
- apr_status_t rs;
- for ( b = APR_BRIGADE_FIRST(bb);
- b != APR_BRIGADE_SENTINEL(bb);
- b = APR_BUCKET_NEXT(b))
- {
- if (APR_BUCKET_IS_EOS(b)) {kl
- break;
- }
- const char *buffer;
- size_t bytes;
- if (( rs = apr_bucket_read(b, &buffer, &bytes, APR_BLOCK_READ))) {
- ap_log_rerror(APLOG_MARK, APLOG_WARNING, rs, f->r, "read failure in luahood");
- return rs;
- }
- char *mine = apr_pstrmemdup(f->r->pool, buffer, bytes);
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, f->r, "sending '%s'", mine);
- }
-
- ap_pass_brigade(f->next, bb);
-
- return OK;
-}
-*/
/**
* "main"
if (strcmp(r->handler, "lua-script")) {
return DECLINED;
}
-
+
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "handling [%s] in mod_lua",
r->filename);
dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
&lua_module);
ap_lua_request_cfg *rcfg = ap_get_module_config(r->request_config,
&lua_module);
- mapped_request_details *d = rcfg->mapped_request_details;
- ap_lua_vm_spec *spec = NULL;
- if (!d) {
- d = apr_palloc(r->pool, sizeof(mapped_request_details));
- spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
- spec->scope = dcfg->vm_scope;
- spec->pool = spec->scope==APL_SCOPE_SERVER ? cfg->pool : r->pool;
- spec->file = r->filename;
- spec->package_paths = cfg->package_paths;
- spec->package_cpaths = cfg->package_cpaths;
- spec->vm_server_pool_min = cfg->vm_server_pool_min;
- spec->vm_server_pool_max = cfg->vm_server_pool_max;
- spec->cb = &lua_open_callback;
- spec->cb_arg = NULL;
- d->spec = spec;
- d->function_name = "handle";
- }
+ ap_lua_vm_spec *spec = NULL;
+ spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
+ spec->scope = dcfg->vm_scope;
+ spec->pool = spec->scope==AP_LUA_SCOPE_SERVER ? cfg->pool : r->pool;
+ spec->file = r->filename;
+ spec->package_paths = cfg->package_paths;
+ spec->package_cpaths = cfg->package_cpaths;
+ spec->vm_server_pool_min = cfg->vm_server_pool_min;
+ spec->vm_server_pool_max = cfg->vm_server_pool_max;
+ spec->cb = &lua_open_callback;
+ spec->cb_arg = NULL;
+
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"request details scope:%u, filename:%s, function:%s",
- d->spec->scope,
- d->spec->file,
- d->function_name);
+ spec->scope,
+ spec->file,
+ "handle");
L = ap_lua_get_lua_state(r->pool,
- d->spec);
-
+ spec);
+
if (!L) {
/* TODO annotate spec with failure reason */
r->status = HTTP_INTERNAL_SERVER_ERROR;
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
- lua_getglobal(L, d->function_name);
+ lua_getglobal(L, "handle");
if (!lua_isfunction(L, -1)) {
ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
"lua: Unable to find function %s in %s",
- d->function_name,
- d->spec->file);
+ "handle",
+ spec->file);
return HTTP_INTERNAL_SERVER_ERROR;
}
ap_lua_run_lua_request(L, r);
-/**
- * Like mod_alias except for lua handler fun :-)
- */
-static int lua_alias_munger(request_rec *r)
-{
- ap_lua_vm_spec *spec;
- ap_lua_request_cfg *rcfg = ap_get_module_config(r->request_config,
- &lua_module);
- const ap_lua_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 ap_lua_mapped_handler_spec *cnd =
- ((const ap_lua_mapped_handler_spec **) cfg->mapped_handlers->elts)[i];
-
- if (OK == ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH,
- matches, 0)) {
- mapped_request_details *d;
- r->handler = "lua-script";
-
- spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
- spec->file = ap_pregsub(r->pool, cnd->file_name, r->uri,
- AP_MAX_REG_MATCH, matches);
- spec->scope = cnd->scope;
- spec->bytecode = cnd->bytecode;
- spec->bytecode_len = cnd->bytecode_len;
- if (spec->scope == APL_SCOPE_ONCE) {
- spec->pool = r->pool;
- }
-
- spec->cb = &lua_open_callback;
- spec->cb_arg = NULL;
-
- d = apr_palloc(r->pool, sizeof(mapped_request_details));
-
- d->function_name = ap_pregsub(r->pool, cnd->function_name, r->uri,
- AP_MAX_REG_MATCH, matches);
- d->spec = spec;
-
- /* now do replacement on method name where? */
- r->filename = apr_pstrdup(r->pool, spec->file);
- rcfg->mapped_request_details = d;
- return OK;
- }
- }
- return DECLINED;
-}
/* ---------------- Configury stuff --------------- */
spec->vm_server_pool_max = cfg->vm_server_pool_max;
spec->bytecode = hook_spec->bytecode;
spec->bytecode_len = hook_spec->bytecode_len;
- spec->pool = spec->scope==APL_SCOPE_SERVER ? cfg->pool : r->pool;
+ spec->pool = spec->scope==AP_LUA_SCOPE_SERVER ? cfg->pool : r->pool;
spec->package_paths = cfg->package_paths;
spec->package_cpaths = cfg->package_cpaths;
spec->cb = &lua_open_callback;
{
ap_lua_dir_cfg *cfg = (ap_lua_dir_cfg *) _cfg;
if (strcmp("once", scope) == 0) {
- cfg->vm_scope = APL_SCOPE_ONCE;
+ cfg->vm_scope = AP_LUA_SCOPE_ONCE;
}
else if (strcmp("request", scope) == 0) {
- cfg->vm_scope = APL_SCOPE_REQUEST;
+ cfg->vm_scope = AP_LUA_SCOPE_REQUEST;
}
else if (strcmp("conn", scope) == 0) {
- cfg->vm_scope = APL_SCOPE_CONN;
+ cfg->vm_scope = AP_LUA_SCOPE_CONN;
}
else if (strcmp("server", scope) == 0) {
- cfg->vm_scope = APL_SCOPE_SERVER;
+ cfg->vm_scope = AP_LUA_SCOPE_SERVER;
if (min)
cfg->vm_server_pool_min = atoi(min);
if (max)
}
-/**
- * Called for config directive which looks like
- * AddLuaHandler /alias /path/to/lua/file.lua [handler_function_name]
- */
-static const char *lua_map_handler(cmd_parms *cmd, void *_cfg,
- const char *path, const char *file,
- const char *function)
-{
- ap_lua_dir_cfg *cfg = (ap_lua_dir_cfg *) _cfg;
- apr_status_t rv;
- const char *function_name;
- function_name = function ? function : "handle";
- rv = ap_lua_map_handler(cfg, file, function_name, path, "once");
- if (rv != APR_SUCCESS) {
- return apr_psprintf(cmd->pool,
- "Unable to configure a lua handler for path "
- "'%s', handler %s#%s",
- path, file, function_name);
- }
- return NULL;
-}
static const char *register_lua_root(cmd_parms *cmd, void *_cfg,
const char *root)
AP_INIT_TAKE1("LuaPackageCPath", register_package_cdir, NULL, OR_ALL,
"Add a directory to lua's package.cpath"),
- AP_INIT_TAKE23("LuaMapHandler", lua_map_handler, NULL, OR_ALL,
- "Map a path to a lua handler"),
AP_INIT_TAKE23("LuaHookTranslateName", register_translate_name_hook, NULL,
OR_ALL,
"Provide a hook for the translate name phase of request processing"),
+
AP_INIT_RAW_ARGS("<LuaHookTranslateName", register_translate_name_block,
NULL,
EXEC_ON_READ | OR_ALL,
cfg->pool = p;
cfg->hooks = apr_hash_make(p);
cfg->dir = apr_pstrdup(p, dir);
- cfg->vm_scope = APL_SCOPE_ONCE;
+ cfg->vm_scope = AP_LUA_SCOPE_ONCE;
return cfg;
}
APR_HOOK_MIDDLE);
ap_hook_quick_handler(lua_quick_harness, NULL, NULL, APR_HOOK_FIRST);
- ap_hook_translate_name(lua_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
ap_hook_post_config(lua_post_config, NULL, NULL, APR_HOOK_MIDDLE);
APR_OPTIONAL_HOOK(ap_lua, lua_open, lua_open_hook, NULL, NULL,