You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by hu...@apache.org on 2014/02/05 13:04:15 UTC
svn commit: r1564727 - /httpd/httpd/trunk/modules/lua/lua_request.c
Author: humbedooh
Date: Wed Feb 5 12:04:14 2014
New Revision: 1564727
URL: http://svn.apache.org/r1564727
Log:
Fix support for uploading files by using pushlstring instead of pushstring when pushing binary data.
Modified:
httpd/httpd/trunk/modules/lua/lua_request.c
Modified: httpd/httpd/trunk/modules/lua/lua_request.c
URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/lua/lua_request.c?rev=1564727&r1=1564726&r2=1564727&view=diff
==============================================================================
--- httpd/httpd/trunk/modules/lua/lua_request.c (original)
+++ httpd/httpd/trunk/modules/lua/lua_request.c Wed Feb 5 12:04:14 2014
@@ -172,6 +172,55 @@ static int req_aprtable2luatable_cb(void
return 1;
}
+/* helper callback for req_parseargs */
+static int req_aprtable2luatable_cb_len(void *l, const char *key,
+ const char *value, size_t len)
+{
+ int t;
+ lua_State *L = (lua_State *) l; /* [table<s,t>, table<s,s>] */
+ /* rstack_dump(L, RRR, "start of cb"); */
+ /* L is [table<s,t>, table<s,s>] */
+ /* build complex */
+
+ lua_getfield(L, -1, key); /* [VALUE, table<s,t>, table<s,s>] */
+ /* rstack_dump(L, RRR, "after getfield"); */
+ 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_pushlstring(L, value, len); /* [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:{
+ /* [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_pushlstring(L, value, len); /* [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_pushlstring(L, value, len); /* [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;
+}
+
/*
=======================================================================================================================
@@ -313,7 +362,7 @@ static int req_parsebody(lua_State *L)
"Content-Disposition: form-data; name=\"%255[^\"]\"; filename=\"%255[^\"]\"",
key, filename);
if (strlen(key)) {
- req_aprtable2luatable_cb(L, key, buffer);
+ req_aprtable2luatable_cb_len(L, key, buffer, vlen);
}
}
}