X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=saml%2Futil%2FCommonDomainCookie.cpp;h=23b15ef918d11c63ad357d999ba4cd7f002cfaa2;hb=93fbe11fc4aa567cc3ac14764044f7ab7a43edb3;hp=772fd184466e10c0d97c8ae807d4436cbea9a7d8;hpb=f1208cd2f514700244816377443c4951dc22c848;p=shibboleth%2Fcpp-opensaml.git diff --git a/saml/util/CommonDomainCookie.cpp b/saml/util/CommonDomainCookie.cpp index 772fd18..23b15ef 100644 --- a/saml/util/CommonDomainCookie.cpp +++ b/saml/util/CommonDomainCookie.cpp @@ -27,6 +27,7 @@ #include "internal.h" #include "util/CommonDomainCookie.h" +#include #include #include #include @@ -34,6 +35,7 @@ using namespace opensaml; using namespace xmltooling; +using namespace boost; using namespace std; const char CommonDomainCookie::CDCName[] = "_saml_idp"; @@ -48,23 +50,19 @@ CommonDomainCookie::CommonDomainCookie(const char* cookie) XMLToolingConfig::getConfig().getURLEncoder()->decode(b64); // Chop it up and save off elements. - vector templist; - char* ptr=b64; - while (*ptr) { - while (*ptr && isspace(*ptr)) ptr++; - char* end=ptr; - while (*end && !isspace(*end)) end++; - templist.push_back(string(ptr,end-ptr)); - ptr=end; - } + split(m_list, b64, is_space(), algorithm::token_compress_on); free(b64); - // Now Base64 decode the list. + // Remove empty elements. + m_list.erase(remove(m_list.begin(), m_list.end(), ""), m_list.end()); + + // Now Base64 decode the list elements, overwriting them. xsecsize_t len; - for (vector::iterator i=templist.begin(); i!=templist.end(); ++i) { + for (vector::iterator i = m_list.begin(); i != m_list.end(); ++i) { + trim(*i); XMLByte* decoded=Base64::decode(reinterpret_cast(i->c_str()),&len); if (decoded && *decoded) { - m_list.push_back(reinterpret_cast(decoded)); + i->assign(reinterpret_cast(decoded)); #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE XMLString::release(&decoded); #else @@ -85,13 +83,8 @@ const vector& CommonDomainCookie::get() const const char* CommonDomainCookie::set(const char* entityID) { - // First scan the list for this IdP. - for (vector::iterator i=m_list.begin(); i!=m_list.end(); i++) { - if (*i == entityID) { - m_list.erase(i); - break; - } - } + // First remove the IdP from the list. + m_list.erase(remove(m_list.begin(), m_list.end(), entityID), m_list.end()); // Append it to the end. m_list.push_back(entityID); @@ -99,24 +92,27 @@ const char* CommonDomainCookie::set(const char* entityID) // Now rebuild the delimited list. xsecsize_t len; string delimited; - for (vector::const_iterator j=m_list.begin(); j!=m_list.end(); j++) { - if (!delimited.empty()) delimited += ' '; + for (vector::const_iterator j = m_list.begin(); j != m_list.end(); ++j) { - XMLByte* b64=Base64::encode(reinterpret_cast(j->c_str()),j->length(),&len); - XMLByte *pos, *pos2; - for (pos=b64, pos2=b64; *pos2; pos2++) - if (isgraph(*pos2)) - *pos++=*pos2; - *pos=0; + XMLByte* b64 = Base64::encode(reinterpret_cast(j->c_str()), j->length(), &len); + if (b64) { + XMLByte *pos, *pos2; + for (pos = b64, pos2 = b64; *pos2; ++pos2) + if (isgraph(*pos2)) + *pos++ = *pos2; + *pos = 0; - delimited += reinterpret_cast(b64); + if (!delimited.empty()) + delimited += ' '; + delimited += reinterpret_cast(b64); #ifdef OPENSAML_XERCESC_HAS_XMLBYTE_RELEASE - XMLString::release(&b64); + XMLString::release(&b64); #else - XMLString::release((char**)&b64); + XMLString::release((char**)&b64); #endif + } } - m_encoded=XMLToolingConfig::getConfig().getURLEncoder()->encode(delimited.c_str()); + m_encoded = XMLToolingConfig::getConfig().getURLEncoder()->encode(delimited.c_str()); return m_encoded.c_str(); }