From: Jim Jagielski Date: Wed, 25 Jul 2012 11:50:06 +0000 (+0000) Subject: Merge r1352047, r1361298 from trunk: X-Git-Tag: 2.4.3~178 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f9e205b8578f4af9a6f55e57a0a0479cc5561453;p=apache Merge r1352047, r1361298 from trunk: 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 --- diff --git a/CHANGES b/CHANGES index 11a91d1667..93878c538c 100644 --- 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 ] + *) 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 21db41bf99..ca8ce7330e 100644 --- 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: diff --git a/modules/lua/lua_request.c b/modules/lua/lua_request.c index 91bd3b75e6..a21f5a6032 100644 --- a/modules/lua/lua_request.c +++ b/modules/lua/lua_request.c @@ -164,6 +164,34 @@ static int req_parseargs(lua_State *L) return 2; /* [table, table>] */ } +/* 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, table>] */ +} + /* 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, diff --git a/modules/lua/mod_lua.h b/modules/lua/mod_lua.h index 5394f7a485..85499ee2f6 100644 --- a/modules/lua/mod_lua.h +++ b/modules/lua/mod_lua.h @@ -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)