Title: [226656] trunk/Source/WebCore
Revision
226656
Author
[email protected]
Date
2018-01-09 13:15:32 -0800 (Tue, 09 Jan 2018)

Log Message

[Curl] Move FormData related tasks into new CurlFormDataStream class.
https://bugs.webkit.org/show_bug.cgi?id=181106

Patch by Basuke Suzuki <[email protected]> on 2018-01-09
Reviewed by Alex Christensen.

No new tests because no behavior change.

* platform/Curl.cmake:
* platform/network/curl/CurlFormDataStream.cpp: Added.
(WebCore::CurlFormDataStream::CurlFormDataStream):
(WebCore::CurlFormDataStream::~CurlFormDataStream):
(WebCore::CurlFormDataStream::clean):
(WebCore::CurlFormDataStream::shouldUseChunkTransfer):
(WebCore::CurlFormDataStream::totalSize):
(WebCore::CurlFormDataStream::computeContentLength):
(WebCore::CurlFormDataStream::read):
(WebCore::CurlFormDataStream::readFromFile):
(WebCore::CurlFormDataStream::readFromData):
* platform/network/curl/CurlFormDataStream.h: Renamed from Source/WebCore/platform/network/curl/FormDataStreamCurl.h.
(WebCore::CurlFormDataStream::elementSize):
(WebCore::CurlFormDataStream::totalReadSize):
* platform/network/curl/CurlRequest.cpp:
(WebCore::CurlRequest::CurlRequest):
(WebCore::CurlRequest::willSendData):
(WebCore::CurlRequest::finalizeTransfer):
(WebCore::CurlRequest::setupPUT):
(WebCore::CurlRequest::setupPOST):
(WebCore::CurlRequest::setupSendData):
(WebCore::CurlRequest::resolveBlobReferences): Deleted.
(WebCore::CurlRequest::setupFormData): Deleted.
* platform/network/curl/CurlRequest.h:
* platform/network/curl/FormDataStreamCurl.cpp: Removed.

Modified Paths

Added Paths

Removed Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (226655 => 226656)


--- trunk/Source/WebCore/ChangeLog	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/ChangeLog	2018-01-09 21:15:32 UTC (rev 226656)
@@ -1,3 +1,38 @@
+2018-01-09  Basuke Suzuki  <[email protected]>
+
+        [Curl] Move FormData related tasks into new CurlFormDataStream class.
+        https://bugs.webkit.org/show_bug.cgi?id=181106
+
+        Reviewed by Alex Christensen.
+
+        No new tests because no behavior change.
+
+        * platform/Curl.cmake:
+        * platform/network/curl/CurlFormDataStream.cpp: Added.
+        (WebCore::CurlFormDataStream::CurlFormDataStream):
+        (WebCore::CurlFormDataStream::~CurlFormDataStream):
+        (WebCore::CurlFormDataStream::clean):
+        (WebCore::CurlFormDataStream::shouldUseChunkTransfer):
+        (WebCore::CurlFormDataStream::totalSize):
+        (WebCore::CurlFormDataStream::computeContentLength):
+        (WebCore::CurlFormDataStream::read):
+        (WebCore::CurlFormDataStream::readFromFile):
+        (WebCore::CurlFormDataStream::readFromData):
+        * platform/network/curl/CurlFormDataStream.h: Renamed from Source/WebCore/platform/network/curl/FormDataStreamCurl.h.
+        (WebCore::CurlFormDataStream::elementSize):
+        (WebCore::CurlFormDataStream::totalReadSize):
+        * platform/network/curl/CurlRequest.cpp:
+        (WebCore::CurlRequest::CurlRequest):
+        (WebCore::CurlRequest::willSendData):
+        (WebCore::CurlRequest::finalizeTransfer):
+        (WebCore::CurlRequest::setupPUT):
+        (WebCore::CurlRequest::setupPOST):
+        (WebCore::CurlRequest::setupSendData):
+        (WebCore::CurlRequest::resolveBlobReferences): Deleted.
+        (WebCore::CurlRequest::setupFormData): Deleted.
+        * platform/network/curl/CurlRequest.h:
+        * platform/network/curl/FormDataStreamCurl.cpp: Removed.
+
 2018-01-09  Zalan Bujtas  <[email protected]>
 
         [RenderTreeBuilder] Move MathML addChild logic to RenderTreeBuilder

Modified: trunk/Source/WebCore/platform/Curl.cmake (226655 => 226656)


--- trunk/Source/WebCore/platform/Curl.cmake	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/platform/Curl.cmake	2018-01-09 21:15:32 UTC (rev 226656)
@@ -11,12 +11,12 @@
     platform/network/curl/CurlCacheManager.cpp
     platform/network/curl/CurlContext.cpp
     platform/network/curl/CurlDownload.cpp
+    platform/network/curl/CurlFormDataStream.cpp
     platform/network/curl/CurlRequest.cpp
     platform/network/curl/CurlRequestScheduler.cpp
     platform/network/curl/CurlSSLHandle.cpp
     platform/network/curl/CurlSSLVerifier.cpp
     platform/network/curl/DNSCurl.cpp
-    platform/network/curl/FormDataStreamCurl.cpp
     platform/network/curl/MultipartHandle.cpp
     platform/network/curl/NetworkStorageSessionCurl.cpp
     platform/network/curl/ProxyServerCurl.cpp

Added: trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.cpp (0 => 226656)


--- trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.cpp	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.cpp	2018-01-09 21:15:32 UTC (rev 226656)
@@ -0,0 +1,205 @@
+/*
+ * Copyright (C) 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2006 Michael Emmel [email protected]
+ * Copyright (C) 2007 Alp Toker <[email protected]>
+ * Copyright (C) 2007 Holger Hans Peter Freyther
+ * Copyright (C) 2008 Collabora Ltd.
+ * Copyright (C) 2018 Sony Interactive Entertainment Inc.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CurlFormDataStream.h"
+
+#if USE(CURL)
+
+#include "CurlContext.h"
+#include "Logging.h"
+#include <wtf/MainThread.h>
+
+namespace WebCore {
+
+CurlFormDataStream::CurlFormDataStream(const FormData* formData)
+{
+    ASSERT(isMainThread());
+
+    if (!formData || formData->isEmpty())
+        return;
+
+    m_formData = formData->isolatedCopy();
+
+    // Resolve the blob elements so the formData can correctly report it's size.
+    m_formData = m_formData->resolveBlobReferences();
+}
+
+CurlFormDataStream::~CurlFormDataStream()
+{
+
+}
+
+void CurlFormDataStream::clean()
+{
+    if (m_postData)
+        m_postData = nullptr;
+
+    if (m_fileHandle != FileSystem::invalidPlatformFileHandle) {
+        FileSystem::closeFile(m_fileHandle);
+        m_fileHandle = FileSystem::invalidPlatformFileHandle;
+    }
+}
+
+std::optional<const Vector<char>&> CurlFormDataStream::getPostData()
+{
+    if (!m_formData)
+        return std::nullopt;
+
+    if (!m_postData)
+        m_postData = std::make_unique<Vector<char>>(m_formData->flatten());
+
+    return *m_postData;
+}
+
+bool CurlFormDataStream::shouldUseChunkTransfer()
+{
+    computeContentLength();
+
+    return m_shouldUseChunkTransfer;
+}
+
+unsigned long long CurlFormDataStream::totalSize()
+{
+    computeContentLength();
+
+    return m_totalSize;
+}
+
+void CurlFormDataStream::computeContentLength()
+{
+    static auto maxCurlOffT = CurlHandle::maxCurlOffT();
+
+    if (!m_formData || m_isContentLengthUpdated)
+        return;
+
+    m_isContentLengthUpdated = true;
+
+    for (const auto& element : m_formData->elements()) {
+        if (element.m_type == FormDataElement::Type::EncodedFile) {
+            long long fileSize;
+            if (FileSystem::getFileSize(element.m_filename, fileSize)) {
+                if (fileSize > maxCurlOffT) {
+                    // File size is too big for specifying it to curl
+                    m_shouldUseChunkTransfer = true;
+                }
+
+                m_totalSize += fileSize;
+            } else
+                m_shouldUseChunkTransfer = true;
+        } else
+            m_totalSize += element.m_data.size();
+    }
+}
+
+std::optional<size_t> CurlFormDataStream::read(char* buffer, size_t size)
+{
+    if (!m_formData)
+        return std::nullopt;
+
+    const auto totalElementSize = m_formData->elements().size();
+    if (m_elementPosition >= totalElementSize)
+        return 0;
+
+    size_t totalReadBytes = 0;
+
+    while ((m_elementPosition < totalElementSize) && (totalReadBytes < size)) {
+        const auto& element = m_formData->elements().at(m_elementPosition);
+
+        std::optional<size_t> readBytes;
+        size_t bufferSize = size - totalReadBytes;
+        char* bufferPosition = buffer + totalReadBytes;
+
+        if (element.m_type == FormDataElement::Type::EncodedFile)
+            readBytes = readFromFile(element, bufferPosition, bufferSize);
+        else
+            readBytes = readFromData(element, bufferPosition, bufferSize);
+
+        if (!readBytes)
+            return std::nullopt;
+
+        totalReadBytes += *readBytes;
+    }
+
+    m_totalReadSize += totalReadBytes;
+
+    return totalReadBytes;
+}
+
+std::optional<size_t> CurlFormDataStream::readFromFile(const FormDataElement& element, char* buffer, size_t size)
+{
+    if (m_fileHandle == FileSystem::invalidPlatformFileHandle)
+        m_fileHandle = FileSystem::openFile(element.m_filename, FileSystem::FileOpenMode::Read);
+
+    if (!FileSystem::isHandleValid(m_fileHandle)) {
+        LOG(Network, "Curl - Failed while trying to open %s for upload\n", element.m_filename.utf8().data());
+        m_fileHandle = FileSystem::invalidPlatformFileHandle;
+        return std::nullopt;
+    }
+
+    auto readBytes = FileSystem::readFromFile(m_fileHandle, buffer, size);
+    if (readBytes < 0) {
+        LOG(Network, "Curl - Failed while trying to read %s for upload\n", element.m_filename.utf8().data());
+        FileSystem::closeFile(m_fileHandle);
+        m_fileHandle = FileSystem::invalidPlatformFileHandle;
+        return std::nullopt;
+    }
+
+    if (!readBytes) {
+        FileSystem::closeFile(m_fileHandle);
+        m_fileHandle = FileSystem::invalidPlatformFileHandle;
+        m_elementPosition++;
+    }
+
+    return readBytes;
+}
+
+std::optional<size_t> CurlFormDataStream::readFromData(const FormDataElement& element, char* buffer, size_t size)
+{
+    size_t elementSize = element.m_data.size() - m_dataOffset;
+    const char* elementBuffer = element.m_data.data() + m_dataOffset;
+
+    size_t readBytes = elementSize > size ? size : elementSize;
+    memcpy(buffer, elementBuffer, readBytes);
+
+    if (elementSize > readBytes)
+        m_dataOffset += readBytes;
+    else {
+        m_dataOffset = 0;
+        m_elementPosition++;
+    }
+
+    return readBytes;
+}
+
+} // namespace WebCore
+
+#endif

Copied: trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.h (from rev 226655, trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.h) (0 => 226656)


--- trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.h	                        (rev 0)
+++ trunk/Source/WebCore/platform/network/curl/CurlFormDataStream.h	2018-01-09 21:15:32 UTC (rev 226656)
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2008 Apple Inc.  All rights reserved.
+ * Copyright (C) 2017 Sony Interactive Entertainment Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "FileSystem.h"
+#include "FormData.h"
+#include <wtf/Vector.h>
+
+namespace WebCore {
+
+class CurlFormDataStream {
+public:
+    CurlFormDataStream(const FormData*);
+    ~CurlFormDataStream();
+
+    void clean();
+
+    size_t elementSize() { return m_formData ? m_formData->elements().size() : 0; }
+
+    std::optional<const Vector<char>&> getPostData();
+    bool shouldUseChunkTransfer();
+    unsigned long long totalSize();
+
+    std::optional<size_t> read(char*, size_t);
+    unsigned long long totalReadSize() { return m_totalReadSize; }
+
+private:
+    void computeContentLength();
+
+    std::optional<size_t> readFromFile(const FormDataElement&, char*, size_t);
+    std::optional<size_t> readFromData(const FormDataElement&, char*, size_t);
+
+    RefPtr<FormData> m_formData;
+
+    std::unique_ptr<Vector<char>> m_postData;
+    bool m_isContentLengthUpdated { false };
+    bool m_shouldUseChunkTransfer { false };
+    unsigned long long m_totalSize { 0 };
+    unsigned long long m_totalReadSize { 0 };
+
+    size_t m_elementPosition { 0 };
+
+    FileSystem::PlatformFileHandle m_fileHandle { FileSystem::invalidPlatformFileHandle };
+    size_t m_dataOffset { 0 };
+};
+
+} // namespace WebCore

Modified: trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp (226655 => 226656)


--- trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequest.cpp	2018-01-09 21:15:32 UTC (rev 226656)
@@ -40,11 +40,11 @@
 CurlRequest::CurlRequest(const ResourceRequest&request, CurlRequestClient* client, bool shouldSuspend)
     : m_request(request.isolatedCopy())
     , m_shouldSuspend(shouldSuspend)
+    , m_formDataStream(m_request.httpBody())
 {
     ASSERT(isMainThread());
 
     setClient(client);
-    resolveBlobReferences(m_request);
 }
 
 void CurlRequest::setUserPass(const String& user, const String& password)
@@ -235,24 +235,26 @@
 // Iterate through FormData elements and upload files.
 // Carefully respect the given buffer size and fill the rest of the data at the next calls.
 
-size_t CurlRequest::willSendData(char* ptr, size_t blockSize, size_t numberOfBlocks)
+size_t CurlRequest::willSendData(char* buffer, size_t blockSize, size_t numberOfBlocks)
 {
     if (isCompletedOrCancelled())
         return CURL_READFUNC_ABORT;
 
     if (!blockSize || !numberOfBlocks)
-        return 0;
+        return CURL_READFUNC_ABORT;
 
-    if (!m_formDataStream || !m_formDataStream->hasMoreElements())
-        return 0;
+    // Check for overflow.
+    if (blockSize > (std::numeric_limits<size_t>::max() / numberOfBlocks))
+        return CURL_READFUNC_ABORT;
 
-    auto sendBytes = m_formDataStream->read(ptr, blockSize, numberOfBlocks);
+    size_t bufferSize = blockSize * numberOfBlocks;
+    auto sendBytes = m_formDataStream.read(buffer, bufferSize);
     if (!sendBytes) {
         // Something went wrong so error the job.
         return CURL_READFUNC_ABORT;
     }
 
-    return sendBytes;
+    return *sendBytes;
 }
 
 // This is being called for each HTTP header in the response. This includes '\r\n'
@@ -394,24 +396,11 @@
 
 void CurlRequest::finalizeTransfer()
 {
-    m_formDataStream = nullptr;
     closeDownloadFile();
+    m_formDataStream.clean();
     m_curlHandle = nullptr;
 }
 
-void CurlRequest::resolveBlobReferences(ResourceRequest& request)
-{
-    ASSERT(isMainThread());
-
-    auto body = request.httpBody();
-    if (!body || body->isEmpty())
-        return;
-
-    // Resolve the blob elements so the formData can correctly report it's size.
-    RefPtr<FormData> formData = body->resolveBlobReferences();
-    request.setHTTPBody(WTFMove(formData));
-}
-
 void CurlRequest::setupPUT(ResourceRequest& request)
 {
     m_curlHandle->enableHttpPutRequest();
@@ -419,11 +408,11 @@
     // Disable the Expect: 100 continue header
     m_curlHandle->removeRequestHeader("Expect");
 
-    auto body = request.httpBody();
-    if (!body || body->isEmpty())
+    auto elementSize = m_formDataStream.elementSize();
+    if (!elementSize)
         return;
 
-    setupFormData(request, false);
+    setupSendData(true);
 }
 
 void CurlRequest::setupPOST(ResourceRequest& request)
@@ -430,63 +419,31 @@
 {
     m_curlHandle->enableHttpPostRequest();
 
-    auto body = request.httpBody();
-    if (!body || body->isEmpty())
+    auto elementSize = m_formDataStream.elementSize();
+    if (!elementSize)
         return;
 
-    auto numElements = body->elements().size();
-    if (!numElements)
-        return;
-
     // Do not stream for simple POST data
-    if (numElements == 1) {
-        m_postBuffer = body->flatten();
-        if (m_postBuffer.size())
-            m_curlHandle->setPostFields(m_postBuffer.data(), m_postBuffer.size());
+    if (elementSize == 1) {
+        auto postData = m_formDataStream.getPostData();
+        if (postData && postData->size())
+            m_curlHandle->setPostFields(postData->data(), postData->size());
     } else
-        setupFormData(request, true);
+        setupSendData(false);
 }
 
-void CurlRequest::setupFormData(ResourceRequest& request, bool isPostRequest)
+void CurlRequest::setupSendData(bool forPutMethod)
 {
-    static auto maxCurlOffT = CurlHandle::maxCurlOffT();
-
-    // Obtain the total size of the form data
-    curl_off_t size = 0;
-    bool chunkedTransfer = false;
-    auto elements = request.httpBody()->elements();
-
-    for (auto element : elements) {
-        if (element.m_type == FormDataElement::Type::EncodedFile) {
-            long long fileSizeResult;
-            if (FileSystem::getFileSize(element.m_filename, fileSizeResult)) {
-                if (fileSizeResult > maxCurlOffT) {
-                    // File size is too big for specifying it to cURL
-                    chunkedTransfer = true;
-                    break;
-                }
-                size += fileSizeResult;
-            } else {
-                chunkedTransfer = true;
-                break;
-            }
-        } else
-            size += element.m_data.size();
-    }
-
-    // cURL guesses that we want chunked encoding as long as we specify the header
-    if (chunkedTransfer)
+    // curl guesses that we want chunked encoding as long as we specify the header
+    if (m_formDataStream.shouldUseChunkTransfer())
         m_curlHandle->appendRequestHeader("Transfer-Encoding: chunked");
     else {
-        if (isPostRequest)
-            m_curlHandle->setPostFieldLarge(size);
+        if (forPutMethod)
+            m_curlHandle->setInFileSizeLarge(static_cast<curl_off_t>(m_formDataStream.totalSize()));
         else
-            m_curlHandle->setInFileSizeLarge(size);
+            m_curlHandle->setPostFieldLarge(static_cast<curl_off_t>(m_formDataStream.totalSize()));
     }
 
-    m_formDataStream = std::make_unique<FormDataStream>();
-    m_formDataStream->setHTTPBody(request.httpBody());
-
     m_curlHandle->setReadCallbackFunction(willSendDataCallback, this);
 }
 

Modified: trunk/Source/WebCore/platform/network/curl/CurlRequest.h (226655 => 226656)


--- trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/platform/network/curl/CurlRequest.h	2018-01-09 21:15:32 UTC (rev 226656)
@@ -25,11 +25,11 @@
 
 #pragma once
 
+#include "CurlFormDataStream.h"
 #include "CurlRequestSchedulerClient.h"
 #include "CurlResponse.h"
 #include "CurlSSLVerifier.h"
 #include "FileSystem.h"
-#include "FormDataStreamCurl.h"
 #include "NetworkLoadMetrics.h"
 #include "ResourceRequest.h"
 #include <wtf/Noncopyable.h>
@@ -104,10 +104,9 @@
     void finalizeTransfer();
 
     // For POST and PUT method 
-    void resolveBlobReferences(ResourceRequest&);
     void setupPOST(ResourceRequest&);
     void setupPUT(ResourceRequest&);
-    void setupFormData(ResourceRequest&, bool);
+    void setupSendData(bool forPutMethod);
 
     // Processing for DidReceiveResponse
     bool needToInvokeDidReceiveResponse() const { return !m_didNotifyResponse || !m_didReturnFromNotify; }
@@ -142,8 +141,7 @@
     bool m_shouldSuspend { false };
 
     std::unique_ptr<CurlHandle> m_curlHandle;
-    std::unique_ptr<FormDataStream> m_formDataStream;
-    Vector<char> m_postBuffer;
+    CurlFormDataStream m_formDataStream;
     CurlSSLVerifier m_sslVerifier;
 
     CurlResponse m_response;

Deleted: trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.cpp (226655 => 226656)


--- trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.cpp	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.cpp	2018-01-09 21:15:32 UTC (rev 226656)
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc.  All rights reserved.
- * Copyright (C) 2006 Michael Emmel [email protected]
- * Copyright (C) 2007 Alp Toker <[email protected]>
- * Copyright (C) 2007 Holger Hans Peter Freyther
- * Copyright (C) 2008 Collabora Ltd.
- * Copyright (C) 2017 Sony Interactive Entertainment Inc.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "FormDataStreamCurl.h"
-
-#if USE(CURL)
-
-#include "FormData.h"
-
-namespace WebCore {
-
-FormDataStream::~FormDataStream()
-{
-    if (m_file)
-        fclose(m_file);
-}
-
-size_t FormDataStream::read(void* ptr, size_t blockSize, size_t numberOfBlocks)
-{
-    // Check for overflow.
-    if (!numberOfBlocks || blockSize > std::numeric_limits<size_t>::max() / numberOfBlocks)
-        return 0;
-
-    Vector<FormDataElement> elements;
-    if (m_formData)
-        elements = m_formData->elements();
-
-    if (m_formDataElementIndex >= elements.size())
-        return 0;
-
-    FormDataElement element = elements[m_formDataElementIndex];
-
-    size_t toSend = blockSize * numberOfBlocks;
-    size_t sent;
-
-    if (element.m_type == FormDataElement::Type::EncodedFile) {
-        if (!m_file)
-            m_file = fopen(element.m_filename.utf8().data(), "rb");
-
-        if (!m_file) {
-            // FIXME: show a user error?
-#ifndef NDEBUG
-            printf("Failed while trying to open %s for upload\n", element.m_filename.utf8().data());
-#endif
-            return 0;
-        }
-
-        sent = fread(ptr, blockSize, numberOfBlocks, m_file);
-        if (!blockSize && ferror(m_file)) {
-            // FIXME: show a user error?
-#ifndef NDEBUG
-            printf("Failed while trying to read %s for upload\n", element.m_filename.utf8().data());
-#endif
-            return 0;
-        }
-        if (feof(m_file)) {
-            fclose(m_file);
-            m_file = 0;
-            m_formDataElementIndex++;
-        }
-    } else {
-        size_t elementSize = element.m_data.size() - m_formDataElementDataOffset;
-        sent = elementSize > toSend ? toSend : elementSize;
-        memcpy(ptr, element.m_data.data() + m_formDataElementDataOffset, sent);
-        if (elementSize > sent)
-            m_formDataElementDataOffset += sent;
-        else {
-            m_formDataElementDataOffset = 0;
-            m_formDataElementIndex++;
-        }
-    }
-
-    return sent;
-}
-
-bool FormDataStream::hasMoreElements() const
-{
-    Vector<FormDataElement> elements;
-    if (m_formData)
-        elements = m_formData->elements();
-
-    return m_formDataElementIndex < elements.size();
-}
-
-} // namespace WebCore
-
-#endif

Deleted: trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.h (226655 => 226656)


--- trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.h	2018-01-09 21:13:35 UTC (rev 226655)
+++ trunk/Source/WebCore/platform/network/curl/FormDataStreamCurl.h	2018-01-09 21:15:32 UTC (rev 226656)
@@ -1,54 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc.  All rights reserved.
- * Copyright (C) 2017 Sony Interactive Entertainment Inc.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
- * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
- * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
- * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
- * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
- * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#pragma once
-
-#include <stdio.h>
-
-namespace WebCore {
-
-class FormData;
-
-class FormDataStream {
-public:
-    FormDataStream() = default;
-    ~FormDataStream();
-
-    void setHTTPBody(FormData* formData) { m_formData = formData; }
-    size_t read(void* ptr, size_t blockSize, size_t numberOfBlocks);
-    bool hasMoreElements() const;
-
-private:
-    // We can hold a weak reference to our ResourceRequest as it holds a strong reference
-    // to us through its owner.
-    FormData* m_formData { };
-
-    FILE* m_file { };
-    size_t m_formDataElementIndex { 0 };
-    size_t m_formDataElementDataOffset { 0 };
-};
-
-} // namespace WebCore
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to