diff options
author | Pixel <Pixel> | 2001-10-30 17:38:54 +0000 |
---|---|---|
committer | Pixel <Pixel> | 2001-10-30 17:38:54 +0000 |
commit | 57633137f749b0098eaf703f49ed00c96128966d (patch) | |
tree | f7e55be48d4724d44e5ed2362cf836162e866d05 /lib/HttpServ.cc | |
parent | e5057005049b11af44cb804118f95370f03ab32c (diff) |
Huge work on Tasking System.
Diffstat (limited to 'lib/HttpServ.cc')
-rw-r--r-- | lib/HttpServ.cc | 43 |
1 files changed, 22 insertions, 21 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc index 69dff1e..9ec6ba3 100644 --- a/lib/HttpServ.cc +++ b/lib/HttpServ.cc @@ -22,11 +22,12 @@ void HttpServ::MainLoop(Action * p) { void HttpServ::ProcessRequest(Action * p, Socket s) { String file, domain, t; Buffer b; - ReadJob c(s, b); + Task * c = new ReadJob(&s, &b); Action * f; int len; - c.Do(); + c->Run(); + delete c; bad = false; @@ -34,7 +35,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { cerr << "Got a request\n----\n"; - bool post = ParseUri(file, domain, b); + bool post = ParseUri(file, domain, &b); len = -1; do { @@ -45,7 +46,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { len = t.extract(16).to_int(); } } while (t.strlen()); - + if (post) { // On a pas eu de ligne 'Content-Length' mais on a eu une méthode POST. // Cela est une erreur. @@ -55,7 +56,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { } else { cerr << "Got a POST request. Parsing variables. (len = " << len << ")\n"; // Les variables seront initialisées ici. - ParseVars(s, len); + ParseVars(&s, len); } } else { Vars = new Variables(0); @@ -78,19 +79,19 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { } if (bad) { - ShowError(s); + ShowError(&s); } else { if (((domain == "") || (domain == "/")) && (file == "")) { // Si le navigateur a demandé l'URL '/', alors on renvoie une notification // de redirection. - SendRedirect(s); + SendRedirect(&s); } else if (domain == "/bin") { // Le domaine 'bin' est réservé aux actions. On cherche donc l'action à effectuer. if ((f = p->Look4URL(file))) { - SendHeads(s, "text/html"); + SendHeads(&s, "text/html"); f->Do(Vars, &s); } else { - ShowError(s); + ShowError(&s); } } else { // Dans tous les autres cas de domaine, on cherche le fichier dans le répertoire datas. @@ -98,12 +99,12 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { // d'input renvoie une erreur. try { Input i(String("datas/") + file); - SendHeads(s, GetMime(file)); + SendHeads(&s, GetMime(file)); s.ReadFile(i); cerr << "File found, dumped.\n"; } catch (IOGeneral e) { - ShowError(s); + ShowError(&s); cerr << "File not found, error showed.\n"; } } @@ -114,7 +115,7 @@ void HttpServ::ProcessRequest(Action * p, Socket s) { cerr << "----\n"; } -void HttpServ::ParseVars(Handle & s, int len) { +void HttpServ::ParseVars(Handle * s, int len) { String t, v; char conv[3], l; int hconv, nbvars; @@ -122,7 +123,7 @@ void HttpServ::ParseVars(Handle & s, int len) { t = ""; for (int i = 0; i < len; i++) { - s.read(&l, 1); + s->read(&l, 1); t += l; } cerr << "Post variables line: '" <<t << "'\n"; @@ -174,13 +175,13 @@ 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 HttpServ::ParseUri(String & file, String & domain, Handle * s) { String t, Uri; bool post = false; char * p = NULL; ssize_t sppos; - s >> t; + *s >> t; cerr << t << endl; bad = false; @@ -233,8 +234,8 @@ 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) { - s << "HTTP/1.1 301 Moved Permanently" << endhl << +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 << "Cache-Control: no-cache" << endhl << @@ -250,8 +251,8 @@ void HttpServ::SendRedirect(Handle & s) { * Nous envoyons les entetes de réponse HTTP. */ -void HttpServ::SendHeads(Handle & s, const String & mime) { - s << "HTTP/1.1 200 OK" << endhl << +void HttpServ::SendHeads(Handle * s, const String & mime) { + *s << "HTTP/1.1 200 OK" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << "Connection-Type: closed" << endhl << @@ -262,8 +263,8 @@ void HttpServ::SendHeads(Handle & s, const String & mime) { * Affichage d'une erreur 404. */ -void HttpServ::ShowError(Handle & s) { - s << "HTTP/1.1 404 Not Found" << endhl << +void HttpServ::ShowError(Handle * s) { + *s << "HTTP/1.1 404 Not Found" << endhl << "Server: " << name << endhl << "Cache-Control: no-cache" << endhl << "Connection-Type: closed" << endhl << |