Remove inline dummy credential resolver.
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.cpp
index 34d82f6..f257b8c 100644 (file)
@@ -1,17 +1,21 @@
-/*
- *  Copyright 2001-2010 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.
+ *
+ * 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.
  */
 
 /**
@@ -119,9 +123,9 @@ XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
     return nullptr;
 }
 
-void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, set<xstring>& prefixes)
+void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
 {
-    set<xstring> child_prefixes;
+    map<xstring,xstring> child_prefixes;
     const list<XMLObject*>& children = tree.getOrderedChildren();
     for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
         if (*i)
@@ -136,13 +140,26 @@ void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, set<xstring>& p
             case Namespace::Indeterminate:
                 break;
             case Namespace::VisiblyUsed:
-                child_prefixes.erase(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+            {
+                // See if the prefix was noted as non-visible below.
+                const XMLCh* p = ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull;
+                map<xstring,xstring>::iterator decl = child_prefixes.find(p);
+                if (decl != child_prefixes.end()) {
+                    // It's declared below, see if it's the same namespace. If so, pull it from the set,
+                    // otherwise leave it in the set.
+                    if (decl->second == (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull))
+                        child_prefixes.erase(decl);
+                }
                 break;
+            }
             case Namespace::NonVisiblyUsed:
-                prefixes.insert(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+                // It may already be in the map from another branch of the tree, but as long
+                // as it's set to something so the parent knows about it, we're good.
+                prefixes[ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull] = (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull);
                 break;
         }
     }
+
     prefixes.insert(child_prefixes.begin(), child_prefixes.end());
 }
 
@@ -163,9 +180,12 @@ xmltooling::QName* XMLHelper::getNodeValueAsQName(const DOMNode* domNode)
     if (!domNode)
         return nullptr;
     
-    int i;
     const XMLCh* value=domNode->getTextContent();
-    if (value && (i=XMLString::indexOf(value,chColon))>0) {
+    if (!value || !*value)
+        return nullptr;
+
+    int i;
+    if ((i=XMLString::indexOf(value,chColon))>0) {
         XMLCh* prefix=new XMLCh[i+1];
         XMLString::subString(prefix,value,0,i);
         prefix[i]=chNull;