summaryrefslogtreecommitdiff
path: root/uhttpd-lua.c
diff options
context:
space:
mode:
authorjow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-05-03 17:19:20 +0000
committerjow <jow@3c298f89-4303-0410-b956-a3cf2f4a3e73>2012-05-03 17:19:20 +0000
commit4965d6c03d5fd46a2498726079aa1880c9818770 (patch)
tree76ca67e830a682292bd5b52a2dbb0d7b0dcbb007 /uhttpd-lua.c
parentf978449dac910d3379e44ea438198c8f29df8008 (diff)
downloaduhttpd-4965d6c03d5fd46a2498726079aa1880c9818770.tar.gz
uhttpd: added uhttpd.docroot
Passes the document-root to the Lua handler by placing it in uhttpd.docroot. It could alternatively be placed in env.DOCUMENT_ROOT which would more closely resemble the CGI protocol; but would mean that it is not available at the time when the handler-chunk is loaded but rather not until the handler is called, without any code savings. Signed-off-by: David Favro <openwrt@meta-dynamic.com> git-svn-id: svn://svn.openwrt.org/openwrt/trunk/package/uhttpd/src@31571 3c298f89-4303-0410-b956-a3cf2f4a3e73
Diffstat (limited to 'uhttpd-lua.c')
-rw-r--r--uhttpd-lua.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/uhttpd-lua.c b/uhttpd-lua.c
index a140dc2..83b0b0a 100644
--- a/uhttpd-lua.c
+++ b/uhttpd-lua.c
@@ -137,7 +137,7 @@ static int uh_lua_urlencode(lua_State *L)
}
-lua_State * uh_lua_init(const char *handler)
+lua_State * uh_lua_init(const struct config *conf)
{
lua_State *L = lua_open();
const char *err_str = NULL;
@@ -164,12 +164,20 @@ lua_State * uh_lua_init(const char *handler)
lua_pushcfunction(L, uh_lua_urlencode);
lua_setfield(L, -2, "urlencode");
+ /* Pass the document-root to the Lua handler by placing it in
+ ** uhttpd.docroot. It could alternatively be placed in env.DOCUMENT_ROOT
+ ** which would more closely resemble the CGI protocol; but would mean that
+ ** it is not available at the time when the handler-chunk is loaded but
+ ** rather not until the handler is called, without any code savings. */
+ lua_pushstring(L, conf->docroot);
+ lua_setfield(L, -2, "docroot");
+
/* _G.uhttpd = { ... } */
lua_setfield(L, LUA_GLOBALSINDEX, "uhttpd");
/* load Lua handler */
- switch( luaL_loadfile(L, handler) )
+ switch( luaL_loadfile(L, conf->lua_handler) )
{
case LUA_ERRSYNTAX:
fprintf(stderr,