]> granicus.if.org Git - apache/commitdiff
Merge r1352047, r1361298 from trunk:
authorJim Jagielski <jim@apache.org>
Wed, 25 Jul 2012 11:50:06 +0000 (11:50 +0000)
committerJim Jagielski <jim@apache.org>
Wed, 25 Jul 2012 11:50:06 +0000 (11:50 +0000)
Add the missing parsebody function to mod_lua, for parsing POST data.
PR 53064.

- Define LUA_COMPAT_ALL so mod_lua will be compatible with Lua 5.2
- Add an optional integer argument for parsebody, specifying the maximum size of POST that will be accepted.
Submitted by: humbedooh
Reviewed/backported by: jim

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1365539 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
modules/lua/lua_request.c
modules/lua/mod_lua.h

diff --git a/CHANGES b/CHANGES
index 11a91d16679d8abd3d50803ca4eb79b226b38efd..93878c538cb16ec2f01eeba309c338c5a78bd694 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -7,6 +7,9 @@ Changes with Apache 2.4.3
      possible XSS for a site where untrusted users can upload files to
      a location with MultiViews enabled. [Niels Heinen <heinenn google.com>]
 
+  *) mod_lua: Add the parsebody function for parsing POST data. PR 53064.
+     [Daniel Gruno]
+
   *) apxs: Use LDFLAGS from config_vars.mk in addition to CFLAGS and CPPFLAGS.
      [Stefan Fritsch]
 
diff --git a/STATUS b/STATUS
index 21db41bf99321110768fc2238901c1d11f2353e6..ca8ce7330e85f0263ce016cd4930a1f447040808 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -88,14 +88,6 @@ RELEASE SHOWSTOPPERS:
 PATCHES ACCEPTED TO BACKPORT FROM TRUNK:
   [ start all new proposals below, under PATCHES PROPOSED. ]
 
-   * mod_lua: - Add a parsebody function for retrieving POST data. PR: 53064
-              - Make mod_lua compatible with Lua 5.2
-     Trunk patch:
-       http://svn.apache.org/viewvc?view=revision&revision=1352047 and
-       http://svn.apache.org/viewvc?view=revision&revision=1361298
-     2.4.x patch:
-       http://www.humbedooh.com/mods/mod_lua.patch (+CHANGES)
-     +1: humbedooh, rjung, jim
 
 
 PATCHES PROPOSED TO BACKPORT FROM TRUNK:
index 91bd3b75e600e4ea2bc855e8d8fee6561377ba4e..a21f5a60320ccc70d4f3bb8e25e5c0bae085a07c 100644 (file)
@@ -164,6 +164,34 @@ static int req_parseargs(lua_State *L)
     return 2;                   /* [table<string, string>, table<string, array<string>>] */
 }
 
+/* r:parsebody() returning a lua table */
+static int req_parsebody(lua_State *L)
+{
+    apr_array_header_t          *pairs;
+    apr_off_t len;
+    int res;
+    apr_size_t size;
+    apr_size_t max_post_size;
+    char *buffer;
+    request_rec *r = ap_lua_check_request_rec(L, 1);
+    max_post_size = (apr_size_t) luaL_optint(L, 2, MAX_STRING_LEN);
+    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);
+        }
+    }
+    return 2;                   /* [table<string, string>, table<string, array<string>>] */
+}
+
 /* wrap ap_rputs as r:puts(String) */
 static int req_puts(lua_State *L)
 {
@@ -610,6 +638,8 @@ AP_LUA_DECLARE(void) ap_lua_load_request_lmodule(lua_State *L, apr_pool_t *p)
                  makefun(&req_document_root, APL_REQ_FUNTYPE_STRING, p));
     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,
+                 makefun(&req_parsebody, APL_REQ_FUNTYPE_LUACFUN, p));
     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,
index 5394f7a48501d621e721d78134a3c3d4f7c3aee4..85499ee2f657879172ac7f494d862f9175d0d10f 100644 (file)
@@ -44,6 +44,8 @@
 #include "lauxlib.h"
 #include "lualib.h"
 
+/* Allow for Lua 5.2 backwards compatibility */
+#define LUA_COMPAT_ALL
 #if LUA_VERSION_NUM > 501
 /* Load mode for lua_load() */
 #define lua_load(a,b,c,d) lua_load(a,b,c,d,NULL)