summaryrefslogtreecommitdiffstats
path: root/modules/lua
diff options
context:
space:
mode:
authorStefan Fritsch <sf@apache.org>2012-06-17 00:46:30 +0200
committerStefan Fritsch <sf@apache.org>2012-06-17 00:46:30 +0200
commitd7ed5d0ed6de4ae3c69fa0561432d890219c11ac (patch)
treebe29b0e9ca963c59f75d564d73761af8b591305b /modules/lua
parentchange various strings from char * to const char * (diff)
downloadapache2-d7ed5d0ed6de4ae3c69fa0561432d890219c11ac.tar.xz
apache2-d7ed5d0ed6de4ae3c69fa0561432d890219c11ac.zip
factor common code into utility function
also improve logging a bit and adjust some log levels git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1351018 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'modules/lua')
-rw-r--r--modules/lua/mod_lua.c182
1 files changed, 93 insertions, 89 deletions
diff --git a/modules/lua/mod_lua.c b/modules/lua/mod_lua.c
index 0598cc6e10..18553eb212 100644
--- a/modules/lua/mod_lua.c
+++ b/modules/lua/mod_lua.c
@@ -78,73 +78,114 @@ static int lua_open_hook(lua_State *L, apr_pool_t *p)
return OK;
}
+static const char *scope_to_string(unsigned int scope)
+{
+ switch (scope) {
+ case AP_LUA_SCOPE_ONCE:
+ case AP_LUA_SCOPE_UNSET:
+ return "once";
+ case AP_LUA_SCOPE_REQUEST:
+ return "request";
+ case AP_LUA_SCOPE_CONN:
+ return "conn";
+#if APR_HAS_THREADS
+ case AP_LUA_SCOPE_THREAD:
+ return "thread";
+#endif
+ default:
+ ap_assert(0);
+ }
+}
+
+static ap_lua_vm_spec *create_vm_spec(apr_pool_t **lifecycle_pool,
+ request_rec *r,
+ const ap_lua_dir_cfg *cfg,
+ const ap_lua_server_cfg *server_cfg,
+ const char *filename,
+ const char *bytecode,
+ apr_size_t bytecode_len,
+ const char *function,
+ const char *what)
+{
+ apr_pool_t *pool;
+ ap_lua_vm_spec *spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
+
+ spec->scope = cfg->vm_scope;
+ spec->pool = r->pool;
+ spec->package_paths = cfg->package_paths;
+ spec->package_cpaths = cfg->package_cpaths;
+ spec->cb = &lua_open_callback;
+ spec->cb_arg = NULL;
+ spec->bytecode = bytecode;
+ spec->bytecode_len = bytecode_len;
+
+ if (filename) {
+ char *file;
+ apr_filepath_merge(&file, server_cfg->root_path,
+ filename, APR_FILEPATH_NOTRELATIVE, r->pool);
+ spec->file = file;
+ }
+ else {
+ spec->file = r->filename;
+ }
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE2, 0, r, APLOGNO()
+ "%s details: scope: %s, file: %s, func: %s",
+ what, scope_to_string(spec->scope), spec->file,
+ function ? function : "-");
+
+ switch (spec->scope) {
+ case AP_LUA_SCOPE_ONCE:
+ case AP_LUA_SCOPE_UNSET:
+ apr_pool_create(&pool, r->pool);
+ break;
+ case AP_LUA_SCOPE_REQUEST:
+ pool = r->pool;
+ break;
+ case AP_LUA_SCOPE_CONN:
+ pool = r->connection->pool;
+ break;
+#if APR_HAS_THREADS
+ case AP_LUA_SCOPE_THREAD:
+ pool = apr_thread_pool_get(r->connection->current_thread);
+ break;
+#endif
+ default:
+ ap_assert(0);
+ }
+
+ *lifecycle_pool = pool;
+ return spec;
+}
+
/**
* "main"
*/
static int lua_handler(request_rec *r)
{
- ap_lua_dir_cfg *dcfg;
- apr_pool_t *pool;
if (strcmp(r->handler, "lua-script")) {
return DECLINED;
}
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01472) "handling [%s] in mod_lua",
- r->filename);
- dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE1, 0, r, APLOGNO(01472)
+ "handling [%s] in mod_lua", r->filename);
+ /* XXX: This seems wrong because it may generate wrong headers for HEAD requests */
if (!r->header_only) {
lua_State *L;
+ apr_pool_t *pool;
const ap_lua_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
&lua_module);
- ap_lua_vm_spec *spec = NULL;
+ ap_lua_vm_spec *spec = create_vm_spec(&pool, r, cfg, NULL, NULL, NULL,
+ 0, "handle", "request handler");
- spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
- spec->scope = dcfg->vm_scope;
- spec->pool = r->pool;
- spec->file = r->filename;
- spec->package_paths = cfg->package_paths;
- spec->package_cpaths = cfg->package_cpaths;
- spec->cb = &lua_open_callback;
- spec->cb_arg = NULL;
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01473)
- "request details scope:%u, filename:%s, function:%s",
- spec->scope,
- spec->file,
- "handle");
-
- switch (spec->scope) {
- case AP_LUA_SCOPE_ONCE:
- case AP_LUA_SCOPE_UNSET:
- apr_pool_create(&pool, r->pool);
- break;
- case AP_LUA_SCOPE_REQUEST:
- pool = r->pool;
- break;
- case AP_LUA_SCOPE_CONN:
- pool = r->connection->pool;
- break;
- case AP_LUA_SCOPE_THREAD:
- #if APR_HAS_THREADS
- pool = apr_thread_pool_get(r->connection->current_thread);
- break;
- #endif
- default:
- ap_assert(0);
- }
-
- L = ap_lua_get_lua_state(pool,
- spec);
-
+ L = ap_lua_get_lua_state(pool, spec);
if (!L) {
/* TODO annotate spec with failure reason */
r->status = HTTP_INTERNAL_SERVER_ERROR;
ap_rputs("Unable to compile VM, see logs", r);
return HTTP_INTERNAL_SERVER_ERROR;
}
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01474) "got a vm!");
+ ap_log_rerror(APLOG_MARK, APLOG_TRACE3, 0, r, APLOGNO(01474) "got a vm!");
lua_getglobal(L, "handle");
if (!lua_isfunction(L, -1)) {
ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, APLOGNO(01475)
@@ -163,7 +204,6 @@ static int lua_handler(request_rec *r)
-
/* ---------------- Configury stuff --------------- */
/** harnesses for magic hooks **/
@@ -184,54 +224,18 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name, int ap
if (hook_specs) {
int i;
for (i = 0; i < hook_specs->nelts; i++) {
- char *file;
ap_lua_mapped_handler_spec *hook_spec =
((ap_lua_mapped_handler_spec **) hook_specs->elts)[i];
if (hook_spec == NULL) {
continue;
}
- spec = apr_pcalloc(r->pool, sizeof(ap_lua_vm_spec));
-
- spec->file = hook_spec->file_name;
- spec->scope = cfg->vm_scope;
- spec->bytecode = hook_spec->bytecode;
- spec->bytecode_len = hook_spec->bytecode_len;
- spec->pool = r->pool;
- spec->package_paths = cfg->package_paths;
- spec->package_cpaths = cfg->package_cpaths;
- spec->cb = &lua_open_callback;
- spec->cb_arg = NULL;
-
- apr_filepath_merge(&file, server_cfg->root_path,
- spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
- spec->file = file;
-
- ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(01476)
- "request details scope:%u, filename:%s, function:%s",
- spec->scope,
- spec->file,
- hook_spec->function_name ? hook_spec->function_name : "-");
-
- switch (spec->scope) {
- case AP_LUA_SCOPE_ONCE:
- case AP_LUA_SCOPE_UNSET:
- apr_pool_create(&pool, r->pool);
- break;
- case AP_LUA_SCOPE_REQUEST:
- pool = r->pool;
- break;
- case AP_LUA_SCOPE_CONN:
- pool = r->connection->pool;
- break;
- case AP_LUA_SCOPE_THREAD:
- #if APR_HAS_THREADS
- pool = apr_thread_pool_get(r->connection->current_thread);
- break;
- #endif
- default:
- ap_assert(0);
- }
+ spec = create_vm_spec(&pool, r, cfg, server_cfg,
+ hook_spec->file_name,
+ hook_spec->bytecode,
+ hook_spec->bytecode_len,
+ hook_spec->function_name,
+ "request hook");
L = ap_lua_get_lua_state(pool, spec);