diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Exceptions.cc | 4 | ||||
-rw-r--r-- | lib/HttpServ.cc | 21 | ||||
-rw-r--r-- | lib/ReadJob.cc | 4 |
3 files changed, 17 insertions, 12 deletions
diff --git a/lib/Exceptions.cc b/lib/Exceptions.cc index 3989836..eed138a 100644 --- a/lib/Exceptions.cc +++ b/lib/Exceptions.cc @@ -22,12 +22,12 @@ char * GeneralException::GetMsg() { } MemoryException::MemoryException(ssize_t s) { - sprintf(t, _("Failed allocating %lld bytes."), s); + sprintf(t, _("Failed allocating %ld bytes."), s); msg = strdup(t); } IOException::IOException(String fn, op_t op, ssize_t s) { - sprintf(t, _("An error has occured while %s %lld bytes from %s: %s"), op == IO_WRITE ? _("writing") : _("reading"), + sprintf(t, _("An error has occured while %s %ld bytes from %s: %s"), op == IO_WRITE ? _("writing") : _("reading"), s, fn.to_charp(), strerror(errno)); msg = strdup(t); } diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index b354f69..69dff1e 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -2,6 +2,7 @@ #include "Action.h" #include "HttpServ.h" #include "Buffer.h" +#include "ReadJob.h" #include "config.h" String endhl = "\r\n", endnl = "\n"; @@ -14,14 +15,18 @@ HttpServ::HttpServ(int port, const String & nname) : name(nname), localport(port void HttpServ::MainLoop(Action * p) { while (1) { - ProcessRequest(p, Socket(Listener.Accept())); + ProcessRequest(p, Listener.Accept()); } } void HttpServ::ProcessRequest(Action * p, Socket s) { String file, domain, t; + Buffer b; + ReadJob c(s, b); Action * f; int len; + + c.Do(); bad = false; @@ -29,11 +34,11 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { cerr << "Got a request\n----\n"; - bool post = ParseUri(file, domain, s); + bool post = ParseUri(file, domain, b); len = -1; do { - s >> t; + b >> t; cerr << t << endl; if ((t.strstr("Content-Length: ") == 0) || (t.strstr("Content-length: ") == 0)) { cerr << "Saw 'Content-Lenght:', reading length from '" << t.extract(16) << "'\n"; @@ -109,7 +114,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { cerr << "----\n"; } -void HttpServ::ParseVars(Socket & s, int len) { +void HttpServ::ParseVars(Handle & s, int len) { String t, v; char conv[3], l; int hconv, nbvars; @@ -169,7 +174,7 @@ void HttpServ::ParseVars(Socket & s, int len) { * c'est à dire la méthode demandée par le client. */ -bool HttpServ::ParseUri(String & file, String & domain, Socket & s) { +bool HttpServ::ParseUri(String & file, String & domain, Handle & s) { String t, Uri; bool post = false; char * p = NULL; @@ -228,7 +233,7 @@ bool HttpServ::ParseUri(String & file, String & domain, Socket & s) { /* * Ceci sert à rediriger le navigateur vers l'url de démarrage. */ -void HttpServ::SendRedirect(Socket & s) { +void HttpServ::SendRedirect(Handle & s) { s << "HTTP/1.1 301 Moved Permanently" << endhl << "Server: " << name << endhl << "Location: http://127.0.0.1:" << localport << "/bin/start" << endhl << @@ -245,7 +250,7 @@ void HttpServ::SendRedirect(Socket & s) { * Nous envoyons les entetes de réponse HTTP. */ -void HttpServ::SendHeads(Socket & s, const String & mime) { +void HttpServ::SendHeads(Handle & s, const String & mime) { s << "HTTP/1.1 200 OK" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << @@ -257,7 +262,7 @@ void HttpServ::SendHeads(Socket & s, const String & mime) { * Affichage d'une erreur 404. */ -void HttpServ::ShowError(Socket & s) { +void HttpServ::ShowError(Handle & s) { s << "HTTP/1.1 404 Not Found" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << diff --git a/lib/ReadJob.cc b/lib/ReadJob.cc index 9f4e084..bd63377 100644 --- a/lib/ReadJob.cc +++ b/lib/ReadJob.cc @@ -9,8 +9,8 @@ int ReadJob::Do() { String buff; while (!s.IsClosed()) { - buff << s; - buff >> d; + s >> buff; + d << buff; if (buff == "") return TASK_DONE; } } |