diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LuaHttp.cc | 248 |
1 files changed, 146 insertions, 102 deletions
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc index 422c0b3..c508474 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.17 2007-06-19 13:39:14 pixel Exp $ */ +/* $Id: LuaHttp.cc,v 1.18 2007-07-12 10:46:34 pixel Exp $ */ #include "md5.h" #include "Domain.h" @@ -26,16 +26,7 @@ #include "LuaTask.h" #include "Base64.h" -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 LuaDomain; class LuaLuaDomain : public LuaObject { public: @@ -50,27 +41,36 @@ LuaLuaDomain::LuaLuaDomain(LuaDomain * _d) : d(_d) { } enum LuaDomain_methods_t { LUADOMAIN_ONTOP = 0, + LUADOMAIN_GETPATTERN, }; enum LuaDomain_functions_t { LUADOMAIN_NEWDOMAIN = 0, + LUADOMAIN_IDOMAIN, + LUADOMAIN_NDOMAIN, }; struct lua_functypes_t LuaDomain_methods[] = { - { LUADOMAIN_ONTOP, "OnTop", 0, 0, { } }, + { LUADOMAIN_ONTOP, "OnTop", 0, 0, { } }, + { LUADOMAIN_GETPATTERN, "GetPattern", 0, 0, { } }, { -1, 0, 0, 0, 0 }, }; struct lua_functypes_t LuaDomain_functions[] = { { LUADOMAIN_NEWDOMAIN, "Domain", 2, 2, { LUA_STRING, LUA_FUNCTION } }, + { LUADOMAIN_IDOMAIN, "iDomain", 0, 0, { } }, + { LUADOMAIN_NDOMAIN, "nDomain", 2, 2, { LUA_USERDATA, LUA_STRING | LUA_NIL } }, { -1, 0, 0, 0, 0 }, }; class sLua_LuaDomain : public Base { public: DECLARE_METHOD(LuaDomain, LUADOMAIN_ONTOP); + DECLARE_METHOD(LuaDomain, LUADOMAIN_GETPATTERN); DECLARE_FUNCTION(LuaDomain, LUADOMAIN_NEWDOMAIN); + DECLARE_FUNCTION(LuaDomain, LUADOMAIN_IDOMAIN); + DECLARE_FUNCTION(LuaDomain, LUADOMAIN_NDOMAIN); private: static int LuaDomain_proceed(Lua * L, int n, LuaDomain * obj, int caller); @@ -81,6 +81,7 @@ void LuaLuaDomain::pushmembers(Lua * L) { pushme(L, d, "LuaDomain"); PUSH_METHOD(LuaDomain, LUADOMAIN_ONTOP); + PUSH_METHOD(LuaDomain, LUADOMAIN_GETPATTERN); } void LuaLuaDomain::pushstatics(Lua * L) throw (GeneralException) { @@ -88,6 +89,8 @@ void LuaLuaDomain::pushstatics(Lua * L) throw (GeneralException) { CHECK_FUNCTIONS(LuaDomain); PUSH_FUNCTION(LuaDomain, LUADOMAIN_NEWDOMAIN); + PUSH_FUNCTION(LuaDomain, LUADOMAIN_IDOMAIN); + PUSH_FUNCTION(LuaDomain, LUADOMAIN_NDOMAIN); } #define DOMAIN_REGISTRY "DOMAINS_KEYS" @@ -277,108 +280,113 @@ int sLua_HttpResponse::HttpResponse_proceed_statics(Lua * L, int n, int caller) return r; } -LuaDomain::LuaDomain(Lua * _L, String r) : Domain(r), L(_L->Father()) { - id = max_id++; +class LuaDomain : public Domain { + public: + 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(); -} - -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; + 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(false); - oldL->pop(); + 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->push(DOMAIN_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->gettable(); + L->remove(); - p = strchr(v, '='); - *p = 0; - 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(); - L->push(v); - L->push(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->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("uri"); + L->push(req.uri); + L->settable(); - p = strchr(v, '='); - *p = 0; - p++; + L->push("login"); + L->push(req.login); + L->settable(); - L->push(v); - L->push(p); + 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(); - free(v); + LuaHttpResponse r(res); + r.push(L); + + res->builder = new LuaTask(L, 2); } - 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); -} + private: + Lua * L; + static int max_id; + int id; +}; int LuaDomain::max_id = 1; @@ -389,6 +397,10 @@ int sLua_LuaDomain::LuaDomain_proceed(Lua * L, int n, LuaDomain * obj, int calle case LUADOMAIN_ONTOP: obj->OnTop(); break; + case LUADOMAIN_GETPATTERN: + L->push(obj->GetPattern()); + r = 1; + break; } return r; @@ -396,6 +408,7 @@ int sLua_LuaDomain::LuaDomain_proceed(Lua * L, int n, LuaDomain * obj, int calle int sLua_LuaDomain::LuaDomain_proceed_statics(Lua * L, int n, int caller) { int r = 0; + Domain ** p; switch (caller) { case LUADOMAIN_NEWDOMAIN: @@ -405,6 +418,37 @@ int sLua_LuaDomain::LuaDomain_proceed_statics(Lua * L, int n, int caller) { r = 1; } break; + case LUADOMAIN_IDOMAIN: + L->getglobal("nDomain"); + p = (Domain **) L->newuser(sizeof(Domain *)); + *p = 0; + L->push(); + r = 3; + printm(M_INFO, "IDOMAIN called.\n"); + break; + case LUADOMAIN_NDOMAIN: + p = (Domain **) L->touserdata(1); + printm(M_INFO, "NDOMAIN called.\n"); + if (*p) { + printm(M_INFO, "Not first time.\n"); + *p = (*p)->Next(); + } else { + printm(M_INFO, "First time. p = %p\n", Domain::First()); + *p = Domain::First(); + printm(M_INFO, "First has pattern: "); + printm(M_BARE, Domain::First()->GetPattern()); + } + if (*p) { + printm(M_INFO, "Still has data.\n"); + printm(M_INFO, "Get pattern = "); + printm(M_BARE, (*p)->GetPattern()); + L->push((*p)->GetPattern()); + } else { + printm(M_INFO, "No more data.\n"); + L->push(); + } + r = 1; + break; } return r; |