httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From minf...@apache.org
Subject svn commit: r1490599 [1/2] - in /httpd/httpd/branches/2.4.x: CHANGES STATUS modules/lua/lua_apr.c modules/lua/lua_apr.h modules/lua/lua_request.c modules/lua/lua_vmprep.c modules/lua/lua_vmprep.h modules/lua/mod_lua.c modules/lua/mod_lua.h
Date Fri, 07 Jun 2013 11:51:29 GMT
Author: minfrin
Date: Fri Jun  7 11:51:28 2013
New Revision: 1490599

URL: http://svn.apache.org/r1490599
Log:
mod_lua: Sync 2.4 branch with trunk. This includes (but is not limited to)
Server pools, new apr functions for the request_rec table, input/output filters,
LuaCodeCache, LuaMapHandler and multipart form data handling. This is long
overdue, and has become too spaghetti-ish to propose in chunks :|

trunk patch: http://svn.apache.org/r1366890
             http://svn.apache.org/r1367025
             http://svn.apache.org/r1367040
             http://svn.apache.org/r1367048
             http://svn.apache.org/r1383024
             http://svn.apache.org/r1383028
             http://svn.apache.org/r1383037
             http://svn.apache.org/r1367725
             http://svn.apache.org/r1367875
             http://svn.apache.org/r1368109
             http://svn.apache.org/r1369656
             http://svn.apache.org/r1369793
             http://svn.apache.org/r1369800
             http://svn.apache.org/r1370158
             http://svn.apache.org/r1433967
             http://svn.apache.org/r1429169
             http://svn.apache.org/r1425450
             http://svn.apache.org/r1425243
             http://svn.apache.org/r1422552
             http://svn.apache.org/r1422548
             http://svn.apache.org/r1422531
             http://svn.apache.org/r1422373
             http://svn.apache.org/r1422072
             http://svn.apache.org/r1421784
             http://svn.apache.org/r1421780
             (the list goes on...)
    2.4.x patch: http://www.humbedooh.com/mod_lua_sync.patch (+CHANGES)

Submitted by: humbedooh
Reviewed by: jim, covener, fuankg

Modified:
    httpd/httpd/branches/2.4.x/CHANGES
    httpd/httpd/branches/2.4.x/STATUS
    httpd/httpd/branches/2.4.x/modules/lua/lua_apr.c
    httpd/httpd/branches/2.4.x/modules/lua/lua_apr.h
    httpd/httpd/branches/2.4.x/modules/lua/lua_request.c
    httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.c
    httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.h
    httpd/httpd/branches/2.4.x/modules/lua/mod_lua.c
    httpd/httpd/branches/2.4.x/modules/lua/mod_lua.h

Modified: httpd/httpd/branches/2.4.x/CHANGES
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/CHANGES?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/CHANGES [utf-8] (original)
+++ httpd/httpd/branches/2.4.x/CHANGES [utf-8] Fri Jun  7 11:51:28 2013
@@ -2,6 +2,11 @@
 
 Changes with Apache 2.4.5
 
+  *) mod_lua: Sync 2.4 branch with trunk. This includes (but is not limited to)
+     Server pools, new apr functions for the request_rec table, input/output
+     filters, LuaCodeCache, LuaMapHandler and multipart form data handling.
+     [Daniel Gruno]
+
   *) core: make the "default" parameter of the "ErrorDocument" option case
      insensitive. PR 54419 [Tianyin Xu <tixu cs ucsd edu>]
 

Modified: httpd/httpd/branches/2.4.x/STATUS
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/STATUS?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/STATUS (original)
+++ httpd/httpd/branches/2.4.x/STATUS Fri Jun  7 11:51:28 2013
@@ -90,47 +90,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
  
-  * mod_lua: Sync 2.4 branch with trunk. This includes (but is not limited to) 
-             Server pools, new apr functions for the request_rec table, input/
-             output filters, LuaCodeCache, LuaMapHandler and multipart form data
-             handling. This is long overdue, and has become too spaghetti-ish to 
-             propose in chunks :|
-    trunk patch: http://svn.apache.org/r1366890
-                 http://svn.apache.org/r1367025
-                 http://svn.apache.org/r1367040
-                 http://svn.apache.org/r1367048
-                 http://svn.apache.org/r1383024
-                 http://svn.apache.org/r1383028
-                 http://svn.apache.org/r1383037
-                 http://svn.apache.org/r1367725
-                 http://svn.apache.org/r1367875
-                 http://svn.apache.org/r1368109
-                 http://svn.apache.org/r1369656
-                 http://svn.apache.org/r1369793
-                 http://svn.apache.org/r1369800
-                 http://svn.apache.org/r1370158
-                 http://svn.apache.org/r1433967
-                 http://svn.apache.org/r1429169
-                 http://svn.apache.org/r1425450
-                 http://svn.apache.org/r1425243
-                 http://svn.apache.org/r1422552
-                 http://svn.apache.org/r1422548                                                                        
-                 http://svn.apache.org/r1422531
-                 http://svn.apache.org/r1422373
-                 http://svn.apache.org/r1422072
-                 http://svn.apache.org/r1421784
-                 http://svn.apache.org/r1421780
-                 (the list goes on...)
-    2.4.x patch: http://www.humbedooh.com/mod_lua_sync.patch (+CHANGES)
-    +1: humbedooh, jim, covener
-    +0.5: fuankg - all issues I found so far are meanwhile fixed either by
-                 humbedooh or by myself; I did spend a bunch of hours during
-                 last weeks to test as much as possible, and I believe its
-                 now good enough provided that we copy the whole current trunk
-                 code over; but nevertheless I feel that I have only tested
-                 half of all new stuff, and therefore the +0.5 - I would like
-                 to have someone else add a vote too.
-
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
   [ New proposals should be added at the end of the list ]

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_apr.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_apr.c?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_apr.c (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_apr.c Fri Jun  7 11:51:28 2013
@@ -14,8 +14,6 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-#include "apr.h"
-#include "apr_tables.h"
 
 #include "mod_lua.h"
 #include "lua_apr.h"
@@ -30,11 +28,11 @@
 #endif
 
 
-AP_LUA_DECLARE(apr_table_t*) ap_lua_check_apr_table(lua_State *L, int index)
+AP_LUA_DECLARE(apr_table_t *) ap_lua_check_apr_table(lua_State *L, int index)
 {
     apr_table_t *t;
     luaL_checkudata(L, index, "Apr.Table");
-    t = (apr_table_t *) lua_unboxpointer(L, index);
+    t = lua_unboxpointer(L, index);
     return t;
 }
 
@@ -48,9 +46,9 @@ AP_LUA_DECLARE(void) ap_lua_push_apr_tab
 
 static int lua_table_set(lua_State *L)
 {
-    apr_table_t *t = ap_lua_check_apr_table(L, 1);
-    const char *key = luaL_checkstring(L, 2);
-    const char *val = luaL_checkstring(L, 3);
+    apr_table_t    *t = ap_lua_check_apr_table(L, 1);
+    const char     *key = luaL_checkstring(L, 2);
+    const char     *val = luaL_checkstring(L, 3);
 
     apr_table_set(t, key, val);
     return 0;
@@ -58,9 +56,9 @@ static int lua_table_set(lua_State *L)
 
 static int lua_table_get(lua_State *L)
 {
-    apr_table_t *t = ap_lua_check_apr_table(L, 1);
-    const char *key = luaL_checkstring(L, 2);
-    const char *val = apr_table_get(t, key);
+    apr_table_t    *t = ap_lua_check_apr_table(L, 1);
+    const char     *key = luaL_checkstring(L, 2);
+    const char     *val = apr_table_get(t, key);
     lua_pushstring(L, val);
     return 1;
 }
@@ -88,3 +86,6 @@ AP_LUA_DECLARE(int) ap_lua_init(lua_Stat
 
     return 0;
 }
+
+
+

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_apr.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_apr.h?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_apr.h (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_apr.h Fri Jun  7 11:51:28 2013
@@ -18,8 +18,20 @@
 #ifndef _LUA_APR_H_
 #define _LUA_APR_H_
 
+#include "scoreboard.h"
+#include "http_main.h"
+#include "ap_mpm.h"
+#include "apr_md5.h"
+#include "apr_sha1.h"
+#include "apr_poll.h"
+#include "apr.h"
+#include "apr_tables.h"
+#include "apr_base64.h"
+
+
 AP_LUA_DECLARE(int) ap_lua_init(lua_State *L, apr_pool_t * p);
 AP_LUA_DECLARE(apr_table_t*) ap_lua_check_apr_table(lua_State *L, int index);
 AP_LUA_DECLARE(void) ap_lua_push_apr_table(lua_State *L, apr_table_t *t);
+AP_LUA_DECLARE(int) ap_lua_load_httpd_functions(lua_State *L);
 
 #endif /* !_LUA_APR_H_ */

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_request.c?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_request.c (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_request.c Fri Jun  7 11:51:28 2013
@@ -18,9 +18,12 @@
 #include "mod_lua.h"
 #include "util_script.h"
 #include "lua_apr.h"
+#include "scoreboard.h"
 #include "lua_dbd.h"
+#include "util_md5.h"
 
 APLOG_USE_MODULE(lua);
+#define POST_MAX_VARS 500
 
 typedef char *(*req_field_string_f) (request_rec * r);
 typedef int (*req_field_int_f) (request_rec * r);
@@ -30,9 +33,7 @@ void ap_lua_rstack_dump(lua_State *L, re
 {
     int i;
     int top = lua_gettop(L);
-
     ap_log_rerror(APLOG_MARK, APLOG_INFO, 0, r, APLOGNO(01484) "Lua Stack Dump: [%s]", msg);
-
     for (i = 1; i <= top; i++) {
         int t = lua_type(L, i);
         switch (t) {
@@ -153,6 +154,87 @@ static int req_aprtable2luatable_cb(void
     return 1;
 }
 
+
+/*
+ =======================================================================================================================
+    lua_read_body(request_rec *r, const char **rbuf, apr_off_t *size): Reads any additional form data sent in POST/PUT
+    requests. Used for multipart POST data.
+ =======================================================================================================================
+ */
+static int lua_read_body(request_rec *r, const char **rbuf, apr_off_t *size)
+{
+    int rc = OK;
+
+    if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR))) {
+        return (rc);
+    }
+    if (ap_should_client_block(r)) {
+
+        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+        char         argsbuffer[HUGE_STRING_LEN];
+        apr_off_t    rsize, len_read, rpos = 0;
+        apr_off_t length = r->remaining;
+        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+        *rbuf = (const char *) apr_pcalloc(r->pool, (apr_size_t) (length + 1));
+        *size = length;
+        while ((len_read = ap_get_client_block(r, argsbuffer, sizeof(argsbuffer))) > 0) {
+            if ((rpos + len_read) > length) {
+                rsize = length - rpos;
+            }
+            else {
+                rsize = len_read;
+            }
+
+            memcpy((char *) *rbuf + rpos, argsbuffer, (size_t) rsize);
+            rpos += rsize;
+        }
+    }
+
+    return (rc);
+}
+
+
+/*
+ * =======================================================================================================================
+ * lua_write_body: Reads any additional form data sent in POST/PUT requests
+ * and writes to a file.
+ * =======================================================================================================================
+ */
+static apr_status_t lua_write_body(request_rec *r, apr_file_t *file, apr_off_t *size)
+{
+    apr_status_t rc = OK;
+
+    if ((rc = ap_setup_client_block(r, REQUEST_CHUNKED_ERROR)))
+        return rc;
+    if (ap_should_client_block(r)) {
+        char argsbuffer[HUGE_STRING_LEN];
+        apr_off_t rsize,
+                  len_read,
+                  rpos = 0;
+        apr_off_t length = r->remaining;
+        apr_size_t written;
+
+        *size = length;
+        while ((len_read =
+                    ap_get_client_block(r, argsbuffer,
+                                        sizeof(argsbuffer))) > 0) {
+            if ((rpos + len_read) > length)
+                rsize = (apr_size_t) length - rpos;
+            else
+                rsize = len_read;
+
+            rc = apr_file_write_full(file, argsbuffer, (apr_size_t) rsize,
+                                     &written);
+            if (written != rsize || rc != OK)
+                return APR_ENOSPC;
+            rpos += rsize;
+        }
+    }
+
+    return rc;
+}
+
 /* r:parseargs() returning a lua table */
 static int req_parseargs(lua_State *L)
 {
@@ -165,7 +247,7 @@ static int req_parseargs(lua_State *L)
     return 2;                   /* [table<string, string>, table<string, array<string>>] */
 }
 
-/* r:parsebody() returning a lua table */
+/* r:parsebody(): Parses regular (url-enocded) or multipart POST data and returns two tables*/
 static int req_parsebody(lua_State *L)
 {
     apr_array_header_t          *pairs;
@@ -173,26 +255,127 @@ static int req_parsebody(lua_State *L)
     int res;
     apr_size_t size;
     apr_size_t max_post_size;
-    char *buffer;
+    char *multipart;
+    const char *contentType;
     request_rec *r = ap_lua_check_request_rec(L, 1);
     max_post_size = (apr_size_t) luaL_optint(L, 2, MAX_STRING_LEN);
+    multipart = apr_pcalloc(r->pool, 256);
+    contentType = apr_table_get(r->headers_in, "Content-Type");
     lua_newtable(L);
-    lua_newtable(L);            /* [table, table] */
-    res = ap_parse_form_data(r, NULL, &pairs, -1, max_post_size);
-    if (res == OK) {
-        while(pairs && !apr_is_empty_array(pairs)) {
-            ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
-            apr_brigade_length(pair->value, 1, &len);
-            size = (apr_size_t) len;
-            buffer = apr_palloc(r->pool, size + 1);
-            apr_brigade_flatten(pair->value, buffer, &size);
-            buffer[len] = 0;
-            req_aprtable2luatable_cb(L, pair->name, buffer);
+    lua_newtable(L);            /* [table, table] */    
+    if (contentType != NULL && (sscanf(contentType, "multipart/form-data; boundary=%250c", multipart) == 1)) {
+        char        *buffer, *key, *filename;
+        char        *start = 0, *end = 0, *crlf = 0;
+        const char  *data;
+        int         i;
+        size_t      vlen = 0;
+        size_t      len = 0;
+        if (lua_read_body(r, &data, (apr_off_t*) &size) != OK) {
+            return 2;
+        }
+        len = strlen(multipart);
+        i = 0;
+        for
+        (
+            start = strstr((char *) data, multipart);
+            start != start + size;
+            start = end
+        ) {
+            i++;
+            if (i == POST_MAX_VARS) break;
+            end = strstr((char *) (start + 1), multipart);
+            if (!end) end = start + size;
+            crlf = strstr((char *) start, "\r\n\r\n");
+            if (!crlf) break;
+            key = (char *) apr_pcalloc(r->pool, 256);
+            filename = (char *) apr_pcalloc(r->pool, 256);
+            vlen = end - crlf - 8;
+            buffer = (char *) apr_pcalloc(r->pool, vlen+1);
+            memcpy(buffer, crlf + 4, vlen);
+            sscanf(start + len + 2,
+                "Content-Disposition: form-data; name=\"%255[^\"]\"; filename=\"%255[^\"]\"",
+                key, filename);
+            if (strlen(key)) {
+                req_aprtable2luatable_cb(L, key, buffer);
+            }
+        }
+    }
+    else {
+        char *buffer;
+        res = ap_parse_form_data(r, NULL, &pairs, -1, max_post_size);
+        if (res == OK) {
+            while(pairs && !apr_is_empty_array(pairs)) {
+                ap_form_pair_t *pair = (ap_form_pair_t *) apr_array_pop(pairs);
+                apr_brigade_length(pair->value, 1, &len);
+                size = (apr_size_t) len;
+                buffer = apr_palloc(r->pool, size + 1);
+                apr_brigade_flatten(pair->value, buffer, &size);
+                buffer[len] = 0;
+                req_aprtable2luatable_cb(L, pair->name, buffer);
+            }
         }
     }
     return 2;                   /* [table<string, string>, table<string, array<string>>] */
 }
 
+
+/*
+ * lua_ap_requestbody; r:requestbody([filename]) - Reads or stores the request
+ * body
+ */
+static int lua_ap_requestbody(lua_State *L)
+{
+    const char     *filename;
+    request_rec    *r;
+    apr_off_t      maxSize;
+    
+    r = ap_lua_check_request_rec(L, 1);
+    filename = luaL_optstring(L, 2, 0);
+    maxSize = luaL_optint(L, 3, 0);
+
+    if (r) {
+        apr_off_t size;
+        if (maxSize > 0 && r->remaining > maxSize) {
+            lua_pushnil(L);
+            lua_pushliteral(L, "Request body was larger than the permitted size.");
+            return 2;
+        }
+        if (r->method_number != M_POST && r->method_number != M_PUT)
+            return (0);
+        if (!filename) {
+            const char     *data;
+
+            if (lua_read_body(r, &data, &size) != OK)
+                return (0);
+
+            lua_pushlstring(L, data, (size_t) size);
+            lua_pushinteger(L, (lua_Integer) size);
+            return (2);
+        } else {
+            apr_status_t rc;
+            apr_file_t     *file;
+
+            rc = apr_file_open(&file, filename, APR_CREATE | APR_FOPEN_WRITE,
+                               APR_FPROT_OS_DEFAULT, r->pool);
+            lua_settop(L, 0);
+            if (rc == APR_SUCCESS) {
+                rc = lua_write_body(r, file, &size);
+                apr_file_close(file);
+                if (rc != OK) {
+                    lua_pushboolean(L, 0);
+                    return 1;
+                }
+                lua_pushinteger(L, (lua_Integer) size);
+                return (1);
+            } else
+                lua_pushboolean(L, 0);
+            return (1);
+        }
+    }
+
+    return (0);
+}
+
 /* wrap ap_rputs as r:puts(String) */
 static int req_puts(lua_State *L)
 {
@@ -212,10 +395,12 @@ static int req_write(lua_State *L)
 {
     request_rec *r = ap_lua_check_request_rec(L, 1);
     size_t n;
+    int rv;
     const char *buf = luaL_checklstring(L, 2, &n);
 
-    ap_rwrite((void *) buf, n, r);
-    return 0;
+    rv = ap_rwrite((void *) buf, n, r);
+    lua_pushinteger(L, rv);
+    return 1;
 }
 
 /* r:addoutputfilter(name|function) */
@@ -372,6 +557,11 @@ static const char *req_useragent_ip_fiel
     return r->useragent_ip;
 }
 
+static int req_remaining_field(request_rec *r)
+{
+    return r->remaining;
+}
+
 static int req_status_field(request_rec *r)
 {
     return r->status;
@@ -412,7 +602,938 @@ static int req_ssl_is_https_field(reques
     return ap_lua_ssl_is_https(r->connection);
 }
 
-/* END dispatch mathods for request_rec fields */
+static int lua_ap_rflush (lua_State *L) {
+
+    int returnValue;
+    request_rec *r;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    returnValue = ap_rflush(r);
+    lua_pushboolean(L, (returnValue == 0));
+    return 1;
+}
+
+static int lua_ap_port(request_rec* r) 
+{
+    return (int) ap_get_server_port(r);
+}
+
+static const char* lua_ap_options(request_rec* r) 
+{
+    int opts;
+    opts = ap_allow_options(r);
+    return apr_psprintf(r->pool, "%s %s %s %s %s %s", (opts&OPT_INDEXES) ? "Indexes" : "", (opts&OPT_INCLUDES) ? "Includes" : "", (opts&OPT_SYM_LINKS) ? "FollowSymLinks" : "", (opts&OPT_EXECCGI) ? "ExecCGI" : "", (opts&OPT_MULTI) ? "MultiViews" : "", (opts&OPT_ALL) == OPT_ALL ? "All" : "" );
+}
+
+static const char* lua_ap_allowoverrides(request_rec* r) 
+{
+    int opts;
+    opts = ap_allow_overrides(r);
+    return apr_psprintf(r->pool, "%s %s %s %s %s %s", (opts&OR_NONE) ? "None" : "", (opts&OR_LIMIT) ? "Limit" : "", (opts&OR_OPTIONS) ? "Options" : "", (opts&OR_FILEINFO) ? "FileInfo" : "", (opts&OR_AUTHCFG) ? "AuthCfg" : "", (opts&OR_INDEXES) ? "Indexes" : "" );
+}
+
+static int lua_ap_started(request_rec* r) 
+{
+    return ap_scoreboard_image->global->restart_time;
+}
+
+static const char* lua_ap_basic_auth_pw(request_rec* r) 
+{
+    const char* pw = NULL;
+    ap_get_basic_auth_pw(r, &pw);
+    return pw ? pw : "";
+}
+
+static int lua_ap_limit_req_body(request_rec* r) 
+{
+    return (int) ap_get_limit_req_body(r);
+}
+
+static int lua_ap_is_initial_req(request_rec *r)
+{
+    return ap_is_initial_req(r);
+}
+
+static int lua_ap_some_auth_required(request_rec *r)
+{
+    return ap_some_auth_required(r);
+}
+
+static int lua_ap_sendfile(lua_State *L)
+{
+
+    apr_finfo_t file_info;
+    const char  *filename;
+    request_rec *r;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    filename = lua_tostring(L, 2);
+    apr_stat(&file_info, filename, APR_FINFO_NORM, r->pool);
+    if (file_info.filetype == APR_NOFILE || file_info.filetype == APR_DIR) {
+        lua_pushboolean(L, 0);
+    }
+    else {
+        apr_size_t      sent;
+        apr_status_t    rc;
+        apr_file_t      *file;
+
+        rc = apr_file_open(&file, filename, APR_READ, APR_OS_DEFAULT,
+                            r->pool);
+        if (rc == APR_SUCCESS) {
+            ap_send_fd(file, r, 0, file_info.size, &sent);
+            apr_file_close(file);
+            lua_pushinteger(L, sent);
+        }
+        else {
+            lua_pushboolean(L, 0);
+        }
+    }
+
+    return (1);
+}
+
+
+/*
+ * lua_apr_b64encode; r:encode_base64(string) - encodes a string to Base64
+ * format
+ */
+static int lua_apr_b64encode(lua_State *L)
+{
+    const char     *plain;
+    char           *encoded;
+    size_t          plain_len, encoded_len;
+    request_rec    *r;
+
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    plain = lua_tolstring(L, 2, &plain_len);
+    encoded_len = apr_base64_encode_len(plain_len) + 1;
+    if (encoded_len) {
+        encoded = apr_palloc(r->pool, encoded_len);
+        apr_base64_encode(encoded, plain, plain_len);
+        lua_pushlstring(L, encoded, encoded_len);
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_apr_b64decode; r:decode_base64(string) - decodes a Base64 string
+ */
+static int lua_apr_b64decode(lua_State *L)
+{
+    const char     *encoded;
+    char           *plain;
+    size_t          encoded_len, decoded_len;
+    request_rec    *r;
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    encoded = lua_tolstring(L, 2, &encoded_len);
+    decoded_len = apr_base64_decode_len(encoded) + 1;
+    if (decoded_len) {
+        plain = apr_palloc(r->pool, decoded_len);
+        apr_base64_decode(plain, encoded);
+        lua_pushlstring(L, plain, decoded_len);
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_ap_unescape; r:unescape(string) - Unescapes an URL-encoded string
+ */
+static int lua_ap_unescape(lua_State *L)
+{
+    const char     *escaped;
+    char           *plain;
+    size_t x,
+           y;
+    request_rec    *r;
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    escaped = lua_tolstring(L, 2, &x);
+    plain = apr_pstrdup(r->pool, escaped);
+    y = ap_unescape_urlencoded(plain);
+    if (!y) {
+        lua_pushstring(L, plain);
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_ap_escape; r:escape(string) - URL-escapes a string
+ */
+static int lua_ap_escape(lua_State *L)
+{
+    const char     *plain;
+    char           *escaped;
+    size_t x;
+    request_rec    *r;
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    plain = lua_tolstring(L, 2, &x);
+    escaped = ap_escape_urlencoded(r->pool, plain);
+    lua_pushstring(L, escaped);
+    return 1;
+}
+
+/*
+ * lua_apr_md5; r:md5(string) - Calculates an MD5 digest of a string
+ */
+static int lua_apr_md5(lua_State *L)
+{
+    const char     *buffer;
+    char           *result;
+    size_t len;
+    request_rec    *r;
+
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    buffer = lua_tolstring(L, 2, &len);
+    result = ap_md5_binary(r->pool, (const unsigned char *)buffer, len);
+    lua_pushstring(L, result);
+    return 1;
+}
+
+/*
+ * lua_apr_sha1; r:sha1(string) - Calculates the SHA1 digest of a string
+ */
+static int lua_apr_sha1(lua_State *L)
+{
+    unsigned char digest[APR_SHA1_DIGESTSIZE];
+    apr_sha1_ctx_t sha1;
+    const char     *buffer;
+    char           *result;
+    size_t len;
+    request_rec    *r;
+
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    result = apr_pcalloc(r->pool, sizeof(digest) * 2 + 1);
+    buffer = lua_tolstring(L, 2, &len);
+    apr_sha1_init(&sha1);
+    apr_sha1_update(&sha1, buffer, len);
+    apr_sha1_final(digest, &sha1);
+    ap_bin2hex(digest, sizeof(digest), result);
+    lua_pushstring(L, result);
+    return 1;
+}
+
+
+
+/*
+ * lua_ap_banner; r:banner() - Returns the current server banner
+ */
+static int lua_ap_banner(lua_State *L)
+{
+    lua_pushstring(L, ap_get_server_banner());
+    return 1;
+}
+
+/*
+ * lua_ap_mpm_query; r:mpm_query(info) - Queries for MPM info
+ */
+static int lua_ap_mpm_query(lua_State *L)
+{
+    int x,
+        y;
+
+    x = lua_tonumber(L, 1);
+    ap_mpm_query(x, &y);
+    lua_pushnumber(L, y);
+    return 1;
+}
+
+/*
+ * lua_ap_expr; r:expr(string) - Evaluates an expr statement.
+ */
+static int lua_ap_expr(lua_State *L)
+{
+    request_rec    *r;
+    int x = 0;
+    const char     *expr,
+    *err;
+    ap_expr_info_t res;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    expr = lua_tostring(L, 2);
+
+
+    res.filename = NULL;
+    res.flags = 0;
+    res.line_number = 0;
+    res.module_index = APLOG_MODULE_INDEX;
+
+    err = ap_expr_parse(r->pool, r->pool, &res, expr, NULL);
+    if (!err) {
+        x = ap_expr_exec(r, &res, &err);
+        lua_pushboolean(L, x);
+        if (x < 0) {
+            lua_pushstring(L, err);
+            return 2;
+        }
+        return 1;
+    } else {
+        lua_pushboolean(L, 0);
+        lua_pushstring(L, err);
+        return 2;
+    }
+    lua_pushboolean(L, 0);
+    return 1;
+}
+
+
+/*
+ * lua_ap_regex; r:regex(string, pattern) - Evaluates a regex and returns
+ * captures if matched
+ */
+static int lua_ap_regex(lua_State *L)
+{
+    request_rec    *r;
+    int i,
+        rv;
+    const char     *pattern,
+    *source;
+    char           *err;
+    ap_regex_t regex;
+    ap_regmatch_t matches[AP_MAX_REG_MATCH+1];
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    luaL_checktype(L, 3, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    pattern = lua_tostring(L, 2);
+    source = lua_tostring(L, 3);
+
+    rv = ap_regcomp(&regex, pattern, 0);
+    if (rv) {
+        lua_pushboolean(L, 0);
+        err = apr_palloc(r->pool, 256);
+        ap_regerror(rv, &regex, err, 256);
+        lua_pushstring(L, err);
+        return 2;
+    }
+
+    rv = ap_regexec(&regex, source, AP_MAX_REG_MATCH, matches, 0);
+    if (rv == AP_REG_NOMATCH) {
+        lua_pushboolean(L, 0);
+        return 1;
+    }
+    
+    lua_newtable(L);
+    for (i = 0; i <= regex.re_nsub; i++) {
+        lua_pushinteger(L, i);
+        if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0)
+            lua_pushstring(L,
+                           apr_pstrndup(r->pool, source + matches[i].rm_so,
+                                        matches[i].rm_eo - matches[i].rm_so));
+        else
+            lua_pushnil(L);
+        lua_settable(L, -3);
+
+    }
+    return 1;
+}
+
+
+
+
+/*
+ * lua_ap_scoreboard_process; r:scoreboard_process(a) - returns scoreboard info
+ */
+static int lua_ap_scoreboard_process(lua_State *L)
+{
+    int i;
+    process_score  *ps_record;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TNUMBER);
+    i = lua_tonumber(L, 2);
+    ps_record = ap_get_scoreboard_process(i);
+    if (ps_record) {
+        lua_newtable(L);
+
+        lua_pushstring(L, "connections");
+        lua_pushnumber(L, ps_record->connections);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "keepalive");
+        lua_pushnumber(L, ps_record->keep_alive);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "lingering_close");
+        lua_pushnumber(L, ps_record->lingering_close);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "pid");
+        lua_pushnumber(L, ps_record->pid);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "suspended");
+        lua_pushnumber(L, ps_record->suspended);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "write_completion");
+        lua_pushnumber(L, ps_record->write_completion);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "not_accepting");
+        lua_pushnumber(L, ps_record->not_accepting);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "quiescing");
+        lua_pushnumber(L, ps_record->quiescing);
+        lua_settable(L, -3);
+
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_ap_scoreboard_worker; r:scoreboard_worker(proc, thread) - Returns thread
+ * info
+ */
+static int lua_ap_scoreboard_worker(lua_State *L)
+{
+    int i,
+        j;
+    worker_score   *ws_record;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TNUMBER);
+    luaL_checktype(L, 3, LUA_TNUMBER);
+    i = lua_tonumber(L, 2);
+    j = lua_tonumber(L, 3);
+    ws_record = ap_get_scoreboard_worker_from_indexes(i, j);
+    if (ws_record) {
+        lua_newtable(L);
+
+        lua_pushstring(L, "access_count");
+        lua_pushnumber(L, ws_record->access_count);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "bytes_served");
+        lua_pushnumber(L, ws_record->bytes_served);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "client");
+        lua_pushstring(L, ws_record->client);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "conn_bytes");
+        lua_pushnumber(L, ws_record->conn_bytes);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "conn_count");
+        lua_pushnumber(L, ws_record->conn_count);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "generation");
+        lua_pushnumber(L, ws_record->generation);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "last_used");
+        lua_pushnumber(L, ws_record->last_used);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "pid");
+        lua_pushnumber(L, ws_record->pid);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "request");
+        lua_pushstring(L, ws_record->request);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "start_time");
+        lua_pushnumber(L, ws_record->start_time);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "status");
+        lua_pushnumber(L, ws_record->status);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "stop_time");
+        lua_pushnumber(L, ws_record->stop_time);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "tid");
+
+        lua_pushinteger(L, (lua_Integer) ws_record->tid);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "vhost");
+        lua_pushstring(L, ws_record->vhost);
+        lua_settable(L, -3);
+#ifdef HAVE_TIMES
+        lua_pushstring(L, "stimes");
+        lua_pushnumber(L, ws_record->times.tms_stime);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "utimes");
+        lua_pushnumber(L, ws_record->times.tms_utime);
+        lua_settable(L, -3);
+#endif
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_ap_restarted; r:started() - Returns the timestamp of last server
+ * (re)start
+ */
+static int lua_ap_restarted(lua_State *L)
+{
+    lua_pushnumber(L, ap_scoreboard_image->global->restart_time);
+    return 1;
+}
+
+/*
+ * lua_ap_clock; r:clock() - Returns timestamp with microsecond precision
+ */
+static int lua_ap_clock(lua_State *L)
+{
+    apr_time_t now;
+    now = apr_time_now();
+    lua_pushnumber(L, now);
+    return 1;
+}
+
+/*
+ * lua_ap_add_input_filter; r:add_input_filter(name) - Adds an input filter to
+ * the chain
+ */
+static int lua_ap_add_input_filter(lua_State *L)
+{
+    request_rec    *r;
+    const char     *filterName;
+    ap_filter_rec_t *filter;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    filterName = lua_tostring(L, 2);
+    filter = ap_get_input_filter_handle(filterName);
+    if (filter) {
+        ap_add_input_filter_handle(filter, NULL, r, r->connection);
+        lua_pushboolean(L, 1);
+    } else
+        lua_pushboolean(L, 0);
+    return 1;
+}
+
+
+/*
+ * lua_ap_module_info; r:module_info(mod_name) - Returns information about a
+ * loaded module
+ */
+static int lua_ap_module_info(lua_State *L)
+{
+    const char     *moduleName;
+    module         *mod;
+
+    luaL_checktype(L, 1, LUA_TSTRING);
+    moduleName = lua_tostring(L, 1);
+    mod = ap_find_linked_module(moduleName);
+    if (mod) {
+        const command_rec *cmd;
+        lua_newtable(L);
+        lua_pushstring(L, "commands");
+        lua_newtable(L);
+        for (cmd = mod->cmds; cmd->name; ++cmd) {
+            lua_pushstring(L, cmd->name);
+            lua_pushstring(L, cmd->errmsg);
+            lua_settable(L, -3);
+        }
+        lua_settable(L, -3);
+        return 1;
+    }
+    return 0;
+}
+
+/*
+ * lua_ap_runtime_dir_relative: r:runtime_dir_relative(file): Returns the
+ * filename as relative to the runtime dir
+ */
+static int lua_ap_runtime_dir_relative(lua_State *L)
+{
+    request_rec    *r;
+    const char     *file;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    file = luaL_optstring(L, 2, ".");
+    lua_pushstring(L, ap_runtime_dir_relative(r->pool, file));
+    return 1;
+}
+
+/*
+ * lua_ap_set_document_root; r:set_document_root(path) - sets the current doc
+ * root for the request
+ */
+static int lua_ap_set_document_root(lua_State *L)
+{
+    request_rec    *r;
+    const char     *root;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    root = lua_tostring(L, 2);
+    ap_set_document_root(r, root);
+    return 0;
+}
+
+/*
+ * lua_ap_stat; r:stat(filename) - Runs stat on a file and returns the file
+ * info as a table
+ */
+static int lua_ap_stat(lua_State *L)
+{
+    request_rec    *r;
+    const char     *filename;
+    apr_finfo_t file_info;
+
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    r = ap_lua_check_request_rec(L, 1);
+    filename = lua_tostring(L, 2);
+    if (apr_stat(&file_info, filename, APR_FINFO_NORM, r->pool) == OK) {
+        lua_newtable(L);
+
+        lua_pushstring(L, "mtime");
+        lua_pushinteger(L, file_info.mtime);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "atime");
+        lua_pushinteger(L, file_info.atime);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "ctime");
+        lua_pushinteger(L, file_info.ctime);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "size");
+        lua_pushinteger(L, file_info.size);
+        lua_settable(L, -3);
+
+        lua_pushstring(L, "filetype");
+        lua_pushinteger(L, file_info.filetype);
+        lua_settable(L, -3);
+
+        return 1;
+    }
+    else {
+        return 0;
+    }
+}
+
+/*
+ * lua_ap_loaded_modules; r:loaded_modules() - Returns a list of loaded modules
+ */
+static int lua_ap_loaded_modules(lua_State *L)
+{
+    int i;
+    lua_newtable(L);
+    for (i = 0; ap_loaded_modules[i] && ap_loaded_modules[i]->name; i++) {
+        lua_pushinteger(L, i + 1);
+        lua_pushstring(L, ap_loaded_modules[i]->name);
+        lua_settable(L, -3);
+    }
+    return 1;
+}
+
+/*
+ * lua_ap_server_info; r:server_info() - Returns server info, such as the
+ * executable filename, server root, mpm etc
+ */
+static int lua_ap_server_info(lua_State *L)
+{
+    lua_newtable(L);
+
+    lua_pushstring(L, "server_executable");
+    lua_pushstring(L, ap_server_argv0);
+    lua_settable(L, -3);
+
+    lua_pushstring(L, "server_root");
+    lua_pushstring(L, ap_server_root);
+    lua_settable(L, -3);
+
+    lua_pushstring(L, "scoreboard_fname");
+    lua_pushstring(L, ap_scoreboard_fname);
+    lua_settable(L, -3);
+
+    lua_pushstring(L, "server_mpm");
+    lua_pushstring(L, ap_show_mpm());
+    lua_settable(L, -3);
+
+    return 1;
+}
+
+
+/*
+ * === Auto-scraped functions ===
+ */
+
+
+/**
+ * ap_set_context_info: Set context_prefix and context_document_root.
+ * @param r The request
+ * @param prefix the URI prefix, without trailing slash
+ * @param document_root the corresponding directory on disk, without trailing
+ * slash
+ * @note If one of prefix of document_root is NULL, the corrsponding
+ * property will not be changed.
+ */
+static int lua_ap_set_context_info(lua_State *L)
+{
+
+    request_rec    *r;
+    const char     *prefix;
+    const char     *document_root;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    prefix = lua_tostring(L, 2);
+    luaL_checktype(L, 3, LUA_TSTRING);
+    document_root = lua_tostring(L, 3);
+    ap_set_context_info(r, prefix, document_root);
+    return 0;
+}
+
+
+/**
+ * ap_os_escape_path (apr_pool_t *p, const char *path, int partial)
+ * convert an OS path to a URL in an OS dependant way.
+ * @param p The pool to allocate from
+ * @param path The path to convert
+ * @param partial if set, assume that the path will be appended to something
+ *        with a '/' in it (and thus does not prefix "./")
+ * @return The converted URL
+ */
+static int lua_ap_os_escape_path(lua_State *L)
+{
+
+    char           *returnValue;
+    request_rec    *r;
+    const char     *path;
+    int partial = 0;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    path = lua_tostring(L, 2);
+    if (lua_isboolean(L, 3))
+        partial = lua_toboolean(L, 3);
+    returnValue = ap_os_escape_path(r->pool, path, partial);
+    lua_pushstring(L, returnValue);
+    return 1;
+}
+
+
+/**
+ * ap_escape_logitem (apr_pool_t *p, const char *str)
+ * Escape a string for logging
+ * @param p The pool to allocate from
+ * @param str The string to escape
+ * @return The escaped string
+ */
+static int lua_ap_escape_logitem(lua_State *L)
+{
+
+    char           *returnValue;
+    request_rec    *r;
+    const char     *str;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    str = lua_tostring(L, 2);
+    returnValue = ap_escape_logitem(r->pool, str);
+    lua_pushstring(L, returnValue);
+    return 1;
+}
+
+/**
+ * ap_strcmp_match (const char *str, const char *expected)
+ * Determine if a string matches a patterm containing the wildcards '?' or '*'
+ * @param str The string to check
+ * @param expected The pattern to match against
+ * @param ignoreCase Whether to ignore case when matching
+ * @return 1 if the two strings match, 0 otherwise
+ */
+static int lua_ap_strcmp_match(lua_State *L)
+{
+
+    int returnValue;
+    const char     *str;
+    const char     *expected;
+    int ignoreCase = 0;
+    luaL_checktype(L, 1, LUA_TSTRING);
+    str = lua_tostring(L, 1);
+    luaL_checktype(L, 2, LUA_TSTRING);
+    expected = lua_tostring(L, 2);
+    if (lua_isboolean(L, 3))
+        ignoreCase = lua_toboolean(L, 3);
+    if (!ignoreCase)
+        returnValue = ap_strcmp_match(str, expected);
+    else
+        returnValue = ap_strcasecmp_match(str, expected);
+    lua_pushboolean(L, (!returnValue));
+    return 1;
+}
+
+
+/**
+ * ap_set_keepalive (request_rec *r)
+ * Set the keepalive status for this request
+ * @param r The current request
+ * @return 1 if keepalive can be set, 0 otherwise
+ */
+static int lua_ap_set_keepalive(lua_State *L)
+{
+
+    int returnValue;
+    request_rec    *r;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    returnValue = ap_set_keepalive(r);
+    lua_pushboolean(L, returnValue);
+    return 1;
+}
+
+/**
+ * ap_make_etag (request_rec *r, int force_weak)
+ * Construct an entity tag from the resource information.  If it's a real
+ * file, build in some of the file characteristics.
+ * @param r The current request
+ * @param force_weak Force the entity tag to be weak - it could be modified
+ *                   again in as short an interval.
+ * @return The entity tag
+ */
+static int lua_ap_make_etag(lua_State *L)
+{
+
+    char           *returnValue;
+    request_rec    *r;
+    int force_weak;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TBOOLEAN);
+    force_weak = luaL_optint(L, 2, 0);
+    returnValue = ap_make_etag(r, force_weak);
+    lua_pushstring(L, returnValue);
+    return 1;
+}
+
+
+
+/**
+ * ap_send_interim_response (request_rec *r, int send_headers)
+ * Send an interim (HTTP 1xx) response immediately.
+ * @param r The request
+ * @param send_headers Whether to send&clear headers in r->headers_out
+ */
+static int lua_ap_send_interim_response(lua_State *L)
+{
+
+    request_rec    *r;
+    int send_headers = 0;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    if (lua_isboolean(L, 2))
+        send_headers = lua_toboolean(L, 2);
+    ap_send_interim_response(r, send_headers);
+    return 0;
+}
+
+
+/**
+ * ap_custom_response (request_rec *r, int status, const char *string)
+ * Install a custom response handler for a given status
+ * @param r The current request
+ * @param status The status for which the custom response should be used
+ * @param string The custom response.  This can be a static string, a file
+ *               or a URL
+ */
+static int lua_ap_custom_response(lua_State *L)
+{
+
+    request_rec    *r;
+    int status;
+    const char     *string;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    luaL_checktype(L, 2, LUA_TNUMBER);
+    status = lua_tointeger(L, 2);
+    luaL_checktype(L, 3, LUA_TSTRING);
+    string = lua_tostring(L, 3);
+    ap_custom_response(r, status, string);
+    return 0;
+}
+
+
+/**
+ * ap_exists_config_define (const char *name)
+ * Check for a definition from the server command line
+ * @param name The define to check for
+ * @return 1 if defined, 0 otherwise
+ */
+static int lua_ap_exists_config_define(lua_State *L)
+{
+
+    int returnValue;
+    const char     *name;
+    luaL_checktype(L, 1, LUA_TSTRING);
+    name = lua_tostring(L, 1);
+    returnValue = ap_exists_config_define(name);
+    lua_pushinteger(L, returnValue);
+    return 1;
+}
+
+static int lua_ap_get_server_name_for_url(lua_State *L)
+{
+
+    const char     *servername;
+    request_rec    *r;
+    luaL_checktype(L, 1, LUA_TUSERDATA);
+    r = ap_lua_check_request_rec(L, 1);
+    servername = ap_get_server_name_for_url(r);
+    lua_pushstring(L, servername);
+    return 1;
+}
+
+
+
+/**
+ * ap_state_query (int query_code) item starts a new field  */
+static int lua_ap_state_query(lua_State *L)
+{
+
+    int returnValue;
+    int query_code;
+    luaL_checktype(L, 1, LUA_TNUMBER);
+    query_code = lua_tointeger(L, 1);
+    returnValue = ap_state_query(query_code);
+    lua_pushinteger(L, returnValue);
+    return 1;
+}
+
+static int lua_ap_sleep(lua_State *L)
+{
+
+    int msec;
+    luaL_checktype(L, 1, LUA_TNUMBER);
+    msec = (lua_tonumber(L, 1) * 1000000);
+    apr_sleep(msec);
+    return 0;
+}
+
+/* END dispatch methods for request_rec fields */
 
 static int req_dispatch(lua_State *L)
 {
@@ -752,10 +1873,109 @@ AP_LUA_DECLARE(void) ap_lua_load_request
                  makefun(&req_notes, APL_REQ_FUNTYPE_TABLE, p));
     apr_hash_set(dispatch, "subprocess_env", APR_HASH_KEY_STRING,
                  makefun(&req_subprocess_env, APL_REQ_FUNTYPE_TABLE, p));
+    apr_hash_set(dispatch, "flush", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_rflush, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "port", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_port, APL_REQ_FUNTYPE_INT, p));
+    apr_hash_set(dispatch, "banner", APR_HASH_KEY_STRING,
+                 makefun(&ap_get_server_banner, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "options", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_options, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "allowoverrides", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_allowoverrides, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "started", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_started, APL_REQ_FUNTYPE_INT, p));
+    apr_hash_set(dispatch, "basic_auth_pw", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_basic_auth_pw, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "limit_req_body", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_limit_req_body, APL_REQ_FUNTYPE_INT, p));
+    apr_hash_set(dispatch, "server_built", APR_HASH_KEY_STRING,
+                 makefun(&ap_get_server_built, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "is_initial_req", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_is_initial_req, APL_REQ_FUNTYPE_BOOLEAN, p));
+    apr_hash_set(dispatch, "remaining", APR_HASH_KEY_STRING,
+                 makefun(&req_remaining_field, APL_REQ_FUNTYPE_INT, p));
+    apr_hash_set(dispatch, "some_auth_required", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_some_auth_required, APL_REQ_FUNTYPE_BOOLEAN, p));
+    apr_hash_set(dispatch, "server_name", APR_HASH_KEY_STRING,
+                 makefun(&ap_get_server_name, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "auth_name", APR_HASH_KEY_STRING,
+                 makefun(&ap_auth_name, APL_REQ_FUNTYPE_STRING, p));
+    apr_hash_set(dispatch, "sendfile", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_sendfile, APL_REQ_FUNTYPE_LUACFUN, p));
     apr_hash_set(dispatch, "dbacquire", APR_HASH_KEY_STRING,
                  makefun(&lua_db_acquire, APL_REQ_FUNTYPE_LUACFUN, p));
-
-
+    apr_hash_set(dispatch, "stat", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_stat, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "regex", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_regex, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "sleep", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_sleep, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "base64_encode", APR_HASH_KEY_STRING,
+                 makefun(&lua_apr_b64encode, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "base64_decode", APR_HASH_KEY_STRING,
+                 makefun(&lua_apr_b64decode, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "md5", APR_HASH_KEY_STRING,
+                 makefun(&lua_apr_md5, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "sha1", APR_HASH_KEY_STRING,
+                 makefun(&lua_apr_sha1, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "escape", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_escape, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "unescape", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_unescape, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "banner", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_banner, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "port", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_port, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "mpm_query", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_mpm_query, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "expr", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_expr, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "scoreboard_process", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_scoreboard_process, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "scoreboard_worker", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_scoreboard_worker, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "started", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_restarted, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "clock", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_clock, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "requestbody", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_requestbody, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "add_input_filter", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_add_input_filter, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "module_info", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_module_info, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "loaded_modules", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_loaded_modules, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "runtime_dir_relative", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_runtime_dir_relative, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "server_info", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_server_info, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "set_document_root", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_set_document_root, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "set_context_info", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_set_context_info, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "os_escape_path", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_os_escape_path, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "escape_logitem", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_escape_logitem, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "strcmp_match", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_strcmp_match, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "set_keepalive", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_set_keepalive, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "make_etag", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_make_etag, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "send_interim_response", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_send_interim_response, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "custom_response", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_custom_response, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "exists_config_define", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_exists_config_define, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "state_query", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_state_query, APL_REQ_FUNTYPE_LUACFUN, p));
+    apr_hash_set(dispatch, "get_server_name_for_url", APR_HASH_KEY_STRING,
+                 makefun(&lua_ap_get_server_name_for_url, APL_REQ_FUNTYPE_LUACFUN, p));
+    
     lua_pushlightuserdata(L, dispatch);
     lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Request.dispatch");
 

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.c
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.c?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.c (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.c Fri Jun  7 11:51:28 2013
@@ -23,6 +23,15 @@
 
 APLOG_USE_MODULE(lua);
 
+#if APR_HAS_THREADS
+    apr_thread_mutex_t *ap_lua_mutex;
+    
+void ap_lua_init_mutex(apr_pool_t *pool, server_rec *s) 
+{
+    apr_thread_mutex_create(&ap_lua_mutex, APR_THREAD_MUTEX_DEFAULT, pool);
+}
+#endif
+
 /* forward dec'l from this file */
 
 #if 0
@@ -127,7 +136,7 @@ AP_LUA_DECLARE(void) ap_lua_load_apache2
     makeintegerfield(L, AUTHZ_NEUTRAL);
     makeintegerfield(L, AUTHZ_GENERAL_ERROR);
     makeintegerfield(L, AUTHZ_DENIED_NO_USER);
-
+    
     /*
        makeintegerfield(L, HTTP_CONTINUE);
        makeintegerfield(L, HTTP_SWITCHING_PROTOCOLS);
@@ -201,6 +210,16 @@ static apr_status_t cleanup_lua(void *l)
     return APR_SUCCESS;
 }
 
+static apr_status_t server_cleanup_lua(void *resource)
+{
+    ap_lua_server_spec* spec = (ap_lua_server_spec*) resource;
+    AP_DEBUG_ASSERT(spec != NULL);
+    if (spec->L != NULL) {
+        lua_close((lua_State *) spec->L);
+    }
+    return APR_SUCCESS;
+}
+
 /*
         munge_path(L, 
                    "path", 
@@ -333,33 +352,155 @@ static apr_status_t vm_construct(lua_Sta
     return APR_SUCCESS;
 }
 
+static ap_lua_vm_spec* copy_vm_spec(apr_pool_t* pool, ap_lua_vm_spec* spec) 
+{
+    ap_lua_vm_spec* copied_spec = apr_pcalloc(pool, sizeof(ap_lua_vm_spec));
+    copied_spec->bytecode_len = spec->bytecode_len;
+    copied_spec->bytecode = apr_pstrdup(pool, spec->bytecode);
+    copied_spec->cb = spec->cb;
+    copied_spec->cb_arg = NULL;
+    copied_spec->file = apr_pstrdup(pool, spec->file);
+    copied_spec->package_cpaths = apr_array_copy(pool, spec->package_cpaths);
+    copied_spec->package_paths = apr_array_copy(pool, spec->package_paths);
+    copied_spec->pool = pool;
+    copied_spec->scope = AP_LUA_SCOPE_SERVER;
+    copied_spec->codecache = spec->codecache;
+    return copied_spec;
+}
+
+static apr_status_t server_vm_construct(lua_State **resource, void *params, apr_pool_t *pool)
+{
+    lua_State* L;
+    ap_lua_server_spec* spec = apr_pcalloc(pool, sizeof(ap_lua_server_spec));
+    *resource = NULL;
+    if (vm_construct(&L, params, pool) == APR_SUCCESS) {
+        spec->finfo = apr_pcalloc(pool, sizeof(ap_lua_finfo));
+        if (L != NULL) {
+            spec->L = L;
+            *resource = (void*) spec;
+            lua_pushlightuserdata(L, spec);
+            lua_setfield(L, LUA_REGISTRYINDEX, "Apache2.Lua.server_spec");
+            return APR_SUCCESS;
+        }
+    }
+    return APR_EGENERAL;
+}
+
 /**
  * Function used to create a lua_State instance bound into the web
  * server in the appropriate scope.
  */
 AP_LUA_DECLARE(lua_State*)ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
-                                               ap_lua_vm_spec *spec)
+                                               ap_lua_vm_spec *spec, request_rec* r)
 {
     lua_State *L = NULL;
-
-    if (apr_pool_userdata_get((void **)&L, spec->file,
-                              lifecycle_pool) == APR_SUCCESS) {
-      
-      if(L==NULL) {
+    ap_lua_finfo *cache_info = NULL;
+    int tryCache = 0;
+    
+    if (spec->scope == AP_LUA_SCOPE_SERVER) {
+        char *hash;
+        apr_reslist_t* reslist = NULL;
+        ap_lua_server_spec* sspec = NULL;
+        hash = apr_psprintf(r->pool, "reslist:%s", spec->file);
+#if APR_HAS_THREADS
+        apr_thread_mutex_lock(ap_lua_mutex);
+#endif
+        if (apr_pool_userdata_get((void **)&reslist, hash,
+                                  r->server->process->pool) == APR_SUCCESS) {
+            if (reslist != NULL) {
+                if (apr_reslist_acquire(reslist, (void**) &sspec) == APR_SUCCESS) {
+                    L = sspec->L;
+                    cache_info = sspec->finfo;
+                }
+            }
+        }
+        if (L == NULL) {
+            ap_lua_vm_spec* server_spec = copy_vm_spec(r->server->process->pool, spec);
+            if (
+                    apr_reslist_create(&reslist, spec->vm_min, spec->vm_max, spec->vm_max, 0, 
+                                (apr_reslist_constructor) server_vm_construct, 
+                                (apr_reslist_destructor) server_cleanup_lua, 
+                                server_spec, r->server->process->pool)
+                    == APR_SUCCESS && reslist != NULL) {
+                apr_pool_userdata_set(reslist, hash, NULL,
+                                            r->server->process->pool);
+                if (apr_reslist_acquire(reslist, (void**) &sspec) == APR_SUCCESS) {
+                    L = sspec->L;
+                    cache_info = sspec->finfo;
+                }
+                else {
+                    return NULL;
+                }
+            }
+        }
+#if APR_HAS_THREADS
+        apr_thread_mutex_unlock(ap_lua_mutex);
+#endif
+    }
+    else {
+        if (apr_pool_userdata_get((void **)&L, spec->file,
+                              lifecycle_pool) != APR_SUCCESS) {
+            L = NULL;
+        }
+    }
+    if (L == NULL) {
         ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(01483)
-                      "creating lua_State with file %s", spec->file);
+                        "creating lua_State with file %s", spec->file);
         /* not available, so create */
-        
-        if(!vm_construct(&L, spec, lifecycle_pool)) {
-          AP_DEBUG_ASSERT(L != NULL);
-          apr_pool_userdata_set(L, 
-                                spec->file, 
-                                cleanup_lua,
-                                lifecycle_pool);
+
+        if (!vm_construct(&L, spec, lifecycle_pool)) {
+            AP_DEBUG_ASSERT(L != NULL);
+            apr_pool_userdata_set(L, spec->file, cleanup_lua, lifecycle_pool);
+        }
+    }
+
+    if (spec->codecache == AP_LUA_CACHE_FOREVER || (spec->bytecode && spec->bytecode_len > 0)) {
+        tryCache = 1;
+    }
+    else {
+        char* mkey;
+        if (spec->scope != AP_LUA_SCOPE_SERVER) {
+            mkey = apr_psprintf(r->pool, "ap_lua_modified:%s", spec->file);
+            apr_pool_userdata_get((void **)&cache_info, mkey, lifecycle_pool);
+            if (cache_info == NULL) {
+                cache_info = apr_pcalloc(lifecycle_pool, sizeof(ap_lua_finfo));
+                apr_pool_userdata_set((void*) cache_info, mkey, NULL, lifecycle_pool);
+            }
+        }
+        if (spec->codecache == AP_LUA_CACHE_STAT) {
+            apr_finfo_t lua_finfo;
+            apr_stat(&lua_finfo, spec->file, APR_FINFO_MTIME|APR_FINFO_SIZE, lifecycle_pool);
+
+            /* On first visit, modified will be zero, but that's fine - The file is 
+            loaded in the vm_construct function.
+            */
+            if ((cache_info->modified == lua_finfo.mtime && cache_info->size == lua_finfo.size)
+                    || cache_info->modified == 0) {
+                tryCache = 1;
+            }
+            cache_info->modified = lua_finfo.mtime;
+            cache_info->size = lua_finfo.size;
+        }
+        else if (spec->codecache == AP_LUA_CACHE_NEVER) {
+            if (cache_info->runs == 0)
+                tryCache = 1;
         }
-      }
+        cache_info->runs++;
+    }
+    if (tryCache == 0 && spec->scope != AP_LUA_SCOPE_ONCE) {
+        int rc;
+        ap_log_perror(APLOG_MARK, APLOG_DEBUG, 0, lifecycle_pool, APLOGNO(02332)
+            "(re)loading lua file %s", spec->file);
+        rc = luaL_loadfile(L, spec->file);
+        if (rc != 0) {
+            ap_log_perror(APLOG_MARK, APLOG_ERR, 0, lifecycle_pool, APLOGNO(02333)
+                          "Error loading %s: %s", spec->file,
+                          rc == LUA_ERRMEM ? "memory allocation error"
+                                           : lua_tostring(L, 0));
+            return 0;
+        }
+        lua_pcall(L, 0, LUA_MULTRET, 0);
     }
-        /*}*/
 
     return L;
 }

Modified: httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.h
URL: http://svn.apache.org/viewvc/httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.h?rev=1490599&r1=1490598&r2=1490599&view=diff
==============================================================================
--- httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.h (original)
+++ httpd/httpd/branches/2.4.x/modules/lua/lua_vmprep.h Fri Jun  7 11:51:28 2013
@@ -29,6 +29,7 @@
 #include "apr_file_info.h"
 #include "apr_time.h"
 #include "apr_pools.h"
+#include "apr_reslist.h"
 
 
 #ifndef VMPREP_H
@@ -39,11 +40,18 @@
 #define AP_LUA_SCOPE_REQUEST       2
 #define AP_LUA_SCOPE_CONN          3
 #define AP_LUA_SCOPE_THREAD        4
+#define AP_LUA_SCOPE_SERVER        5
 
+#define AP_LUA_CACHE_UNSET         0
+#define AP_LUA_CACHE_NEVER         1
+#define AP_LUA_CACHE_STAT          2
+#define AP_LUA_CACHE_FOREVER       3
+
+#define AP_LUA_FILTER_INPUT        1
+#define AP_LUA_FILTER_OUTPUT       2
 
 typedef void (*ap_lua_state_open_callback) (lua_State *L, apr_pool_t *p,
                                              void *ctx);
-
 /**
  * Specification for a lua virtual machine
  */
@@ -56,8 +64,10 @@ typedef struct
     /* name of base file to load in the vm */
     const char *file;
 
-    /* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_THREAD */
+    /* APL_SCOPE_ONCE | APL_SCOPE_REQUEST | APL_SCOPE_CONN | APL_SCOPE_THREAD | APL_SCOPE_SERVER */
     int scope;
+    unsigned int vm_min;
+    unsigned int vm_max;
 
     ap_lua_state_open_callback cb;
     void* cb_arg;
@@ -71,6 +81,8 @@ typedef struct
      */
     const char *bytecode;
     apr_size_t bytecode_len;
+    
+    int codecache;
 } ap_lua_vm_spec;
 
 typedef struct
@@ -81,8 +93,28 @@ typedef struct
     ap_regex_t *uri_pattern;
     const char *bytecode;
     apr_size_t bytecode_len;
+    int codecache;
 } ap_lua_mapped_handler_spec;
 
+typedef struct
+{
+    const char *function_name;
+    const char *file_name;
+    const char* filter_name;
+    int         direction; /* AP_LUA_FILTER_INPUT | AP_LUA_FILTER_OUTPUT */
+} ap_lua_filter_handler_spec;
+
+typedef struct {
+    apr_size_t runs;
+    apr_time_t modified;
+    apr_size_t size;
+} ap_lua_finfo;
+
+typedef struct {
+    lua_State* L;
+    ap_lua_finfo* finfo;
+} ap_lua_server_spec;
+
 /* remove and make static once out of mod_wombat.c */
 AP_LUA_DECLARE(void) ap_lua_openlibs(lua_State *L);
 
@@ -107,8 +139,15 @@ AP_LUA_DECLARE(void) ap_lua_load_apache2
  * @ctx a baton passed to cb
  */
 AP_LUA_DECLARE(lua_State*) ap_lua_get_lua_state(apr_pool_t *lifecycle_pool,
-                                                ap_lua_vm_spec *spec);
-
+                                                ap_lua_vm_spec *spec, request_rec* r);
 
+#if APR_HAS_THREADS || defined(DOXYGEN)
+/*
+ * Initialize mod_lua mutex.
+ * @pool pool for mutex
+ * @s server_rec for logging
+ */
+void ap_lua_init_mutex(apr_pool_t *pool, server_rec *s);
+#endif
 
 #endif



Mime
View raw message