From 64dcaec957e9befd960779498d7fe35bbb62141a Mon Sep 17 00:00:00 2001 From: Scott Cantor Date: Tue, 31 Jul 2007 17:52:04 +0000 Subject: [PATCH] Multi-line svn commit, see body. Backport libcurl-based Xerces net access. Convert logging to log4shib via compile time switch. --- config_win32.h | 27 ++- configure.ac | 60 +++-- xmltooling/AbstractXMLObject.cpp | 3 +- xmltooling/AbstractXMLObject.h | 5 +- xmltooling/XMLObjectBuilder.cpp | 5 +- xmltooling/XMLToolingConfig.cpp | 13 +- xmltooling/config_pub.h.in | 6 + xmltooling/config_pub_win32.h | 6 + xmltooling/encryption/impl/Decrypter.cpp | 8 +- xmltooling/impl/MemoryStorageService.cpp | 4 +- xmltooling/impl/UnknownElement.cpp | 4 +- xmltooling/logging.h | 44 ++++ .../security/impl/AbstractPKIXTrustEngine.cpp | 4 +- .../security/impl/ChainingCredentialResolver.cpp | 4 +- xmltooling/security/impl/ChainingTrustEngine.cpp | 4 +- xmltooling/security/impl/CredentialCriteria.cpp | 6 +- .../security/impl/ExplicitKeyTrustEngine.cpp | 4 +- .../security/impl/FilesystemCredentialResolver.cpp | 4 +- xmltooling/security/impl/InlineKeyResolver.cpp | 4 +- xmltooling/signature/impl/XMLSecSignatureImpl.cpp | 4 +- xmltooling/soap/impl/CURLSOAPTransport.cpp | 4 +- xmltooling/soap/impl/SOAPClient.cpp | 4 +- xmltooling/util/CurlNetAccessor.cpp | 93 ++++++++ xmltooling/util/CurlNetAccessor.hpp | 72 ++++++ xmltooling/util/CurlURLInputStream.cpp | 248 +++++++++++++++++++++ xmltooling/util/CurlURLInputStream.hpp | 123 ++++++++++ xmltooling/util/NDC.cpp | 13 +- xmltooling/util/ParserPool.cpp | 4 +- xmltooling/util/ReloadableXMLFile.cpp | 2 +- xmltooling/util/ReloadableXMLFile.h | 6 +- xmltooling/util/Win32Threads.cpp | 5 +- xmltooling/xmltooling-lite.vcproj | 4 +- xmltooling/xmltooling.vcproj | 20 +- 33 files changed, 727 insertions(+), 90 deletions(-) create mode 100644 xmltooling/logging.h create mode 100644 xmltooling/util/CurlNetAccessor.cpp create mode 100644 xmltooling/util/CurlNetAccessor.hpp create mode 100644 xmltooling/util/CurlURLInputStream.cpp create mode 100644 xmltooling/util/CurlURLInputStream.hpp diff --git a/config_win32.h b/config_win32.h index 1fbb096..63a1a56 100644 --- a/config_win32.h +++ b/config_win32.h @@ -3,9 +3,8 @@ /* Define if C++ compiler supports covariant virtual methods. */ #define HAVE_COVARIANT_RETURNS 1 -/* Define to 1 if you have the header file. -#define HAVE_DLFCN_H 1 -*/ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_DLFCN_H */ /* Define to 1 if you have the `gmtime_r' function. */ /* #undef HAVE_GMTIME_R */ @@ -14,12 +13,14 @@ specialization. */ #define HAVE_GOOD_STL 1 -/* Define to 1 if you have the header file. -#define HAVE_INTTYPES_H 1 -*/ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_INTTYPES_H */ -/* Define if log4cpp library was found */ -#define HAVE_LIBLOG4CPP 1 +/* Define if log4shib library is used. */ +#define XMLTOOLING_LOG4SHIB 1 + +/* Define if log4cpp library is used. */ +/* #undef XMLTOOLING_LOG4CPP */ /* Define if Xerces-C library was found */ #define HAVE_LIBXERCESC 1 @@ -42,9 +43,8 @@ /* Define to 1 if you have the `strdup' function. */ #define HAVE_STRDUP 1 -/* Define to 1 if you have the header file. -#define HAVE_STRINGS_H 1 -*/ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_STRINGS_H */ /* Define to 1 if you have the header file. */ #define HAVE_STRING_H 1 @@ -58,9 +58,8 @@ /* Define to 1 if you have the header file. */ #define HAVE_SYS_TYPES_H 1 -/* Define to 1 if you have the header file. -#define HAVE_UNISTD_H 1 -*/ +/* Define to 1 if you have the header file. */ +/* #undef HAVE_UNISTD_H */ /* Name of package */ #define PACKAGE "xmltooling" diff --git a/configure.ac b/configure.ac index d81ed42..6242c3a 100644 --- a/configure.ac +++ b/configure.ac @@ -93,30 +93,54 @@ AC_TRY_LINK( [ class derived: virtual public base { public: virtual derived *GetPtr( void ) { return this; } }; ], [AC_DEFINE(HAVE_COVARIANT_RETURNS,1,[Define if C++ compiler supports covariant virtual methods.])]) -# log4cpp settings -AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config) -AC_ARG_WITH(log4cpp, - AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp-config is installed]), +# log4shib settings (favor this version over the log4cpp code) +AC_PATH_PROG(LOG4SHIB_CONFIG,log4shib-config) +AC_ARG_WITH(log4shib, + AC_HELP_STRING([--with-log4shib=PATH], [where log4shib-config is installed]), [ - LOG4CPP_CONFIG="${with_log4cpp}" - if ! test -f "${LOG4CPP_CONFIG}" ; then - LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config" + LOG4SHIB_CONFIG="${with_log4shib}" + if ! test -f "${LOG4SHIB_CONFIG}" ; then + LOG4SHIB_CONFIG="${with_log4shib}/bin/log4shib-config" fi ]) -if test -f "${LOG4CPP_CONFIG}"; then - LDFLAGS="`${LOG4CPP_CONFIG} --libs` $LDFLAGS" - CPPFLAGS="`${LOG4CPP_CONFIG} --cflags` $CPPFLAGS" +if test -f "${LOG4SHIB_CONFIG}"; then + LDFLAGS="`${LOG4SHIB_CONFIG} --libs` $LDFLAGS" + CPPFLAGS="`${LOG4SHIB_CONFIG} --cflags` $CPPFLAGS" else - AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option]) - LIBS="-llog4cpp $LIBS" + AC_MSG_WARN([log4shib-config not found, may need to use --with-log4shib option]) + AC_MSG_WARN([will look for original log4cpp library]) + + # log4cpp settings + AC_PATH_PROG(LOG4CPP_CONFIG,log4cpp-config) + AC_ARG_WITH(log4cpp, + AC_HELP_STRING([--with-log4cpp=PATH], [where log4cpp-config is installed]), + [ + LOG4CPP_CONFIG="${with_log4cpp}" + if ! test -f "${LOG4CPP_CONFIG}" ; then + LOG4CPP_CONFIG="${with_log4cpp}/bin/log4cpp-config" + fi + ]) + if test -f "${LOG4CPP_CONFIG}"; then + 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" + else + AC_MSG_ERROR([log4cpp-config not found, may need to use --with-log4cpp option]) + fi + 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_TRY_LINK( + [#include ], + [log4cpp::Category::getInstance("foo")], + [AC_DEFINE(XMLTOOLING_LOG4CPP,1,[Define if log4cpp library is used.])], + [AC_MSG_ERROR([unable to link with log4cpp])]) fi -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([log4shib/Category.hh],,AC_MSG_ERROR([unable to find log4shib header files])) AC_TRY_LINK( - [#include ], - [log4cpp::Category::getInstance("foo")], - [AC_DEFINE(HAVE_LIBLOG4CPP,1,[Define if log4cpp library was found])], - [AC_MSG_ERROR([unable to link with log4cpp])]) + [#include ], + [log4shib::Category::getInstance("foo")], + [AC_DEFINE(XMLTOOLING_LOG4SHIB,1,[Define if log4shib library is used.])], + [AC_MSG_ERROR([unable to link with log4shib])]) # Xerces settings AC_ARG_WITH(xerces, diff --git a/xmltooling/AbstractXMLObject.cpp b/xmltooling/AbstractXMLObject.cpp index 3eee63a..7c73f3f 100644 --- a/xmltooling/AbstractXMLObject.cpp +++ b/xmltooling/AbstractXMLObject.cpp @@ -25,12 +25,11 @@ #include "exceptions.h" #include -#include using namespace xmltooling; AbstractXMLObject::AbstractXMLObject(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType) - : m_log(log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL), + : m_log(logging::Category::getInstance(XMLTOOLING_LOGCAT".XMLObject")), m_schemaLocation(NULL), m_noNamespaceSchemaLocation(NULL), m_parent(NULL), m_elementQname(nsURI, localName, prefix), m_typeQname(NULL) { addNamespace(Namespace(nsURI, prefix)); diff --git a/xmltooling/AbstractXMLObject.h b/xmltooling/AbstractXMLObject.h index 80b2971..3b41d6d 100644 --- a/xmltooling/AbstractXMLObject.h +++ b/xmltooling/AbstractXMLObject.h @@ -23,11 +23,10 @@ #ifndef __xmltooling_abstractxmlobj_h__ #define __xmltooling_abstractxmlobj_h__ +#include #include #include -#include - #if defined (_MSC_VER) #pragma warning( push ) #pragma warning( disable : 4250 4251 ) @@ -195,7 +194,7 @@ namespace xmltooling { /** * Logging object. */ - log4cpp::Category& m_log; + logging::Category& m_log; /** * Stores off xsi:schemaLocation attribute. diff --git a/xmltooling/XMLObjectBuilder.cpp b/xmltooling/XMLObjectBuilder.cpp index a60d3a5..982f6a2 100644 --- a/xmltooling/XMLObjectBuilder.cpp +++ b/xmltooling/XMLObjectBuilder.cpp @@ -21,14 +21,13 @@ */ #include "internal.h" +#include "logging.h" #include "XMLObjectBuilder.h" #include "util/NDC.h" #include "util/XMLHelper.h" -#include - +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; map XMLObjectBuilder::m_map; diff --git a/xmltooling/XMLToolingConfig.cpp b/xmltooling/XMLToolingConfig.cpp index f4fc4d3..476f8f1 100644 --- a/xmltooling/XMLToolingConfig.cpp +++ b/xmltooling/XMLToolingConfig.cpp @@ -22,6 +22,7 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "XMLToolingConfig.h" #include "encryption/Encryption.h" #include "encryption/Encrypter.h" @@ -48,9 +49,13 @@ #endif #include -#include -#include -#include +#if defined(XMLTOOLING_LOG4SHIB) +# include +# include +#elif defined(XMLTOOLING_LOG4CPP) +# include +# include +#endif #include #ifndef XMLTOOLING_NO_XMLSEC # include @@ -61,8 +66,8 @@ using namespace soap11; using namespace xmlencryption; using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; DECL_XMLTOOLING_EXCEPTION_FACTORY(XMLParserException,xmltooling); diff --git a/xmltooling/config_pub.h.in b/xmltooling/config_pub.h.in index 45c9e8d..144d787 100644 --- a/xmltooling/config_pub.h.in +++ b/xmltooling/config_pub.h.in @@ -5,5 +5,11 @@ specialization. */ #undef HAVE_GOOD_STL +/* Define if log4shib library is used. */ +#undef XMLTOOLING_LOG4SHIB + +/* Define if log4cpp library is used. */ +#undef XMLTOOLING_LOG4CPP + /* Define to 1 to disable XML-Security-dependent features. */ #undef XMLTOOLING_NO_XMLSEC diff --git a/xmltooling/config_pub_win32.h b/xmltooling/config_pub_win32.h index 75ac0f9..0c13ee2 100644 --- a/xmltooling/config_pub_win32.h +++ b/xmltooling/config_pub_win32.h @@ -5,6 +5,12 @@ specialization. */ #define HAVE_GOOD_STL 1 +/* Define if log4shib library is used. */ +#define XMLTOOLING_LOG4SHIB 1 + +/* Define if log4cpp library is used. */ +/* #undef XMLTOOLING_LOG4CPP */ + /* Define to 1 to disable XML-Security-dependent features. */ /* #undef XMLTOOLING_NO_XMLSEC */ diff --git a/xmltooling/encryption/impl/Decrypter.cpp b/xmltooling/encryption/impl/Decrypter.cpp index 89a274b..47ed588 100644 --- a/xmltooling/encryption/impl/Decrypter.cpp +++ b/xmltooling/encryption/impl/Decrypter.cpp @@ -21,13 +21,13 @@ */ #include "internal.h" +#include "logging.h" #include "encryption/Decrypter.h" #include "encryption/EncryptedKeyResolver.h" #include "security/Credential.h" #include "security/CredentialCriteria.h" #include "security/CredentialResolver.h" -#include #include #include #include @@ -119,7 +119,7 @@ DOMDocumentFragment* Decrypter::decryptData(const EncryptedData& encryptedData, return decryptData(encryptedData, key); } catch(DecryptionException& ex) { - log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); + logging::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); } } @@ -219,7 +219,7 @@ void Decrypter::decryptData(ostream& out, const EncryptedData& encryptedData, co return decryptData(out, encryptedData, key); } catch(DecryptionException& ex) { - log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); + logging::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); } } @@ -320,7 +320,7 @@ XSECCryptoKey* Decrypter::decryptKey(const EncryptedKey& encryptedKey, const XML } } catch(DecryptionException& ex) { - log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); + logging::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what()); } } diff --git a/xmltooling/impl/MemoryStorageService.cpp b/xmltooling/impl/MemoryStorageService.cpp index 3d2f11d..af0fd71 100644 --- a/xmltooling/impl/MemoryStorageService.cpp +++ b/xmltooling/impl/MemoryStorageService.cpp @@ -21,16 +21,16 @@ */ #include "internal.h" +#include "logging.h" #include "util/NDC.h" #include "util/StorageService.h" #include "util/Threads.h" #include "util/XMLHelper.h" -#include #include +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/impl/UnknownElement.cpp b/xmltooling/impl/UnknownElement.cpp index 5a6c2c9..af4d12e 100644 --- a/xmltooling/impl/UnknownElement.cpp +++ b/xmltooling/impl/UnknownElement.cpp @@ -22,17 +22,17 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "impl/UnknownElement.h" #include "util/NDC.h" #include "util/XMLHelper.h" -#include #include #include #include +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; #ifndef XMLTOOLING_NO_XMLSEC using xmlsignature::Signature; diff --git a/xmltooling/logging.h b/xmltooling/logging.h new file mode 100644 index 0000000..377db18 --- /dev/null +++ b/xmltooling/logging.h @@ -0,0 +1,44 @@ +/* + * 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/logging.h + * + * Assist with logging portability. + */ + +#ifndef __xmltooling_logging_h__ +#define __xmltooling_logging_h__ + +#include + +#if defined(XMLTOOLING_LOG4SHIB) +# include +# include +namespace xmltooling { + namespace logging = log4shib; +}; +#elif defined(XMLTOOLING_LOG4CPP) +# include +# include +namespace xmltooling { + namespace logging = log4cpp; +}; +#else +# error "Supported logging library not available." +#endif + +#endif /* __xmltooling_logging_h__ */ diff --git a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp index 4ee5691..b98ce39 100644 --- a/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp +++ b/xmltooling/security/impl/AbstractPKIXTrustEngine.cpp @@ -22,10 +22,10 @@ */ #include "internal.h" +#include "logging.h" #include "security/AbstractPKIXTrustEngine.h" #include "signature/KeyInfo.h" -#include #include #include #include @@ -38,8 +38,8 @@ #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; diff --git a/xmltooling/security/impl/ChainingCredentialResolver.cpp b/xmltooling/security/impl/ChainingCredentialResolver.cpp index 312645e..72ce39f 100644 --- a/xmltooling/security/impl/ChainingCredentialResolver.cpp +++ b/xmltooling/security/impl/ChainingCredentialResolver.cpp @@ -21,16 +21,16 @@ */ #include "internal.h" +#include "logging.h" #include "XMLToolingConfig.h" #include "security/CredentialResolver.h" #include "util/NDC.h" #include "util/XMLHelper.h" -#include #include +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/security/impl/ChainingTrustEngine.cpp b/xmltooling/security/impl/ChainingTrustEngine.cpp index eda259c..4b5aa2c 100644 --- a/xmltooling/security/impl/ChainingTrustEngine.cpp +++ b/xmltooling/security/impl/ChainingTrustEngine.cpp @@ -22,15 +22,15 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "security/ChainingTrustEngine.h" #include "util/XMLHelper.h" -#include #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/security/impl/CredentialCriteria.cpp b/xmltooling/security/impl/CredentialCriteria.cpp index f7521a0..e229a06 100644 --- a/xmltooling/security/impl/CredentialCriteria.cpp +++ b/xmltooling/security/impl/CredentialCriteria.cpp @@ -21,11 +21,11 @@ */ #include "internal.h" +#include "logging.h" #include "security/Credential.h" #include "security/CredentialCriteria.h" #include "security/KeyInfoResolver.h" -#include #include #include #include @@ -75,7 +75,7 @@ bool CredentialCriteria::matches(const Credential& credential) const if (key1->getProviderName()!=DSIGConstants::s_unicodeStrPROVOpenSSL || key2->getProviderName()!=DSIGConstants::s_unicodeStrPROVOpenSSL) { - log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".Credential").warn("comparison of non-OpenSSL credentials are not supported"); + logging::Category::getInstance(XMLTOOLING_LOGCAT".Credential").warn("comparison of non-OpenSSL credentials are not supported"); return false; } @@ -95,6 +95,6 @@ bool CredentialCriteria::matches(const Credential& credential) const return (BN_cmp(dsa1->pub_key,dsa2->pub_key) == 0); } - log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".CredentialCriteria").warn("unsupported key type for comparison"); + logging::Category::getInstance(XMLTOOLING_LOGCAT".CredentialCriteria").warn("unsupported key type for comparison"); return false; } diff --git a/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp b/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp index de1c6b3..bed55d5 100644 --- a/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp +++ b/xmltooling/security/impl/ExplicitKeyTrustEngine.cpp @@ -21,6 +21,7 @@ */ #include "internal.h" +#include "logging.h" #include "security/Credential.h" #include "security/CredentialCriteria.h" #include "security/CredentialResolver.h" @@ -29,15 +30,14 @@ #include "signature/SignatureValidator.h" #include "util/NDC.h" -#include #include #include #include #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/security/impl/FilesystemCredentialResolver.cpp b/xmltooling/security/impl/FilesystemCredentialResolver.cpp index 8e29e8d..bd63dae 100644 --- a/xmltooling/security/impl/FilesystemCredentialResolver.cpp +++ b/xmltooling/security/impl/FilesystemCredentialResolver.cpp @@ -21,6 +21,7 @@ */ #include "internal.h" +#include "logging.h" #include "security/BasicX509Credential.h" #include "security/CredentialCriteria.h" #include "security/CredentialResolver.h" @@ -32,15 +33,14 @@ #include #include #include -#include #include #include #include #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; // OpenSSL password callback... diff --git a/xmltooling/security/impl/InlineKeyResolver.cpp b/xmltooling/security/impl/InlineKeyResolver.cpp index 2c2e87d..126a6ea 100644 --- a/xmltooling/security/impl/InlineKeyResolver.cpp +++ b/xmltooling/security/impl/InlineKeyResolver.cpp @@ -21,6 +21,7 @@ */ #include "internal.h" +#include "logging.h" #include "security/BasicX509Credential.h" #include "security/KeyInfoCredentialContext.h" #include "security/KeyInfoResolver.h" @@ -31,7 +32,6 @@ #include "util/XMLConstants.h" #include "validation/ValidatorSuite.h" -#include #include #include #include @@ -42,8 +42,8 @@ #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp index e3aaaac..938a684 100644 --- a/xmltooling/signature/impl/XMLSecSignatureImpl.cpp +++ b/xmltooling/signature/impl/XMLSecSignatureImpl.cpp @@ -22,6 +22,7 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "impl/UnknownElement.h" #include "security/Credential.h" #include "signature/KeyInfo.h" @@ -30,7 +31,6 @@ #include "util/XMLConstants.h" #include "util/XMLHelper.h" -#include #include #include #include @@ -45,8 +45,8 @@ #include using namespace xmlsignature; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; using xmlconstants::XMLSIG_NS; using xmlconstants::XMLSIG_PREFIX; diff --git a/xmltooling/soap/impl/CURLSOAPTransport.cpp b/xmltooling/soap/impl/CURLSOAPTransport.cpp index f1a6022..48e1a9e 100644 --- a/xmltooling/soap/impl/CURLSOAPTransport.cpp +++ b/xmltooling/soap/impl/CURLSOAPTransport.cpp @@ -22,6 +22,7 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "security/CredentialCriteria.h" #include "security/OpenSSLTrustEngine.h" #include "security/OpenSSLCredential.h" @@ -32,11 +33,10 @@ #include #include -#include #include +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; namespace xmltooling { diff --git a/xmltooling/soap/impl/SOAPClient.cpp b/xmltooling/soap/impl/SOAPClient.cpp index 2a56979..23d9b8c 100644 --- a/xmltooling/soap/impl/SOAPClient.cpp +++ b/xmltooling/soap/impl/SOAPClient.cpp @@ -22,17 +22,17 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "soap/SOAP.h" #include "soap/SOAPClient.h" #include "util/XMLHelper.h" #include "validation/ValidatorSuite.h" #include -#include using namespace soap11; +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; SOAPClient::~SOAPClient() diff --git a/xmltooling/util/CurlNetAccessor.cpp b/xmltooling/util/CurlNetAccessor.cpp new file mode 100644 index 0000000..6224f20 --- /dev/null +++ b/xmltooling/util/CurlNetAccessor.cpp @@ -0,0 +1,93 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * $Id$ + */ + +#include "internal.h" + +#include +#include +#include +#include +#include +#include + +using namespace xmltooling; + +const XMLCh 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, + chLatin_s, chLatin_o, chLatin_r, chNull +}; + + +CurlNetAccessor::CurlNetAccessor() +{ + initCurl(); +} + + +CurlNetAccessor::~CurlNetAccessor() +{ + cleanupCurl(); +} + + +// +// Global once-only init and cleanup of curl +// +// The init count used here is not thread protected; we assume +// that creation of the CurlNetAccessor will be serialized by +// the application. If the application is also using curl, then +// care must be taken that curl is initialized only once, by some +// other means, or by overloading these methods. +// +int CurlNetAccessor::fgCurlInitCount = 0; + +void +CurlNetAccessor::initCurl() +{ + if (fgCurlInitCount++ == 0) + curl_global_init( 0 + | CURL_GLOBAL_ALL // Initialize all curl modules + // | CURL_GLOBAL_WIN32 // Initialize Windows sockets first + // | CURL_GLOBAL_SSL // Initialize SSL first + ); +} + + +void +CurlNetAccessor::cleanupCurl() +{ + if (fgCurlInitCount > 0 && --fgCurlInitCount == 0) + curl_global_cleanup(); +} + + +BinInputStream* +CurlNetAccessor::makeNew(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) +{ + // Just create a CurlURLInputStream + // We defer any checking of the url type for curl in CurlURLInputStream + CurlURLInputStream* retStrm = + new (urlSource.getMemoryManager()) CurlURLInputStream(urlSource, httpInfo); + return retStrm; +} + diff --git a/xmltooling/util/CurlNetAccessor.hpp b/xmltooling/util/CurlNetAccessor.hpp new file mode 100644 index 0000000..4aabcea --- /dev/null +++ b/xmltooling/util/CurlNetAccessor.hpp @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * $Id$ + */ + +#if !defined(XERCESC_INCLUDE_GUARD_CURLNETACCESSOR_HPP) +#define XERCESC_INCLUDE_GUARD_CURLNETACCESSOR_HPP + +#include + +#include +#include +#include +#include + +namespace xmltooling { + +// +// This class is the wrapper for the socket based code which +// provides the ability to fetch a resource specified using +// a HTTP or FTP URL. +// + +class XMLTOOL_EXPORT CurlNetAccessor : public XMLNetAccessor +{ +public : + CurlNetAccessor(); + ~CurlNetAccessor(); + + virtual BinInputStream* makeNew(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0); + virtual const XMLCh* getId() const; + + virtual void initCurl(void); + virtual void cleanupCurl(void); + +private : + static int fgCurlInitCount; + static const XMLCh fgMyName[]; + + CurlNetAccessor(const CurlNetAccessor&); + CurlNetAccessor& operator=(const CurlNetAccessor&); + +}; // CurlNetAccessor + + +inline const XMLCh* CurlNetAccessor::getId() const +{ + return fgMyName; +} + + +}; + +#endif // CURLNETACCESSOR_HPP + + diff --git a/xmltooling/util/CurlURLInputStream.cpp b/xmltooling/util/CurlURLInputStream.cpp new file mode 100644 index 0000000..4b4c9d2 --- /dev/null +++ b/xmltooling/util/CurlURLInputStream.cpp @@ -0,0 +1,248 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * $Id$ + */ + +#include "internal.h" + +#include +#include +#include +#include +#ifdef HAVE_UNISTD_H +# include +#endif +//#include +//#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +using namespace xmltooling; + + +CurlURLInputStream::CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo/*=0*/) + : fMulti(0) + , fEasy(0) + , fMemoryManager(urlSource.getMemoryManager()) + , fURLSource(urlSource) + , fURL(0) + , fTotalBytesRead(0) + , fWritePtr(0) + , fBytesRead(0) + , fBytesToRead(0) + , fDataAvailable(false) + , fBufferHeadPtr(fBuffer) + , fBufferTailPtr(fBuffer) +{ + // Allocate the curl multi handle + fMulti = curl_multi_init(); + + // Allocate the curl easy handle + fEasy = curl_easy_init(); + + // Get the text of the URL we're going to use + fURL.reset(XMLString::transcode(fURLSource.getURLText(), fMemoryManager), fMemoryManager); + + //printf("Curl trying to fetch %s\n", fURL.get()); + + // Set URL option + 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 + + // Add easy handle to the multi stack + curl_multi_add_handle(fMulti, fEasy); +} + + +CurlURLInputStream::~CurlURLInputStream() +{ + // Remove the easy handle from the multi stack + curl_multi_remove_handle(fMulti, fEasy); + + // Cleanup the easy handle + curl_easy_cleanup(fEasy); + + // Cleanup the multi handle + curl_multi_cleanup(fMulti); +} + + +size_t +CurlURLInputStream::staticWriteCallback(char *buffer, + size_t size, + size_t nitems, + void *outstream) +{ + return ((CurlURLInputStream*)outstream)->writeCallback(buffer, size, nitems); +} + + + +size_t +CurlURLInputStream::writeCallback(char *buffer, + size_t size, + size_t nitems) +{ + size_t cnt = size * nitems; + size_t totalConsumed = 0; + + // Consume as many bytes as possible immediately into the buffer + size_t consume = (cnt > fBytesToRead) ? fBytesToRead : cnt; + memcpy(fWritePtr, buffer, consume); + fWritePtr += consume; + fBytesRead += consume; + fTotalBytesRead += consume; + fBytesToRead -= consume; + + //printf("write callback consuming %d bytes\n", consume); + + // If bytes remain, rebuffer as many as possible into our holding buffer + buffer += consume; + totalConsumed += consume; + cnt -= consume; + if (cnt > 0) + { + size_t bufAvail = sizeof(fBuffer) - (fBufferHeadPtr - fBuffer); + consume = (cnt > bufAvail) ? bufAvail : cnt; + memcpy(fBufferHeadPtr, buffer, consume); + fBufferHeadPtr += consume; + buffer += consume; + totalConsumed += consume; + //printf("write callback rebuffering %d bytes\n", consume); + } + + // Return the total amount we've consumed. If we don't consume all the bytes + // then an error will be generated. Since our buffer size is equal to the + // maximum size that curl will write, this should never happen unless there + // is a logic error somewhere here. + return totalConsumed; +} + + +unsigned int +CurlURLInputStream::readBytes(XMLByte* const toFill + , const unsigned int maxToRead) +{ + fBytesRead = 0; + fBytesToRead = maxToRead; + fWritePtr = toFill; + + for (bool tryAgain = true; fBytesToRead > 0 && (tryAgain || fBytesRead == 0); ) + { + // First, any buffered data we have available + size_t bufCnt = fBufferHeadPtr - fBufferTailPtr; + bufCnt = (bufCnt > fBytesToRead) ? fBytesToRead : bufCnt; + if (bufCnt > 0) + { + memcpy(fWritePtr, fBufferTailPtr, bufCnt); + fWritePtr += bufCnt; + fBytesRead += bufCnt; + fTotalBytesRead += bufCnt; + fBytesToRead -= bufCnt; + + fBufferTailPtr += bufCnt; + if (fBufferTailPtr == fBufferHeadPtr) + fBufferHeadPtr = fBufferTailPtr = fBuffer; + + //printf("consuming %d buffered bytes\n", bufCnt); + + tryAgain = true; + continue; + } + + // Ask the curl to do some work + int runningHandles = 0; + CURLMcode curlResult = curl_multi_perform(fMulti, &runningHandles); + tryAgain = (curlResult == CURLM_CALL_MULTI_PERFORM); + + // Process messages from curl + int msgsInQueue = 0; + for (CURLMsg* msg = NULL; (msg = curl_multi_info_read(fMulti, &msgsInQueue)) != NULL; ) + { + //printf("msg %d, %d from curl\n", msg->msg, msg->data.result); + + if (msg->msg != CURLMSG_DONE) + continue; + + switch (msg->data.result) + { + case CURLE_OK: + // We completed successfully. runningHandles should have dropped to zero, so we'll bail out below... + break; + + case CURLE_UNSUPPORTED_PROTOCOL: + ThrowXMLwithMemMgr(MalformedURLException, XMLExcepts::URL_UnsupportedProto, fMemoryManager); + break; + + case CURLE_COULDNT_RESOLVE_HOST: + case CURLE_COULDNT_RESOLVE_PROXY: + ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_TargetResolution, fURLSource.getHost(), fMemoryManager); + break; + + case CURLE_COULDNT_CONNECT: + ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ConnSocket, fURLSource.getURLText(), fMemoryManager); + + case CURLE_RECV_ERROR: + ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_ReadSocket, fURLSource.getURLText(), fMemoryManager); + break; + + default: + ThrowXMLwithMemMgr1(NetAccessorException, XMLExcepts::NetAcc_InternalError, fURLSource.getURLText(), fMemoryManager); + break; + } + } + + // If nothing is running any longer, bail out + if (runningHandles == 0) + break; + + // If there is no further data to read, and we haven't + // 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; + + // As curl for the file descriptors to wait on + (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); + } + } + + return fBytesRead; +} + diff --git a/xmltooling/util/CurlURLInputStream.hpp b/xmltooling/util/CurlURLInputStream.hpp new file mode 100644 index 0000000..38e2391 --- /dev/null +++ b/xmltooling/util/CurlURLInputStream.hpp @@ -0,0 +1,123 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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. + */ + +/* + * $Id$ + */ + +#if !defined(XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP) +#define XERCESC_INCLUDE_GUARD_CURLURLINPUTSTREAM_HPP + +#include + +#include +#include +#include + +#include +#include +#include +#include +#include + +namespace xmltooling { + +// +// This class implements the BinInputStream interface specified by the XML +// parser. +// + +class XMLTOOL_EXPORT CurlURLInputStream : public BinInputStream +{ +public : + CurlURLInputStream(const XMLURL& urlSource, const XMLNetHTTPInfo* httpInfo=0); + ~CurlURLInputStream(); + + unsigned int curPos() const; + unsigned int readBytes + ( + XMLByte* const toFill + , const unsigned int maxToRead + ); + + +private : + // ----------------------------------------------------------------------- + // Unimplemented constructors and operators + // ----------------------------------------------------------------------- + CurlURLInputStream(const CurlURLInputStream&); + CurlURLInputStream& operator=(const CurlURLInputStream&); + + static size_t staticWriteCallback(char *buffer, + size_t size, + size_t nitems, + void *outstream); + size_t writeCallback( char *buffer, + size_t size, + size_t nitems); + + + // ----------------------------------------------------------------------- + // Private data members + // + // fSocket + // The socket representing the connection to the remote file. + // fBytesProcessed + // Its a rolling count of the number of bytes processed off this + // input stream. + // fBuffer + // Holds the http header, plus the first part of the actual + // data. Filled at the time the stream is opened, data goes + // out to user in response to readBytes(). + // fBufferPos, fBufferEnd + // Pointers into fBuffer, showing start and end+1 of content + // that readBytes must return. + // ----------------------------------------------------------------------- + + CURLM* fMulti; + CURL* fEasy; + + MemoryManager* fMemoryManager; + + XMLURL fURLSource; + ArrayJanitor fURL; + + unsigned long fTotalBytesRead; + XMLByte* fWritePtr; + unsigned long fBytesRead; + unsigned long fBytesToRead; + bool fDataAvailable; + + // Overflow buffer for when curl writes more data to us + // than we've asked for. + XMLByte fBuffer[CURL_MAX_WRITE_SIZE]; + XMLByte* fBufferHeadPtr; + XMLByte* fBufferTailPtr; + +}; // CurlURLInputStream + + +inline unsigned int +CurlURLInputStream::curPos() const +{ + return fTotalBytesRead; +} + +}; + +#endif // CURLURLINPUTSTREAM_HPP + diff --git a/xmltooling/util/NDC.cpp b/xmltooling/util/NDC.cpp index 249cc96..ac23379 100644 --- a/xmltooling/util/NDC.cpp +++ b/xmltooling/util/NDC.cpp @@ -21,23 +21,28 @@ */ #include "internal.h" +#include "logging.h" #include "util/NDC.h" -#include +#if defined(XMLTOOLING_LOG4SHIB) +# include +#elif defined(XMLTOOLING_LOG4CPP) +# include +#endif using namespace xmltooling; NDC::NDC(const char* context) { - log4cpp::NDC::push(context); + logging::NDC::push(context); } NDC::NDC(const std::string& context) { - log4cpp::NDC::push(context); + logging::NDC::push(context); } NDC::~NDC() { - log4cpp::NDC::pop(); + logging::NDC::pop(); } diff --git a/xmltooling/util/ParserPool.cpp b/xmltooling/util/ParserPool.cpp index 3c8ffe1..18f27ea 100644 --- a/xmltooling/util/ParserPool.cpp +++ b/xmltooling/util/ParserPool.cpp @@ -22,6 +22,7 @@ #include "internal.h" #include "exceptions.h" +#include "logging.h" #include "util/NDC.h" #include "util/ParserPool.h" #include "util/XMLHelper.h" @@ -30,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -38,9 +38,9 @@ #include #include +using namespace xmltooling::logging; using namespace xmltooling; using namespace std; -using namespace log4cpp; ParserPool::ParserPool(bool namespaceAware, bool schemaAware) : m_namespaceAware(namespaceAware), m_schemaAware(schemaAware), m_lock(Mutex::create()) {} diff --git a/xmltooling/util/ReloadableXMLFile.cpp b/xmltooling/util/ReloadableXMLFile.cpp index 6a35afa..5bdb545 100644 --- a/xmltooling/util/ReloadableXMLFile.cpp +++ b/xmltooling/util/ReloadableXMLFile.cpp @@ -35,8 +35,8 @@ #include #include +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i); diff --git a/xmltooling/util/ReloadableXMLFile.h b/xmltooling/util/ReloadableXMLFile.h index 2b96cb1..cb4c5c3 100644 --- a/xmltooling/util/ReloadableXMLFile.h +++ b/xmltooling/util/ReloadableXMLFile.h @@ -23,13 +23,13 @@ #ifndef __xmltooling_reloadable_h__ #define __xmltooling_reloadable_h__ +#include #include #include #include #include #include -#include namespace xmltooling { @@ -58,7 +58,7 @@ namespace xmltooling { * @param e DOM to supply configuration * @param log logging object to use */ - ReloadableXMLFile(const xercesc::DOMElement* e, log4cpp::Category& log); + ReloadableXMLFile(const xercesc::DOMElement* e, logging::Category& log); virtual ~ReloadableXMLFile() { delete m_lock; @@ -103,7 +103,7 @@ namespace xmltooling { RWLock* m_lock; /** Logging object. */ - log4cpp::Category& m_log; + logging::Category& m_log; public: Lockable* lock(); diff --git a/xmltooling/util/Win32Threads.cpp b/xmltooling/util/Win32Threads.cpp index 5018485..3bf6419 100644 --- a/xmltooling/util/Win32Threads.cpp +++ b/xmltooling/util/Win32Threads.cpp @@ -21,16 +21,15 @@ */ #include "internal.h" +#include "logging.h" #include "util/Threads.h" -#include - #ifndef WIN32 # error "This implementation is for WIN32 platforms." #endif +using namespace xmltooling::logging; using namespace xmltooling; -using namespace log4cpp; using namespace std; // base error code for a routine to return on failure diff --git a/xmltooling/xmltooling-lite.vcproj b/xmltooling/xmltooling-lite.vcproj index 1d7df37..9094fa2 100644 --- a/xmltooling/xmltooling-lite.vcproj +++ b/xmltooling/xmltooling-lite.vcproj @@ -62,7 +62,7 @@ /> + + + + @@ -540,6 +548,14 @@ Name="util" > + + + + -- 2.1.4