diff options
Diffstat (limited to 'lib/LuaHttp.cc')
-rw-r--r-- | lib/LuaHttp.cc | 202 |
1 files changed, 103 insertions, 99 deletions
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index c508474..81e263a 100644 --- a/lib/LuaHttp.cc +++ b/lib/LuaHttp.cc @@ -17,7 +17,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -/* $Id: LuaHttp.cc,v 1.18 2007-07-12 10:46:34 pixel Exp $ */ +/* $Id: LuaHttp.cc,v 1.19 2007-07-12 11:32:00 pixel Exp $ */ #include "md5.h" #include "Domain.h" @@ -26,7 +26,16 @@ #include "LuaTask.h" #include "Base64.h" -class LuaDomain; +class LuaDomain : public Domain { + public: + LuaDomain(Lua * _L, String r); + virtual ~LuaDomain(); + virtual void Do(const HttpRequest & req, HttpResponse * res) throw (GeneralException); + private: + Lua * L; + static int max_id; + int id; +}; class LuaLuaDomain : public LuaObject { public: @@ -280,113 +289,108 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) return r; } -class LuaDomain : public Domain { - public: - LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) { - id = max_id++; +LuaDomain::LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) { + id = max_id++; - L->push(DOMAIN_REGISTRY); - L->gettable(LUA_REGISTRYINDEX); - L->push((lua_Number) id); - L->copy(2); - L->settable(); - L->pop(); - } - virtual ~LuaDomain() { - L->push(DOMAIN_REGISTRY); - L->gettable(LUA_REGISTRYINDEX); - L->push((lua_Number) id); - L->push(); - L->settable(); - L->pop(); - } - virtual void Do(const HttpRequest & req, HttpResponse * res) throw (GeneralException) { - int i; - - Lua * oldL = L; - Lua * L = oldL->thread(true); - oldL->pop(); - - L->push(DOMAIN_REGISTRY); - L->gettable(LUA_REGISTRYINDEX); - L->push((lua_Number) id); - L->gettable(); - L->remove(); + L->push(DOMAIN_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->copy(2); + L->settable(); + L->pop(); +} + +LuaDomain::~LuaDomain() { + L->push(DOMAIN_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->push(); + L->settable(); + L->pop(); +} + +void LuaDomain::Do(const HttpRequest & req, HttpResponse * res) throw (GeneralException) { + int i; + + Lua * oldL = L; + Lua * L = oldL->thread(true); + oldL->pop(); + + L->push(DOMAIN_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->gettable(); + L->remove(); + + L->newtable(); + + L->push("vars"); + L->newtable(); + for (i = 0; i < req.vars->GetNb(); i++) { + char * v = (*(req.vars))[i].strdup(), * p; - L->newtable(); - - L->push("vars"); - L->newtable(); - for (i = 0; i < req.vars->GetNb(); i++) { - char * v = (*(req.vars))[i].strdup(), * p; - - p = strchr(v, '='); - *p = 0; - p++; - - L->push(v); - L->push(p); - L->settable(); - - free(v); - } - L->settable(); + p = strchr(v, '='); + *p = 0; + p++; - L->push("headers"); - L->newtable(); - for (i = 0; i < req.headers->GetNb(); i++) { - char * v = (*(req.headers))[i].strdup(), * p; - - p = strchr(v, '='); - *p = 0; - p++; - - L->push(v); - L->push(p); - L->settable(); - - free(v); - } + L->push(v); + L->push(p); L->settable(); - L->push("uri"); - L->push(req.uri); - L->settable(); + free(v); + } + L->settable(); + + L->push("headers"); + L->newtable(); + for (i = 0; i < req.headers->GetNb(); i++) { + char * v = (*(req.headers))[i].strdup(), * p; - L->push("login"); - L->push(req.login); - L->settable(); + p = strchr(v, '='); + *p = 0; + p++; - L->push("password"); - L->push(req.password); + L->push(v); + L->push(p); L->settable(); - - L->push("lip"); - L->push((lua_Number) req.lip); - L->settable(); - L->push("dip"); - L->push((lua_Number) req.dip); - L->settable(); - - L->push("lport"); - L->push((lua_Number) req.lport); - L->settable(); - - L->push("dport"); - L->push((lua_Number) req.dport); - L->settable(); - - LuaHttpResponse r(res); - r.push(L); - - res->builder = new LuaTask(L, 2); + free(v); } - private: - Lua * L; - static int max_id; - int id; -}; + L->settable(); + + L->push("uri"); + L->push(req.uri); + L->settable(); + + L->push("login"); + L->push(req.login); + L->settable(); + + L->push("password"); + L->push(req.password); + L->settable(); + + L->push("lip"); + L->push((lua_Number) req.lip); + L->settable(); + + L->push("dip"); + L->push((lua_Number) req.dip); + L->settable(); + + L->push("lport"); + L->push((lua_Number) req.lport); + L->settable(); + + L->push("dport"); + L->push((lua_Number) req.dport); + L->settable(); + + LuaHttpResponse r(res); + r.push(L); + + res->builder = new LuaTask(L, 2); +} int LuaDomain::max_id = 1; |