]> granicus.if.org Git - apache/commitdiff
Reformat mod_lua according to the HTTP Server Project C Style Guide:
authorPaul Querna <pquerna@apache.org>
Sun, 21 Dec 2008 21:41:52 +0000 (21:41 +0000)
committerPaul Querna <pquerna@apache.org>
Sun, 21 Dec 2008 21:41:52 +0000 (21:41 +0000)
  <http://httpd.apache.org/dev/styleguide.html>
No functional changes.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@728516 13f79535-47bb-0310-9956-ffa450edef68

modules/lua/lua_apr.c
modules/lua/lua_apr.h
modules/lua/lua_config.c
modules/lua/lua_config.h
modules/lua/lua_request.c
modules/lua/lua_request.h
modules/lua/lua_vmprep.c
modules/lua/lua_vmprep.h
modules/lua/mod_lua.c
modules/lua/mod_lua.h

index b744ea0900203b9b4ff59cbca9225c2c0e2ba7bb..c3b4fb753d6a8c22840376c0a0663f01c2c6f730 100644 (file)
 #endif
 
 
-apr_table_t* check_apr_table(lua_State* L, int index) {
+apr_table_t *check_apr_table(lua_State *L, int index)
+{
     luaL_checkudata(L, index, "Apr.Table");
-    apr_table_t* t = (apr_table_t*)lua_unboxpointer(L, index);
+    apr_table_t *t = (apr_table_t *) lua_unboxpointer(L, index);
     return t;
 }
 
 
-void apl_push_apr_table(lua_State* L, const char *name, apr_table_t *t) {
-    lua_boxpointer(L, t);    
+void apl_push_apr_table(lua_State *L, const char *name, apr_table_t *t)
+{
+    lua_boxpointer(L, t);
     luaL_getmetatable(L, "Apr.Table");
     lua_setmetatable(L, -2);
     lua_setfield(L, -2, name);
 }
 
-static int lua_table_set(lua_State* L) {
+static int lua_table_set(lua_State *L)
+{
     apr_table_t *t = check_apr_table(L, 1);
-    const charkey = luaL_checkstring(L, 2);
-    const charval = luaL_checkstring(L, 3);
+    const char *key = luaL_checkstring(L, 2);
+    const char *val = luaL_checkstring(L, 3);
 
     apr_table_set(t, key, val);
     return 0;
 }
 
-static int lua_table_get(lua_State* L) {
+static int lua_table_get(lua_State *L)
+{
     apr_table_t *t = check_apr_table(L, 1);
-    const charkey = luaL_checkstring(L, 2);
+    const char *key = luaL_checkstring(L, 2);
     const char *val = apr_table_get(t, key);
     lua_pushstring(L, val);
     return 1;
@@ -70,7 +74,8 @@ static const luaL_reg lua_table_methods[] = {
 };
 
 
-int apr_lua_init(lua_State *L, apr_pool_t *p) {
+int apr_lua_init(lua_State *L, apr_pool_t *p)
+{
     luaL_newmetatable(L, "Apr.Table");
     luaL_openlib(L, "apr_table", lua_table_methods, 0);
     lua_pushstring(L, "__index");
@@ -82,7 +87,6 @@ int apr_lua_init(lua_State *L, apr_pool_t *p) {
     lua_pushstring(L, "set");
     lua_gettable(L, 2);
     lua_settable(L, 1);
-    
+
     return 0;
 }
-
index c492ee871633adcd0677c2b81c55f977daa5fa74..d5a2efe0af38fd7a0056b9a5e3d793df563ae452 100644 (file)
@@ -18,8 +18,8 @@
 #ifndef _LUA_APR_H_
 #define _LUA_APR_H_
 
-int apr_lua_init(lua_State *L, apr_pool_t *p);
-apr_table_t* check_apr_table(lua_State* L, int index);
-void apl_push_apr_table(lua_StateL, const char *name, apr_table_t *t);
+int apr_lua_init(lua_State *L, apr_pool_t * p);
+apr_table_t *check_apr_table(lua_State *L, int index);
+void apl_push_apr_table(lua_State *L, const char *name, apr_table_t *t);
 
 #endif /* !_LUA_APR_H_ */
index 46fa419a5ed9b938b59b0634fe380e2abbb50b0e..858ae0aafdacf60ca944ac38e47666e20c9530c1 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include "lua_config.h"
 #include "lua_vmprep.h"
 
-static apl_dir_cfg* check_dir_config(lua_State* L, int index) {
+static apl_dir_cfg *check_dir_config(lua_State *L, int index)
+{
     luaL_checkudata(L, index, "Apache2.DirConfig");
-    apl_dir_cfg *cfg = (apl_dir_cfg*)lua_unboxpointer(L, index);
-    return cfg;    
+    apl_dir_cfg *cfg = (apl_dir_cfg *) lua_unboxpointer(L, index);
+    return cfg;
 }
 
-static cmd_parms* check_cmd_parms(lua_State* L, int index) {
+static cmd_parms *check_cmd_parms(lua_State *L, int index)
+{
     luaL_checkudata(L, index, "Apache2.CommandParameters");
-    cmd_parms *cmd = (cmd_parms*)lua_unboxpointer(L, index);
-    return cmd;    
+    cmd_parms *cmd = (cmd_parms *) lua_unboxpointer(L, index);
+    return cmd;
 }
 
-static int apl_toscope(const char *name) {
-    if (0 == apr_strnatcmp("once", name)) return APL_SCOPE_ONCE;
-    if (0 == apr_strnatcmp("request", name)) return APL_SCOPE_REQUEST;
-    if (0 == apr_strnatcmp("connection", name)) return APL_SCOPE_CONN;
-    if (0 == apr_strnatcmp("conn", name)) return APL_SCOPE_CONN;
-    if (0 == apr_strnatcmp("server", name)) return APL_SCOPE_SERVER;
+static int apl_toscope(const char *name)
+{
+    if (0 == apr_strnatcmp("once", name))
+        return APL_SCOPE_ONCE;
+    if (0 == apr_strnatcmp("request", name))
+        return APL_SCOPE_REQUEST;
+    if (0 == apr_strnatcmp("connection", name))
+        return APL_SCOPE_CONN;
+    if (0 == apr_strnatcmp("conn", name))
+        return APL_SCOPE_CONN;
+    if (0 == apr_strnatcmp("server", name))
+        return APL_SCOPE_SERVER;
     return APL_SCOPE_ONCE;
 }
 
-apr_status_t apl_lua_map_handler(apl_dir_cfg *cfg, 
-                                 const char *file, 
+apr_status_t apl_lua_map_handler(apl_dir_cfg *cfg,
+                                 const char *file,
                                  const char *function,
-                                 const char *pattern,
-                                 const char *scope) {
+                                 const char *pattern, const char *scope)
+{
     apr_status_t rv;
-    apl_mapped_handler_spec *handler = apr_palloc(cfg->pool, sizeof(apl_mapped_handler_spec));
+    apl_mapped_handler_spec *handler =
+        apr_palloc(cfg->pool, sizeof(apl_mapped_handler_spec));
     handler->uri_pattern = NULL;
     handler->function_name = NULL;
-    
+
     ap_regex_t *uri_pattern = apr_palloc(cfg->pool, sizeof(ap_regex_t));
     if ((rv = ap_regcomp(uri_pattern, pattern, 0)) != APR_SUCCESS) {
         return rv;
@@ -56,19 +65,22 @@ apr_status_t apl_lua_map_handler(apl_dir_cfg *cfg,
     handler->file_name = apr_pstrdup(cfg->pool, file);
     handler->uri_pattern = uri_pattern;
     handler->scope = apl_toscope(scope);
-    
+
     handler->function_name = apr_pstrdup(cfg->pool, function);
-    *(const apl_mapped_handler_spec**)apr_array_push(cfg->mapped_handlers) = handler;    
+    *(const apl_mapped_handler_spec **) apr_array_push(cfg->mapped_handlers) =
+        handler;
     return APR_SUCCESS;
 }
 
 /* Change to use apl_lua_map_handler */
-static int cfg_lua_map_handler(lua_State *L) {
+static int cfg_lua_map_handler(lua_State *L)
+{
     apl_dir_cfg *cfg = check_dir_config(L, 1);
-    apl_mapped_handler_spec *handler = apr_palloc(cfg->pool, sizeof(apl_mapped_handler_spec));
+    apl_mapped_handler_spec *handler =
+        apr_palloc(cfg->pool, sizeof(apl_mapped_handler_spec));
     handler->uri_pattern = NULL;
     handler->function_name = NULL;
-    
+
     luaL_checktype(L, 2, LUA_TTABLE);
     lua_getfield(L, 2, "file");
     if (lua_isstring(L, -1)) {
@@ -76,19 +88,20 @@ static int cfg_lua_map_handler(lua_State *L) {
         handler->file_name = apr_pstrdup(cfg->pool, file);
     }
     lua_pop(L, 1);
-    
+
     lua_getfield(L, 2, "pattern");
     if (lua_isstring(L, -1)) {
         const char *pattern = lua_tostring(L, -1);
-        
+
         ap_regex_t *uri_pattern = apr_palloc(cfg->pool, sizeof(ap_regex_t));
         if (ap_regcomp(uri_pattern, pattern, 0) != OK) {
-            return luaL_error(L, "Unable to compile regular expression, '%s'", pattern);
+            return luaL_error(L, "Unable to compile regular expression, '%s'",
+                              pattern);
         }
         handler->uri_pattern = uri_pattern;
     }
     lua_pop(L, 1);
-    
+
     lua_getfield(L, 2, "scope");
     if (lua_isstring(L, -1)) {
         const char *scope = lua_tostring(L, -1);
@@ -98,7 +111,7 @@ static int cfg_lua_map_handler(lua_State *L) {
         handler->scope = APL_SCOPE_ONCE;
     }
     lua_pop(L, 1);
-    
+
     lua_getfield(L, 2, "func");
     if (lua_isstring(L, -1)) {
         const char *value = lua_tostring(L, -1);
@@ -108,13 +121,15 @@ static int cfg_lua_map_handler(lua_State *L) {
         handler->function_name = "handle";
     }
     lua_pop(L, 1);
-    
-    
-    *(const apl_mapped_handler_spec**)apr_array_push(cfg->mapped_handlers) = handler;    
+
+
+    *(const apl_mapped_handler_spec **) apr_array_push(cfg->mapped_handlers) =
+        handler;
     return 0;
 }
 
-static int cfg_directory(lua_State *L) {
+static int cfg_directory(lua_State *L)
+{
     apl_dir_cfg *cfg = check_dir_config(L, 1);
     lua_pushstring(L, cfg->dir);
     return 1;
@@ -129,69 +144,104 @@ static int cfg_directory(lua_State *L) {
 static const struct luaL_Reg cfg_methods[] = {
     {"match_handler", cfg_lua_map_handler},
     {"directory", cfg_directory},
-   /* {"root", cfg_root}, */
+    /* {"root", cfg_root}, */
     {NULL, NULL}
 };
 
 
 
-static int cmd_foo(lua_State *L) {
+static int cmd_foo(lua_State *L)
+{
     cmd_parms *cmd = check_cmd_parms(L, 1);
     ap_log_error(APLOG_MARK, APLOG_ERR, 0, cmd->server, "FOO!");
     return 0;
 }
 
 /* helper function for the logging functions below */
-static int cmd_log_at(lua_State* L, int level) {
+static int cmd_log_at(lua_State *L, int level)
+{
     cmd_parms *cmd = check_cmd_parms(L, 1);
     lua_Debug dbg;
-    
+
     lua_getstack(L, 1, &dbg);
     lua_getinfo(L, "Sl", &dbg);
 
-    const charmsg = luaL_checkstring(L, 2);
+    const char *msg = luaL_checkstring(L, 2);
     ap_log_error(dbg.source, dbg.currentline, level, 0, cmd->server, msg);
     return 0;
 }
 
 /* r:debug(String) and friends which use apache logging */
-static int cmd_emerg(lua_State* L)  { cmd_log_at(L, APLOG_EMERG); return 0; }
-static int cmd_alert(lua_State* L)  { cmd_log_at(L, APLOG_ALERT); return 0; }
-static int cmd_crit(lua_State* L)   { cmd_log_at(L, APLOG_CRIT); return 0; }
-static int cmd_err(lua_State* L)    { cmd_log_at(L, APLOG_ERR); return 0; }
-static int cmd_warn(lua_State* L)   { cmd_log_at(L, APLOG_WARNING); return 0; }
-static int cmd_notice(lua_State* L) { cmd_log_at(L, APLOG_NOTICE); return 0; }
-static int cmd_info(lua_State* L)   { cmd_log_at(L, APLOG_INFO); return 0; }
-static int cmd_debug(lua_State* L)  { cmd_log_at(L, APLOG_DEBUG); return 0; }
+static int cmd_emerg(lua_State *L)
+{
+    cmd_log_at(L, APLOG_EMERG);
+    return 0;
+}
+static int cmd_alert(lua_State *L)
+{
+    cmd_log_at(L, APLOG_ALERT);
+    return 0;
+}
+static int cmd_crit(lua_State *L)
+{
+    cmd_log_at(L, APLOG_CRIT);
+    return 0;
+}
+static int cmd_err(lua_State *L)
+{
+    cmd_log_at(L, APLOG_ERR);
+    return 0;
+}
+static int cmd_warn(lua_State *L)
+{
+    cmd_log_at(L, APLOG_WARNING);
+    return 0;
+}
+static int cmd_notice(lua_State *L)
+{
+    cmd_log_at(L, APLOG_NOTICE);
+    return 0;
+}
+static int cmd_info(lua_State *L)
+{
+    cmd_log_at(L, APLOG_INFO);
+    return 0;
+}
+static int cmd_debug(lua_State *L)
+{
+    cmd_log_at(L, APLOG_DEBUG);
+    return 0;
+}
 
 
-static const struct luaL_Reg cmd_methods[] = {    
+static const struct luaL_Reg cmd_methods[] = {
     {"foo", cmd_foo},
-    
-    {"debug",   cmd_debug},
-    {"info",    cmd_info},
-    {"notice",  cmd_notice},
-    {"warn",    cmd_warn},
-    {"err",     cmd_err},
-    {"crit",    cmd_crit},
-    {"alert",   cmd_alert},
-    {"emerg",   cmd_emerg},
+
+    {"debug", cmd_debug},
+    {"info", cmd_info},
+    {"notice", cmd_notice},
+    {"warn", cmd_warn},
+    {"err", cmd_err},
+    {"crit", cmd_crit},
+    {"alert", cmd_alert},
+    {"emerg", cmd_emerg},
 
     {NULL, NULL}
 };
 
-void apl_load_config_lmodule(lua_State *L) {
-    luaL_newmetatable(L, "Apache2.DirConfig"); /* [metatable] */
-    lua_pushvalue(L, -1); 
+void apl_load_config_lmodule(lua_State *L)
+{
+    luaL_newmetatable(L, "Apache2.DirConfig");  /* [metatable] */
+    lua_pushvalue(L, -1);
+
+    lua_setfield(L, -2, "__index");
+    luaL_register(L, NULL, cfg_methods);        /* [metatable] */
+
 
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, cfg_methods); /* [metatable] */
-    
-    
     luaL_newmetatable(L, "Apache2.CommandParameters");
-    lua_pushvalue(L, -1); 
+    lua_pushvalue(L, -1);
+
+    lua_setfield(L, -2, "__index");
+    luaL_register(L, NULL, cmd_methods);        /* [metatable] */
 
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, cmd_methods); /* [metatable] */
-    
 }
index db56e949cbf07f0248f076eb683cfd09222ae89e..8f8761ee961c02b51bbdb51038575bfe544ca07e 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include "mod_lua.h"
 
 #ifndef _APL_CONFIG_H_
 #define _APL_CONFIG_H_
-                 
-APR_DECLARE(void) apl_load_config_lmodule(lua_State *L);                                                                 
 
-APR_DECLARE(apr_status_t) apl_lua_map_handler(apl_dir_cfg *cfg, 
-                                              const char *file, 
+APR_DECLARE(void) apl_load_config_lmodule(lua_State *L);
+
+APR_DECLARE(apr_status_t) apl_lua_map_handler(apl_dir_cfg *cfg,
+                                              const char *file,
                                               const char *function,
                                               const char *pattern,
                                               const char *scope);
 
 #endif /* !_APL_CONFIG_H_ */
-
index 7b555f9b45e691e814671109650156f4faaddd59..7717fbd3c1782e5d17cfa814f37eb81e1411acbe 100644 (file)
 #include "util_script.h"
 #include "lua_apr.h"
 
-typedef char* (*req_field_string_f) (request_rec* r);
-typedef int (*req_field_int_f) (request_rec* r);
+typedef char *(*req_field_string_f) (request_rec * r);
+typedef int (*req_field_int_f) (request_rec * r);
 
-void rstack_dump(lua_State* L, request_rec* r, const char* msg) {
+void rstack_dump(lua_State *L, request_rec *r, const char *msg)
+{
     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "Lua Stack Dump: [%s]", msg);
 
     int i;
     int top = lua_gettop(L);
-    for (i = 1; i<= top; i++) {
+    for (i = 1; i <= top; i++) {
         int t = lua_type(L, i);
-        switch(t) {
-            case LUA_TSTRING: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+        switch (t) {
+        case LUA_TSTRING:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
                               "%d:  '%s'", i, lua_tostring(L, i));
                 break;
             }
-            case LUA_TUSERDATA: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d:  userdata", i);                
+        case LUA_TUSERDATA:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d:  userdata",
+                              i);
                 break;
             }
-            case LUA_TLIGHTUSERDATA: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d:  lightuserdata", i);
+        case LUA_TLIGHTUSERDATA:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
+                              "%d:  lightuserdata", i);
                 break;
             }
-            case LUA_TNIL: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
-                              "%d:  NIL", i);
+        case LUA_TNIL:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d:  NIL", i);
                 break;
             }
-            case LUA_TNONE: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
-                              "%d:  None", i);
+        case LUA_TNONE:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, "%d:  None", i);
                 break;
             }
-            case LUA_TBOOLEAN: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
-                              "%d:  %s", i,  lua_toboolean(L, i) ? "true" : "false");
+        case LUA_TBOOLEAN:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
+                              "%d:  %s", i, lua_toboolean(L,
+                                                          i) ? "true" :
+                              "false");
                 break;
             }
-            case LUA_TNUMBER: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+        case LUA_TNUMBER:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
                               "%d:  %g", i, lua_tonumber(L, i));
                 break;
             }
-            case LUA_TTABLE: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+        case LUA_TTABLE:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
                               "%d:  <table>", i);
                 break;
             }
-            case LUA_TFUNCTION: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+        case LUA_TFUNCTION:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
                               "%d:  <function>", i);
                 break;
             }
-            default: {
-                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, 
+        default:{
+                ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r,
                               "%d:  unkown: -[%s]-", i, lua_typename(L, i));
-                break;                
+                break;
             }
         }
     }
@@ -87,275 +90,341 @@ void rstack_dump(lua_State* L, request_rec* r, const char* msg) {
  * userdata thingamajig and return it if it is. if it is not
  * lua will enter its error handling routine.
  */
-static request_rec* apl_check_request_rec(lua_State* L, int index) {
+static request_rec *apl_check_request_rec(lua_State *L, int index)
+{
     luaL_checkudata(L, index, "Apache2.Request");
-    request_rec* r = (request_rec*)lua_unboxpointer(L, index);
-    return r;    
+    request_rec *r = (request_rec *) lua_unboxpointer(L, index);
+    return r;
 }
 
 /* ------------------ request methods -------------------- */
 /* helper callback for req_parseargs */
-static int req_aprtable2luatable_cb(void *l, const char *key, const char *value) {
-    lua_State* L = (lua_State*)l; /* [table<s,t>, table<s,s>] */
+static int req_aprtable2luatable_cb(void *l, const char *key,
+                                    const char *value)
+{
+    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>] */
     /* build complex */
 
-    lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
-    /* rstack_dump(L, RRR, "after getfield"); */ 
+    lua_getfield(L, -1, key);   /* [VALUE, table<s,t>, table<s,s>] */
+    /* rstack_dump(L, RRR, "after getfield"); */
     int t = lua_type(L, -1);
-    switch(t) {
-        case LUA_TNIL:
-        case LUA_TNONE: {
-            lua_pop(L, 1); /* [table<s,t>, table<s,s>] */
-            lua_newtable(L); /* [array, table<s,t>, table<s,s>] */
-            lua_pushnumber(L, 1); /* [1, array, table<s,t>, table<s,s>] */
-            lua_pushstring(L, value); /* [string, 1, array, table<s,t>, table<s,s>] */
-            lua_settable(L, -3); /* [array, table<s,t>, table<s,s>]  */
-            lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
+    switch (t) {
+    case LUA_TNIL:
+    case LUA_TNONE:{
+            lua_pop(L, 1);      /* [table<s,t>, table<s,s>] */
+            lua_newtable(L);    /* [array, table<s,t>, table<s,s>] */
+            lua_pushnumber(L, 1);       /* [1, array, table<s,t>, table<s,s>] */
+            lua_pushstring(L, value);   /* [string, 1, array, table<s,t>, table<s,s>] */
+            lua_settable(L, -3);        /* [array, table<s,t>, table<s,s>]  */
+            lua_setfield(L, -2, key);   /* [table<s,t>, table<s,s>] */
             break;
         }
-        case LUA_TTABLE: {
+    case LUA_TTABLE:{
             /* [array, table<s,t>, table<s,s>] */
             int size = lua_objlen(L, -1);
-            lua_pushnumber(L, size + 1); /* [#, array, table<s,t>, table<s,s>] */
-            lua_pushstring(L, value); /* [string, #, array, table<s,t>, table<s,s>] */
-            lua_settable(L, -3); /* [array, table<s,t>, table<s,s>] */
-            lua_setfield(L, -2, key); /* [table<s,t>, table<s,s>] */
+            lua_pushnumber(L, size + 1);        /* [#, array, table<s,t>, table<s,s>] */
+            lua_pushstring(L, value);   /* [string, #, array, table<s,t>, table<s,s>] */
+            lua_settable(L, -3);        /* [array, table<s,t>, table<s,s>] */
+            lua_setfield(L, -2, key);   /* [table<s,t>, table<s,s>] */
             break;
         }
     }
 
     /* L is [table<s,t>, table<s,s>] */
     /* build simple */
-    lua_getfield(L, -2, key); /* [VALUE, table<s,s>, table<s,t>] */
-    if (lua_isnoneornil(L, -1)) { /* only set if not already set */
-        lua_pop(L, 1); /* [table<s,s>, table<s,t>]] */
-        lua_pushstring(L, value); /* [string, table<s,s>, table<s,t>] */
-        lua_setfield(L, -3, key); /* [table<s,s>, table<s,t>]  */
-    } else { lua_pop(L, 1); }
+    lua_getfield(L, -2, key);   /* [VALUE, table<s,s>, table<s,t>] */
+    if (lua_isnoneornil(L, -1)) {       /* only set if not already set */
+        lua_pop(L, 1);          /* [table<s,s>, table<s,t>]] */
+        lua_pushstring(L, value);       /* [string, table<s,s>, table<s,t>] */
+        lua_setfield(L, -3, key);       /* [table<s,s>, table<s,t>]  */
+    }
+    else {
+        lua_pop(L, 1);
+    }
     return 1;
 }
 
 /* r:parseargs() returning a lua table */
-static int req_parseargs(lua_State* L) {
-    request_rec* r = apl_check_request_rec(L, 1);
+static int req_parseargs(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     lua_newtable(L);
-    lua_newtable(L); /* [table, table] */
-    apr_table_tform_table;
+    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>>] */
+    apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
+    return 2;                   /* [table<string, string>, table<string, array<string>>] */
 }
 
 /* wrap ap_rputs as r:puts(String) */
-static int req_puts(lua_State* L) {    
-    request_rec* r = apl_check_request_rec(L, 1);
-    
+static int req_puts(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
+
     int argc = lua_gettop(L);
     int i;
-    
-    for (i=2;i<=argc;i++) {
+
+    for (i = 2; i <= argc; i++) {
         ap_rputs(luaL_checkstring(L, i), r);
     }
     return 0;
 }
 
 /* wrap ap_rwrite as r:write(String) */
-static int req_write(lua_State* L) {
-    request_rec* r = apl_check_request_rec(L, 1);
+static int req_write(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     size_t n;
-    const charbuf = luaL_checklstring(L, 2, &n);
-  
-    ap_rwrite((void *)buf, n, r);
+    const char *buf = luaL_checklstring(L, 2, &n);
+
+    ap_rwrite((void *) buf, n, r);
     return 0;
 }
 
 /* r:parsebody() */
-static int req_parsebody(lua_State* L) {
-    request_rec* r = apl_check_request_rec(L, 1);
+static int req_parsebody(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     lua_newtable(L);
     lua_newtable(L);
-    apr_table_tform_table;
+    apr_table_t *form_table;
     if (ap_body_to_table(r, &form_table) == APR_SUCCESS) {
-        apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);        
+        apr_table_do(req_aprtable2luatable_cb, L, form_table, NULL);
     }
     return 2;
 }
 
 /* r:addoutputfilter(name|function) */
-static int req_add_output_filter(lua_State *L) {
-    request_rec* r = apl_check_request_rec(L, 1);    
+static int req_add_output_filter(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     const char *name = luaL_checkstring(L, 2);
-    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "adding output filter %s", name);
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "adding output filter %s",
+                  name);
     ap_add_output_filter(name, L, r, r->connection);
     return 0;
 }
 
-static int req_document_root(lua_State* L) {
-  request_rec* r = apl_check_request_rec(L, 1);
-  char* doc_root = apr_pstrdup(r->pool, ap_document_root(r));
-  lua_pushstring(L, doc_root);
-  return 1;
+static int req_document_root(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
+    char *doc_root = apr_pstrdup(r->pool, ap_document_root(r));
+    lua_pushstring(L, doc_root);
+    return 1;
 }
 
 /* BEGIN dispatch mathods for request_rec fields */
 
-static char* req_uri_field(request_rec* r) {
+static char *req_uri_field(request_rec *r)
+{
     return r->uri;
 }
 
-static const char* req_method_field(request_rec* r) {
+static const char *req_method_field(request_rec *r)
+{
     return r->method;
 }
 
-static const char* req_hostname_field(request_rec* r) {
+static const char *req_hostname_field(request_rec *r)
+{
     return r->hostname;
 }
 
-static const char* req_args_field(request_rec* r) {
+static const char *req_args_field(request_rec *r)
+{
     return r->args;
 }
 
-static const char* req_path_info_field(request_rec* r) {
+static const char *req_path_info_field(request_rec *r)
+{
     return r->path_info;
 }
 
-static const char* req_canonical_filename_field(request_rec* r) {
+static const char *req_canonical_filename_field(request_rec *r)
+{
     return r->canonical_filename;
 }
 
-static const char* req_filename_field(request_rec* r) {
+static const char *req_filename_field(request_rec *r)
+{
     return r->filename;
 }
 
-static const char* req_user_field(request_rec* r) {
+static const char *req_user_field(request_rec *r)
+{
     return r->user;
 }
 
-static const char* req_unparsed_uri_field(request_rec* r) {
+static const char *req_unparsed_uri_field(request_rec *r)
+{
     return r->unparsed_uri;
 }
 
-static const char* req_ap_auth_type_field(request_rec* r) {
+static const char *req_ap_auth_type_field(request_rec *r)
+{
     return r->ap_auth_type;
 }
 
-static const char* req_content_encoding_field(request_rec* r) {
+static const char *req_content_encoding_field(request_rec *r)
+{
     return r->content_encoding;
 }
 
-static const char* req_content_type_field(request_rec* r) {
+static const char *req_content_type_field(request_rec *r)
+{
     return r->content_type;
 }
 
-static const char* req_range_field(request_rec* r) {
+static const char *req_range_field(request_rec *r)
+{
     return r->range;
 }
 
-static const char* req_protocol_field(request_rec* r) {
+static const char *req_protocol_field(request_rec *r)
+{
     return r->protocol;
 }
 
-static const char* req_the_request_field(request_rec* r) {
+static const char *req_the_request_field(request_rec *r)
+{
     return r->the_request;
 }
 
-static int req_status_field(request_rec* r) {
+static int req_status_field(request_rec *r)
+{
     return r->status;
 }
 
-static int req_assbackwards_field(request_rec* r) {
+static int req_assbackwards_field(request_rec *r)
+{
     return r->assbackwards;
 }
 
 /* END dispatch mathods for request_rec fields */
 
-static int req_dispatch(lua_State* L) {
-    request_rec* r = apl_check_request_rec(L, 1);
+static int req_dispatch(lua_State *L)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     const char *name = luaL_checkstring(L, 2);
     lua_pop(L, 2);
+
     lua_getfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
-    apr_hash_tdispatch = lua_touserdata(L, 1);
+    apr_hash_t *dispatch = lua_touserdata(L, 1);
     lua_pop(L, 1);
-    
-    req_fun_trft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
+
+    req_fun_t *rft = apr_hash_get(dispatch, name, APR_HASH_KEY_STRING);
     if (rft) {
-        switch(rft->type) {
-            case APL_REQ_FUNTYPE_TABLE: {
-                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
-                              "request_rec->dispatching %s -> apr table (NOT IMPLEMENTED YET)", name);
+        switch (rft->type) {
+        case APL_REQ_FUNTYPE_TABLE:{
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+                              "request_rec->dispatching %s -> apr table (NOT IMPLEMENTED YET)",
+                              name);
                 return 0;
             }
-            
-            case APL_REQ_FUNTYPE_LUACFUN: {
-                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
-                              "request_rec->dispatching %s -> lua_CFunction", name);
+
+        case APL_REQ_FUNTYPE_LUACFUN:{
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
+                              "request_rec->dispatching %s -> lua_CFunction",
+                              name);
                 lua_CFunction func = rft->fun;
-                lua_pushcfunction(L, func);      
-                return 1;                
+                lua_pushcfunction(L, func);
+                return 1;
             }
-            case APL_REQ_FUNTYPE_STRING: {
-                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
+        case APL_REQ_FUNTYPE_STRING:{
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                               "request_rec->dispatching %s -> string", name);
                 req_field_string_f func = rft->fun;
-                char* rs = (*func)(r);
+                char *rs = (*func) (r);
                 lua_pushstring(L, rs);
-                return 1;                
+                return 1;
             }
-            case APL_REQ_FUNTYPE_INT: {
-                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
+        case APL_REQ_FUNTYPE_INT:{
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                               "request_rec->dispatching %s -> int", name);
                 req_field_int_f func = rft->fun;
-                int rs = (*func)(r);
+                int rs = (*func) (r);
                 lua_pushnumber(L, rs);
-                return 1;                
+                return 1;
             }
-            case APL_REQ_FUNTYPE_BOOLEAN: {
-                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
+        case APL_REQ_FUNTYPE_BOOLEAN:{
+                ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r,
                               "request_rec->dispatching %s -> boolean", name);
                 req_field_int_f func = rft->fun;
-                int rs = (*func)(r);
+                int rs = (*func) (r);
                 lua_pushboolean(L, rs);
-                return 1;                
+                return 1;
             }
         }
     }
-    
-    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, 
-                  "nothing for %s", name);  
+
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "nothing for %s", name);
     return 0;
 }
 
 /* helper function for the logging functions below */
-static int req_log_at(lua_State* L, int level) {
-    request_rec* r = apl_check_request_rec(L, 1);
+static int req_log_at(lua_State *L, int level)
+{
+    request_rec *r = apl_check_request_rec(L, 1);
     lua_Debug dbg;
-    
+
     lua_getstack(L, 1, &dbg);
     lua_getinfo(L, "Sl", &dbg);
 
-    const charmsg = luaL_checkstring(L, 2);
+    const char *msg = luaL_checkstring(L, 2);
     ap_log_rerror(dbg.source, dbg.currentline, level, 0, r, msg);
     return 0;
 }
 
 /* r:debug(String) and friends which use apache logging */
-static int req_emerg(lua_State* L)  { req_log_at(L, APLOG_EMERG); return 0; }
-static int req_alert(lua_State* L)  { req_log_at(L, APLOG_ALERT); return 0; }
-static int req_crit(lua_State* L)   { req_log_at(L, APLOG_CRIT); return 0; }
-static int req_err(lua_State* L)    { req_log_at(L, APLOG_ERR); return 0; }
-static int req_warn(lua_State* L)   { req_log_at(L, APLOG_WARNING); return 0; }
-static int req_notice(lua_State* L) { req_log_at(L, APLOG_NOTICE); return 0; }
-static int req_info(lua_State* L)   { req_log_at(L, APLOG_INFO); return 0; }
-static int req_debug(lua_State* L)  { req_log_at(L, APLOG_DEBUG); return 0; }
+static int req_emerg(lua_State *L)
+{
+    req_log_at(L, APLOG_EMERG);
+    return 0;
+}
+static int req_alert(lua_State *L)
+{
+    req_log_at(L, APLOG_ALERT);
+    return 0;
+}
+static int req_crit(lua_State *L)
+{
+    req_log_at(L, APLOG_CRIT);
+    return 0;
+}
+static int req_err(lua_State *L)
+{
+    req_log_at(L, APLOG_ERR);
+    return 0;
+}
+static int req_warn(lua_State *L)
+{
+    req_log_at(L, APLOG_WARNING);
+    return 0;
+}
+static int req_notice(lua_State *L)
+{
+    req_log_at(L, APLOG_NOTICE);
+    return 0;
+}
+static int req_info(lua_State *L)
+{
+    req_log_at(L, APLOG_INFO);
+    return 0;
+}
+static int req_debug(lua_State *L)
+{
+    req_log_at(L, APLOG_DEBUG);
+    return 0;
+}
 
 /* handle r.status = 201 */
-static int req_newindex(lua_State* L) {
-    /* request_rec* r = lua_touserdata(L, lua_upvalueindex(1)); */ 
+static int req_newindex(lua_State *L)
+{
+    /* request_rec* r = lua_touserdata(L, lua_upvalueindex(1)); */
     /* const char* key = luaL_checkstring(L, -2); */
-    request_recr = apl_check_request_rec(L, 1);
+    request_rec *r = apl_check_request_rec(L, 1);
     rstack_dump(L, r, "req_newindex");
     const char *key = luaL_checkstring(L, 2);
     rstack_dump(L, r, "req_newindex");
@@ -368,9 +437,9 @@ static int req_newindex(lua_State* L) {
         lua_pop(L, 1);
         return 0;
     }
-    
+
     if (0 == apr_strnatcmp("content_type", key)) {
-        const charvalue = luaL_checkstring(L, 3);
+        const char *value = luaL_checkstring(L, 3);
         r->content_type = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -378,9 +447,9 @@ static int req_newindex(lua_State* L) {
         lua_pop(L, 1);
         return 0;
     }
-    
+
     if (0 == apr_strnatcmp("filename", key)) {
-        const charvalue = luaL_checkstring(L, 3);
+        const char *value = luaL_checkstring(L, 3);
         r->filename = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -390,7 +459,7 @@ static int req_newindex(lua_State* L) {
     }
 
     if (0 == apr_strnatcmp("uri", key)) {
-        const charvalue = luaL_checkstring(L, 3);
+        const char *value = luaL_checkstring(L, 3);
         r->uri = apr_pstrdup(r->pool, value);
         luaL_getmetatable(L, "Apache2.Request");
         lua_pushstring(L, value);
@@ -398,8 +467,11 @@ static int req_newindex(lua_State* L) {
         lua_pop(L, 1);
         return 0;
     }
-    
-    lua_pushstring(L, apr_psprintf(r->pool, "Property [%s] may not be set on a request_rec", key));
+
+    lua_pushstring(L,
+                   apr_psprintf(r->pool,
+                                "Property [%s] may not be set on a request_rec",
+                                key));
     lua_error(L);
     return 0;
 }
@@ -422,110 +494,116 @@ static const struct luaL_Reg server_methods[] = {
 };
 
 
-static req_fun_t* makefun(void* fun, int type, apr_pool_t* pool) {
-    req_fun_t* rft = apr_palloc(pool, sizeof(req_fun_t));
+static req_fun_t *makefun(void *fun, int type, apr_pool_t *pool)
+{
+    req_fun_t *rft = apr_palloc(pool, sizeof(req_fun_t));
     rft->fun = fun;
     rft->type = type;
     return rft;
 }
 
-void apl_load_request_lmodule(lua_State *L, apr_pool_t *p) {
-    
-    apr_hash_t* dispatch = apr_hash_make(p);
-    
-    apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING, 
+void apl_load_request_lmodule(lua_State *L, apr_pool_t *p)
+{
+
+    apr_hash_t *dispatch = apr_hash_make(p);
+
+    apr_hash_set(dispatch, "puts", APR_HASH_KEY_STRING,
                  makefun(&req_puts, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "write", APR_HASH_KEY_STRING,
                  makefun(&req_write, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "document_root", APR_HASH_KEY_STRING,
                  makefun(&req_document_root, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "parseargs", APR_HASH_KEY_STRING,
                  makefun(&req_parseargs, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "parsebody", APR_HASH_KEY_STRING,
                  makefun(&req_parsebody, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "debug", APR_HASH_KEY_STRING,
                  makefun(&req_debug, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "info", APR_HASH_KEY_STRING,
                  makefun(&req_info, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "notice", APR_HASH_KEY_STRING,
                  makefun(&req_notice, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "warn", APR_HASH_KEY_STRING,
                  makefun(req_warn, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "err", APR_HASH_KEY_STRING,
                  makefun(&req_err, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "crit", APR_HASH_KEY_STRING,
                  makefun(&req_crit, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "alert", APR_HASH_KEY_STRING,
                  makefun(&req_alert, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "emerg", APR_HASH_KEY_STRING,
                  makefun(&req_emerg, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "add_output_filter", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "add_output_filter", APR_HASH_KEY_STRING,
                  makefun(&req_add_output_filter, APL_REQ_FUNTYPE_LUACFUN, p));
-    apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING, 
-                 makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN, p));
-    apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "assbackwards", APR_HASH_KEY_STRING,
+                 makefun(&req_assbackwards_field, APL_REQ_FUNTYPE_BOOLEAN,
+                         p));
+    apr_hash_set(dispatch, "status", APR_HASH_KEY_STRING,
                  makefun(&req_status_field, APL_REQ_FUNTYPE_INT, p));
-    apr_hash_set(dispatch, "protocol", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "protocol", APR_HASH_KEY_STRING,
                  makefun(&req_protocol_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "range", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "range", APR_HASH_KEY_STRING,
                  makefun(&req_range_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "content_type", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "content_type", APR_HASH_KEY_STRING,
                  makefun(&req_content_type_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "content_encoding", APR_HASH_KEY_STRING, 
-                 makefun(&req_content_encoding_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "ap_auth_type", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "content_encoding", APR_HASH_KEY_STRING,
+                 makefun(&req_content_encoding_field, APL_REQ_FUNTYPE_STRING,
+                         p));
+    apr_hash_set(dispatch, "ap_auth_type", APR_HASH_KEY_STRING,
                  makefun(&req_ap_auth_type_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "unparsed_uri", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "unparsed_uri", APR_HASH_KEY_STRING,
                  makefun(&req_unparsed_uri_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "user", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "user", APR_HASH_KEY_STRING,
                  makefun(&req_user_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "filename", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "filename", APR_HASH_KEY_STRING,
                  makefun(&req_filename_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "canonical_filename", APR_HASH_KEY_STRING, 
-                 makefun(&req_canonical_filename_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "path_info", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "canonical_filename", APR_HASH_KEY_STRING,
+                 makefun(&req_canonical_filename_field,
+                         APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "path_info", APR_HASH_KEY_STRING,
                  makefun(&req_path_info_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "args", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "args", APR_HASH_KEY_STRING,
                  makefun(&req_args_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "hostname", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "hostname", APR_HASH_KEY_STRING,
                  makefun(&req_hostname_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "uri", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "uri", APR_HASH_KEY_STRING,
                  makefun(&req_uri_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "the_request", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "the_request", APR_HASH_KEY_STRING,
                  makefun(&req_the_request_field, APL_REQ_FUNTYPE_STRING, p));
-    apr_hash_set(dispatch, "method", APR_HASH_KEY_STRING, 
+    apr_hash_set(dispatch, "method", APR_HASH_KEY_STRING,
                  makefun(&req_method_field, APL_REQ_FUNTYPE_STRING, p));
-    
+
     lua_pushlightuserdata(L, dispatch);
     lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
-    
-    luaL_newmetatable(L, "Apache2.Request"); /* [metatable] */
-    lua_pushvalue(L, -1); 
 
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, request_methods); /* [metatable] */
+    luaL_newmetatable(L, "Apache2.Request");    /* [metatable] */
+    lua_pushvalue(L, -1);
+
+    lua_setfield(L, -2, "__index");
+    luaL_register(L, NULL, request_methods);    /* [metatable] */
 
     lua_pop(L, 2);
 
     luaL_newmetatable(L, "Apache2.Connection"); /* [metatable] */
-    lua_pushvalue(L, -1); 
+    lua_pushvalue(L, -1);
 
-    lua_setfield(L, -2, "__index"); 
+    lua_setfield(L, -2, "__index");
     luaL_register(L, NULL, connection_methods); /* [metatable] */
 
     lua_pop(L, 2);
 
-    luaL_newmetatable(L, "Apache2.Server"); /* [metatable] */
-    lua_pushvalue(L, -1); 
+    luaL_newmetatable(L, "Apache2.Server");     /* [metatable] */
+    lua_pushvalue(L, -1);
 
-    lua_setfield(L, -2, "__index"); 
-    luaL_register(L, NULL, server_methods); /* [metatable] */
+    lua_setfield(L, -2, "__index");
+    luaL_register(L, NULL, server_methods);     /* [metatable] */
 
     lua_pop(L, 2);
 
 }
 
-void apl_push_connection(lua_State* L, conn_rec* c) {  
+void apl_push_connection(lua_State *L, conn_rec *c)
+{
     lua_boxpointer(L, c);
     luaL_getmetatable(L, "Apache2.Connection");
     lua_setmetatable(L, -2);
@@ -534,27 +612,28 @@ void apl_push_connection(lua_State* L, conn_rec* c) {
     apl_push_apr_table(L, "notes", c->notes);
 
     lua_pushstring(L, c->remote_ip);
-    lua_setfield(L, -2, "remote_ip");    
+    lua_setfield(L, -2, "remote_ip");
 
     lua_pop(L, 1);
 }
 
 
-void apl_push_server(lua_State* L, server_rec* s) {  
+void apl_push_server(lua_State *L, server_rec *s)
+{
     lua_boxpointer(L, s);
     luaL_getmetatable(L, "Apache2.Server");
     lua_setmetatable(L, -2);
     luaL_getmetatable(L, "Apache2.Server");
 
     lua_pushstring(L, s->server_hostname);
-    lua_setfield(L, -2, "server_hostname");    
+    lua_setfield(L, -2, "server_hostname");
 
     lua_pop(L, 1);
 }
 
-void apl_push_request(lua_State* L, request_rec* r) {  
+void apl_push_request(lua_State *L, request_rec *r)
+{
     lua_boxpointer(L, r);
     luaL_getmetatable(L, "Apache2.Request");
     lua_setmetatable(L, -2);
 }
-
index a5ecb44a2697ac1c297185caa494eb74f51967fe..beed41fc98d54737893caab44304a75f8dbf7fd6 100644 (file)
@@ -18,7 +18,7 @@
 #ifndef _LUA_REQUEST_H_
 #define _LUA_REQUEST_H_
 
-APR_DECLARE(void) apl_push_request(lua_State* L, request_rec* r);
+APR_DECLARE(void) apl_push_request(lua_State *L, request_rec *r);
 APR_DECLARE(void) apl_load_request_lmodule(lua_State *L, apr_pool_t *p);
 
 #define APL_REQ_FUNTYPE_STRING      1
@@ -27,11 +27,11 @@ APR_DECLARE(void) apl_load_request_lmodule(lua_State *L, apr_pool_t *p);
 #define APL_REQ_FUNTYPE_LUACFUN     4
 #define APL_REQ_FUNTYPE_BOOLEAN     5
 
-typedef struct {
+typedef struct
+{
     void *fun;
     int type;
 } req_fun_t;
 
 
 #endif /* !_LUA_REQUEST_H_ */
-
index 6be8fab11bd3ca24e33cfae42d4cb3fc4e177f81..66eabc673b901bc5eba359a5afcf4e8a3f2510f6 100644 (file)
 
 /* forward dec'l from this file */
 
-static void pstack_dump(lua_State* L, apr_pool_t* r, int level, const char* msg) {
+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);
-    for (i = 1; i<= top; i++) {
+    for (i = 1; i <= top; i++) {
         int t = lua_type(L, i);
-        switch(t) {
-            case LUA_TSTRING: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
+        switch (t) {
+        case LUA_TSTRING:{
+                ap_log_perror(APLOG_MARK, level, 0, r,
                               "%d:  '%s'", i, lua_tostring(L, i));
                 break;
             }
-            case LUA_TUSERDATA: {
-                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  userdata", i);                
+        case LUA_TUSERDATA:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  userdata", i);
                 break;
             }
-            case LUA_TLIGHTUSERDATA: {
-                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  lightuserdata", i);
+        case LUA_TLIGHTUSERDATA:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  lightuserdata",
+                              i);
                 break;
             }
-            case LUA_TNIL: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  NIL", i);
+        case LUA_TNIL:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  NIL", i);
                 break;
             }
-            case LUA_TNONE: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  None", i);
+        case LUA_TNONE:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  None", i);
                 break;
             }
-            case LUA_TBOOLEAN: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  %s", i,  lua_toboolean(L, i) ? "true" : "false");
+        case LUA_TBOOLEAN:{
+                ap_log_perror(APLOG_MARK, level, 0, r,
+                              "%d:  %s", i, lua_toboolean(L,
+                                                          i) ? "true" :
+                              "false");
                 break;
             }
-            case LUA_TNUMBER: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
+        case LUA_TNUMBER:{
+                ap_log_perror(APLOG_MARK, level, 0, r,
                               "%d:  %g", i, lua_tonumber(L, i));
                 break;
             }
-            case LUA_TTABLE: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  <table>", i);
+        case LUA_TTABLE:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  <table>", i);
                 break;
             }
-            case LUA_TTHREAD: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  <thread>", i);
+        case LUA_TTHREAD:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  <thread>", i);
                 break;
             }
-            case LUA_TFUNCTION: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
-                              "%d:  <function>", i);
+        case LUA_TFUNCTION:{
+                ap_log_perror(APLOG_MARK, level, 0, r, "%d:  <function>", i);
                 break;
             }
-            default: {
-                ap_log_perror(APLOG_MARK, level, 0, r, 
+        default:{
+                ap_log_perror(APLOG_MARK, level, 0, r,
                               "%d:  unkown: [%s]", i, lua_typename(L, i));
-                break;                
+                break;
             }
         }
     }
@@ -92,13 +92,14 @@ static void pstack_dump(lua_State* L, apr_pool_t* r, int level, const char* msg)
 
 /* BEGIN apache lmodule  */
 
-void apl_load_apache2_lmodule(lua_State *L) {
+void apl_load_apache2_lmodule(lua_State *L)
+{
     lua_getglobal(L, "package");
     lua_getfield(L, -1, "loaded");
-    lua_newtable(L);    
+    lua_newtable(L);
     lua_setfield(L, -2, "apache2");
     lua_setglobal(L, "apache2");
-    lua_pop(L, 1); /* empty stack */
+    lua_pop(L, 1);              /* empty stack */
 
     lua_getglobal(L, "apache2");
     lua_pushinteger(L, OK);
@@ -109,187 +110,186 @@ void apl_load_apache2_lmodule(lua_State *L) {
 
     lua_pushinteger(L, DONE);
     lua_setfield(L, -2, "DONE");
-   
+
     lua_pushstring(L, ap_get_server_banner());
     lua_setfield(L, -2, "version");
 
     lua_pushinteger(L, HTTP_MOVED_TEMPORARILY);
     lua_setfield(L, -2, "HTTP_MOVED_TEMPORARILY");
-    
+
     /*
-    lua_pushinteger(L, HTTP_CONTINUE);
-    lua_setfield(L, -2, "HTTP_CONTINUE");
-    lua_pushinteger(L, HTTP_SWITCHING_PROTOCOLS);
-    lua_setfield(L, -2, "HTTP_SWITCHING_PROTOCOLS");
-    lua_pushinteger(L, HTTP_PROCESSING);
-    lua_setfield(L, -2, "HTTP_PROCESSING");
-    lua_pushinteger(L, HTTP_OK);
-    lua_setfield(L, -2, "HTTP_OK");
-    lua_pushinteger(L, HTTP_CREATED);
-    lua_setfield(L, -2, "HTTP_CREATED");
-    lua_pushinteger(L, HTTP_ACCEPTED);
-    lua_setfield(L, -2, "HTTP_ACCEPTED");
-    lua_pushinteger(L, HTTP_NON_AUTHORITATIVE);
-    lua_setfield(L, -2, "HTTP_NON_AUTHORITATIVE");
-    lua_pushinteger(L, HTTP_NO_CONTENT);
-    lua_setfield(L, -2, "HTTP_NO_CONTENT");
-    lua_pushinteger(L, HTTP_RESET_CONTENT);
-    lua_setfield(L, -2, "HTTP_RESET_CONTENT");
-    lua_pushinteger(L, HTTP_PARTIAL_CONTENT);
-    lua_setfield(L, -2, "HTTP_PARTIAL_CONTENT");
-    lua_pushinteger(L, HTTP_MULTI_STATUS);
-    lua_setfield(L, -2, "HTTP_MULTI_STATUS");
-    lua_pushinteger(L, HTTP_MULTIPLE_CHOICES);
-    lua_setfield(L, -2, "HTTP_MULTIPLE_CHOICES");
-    lua_pushinteger(L, HTTP_MOVED_PERMANENTLY);
-    lua_setfield(L, -2, "HTTP_MOVED_PERMANENTLY");
-    lua_pushinteger(L, HTTP_SEE_OTHER);
-    lua_setfield(L, -2, "HTTP_SEE_OTHER");
-    lua_pushinteger(L, HTTP_NOT_MODIFIED);
-    lua_setfield(L, -2, "HTTP_NOT_MODIFIED");
-    lua_pushinteger(L, HTTP_USE_PROXY);
-    lua_setfield(L, -2, "HTTP_USE_PROXY");
-    lua_pushinteger(L, HTTP_TEMPORARY_REDIRECT);
-    lua_setfield(L, -2, "HTTP_TEMPORARY_REDIRECT");
-    lua_pushinteger(L, HTTP_BAD_REQUEST);
-    lua_setfield(L, -2, "HTTP_BAD_REQUEST");
-    lua_pushinteger(L, HTTP_UNAUTHORIZED);
-    lua_setfield(L, -2, "HTTP_UNAUTHORIZED");
-    lua_pushinteger(L, HTTP_PAYMENT_REQUIRED);
-    lua_setfield(L, -2, "HTTP_PAYMENT_REQUIRED");
-    lua_pushinteger(L, HTTP_FORBIDDEN);
-    lua_setfield(L, -2, "HTTP_FORBIDDEN");
-    lua_pushinteger(L, HTTP_NOT_FOUND);
-    lua_setfield(L, -2, "HTTP_NOT_FOUND");
-    lua_pushinteger(L, HTTP_METHOD_NOT_ALLOWED);
-    lua_setfield(L, -2, "HTTP_METHOD_NOT_ALLOWED");
-    lua_pushinteger(L, HTTP_NOT_ACCEPTABLE);
-    lua_setfield(L, -2, "HTTP_NOT_ACCEPTABLE");
-    lua_pushinteger(L, HTTP_PROXY_AUTHENTICATION_REQUIRED);
-    lua_setfield(L, -2, "HTTP_PROXY_AUTHENTICATION_REQUIRED");
-    lua_pushinteger(L, HTTP_REQUEST_TIME_OUT);
-    lua_setfield(L, -2, "HTTP_REQUEST_TIME_OUT");
-    lua_pushinteger(L, HTTP_CONFLICT);
-    lua_setfield(L, -2, "HTTP_CONFLICT");
-    lua_pushinteger(L, HTTP_GONE);
-    lua_setfield(L, -2, "HTTP_GONE");
-    lua_pushinteger(L, HTTP_LENGTH_REQUIRED);
-    lua_setfield(L, -2, "HTTP_LENGTH_REQUIRED");
-    lua_pushinteger(L, HTTP_PRECONDITION_FAILED);
-    lua_setfield(L, -2, "HTTP_PRECONDITION_FAILED");
-    lua_pushinteger(L, HTTP_REQUEST_ENTITY_TOO_LARGE);
-    lua_setfield(L, -2, "HTTP_REQUEST_ENTITY_TOO_LARGE");
-    lua_pushinteger(L, HTTP_REQUEST_URI_TOO_LARGE);
-    lua_setfield(L, -2, "HTTP_REQUEST_URI_TOO_LARGE");
-    lua_pushinteger(L, HTTP_UNSUPPORTED_MEDIA_TYPE);
-    lua_setfield(L, -2, "HTTP_UNSUPPORTED_MEDIA_TYPE");
-    lua_pushinteger(L, HTTP_RANGE_NOT_SATISFIABLE);
-    lua_setfield(L, -2, "HTTP_RANGE_NOT_SATISFIABLE");
-    lua_pushinteger(L, HTTP_EXPECTATION_FAILED);
-    lua_setfield(L, -2, "HTTP_EXPECTATION_FAILED");
-    lua_pushinteger(L, HTTP_UNPROCESSABLE_ENTITY);
-    lua_setfield(L, -2, "HTTP_UNPROCESSABLE_ENTITY");
-    lua_pushinteger(L, HTTP_LOCKED);
-    lua_setfield(L, -2, "HTTP_LOCKED");
-    lua_pushinteger(L, HTTP_FAILED_DEPENDENCY);
-    lua_setfield(L, -2, "HTTP_FAILED_DEPENDENCY");
-    lua_pushinteger(L, HTTP_UPGRADE_REQUIRED);
-    lua_setfield(L, -2, "HTTP_UPGRADE_REQUIRED");
-    lua_pushinteger(L, HTTP_INTERNAL_SERVER_ERROR);
-    lua_setfield(L, -2, "HTTP_INTERNAL_SERVER_ERROR");
-    lua_pushinteger(L, HTTP_NOT_IMPLEMENTED);
-    lua_setfield(L, -2, "HTTP_NOT_IMPLEMENTED");
-    lua_pushinteger(L, HTTP_BAD_GATEWAY);
-    lua_setfield(L, -2, "HTTP_BAD_GATEWAY");
-    lua_pushinteger(L, HTTP_SERVICE_UNAVAILABLE);
-    lua_setfield(L, -2, "HTTP_SERVICE_UNAVAILABLE");
-    lua_pushinteger(L, HTTP_GATEWAY_TIME_OUT);
-    lua_setfield(L, -2, "HTTP_GATEWAY_TIME_OUT");
-    lua_pushinteger(L, HTTP_VERSION_NOT_SUPPORTED);
-    lua_setfield(L, -2, "HTTP_VERSION_NOT_SUPPORTED");
-    lua_pushinteger(L, HTTP_VARIANT_ALSO_VARIES);
-    lua_setfield(L, -2, "HTTP_VARIANT_ALSO_VARIES");
-    lua_pushinteger(L, HTTP_INSUFFICIENT_STORAGE);
-    lua_setfield(L, -2, "HTTP_INSUFFICIENT_STORAGE");
-    lua_pushinteger(L, HTTP_NOT_EXTENDED);
-    lua_setfield(L, -2, "HTTP_NOT_EXTENDED");
-    */
-} 
+       lua_pushinteger(L, HTTP_CONTINUE);
+       lua_setfield(L, -2, "HTTP_CONTINUE");
+       lua_pushinteger(L, HTTP_SWITCHING_PROTOCOLS);
+       lua_setfield(L, -2, "HTTP_SWITCHING_PROTOCOLS");
+       lua_pushinteger(L, HTTP_PROCESSING);
+       lua_setfield(L, -2, "HTTP_PROCESSING");
+       lua_pushinteger(L, HTTP_OK);
+       lua_setfield(L, -2, "HTTP_OK");
+       lua_pushinteger(L, HTTP_CREATED);
+       lua_setfield(L, -2, "HTTP_CREATED");
+       lua_pushinteger(L, HTTP_ACCEPTED);
+       lua_setfield(L, -2, "HTTP_ACCEPTED");
+       lua_pushinteger(L, HTTP_NON_AUTHORITATIVE);
+       lua_setfield(L, -2, "HTTP_NON_AUTHORITATIVE");
+       lua_pushinteger(L, HTTP_NO_CONTENT);
+       lua_setfield(L, -2, "HTTP_NO_CONTENT");
+       lua_pushinteger(L, HTTP_RESET_CONTENT);
+       lua_setfield(L, -2, "HTTP_RESET_CONTENT");
+       lua_pushinteger(L, HTTP_PARTIAL_CONTENT);
+       lua_setfield(L, -2, "HTTP_PARTIAL_CONTENT");
+       lua_pushinteger(L, HTTP_MULTI_STATUS);
+       lua_setfield(L, -2, "HTTP_MULTI_STATUS");
+       lua_pushinteger(L, HTTP_MULTIPLE_CHOICES);
+       lua_setfield(L, -2, "HTTP_MULTIPLE_CHOICES");
+       lua_pushinteger(L, HTTP_MOVED_PERMANENTLY);
+       lua_setfield(L, -2, "HTTP_MOVED_PERMANENTLY");
+       lua_pushinteger(L, HTTP_SEE_OTHER);
+       lua_setfield(L, -2, "HTTP_SEE_OTHER");
+       lua_pushinteger(L, HTTP_NOT_MODIFIED);
+       lua_setfield(L, -2, "HTTP_NOT_MODIFIED");
+       lua_pushinteger(L, HTTP_USE_PROXY);
+       lua_setfield(L, -2, "HTTP_USE_PROXY");
+       lua_pushinteger(L, HTTP_TEMPORARY_REDIRECT);
+       lua_setfield(L, -2, "HTTP_TEMPORARY_REDIRECT");
+       lua_pushinteger(L, HTTP_BAD_REQUEST);
+       lua_setfield(L, -2, "HTTP_BAD_REQUEST");
+       lua_pushinteger(L, HTTP_UNAUTHORIZED);
+       lua_setfield(L, -2, "HTTP_UNAUTHORIZED");
+       lua_pushinteger(L, HTTP_PAYMENT_REQUIRED);
+       lua_setfield(L, -2, "HTTP_PAYMENT_REQUIRED");
+       lua_pushinteger(L, HTTP_FORBIDDEN);
+       lua_setfield(L, -2, "HTTP_FORBIDDEN");
+       lua_pushinteger(L, HTTP_NOT_FOUND);
+       lua_setfield(L, -2, "HTTP_NOT_FOUND");
+       lua_pushinteger(L, HTTP_METHOD_NOT_ALLOWED);
+       lua_setfield(L, -2, "HTTP_METHOD_NOT_ALLOWED");
+       lua_pushinteger(L, HTTP_NOT_ACCEPTABLE);
+       lua_setfield(L, -2, "HTTP_NOT_ACCEPTABLE");
+       lua_pushinteger(L, HTTP_PROXY_AUTHENTICATION_REQUIRED);
+       lua_setfield(L, -2, "HTTP_PROXY_AUTHENTICATION_REQUIRED");
+       lua_pushinteger(L, HTTP_REQUEST_TIME_OUT);
+       lua_setfield(L, -2, "HTTP_REQUEST_TIME_OUT");
+       lua_pushinteger(L, HTTP_CONFLICT);
+       lua_setfield(L, -2, "HTTP_CONFLICT");
+       lua_pushinteger(L, HTTP_GONE);
+       lua_setfield(L, -2, "HTTP_GONE");
+       lua_pushinteger(L, HTTP_LENGTH_REQUIRED);
+       lua_setfield(L, -2, "HTTP_LENGTH_REQUIRED");
+       lua_pushinteger(L, HTTP_PRECONDITION_FAILED);
+       lua_setfield(L, -2, "HTTP_PRECONDITION_FAILED");
+       lua_pushinteger(L, HTTP_REQUEST_ENTITY_TOO_LARGE);
+       lua_setfield(L, -2, "HTTP_REQUEST_ENTITY_TOO_LARGE");
+       lua_pushinteger(L, HTTP_REQUEST_URI_TOO_LARGE);
+       lua_setfield(L, -2, "HTTP_REQUEST_URI_TOO_LARGE");
+       lua_pushinteger(L, HTTP_UNSUPPORTED_MEDIA_TYPE);
+       lua_setfield(L, -2, "HTTP_UNSUPPORTED_MEDIA_TYPE");
+       lua_pushinteger(L, HTTP_RANGE_NOT_SATISFIABLE);
+       lua_setfield(L, -2, "HTTP_RANGE_NOT_SATISFIABLE");
+       lua_pushinteger(L, HTTP_EXPECTATION_FAILED);
+       lua_setfield(L, -2, "HTTP_EXPECTATION_FAILED");
+       lua_pushinteger(L, HTTP_UNPROCESSABLE_ENTITY);
+       lua_setfield(L, -2, "HTTP_UNPROCESSABLE_ENTITY");
+       lua_pushinteger(L, HTTP_LOCKED);
+       lua_setfield(L, -2, "HTTP_LOCKED");
+       lua_pushinteger(L, HTTP_FAILED_DEPENDENCY);
+       lua_setfield(L, -2, "HTTP_FAILED_DEPENDENCY");
+       lua_pushinteger(L, HTTP_UPGRADE_REQUIRED);
+       lua_setfield(L, -2, "HTTP_UPGRADE_REQUIRED");
+       lua_pushinteger(L, HTTP_INTERNAL_SERVER_ERROR);
+       lua_setfield(L, -2, "HTTP_INTERNAL_SERVER_ERROR");
+       lua_pushinteger(L, HTTP_NOT_IMPLEMENTED);
+       lua_setfield(L, -2, "HTTP_NOT_IMPLEMENTED");
+       lua_pushinteger(L, HTTP_BAD_GATEWAY);
+       lua_setfield(L, -2, "HTTP_BAD_GATEWAY");
+       lua_pushinteger(L, HTTP_SERVICE_UNAVAILABLE);
+       lua_setfield(L, -2, "HTTP_SERVICE_UNAVAILABLE");
+       lua_pushinteger(L, HTTP_GATEWAY_TIME_OUT);
+       lua_setfield(L, -2, "HTTP_GATEWAY_TIME_OUT");
+       lua_pushinteger(L, HTTP_VERSION_NOT_SUPPORTED);
+       lua_setfield(L, -2, "HTTP_VERSION_NOT_SUPPORTED");
+       lua_pushinteger(L, HTTP_VARIANT_ALSO_VARIES);
+       lua_setfield(L, -2, "HTTP_VARIANT_ALSO_VARIES");
+       lua_pushinteger(L, HTTP_INSUFFICIENT_STORAGE);
+       lua_setfield(L, -2, "HTTP_INSUFFICIENT_STORAGE");
+       lua_pushinteger(L, HTTP_NOT_EXTENDED);
+       lua_setfield(L, -2, "HTTP_NOT_EXTENDED");
+     */
+}
 
 /* END apache2 lmodule */
 
 /*  END library functions */
 
 /* callback for cleaning up a lua vm when pool is closed */
-static apr_status_t cleanup_lua(void *l) {
-  lua_close((lua_State*) l);
-  return APR_SUCCESS;
+static apr_status_t cleanup_lua(void *l)
+{
+    lua_close((lua_State *) l);
+    return APR_SUCCESS;
 }
 
-static void munge_path(lua_State *L, 
+static void munge_path(lua_State *L,
                        const char *field,
-                       const char *sub_pat, 
+                       const char *sub_pat,
                        const char *rep_pat,
-                       apr_pool_t *pool, 
-                       apr_array_header_t *paths, 
-                       const char *file) {
-  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);
-  luaL_gsub(L, current, rep_pat, pattern);
-  lua_setfield(L, -3, field);
-  lua_getfield(L, -2, field);
-  const char* modified = lua_tostring(L, -1);
-  lua_pop(L, 2);
-  
-  char * part = apr_pstrdup(pool, modified);
-  int i;
-  for (i = 0; i < paths->nelts; i++) {
-    const char *new_path = ((const char**)paths->elts)[i];
-    part = apr_pstrcat(pool, part, ";", new_path, NULL);
-  }
-  lua_pushstring(L, part);
-  lua_setfield(L, -2, field);
-  lua_pop(L, 1); /* pop "package" off the stack     */
+                       apr_pool_t *pool,
+                       apr_array_header_t *paths, const char *file)
+{
+    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);
+    luaL_gsub(L, current, rep_pat, pattern);
+    lua_setfield(L, -3, field);
+    lua_getfield(L, -2, field);
+    const char *modified = lua_tostring(L, -1);
+    lua_pop(L, 2);
+
+    char *part = apr_pstrdup(pool, modified);
+    int i;
+    for (i = 0; i < paths->nelts; i++) {
+        const char *new_path = ((const char **) paths->elts)[i];
+        part = apr_pstrcat(pool, part, ";", new_path, NULL);
+    }
+    lua_pushstring(L, part);
+    lua_setfield(L, -2, field);
+    lua_pop(L, 1);              /* pop "package" off the stack     */
 }
 
-lua_State* apl_get_lua_state(apr_pool_t* lifecycle_pool, 
-                            char* file, 
-                            apr_array_header_t* package_paths, 
-                            apr_array_header_t* package_cpaths,
-                            apl_lua_state_open_callback cb,
-                            void* btn) {
-    
-    lua_State* L;
-    ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool, "obtaining lua_State");
-    if (!apr_pool_userdata_get((void**)&L, file, lifecycle_pool)) {
-        ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool, "creating lua_State with file %s", file);
+lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
+                             char *file,
+                             apr_array_header_t *package_paths,
+                             apr_array_header_t *package_cpaths,
+                             apl_lua_state_open_callback cb, void *btn)
+{
+
+    lua_State *L;
+    ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
+                  "obtaining lua_State");
+    if (!apr_pool_userdata_get((void **) &L, file, lifecycle_pool)) {
+        ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, lifecycle_pool,
+                      "creating lua_State with file %s", file);
         /* not available, so create */
-        L =  luaL_newstate();
-        luaL_openlibs(L);        
-        if (package_paths) 
-            munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool, package_paths, file);
-        if (package_cpaths) 
-            munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool, package_cpaths, file);
-        
+        L = luaL_newstate();
+        luaL_openlibs(L);
+        if (package_paths)
+            munge_path(L, "path", "?.lua", "./?.lua", lifecycle_pool,
+                       package_paths, file);
+        if (package_cpaths)
+            munge_path(L, "cpath", "?.so", "./?.so", lifecycle_pool,
+                       package_cpaths, file);
+
         if (cb) {
             cb(L, lifecycle_pool, btn);
         }
-        
+
         luaL_loadfile(L, file);
         lua_pcall(L, 0, LUA_MULTRET, 0);
         apr_pool_userdata_set(L, file, &cleanup_lua, 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;
 }
-
-
-
-
-
-
index fa07bf81423bc96fbba125e2c5a9c38ab71b083c..b2e4481319835d9084bd89d06bad9441976d613f 100644 (file)
 
 /**
  * Specification for a lua virtual machine
- */ 
-typedef struct {
+ */
+typedef struct
+{
 
     /* NEED TO ADD ADDITIONAL PACKAGE PATHS AS PART OF SPEC INSTEAD OF DIR CONFIG */
-    apr_array_header_tpackage_paths;
-    apr_array_header_tpackage_cpaths;
-    
+    apr_array_header_t *package_paths;
+    apr_array_header_t *package_cpaths;
+
     /* name of base file to load in the vm */
-    char *file;             
+    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;
-    
+
     /* pool to use for lifecycle if APL_SCOPE_ONCE is set, otherwise unused */
     apr_pool_t *pool;
 
@@ -68,7 +69,8 @@ typedef struct {
     apr_size_t bytecode_len;
 } apl_vm_spec;
 
-typedef struct {
+typedef struct
+{
     int code_cache_style;
     char *function_name;
     char *file_name;
@@ -78,17 +80,18 @@ typedef struct {
     apr_size_t bytecode_len;
 } apl_mapped_handler_spec;
 
-typedef struct {
+typedef struct
+{
     apr_pool_t *pool;
     apr_hash_t *compiled_files;
-    apr_thread_rwlock_tcompiled_files_lock;
+    apr_thread_rwlock_t *compiled_files_lock;
 } apl_code_cache;
 
 /* remove and make static once out of mod_wombat.c */
-void apl_openlibs(lua_StateL);
+void apl_openlibs(lua_State *L);
 
 /* remove and make static once out of mod_wombat.c */
-void apl_registerlib(lua_State* L, char* name, lua_CFunction f);
+void apl_registerlib(lua_State *L, char *name, lua_CFunction f);
 
 /**
  * Fake out addition of the "apache2" module
@@ -108,7 +111,8 @@ void apl_load_apache2_lmodule(lua_State *L);
 /* returns NULL if the spec requires a request scope or conn scope */
 /* lua_State* apl_sgetvm(server_rec *r, apl_vm_spec *spec); */
 
-typedef void (*apl_lua_state_open_callback) (lua_State* L, apr_pool_t* p, void* ctx);
+typedef void (*apl_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
+                                             void *ctx);
 
 /*
  * alternate means of getting lua_State (preferred eventually)
@@ -122,14 +126,12 @@ typedef void (*apl_lua_state_open_callback) (lua_State* L, apr_pool_t* p, void*
  * @cb callback for vm initialization called *before* the file is opened
  * @ctx a baton passed to cb
  */
-lua_State* apl_get_lua_state(apr_pool_t* lifecycle_pool, 
-                             char* file, 
-                             apr_array_header_t* package_paths, 
-                             apr_array_header_t* package_cpaths,
-                             apl_lua_state_open_callback cb,
-                             void* btn);
-                             
-                             
+lua_State *apl_get_lua_state(apr_pool_t *lifecycle_pool,
+                             char *file,
+                             apr_array_header_t *package_paths,
+                             apr_array_header_t *package_cpaths,
+                             apl_lua_state_open_callback cb, void *btn);
+
 
-#endif
 
+#endif
index 51b6f4fda2a7f0330d7db0f40112c8b66ad5e203..328614d27b80cf372257c157e329b29d8f75370c 100644 (file)
 
 APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_open,
                                     (lua_State *L, apr_pool_t *p),
-                                    (L, p),
-                                    OK, DECLINED)
+                                    (L, p), OK, DECLINED)
 
 APR_IMPLEMENT_OPTIONAL_HOOK_RUN_ALL(apl, AP_LUA, int, lua_request,
                                     (lua_State *L, request_rec *r),
-                                    (L, r),
-                                    OK, DECLINED)
+                                    (L, r), OK, DECLINED)
 
-module AP_MODULE_DECLARE_DATA lua_module;
+     module AP_MODULE_DECLARE_DATA lua_module;
 
 /**
  * error reporting if lua has an error. 
  * Extracts the error from lua stack and prints
  */
-static void report_lua_error(lua_State *L, request_rec *r) {
+static void report_lua_error(lua_State *L, request_rec *r)
+{
     r->status = 500;
-    r->content_type = "text/html";      
+    r->content_type = "text/html";
 
     ap_rputs("<b>Error!</b>\n", r);
     ap_rputs("<p>", r);
-    const charlua_response = lua_tostring(L, -1);
-    ap_rputs(lua_response, r);            
+    const char *lua_response = lua_tostring(L, -1);
+    ap_rputs(lua_response, r);
     ap_rputs("</p>\n", r);
-    
-    ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, "Lua error: %s", lua_response);
+
+    ap_log_perror(APLOG_MARK, APLOG_WARNING, 0, r->pool, "Lua error: %s",
+                  lua_response);
 }
 
-static void lua_open_callback(lua_State *L, apr_pool_t *p, void* ctx) {
+static void lua_open_callback(lua_State *L, apr_pool_t *p, void *ctx)
+{
     apr_lua_init(L, p);
     apl_load_apache2_lmodule(L);
     apl_load_request_lmodule(L, p);
     apl_load_config_lmodule(L);
 }
 
-static int lua_open_hook(lua_State *L, apr_pool_t *p) {
+static int lua_open_hook(lua_State *L, apr_pool_t *p)
+{
     lua_open_callback(L, p, NULL);
     return OK;
 }
@@ -94,16 +96,19 @@ static apr_status_t luahood(ap_filter_t *f, apr_bucket_brigade *bb) {
 /**
  * "main"
  */
-static int lua_handler(request_rec *r) {        
+static int lua_handler(request_rec *r)
+{
     if (strcmp(r->handler, "lua-script")) {
         return DECLINED;
     }
-    
-    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "handling [%s] in mod_lua", r->filename);
+
+    ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "handling [%s] in mod_lua",
+                  r->filename);
     apl_dir_cfg *dcfg = ap_get_module_config(r->per_dir_config, &lua_module);
-    
-    if (!r->header_only) {        
-        apl_request_cfg* rcfg = ap_get_module_config(r->request_config, &lua_module);
+
+    if (!r->header_only) {
+        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) {
@@ -116,16 +121,17 @@ static int lua_handler(request_rec *r) {
             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->file,
-                                          cfg->package_paths,
-                                          cfg->package_cpaths,
-                                          &lua_open_callback, NULL); 
-                                          
+        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->file,
+                                         cfg->package_paths,
+                                         cfg->package_cpaths,
+                                         &lua_open_callback, NULL);
+
         ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, "got a vm!");
         if (!L) {
             /* TODO annotate spec with failure reason */
@@ -146,19 +152,27 @@ static int lua_handler(request_rec *r) {
 /**
  * Like mod_alias except for lua handler fun :-) 
  */
-static int apl_alias_munger(request_rec *r) {
-    const apl_dir_cfg *cfg = ap_get_module_config(r->per_dir_config, &lua_module);
-    
+static int apl_alias_munger(request_rec *r)
+{
+    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];
-        if (OK == ap_regexec(cnd->uri_pattern, r->uri, AP_MAX_REG_MATCH, matches, 0)) {
+        const apl_mapped_handler_spec *cnd =
+            ((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->file =  ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH, matches);
+            spec->file =
+                ap_pregsub(r->pool, cnd->file_name, r->uri, AP_MAX_REG_MATCH,
+                           matches);
             spec->scope = cnd->scope;
             spec->code_cache_style = cnd->code_cache_style;
             spec->bytecode = cnd->bytecode;
@@ -166,75 +180,87 @@ static int apl_alias_munger(request_rec *r) {
             if (spec->scope == APL_SCOPE_ONCE) {
                 spec->pool = r->pool;
             }
-            
-            mapped_request_details *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);
+
+            mapped_request_details *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);
-            apl_request_cfg *rcfg = ap_get_module_config(r->request_config, &lua_module);
+            apl_request_cfg *rcfg =
+                ap_get_module_config(r->request_config, &lua_module);
             rcfg->mapped_request_details = d;
             return OK;
         }
     }
-    return DECLINED;    
+    return DECLINED;
 }
 
 /* ---------------- Configury stuff --------------- */
 
 /** harnesses for magic hooks **/
 
-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;
-    
-    const apl_dir_cfg* cfg = (apl_dir_cfg*) ap_get_module_config(r->per_dir_config,
-                                                                       &lua_module);
-    apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
+
+    const apl_dir_cfg *cfg =
+        (apl_dir_cfg *) ap_get_module_config(r->per_dir_config,
+                                             &lua_module);
+    apr_array_header_t *hook_specs =
+        apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
     if (hook_specs) {
         int i;
-        for (i=0; i < hook_specs->nelts; i++) {
-            apl_mapped_handler_spec *hook_spec = ((apl_mapped_handler_spec**)hook_specs->elts)[i];
-            if (hook_spec == NULL) continue;
+        for (i = 0; i < hook_specs->nelts; i++) {
+            apl_mapped_handler_spec *hook_spec =
+                ((apl_mapped_handler_spec **) hook_specs->elts)[i];
+            if (hook_spec == NULL)
+                continue;
             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;
             spec->scope = hook_spec->scope;
             spec->bytecode = hook_spec->bytecode;
             spec->bytecode_len = hook_spec->bytecode_len;
             spec->pool = r->pool;
-            
+
             /*
-            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);
-            lua_State *L =  apl_get_lua_state(r->pool,
-                                              fixed_filename,
-                                              cfg->package_paths,
-                                              cfg->package_cpaths,
-                                              &lua_open_callback, NULL);
-            
-            
-            
+               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);
+            lua_State *L = apl_get_lua_state(r->pool,
+                                             fixed_filename,
+                                             cfg->package_paths,
+                                             cfg->package_cpaths,
+                                             &lua_open_callback, NULL);
+
+
+
             if (!L) {
-                ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "lua: Failed to obtain lua interpreter for %s %s",
-                              hook_spec->function_name,
-                              hook_spec->file_name);
+                ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
+                              "lua: Failed to obtain lua interpreter for %s %s",
+                              hook_spec->function_name, hook_spec->file_name);
                 return 500;
             }
 
             if (hook_spec->function_name != NULL) {
                 lua_getglobal(L, hook_spec->function_name);
                 if (!lua_isfunction(L, -1)) {
-                    ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r, "lua: Unable to find function %s in %s",
+                    ap_log_rerror(APLOG_MARK, APLOG_CRIT, 0, r,
+                                  "lua: Unable to find function %s in %s",
                                   hook_spec->function_name,
                                   hook_spec->file_name);
                     return 500;
@@ -244,7 +270,7 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name) {
             }
             else {
                 apl_run_lua_request(L, r);
-                
+
                 int t = lua_gettop(L);
                 lua_setglobal(L, "r");
                 lua_settop(L, t);
@@ -267,15 +293,17 @@ static int lua_request_rec_hook_harness(request_rec *r, const char *name) {
 }
 
 
-static apr_size_t config_getstr(ap_configfile_t *cfg, char *buf, size_t bufsiz)
+static apr_size_t config_getstr(ap_configfile_t *cfg, char *buf,
+                                size_t bufsiz)
 {
     apr_size_t i = 0;
-    
+
     if (cfg->getstr) {
-        const char *res = (cfg->getstr)(buf, bufsiz, cfg->param);
+        const char *res = (cfg->getstr) (buf, bufsiz, cfg->param);
         if (res) {
             i = strlen(buf);
-            if (i && buf[i - 1] == '\n') ++cfg->line_number;
+            if (i && buf[i - 1] == '\n')
+                ++cfg->line_number;
         }
         else {
             buf[0] = '\0';
@@ -284,8 +312,9 @@ static apr_size_t config_getstr(ap_configfile_t *cfg, char *buf, size_t bufsiz)
     }
     else {
         while (i < bufsiz) {
-            int ch = (cfg->getch)(cfg->param);
-            if (ch == EOF) break;
+            int ch = (cfg->getch) (cfg->param);
+            if (ch == EOF)
+                break;
             buf[i++] = ch;
             if (ch == '\n') {
                 ++cfg->line_number;
@@ -296,7 +325,8 @@ static apr_size_t config_getstr(ap_configfile_t *cfg, char *buf, size_t bufsiz)
     return i;
 }
 
-typedef struct cr_ctx {
+typedef struct cr_ctx
+{
     cmd_parms *cmd;
     ap_configfile_t *cfp;
     size_t startline;
@@ -312,42 +342,47 @@ typedef struct cr_ctx {
  * be happy. this is cool.
  *
  */
-static const char *lf = "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
+static const char *lf =
+    "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";
 #define N_LF 32
 
-static const char *direct_chunkreader(lua_State *lvm, void *udata, size_t *plen)
+static const char *direct_chunkreader(lua_State *lvm, void *udata,
+                                      size_t *plen)
 {
     const char *p;
     struct cr_ctx *ctx = udata;
-    
+
     if (ctx->startline) {
         *plen = ctx->startline > N_LF ? N_LF : ctx->startline;
         ctx->startline -= *plen;
         return lf;
     }
     *plen = config_getstr(ctx->cfp, ctx->buf, HUGE_STRING_LEN);
-    
+
     for (p = ctx->buf; isspace(*p); ++p);
     if (p[0] == '<' && p[1] == '/') {
         int i = 0;
         while (i < strlen(ctx->endstr)) {
-            if (tolower(p[i + 2]) != ctx->endstr[i]) return ctx->buf;
+            if (tolower(p[i + 2]) != ctx->endstr[i])
+                return ctx->buf;
             ++i;
         }
         *plen = 0;
         return NULL;
     }
-    /*fprintf(stderr, "buf read: %s\n", ctx->buf);*/
+    /*fprintf(stderr, "buf read: %s\n", ctx->buf); */
     return ctx->buf;
 }
 
-static int ldump_writer (lua_State *L, const void* b, size_t size, void* B) {
-    (void)L;
-    luaL_addlstring((luaL_Buffer*) B, (const char *)b, size);
+static int ldump_writer(lua_State *L, const void *b, size_t size, void *B)
+{
+    (void) L;
+    luaL_addlstring((luaL_Buffer *) B, (const char *) b, size);
     return 0;
 }
 
-typedef struct hack_section_baton {
+typedef struct hack_section_baton
+{
     const char *name;
     apl_mapped_handler_spec *spec;
 } hack_section_baton;
@@ -362,31 +397,35 @@ typedef struct hack_section_baton {
  * back into the parent section -- from which you can then get the new directive
  * invoked.... anyways. evil. Rici taught me how to do this hack :-)
  */
-static const char *hack_section_handler(cmd_parms *cmd, void *_cfg, const char *arg)
+static const char *hack_section_handler(cmd_parms *cmd, void *_cfg,
+                                        const char *arg)
 {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
     ap_directive_t *directive = cmd->directive;
-    hack_section_batonbaton = directive->data;
+    hack_section_baton *baton = directive->data;
 
-    apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, baton->name, APR_HASH_KEY_STRING);
+    apr_array_header_t *hook_specs =
+        apr_hash_get(cfg->hooks, baton->name, APR_HASH_KEY_STRING);
     if (!hook_specs) {
-        hook_specs = apr_array_make(cmd->pool, 2, sizeof(apl_mapped_handler_spec*));
-        apr_hash_set(cfg->hooks, apr_pstrdup(cmd->pool, baton->name), APR_HASH_KEY_STRING, hook_specs);
+        hook_specs =
+            apr_array_make(cmd->pool, 2, sizeof(apl_mapped_handler_spec *));
+        apr_hash_set(cfg->hooks, apr_pstrdup(cmd->pool, baton->name),
+                     APR_HASH_KEY_STRING, hook_specs);
     }
 
     baton->spec->scope = cfg->vm_scope;
 
-    *(apl_mapped_handler_spec**)apr_array_push(hook_specs) = baton->spec;
+    *(apl_mapped_handler_spec **) apr_array_push(hook_specs) = baton->spec;
 
     return NULL;
 }
 
-static const char *register_named_block_function_hook(const char *name, 
-                                                      cmd_parms *cmd, 
-                                                      void *mconfig, 
+static const char *register_named_block_function_hook(const char *name,
+                                                      cmd_parms *cmd,
+                                                      void *mconfig,
                                                       const char *line)
 {
-    const charfunction;
+    const char *function;
 
     if (line && line[0] == '>') {
         function = NULL;
@@ -397,26 +436,29 @@ static const char *register_named_block_function_hook(const char *name,
         word = ap_getword_conf(cmd->pool, &line);
         wordlen = strlen(word);
         if (wordlen == 0 || word[wordlen - 1] != '>') {
-            return apr_pstrcat(cmd->pool, cmd->directive->directive, "> takes exactly one argument", NULL);
+            return apr_pstrcat(cmd->pool, cmd->directive->directive,
+                               "> takes exactly one argument", NULL);
         }
         else {
             function = apr_pstrndup(cmd->pool, word, wordlen - 1);
         }
     }
 
-    apl_mapped_handler_spec *spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
+    apl_mapped_handler_spec *spec =
+        apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
 
     {
         cr_ctx ctx;
         char buf[32];
-        lua_Statelvm;
+        lua_State *lvm;
         char *tmp;
         int rv;
 
         apr_snprintf(buf, sizeof(buf), "%u", cmd->config_file->line_number);
-        spec->file_name = apr_pstrcat(cmd->pool, cmd->config_file->name, ":", buf, NULL);
+        spec->file_name =
+            apr_pstrcat(cmd->pool, cmd->config_file->name, ":", buf, NULL);
         if (function) {
-            spec->function_name = (char*)function;
+            spec->function_name = (char *) function;
         }
         else {
             function = NULL;
@@ -424,9 +466,9 @@ static const char *register_named_block_function_hook(const char *name,
         spec->code_cache_style = APL_CODE_CACHE_FOREVER;
 
         ctx.cmd = cmd;
-        tmp = apr_pstrdup(cmd->pool, cmd->err_directive->directive+1);
+        tmp = apr_pstrdup(cmd->pool, cmd->err_directive->directive + 1);
         ap_str_tolower(tmp);
-        ctx.endstr = tmp; 
+        ctx.endstr = tmp;
         ctx.cfp = cmd->config_file;
         ctx.startline = cmd->config_file->line_number;
 
@@ -438,7 +480,9 @@ static const char *register_named_block_function_hook(const char *name,
         rv = lua_load(lvm, direct_chunkreader, &ctx, spec->file_name);
 
         if (rv != 0) {
-            const char *errstr = apr_pstrcat(cmd->pool, "Lua Error:", lua_tostring(lvm, -1), NULL);
+            const char *errstr =
+                apr_pstrcat(cmd->pool, "Lua Error:", lua_tostring(lvm, -1),
+                            NULL);
             lua_close(lvm);
             return errstr;
         }
@@ -448,7 +492,9 @@ static const char *register_named_block_function_hook(const char *name,
             lua_dump(lvm, ldump_writer, &b);
             luaL_pushresult(&b);
             spec->bytecode_len = lua_strlen(lvm, -1);
-            spec->bytecode = apr_pstrmemdup(cmd->pool, lua_tostring(lvm, -1), spec->bytecode_len);
+            spec->bytecode =
+                apr_pstrmemdup(cmd->pool, lua_tostring(lvm, -1),
+                               spec->bytecode_len);
             lua_close(lvm);
         }
 
@@ -458,14 +504,16 @@ static const char *register_named_block_function_hook(const char *name,
         if (!*current) {
             *current = apr_pcalloc(cmd->pool, sizeof(**current));
         }
-        
-        hack_section_baton *baton = apr_pcalloc(cmd->pool, sizeof(hack_section_baton));
+
+        hack_section_baton *baton =
+            apr_pcalloc(cmd->pool, sizeof(hack_section_baton));
         baton->name = name;
         baton->spec = spec;
 
         (*current)->filename = cmd->config_file->name;
         (*current)->line_num = cmd->config_file->line_number;
-        (*current)->directive = apr_pstrdup(cmd->pool, "Lua_____ByteCodeHack");
+        (*current)->directive =
+            apr_pstrdup(cmd->pool, "Lua_____ByteCodeHack");
         (*current)->args = NULL;
         (*current)->data = baton;
     }
@@ -473,149 +521,223 @@ static const char *register_named_block_function_hook(const char *name,
     return NULL;
 }
 
-static const char* register_named_file_function_hook(const char *name, 
-                                                     cmd_parms *cmd, 
-                                                     void *_cfg, 
-                                                     const char *file, 
-                                                     const char *function) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
-    
-    apr_array_header_t *hook_specs = apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
+static const char *register_named_file_function_hook(const char *name,
+                                                     cmd_parms *cmd,
+                                                     void *_cfg,
+                                                     const char *file,
+                                                     const char *function)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
+
+    apr_array_header_t *hook_specs =
+        apr_hash_get(cfg->hooks, name, APR_HASH_KEY_STRING);
     if (!hook_specs) {
-        hook_specs = apr_array_make(cmd->pool, 2, sizeof(apl_mapped_handler_spec*));
-        apr_hash_set(cfg->hooks, apr_pstrdup(cmd->pool, name), APR_HASH_KEY_STRING, hook_specs);
+        hook_specs =
+            apr_array_make(cmd->pool, 2, sizeof(apl_mapped_handler_spec *));
+        apr_hash_set(cfg->hooks, apr_pstrdup(cmd->pool, name),
+                     APR_HASH_KEY_STRING, hook_specs);
     }
 
-    apl_mapped_handler_spec *spec = apr_pcalloc(cmd->pool, sizeof(apl_mapped_handler_spec));
+    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;
     spec->code_cache_style = APL_CODE_CACHE_STAT;
     /*
-        int code_cache_style;
-        char *function_name;
-        char *file_name;
-        int scope;
-    */
-    *(apl_mapped_handler_spec**)apr_array_push(hook_specs) = spec;
+       int code_cache_style;
+       char *function_name;
+       char *file_name;
+       int scope;
+     */
+    *(apl_mapped_handler_spec **) apr_array_push(hook_specs) = spec;
     return NULL;
 }
 
-static int lua_check_user_id_harness(request_rec *r) {
+static int lua_check_user_id_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "check_user_id");
 }
 
-static int lua_translate_name_harness(request_rec *r) {
+static int lua_translate_name_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "translate_name");
 }
 
-static int lua_fixup_harness(request_rec *r) {
+static int lua_fixup_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "fixups");
 }
 
-static int lua_map_to_storage_harness(request_rec *r) {
+static int lua_map_to_storage_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "map_to_storage");
 }
 
-static int lua_type_checker_harness(request_rec *r) {
+static int lua_type_checker_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "type_checker");
 }
 
-static int lua_access_checker_harness(request_rec *r) {
+static int lua_access_checker_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "access_checker");
 }
 
-static int lua_auth_checker_harness(request_rec *r) {
+static int lua_auth_checker_harness(request_rec *r)
+{
     return lua_request_rec_hook_harness(r, "auth_checker");
 }
 
-static void lua_insert_filter_harness(request_rec *r) {
+static void lua_insert_filter_harness(request_rec *r)
+{
     /* ap_log_rerror(APLOG_MARK, APLOG_WARNING, 0, r, "LuaHookInsertFilter not yet implemented"); */
 }
 
-static int lua_quick_harness(request_rec *r, int lookup) {
-    if(lookup) {
+static int lua_quick_harness(request_rec *r, int lookup)
+{
+    if (lookup) {
         return DECLINED;
     }
     return lua_request_rec_hook_harness(r, "quick");
 }
 
-static const char* register_translate_name_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("translate_name", cmd, _cfg, file, function);
+static const char *register_translate_name_hook(cmd_parms *cmd, void *_cfg,
+                                                const char *file,
+                                                const char *function)
+{
+    return register_named_file_function_hook("translate_name", cmd, _cfg,
+                                             file, function);
 }
 
-static const char *register_translate_name_block(cmd_parms *cmd, void *_cfg, const char *line)
+static const char *register_translate_name_block(cmd_parms *cmd, void *_cfg,
+                                                 const char *line)
 {
-    return register_named_block_function_hook("translate_name", cmd, _cfg, line);
+    return register_named_block_function_hook("translate_name", cmd, _cfg,
+                                              line);
 }
 
 
-static const char* register_fixups_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("fixups", cmd, _cfg, file, function);
+static const char *register_fixups_hook(cmd_parms *cmd, void *_cfg,
+                                        const char *file,
+                                        const char *function)
+{
+    return register_named_file_function_hook("fixups", cmd, _cfg, file,
+                                             function);
 }
-static const char* register_fixups_block(cmd_parms *cmd, void *_cfg, const char *line) {
+static const char *register_fixups_block(cmd_parms *cmd, void *_cfg,
+                                         const char *line)
+{
     return register_named_block_function_hook("fixups", cmd, _cfg, line);
 }
 
-static const char* register_map_to_storage_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("map_to_storage", cmd, _cfg, file, function);
+static const char *register_map_to_storage_hook(cmd_parms *cmd, void *_cfg,
+                                                const char *file,
+                                                const char *function)
+{
+    return register_named_file_function_hook("map_to_storage", cmd, _cfg,
+                                             file, function);
 }
-static const char* register_map_to_storage_block(cmd_parms *cmd, void *_cfg, const char *line) {
-    return register_named_block_function_hook("map_to_storage", cmd, _cfg, line);
+static const char *register_map_to_storage_block(cmd_parms *cmd, void *_cfg,
+                                                 const char *line)
+{
+    return register_named_block_function_hook("map_to_storage", cmd, _cfg,
+                                              line);
 }
 
-static const char* register_check_user_id_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("check_user_id", cmd, _cfg, file, function);
+static const char *register_check_user_id_hook(cmd_parms *cmd, void *_cfg,
+                                               const char *file,
+                                               const char *function)
+{
+    return register_named_file_function_hook("check_user_id", cmd, _cfg, file,
+                                             function);
 }
-static const char* register_check_user_id_block(cmd_parms *cmd, void *_cfg, const char *line) {
-    return register_named_block_function_hook("check_user_id", cmd, _cfg, line);
+static const char *register_check_user_id_block(cmd_parms *cmd, void *_cfg,
+                                                const char *line)
+{
+    return register_named_block_function_hook("check_user_id", cmd, _cfg,
+                                              line);
 }
 
-static const char* register_type_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("type_checker", cmd, _cfg, file, function);
+static const char *register_type_checker_hook(cmd_parms *cmd, void *_cfg,
+                                              const char *file,
+                                              const char *function)
+{
+    return register_named_file_function_hook("type_checker", cmd, _cfg, file,
+                                             function);
 }
-static const char* register_type_checker_block(cmd_parms *cmd, void *_cfg, const char *line) {
-    return register_named_block_function_hook("type_checker", cmd, _cfg, line);
+static const char *register_type_checker_block(cmd_parms *cmd, void *_cfg,
+                                               const char *line)
+{
+    return register_named_block_function_hook("type_checker", cmd, _cfg,
+                                              line);
 }
 
-static const char* register_access_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("access_checker", cmd, _cfg, file, function);
+static const char *register_access_checker_hook(cmd_parms *cmd, void *_cfg,
+                                                const char *file,
+                                                const char *function)
+{
+    return register_named_file_function_hook("access_checker", cmd, _cfg,
+                                             file, function);
 }
-static const char* register_access_checker_block(cmd_parms *cmd, void *_cfg, const char *line) {
-    return register_named_block_function_hook("access_checker", cmd, _cfg, line);
+static const char *register_access_checker_block(cmd_parms *cmd, void *_cfg,
+                                                 const char *line)
+{
+    return register_named_block_function_hook("access_checker", cmd, _cfg,
+                                              line);
 }
 
-static const char* register_auth_checker_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("auth_checker", cmd, _cfg, file, function);
+static const char *register_auth_checker_hook(cmd_parms *cmd, void *_cfg,
+                                              const char *file,
+                                              const char *function)
+{
+    return register_named_file_function_hook("auth_checker", cmd, _cfg, file,
+                                             function);
 }
-static const char* register_auth_checker_block(cmd_parms *cmd, void *_cfg, const char *line) {
-    return register_named_block_function_hook("auth_checker", cmd, _cfg, line);
+static const char *register_auth_checker_block(cmd_parms *cmd, void *_cfg,
+                                               const char *line)
+{
+    return register_named_block_function_hook("auth_checker", cmd, _cfg,
+                                              line);
 }
 
-static const char* register_insert_filter_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
+static const char *register_insert_filter_hook(cmd_parms *cmd, void *_cfg,
+                                               const char *file,
+                                               const char *function)
+{
     return "LuaHookInsertFilter not yet implemented";
 }
 
-static const char* register_quick_hook(cmd_parms *cmd, void *_cfg, const char *file, const char *function) {
-    return register_named_file_function_hook("quick", cmd, _cfg, file, function);
+static const char *register_quick_hook(cmd_parms *cmd, void *_cfg,
+                                       const char *file, const char *function)
+{
+    return register_named_file_function_hook("quick", cmd, _cfg, file,
+                                             function);
 }
-static const char* register_quick_block(cmd_parms *cmd, void *_cfg, const char *line) {
+static const char *register_quick_block(cmd_parms *cmd, void *_cfg,
+                                        const char *line)
+{
     return "LuaQuickHook in an inline block not yet implemented";
 }
 
 
 
-static const char* register_package_helper(cmd_parms *cmd, const char *arg, apr_array_header_t *dir_array) {
+static const char *register_package_helper(cmd_parms *cmd, const char *arg,
+                                           apr_array_header_t *dir_array)
+{
     apr_status_t rv;
-        
-    apl_server_cfg *server_cfg = ap_get_module_config(cmd->server->module_config, &lua_module);
+
+    apl_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);
+        return apr_psprintf(cmd->pool,
+                            "Unable to build full path to file, %s", arg);
     }
-    
-    *(const char**)apr_array_push(dir_array) = fixed_filename;
+
+    *(const char **) apr_array_push(dir_array) = fixed_filename;
     return NULL;
 }
 
@@ -624,9 +746,11 @@ static const char* register_package_helper(cmd_parms *cmd, const char *arg, apr_
  * Called for config directive which looks like
  * LuaPackagePath /lua/package/path/mapped/thing/like/this/?.lua
  */
-static const char* register_package_dir(cmd_parms *cmd, void *_cfg, const char *arg) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
-    
+static const char *register_package_dir(cmd_parms *cmd, void *_cfg,
+                                        const char *arg)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
+
     return register_package_helper(cmd, arg, cfg->package_paths);
 }
 
@@ -634,9 +758,11 @@ static const char* register_package_dir(cmd_parms *cmd, void *_cfg, const char *
  * Called for config directive which looks like
  * LuaPackageCPath /lua/package/path/mapped/thing/like/this/?.so
  */
-static const char* register_package_cdir(cmd_parms *cmd, void *_cfg, const char *arg) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
-    
+static const char *register_package_cdir(cmd_parms *cmd, void *_cfg,
+                                         const char *arg)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
+
     return register_package_helper(cmd, arg, cfg->package_cpaths);
 }
 
@@ -644,8 +770,10 @@ static const char* register_package_cdir(cmd_parms *cmd, void *_cfg, const char
  * Called for config directive which looks like
  * LuaCodeCache 
  */
-static const char* register_code_cache(cmd_parms *cmd, void *_cfg, const char *arg) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
+static const char *register_code_cache(cmd_parms *cmd, void *_cfg,
+                                       const char *arg)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
     if (apr_strnatcmp("stat", arg) == 0) {
         cfg->code_cache_style = APL_CODE_CACHE_STAT;
     }
@@ -656,17 +784,18 @@ static const char* register_code_cache(cmd_parms *cmd, void *_cfg, const char *a
         cfg->code_cache_style = APL_CODE_CACHE_NEVER;
     }
     else {
-        return apr_psprintf(cmd->pool, 
-               "Invalid value for LuaCodeCache, '%s', acceptable values are %s", 
-               arg, "'stat', 'forever', and 'never'");
+        return apr_psprintf(cmd->pool,
+                            "Invalid value for LuaCodeCache, '%s', acceptable values are %s",
+                            arg, "'stat', 'forever', and 'never'");
     }
     return NULL;
 }
 
-static const char* register_lua_scope(cmd_parms *cmd, void *_cfg, const char *scope,
-                                                                  const char *min,
-                                                                  const char *max) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
+static const char *register_lua_scope(cmd_parms *cmd, void *_cfg,
+                                      const char *scope, const char *min,
+                                      const char *max)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
     if (apr_strnatcmp("once", scope) == 0) {
         cfg->vm_scope = APL_SCOPE_ONCE;
     }
@@ -678,13 +807,15 @@ static const char* register_lua_scope(cmd_parms *cmd, void *_cfg, const char *sc
     }
     else if (apr_strnatcmp("server", scope) == 0) {
         cfg->vm_scope = APL_SCOPE_SERVER;
-        if (min) cfg->vm_server_pool_min = atoi(min);
-        if (max) cfg->vm_server_pool_max = atoi(max);
+        if (min)
+            cfg->vm_server_pool_min = atoi(min);
+        if (max)
+            cfg->vm_server_pool_max = atoi(max);
     }
     else {
-        return apr_psprintf(cmd->pool, 
-               "Invalid value for LuaScope, '%s', acceptable values are %s", 
-               scope, "'once', 'request', 'conn', and 'server'");
+        return apr_psprintf(cmd->pool,
+                            "Invalid value for LuaScope, '%s', acceptable values are %s",
+                            scope, "'once', 'request', 'conn', and 'server'");
     }
     return NULL;
 }
@@ -694,24 +825,31 @@ static const char* register_lua_scope(cmd_parms *cmd, void *_cfg, const char *sc
  * 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) {
-    apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg;
+static const char *lua_map_handler(cmd_parms *cmd, void *_cfg,
+                                   const char *path, const char *file,
+                                   const char *function)
+{
+    apl_dir_cfg *cfg = (apl_dir_cfg *) _cfg;
 
     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, "Unable to configure a lua handler for path '%s', handler %s#%s",
-                                       path, file, function_name);
+        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) {
+static const char *register_lua_root(cmd_parms *cmd, void *_cfg,
+                                     const char *root)
+{
     /* apl_dir_cfg* cfg = (apl_dir_cfg*)_cfg; */
-    apl_server_cfg* cfg = ap_get_module_config(cmd->server->module_config, &lua_module);
-    
+    apl_server_cfg *cfg =
+        ap_get_module_config(cmd->server->module_config, &lua_module);
+
     cfg->root_path = root;
     return NULL;
 }
@@ -720,94 +858,108 @@ static const char* register_lua_root(cmd_parms *cmd, void *_cfg, const char *roo
 
 command_rec lua_commands[] = {
 
-    AP_INIT_TAKE1("LuaRoot", register_lua_root, NULL, OR_ALL, 
-                "Specify the base path for resolving relative paths for mod_lua directives"),
+    AP_INIT_TAKE1("LuaRoot", register_lua_root, NULL, OR_ALL,
+                  "Specify the base path for resolving relative paths for mod_lua directives"),
 
-    
-    AP_INIT_TAKE1("LuaPackagePath", register_package_dir, NULL, OR_ALL, 
+
+    AP_INIT_TAKE1("LuaPackagePath", register_package_dir, NULL, OR_ALL,
                   "Add a directory to lua's package.path"),
-                  
-    AP_INIT_TAKE1("LuaPackageCPath", register_package_cdir, NULL, OR_ALL, 
+
+    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_TAKE2("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,
+
+    AP_INIT_TAKE23("LuaMapHandler", lua_map_handler, NULL, OR_ALL,
+                   "Map a path to a lua handler"),
+
+    AP_INIT_TAKE2("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,
                      "Provide a hook for the translate name phase of request processing"),
 
-    AP_INIT_TAKE2("LuaHookFixups", register_fixups_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookFixups", register_fixups_hook, NULL, OR_ALL,
                   "Provide a hook for the fixups phase of request processing"),
     AP_INIT_RAW_ARGS("<LuaHookFixups", register_fixups_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
+                     EXEC_ON_READ | OR_ALL,
                      "Provide a inline hook for the fixups phase of request processing"),
 
 /* todo: test */
-    AP_INIT_TAKE2("LuaHookMapToStorage", register_map_to_storage_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookMapToStorage", register_map_to_storage_hook, NULL,
+                  OR_ALL,
                   "Provide a hook for the map_to_storage phase of request processing"),
-    AP_INIT_RAW_ARGS("<LuaHookMapToStorage", register_map_to_storage_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
+    AP_INIT_RAW_ARGS("<LuaHookMapToStorage", register_map_to_storage_block,
+                     NULL,
+                     EXEC_ON_READ | OR_ALL,
                      "Provide a hook for the map_to_storage phase of request processing"),
 
     /* todo: test */
-    AP_INIT_TAKE2("LuaHookCheckUserID", register_check_user_id_hook, NULL, OR_ALL, 
-                  "Provide a hook for the check_user_id phase of request processing"),    
-    AP_INIT_RAW_ARGS("<LuaHookCheckUserID", register_check_user_id_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
-                     "Provide a hook for the check_user_id phase of request processing"),    
+    AP_INIT_TAKE2("LuaHookCheckUserID", register_check_user_id_hook, NULL,
+                  OR_ALL,
+                  "Provide a hook for the check_user_id phase of request processing"),
+    AP_INIT_RAW_ARGS("<LuaHookCheckUserID", register_check_user_id_block,
+                     NULL,
+                     EXEC_ON_READ | OR_ALL,
+                     "Provide a hook for the check_user_id phase of request processing"),
 
     /* todo: test */
-    AP_INIT_TAKE2("LuaHookTypeChecker", register_type_checker_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookTypeChecker", register_type_checker_hook, NULL,
+                  OR_ALL,
                   "Provide a hook for the type_checker phase of request processing"),
     AP_INIT_RAW_ARGS("<LuaHookTypeChecker", register_type_checker_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
+                     EXEC_ON_READ | OR_ALL,
                      "Provide a hook for the type_checker phase of request processing"),
 
     /* todo: test */
-    AP_INIT_TAKE2("LuaHookAccessChecker", register_access_checker_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookAccessChecker", register_access_checker_hook, NULL,
+                  OR_ALL,
                   "Provide a hook for the access_checker phase of request processing"),
-    AP_INIT_RAW_ARGS("<LuaHookAccessChecker", register_access_checker_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
+    AP_INIT_RAW_ARGS("<LuaHookAccessChecker", register_access_checker_block,
+                     NULL,
+                     EXEC_ON_READ | OR_ALL,
                      "Provide a hook for the access_checker phase of request processing"),
 
     /* todo: test */
-    AP_INIT_TAKE2("LuaHookAuthChecker", register_auth_checker_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookAuthChecker", register_auth_checker_hook, NULL,
+                  OR_ALL,
                   "Provide a hook for the auth_checker phase of request processing"),
     AP_INIT_RAW_ARGS("<LuaHookAuthChecker", register_auth_checker_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
+                     EXEC_ON_READ | OR_ALL,
                      "Provide a hook for the auth_checker phase of request processing"),
 
     /* todo: test */
-    AP_INIT_TAKE2("LuaHookInsertFilter", register_insert_filter_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaHookInsertFilter", register_insert_filter_hook, NULL,
+                  OR_ALL,
                   "Provide a hook for the insert_filter phase of request processing"),
-    
-    AP_INIT_TAKE1("LuaCodeCache", register_code_cache, NULL, OR_ALL, 
+
+    AP_INIT_TAKE1("LuaCodeCache", register_code_cache, NULL, OR_ALL,
                   "Configure the compiled code cache. \
                    Default is to stat the file each time, options are stat|forever|never"),
-                   
+
     AP_INIT_TAKE123("LuaScope", register_lua_scope, NULL, OR_ALL,
-                  "One of once, request, conn, server -- default is once"),
+                    "One of once, request, conn, server -- default is once"),
 
-    AP_INIT_TAKE2("LuaQuickHandler", register_quick_hook, NULL, OR_ALL, 
+    AP_INIT_TAKE2("LuaQuickHandler", register_quick_hook, NULL, OR_ALL,
                   "Provide a hook for the quick handler of request processing"),
     AP_INIT_RAW_ARGS("<LuaQuickHandler", register_quick_block, NULL,
-                     EXEC_ON_READ|OR_ALL,
-                    "Provide a hook for the quick handler of request processing"),
+                     EXEC_ON_READ | OR_ALL,
+                     "Provide a hook for the quick handler of request processing"),
 
-    AP_INIT_RAW_ARGS("Lua_____ByteCodeHack", hack_section_handler, NULL, OR_ALL, 
+    AP_INIT_RAW_ARGS("Lua_____ByteCodeHack", hack_section_handler, NULL,
+                     OR_ALL,
                      "(internal) Byte code handler"),
-    { NULL }
+    {NULL}
 };
 
 
-static void* create_dir_config(apr_pool_t *p, char *dir) {
-    apl_dir_cfg* cfg =  apr_pcalloc(p, sizeof(apl_dir_cfg));
-    cfg->package_paths = apr_array_make(p, 2, sizeof(char*));
-    cfg->package_cpaths = apr_array_make(p, 2, sizeof(char*));
-    cfg->mapped_handlers = apr_array_make(p, 1, sizeof(apl_mapped_handler_spec*));
+static void *create_dir_config(apr_pool_t *p, char *dir)
+{
+    apl_dir_cfg *cfg = apr_pcalloc(p, sizeof(apl_dir_cfg));
+    cfg->package_paths = apr_array_make(p, 2, sizeof(char *));
+    cfg->package_cpaths = apr_array_make(p, 2, sizeof(char *));
+    cfg->mapped_handlers =
+        apr_array_make(p, 1, sizeof(apl_mapped_handler_spec *));
     cfg->code_cache_style = APL_CODE_CACHE_STAT;
     cfg->pool = p;
     cfg->hooks = apr_hash_make(p);
@@ -816,7 +968,8 @@ static void* create_dir_config(apr_pool_t *p, char *dir) {
     return cfg;
 }
 
-static int create_request_config(request_rec *r) {
+static int create_request_config(request_rec *r)
+{
     apl_request_cfg *cfg = apr_palloc(r->pool, sizeof(apl_request_cfg));
     cfg->mapped_request_details = NULL;
     cfg->request_scoped_vms = apr_hash_make(r->pool);
@@ -824,8 +977,9 @@ static int create_request_config(request_rec *r) {
     return OK;
 }
 
-static void* create_server_config(apr_pool_t *p, server_rec *s) {
-    
+static void *create_server_config(apr_pool_t *p, server_rec *s)
+{
+
     apl_server_cfg *cfg = apr_pcalloc(p, sizeof(apl_server_cfg));
     cfg->code_cache = apr_pcalloc(p, sizeof(apl_code_cache));
     apr_thread_rwlock_create(&cfg->code_cache->compiled_files_lock, p);
@@ -834,48 +988,57 @@ static void* create_server_config(apr_pool_t *p, server_rec *s) {
     apr_thread_rwlock_create(&cfg->vm_reslists_lock, p);
     cfg->code_cache->pool = p;
     cfg->root_path = NULL;
-    
+
     return cfg;
 }
 
-static int lua_request_hook(lua_State *L, request_rec *r) {
+static int lua_request_hook(lua_State *L, request_rec *r)
+{
     apl_push_request(L, r);
     return OK;
 }
 
-static void lua_register_hooks(apr_pool_t *p) {
+static void lua_register_hooks(apr_pool_t *p)
+{
     /* ap_register_output_filter("luahood", luahood, NULL, AP_FTYPE_RESOURCE); */
     ap_hook_handler(lua_handler, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_create_request(create_request_config, NULL, NULL, APR_HOOK_MIDDLE);
-    
+    ap_hook_create_request(create_request_config, NULL, NULL,
+                           APR_HOOK_MIDDLE);
+
     /* http_request.h hooks */
-    ap_hook_translate_name(lua_translate_name_harness, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_translate_name(lua_translate_name_harness, NULL, NULL,
+                           APR_HOOK_MIDDLE);
     ap_hook_fixups(lua_fixup_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_map_to_storage(lua_map_to_storage_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_check_user_id(lua_check_user_id_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_type_checker(lua_type_checker_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_access_checker(lua_access_checker_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_auth_checker(lua_auth_checker_harness, NULL, NULL, APR_HOOK_MIDDLE);
-    ap_hook_insert_filter(lua_insert_filter_harness, NULL, NULL, APR_HOOK_MIDDLE);
+    ap_hook_map_to_storage(lua_map_to_storage_harness, NULL, NULL,
+                           APR_HOOK_MIDDLE);
+    ap_hook_check_user_id(lua_check_user_id_harness, NULL, NULL,
+                          APR_HOOK_MIDDLE);
+    ap_hook_type_checker(lua_type_checker_harness, NULL, NULL,
+                         APR_HOOK_MIDDLE);
+    ap_hook_access_checker(lua_access_checker_harness, NULL, NULL,
+                           APR_HOOK_MIDDLE);
+    ap_hook_auth_checker(lua_auth_checker_harness, NULL, NULL,
+                         APR_HOOK_MIDDLE);
+    ap_hook_insert_filter(lua_insert_filter_harness, NULL, NULL,
+                          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_translate_name(apl_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);    
+    ap_hook_translate_name(apl_alias_munger, NULL, NULL, APR_HOOK_MIDDLE);
 
     APR_OPTIONAL_HOOK(apl, lua_open, lua_open_hook, NULL, NULL,
                       APR_HOOK_REALLY_FIRST);
 
     APR_OPTIONAL_HOOK(apl, lua_request, lua_request_hook, NULL, NULL,
-                     APR_HOOK_REALLY_FIRST); 
+                      APR_HOOK_REALLY_FIRST);
 }
 
 module AP_MODULE_DECLARE_DATA lua_module = {
-    STANDARD20_MODULE_STUFF, 
-    create_dir_config,              /* create per-dir    config structures */
-    NULL,                           /* merge  per-dir    config structures */
-    create_server_config,           /* create per-server config structures */
-    NULL,                           /* merge  per-server config structures */
-    lua_commands,                /* table of config file commands       */
-    lua_register_hooks           /* register hooks                      */
+    STANDARD20_MODULE_STUFF,
+    create_dir_config,          /* create per-dir    config structures */
+    NULL,                       /* merge  per-dir    config structures */
+    create_server_config,       /* create per-server config structures */
+    NULL,                       /* merge  per-server config structures */
+    lua_commands,               /* table of config file commands       */
+    lua_register_hooks          /* register hooks                      */
 };
-
index 0b656faac632592c3727e9df80b33f44284b08d4..179362896d92f2f76b7ac3a231351089b694592e 100644 (file)
 #define lua_unboxpointer(L,i)  (*(void **)(lua_touserdata(L, i)))
 #endif
 
-void rstack_dump(lua_State* L, request_rec* r, const char* msg);
+void rstack_dump(lua_State *L, request_rec *r, const char *msg);
 
-typedef struct {
-    apr_array_header_t* package_paths;
-    apr_array_header_t* package_cpaths;
+typedef struct
+{
+    apr_array_header_t *package_paths;
+    apr_array_header_t *package_cpaths;
 
     /**
      * mapped handlers
      */
-    apr_array_header_tmapped_handlers;
+    apr_array_header_t *mapped_handlers;
 
     apr_pool_t *pool;
-    
+
     /**
      * CODE_CACHE_STAT | CODE_CACHE_FOREVER | CODE_CACHE_NEVER
-     */ 
+     */
     unsigned int code_cache_style;
-    
+
     /** 
      * APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_SERVER
      */
     unsigned int vm_scope;
     unsigned int vm_server_pool_min;
     unsigned int vm_server_pool_max;
-    
+
     /* info for the hook harnesses */
-    apr_hash_t *hooks; /* <wombat_hook_info> */
-    
+    apr_hash_t *hooks;          /* <wombat_hook_info> */
+
     /* the actual directory being configured */
     char *dir;
 } apl_dir_cfg;
 
-typedef struct {
+typedef struct
+{
     apl_code_cache *code_cache;
     apr_hash_t *vm_reslists;
     apr_thread_rwlock_t *vm_reslists_lock;
 
     /* value of the LuaRoot directive */
-    const char *root_path;  
+    const char *root_path;
 } apl_server_cfg;
 
-typedef struct {
+typedef struct
+{
     char *function_name;
     apl_vm_spec *spec;
 } mapped_request_details;
 
-typedef struct {
+typedef struct
+{
     mapped_request_details *mapped_request_details;
     apr_hash_t *request_scoped_vms;
 } apl_request_cfg;
 
-typedef struct {
+typedef struct
+{
     lua_State *L;
     char *function;
 } apl_filter_ctx;
@@ -140,4 +145,3 @@ APR_DECLARE_EXTERNAL_HOOK(apl, AP_LUA, int, lua_request,
                           (lua_State *L, request_rec *r));
 
 #endif /* !_MOD_LUA_H_ */
-