https://bugs.internet2.edu/jira/browse/SSPCPP-125
authorcantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 23 Jul 2008 18:20:35 +0000 (18:20 +0000)
committercantor <cantor@cb58f699-b61c-0410-a6fe-9272a202ed29>
Wed, 23 Jul 2008 18:20:35 +0000 (18:20 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-sp/branches/REL_2@2856 cb58f699-b61c-0410-a6fe-9272a202ed29

shibsp/attribute/filtering/impl/AttributeScopeStringFunctor.cpp
shibsp/attribute/filtering/impl/AttributeValueStringFunctor.cpp

index 48b99d0..14a1bb1 100644 (file)
@@ -40,21 +40,27 @@ namespace shibsp {
      */
     class SHIBSP_DLLLOCAL AttributeScopeStringFunctor : public MatchFunctor
     {
-        xmltooling::auto_ptr_char m_value;
         xmltooling::auto_ptr_char m_attributeID;
+        char* m_value;
         bool m_ignoreCase;
 
         bool hasScope(const FilteringContext& filterContext) const;
 
     public:
         AttributeScopeStringFunctor(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("AttributeScopeString MatchFunctor requires non-empty value attribute.");
+            }
             const XMLCh* flag = e ? e->getAttributeNS(NULL,ignoreCase) : NULL;
             m_ignoreCase = (flag && (*flag == chLatin_t || *flag == chDigit_1)); 
         }
 
+        virtual ~AttributeScopeStringFunctor() {
+            delete[] m_value;
+        }
+
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
             if (!m_attributeID.get() || !*m_attributeID.get())
                 throw AttributeFilteringException("No attributeID specified.");
@@ -65,13 +71,13 @@ namespace shibsp {
             if (!m_attributeID.get() || !*m_attributeID.get() || XMLString::equals(m_attributeID.get(), attribute.getId())) {
                 if (m_ignoreCase) {
 #ifdef HAVE_STRCASECMP
-                    return !strcasecmp(attribute.getScope(index), m_value.get());
+                    return !strcasecmp(attribute.getScope(index), m_value);
 #else
-                    return !stricmp(attribute.getScope(index), m_value.get());
+                    return !stricmp(attribute.getScope(index), m_value);
 #endif
                 }
                 else
-                    return !strcmp(attribute.getScope(index), m_value.get());
+                    return !strcmp(attribute.getScope(index), m_value);
             }
             return hasScope(filterContext);
         }
@@ -94,15 +100,15 @@ bool AttributeScopeStringFunctor::hasScope(const FilteringContext& filterContext
         for (size_t index = 0; index < count; ++index) {
             if (m_ignoreCase) {
 #ifdef HAVE_STRCASECMP
-                if (!strcasecmp(attrs.first->second->getScope(index), m_value.get()))
+                if (!strcasecmp(attrs.first->second->getScope(index), m_value))
                     return true;
 #else
-                if (!stricmp(attrs.first->second->getScope(index), m_value.get()))
+                if (!stricmp(attrs.first->second->getScope(index), m_value))
                     return true;
 #endif
             }
             else {
-                if (!strcmp(attrs.first->second->getScope(index), m_value.get()))
+                if (!strcmp(attrs.first->second->getScope(index), m_value))
                     return true;
             }
         }
index 815f901..707f318 100644 (file)
@@ -40,17 +40,19 @@ namespace shibsp {
      */
     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"
@@ -58,6 +60,10 @@ namespace shibsp {
             }
         }
 
+        virtual ~AttributeValueStringFunctor() {
+            delete[] m_value;
+        }
+
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
             if (!m_attributeID.get() || !*m_attributeID.get())
                 throw AttributeFilteringException("No attributeID specified.");
@@ -99,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
 }