summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorpixel <pixel>2007-06-18 09:25:47 +0000
committerpixel <pixel>2007-06-18 09:25:47 +0000
commit3839686287a49edf94d4febcfdd90d261eae223d (patch)
treeb4c9757c62a5c3ad2f32b7b0011cb5efc93de2b0 /lib
parent62c3fb9b2492667f26d768e8e1f2317a264b01f1 (diff)
URI UnMangling.
Diffstat (limited to 'lib')
-rw-r--r--lib/HttpServ.cc45
1 files changed, 44 insertions, 1 deletions
diff --git a/lib/HttpServ.cc b/lib/HttpServ.cc
index bc836c4..d00890e 100644
--- a/lib/HttpServ.cc
+++ b/lib/HttpServ.cc
@@ -17,7 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-/* $Id: HttpServ.cc,v 1.51 2007-06-17 15:21:50 pixel Exp $ */
+/* $Id: HttpServ.cc,v 1.52 2007-06-18 09:25:47 pixel Exp $ */
#ifdef HAVE_CONFIG_H
#include "config.h"
@@ -45,6 +45,7 @@ class ProcessRequest : public Task {
virtual int Do() throw (GeneralException);
private:
String GetMime(const String &);
+ String UnMangle(const String &, int p = 0);
bool ParseUri(String &, String &, String &, Handle *);
void ParseVars(Handle *, int);
void ShowError(Handle *);
@@ -397,6 +398,7 @@ bool ProcessRequest::ParseUri(String & file, String & domain, String & gvars, Ha
Uri = "";
}
}
+ Uri = UnMangle(Uri);
posslash = Uri.strrchr('/');
file = Uri.to_charp(posslash + 1);
if (posslash > 0) {
@@ -480,6 +482,47 @@ String ProcessRequest::GetMime(const String & f) {
return "text/plain";
}
+String ProcessRequest::UnMangle(const String & s, int p) {
+ String r;
+ char c1, c2, c[2] = "x";
+
+ if (s.strlen() <= p)
+ return "";
+
+ switch (s[p]) {
+ case '%':
+ c1 = s[p + 1];
+ c2 = s[p + 2];
+
+ if ((((c1 >= '0') && (c1 <= '9')) || ((c1 >= 'A') && (c1 <= 'F')) || ((c1 >= 'a') && (c1 <= 'f'))) &&
+ (((c2 >= '0') && (c2 <= '9')) || ((c2 >= 'A') && (c2 <= 'F')) || ((c2 >= 'a') && (c2 <= 'f')))) {
+ if ((c1 >= '0') && (c1 <= '9')) c1 -= '0';
+ if ((c2 >= '0') && (c2 <= '9')) c2 -= '0';
+ if ((c1 >= 'A') && (c1 <= 'F')) c1 -= 'A' - 10;
+ if ((c2 >= 'A') && (c2 <= 'F')) c2 -= 'A' - 10;
+ if ((c1 >= 'a') && (c1 <= 'f')) c1 -= 'a' - 10;
+ if ((c2 >= 'a') && (c2 <= 'f')) c2 -= 'a' - 10;
+ c[0] = c1 * 16 + c2;
+ r = c;
+ p += 3;
+ } else {
+ r = "%";
+ p++;
+ }
+ break;
+ case '+':
+ r = " ";
+ p++;
+ break;
+ default:
+ r = s[p];
+ p++;
+ break;
+ }
+
+ return r + UnMangle(s, p);
+}
+
HttpServ::HttpServ(Action * ap, int port, const String & nname) throw (GeneralException) : root("/bin/start") {
bool r = true;