Backport libcurl-based Xerces net access.
Convert logging to log4shib via compile time switch.
/* Define if C++ compiler supports covariant virtual methods. */
#define HAVE_COVARIANT_RETURNS 1
-/* Define to 1 if you have the <dlfcn.h> header file.
-#define HAVE_DLFCN_H 1
-*/
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
/* Define to 1 if you have the `gmtime_r' function. */
/* #undef HAVE_GMTIME_R */
specialization. */
#define HAVE_GOOD_STL 1
-/* Define to 1 if you have the <inttypes.h> header file.
-#define HAVE_INTTYPES_H 1
-*/
+/* Define to 1 if you have the <inttypes.h> 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
/* Define to 1 if you have the `strdup' function. */
#define HAVE_STRDUP 1
-/* Define to 1 if you have the <strings.h> header file.
-#define HAVE_STRINGS_H 1
-*/
+/* Define to 1 if you have the <strings.h> header file. */
+/* #undef HAVE_STRINGS_H */
/* Define to 1 if you have the <string.h> header file. */
#define HAVE_STRING_H 1
/* Define to 1 if you have the <sys/types.h> header file. */
#define HAVE_SYS_TYPES_H 1
-/* Define to 1 if you have the <unistd.h> header file.
-#define HAVE_UNISTD_H 1
-*/
+/* Define to 1 if you have the <unistd.h> header file. */
+/* #undef HAVE_UNISTD_H */
/* Name of package */
#define PACKAGE "xmltooling"
[ 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.hh>],
+ [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.hh>],
- [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.hh>],
+ [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,
#include "exceptions.h"
#include <algorithm>
-#include <log4cpp/Category.hh>
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));
#ifndef __xmltooling_abstractxmlobj_h__
#define __xmltooling_abstractxmlobj_h__
+#include <xmltooling/logging.h>
#include <xmltooling/XMLObject.h>
#include <xmltooling/util/DateTime.h>
-#include <log4cpp/Category.hh>
-
#if defined (_MSC_VER)
#pragma warning( push )
#pragma warning( disable : 4250 4251 )
/**
* Logging object.
*/
- log4cpp::Category& m_log;
+ logging::Category& m_log;
/**
* Stores off xsi:schemaLocation attribute.
*/
#include "internal.h"
+#include "logging.h"
#include "XMLObjectBuilder.h"
#include "util/NDC.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
-
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
map<QName,XMLObjectBuilder*> XMLObjectBuilder::m_map;
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "XMLToolingConfig.h"
#include "encryption/Encryption.h"
#include "encryption/Encrypter.h"
#endif
#include <stdexcept>
-#include <log4cpp/Category.hh>
-#include <log4cpp/PropertyConfigurator.hh>
-#include <log4cpp/OstreamAppender.hh>
+#if defined(XMLTOOLING_LOG4SHIB)
+# include <log4shib/PropertyConfigurator.hh>
+# include <log4shib/OstreamAppender.hh>
+#elif defined(XMLTOOLING_LOG4CPP)
+# include <log4cpp/PropertyConfigurator.hh>
+# include <log4cpp/OstreamAppender.hh>
+#endif
#include <xercesc/util/PlatformUtils.hpp>
#ifndef XMLTOOLING_NO_XMLSEC
# include <curl/curl.h>
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);
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
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 */
*/
#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 <log4cpp/Category.hh>
#include <xsec/enc/XSECCryptoException.hpp>
#include <xsec/framework/XSECException.hpp>
#include <xsec/framework/XSECAlgorithmMapper.hpp>
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());
}
}
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());
}
}
}
}
catch(DecryptionException& ex) {
- log4cpp::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what());
+ logging::Category::getInstance(XMLTOOLING_LOGCAT".Decrypter").warn(ex.what());
}
}
*/
#include "internal.h"
+#include "logging.h"
#include "util/NDC.h"
#include "util/StorageService.h"
#include "util/Threads.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "impl/UnknownElement.h"
#include "util/NDC.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/framework/Wrapper4InputSource.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
#ifndef XMLTOOLING_NO_XMLSEC
using xmlsignature::Signature;
--- /dev/null
+/*
+ * 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 <xmltooling/base.h>
+
+#if defined(XMLTOOLING_LOG4SHIB)
+# include <log4shib/Category.hh>
+# include <log4shib/CategoryStream.hh>
+namespace xmltooling {
+ namespace logging = log4shib;
+};
+#elif defined(XMLTOOLING_LOG4CPP)
+# include <log4cpp/Category.hh>
+# include <log4cpp/CategoryStream.hh>
+namespace xmltooling {
+ namespace logging = log4cpp;
+};
+#else
+# error "Supported logging library not available."
+#endif
+
+#endif /* __xmltooling_logging_h__ */
*/
#include "internal.h"
+#include "logging.h"
#include "security/AbstractPKIXTrustEngine.h"
#include "signature/KeyInfo.h"
-#include <log4cpp/Category.hh>
#include <openssl/x509_vfy.h>
#include <openssl/x509v3.h>
#include <xmltooling/security/CredentialCriteria.h>
#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
*/
#include "internal.h"
+#include "logging.h"
#include "XMLToolingConfig.h"
#include "security/CredentialResolver.h"
#include "util/NDC.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "security/ChainingTrustEngine.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
*/
#include "internal.h"
+#include "logging.h"
#include "security/Credential.h"
#include "security/CredentialCriteria.h"
#include "security/KeyInfoResolver.h"
-#include <log4cpp/Category.hh>
#include <openssl/dsa.h>
#include <openssl/rsa.h>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp>
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;
}
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;
}
*/
#include "internal.h"
+#include "logging.h"
#include "security/Credential.h"
#include "security/CredentialCriteria.h"
#include "security/CredentialResolver.h"
#include "signature/SignatureValidator.h"
#include "util/NDC.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
*/
#include "internal.h"
+#include "logging.h"
#include "security/BasicX509Credential.h"
#include "security/CredentialCriteria.h"
#include "security/CredentialResolver.h"
#include <sys/types.h>
#include <sys/stat.h>
#include <openssl/pkcs12.h>
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoX509.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyRSA.hpp>
#include <xsec/enc/OpenSSL/OpenSSLCryptoKeyDSA.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
// OpenSSL password callback...
*/
#include "internal.h"
+#include "logging.h"
#include "security/BasicX509Credential.h"
#include "security/KeyInfoCredentialContext.h"
#include "security/KeyInfoResolver.h"
#include "util/XMLConstants.h"
#include "validation/ValidatorSuite.h"
-#include <log4cpp/Category.hh>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xsec/dsig/DSIGKeyInfoX509.hpp>
#include <xsec/enc/XSECKeyInfoResolverDefault.hpp>
#include <xsec/framework/XSECException.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "impl/UnknownElement.h"
#include "security/Credential.h"
#include "signature/KeyInfo.h"
#include "util/XMLConstants.h"
#include "util/XMLHelper.h"
-#include <log4cpp/Category.hh>
#include <xercesc/framework/MemBufInputSource.hpp>
#include <xercesc/framework/Wrapper4InputSource.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xsec/transformers/TXFMOutputFile.hpp>
using namespace xmlsignature;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
using xmlconstants::XMLSIG_NS;
using xmlconstants::XMLSIG_PREFIX;
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "security/CredentialCriteria.h"
#include "security/OpenSSLTrustEngine.h"
#include "security/OpenSSLCredential.h"
#include <list>
#include <curl/curl.h>
-#include <log4cpp/Category.hh>
#include <openssl/x509_vfy.h>
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
namespace xmltooling {
#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 <sstream>
-#include <log4cpp/Category.hh>
using namespace soap11;
+using namespace xmltooling::logging;
using namespace xmltooling;
-using namespace log4cpp;
using namespace std;
SOAPClient::~SOAPClient()
--- /dev/null
+/*
+ * 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 <xercesc/util/XMLUniDefs.hpp>
+#include <xercesc/util/XMLUni.hpp>
+#include <xercesc/util/XMLString.hpp>
+#include <xercesc/util/XMLExceptMsgs.hpp>
+#include <xmltooling/util/CurlURLInputStream.hpp>
+#include <xmltooling/util/CurlNetAccessor.hpp>
+
+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;
+}
+
--- /dev/null
+/*
+ * 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 <xmltooling/base.h>
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/util/XMLURL.hpp>
+#include <xercesc/util/BinInputStream.hpp>
+#include <xercesc/util/XMLNetAccessor.hpp>
+
+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
+
+
--- /dev/null
+/*
+ * 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+//#include <sys/types.h>
+//#include <sys/time.h>
+
+#include <xercesc/util/XercesDefs.hpp>
+#include <xercesc/util/XMLNetAccessor.hpp>
+#include <xercesc/util/XMLString.hpp>
+#include <xercesc/util/XMLExceptMsgs.hpp>
+#include <xercesc/util/Janitor.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
+#include <xercesc/util/TransService.hpp>
+#include <xercesc/util/TranscodingException.hpp>
+#include <xercesc/util/PlatformUtils.hpp>
+
+#include <xmltooling/util/CurlURLInputStream.hpp>
+
+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;
+}
+
--- /dev/null
+/*
+ * 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 <xmltooling/base.h>
+
+#include <curl/curl.h>
+#include <curl/multi.h>
+#include <curl/easy.h>
+
+#include <xercesc/util/XMLURL.hpp>
+#include <xercesc/util/XMLExceptMsgs.hpp>
+#include <xercesc/util/Janitor.hpp>
+#include <xercesc/util/BinInputStream.hpp>
+#include <xercesc/util/XMLNetAccessor.hpp>
+
+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<char> 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
+
*/
#include "internal.h"
+#include "logging.h"
#include "util/NDC.h"
-#include <log4cpp/NDC.hh>
+#if defined(XMLTOOLING_LOG4SHIB)
+# include <log4shib/NDC.hh>
+#elif defined(XMLTOOLING_LOG4CPP)
+# include <log4cpp/NDC.hh>
+#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();
}
#include "internal.h"
#include "exceptions.h"
+#include "logging.h"
#include "util/NDC.h"
#include "util/ParserPool.h"
#include "util/XMLHelper.h"
#include <functional>
#include <sys/types.h>
#include <sys/stat.h>
-#include <log4cpp/Category.hh>
#include <xercesc/util/PlatformUtils.hpp>
#include <xercesc/util/XMLUniDefs.hpp>
#include <xercesc/sax/SAXException.hpp>
#include <xercesc/framework/LocalFileInputSource.hpp>
#include <xercesc/framework/Wrapper4InputSource.hpp>
+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()) {}
#include <xercesc/framework/URLInputSource.hpp>\r
#include <xercesc/util/XMLUniDefs.hpp>\r
\r
+using namespace xmltooling::logging;\r
using namespace xmltooling;\r
-using namespace log4cpp;\r
using namespace std;\r
\r
static const XMLCh uri[] = UNICODE_LITERAL_3(u,r,i);\r
#ifndef __xmltooling_reloadable_h__
#define __xmltooling_reloadable_h__
+#include <xmltooling/logging.h>
#include <xmltooling/Lockable.h>
#include <xmltooling/util/Threads.h>
#include <ctime>
#include <string>
#include <xercesc/dom/DOM.hpp>
-#include <log4cpp/Category.hh>
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;
RWLock* m_lock;
/** Logging object. */
- log4cpp::Category& m_log;
+ logging::Category& m_log;
public:
Lockable* lock();
*/
#include "internal.h"
+#include "logging.h"
#include "util/Threads.h"
-#include <log4cpp/Category.hh>
-
#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
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4cppD.lib xerces-c_2D.lib"\r
+ AdditionalDependencies="wsock32.lib log4shib1D.lib xerces-c_2D.lib"\r
OutputFile="$(OutDir)\$(ProjectName)1_0D.dll"\r
LinkIncremental="2"\r
GenerateDebugInformation="true"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4cpp.lib xerces-c_2.lib"\r
+ AdditionalDependencies="wsock32.lib log4shib1.lib xerces-c_2.lib"\r
OutputFile="$(OutDir)\$(ProjectName)1_0.dll"\r
GenerateDebugInformation="true"\r
SubSystem="2"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4cppD.lib xerces-c_2D.lib xsec_1D.lib libeay32_0_9_8D.lib ssleay32_0_9_8D.lib libcurld_imp.lib"\r
+ AdditionalDependencies="wsock32.lib log4shib1D.lib xerces-c_2D.lib xsec_1D.lib libeay32_0_9_8D.lib ssleay32_0_9_8D.lib libcurld_imp.lib"\r
OutputFile="$(OutDir)\$(ProjectName)1_0D.dll"\r
LinkIncremental="2"\r
GenerateDebugInformation="true"\r
/>\r
<Tool\r
Name="VCLinkerTool"\r
- AdditionalDependencies="wsock32.lib log4cpp.lib xerces-c_2.lib xsec_1.lib libeay32_0_9_8.lib ssleay32_0_9_8.lib libcurl_imp.lib"\r
+ AdditionalDependencies="wsock32.lib log4shib1.lib xerces-c_2.lib xsec_1.lib libeay32_0_9_8.lib ssleay32_0_9_8.lib libcurl_imp.lib"\r
OutputFile="$(OutDir)\$(ProjectName)1_0.dll"\r
GenerateDebugInformation="true"\r
SubSystem="2"\r
Name="util"\r
>\r
<File\r
+ RelativePath=".\util\CurlNetAccessor.cpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\util\CurlURLInputStream.cpp"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\DateTime.cpp"\r
>\r
</File>\r
Name="util"\r
>\r
<File\r
+ RelativePath=".\util\CurlNetAccessor.hpp"\r
+ >\r
+ </File>\r
+ <File\r
+ RelativePath=".\util\CurlURLInputStream.hpp"\r
+ >\r
+ </File>\r
+ <File\r
RelativePath=".\util\DateTime.h"\r
>\r
</File>\r