diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/LuaSmtp.cc | 50 | ||||
-rw-r--r-- | lib/MailServer.cc | 12 |
2 files changed, 51 insertions, 11 deletions
diff --git a/lib/LuaSmtp.cc b/lib/LuaSmtp.cc index 8652ece..cd2919f 100644 --- a/lib/LuaSmtp.cc +++ b/lib/LuaSmtp.cc @@ -26,7 +26,7 @@ class LuaMailHandler : public MailHandler { public: LuaMailHandler(Lua * _L); virtual ~LuaMailHandler(); - virtual bool doProcessMail(Handle * in, const String & from, std::vector<String> tos); + virtual Task * doProcessMail(Handle * in, const String & from, std::vector<String> tos); private: Lua * L; static int max_id; @@ -76,6 +76,8 @@ void LuaLuaMailHandler::pushmembers(Lua * L) { PUSH_METHOD(LuaMailHandler, LUAMAILHANDLER_ONTOP); } +#define MAILHANDLER_REGISTRY "MAILHANDLERS_KEYS" + void LuaLuaMailHandler::pushstatics(Lua * L) throw (GeneralException) { CHECK_METHODS(LuaMailHandler); CHECK_FUNCTIONS(LuaMailHandler); @@ -83,9 +85,11 @@ void LuaLuaMailHandler::pushstatics(Lua * L) throw (GeneralException) { PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NEWMAILHANDLER); // PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_IMAILHANDLER); // PUSH_FUNCTION(LuaMailHandler, LUAMAILHANDLER_NMAILHANDLER); -} -#define MAILHANDLER_REGISTRY "MAILHANDLERS_KEYS" + L->push(MAILHANDLER_REGISTRY); + L->newtable(); + L->settable(LUA_REGISTRYINDEX); +} LuaMailHandler::LuaMailHandler(Lua * _L) : MailHandler(), L(_L->Father()) { id = max_id++; /***FIXME***/ @@ -93,7 +97,7 @@ LuaMailHandler::LuaMailHandler(Lua * _L) : MailHandler(), L(_L->Father()) { L->push(MAILHANDLER_REGISTRY); L->gettable(LUA_REGISTRYINDEX); L->push((lua_Number) id); - L->copy(2); + L->copy(1); L->settable(); L->pop(); } @@ -107,8 +111,42 @@ LuaMailHandler::~LuaMailHandler() { L->pop(); } -bool LuaMailHandler::doProcessMail(Handle * in, const String & from, std::vector<String> tos) { - return true; +Task * LuaMailHandler::doProcessMail(Handle * in, const String & from, std::vector<String> tos) { + Task * r = 0; + Lua * oldL = L; + Lua * L = oldL->thread(true); + oldL->pop(); + int j; + std::vector<String>::iterator i; + + L->push(MAILHANDLER_REGISTRY); + L->gettable(LUA_REGISTRYINDEX); + L->push((lua_Number) id); + L->gettable(); + L->remove(); + + LuaHandle lh(in); + lh.push(L); + L->push(from); + + L->newtable(); + + for (i = tos.begin(), j = 1; i != tos.end(); i++, j++) { + L->push((lua_Number) j); + L->push(*i); + L->settable(); + } + + L->call(3, 1); + + if (L->isfunction()) { + r = new LuaTask(L, 0, true); + } else { + L->pop(); + L->weaken(); + } + + return r; } int LuaMailHandler::max_id = 1; diff --git a/lib/MailServer.cc b/lib/MailServer.cc index 56446de..0f5194c 100644 --- a/lib/MailServer.cc +++ b/lib/MailServer.cc @@ -158,7 +158,8 @@ int ProcessSMTPRequest::Do() { } } - MailHandler::ProcessMail(out, from, tos); + /***TODO*** Wait for the task and destroy it. */ + Task * r = MailHandler::ProcessMail(out, from, tos); delete out; @@ -193,14 +194,15 @@ MailHandler::~MailHandler() { head = next; } -bool MailHandler::ProcessMail(Handle * in, const String & from, std::vector<String> tos) { +Task * MailHandler::ProcessMail(Handle * in, const String & from, std::vector<String> tos) { MailHandler * cur; + Task * r; for (cur = head; cur; cur = cur->next) { - if (cur->ProcessMail(in, from, tos)) - return true; + if (( r = cur->ProcessMail(in, from, tos))) + return r; } - return false; + return 0; } void MailHandler::OnTop() { |