summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/Domain.h4
-rw-r--r--include/HttpServ.h4
-rw-r--r--lib/Domain.cc8
-rw-r--r--lib/HttpServ.cc5
-rw-r--r--lib/LuaHttp.cc15
5 files changed, 29 insertions, 7 deletions
diff --git a/include/Domain.h b/include/Domain.h
index d091728..9cd8483 100644
--- a/include/Domain.h
+++ b/include/Domain.h
@@ -27,14 +27,14 @@ class Domain : public Base {
public:
Domain(const Regex &);
virtual ~Domain();
- static Domain * find_domain(const String & url);
+ static Domain * find_domain(const String & url, int nmatches = 0, regmatch_t * pmatches = 0);
void OnTop();
virtual void Do(const HttpRequest &, HttpResponse *) throw (GeneralException) = 0;
static Domain * First();
Domain * Next();
String GetPattern();
private:
- Domain * find_domain_r(const String & url);
+ Domain * find_domain_r(const String & url, int nmatches = 0, regmatch_t * pmatches = 0);
static Domain * head;
Domain * next, * prev;
Regex pattern;
diff --git a/include/HttpServ.h b/include/HttpServ.h
index 2b2e5da..d8283aa 100644
--- a/include/HttpServ.h
+++ b/include/HttpServ.h
@@ -27,6 +27,7 @@
#include <Buffer.h>
#include <Handle.h>
#include <Exceptions.h>
+#include <BRegex.h>
class HttpResponse : public Base {
public:
@@ -65,12 +66,15 @@ class HttpResponse : public Base {
bool already_prepared;
};
+#define MAX_MATCHES 64
+
class HttpRequest : public Base {
public:
Variables * vars, * headers;
String method, uri, login, password;
Uint32 lip, dip;
int lport, dport;
+ regmatch_t pmatches[MAX_MATCHES];
};
class Action;
diff --git a/lib/Domain.cc b/lib/Domain.cc
index d94bf47..6114e90 100644
--- a/lib/Domain.cc
+++ b/lib/Domain.cc
@@ -63,17 +63,17 @@ void Domain::OnTop() {
next->prev = this;
}
-Domain * Domain::find_domain(const String & url) {
+Domain * Domain::find_domain(const String & url, int nmatches, regmatch_t * pmatches) {
Domain * r = 0;
if (head)
- r = head->find_domain_r(url);
+ r = head->find_domain_r(url, nmatches, pmatches);
return r;
}
-Domain * Domain::find_domain_r(const String & url) {
- if (pattern.Match(url))
+Domain * Domain::find_domain_r(const String & url, int nmatches, regmatch_t * pmatches) {
+ if (pattern.Match(url, nmatches, pmatches))
return this;
if (next)
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index ec320bc..80448a8 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -253,6 +253,8 @@ int ProcessRequest::Do() throw(GeneralException) {
if (file == "favicon.ico") {
domain = "/image";
}
+
+ regmatch_t pmatches[MAX_MATCHES];
if (!bad) {
// Nous vérifions le domaine.
@@ -263,7 +265,7 @@ int ProcessRequest::Do() throw(GeneralException) {
if (domain == "/") bad = false;
// L'url sans domaine ni fichier est valide. (cela arrive sur certains navigateurs...)
if (domain == "") bad = (file != "");
- if ((d = Domain::find_domain(Uri))) bad = false;
+ if ((d = Domain::find_domain(Uri, MAX_MATCHES, pmatches))) bad = false;
if (bad) {
printm(M_INFO, _("Error: bad domain.\n"));
}
@@ -286,6 +288,7 @@ int ProcessRequest::Do() throw(GeneralException) {
request.lport = s.GetPort();
request.dport = s.GetDistantPort();
request.method = Method;
+ memcpy(request.pmatches, pmatches, sizeof(regmatch_t) * MAX_MATCHES);
d->Do(request, &response);
a = response.BuildResponse(&s);
} else if (((domain == "") || (domain == "/")) && (file == "")) {
diff --git a/lib/LuaHttp.cc b/lib/LuaHttp.cc
index a524cc1..a3c728a 100644
--- a/lib/LuaHttp.cc
+++ b/lib/LuaHttp.cc
@@ -486,6 +486,21 @@ void LuaDomain::Do(const HttpRequest & req, HttpResponse * res) throw (GeneralEx
L->push("dport");
L->push((lua_Number) req.dport);
L->settable();
+
+ L->push("matches");
+ L->newtable();
+ for (i = 0; i < MAX_MATCHES; i++) {
+ if (req.pmatches[i].rm_so == -1)
+ continue;
+ L->newtable();
+ L->push("start");
+ L->push((lua_Number) req.pmatches[i].rm_so + 1);
+ L->settable();
+ L->push("size");
+ L->push((lua_Number) req.pmatches[i].rm_eo - req.pmatches[i].rm_so);
+ L->settable();
+ L->settable();
+ }
LuaHttpResponse r(res);
r.push(L);