https://bugs.documentfoundation.org/show_bug.cgi?id=158352

--- Comment #5 from jirib79 <[email protected]> ---
I created a diff with gemini-3.8-flash which works and solves the problem but
my skills are not able to fully review it.

I tested the diff:

1. system proxy (default):
   - no http proxy env vars: direct connection
   - http proxy env vars: using the proxy (as before)

2. manual proxy (explicit in LO setting):
   - no http proxy env vars: using the explicitly set proxy (fixes the issue)
   - http proxy env vars: using the explicitly set proxy (wins over env vars)

3. none proxy (in LO settigns):
   - no http proxy env vars: direct connection
   - http proxy env vars: direct connection

diff --git a/lingucomponent/Library_LanguageTool.mk
b/lingucomponent/Library_LanguageTool.mk
index aa09327cd..4f1ba58bb 100644
--- a/lingucomponent/Library_LanguageTool.mk
+++ b/lingucomponent/Library_LanguageTool.mk
@@ -29,6 +29,7 @@ $(eval $(call gb_Library_use_libraries,LanguageTool,\
        lng \
        sal \
        tl \
+       ucbhelper \
        utl \
 ))

diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
index d8a9da3fd..0ceb936a4 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.cxx
@@ -34,6 +34,7 @@
 #include <set>
 #include <string.h>

+#include <officecfg/Inet.hxx>
 #include <officecfg/Office/Linguistic.hxx>

 #include <curl/curl.h>
@@ -47,6 +48,9 @@
 #include <sal/log.hxx>
 #include <tools/color.hxx>
 #include <tools/long.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/proxydecider.hxx>
+#include <comphelper/processfactory.hxx>
 #include <framework/interaction.hxx>
 #include <com/sun/star/task/InteractionClassification.hpp>
 #include <com/sun/star/task/InteractionHandler.hpp>
@@ -126,7 +130,8 @@ enum class HTTP_METHOD

 std::string makeHttpRequest_impl(std::u16string_view aURL, HTTP_METHOD method,
                                  const OString& aPostData, curl_slist*
pHttpHeader,
-                                 tools::Long& nStatusCode, CURLcode&
eCURLCode)
+                                 tools::Long& nStatusCode, CURLcode&
eCURLCode,
+                                 const ucbhelper::InternetProxyDecider*
pProxyDecider)
 {
     struct curl_cleanup_t
     {
@@ -141,6 +146,55 @@ std::string makeHttpRequest_impl(std::u16string_view aURL,
HTTP_METHOD method,

     ::InitCurl_easy(curl.get());

+    if (pProxyDecider)
+    {
+        sal_Int32 nProxyType =
officecfg::Inet::Settings::ooInetProxyType::get().value_or(1);
+        if (nProxyType == 0) // None / Direct connection
+        {
+            (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, "");
+        }
+        else if (nProxyType == 2) // Manual proxy configuration
+        {
+            INetURLObject aUrl(aURL);
+            sal_Int32 nPort = aUrl.GetPort();
+            if (nPort == 0)
+                nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 :
80;
+            const OUString sProxy = pProxyDecider->getProxy(
+                INetURLObject::GetSchemeName(aUrl.GetProtocol()),
aUrl.GetHost(), nPort);
+            if (!sProxy.isEmpty())
+            {
+                OString const utf8Proxy = OUStringToOString(sProxy,
RTL_TEXTENCODING_UTF8);
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY,
utf8Proxy.getStr());
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXYAUTH,
CURLAUTH_ANY);
+            }
+            else
+            {
+                // Host is in LibreOffice's "No proxy for" exclusion list
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY, "");
+            }
+        }
+        else // nProxyType == 1: System proxy
+        {
+#ifdef _WIN32
+            INetURLObject aUrl(aURL);
+            sal_Int32 nPort = aUrl.GetPort();
+            if (nPort == 0)
+                nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443 :
80;
+            const OUString sProxy = pProxyDecider->getProxy(
+                INetURLObject::GetSchemeName(aUrl.GetProtocol()),
aUrl.GetHost(), nPort);
+            if (!sProxy.isEmpty())
+            {
+                OString const utf8Proxy = OUStringToOString(sProxy,
RTL_TEXTENCODING_UTF8);
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXY,
utf8Proxy.getStr());
+                (void)curl_easy_setopt(curl.get(), CURLOPT_PROXYAUTH,
CURLAUTH_ANY);
+            }
+#else
+            // On Linux/Unix, leave CURLOPT_PROXY unset so libcurl
automatically
+            // handles http_proxy, https_proxy, all_proxy, and no_proxy env
vars natively.
+#endif
+        }
+    }
+
     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);
@@ -178,7 +232,8 @@ std::string makeHttpRequest_impl(std::u16string_view aURL,
HTTP_METHOD method,
 }

 std::string makeDudenHttpRequest(std::u16string_view aURL, const OString&
aPostData,
-                                 tools::Long& nStatusCode, CURLcode&
eCURLCode)
+                                 tools::Long& nStatusCode, CURLcode&
eCURLCode,
+                                 const ucbhelper::InternetProxyDecider*
pProxyDecider)
 {
     struct curl_slist* pList = nullptr;
     OString sAccessToken
@@ -193,11 +248,12 @@ std::string makeDudenHttpRequest(std::u16string_view
aURL, const OString& aPostD
     }

     return makeHttpRequest_impl(aURL, HTTP_METHOD::HTTP_POST, aPostData,
pList, nStatusCode,
-                                eCURLCode);
+                                eCURLCode, pProxyDecider);
 }

 std::string makeHttpRequest(std::u16string_view aURL, HTTP_METHOD method,
const OString& aPostData,
-                            tools::Long& nStatusCode, CURLcode& eCURLCode)
+                            tools::Long& nStatusCode, CURLcode& eCURLCode,
+                            const ucbhelper::InternetProxyDecider*
pProxyDecider)
 {
     OString realPostData(aPostData);
     if (method == HTTP_METHOD::HTTP_POST)
@@ -209,7 +265,8 @@ std::string makeHttpRequest(std::u16string_view aURL,
HTTP_METHOD method, const
             realPostData += "&username=" + encodeTextForLT(username) +
"&apiKey=" + apiKey;
     }

-    return makeHttpRequest_impl(aURL, method, realPostData, nullptr,
nStatusCode, eCURLCode);
+    return makeHttpRequest_impl(aURL, method, realPostData, nullptr,
nStatusCode, eCURLCode,
+                                pProxyDecider);
 }

 template <typename Func>
@@ -364,8 +421,10 @@ void lclShowCURLErrorInteraction(const
css::uno::Reference<css::uno::XComponentC
 LanguageToolGrammarChecker::LanguageToolGrammarChecker(
     const css::uno::Reference<css::uno::XComponentContext>& xContext)
     : mCachedResults(10)
-    , mxContext(xContext)
+    , mxContext(xContext.is() ? xContext :
comphelper::getProcessComponentContext())
 {
+    if (mxContext.is())
+        m_xProxyDecider =
std::make_unique<ucbhelper::InternetProxyDecider>(mxContext);
 }

 LanguageToolGrammarChecker::~LanguageToolGrammarChecker() {}
@@ -514,10 +573,11 @@ ProofreadingResult SAL_CALL
LanguageToolGrammarChecker::doProofreading(
     std::string response_body;
     CURLcode eCURLCode = CURLE_OK;
     if (bDudenProtocol)
-        response_body = makeDudenHttpRequest(checkerURL, postData, http_code,
eCURLCode);
+        response_body = makeDudenHttpRequest(checkerURL, postData, http_code,
eCURLCode,
+                                             m_xProxyDecider.get());
     else
-        response_body
-            = makeHttpRequest(checkerURL, HTTP_METHOD::HTTP_POST, postData,
http_code, eCURLCode);
+        response_body = makeHttpRequest(checkerURL, HTTP_METHOD::HTTP_POST,
postData, http_code,
+                                        eCURLCode, m_xProxyDecider.get());

     if (eCURLCode != CURLE_OK)
     {
diff --git a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
index 487d6d154..66c49fe88 100644
--- a/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
+++ b/lingucomponent/source/spellcheck/languagetool/languagetoolimp.hxx
@@ -28,9 +28,15 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <linguistic/misc.hxx>
 #include <string_view>
+#include <memory>
 #include <o3tl/lru_map.hxx>
 #include <tools/long.hxx>

+namespace ucbhelper
+{
+class InternetProxyDecider;
+}
+
 class LanguageToolGrammarChecker
     : public cppu::WeakImplHelper<css::linguistic2::XProofreader,
css::lang::XInitialization,
                                   css::lang::XServiceInfo,
css::lang::XServiceDisplayName>
@@ -39,6 +45,7 @@ class LanguageToolGrammarChecker
     o3tl::lru_map<OString,
css::uno::Sequence<css::linguistic2::SingleProofreadingError>>
         mCachedResults;
     css::uno::Reference<css::uno::XComponentContext> mxContext;
+    std::unique_ptr<ucbhelper::InternetProxyDecider> m_xProxyDecider;
     OUString maLastErrorCheckerURL;
     LanguageToolGrammarChecker(const LanguageToolGrammarChecker&) = delete;
     LanguageToolGrammarChecker& operator=(const LanguageToolGrammarChecker&) =
delete;
diff --git a/svl/source/crypto/cryptosign.cxx
b/svl/source/crypto/cryptosign.cxx
index f9e23c54d..7ce772304 100644
--- a/svl/source/crypto/cryptosign.cxx
+++ b/svl/source/crypto/cryptosign.cxx
@@ -18,7 +18,10 @@
 #include <o3tl/numeric.hxx>

 #if USE_CRYPTO_NSS
+#include <officecfg/Inet.hxx>
 #include <systools/curlinit.hxx>
+#include <tools/urlobj.hxx>
+#include <ucbhelper/proxydecider.hxx>
 #endif

 #include <rtl/character.hxx>
@@ -1129,6 +1132,56 @@ bool Signing::Sign(OStringBuffer& rCMSHexBuffer)

         ::InitCurl_easy(curl);

+        {
+            sal_Int32 nProxyType =
officecfg::Inet::Settings::ooInetProxyType::get().value_or(1);
+            if (nProxyType == 0) // None / Direct connection
+            {
+                curl_easy_setopt(curl, CURLOPT_PROXY, "");
+            }
+            else if (nProxyType == 2) // Manual proxy configuration
+            {
+                ucbhelper::InternetProxyDecider
aProxyDecider(comphelper::getProcessComponentContext());
+                INetURLObject aUrl(m_aSignTSA);
+                sal_Int32 nPort = aUrl.GetPort();
+                if (nPort == 0)
+                    nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443
: 80;
+                const OUString sProxy = aProxyDecider.getProxy(
+                    INetURLObject::GetSchemeName(aUrl.GetProtocol()),
aUrl.GetHost(), nPort);
+                if (!sProxy.isEmpty())
+                {
+                    OString const utf8Proxy = OUStringToOString(sProxy,
RTL_TEXTENCODING_UTF8);
+                    curl_easy_setopt(curl, CURLOPT_PROXY, utf8Proxy.getStr());
+                    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+                }
+                else
+                {
+                    // Host is in LibreOffice's "No proxy for" exclusion list
+                    curl_easy_setopt(curl, CURLOPT_PROXY, "");
+                }
+            }
+            else // nProxyType == 1: System proxy
+            {
+#ifdef _WIN32
+                ucbhelper::InternetProxyDecider
aProxyDecider(comphelper::getProcessComponentContext());
+                INetURLObject aUrl(m_aSignTSA);
+                sal_Int32 nPort = aUrl.GetPort();
+                if (nPort == 0)
+                    nPort = (aUrl.GetProtocol() == INetProtocol::Https) ? 443
: 80;
+                const OUString sProxy = aProxyDecider.getProxy(
+                    INetURLObject::GetSchemeName(aUrl.GetProtocol()),
aUrl.GetHost(), nPort);
+                if (!sProxy.isEmpty())
+                {
+                    OString const utf8Proxy = OUStringToOString(sProxy,
RTL_TEXTENCODING_UTF8);
+                    curl_easy_setopt(curl, CURLOPT_PROXY, utf8Proxy.getStr());
+                    curl_easy_setopt(curl, CURLOPT_PROXYAUTH, CURLAUTH_ANY);
+                }
+#else
+                // On Linux/Unix, leave CURLOPT_PROXY unset so libcurl
automatically
+                // handles http_proxy, https_proxy, all_proxy, and no_proxy
env vars natively.
+#endif
+            }
+        }
+
         SAL_INFO("svl.crypto", "Setting curl to verbose: " <<
(curl_easy_setopt(curl, CURLOPT_VERBOSE, 1) == CURLE_OK ? "OK" : "FAIL"));

         if ((rc = curl_easy_setopt(curl, CURLOPT_URL,
OUStringToOString(m_aSignTSA, RTL_TEXTENCODING_UTF8).getStr())) != CURLE_OK)

--- a/tools/qa/cppunit/test_urlobj.cxx
+++ b/tools/qa/cppunit/test_urlobj.cxx
@@ -402,6 +402,19 @@
             }
         }

+        void testSchemeNameVsScheme()
+        {
+            INetURLObject aHttpUrl(u"http://api.languagetool.org/v2/check";);
+            CPPUNIT_ASSERT_EQUAL(INetProtocol::Http, aHttpUrl.GetProtocol());
+            CPPUNIT_ASSERT_EQUAL(u"http"_ustr,
INetURLObject::GetSchemeName(aHttpUrl.GetProtocol()));
+            CPPUNIT_ASSERT_EQUAL(u"http://"_ustr,
INetURLObject::GetScheme(aHttpUrl.GetProtocol()));
+
+            INetURLObject aHttpsUrl(u"https://api.languagetool.org/v2/check";);
+            CPPUNIT_ASSERT_EQUAL(INetProtocol::Https,
aHttpsUrl.GetProtocol());
+            CPPUNIT_ASSERT_EQUAL(u"https"_ustr,
INetURLObject::GetSchemeName(aHttpsUrl.GetProtocol()));
+            CPPUNIT_ASSERT_EQUAL(u"https://"_ustr,
INetURLObject::GetScheme(aHttpsUrl.GetProtocol()));
+        }
+
         // Change the following lines only, if you add, remove or rename
         // member functions of the current class,
         // because these macros are need by auto register mechanism.
@@ -420,6 +433,7 @@
         CPPUNIT_TEST( testTd146382 );
         CPPUNIT_TEST( testParseSmart );
         CPPUNIT_TEST( testIsExoticProtocol );
+        CPPUNIT_TEST( testSchemeNameVsScheme );
         CPPUNIT_TEST_SUITE_END(  );
     };                          // class createPool

-- 
You are receiving this mail because:
You are the assignee for the bug.

Reply via email to