Reducing header overuse, non-inlining selected methods (CPPOST-35).
[shibboleth/cpp-sp.git] / shibsp / attribute / filtering / impl / AttributeValueStringFunctor.cpp
index 815f901..7721fe8 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  Copyright 2001-2009 Internet2
  * 
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -25,6 +25,7 @@
 #include "attribute/Attribute.h"
 #include "attribute/filtering/FilteringContext.h"
 #include "attribute/filtering/FilterPolicyContext.h"
+#include "attribute/filtering/MatchFunctor.h"
 
 using namespace shibsp;
 using namespace std;
@@ -40,17 +41,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 +61,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 +106,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
 }