#endif
#include <stdexcept>
-#include <boost/algorithm/string.hpp>
#include <boost/bind.hpp>
#include <boost/ptr_container/ptr_vector.hpp>
+#include <boost/tokenizer.hpp>
#if defined(XMLTOOLING_LOG4SHIB)
# include <log4shib/PropertyConfigurator.hh>
// Load catalogs from path.
if (!catalog_path.empty()) {
- vector<string> catpaths;
- split(catpaths, catalog_path, is_any_of(PATH_SEPARATOR_STR), algorithm::token_compress_on);
+ boost::tokenizer< char_separator<char> > catpaths(catalog_path, 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), m_validatingPool, boost::bind(&string::c_str,_1))
+ boost::bind(static_cast<bool (ParserPool::*)(const char*)>(&ParserPool::loadCatalog),
+ m_validatingPool, boost::bind(&string::c_str,_1))
);
}
#include "util/Threads.h"
#include "util/XMLHelper.h"
-#include <algorithm>
-#include <functional>
#include <sys/types.h>
#include <sys/stat.h>
+#include <algorithm>
+#include <functional>
+#include <boost/algorithm/string.hpp>
+#include <boost/bind.hpp>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/sax/SAXException.hpp>
using namespace xmltooling::logging;
using namespace xmltooling;
using namespace xercesc;
+using namespace boost;
using namespace std;
m_pool.top()->release();
m_pool.pop();
}
- delete m_lock;
- delete m_security;
}
DOMDocument* ParserPool::newDocument()
}
// Functor to double its argument separated by a character and append to a buffer
-template <class T> class doubleit
-{
+template <class T> class doubleit {
public:
doubleit(T& t, const typename T::value_type& s) : temp(t), sep(s) {}
void operator() (const pair<const T,T>& s) { temp += s.first + sep + s.first + sep; }
return false;
}
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
m_schemaLocMap[nsURI]=pathname;
m_schemaLocations.erase();
- for_each(m_schemaLocMap.begin(),m_schemaLocMap.end(),doubleit<xstring>(m_schemaLocations,chSpace));
+ for_each(m_schemaLocMap.begin(), m_schemaLocMap.end(), doubleit<xstring>(m_schemaLocations,chSpace));
return true;
}
// Fetch all the <system> elements.
DOMNodeList* mappings=root->getElementsByTagNameNS(CATALOG_NS,system);
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
for (XMLSize_t i=0; i<mappings->getLength(); i++) {
root=static_cast<DOMElement*>(mappings->item(i));
const XMLCh* from=root->getAttributeNS(nullptr,systemId);
m_schemaLocMap[from]=to;
}
m_schemaLocations.erase();
- for_each(m_schemaLocMap.begin(),m_schemaLocMap.end(),doubleit<xstring>(m_schemaLocations,chSpace));
+ for_each(m_schemaLocMap.begin(), m_schemaLocMap.end(), doubleit<xstring>(m_schemaLocations,chSpace));
}
- catch (exception& e) {
+ catch (std::exception& e) {
log.error("catalog loader caught exception: %s", e.what());
return false;
}
}
// Find well-known schemas in the specified location.
- map<xstring,xstring>::const_iterator i=m_schemaLocMap.find(systemId);
- if (i!=m_schemaLocMap.end())
- return new Wrapper4InputSource(new LocalFileInputSource(baseURI,i->second.c_str()));
-
- // Check for entity as a value in the map.
- for (i=m_schemaLocMap.begin(); i!=m_schemaLocMap.end(); ++i) {
- if (XMLString::endsWith(i->second.c_str(), systemId))
- return new Wrapper4InputSource(new LocalFileInputSource(baseURI,i->second.c_str()));
- }
+ map<xstring,xstring>::const_iterator i = m_schemaLocMap.find(systemId);
+ 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.
+ 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)
+ );
+ if (i != m_schemaLocMap.end())
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI, i->second.c_str()));
// We'll allow anything without embedded slashes.
- if (XMLString::indexOf(systemId, chForwardSlash)==-1)
- return new Wrapper4InputSource(new LocalFileInputSource(baseURI,systemId));
+ if (XMLString::indexOf(systemId, chForwardSlash) == -1 && XMLString::indexOf(systemId, chBackSlash) == -1)
+ return new Wrapper4InputSource(new LocalFileInputSource(baseURI, systemId));
// Shortcircuit the request.
auto_ptr_char temp(systemId);
log.debug("unauthorized entity request (%s), blocking it", temp.get());
static const XMLByte nullbuf[] = {0};
- return new Wrapper4InputSource(new MemBufInputSource(nullbuf,0,systemId));
+ return new Wrapper4InputSource(new MemBufInputSource(nullbuf, 0, systemId));
}
#ifdef XMLTOOLING_XERCESC_COMPLIANT_DOMLS
parser->getDomConfig()->setParameter(XMLUni::fgXercesUserAdoptsDOMDocument, true);
parser->getDomConfig()->setParameter(XMLUni::fgXercesDisableDefaultEntityResolution, true);
parser->getDomConfig()->setParameter(XMLUni::fgDOMResourceResolver, dynamic_cast<DOMLSResourceResolver*>(this));
- parser->getDomConfig()->setParameter(XMLUni::fgXercesSecurityManager, m_security);
+ parser->getDomConfig()->setParameter(XMLUni::fgXercesSecurityManager, m_security.get());
return parser;
}
DOMLSParser* ParserPool::checkoutBuilder()
{
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
if (m_pool.empty()) {
DOMLSParser* builder=createBuilder();
return builder;
void ParserPool::checkinBuilder(DOMLSParser* builder)
{
if (builder) {
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
m_pool.push(builder);
}
}
// This ensures the entity resolver will be given the namespace as a systemId it can check.
parser->setProperty(XMLUni::fgXercesSchemaExternalSchemaLocation,const_cast<XMLCh*>(m_schemaLocations.c_str()));
}
- parser->setProperty(XMLUni::fgXercesSecurityManager, m_security);
+ parser->setProperty(XMLUni::fgXercesSecurityManager, m_security.get());
parser->setFeature(XMLUni::fgXercesUserAdoptsDOMDocument, true);
parser->setFeature(XMLUni::fgXercesDisableDefaultEntityResolution, true);
parser->setEntityResolver(this);
DOMBuilder* ParserPool::checkoutBuilder()
{
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
if (m_pool.empty()) {
DOMBuilder* builder=createBuilder();
return builder;
void ParserPool::checkinBuilder(DOMBuilder* builder)
{
if (builder) {
- Lock lock(m_lock);
+ Lock lock(m_lock.get());
m_pool.push(builder);
}
}
#include "io/GenericRequest.h"
#include "util/TemplateEngine.h"
+#include <boost/algorithm/string/trim.hpp>
+
using namespace xmltooling;
using namespace std;
+using boost::trim;
namespace {
static const pair<const string,string> emptyPair;
}
}
-void TemplateEngine::trimspace(string& s) const
-{
- string::size_type end = s.size() - 1, start = 0;
-
- // Trim stuff on right.
- while (end > 0 && !isgraph(s[end])) end--;
-
- // Trim stuff on left.
- while (start < end && !isgraph(s[start])) start++;
-
- // Modify the string.
- s = s.substr(start, end - start + 1);
-}
-
void TemplateEngine::process(
bool visible,
const string& buf,
const char*& lastpos,
ostream& os,
const TemplateParameters& parameters,
- const std::pair<const std::string,std::string>& loopentry,
+ const pair<const string,string>& loopentry,
const XMLToolingException* e
) const
{
// search for the end-tag
if ((thispos = strstr(lastpos, "/>")) != nullptr) {
string key = buf.substr(lastpos-line, thispos-lastpos);
- trimspace(key);
+ trim(key);
if (key == "$name" && !loopentry.first.empty())
html_encode(os,loopentry.first.c_str());
// search for the end of this tag
if ((thispos = strchr(lastpos, '>')) != nullptr) {
string key = buf.substr(lastpos-line, thispos-lastpos);
- trimspace(key);
+ trim(key);
bool cond=false;
if (visible)
cond = parameters.getParameter(key.c_str()) || (e && e->getProperty(key.c_str()));
// search for the end of this tag
if ((thispos = strchr(lastpos, '>')) != nullptr) {
string key = buf.substr(lastpos-line, thispos-lastpos);
- trimspace(key);
+ trim(key);
bool cond=visible;
if (visible)
cond = !(parameters.getParameter(key.c_str()) || (e && e->getProperty(key.c_str())));
// search for the end of this tag
if ((thispos = strchr(lastpos, '>')) != nullptr) {
key = buf.substr(lastpos-line, thispos-lastpos);
- trimspace(key);
+ trim(key);
lastpos = thispos + 1; // strlen(">")
}