diff options
author | Pixel <pixel@nobis-crew.org> | 2008-10-15 18:31:13 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2008-10-15 18:31:13 -0700 |
commit | 05a34ba1975a57444c9cdb507c4707b4a63b4bf7 (patch) | |
tree | b662358735c480cbf3b7a4be7c72eebb2e874c94 /lib | |
parent | 465af69f28fddccdbcfea9a82aeadf3f106e6d12 (diff) |
Adding matches into the LuaDomain controler, in order to handle submatches directly at Domain matches.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Domain.cc | 8 | ||||
-rw-r--r-- | lib/HttpServ.cc | 5 | ||||
-rw-r--r-- | lib/LuaHttp.cc | 15 |
3 files changed, 23 insertions, 5 deletions
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); |