Fix use of temp object in tokenizer
[shibboleth/cpp-xmltooling.git] / xmltooling / util / ParserPool.cpp
index 6a4700d..ca155ca 100644 (file)
@@ -39,6 +39,7 @@
 #include <functional>
 #include <boost/algorithm/string.hpp>
 #include <boost/bind.hpp>
+#include <boost/tokenizer.hpp>
 #include <xercesc/util/PlatformUtils.hpp>
 #include <xercesc/util/XMLUniDefs.hpp>
 #include <xercesc/sax/SAXException.hpp>
@@ -236,6 +237,19 @@ bool ParserPool::loadSchema(const XMLCh* nsURI, const XMLCh* pathname)
     return true;
 }
 
+bool ParserPool::loadCatalogs(const char* pathnames)
+{
+    string temp(pathnames);
+    boost::tokenizer< char_separator<char> > catpaths(temp, char_separator<char>(PATH_SEPARATOR_STR));
+    for_each(
+        catpaths.begin(), catpaths.end(),
+        // Call loadCatalog with an inner call to s->c_str() on each entry.
+        boost::bind(static_cast<bool (ParserPool::*)(const char*)>(&ParserPool::loadCatalog),
+            boost::ref(this), boost::bind(&string::c_str, _1))
+        );
+    return catpaths.begin() != catpaths.end();
+}
+
 bool ParserPool::loadCatalog(const char* pathname)
 {
     auto_ptr_XMLCh temp(pathname);
@@ -325,6 +339,7 @@ DOMInputSource* ParserPool::resolveEntity(
 #endif
     if (!systemId)
         return nullptr;
+    xstring sysId(systemId);
 
     Category& log=Category::getInstance(XMLTOOLING_LOGCAT".ParserPool");
     if (log.isDebugEnabled()) {
@@ -334,14 +349,15 @@ DOMInputSource* ParserPool::resolveEntity(
     }
 
     // Find well-known schemas in the specified location.
-    map<xstring,xstring>::const_iterator i = m_schemaLocMap.find(systemId);
+    map<xstring,xstring>::const_iterator i = m_schemaLocMap.find(sysId);
     if (i != m_schemaLocMap.end())
         return new Wrapper4InputSource(new LocalFileInputSource(baseURI, i->second.c_str()));
 
     // Check for entity as a suffix of a value in the map.
+    bool (*p_ends_with)(const xstring&, const xstring&) = ends_with;
     i = find_if(
         m_schemaLocMap.begin(), m_schemaLocMap.end(),
-        boost::bind(ends_with<const xstring&,const xstring&>, boost::bind(&map<xstring,xstring>::value_type::second, _1), systemId)
+        boost::bind(p_ends_with, boost::bind(&map<xstring,xstring>::value_type::second, _1), boost::ref(sysId))
         );
     if (i != m_schemaLocMap.end())
         return new Wrapper4InputSource(new LocalFileInputSource(baseURI, i->second.c_str()));