diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-07-13 17:10:56 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-07-13 17:10:56 +0000 |
commit | 268dea84ecccf5c23b7b95f303c29d02bbc4d4b6 (patch) | |
tree | a10b65cb7ffda97d2ca25344848cb6952b2b6ad7 /package/uhttpd/src/uhttpd-lua.c | |
parent | 89511a81d0c9f6a22db3ca0c4a9975bc98228e01 (diff) | |
download | master-187ad058-268dea84ecccf5c23b7b95f303c29d02bbc4d4b6.tar.gz master-187ad058-268dea84ecccf5c23b7b95f303c29d02bbc4d4b6.tar.bz2 master-187ad058-268dea84ecccf5c23b7b95f303c29d02bbc4d4b6.zip |
[package] uhttpd: various changes
- remove unused variables
- simply ignore command line args which belong to not enabled features
- resolve peer address at accept() time, should solve (#11850)
- remove floating point operations where possible
git-svn-id: svn://svn.openwrt.org/openwrt/trunk@32704 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'package/uhttpd/src/uhttpd-lua.c')
-rw-r--r-- | package/uhttpd/src/uhttpd-lua.c | 35 |
1 files changed, 9 insertions, 26 deletions
diff --git a/package/uhttpd/src/uhttpd-lua.c b/package/uhttpd/src/uhttpd-lua.c index 94626bb56b..e113937399 100644 --- a/package/uhttpd/src/uhttpd-lua.c +++ b/package/uhttpd/src/uhttpd-lua.c @@ -66,7 +66,7 @@ static int uh_lua_recv(lua_State *L) return 1; } -static int uh_lua_send_common(lua_State *L, int chunked) +static int uh_lua_send_common(lua_State *L, bool chunked) { size_t length; @@ -112,12 +112,12 @@ out: static int uh_lua_send(lua_State *L) { - return uh_lua_send_common(L, 0); + return uh_lua_send_common(L, false); } static int uh_lua_sendc(lua_State *L) { - return uh_lua_send_common(L, 1); + return uh_lua_send_common(L, true); } static int uh_lua_str2str(lua_State *L, int (*xlate_func) (char *, int, const char *, int)) @@ -414,21 +414,7 @@ bool uh_lua_request(struct client *cl, lua_State *L) lua_newtable(L); /* request method */ - switch(req->method) - { - case UH_HTTP_MSG_GET: - lua_pushstring(L, "GET"); - break; - - case UH_HTTP_MSG_HEAD: - lua_pushstring(L, "HEAD"); - break; - - case UH_HTTP_MSG_POST: - lua_pushstring(L, "POST"); - break; - } - + lua_pushstring(L, http_methods[req->method]); lua_setfield(L, -2, "REQUEST_METHOD"); /* request url */ @@ -462,14 +448,10 @@ bool uh_lua_request(struct client *cl, lua_State *L) } /* http protcol version */ - lua_pushnumber(L, floor(req->version * 10) / 10); + lua_pushnumber(L, 0.9 + (req->version / 10.0)); lua_setfield(L, -2, "HTTP_VERSION"); - if (req->version > 1.0) - lua_pushstring(L, "HTTP/1.1"); - else - lua_pushstring(L, "HTTP/1.0"); - + lua_pushstring(L, http_versions[req->version]); lua_setfield(L, -2, "SERVER_PROTOCOL"); @@ -529,12 +511,13 @@ bool uh_lua_request(struct client *cl, lua_State *L) if (! err_str) err_str = "Unknown error"; - printf("HTTP/%.1f 500 Internal Server Error\r\n" + printf("%s 500 Internal Server Error\r\n" "Connection: close\r\n" "Content-Type: text/plain\r\n" "Content-Length: %i\r\n\r\n" "Lua raised a runtime error:\n %s\n", - req->version, 31 + strlen(err_str), err_str); + http_versions[req->version], + 31 + strlen(err_str), err_str); break; |