Move request cookie processing down to base class.
authorScott Cantor <cantor.2@osu.edu>
Sun, 25 Nov 2007 23:36:11 +0000 (23:36 +0000)
committerScott Cantor <cantor.2@osu.edu>
Sun, 25 Nov 2007 23:36:11 +0000 (23:36 +0000)
xmltooling/Makefile.am
xmltooling/io/HTTPRequest.cpp [new file with mode: 0644]
xmltooling/io/HTTPRequest.h

index 751f13d..efb133f 100644 (file)
@@ -172,6 +172,7 @@ common_sources = \
        impl/UnknownElement.cpp \
        io/AbstractXMLObjectMarshaller.cpp \
        io/AbstractXMLObjectUnmarshaller.cpp \
+       io/HTTPRequest.cpp \
        signature/impl/KeyInfoImpl.cpp \
        signature/impl/KeyInfoSchemaValidators.cpp \
        soap/impl/SOAPClient.cpp \
diff --git a/xmltooling/io/HTTPRequest.cpp b/xmltooling/io/HTTPRequest.cpp
new file mode 100644 (file)
index 0000000..ff73107
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ *  Copyright 2001-2007 Internet2
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * HTTPRequest.cpp
+ * 
+ * Interface to HTTP requests  
+ */
+
+#include "internal.h"
+#include "HTTPRequest.h"
+
+using namespace xmltooling;
+using namespace std;
+
+const char* HTTPRequest::getCookie(const char* name) const
+{
+    if (m_cookieMap.empty()) {
+        string cookies=getHeader("Cookie");
+
+        string::size_type pos=0,cname,namelen,val,vallen;
+        while (pos !=string::npos && pos < cookies.length()) {
+            while (isspace(cookies[pos])) pos++;
+            cname=pos;
+            pos=cookies.find_first_of("=",pos);
+            if (pos == string::npos)
+                break;
+            namelen=pos-cname;
+            pos++;
+            if (pos==cookies.length())
+                break;
+            val=pos;
+            pos=cookies.find_first_of(";",pos);
+            if (pos != string::npos) {
+                vallen=pos-val;
+                pos++;
+                m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val,vallen)));
+            }
+            else
+                m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val)));
+        }
+    }
+    map<string,string>::const_iterator lookup=m_cookieMap.find(name);
+    return (lookup==m_cookieMap.end()) ? NULL : lookup->second.c_str();
+}
index caee6d5..2a5abf7 100644 (file)
 
 #include <xmltooling/io/GenericRequest.h>
 
+#include <map>
+
 namespace xmltooling {
-    
+
+#if defined (_MSC_VER)
+    #pragma warning( push )
+    #pragma warning( disable : 4251 )
+#endif
+
     /**
      * Interface to HTTP requests.
      * 
@@ -83,7 +90,23 @@ namespace xmltooling {
          * @return the header's value, or an empty string
          */
         virtual std::string getHeader(const char* name) const=0;
+
+        /**
+         * Get a cookie value supplied by the client.
+         * 
+         * @param name  name of cookie
+         * @return  cookie value or NULL
+         */
+        virtual const char* getCookie(const char* name) const;
+
+    private:
+        mutable std::map<std::string,std::string> m_cookieMap;
     };
+
+#if defined (_MSC_VER)
+    #pragma warning( pop )
+#endif
+
 };
 
 #endif /* __xmltooling_httpreq_h__ */