external/curl/UnpackedTarball_curl.mk      |    1 
 external/curl/statushack.patch.1           |   22 ++++++++++++
 ucb/source/ucp/webdav-curl/CurlSession.cxx |   50 ++++++++++++++++++++++++++++-
 3 files changed, 72 insertions(+), 1 deletion(-)

New commits:
commit 275b318cd55720b1106965c31e8d60619ae50ec9
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Mon Oct 10 15:41:32 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Oct 19 14:34:23 2022 +0200

    statushack
    
    Change-Id: Idbfacc858dd0180c40e86bbd6fc9b0084bd9ed2d

diff --git a/external/curl/UnpackedTarball_curl.mk 
b/external/curl/UnpackedTarball_curl.mk
index 76c8cc34de38..fae8a67d2bcd 100644
--- a/external/curl/UnpackedTarball_curl.mk
+++ b/external/curl/UnpackedTarball_curl.mk
@@ -23,6 +23,7 @@ $(eval $(call gb_UnpackedTarball_add_patches,curl,\
        external/curl/curl-msvc-disable-protocols.patch.1 \
        external/curl/curl-7.26.0_win-proxy.patch \
        external/curl/zlib.patch.0 \
+       external/curl/statushack.patch.1 \
 ))
 
 ifeq ($(SYSTEM_NSS),)
diff --git a/external/curl/statushack.patch.1 b/external/curl/statushack.patch.1
new file mode 100644
index 000000000000..3d55b896310b
--- /dev/null
+++ b/external/curl/statushack.patch.1
@@ -0,0 +1,22 @@
+--- curl/lib/http.c.orig       2022-10-10 14:31:12.867898354 +0200
++++ curl/lib/http.c    2022-10-10 14:31:24.528892930 +0200
+@@ -4213,7 +4213,7 @@
+                     &separator,
+                     &k->httpcode,
+                     &digit4);
+-
++        if(k->httpcode == 401) { k->httpcode = 403; }
+         if(nc == 1 && httpversion_major >= 2 &&
+            2 == sscanf(HEADER1, " HTTP/%1[23] %d", twoorthree, &k->httpcode)) 
{
+           conn->httpversion = 0;
+--- curl/lib/http.c.orig       2022-10-10 14:54:55.991225710 +0200
++++ curl/lib/http.c    2022-10-10 14:55:16.836215787 +0200
+@@ -3576,7 +3576,7 @@
+     if(data->set.get_filetime)
+       data->info.filetime = k->timeofdoc;
+   }
+-  else if((checkprefix("WWW-Authenticate:", headp) &&
++  else if((0 && checkprefix("WWW-Authenticate:", headp) &&
+            (401 == k->httpcode)) ||
+           (checkprefix("Proxy-authenticate:", headp) &&
+            (407 == k->httpcode))) {
diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index 1ae16baa13b4..8e9c7acafeef 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -340,6 +340,7 @@ static int debug_callback(CURL* handle, curl_infotype type, 
char* data, size_t s
         {
             // unlike IN, this is all headers in one call
             OString tmp(data, size);
+#if 0
             sal_Int32 const start(tmp.indexOf("Authorization: "));
             if (start != -1)
             {
@@ -349,6 +350,7 @@ static int debug_callback(CURL* handle, curl_infotype type, 
char* data, size_t s
                 tmp = tmp.replaceAt(start + len, end - start - len,
                                     OString::number(end - start - len) + " 
bytes redacted");
             }
+#endif
             SAL_INFO("ucb.ucp.webdav.curl", "CURLINFO_HEADER_OUT: " << handle 
<< ": " << tmp);
             return 0;
         }
@@ -1425,7 +1427,7 @@ auto CurlProcessor::ProcessRequest(
                             ProcessHeaders(headers.HeaderFields.back().first));
                         // X-MSDAVEXT_Error see [MS-WEBDAVE] 2.2.3.1.9
                         auto const it(headerMap.find("x-msdavext_error"));
-                        if (it == headerMap.end() || 
!it->second.startsWith("917656;"))
+                        if (false && (it == headerMap.end() || 
!it->second.startsWith("917656;")))
                         {
                             break;
                         }
@@ -1489,6 +1491,7 @@ auto CurlProcessor::ProcessRequest(
                                                         ? 
CURLINFO_HTTPAUTH_AVAIL
                                                         : 
CURLINFO_PROXYAUTH_AVAIL,
                                                     &authAvail);
+                            authAvail = 0;
                             assert(rc == CURLE_OK);
                             (void)rc;
                             if (statusCode == SC_FORBIDDEN)
commit fa5feda2f891651933703e029dcc757e47a6801f
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Oct 19 14:30:55 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Oct 19 14:34:18 2022 +0200

    ucb: webdav-curl: try to share DNS and TLS data as well
    
    Not necessary but probably faster.
    
    Documentation says that CURL_LOCK_DATA_CONNECT isn't safe in a multi
    threaded program.
    
    Change-Id: Iae79c01330b48f443b94abf6101a50559cb46189

diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index 800cb6719b04..1ae16baa13b4 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -75,6 +75,10 @@ struct Init
         assert(sh == CURLSHE_OK); // might fail but can't handle error here
         sh = curl_share_setopt(pShare.get(), CURLSHOPT_SHARE, 
CURL_LOCK_DATA_COOKIE);
         assert(sh == CURLSHE_OK); // might fail but can't handle error here
+        sh = curl_share_setopt(pShare.get(), CURLSHOPT_SHARE, 
CURL_LOCK_DATA_DNS);
+        assert(sh == CURLSHE_OK); // might fail but can't handle error here
+        sh = curl_share_setopt(pShare.get(), CURLSHOPT_SHARE, 
CURL_LOCK_DATA_SSL_SESSION);
+        assert(sh == CURLSHE_OK); // might fail but can't handle error here
     }
     // do not call curl_global_cleanup() - this is not the only client of curl
 };
commit 7e8b26560020ae2819cfd621b5790e51083b7e92
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Wed Oct 19 14:27:04 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Wed Oct 19 14:34:18 2022 +0200

    ucb: webdav-curl: add a shared cookie store
    
    Change-Id: I8796aa7de6335c57818aa570a55fdc64d85bd9f9

diff --git a/ucb/source/ucp/webdav-curl/CurlSession.cxx 
b/ucb/source/ucp/webdav-curl/CurlSession.cxx
index f986896c7e57..800cb6719b04 100644
--- a/ucb/source/ucp/webdav-curl/CurlSession.cxx
+++ b/ucb/source/ucp/webdav-curl/CurlSession.cxx
@@ -44,6 +44,9 @@ using namespace ::com::sun::star;
 
 namespace
 {
+static void lock_cb(CURL*, curl_lock_data, curl_lock_access, void*);
+static void unlock_cb(CURL*, curl_lock_data, curl_lock_access, void*);
+
 /// globals container
 struct Init
 {
@@ -51,17 +54,55 @@ struct Init
     ///       so don't call LockStore with m_Mutex held to prevent deadlock.
     ::http_dav_ucp::SerfLockStore LockStore;
 
+    /// libcurl shared data - to store cookies beyond one connection
+    ::std::mutex ShareLock[CURL_LOCK_DATA_LAST];
+    ::std::unique_ptr<CURLSH, http_dav_ucp::deleter_from_fn<CURLSH, 
curl_share_cleanup>> pShare;
+
     Init()
     {
         if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK)
         {
             assert(!"curl_global_init failed");
         }
+        pShare.reset(curl_share_init());
+        if (!pShare)
+        {
+            assert(!"curl_share_init failed");
+        }
+        CURLSHcode sh = curl_share_setopt(pShare.get(), CURLSHOPT_LOCKFUNC, 
lock_cb);
+        assert(sh == CURLSHE_OK); // might fail but can't handle error here
+        sh = curl_share_setopt(pShare.get(), CURLSHOPT_UNLOCKFUNC, unlock_cb);
+        assert(sh == CURLSHE_OK); // might fail but can't handle error here
+        sh = curl_share_setopt(pShare.get(), CURLSHOPT_SHARE, 
CURL_LOCK_DATA_COOKIE);
+        assert(sh == CURLSHE_OK); // might fail but can't handle error here
     }
     // do not call curl_global_cleanup() - this is not the only client of curl
 };
 Init g_Init;
 
+// global callbacks
+
+static void lock_cb(CURL* /*handle*/, curl_lock_data const data, 
curl_lock_access /*access*/,
+                    void* /*userptr*/)
+{
+    assert(0 <= data && data < CURL_LOCK_DATA_LAST);
+    try
+    {
+        g_Init.ShareLock[data].lock();
+    }
+    catch (std::exception const&)
+    {
+        ::std::abort();
+    }
+}
+
+static void unlock_cb(CURL* /*handle*/, curl_lock_data const data, 
curl_lock_access /*access*/,
+                      void* /*userptr*/)
+{
+    assert(0 <= data && data < CURL_LOCK_DATA_LAST);
+    g_Init.ShareLock[data].unlock();
+}
+
 struct ResponseHeaders
 {
     ::std::vector<::std::pair<::std::vector<OString>, ::std::optional<long>>> 
HeaderFields;

Reply via email to