desktop/source/app/updater.cxx | 2 desktop/source/minidump/minidump.cxx | 2 extensions/source/update/check/download.cxx | 2 include/curlinit.hxx | 38 ------ include/systools/curlinit.hxx | 62 ++++++++++ lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx | 5 linguistic/source/translate.cxx | 2 svl/source/crypto/cryptosign.cxx | 2 ucb/source/ucp/cmis/cmis_content.cxx | 2 ucb/source/ucp/ftp/ftploaderthread.cxx | 2 ucb/source/ucp/webdav-curl/CurlSession.cxx | 28 ---- vcl/source/app/svmain.cxx | 2 12 files changed, 76 insertions(+), 73 deletions(-)
New commits: commit 04b49e8dd5bbb5a9c308f2b517e0319751e1f077 Author: Mike Kaganski <[email protected]> AuthorDate: Fri Nov 10 15:36:45 2023 +0300 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Nov 14 16:31:20 2023 +0100 Move user agent initialization to InitCurl_easy Places that didn't initialize it previously, would benefit automatically Change-Id: I2f1ff25fc58d9378462072bc92d7b37be2370fc8 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159299 Tested-by: Jenkins Reviewed-by: Mike Kaganski <[email protected]> (cherry picked from commit f5926c8cfbd5af1fb7214428b4b03453b826f9a5) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/159418 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Miklos Vajna <[email protected]> diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx index 4e4d2cda413f..ac2baf433c15 100644 --- a/desktop/source/app/updater.cxx +++ b/desktop/source/app/updater.cxx @@ -38,7 +38,7 @@ #include <orcus/config.hpp> #include <orcus/pstring.hpp> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #include <comphelper/hash.hxx> #include <com/sun/star/container/XNameAccess.hpp> diff --git a/desktop/source/minidump/minidump.cxx b/desktop/source/minidump/minidump.cxx index 7fbb0884987d..0a31fff6f285 100644 --- a/desktop/source/minidump/minidump.cxx +++ b/desktop/source/minidump/minidump.cxx @@ -17,7 +17,7 @@ #include <curl/curl.h> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #ifdef _WIN32 #include <memory> diff --git a/extensions/source/update/check/download.cxx b/extensions/source/update/check/download.cxx index cdbbe2c32734..aba9792205f0 100644 --- a/extensions/source/update/check/download.cxx +++ b/extensions/source/update/check/download.cxx @@ -23,7 +23,7 @@ #include <curl/curl.h> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #include <o3tl/string_view.hxx> #include <osl/diagnose.h> diff --git a/include/curlinit.hxx b/include/curlinit.hxx deleted file mode 100644 index 18888cf766f9..000000000000 --- a/include/curlinit.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - */ - -#pragma once - -#include <curl/curl.h> - -#if defined(LINUX) && !defined(SYSTEM_CURL) -#include <com/sun/star/uno/RuntimeException.hpp> - -#include "opensslinit.hxx" - -static void InitCurl_easy(CURL* const pCURL) -{ - char const* const path = GetCABundleFile(); - auto rc = curl_easy_setopt(pCURL, CURLOPT_CAINFO, path); - if (rc != CURLE_OK) // only if OOM? - { - throw css::uno::RuntimeException("CURLOPT_CAINFO failed"); - } -} - -#else - -static void InitCurl_easy(CURL* const) -{ - // these don't use OpenSSL so CAs work out of the box -} - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/systools/curlinit.hxx b/include/systools/curlinit.hxx new file mode 100644 index 000000000000..b47fa4e51bb6 --- /dev/null +++ b/include/systools/curlinit.hxx @@ -0,0 +1,62 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <curl/curl.h> + +#if defined(LINUX) && !defined(SYSTEM_CURL) +#include <com/sun/star/uno/RuntimeException.hpp> + +#include "opensslinit.hxx" + +#include <rtl/string.hxx> +#include <sal/log.hxx> + +#include <config_version.h> + +static void InitCurl_easy(CURL* const pCURL) +{ + char const* const path = GetCABundleFile(); + auto rc = curl_easy_setopt(pCURL, CURLOPT_CAINFO, path); + if (rc != CURLE_OK) // only if OOM? + { + throw css::uno::RuntimeException("CURLOPT_CAINFO failed"); + } + + curl_version_info_data const* const pVersion(curl_version_info(CURLVERSION_NOW)); + assert(pVersion); + SAL_INFO("ucb.ucp.webdav.curl", + "curl version: " << pVersion->version << " " << pVersion->host + << " features: " << ::std::hex << pVersion->features << " ssl: " + << pVersion->ssl_version << " libz: " << pVersion->libz_version); + // Make sure a User-Agent header is always included, as at least + // en.wikipedia.org:80 forces back 403 "Scripts should use an informative + // User-Agent string with contact information, or they may be IP-blocked + // without notice" otherwise: + OString const useragent( + OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " denylistedbackend/") + + pVersion->version + " " + pVersion->ssl_version); + // looks like an explicit "User-Agent" header in CURLOPT_HTTPHEADER + // will override CURLOPT_USERAGENT, see Curl_http_useragent(), so no need + // to check anything here + rc = curl_easy_setopt(pCURL, CURLOPT_USERAGENT, useragent.getStr()); + assert(rc == CURLE_OK); +} + +#else + +static void InitCurl_easy(CURL* const) +{ + // these don't use OpenSSL so CAs work out of the box +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/include/opensslinit.hxx b/include/systools/opensslinit.hxx similarity index 100% rename from include/opensslinit.hxx rename to include/systools/opensslinit.hxx diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx index 8ab76f40b3b9..e568aa6ea35a 100644 --- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx +++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx @@ -35,8 +35,11 @@ #include <boost/property_tree/json_parser.hpp> #include <algorithm> #include <string_view> -#include <curlinit.hxx> #include <svtools/languagetoolcfg.hxx> + +#include <systools/curlinit.hxx> + +#include <sal/log.hxx> #include <tools/color.hxx> #include <tools/long.hxx> #include <com/sun/star/uno/Any.hxx> diff --git a/linguistic/source/translate.cxx b/linguistic/source/translate.cxx index fdd95fca2988..6abaff42f0dc 100644 --- a/linguistic/source/translate.cxx +++ b/linguistic/source/translate.cxx @@ -4,7 +4,7 @@ #include <rtl/string.h> #include <boost/property_tree/ptree.hpp> #include <boost/property_tree/json_parser.hpp> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #include <vcl/htmltransferable.hxx> #include <tools/long.hxx> diff --git a/svl/source/crypto/cryptosign.cxx b/svl/source/crypto/cryptosign.cxx index b5e2eb0155e1..638bf9aa51d1 100644 --- a/svl/source/crypto/cryptosign.cxx +++ b/svl/source/crypto/cryptosign.cxx @@ -16,7 +16,7 @@ #include <config_crypto.h> #if USE_CRYPTO_NSS -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #endif #include <rtl/character.hxx> diff --git a/ucb/source/ucp/cmis/cmis_content.cxx b/ucb/source/ucp/cmis/cmis_content.cxx index 2ec1c336a706..0301d83707d6 100644 --- a/ucb/source/ucp/cmis/cmis_content.cxx +++ b/ucb/source/ucp/cmis/cmis_content.cxx @@ -56,7 +56,7 @@ #include <ucbhelper/proxydecider.hxx> #include <ucbhelper/macros.hxx> #include <sax/tools/converter.hxx> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #include <utility> diff --git a/ucb/source/ucp/ftp/ftploaderthread.cxx b/ucb/source/ucp/ftp/ftploaderthread.cxx index 91130fc1bc9c..414cfe78f508 100644 --- a/ucb/source/ucp/ftp/ftploaderthread.cxx +++ b/ucb/source/ucp/ftp/ftploaderthread.cxx @@ -25,7 +25,7 @@ #include "ftploaderthread.hxx" #include "curl.hxx" -#include <curlinit.hxx> +#include <systools/curlinit.hxx> using namespace ftp; diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx b/ucb/source/ucp/webdav-curl/CurlSession.cxx index 9ee1886803fa..48fcc9bfba7d 100644 --- a/ucb/source/ucp/webdav-curl/CurlSession.cxx +++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx @@ -35,7 +35,7 @@ #include <rtl/uri.hxx> #include <rtl/strbuf.hxx> #include <rtl/ustrbuf.hxx> -#include <curlinit.hxx> +#include <systools/curlinit.hxx> #include <config_version.h> #include <map> @@ -612,33 +612,9 @@ CurlSession::CurlSession(uno::Reference<uno::XComponentContext> xContext, throw DAVException(DAVException::DAV_SESSION_CREATE, ConnectionEndPointString(m_URI.GetHost(), m_URI.GetPort())); } - curl_version_info_data const* const pVersion(curl_version_info(CURLVERSION_NOW)); - assert(pVersion); - SAL_INFO("ucb.ucp.webdav.curl", - "curl version: " << pVersion->version << " " << pVersion->host - << " features: " << ::std::hex << pVersion->features << " ssl: " - << pVersion->ssl_version << " libz: " << pVersion->libz_version); - // Make sure a User-Agent header is always included, as at least - // en.wikipedia.org:80 forces back 403 "Scripts should use an informative - // User-Agent string with contact information, or they may be IP-blocked - // without notice" otherwise: - OString const useragent( - OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " denylistedbackend/") - + ::std::string_view(pVersion->version, strlen(pVersion->version)) + " " - + pVersion->ssl_version); - // looks like an explicit "User-Agent" header in CURLOPT_HTTPHEADER - // will override CURLOPT_USERAGENT, see Curl_http_useragent(), so no need - // to check anything here - auto rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_USERAGENT, useragent.getStr()); - if (rc != CURLE_OK) - { - SAL_WARN("ucb.ucp.webdav.curl", "CURLOPT_USERAGENT failed: " << GetErrorString(rc)); - throw DAVException(DAVException::DAV_SESSION_CREATE, - ConnectionEndPointString(m_URI.GetHost(), m_URI.GetPort())); - } m_ErrorBuffer[0] = '\0'; // this supposedly gives the highest quality error reporting - rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_ERRORBUFFER, m_ErrorBuffer); + auto rc = curl_easy_setopt(m_pCurl.get(), CURLOPT_ERRORBUFFER, m_ErrorBuffer); assert(rc == CURLE_OK); #if 1 // just for debugging... diff --git a/vcl/source/app/svmain.cxx b/vcl/source/app/svmain.cxx index 0f9fcc17a49b..8cc08cf4c235 100644 --- a/vcl/source/app/svmain.cxx +++ b/vcl/source/app/svmain.cxx @@ -81,7 +81,7 @@ #include <config_features.h> #include <config_feature_opencl.h> -#include <opensslinit.hxx> +#include <systools/opensslinit.hxx> #include <osl/process.h> #include <com/sun/star/lang/XComponent.hpp>
