Backport fixes from main branch and rev version.
[shibboleth/cpp-sp.git] / shibsp / attribute / filtering / impl / AttributeValueStringFunctor.cpp
index 16b2725..d29a403 100644 (file)
 #include "attribute/filtering/FilterPolicyContext.h"
 #include "attribute/filtering/MatchFunctor.h"
 
+#include <xmltooling/util/XMLHelper.h>
+
 using namespace shibsp;
 using namespace std;
+using xmltooling::XMLHelper;
 
 namespace shibsp {
 
@@ -42,7 +45,7 @@ namespace shibsp {
      */
     class SHIBSP_DLLLOCAL AttributeValueStringFunctor : public MatchFunctor
     {
-        xmltooling::auto_ptr_char m_attributeID;
+        string m_attributeID;
         char* m_value;
 
         bool hasValue(const FilteringContext& filterContext) const;
@@ -50,7 +53,8 @@ namespace shibsp {
 
     public:
         AttributeValueStringFunctor(const DOMElement* e)
-            : m_value(e ? xmltooling::toUTF8(e->getAttributeNS(nullptr,value)) : nullptr), m_attributeID(e ? e->getAttributeNS(nullptr,attributeID) : nullptr) {
+               : m_attributeID(XMLHelper::getAttrString(e, nullptr, attributeID)),
+                 m_value(e ? xmltooling::toUTF8(e->getAttributeNS(nullptr,value)) : nullptr) {
             if (!m_value || !*m_value) {
                 delete[] m_value;
                 throw ConfigurationException("AttributeValueString MatchFunctor requires non-empty value attribute.");
@@ -67,13 +71,13 @@ namespace shibsp {
         }
 
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
-            if (!m_attributeID.get() || !*m_attributeID.get())
+            if (m_attributeID.empty())
                 throw AttributeFilteringException("No attributeID specified.");
             return hasValue(filterContext);
         }
 
         bool evaluatePermitValue(const FilteringContext& filterContext, const Attribute& attribute, size_t index) const {
-            if (!m_attributeID.get() || !*m_attributeID.get() || XMLString::equals(m_attributeID.get(), attribute.getId()))
+            if (m_attributeID.empty() || m_attributeID == attribute.getId())
                 return matches(attribute, index);
             return hasValue(filterContext);
         }
@@ -90,7 +94,7 @@ bool AttributeValueStringFunctor::hasValue(const FilteringContext& filterContext
 {
     size_t count;
     pair<multimap<string,Attribute*>::const_iterator,multimap<string,Attribute*>::const_iterator> attrs =
-        filterContext.getAttributes().equal_range(m_attributeID.get());
+        filterContext.getAttributes().equal_range(m_attributeID);
     for (; attrs.first != attrs.second; ++attrs.first) {
         count = attrs.first->second->valueCount();
         for (size_t index = 0; index < count; ++index) {