diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2012-05-03 17:19:20 +0000 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2012-05-03 17:19:20 +0000 |
commit | 54b34ccbc5a41e7bdbf29271dcc380715418f8c1 (patch) | |
tree | c764006195d2181e43fd9461543327e70523740e /package | |
parent | bcd8d530d10127ce0be796fe7ef42944c47d4485 (diff) | |
download | upstream-54b34ccbc5a41e7bdbf29271dcc380715418f8c1.tar.gz upstream-54b34ccbc5a41e7bdbf29271dcc380715418f8c1.tar.bz2 upstream-54b34ccbc5a41e7bdbf29271dcc380715418f8c1.zip |
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>
SVN-Revision: 31571
Diffstat (limited to 'package')
-rw-r--r-- | package/uhttpd/src/uhttpd-lua.c | 12 | ||||
-rw-r--r-- | package/uhttpd/src/uhttpd-lua.h | 2 | ||||
-rw-r--r-- | package/uhttpd/src/uhttpd.c | 2 | ||||
-rw-r--r-- | package/uhttpd/src/uhttpd.h | 2 |
4 files changed, 13 insertions, 5 deletions
diff --git a/package/uhttpd/src/uhttpd-lua.c b/package/uhttpd/src/uhttpd-lua.c index a140dc2f2d..83b0b0a26b 100644 --- a/package/uhttpd/src/uhttpd-lua.c +++ b/package/uhttpd/src/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, diff --git a/package/uhttpd/src/uhttpd-lua.h b/package/uhttpd/src/uhttpd-lua.h index 7304665000..2d2f73c1c2 100644 --- a/package/uhttpd/src/uhttpd-lua.h +++ b/package/uhttpd/src/uhttpd-lua.h @@ -32,7 +32,7 @@ #define UH_LUA_ERR_PARAM -3 -lua_State * uh_lua_init(); +lua_State * uh_lua_init(const struct config *conf); void uh_lua_request( struct client *cl, struct http_request *req, lua_State *L diff --git a/package/uhttpd/src/uhttpd.c b/package/uhttpd/src/uhttpd.c index 5d66e23a50..78e0b5d952 100644 --- a/package/uhttpd/src/uhttpd.c +++ b/package/uhttpd/src/uhttpd.c @@ -1089,7 +1089,7 @@ int main (int argc, char **argv) if( ! conf.lua_prefix ) conf.lua_prefix = "/lua"; - conf.lua_state = conf.lua_init(conf.lua_handler); + conf.lua_state = conf.lua_init(&conf); } } #endif diff --git a/package/uhttpd/src/uhttpd.h b/package/uhttpd/src/uhttpd.h index 993bf93af1..c03d1ae651 100644 --- a/package/uhttpd/src/uhttpd.h +++ b/package/uhttpd/src/uhttpd.h @@ -83,7 +83,7 @@ struct config { char *lua_prefix; char *lua_handler; lua_State *lua_state; - lua_State * (*lua_init) (const char *handler); + lua_State * (*lua_init) (const struct config *conf); void (*lua_close) (lua_State *L); void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L); #endif |