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 XMLString::release(&decoded);
68 const char* CommonDomainCookie::set(const char* entityID)
70 // First scan the list for this IdP.
71 for (vector<string>::iterator i=m_list.begin(); i!=m_list.end(); i++) {
78 // Append it to the end.
79 m_list.push_back(entityID);
81 // Now rebuild the delimited list.
84 for (vector<string>::const_iterator j=m_list.begin(); j!=m_list.end(); j++) {
85 if (!delimited.empty()) delimited += ' ';
87 XMLByte* b64=Base64::encode(reinterpret_cast<const XMLByte*>(j->c_str()),j->length(),&len);
89 for (pos=b64, pos2=b64; *pos2; pos2++)
94 delimited += reinterpret_cast<char*>(b64);
95 XMLString::release(&b64);
98 m_encoded=XMLToolingConfig::getConfig().getURLEncoder()->encode(delimited.c_str());
99 return m_encoded.c_str();