Add warning for policy mapping on older OpenSSL.
[shibboleth/cpp-xmltooling.git] / xmltooling / AbstractXMLObject.cpp
index 10d5844..33f6cd5 100644 (file)
@@ -1,17 +1,21 @@
-/*
-*  Copyright 2001-2010 Internet2
+/**
+ * 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.
  *
-* 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
+ * 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
  *
- *     http://www.apache.org/licenses/LICENSE-2.0
+ * 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.
+ * 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.
  */
 
 /**
@@ -130,24 +134,31 @@ void XMLObject::setNil(const XMLCh* value)
 
 void AbstractXMLObject::addNamespace(const Namespace& ns) const
 {
-    std::set<Namespace>::iterator i = m_namespaces.find(ns);
-    if (i == m_namespaces.end())
-        m_namespaces.insert(ns);
-    else {
-        if (ns.alwaysDeclare())
-            const_cast<Namespace&>(*i).setAlwaysDeclare(true);
-        switch (ns.usage()) {
-            case Namespace::Indeterminate:
-                break;
-            case Namespace::VisiblyUsed:
-                const_cast<Namespace&>(*i).setUsage(Namespace::VisiblyUsed);
-                break;
-            case Namespace::NonVisiblyUsed:
-                if (i->usage() == Namespace::Indeterminate)
-                    const_cast<Namespace&>(*i).setUsage(Namespace::NonVisiblyUsed);
-                break;
+    for (set<Namespace>::const_iterator n = m_namespaces.begin(); n != m_namespaces.end(); ++n) {
+        // Look for the prefix in the existing set.
+        if (XMLString::equals(ns.getNamespacePrefix(), n->getNamespacePrefix())) {
+            // See if it's the same declaration, and overlay various properties if so.
+            if (XMLString::equals(ns.getNamespaceURI(), n->getNamespaceURI())) {
+                if (ns.alwaysDeclare())
+                    const_cast<Namespace&>(*n).setAlwaysDeclare(true);
+                switch (ns.usage()) {
+                    case Namespace::Indeterminate:
+                        break;
+                    case Namespace::VisiblyUsed:
+                        const_cast<Namespace&>(*n).setUsage(Namespace::VisiblyUsed);
+                        break;
+                    case Namespace::NonVisiblyUsed:
+                        if (n->usage() == Namespace::Indeterminate)
+                            const_cast<Namespace&>(*n).setUsage(Namespace::NonVisiblyUsed);
+                        break;
+                }
+            }
+            return;
         }
     }
+
+    // If the prefix is now, go ahead and add it.
+    m_namespaces.insert(ns);
 }
 
 void AbstractXMLObject::removeNamespace(const Namespace& ns)