Imported Upstream version 2.4+dfsg
[shibboleth/sp.git] / shibsp / util / DOMPropertySet.cpp
index f2cb41a..2c7f64b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2007 Internet2
+ *  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.
@@ -32,6 +32,18 @@ using namespace xmltooling;
 using namespace xercesc;
 using namespace std;
 
+PropertySet::PropertySet()
+{
+}
+
+PropertySet::~PropertySet()
+{
+}
+
+DOMPropertySet::DOMPropertySet() : m_parent(nullptr), m_root(nullptr)
+{
+}
+
 DOMPropertySet::~DOMPropertySet()
 {
     for (map<string,pair<char*,const XMLCh*> >::iterator i=m_map.begin(); i!=m_map.end(); i++)
@@ -39,6 +51,21 @@ DOMPropertySet::~DOMPropertySet()
     for_each(m_nested.begin(),m_nested.end(),cleanup_pair<string,DOMPropertySet>());
 }
 
+const PropertySet* DOMPropertySet::getParent() const
+{
+    return m_parent;
+}
+
+void DOMPropertySet::setParent(const PropertySet* parent)
+{
+    m_parent = parent;
+}
+
+const DOMElement* DOMPropertySet::getElement() const
+{
+    return m_root;
+}
+
 void DOMPropertySet::load(
     const DOMElement* e,
     Category* log,
@@ -70,7 +97,7 @@ void DOMPropertySet::load(
             if (remapper) {
                 remap=remapper->find(realname);
                 if (remap!=remapper->end()) {
-                    log->warn("remapping property (%s) to (%s)",realname,remap->second.c_str());
+                    log->warn("deprecation - remapping property (%s) to (%s)",realname,remap->second.c_str());
                     realname=remap->second.c_str();
                 }
             }
@@ -102,7 +129,7 @@ void DOMPropertySet::load(
         if (remapper) {
             remap=remapper->find(realname);
             if (remap!=remapper->end()) {
-                log->warn("remapping property set (%s) to (%s)",realname,remap->second.c_str());
+                log->warn("deprecation - remapping nested property set (%s) to (%s)",realname,remap->second.c_str());
                 realname=remap->second.c_str();
             }
         }
@@ -146,7 +173,7 @@ pair<bool,bool> DOMPropertySet::getBool(const char* name, const char* ns) const
 
 pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* ns) const
 {
-    pair<bool,const char*> ret(false,NULL);
+    pair<bool,const char*> ret(false,nullptr);
     map<string,pair<char*,const XMLCh*> >::const_iterator i;
 
     if (ns)
@@ -158,7 +185,7 @@ pair<bool,const char*> DOMPropertySet::getString(const char* name, const char* n
         return pair<bool,const char*>(true,i->second.first);
     else if (m_parent)
         return m_parent->getString(name,ns);
-    return pair<bool,const char*>(false,NULL);
+    return pair<bool,const char*>(false,nullptr);
 }
 
 pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const char* ns) const
@@ -174,7 +201,7 @@ pair<bool,const XMLCh*> DOMPropertySet::getXMLString(const char* name, const cha
         return make_pair(true,i->second.second);
     else if (m_parent)
         return m_parent->getXMLString(name,ns);
-    return pair<bool,const XMLCh*>(false,NULL);
+    return pair<bool,const XMLCh*>(false,nullptr);
 }
 
 pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const char* ns) const
@@ -187,7 +214,7 @@ pair<bool,unsigned int> DOMPropertySet::getUnsignedInt(const char* name, const c
         i=m_map.find(name);
 
     if (i!=m_map.end())
-        return pair<bool,unsigned int>(true,strtol(i->second.first,NULL,10));
+        return pair<bool,unsigned int>(true,strtol(i->second.first,nullptr,10));
     else if (m_parent)
         return m_parent->getUnsignedInt(name,ns);
     return pair<bool,unsigned int>(false,0);
@@ -226,5 +253,23 @@ const PropertySet* DOMPropertySet::getPropertySet(const char* name, const char*
     else
         i=m_nested.find(name);
 
-    return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : NULL);
+    return (i!=m_nested.end()) ? i->second : (m_parent ? m_parent->getPropertySet(name,ns) : nullptr);
+}
+
+bool DOMPropertySet::setProperty(const char* name, const char* val, const char* ns)
+{
+    string propname = ns ? (string("{") + ns + "}" + name) : name;
+
+    // Erase existing property.
+    if (m_map.count(propname) > 0) {
+        XMLString::release(&m_map[propname].first);
+        m_map.erase(propname);
+    }
+
+    char* dup = XMLString::replicate(val);
+    auto_ptr_XMLCh widedup(val);
+    m_injected.push_back(widedup.get());
+    m_map[propname] = make_pair(dup, m_injected.back().c_str());
+
+    return true;
 }