summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPixel <pixel@nobis-crew.org>2008-10-09 18:14:16 -0700
committerPixel <pixel@nobis-crew.org>2008-10-09 18:14:16 -0700
commit3a4c10272436374bb0992e7a225fb1f4a716cc5d (patch)
treea3bbec001c663bc92b47338ac65c4f9101b811b5
parent04977e4a8df1ca6993d749f914c94980708e0217 (diff)
Having Lua interfering with the MailHandler now, and switching the MailProcessing to a background task.
-rw-r--r--include/MailServer.h4
-rw-r--r--lib/LuaSmtp.cc50
-rw-r--r--lib/MailServer.cc12
3 files changed, 53 insertions, 13 deletions
diff --git a/include/MailServer.h b/include/MailServer.h
index 296ba50..f3444b6 100644
--- a/include/MailServer.h
+++ b/include/MailServer.h
@@ -32,8 +32,8 @@ class MailHandler : public Base {
public:
MailHandler();
virtual ~MailHandler();
- virtual bool doProcessMail(Handle * in, const String & from, std::vector<String> tos) = 0;
- static bool ProcessMail(Handle * in, const String & from, std::vector<String> tos);
+ virtual Task * doProcessMail(Handle * in, const String & from, std::vector<String> tos) = 0;
+ static Task * ProcessMail(Handle * in, const String & from, std::vector<String> tos);
void OnTop();
private:
static MailHandler * head;
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() {