2 * Copyright 2001-2007 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 <xmltooling/XMLToolingConfig.h>
28 #include <xmltooling/util/URLEncoder.h>
30 using namespace opensaml;
31 using namespace xmltooling;
34 const char CommonDomainCookie::CDCName[] = "_saml_idp";
36 CommonDomainCookie::CommonDomainCookie(const char* cookie)
41 // Copy it so we can URL-decode it.
42 char* b64=strdup(cookie);
43 XMLToolingConfig::getConfig().getURLEncoder()->decode(b64);
45 // Chop it up and save off elements.
46 vector<string> templist;
49 while (*ptr && isspace(*ptr)) ptr++;
51 while (*end && !isspace(*end)) end++;
52 templist.push_back(string(ptr,end-ptr));
57 // Now Base64 decode the list.
59 for (vector<string>::iterator i=templist.begin(); i!=templist.end(); ++i) {
60 XMLByte* decoded=Base64::decode(reinterpret_cast<const XMLByte*>(i->c_str()),&len);
61 if (decoded && *decoded) {
62 m_list.push_back(reinterpret_cast<char*>(decoded));
63 #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
64 XMLString::release(&decoded);
66 XMLString::release((char**)&decoded);
72 const char* CommonDomainCookie::set(const char* entityID)
74 // First scan the list for this IdP.
75 for (vector<string>::iterator i=m_list.begin(); i!=m_list.end(); i++) {
82 // Append it to the end.
83 m_list.push_back(entityID);
85 // Now rebuild the delimited list.
88 for (vector<string>::const_iterator j=m_list.begin(); j!=m_list.end(); j++) {
89 if (!delimited.empty()) delimited += ' ';
91 XMLByte* b64=Base64::encode(reinterpret_cast<const XMLByte*>(j->c_str()),j->length(),&len);
93 for (pos=b64, pos2=b64; *pos2; pos2++)
98 delimited += reinterpret_cast<char*>(b64);
99 #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE
100 XMLString::release(&b64);
102 XMLString::release((char**)&b64);
106 m_encoded=XMLToolingConfig::getConfig().getURLEncoder()->encode(delimited.c_str());
107 return m_encoded.c_str();