VS10 solution files, convert from NULL macro to nullptr.
[shibboleth/sp.git] / shibsp / attribute / filtering / impl / ChainingAttributeFilter.cpp
1 /*
2  *  Copyright 2001-2010 Internet2
3  * 
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * ChainingAttributeFilter.cpp
19  * 
20  * Chains together multiple AttributeFilter plugins.
21  */
22
23 #include "internal.h"
24 #include "attribute/filtering/AttributeFilter.h"
25 #include "attribute/filtering/FilteringContext.h"
26
27 #include <xercesc/util/XMLUniDefs.hpp>
28 #include <xmltooling/util/XMLHelper.h>
29
30 using namespace shibsp;
31 using namespace xmltooling;
32 using namespace std;
33
34 namespace shibsp {
35
36     class SHIBSP_DLLLOCAL ChainingAttributeFilter : public AttributeFilter
37     {
38     public:
39         ChainingAttributeFilter(const DOMElement* e);
40         virtual ~ChainingAttributeFilter() {
41             for_each(m_filters.begin(), m_filters.end(), xmltooling::cleanup<AttributeFilter>());
42         }
43         
44         Lockable* lock() {
45             return this;
46         }
47         void unlock() {
48         }
49         
50         void filterAttributes(const FilteringContext& context, vector<Attribute*>& attributes) const {
51             for (vector<AttributeFilter*>::const_iterator i=m_filters.begin(); i!=m_filters.end(); ++i) {
52                 Locker locker(*i);
53                 (*i)->filterAttributes(context, attributes);
54             }
55         }
56
57     private:
58         vector<AttributeFilter*> m_filters;
59     };
60
61     static const XMLCh _AttributeFilter[] = UNICODE_LITERAL_15(A,t,t,r,i,b,u,t,e,F,i,l,t,e,r);
62     static const XMLCh _type[] =            UNICODE_LITERAL_4(t,y,p,e);
63
64     AttributeFilter* SHIBSP_DLLLOCAL ChainingAttributeFilterFactory(const DOMElement* const & e)
65     {
66         return new ChainingAttributeFilter(e);
67     }
68 };
69
70 ChainingAttributeFilter::ChainingAttributeFilter(const DOMElement* e)
71 {
72     SPConfig& conf = SPConfig::getConfig();
73
74     // Load up the chain of handlers.
75     e = e ? XMLHelper::getFirstChildElement(e, _AttributeFilter) : nullptr;
76     while (e) {
77         auto_ptr_char type(e->getAttributeNS(nullptr,_type));
78         if (type.get() && *(type.get())) {
79             try {
80                 m_filters.push_back(conf.AttributeFilterManager.newPlugin(type.get(),e));
81             }
82             catch (exception& ex) {
83                 Category::getInstance(SHIBSP_LOGCAT".AttributeFilter").error(
84                     "caught exception processing embedded AttributeFilter element: %s", ex.what()
85                     );
86             }
87         }
88         e = XMLHelper::getNextSiblingElement(e, _AttributeFilter);
89     }
90 }