Change license header.
[shibboleth/cpp-sp.git] / shibsp / attribute / filtering / impl / NumberOfAttributeValuesFunctor.cpp
index 91d1106..0053ab6 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2007 Internet2
- * 
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
+/**
+ * Licensed to the University Corporation for Advanced Internet
+ * Development, Inc. (UCAID) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for
+ * additional information regarding copyright ownership.
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * UCAID licenses this file to you under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the
+ * License at
  *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
+ * either express or implied. See the License for the specific
+ * language governing permissions and limitations under the License.
  */
 
 /**
 #include "attribute/Attribute.h"
 #include "attribute/filtering/FilteringContext.h"
 #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 {
 
@@ -43,21 +51,17 @@ namespace shibsp {
     class SHIBSP_DLLLOCAL NumberOfAttributeValuesFunctor : public MatchFunctor
     {
         unsigned int m_min,m_max;
-        xmltooling::auto_ptr_char m_attributeID;
+        string m_attributeID;
 
         size_t count(const FilteringContext& filterContext) const;
 
     public:
         NumberOfAttributeValuesFunctor(const DOMElement* e)
-                : m_min(0), m_max(INT_MAX), m_attributeID(e ? e->getAttributeNS(NULL,attributeID) : NULL) {
-            if (!m_attributeID.get() || !*m_attributeID.get())
+            : m_min(XMLHelper::getAttrInt(e, 0, minimum)),
+                m_max(XMLHelper::getAttrInt(e, INT_MAX, maximum)),
+                m_attributeID(XMLHelper::getAttrString(e, nullptr, attributeID)) {
+            if (m_attributeID.empty())
                 throw ConfigurationException("No attributeID specified.");
-            const XMLCh* num = e->getAttributeNS(NULL, minimum);
-            if (num && *num)
-                m_min = XMLString::parseInt(num);
-            num = e->getAttributeNS(NULL, maximum);
-            if (num && *num)
-                m_max = XMLString::parseInt(num);
         }
 
         bool evaluatePolicyRequirement(const FilteringContext& filterContext) const {
@@ -82,7 +86,7 @@ size_t NumberOfAttributeValuesFunctor::count(const FilteringContext& filterConte
 {
     size_t count = 0;
     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();
     return count;