desktop/source/app/updater.cxx                                    |    2 
 desktop/source/minidump/minidump.cxx                              |    2 
 extensions/source/update/check/download.cxx                       |    2 
 include/systools/curlinit.hxx                                     |   24 
++++++++
 lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx |   10 ---
 linguistic/source/translate.cxx                                   |    2 
 svl/source/crypto/cryptosign.cxx                                  |    2 
 ucb/source/ucp/cmis/cmis_content.cxx                              |    2 
 ucb/source/ucp/webdav-curl/CurlSession.cxx                        |   28 
----------
 vcl/source/app/svmain.cxx                                         |    2 
 10 files changed, 34 insertions(+), 42 deletions(-)

New commits:
commit f5926c8cfbd5af1fb7214428b4b03453b826f9a5
Author:     Mike Kaganski <mike.kagan...@collabora.com>
AuthorDate: Fri Nov 10 15:36:45 2023 +0300
Commit:     Mike Kaganski <mike.kagan...@collabora.com>
CommitDate: Sat Nov 11 08:42:57 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 <mike.kagan...@collabora.com>

diff --git a/desktop/source/app/updater.cxx b/desktop/source/app/updater.cxx
index 7ff6234b4555..edac2cb38350 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 9b4823777289..ab5402c0ae42 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/systools/curlinit.hxx
similarity index 56%
rename from include/curlinit.hxx
rename to include/systools/curlinit.hxx
index c80397caf466..7034534af66f 100644
--- a/include/curlinit.hxx
+++ b/include/systools/curlinit.hxx
@@ -19,6 +19,11 @@
 #include "opensslinit.hxx"
 #endif
 
+#include <rtl/string.hxx>
+#include <sal/log.hxx>
+
+#include <config_version.h>
+
 static void InitCurl_easy(CURL* const pCURL)
 {
     CURLcode rc;
@@ -44,6 +49,25 @@ static void InitCurl_easy(CURL* const pCURL)
         rc = curl_easy_setopt(pCURL, CURLOPT_REDIR_PROTOCOLS_STR, "https");
         assert(rc == CURLE_OK);
     }
+
+    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);
 }
 
 /* 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 45b4f9df6bdc..599bb01c6194 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -42,7 +42,7 @@
 #include <algorithm>
 #include <string_view>
 
-#include <curlinit.hxx>
+#include <systools/curlinit.hxx>
 
 #include <sal/log.hxx>
 #include <tools/color.hxx>
@@ -135,14 +135,6 @@ std::string makeHttpRequest_impl(std::u16string_view aURL, 
HTTP_METHOD method,
 
     ::InitCurl_easy(curl.get());
 
-    // Same useragent string as in CurlSession 
(ucp/webdav-curl/CurlSession.cxx)
-    curl_version_info_data const* const 
pVersion(curl_version_info(CURLVERSION_NOW));
-    assert(pVersion);
-    OString const useragent(
-        OString::Concat("LibreOffice " LIBO_VERSION_DOTTED " 
denylistedbackend/")
-        + pVersion->version + " " + pVersion->ssl_version);
-    (void)curl_easy_setopt(curl.get(), CURLOPT_USERAGENT, useragent.getStr());
-
     OString aURL8 = OUStringToOString(aURL, RTL_TEXTENCODING_UTF8);
     (void)curl_easy_setopt(curl.get(), CURLOPT_HTTPHEADER, pHttpHeader);
     (void)curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L);
diff --git a/linguistic/source/translate.cxx b/linguistic/source/translate.cxx
index 719cfb0374c9..8c3410777003 100644
--- a/linguistic/source/translate.cxx
+++ b/linguistic/source/translate.cxx
@@ -13,7 +13,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 378a62f1ea56..a234afccbc27 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 b8ef0b77f734..1a499e1bdb3c 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/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index cc37f0b4da77..c07919b6d4b7 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -36,7 +36,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>
@@ -613,33 +613,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 3458e6df2a29..71dcca106a57 100644
--- a/vcl/source/app/svmain.cxx
+++ b/vcl/source/app/svmain.cxx
@@ -82,7 +82,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>

Reply via email to