mirror of
git://projects.qi-hardware.com/openwrt-xburst.git
synced 2024-12-24 19:32:03 +02:00
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@31571 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
parent
8329c6da4f
commit
37f687e099
@ -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();
|
lua_State *L = lua_open();
|
||||||
const char *err_str = NULL;
|
const char *err_str = NULL;
|
||||||
@ -164,12 +164,20 @@ lua_State * uh_lua_init(const char *handler)
|
|||||||
lua_pushcfunction(L, uh_lua_urlencode);
|
lua_pushcfunction(L, uh_lua_urlencode);
|
||||||
lua_setfield(L, -2, "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 = { ... } */
|
/* _G.uhttpd = { ... } */
|
||||||
lua_setfield(L, LUA_GLOBALSINDEX, "uhttpd");
|
lua_setfield(L, LUA_GLOBALSINDEX, "uhttpd");
|
||||||
|
|
||||||
|
|
||||||
/* load Lua handler */
|
/* load Lua handler */
|
||||||
switch( luaL_loadfile(L, handler) )
|
switch( luaL_loadfile(L, conf->lua_handler) )
|
||||||
{
|
{
|
||||||
case LUA_ERRSYNTAX:
|
case LUA_ERRSYNTAX:
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
#define UH_LUA_ERR_PARAM -3
|
#define UH_LUA_ERR_PARAM -3
|
||||||
|
|
||||||
|
|
||||||
lua_State * uh_lua_init();
|
lua_State * uh_lua_init(const struct config *conf);
|
||||||
|
|
||||||
void uh_lua_request(
|
void uh_lua_request(
|
||||||
struct client *cl, struct http_request *req, lua_State *L
|
struct client *cl, struct http_request *req, lua_State *L
|
||||||
|
@ -1089,7 +1089,7 @@ int main (int argc, char **argv)
|
|||||||
if( ! conf.lua_prefix )
|
if( ! conf.lua_prefix )
|
||||||
conf.lua_prefix = "/lua";
|
conf.lua_prefix = "/lua";
|
||||||
|
|
||||||
conf.lua_state = conf.lua_init(conf.lua_handler);
|
conf.lua_state = conf.lua_init(&conf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -83,7 +83,7 @@ struct config {
|
|||||||
char *lua_prefix;
|
char *lua_prefix;
|
||||||
char *lua_handler;
|
char *lua_handler;
|
||||||
lua_State *lua_state;
|
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_close) (lua_State *L);
|
||||||
void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
|
void (*lua_request) (struct client *cl, struct http_request *req, lua_State *L);
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user