summaryrefslogtreecommitdiff
path: root/lib/HttpServ.cc
diff options
context:
space:
mode:
Diffstat (limited to 'lib/HttpServ.cc')
-rw-r--r--lib/HttpServ.cc33
1 files changed, 22 insertions, 11 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index 5c9a8aa..69d4b2f 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -9,13 +9,14 @@
#include "CopyJob.h"
#include "Task.h"
#include "Base64.h"
+#include "Domain.h"
#include "gettext.h"
String endhl = "\r\n", endnl = "\n";
class ProcessRequest : public Task {
public:
- ProcessRequest(Action *, const Socket &, const String &, int);
+ ProcessRequest(Action * action, const Socket & out, const String & server_name, int server_port, const String & root = "/bin/start");
virtual ~ProcessRequest() {}
virtual String GetName();
protected:
@@ -28,20 +29,21 @@ class ProcessRequest : public Task {
void SendHeads(Handle *, const String &, const String & = "", time_t = -1);
void SendRedirect(Handle *);
- String file, domain, t;
+ String file, domain, t, Uri;
Buffer b;
Task * c, * a;
Action * f;
int len, localport;
Action * p;
Socket s;
+ Domain * d;
- String name, host, gvars, login, password;
+ String name, host, gvars, login, password, root;
Variables * Vars, * Heads;
bool bad, hasvars, post;
};
-ProcessRequest::ProcessRequest(Action * ap, const Socket & as, const String & aname, int aport) : localport(aport), p(ap), s(as), name(aname) {
+ProcessRequest::ProcessRequest(Action * ap, const Socket & as, const String & aname, int aport, const String & aroot) : localport(aport), p(ap), s(as), name(aname), root(aroot) {
SetBurst();
}
@@ -151,6 +153,7 @@ int ProcessRequest::Do() throw(GeneralException) {
if (domain == "/image") bad = false;
if (domain == "/bin") bad = false;
if (domain == "/") bad = false;
+ if ((d = Domain::find_domain(Uri))) bad = false;
if (bad) {
std::cerr << _("Error: bad domain.\n");
}
@@ -177,7 +180,7 @@ int ProcessRequest::Do() throw(GeneralException) {
} else {
ShowError(&b);
}
- } else {
+ } else if (domain == "/image") {
// Dans tous les autres cas de domaine, on cherche le fichier dans le répertoire data.
// On utilise try au cas où le fichier n'existe pas et donc que le constructeur
// d'input renvoie une erreur.
@@ -192,7 +195,11 @@ int ProcessRequest::Do() throw(GeneralException) {
ShowError(&b);
std::cerr << _("File not found, error shown.\n");
}
- }
+ } else if (d) {
+// d->Do(&response);
+ } else {
+ ShowError(&b);
+ }
}
if (a) a->Stop();
@@ -284,7 +291,7 @@ void ProcessRequest::ParseVars(Handle * s, int len) {
*/
bool ProcessRequest::ParseUri(String & file, String & domain, String & gvars, Handle * s) {
- String t, Uri;
+ String t;
bool post = false;
const char * p = 0;
ssize_t sppos;
@@ -368,11 +375,11 @@ bool ProcessRequest::ParseUri(String & file, String & domain, String & gvars, Ha
void ProcessRequest::SendRedirect(Handle * s) {
*s << "HTTP/1.1 301 Moved Permanently" << endhl <<
"Server: " << name << endhl <<
- "Location: http://" << host << "/bin/start" << endhl <<
+ "Location: http://" << host << root << endhl <<
"Cache-Control: no-cache" << endhl <<
"Connection: closed" << endhl <<
"Content-Type: text/html" << endhl << endhl <<
- p->GetSkinner()->Redirect("http://" + host + "/bin/start");
+ p->GetSkinner()->Redirect("http://" + host + root);
}
/*
@@ -434,7 +441,7 @@ String ProcessRequest::GetMime(const String & f) {
return "text/plain";
}
-HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) {
+HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) : root("/bin/start") {
bool r = true;
p = ap;
@@ -464,11 +471,15 @@ HttpServ::~HttpServ(void) {
Listener.close();
}
+void HttpServ::SetRoot(const String & _root) {
+ root = _root;
+}
+
int HttpServ::Do() throw (GeneralException) {
try {
Socket s = Listener.Accept();
s.SetNonBlock();
- new ProcessRequest(p, s, name, localport);
+ new ProcessRequest(p, s, name, localport, root);
}
catch (GeneralException) {
}