diff options
-rw-r--r-- | include/CopyJob.h | 1 | ||||
-rw-r--r-- | include/HttpServ.h | 18 | ||||
-rw-r--r-- | include/ReadJob.h | 1 | ||||
-rw-r--r-- | include/Socket.h | 2 | ||||
-rw-r--r-- | include/Task.h | 2 | ||||
-rw-r--r-- | lib/CopyJob.cc | 4 | ||||
-rw-r--r-- | lib/HttpServ.cc | 102 | ||||
-rw-r--r-- | lib/ReadJob.cc | 2 | ||||
-rw-r--r-- | lib/Socket.cc | 4 | ||||
-rw-r--r-- | lib/Task.cc | 2 | ||||
-rw-r--r-- | po/fr.po | 33 |
11 files changed, 104 insertions, 67 deletions
diff --git a/include/CopyJob.h b/include/CopyJob.h index a4f4bca..67cbf36 100644 --- a/include/CopyJob.h +++ b/include/CopyJob.h @@ -17,7 +17,6 @@ class CopyJob : public Task { Handle * s, * d; ssize_t siz, cursiz; char buffer[COPY_BUFSIZ]; - int current; }; #else diff --git a/include/HttpServ.h b/include/HttpServ.h index 7ac40e2..18295bc 100644 --- a/include/HttpServ.h +++ b/include/HttpServ.h @@ -6,6 +6,7 @@ #include <String.h> #include <Variables.h> #include <Action.h> +#include <Task.h> #include <Exceptions.h> /* @@ -16,24 +17,17 @@ * qui est obligatoirement statique et doit posseder l'url /bin/start. */ -class HttpServ : public Base { +class HttpServ : public Task { public: HttpServ(int = 1500, const String & = String("GruiK Server v0.1")) throw (GeneralException); ~HttpServ() {} - void MainLoop(Action *); + void SetMenu(Action *); + virtual String GetName(); + protected: + virtual int Do(); private: - String GetMime(const String &); - void ProcessRequest(Action *, Socket); - bool ParseUri(String &, String &, Handle *); - void ParseVars(Handle *, int); - void ShowError(Handle *); - void SendHeads(Handle *, const String &); - void SendRedirect(Handle *); - String name; Socket Listener; - Variables * Vars; int localport; - bool bad; }; extern String endhl, endnl; diff --git a/include/ReadJob.h b/include/ReadJob.h index 90ba2c8..5cc4846 100644 --- a/include/ReadJob.h +++ b/include/ReadJob.h @@ -14,7 +14,6 @@ class ReadJob : public Task { virtual String GetName(); private: Handle * s, * d; - int current; }; #else diff --git a/include/Socket.h b/include/Socket.h index 9d70205..6bd612c 100644 --- a/include/Socket.h +++ b/include/Socket.h @@ -36,7 +36,7 @@ class Socket : public Handle { bool SetLocal(String, int = 0); bool Connect(String, int); bool Listen(); - Socket Accept(); + Socket Accept() throw (GeneralException); bool IsConnected(); bool IsListening(); size_t WriteFile(Output &); diff --git a/include/Task.h b/include/Task.h index f2d4b0b..1842314 100644 --- a/include/Task.h +++ b/include/Task.h @@ -26,6 +26,8 @@ class Task : public Base { protected: virtual int Do() throw (GeneralException); + int current; + private: int state; bool suspended; diff --git a/lib/CopyJob.cc b/lib/CopyJob.cc index e46e3da..fb8c6e2 100644 --- a/lib/CopyJob.cc +++ b/lib/CopyJob.cc @@ -1,7 +1,7 @@ #include "CopyJob.h" #include "General.h" -CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz) : s(as), d(ad), siz(asiz), cursiz(0), current(0) { } +CopyJob::CopyJob(Handle * as, Handle * ad, ssize_t asiz) : s(as), d(ad), siz(asiz), cursiz(0) { } CopyJob::~CopyJob() { } @@ -30,6 +30,8 @@ int CopyJob::Do() throw (GeneralException) { } cursiz += r; } + + return TASK_DONE; } String CopyJob::GetName() { diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 3bec28f..7464e5b 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -3,38 +3,54 @@ #include "HttpServ.h" #include "Buffer.h" #include "ReadJob.h" +#include "Task.h" #include "config.h" String endhl = "\r\n", endnl = "\n"; -HttpServ::HttpServ(int port, const String & nname) throw (GeneralException) : name(nname), localport(port) { - bool r = true; - - r = Listener.SetLocal("", port); - if (r) { - r = Listener.Listen(); - } - - if (!r) { - throw GeneralException("Initialisation of the Mini HTTP-Server failed."); - } - - cerr << "Mini HTTP-Server '" << name << "' ready and listening for port " << port << endl; -} - -void HttpServ::MainLoop(Action * p) { - while (1) { - ProcessRequest(p, Listener.Accept()); - } -} +class ProcessRequest : public Task { + public: + ProcessRequest(Action *, const Socket &); + virtual ~ProcessRequest() {} + virtual String GetName(); + protected: + virtual int Do(); + private: + String GetMime(const String &); + bool ParseUri(String &, String &, Handle *); + void ParseVars(Handle *, int); + void ShowError(Handle *); + void SendHeads(Handle *, const String &); + void SendRedirect(Handle *); -void HttpServ::ProcessRequest(Action * p, Socket s) { String file, domain, t; Buffer b; - Task * c = new ReadJob(&s, &b); + Task * c; Action * f; int len; - + Action * p; + Socket s; + + String name; + Variables * Vars; + bool bad; + +}; + +ProcessRequest::ProcessRequest(Action * ap, const Socket & as) : p(ap), s(as) { } + +String ProcessRequest::GetName() { + return "Processing HTTP request"; +} + +int ProcessRequest::Do() { + c = new ReadJob(&s, &b); + +} + +void ProcessRequest::ProcessRequest(Action * p, Socket s) { + c = new ReadJob(&s, &b); + s.SetNonBlock(); c->Run(); @@ -126,7 +142,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { cerr << "----\n"; } -void HttpServ::ParseVars(Handle * s, int len) { +void ProcessRequest::ParseVars(Handle * s, int len) { String t, v; char conv[3], l; int hconv, nbvars; @@ -186,7 +202,7 @@ void HttpServ::ParseVars(Handle * s, int len) { * c'est à dire la méthode demandée par le client. */ -bool HttpServ::ParseUri(String & file, String & domain, Handle * s) { +bool ProcessRequest::ParseUri(String & file, String & domain, Handle * s) { String t, Uri; bool post = false; const char * p = NULL; @@ -245,7 +261,7 @@ bool HttpServ::ParseUri(String & file, String & domain, Handle * s) { /* * Ceci sert à rediriger le navigateur vers l'url de démarrage. */ -void HttpServ::SendRedirect(Handle * s) { +void ProcessRequest::SendRedirect(Handle * s) { *s << "HTTP/1.1 301 Moved Permanently" << endhl << "Server: " << name << endhl << "Location: http://127.0.0.1:" << localport << "/bin/start" << endhl << @@ -262,7 +278,7 @@ void HttpServ::SendRedirect(Handle * s) { * Nous envoyons les entetes de réponse HTTP. */ -void HttpServ::SendHeads(Handle * s, const String & mime) { +void ProcessRequest::SendHeads(Handle * s, const String & mime) { *s << "HTTP/1.1 200 OK" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << @@ -274,7 +290,7 @@ void HttpServ::SendHeads(Handle * s, const String & mime) { * Affichage d'une erreur 404. */ -void HttpServ::ShowError(Handle * s) { +void ProcessRequest::ShowError(Handle * s) { *s << "HTTP/1.1 404 Not Found" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << @@ -291,7 +307,7 @@ void HttpServ::ShowError(Handle * s) { * Par défaut, nous mettons "text/plain". */ -String HttpServ::GetMime(const String & f) { +String ProcessRequest::GetMime(const String & f) { String ext; size_t ppos; @@ -309,3 +325,31 @@ String HttpServ::GetMime(const String & f) { return "text/plain"; } + +HttpServ::HttpServ(int port, const String & nname) throw (GeneralException) : name(nname), localport(port) { + bool r = true; + + r = Listener.SetLocal("", port); + if (r) { + r = Listener.Listen(); + } + + if (!r) { + throw GeneralException("Initialisation of the Mini HTTP-Server failed."); + } + + r.SetNonBlock(); + + cerr << "Mini HTTP-Server '" << name << "' ready and listening for port " << port << endl; +} + +int HttpServ::Do(Action * p) { + try { + Socket s = Listener.Accept(); + new ProcessRequest(p, Listener.Accept()); + } + catch (GeneralException) { + return TASK_ON_HOLD; + } +} + diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc index 2c244ad..6640d82 100644 --- a/lib/ReadJob.cc +++ b/lib/ReadJob.cc @@ -1,7 +1,7 @@ #include "ReadJob.h" #include "HttpServ.h" -ReadJob::ReadJob(Handle * as, Handle * ad) : s(as), d(ad), current(0) { } +ReadJob::ReadJob(Handle * as, Handle * ad) : s(as), d(ad) { } ReadJob::~ReadJob() { } diff --git a/lib/Socket.cc b/lib/Socket.cc index de6f42e..f3f4c0f 100644 --- a/lib/Socket.cc +++ b/lib/Socket.cc @@ -133,13 +133,13 @@ bool Socket::Listen(void) { return listening; } -Socket Socket::Accept(void) { +Socket Socket::Accept(void) throw (GeneralException) { struct sockaddr inaddr; socklen_t inlen = sizeof(inaddr); int h; if ((h = accept(GetHandle(), &inaddr, &inlen)) < 0) { - return Socket(); + throw GeneralException("Failed accepting."); } else { return Socket(h); } diff --git a/lib/Task.cc b/lib/Task.cc index fd1bf3f..063a983 100644 --- a/lib/Task.cc +++ b/lib/Task.cc @@ -4,7 +4,7 @@ #include "Task.h" #include "String.h" -Task::Task() : state(TASK_ON_HOLD), suspended(false) { +Task::Task() : state(TASK_ON_HOLD), suspended(false), current(0) { TaskMan::AddTask(this); } Task::~Task() { @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: Baltisot 1.0.0\n" -"POT-Creation-Date: 2001-11-10 14:48+0100\n" +"POT-Creation-Date: 2001-11-14 18:16+0100\n" "PO-Revision-Date: 2001-10-29 08:26GMT\n" "Last-Translator: Nicolas Noble <nicolas@nobis-crew.org>\n" "Language-Team: French <fr@li.org>\n" @@ -14,35 +14,32 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "X-Generator: KBabel 0.8\n" -#: lib/Exceptions.cc:25 -#, fuzzy, c-format +#: lib/Exceptions.cc:37 +#, c-format msgid "Failed allocating %ld bytes." -msgstr "N'a pu allouer %lld octets." +msgstr "N'a pu allouer %ld octets." -#: lib/Exceptions.cc:30 -#, fuzzy, c-format +#: lib/Exceptions.cc:42 +#, c-format msgid "An error has occured while %s %ld bytes from %s: %s" -msgstr "Une erreur est survenue en %s %lld octets depuis %s: %s" +msgstr "Une erreur est survenue en %s %ld octets depuis %s: %s" -#: lib/Exceptions.cc:30 +#: lib/Exceptions.cc:42 msgid "writing" msgstr "écrivant" -#: lib/Exceptions.cc:30 +#: lib/Exceptions.cc:42 msgid "reading" msgstr "lisant" -#: lib/Exceptions.cc:39 +#: lib/Exceptions.cc:51 msgid "No more bytes for reading or writing." -msgstr "" +msgstr "Plus d'octets à lire ou écrire" -#: lib/Exceptions.cc:41 +#: lib/Exceptions.cc:57 msgid "Switching task in a non-tasked environnement" -msgstr "" +msgstr "Basculement de tâche dans un environnement non multi-tâches" -#: lib/Handle.cc:153 +#: lib/Handle.cc:151 msgid "Bare Handle - should not happend" -msgstr "" - -#~ msgid "Internal error: has occured while %s from %s: open for %s." -#~ msgstr "Erreur interne: est survenue en %s depuis %s: ouvert pour %s." +msgstr "Handle pur - ne devrait pas arriver" |