Merge commit '2.5.0' into moonshot-packaging-fixes
[shibboleth/sp.git] / shibsp / attribute / filtering / impl / AttributeValueRegexFunctor.cpp
index 39e77c6..b1315cd 100644 (file)
 #include "attribute/filtering/MatchFunctor.h"
 
 #include <xmltooling/util/XMLHelper.h>
-
 #include <xercesc/util/regx/RegularExpression.hpp>
 
 using namespace shibsp;
+using namespace xmltooling;
+using namespace boost;
 using namespace std;
-using xmltooling::XMLHelper;
 
 namespace shibsp {
 
@@ -52,19 +52,19 @@ namespace shibsp {
     class SHIBSP_DLLLOCAL AttributeValueRegexFunctor : public MatchFunctor
     {
         string m_attributeID;
-        RegularExpression* m_regex;
+        scoped_ptr<RegularExpression> m_regex;
 
         bool hasValue(const FilteringContext& filterContext) const;
         bool matches(const Attribute& attribute, size_t index) const;
 
     public:
         AttributeValueRegexFunctor(const DOMElement* e)
-                : m_attributeID(XMLHelper::getAttrString(e, nullptr, attributeID)), m_regex(nullptr) {
-            const XMLCh* r = e ? e->getAttributeNS(nullptr,regex) : nullptr;
+                : m_attributeID(XMLHelper::getAttrString(e, nullptr, attributeID)) {
+            const XMLCh* r = e ? e->getAttributeNS(nullptr, regex) : nullptr;
             if (!r || !*r)
                 throw ConfigurationException("AttributeValueRegex MatchFunctor requires non-empty regex attribute.");
             try {
-                m_regex = new RegularExpression(r, e->getAttributeNS(nullptr,options));
+                m_regex.reset(new RegularExpression(r, e->getAttributeNS(nullptr, options)));
             }
             catch (XMLException& ex) {
                 xmltooling::auto_ptr_char temp(ex.getMessage());
@@ -72,9 +72,7 @@ namespace shibsp {
             }
         }
 
-        virtual ~AttributeValueRegexFunctor() {
-            delete m_regex;
-        }
+        virtual ~AttributeValueRegexFunctor() {}
 
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
             if (m_attributeID.empty())
@@ -89,7 +87,7 @@ namespace shibsp {
         }
     };
 
-    MatchFunctor* SHIBSP_DLLLOCAL AttributeValueRegexFactory(const std::pair<const FilterPolicyContext*,const DOMElement*>& p)
+    MatchFunctor* SHIBSP_DLLLOCAL AttributeValueRegexFactory(const pair<const FilterPolicyContext*,const DOMElement*>& p)
     {
         return new AttributeValueRegexFunctor(p.second);
     }
@@ -116,8 +114,6 @@ bool AttributeValueRegexFunctor::matches(const Attribute& attribute, size_t inde
     const char* val = attribute.getString(index);
     if (!val)
         return false;
-    XMLCh* temp = xmltooling::fromUTF8(val);
-    bool ret = m_regex->matches(temp);
-    delete[] temp;
-    return ret;
+    auto_arrayptr<XMLCh> temp(fromUTF8(val));
+    return m_regex->matches(temp.get());
 }