From 9f7aeb339a764a2fbe2097909b78a6fd8c138f2b Mon Sep 17 00:00:00 2001 From: cantor Date: Mon, 3 Dec 2007 16:41:03 +0000 Subject: [PATCH] Second beta. git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/tags/1.0-beta2@444 de75baf8-a10c-0410-a50a-987c0e22f00f --- .cproject | 37 +-- Makefile.am | 4 +- acx_pthread.m4 | 11 +- checkinstall | 9 - config_win32.h | 4 + configure.ac | 39 +-- depend | 6 + pkginfo.in | 16 +- postinstall | 9 + schemas/xmldsig-core-schema.xsd | 4 +- xmltooling.spec.in | 16 +- .../AbstractAttributeExtensibleXMLObject.cpp | 13 +- xmltooling/Makefile.am | 6 + xmltooling/Namespace.cpp | 2 + xmltooling/QName.cpp | 2 + xmltooling/XMLToolingConfig.cpp | 12 +- xmltooling/base.h | 44 +++- xmltooling/config_pub.h.in | 4 + xmltooling/config_pub_win32.h | 4 + xmltooling/encryption/impl/Decrypter.cpp | 12 +- xmltooling/io/AbstractXMLObjectMarshaller.cpp | 15 +- xmltooling/io/HTTPRequest.cpp | 58 +++++ xmltooling/io/HTTPRequest.h | 25 +- xmltooling/io/HTTPResponse.h | 1 + xmltooling/security/BasicX509Credential.h | 3 + xmltooling/security/Credential.h | 17 ++ xmltooling/security/CredentialCriteria.h | 28 +-- .../security/impl/AbstractPKIXTrustEngine.cpp | 6 +- xmltooling/security/impl/CredentialCriteria.cpp | 19 +- .../security/impl/ExplicitKeyTrustEngine.cpp | 14 +- .../security/impl/FilesystemCredentialResolver.cpp | 23 +- xmltooling/security/impl/InlineKeyResolver.cpp | 81 ------ xmltooling/soap/SOAP.h | 14 +- xmltooling/soap/impl/CURLSOAPTransport.cpp | 4 +- xmltooling/soap/impl/SOAPClient.cpp | 9 + xmltooling/soap/impl/SOAPImpl.cpp | 36 +-- xmltooling/util/CurlNetAccessor.cpp | 2 +- xmltooling/util/CurlNetAccessor.hpp | 4 +- xmltooling/util/CurlURLInputStream.cpp | 25 +- xmltooling/util/CurlURLInputStream.hpp | 4 +- xmltooling/util/ParserPool.cpp | 8 +- xmltooling/util/Predicates.h | 115 +++++++++ xmltooling/util/ReloadableXMLFile.cpp | 6 +- xmltooling/util/XMLObjectChildrenList.h | 271 +++++++++++++++++++-- xmltooling/xmltooling-lite.vcproj | 8 + xmltooling/xmltooling.vcproj | 8 + xmltoolingtest/EncryptionTest.h | 2 +- xmltoolingtest/SignatureTest.h | 2 +- xmltoolingtest/data/SimpleXMLObjectWithContent.xml | Bin 290 -> 288 bytes 49 files changed, 776 insertions(+), 286 deletions(-) delete mode 100644 checkinstall create mode 100644 depend create mode 100644 postinstall create mode 100644 xmltooling/io/HTTPRequest.cpp create mode 100644 xmltooling/util/Predicates.h diff --git a/.cproject b/.cproject index 38380e1..ad22b26 100644 --- a/.cproject +++ b/.cproject @@ -47,7 +47,26 @@ + + + + + + + + + + + + + + + + + + + @@ -66,23 +85,9 @@ - - - - - - - - - - - - - - - - + + diff --git a/Makefile.am b/Makefile.am index 25be000..05bea16 100644 --- a/Makefile.am +++ b/Makefile.am @@ -8,6 +8,7 @@ MOSTLYCLEANFILES = $(DX_CLEANFILES) dist-hook: rm -rf `find $(distdir)/xmltoolingtest/data -name .svn` + rm -rf `find $(distdir)/doc/api -name .svn` SUBDIRS = doc schemas xmltooling xmltoolingtest @@ -48,6 +49,7 @@ EXTRA_DIST = $(DX_CONFIG) \ xmltooling.spec \ pkginfo.in \ pkginfo \ - checkinstall + depend \ + postinstall DISTCLEANFILES = xmltooling.spec pkginfo diff --git a/acx_pthread.m4 b/acx_pthread.m4 index 7ac8ffd..33f1d29 100644 --- a/acx_pthread.m4 +++ b/acx_pthread.m4 @@ -243,8 +243,15 @@ if test "x$acx_pthread_ok" = xyes; then AC_MSG_CHECKING([if more special flags are required for pthreads]) flag=no case "${host_cpu}-${host_os}" in - *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; - *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; + *-aix* | *-freebsd*) flag="-D_THREAD_SAFE";; + *-osf* | *-hpux*) flag="-D_REENTRANT";; + *solaris*) + if test "$GCC" = "yes"; then + flag="-D_REENTRANT" + else + flag="-mt -D_REENTRANT" + fi + ;; esac AC_MSG_RESULT(${flag}) if test "x$flag" != xno; then diff --git a/checkinstall b/checkinstall deleted file mode 100644 index 6adfb56..0000000 --- a/checkinstall +++ /dev/null @@ -1,9 +0,0 @@ -#!/bin/sh - -expected_platform="sparc" -platform=`uname -p` -if [ ${platform} != ${expected_platform} ]; then - echo "This package must be installed on ${expected_platform}" - exit 1 -fi -exit 0 diff --git a/config_win32.h b/config_win32.h index 63a1a56..2f9815a 100644 --- a/config_win32.h +++ b/config_win32.h @@ -13,6 +13,10 @@ specialization. */ #define HAVE_GOOD_STL 1 +/* Define to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#define HAVE_ITERATOR_TRAITS 1 + /* Define to 1 if you have the header file. */ /* #undef HAVE_INTTYPES_H */ diff --git a/configure.ac b/configure.ac index ae4acd6..d14baf6 100644 --- a/configure.ac +++ b/configure.ac @@ -106,10 +106,11 @@ AC_ARG_WITH(log4shib, if test -f "${LOG4SHIB_CONFIG}"; then LDFLAGS="`${LOG4SHIB_CONFIG} --libs` $LDFLAGS" CPPFLAGS="`${LOG4SHIB_CONFIG} --cflags` $CPPFLAGS" - AC_CHECK_HEADER([log4shib/Category.hh],,AC_MSG_ERROR([unable to find log4shib header files])) + AC_CHECK_HEADER([log4shib/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4shib header files])) AC_TRY_LINK( - [#include ], - [log4shib::Category::getInstance("foo")], + [#include +#include ], + [log4shib::Category::getInstance("foo").errorStream() << log4shib::eol], [AC_DEFINE(XMLTOOLING_LOG4SHIB,1,[Define if log4shib library is used.])], [AC_MSG_ERROR([unable to link with log4shib])]) else @@ -130,13 +131,13 @@ else AC_MSG_WARN([will try to use log4cpp, note that most non-Internet2 supplied versions are not thread-safe]) LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS" CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS" - AC_CHECK_HEADER([log4cpp/Category.hh],,AC_MSG_ERROR([unable to find log4cpp header files])) - AC_CHECK_HEADER([log4cpp/PropertyConfigurator.hh],,AC_MSG_ERROR([you need at least log4cpp 0.3.x])) + AC_CHECK_HEADER([log4cpp/CategoryStream.hh],,AC_MSG_ERROR([unable to find log4cpp header files])) AC_TRY_LINK( - [#include ], - [log4cpp::Category::getInstance("foo")], + [#include +#include ], + [log4cpp::Category::getInstance("foo").errorStream() << log4cpp::eol], [AC_DEFINE(XMLTOOLING_LOG4CPP,1,[Define if log4cpp library is used.])], - [AC_MSG_ERROR([unable to link with log4cpp])]) + [AC_MSG_ERROR([unable to link with log4cpp, need version 1.0 or later])]) else AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option]) fi @@ -188,23 +189,21 @@ if test x_$with_xmlsec != x_no; then AC_MSG_CHECKING([XML-Security version]) AC_PREPROC_IFELSE( [AC_LANG_PROGRAM([#include ], - [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3) || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM == 3 && XSEC_VERSION_MINOR > 0) + [#if XSEC_VERSION_MAJOR > 1 || (XSEC_VERSION_MAJOR == 1 && XSEC_VERSION_MEDIUM > 3) int i = 0; #else -#error need version 1.3.1 or later +#error need version 1.4.0 or later #endif])], [AC_MSG_RESULT(OK)], - [AC_MSG_FAILURE([XML-Security version 1.3.1 or greater is required.])]) + [AC_MSG_FAILURE([XML-Security version 1.4.0 or greater is required.])]) AC_TRY_LINK( [#include ], [XSECPlatformUtils::Initialise()],, - [AC_MSG_ERROR([unable to link with XML-Sec])]) + [AC_MSG_ERROR([unable to link with XML-Security])]) # restore master libs LIBS="$save_LIBS" - AC_LANG(C) - # libcurl settings AC_PATH_PROG(CURL_CONFIG,curl-config) AC_ARG_WITH(curl, @@ -240,8 +239,10 @@ int i = 0; AC_ARG_WITH(openssl, AC_HELP_STRING([--with-openssl=PATH], [where openssl is installed]), [if test x_$with_openssl != x_/usr; then - SSLFLAGS="-I${with_openssl}/include" + SSLFLAGS="-I${with_openssl}/include" SSLLIBS="-L${with_openssl}/lib -lcrypto -lssl" + else + SSLLIBS="-lcrypto -lssl" fi]) if test "x$SSLLIBS" = "x" ; then @@ -282,8 +283,6 @@ int i = 0; LIBS="$save_LIBS" AC_SUBST(XMLSEC_LIBS) - - AC_LANG(C++) else AC_MSG_WARN([xmlsec disabled, building without signature/encryption support]) AC_DEFINE(XMLTOOLING_NO_XMLSEC,1, @@ -298,6 +297,12 @@ AC_TRY_LINK( [AC_DEFINE(HAVE_GOOD_STL,1, [Define if you have an STL implementation that supports useful string specialization.])], ) +AC_TRY_LINK( + [#include ], + [std::iterator_traits::iterator>::value_type foo=0], + [AC_DEFINE(HAVE_ITERATOR_TRAITS,1, + [Define to 1 if you have an STL implementation that supports std::iterator_traits.])], + ) # Check for unit test support CXXTEST="/usr/bin/cxxtestgen.pl" diff --git a/depend b/depend new file mode 100644 index 0000000..b663e92 --- /dev/null +++ b/depend @@ -0,0 +1,6 @@ +P SHIBossl OpenSSL + 0.9.8g +P SHIBxerces xerces-c + 2.8.0 +P SHIBxmlsec xml-security-c + 1.4.0 diff --git a/pkginfo.in b/pkginfo.in index 653cc91..34a0393 100644 --- a/pkginfo.in +++ b/pkginfo.in @@ -1,10 +1,12 @@ -ARCH=sparc PKG=SHIBxmltool -NAME=XML Tooling Library for C++ +ARCH=sparc VERSION=@-VERSION-@ -CATEGORY=system -VENDOR=http://www.opensaml.org/ packaged for Shibboleth by Scott Cantor -HOTLINE=http://bugzilla.internet2.edu/ -EMAIL=cantor.2@osu.edu -PSTAMP=1May2006 +BASEDIR=/usr/local +NAME=xmltooling-c +CATEGORY=application,textproc,security +DESC=Library for DOM processing with Signature/Encryption for C++ +VENDOR=Internet2 +HOTLINE=https://bugs.internet2.edu/ CLASSES=none +PSTAMP=sunra.internet2.edu 2007-11-15 +EMAIL=cantor.2@osu.edu diff --git a/postinstall b/postinstall new file mode 100644 index 0000000..321de70 --- /dev/null +++ b/postinstall @@ -0,0 +1,9 @@ +#!/bin/sh + +cd ${CLIENT_BASEDIR}/share/xml/xmltooling + +sed "s|uri=\".*${CLIENT_BASEDIR}|uri=\"${CLIENT_BASEDIR}|1" catalog.xml > catalog.xml.tmp +mv catalog.xml.tmp catalog.xml +chmod 644 catalog.xml + +exit 0 diff --git a/schemas/xmldsig-core-schema.xsd b/schemas/xmldsig-core-schema.xsd index 50c834f..3cb1daa 100644 --- a/schemas/xmldsig-core-schema.xsd +++ b/schemas/xmldsig-core-schema.xsd @@ -66,7 +66,7 @@ - + @@ -76,7 +76,7 @@ - + diff --git a/xmltooling.spec.in b/xmltooling.spec.in index 481b7e2..e6c3313 100644 --- a/xmltooling.spec.in +++ b/xmltooling.spec.in @@ -1,17 +1,17 @@ Name: xmltooling Summary: Open source XMLTooling library Version: @-VERSION-@ -Release: 3 +Release: 4 Group: System Environment/Libraries Vendor: Internet2 License: Apache 2.0 URL: http://www.opensaml.org/ Source0: %{name}-%{version}.tar.gz BuildRoot: %{_tmppath}/%{name}-%{version}-root -BuildRequires: xerces%{?xercesver}-c-devel >= 2.6.1 +BuildRequires: xerces%{?xercesver}-c-devel >= 2.8.0 BuildRequires: xml-security-c-devel >= 1.4.0 -BuildRequires: openssl-devel, cxxtest -%{?_with_log4cpp:BuildRequires: log4cpp-devel >= 0.3.5} +BuildRequires: openssl-devel, curl-devel >= 7.10.6 +%{?_with_log4cpp:BuildRequires: log4cpp-devel >= 1.0} %{!?_with_log4cpp:BuildRequires: log4shib-devel} %description @@ -56,6 +56,8 @@ XMLTooling Library API documentation generated by doxygen. %install [ "$RPM_BUILD_ROOT" != "/" ] && %{__rm} -rf $RPM_BUILD_ROOT %{__make} install DESTDIR=$RPM_BUILD_ROOT +find $RPM_BUILD_ROOT/%{_bindir} -type f | + %{__sed} -e "s|$RPM_BUILD_ROOT||" | sort > rpm.binlist %check || : %{__make} check @@ -71,13 +73,12 @@ XMLTooling Library API documentation generated by doxygen. %postun -p /sbin/ldconfig %endif -%files +%files -f rpm.binlist %defattr(-,root,root,-) %{_libdir}/libxmltooling.so.* %{_libdir}/libxmltooling-lite.so.* %dir %{_datadir}/xml/xmltooling %{_datadir}/xml/xmltooling -%exclude %{_bindir}/xmltoolingtest %docdir %{_datadir}/doc/xmltooling %{_datadir}/doc/xmltooling/LICENSE.txt %{_datadir}/doc/xmltooling/NOTICE.txt @@ -96,6 +97,9 @@ XMLTooling Library API documentation generated by doxygen. %doc %{_datadir}/doc/xmltooling/api %changelog +* Thu Nov 08 2007 Scott Cantor - 1.0-4 +- Second public beta. + * Thu Aug 16 2007 Scott Cantor - 1.0-3 - First public beta. diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp index 74c4a34..2efde22 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -55,25 +55,22 @@ void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedNa if (i!=m_attributeMap.end()) { releaseThisandParentDOM(); XMLString::release(&(i->second)); - if (value) { + if (value && *value) { i->second=XMLString::replicate(value); + if (ID) + m_idAttribute=i; } else { if (m_idAttribute==i) m_idAttribute=m_attributeMap.end(); m_attributeMap.erase(i); } - - if (ID) { - m_idAttribute=i; - } } - else if (value) { + else if (value && *value) { releaseThisandParentDOM(); m_attributeMap[qualifiedName]=XMLString::replicate(value); - if (ID) { + if (ID) m_idAttribute = m_attributeMap.find(qualifiedName); - } } } diff --git a/xmltooling/Makefile.am b/xmltooling/Makefile.am index 511bc26..efb133f 100644 --- a/xmltooling/Makefile.am +++ b/xmltooling/Makefile.am @@ -98,9 +98,12 @@ soapinclude_HEADERS = \ soap/OpenSSLSOAPTransport.h utilinclude_HEADERS = \ + util/CurlNetAccessor.hpp \ + util/CurlURLInputStream.hpp \ util/DateTime.h \ util/NDC.h \ util/ParserPool.h \ + util/Predicates.h \ util/ReloadableXMLFile.h \ util/ReplayCache.h \ util/StorageService.h \ @@ -140,6 +143,8 @@ xmlsec_sources = \ signature/impl/SignatureValidator.cpp \ signature/impl/XMLSecSignatureImpl.cpp \ soap/impl/CURLSOAPTransport.cpp \ + util/CurlNetAccessor.cpp \ + util/CurlURLInputStream.cpp \ util/ReplayCache.cpp \ util/StorageService.cpp @@ -167,6 +172,7 @@ common_sources = \ impl/UnknownElement.cpp \ io/AbstractXMLObjectMarshaller.cpp \ io/AbstractXMLObjectUnmarshaller.cpp \ + io/HTTPRequest.cpp \ signature/impl/KeyInfoImpl.cpp \ signature/impl/KeyInfoSchemaValidators.cpp \ soap/impl/SOAPClient.cpp \ diff --git a/xmltooling/Namespace.cpp b/xmltooling/Namespace.cpp index ca3f896..ec272c0 100644 --- a/xmltooling/Namespace.cpp +++ b/xmltooling/Namespace.cpp @@ -88,6 +88,8 @@ Namespace& Namespace::operator=(const Namespace& src) bool xmltooling::operator==(const Namespace& op1, const Namespace& op2) { + if (&op1 == &op2) + return true; return (XMLString::equals(op1.getNamespaceURI(),op2.getNamespaceURI()) && XMLString::equals(op1.getNamespacePrefix(),op2.getNamespacePrefix())); } diff --git a/xmltooling/QName.cpp b/xmltooling/QName.cpp index 29f2714..b161da6 100644 --- a/xmltooling/QName.cpp +++ b/xmltooling/QName.cpp @@ -164,6 +164,8 @@ QName& QName::operator=(const QName& src) bool xmltooling::operator==(const QName& op1, const QName& op2) { + if (&op1 == &op2) + return true; return (!XMLString::compareString(op1.getNamespaceURI(),op2.getNamespaceURI()) && !XMLString::compareString(op1.getLocalPart(),op2.getLocalPart())); } diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index 476f8f1..2c06eac 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -215,12 +215,12 @@ bool XMLToolingInternalConfig::init() #endif XMLPlatformUtils::Initialize(); - log.debug("Xerces initialization complete"); + log.debug("Xerces %s initialization complete", XERCES_FULLVERSIONDOT); #ifndef XMLTOOLING_NO_XMLSEC XSECPlatformUtils::Initialise(); m_xsecProvider=new XSECProvider(); - log.debug("XMLSec initialization complete"); + log.debug("XML-Security %s initialization complete", XSEC_FULLVERSIONDOT); #endif m_parserPool=new ParserPool(); @@ -298,7 +298,7 @@ bool XMLToolingInternalConfig::init() # endif #endif - log.info("library initialization complete"); + log.info("%s library initialization complete", PACKAGE_STRING); return true; } @@ -375,7 +375,7 @@ void XMLToolingInternalConfig::term() #ifdef _DEBUG xmltooling::NDC ndc("term"); #endif - Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("library shutdown complete"); + Category::getInstance(XMLTOOLING_LOGCAT".XMLToolingConfig").info("%s library shutdown complete", PACKAGE_STRING); } Lockable* XMLToolingInternalConfig::lock() @@ -475,9 +475,9 @@ void xmltooling::log_openssl() unsigned long code=ERR_get_error_line_data(&file,&line,&data,&flags); while (code) { Category& log=Category::getInstance("OpenSSL"); - log.errorStream() << "error code: " << code << " in " << file << ", line " << line << CategoryStream::ENDLINE; + log.errorStream() << "error code: " << code << " in " << file << ", line " << line << logging::eol; if (data && (flags & ERR_TXT_STRING)) - log.errorStream() << "error data: " << data << CategoryStream::ENDLINE; + log.errorStream() << "error data: " << data << logging::eol; code=ERR_get_error_line_data(&file,&line,&data,&flags); } } diff --git a/xmltooling/base.h b/xmltooling/base.h index 237f798..31e9edf 100644 --- a/xmltooling/base.h +++ b/xmltooling/base.h @@ -349,6 +349,42 @@ #define END_XMLOBJECT } /** + * Declares a static variable holding the XMLObject's element QName. + */ +#define DECL_ELEMENT_QNAME \ + public: \ + XMLTOOLING_DOXYGEN(Element QName) \ + static xmltooling::QName ELEMENT_QNAME + +/** + * Declares a static variable holding the XMLObject's schema type QName. + */ +#define DECL_TYPE_QNAME \ + public: \ + XMLTOOLING_DOXYGEN(Type QName) \ + static xmltooling::QName TYPE_QNAME + +/** + * Implements a static variable holding an XMLObject's element QName. + * + * @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 IMPL_ELEMENT_QNAME(cname,namespaceURI,namespacePrefix) \ + xmltooling::QName cname::ELEMENT_QNAME(namespaceURI,cname::LOCAL_NAME,namespacePrefix) + +/** + * Implements a static variable holding an XMLObject's schema type QName. + * + * @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 IMPL_TYPE_QNAME(cname,namespaceURI,namespacePrefix) \ + xmltooling::QName cname::TYPE_QNAME(namespaceURI,cname::TYPE_NAME,namespacePrefix) + +/** * Declares abstract set method for a typed XML attribute. * The get method is omitted. * @@ -841,7 +877,7 @@ * @param namespaceURI the XML namespace of the attribute */ #define MARSHALL_STRING_ATTRIB(proper,ucase,namespaceURI) \ - if (m_##proper) { \ + if (m_##proper && *m_##proper) { \ domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \ } @@ -865,7 +901,7 @@ * @param namespaceURI the XML namespace of the attribute */ #define MARSHALL_INTEGER_ATTRIB(proper,ucase,namespaceURI) \ - if (m_##proper) { \ + if (m_##proper && *m_##proper) { \ domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \ } @@ -915,7 +951,7 @@ * @param namespaceURI the XML namespace of the attribute */ #define MARSHALL_ID_ATTRIB(proper,ucase,namespaceURI) \ - if (m_##proper) { \ + if (m_##proper && *m_##proper) { \ domElement->setAttributeNS(namespaceURI, ucase##_ATTRIB_NAME, m_##proper); \ domElement->setIdAttributeNS(namespaceURI, ucase##_ATTRIB_NAME); \ } @@ -1093,7 +1129,7 @@ #define DECL_INTEGER_CONTENT(proper) \ XMLTOOLING_DOXYGEN(Returns proper in integer form after a NULL indicator.) \ std::pair get##proper() const { \ - return std::make_pair((getTextContent()!=NULL), (getTextContent()!=NULL ? xercesc::XMLString::parseInt(getTextContent()) : NULL)); \ + return std::make_pair((getTextContent()!=NULL), (getTextContent()!=NULL ? xercesc::XMLString::parseInt(getTextContent()) : 0)); \ } \ XMLTOOLING_DOXYGEN(Sets proper.) \ void set##proper(int proper) { \ diff --git a/xmltooling/config_pub.h.in b/xmltooling/config_pub.h.in index 144d787..1ae9290 100644 --- a/xmltooling/config_pub.h.in +++ b/xmltooling/config_pub.h.in @@ -5,6 +5,10 @@ specialization. */ #undef HAVE_GOOD_STL +/* Define to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#undef HAVE_ITERATOR_TRAITS + /* Define if log4shib library is used. */ #undef XMLTOOLING_LOG4SHIB diff --git a/xmltooling/config_pub_win32.h b/xmltooling/config_pub_win32.h index 0c13ee2..bf1053b 100644 --- a/xmltooling/config_pub_win32.h +++ b/xmltooling/config_pub_win32.h @@ -5,6 +5,10 @@ specialization. */ #define HAVE_GOOD_STL 1 +/* Define to 1 if you have an STL implementation that supports + std::iterator_traits. */ +#define HAVE_ITERATOR_TRAITS 1 + /* Define if log4shib library is used. */ #define XMLTOOLING_LOG4SHIB 1 diff --git a/xmltooling/encryption/impl/Decrypter.cpp b/xmltooling/encryption/impl/Decrypter.cpp index 47ed588..c68d1cd 100644 --- a/xmltooling/encryption/impl/Decrypter.cpp +++ b/xmltooling/encryption/impl/Decrypter.cpp @@ -92,7 +92,7 @@ DOMDocumentFragment* Decrypter::decryptData(const EncryptedData& encryptedData, CredentialCriteria::KEYINFO_EXTRACTION_KEYNAMES | CredentialCriteria::KEYINFO_EXTRACTION_IMPLICIT_KEYNAMES; if (m_criteria) { - m_criteria->setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + m_criteria->setUsage(Credential::ENCRYPTION_CREDENTIAL); m_criteria->setKeyInfo(encryptedData.getKeyInfo(), types); const EncryptionMethod* meth = encryptedData.getEncryptionMethod(); if (meth) @@ -101,7 +101,7 @@ DOMDocumentFragment* Decrypter::decryptData(const EncryptedData& encryptedData, } else { CredentialCriteria criteria; - criteria.setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + criteria.setUsage(Credential::ENCRYPTION_CREDENTIAL); criteria.setKeyInfo(encryptedData.getKeyInfo(), types); const EncryptionMethod* meth = encryptedData.getEncryptionMethod(); if (meth) @@ -192,7 +192,7 @@ void Decrypter::decryptData(ostream& out, const EncryptedData& encryptedData, co CredentialCriteria::KEYINFO_EXTRACTION_KEYNAMES | CredentialCriteria::KEYINFO_EXTRACTION_IMPLICIT_KEYNAMES; if (m_criteria) { - m_criteria->setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + m_criteria->setUsage(Credential::ENCRYPTION_CREDENTIAL); m_criteria->setKeyInfo(encryptedData.getKeyInfo(), types); const EncryptionMethod* meth = encryptedData.getEncryptionMethod(); if (meth) @@ -201,7 +201,7 @@ void Decrypter::decryptData(ostream& out, const EncryptedData& encryptedData, co } else { CredentialCriteria criteria; - criteria.setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + criteria.setUsage(Credential::ENCRYPTION_CREDENTIAL); criteria.setKeyInfo(encryptedData.getKeyInfo(), types); const EncryptionMethod* meth = encryptedData.getEncryptionMethod(); if (meth) @@ -276,7 +276,7 @@ XSECCryptoKey* Decrypter::decryptKey(const EncryptedKey& encryptedKey, const XML CredentialCriteria::KEYINFO_EXTRACTION_IMPLICIT_KEYNAMES; vector creds; if (m_criteria) { - m_criteria->setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + m_criteria->setUsage(Credential::ENCRYPTION_CREDENTIAL); m_criteria->setKeyInfo(encryptedKey.getKeyInfo(), types); const EncryptionMethod* meth = encryptedKey.getEncryptionMethod(); if (meth) @@ -285,7 +285,7 @@ XSECCryptoKey* Decrypter::decryptKey(const EncryptedKey& encryptedKey, const XML } else { CredentialCriteria criteria; - criteria.setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + criteria.setUsage(Credential::ENCRYPTION_CREDENTIAL); criteria.setKeyInfo(encryptedKey.getKeyInfo(), types); const EncryptionMethod* meth = encryptedKey.getEncryptionMethod(); if (meth) diff --git a/xmltooling/io/AbstractXMLObjectMarshaller.cpp b/xmltooling/io/AbstractXMLObjectMarshaller.cpp index 500f431..0c87aff 100644 --- a/xmltooling/io/AbstractXMLObjectMarshaller.cpp +++ b/xmltooling/io/AbstractXMLObjectMarshaller.cpp @@ -316,23 +316,22 @@ void AbstractXMLObjectMarshaller::marshallContent( { m_log.debug("marshalling text and child elements for XMLObject"); - const XMLCh* val; unsigned int pos=0; + const XMLCh* val = getTextContent(pos); + if (val && *val) + domElement->appendChild(domElement->getOwnerDocument()->createTextNode(val)); + const list& children=getOrderedChildren(); for (list::const_iterator i=children.begin(); i!=children.end(); ++i) { - val = getTextContent(pos); - if (val && *val) - domElement->appendChild(domElement->getOwnerDocument()->createTextNode(val)); if (*i) { #ifndef XMLTOOLING_NO_XMLSEC (*i)->marshall(domElement,NULL,credential); #else (*i)->marshall(domElement); #endif - ++pos; + val = getTextContent(++pos); + if (val && *val) + domElement->appendChild(domElement->getOwnerDocument()->createTextNode(val)); } } - val = getTextContent(pos); - if (val && *val) - domElement->appendChild(domElement->getOwnerDocument()->createTextNode(val)); } diff --git a/xmltooling/io/HTTPRequest.cpp b/xmltooling/io/HTTPRequest.cpp new file mode 100644 index 0000000..ff73107 --- /dev/null +++ b/xmltooling/io/HTTPRequest.cpp @@ -0,0 +1,58 @@ +/* + * Copyright 2001-2007 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. + */ + +/** + * HTTPRequest.cpp + * + * Interface to HTTP requests + */ + +#include "internal.h" +#include "HTTPRequest.h" + +using namespace xmltooling; +using namespace std; + +const char* HTTPRequest::getCookie(const char* name) const +{ + if (m_cookieMap.empty()) { + string cookies=getHeader("Cookie"); + + string::size_type pos=0,cname,namelen,val,vallen; + while (pos !=string::npos && pos < cookies.length()) { + while (isspace(cookies[pos])) pos++; + cname=pos; + pos=cookies.find_first_of("=",pos); + if (pos == string::npos) + break; + namelen=pos-cname; + pos++; + if (pos==cookies.length()) + break; + val=pos; + pos=cookies.find_first_of(";",pos); + if (pos != string::npos) { + vallen=pos-val; + pos++; + m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val,vallen))); + } + else + m_cookieMap.insert(make_pair(cookies.substr(cname,namelen),cookies.substr(val))); + } + } + map::const_iterator lookup=m_cookieMap.find(name); + return (lookup==m_cookieMap.end()) ? NULL : lookup->second.c_str(); +} diff --git a/xmltooling/io/HTTPRequest.h b/xmltooling/io/HTTPRequest.h index caee6d5..2a5abf7 100644 --- a/xmltooling/io/HTTPRequest.h +++ b/xmltooling/io/HTTPRequest.h @@ -25,8 +25,15 @@ #include +#include + namespace xmltooling { - + +#if defined (_MSC_VER) + #pragma warning( push ) + #pragma warning( disable : 4251 ) +#endif + /** * Interface to HTTP requests. * @@ -83,7 +90,23 @@ namespace xmltooling { * @return the header's value, or an empty string */ virtual std::string getHeader(const char* name) const=0; + + /** + * Get a cookie value supplied by the client. + * + * @param name name of cookie + * @return cookie value or NULL + */ + virtual const char* getCookie(const char* name) const; + + private: + mutable std::map m_cookieMap; }; + +#if defined (_MSC_VER) + #pragma warning( pop ) +#endif + }; #endif /* __xmltooling_httpreq_h__ */ diff --git a/xmltooling/io/HTTPResponse.h b/xmltooling/io/HTTPResponse.h index 63e1f4b..77aec51 100644 --- a/xmltooling/io/HTTPResponse.h +++ b/xmltooling/io/HTTPResponse.h @@ -79,6 +79,7 @@ namespace xmltooling { enum status_t { XMLTOOLING_HTTP_STATUS_OK = 200, XMLTOOLING_HTTP_STATUS_MOVED = 302, + XMLTOOLING_HTTP_STATUS_UNAUTHORIZED = 401, XMLTOOLING_HTTP_STATUS_FORBIDDEN = 403, XMLTOOLING_HTTP_STATUS_NOTFOUND = 404, XMLTOOLING_HTTP_STATUS_ERROR = 500 diff --git a/xmltooling/security/BasicX509Credential.h b/xmltooling/security/BasicX509Credential.h index 6b4b486..b398133 100644 --- a/xmltooling/security/BasicX509Credential.h +++ b/xmltooling/security/BasicX509Credential.h @@ -84,6 +84,9 @@ namespace xmltooling { public: virtual ~BasicX509Credential(); + unsigned int getUsage() const { + return UNSPECIFIED_CREDENTIAL; + } const char* getAlgorithm() const; unsigned int getKeySize() const; diff --git a/xmltooling/security/Credential.h b/xmltooling/security/Credential.h index 8fa7bb4..02d4999 100644 --- a/xmltooling/security/Credential.h +++ b/xmltooling/security/Credential.h @@ -62,6 +62,23 @@ namespace xmltooling { }; /** + * Bitmask of use cases for credentials. + */ + enum UsageTypes { + UNSPECIFIED_CREDENTIAL = 0, + SIGNING_CREDENTIAL = 1, + TLS_CREDENTIAL = 2, + ENCRYPTION_CREDENTIAL = 4 + }; + + /** + * Get credential usage types. + * + * @return the usage bitmask + */ + virtual unsigned int getUsage() const=0; + + /** * Returns an algorithm identifier for the Credential. * * @return the Credential algorithm, or NULL if indeterminate diff --git a/xmltooling/security/CredentialCriteria.h b/xmltooling/security/CredentialCriteria.h index d331c89..8e40b9f 100644 --- a/xmltooling/security/CredentialCriteria.h +++ b/xmltooling/security/CredentialCriteria.h @@ -42,7 +42,7 @@ namespace xmltooling { { MAKE_NONCOPYABLE(CredentialCriteria); public: - CredentialCriteria() : m_keyUsage(UNSPECIFIED_CREDENTIAL), m_keySize(0), m_key(NULL), + CredentialCriteria() : m_keyUsage(Credential::UNSPECIFIED_CREDENTIAL), m_keySize(0), m_key(NULL), m_keyInfo(NULL), m_nativeKeyInfo(NULL), m_credential(NULL) { } virtual ~CredentialCriteria() { @@ -56,32 +56,22 @@ namespace xmltooling { * @return true iff the Credential is consistent with this criteria */ virtual bool matches(const Credential& credential) const; - - /** - * Enumeration of use cases for credentials. - */ - enum UsageType { - UNSPECIFIED_CREDENTIAL, - SIGNING_CREDENTIAL, - TLS_CREDENTIAL, - ENCRYPTION_CREDENTIAL - }; - + /** - * Get the key usage criteria. + * Get key usage criteria. * - * @return the usage. + * @return the usage mask */ - UsageType getUsage() const { + unsigned int getUsage() const { return m_keyUsage; } /** - * Set the key usage criteria. + * Set key usage criteria. * - * @param usage the usage to set + * @param usage the usage mask to set */ - void setUsage(UsageType usage) { + void setUsage(unsigned int usage) { m_keyUsage = usage; } @@ -301,7 +291,7 @@ namespace xmltooling { } private: - UsageType m_keyUsage; + unsigned int m_keyUsage; unsigned int m_keySize; std::string m_peerName,m_keyAlgorithm; std::set m_keyNames; diff --git a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp index b98ce39..69e24f3 100644 --- a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp +++ b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp @@ -169,7 +169,7 @@ bool AbstractPKIXTrustEngine::checkEntityNames( buf[len] = '\0'; subjectstr+=buf; } - log.debugStream() << "certificate subject: " << subjectstr << CategoryStream::ENDLINE; + log.debugStream() << "certificate subject: " << subjectstr << logging::eol; // The flags give us LDAP order instead of X.500, with a comma plus space separator. len=X509_NAME_print_ex(b2,subject,0,XN_FLAG_RFC2253 + XN_FLAG_SEP_CPLUS_SPC - XN_FLAG_SEP_COMMA_PLUS); BIO_flush(b2); @@ -262,8 +262,8 @@ bool AbstractPKIXTrustEngine::validate( if (criteria && criteria->getPeerName() && *(criteria->getPeerName())) { log.debug("checking that the certificate name is acceptable"); - if (criteria->getUsage()==CredentialCriteria::UNSPECIFIED_CREDENTIAL) - criteria->setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + if (criteria->getUsage()==Credential::UNSPECIFIED_CREDENTIAL) + criteria->setUsage(Credential::SIGNING_CREDENTIAL); if (!checkEntityNames(certEE,credResolver,*criteria)) { log.error("certificate name was not acceptable"); return false; diff --git a/xmltooling/security/impl/CredentialCriteria.cpp b/xmltooling/security/impl/CredentialCriteria.cpp index e229a06..9d3cabd 100644 --- a/xmltooling/security/impl/CredentialCriteria.cpp +++ b/xmltooling/security/impl/CredentialCriteria.cpp @@ -36,6 +36,13 @@ using namespace std; bool CredentialCriteria::matches(const Credential& credential) const { + // Usage check, if specified and we have one, compare masks. + if (getUsage() != Credential::UNSPECIFIED_CREDENTIAL) { + if (credential.getUsage() != Credential::UNSPECIFIED_CREDENTIAL) + if ((getUsage() & credential.getUsage()) == 0) + return false; + } + // Algorithm check, if specified and we have one. const char* alg = getKeyAlgorithm(); if (alg && *alg) { @@ -65,11 +72,11 @@ bool CredentialCriteria::matches(const Credential& credential) const } // See if we have to match a specific key. - XSECCryptoKey* key1 = getPublicKey(); + const XSECCryptoKey* key1 = getPublicKey(); if (!key1) return true; // no key to compare against, so we're done - XSECCryptoKey* key2 = credential.getPublicKey(); + const XSECCryptoKey* key2 = credential.getPublicKey(); if (!key2) return true; // no key here, so we can't test it @@ -82,16 +89,16 @@ bool CredentialCriteria::matches(const Credential& credential) const if (key1->getKeyType()==XSECCryptoKey::KEY_RSA_PUBLIC || key1->getKeyType()==XSECCryptoKey::KEY_RSA_PAIR) { if (key2->getKeyType()!=XSECCryptoKey::KEY_RSA_PUBLIC && key2->getKeyType()!=XSECCryptoKey::KEY_RSA_PAIR) return false; - RSA* rsa1 = static_cast(key1)->getOpenSSLRSA(); - RSA* rsa2 = static_cast(key2)->getOpenSSLRSA(); + const RSA* rsa1 = static_cast(key1)->getOpenSSLRSA(); + const RSA* rsa2 = static_cast(key2)->getOpenSSLRSA(); return (BN_cmp(rsa1->n,rsa2->n) == 0 && BN_cmp(rsa1->e,rsa2->e) == 0); } if (key1->getKeyType()==XSECCryptoKey::KEY_DSA_PUBLIC || key1->getKeyType()==XSECCryptoKey::KEY_DSA_PAIR) { if (key2->getKeyType()!=XSECCryptoKey::KEY_DSA_PUBLIC && key2->getKeyType()!=XSECCryptoKey::KEY_DSA_PAIR) return false; - DSA* dsa1 = static_cast(key1)->getOpenSSLDSA(); - DSA* dsa2 = static_cast(key2)->getOpenSSLDSA(); + const DSA* dsa1 = static_cast(key1)->getOpenSSLDSA(); + const DSA* dsa2 = static_cast(key2)->getOpenSSLDSA(); return (BN_cmp(dsa1->pub_key,dsa2->pub_key) == 0); } diff --git a/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp b/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp index bed55d5..346c35f 100644 --- a/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp +++ b/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp @@ -94,13 +94,13 @@ bool ExplicitKeyTrustEngine::validate( vector credentials; if (criteria) { - criteria->setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + criteria->setUsage(Credential::SIGNING_CREDENTIAL); criteria->setSignature(sig, CredentialCriteria::KEYINFO_EXTRACTION_KEY); credResolver.resolve(credentials,criteria); } else { CredentialCriteria cc; - cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + cc.setUsage(Credential::SIGNING_CREDENTIAL); cc.setSignature(sig, CredentialCriteria::KEYINFO_EXTRACTION_KEY); credResolver.resolve(credentials,&cc); } @@ -144,14 +144,14 @@ bool ExplicitKeyTrustEngine::validate( vector credentials; if (criteria) { - criteria->setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + criteria->setUsage(Credential::SIGNING_CREDENTIAL); criteria->setKeyInfo(keyInfo, CredentialCriteria::KEYINFO_EXTRACTION_KEY); criteria->setXMLAlgorithm(sigAlgorithm); credResolver.resolve(credentials,criteria); } else { CredentialCriteria cc; - cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + cc.setUsage(Credential::SIGNING_CREDENTIAL); cc.setKeyInfo(keyInfo, CredentialCriteria::KEYINFO_EXTRACTION_KEY); cc.setXMLAlgorithm(sigAlgorithm); credResolver.resolve(credentials,&cc); @@ -223,13 +223,13 @@ bool ExplicitKeyTrustEngine::validate( vector credentials; if (criteria) { - if (criteria->getUsage()==CredentialCriteria::UNSPECIFIED_CREDENTIAL) - criteria->setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + if (criteria->getUsage()==Credential::UNSPECIFIED_CREDENTIAL) + criteria->setUsage(Credential::SIGNING_CREDENTIAL); credResolver.resolve(credentials,criteria); } else { CredentialCriteria cc; - cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + cc.setUsage(Credential::SIGNING_CREDENTIAL); credResolver.resolve(credentials,&cc); } if (credentials.empty()) { diff --git a/xmltooling/security/impl/FilesystemCredentialResolver.cpp b/xmltooling/security/impl/FilesystemCredentialResolver.cpp index 7bf0d0e..6fd9a48 100644 --- a/xmltooling/security/impl/FilesystemCredentialResolver.cpp +++ b/xmltooling/security/impl/FilesystemCredentialResolver.cpp @@ -69,7 +69,7 @@ namespace xmltooling { { public: FilesystemCredential(FilesystemCredentialResolver* resolver, XSECCryptoKey* key, const std::vector& xseccerts) - : BasicX509Credential(key, xseccerts), m_resolver(resolver) { + : BasicX509Credential(key, xseccerts), m_resolver(resolver), m_usage(UNSPECIFIED_CREDENTIAL) { if (!m_xseccerts.empty()) extractNames(m_xseccerts.front(), m_keyNames); initKeyInfo(); @@ -77,12 +77,29 @@ namespace xmltooling { virtual ~FilesystemCredential() { } + unsigned int getUsage() const { + return m_usage; + } + + void setUsage(const XMLCh* usage) { + if (usage && *usage) { + auto_ptr_char u(usage); + if (!strcmp(u.get(), "signing")) + m_usage = SIGNING_CREDENTIAL | TLS_CREDENTIAL; + else if (!strcmp(u.get(), "TLS")) + m_usage = TLS_CREDENTIAL; + else if (!strcmp(u.get(), "encryption")) + m_usage = ENCRYPTION_CREDENTIAL; + } + } + void addKeyNames(const DOMElement* e); void attach(SSL_CTX* ctx) const; private: FilesystemCredentialResolver* m_resolver; + unsigned int m_usage; }; #if defined (_MSC_VER) @@ -147,6 +164,7 @@ namespace xmltooling { static const XMLCh Name[] = UNICODE_LITERAL_4(N,a,m,e); static const XMLCh password[] = UNICODE_LITERAL_8(p,a,s,s,w,o,r,d); static const XMLCh Path[] = UNICODE_LITERAL_4(P,a,t,h); + static const XMLCh _use[] = UNICODE_LITERAL_3(u,s,e); }; FilesystemCredentialResolver::FilesystemCredentialResolver(const DOMElement* e) : m_credential(NULL) @@ -181,6 +199,7 @@ FilesystemCredentialResolver::FilesystemCredentialResolver(const DOMElement* e) } const DOMElement* root=e; + const XMLCh* usage = root->getAttributeNS(NULL,_use); XSECCryptoKey* key=NULL; vector xseccerts; @@ -261,6 +280,7 @@ FilesystemCredentialResolver::FilesystemCredentialResolver(const DOMElement* e) if (!e) { m_credential = new FilesystemCredential(this,key,xseccerts); m_credential->addKeyNames(keynode); + m_credential->setUsage(usage); return; } auto_ptr_char certpass(e->getAttributeNS(NULL,password)); @@ -425,6 +445,7 @@ FilesystemCredentialResolver::FilesystemCredentialResolver(const DOMElement* e) key = xseccerts.front()->clonePublicKey(); m_credential = new FilesystemCredential(this, key, xseccerts); m_credential->addKeyNames(keynode); + m_credential->setUsage(usage); } XSECCryptoKey* FilesystemCredentialResolver::loadKey() diff --git a/xmltooling/security/impl/InlineKeyResolver.cpp b/xmltooling/security/impl/InlineKeyResolver.cpp index 126a6ea..f0da979 100644 --- a/xmltooling/security/impl/InlineKeyResolver.cpp +++ b/xmltooling/security/impl/InlineKeyResolver.cpp @@ -239,32 +239,6 @@ bool InlineCredential::resolveKey(const KeyInfo* keyInfo) } } - // Check for RetrievalMethod. - const XMLCh* fragID=NULL; - const XMLObject* treeRoot=NULL; - const vector& methods=keyInfo->getRetrievalMethods(); - for (vector::const_iterator m=methods.begin(); m!=methods.end(); ++m) { - if (!XMLString::equals((*m)->getType(),RetrievalMethod::TYPE_RSAKEYVALUE) && - !XMLString::equals((*m)->getType(),RetrievalMethod::TYPE_DSAKEYVALUE)) - continue; - fragID = (*m)->getURI(); - if (!fragID || *fragID != chPound || !*(fragID+1)) { - log.warn("skipping ds:RetrievalMethod with an empty or non-local reference"); - continue; - } - if (!treeRoot) { - treeRoot = keyInfo; - while (treeRoot->getParent()) - treeRoot = treeRoot->getParent(); - } - keyInfo = dynamic_cast(XMLHelper::getXMLObjectById(*treeRoot, fragID+1)); - if (!keyInfo) { - log.warn("skipping ds:RetrievalMethod, local reference did not resolve to a ds:KeyInfo"); - continue; - } - if (resolveKey(keyInfo)) - return true; - } return false; } @@ -298,35 +272,6 @@ bool InlineCredential::resolveCerts(const KeyInfo* keyInfo) } } } - - if (m_xseccerts.empty()) { - // Check for RetrievalMethod. - const XMLCh* fragID=NULL; - const XMLObject* treeRoot=NULL; - const vector methods=keyInfo->getRetrievalMethods(); - for (vector::const_iterator m=methods.begin(); m!=methods.end(); ++m) { - if (!XMLString::equals((*m)->getType(),RetrievalMethod::TYPE_X509DATA)) - continue; - fragID = (*m)->getURI(); - if (!fragID || *fragID != chPound || !*(fragID+1)) { - log.warn("skipping ds:RetrievalMethod with an empty or non-local reference"); - continue; - } - if (!treeRoot) { - treeRoot = keyInfo; - while (treeRoot->getParent()) - treeRoot = treeRoot->getParent(); - } - keyInfo = dynamic_cast(XMLHelper::getXMLObjectById(*treeRoot, fragID+1)); - if (!keyInfo) { - log.warn("skipping ds:RetrievalMethod, local reference did not resolve to a ds:KeyInfo"); - continue; - } - if (resolveCerts(keyInfo)) - return true; - } - return false; - } log.debug("resolved %d certificate(s)", m_xseccerts.size()); return !m_xseccerts.empty(); @@ -364,32 +309,6 @@ bool InlineCredential::resolveCRL(const KeyInfo* keyInfo) } } - // Check for RetrievalMethod. - const XMLCh* fragID=NULL; - const XMLObject* treeRoot=NULL; - const vector methods=keyInfo->getRetrievalMethods(); - for (vector::const_iterator m=methods.begin(); m!=methods.end(); ++m) { - if (!XMLString::equals((*m)->getType(),RetrievalMethod::TYPE_X509DATA)) - continue; - fragID = (*m)->getURI(); - if (!fragID || *fragID != chPound || !*(fragID+1)) { - log.warn("skipping ds:RetrievalMethod with an empty or non-local reference"); - continue; - } - if (!treeRoot) { - treeRoot = keyInfo; - while (treeRoot->getParent()) - treeRoot = treeRoot->getParent(); - } - keyInfo = dynamic_cast(XMLHelper::getXMLObjectById(*treeRoot, fragID+1)); - if (!keyInfo) { - log.warn("skipping ds:RetrievalMethod, local reference did not resolve to a ds:KeyInfo"); - continue; - } - if (resolveCRL(keyInfo)) - return true; - } - return false; } diff --git a/xmltooling/soap/SOAP.h b/xmltooling/soap/SOAP.h index 8ef5de0..031599b 100644 --- a/xmltooling/soap/SOAP.h +++ b/xmltooling/soap/SOAP.h @@ -81,8 +81,10 @@ namespace soap11 { END_XMLOBJECT; BEGIN_XMLOBJECT(XMLTOOL_API,Header,xmltooling::ElementProxy,SOAP 1.1 Header element); - DECL_BOOLEAN_ATTRIB(MustUnderstand,MUSTUNDERSTAND,false); - DECL_STRING_ATTRIB(Actor,ACTOR); + /** Actor header block attribute name */ + static const XMLCh ACTOR_ATTRIB_NAME[]; + /** mustUnderstand header block attribute name */ + static const XMLCh MUSTUNDERSTAND_ATTRIB_NAME[]; /** Header (type) local name */ static const XMLCh TYPE_NAME[]; END_XMLOBJECT; @@ -95,13 +97,13 @@ namespace soap11 { END_XMLOBJECT; DECL_SOAP11OBJECTBUILDER(Body); - DECL_SOAP11OBJECTBUILDER(Detail); DECL_SOAP11OBJECTBUILDER(Envelope); DECL_SOAP11OBJECTBUILDER(Fault); - DECL_SOAP11OBJECTBUILDER(Faultactor); - DECL_SOAP11OBJECTBUILDER(Faultcode); - DECL_SOAP11OBJECTBUILDER(Faultstring); DECL_SOAP11OBJECTBUILDER(Header); + DECL_XMLOBJECTBUILDER(XMLTOOL_API,Detail,NULL,NULL); + DECL_XMLOBJECTBUILDER(XMLTOOL_API,Faultactor,NULL,NULL); + DECL_XMLOBJECTBUILDER(XMLTOOL_API,Faultcode,NULL,NULL); + DECL_XMLOBJECTBUILDER(XMLTOOL_API,Faultstring,NULL,NULL); /** * Registers builders and validators for SOAP 1.1 classes into the runtime. diff --git a/xmltooling/soap/impl/CURLSOAPTransport.cpp b/xmltooling/soap/impl/CURLSOAPTransport.cpp index 190d6a1..6f8f11f 100644 --- a/xmltooling/soap/impl/CURLSOAPTransport.cpp +++ b/xmltooling/soap/impl/CURLSOAPTransport.cpp @@ -546,7 +546,7 @@ int xmltooling::verify_callback(X509_STORE_CTX* x509_ctx, void* arg) bool success=false; if (ctx->m_criteria) { - ctx->m_criteria->setUsage(CredentialCriteria::TLS_CREDENTIAL); + ctx->m_criteria->setUsage(Credential::TLS_CREDENTIAL); // Bypass name check (handled for us by curl). ctx->m_criteria->setPeerName(NULL); success = ctx->m_trustEngine->validate(x509_ctx->cert,x509_ctx->untrusted,*(ctx->m_peerResolver),ctx->m_criteria); @@ -554,7 +554,7 @@ int xmltooling::verify_callback(X509_STORE_CTX* x509_ctx, void* arg) else { // Bypass name check (handled for us by curl). CredentialCriteria cc; - cc.setUsage(CredentialCriteria::TLS_CREDENTIAL); + cc.setUsage(Credential::TLS_CREDENTIAL); success = ctx->m_trustEngine->validate(x509_ctx->cert,x509_ctx->untrusted,*(ctx->m_peerResolver),&cc); } diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index fdca645..9120310 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -56,6 +56,10 @@ void SOAPClient::send(const Envelope& env, const SOAPTransport::Address& addr) m_transport = XMLToolingConfig::getConfig().SOAPTransportManager.newPlugin(scheme.c_str(), addr); prepareTransport(*m_transport); + Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient"); + if (log.isDebugEnabled()) + log.debugStream() << "marshalled envelope:" << logging::eol << env << logging::eol; + // Serialize envelope. stringstream s; s << env; @@ -83,6 +87,11 @@ Envelope* SOAPClient::receive() DOMDocument* doc = (m_validate ? XMLToolingConfig::getConfig().getValidatingParser() : XMLToolingConfig::getConfig().getParser()).parse(out); XercesJanitor janitor(doc); + + Category& log = Category::getInstance(XMLTOOLING_LOGCAT".SOAPClient"); + if (log.isDebugEnabled()) + log.debugStream() << "received XML:" << logging::eol << *(doc->getDocumentElement()) << logging::eol; + auto_ptr xmlObject(XMLObjectBuilder::buildOneFromElement(doc->getDocumentElement(), true)); janitor.release(); if (!m_validate) diff --git a/xmltooling/soap/impl/SOAPImpl.cpp b/xmltooling/soap/impl/SOAPImpl.cpp index 57c7fde..e6fc4d6 100644 --- a/xmltooling/soap/impl/SOAPImpl.cpp +++ b/xmltooling/soap/impl/SOAPImpl.cpp @@ -184,10 +184,10 @@ namespace { protected: void processChildElement(XMLObject* childXMLObject, const DOMElement* root) { - PROC_TYPED_CHILD(Faultcode,SOAP11ENV_NS,false); - PROC_TYPED_CHILD(Faultstring,SOAP11ENV_NS,false); - PROC_TYPED_CHILD(Faultactor,SOAP11ENV_NS,false); - PROC_TYPED_CHILD(Detail,SOAP11ENV_NS,false); + PROC_TYPED_CHILD(Faultcode,NULL,false); + PROC_TYPED_CHILD(Faultstring,NULL,false); + PROC_TYPED_CHILD(Faultactor,NULL,false); + PROC_TYPED_CHILD(Detail,NULL,false); AbstractXMLObjectUnmarshaller::processChildElement(childXMLObject,root); } }; @@ -228,6 +228,7 @@ namespace { IMPL_STRING_ATTRIB(EncodingStyle); IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject, m_children.end()); + using AbstractAttributeExtensibleXMLObject::setAttribute; void setAttribute(QName& qualifiedName, const XMLCh* value, bool ID=false) { if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),SOAP11ENV_NS)) { if (XMLString::equals(qualifiedName.getLocalPart(),ENCODINGSTYLE_ATTRIB_NAME)) { @@ -260,18 +261,12 @@ namespace { public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller { - void init() { - m_Actor=NULL; - m_MustUnderstand=xmlconstants::XML_BOOL_NULL; - } public: virtual ~HeaderImpl() { - XMLString::release(&m_Actor); } HeaderImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) : AbstractXMLObject(nsURI, localName, prefix, schemaType) { - init(); } HeaderImpl(const HeaderImpl& src) @@ -279,37 +274,16 @@ namespace { AbstractAttributeExtensibleXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src) { - init(); - setActor(src.getActor()); - MustUnderstand(m_MustUnderstand); VectorOf(XMLObject) v=getUnknownXMLObjects(); for (vector::const_iterator i=src.m_UnknownXMLObjects.begin(); i!=src.m_UnknownXMLObjects.end(); ++i) v.push_back((*i)->clone()); } IMPL_XMLOBJECT_CLONE(Header); - IMPL_STRING_ATTRIB(Actor); - IMPL_BOOLEAN_ATTRIB(MustUnderstand); IMPL_XMLOBJECT_CHILDREN(UnknownXMLObject, m_children.end()); - void setAttribute(QName& qualifiedName, const XMLCh* value, bool ID=false) { - if (qualifiedName.hasNamespaceURI() && XMLString::equals(qualifiedName.getNamespaceURI(),SOAP11ENV_NS)) { - if (XMLString::equals(qualifiedName.getLocalPart(),MUSTUNDERSTAND_ATTRIB_NAME)) { - setMustUnderstand(value); - return; - } - else if (XMLString::equals(qualifiedName.getLocalPart(),ACTOR_ATTRIB_NAME)) { - setActor(value); - return; - } - } - AbstractAttributeExtensibleXMLObject::setAttribute(qualifiedName, value, ID); - } - protected: void marshallAttributes(DOMElement* domElement) const { - MARSHALL_STRING_ATTRIB(Actor,ACTOR,SOAP11ENV_NS); - MARSHALL_BOOLEAN_ATTRIB(MustUnderstand,MUSTUNDERSTAND,SOAP11ENV_NS); marshallExtensionAttributes(domElement); } diff --git a/xmltooling/util/CurlNetAccessor.cpp b/xmltooling/util/CurlNetAccessor.cpp index 4e255b5..e09ffe5 100644 --- a/xmltooling/util/CurlNetAccessor.cpp +++ b/xmltooling/util/CurlNetAccessor.cpp @@ -30,7 +30,7 @@ using namespace xmltooling; -const XMLCh CurlNetAccessor::fgMyName[] = +const XMLCh xmltooling::CurlNetAccessor::fgMyName[] = { chLatin_C, chLatin_u, chLatin_r, chLatin_l, chLatin_N, chLatin_e, chLatin_t, chLatin_A, chLatin_c, chLatin_c, chLatin_e, chLatin_s, diff --git a/xmltooling/util/CurlNetAccessor.hpp b/xmltooling/util/CurlNetAccessor.hpp index a032d57..a1ff700 100644 --- a/xmltooling/util/CurlNetAccessor.hpp +++ b/xmltooling/util/CurlNetAccessor.hpp @@ -19,7 +19,7 @@ * $Id$ */ -#if !defined(XERCESC_INCLUDE_GUARD_CURLNETACCESSOR_HPP) +#if !defined(XERCESC_INCLUDE_GUARD_CURLNETACCESSOR_HPP) && !defined(XMLTOOLING_LITE) #define XERCESC_INCLUDE_GUARD_CURLNETACCESSOR_HPP #include @@ -37,7 +37,7 @@ namespace xmltooling { // a HTTP or FTP URL. // -class XMLTOOL_EXPORT CurlNetAccessor : public XMLNetAccessor +class XMLTOOL_API CurlNetAccessor : public XMLNetAccessor { public : CurlNetAccessor(); diff --git a/xmltooling/util/CurlURLInputStream.cpp b/xmltooling/util/CurlURLInputStream.cpp index 4b4c9d2..bba89a3 100644 --- a/xmltooling/util/CurlURLInputStream.cpp +++ b/xmltooling/util/CurlURLInputStream.cpp @@ -75,6 +75,14 @@ CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTP curl_easy_setopt(fEasy, CURLOPT_URL, fURL.get()); curl_easy_setopt(fEasy, CURLOPT_WRITEDATA, this); // Pass this pointer to write function curl_easy_setopt(fEasy, CURLOPT_WRITEFUNCTION, staticWriteCallback); // Our static write function + curl_easy_setopt(fEasy, CURLOPT_CONNECTTIMEOUT, 15); + curl_easy_setopt(fEasy, CURLOPT_TIMEOUT, 30); + curl_easy_setopt(fEasy, CURLOPT_SSLVERSION, CURL_SSLVERSION_SSLv3); + curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYHOST, 0); + curl_easy_setopt(fEasy, CURLOPT_SSL_VERIFYPEER, 0); + curl_easy_setopt(fEasy, CURLOPT_NOPROGRESS, 1); + curl_easy_setopt(fEasy, CURLOPT_NOSIGNAL, 1); + curl_easy_setopt(fEasy, CURLOPT_FAILONERROR, 1); // Add easy handle to the multi stack curl_multi_add_handle(fMulti, fEasy); @@ -227,19 +235,22 @@ CurlURLInputStream::readBytes(XMLByte* const toFill // read any yet on this invocation, call select to wait for data if (!tryAgain && fBytesRead == 0) { - fd_set readSet[16]; - fd_set writeSet[16]; - fd_set exceptSet[16]; - int fdcnt = 16; + fd_set readSet; + fd_set writeSet; + fd_set exceptSet; + int fdcnt=0; - // As curl for the file descriptors to wait on - (void) curl_multi_fdset(fMulti, readSet, writeSet, exceptSet, &fdcnt); + // Ask curl for the file descriptors to wait on + FD_ZERO(&readSet); + FD_ZERO(&writeSet); + FD_ZERO(&exceptSet); + (void) curl_multi_fdset(fMulti, &readSet, &writeSet, &exceptSet, &fdcnt); // Wait on the file descriptors timeval tv; tv.tv_sec = 2; tv.tv_usec = 0; - (void) select(fdcnt, readSet, writeSet, exceptSet, &tv); + (void) select(fdcnt, &readSet, &writeSet, &exceptSet, &tv); } } diff --git a/xmltooling/util/CurlURLInputStream.hpp b/xmltooling/util/CurlURLInputStream.hpp index 38e2391..a8bb925 100644 --- a/xmltooling/util/CurlURLInputStream.hpp +++ b/xmltooling/util/CurlURLInputStream.hpp @@ -19,7 +19,7 @@ * $Id$ */ -#if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP) +#if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP) && !defined(XMLTOOLING_LITE) #define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP #include @@ -41,7 +41,7 @@ namespace xmltooling { // parser. // -class XMLTOOL_EXPORT CurlURLInputStream : public BinInputStream +class XMLTOOL_API CurlURLInputStream : public BinInputStream { public : CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0); diff --git a/xmltooling/util/ParserPool.cpp b/xmltooling/util/ParserPool.cpp index 18f27ea..693cef4 100644 --- a/xmltooling/util/ParserPool.cpp +++ b/xmltooling/util/ParserPool.cpp @@ -280,19 +280,19 @@ bool ParserPool::handleError(const DOMError& e) case DOMError::DOM_SEVERITY_WARNING: log.warnStream() << "warning on line " << locator->getLineNumber() << ", column " << locator->getColumnNumber() - << ", message: " << temp.get() << CategoryStream::ENDLINE; + << ", message: " << temp.get() << logging::eol; return true; case DOMError::DOM_SEVERITY_ERROR: log.errorStream() << "error on line " << locator->getLineNumber() << ", column " << locator->getColumnNumber() - << ", message: " << temp.get() << CategoryStream::ENDLINE; + << ", message: " << temp.get() << logging::eol; throw XMLParserException(string("error during XML parsing: ") + (temp.get() ? temp.get() : "no message")); case DOMError::DOM_SEVERITY_FATAL_ERROR: log.critStream() << "fatal error on line " << locator->getLineNumber() << ", column " << locator->getColumnNumber() - << ", message: " << temp.get() << CategoryStream::ENDLINE; + << ", message: " << temp.get() << logging::eol; throw XMLParserException(string("fatal error during XML parsing: ") + (temp.get() ? temp.get() : "no message")); } throw XMLParserException(string("unclassified error during XML parsing: ") + (temp.get() ? temp.get() : "no message")); @@ -369,7 +369,7 @@ unsigned int StreamInputSource::StreamBinInputStream::readBytes(XMLByte* const t catch(ios_base::failure& e) { Category::getInstance(XMLTOOLING_LOGCAT".StreamInputSource").critStream() << "XML::StreamInputSource::StreamBinInputStream::readBytes caught an exception: " << e.what() - << CategoryStream::ENDLINE; + << logging::eol; *toFill=0; return 0; } diff --git a/xmltooling/util/Predicates.h b/xmltooling/util/Predicates.h new file mode 100644 index 0000000..b822862 --- /dev/null +++ b/xmltooling/util/Predicates.h @@ -0,0 +1,115 @@ +/* + * Copyright 2001-2007 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 xmltooling/util/Predicates.h + * + * Useful XMLObject predicates for use with STL algorithms. + */ + +#ifndef __xmltooling_predicates_h__ +#define __xmltooling_predicates_h__ + +#include + +#include + +namespace xmltooling { + + /** + * Predicate that checks the QName of an XMLObject. + */ + class hasQName + { + public: + /** + * Constructor. + * + * @param q the QName to check for + */ + hasQName(const QName& q) : m_q(q) { + } + + /** + * Returns true iff the provided object's QName matches the constructor argument. + * + * @param xmlObject the object to examine + */ + bool operator()(const XMLObject* xmlObject) const { + return xmlObject ? (xmlObject->getElementQName() == m_q) : false; + } + + private: + const QName& m_q; + }; + + /** + * Predicate that checks the xsi:type of an XMLObject. + */ + class hasSchemaType + { + public: + /** + * Constructor. + * + * @param q the QName to check for + */ + hasSchemaType(const QName& q) : m_q(q) { + } + + /** + * Returns true iff the provided object's xsi:type matches the constructor argument. + * + * @param xmlObject the object to examine + */ + bool operator()(const XMLObject* xmlObject) const { + const QName* xsitype = xmlObject ? xmlObject->getSchemaType() : NULL; + return xsitype ? (*xsitype == m_q) : false; + } + + private: + const QName& m_q; + }; + + /** + * Template algorithm returns first pointer element from a container that matches a predicate. + * + * @param c read-only container of pointer-based objects + * @param p a predicate function + * @return the first object in the container matching the predicate, or NULL + */ + template + typename Container::value_type find_if(const Container& c, const Predicate& p) { + typename Container::const_iterator i = std::find_if(c.begin(), c.end(), p); + return (i!=c.end()) ? *i : NULL; + } + + /** + * Template algorithm returns first pointer element from a container that matches a predicate. + * + * @param c read-only container of pointer-based objects + * @param p a predicate function + * @return the first object in the container matching the predicate, or NULL + */ + template + typename Container::value_type find_if(Container& c, const Predicate& p) { + typename Container::iterator i = std::find_if(c.begin(), c.end(), p); + return (i!=c.end()) ? *i : NULL; + } + +}; + +#endif /* __xmltooling_predicates_h__ */ diff --git a/xmltooling/util/ReloadableXMLFile.cpp b/xmltooling/util/ReloadableXMLFile.cpp index 5bdb545..5391a94 100644 --- a/xmltooling/util/ReloadableXMLFile.cpp +++ b/xmltooling/util/ReloadableXMLFile.cpp @@ -170,7 +170,7 @@ pair ReloadableXMLFile::load(bool backup) doc=XMLToolingConfig::getConfig().getParser().parse(dsrc); } - m_log.infoStream() << "loaded XML resource (" << (backup ? m_backing : m_source) << ")" << CategoryStream::ENDLINE; + 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()); @@ -189,14 +189,14 @@ pair ReloadableXMLFile::load(bool backup) catch (XMLException& e) { auto_ptr_char msg(e.getMessage()); m_log.critStream() << "Xerces error while loading resource (" << (backup ? m_backing : m_source) << "): " - << msg.get() << CategoryStream::ENDLINE; + << msg.get() << logging::eol; if (!backup && !m_backing.empty()) return load(true); throw XMLParserException(msg.get()); } catch (exception& e) { m_log.critStream() << "error while loading configuration from (" - << (m_source.empty() ? "inline" : (backup ? m_backing : m_source)) << "): " << e.what() << CategoryStream::ENDLINE; + << (m_source.empty() ? "inline" : (backup ? m_backing : m_source)) << "): " << e.what() << logging::eol; if (!backup && !m_backing.empty()) return load(true); throw; diff --git a/xmltooling/util/XMLObjectChildrenList.h b/xmltooling/util/XMLObjectChildrenList.h index df6b860..c0b6575 100644 --- a/xmltooling/util/XMLObjectChildrenList.h +++ b/xmltooling/util/XMLObjectChildrenList.h @@ -81,27 +81,150 @@ namespace xmltooling { /** * STL iterator that mediates access to an iterator over typed XML children. - * @param _Ty a bidrectional sequence of the subtype to iterate over + * + * @param Container type of container + * @param _Ty a bidrectional iterator to guard */ - template + template class XMLObjectChildrenIterator { /// @cond OFF - typename _Ty::iterator m_iter; + _Ty m_iter; template friend class XMLObjectChildrenList; template friend class XMLObjectPairList; public: +#ifdef HAVE_ITERATOR_TRAITS + typedef typename std::iterator_traits<_Ty>::iterator_category iterator_category; + typedef typename std::iterator_traits<_Ty>::value_type value_type; + typedef typename std::iterator_traits<_Ty>::difference_type difference_type; + typedef typename std::iterator_traits<_Ty>::pointer pointer; + typedef typename std::iterator_traits<_Ty>::reference reference; +#else + typedef typename _Ty::iterator_category iterator_category; typedef typename _Ty::value_type value_type; - typedef typename _Ty::reference reference; - typedef typename _Ty::pointer pointer; - typedef typename _Ty::const_reference const_reference; - typedef typename _Ty::const_pointer const_pointer; typedef typename _Ty::difference_type difference_type; + typedef typename _Ty::pointer pointer; + typedef typename _Ty::reference reference; +#endif + typedef typename Container::const_reference const_reference; + typedef typename Container::const_pointer const_pointer; + + XMLObjectChildrenIterator() { + } + + XMLObjectChildrenIterator(_Ty iter) { + m_iter=iter; + } + + const_reference operator*() const { + return *m_iter; + } + + const_reference operator->() const { + return *m_iter; + } + + XMLObjectChildrenIterator& operator++() { + // preincrement + ++m_iter; + return (*this); + } + + XMLObjectChildrenIterator& operator--() { + // predecrement + --m_iter; + return (*this); + } + + XMLObjectChildrenIterator operator++(int) { + // postincrement + XMLObjectChildrenIterator _Tmp = *this; + ++*this; + return (_Tmp); + } + + XMLObjectChildrenIterator operator--(int) { + // postdecrement + XMLObjectChildrenIterator _Tmp = *this; + --*this; + return (_Tmp); + } + + XMLObjectChildrenIterator& operator+=(difference_type _Off) { + // increment by integer + m_iter += _Off; + return (*this); + } + + XMLObjectChildrenIterator operator+(difference_type _Off) const { + // return this + integer + return m_iter + _Off; + } + + XMLObjectChildrenIterator& operator-=(difference_type _Off) { + // decrement by integer + return (*this += -_Off); + } + + XMLObjectChildrenIterator operator-(difference_type _Off) const { + // return this - integer + XMLObjectChildrenIterator _Tmp = *this; + return (_Tmp -= _Off); + } + + difference_type operator-(const XMLObjectChildrenIterator& _Right) const { + // return difference of iterators + return m_iter - _Right.m_iter; + } + + const_reference operator[](difference_type _Off) const { + // subscript + return (*(*this + _Off)); + } + + bool operator==(const XMLObjectChildrenIterator &_Right) const { + // test for iterator equality + return (m_iter == _Right.m_iter); + } + + bool operator!=(const XMLObjectChildrenIterator &_Right) const { + // test for iterator inequality + return (!(m_iter == _Right.m_iter)); + } + + bool operator<(const XMLObjectChildrenIterator &_Right) const { + return (m_iter < _Right.m_iter); + } + /// @endcond + }; + +#ifndef HAVE_ITERATOR_TRAITS + /** + * STL iterator that mediates access to an iterator that's a pointer. + * + * @param Container type of container + * @param _Ty the type of object being referenced + */ + template + class XMLObjectChildrenIterator + { + /// @cond OFF + typename _Ty* m_iter; + template friend class XMLObjectChildrenList; + template friend class XMLObjectPairList; + public: + typedef std::random_access_iterator_tag iterator_category; + typedef _Ty value_type; + typedef ptrdiff_t difference_type; + typedef _Ty* pointer; + typedef _Ty& reference; + typedef const _Ty& const_reference; + typedef const _Ty* const_pointer; XMLObjectChildrenIterator() { } - XMLObjectChildrenIterator(typename _Ty::iterator iter) { + XMLObjectChildrenIterator(_Ty* iter) { m_iter=iter; } @@ -180,8 +303,124 @@ namespace xmltooling { // test for iterator inequality return (!(m_iter == _Right.m_iter)); } + + bool operator<(const XMLObjectChildrenIterator &_Right) const { + return (m_iter < _Right.m_iter); + } + /// @endcond + }; + + /** + * STL iterator that mediates access to an iterator that's a const pointer. + * + * @param Container type of container + * @param _Ty the type of object being referenced + */ + template + class XMLObjectChildrenIterator + { + /// @cond OFF + typename const _Ty* m_iter; + template friend class XMLObjectChildrenList; + template friend class XMLObjectPairList; + public: + typedef std::random_access_iterator_tag iterator_category; + typedef _Ty value_type; + typedef ptrdiff_t difference_type; + typedef const _Ty* pointer; + typedef const _Ty& reference; + typedef const _Ty& const_reference; + typedef const _Ty* const_pointer; + + XMLObjectChildrenIterator() { + } + + XMLObjectChildrenIterator(_Ty* iter) { + m_iter=iter; + } + + const_reference operator*() const { + return *m_iter; + } + + const_reference operator->() const { + return *m_iter; + } + + XMLObjectChildrenIterator& operator++() { + // preincrement + ++m_iter; + return (*this); + } + + XMLObjectChildrenIterator& operator--() { + // predecrement + --m_iter; + return (*this); + } + + XMLObjectChildrenIterator operator++(int) { + // postincrement + XMLObjectChildrenIterator _Tmp = *this; + ++*this; + return (_Tmp); + } + + XMLObjectChildrenIterator operator--(int) { + // postdecrement + XMLObjectChildrenIterator _Tmp = *this; + --*this; + return (_Tmp); + } + + XMLObjectChildrenIterator& operator+=(difference_type _Off) { + // increment by integer + m_iter += _Off; + return (*this); + } + + XMLObjectChildrenIterator operator+(difference_type _Off) const { + // return this + integer + return m_iter + _Off; + } + + XMLObjectChildrenIterator& operator-=(difference_type _Off) { + // decrement by integer + return (*this += -_Off); + } + + XMLObjectChildrenIterator operator-(difference_type _Off) const { + // return this - integer + XMLObjectChildrenIterator _Tmp = *this; + return (_Tmp -= _Off); + } + + difference_type operator-(const XMLObjectChildrenIterator& _Right) const { + // return difference of iterators + return m_iter - _Right.m_iter; + } + + const_reference operator[](difference_type _Off) const { + // subscript + return (*(*this + _Off)); + } + + bool operator==(const XMLObjectChildrenIterator &_Right) const { + // test for iterator equality + return (m_iter == _Right.m_iter); + } + + bool operator!=(const XMLObjectChildrenIterator &_Right) const { + // test for iterator inequality + return (!(m_iter == _Right.m_iter)); + } + + bool operator<(const XMLObjectChildrenIterator &_Right) const { + return (m_iter < _Right.m_iter); + } /// @endcond }; +#endif /** * STL-compatible container that mediates access to underlying lists of typed XML children. @@ -205,8 +444,8 @@ namespace xmltooling { typedef typename Container::size_type size_type; // We override the iterator types with our constrained wrapper. - typedef XMLObjectChildrenIterator iterator; - typedef XMLObjectChildrenIterator const_iterator; + typedef XMLObjectChildrenIterator iterator; + typedef XMLObjectChildrenIterator const_iterator; /// @endcond /** @@ -249,12 +488,12 @@ namespace xmltooling { const_iterator begin() const { // return iterator for beginning of const sequence - return m_container.begin(); + return const_cast(m_container).begin(); } const_iterator end() const { // return iterator for end of const sequence - return m_container.end(); + return const_cast(m_container).end(); } const_reference at(size_type _Pos) const { @@ -359,8 +598,8 @@ namespace xmltooling { typedef typename Container::size_type size_type; // We override the iterator types with our constrained wrapper. - typedef XMLObjectChildrenIterator iterator; - typedef XMLObjectChildrenIterator const_iterator; + typedef XMLObjectChildrenIterator iterator; + typedef XMLObjectChildrenIterator const_iterator; /// @endcond /** @@ -403,12 +642,12 @@ namespace xmltooling { const_iterator begin() const { // return iterator for beginning of const sequence - return m_container.begin(); + return const_cast(m_container).begin(); } const_iterator end() const { // return iterator for end of const sequence - return m_container.end(); + return const_cast(m_container).end(); } const_reference at(size_type _Pos) const { diff --git a/xmltooling/xmltooling-lite.vcproj b/xmltooling/xmltooling-lite.vcproj index cb1a9d7..489992b 100644 --- a/xmltooling/xmltooling-lite.vcproj +++ b/xmltooling/xmltooling-lite.vcproj @@ -279,6 +279,10 @@ RelativePath=".\io\AbstractXMLObjectUnmarshaller.cpp" > + + + + diff --git a/xmltooling/xmltooling.vcproj b/xmltooling/xmltooling.vcproj index 070fba3..9b148c4 100644 --- a/xmltooling/xmltooling.vcproj +++ b/xmltooling/xmltooling.vcproj @@ -294,6 +294,10 @@ RelativePath=".\io\AbstractXMLObjectUnmarshaller.cpp" > + + + + diff --git a/xmltoolingtest/EncryptionTest.h b/xmltoolingtest/EncryptionTest.h index 3d6c79a..7cd05e6 100644 --- a/xmltoolingtest/EncryptionTest.h +++ b/xmltoolingtest/EncryptionTest.h @@ -56,7 +56,7 @@ public: try { CredentialCriteria cc; - cc.setUsage(CredentialCriteria::ENCRYPTION_CREDENTIAL); + cc.setUsage(Credential::ENCRYPTION_CREDENTIAL); Locker locker(m_resolver); const Credential* cred=m_resolver->resolve(&cc); TSM_ASSERT("Retrieved credential was null", cred!=NULL); diff --git a/xmltoolingtest/SignatureTest.h b/xmltoolingtest/SignatureTest.h index 8e05cce..fc682e1 100644 --- a/xmltoolingtest/SignatureTest.h +++ b/xmltoolingtest/SignatureTest.h @@ -119,7 +119,7 @@ public: sig->setContentReference(new TestContext(&chNull)); CredentialCriteria cc; - cc.setUsage(CredentialCriteria::SIGNING_CREDENTIAL); + cc.setUsage(Credential::SIGNING_CREDENTIAL); Locker locker(m_resolver); const Credential* cred = m_resolver->resolve(&cc); TSM_ASSERT("Retrieved credential was null", cred!=NULL); diff --git a/xmltoolingtest/data/SimpleXMLObjectWithContent.xml b/xmltoolingtest/data/SimpleXMLObjectWithContent.xml index d6df34555516c777c53b24c1662f80eb624581db..3bf4dcfa0ef427684c4a80b2c33162aed2523078 100644 GIT binary patch delta 9 QcmZ3)w18>C&55_&0TdeqV*mgE delta 11 ScmZ3$w1{cKO-6-@H#`6t_XL6f -- 2.1.4