From: Scott Cantor Date: Mon, 12 Oct 2009 21:58:41 +0000 (+0000) Subject: Reducing header overuse, non-inlining selected methods (CPPOST-35). X-Git-Tag: 1.3~17 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=shibboleth%2Fcpp-xmltooling.git;a=commitdiff_plain;h=bd026f07e729e66127b3efd48aee443fba815af3 Reducing header overuse, non-inlining selected methods (CPPOST-35). --- diff --git a/.cproject b/.cproject index f481b92..8e67507 100644 --- a/.cproject +++ b/.cproject @@ -1,7 +1,4 @@ - - - - + @@ -68,7 +65,7 @@ - + diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp index b24ee87..eae509f 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +22,8 @@ #include "internal.h" #include "AbstractAttributeExtensibleXMLObject.h" +#include "ElementExtensibleXMLObject.h" +#include "ElementProxy.h" #include #include @@ -33,12 +35,60 @@ using xercesc::DOMAttr; using xercesc::DOMElement; using xercesc::XMLString; +ElementExtensibleXMLObject::ElementExtensibleXMLObject() +{ +} + +ElementExtensibleXMLObject::~ElementExtensibleXMLObject() +{ +} + +ElementProxy::ElementProxy() +{ +} + +ElementProxy::~ElementProxy() +{ +} + set AttributeExtensibleXMLObject::m_idAttributeSet; -AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() +AttributeExtensibleXMLObject::AttributeExtensibleXMLObject() { - for (map::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) - XMLString::release(&(i->second)); +} + +AttributeExtensibleXMLObject::~AttributeExtensibleXMLObject() +{ +} + +const set& AttributeExtensibleXMLObject::getRegisteredIDAttributes() +{ + return m_idAttributeSet; +} + +bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const QName& name) +{ + return m_idAttributeSet.find(name)!=m_idAttributeSet.end(); +} + +void AttributeExtensibleXMLObject::registerIDAttribute(const QName& name) +{ + m_idAttributeSet.insert(name); +} + +void AttributeExtensibleXMLObject::deregisterIDAttribute(const QName& name) +{ + m_idAttributeSet.erase(name); +} + +void AttributeExtensibleXMLObject::deregisterIDAttributes() +{ + m_idAttributeSet.clear(); +} + +AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject() +{ + m_idAttribute = m_attributeMap.end(); } AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src) @@ -53,6 +103,18 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const } } +AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() +{ + for (map::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) + XMLString::release(&(i->second)); +} + +const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const QName& qualifiedName) const +{ + map::const_iterator i=m_attributeMap.find(qualifiedName); + return (i==m_attributeMap.end()) ? NULL : i->second; +} + void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID) { map::iterator i=m_attributeMap.find(qualifiedName); @@ -78,6 +140,15 @@ void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedNa } } +const map& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const +{ + return m_attributeMap; +} +const XMLCh* AbstractAttributeExtensibleXMLObject::getXMLID() const +{ + return (m_idAttribute == m_attributeMap.end()) ? NULL : m_idAttribute->second; +} + void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute) { QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.h b/xmltooling/AbstractAttributeExtensibleXMLObject.h index 9698e5b..0429461 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.h +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.h @@ -45,25 +45,14 @@ namespace xmltooling { public: virtual ~AbstractAttributeExtensibleXMLObject(); - const XMLCh* getAttribute(const QName& qualifiedName) const { - std::map::const_iterator i=m_attributeMap.find(qualifiedName); - return (i==m_attributeMap.end()) ? NULL : i->second; - } - + // Virtual function overrides. + const XMLCh* getAttribute(const QName& qualifiedName) const; void setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID=false); - - const std::map& getExtensionAttributes() const { - return m_attributeMap; - } - - const XMLCh* getXMLID() const { - return (m_idAttribute == m_attributeMap.end()) ? NULL : m_idAttribute->second; - } + const std::map& getExtensionAttributes() const; + const XMLCh* getXMLID() const; protected: - AbstractAttributeExtensibleXMLObject() { - m_idAttribute = m_attributeMap.end(); - } + AbstractAttributeExtensibleXMLObject(); /** Copy constructor. */ AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src); diff --git a/xmltooling/AbstractComplexElement.cpp b/xmltooling/AbstractComplexElement.cpp index 6f6f9f1..ea08e19 100644 --- a/xmltooling/AbstractComplexElement.cpp +++ b/xmltooling/AbstractComplexElement.cpp @@ -36,6 +36,16 @@ namespace { } } +AbstractComplexElement::AbstractComplexElement() +{ +} + +AbstractComplexElement::AbstractComplexElement(const AbstractComplexElement& src) +{ + for (vector::const_iterator i=src.m_text.begin(); i!=src.m_text.end(); ++i) + m_text.push_back(XMLString::replicate(*i)); +} + AbstractComplexElement::~AbstractComplexElement() { for_each(m_children.begin(), m_children.end(), cleanup()); for (vector::iterator i=m_text.begin(); i!=m_text.end(); ++i) @@ -49,15 +59,19 @@ bool AbstractComplexElement::hasChildren() const return (find_if(m_children.begin(), m_children.end(), _nonnull) != m_children.end()); } +const list& AbstractComplexElement::getOrderedChildren() const +{ + return m_children; +} + void AbstractComplexElement::removeChild(XMLObject* child) { m_children.erase(remove(m_children.begin(), m_children.end(), child), m_children.end()); } -AbstractComplexElement::AbstractComplexElement(const AbstractComplexElement& src) +const XMLCh* AbstractComplexElement::getTextContent(unsigned int position) const { - for (vector::const_iterator i=src.m_text.begin(); i!=src.m_text.end(); ++i) - m_text.push_back(XMLString::replicate(*i)); + return (m_text.size() > position) ? m_text[position] : NULL; } void AbstractComplexElement::setTextContent(const XMLCh* value, unsigned int position) diff --git a/xmltooling/AbstractComplexElement.h b/xmltooling/AbstractComplexElement.h index cf88200..9f8c24d 100644 --- a/xmltooling/AbstractComplexElement.h +++ b/xmltooling/AbstractComplexElement.h @@ -40,23 +40,16 @@ namespace xmltooling { { public: virtual ~AbstractComplexElement(); - - bool hasChildren() const; - - const std::list& getOrderedChildren() const { - return m_children; - } + // Virtual function overrides. + bool hasChildren() const; + const std::list& getOrderedChildren() const; void removeChild(XMLObject* child); - - const XMLCh* getTextContent(unsigned int position=0) const { - return (m_text.size() > position) ? m_text[position] : NULL; - } - + const XMLCh* getTextContent(unsigned int position=0) const; void setTextContent(const XMLCh* value, unsigned int position=0); protected: - AbstractComplexElement() {} + AbstractComplexElement(); /** Copy constructor. */ AbstractComplexElement(const AbstractComplexElement& src); diff --git a/xmltooling/AbstractDOMCachingXMLObject.cpp b/xmltooling/AbstractDOMCachingXMLObject.cpp index b8d3b42..476eccd 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.cpp +++ b/xmltooling/AbstractDOMCachingXMLObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,12 +33,26 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +AbstractDOMCachingXMLObject::AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) +{ +} + +AbstractDOMCachingXMLObject::AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src) + : AbstractXMLObject(src), m_dom(NULL), m_document(NULL) +{ +} + AbstractDOMCachingXMLObject::~AbstractDOMCachingXMLObject() { if (m_document) m_document->release(); } +DOMElement* AbstractDOMCachingXMLObject::getDOM() const +{ + return m_dom; +} + void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument) const { m_dom=dom; @@ -49,6 +63,13 @@ void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument) con } } +void AbstractDOMCachingXMLObject::setDocument(DOMDocument* doc) const +{ + if (m_document) + m_document->release(); + m_document=doc; +} + void AbstractDOMCachingXMLObject::releaseDOM() const { if (m_dom) { diff --git a/xmltooling/AbstractDOMCachingXMLObject.h b/xmltooling/AbstractDOMCachingXMLObject.h index 125ef79..6f78d98 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.h +++ b/xmltooling/AbstractDOMCachingXMLObject.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -40,35 +40,22 @@ namespace xmltooling { { public: virtual ~AbstractDOMCachingXMLObject(); - - xercesc::DOMElement* getDOM() const { - return m_dom; - } - + + // Virtual function overrides. + xercesc::DOMElement* getDOM() const; void setDOM(xercesc::DOMElement* dom, bool bindDocument=false) const; - - void setDocument(xercesc::DOMDocument* doc) const { - if (m_document) - m_document->release(); - m_document=doc; - } - - virtual void releaseDOM() const; - - virtual void releaseParentDOM(bool propagateRelease=true) const; - - virtual void releaseChildrenDOM(bool propagateRelease=true) const; - + void setDocument(xercesc::DOMDocument* doc) const; + void releaseDOM() const; + void releaseParentDOM(bool propagateRelease=true) const; + void releaseChildrenDOM(bool propagateRelease=true) const; XMLObject* clone() const; - void detach(); protected: - AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) {} + AbstractDOMCachingXMLObject(); /** Copy constructor. */ - AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src) - : AbstractXMLObject(src), m_dom(NULL), m_document(NULL) {} + AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src); /** * If a DOM representation exists, this clones it into a new document. diff --git a/xmltooling/AbstractSimpleElement.cpp b/xmltooling/AbstractSimpleElement.cpp index 1276d4b..43003dd 100644 --- a/xmltooling/AbstractSimpleElement.cpp +++ b/xmltooling/AbstractSimpleElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,13 +24,50 @@ #include "AbstractSimpleElement.h" using namespace xmltooling; +using xercesc::XMLString; using namespace std; // shared "empty" list of children for childless objects list AbstractSimpleElement::m_no_children; +AbstractSimpleElement::AbstractSimpleElement() : m_value(NULL) +{ +} + +AbstractSimpleElement::AbstractSimpleElement(const AbstractSimpleElement& src) + : AbstractXMLObject(src), m_value(XMLString::replicate(src.m_value)) +{ +} + +AbstractSimpleElement::~AbstractSimpleElement() +{ + XMLString::release(&m_value); +} + +bool AbstractSimpleElement::hasChildren() const +{ + return false; +} + +const list& AbstractSimpleElement::getOrderedChildren() const +{ + return m_no_children; +} + void AbstractSimpleElement::removeChild(XMLObject* child) { throw XMLObjectException("Cannot remove child from a childless object."); } + +const XMLCh* AbstractSimpleElement::getTextContent(unsigned int position) const +{ + return (position==0) ? m_value : NULL; +} + +void AbstractSimpleElement::setTextContent(const XMLCh* value, unsigned int position) +{ + if (position > 0) + throw XMLObjectException("Cannot set text content in simple element at position > 0."); + m_value=prepareForAssignment(m_value,value); +} diff --git a/xmltooling/AbstractSimpleElement.h b/xmltooling/AbstractSimpleElement.h index 461b1cc..2abf232 100644 --- a/xmltooling/AbstractSimpleElement.h +++ b/xmltooling/AbstractSimpleElement.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,36 +39,20 @@ namespace xmltooling { class XMLTOOL_API AbstractSimpleElement : public virtual AbstractXMLObject { public: - virtual ~AbstractSimpleElement() { - xercesc::XMLString::release(&m_value); - } + virtual ~AbstractSimpleElement(); - bool hasChildren() const { - return false; - } - - const std::list& getOrderedChildren() const { - return m_no_children; - } - + // Virtual function overrides. + bool hasChildren() const; + const std::list& getOrderedChildren() const; void removeChild(XMLObject* child); - - virtual const XMLCh* getTextContent(unsigned int position=0) const { - return (position==0) ? m_value : NULL; - } - - virtual void setTextContent(const XMLCh* value, unsigned int position=0) { - if (position > 0) - throw XMLObjectException("Cannot set text content in simple element at position > 0."); - m_value=prepareForAssignment(m_value,value); - } + const XMLCh* getTextContent(unsigned int position=0) const; + void setTextContent(const XMLCh* value, unsigned int position=0); protected: - AbstractSimpleElement() : m_value(NULL) {} + AbstractSimpleElement(); /** Copy constructor. */ - AbstractSimpleElement(const AbstractSimpleElement& src) - : AbstractXMLObject(src), m_value(xercesc::XMLString::replicate(src.m_value)) {} + AbstractSimpleElement(const AbstractSimpleElement& src); private: XMLCh* m_value; diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp index 1a51a44..491aaa8 100644 --- a/xmltooling/AbstractXMLObject.cpp +++ b/xmltooling/AbstractXMLObject.cpp @@ -21,15 +21,41 @@ */ #include "internal.h" -#include "AbstractXMLObject.h" #include "exceptions.h" +#include "AbstractXMLObject.h" +#include "util/DateTime.h" #include using namespace xmltooling; +using std::set; using xercesc::XMLString; +XMLObject::XMLObject() +{ +} + +XMLObject::~XMLObject() +{ +} + +void XMLObject::releaseThisandParentDOM() const +{ + if (getDOM()) { + releaseDOM(); + releaseParentDOM(true); + } +} + +void XMLObject::releaseThisAndChildrenDOM() const +{ + if (getDOM()) { + releaseChildrenDOM(true); + releaseDOM(); + } +} + AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL), m_nil(xmlconstants::XML_BOOL_NULL), @@ -58,6 +84,29 @@ AbstractXMLObject::~AbstractXMLObject() xercesc::XMLString::release(&m_noNamespaceSchemaLocation); } +void AbstractXMLObject::detach() +{ + if (!getParent()) + return; + else if (getParent()->hasParent()) + throw XMLObjectException("Cannot detach an object whose parent is itself a child."); + + // Pull ourselves out of the parent and then blast him. + getParent()->removeChild(this); + delete m_parent; + m_parent = NULL; +} + +const QName& AbstractXMLObject::getElementQName() const +{ + return m_elementQname; +} + +const set& AbstractXMLObject::getNamespaces() const +{ + return m_namespaces; +} + void XMLObject::setNil(const XMLCh* value) { if (value) { @@ -92,6 +141,49 @@ void AbstractXMLObject::addNamespace(const Namespace& ns) const const_cast(*i).setAlwaysDeclare(true); } +void AbstractXMLObject::removeNamespace(const Namespace& ns) +{ + m_namespaces.erase(ns); +} + +const QName* AbstractXMLObject::getSchemaType() const +{ + return m_typeQname; +} + +const XMLCh* AbstractXMLObject::getXMLID() const +{ + return NULL; +} + +xmlconstants::xmltooling_bool_t AbstractXMLObject::getNil() const +{ + return m_nil; +} + +void AbstractXMLObject::nil(xmlconstants::xmltooling_bool_t value) +{ + if (m_nil != value) { + releaseThisandParentDOM(); + m_nil = value; + } +} + +bool AbstractXMLObject::hasParent() const +{ + return m_parent != NULL; +} + +XMLObject* AbstractXMLObject::getParent() const +{ + return m_parent; +} + +void AbstractXMLObject::setParent(XMLObject* parent) +{ + m_parent = parent; +} + XMLCh* AbstractXMLObject::prepareForAssignment(XMLCh* oldValue, const XMLCh* newValue) { if (!XMLString::equals(oldValue,newValue)) { @@ -186,16 +278,3 @@ XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObjec return newValue; } - -void AbstractXMLObject::detach() -{ - if (!getParent()) - return; - else if (getParent()->hasParent()) - throw XMLObjectException("Cannot detach an object whose parent is itself a child."); - - // Pull ourselves out of the parent and then blast him. - getParent()->removeChild(this); - delete m_parent; - m_parent = NULL; -} diff --git a/xmltooling/AbstractXMLObject.h b/xmltooling/AbstractXMLObject.h index 9d6319e..b7b22dc 100644 --- a/xmltooling/AbstractXMLObject.h +++ b/xmltooling/AbstractXMLObject.h @@ -24,8 +24,8 @@ #define __xmltooling_abstractxmlobj_h__ #include +#include #include -#include #if defined (_MSC_VER) #pragma warning( push ) @@ -34,6 +34,8 @@ namespace xmltooling { + class XMLTOOL_API DateTime; + /** * An abstract implementation of XMLObject. * This is the primary concrete base class, and supplies basic namespace, @@ -46,52 +48,19 @@ namespace xmltooling { public: virtual ~AbstractXMLObject(); + // Virtual function overrides. void detach(); - - const QName& getElementQName() const { - return m_elementQname; - } - - const std::set& getNamespaces() const { - return m_namespaces; - } - + const QName& getElementQName() const; + const std::set& getNamespaces() const; void addNamespace(const Namespace& ns) const; - - void removeNamespace(const Namespace& ns) { - m_namespaces.erase(ns); - } - - const QName* getSchemaType() const { - return m_typeQname; - } - - const XMLCh* getXMLID() const { - return NULL; - } - - xmlconstants::xmltooling_bool_t getNil() const { - return m_nil; - } - - void nil(xmlconstants::xmltooling_bool_t value) { - if (m_nil != value) { - releaseThisandParentDOM(); - m_nil = value; - } - } - - bool hasParent() const { - return m_parent != NULL; - } - - XMLObject* getParent() const { - return m_parent; - } - - void setParent(XMLObject* parent) { - m_parent = parent; - } + void removeNamespace(const Namespace& ns); + const QName* getSchemaType() const; + const XMLCh* getXMLID() const; + xmlconstants::xmltooling_bool_t getNil() const; + void nil(xmlconstants::xmltooling_bool_t value); + bool hasParent() const; + XMLObject* getParent() const; + void setParent(XMLObject* parent); protected: /** diff --git a/xmltooling/AttributeExtensibleXMLObject.h b/xmltooling/AttributeExtensibleXMLObject.h index d839e3a..08eff0f 100644 --- a/xmltooling/AttributeExtensibleXMLObject.h +++ b/xmltooling/AttributeExtensibleXMLObject.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,10 +38,10 @@ namespace xmltooling { class XMLTOOL_API AttributeExtensibleXMLObject : public virtual XMLObject { protected: - AttributeExtensibleXMLObject() {} + AttributeExtensibleXMLObject(); public: - virtual ~AttributeExtensibleXMLObject() {} + virtual ~AttributeExtensibleXMLObject(); /** * Gets the value of an XML attribute of the object. @@ -73,43 +73,33 @@ namespace xmltooling { * * @return list of all the ID attributes currently registered */ - static const std::set& getRegisteredIDAttributes() { - return m_idAttributeSet; - } + static const std::set& getRegisteredIDAttributes(); /** * Tests whether an XML attribute is registered as an XML ID. * * @return true iff the attribute name matches a registered XML ID attribute */ - static bool isRegisteredIDAttribute(const QName& name) { - return m_idAttributeSet.find(name)!=m_idAttributeSet.end(); - } + static bool isRegisteredIDAttribute(const QName& name); /** * Registers a new attribute as being of XML ID type. * * @param name the qualified attribute name */ - static void registerIDAttribute(const QName& name) { - m_idAttributeSet.insert(name); - } + static void registerIDAttribute(const QName& name); /** * Deregisters an ID attribute. * * @param name the qualified attribute name */ - static void deregisterIDAttribute(const QName& name) { - m_idAttributeSet.erase(name); - } + static void deregisterIDAttribute(const QName& name); /** * Deregisters all ID attributes. */ - static void deregisterIDAttributes() { - m_idAttributeSet.clear(); - } + static void deregisterIDAttributes(); private: /** Set of attributes to treat as XML IDs. */ diff --git a/xmltooling/ConcreteXMLObjectBuilder.h b/xmltooling/ConcreteXMLObjectBuilder.h index 40da9e0..be6f101 100644 --- a/xmltooling/ConcreteXMLObjectBuilder.h +++ b/xmltooling/ConcreteXMLObjectBuilder.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ namespace xmltooling { class XMLTOOL_API ConcreteXMLObjectBuilder : public XMLObjectBuilder { public: - virtual ~ConcreteXMLObjectBuilder() {} + virtual ~ConcreteXMLObjectBuilder(); using XMLObjectBuilder::buildObject; @@ -46,7 +46,7 @@ namespace xmltooling { virtual XMLObject* buildObject() const=0; protected: - ConcreteXMLObjectBuilder() {} + ConcreteXMLObjectBuilder(); }; }; diff --git a/xmltooling/ElementExtensibleXMLObject.h b/xmltooling/ElementExtensibleXMLObject.h index df31b5b..eb1097c 100644 --- a/xmltooling/ElementExtensibleXMLObject.h +++ b/xmltooling/ElementExtensibleXMLObject.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,10 +39,10 @@ namespace xmltooling { class XMLTOOL_API ElementExtensibleXMLObject : public virtual XMLObject { protected: - ElementExtensibleXMLObject() {} + ElementExtensibleXMLObject(); public: - virtual ~ElementExtensibleXMLObject() {} + virtual ~ElementExtensibleXMLObject(); /** * Gets a mutable list of child objects diff --git a/xmltooling/ElementProxy.h b/xmltooling/ElementProxy.h index 8c814b3..1dee1a5 100644 --- a/xmltooling/ElementProxy.h +++ b/xmltooling/ElementProxy.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,10 +34,10 @@ namespace xmltooling { class XMLTOOL_API ElementProxy : public virtual AttributeExtensibleXMLObject, public virtual ElementExtensibleXMLObject { protected: - ElementProxy() {} + ElementProxy(); public: - virtual ~ElementProxy() {} + virtual ~ElementProxy(); }; }; diff --git a/xmltooling/Lockable.cpp b/xmltooling/Lockable.cpp new file mode 100644 index 0000000..4d9c5a4 --- /dev/null +++ b/xmltooling/Lockable.cpp @@ -0,0 +1,59 @@ +/* + * Copyright 2009 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * Lockable.cpp + * + * Locking abstraction. + */ + +#include "internal.h" +#include "Lockable.h" + +using namespace xmltooling; + +Lockable::Lockable() +{ +} + +Lockable::~Lockable() +{ +} + +Locker::Locker(Lockable* lockee, bool lock) +{ + if (lockee && lock) + m_lockee=lockee->lock(); + else + m_lockee=lockee; +} + +void Locker::assign(Lockable* lockee, bool lock) +{ + if (m_lockee) + m_lockee->unlock(); + m_lockee=NULL; + if (lockee && lock) + m_lockee=lockee->lock(); + else + m_lockee=lockee; +} + +Locker::~Locker() +{ + if (m_lockee) + m_lockee->unlock(); +} diff --git a/xmltooling/Lockable.h b/xmltooling/Lockable.h index 629c046..a244d2d 100644 --- a/xmltooling/Lockable.h +++ b/xmltooling/Lockable.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * @file xmltooling/Lockable.h * - * Locking abstraction + * Locking abstraction. */ #ifndef __xmltooling_lockable_h__ @@ -30,9 +30,12 @@ namespace xmltooling { /** * Abstract mixin interface for interfaces that support locking */ - struct XMLTOOL_API Lockable + class XMLTOOL_API Lockable { - virtual ~Lockable() {} + protected: + Lockable(); + public: + virtual ~Lockable(); /** * Lock the associated object for exclusive access. @@ -60,12 +63,7 @@ namespace xmltooling { * @param lockee pointer to an object to hold, and optionally lock * @param lock true iff object is not yet locked */ - Locker(Lockable* lockee=NULL, bool lock=true) { - if (lockee && lock) - m_lockee=lockee->lock(); - else - m_lockee=lockee; - } + Locker(Lockable* lockee=NULL, bool lock=true); /** * Optionally locks an object and stores it for later release. @@ -74,23 +72,12 @@ namespace xmltooling { * @param lockee pointer to an object to hold, and optionally lock * @param lock true iff object is not yet locked */ - void assign(Lockable* lockee=NULL, bool lock=true) { - if (m_lockee) - m_lockee->unlock(); - m_lockee=NULL; - if (lockee && lock) - m_lockee=lockee->lock(); - else - m_lockee=lockee; - } + void assign(Lockable* lockee=NULL, bool lock=true); /** * Destructor releases lock on held pointer, if any. */ - ~Locker() { - if (m_lockee) - m_lockee->unlock(); - } + ~Locker(); private: Lockable* m_lockee; diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index 9ce25a4..374cf1b 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -168,6 +168,7 @@ common_sources = \ AbstractSimpleElement.cpp \ AbstractXMLObject.cpp \ exceptions.cpp \ + Lockable.cpp \ Namespace.cpp \ QName.cpp \ unicode.cpp \ diff --git a/xmltooling/XMLObject.h b/xmltooling/XMLObject.h index 85f7054..d61ac84 100644 --- a/xmltooling/XMLObject.h +++ b/xmltooling/XMLObject.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ #ifndef __xmltooling_xmlobj_h__ #define __xmltooling_xmlobj_h__ -#include #include #include @@ -48,6 +47,7 @@ namespace xmltooling { #ifndef XMLTOOLING_NO_XMLSEC class XMLTOOL_API Credential; #endif + class XMLTOOL_API QName; /** * Object that represents an XML Element that has been unmarshalled into this C++ object. @@ -55,7 +55,7 @@ namespace xmltooling { class XMLTOOL_API XMLObject { public: - virtual ~XMLObject() {} + virtual ~XMLObject(); /** * Creates a copy of the object, along with all of its children. @@ -284,22 +284,12 @@ namespace xmltooling { /** * A convenience method that is equal to calling releaseDOM() then releaseParentDOM(true). */ - void releaseThisandParentDOM() const { - if (getDOM()) { - releaseDOM(); - releaseParentDOM(true); - } - } + void releaseThisandParentDOM() const; /** * A convenience method that is equal to calling releaseChildrenDOM(true) then releaseDOM(). */ - void releaseThisAndChildrenDOM() const { - if (getDOM()) { - releaseChildrenDOM(true); - releaseDOM(); - } - } + void releaseThisAndChildrenDOM() const; /** * Marshalls the XMLObject, and its children, into a DOM element. @@ -362,7 +352,7 @@ namespace xmltooling { virtual XMLObject* unmarshall(xercesc::DOMElement* element, bool bindDocument=false)=0; protected: - XMLObject() {} + XMLObject(); private: XMLObject& operator=(const XMLObject& src); }; diff --git a/xmltooling/XMLObjectBuilder.cpp b/xmltooling/XMLObjectBuilder.cpp index 972e212..c8eeda8 100644 --- a/xmltooling/XMLObjectBuilder.cpp +++ b/xmltooling/XMLObjectBuilder.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,7 +22,7 @@ #include "internal.h" #include "logging.h" -#include "XMLObjectBuilder.h" +#include "ConcreteXMLObjectBuilder.h" #include "util/NDC.h" #include "util/XMLHelper.h" @@ -30,11 +30,51 @@ using namespace xmltooling::logging; using namespace xmltooling; using namespace std; +using xercesc::DOMDocument; using xercesc::DOMElement; map XMLObjectBuilder::m_map; XMLObjectBuilder* XMLObjectBuilder::m_default=NULL; +XMLObjectBuilder::XMLObjectBuilder() +{ +} + +XMLObjectBuilder::~XMLObjectBuilder() +{ +} + +XMLObject* XMLObjectBuilder::buildFromQName(const QName& q) const +{ + return buildObject(q.getNamespaceURI(),q.getLocalPart(),q.getPrefix()); +} + +XMLObject* XMLObjectBuilder::buildFromElement(DOMElement* element, bool bindDocument) const +{ + auto_ptr ret( + buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix(),XMLHelper::getXSIType(element)) + ); + ret->unmarshall(element,bindDocument); + return ret.release(); +} + +XMLObject* XMLObjectBuilder::buildFromDocument(DOMDocument* doc, bool bindDocument) const +{ + return buildFromElement(doc->getDocumentElement(),bindDocument); +} + +XMLObject* XMLObjectBuilder::buildOneFromElement(xercesc::DOMElement* element, bool bindDocument) +{ + const XMLObjectBuilder* b=getBuilder(element); + return b ? b->buildFromElement(element,bindDocument) : NULL; +} + +const XMLObjectBuilder* XMLObjectBuilder::getBuilder(const QName& key) +{ + map::const_iterator i=m_map.find(key); + return (i==m_map.end()) ? NULL : i->second; +} + const XMLObjectBuilder* XMLObjectBuilder::getBuilder(const DOMElement* domElement) { #ifdef _DEBUG @@ -66,9 +106,51 @@ const XMLObjectBuilder* XMLObjectBuilder::getBuilder(const DOMElement* domElemen return m_default; } +const XMLObjectBuilder* XMLObjectBuilder::getDefaultBuilder() +{ + return m_default; +} + +const map& XMLObjectBuilder::getBuilders() +{ + return m_map; +} + +void XMLObjectBuilder::registerBuilder(const QName& builderKey, XMLObjectBuilder* builder) +{ + deregisterBuilder(builderKey); + m_map[builderKey]=builder; +} + +void XMLObjectBuilder::registerDefaultBuilder(XMLObjectBuilder* builder) +{ + deregisterDefaultBuilder(); + m_default=builder; +} + +void XMLObjectBuilder::deregisterBuilder(const QName& builderKey) +{ + delete getBuilder(builderKey); + m_map.erase(builderKey); +} + +void XMLObjectBuilder::deregisterDefaultBuilder() +{ + delete m_default; + m_default=NULL; +} + void XMLObjectBuilder::destroyBuilders() { for_each(m_map.begin(),m_map.end(),cleanup_pair()); m_map.clear(); deregisterDefaultBuilder(); } + +ConcreteXMLObjectBuilder::ConcreteXMLObjectBuilder() +{ +} + +ConcreteXMLObjectBuilder::~ConcreteXMLObjectBuilder() +{ +} diff --git a/xmltooling/XMLObjectBuilder.h b/xmltooling/XMLObjectBuilder.h index 7592dc7..01eb11e 100644 --- a/xmltooling/XMLObjectBuilder.h +++ b/xmltooling/XMLObjectBuilder.h @@ -45,7 +45,7 @@ namespace xmltooling { { MAKE_NONCOPYABLE(XMLObjectBuilder); public: - virtual ~XMLObjectBuilder() {} + virtual ~XMLObjectBuilder(); /** * Creates an empty XMLObject with a particular element name. @@ -67,9 +67,7 @@ namespace xmltooling { * @param q QName of element for object * @return the empty XMLObject */ - XMLObject* buildFromQName(const QName& q) const { - return buildObject(q.getNamespaceURI(),q.getLocalPart(),q.getPrefix()); - } + XMLObject* buildFromQName(const QName& q) const; /** * Creates an unmarshalled XMLObject from a DOM Element. @@ -78,13 +76,7 @@ namespace xmltooling { * @param bindDocument true iff the XMLObject should take ownership of the DOM Document * @return the unmarshalled XMLObject */ - XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const { - std::auto_ptr ret( - buildObject(element->getNamespaceURI(),element->getLocalName(),element->getPrefix(),XMLHelper::getXSIType(element)) - ); - ret->unmarshall(element,bindDocument); - return ret.release(); - } + XMLObject* buildFromElement(xercesc::DOMElement* element, bool bindDocument=false) const; /** * Creates an unmarshalled XMLObject from the root of a DOM Document. @@ -93,9 +85,7 @@ namespace xmltooling { * @param bindDocument true iff the XMLObject should take ownership of the DOM Document * @return the unmarshalled XMLObject */ - XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const { - return buildFromElement(doc->getDocumentElement(),bindDocument); - } + XMLObject* buildFromDocument(xercesc::DOMDocument* doc, bool bindDocument=true) const; /** * Creates an unmarshalled XMLObject using the default build method, if a builder can be found. @@ -104,10 +94,7 @@ namespace xmltooling { * @param bindDocument true iff the new XMLObject should take ownership of the DOM Document * @return the unmarshalled object or NULL if no builder is available */ - static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false) { - const XMLObjectBuilder* b=getBuilder(element); - return b ? b->buildFromElement(element,bindDocument) : NULL; - } + static XMLObject* buildOneFromElement(xercesc::DOMElement* element, bool bindDocument=false); /** * Retrieves an XMLObjectBuilder using the key it was registered with. @@ -115,10 +102,7 @@ namespace xmltooling { * @param key the key used to register the builder * @return the builder or NULL */ - static const XMLObjectBuilder* getBuilder(const QName& key) { - std::map::const_iterator i=m_map.find(key); - return (i==m_map.end()) ? NULL : i->second; - } + static const XMLObjectBuilder* getBuilder(const QName& key); /** * Retrieves an XMLObjectBuilder for a given DOM element. @@ -134,18 +118,14 @@ namespace xmltooling { * * @return the default builder or NULL */ - static const XMLObjectBuilder* getDefaultBuilder() { - return m_default; - } + static const XMLObjectBuilder* getDefaultBuilder(); /** * Gets an immutable list of all the builders currently registered. * * @return list of all the builders currently registered */ - static const std::map& getBuilders() { - return m_map; - } + static const std::map& getBuilders(); /** * Registers a new builder for the given key. @@ -153,38 +133,26 @@ namespace xmltooling { * @param builderKey the key used to retrieve this builder later * @param builder the builder */ - static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder) { - deregisterBuilder(builderKey); - m_map[builderKey]=builder; - } + static void registerBuilder(const QName& builderKey, XMLObjectBuilder* builder); /** * Registers a default builder * * @param builder the default builder */ - static void registerDefaultBuilder(XMLObjectBuilder* builder) { - deregisterDefaultBuilder(); - m_default=builder; - } + static void registerDefaultBuilder(XMLObjectBuilder* builder); /** * Deregisters a builder. * * @param builderKey the key for the builder to be deregistered */ - static void deregisterBuilder(const QName& builderKey) { - delete getBuilder(builderKey); - m_map.erase(builderKey); - } + static void deregisterBuilder(const QName& builderKey); /** * Deregisters default builder. */ - static void deregisterDefaultBuilder() { - delete m_default; - m_default=NULL; - } + static void deregisterDefaultBuilder(); /** * Unregisters and destroys all registered builders. @@ -192,7 +160,7 @@ namespace xmltooling { static void destroyBuilders(); protected: - XMLObjectBuilder() {} + XMLObjectBuilder(); private: static std::map m_map; diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 7e99906..e3710aa 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -33,6 +33,7 @@ #include "security/OpenSSLCryptoX509CRL.h" #include "security/CredentialResolver.h" #include "security/KeyInfoResolver.h" +#include "signature/KeyInfo.h" #include "signature/Signature.h" #include "soap/SOAP.h" #include "soap/SOAPTransport.h" @@ -41,6 +42,7 @@ #include "util/ReplayCache.h" #include "util/StorageService.h" #include "util/TemplateEngine.h" +#include "util/Threads.h" #include "util/URLEncoder.h" #include "util/XMLConstants.h" #include "validation/ValidatorSuite.h" @@ -204,10 +206,14 @@ bool XMLToolingInternalConfig::log_config(const char* config) } #ifndef XMLTOOLING_LITE -void XMLToolingConfig::setReplayCache(ReplayCache* replayCache) +const KeyInfoResolver* XMLToolingConfig::getKeyInfoResolver() const { - delete m_replayCache; - m_replayCache = replayCache; + return m_keyInfoResolver; +} + +ReplayCache* XMLToolingConfig::getReplayCache() const +{ + return m_replayCache; } void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoResolver) @@ -215,8 +221,29 @@ void XMLToolingConfig::setKeyInfoResolver(xmltooling::KeyInfoResolver *keyInfoRe delete m_keyInfoResolver; m_keyInfoResolver = keyInfoResolver; } + +void XMLToolingConfig::setReplayCache(ReplayCache* replayCache) +{ + delete m_replayCache; + m_replayCache = replayCache; +} #endif +PathResolver* XMLToolingConfig::getPathResolver() const +{ + return m_pathResolver; +} + +TemplateEngine* XMLToolingConfig::getTemplateEngine() const +{ + return m_templateEngine; +} + +const URLEncoder* XMLToolingConfig::getURLEncoder() const +{ + return m_urlEncoder; +} + void XMLToolingConfig::setPathResolver(PathResolver* pathResolver) { delete m_pathResolver; diff --git a/xmltooling/XMLToolingConfig.h b/xmltooling/XMLToolingConfig.h index 3c24b2a..8afee3d 100644 --- a/xmltooling/XMLToolingConfig.h +++ b/xmltooling/XMLToolingConfig.h @@ -163,18 +163,14 @@ namespace xmltooling { * * @return global KeyInfoResolver or NULL */ - const KeyInfoResolver* getKeyInfoResolver() const { - return m_keyInfoResolver; - } + const KeyInfoResolver* getKeyInfoResolver() const; /** * Returns the global ReplayCache instance. * * @return global ReplayCache or NULL */ - ReplayCache* getReplayCache() const { - return m_replayCache; - } + ReplayCache* getReplayCache() const; /** * Sets the global KeyInfoResolver instance. @@ -200,27 +196,21 @@ namespace xmltooling { * * @return global PathResolver or NULL */ - PathResolver* getPathResolver() const { - return m_pathResolver; - } + PathResolver* getPathResolver() const; /** * Returns the global TemplateEngine instance. * * @return global TemplateEngine or NULL */ - TemplateEngine* getTemplateEngine() const { - return m_templateEngine; - } + TemplateEngine* getTemplateEngine() const; /** * Returns the global URLEncoder instance. * * @return global URLEncoder or NULL */ - const URLEncoder* getURLEncoder() const { - return m_urlEncoder; - } + const URLEncoder* getURLEncoder() const; /** * Sets the global PathResolver instance. diff --git a/xmltooling/encryption/Decrypter.h b/xmltooling/encryption/Decrypter.h index f1eeb21..8d2b574 100644 --- a/xmltooling/encryption/Decrypter.h +++ b/xmltooling/encryption/Decrypter.h @@ -23,9 +23,9 @@ #if !defined(__xmltooling_decrypter_h__) && !defined(XMLTOOLING_NO_XMLSEC) #define __xmltooling_decrypter_h__ -#include +#include -#include +class XENCCipher; namespace xmltooling { class XMLTOOL_API CredentialCriteria; @@ -34,6 +34,8 @@ namespace xmltooling { namespace xmlencryption { + class XMLTOOL_API EncryptedData; + class XMLTOOL_API EncryptedKey; class XMLTOOL_API EncryptedKeyResolver; /** @@ -53,8 +55,7 @@ namespace xmlencryption { const xmltooling::CredentialResolver* credResolver=NULL, xmltooling::CredentialCriteria* criteria=NULL, const EncryptedKeyResolver* EKResolver=NULL - ) : m_cipher(NULL), m_credResolver(credResolver), m_criteria(criteria), m_EKResolver(EKResolver) { - } + ); virtual ~Decrypter(); @@ -63,9 +64,7 @@ namespace xmlencryption { * * @param EKResolver the EncryptedKeyResolver to attach */ - void setEncryptedKeyResolver(const EncryptedKeyResolver* EKResolver) { - m_EKResolver=EKResolver; - } + void setEncryptedKeyResolver(const EncryptedKeyResolver* EKResolver); /** * Replace the current CredentialResolver interface, if any, with a new one. @@ -73,10 +72,7 @@ namespace xmlencryption { * @param resolver the locked CredentialResolver to attach, or NULL to clear * @param criteria optional external criteria to use with resolver */ - void setKEKResolver(const xmltooling::CredentialResolver* resolver, xmltooling::CredentialCriteria* criteria) { - m_credResolver=resolver; - m_criteria=criteria; - } + void setKEKResolver(const xmltooling::CredentialResolver* resolver, xmltooling::CredentialCriteria* criteria); /** * Decrypts the supplied information using the supplied key, and returns diff --git a/xmltooling/encryption/EncryptedKeyResolver.h b/xmltooling/encryption/EncryptedKeyResolver.h index 9a4c42e..a93a825 100644 --- a/xmltooling/encryption/EncryptedKeyResolver.h +++ b/xmltooling/encryption/EncryptedKeyResolver.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -33,8 +33,8 @@ namespace xmlencryption { class XMLTOOL_API EncryptedKeyResolver { MAKE_NONCOPYABLE(EncryptedKeyResolver); public: - EncryptedKeyResolver() {} - virtual ~EncryptedKeyResolver() {} + EncryptedKeyResolver(); + virtual ~EncryptedKeyResolver(); /** * Returns an encrypted key based on the supplied object's KeyInfo information. diff --git a/xmltooling/encryption/Encrypter.h b/xmltooling/encryption/Encrypter.h index 33383ad..a195585 100644 --- a/xmltooling/encryption/Encrypter.h +++ b/xmltooling/encryption/Encrypter.h @@ -23,10 +23,11 @@ #if !defined(__xmltooling_encrypter_h__) && !defined(XMLTOOLING_NO_XMLSEC) #define __xmltooling_encrypter_h__ -#include +#include -#include -#include +#include + +class XENCCipher; namespace xmltooling { class XMLTOOL_API Credential; @@ -34,6 +35,9 @@ namespace xmltooling { namespace xmlencryption { + class XMLTOOL_API EncryptedData; + class XMLTOOL_API EncryptedKey; + /** * Wrapper API for XML Encryption functionality. * Designed to allow both external and internal key generation as follows: @@ -82,11 +86,9 @@ namespace xmlencryption { unsigned int keyBufferSize=0, const xmltooling::Credential* credential=NULL, bool compact=false - ) : m_algorithm(algorithm), m_keyBuffer(keyBuffer), m_keyBufferSize(keyBufferSize), - m_credential(credential), m_compact(compact) { - } + ); - ~EncryptionParams() {} + ~EncryptionParams(); /** Data encryption algorithm. */ const XMLCh* m_algorithm; @@ -116,13 +118,10 @@ namespace xmlencryption { * @param recipient optional name of recipient of encrypted key */ KeyEncryptionParams( - const xmltooling::Credential& credential, - const XMLCh* algorithm=NULL, - const XMLCh* recipient=NULL - ) : m_credential(credential), m_algorithm(algorithm), m_recipient(recipient) { - } + const xmltooling::Credential& credential, const XMLCh* algorithm=NULL, const XMLCh* recipient=NULL + ); - ~KeyEncryptionParams() {} + ~KeyEncryptionParams(); /** Credential containing key encryption key. */ const xmltooling::Credential& m_credential; @@ -134,7 +133,7 @@ namespace xmlencryption { const XMLCh* m_recipient; }; - Encrypter() : m_cipher(NULL) {} + Encrypter(); virtual ~Encrypter(); diff --git a/xmltooling/encryption/Encryption.h b/xmltooling/encryption/Encryption.h index dc3d2c8..f56a248 100644 --- a/xmltooling/encryption/Encryption.h +++ b/xmltooling/encryption/Encryption.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,17 @@ #if !defined(__xmltooling_encryption_h__) && !defined(XMLTOOLING_NO_XMLSEC) #define __xmltooling_encryption_h__ -#include +#include +#include +#include + #include +namespace xmlsignature { + class XMLTOOL_API KeyInfo; + class XMLTOOL_API Transform; +}; + /** * Macro for declaring encryption builders. * diff --git a/xmltooling/encryption/impl/Decrypter.cpp b/xmltooling/encryption/impl/Decrypter.cpp index b29ca13..483715a 100644 --- a/xmltooling/encryption/impl/Decrypter.cpp +++ b/xmltooling/encryption/impl/Decrypter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,6 +24,7 @@ #include "logging.h" #include "encryption/Decrypter.h" #include "encryption/EncryptedKeyResolver.h" +#include "encryption/Encryption.h" #include "security/Credential.h" #include "security/CredentialCriteria.h" #include "security/CredentialResolver.h" @@ -33,6 +34,7 @@ #include #include #include +#include #include #include @@ -42,12 +44,28 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +Decrypter::Decrypter(const CredentialResolver* credResolver, CredentialCriteria* criteria, const EncryptedKeyResolver* EKResolver) + : m_cipher(NULL), m_credResolver(credResolver), m_criteria(criteria), m_EKResolver(EKResolver) +{ +} + Decrypter::~Decrypter() { if (m_cipher) XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->releaseCipher(m_cipher); } +void Decrypter::setEncryptedKeyResolver(const EncryptedKeyResolver* EKResolver) +{ + m_EKResolver=EKResolver; +} + +void Decrypter::setKEKResolver(const CredentialResolver* resolver, CredentialCriteria* criteria) +{ + m_credResolver=resolver; + m_criteria=criteria; +} + DOMDocumentFragment* Decrypter::decryptData(const EncryptedData& encryptedData, XSECCryptoKey* key) { if (encryptedData.getDOM()==NULL) diff --git a/xmltooling/encryption/impl/EncryptedKeyResolver.cpp b/xmltooling/encryption/impl/EncryptedKeyResolver.cpp index 5afe82e..421bec6 100644 --- a/xmltooling/encryption/impl/EncryptedKeyResolver.cpp +++ b/xmltooling/encryption/impl/EncryptedKeyResolver.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,21 @@ #include "internal.h" #include "encryption/EncryptedKeyResolver.h" +#include "signature/KeyInfo.h" using namespace xmlencryption; using namespace xmlsignature; using namespace xmltooling; using namespace std; +EncryptedKeyResolver::EncryptedKeyResolver() +{ +} + +EncryptedKeyResolver::~EncryptedKeyResolver() +{ +} + const EncryptedKey* EncryptedKeyResolver::resolveKey(const EncryptedData& encryptedData, const XMLCh* recipient) const { if (!encryptedData.getKeyInfo()) diff --git a/xmltooling/encryption/impl/Encrypter.cpp b/xmltooling/encryption/impl/Encrypter.cpp index 21601b8..a6996c0 100644 --- a/xmltooling/encryption/impl/Encrypter.cpp +++ b/xmltooling/encryption/impl/Encrypter.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,12 +22,15 @@ #include "internal.h" #include "encryption/Encrypter.h" +#include "encryption/Encryption.h" #include "security/Credential.h" +#include "signature/KeyInfo.h" #include #include #include #include +#include #include #include @@ -37,6 +40,29 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +Encrypter::EncryptionParams::EncryptionParams( + const XMLCh* algorithm, const unsigned char* keyBuffer, unsigned int keyBufferSize, const Credential* credential, bool compact + ) : m_algorithm(algorithm), m_keyBuffer(keyBuffer), m_keyBufferSize(keyBufferSize), m_credential(credential), m_compact(compact) +{ +} + +Encrypter::EncryptionParams::~EncryptionParams() +{ +} + +Encrypter::KeyEncryptionParams::KeyEncryptionParams(const Credential& credential, const XMLCh* algorithm, const XMLCh* recipient) + : m_credential(credential), m_algorithm(algorithm), m_recipient(recipient) +{ +} + +Encrypter::KeyEncryptionParams::~KeyEncryptionParams() +{ +} + +Encrypter::Encrypter() : m_cipher(NULL) +{ +} + Encrypter::~Encrypter() { XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->releaseCipher(m_cipher); diff --git a/xmltooling/encryption/impl/EncryptionImpl.cpp b/xmltooling/encryption/impl/EncryptionImpl.cpp index a6d0af7..df2eda0 100644 --- a/xmltooling/encryption/impl/EncryptionImpl.cpp +++ b/xmltooling/encryption/impl/EncryptionImpl.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,7 @@ #include "encryption/Encryption.h" #include "io/AbstractXMLObjectMarshaller.h" #include "io/AbstractXMLObjectUnmarshaller.h" +#include "signature/KeyInfo.h" #include "util/XMLHelper.h" #include diff --git a/xmltooling/encryption/impl/EncryptionSchemaValidators.cpp b/xmltooling/encryption/impl/EncryptionSchemaValidators.cpp index 4adcb7b..16d7adc 100644 --- a/xmltooling/encryption/impl/EncryptionSchemaValidators.cpp +++ b/xmltooling/encryption/impl/EncryptionSchemaValidators.cpp @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include "internal.h" #include "exceptions.h" #include "encryption/Encryption.h" +#include "validation/Validator.h" #include "validation/ValidatorSuite.h" using namespace xmlencryption; diff --git a/xmltooling/impl/AnyElement.cpp b/xmltooling/impl/AnyElement.cpp index 8fb4cfc..27c1702 100644 --- a/xmltooling/impl/AnyElement.cpp +++ b/xmltooling/impl/AnyElement.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 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,19 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +AnyElementImpl::AnyElementImpl() +{ +} + +AnyElementImpl::AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType) + : AbstractXMLObject(nsURI, localName, prefix, schemaType) +{ +} + +AnyElementImpl::~AnyElementImpl() +{ +} + XMLObject* AnyElementImpl::clone() const { auto_ptr domClone(AbstractDOMCachingXMLObject::clone()); AnyElementImpl* ret=dynamic_cast(domClone.get()); @@ -43,27 +56,34 @@ XMLObject* AnyElementImpl::clone() const { return new AnyElementImpl(*this); } -AnyElementImpl::AnyElementImpl(const AnyElementImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src), - AbstractComplexElement(src), AbstractAttributeExtensibleXMLObject(src) { +AnyElementImpl::AnyElementImpl(const AnyElementImpl& src) + : AbstractXMLObject(src), + AbstractDOMCachingXMLObject(src), + AbstractComplexElement(src), + AbstractAttributeExtensibleXMLObject(src) { const vector& children = src.getUnknownXMLObjects(); for (vector::const_iterator i=children.begin(); i!=children.end(); ++i) getUnknownXMLObjects().push_back((*i)->clone()); } -void AnyElementImpl::marshallAttributes(DOMElement* domElement) const { +void AnyElementImpl::marshallAttributes(DOMElement* domElement) const +{ marshallExtensionAttributes(domElement); } -void AnyElementImpl::processChildElement(XMLObject* childXMLObject, const DOMElement* root) { +void AnyElementImpl::processChildElement(XMLObject* childXMLObject, const DOMElement* root) +{ getUnknownXMLObjects().push_back(childXMLObject); } -void AnyElementImpl::processAttribute(const DOMAttr* attribute) { +void AnyElementImpl::processAttribute(const DOMAttr* attribute) +{ unmarshallExtensionAttribute(attribute); } XMLObject* AnyElementBuilder::buildObject( const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType - ) const { + ) const +{ return new AnyElementImpl(nsURI, localName, prefix, schemaType); } diff --git a/xmltooling/impl/AnyElement.h b/xmltooling/impl/AnyElement.h index 5fad8ec..4151cd3 100644 --- a/xmltooling/impl/AnyElement.h +++ b/xmltooling/impl/AnyElement.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,15 +49,14 @@ namespace xmltooling { { /// @cond OFF public: - virtual ~AnyElementImpl() {} + virtual ~AnyElementImpl(); - AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL) - : AbstractXMLObject(nsURI, localName, prefix, schemaType) {} + AnyElementImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL); XMLObject* clone() const; protected: - AnyElementImpl() {} + AnyElementImpl(); AnyElementImpl(const AnyElementImpl& src); IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject,m_children.end()); diff --git a/xmltooling/impl/UnknownElement.cpp b/xmltooling/impl/UnknownElement.cpp index b1bc80f..9f68476 100644 --- a/xmltooling/impl/UnknownElement.cpp +++ b/xmltooling/impl/UnknownElement.cpp @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * UnknownElement.cpp * - * Basic implementation suitable for use as default for unrecognized content + * Basic implementation suitable for use as default for unrecognized content. */ #include "internal.h" @@ -39,6 +39,15 @@ using namespace std; using xmlsignature::Signature; #endif +UnknownElementImpl::UnknownElementImpl(const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix) + : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix) +{ +} + +UnknownElementImpl::~UnknownElementImpl() +{ +} + void UnknownElementImpl::releaseDOM() const { #ifdef _DEBUG @@ -68,6 +77,25 @@ XMLObject* UnknownElementImpl::clone() const return ret; } +const XMLCh* UnknownElementImpl::getTextContent(unsigned int position) const +{ + throw XMLObjectException("Direct access to content is not permitted."); +} + +void UnknownElementImpl::setTextContent(const XMLCh*, unsigned int position) +{ + throw XMLObjectException("Direct access to content is not permitted."); +} + +void UnknownElementImpl::setDocumentElement(DOMDocument* document, DOMElement* element) const +{ + DOMElement* documentRoot = document->getDocumentElement(); + if (documentRoot) + document->replaceChild(element, documentRoot); + else + document->appendChild(element); +} + void UnknownElementImpl::serialize(string& s) const { if (getDOM()) @@ -206,7 +234,8 @@ XMLObject* UnknownElementImpl::unmarshall(DOMElement* element, bool bindDocument XMLObject* UnknownElementBuilder::buildObject( const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType - ) const { + ) const +{ return new UnknownElementImpl(nsURI,localName,prefix); } diff --git a/xmltooling/impl/UnknownElement.h b/xmltooling/impl/UnknownElement.h index ed24fae..d88d281 100644 --- a/xmltooling/impl/UnknownElement.h +++ b/xmltooling/impl/UnknownElement.h @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * @file xmltooling/impl/UnknownElement.h * - * Basic implementation suitable for use as default for unrecognized content + * Basic implementation suitable for use as default for unrecognized content. */ #ifndef __xmltooling_unkelement_h__ @@ -42,20 +42,14 @@ namespace xmltooling { class XMLTOOL_DLLLOCAL UnknownElementImpl : public AbstractSimpleElement, public AbstractDOMCachingXMLObject { public: - UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL) - : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix) {} + UnknownElementImpl(const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL); - void releaseDOM() const; + virtual ~UnknownElementImpl(); + void releaseDOM() const; XMLObject* clone() const; - - const XMLCh* getTextContent(unsigned int position=0) const { - throw XMLObjectException("Direct access to content is not permitted."); - } - - void setTextContent(const XMLCh*, unsigned int position=0) { - throw XMLObjectException("Direct access to content is not permitted."); - } + const XMLCh* getTextContent(unsigned int position=0) const; + void setTextContent(const XMLCh*, unsigned int position=0); xercesc::DOMElement* marshall( xercesc::DOMDocument* document=NULL @@ -75,13 +69,7 @@ namespace xmltooling { XMLObject* unmarshall(xercesc::DOMElement* element, bool bindDocument=false); protected: - void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const { - xercesc::DOMElement* documentRoot = document->getDocumentElement(); - if (documentRoot) - document->replaceChild(element, documentRoot); - else - document->appendChild(element); - } + void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const; mutable std::string m_xml; diff --git a/xmltooling/io/AbstractXMLObjectMarshaller.cpp b/xmltooling/io/AbstractXMLObjectMarshaller.cpp index 0157327..3a6064e 100644 --- a/xmltooling/io/AbstractXMLObjectMarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectMarshaller.cpp @@ -43,6 +43,23 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +AbstractXMLObjectMarshaller::AbstractXMLObjectMarshaller() +{ +} + +AbstractXMLObjectMarshaller::~AbstractXMLObjectMarshaller() +{ +} + +void AbstractXMLObjectMarshaller::setDocumentElement(DOMDocument* document, DOMElement* element) const +{ + DOMElement* documentRoot = document->getDocumentElement(); + if (documentRoot) + document->replaceChild(element, documentRoot); + else + document->appendChild(element); +} + DOMElement* AbstractXMLObjectMarshaller::marshall( DOMDocument* document #ifndef XMLTOOLING_NO_XMLSEC @@ -361,3 +378,7 @@ void AbstractXMLObjectMarshaller::marshallContent( } } } + +void AbstractXMLObjectMarshaller::marshallAttributes(DOMElement* domElement) const +{ +} diff --git a/xmltooling/io/AbstractXMLObjectMarshaller.h b/xmltooling/io/AbstractXMLObjectMarshaller.h index 9481deb..bffe944 100644 --- a/xmltooling/io/AbstractXMLObjectMarshaller.h +++ b/xmltooling/io/AbstractXMLObjectMarshaller.h @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,7 +38,7 @@ namespace xmltooling { class XMLTOOL_API AbstractXMLObjectMarshaller : public virtual AbstractXMLObject { public: - virtual ~AbstractXMLObjectMarshaller() {} + virtual ~AbstractXMLObjectMarshaller(); xercesc::DOMElement* marshall( xercesc::DOMDocument* document=NULL @@ -57,7 +57,7 @@ namespace xmltooling { ) const; protected: - AbstractXMLObjectMarshaller() {} + AbstractXMLObjectMarshaller(); /** * Sets the given element as the Document Element of the given Document. @@ -66,13 +66,7 @@ namespace xmltooling { * @param document the document * @param element the Element that will serve as the Document Element */ - void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const { - xercesc::DOMElement* documentRoot = document->getDocumentElement(); - if (documentRoot) - document->replaceChild(element, documentRoot); - else - document->appendChild(element); - } + void setDocumentElement(xercesc::DOMDocument* document, xercesc::DOMElement* element) const; #ifndef XMLTOOLING_NO_XMLSEC /** @@ -146,7 +140,7 @@ namespace xmltooling { * * @throws MarshallingException thrown if there is a problem marshalling an attribute */ - virtual void marshallAttributes(xercesc::DOMElement* domElement) const {} + virtual void marshallAttributes(xercesc::DOMElement* domElement) const; }; }; diff --git a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp index e633b70..b200f5b 100644 --- a/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectUnmarshaller.cpp @@ -35,6 +35,13 @@ using namespace xmltooling; using namespace xercesc; using namespace std; +AbstractXMLObjectUnmarshaller::AbstractXMLObjectUnmarshaller() +{ +} + +AbstractXMLObjectUnmarshaller::~AbstractXMLObjectUnmarshaller() +{ +} XMLObject* AbstractXMLObjectUnmarshaller::unmarshall(DOMElement* element, bool bindDocument) { diff --git a/xmltooling/io/AbstractXMLObjectUnmarshaller.h b/xmltooling/io/AbstractXMLObjectUnmarshaller.h index fc23c97..d25c18a 100644 --- a/xmltooling/io/AbstractXMLObjectUnmarshaller.h +++ b/xmltooling/io/AbstractXMLObjectUnmarshaller.h @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,12 +38,12 @@ namespace xmltooling { class XMLTOOL_API AbstractXMLObjectUnmarshaller : public virtual AbstractXMLObject { public: - virtual ~AbstractXMLObjectUnmarshaller() {} + virtual ~AbstractXMLObjectUnmarshaller(); XMLObject* unmarshall(xercesc::DOMElement* element, bool bindDocument=false); protected: - AbstractXMLObjectUnmarshaller() {} + AbstractXMLObjectUnmarshaller(); /** * Unmarshalls the attributes from the given DOM Element into the XMLObject. If the attribute diff --git a/xmltooling/io/GenericRequest.h b/xmltooling/io/GenericRequest.h index e540b2e..a874040 100644 --- a/xmltooling/io/GenericRequest.h +++ b/xmltooling/io/GenericRequest.h @@ -42,9 +42,9 @@ namespace xmltooling { class XMLTOOL_API GenericRequest { MAKE_NONCOPYABLE(GenericRequest); protected: - GenericRequest() {} + GenericRequest(); public: - virtual ~GenericRequest() {} + virtual ~GenericRequest(); /** * Returns the URL scheme of the request (http, https, ftp, ldap, etc.) diff --git a/xmltooling/io/GenericResponse.h b/xmltooling/io/GenericResponse.h index 57a459d..6b0d55c 100644 --- a/xmltooling/io/GenericResponse.h +++ b/xmltooling/io/GenericResponse.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,9 +36,9 @@ namespace xmltooling { class XMLTOOL_API GenericResponse { MAKE_NONCOPYABLE(GenericResponse); protected: - GenericResponse() {} + GenericResponse(); public: - virtual ~GenericResponse() {} + virtual ~GenericResponse(); /** * Sets or clears the MIME type of the response. diff --git a/xmltooling/io/HTTPRequest.cpp b/xmltooling/io/HTTPRequest.cpp index ff73107..2a71c30 100644 --- a/xmltooling/io/HTTPRequest.cpp +++ b/xmltooling/io/HTTPRequest.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * HTTPRequest.cpp * - * Interface to HTTP requests + * Interface to HTTP requests. */ #include "internal.h" @@ -26,6 +26,27 @@ using namespace xmltooling; using namespace std; +GenericRequest::GenericRequest() +{ +} + +GenericRequest::~GenericRequest() +{ +} + +HTTPRequest::HTTPRequest() +{ +} + +HTTPRequest::~HTTPRequest() +{ +} + +bool HTTPRequest::isSecure() const +{ + return strcmp(getScheme(),"https")==0; +} + const char* HTTPRequest::getCookie(const char* name) const { if (m_cookieMap.empty()) { diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h index a600be2..b2c65f5 100644 --- a/xmltooling/io/HTTPRequest.h +++ b/xmltooling/io/HTTPRequest.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * @file xmltooling/io/HTTPRequest.h * - * Interface to HTTP requests + * Interface to HTTP requests. */ #ifndef __xmltooling_httpreq_h__ @@ -46,13 +46,11 @@ namespace xmltooling { */ class XMLTOOL_API HTTPRequest : public GenericRequest { protected: - HTTPRequest() {} + HTTPRequest(); public: - virtual ~HTTPRequest() {} + virtual ~HTTPRequest(); - bool isSecure() const { - return strcmp(getScheme(),"https")==0; - } + bool isSecure() const; /** * Returns the HTTP method of the request (GET, POST, etc.) diff --git a/xmltooling/io/HTTPResponse.cpp b/xmltooling/io/HTTPResponse.cpp index 934de5e..ab2255a 100644 --- a/xmltooling/io/HTTPResponse.cpp +++ b/xmltooling/io/HTTPResponse.cpp @@ -24,6 +24,28 @@ #include "HTTPResponse.h" using namespace xmltooling; +using std::istream; + +GenericResponse::GenericResponse() +{ +} + +GenericResponse::~GenericResponse() +{ +} + +HTTPResponse::HTTPResponse() +{ +} + +HTTPResponse::~HTTPResponse() +{ +} + +void HTTPResponse::setContentType(const char* type) +{ + setResponseHeader("Content-Type", type); +} void HTTPResponse::setCookie(const char* name, const char* value) { @@ -31,3 +53,13 @@ void HTTPResponse::setCookie(const char* name, const char* value) cookie = cookie + '=' + value; setResponseHeader("Set-Cookie", cookie.c_str()); } + +long HTTPResponse::sendError(istream& inputStream) +{ + return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_ERROR); +} + +long HTTPResponse::sendResponse(istream& inputStream) +{ + return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_OK); +} diff --git a/xmltooling/io/HTTPResponse.h b/xmltooling/io/HTTPResponse.h index ab36b93..6c38321 100644 --- a/xmltooling/io/HTTPResponse.h +++ b/xmltooling/io/HTTPResponse.h @@ -38,13 +38,11 @@ namespace xmltooling { */ class XMLTOOL_API HTTPResponse : public GenericResponse { protected: - HTTPResponse() {} + HTTPResponse(); public: - virtual ~HTTPResponse() {} + virtual ~HTTPResponse(); - void setContentType(const char* type) { - setResponseHeader("Content-Type", type); - } + void setContentType(const char* type); /** * Sets or clears a response header. @@ -81,15 +79,10 @@ namespace xmltooling { XMLTOOLING_HTTP_STATUS_ERROR = 500 }; - using GenericResponse::sendResponse; - - long sendError(std::istream& inputStream) { - return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_ERROR); - } + long sendError(std::istream& inputStream); - long sendResponse(std::istream& inputStream) { - return sendResponse(inputStream, XMLTOOLING_HTTP_STATUS_OK); - } + using GenericResponse::sendResponse; + long sendResponse(std::istream& inputStream); }; }; diff --git a/xmltooling/security/AbstractPKIXTrustEngine.h b/xmltooling/security/AbstractPKIXTrustEngine.h index 9c6ef91..5d1a0d8 100644 --- a/xmltooling/security/AbstractPKIXTrustEngine.h +++ b/xmltooling/security/AbstractPKIXTrustEngine.h @@ -26,10 +26,11 @@ #include #include -#include namespace xmltooling { + class XMLTOOL_API XSECCryptoX509CRL; + /** * A trust engine that uses X.509 trust anchors and CRLs associated with a peer * to perform PKIX validation of signatures and credentials. @@ -69,7 +70,7 @@ namespace xmltooling { bool checkEntityNames(X509* certEE, const CredentialResolver& credResolver, const CredentialCriteria& criteria) const; public: - virtual ~AbstractPKIXTrustEngine() {} + virtual ~AbstractPKIXTrustEngine(); bool validate( xmlsignature::Signature& sig, @@ -110,10 +111,10 @@ namespace xmltooling { class XMLTOOL_API PKIXValidationInfoIterator { MAKE_NONCOPYABLE(PKIXValidationInfoIterator); protected: - PKIXValidationInfoIterator() {} + PKIXValidationInfoIterator(); public: - virtual ~PKIXValidationInfoIterator() {} + virtual ~PKIXValidationInfoIterator(); /** * Advances to the next set of information, if any. diff --git a/xmltooling/security/BasicX509Credential.h b/xmltooling/security/BasicX509Credential.h index 0d899fd..09d9ffe 100644 --- a/xmltooling/security/BasicX509Credential.h +++ b/xmltooling/security/BasicX509Credential.h @@ -24,9 +24,14 @@ #define __xmltooling_basicx509cred_h__ #include -#include -#include +#include +#include +#include + +namespace xmlsignature { + class XMLTOOL_API KeyInfo; +}; namespace xmltooling { @@ -101,7 +106,7 @@ namespace xmltooling { public: virtual ~BasicX509Credential(); - // Virtual overrides. + // Virtual function overrides. unsigned int getUsage() const; const char* getAlgorithm() const; unsigned int getKeySize() const; diff --git a/xmltooling/security/ChainingTrustEngine.h b/xmltooling/security/ChainingTrustEngine.h index 696e539..ebee77e 100644 --- a/xmltooling/security/ChainingTrustEngine.h +++ b/xmltooling/security/ChainingTrustEngine.h @@ -26,6 +26,8 @@ #include #include +#include + namespace xmltooling { /** diff --git a/xmltooling/security/Credential.h b/xmltooling/security/Credential.h index ecd575a..781c3d8 100644 --- a/xmltooling/security/Credential.h +++ b/xmltooling/security/Credential.h @@ -24,11 +24,12 @@ #define __xmltooling_cred_h__ #include -#include #include #include +class XSECCryptoKey; + namespace xmlsignature { class XMLTOOL_API KeyInfo; }; @@ -48,10 +49,10 @@ namespace xmltooling { { MAKE_NONCOPYABLE(Credential); protected: - Credential() {} + Credential(); public: - virtual ~Credential() {} + virtual ~Credential(); /** * Bitmask constants for limiting resolution process inside a CredentialResolver. @@ -139,9 +140,7 @@ namespace xmltooling { * * @return resolution context of the credential */ - virtual const CredentialContext* getCredentalContext() const { - return NULL; - } + virtual const CredentialContext* getCredentalContext() const; }; }; diff --git a/xmltooling/security/CredentialContext.h b/xmltooling/security/CredentialContext.h index 7cd3abd..aa38656 100644 --- a/xmltooling/security/CredentialContext.h +++ b/xmltooling/security/CredentialContext.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -36,10 +36,10 @@ namespace xmltooling { { MAKE_NONCOPYABLE(CredentialContext); protected: - CredentialContext() {} + CredentialContext(); public: - virtual ~CredentialContext() {} + virtual ~CredentialContext(); }; }; diff --git a/xmltooling/security/CredentialCriteria.h b/xmltooling/security/CredentialCriteria.h index 711b431..c7b711d 100644 --- a/xmltooling/security/CredentialCriteria.h +++ b/xmltooling/security/CredentialCriteria.h @@ -69,76 +69,56 @@ namespace xmltooling { * * @return the usage mask */ - unsigned int getUsage() const { - return m_keyUsage; - } + unsigned int getUsage() const; /** * Set key usage criteria. * * @param usage the usage mask to set */ - void setUsage(unsigned int usage) { - m_keyUsage = usage; - } + void setUsage(unsigned int usage); /** * Get the peer name criteria. * * @return the peer name */ - const char* getPeerName() const { - return m_peerName.c_str(); - } + const char* getPeerName() const; /** * Set the peer name criteria. * * @param peerName peer name to set */ - void setPeerName(const char* peerName) { - m_peerName.erase(); - if (peerName) - m_peerName = peerName; - } + void setPeerName(const char* peerName); /** * Get the key algorithm criteria. * * @return the key algorithm */ - const char* getKeyAlgorithm() const { - return m_keyAlgorithm.c_str(); - } + const char* getKeyAlgorithm() const; /** * Set the key algorithm criteria. * * @param keyAlgorithm The key algorithm to set */ - void setKeyAlgorithm(const char* keyAlgorithm) { - m_keyAlgorithm.erase(); - if (keyAlgorithm) - m_keyAlgorithm = keyAlgorithm; - } + void setKeyAlgorithm(const char* keyAlgorithm); /** * Get the key size criteria. * * @return the key size, or 0 */ - unsigned int getKeySize() const { - return m_keySize; - } + unsigned int getKeySize() const; /** * Set the key size criteria. * * @param keySize Key size to set */ - void setKeySize(unsigned int keySize) { - m_keySize = keySize; - } + void setKeySize(unsigned int keySize); /** * Set the key algorithm and size criteria based on an XML algorithm specifier. @@ -152,27 +132,21 @@ namespace xmltooling { * * @return an immutable set of key names */ - const std::set& getKeyNames() const { - return m_keyNames; - } + const std::set& getKeyNames() const; /** * Gets key name criteria. * * @return a mutable set of key names */ - std::set& getKeyNames() { - return m_keyNames; - } + std::set& getKeyNames(); /** * Returns the public key criteria. * * @return a public key */ - virtual XSECCryptoKey* getPublicKey() const { - return m_key; - } + virtual XSECCryptoKey* getPublicKey() const; /** * Sets the public key criteria. @@ -182,9 +156,7 @@ namespace xmltooling { * * @param key a public key */ - void setPublicKey(XSECCryptoKey* key) { - m_key = key; - } + void setPublicKey(XSECCryptoKey* key); /** * Bitmask constants controlling the kinds of criteria set automatically @@ -200,9 +172,7 @@ namespace xmltooling { * * @return the KeyInfo criteria */ - const xmlsignature::KeyInfo* getKeyInfo() const { - return m_keyInfo; - } + const xmlsignature::KeyInfo* getKeyInfo() const; /** * Sets the KeyInfo criteria. @@ -217,9 +187,7 @@ namespace xmltooling { * * @return the native KeyInfo criteria */ - DSIGKeyInfoList* getNativeKeyInfo() const { - return m_nativeKeyInfo; - } + DSIGKeyInfoList* getNativeKeyInfo() const; /** * Sets the KeyInfo criteria. diff --git a/xmltooling/security/CredentialResolver.h b/xmltooling/security/CredentialResolver.h index 2c4b2cf..5cd31fc 100644 --- a/xmltooling/security/CredentialResolver.h +++ b/xmltooling/security/CredentialResolver.h @@ -37,10 +37,10 @@ namespace xmltooling { { MAKE_NONCOPYABLE(CredentialResolver); protected: - CredentialResolver() {} + CredentialResolver(); public: - virtual ~CredentialResolver() {} + virtual ~CredentialResolver(); /** * Returns a single Credential according to the supplied criteria. diff --git a/xmltooling/security/KeyInfoCredentialContext.h b/xmltooling/security/KeyInfoCredentialContext.h index 589d2cf..56d927a 100644 --- a/xmltooling/security/KeyInfoCredentialContext.h +++ b/xmltooling/security/KeyInfoCredentialContext.h @@ -44,36 +44,30 @@ namespace xmltooling { * * @param keyInfo surrounding KeyInfo context object */ - KeyInfoCredentialContext(const xmlsignature::KeyInfo* keyInfo=NULL) : m_keyInfo(keyInfo), m_nativeKeyInfo(NULL) { - } + KeyInfoCredentialContext(const xmlsignature::KeyInfo* keyInfo=NULL); /** * Constructor * * @param keyInfo surrounding native KeyInfo context object */ - KeyInfoCredentialContext(DSIGKeyInfoList* keyInfo) : m_keyInfo(NULL), m_nativeKeyInfo(keyInfo) { - } + KeyInfoCredentialContext(DSIGKeyInfoList* keyInfo); - virtual ~KeyInfoCredentialContext() {} + virtual ~KeyInfoCredentialContext(); /** * Gets the KeyInfo context. * * @return the KeyInfo context */ - const xmlsignature::KeyInfo* getKeyInfo() const { - return m_keyInfo; - } + const xmlsignature::KeyInfo* getKeyInfo() const; /** * Gets the native KeyInfo context. * * @return the native KeyInfo context */ - DSIGKeyInfoList* getNativeKeyInfo() const { - return m_nativeKeyInfo; - } + DSIGKeyInfoList* getNativeKeyInfo() const; private: const xmlsignature::KeyInfo* m_keyInfo; diff --git a/xmltooling/security/KeyInfoResolver.h b/xmltooling/security/KeyInfoResolver.h index b2f5350..06163b8 100644 --- a/xmltooling/security/KeyInfoResolver.h +++ b/xmltooling/security/KeyInfoResolver.h @@ -50,9 +50,9 @@ namespace xmltooling { class XMLTOOL_API KeyInfoResolver { MAKE_NONCOPYABLE(KeyInfoResolver); protected: - KeyInfoResolver() {} + KeyInfoResolver(); public: - virtual ~KeyInfoResolver() {} + virtual ~KeyInfoResolver(); /** * Returns a credential based on the supplied KeyInfo information. diff --git a/xmltooling/security/OpenSSLCredential.h b/xmltooling/security/OpenSSLCredential.h index 73915dc..24ccf42 100644 --- a/xmltooling/security/OpenSSLCredential.h +++ b/xmltooling/security/OpenSSLCredential.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,10 +35,10 @@ namespace xmltooling { class XMLTOOL_API OpenSSLCredential : public virtual X509Credential { protected: - OpenSSLCredential() {} + OpenSSLCredential(); public: - virtual ~OpenSSLCredential() {} + virtual ~OpenSSLCredential(); /** * Attaches credential to an OpenSSL SSL context object. diff --git a/xmltooling/security/OpenSSLCryptoX509CRL.h b/xmltooling/security/OpenSSLCryptoX509CRL.h index fd243ae..1328420 100644 --- a/xmltooling/security/OpenSSLCryptoX509CRL.h +++ b/xmltooling/security/OpenSSLCryptoX509CRL.h @@ -35,16 +35,12 @@ namespace xmltooling { class XMLTOOL_API OpenSSLCryptoX509CRL : public XSECCryptoX509CRL { public: /** Default constructor. */ - OpenSSLCryptoX509CRL() : mp_X509CRL(NULL), m_DERX509CRL("") {} + OpenSSLCryptoX509CRL(); virtual ~OpenSSLCryptoX509CRL(); - const XMLCh* getProviderName() const { - return DSIGConstants::s_unicodeStrPROVOpenSSL; - } + const XMLCh* getProviderName() const; void loadX509CRLBase64Bin(const char* buf, unsigned int len); - safeBuffer& getDEREncodingSB(void) { - return m_DERX509CRL; - } + safeBuffer& getDEREncodingSB(); /** * Constructor @@ -58,9 +54,7 @@ namespace xmltooling { * * @return native CRL object, or NULL */ - X509_CRL* getOpenSSLX509CRL() { - return mp_X509CRL; - } + X509_CRL* getOpenSSLX509CRL(); XSECCryptoX509CRL* clone() const; diff --git a/xmltooling/security/OpenSSLTrustEngine.h b/xmltooling/security/OpenSSLTrustEngine.h index 3218cbc..46f68f1 100644 --- a/xmltooling/security/OpenSSLTrustEngine.h +++ b/xmltooling/security/OpenSSLTrustEngine.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -49,10 +49,10 @@ namespace xmltooling { * * @param e DOM to supply configuration for provider */ - OpenSSLTrustEngine(const xercesc::DOMElement* e=NULL) : X509TrustEngine(e) {} + OpenSSLTrustEngine(const xercesc::DOMElement* e=NULL); public: - virtual ~OpenSSLTrustEngine() {} + virtual ~OpenSSLTrustEngine(); using X509TrustEngine::validate; diff --git a/xmltooling/security/SecurityHelper.h b/xmltooling/security/SecurityHelper.h index 3b69ada..7ad65d9 100644 --- a/xmltooling/security/SecurityHelper.h +++ b/xmltooling/security/SecurityHelper.h @@ -25,6 +25,7 @@ #include +#include #include class XSECCryptoKey; diff --git a/xmltooling/security/SignatureTrustEngine.h b/xmltooling/security/SignatureTrustEngine.h index 6288951..fe17c16 100644 --- a/xmltooling/security/SignatureTrustEngine.h +++ b/xmltooling/security/SignatureTrustEngine.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -53,10 +53,10 @@ namespace xmltooling { * * @param e DOM to supply configuration for provider */ - SignatureTrustEngine(const xercesc::DOMElement* e=NULL) : TrustEngine(e) {} + SignatureTrustEngine(const xercesc::DOMElement* e=NULL); public: - virtual ~SignatureTrustEngine() {} + virtual ~SignatureTrustEngine(); /** * Determines whether an XML signature is correct and valid with respect to diff --git a/xmltooling/security/TrustEngine.h b/xmltooling/security/TrustEngine.h index c187648..1e50c43 100644 --- a/xmltooling/security/TrustEngine.h +++ b/xmltooling/security/TrustEngine.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/xmltooling/security/X509Credential.h b/xmltooling/security/X509Credential.h index edd83f4..86df5e2 100644 --- a/xmltooling/security/X509Credential.h +++ b/xmltooling/security/X509Credential.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,22 +24,23 @@ #define __xmltooling_x509cred_h__ #include -#include -#include +class XSECCryptoX509; namespace xmltooling { + class XMLTOOL_API XSECCryptoX509CRL; + /** * Wraps an X.509-based Credential. */ class XMLTOOL_API X509Credential : public virtual Credential { protected: - X509Credential() {} + X509Credential(); public: - virtual ~X509Credential() {} + virtual ~X509Credential(); /** * Bitmask constants for limiting resolution process inside a CredentialResolver. diff --git a/xmltooling/security/X509TrustEngine.h b/xmltooling/security/X509TrustEngine.h index b73ff0b..40590ee 100644 --- a/xmltooling/security/X509TrustEngine.h +++ b/xmltooling/security/X509TrustEngine.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,8 @@ #include #include -#include + +class XSECCryptoX509; namespace xmltooling { @@ -51,10 +52,10 @@ namespace xmltooling { * * @param e DOM to supply configuration for provider */ - X509TrustEngine(const xercesc::DOMElement* e=NULL) : TrustEngine(e) {} + X509TrustEngine(const xercesc::DOMElement* e=NULL); public: - virtual ~X509TrustEngine() {} + virtual ~X509TrustEngine(); /** * Determines whether an X.509 credential is valid with respect to the diff --git a/xmltooling/security/XSECCryptoX509CRL.h b/xmltooling/security/XSECCryptoX509CRL.h index e545293..ccfe05c 100644 --- a/xmltooling/security/XSECCryptoX509CRL.h +++ b/xmltooling/security/XSECCryptoX509CRL.h @@ -36,9 +36,9 @@ namespace xmltooling { class XMLTOOL_API XSECCryptoX509CRL { MAKE_NONCOPYABLE(XSECCryptoX509CRL); protected: - XSECCryptoX509CRL() {} + XSECCryptoX509CRL(); public: - virtual ~XSECCryptoX509CRL() {} + virtual ~XSECCryptoX509CRL(); /** * Returns a string that identifies the crypto owner of this library. diff --git a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp index a20f034..1f0f8fc 100644 --- a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp +++ b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp @@ -163,6 +163,14 @@ namespace { } }; +AbstractPKIXTrustEngine::PKIXValidationInfoIterator::PKIXValidationInfoIterator() +{ +} + +AbstractPKIXTrustEngine::PKIXValidationInfoIterator::~PKIXValidationInfoIterator() +{ +} + AbstractPKIXTrustEngine::AbstractPKIXTrustEngine(const xercesc::DOMElement* e) : TrustEngine(e), m_fullCRLChain(false) { static XMLCh fullCRLChain[] = UNICODE_LITERAL_12(f,u,l,l,C,R,L,C,h,a,i,n); @@ -170,6 +178,10 @@ AbstractPKIXTrustEngine::AbstractPKIXTrustEngine(const xercesc::DOMElement* e) : m_fullCRLChain = (flag && (*flag == xercesc::chLatin_t || *flag == xercesc::chDigit_1)); } +AbstractPKIXTrustEngine::~AbstractPKIXTrustEngine() +{ +} + bool AbstractPKIXTrustEngine::checkEntityNames( X509* certEE, const CredentialResolver& credResolver, const CredentialCriteria& criteria ) const diff --git a/xmltooling/security/impl/BasicX509Credential.cpp b/xmltooling/security/impl/BasicX509Credential.cpp index 9ceaf89..595dc8b 100644 --- a/xmltooling/security/impl/BasicX509Credential.cpp +++ b/xmltooling/security/impl/BasicX509Credential.cpp @@ -22,6 +22,9 @@ #include "internal.h" #include "security/BasicX509Credential.h" +#include "security/KeyInfoCredentialContext.h" +#include "security/OpenSSLCredential.h" +#include "security/XSECCryptoX509CRL.h" #include "signature/KeyInfo.h" #include @@ -32,6 +35,65 @@ using namespace xmlsignature; using namespace xmltooling; using namespace std; +Credential::Credential() +{ +} + +Credential::~Credential() +{ +} + +const CredentialContext* Credential::getCredentalContext() const +{ + return NULL; +} + +X509Credential::X509Credential() +{ +} + +X509Credential::~X509Credential() +{ +} + +OpenSSLCredential::OpenSSLCredential() +{ +} + +OpenSSLCredential::~OpenSSLCredential() +{ +} + +CredentialContext::CredentialContext() +{ +} + +CredentialContext::~CredentialContext() +{ +} + +KeyInfoCredentialContext::KeyInfoCredentialContext(const KeyInfo* keyInfo) : m_keyInfo(keyInfo), m_nativeKeyInfo(NULL) +{ +} + +KeyInfoCredentialContext::KeyInfoCredentialContext(DSIGKeyInfoList* keyInfo) : m_keyInfo(NULL), m_nativeKeyInfo(keyInfo) +{ +} + +KeyInfoCredentialContext::~KeyInfoCredentialContext() +{ +} + +const KeyInfo* KeyInfoCredentialContext::getKeyInfo() const +{ + return m_keyInfo; +} + +DSIGKeyInfoList* KeyInfoCredentialContext::getNativeKeyInfo() const +{ + return m_nativeKeyInfo; +} + BasicX509Credential::BasicX509Credential(bool ownCerts) : m_key(NULL), m_ownCerts(ownCerts), m_keyInfo(NULL), m_compactKeyInfo(NULL) { } diff --git a/xmltooling/security/impl/CredentialCriteria.cpp b/xmltooling/security/impl/CredentialCriteria.cpp index 12a6993..2e9a635 100644 --- a/xmltooling/security/impl/CredentialCriteria.cpp +++ b/xmltooling/security/impl/CredentialCriteria.cpp @@ -35,6 +35,8 @@ #include #include +using xmlsignature::KeyInfo; +using xmlsignature::Signature; using namespace xmltooling; using namespace std; @@ -49,6 +51,50 @@ CredentialCriteria::~CredentialCriteria() delete m_credential; } +unsigned int CredentialCriteria::getUsage() const +{ + return m_keyUsage; +} + +void CredentialCriteria::setUsage(unsigned int usage) +{ + m_keyUsage = usage; +} + +const char* CredentialCriteria::getPeerName() const +{ + return m_peerName.c_str(); +} + +void CredentialCriteria::setPeerName(const char* peerName) +{ + m_peerName.erase(); + if (peerName) + m_peerName = peerName; +} + +const char* CredentialCriteria::getKeyAlgorithm() const +{ + return m_keyAlgorithm.c_str(); +} + +void CredentialCriteria::setKeyAlgorithm(const char* keyAlgorithm) +{ + m_keyAlgorithm.erase(); + if (keyAlgorithm) + m_keyAlgorithm = keyAlgorithm; +} + +unsigned int CredentialCriteria::getKeySize() const +{ + return m_keySize; +} + +void CredentialCriteria::setKeySize(unsigned int keySize) +{ + m_keySize = keySize; +} + void CredentialCriteria::setXMLAlgorithm(const XMLCh* algorithm) { if (algorithm) { @@ -62,7 +108,32 @@ void CredentialCriteria::setXMLAlgorithm(const XMLCh* algorithm) } } -void CredentialCriteria::setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int extraction) +const set& CredentialCriteria::getKeyNames() const +{ + return m_keyNames; +} + +set& CredentialCriteria::getKeyNames() +{ + return m_keyNames; +} + +XSECCryptoKey* CredentialCriteria::getPublicKey() const +{ + return m_key; +} + +void CredentialCriteria::setPublicKey(XSECCryptoKey* key) +{ + m_key = key; +} + +const KeyInfo* CredentialCriteria::getKeyInfo() const +{ + return m_keyInfo; +} + +void CredentialCriteria::setKeyInfo(const KeyInfo* keyInfo, int extraction) { delete m_credential; m_credential = NULL; @@ -80,7 +151,12 @@ void CredentialCriteria::setKeyInfo(const xmlsignature::KeyInfo* keyInfo, int ex if (xcred) xcred->extract(); } -} +} + +DSIGKeyInfoList* CredentialCriteria::getNativeKeyInfo() const +{ + return m_nativeKeyInfo; +} void CredentialCriteria::setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extraction) { @@ -102,10 +178,10 @@ void CredentialCriteria::setNativeKeyInfo(DSIGKeyInfoList* keyInfo, int extracti } } -void CredentialCriteria::setSignature(const xmlsignature::Signature& sig, int extraction) +void CredentialCriteria::setSignature(const Signature& sig, int extraction) { setXMLAlgorithm(sig.getSignatureAlgorithm()); - xmlsignature::KeyInfo* k = sig.getKeyInfo(); + KeyInfo* k = sig.getKeyInfo(); if (k) return setKeyInfo(k, extraction); DSIGSignature* dsig = sig.getXMLSignature(); diff --git a/xmltooling/security/impl/CredentialResolver.cpp b/xmltooling/security/impl/CredentialResolver.cpp index 75585d5..58c135c 100644 --- a/xmltooling/security/impl/CredentialResolver.cpp +++ b/xmltooling/security/impl/CredentialResolver.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * CredentialResolver.cpp * - * Registration of factories for built-in resolvers + * An API for resolving keys and certificates based on application criteria. */ #include "internal.h" @@ -36,3 +36,11 @@ void XMLTOOL_API xmltooling::registerCredentialResolvers() conf.CredentialResolverManager.registerFactory(FILESYSTEM_CREDENTIAL_RESOLVER, FilesystemCredentialResolverFactory); conf.CredentialResolverManager.registerFactory(CHAINING_CREDENTIAL_RESOLVER, ChainingCredentialResolverFactory); } + +CredentialResolver::CredentialResolver() +{ +} + +CredentialResolver::~CredentialResolver() +{ +} diff --git a/xmltooling/security/impl/FilesystemCredentialResolver.cpp b/xmltooling/security/impl/FilesystemCredentialResolver.cpp index 2ae0edd..d7dd073 100644 --- a/xmltooling/security/impl/FilesystemCredentialResolver.cpp +++ b/xmltooling/security/impl/FilesystemCredentialResolver.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * FilesystemCredentialResolver.cpp * - * Supplies credentials from local files + * Supplies credentials from local files. */ #include "internal.h" @@ -28,10 +28,13 @@ #include "security/KeyInfoResolver.h" #include "security/OpenSSLCredential.h" #include "security/SecurityHelper.h" +#include "security/XSECCryptoX509CRL.h" #include "util/NDC.h" #include "util/PathResolver.h" +#include "util/Threads.h" #include "util/XMLHelper.h" +#include #include #include #include diff --git a/xmltooling/security/impl/InlineKeyResolver.cpp b/xmltooling/security/impl/InlineKeyResolver.cpp index f437ac4..252539b 100644 --- a/xmltooling/security/impl/InlineKeyResolver.cpp +++ b/xmltooling/security/impl/InlineKeyResolver.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ #include "security/BasicX509Credential.h" #include "security/KeyInfoCredentialContext.h" #include "security/KeyInfoResolver.h" +#include "security/XSECCryptoX509CRL.h" #include "signature/KeyInfo.h" #include "signature/Signature.h" #include "util/NDC.h" diff --git a/xmltooling/security/impl/KeyInfoResolver.cpp b/xmltooling/security/impl/KeyInfoResolver.cpp index 8e28538..0700fb8 100644 --- a/xmltooling/security/impl/KeyInfoResolver.cpp +++ b/xmltooling/security/impl/KeyInfoResolver.cpp @@ -17,7 +17,7 @@ /** * KeyInfoResolver.cpp * - * Registration of factories for built-in resolvers + * Resolves credentials from KeyInfo information. */ #include "internal.h" @@ -39,6 +39,14 @@ void XMLTOOL_API xmltooling::registerKeyInfoResolvers() conf.KeyInfoResolverManager.registerFactory(INLINE_KEYINFO_RESOLVER, InlineKeyInfoResolverFactory); } +KeyInfoResolver::KeyInfoResolver() +{ +} + +KeyInfoResolver::~KeyInfoResolver() +{ +} + Credential* KeyInfoResolver::resolve(const Signature* sig, int types) const { const KeyInfo* keyInfo = sig->getKeyInfo(); diff --git a/xmltooling/security/impl/OpenSSLCryptoX509CRL.cpp b/xmltooling/security/impl/OpenSSLCryptoX509CRL.cpp index fc8f7c6..54dd804 100644 --- a/xmltooling/security/impl/OpenSSLCryptoX509CRL.cpp +++ b/xmltooling/security/impl/OpenSSLCryptoX509CRL.cpp @@ -34,6 +34,10 @@ XSEC_USING_XERCES(Janitor); using namespace xmltooling; +OpenSSLCryptoX509CRL::OpenSSLCryptoX509CRL() : mp_X509CRL(NULL), m_DERX509CRL("") +{ +} + OpenSSLCryptoX509CRL::~OpenSSLCryptoX509CRL() { if (mp_X509CRL) @@ -73,7 +77,13 @@ OpenSSLCryptoX509CRL::OpenSSLCryptoX509CRL(X509_CRL* x) { BIO_free_all(b64); } -void OpenSSLCryptoX509CRL::loadX509CRLBase64Bin(const char* buf, unsigned int len) { +const XMLCh* OpenSSLCryptoX509CRL::getProviderName() const +{ + return DSIGConstants::s_unicodeStrPROVOpenSSL; +} + +void OpenSSLCryptoX509CRL::loadX509CRLBase64Bin(const char* buf, unsigned int len) +{ // Free anything currently held. @@ -111,6 +121,16 @@ void OpenSSLCryptoX509CRL::loadX509CRLBase64Bin(const char* buf, unsigned int le } +safeBuffer& OpenSSLCryptoX509CRL::getDEREncodingSB() +{ + return m_DERX509CRL; +} + +X509_CRL* OpenSSLCryptoX509CRL::getOpenSSLX509CRL() +{ + return mp_X509CRL; +} + XSECCryptoX509CRL* OpenSSLCryptoX509CRL::clone() const { OpenSSLCryptoX509CRL* copy = new OpenSSLCryptoX509CRL(); diff --git a/xmltooling/security/impl/TrustEngine.cpp b/xmltooling/security/impl/TrustEngine.cpp index 1c67741..d00a611 100644 --- a/xmltooling/security/impl/TrustEngine.cpp +++ b/xmltooling/security/impl/TrustEngine.cpp @@ -22,7 +22,8 @@ #include "internal.h" #include "security/KeyInfoResolver.h" -#include "security/TrustEngine.h" +#include "security/SignatureTrustEngine.h" +#include "security/OpenSSLTrustEngine.h" #include "util/XMLHelper.h" #include @@ -65,3 +66,27 @@ TrustEngine::~TrustEngine() { delete m_keyInfoResolver; } + +SignatureTrustEngine::SignatureTrustEngine(const DOMElement* e) : TrustEngine(e) +{ +} + +SignatureTrustEngine::~SignatureTrustEngine() +{ +} + +X509TrustEngine::X509TrustEngine(const DOMElement* e) : TrustEngine(e) +{ +} + +X509TrustEngine::~X509TrustEngine() +{ +} + +OpenSSLTrustEngine::OpenSSLTrustEngine(const DOMElement* e) : X509TrustEngine(e) +{ +} + +OpenSSLTrustEngine::~OpenSSLTrustEngine() +{ +} diff --git a/xmltooling/security/impl/XSECCryptoX509CRL.cpp b/xmltooling/security/impl/XSECCryptoX509CRL.cpp index 787a101..8111609 100644 --- a/xmltooling/security/impl/XSECCryptoX509CRL.cpp +++ b/xmltooling/security/impl/XSECCryptoX509CRL.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 The Apache Software Foundation. + * Copyright 2001-2009 The Apache Software Foundation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,6 +28,14 @@ using namespace xmltooling; +XSECCryptoX509CRL::XSECCryptoX509CRL() +{ +} + +XSECCryptoX509CRL::~XSECCryptoX509CRL() +{ +} + void XSECCryptoX509CRL::loadX509CRLPEM(const char* buf, unsigned int len) { const char * b; diff --git a/xmltooling/signature/ContentReference.h b/xmltooling/signature/ContentReference.h index a24c9d0..f902ee4 100644 --- a/xmltooling/signature/ContentReference.h +++ b/xmltooling/signature/ContentReference.h @@ -35,7 +35,7 @@ namespace xmlsignature { { MAKE_NONCOPYABLE(ContentReference); public: - virtual ~ContentReference() {} + virtual ~ContentReference(); /** * Given a native signature, asks the object to create the reference(s). @@ -46,7 +46,7 @@ namespace xmlsignature { protected: /** Default constructor. */ - ContentReference() {} + ContentReference(); }; }; diff --git a/xmltooling/signature/Signature.h b/xmltooling/signature/Signature.h index 58b5570..007f78b 100644 --- a/xmltooling/signature/Signature.h +++ b/xmltooling/signature/Signature.h @@ -23,8 +23,8 @@ #if !defined(__xmltooling_sig_h__) && !defined(XMLTOOLING_NO_XMLSEC) #define __xmltooling_sig_h__ -#include #include +#include class DSIGSignature; class XSECCryptoKey; @@ -46,7 +46,7 @@ namespace xmlsignature { class XMLTOOL_API Signature : public virtual xmltooling::XMLObject { public: - virtual ~Signature() {} + virtual ~Signature(); /** Element local name */ static const XMLCh LOCAL_NAME[]; @@ -195,7 +195,7 @@ namespace xmlsignature { protected: /** Default constructor. */ - Signature() {} + Signature(); }; /** diff --git a/xmltooling/signature/SignatureValidator.h b/xmltooling/signature/SignatureValidator.h index e948e40..f4f23e6 100644 --- a/xmltooling/signature/SignatureValidator.h +++ b/xmltooling/signature/SignatureValidator.h @@ -17,7 +17,7 @@ /** * @file xmltooling/signature/SignatureValidator.h * - * Validator for signatures based on an externally-supplied key + * Validator for signatures based on an externally-supplied key. */ #if !defined(__xmltooling_sigval_h__) && !defined(XMLTOOLING_NO_XMLSEC) @@ -55,7 +55,7 @@ namespace xmlsignature { */ SignatureValidator(const xmltooling::Credential* credential); - virtual ~SignatureValidator() {} + virtual ~SignatureValidator(); void validate(const xmltooling::XMLObject* xmlObject) const; diff --git a/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp index 32b12a7..22684ca 100644 --- a/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp +++ b/xmltooling/signature/impl/KeyInfoSchemaValidators.cpp @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,6 +23,7 @@ #include "internal.h" #include "exceptions.h" #include "signature/KeyInfo.h" +#include "validation/Validator.h" #include "validation/ValidatorSuite.h" using namespace xmlsignature; diff --git a/xmltooling/signature/impl/SignatureValidator.cpp b/xmltooling/signature/impl/SignatureValidator.cpp index 4c7df2b..3fbd883 100644 --- a/xmltooling/signature/impl/SignatureValidator.cpp +++ b/xmltooling/signature/impl/SignatureValidator.cpp @@ -40,6 +40,10 @@ SignatureValidator::SignatureValidator(const Credential* credential) : m_key(NUL { } +SignatureValidator::~SignatureValidator() +{ +} + void SignatureValidator::setKey(XSECCryptoKey* key) { m_key = key; diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index 1ef0838..7bce903 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -53,12 +53,12 @@ using namespace std; using xmlconstants::XMLSIG_NS; using xmlconstants::XMLSIG_PREFIX; +namespace xmlsignature { + #if defined (_MSC_VER) #pragma warning( push ) #pragma warning( disable : 4250 4251 ) #endif - -namespace xmlsignature { class XMLTOOL_DLLLOCAL XMLSecSignatureImpl : public UnknownElementImpl, public virtual Signature { @@ -129,12 +129,27 @@ namespace xmlsignature { mutable KeyInfo* m_keyInfo; ContentReference* m_reference; }; - -}; #if defined (_MSC_VER) #pragma warning( pop ) #endif +}; + +ContentReference::ContentReference() +{ +} + +ContentReference::~ContentReference() +{ +} + +Signature::Signature() +{ +} + +Signature::~Signature() +{ +} XMLSecSignatureImpl::~XMLSecSignatureImpl() { diff --git a/xmltooling/soap/HTTPSOAPTransport.h b/xmltooling/soap/HTTPSOAPTransport.h index 3623f04..ed2171e 100644 --- a/xmltooling/soap/HTTPSOAPTransport.h +++ b/xmltooling/soap/HTTPSOAPTransport.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ namespace xmltooling { class XMLTOOL_API HTTPSOAPTransport : public virtual SOAPTransport { protected: - HTTPSOAPTransport() {} + HTTPSOAPTransport(); public: - virtual ~HTTPSOAPTransport() {} + virtual ~HTTPSOAPTransport(); /** * Indicate whether content should be sent using HTTP 1.1 and diff --git a/xmltooling/soap/OpenSSLSOAPTransport.h b/xmltooling/soap/OpenSSLSOAPTransport.h index 13bdc59..eb38ef0 100644 --- a/xmltooling/soap/OpenSSLSOAPTransport.h +++ b/xmltooling/soap/OpenSSLSOAPTransport.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -35,9 +35,9 @@ namespace xmltooling { class XMLTOOL_API OpenSSLSOAPTransport : public virtual SOAPTransport { protected: - OpenSSLSOAPTransport() {} + OpenSSLSOAPTransport(); public: - virtual ~OpenSSLSOAPTransport() {} + virtual ~OpenSSLSOAPTransport(); /** OpenSSL context callback for manipulating credentials and validation behavior. */ typedef bool (*ssl_ctx_callback_fn)(OpenSSLSOAPTransport* transport, SSL_CTX* ssl_ctx, void* userptr); diff --git a/xmltooling/soap/SOAP.h b/xmltooling/soap/SOAP.h index 641040d..429f54f 100644 --- a/xmltooling/soap/SOAP.h +++ b/xmltooling/soap/SOAP.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ #include #include #include -#include /** * Macro for declaring SOAP builders. diff --git a/xmltooling/soap/SOAPClient.h b/xmltooling/soap/SOAPClient.h index 963c396..3752adf 100644 --- a/xmltooling/soap/SOAPClient.h +++ b/xmltooling/soap/SOAPClient.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,6 @@ #ifndef __xmltooling_soap11client_h__ #define __xmltooling_soap11client_h__ -#include #include namespace soap11 { @@ -46,7 +45,7 @@ namespace soap11 { * * @param validate true iff schema validation should be used */ - SOAPClient(bool validate=false) : m_validate(validate), m_transport(NULL) {} + SOAPClient(bool validate=false); virtual ~SOAPClient(); @@ -57,9 +56,7 @@ namespace soap11 { * * @param validate true iff the client should use a validating XML parser */ - void setValidating(bool validate=true) { - m_validate = validate; - } + void setValidating(bool validate=true); /** * Sends the supplied envelope to the identified recipient/endpoint. @@ -97,7 +94,7 @@ namespace soap11 { * * @param transport reference to transport layer */ - virtual void prepareTransport(xmltooling::SOAPTransport& transport) {} + virtual void prepareTransport(xmltooling::SOAPTransport& transport); /** * Handling of SOAP faults. diff --git a/xmltooling/soap/SOAPTransport.h b/xmltooling/soap/SOAPTransport.h index b2e7ef3..3a5c345 100644 --- a/xmltooling/soap/SOAPTransport.h +++ b/xmltooling/soap/SOAPTransport.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -43,9 +43,9 @@ namespace xmltooling { { MAKE_NONCOPYABLE(SOAPTransport); protected: - SOAPTransport() {} + SOAPTransport(); public: - virtual ~SOAPTransport() {} + virtual ~SOAPTransport(); /** * A simple structure to capture SOAP addressing information. @@ -166,9 +166,7 @@ namespace xmltooling { * @param value implementation- and option-specific string to use * @return true iff the transport supports the option and value supplied */ - virtual bool setProviderOption(const char* provider, const char* option, const char* value) { - return false; - } + virtual bool setProviderOption(const char* provider, const char* option, const char* value); /** * Sends a stream of data over the transport. The function may return without diff --git a/xmltooling/soap/impl/CURLSOAPTransport.cpp b/xmltooling/soap/impl/CURLSOAPTransport.cpp index ebf6f85..62d00e2 100644 --- a/xmltooling/soap/impl/CURLSOAPTransport.cpp +++ b/xmltooling/soap/impl/CURLSOAPTransport.cpp @@ -264,6 +264,35 @@ void xmltooling::termSOAPTransports() g_CURLPool = NULL; } +SOAPTransport::SOAPTransport() +{ +} + +SOAPTransport::~SOAPTransport() +{ +} + +bool SOAPTransport::setProviderOption(const char* provider, const char* option, const char* value) +{ + return false; +} + +HTTPSOAPTransport::HTTPSOAPTransport() +{ +} + +HTTPSOAPTransport::~HTTPSOAPTransport() +{ +} + +OpenSSLSOAPTransport::OpenSSLSOAPTransport() +{ +} + +OpenSSLSOAPTransport::~OpenSSLSOAPTransport() +{ +} + CURLPool::~CURLPool() { for (poolmap_t::iterator i=m_bindingMap.begin(); i!=m_bindingMap.end(); i++) { diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index 43e4c19..8eaeaed 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -36,11 +36,8 @@ using namespace xmltooling; using namespace xercesc; using namespace std; -void SOAPTransport::send(istream* in) +SOAPClient::SOAPClient(bool validate) : m_validate(validate), m_transport(NULL) { - if (!in) - throw IOException("SOAP transport does not support an empty request body."); - return send(*in); } SOAPClient::~SOAPClient() @@ -48,12 +45,24 @@ SOAPClient::~SOAPClient() delete m_transport; } +void SOAPClient::setValidating(bool validate) +{ + m_validate = validate; +} + void SOAPClient::reset() { delete m_transport; m_transport=NULL; } +void SOAPTransport::send(istream* in) +{ + if (!in) + throw IOException("SOAP transport does not support an empty request body."); + return send(*in); +} + void SOAPClient::send(const Envelope& env, const SOAPTransport::Address& addr) { // Prepare a transport object. @@ -128,6 +137,10 @@ Envelope* SOAPClient::receive() return env; } +void SOAPClient::prepareTransport(SOAPTransport& transport) +{ +} + bool SOAPClient::handleFault(const Fault& fault) { const xmltooling::QName* code = (fault.getFaultcode() ? fault.getFaultcode()->getCode() : NULL); diff --git a/xmltooling/soap/impl/SOAPSchemaValidators.cpp b/xmltooling/soap/impl/SOAPSchemaValidators.cpp index be701b8..8bea6d6 100644 --- a/xmltooling/soap/impl/SOAPSchemaValidators.cpp +++ b/xmltooling/soap/impl/SOAPSchemaValidators.cpp @@ -1,5 +1,5 @@ /* -* Copyright 2001-2007 Internet2 +* Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,12 +17,13 @@ /** * SOAPSchemaValidators.cpp * - * Schema validators for SOAP schema + * Schema validators for SOAP schema. */ #include "internal.h" #include "exceptions.h" #include "soap/SOAP.h" +#include "validation/Validator.h" #include "validation/ValidatorSuite.h" using namespace soap11; diff --git a/xmltooling/util/DateTime.cpp b/xmltooling/util/DateTime.cpp index ffe55cf..9183420 100644 --- a/xmltooling/util/DateTime.cpp +++ b/xmltooling/util/DateTime.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -1555,3 +1555,72 @@ void DateTime::searchMiliSeconds(XMLCh*& miliStartPtr, XMLCh*& miliEndPtr) const return; } +void DateTime::setBuffer(const XMLCh* const aString) +{ + reset(); + fEnd = (int) xercesc::XMLString::stringLen(aString); + if (fEnd > 0) { + if (fEnd > fBufferMaxLen) { + delete[] fBuffer; + fBufferMaxLen = fEnd + 8; + fBuffer = new XMLCh[fBufferMaxLen+1]; + } + memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh)); + } +} + +void DateTime::reset() +{ + for ( int i=0; i < xercesc::XMLDateTime::TOTAL_SIZE; i++ ) + fValue[i] = 0; + + fMiliSecond = 0; + fHasTime = false; + fTimeZone[hh] = fTimeZone[mm] = 0; + fStart = fEnd = 0; + + if (fBuffer) + *fBuffer = 0; +} + +void DateTime::copy(const DateTime& rhs) +{ + for ( int i = 0; i < xercesc::XMLDateTime::TOTAL_SIZE; i++ ) + fValue[i] = rhs.fValue[i]; + + fMiliSecond = rhs.fMiliSecond; + fHasTime = rhs.fHasTime; + fTimeZone[hh] = rhs.fTimeZone[hh]; + fTimeZone[mm] = rhs.fTimeZone[mm]; + fStart = rhs.fStart; + fEnd = rhs.fEnd; + + if (fEnd > 0) { + if (fEnd > fBufferMaxLen) { + delete[] fBuffer; + fBufferMaxLen = rhs.fBufferMaxLen; + fBuffer = new XMLCh[fBufferMaxLen+1]; + } + memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh)); + } +} + +void DateTime::initParser() +{ + fStart = 0; // to ensure scan from the very first beginning + // in case the pointer is updated accidentally by someone else. +} + +bool DateTime::isNormalized() const +{ + return (fValue[xercesc::XMLDateTime::utc] == xercesc::XMLDateTime::UTC_STD ? true : false); +} + +int DateTime::getRetVal(int c1, int c2) +{ + if ((c1 == xercesc::XMLDateTime::LESS_THAN && c2 == xercesc::XMLDateTime::GREATER_THAN) || + (c1 == xercesc::XMLDateTime::GREATER_THAN && c2 == xercesc::XMLDateTime::LESS_THAN)) + return xercesc::XMLDateTime::INDETERMINATE; + + return (c1 != xercesc::XMLDateTime::INDETERMINATE) ? c1 : c2; +} diff --git a/xmltooling/util/DateTime.h b/xmltooling/util/DateTime.h index b3fa78f..7a1ced1 100644 --- a/xmltooling/util/DateTime.h +++ b/xmltooling/util/DateTime.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -56,7 +56,7 @@ namespace xmltooling DateTime& operator=(const DateTime&); ~DateTime(); - inline void setBuffer(const XMLCh* const); + void setBuffer(const XMLCh* const); const XMLCh* getRawData() const; const XMLCh* getFormattedString() const; @@ -117,14 +117,14 @@ namespace xmltooling static int compareResult(int, int, bool); static void addDuration(DateTime* pDuration, const DateTime* const pBaseDate, int index); static int compareResult(const DateTime* const, const DateTime* const, bool, int); - static inline int getRetVal(int, int); + static int getRetVal(int, int); - inline void reset(); + void reset(); //inline void assertBuffer() const; - inline void copy(const DateTime&); + void copy(const DateTime&); - inline void initParser(); - inline bool isNormalized() const; + void initParser(); + bool isNormalized() const; void getDate(); void getTime(); @@ -157,77 +157,6 @@ namespace xmltooling double fMiliSecond; bool fHasTime; }; - - inline void DateTime::setBuffer(const XMLCh* const aString) - { - reset(); - fEnd = (int) xercesc::XMLString::stringLen(aString); - if (fEnd > 0) { - if (fEnd > fBufferMaxLen) { - delete[] fBuffer; - fBufferMaxLen = fEnd + 8; - fBuffer = new XMLCh[fBufferMaxLen+1]; - } - memcpy(fBuffer, aString, (fEnd+1) * sizeof(XMLCh)); - } - } - - inline void DateTime::reset() - { - for ( int i=0; i < xercesc::XMLDateTime::TOTAL_SIZE; i++ ) - fValue[i] = 0; - - fMiliSecond = 0; - fHasTime = false; - fTimeZone[hh] = fTimeZone[mm] = 0; - fStart = fEnd = 0; - - if (fBuffer) - *fBuffer = 0; - } - - inline void DateTime::copy(const DateTime& rhs) - { - for ( int i = 0; i < xercesc::XMLDateTime::TOTAL_SIZE; i++ ) - fValue[i] = rhs.fValue[i]; - - fMiliSecond = rhs.fMiliSecond; - fHasTime = rhs.fHasTime; - fTimeZone[hh] = rhs.fTimeZone[hh]; - fTimeZone[mm] = rhs.fTimeZone[mm]; - fStart = rhs.fStart; - fEnd = rhs.fEnd; - - if (fEnd > 0) { - if (fEnd > fBufferMaxLen) { - delete[] fBuffer; - fBufferMaxLen = rhs.fBufferMaxLen; - fBuffer = new XMLCh[fBufferMaxLen+1]; - } - memcpy(fBuffer, rhs.fBuffer, (fEnd+1) * sizeof(XMLCh)); - } - } - - inline void DateTime::initParser() - { - fStart = 0; // to ensure scan from the very first beginning - // in case the pointer is updated accidentally by someone else. - } - - inline bool DateTime::isNormalized() const - { - return (fValue[xercesc::XMLDateTime::utc] == xercesc::XMLDateTime::UTC_STD ? true : false); - } - - inline int DateTime::getRetVal(int c1, int c2) - { - if ((c1 == xercesc::XMLDateTime::LESS_THAN && c2 == xercesc::XMLDateTime::GREATER_THAN) || - (c1 == xercesc::XMLDateTime::GREATER_THAN && c2 == xercesc::XMLDateTime::LESS_THAN)) - return xercesc::XMLDateTime::INDETERMINATE; - - return (c1 != xercesc::XMLDateTime::INDETERMINATE) ? c1 : c2; - } - } #endif /* __xmltool_datetime_h__ */ diff --git a/xmltooling/util/ParserPool.cpp b/xmltooling/util/ParserPool.cpp index 25e4324..6da2911 100644 --- a/xmltooling/util/ParserPool.cpp +++ b/xmltooling/util/ParserPool.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,6 +26,7 @@ #include "util/CurlURLInputStream.h" #include "util/NDC.h" #include "util/ParserPool.h" +#include "util/Threads.h" #include "util/XMLHelper.h" #include @@ -440,6 +441,36 @@ void ParserPool::checkinBuilder(DOMBuilder* builder) #endif +StreamInputSource::StreamInputSource(istream& is, const char* systemId) : InputSource(systemId), m_is(is) +{ +} + +BinInputStream* StreamInputSource::makeStream() const +{ + return new StreamBinInputStream(m_is); +} + +StreamInputSource::StreamBinInputStream::StreamBinInputStream(istream& is) : m_is(is), m_pos(0) +{ +} + +#ifdef XMLTOOLING_XERCESC_64BITSAFE +XMLFilePos +#else +unsigned int +#endif +StreamInputSource::StreamBinInputStream::curPos() const +{ + return m_pos; +} + +#ifdef XMLTOOLING_XERCESC_64BITSAFE +const XMLCh* StreamInputSource::StreamBinInputStream::getContentType() const +{ + return NULL; +} +#endif + xsecsize_t StreamInputSource::StreamBinInputStream::readBytes(XMLByte* const toFill, const xsecsize_t maxToRead) { XMLByte* target=toFill; diff --git a/xmltooling/util/ParserPool.h b/xmltooling/util/ParserPool.h index e901a02..87ba21e 100644 --- a/xmltooling/util/ParserPool.h +++ b/xmltooling/util/ParserPool.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2008 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,6 @@ #define __xmltooling_pool_h__ #include -#include #include #include @@ -46,6 +45,8 @@ namespace xmltooling { + class XMLTOOL_API Mutex; + /** * A thread-safe pool of DOMBuilders that share characteristics. */ @@ -176,9 +177,9 @@ namespace xmltooling { * @param is reference to an input stream * @param systemId optional system identifier to attach to the stream */ - StreamInputSource(std::istream& is, const char* systemId=NULL) : xercesc::InputSource(systemId), m_is(is) {} + StreamInputSource(std::istream& is, const char* systemId=NULL); /// @cond off - virtual xercesc::BinInputStream* makeStream() const { return new StreamBinInputStream(m_is); } + xercesc::BinInputStream* makeStream() const; /// @endcond /** @@ -192,18 +193,15 @@ namespace xmltooling { * * @param is reference to an input stream */ - StreamBinInputStream(std::istream& is) : m_is(is), m_pos(0) {} + StreamBinInputStream(std::istream& is); /// @cond off #ifdef XMLTOOLING_XERCESC_64BITSAFE - XMLFilePos + XMLFilePos curPos() const; + const XMLCh* getContentType() const; #else - unsigned int + unsigned int curPos() const; #endif - curPos() const { return m_pos; } xsecsize_t readBytes(XMLByte* const toFill, const xsecsize_t maxToRead); -#ifdef XMLTOOLING_XERCESC_64BITSAFE - const XMLCh* getContentType() const { return NULL; } -#endif /// @endcond private: std::istream& m_is; diff --git a/xmltooling/util/PathResolver.cpp b/xmltooling/util/PathResolver.cpp index ff69c40..c0f2c11 100644 --- a/xmltooling/util/PathResolver.cpp +++ b/xmltooling/util/PathResolver.cpp @@ -36,6 +36,45 @@ PathResolver::PathResolver() : m_defaultPackage(PACKAGE_NAME), m_defaultPrefix(" setCfgDir("/etc"); } +PathResolver::~PathResolver() +{ +} + +void PathResolver::setDefaultPackageName(const char* pkgname) +{ + m_defaultPackage = pkgname; +} + +void PathResolver::setDefaultPrefix(const char* prefix) +{ + m_defaultPrefix = prefix; +} + +void PathResolver::setLibDir(const char* dir) +{ + m_lib = dir; +} + +void PathResolver::setLogDir(const char* dir) +{ + m_log = dir; +} + +void PathResolver::setXMLDir(const char* dir) +{ + m_xml = dir; +} + +void PathResolver::setRunDir(const char* dir) +{ + m_run = dir; +} + +void PathResolver::setCfgDir(const char* dir) +{ + m_cfg = dir; +} + bool PathResolver::isAbsolute(const char* s) const { switch (*s) { diff --git a/xmltooling/util/PathResolver.h b/xmltooling/util/PathResolver.h index 80ce6c4..a6b6363 100644 --- a/xmltooling/util/PathResolver.h +++ b/xmltooling/util/PathResolver.h @@ -36,7 +36,7 @@ namespace xmltooling { MAKE_NONCOPYABLE(PathResolver); public: PathResolver(); - virtual ~PathResolver() {} + virtual ~PathResolver(); /** Types of file resources to resolve. */ enum file_type_t { @@ -52,18 +52,14 @@ namespace xmltooling { * * @param pkgname name of default package to use */ - virtual void setDefaultPackageName(const char* pkgname) { - m_defaultPackage = pkgname; - } + virtual void setDefaultPackageName(const char* pkgname); /** * Set the default installation prefix to use when resolving files. * * @param prefix name of default prefix to use */ - virtual void setDefaultPrefix(const char* prefix) { - m_defaultPrefix = prefix; - } + virtual void setDefaultPrefix(const char* prefix); /** * Set the lib directory to use when resolving files. @@ -71,9 +67,7 @@ namespace xmltooling { * * @param dir the library directory to use */ - virtual void setLibDir(const char* dir) { - m_lib = dir; - } + virtual void setLibDir(const char* dir); /** * Set the log directory to use when resolving files. @@ -81,9 +75,7 @@ namespace xmltooling { * * @param dir the log directory to use */ - virtual void setLogDir(const char* dir) { - m_log = dir; - } + virtual void setLogDir(const char* dir); /** * Set the XML directory to use when resolving files. @@ -91,9 +83,7 @@ namespace xmltooling { * * @param dir the XML directory to use */ - virtual void setXMLDir(const char* dir) { - m_xml = dir; - } + virtual void setXMLDir(const char* dir); /** * Set the run directory to use when resolving files. @@ -101,9 +91,7 @@ namespace xmltooling { * * @param dir the run directory to use */ - virtual void setRunDir(const char* dir) { - m_run = dir; - } + virtual void setRunDir(const char* dir); /** * Set the config directory to use when resolving files. @@ -111,9 +99,7 @@ namespace xmltooling { * * @param dir the config directory to use */ - virtual void setCfgDir(const char* dir) { - m_cfg = dir; - } + virtual void setCfgDir(const char* dir); /** * Changes the input filename into an absolute pathname to the same file. diff --git a/xmltooling/util/ReloadableXMLFile.cpp b/xmltooling/util/ReloadableXMLFile.cpp index 0ea5ca5..726ad74 100644 --- a/xmltooling/util/ReloadableXMLFile.cpp +++ b/xmltooling/util/ReloadableXMLFile.cpp @@ -1,302 +1,303 @@ -/* - * Copyright 2001-2009 Internet2 - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/** - * @file ReloadableXMLFile.cpp - * - * Base class for file-based XML configuration. - */ - -#include "internal.h" -#include "util/NDC.h" -#include "util/PathResolver.h" -#include "util/ReloadableXMLFile.h" -#include "util/XMLConstants.h" -#include "util/XMLHelper.h" - -#include -#include -#include - -#include -#include -#include - -using namespace xmltooling::logging; -using namespace xmltooling; -using namespace xercesc; -using namespace std; - -static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i); -static const XMLCh url[] = UNICODE_LITERAL_3(u,r,l); -static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); -static const XMLCh pathname[] = UNICODE_LITERAL_8(p,a,t,h,n,a,m,e); -static const XMLCh file[] = UNICODE_LITERAL_4(f,i,l,e); -static const XMLCh filename[] = UNICODE_LITERAL_8(f,i,l,e,n,a,m,e); -static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); -static const XMLCh reloadChanges[] = UNICODE_LITERAL_13(r,e,l,o,a,d,C,h,a,n,g,e,s); -static const XMLCh reloadInterval[] = UNICODE_LITERAL_14(r,e,l,o,a,d,I,n,t,e,r,v,a,l); -static const XMLCh backingFilePath[] = UNICODE_LITERAL_15(b,a,c,k,i,n,g,F,i,l,e,P,a,t,h); - +/* + * Copyright 2001-2009 Internet2 + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file ReloadableXMLFile.cpp + * + * Base class for file-based XML configuration. + */ + +#include "internal.h" +#include "util/NDC.h" +#include "util/PathResolver.h" +#include "util/ReloadableXMLFile.h" +#include "util/Threads.h" +#include "util/XMLConstants.h" +#include "util/XMLHelper.h" + +#include +#include +#include + +#include +#include +#include + +using namespace xmltooling::logging; +using namespace xmltooling; +using namespace xercesc; +using namespace std; + +static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i); +static const XMLCh url[] = UNICODE_LITERAL_3(u,r,l); +static const XMLCh path[] = UNICODE_LITERAL_4(p,a,t,h); +static const XMLCh pathname[] = UNICODE_LITERAL_8(p,a,t,h,n,a,m,e); +static const XMLCh file[] = UNICODE_LITERAL_4(f,i,l,e); +static const XMLCh filename[] = UNICODE_LITERAL_8(f,i,l,e,n,a,m,e); +static const XMLCh validate[] = UNICODE_LITERAL_8(v,a,l,i,d,a,t,e); +static const XMLCh reloadChanges[] = UNICODE_LITERAL_13(r,e,l,o,a,d,C,h,a,n,g,e,s); +static const XMLCh reloadInterval[] = UNICODE_LITERAL_14(r,e,l,o,a,d,I,n,t,e,r,v,a,l); +static const XMLCh backingFilePath[] = UNICODE_LITERAL_15(b,a,c,k,i,n,g,F,i,l,e,P,a,t,h); + ReloadableXMLFile::~ReloadableXMLFile() { delete m_lock; } - -ReloadableXMLFile::ReloadableXMLFile(const DOMElement* e, Category& log) - : m_root(e), m_local(true), m_validate(false), m_filestamp(0), m_reloadInterval(0), m_lock(NULL), m_log(log) -{ -#ifdef _DEBUG - NDC ndc("ReloadableXMLFile"); -#endif - - // Establish source of data... - const XMLCh* source=e->getAttributeNS(NULL,uri); - if (!source || !*source) { - source=e->getAttributeNS(NULL,url); - if (!source || !*source) { - source=e->getAttributeNS(NULL,path); - if (!source || !*source) { - source=e->getAttributeNS(NULL,pathname); - if (!source || !*source) { - source=e->getAttributeNS(NULL,file); - if (!source || !*source) { - source=e->getAttributeNS(NULL,filename); - } - } - } - } - else - m_local=false; - } - else - m_local=false; - - if (source && *source) { - const XMLCh* flag=e->getAttributeNS(NULL,validate); - m_validate=(XMLString::equals(flag,xmlconstants::XML_TRUE) || XMLString::equals(flag,xmlconstants::XML_ONE)); - - auto_ptr_char temp(source); - m_source=temp.get(); - - if (!m_local && !strstr(m_source.c_str(),"://")) { - log.warn("deprecated usage of uri/url attribute for a local resource, use path instead"); - m_local=true; - } - - if (m_local) { - XMLToolingConfig::getConfig().getPathResolver()->resolve(m_source, PathResolver::XMLTOOLING_CFG_FILE); - - flag=e->getAttributeNS(NULL,reloadChanges); - if (!XMLString::equals(flag,xmlconstants::XML_FALSE) && !XMLString::equals(flag,xmlconstants::XML_ZERO)) { -#ifdef WIN32 - struct _stat stat_buf; - if (_stat(m_source.c_str(), &stat_buf) == 0) -#else - struct stat stat_buf; - if (stat(m_source.c_str(), &stat_buf) == 0) -#endif - m_filestamp=stat_buf.st_mtime; - else - throw IOException("Unable to access local file ($1)", params(1,m_source.c_str())); - m_lock=RWLock::create(); - } - log.debug("using local resource (%s), will %smonitor for changes", m_source.c_str(), m_lock ? "" : "not "); - } - else { - log.debug("using remote resource (%s)", m_source.c_str()); - source = e->getAttributeNS(NULL,backingFilePath); - if (source && *source) { - auto_ptr_char temp2(source); - m_backing=temp2.get(); - XMLToolingConfig::getConfig().getPathResolver()->resolve(m_backing, PathResolver::XMLTOOLING_RUN_FILE); - log.debug("backup remote resource with (%s)", m_backing.c_str()); - } - source = e->getAttributeNS(NULL,reloadInterval); - if (source && *source) { - m_reloadInterval = XMLString::parseInt(source); - if (m_reloadInterval > 0) { - m_log.debug("will reload remote resource at most every %d seconds", m_reloadInterval); - m_lock=RWLock::create(); - } - } - m_filestamp = time(NULL); // assume it gets loaded initially - } - } - else { - log.debug("no resource uri/path/name supplied, will load inline configuration"); - } -} - -pair ReloadableXMLFile::load(bool backup) -{ -#ifdef _DEBUG - NDC ndc("init"); -#endif - - try { - if (m_source.empty()) { - // Data comes from the DOM we were handed. - m_log.debug("loading inline configuration..."); - return make_pair(false,XMLHelper::getFirstChildElement(m_root)); - } - else { - // Data comes from a file we have to parse. - if (backup) - m_log.warn("using local backup of remote resource"); - else - m_log.debug("loading configuration from external resource..."); - - DOMDocument* doc=NULL; - if (m_local || backup) { - auto_ptr_XMLCh widenit(backup ? m_backing.c_str() : m_source.c_str()); - LocalFileInputSource src(widenit.get()); - Wrapper4InputSource dsrc(&src,false); - if (m_validate) - doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); - else - doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); - } - else { - URLInputSource src(m_root); - Wrapper4InputSource dsrc(&src,false); - if (m_validate) - doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); - else - doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); - } - - m_log.infoStream() << "loaded XML resource (" << (backup ? m_backing : m_source) << ")" << logging::eol; - - if (!backup && !m_backing.empty()) { - m_log.debug("backing up remote resource to (%s)", m_backing.c_str()); - try { - ofstream backer(m_backing.c_str()); - backer << *doc; - } - catch (exception& ex) { - m_log.crit("exception while backing up resource: %s", ex.what()); - } - } - - return make_pair(true,doc->getDocumentElement()); - } - } - catch (XMLException& e) { - auto_ptr_char msg(e.getMessage()); - m_log.errorStream() << "Xerces error while loading resource (" << (backup ? m_backing : m_source) << "): " - << msg.get() << logging::eol; - if (!backup && !m_backing.empty()) - return load(true); - throw XMLParserException(msg.get()); - } - catch (exception& e) { - m_log.errorStream() << "error while loading configuration from (" - << (m_source.empty() ? "inline" : (backup ? m_backing : m_source)) << "): " << e.what() << logging::eol; - if (!backup && !m_backing.empty()) - return load(true); - throw; - } -} - -Lockable* ReloadableXMLFile::lock() -{ - if (!m_lock) - return this; - - m_lock->rdlock(); - - // Check if we need to refresh. - if (m_local) { -#ifdef WIN32 - struct _stat stat_buf; - if (_stat(m_source.c_str(), &stat_buf) != 0) - return this; -#else - struct stat stat_buf; - if (stat(m_source.c_str(), &stat_buf) != 0) - return this; -#endif - if (m_filestamp>=stat_buf.st_mtime) - return this; - - // Elevate lock and recheck. - m_log.debug("timestamp of local resource changed, elevating to a write lock"); - m_lock->unlock(); - m_lock->wrlock(); - if (m_filestamp>=stat_buf.st_mtime) { - // Somebody else handled it, just downgrade. - m_log.debug("update of local resource handled by another thread, downgrading lock"); - m_lock->unlock(); - m_lock->rdlock(); - return this; - } - - // Update the timestamp regardless. No point in repeatedly trying. - m_filestamp=stat_buf.st_mtime; - m_log.info("change detected, reloading local resource..."); - } - else { - time_t now = time(NULL); - - // Time to reload? If we have no data, filestamp is zero - // and there's no way current time is less than the interval. - if (now - m_filestamp < m_reloadInterval) - return this; - - // Elevate lock and recheck. - m_log.debug("reload interval for remote resource elapsed, elevating to a write lock"); - m_lock->unlock(); - m_lock->wrlock(); - if (now - m_filestamp < m_reloadInterval) { - // Somebody else handled it, just downgrade. - m_log.debug("update of remote resource handled by another thread, downgrading lock"); - m_lock->unlock(); - m_lock->rdlock(); - return this; - } - - m_filestamp = now; - m_log.info("reloading remote resource..."); - } - - // Do this once... - try { - // At this point we're holding the write lock, so make sure we pop it. - SharedLock lockwrap(m_lock,false); - pair ret=load(); - if (ret.first) - ret.second->getOwnerDocument()->release(); - } catch (exception& ex) { - m_log.crit("maintaining existing configuration, error reloading resource (%s): %s", m_source.c_str(), ex.what()); - } - - // If we made it here, the swap may or may not have worked, but we need to relock. - m_log.debug("attempt to update resource complete, relocking"); - m_lock->rdlock(); - return this; -} - + +ReloadableXMLFile::ReloadableXMLFile(const DOMElement* e, Category& log) + : m_root(e), m_local(true), m_validate(false), m_filestamp(0), m_reloadInterval(0), m_lock(NULL), m_log(log) +{ +#ifdef _DEBUG + NDC ndc("ReloadableXMLFile"); +#endif + + // Establish source of data... + const XMLCh* source=e->getAttributeNS(NULL,uri); + if (!source || !*source) { + source=e->getAttributeNS(NULL,url); + if (!source || !*source) { + source=e->getAttributeNS(NULL,path); + if (!source || !*source) { + source=e->getAttributeNS(NULL,pathname); + if (!source || !*source) { + source=e->getAttributeNS(NULL,file); + if (!source || !*source) { + source=e->getAttributeNS(NULL,filename); + } + } + } + } + else + m_local=false; + } + else + m_local=false; + + if (source && *source) { + const XMLCh* flag=e->getAttributeNS(NULL,validate); + m_validate=(XMLString::equals(flag,xmlconstants::XML_TRUE) || XMLString::equals(flag,xmlconstants::XML_ONE)); + + auto_ptr_char temp(source); + m_source=temp.get(); + + if (!m_local && !strstr(m_source.c_str(),"://")) { + log.warn("deprecated usage of uri/url attribute for a local resource, use path instead"); + m_local=true; + } + + if (m_local) { + XMLToolingConfig::getConfig().getPathResolver()->resolve(m_source, PathResolver::XMLTOOLING_CFG_FILE); + + flag=e->getAttributeNS(NULL,reloadChanges); + if (!XMLString::equals(flag,xmlconstants::XML_FALSE) && !XMLString::equals(flag,xmlconstants::XML_ZERO)) { +#ifdef WIN32 + struct _stat stat_buf; + if (_stat(m_source.c_str(), &stat_buf) == 0) +#else + struct stat stat_buf; + if (stat(m_source.c_str(), &stat_buf) == 0) +#endif + m_filestamp=stat_buf.st_mtime; + else + throw IOException("Unable to access local file ($1)", params(1,m_source.c_str())); + m_lock=RWLock::create(); + } + log.debug("using local resource (%s), will %smonitor for changes", m_source.c_str(), m_lock ? "" : "not "); + } + else { + log.debug("using remote resource (%s)", m_source.c_str()); + source = e->getAttributeNS(NULL,backingFilePath); + if (source && *source) { + auto_ptr_char temp2(source); + m_backing=temp2.get(); + XMLToolingConfig::getConfig().getPathResolver()->resolve(m_backing, PathResolver::XMLTOOLING_RUN_FILE); + log.debug("backup remote resource with (%s)", m_backing.c_str()); + } + source = e->getAttributeNS(NULL,reloadInterval); + if (source && *source) { + m_reloadInterval = XMLString::parseInt(source); + if (m_reloadInterval > 0) { + m_log.debug("will reload remote resource at most every %d seconds", m_reloadInterval); + m_lock=RWLock::create(); + } + } + m_filestamp = time(NULL); // assume it gets loaded initially + } + } + else { + log.debug("no resource uri/path/name supplied, will load inline configuration"); + } +} + +pair ReloadableXMLFile::load(bool backup) +{ +#ifdef _DEBUG + NDC ndc("init"); +#endif + + try { + if (m_source.empty()) { + // Data comes from the DOM we were handed. + m_log.debug("loading inline configuration..."); + return make_pair(false,XMLHelper::getFirstChildElement(m_root)); + } + else { + // Data comes from a file we have to parse. + if (backup) + m_log.warn("using local backup of remote resource"); + else + m_log.debug("loading configuration from external resource..."); + + DOMDocument* doc=NULL; + if (m_local || backup) { + auto_ptr_XMLCh widenit(backup ? m_backing.c_str() : m_source.c_str()); + LocalFileInputSource src(widenit.get()); + Wrapper4InputSource dsrc(&src,false); + if (m_validate) + doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); + else + doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); + } + else { + URLInputSource src(m_root); + Wrapper4InputSource dsrc(&src,false); + if (m_validate) + doc=XMLToolingConfig::getConfig().getValidatingParser().parse(dsrc); + else + doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); + } + + m_log.infoStream() << "loaded XML resource (" << (backup ? m_backing : m_source) << ")" << logging::eol; + + if (!backup && !m_backing.empty()) { + m_log.debug("backing up remote resource to (%s)", m_backing.c_str()); + try { + ofstream backer(m_backing.c_str()); + backer << *doc; + } + catch (exception& ex) { + m_log.crit("exception while backing up resource: %s", ex.what()); + } + } + + return make_pair(true,doc->getDocumentElement()); + } + } + catch (XMLException& e) { + auto_ptr_char msg(e.getMessage()); + m_log.errorStream() << "Xerces error while loading resource (" << (backup ? m_backing : m_source) << "): " + << msg.get() << logging::eol; + if (!backup && !m_backing.empty()) + return load(true); + throw XMLParserException(msg.get()); + } + catch (exception& e) { + m_log.errorStream() << "error while loading configuration from (" + << (m_source.empty() ? "inline" : (backup ? m_backing : m_source)) << "): " << e.what() << logging::eol; + if (!backup && !m_backing.empty()) + return load(true); + throw; + } +} + +Lockable* ReloadableXMLFile::lock() +{ + if (!m_lock) + return this; + + m_lock->rdlock(); + + // Check if we need to refresh. + if (m_local) { +#ifdef WIN32 + struct _stat stat_buf; + if (_stat(m_source.c_str(), &stat_buf) != 0) + return this; +#else + struct stat stat_buf; + if (stat(m_source.c_str(), &stat_buf) != 0) + return this; +#endif + if (m_filestamp>=stat_buf.st_mtime) + return this; + + // Elevate lock and recheck. + m_log.debug("timestamp of local resource changed, elevating to a write lock"); + m_lock->unlock(); + m_lock->wrlock(); + if (m_filestamp>=stat_buf.st_mtime) { + // Somebody else handled it, just downgrade. + m_log.debug("update of local resource handled by another thread, downgrading lock"); + m_lock->unlock(); + m_lock->rdlock(); + return this; + } + + // Update the timestamp regardless. No point in repeatedly trying. + m_filestamp=stat_buf.st_mtime; + m_log.info("change detected, reloading local resource..."); + } + else { + time_t now = time(NULL); + + // Time to reload? If we have no data, filestamp is zero + // and there's no way current time is less than the interval. + if (now - m_filestamp < m_reloadInterval) + return this; + + // Elevate lock and recheck. + m_log.debug("reload interval for remote resource elapsed, elevating to a write lock"); + m_lock->unlock(); + m_lock->wrlock(); + if (now - m_filestamp < m_reloadInterval) { + // Somebody else handled it, just downgrade. + m_log.debug("update of remote resource handled by another thread, downgrading lock"); + m_lock->unlock(); + m_lock->rdlock(); + return this; + } + + m_filestamp = now; + m_log.info("reloading remote resource..."); + } + + // Do this once... + try { + // At this point we're holding the write lock, so make sure we pop it. + SharedLock lockwrap(m_lock,false); + pair ret=load(); + if (ret.first) + ret.second->getOwnerDocument()->release(); + } catch (exception& ex) { + m_log.crit("maintaining existing configuration, error reloading resource (%s): %s", m_source.c_str(), ex.what()); + } + + // If we made it here, the swap may or may not have worked, but we need to relock. + m_log.debug("attempt to update resource complete, relocking"); + m_lock->rdlock(); + return this; +} + void ReloadableXMLFile::unlock() { if (m_lock) m_lock->unlock(); } - + pair ReloadableXMLFile::load() { return load(false); diff --git a/xmltooling/util/ReplayCache.cpp b/xmltooling/util/ReplayCache.cpp index 7b53891..ea91d82 100644 --- a/xmltooling/util/ReplayCache.cpp +++ b/xmltooling/util/ReplayCache.cpp @@ -47,3 +47,9 @@ bool ReplayCache::check(const char* context, const char* s, time_t expires) m_storage->createString(context, s, "x", expires); return true; } + +bool ReplayCache::check(const char* context, const XMLCh* s, time_t expires) +{ + auto_ptr_char temp(s); + return check(context, temp.get(), expires); +} diff --git a/xmltooling/util/ReplayCache.h b/xmltooling/util/ReplayCache.h index 0f0d6e2..b208646 100644 --- a/xmltooling/util/ReplayCache.h +++ b/xmltooling/util/ReplayCache.h @@ -65,10 +65,7 @@ namespace xmltooling { * @param s value to check * @param expires time for disposal of value from cache */ - bool check(const char* context, const XMLCh* s, time_t expires) { - auto_ptr_char temp(s); - return check(context, temp.get(), expires); - } + bool check(const char* context, const XMLCh* s, time_t expires); private: bool m_owned; diff --git a/xmltooling/util/StorageService.cpp b/xmltooling/util/StorageService.cpp index 7b6717a..6c563b2 100644 --- a/xmltooling/util/StorageService.cpp +++ b/xmltooling/util/StorageService.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * StorageService.cpp * - * Registration of factories for built-in storage services + * Generic data storage interface. */ #include "internal.h" @@ -35,3 +35,11 @@ void XMLTOOL_API xmltooling::registerStorageServices() XMLToolingConfig& conf=XMLToolingConfig::getConfig(); conf.StorageServiceManager.registerFactory(MEMORY_STORAGE_SERVICE, MemoryStorageServiceFactory); } + +StorageService::StorageService() +{ +} + +StorageService::~StorageService() +{ +} diff --git a/xmltooling/util/StorageService.h b/xmltooling/util/StorageService.h index 2948b8e..04ee2c9 100644 --- a/xmltooling/util/StorageService.h +++ b/xmltooling/util/StorageService.h @@ -43,7 +43,7 @@ namespace xmltooling { { MAKE_NONCOPYABLE(StorageService); public: - virtual ~StorageService() {} + virtual ~StorageService(); /** * Creates a new "short" record in the storage service. @@ -189,7 +189,7 @@ namespace xmltooling { virtual void deleteContext(const char* context)=0; protected: - StorageService() {} + StorageService(); }; /** diff --git a/xmltooling/util/TemplateEngine.cpp b/xmltooling/util/TemplateEngine.cpp index 4062fca..3ff09ae 100644 --- a/xmltooling/util/TemplateEngine.cpp +++ b/xmltooling/util/TemplateEngine.cpp @@ -31,6 +31,23 @@ namespace { static const pair emptyPair; } +TemplateEngine::TemplateEngine() +{ + setTagPrefix("mlp"); +} + +TemplateEngine::~TemplateEngine() +{ +} + +TemplateEngine::TemplateParameters::TemplateParameters() : m_request(NULL) +{ +} + +TemplateEngine::TemplateParameters::~TemplateParameters() +{ +} + const char* TemplateEngine::TemplateParameters::getParameter(const char* name) const { map::const_iterator i=m_map.find(name); diff --git a/xmltooling/util/TemplateEngine.h b/xmltooling/util/TemplateEngine.h index a501f62..71606be 100644 --- a/xmltooling/util/TemplateEngine.h +++ b/xmltooling/util/TemplateEngine.h @@ -58,11 +58,9 @@ namespace xmltooling { MAKE_NONCOPYABLE(TemplateEngine); public: /** Default constructor. */ - TemplateEngine() { - setTagPrefix("mlp"); - } + TemplateEngine(); - virtual ~TemplateEngine() {} + virtual ~TemplateEngine(); /** * Sets the tag name to use when locating template replacement tags. @@ -77,8 +75,8 @@ namespace xmltooling { */ class XMLTOOL_API TemplateParameters { public: - TemplateParameters() : m_request(NULL) {} - virtual ~TemplateParameters() {} + TemplateParameters(); + virtual ~TemplateParameters(); /** Map of known parameters to supply to template. */ std::map m_map; diff --git a/xmltooling/util/URLEncoder.cpp b/xmltooling/util/URLEncoder.cpp index 88e316c..0196f2b 100644 --- a/xmltooling/util/URLEncoder.cpp +++ b/xmltooling/util/URLEncoder.cpp @@ -37,6 +37,14 @@ static char x2c(char *what) return(digit); } +URLEncoder::URLEncoder() +{ +} + +URLEncoder::~URLEncoder() +{ +} + void URLEncoder::decode(char* s) const { register int x,y; diff --git a/xmltooling/util/URLEncoder.h b/xmltooling/util/URLEncoder.h index f07080a..1ba61b6 100644 --- a/xmltooling/util/URLEncoder.h +++ b/xmltooling/util/URLEncoder.h @@ -37,10 +37,9 @@ namespace xmltooling { class XMLTOOL_API URLEncoder { MAKE_NONCOPYABLE(URLEncoder); public: - /** Default constructor. */ - URLEncoder() {} + URLEncoder(); - virtual ~URLEncoder() {} + virtual ~URLEncoder(); /** * Produce a URL-safe but equivalent version of the input string. diff --git a/xmltooling/util/XMLHelper.cpp b/xmltooling/util/XMLHelper.cpp index 9ebde32..73e6681 100644 --- a/xmltooling/util/XMLHelper.cpp +++ b/xmltooling/util/XMLHelper.cpp @@ -167,6 +167,11 @@ DOMElement* XMLHelper::appendChildElement(DOMElement* parentElement, DOMElement* return childElement; } +bool XMLHelper::isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XMLCh* local) +{ + return (n && XMLString::equals(local,n->getLocalName()) && XMLString::equals(ns,n->getNamespaceURI())); +} + const XMLCh* XMLHelper::getTextContent(const DOMElement* e) { DOMNode* child=e->getFirstChild(); diff --git a/xmltooling/util/XMLHelper.h b/xmltooling/util/XMLHelper.h index 81c86c4..98dff81 100644 --- a/xmltooling/util/XMLHelper.h +++ b/xmltooling/util/XMLHelper.h @@ -176,9 +176,7 @@ namespace xmltooling { * @param local local name to compare with * @return true iff the node's qualified name matches the other parameters */ - static bool isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XMLCh* local) { - return (n && xercesc::XMLString::equals(local,n->getLocalName()) && xercesc::XMLString::equals(ns,n->getNamespaceURI())); - } + static bool isNodeNamed(const xercesc::DOMNode* n, const XMLCh* ns, const XMLCh* local); /** * Returns the first matching child element of the node if any. diff --git a/xmltooling/validation/Validator.h b/xmltooling/validation/Validator.h index 72c2e95..afb7605 100644 --- a/xmltooling/validation/Validator.h +++ b/xmltooling/validation/Validator.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,7 +17,7 @@ /** * @file xmltooling/validation/Validator.h * - * Rules checking of XMLObjects + * Rules checking of XMLObjects. */ #ifndef __xmltooling_validator_h__ @@ -35,7 +35,7 @@ namespace xmltooling { { MAKE_NONCOPYABLE(Validator); public: - virtual ~Validator() {} + virtual ~Validator(); /** * Checks to see if an XMLObject is valid. @@ -47,7 +47,7 @@ namespace xmltooling { virtual void validate(const XMLObject* xmlObject) const=0; protected: - Validator() {} + Validator(); }; }; diff --git a/xmltooling/validation/ValidatorSuite.cpp b/xmltooling/validation/ValidatorSuite.cpp index 05b484a..766418d 100644 --- a/xmltooling/validation/ValidatorSuite.cpp +++ b/xmltooling/validation/ValidatorSuite.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,14 +21,41 @@ */ #include "internal.h" +#include "validation/Validator.h" #include "validation/ValidatorSuite.h" -#include "util/XMLHelper.h" using namespace xmltooling; using namespace std; +Validator::Validator() +{ +} + +Validator::~Validator() +{ +} + ValidatorSuite xmltooling::SchemaValidators("SchemaValidators"); +ValidatorSuite::ValidatorSuite(const char* id) : m_id(id) +{ +} + +ValidatorSuite::~ValidatorSuite() +{ + destroyValidators(); +} + +const char* ValidatorSuite::getId() +{ + return m_id.c_str(); +} + +void ValidatorSuite::registerValidator(const QName& key, Validator* validator) +{ + m_map.insert(pair(key, validator)); +} + void ValidatorSuite::deregisterValidators(const QName& key) { pair::iterator,multimap::iterator> range=m_map.equal_range(key); diff --git a/xmltooling/validation/ValidatorSuite.h b/xmltooling/validation/ValidatorSuite.h index 62feec0..a7d4ff1 100644 --- a/xmltooling/validation/ValidatorSuite.h +++ b/xmltooling/validation/ValidatorSuite.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,9 +24,9 @@ #define __xmltooling_valsuite_h__ #include -#include #include +#include #if defined (_MSC_VER) #pragma warning( push ) @@ -35,6 +35,8 @@ namespace xmltooling { + class XMLTOOL_API Validator; + /** * A collection of validators that can be applied to an XMLObject and its children. These collections can represent * usage specific checks, such as those outlined in schemas or profiles of specific XML specifications. @@ -51,20 +53,16 @@ namespace xmltooling { * * @param id an identifier for the suite */ - ValidatorSuite(const char* id) : m_id(id) {} + ValidatorSuite(const char* id); - ~ValidatorSuite() { - destroyValidators(); - } + ~ValidatorSuite(); /** * Gets a unique ID for this suite. * * @return a unique ID for this suite */ - const char* getId() { - return m_id.c_str(); - } + const char* getId(); /** * Evaluates the registered validators against the given XMLObject and it's children. @@ -81,9 +79,7 @@ namespace xmltooling { * @param key the key used to retrieve the validator * @param validator the validator */ - void registerValidator(const QName& key, Validator* validator) { - m_map.insert(std::pair(key, validator)); - } + void registerValidator(const QName& key, Validator* validator); /** * Deregisters validators. diff --git a/xmltooling/xmltooling-lite.vcproj b/xmltooling/xmltooling-lite.vcproj index 0fd03ca..ca08327 100644 --- a/xmltooling/xmltooling-lite.vcproj +++ b/xmltooling/xmltooling-lite.vcproj @@ -371,6 +371,10 @@ > + + diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index 5529d5b..f04bbe5 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -369,6 +369,10 @@ > + + diff --git a/xmltoolingtest/EncryptionTest.h b/xmltoolingtest/EncryptionTest.h index 7cd05e6..38edea7 100644 --- a/xmltoolingtest/EncryptionTest.h +++ b/xmltoolingtest/EncryptionTest.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,6 +18,7 @@ #include #include +#include #include #include #include diff --git a/xmltoolingtest/InlineKeyResolverTest.h b/xmltoolingtest/InlineKeyResolverTest.h index 007af8c..cc13252 100644 --- a/xmltoolingtest/InlineKeyResolverTest.h +++ b/xmltoolingtest/InlineKeyResolverTest.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007 Internet2 + * Copyright 2001-2009 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,6 +20,7 @@ #include #include #include +#include using namespace xmlsignature;