From 924fa732e0ad839fdad7ebf14fab616aa8539335 Mon Sep 17 00:00:00 2001 From: cantor Date: Sat, 1 Apr 2006 21:55:46 +0000 Subject: [PATCH] Evolving macros, reduce casting in accessors, add const collection access. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/trunk@68 de75baf8-a10c-0410-a50a-987c0e22f00f --- xmltooling/AbstractElementProxy.h | 6 +- xmltooling/AbstractXMLObject.cpp | 8 +- xmltooling/AbstractXMLObject.h | 6 +- xmltooling/ElementProxy.h | 8 +- xmltooling/Makefile.am | 4 +- xmltooling/XMLToolingConfig.cpp | 44 ++-- xmltooling/base.h | 305 +++++++++++++++++++--- xmltooling/signature/KeyInfo.h | 111 +++++--- xmltooling/signature/Signature.h | 25 +- xmltooling/signature/impl/KeyInfoImpl.cpp | 172 ++++++------ xmltooling/signature/impl/KeyInfoImpl.h | 54 ---- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 13 +- xmltooling/signature/impl/XMLSecSignatureImpl.h | 41 --- xmltooling/xmltooling.vcproj | 12 - xmltoolingtest/ComplexXMLObjectTest.h | 2 +- xmltoolingtest/XMLObjectBaseTestCase.h | 4 + 16 files changed, 492 insertions(+), 323 deletions(-) delete mode 100644 xmltooling/signature/impl/KeyInfoImpl.h delete mode 100644 xmltooling/signature/impl/XMLSecSignatureImpl.h diff --git a/xmltooling/AbstractElementProxy.h b/xmltooling/AbstractElementProxy.h index 1bbd34e..19bad7b 100644 --- a/xmltooling/AbstractElementProxy.h +++ b/xmltooling/AbstractElementProxy.h @@ -49,7 +49,11 @@ namespace xmltooling { virtual ListOf(XMLObject) getXMLObjects(); - protected: + virtual const std::list& getXMLObjects() const { + return m_children; + } + + protected: AbstractElementProxy() : m_value(NULL) {} /** Copy constructor. */ diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp index bb40e91..780304a 100644 --- a/xmltooling/AbstractXMLObject.cpp +++ b/xmltooling/AbstractXMLObject.cpp @@ -61,17 +61,15 @@ XMLObject* AbstractXMLObject::prepareForAssignment(XMLObject* oldValue, XMLObjec if (newValue) { releaseThisandParentDOM(); newValue->setParent(this); - return newValue; - } - else { - return NULL; } + return newValue; } if (oldValue != newValue) { delete oldValue; releaseThisandParentDOM(); - newValue->setParent(this); + if (newValue) + newValue->setParent(this); } return newValue; diff --git a/xmltooling/AbstractXMLObject.h b/xmltooling/AbstractXMLObject.h index 7a4ff1f..251a60f 100644 --- a/xmltooling/AbstractXMLObject.h +++ b/xmltooling/AbstractXMLObject.h @@ -125,11 +125,13 @@ namespace xmltooling { * A helper function for derived classes, for assignment of (singleton) XML objects. * * It is indifferent to whether either the old or the new version of the value is null. - * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate + * This method will do a safe compare of the objects and will also invalidate the DOM if appropriate. + * Note that since the new value (even if NULL) is always returned, it may be more efficient + * to discard the return value and just assign independently if a dynamic cast would be involved. * * @param oldValue - current value * @param newValue - proposed new value - * @return the value to assign + * @return the new value * * @throws XMLObjectException if the new child already has a parent. */ diff --git a/xmltooling/ElementProxy.h b/xmltooling/ElementProxy.h index 874139b..53b3d48 100644 --- a/xmltooling/ElementProxy.h +++ b/xmltooling/ElementProxy.h @@ -52,7 +52,6 @@ namespace xmltooling { * @param value value to set, or NULL to clear */ virtual void setTextContent(const XMLCh* value)=0; - /** * Gets a mutable list of child objects @@ -60,6 +59,13 @@ namespace xmltooling { * @return mutable list of child objects */ virtual ListOf(XMLObject) getXMLObjects()=0; + + /** + * Gets an immutable list of child objects + * + * @return immutable list of child objects + */ + virtual const std::list& getXMLObjects() const=0; }; }; diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index 5b4e2bc..fa5ee26 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -60,9 +60,7 @@ valinclude_HEADERS = \ validation/Validator.h noinst_HEADERS = \ - internal.h \ - signature/impl/KeyInfoImpl.h \ - signature/impl/XMLSecSignatureImpl.h + internal.h if BUILD_XMLSEC xmlsec_sources = \ diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 3cfbe79..2c8d410 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -21,15 +21,11 @@ */ #include "internal.h" - -#define XMLTOOLING_DEFINE_CONSTANTS -#include - #include "exceptions.h" #include "XMLToolingConfig.h" #include "impl/UnknownElement.h" -#include "signature/impl/KeyInfoImpl.h" -#include "signature/impl/XMLSecSignatureImpl.h" +#include "signature/KeyInfo.h" +#include "signature/Signature.h" #include "util/NDC.h" #include "util/XMLConstants.h" #include "validation/Validator.h" @@ -52,6 +48,17 @@ using namespace log4cpp; using namespace xmltooling; using namespace std; +#define REGISTER_ELEMENT(namespaceURI,cname) \ + q=QName(namespaceURI,cname##::LOCAL_NAME); \ + XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ + Validator::registerValidator(q,new cname##SchemaValidator()) + +#define REGISTER_TYPE(namespaceURI,cname) \ + q=QName(namespaceURI,cname##::TYPE_NAME); \ + XMLObjectBuilder::registerBuilder(q,new cname##Builder()); \ + Validator::registerValidator(q,new cname##SchemaValidator()) + + DECL_EXCEPTION_FACTORY(XMLParserException); DECL_EXCEPTION_FACTORY(XMLObjectException); DECL_EXCEPTION_FACTORY(MarshallingException); @@ -158,23 +165,18 @@ bool XMLToolingInternalConfig::init() // default registrations XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder()); - QName q(XMLConstants::XMLSIG_NS,KeyInfo::LOCAL_NAME); - XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl()); - Validator::registerValidator(q,new KeyInfoSchemaValidator()); - q=QName(XMLConstants::XMLSIG_NS,KeyInfo::TYPE_NAME); - XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl()); - Validator::registerValidator(q,new KeyInfoSchemaValidator()); - - q=QName(XMLConstants::XMLSIG_NS,KeyName::LOCAL_NAME); - XMLObjectBuilder::registerBuilder(q,new KeyNameBuilderImpl()); - Validator::registerValidator(q,new KeyNameSchemaValidator()); - - q=QName(XMLConstants::XMLSIG_NS,MgmtData::LOCAL_NAME); - XMLObjectBuilder::registerBuilder(q,new MgmtDataBuilderImpl()); - Validator::registerValidator(q,new MgmtDataSchemaValidator()); + QName q; + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyInfo); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,KeyName); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,MgmtData); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,RSAKeyValue); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Exponent); + REGISTER_ELEMENT(XMLConstants::XMLSIG_NS,Modulus); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,KeyInfo); + REGISTER_TYPE(XMLConstants::XMLSIG_NS,RSAKeyValue); #ifndef XMLTOOLING_NO_XMLSEC - XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new XMLSecSignatureBuilder()); + XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new SignatureBuilder()); #endif REGISTER_EXCEPTION_FACTORY(XMLParserException); diff --git a/xmltooling/base.h b/xmltooling/base.h index de15fe1..7de34c5 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -88,16 +88,89 @@ type(const type&); \ type& operator=(const type&); +#define UNICODE_LITERAL_1(a) {chLatin_##a, chNull} +#define UNICODE_LITERAL_2(a,b) {chLatin_##a, chLatin_##b, chNull} +#define UNICODE_LITERAL_3(a,b,c) {chLatin_##a, chLatin_##b, chLatin_##c, chNull} +#define UNICODE_LITERAL_4(a,b,c,d) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chNull} +#define UNICODE_LITERAL_5(a,b,c,d,e) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chNull} +#define UNICODE_LITERAL_6(a,b,c,d,e,f) {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chNull} +#define UNICODE_LITERAL_7(a,b,c,d,e,f,g) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chNull} +#define UNICODE_LITERAL_8(a,b,c,d,e,f,g,h) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chNull} +#define UNICODE_LITERAL_9(a,b,c,d,e,f,g,h,i) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, chNull} +#define UNICODE_LITERAL_10(a,b,c,d,e,f,g,h,i,j) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chNull} +#define UNICODE_LITERAL_11(a,b,c,d,e,f,g,h,i,j,k) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chNull} +#define UNICODE_LITERAL_12(a,b,c,d,e,f,g,h,i,j,k,l) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chNull} +#define UNICODE_LITERAL_13(a,b,c,d,e,f,g,h,i,j,k,l,m) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chNull} +#define UNICODE_LITERAL_14(a,b,c,d,e,f,g,h,i,j,k,l,m,n) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chNull} +#define UNICODE_LITERAL_15(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chNull} +#define UNICODE_LITERAL_16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chNull} +#define UNICODE_LITERAL_17(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chNull} +#define UNICODE_LITERAL_18(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, chNull} +#define UNICODE_LITERAL_19(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chNull} +#define UNICODE_LITERAL_20(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chNull} +#define UNICODE_LITERAL_21(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chNull} +#define UNICODE_LITERAL_22(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chNull} +#define UNICODE_LITERAL_23(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chNull} +#define UNICODE_LITERAL_24(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chNull} +#define UNICODE_LITERAL_25(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chNull} +#define UNICODE_LITERAL_26(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z) \ + {chLatin_##a, chLatin_##b, chLatin_##c, chLatin_##d, chLatin_##e, chLatin_##f, chLatin_##g, chLatin_##h, chLatin_##i, \ + chLatin_##j, chLatin_##k, chLatin_##l, chLatin_##m, chLatin_##n, chLatin_##o, chLatin_##p, chLatin_##q, chLatin_##r, \ + chLatin_##s, chLatin_##t, chLatin_##u, chLatin_##v, chLatin_##w, chLatin_##x, chLatin_##y, chLatin_##z, chNull} + /** * Begins the declaration of an XMLObject specialization. * Basic boilerplate includes a protected constructor, empty virtual destructor, * and Unicode constants for the default associated element's name and prefix. * - * @param cname the name of the class to declare - * @param base the base class to derive from using public virtual inheritance + * @param linkage linkage specifier for the class + * @param cname the name of the class to declare + * @param base the base class to derive from using public virtual inheritance */ -#define BEGIN_XMLOBJECT(cname,base) \ - class XMLTOOL_API cname : public virtual base, public virtual ValidatingXMLObject { \ +#define BEGIN_XMLOBJECT(linkage,cname,base) \ + class linkage cname : public virtual base, public virtual ValidatingXMLObject { \ protected: \ cname() {} \ public: \ @@ -119,12 +192,13 @@ * @param upcased the upcased name of the attribute */ #define DECL_XMLOBJECT_ATTRIB(proper,upcased) \ - XMLTOOLING_DOXYGEN(proper attribute name) \ - static const XMLCh upcased##_ATTRIB_NAME[]; \ - XMLTOOLING_DOXYGEN(Returns the proper attribute.) \ - virtual const XMLCh* get##proper() const=0; \ - XMLTOOLING_DOXYGEN(Sets the proper attribute.) \ - virtual void set##proper(const XMLCh* proper)=0 + public: \ + XMLTOOLING_DOXYGEN(proper attribute name) \ + static const XMLCh upcased##_ATTRIB_NAME[]; \ + XMLTOOLING_DOXYGEN(Returns the proper attribute.) \ + virtual const XMLCh* get##proper() const=0; \ + XMLTOOLING_DOXYGEN(Sets the proper attribute.) \ + virtual void set##proper(const XMLCh* proper)=0 /** * Implements get/set methods and a private member for a named XML attribute. @@ -143,6 +217,95 @@ } /** + * Declares abstract get/set methods for a typed XML child object. + * + * @param proper the proper name of the child type + */ +#define DECL_XMLOBJECT_CHILD(proper) \ + public: \ + XMLTOOLING_DOXYGEN(Returns the proper child.) \ + virtual proper* get##proper() const=0; \ + XMLTOOLING_DOXYGEN(Sets the proper child.) \ + virtual void set##proper(proper* child)=0 + +/** + * Implements get/set methods and a private list iterator member for a typed XML child object. + * + * @param proper the proper name of the child type + */ +#define IMPL_XMLOBJECT_CHILD(proper) \ + private: \ + proper* m_##proper; \ + std::list::iterator m_pos_##proper; \ + public: \ + proper* get##proper() const { \ + return m_##proper; \ + } \ + void set##proper(proper* child) { \ + prepareForAssignment(m_##proper,child); \ + *m_pos_##proper = m_##proper = child; \ + } + +/** + * Declares abstract get/set methods for a typed XML child collection. + * + * @param proper the proper name of the child type + */ +#define DECL_XMLOBJECT_CHILDREN(proper) \ + public: \ + XMLTOOLING_DOXYGEN(Returns modifiable proper collection.) \ + virtual VectorOf(proper) get##proper##s()=0; \ + XMLTOOLING_DOXYGEN(Returns reference to immutable proper collection.) \ + virtual const std::vector& get##proper##s() const=0 + +/** + * Implements get method and a private vector member for a typed XML child collection. + * + * @param proper the proper name of the child type + * @param fence insertion fence for new objects of the child collection in backing list + */ +#define IMPL_XMLOBJECT_CHILDREN(proper,fence) \ + private: \ + std::vector m_##proper##s; \ + public: \ + VectorOf(proper) get##proper##s() { \ + return VectorOf(proper)(this, m_##proper##s, &m_children, fence); \ + } \ + const std::vector& get##proper##s() const { \ + return m_##proper##s; \ + } + +/** + * Implements unmarshalling process branch for typed child collection element + * + * @param proper the proper name of the child type + * @param namespaceURI the XML namespace of the child element + */ +#define PROC_XMLOBJECT_CHILDREN(proper,namespaceURI) \ + if (XMLHelper::isNodeNamed(root,namespaceURI,proper##::LOCAL_NAME)) { \ + proper* typesafe=dynamic_cast(childXMLObject); \ + if (typesafe) { \ + get##proper##s().push_back(typesafe); \ + return; \ + } \ + } + +/** + * Implements unmarshalling process branch for typed child singleton element + * + * @param proper the proper name of the child type + * @param namespaceURI the XML namespace of the child element + */ +#define PROC_XMLOBJECT_CHILD(proper,namespaceURI) \ + if (XMLHelper::isNodeNamed(root,namespaceURI,proper##::LOCAL_NAME)) { \ + proper* typesafe=dynamic_cast(childXMLObject); \ + if (typesafe) { \ + set##proper(typesafe); \ + return; \ + } \ + } + +/** * Declares abstract get/set methods for named XML element content. * * @param proper the proper name to label the element's content @@ -199,19 +362,58 @@ } /** + * Declares and defines an implementation class for an XMLObject with + * a simple content model and type, handling it as string data. + * + * @param linkage linkage specifier for the class + * @param cname the name of the XMLObject specialization + * @param proper the proper name to label the element's content + */ +#define DECL_XMLOBJECTIMPL_SIMPLE(linkage,cname,proper) \ + class linkage cname##Impl \ + : public cname, \ + public AbstractDOMCachingXMLObject, \ + public AbstractValidatingXMLObject, \ + public AbstractXMLObjectMarshaller, \ + public AbstractXMLObjectUnmarshaller \ + { \ + public: \ + virtual ~cname##Impl() {} \ + cname##Impl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) \ + : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_##proper(NULL) { \ + } \ + cname##Impl(const cname##Impl& src) \ + : AbstractXMLObject(src), \ + AbstractDOMCachingXMLObject(src), \ + AbstractValidatingXMLObject(src), \ + m_##proper(XMLString::replicate(src.m_##proper)) { \ + } \ + IMPL_XMLOBJECT_CLONE(cname) \ + IMPL_XMLOBJECT_CONTENT(proper) \ + } + +/** * Begins the declaration of an XMLObjectBuilder specialization. * Basic boilerplate includes an empty virtual destructor, and - * a default builder. + * a default builder that defaults the element name. * - * @param cname the name of the XMLObject specialization + * @param linkage linkage specifier for the class + * @param cname the name of the XMLObject specialization + * @param namespaceURI the XML namespace of the default associated element + * @param namespacePrefix the XML namespace prefix of the default associated element */ -#define BEGIN_XMLOBJECTBUILDER(cname) \ +#define BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \ XMLTOOLING_DOXYGEN(Builder for cname objects.) \ - class XMLTOOL_API cname##Builder : public xmltooling::XMLObjectBuilder { \ + class linkage cname##Builder : public xmltooling::XMLObjectBuilder { \ public: \ virtual ~cname##Builder() {} \ XMLTOOLING_DOXYGEN(Default builder.) \ - virtual cname* buildObject() const=0 + virtual cname* buildObject() const { \ + return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \ + } \ + virtual cname* buildObject( \ + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL \ + ) const /** * Ends the declaration of an XMLObjectBuilder specialization. @@ -219,29 +421,24 @@ #define END_XMLOBJECTBUILDER } /** - * Begins the declaration of an XMLObjectBuilder specialization implementation class. + * Declares a generic XMLObjectBuilder specialization. * + * @param linkage linkage specifier for the class * @param cname the name of the XMLObject specialization * @param namespaceURI the XML namespace of the default associated element * @param namespacePrefix the XML namespace prefix of the default associated element */ -#define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI,namespacePrefix) \ - class XMLTOOL_DLLLOCAL cname##BuilderImpl : public cname##Builder { \ - public: \ - cname* buildObject( \ - const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL \ - ) const; \ - cname* buildObject() const { \ - return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \ - } + #define DECL_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix) \ + BEGIN_XMLOBJECTBUILDER(linkage,cname,namespaceURI,namespacePrefix); \ + END_XMLOBJECTBUILDER /** - * Begins the declaration of an XMLObjectBuilder specialization implementation class. + * Implements the standard XMLObjectBuilder specialization function. * * @param cname the name of the XMLObject specialization */ #define IMPL_XMLOBJECTBUILDER(cname) \ - cname* cname##BuilderImpl::buildObject( \ + cname* cname##Builder::buildObject( \ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \ ) const \ { \ @@ -249,30 +446,58 @@ } /** - * Ends the declaration of an XMLObjectBuilder specialization implementation class. - */ -#define END_XMLOBJECTBUILDERIMPL } - -/** - * Begins the declaration of a Validator specialization. + * Begins the declaration of a Schema Validator specialization. * + * @param linkage linkage specifier for the class * @param cname the base name of the Validator specialization */ - #define BEGIN_XMLOBJECTVALIDATOR(cname) \ - class cname##Validator : public Validator \ + #define BEGIN_XMLOBJECTVALIDATOR(linkage,cname) \ + class linkage cname##SchemaValidator : public Validator \ { \ public: \ - virtual ~cname##Validator() {} \ - Validator* clone() const { \ - return new cname##Validator(); \ + virtual ~cname##SchemaValidator() {} \ + virtual cname##SchemaValidator* clone() const { \ + return new cname##SchemaValidator(); \ } \ - void validate(const XMLObject* xmlObject) const + virtual void validate(const XMLObject* xmlObject) const { \ + const cname* ptr=dynamic_cast(xmlObject); \ + if (!ptr) \ + throw ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) /** * Ends the declaration of a Validator specialization. */ -#define END_XMLOBJECTVALIDATOR } +#define END_XMLOBJECTVALIDATOR } } +/** + * Validator code that checks the object type. + * + * @param cname the name of the XMLObject specialization + */ +#define XMLOBJECTVALIDATOR_CHECKTYPE(cname) \ + const cname* ptr=dynamic_cast(xmlObject); \ + if (!ptr) \ + throw ValidationException(#cname"SchemaValidator: unsupported object type ($1).",xmltooling::params(1,typeid(xmlObject).name())) + +/** + * Validator code that checks for a required attribute, content, or singleton. + * + * @param cname the name of the XMLObject specialization + * @param proper the proper name of the attribute, content, or singleton member + */ +#define XMLOBJECTVALIDATOR_REQUIRE(cname,proper) \ + if (!ptr->get##proper()) \ + throw ValidationException(#cname" must have "#proper".") + +/** + * Validator code that checks for a non-empty collection. + * + * @param cname the name of the XMLObject specialization + * @param proper the proper name of the collection item + */ +#define XMLOBJECTVALIDATOR_CHECKEMPTY(cname,proper) \ + if (ptr->get##proper##s().empty()) \ + throw ValidationException(#cname" must have at least one "#proper".") #include diff --git a/xmltooling/signature/KeyInfo.h b/xmltooling/signature/KeyInfo.h index 83c9e4c..50c8637 100644 --- a/xmltooling/signature/KeyInfo.h +++ b/xmltooling/signature/KeyInfo.h @@ -25,66 +25,99 @@ #define __xmltooling_keyinfo_h__ #include +#include #include +#include #include +#include + +#define DECL_XMLSIGOBJECTBUILDER(cname) \ + DECL_XMLOBJECTBUILDER(XMLTOOL_API,cname,XMLConstants::XMLSIG_NS,XMLConstants::XMLSIG_PREFIX) + namespace xmltooling { /** - * XMLObject representing XML Digital Signature, version 20020212, KeyInfo element. + * XMLObject representing XML Digital Signature, version 20020212, KeyName element. */ - BEGIN_XMLOBJECT(KeyInfo,ElementProxy); - DECL_XMLOBJECT_ATTRIB(Id,ID); - static const XMLCh TYPE_NAME[]; + BEGIN_XMLOBJECT(XMLTOOL_API,KeyName,XMLObject); + DECL_XMLOBJECT_CONTENT(Name); END_XMLOBJECT; - BEGIN_XMLOBJECTBUILDER(KeyInfo); - END_XMLOBJECTBUILDER; - -#ifdef XMLTOOLING_DEFINE_CONSTANTS - const XMLCh KeyInfo::LOCAL_NAME[] = { - chLatin_K, chLatin_e, chLatin_y, chLatin_I, chLatin_n, chLatin_f, chLatin_o, chNull - }; - const XMLCh KeyInfo::TYPE_NAME[] = { - chLatin_K, chLatin_e, chLatin_y, chLatin_I, chLatin_n, chLatin_f, chLatin_o, - chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull - }; - const XMLCh KeyInfo::ID_ATTRIB_NAME[] = { - chLatin_I, chLatin_d, chNull - }; -#endif + /** + * XMLObject representing XML Digital Signature, version 20020212, MgmtData element. + */ + BEGIN_XMLOBJECT(XMLTOOL_API,MgmtData,XMLObject); + DECL_XMLOBJECT_CONTENT(Data); + END_XMLOBJECT; /** - * XMLObject representing XML Digital Signature, version 20020212, KeyName element. + * XMLObject representing XML Digital Signature, version 20020212, Modulus element. */ - BEGIN_XMLOBJECT(KeyName,XMLObject); - DECL_XMLOBJECT_CONTENT(Name); + BEGIN_XMLOBJECT(XMLTOOL_API,Modulus,XMLObject); + DECL_XMLOBJECT_CONTENT(Value); END_XMLOBJECT; - BEGIN_XMLOBJECTBUILDER(KeyName); - END_XMLOBJECTBUILDER; + /** + * XMLObject representing XML Digital Signature, version 20020212, Exponent element. + */ + BEGIN_XMLOBJECT(XMLTOOL_API,Exponent,XMLObject); + DECL_XMLOBJECT_CONTENT(Value); + END_XMLOBJECT; -#ifdef XMLTOOLING_DEFINE_CONSTANTS - const XMLCh KeyName::LOCAL_NAME[] = { - chLatin_K, chLatin_e, chLatin_y, chLatin_N, chLatin_a, chLatin_m, chLatin_e, chNull - }; -#endif + /** + * XMLObject representing XML Digital Signature, version 20020212, RSAKeyValue element. + */ + BEGIN_XMLOBJECT(XMLTOOL_API,RSAKeyValue,XMLObject); + DECL_XMLOBJECT_CHILD(Modulus); + DECL_XMLOBJECT_CHILD(Exponent); + /** RSAKeyValueType local name */ + static const XMLCh TYPE_NAME[]; + END_XMLOBJECT; /** - * XMLObject representing XML Digital Signature, version 20020212, MgmtData element. + * XMLObject representing XML Digital Signature, version 20020212, KeyInfo element. */ - BEGIN_XMLOBJECT(MgmtData,XMLObject); - DECL_XMLOBJECT_CONTENT(Data); + BEGIN_XMLOBJECT(XMLTOOL_API,KeyInfo,ElementProxy); + DECL_XMLOBJECT_ATTRIB(Id,ID); + DECL_XMLOBJECT_CHILDREN(KeyName); + DECL_XMLOBJECT_CHILDREN(MgmtData); + /** KeyInfoType local name */ + static const XMLCh TYPE_NAME[]; END_XMLOBJECT; - BEGIN_XMLOBJECTBUILDER(MgmtData); - END_XMLOBJECTBUILDER; + DECL_XMLSIGOBJECTBUILDER(KeyName); + DECL_XMLSIGOBJECTBUILDER(MgmtData); + DECL_XMLSIGOBJECTBUILDER(Modulus); + DECL_XMLSIGOBJECTBUILDER(Exponent); + DECL_XMLSIGOBJECTBUILDER(RSAKeyValue); + DECL_XMLSIGOBJECTBUILDER(KeyInfo); + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyName); + XMLOBJECTVALIDATOR_REQUIRE(KeyName,Name); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,MgmtData); + XMLOBJECTVALIDATOR_REQUIRE(MgmtData,Data); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Modulus); + XMLOBJECTVALIDATOR_REQUIRE(Modulus,Value); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,Exponent); + XMLOBJECTVALIDATOR_REQUIRE(Exponent,Value); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,RSAKeyValue); + XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Modulus); + XMLOBJECTVALIDATOR_REQUIRE(RSAKeyValue,Exponent); + END_XMLOBJECTVALIDATOR; + + BEGIN_XMLOBJECTVALIDATOR(XMLTOOL_DLLLOCAL,KeyInfo); + XMLOBJECTVALIDATOR_CHECKEMPTY(KeyInfo,XMLObject); + END_XMLOBJECTVALIDATOR; -#ifdef XMLTOOLING_DEFINE_CONSTANTS - const XMLCh MgmtData::LOCAL_NAME[] = { - chLatin_M, chLatin_g, chLatin_m, chLatin_t, chLatin_D, chLatin_a, chLatin_t, chLatin_a, chNull - }; -#endif }; #endif /* __xmltooling_keyinfo_h__ */ diff --git a/xmltooling/signature/Signature.h b/xmltooling/signature/Signature.h index bf886fc..707ad2c 100644 --- a/xmltooling/signature/Signature.h +++ b/xmltooling/signature/Signature.h @@ -39,9 +39,6 @@ namespace xmltooling { public: virtual ~Signature() {} - /** Element prefix */ - static const XMLCh PREFIX[]; - /** Element local name */ static const XMLCh LOCAL_NAME[]; @@ -79,28 +76,24 @@ namespace xmltooling { Signature() {} }; -#ifdef XMLTOOLING_DEFINE_CONSTANTS - const XMLCh Signature::LOCAL_NAME[] = { - chLatin_S, chLatin_i, chLatin_g, chLatin_n, chLatin_a, chLatin_t, chLatin_u, chLatin_r, chLatin_e, chNull - }; - const XMLCh Signature::PREFIX[] = { - chLatin_d, chLatin_s, chNull - }; -#endif - /** * Builder for Signature objects. */ class XMLTOOL_API SignatureBuilder : public XMLObjectBuilder { public: - virtual ~SignatureBuilder() {} - + virtual Signature* buildObject( + const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL + ) const; + /** - * Default builder. + * Default builder + * + * @return empty Signature object */ - virtual Signature* buildObject() const=0; + virtual Signature* buildObject() const; }; + }; #endif /* __xmltooling_sig_h__ */ diff --git a/xmltooling/signature/impl/KeyInfoImpl.cpp b/xmltooling/signature/impl/KeyInfoImpl.cpp index 44dc6ab..b31de4e 100644 --- a/xmltooling/signature/impl/KeyInfoImpl.cpp +++ b/xmltooling/signature/impl/KeyInfoImpl.cpp @@ -25,11 +25,11 @@ #include "exceptions.h" #include "io/AbstractXMLObjectMarshaller.h" #include "io/AbstractXMLObjectUnmarshaller.h" -#include "signature/impl/KeyInfoImpl.h" +#include "signature/KeyInfo.h" #include "util/XMLHelper.h" #include "validation/AbstractValidatingXMLObject.h" -#include +#include using namespace xmltooling; using namespace std; @@ -41,6 +41,53 @@ using namespace std; namespace xmltooling { + class XMLTOOL_DLLLOCAL RSAKeyValueImpl + : public RSAKeyValue, + public AbstractDOMCachingXMLObject, + public AbstractValidatingXMLObject, + public AbstractXMLObjectMarshaller, + public AbstractXMLObjectUnmarshaller + { + public: + virtual ~RSAKeyValueImpl() {} + + RSAKeyValueImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) + : AbstractXMLObject(nsURI, localName, prefix, schemaType) { + init(); + } + + RSAKeyValueImpl(const RSAKeyValueImpl& src) + : AbstractXMLObject(src), + AbstractDOMCachingXMLObject(src), + AbstractValidatingXMLObject(src) { + init(); + setModulus(src.getModulus()); + setExponent(src.getExponent()); + } + + void init() { + m_Modulus=NULL; + m_Exponent=NULL; + m_children.push_back(NULL); + m_children.push_back(NULL); + m_pos_Modulus=m_children.begin(); + m_pos_Exponent=m_children.begin(); + m_pos_Exponent++; + } + + IMPL_XMLOBJECT_CLONE(RSAKeyValue); + IMPL_XMLOBJECT_CHILD(Modulus); + IMPL_XMLOBJECT_CHILD(Exponent); + + protected: + void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { + PROC_XMLOBJECT_CHILD(Modulus,XMLConstants::XMLSIG_NS); + PROC_XMLOBJECT_CHILD(Exponent,XMLConstants::XMLSIG_NS); + + throw UnmarshallingException("Invalid child element: $1",params(1,childXMLObject->getElementQName().toString())); + } + }; + class XMLTOOL_DLLLOCAL KeyInfoImpl : public KeyInfo, public AbstractDOMCachingXMLObject, @@ -64,12 +111,26 @@ namespace xmltooling { m_Id(XMLString::replicate(src.m_Id)) { for (list::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) { - getXMLObjects().push_back((*i) ? (*i)->clone() : NULL); + if (*i) { + KeyName* kn=dynamic_cast(*i); + if (kn) { + getKeyNames().push_back(kn->cloneKeyName()); + continue; + } + MgmtData* md=dynamic_cast(*i); + if (md) { + getMgmtDatas().push_back(md->cloneMgmtData()); + continue; + } + getXMLObjects().push_back((*i)->clone()); + } } } IMPL_XMLOBJECT_CLONE(KeyInfo); IMPL_XMLOBJECT_ATTRIB(Id); + IMPL_XMLOBJECT_CHILDREN(KeyName,m_children.end()); + IMPL_XMLOBJECT_CHILDREN(MgmtData,m_children.end()); protected: void marshallAttributes(DOMElement* domElement) const { @@ -90,7 +151,15 @@ namespace xmltooling { } void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { - getXMLObjects().push_back(childXMLObject); + PROC_XMLOBJECT_CHILDREN(KeyName,XMLConstants::XMLSIG_NS); + PROC_XMLOBJECT_CHILDREN(MgmtData,XMLConstants::XMLSIG_NS); + + // Unknown child. + const XMLCh* nsURI=childXMLObject->getElementQName().getNamespaceURI(); + if (!XMLString::equals(nsURI,XMLConstants::XMLSIG_NS) && nsURI && *nsURI) + getXMLObjects().push_back(childXMLObject); + + throw UnmarshallingException("Invalid child element: $1",params(1,childXMLObject->getElementQName().toString())); } void processAttribute(const DOMAttr* attribute) { @@ -101,55 +170,10 @@ namespace xmltooling { } }; - class XMLTOOL_DLLLOCAL KeyNameImpl - : public KeyName, - public AbstractDOMCachingXMLObject, - public AbstractValidatingXMLObject, - public AbstractXMLObjectMarshaller, - public AbstractXMLObjectUnmarshaller - { - public: - virtual ~KeyNameImpl() {} - - KeyNameImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Name(NULL) { - } - - KeyNameImpl(const KeyNameImpl& src) - : AbstractXMLObject(src), - AbstractDOMCachingXMLObject(src), - AbstractValidatingXMLObject(src), - m_Name(XMLString::replicate(src.m_Name)) { - } - - IMPL_XMLOBJECT_CLONE(KeyName); - IMPL_XMLOBJECT_CONTENT(Name); - }; - - class XMLTOOL_DLLLOCAL MgmtDataImpl - : public MgmtData, - public AbstractDOMCachingXMLObject, - public AbstractValidatingXMLObject, - public AbstractXMLObjectMarshaller, - public AbstractXMLObjectUnmarshaller - { - public: - virtual ~MgmtDataImpl() {} - - MgmtDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Data(NULL) { - } - - MgmtDataImpl(const MgmtDataImpl& src) - : AbstractXMLObject(src), - AbstractDOMCachingXMLObject(src), - AbstractValidatingXMLObject(src), - m_Data(XMLString::replicate(src.m_Data)) { - } - - IMPL_XMLOBJECT_CLONE(MgmtData); - IMPL_XMLOBJECT_CONTENT(Data); - }; + DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,KeyName,Name); + DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,MgmtData,Data); + DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,Modulus,Value); + DECL_XMLOBJECTIMPL_SIMPLE(XMLTOOL_DLLLOCAL,Exponent,Value); }; #if defined (_MSC_VER) @@ -161,32 +185,16 @@ namespace xmltooling { IMPL_XMLOBJECTBUILDER(KeyInfo); IMPL_XMLOBJECTBUILDER(KeyName); IMPL_XMLOBJECTBUILDER(MgmtData); - -// Validators - -void KeyInfoSchemaValidator::validate(const XMLObject* xmlObject) const -{ - const KeyInfo* ptr=dynamic_cast(xmlObject); - if (!ptr) - throw ValidationException("KeyInfoSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name())); - if (!ptr->hasChildren()) - throw ValidationException("KeyInfo is empty"); -} - -void KeyNameSchemaValidator::validate(const XMLObject* xmlObject) const -{ - const KeyName* ptr=dynamic_cast(xmlObject); - if (!ptr) - throw ValidationException("KeyNameSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name())); - if (XMLString::stringLen(ptr->getName())==0) - throw ValidationException("KeyName is empty"); -} - -void MgmtDataSchemaValidator::validate(const XMLObject* xmlObject) const -{ - const MgmtData* ptr=dynamic_cast(xmlObject); - if (!ptr) - throw ValidationException("MgmtDataSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name())); - if (XMLString::stringLen(ptr->getData())==0) - throw ValidationException("MgmtData is empty"); -} +IMPL_XMLOBJECTBUILDER(Modulus); +IMPL_XMLOBJECTBUILDER(Exponent); +IMPL_XMLOBJECTBUILDER(RSAKeyValue); + +const XMLCh KeyInfo::LOCAL_NAME[] = UNICODE_LITERAL_7(K,e,y,I,n,f,o); +const XMLCh KeyInfo::TYPE_NAME[] = UNICODE_LITERAL_11(K,e,y,I,n,f,o,T,y,p,e); +const XMLCh KeyInfo::ID_ATTRIB_NAME[] = UNICODE_LITERAL_2(I,d); +const XMLCh MgmtData::LOCAL_NAME[] = UNICODE_LITERAL_8(M,g,m,t,D,a,t,a); +const XMLCh KeyName::LOCAL_NAME[] = UNICODE_LITERAL_7(K,e,y,N,a,m,e); +const XMLCh Modulus::LOCAL_NAME[] = UNICODE_LITERAL_7(M,o,d,u,l,u,s); +const XMLCh Exponent::LOCAL_NAME[] = UNICODE_LITERAL_8(E,x,p,o,n,e,n,t); +const XMLCh RSAKeyValue::LOCAL_NAME[] = UNICODE_LITERAL_11(R,S,A,K,e,y,V,a,l,u,e); +const XMLCh RSAKeyValue::TYPE_NAME[] = UNICODE_LITERAL_15(R,S,A,K,e,y,V,a,l,u,e,T,y,p,e); diff --git a/xmltooling/signature/impl/KeyInfoImpl.h b/xmltooling/signature/impl/KeyInfoImpl.h deleted file mode 100644 index cb18679..0000000 --- a/xmltooling/signature/impl/KeyInfoImpl.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -* Copyright 2001-2006 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. - */ - -/** - * KeyInfoImpl.h - * - * Builder class for KeyInfo - */ - -#ifndef __xmltooling_keyinfoimpl_h__ -#define __xmltooling_keyinfoimpl_h__ - -#include -#include -#include - -#define BEGIN_XMLSIGOBJECTBUILDERIMPL(cname) \ - BEGIN_XMLOBJECTBUILDERIMPL(cname,XMLConstants::XMLSIG_NS,XMLConstants::XMLSIG_PREFIX) - -namespace xmltooling { - - BEGIN_XMLSIGOBJECTBUILDERIMPL(KeyInfo); - END_XMLOBJECTBUILDERIMPL; - - BEGIN_XMLSIGOBJECTBUILDERIMPL(KeyName); - END_XMLOBJECTBUILDERIMPL; - - BEGIN_XMLSIGOBJECTBUILDERIMPL(MgmtData); - END_XMLOBJECTBUILDERIMPL; - - BEGIN_XMLOBJECTVALIDATOR(KeyInfoSchema); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(KeyNameSchema); - END_XMLOBJECTVALIDATOR; - - BEGIN_XMLOBJECTVALIDATOR(MgmtDataSchema); - END_XMLOBJECTVALIDATOR; -}; - -#endif /* __xmltooling_keyinfoimpl_h__ */ diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index d320a3d..b561814 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -23,7 +23,7 @@ #include "internal.h" #include "exceptions.h" #include "impl/UnknownElement.h" -#include "signature/impl/XMLSecSignatureImpl.h" +#include "signature/Signature.h" #include "util/NDC.h" #include "util/XMLConstants.h" #include "util/XMLHelper.h" @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -236,7 +237,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, MarshallingCont bindDocument=true; } m_signature=XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->newSignature(); - m_signature->setDSIGNSPrefix(Signature::PREFIX); + m_signature->setDSIGNSPrefix(XMLConstants::XMLSIG_PREFIX); cachedDOM=m_signature->createBlankSignature(document, getCanonicalizationMethod(), getSignatureAlgorithm()); } else { @@ -339,7 +340,7 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, Marshalling // Fresh signature, so we just create an empty one. log.debug("creating empty Signature element"); m_signature=XMLToolingInternalConfig::getInternalConfig().m_xsecProvider->newSignature(); - m_signature->setDSIGNSPrefix(Signature::PREFIX); + m_signature->setDSIGNSPrefix(XMLConstants::XMLSIG_PREFIX); cachedDOM=m_signature->createBlankSignature( parentElement->getOwnerDocument(), getCanonicalizationMethod(), getSignatureAlgorithm() ); @@ -401,7 +402,7 @@ XMLObject* XMLSecSignatureImpl::unmarshall(DOMElement* element, bool bindDocumen return this; } -Signature* XMLSecSignatureBuilder::buildObject( +Signature* SignatureBuilder::buildObject( const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType ) const { @@ -410,7 +411,9 @@ Signature* XMLSecSignatureBuilder::buildObject( return buildObject(); } -Signature* XMLSecSignatureBuilder::buildObject() const +Signature* SignatureBuilder::buildObject() const { return new XMLSecSignatureImpl(); } + +const XMLCh Signature::LOCAL_NAME[] = UNICODE_LITERAL_9(S,i,g,n,a,t,u,r,e); diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.h b/xmltooling/signature/impl/XMLSecSignatureImpl.h deleted file mode 100644 index 41b2470..0000000 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* Copyright 2001-2006 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. - */ - -/** - * XMLSecSignatureImpl.h - * - * Builder class for XMLSec-based signature-handling - */ - -#if !defined(__xmltooling_xmlsecsig_h__) && !defined(XMLTOOLING_NO_XMLSEC) -#define __xmltooling_xmlsecsig_h__ - -#include - -namespace xmltooling { - - class XMLTOOL_DLLLOCAL XMLSecSignatureBuilder : public SignatureBuilder - { - public: - Signature* buildObject( - const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL - ) const; - Signature* buildObject() const; - }; - -}; - -#endif /* __xmltooling_xmlsecsig_h__ */ diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index 14d79d6..768d15f 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -450,18 +450,6 @@ RelativePath=".\signature\SigningContext.h" > - - - - - - (b->buildFromDocument(doc)) ); TS_ASSERT(wcObject.get()!=NULL); - + ListOf(XMLObject) kids=wcObject->getXMLObjects(); TSM_ASSERT_EQUALS("Number of child elements was not expected value", 2, kids.size()); diff --git a/xmltoolingtest/XMLObjectBaseTestCase.h b/xmltoolingtest/XMLObjectBaseTestCase.h index ba1116f..ee5fa88 100644 --- a/xmltoolingtest/XMLObjectBaseTestCase.h +++ b/xmltoolingtest/XMLObjectBaseTestCase.h @@ -110,6 +110,10 @@ public: VectorOf(SimpleXMLObject) getSimpleXMLObjects() { return VectorOf(SimpleXMLObject)(this, m_simples, &m_children, m_children.end()); } + + const std::vector& getSimpleXMLObjects() const { + return m_simples; + } protected: void marshallAttributes(DOMElement* domElement) const { -- 2.1.4