2 * Copyright 2001-2009 Internet2
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * CommonDomainCookie.cpp
20 * Helper class for maintaining discovery cookie.
24 #include "util/CommonDomainCookie.h"
26 #include <xercesc/util/Base64.hpp>
27 #include <xsec/framework/XSECDefs.hpp>
28 #include <xmltooling/XMLToolingConfig.h>
29 #include <xmltooling/util/URLEncoder.h>
31 using namespace opensaml;
32 using namespace xmltooling;
35 const char CommonDomainCookie::CDCName[] = "_saml_idp";
37 CommonDomainCookie::CommonDomainCookie(const char* cookie)
42 // Copy it so we can URL-decode it.
43 char* b64=strdup(cookie);
44 XMLToolingConfig::getConfig().getURLEncoder()->decode(b64);
46 // Chop it up and save off elements.
47 vector<string> templist;
50 while (*ptr && isspace(*ptr)) ptr++;
52 while (*end && !isspace(*end)) end++;
53 templist.push_back(string(ptr,end-ptr));
58 // Now Base64 decode the list.
60 for (vector<string>::iterator i=templist.begin(); i!=templist.end(); ++i) {
61 XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(i->c_str()),&len);
62 if (decoded && *decoded) {
63 m_list.push_back(reinterpret_cast<char*>(decoded));
64 #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
65 XMLString::release(&decoded);
67 XMLString::release((char**)&decoded);
73 const char* CommonDomainCookie::set(const char* entityID)
75 // First scan the list for this IdP.
76 for (vector<string>::iterator i=m_list.begin(); i!=m_list.end(); i++) {
83 // Append it to the end.
84 m_list.push_back(entityID);
86 // Now rebuild the delimited list.
89 for (vector<string>::const_iterator j=m_list.begin(); j!=m_list.end(); j++) {
90 if (!delimited.empty()) delimited += ' ';
92 XMLByte* b64=Base64::encode(reinterpret_cast<const XMLByte*>(j->c_str()),j->length(),&len);
94 for (pos=b64, pos2=b64; *pos2; pos2++)
99 delimited += reinterpret_cast<char*>(b64);
100 #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
101 XMLString::release(&b64);
103 XMLString::release((char**)&b64);
107 m_encoded=XMLToolingConfig::getConfig().getURLEncoder()->encode(delimited.c_str());
108 return m_encoded.c_str();