SSPCPP-616 - clean up concatenated string literals
[shibboleth/cpp-sp.git] / shibsp / attribute / ScopedAttributeDecoder.cpp
index 3aadacb..7a667b7 100644 (file)
@@ -1,23 +1,27 @@
-/*
- *  Copyright 2001-2007 Internet2
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- * 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
+ * UCAID licenses this file to you 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
+ * 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.
+ * 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.
  */
 
 /**
  * ScopedAttributeDecoder.cpp
  *
- * Decodes SAML into ScopedAttributes
+ * Decodes SAML into ScopedAttributes.
  */
 
 #include "internal.h"
@@ -35,25 +39,32 @@ using namespace std;
 
 namespace shibsp {
     static const XMLCh Scope[] =            UNICODE_LITERAL_5(S,c,o,p,e);
-    static const XMLCh scopeDelimeter[] =   UNICODE_LITERAL_14(s,c,o,p,e,D,e,l,i,m,e,t,e,r);
+    static const XMLCh scopeDelimiter[] =   UNICODE_LITERAL_14(s,c,o,p,e,D,e,l,i,m,i,t,e,r);
 
     class SHIBSP_DLLLOCAL ScopedAttributeDecoder : virtual public AttributeDecoder
     {
     public:
-        ScopedAttributeDecoder(const DOMElement* e) : AttributeDecoder(e), m_delimeter('@') {
-            if (e && e->hasAttributeNS(NULL,scopeDelimeter)) {
-                auto_ptr_char d(e->getAttributeNS(NULL,scopeDelimeter));
-                m_delimeter = *(d.get());
+        ScopedAttributeDecoder(const DOMElement* e) : AttributeDecoder(e), m_delimiter('@') {
+            if (e && e->hasAttributeNS(nullptr,scopeDelimiter)) {
+                auto_ptr_char d(e->getAttributeNS(nullptr,scopeDelimiter));
+                m_delimiter = *(d.get());
             }
         }
         ~ScopedAttributeDecoder() {}
 
+        // deprecated method
+        shibsp::Attribute* decode(
+            const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=nullptr, const char* relyingParty=nullptr
+            ) const {
+            return decode(nullptr, ids, xmlObject, assertingParty, relyingParty);
+        }
+
         shibsp::Attribute* decode(
-            const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty=NULL, const char* relyingParty=NULL
+            const GenericRequest*, const vector<string>&, const XMLObject*, const char* assertingParty=nullptr, const char* relyingParty=nullptr
             ) const;
 
     private:
-        char m_delimeter;
+        char m_delimiter;
     };
 
     AttributeDecoder* SHIBSP_DLLLOCAL ScopedAttributeDecoderFactory(const DOMElement* const & e)
@@ -63,26 +74,24 @@ namespace shibsp {
 };
 
 shibsp::Attribute* ScopedAttributeDecoder::decode(
-    const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
+    const GenericRequest* request, const vector<string>& ids, const XMLObject* xmlObject, const char* assertingParty, const char* relyingParty
     ) const
 {
     char* val;
     char* scope;
     const XMLCh* xmlscope;
-    QName scopeqname(NULL,Scope);
-    auto_ptr<ScopedAttribute> scoped(new ScopedAttribute(ids, m_delimeter));
-    scoped->setCaseSensitive(m_caseSensitive);
+    xmltooling::QName scopeqname(nullptr,Scope);
+    auto_ptr<ScopedAttribute> scoped(new ScopedAttribute(ids, m_delimiter));
     vector< pair<string,string> >& dest = scoped->getValues();
-    vector<XMLObject*>::const_iterator v,stop;
+    pair<vector<XMLObject*>::const_iterator,vector<XMLObject*>::const_iterator> valrange;
 
-    Category& log = Category::getInstance(SHIBSP_LOGCAT".AttributeDecoder.Scoped");
+    Category& log = Category::getInstance(SHIBSP_LOGCAT ".AttributeDecoder.Scoped");
 
     if (xmlObject && XMLString::equals(opensaml::saml1::Attribute::LOCAL_NAME,xmlObject->getElementQName().getLocalPart())) {
         const opensaml::saml2::Attribute* saml2attr = dynamic_cast<const opensaml::saml2::Attribute*>(xmlObject);
         if (saml2attr) {
             const vector<XMLObject*>& values = saml2attr->getAttributeValues();
-            v = values.begin();
-            stop = values.end();
+            valrange = valueRange(request, values);
             if (log.isDebugEnabled()) {
                 auto_ptr_char n(saml2attr->getName());
                 log.debug(
@@ -95,8 +104,7 @@ shibsp::Attribute* ScopedAttributeDecoder::decode(
             const opensaml::saml1::Attribute* saml1attr = dynamic_cast<const opensaml::saml1::Attribute*>(xmlObject);
             if (saml1attr) {
                 const vector<XMLObject*>& values = saml1attr->getAttributeValues();
-                v = values.begin();
-                stop = values.end();
+                valrange = valueRange(request, values);
                 if (log.isDebugEnabled()) {
                     auto_ptr_char n(saml1attr->getAttributeName());
                     log.debug(
@@ -107,23 +115,22 @@ shibsp::Attribute* ScopedAttributeDecoder::decode(
             }
             else {
                 log.warn("XMLObject type not recognized by ScopedAttributeDecoder, no values returned");
-                return NULL;
+                return nullptr;
             }
         }
 
-        for (; v!=stop; ++v) {
-            if (!(*v)->hasChildren()) {
-                val = toUTF8((*v)->getTextContent());
+        for (; valrange.first != valrange.second; ++valrange.first) {
+            if (!(*valrange.first)->hasChildren()) {
+                val = toUTF8((*valrange.first)->getTextContent());
                 if (val && *val) {
-                    const AttributeExtensibleXMLObject* aexo=dynamic_cast<const AttributeExtensibleXMLObject*>(*v);
-                    xmlscope = aexo->getAttribute(scopeqname);
+                    const AttributeExtensibleXMLObject* aexo=dynamic_cast<const AttributeExtensibleXMLObject*>(*valrange.first);
+                    xmlscope = aexo ? aexo->getAttribute(scopeqname) : nullptr;
                     if (xmlscope && *xmlscope) {
-                        scope = toUTF8(xmlscope);
-                        dest.push_back(pair<string,string>(val,scope));
-                        delete[] scope;
+                        auto_arrayptr<char> noninlinescope(toUTF8(xmlscope));
+                        dest.push_back(pair<string,string>(val,noninlinescope.get()));
                     }
                     else {
-                        scope = strchr(val, m_delimeter);
+                        scope = strchr(val, m_delimiter);
                         if (scope) {
                             *scope++ = 0;
                             if (*scope)
@@ -146,7 +153,7 @@ shibsp::Attribute* ScopedAttributeDecoder::decode(
             }
         }
 
-        return dest.empty() ? NULL : scoped.release();
+        return dest.empty() ? nullptr : _decode(scoped.release());
     }
 
     const NameID* saml2name = dynamic_cast<const NameID*>(xmlObject);
@@ -171,12 +178,12 @@ shibsp::Attribute* ScopedAttributeDecoder::decode(
         }
         else {
             log.warn("XMLObject type not recognized by ScopedAttributeDecoder, no values returned");
-            return NULL;
+            return nullptr;
         }
     }
 
-    if (val && *val && *val!=m_delimeter) {
-        scope = strchr(val, m_delimeter);
+    if (val && *val && *val != m_delimiter) {
+        scope = strchr(val, m_delimiter);
         if (scope) {
             *scope++ = 0;
             if (*scope)
@@ -185,12 +192,12 @@ shibsp::Attribute* ScopedAttributeDecoder::decode(
                 log.warn("ignoring NameID with no scope");
         }
         else {
-            log.warn("ignoring NameID with no scope delimiter (%c)", m_delimeter);
+            log.warn("ignoring NameID with no scope delimiter (%c)", m_delimiter);
         }
     }
     else {
         log.warn("ignoring empty NameID");
     }
     delete[] val;
-    return dest.empty() ? NULL : scoped.release();
+    return dest.empty() ? nullptr : _decode(scoped.release());
 }