Imported Upstream version 2.1.dfsg1
[shibboleth/sp.git] / shibsp / attribute / filtering / impl / AttributeValueStringFunctor.cpp
index 0c2739c..707f318 100644 (file)
@@ -33,23 +33,35 @@ namespace shibsp {
 
     static const XMLCh attributeID[] =  UNICODE_LITERAL_11(a,t,t,r,i,b,u,t,e,I,D);
     static const XMLCh value[] =        UNICODE_LITERAL_5(v,a,l,u,e);
+    static const XMLCh ignoreCase[] =   UNICODE_LITERAL_10(i,g,n,o,r,e,C,a,s,e);
 
     /**
      * A match function that matches the value of an attribute against the specified value.
      */
     class SHIBSP_DLLLOCAL AttributeValueStringFunctor : public MatchFunctor
     {
-        xmltooling::auto_ptr_char m_value;
         xmltooling::auto_ptr_char m_attributeID;
+        char* m_value;
 
         bool hasValue(const FilteringContext& filterContext) const;
         bool matches(const Attribute& attribute, size_t index) const;
 
     public:
         AttributeValueStringFunctor(const DOMElement* e)
-            : m_value(e ? e->getAttributeNS(NULL,value) : NULL), m_attributeID(e ? e->getAttributeNS(NULL,attributeID) : NULL) {
-            if (!m_value.get() || !*m_value.get())
+            : m_value(e ? xmltooling::toUTF8(e->getAttributeNS(NULL,value)) : NULL), m_attributeID(e ? e->getAttributeNS(NULL,attributeID) : NULL) {
+            if (!m_value || !*m_value) {
+                delete[] m_value;
                 throw ConfigurationException("AttributeValueString MatchFunctor requires non-empty value attribute.");
+            }
+            if (e && e->hasAttributeNS(NULL,ignoreCase)) {
+                xmltooling::logging::Category::getInstance(SHIBSP_LOGCAT".AttributeFilter").warn(
+                    "ignoreCase property ignored by AttributeValueString MatchFunctor in favor of attribute's caseSensitive property"
+                    );
+            }
+        }
+
+        virtual ~AttributeValueStringFunctor() {
+            delete[] m_value;
         }
 
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
@@ -93,11 +105,11 @@ bool AttributeValueStringFunctor::matches(const Attribute& attribute, size_t ind
     if (!val)
         return false;
     if (attribute.isCaseSensitive())
-        return !strcmp(m_value.get(), val);
+        return !strcmp(m_value, val);
 
 #ifdef HAVE_STRCASECMP
-    return !strcasecmp(m_value.get(), val);
+    return !strcasecmp(m_value, val);
 #else
-    return !stricmp(m_value.get(), val);
+    return !stricmp(m_value, val);
 #endif
 }