#include <algorithm>
#include <functional>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
using namespace xmltooling;
+using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
using namespace std;
-using xercesc::chColon;
-using xercesc::DOMAttr;
-using xercesc::DOMElement;
-using xercesc::XMLString;
ElementExtensibleXMLObject::ElementExtensibleXMLObject()
{
{
}
-set<QName> AttributeExtensibleXMLObject::m_idAttributeSet;
+set<xmltooling::QName> AttributeExtensibleXMLObject::m_idAttributeSet;
AttributeExtensibleXMLObject::AttributeExtensibleXMLObject()
{
{
}
-const set<QName>& AttributeExtensibleXMLObject::getRegisteredIDAttributes()
+const set<xmltooling::QName>& AttributeExtensibleXMLObject::getRegisteredIDAttributes()
{
return m_idAttributeSet;
}
-bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const QName& name)
+bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const xmltooling::QName& name)
{
return m_idAttributeSet.find(name)!=m_idAttributeSet.end();
}
-void AttributeExtensibleXMLObject::registerIDAttribute(const QName& name)
+void AttributeExtensibleXMLObject::registerIDAttribute(const xmltooling::QName& name)
{
m_idAttributeSet.insert(name);
}
-void AttributeExtensibleXMLObject::deregisterIDAttribute(const QName& name)
+void AttributeExtensibleXMLObject::deregisterIDAttribute(const xmltooling::QName& name)
{
m_idAttributeSet.erase(name);
}
: AbstractXMLObject(src)
{
m_idAttribute = m_attributeMap.end();
- for (map<QName,XMLCh*>::const_iterator i=src.m_attributeMap.begin(); i!=src.m_attributeMap.end(); i++) {
+ for (map<xmltooling::QName,XMLCh*>::const_iterator i = src.m_attributeMap.begin(); i != src.m_attributeMap.end(); ++i) {
m_attributeMap[i->first] = XMLString::replicate(i->second);
}
if (src.m_idAttribute != src.m_attributeMap.end()) {
AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject()
{
- for (map<QName,XMLCh*>::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++)
- XMLString::release(&(i->second));
+ static void (*release)(XMLCh**,MemoryManager*) = &XMLString::release;
+ for_each(
+ m_attributeMap.begin(), m_attributeMap.end(),
+ lambda::bind(
+ release,
+ &lambda::bind(&map<xmltooling::QName,XMLCh*>::value_type::second, boost::ref(_1)),
+ XMLPlatformUtils::fgMemoryManager
+ )
+ );
}
-const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const QName& qualifiedName) const
+const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const xmltooling::QName& qualifiedName) const
{
- map<QName,XMLCh*>::const_iterator i=m_attributeMap.find(qualifiedName);
- return (i==m_attributeMap.end()) ? nullptr : i->second;
+ map<xmltooling::QName,XMLCh*>::const_iterator i = m_attributeMap.find(qualifiedName);
+ return (i != m_attributeMap.end()) ? i->second : nullptr;
}
-void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID)
+void AbstractAttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID)
{
- map<QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
- if (i!=m_attributeMap.end()) {
+ map<xmltooling::QName,XMLCh*>::iterator i=m_attributeMap.find(qualifiedName);
+ if (i != m_attributeMap.end()) {
releaseThisandParentDOM();
XMLString::release(&(i->second));
if (value && *value) {
- i->second=XMLString::replicate(value);
+ i->second = XMLString::replicate(value);
if (ID)
- m_idAttribute=i;
+ m_idAttribute = i;
}
else {
- if (m_idAttribute==i)
- m_idAttribute=m_attributeMap.end();
+ if (m_idAttribute == i)
+ m_idAttribute = m_attributeMap.end();
m_attributeMap.erase(i);
}
}
else if (value && *value) {
releaseThisandParentDOM();
- m_attributeMap[qualifiedName]=XMLString::replicate(value);
+ m_attributeMap[qualifiedName] = XMLString::replicate(value);
if (ID)
m_idAttribute = m_attributeMap.find(qualifiedName);
Namespace newNamespace(qualifiedName.getNamespaceURI(), qualifiedName.getPrefix(), false, Namespace::VisiblyUsed);
}
}
-void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const QName& value)
+void AttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const xmltooling::QName& value)
{
if (!value.hasLocalPart())
return;
addNamespace(newNamespace);
}
-const map<QName,XMLCh*>& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const
+const map<xmltooling::QName,XMLCh*>& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const
{
return m_attributeMap;
}
const XMLCh* AbstractAttributeExtensibleXMLObject::getXMLID() const
{
- return (m_idAttribute == m_attributeMap.end()) ? nullptr : m_idAttribute->second;
+ return (m_idAttribute != m_attributeMap.end()) ? m_idAttribute->second : nullptr;
}
void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute)
{
- QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix());
+ xmltooling::QName q(attribute->getNamespaceURI(), attribute->getLocalName(), attribute->getPrefix());
bool ID = attribute->isId() || isRegisteredIDAttribute(q);
setAttribute(q,attribute->getNodeValue(),ID);
if (ID) {
void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const
{
- for (map<QName,XMLCh*>::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) {
- DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart());
+ for (map<xmltooling::QName,XMLCh*>::const_iterator i = m_attributeMap.begin(); i != m_attributeMap.end(); ++i) {
+ DOMAttr* attr = domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(), i->first.getLocalPart());
if (i->first.hasPrefix())
attr->setPrefix(i->first.getPrefix());
attr->setNodeValue(i->second);
domElement->setAttributeNodeNS(attr);
- if (m_idAttribute==i) {
+ if (m_idAttribute == i) {
#ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE
domElement->setIdAttributeNode(attr, true);
#else
#include "AbstractComplexElement.h"
#include <algorithm>
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/lambda.hpp>
using namespace xmltooling;
+using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
using namespace std;
-using xercesc::XMLString;
-
-namespace {
- bool _nonnull(const XMLObject* ptr) {
- return (ptr!=nullptr);
- }
-}
AbstractComplexElement::AbstractComplexElement()
{
AbstractComplexElement::AbstractComplexElement(const AbstractComplexElement& src)
{
- for (vector<XMLCh*>::const_iterator i=src.m_text.begin(); i!=src.m_text.end(); ++i)
- m_text.push_back(XMLString::replicate(*i));
+ static void (vector<XMLCh*>::* push_back)(XMLCh* const&) = &vector<XMLCh*>::push_back;
+ static XMLCh* (*replicate)(const XMLCh*,MemoryManager*) = &XMLString::replicate;
+
+ for_each(
+ src.m_text.begin(), src.m_text.end(),
+ lambda::bind(push_back, boost::ref(m_text), lambda::bind(replicate, _1, XMLPlatformUtils::fgMemoryManager))
+ );
}
AbstractComplexElement::~AbstractComplexElement() {
+ static void (*release)(XMLCh**,MemoryManager*) = &XMLString::release;
+
for_each(m_children.begin(), m_children.end(), cleanup<XMLObject>());
- for (vector<XMLCh*>::iterator i=m_text.begin(); i!=m_text.end(); ++i)
- XMLString::release(&(*i));
+ for_each(m_text.begin(), m_text.end(), lambda::bind(release, &_1, XMLPlatformUtils::fgMemoryManager));
}
bool AbstractComplexElement::hasChildren() const
{
if (m_children.empty())
return false;
- return (find_if(m_children.begin(), m_children.end(), _nonnull) != m_children.end());
+ return (find_if(m_children.begin(), m_children.end(), (_1 != nullptr)) != m_children.end());
}
const list<XMLObject*>& AbstractComplexElement::getOrderedChildren() const
m_text.push_back(nullptr);
++size;
}
- m_text[position]=prepareForAssignment(m_text[position],value);
+ m_text[position] = prepareForAssignment(m_text[position], value);
}
AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)
: m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")),
m_schemaLocation(nullptr), m_noNamespaceSchemaLocation(nullptr), m_nil(xmlconstants::XML_BOOL_NULL),
- m_parent(nullptr), m_elementQname(nsURI, localName, prefix), m_typeQname(nullptr)
+ m_parent(nullptr), m_elementQname(nsURI, localName, prefix)
{
addNamespace(Namespace(nsURI, prefix, false, Namespace::VisiblyUsed));
if (schemaType) {
- m_typeQname = new QName(*schemaType);
+ m_typeQname.reset(new QName(*schemaType));
addNamespace(Namespace(m_typeQname->getNamespaceURI(), m_typeQname->getPrefix(), false, Namespace::NonVisiblyUsed));
}
}
AbstractXMLObject::AbstractXMLObject(const AbstractXMLObject& src)
: m_namespaces(src.m_namespaces), m_log(src.m_log), m_schemaLocation(XMLString::replicate(src.m_schemaLocation)),
m_noNamespaceSchemaLocation(XMLString::replicate(src.m_noNamespaceSchemaLocation)), m_nil(src.m_nil),
- m_parent(nullptr), m_elementQname(src.m_elementQname), m_typeQname(nullptr)
+ m_parent(nullptr), m_elementQname(src.m_elementQname),
+ m_typeQname(src.m_typeQname.get() ? new QName(*src.m_typeQname) : nullptr)
{
- if (src.m_typeQname)
- m_typeQname=new QName(*src.m_typeQname);
}
AbstractXMLObject::~AbstractXMLObject()
{
- delete m_typeQname;
xercesc::XMLString::release(&m_schemaLocation);
xercesc::XMLString::release(&m_noNamespaceSchemaLocation);
}
const QName* AbstractXMLObject::getSchemaType() const
{
- return m_typeQname;
+ return m_typeQname.get();
}
const XMLCh* AbstractXMLObject::getXMLID() const
private:
XMLObject* m_parent;
QName m_elementQname;
- QName* m_typeQname;
+ std::auto_ptr<QName> m_typeQname;
};
};
#include "util/XMLConstants.h"
#include "validation/ValidatorSuite.h"
+#include <boost/iterator/indirect_iterator.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xsec/dsig/DSIGKeyInfoX509.hpp>
#include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
using namespace xmltooling::logging;
using namespace xmltooling;
using namespace xercesc;
+using namespace boost;
using namespace std;
namespace xmltooling {
const XMLCh* n;
char* kn;
const vector<KeyName*>& knames=keyInfo->getKeyNames();
- for (vector<KeyName*>::const_iterator kn_i=knames.begin(); kn_i!=knames.end(); ++kn_i) {
- n=(*kn_i)->getName();
+ for (indirect_iterator<vector<KeyName*>::const_iterator> kn_i = make_indirect_iterator(knames.begin());
+ kn_i != make_indirect_iterator(knames.end()); ++kn_i) {
+ n = kn_i->getName();
if (n && *n) {
- kn=toUTF8(n);
+ kn = toUTF8(n);
m_keyNames.insert(kn);
delete[] kn;
}
// Check for ds:KeyValue
const vector<KeyValue*>& keyValues = keyInfo->getKeyValues();
- for (vector<KeyValue*>::const_iterator i = keyValues.begin(); i != keyValues.end(); ++i) {
+ for (indirect_iterator<vector<KeyValue*>::const_iterator> i = make_indirect_iterator(keyValues.begin());
+ i != make_indirect_iterator(keyValues.end()); ++i) {
try {
- SchemaValidators.validate(*i); // see if it's a "valid" key
- RSAKeyValue* rsakv = (*i)->getRSAKeyValue();
+ SchemaValidators.validate(*(i.base())); // see if it's a "valid" key
+ RSAKeyValue* rsakv = i->getRSAKeyValue();
if (rsakv) {
log.debug("resolving ds:RSAKeyValue");
auto_ptr_char mod(rsakv->getModulus()->getValue());
m_key = rsa.release();
return true;
}
- DSAKeyValue* dsakv = (*i)->getDSAKeyValue();
+ DSAKeyValue* dsakv = i->getDSAKeyValue();
if (dsakv) {
log.debug("resolving ds:DSAKeyValue");
auto_ptr<XSECCryptoKeyDSA> dsa(XSECPlatformUtils::g_cryptoProvider->keyDSA());
return true;
}
#ifdef XMLTOOLING_XMLSEC_ECC
- ECKeyValue* eckv = (*i)->getECKeyValue();
+ ECKeyValue* eckv = i->getECKeyValue();
if (eckv && eckv->getNamedCurve() && eckv->getPublicKey()) {
log.warn("resolving ds11:ECKeyValue");
auto_ptr<XSECCryptoKeyEC> ec(XSECPlatformUtils::g_cryptoProvider->keyEC());
// Check for ds11:DEREncodedKeyValue
const vector<DEREncodedKeyValue*>& derValues = keyInfo->getDEREncodedKeyValues();
- for (vector<DEREncodedKeyValue*>::const_iterator j = derValues.begin(); j != derValues.end(); ++j) {
+ for (indirect_iterator<vector<DEREncodedKeyValue*>::const_iterator> j = make_indirect_iterator(derValues.begin());
+ j != make_indirect_iterator(derValues.end()); ++j) {
log.debug("resolving ds11:DEREncodedKeyValue");
- m_key = SecurityHelper::fromDEREncoding((*j)->getValue());
+ m_key = SecurityHelper::fromDEREncoding(j->getValue());
if (m_key)
return true;
log.warn("failed to resolve ds11:DEREncodedKeyValue");
const XMLCh* fragID=nullptr;
const XMLObject* treeRoot=nullptr;
const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
- for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
- fragID = (*ref)->getURI();
+ for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+ ref != make_indirect_iterator(refs.end()); ++ref) {
+ fragID = ref->getURI();
if (!fragID || *fragID != chPound || !*(fragID+1)) {
log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
continue;
// Check for ds:X509Data
const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
- for (vector<X509Data*>::const_iterator j=x509Datas.begin(); m_xseccerts.empty() && j!=x509Datas.end(); ++j) {
+ for (vector<X509Data*>::const_iterator j = x509Datas.begin(); m_xseccerts.empty() && j != x509Datas.end(); ++j) {
const vector<X509Certificate*> x509Certs=const_cast<const X509Data*>(*j)->getX509Certificates();
- for (vector<X509Certificate*>::const_iterator k=x509Certs.begin(); k!=x509Certs.end(); ++k) {
+ for (indirect_iterator<vector<X509Certificate*>::const_iterator> k = make_indirect_iterator(x509Certs.begin());
+ k != make_indirect_iterator(x509Certs.end()); ++k) {
try {
- auto_ptr_char x((*k)->getValue());
+ auto_ptr_char x(k->getValue());
if (!x.get()) {
log.warn("skipping empty ds:X509Certificate");
}
const XMLCh* fragID=NULL;
const XMLObject* treeRoot=NULL;
const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
- for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
- fragID = (*ref)->getURI();
+ for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+ ref != make_indirect_iterator(refs.end()); ++ref) {
+ fragID = ref->getURI();
if (!fragID || *fragID != chPound || !*(fragID+1)) {
log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
continue;
const vector<X509Data*>& x509Datas=keyInfo->getX509Datas();
for (vector<X509Data*>::const_iterator j=x509Datas.begin(); j!=x509Datas.end(); ++j) {
const vector<X509CRL*> x509CRLs=const_cast<const X509Data*>(*j)->getX509CRLs();
- for (vector<X509CRL*>::const_iterator k=x509CRLs.begin(); k!=x509CRLs.end(); ++k) {
+ for (indirect_iterator<vector<X509CRL*>::const_iterator> k = make_indirect_iterator(x509CRLs.begin());
+ k != make_indirect_iterator(x509CRLs.end()); ++k) {
try {
- auto_ptr_char x((*k)->getValue());
+ auto_ptr_char x(k->getValue());
if (!x.get()) {
log.warn("skipping empty ds:X509CRL");
}
const XMLCh* fragID=NULL;
const XMLObject* treeRoot=NULL;
const vector<KeyInfoReference*>& refs = keyInfo->getKeyInfoReferences();
- for (vector<KeyInfoReference*>::const_iterator ref = refs.begin(); ref != refs.end(); ++ref) {
- fragID = (*ref)->getURI();
+ for (indirect_iterator<vector<KeyInfoReference*>::const_iterator> ref = make_indirect_iterator(refs.begin());
+ ref != make_indirect_iterator(refs.end()); ++ref) {
+ fragID = ref->getURI();
if (!fragID || *fragID != chPound || !*(fragID+1)) {
log.warn("skipping ds11:KeyInfoReference with an empty or non-local reference");
continue;
#include "util/XMLHelper.h"
#include "util/XMLConstants.h"
+#include <boost/lambda/bind.hpp>
+#include <boost/lambda/if.hpp>
+#include <boost/lambda/lambda.hpp>
#include <xercesc/framework/MemBufFormatTarget.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
using namespace xmltooling;
using namespace xercesc;
+using namespace boost::lambda;
+using namespace boost;
using namespace std;
static const XMLCh type[]={chLatin_t, chLatin_y, chLatin_p, chLatin_e, chNull };
DOMNamedNodeMap* attributes = domElement->getAttributes();
DOMAttr* attribute;
- for(XMLSize_t i = 0; i < attributes->getLength(); i++) {
+ for(XMLSize_t i = 0; i < attributes->getLength(); ++i) {
attribute = static_cast<DOMAttr*>(attributes->item(i));
if(attribute->isId()) {
return attribute;
const XMLObject* ret;
const list<XMLObject*>& children = tree.getOrderedChildren();
- for (list<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+ for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
if (*i) {
ret = getXMLObjectById(*(*i), id);
if (ret)
{
if (XMLString::equals(id, tree.getXMLID()))
return &tree;
-
+
XMLObject* ret;
const list<XMLObject*>& children = tree.getOrderedChildren();
- for (list<XMLObject*>::const_iterator i=children.begin(); i!=children.end(); ++i) {
+ for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
if (*i) {
ret = getXMLObjectById(*(*i), id);
if (ret)
void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& 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)
- getNonVisiblyUsedPrefixes(*(*i), child_prefixes);
- }
+ for_each(
+ tree.getOrderedChildren().begin(), tree.getOrderedChildren().end(),
+ if_(_1 != nullptr)[lambda::bind(&getNonVisiblyUsedPrefixes, boost::ref(*_1), boost::ref(child_prefixes))]
+ );
const set<Namespace>& nsset = tree.getNamespaces();
for (set<Namespace>::const_iterator ns = nsset.begin(); ns != nsset.end(); ++ns) {
// Check for xmlns:xml.