apr_table_t *check_apr_table(lua_State *L, int index)
{
+ apr_table_t *t;
luaL_checkudata(L, index, "Apr.Table");
- apr_table_t *t = (apr_table_t *) lua_unboxpointer(L, index);
+ t = (apr_table_t *) lua_unboxpointer(L, index);
return t;
}
static apl_dir_cfg *check_dir_config(lua_State *L, int index)
{
+ apl_dir_cfg *cfg;
luaL_checkudata(L, index, "Apache2.DirConfig");
- apl_dir_cfg *cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
+ cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
return cfg;
}
static cmd_parms *check_cmd_parms(lua_State *L, int index)
{
+ cmd_parms *cmd;
luaL_checkudata(L, index, "Apache2.CommandParameters");
- cmd_parms *cmd = (cmd_parms *) lua_unboxpointer(L, index);
+ cmd = (cmd_parms *) lua_unboxpointer(L, index);
return cmd;
}
*/
static request_rec *apl_check_request_rec(lua_State *L, int index)
{
+ request_rec *r;
luaL_checkudata(L, index, "Apache2.Request");
- request_rec *r = (request_rec *) lua_unboxpointer(L, index);
+ r = (request_rec *) lua_unboxpointer(L, index);
return r;
}
static int req_aprtable2luatable_cb(void *l, const char *key,
const char *value)
{
+ int t;
lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */
/* rstack_dump(L, RRR, "start of cb"); */
/* L is [table<s,t>, table<s,s>] */
lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
/* rstack_dump(L, RRR, "after getfield"); */
- int t = lua_type(L, -1);
+ t = lua_type(L, -1);
switch (t) {
case LUA_TNIL:
case LUA_TNONE:{
/* r:parseargs() returning a lua table */
static int req_parseargs(lua_State *L)
{
+ apr_table_t *form_table;
request_rec *r = apl_check_request_rec(L, 1);
lua_newtable(L);
lua_newtable(L); /* [table, table] */
- apr_table_t *form_table;
ap_args_to_table(r, &form_table);
apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
return 2; /* [table<string, string>, table<string, array<string>>] */
static void pstack_dump(lua_State *L, apr_pool_t *r, int level,
const char *msg)
{
- ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
-
int i;
int top = lua_gettop(L);
+
+ ap_log_perror(APLOG_MARK, level, 0, r, "Lua Stack Dump: [%s]", msg);
+
for (i = 1; i <= top; i++) {
int t = lua_type(L, i);
switch (t) {
apr_pool_t *pool,
apr_array_header_t *paths, const char *file)
{
+ const char *current;
+ const char *parent_dir;
+ const char *pattern;
+ const char *modified;
+ char *part;
+ int i;
+
lua_getglobal(L, "package");
lua_getfield(L, -1, field);
- const char *current = lua_tostring(L, -1);
- const char *parent_dir = ap_make_dirstr_parent(pool, file);
- const char *pattern = apr_pstrcat(pool, parent_dir, sub_pat, NULL);
+ 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);
- const char *modified = lua_tostring(L, -1);
+ modified = lua_tostring(L, -1);
lua_pop(L, 2);
- char *part = apr_pstrdup(pool, modified);
- int i;
+ part = apr_pstrdup(pool, modified);
for (i = 0; i < paths->nelts; i++) {
const char *new_path = ((const char **) paths->elts)[i];
part = apr_pstrcat(pool, part, ";", new_path, NULL);
/* not available, so create */
L = luaL_newstate();
luaL_openlibs(L);
- if (package_paths)
+ if (package_paths) {
munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
package_paths, spec->file);
- if (package_cpaths)
+ }
+ if (package_cpaths) {
munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
package_cpaths, spec->file);
+ }
if (cb) {
cb(L, lifecycle_pool, btn);
*/
static void report_lua_error(lua_State *L, request_rec *r)
{
+ const char *lua_response;
r->status = 500;
r->content_type = "text/html";
ap_rputs("<b>Error!</b>\n", r);
ap_rputs("<p>", r);
- const char *lua_response = lua_tostring(L, -1);
+ lua_response = lua_tostring(L, -1);
ap_rputs(lua_response, r);
ap_rputs("</p>\n", r);
apl_dir_cfg *dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
if (!r->header_only) {
+ lua_State *L;
+ const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config,
+ &lua_module);
apl_request_cfg *rcfg =
ap_get_module_config(r->request_config, &lua_module);
mapped_request_details *d = rcfg->mapped_request_details;
apl_vm_spec *spec = NULL;
+
if (!d) {
d = apr_palloc(r->pool, sizeof(mapped_request_details));
spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
d->spec = spec;
d->function_name = "handle";
}
+
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
"request details scope:%u, cache:%u", d->spec->scope,
d->spec->code_cache_style);
- 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,
- cfg->package_paths,
- cfg->package_cpaths,
- &lua_open_callback, NULL);
+ L = apl_get_lua_state(r->pool,
+ d->spec,
+ cfg->package_paths,
+ cfg->package_cpaths,
+ &lua_open_callback, NULL);
ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
if (!L) {
*/
static int apl_alias_munger(request_rec *r)
{
+ apl_vm_spec *spec;
+ apl_request_cfg *rcfg = ap_get_module_config(r->request_config,
+ &lua_module);
const apl_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 apl_mapped_handler_spec *cnd =
- ((const apl_mapped_handler_spec **) cfg->mapped_handlers->
- elts)[i];
+ ((const apl_mapped_handler_spec **) cfg->mapped_handlers->elts)[i];
+
if (OK ==
ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH, matches,
0)) {
r->handler = "lua-script";
- apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
+ spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec->file =
ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH,
matches);
/* now do replacement on method name where? */
r->filename = apr_pstrdup(r->pool, spec->file);
- apl_request_cfg *rcfg =
- ap_get_module_config(r->request_config, &lua_module);
rcfg->mapped_request_details = d;
return OK;
}
static int lua_request_rec_hook_harness(request_rec *r, const char *name)
{
+ lua_State *L;
+ apl_vm_spec *spec;
apl_server_cfg *server_cfg = ap_get_module_config(r->server->module_config,
&lua_module);
const apl_dir_cfg *cfg =
if (hook_spec == NULL) {
continue;
}
- apl_vm_spec *spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
+ spec = apr_pcalloc(r->pool, sizeof(apl_vm_spec));
spec->file = hook_spec->file_name;
spec->code_cache_style = hook_spec->code_cache_style;
apr_filepath_merge(&spec->file, server_cfg->root_path,
spec->file, APR_FILEPATH_NOTRELATIVE, r->pool);
- lua_State *L = apl_get_lua_state(r->pool,
- spec,
- cfg->package_paths,
- cfg->package_cpaths,
- &lua_open_callback, NULL);
+ L = apl_get_lua_state(r->pool,
+ spec,
+ cfg->package_paths,
+ cfg->package_cpaths,
+ &lua_open_callback, NULL);
lua_State *lvm;
char *tmp;
int rv;
+ ap_directive_t **current;
apr_snprintf(buf, sizeof(buf), "%u", cmd->config_file->line_number);
spec->file_name =
lua_close(lvm);
}
- ap_directive_t **current = mconfig;
+ current = mconfig;
/* Here, we have to replace our current config node for the next pass */
if (!*current) {
const char *file,
const char *function)
{
+ apl_mapped_handler_spec *spec;
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
apr_array_header_t *hook_specs =
APR_HASH_KEY_STRING, hook_specs);
}
- apl_mapped_handler_spec *spec =
- apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
+ spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
spec->file_name = apr_pstrdup(cmd->pool, file);
spec->function_name = apr_pstrdup(cmd->pool, function);
spec->scope = cfg->vm_scope;
const char *function)
{
apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
-
+ apr_status_t rv;
const char *function_name;
function_name = function ? function : "handle";
- apr_status_t rv;
rv = apl_lua_map_handler(cfg, file, function_name, path, "once");
if (rv != APR_SUCCESS) {
return apr_psprintf(cmd->pool,