From 57ef82d75133bbbb990ab59e166677497aca8098 Mon Sep 17 00:00:00 2001 From: cantor Date: Sun, 25 Nov 2007 23:36:11 +0000 Subject: [PATCH] Move request cookie processing down to base class. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@441 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/Makefile.am | 1 + xmltooling/io/HTTPRequest.cpp | 58 +++++++++++++++++++++++++++++++++++++++++++ xmltooling/io/HTTPRequest.h | 25 ++++++++++++++++++- 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 xmltooling/io/HTTPRequest.cpp diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index 751f13d..efb133f 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -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 index 0000000..ff73107 --- /dev/null +++ b/xmltooling/io/HTTPRequest.cpp @@ -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::const_iterator lookup=m_cookieMap.find(name); + return (lookup==m_cookieMap.end()) ? NULL : lookup->second.c_str(); +} diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h index caee6d5..2a5abf7 100644 --- a/xmltooling/io/HTTPRequest.h +++ b/xmltooling/io/HTTPRequest.h @@ -25,8 +25,15 @@ #include +#include + 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 m_cookieMap; }; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + }; #endif /* __xmltooling_httpreq_h__ */ -- 2.1.4