Improve property inheritance, first batch of SessionInitiators, rename providerId.
[shibboleth/sp.git] / shibsp / util / DOMPropertySet.cpp
index 5df582e..3f45ad6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2006 Internet2
+ *  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.
@@ -37,7 +37,7 @@ DOMPropertySet::~DOMPropertySet()
 {
     for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
         XMLString::release(&(i->second.first));
-    for_each(m_nested.begin(),m_nested.end(),xmltooling::cleanup_pair<string,DOMPropertySet>());
+    for_each(m_nested.begin(),m_nested.end(),cleanup_pair<string,DOMPropertySet>());
 }
 
 void DOMPropertySet::load(
@@ -63,15 +63,19 @@ void DOMPropertySet::load(
             auto_ptr_char ns(a->getNamespaceURI());
             auto_ptr_char name(a->getLocalName());
             const char* realname=name.get();
+            map<string,string>::const_iterator remap;
             if (remapper) {
-                map<string,string>::const_iterator remap=remapper->find(realname);
+                remap=remapper->find(realname);
                 if (remap!=remapper->end()) {
                     log.warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
                     realname=remap->second.c_str();
                 }
             }
             if (ns.get()) {
-                m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
+                if (remapper && (remap=remapper->find(ns.get()))!=remapper->end())
+                    m_map[string("{") + remap->second.c_str() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
+                else
+                    m_map[string("{") + ns.get() + '}' + realname]=pair<char*,const XMLCh*>(val,a->getNodeValue());
                 log.debug("added property {%s}%s (%s)",ns.get(),realname,val);
             }
             else {
@@ -91,16 +95,21 @@ void DOMPropertySet::load(
         auto_ptr_char ns(e->getNamespaceURI());
         auto_ptr_char name(e->getLocalName());
         const char* realname=name.get();
+        map<string,string>::const_iterator remap;
         if (remapper) {
-            map<string,string>::const_iterator remap=remapper->find(realname);
+            remap=remapper->find(realname);
             if (remap!=remapper->end()) {
                 log.warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
                 realname=remap->second.c_str();
             }
         }
         string key;
-        if (ns.get())
-            key=string("{") + ns.get() + '}' + realname;
+        if (ns.get()) {
+            if (remapper && (remap=remapper->find(ns.get()))!=remapper->end())
+                key=string("{") + remap->second.c_str() + '}' + realname;
+            else
+                key=string("{") + ns.get() + '}' + realname;
+        }
         else
             key=realname;
         if (m_nested.find(key)!=m_nested.end())
@@ -118,7 +127,6 @@ void DOMPropertySet::load(
 
 pair<bool,bool> DOMPropertySet::getBool(const char* name, const char* ns) const
 {
-    pair<bool,bool> ret(false,false);
     map<string,pair<char*,const XMLCh*> >::const_iterator i;
 
     if (ns)
@@ -126,11 +134,11 @@ pair<bool,bool> DOMPropertySet::getBool(const char* name, const char* ns) const
     else
         i=m_map.find(name);
 
-    if (i!=m_map.end()) {
-        ret.first=true;
-        ret.second=(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1"));
-    }
-    return ret;
+    if (i!=m_map.end())
+        return make_pair(true,(!strcmp(i->second.first,"true") || !strcmp(i->second.first,"1")));
+    else if (m_parent)
+        return m_parent->getBool(name,ns);
+    return make_pair(false,false);
 }
 
 pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* ns) const
@@ -143,16 +151,15 @@ pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* n
     else
         i=m_map.find(name);
 
-    if (i!=m_map.end()) {
-        ret.first=true;
-        ret.second=i->second.first;
-    }
-    return ret;
+    if (i!=m_map.end())
+        return make_pair(true,i->second.first);
+    else if (m_parent)
+        return m_parent->getString(name,ns);
+    return pair<bool,const char*>(false,NULL);
 }
 
 pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const char* ns) const
 {
-    pair<bool,const XMLCh*> ret(false,NULL);
     map<string,pair<char*,const XMLCh*> >::const_iterator i;
 
     if (ns)
@@ -160,16 +167,15 @@ pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const cha
     else
         i=m_map.find(name);
 
-    if (i!=m_map.end()) {
-        ret.first=true;
-        ret.second=i->second.second;
-    }
-    return ret;
+    if (i!=m_map.end())
+        return make_pair(true,i->second.second);
+    else if (m_parent)
+        return m_parent->getXMLString(name,ns);
+    return pair<bool,const XMLCh*>(false,NULL);
 }
 
 pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const char* ns) const
 {
-    pair<bool,unsigned int> ret(false,0);
     map<string,pair<char*,const XMLCh*> >::const_iterator i;
 
     if (ns)
@@ -177,16 +183,15 @@ pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const c
     else
         i=m_map.find(name);
 
-    if (i!=m_map.end()) {
-        ret.first=true;
-        ret.second=strtol(i->second.first,NULL,10);
-    }
-    return ret;
+    if (i!=m_map.end())
+        return pair<bool,unsigned int>(true,strtol(i->second.first,NULL,10));
+    else if (m_parent)
+        return m_parent->getUnsignedInt(name,ns);
+    return pair<bool,unsigned int>(false,0);
 }
 
 pair<bool,int> DOMPropertySet::getInt(const char* name, const char* ns) const
 {
-    pair<bool,int> ret(false,0);
     map<string,pair<char*,const XMLCh*> >::const_iterator i;
 
     if (ns)
@@ -194,11 +199,11 @@ pair<bool,int> DOMPropertySet::getInt(const char* name, const char* ns) const
     else
         i=m_map.find(name);
 
-    if (i!=m_map.end()) {
-        ret.first=true;
-        ret.second=atoi(i->second.first);
-    }
-    return ret;
+    if (i!=m_map.end())
+        return pair<bool,int>(true,atoi(i->second.first));
+    else if (m_parent)
+        return m_parent->getInt(name,ns);
+    return pair<bool,int>(false,0);
 }
 
 const PropertySet* DOMPropertySet::getPropertySet(const char* name, const char* ns) const
@@ -210,5 +215,5 @@ const PropertySet* DOMPropertySet::getPropertySet(const char* name, const char*
     else
         i=m_nested.find(name);
 
-    return (i!=m_nested.end()) ? i->second : NULL;
+    return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : NULL);
 }