Handle encoded URLs in status handler.
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 16 Nov 2007 19:20:23 +0000 (19:20 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Fri, 16 Nov 2007 19:20:23 +0000 (19:20 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/trunk@2626 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/handler/impl/StatusHandler.cpp

index f090bb0..5a5a11b 100644 (file)
@@ -86,6 +86,16 @@ namespace shibsp {
     vector<string> g_NoCerts;
 #endif
 
+    static char _x2c(const char *what)
+    {
+        register char digit;
+
+        digit = (what[0] >= 'A' ? ((what[0] & 0xdf) - 'A')+10 : (what[0] - '0'));
+        digit *= 16;
+        digit += (what[1] >= 'A' ? ((what[1] & 0xdf) - 'A')+10 : (what[1] - '0'));
+        return(digit);
+    }
+
     class DummyRequest : public HTTPRequest
     {
     public:
@@ -129,7 +139,35 @@ namespace shibsp {
             else {
                 m_hostname.assign(url, slash - url);
             }
-            m_uri = slash;
+
+            while (*slash) {
+                if (*slash == '?') {
+                    m_uri += slash;
+                    break;
+                }
+                else if (*slash == ';') {
+                    // If this is Java being stupid, skip everything up to the query string, if any.
+                    if (!strncmp(slash, ";jsessionid=", 12)) {
+                        if (slash = strchr(slash, '?'))
+                            m_uri += slash;
+                        break;
+                    }
+                    else {
+                        m_uri += *slash;
+                    }
+                }
+                else if (*slash != '%') {
+                    m_uri += *slash;
+                }
+                else {
+                    ++slash;
+                    if (!isxdigit(*slash) || !isxdigit(*(slash+1)))
+                        throw invalid_argument("Bad request, contained unsupported encoded characters.");
+                    m_uri += _x2c(slash);
+                    ++slash;
+                }
+                ++slash;
+            }
         }
 
         ~DummyRequest() {