diff options
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | include/LuaTask.h | 26 | ||||
-rw-r--r-- | lib/LuaTask.cc | 75 |
3 files changed, 101 insertions, 1 deletions
@@ -1,4 +1,3 @@ --) Create LuaTask class. -) Add timeouts in HttpServ and HttpClient. -) Add logging support in HttpServ. -) Remove hardcoded skin, and create the HtmlSkin class. diff --git a/include/LuaTask.h b/include/LuaTask.h new file mode 100644 index 0000000..48f65bf --- /dev/null +++ b/include/LuaTask.h @@ -0,0 +1,26 @@ +#ifndef __LUATASK_H__ +#define __LUATASK_H__ + +#include <Task.h> +#include <Buffer.h> +#include <BLua.h> + +class LuaTask : public Task { + public: + LuaTask(Lua *, const String &); + virtual ~LuaTask(); + virtual String GetName(); + protected: + virtual int Do() throw (GeneralException); + private: + Lua * L; + String cmd; + Task * c; + Buffer * b; + + String task; + + static LuaTask * top; +}; + +#endif diff --git a/lib/LuaTask.cc b/lib/LuaTask.cc new file mode 100644 index 0000000..4608fa1 --- /dev/null +++ b/lib/LuaTask.cc @@ -0,0 +1,75 @@ +#include <LuaTask.h> +#include <LuaHandle.h> +#ifndef LUATASK_OMIT_HTTPCLIENT +#include <HttpClient.h> +#endif + +LuaTask * LuaTask::top = 0; + +LuaTask::LuaTask(Lua * _L, const String & _cmd) : L(_L), cmd(_cmd), c(0), b(0) { + if (top) { + WaitFor(top); + } else { + SetBurst(); + } + top = this; +} + +LuaTask::~LuaTask() { + if (top == this) { + top = 0; + } +} + +String LuaTask::GetName() { + return "LuaTask(" + cmd + ")"; +} + +int LuaTask::Do() throw (GeneralException) { + switch (current) { + case 0: + current = 1; + L->resume(cmd); + case 1: + if (c) { + int nargs = 0; + + if (task == "HttpClient") { + LuaBuffer o(b); + o.pushdestruct(L); + nargs = 1; + } + + delete c; + c = 0; + + L->resume(nargs); + } + if (L->gettop() >= 1) { + task = L->tostring(1); + if (task == "") { + L->error("Must precise a task-type to execute."); + return TASK_DONE; +#ifndef LUATASK_OMIT_HTTPCLIENT + } else if (task == "HttpClient") { + String url = L->tostring(2); + t_headers headers; + + b = new Buffer(true); + + headers.push_back("User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.8.1) Gecko/20061010 Firefox/2.0"); + c = new HttpClient(url, b, "", headers); + WaitFor(c); + Suspend(TASK_ON_HOLD); +#endif + } else { + L->error("Unknow requested task: " + task); + return TASK_DONE; + } + } else { + return TASK_DONE; + } + } + + return TASK_ON_HOLD; +} |