[haiku-webkit-commits] r495 - webkit/trunk/WebCore/platform/network/curl

  • From: webkit@xxxxxxxxxxxxxxx
  • To: haiku-webkit-commits@xxxxxxxxxxxxx
  • Date: Sun, 16 May 2010 15:11:04 +0000

Author: stippi
Date: Sun May 16 15:11:03 2010
New Revision: 495
URL: http://mmlr.dyndns.org/changeset/495

Log:
Sine cURL 7.18, clients need to implement a "seek" function, since the upload
data stream may have to be rewinded when certain authentication methods are
used. This fixes the error when trying to upload attachements to Trac.

Modified:
   webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.cpp
   webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.h
   webkit/trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp

Modified: webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.cpp
==============================================================================
--- webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.cpp   Tue May 
11 12:21:04 2010        (r494)
+++ webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.cpp   Sun May 
16 15:11:03 2010        (r495)
@@ -43,6 +43,20 @@
         fclose(m_file);
 }
 
+int FormDataStream::seek(long long offset, int whence)
+{
+    if (offset != 0 || whence != SEEK_SET)
+        return 1;
+
+    m_formDataElementIndex = 0;
+    m_formDataElementDataOffset = 0;
+    if (m_file) {
+        fclose(m_file);
+        m_file = 0;
+    }
+    return 0;
+}
+
 size_t FormDataStream::read(void* ptr, size_t blockSize, size_t numberOfBlocks)
 {
     // Check for overflow.

Modified: webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.h
==============================================================================
--- webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.h     Tue May 
11 12:21:04 2010        (r494)
+++ webkit/trunk/WebCore/platform/network/curl/FormDataStreamCurl.h     Sun May 
16 15:11:03 2010        (r495)
@@ -45,6 +45,7 @@
 
     ~FormDataStream();
 
+    int seek(long long offset, int whence);
     size_t read(void* ptr, size_t blockSize, size_t numberOfBlocks);
     bool hasMoreElements() const;
 

Modified: webkit/trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp
==============================================================================
--- webkit/trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp        
Tue May 11 12:21:04 2010        (r494)
+++ webkit/trunk/WebCore/platform/network/curl/ResourceHandleManager.cpp        
Sun May 16 15:11:03 2010        (r495)
@@ -400,6 +400,27 @@
     return sent;
 }
 
+/* Used by cURL to rewind the data stream in uploads with certain 
authentication methods.
+   It may also be used for continued uploads to skip the already uploaded 
parts, but this
+   should currently not be used.
+*/
+int seekCallback(void* data, curl_off_t offset, int origin)
+{
+    ResourceHandle* job = static_cast<ResourceHandle*>(data);
+    ResourceHandleInternal* d = job->getInternal();
+
+    if (d->m_cancelled)
+        return 1;
+
+    int result = d->m_formDataStream.seek(offset, origin);
+
+    // Something went wrong so cancel the job.
+    if (result == 1)
+        job->cancel();
+
+    return result;
+}
+
 void 
ResourceHandleManager::downloadTimerCallback(Timer<ResourceHandleManager>* 
timer)
 {
     startScheduledJobs();
@@ -621,6 +642,8 @@
 
     curl_easy_setopt(d->m_handle, CURLOPT_READFUNCTION, readCallback);
     curl_easy_setopt(d->m_handle, CURLOPT_READDATA, job);
+    curl_easy_setopt(d->m_handle, CURLOPT_SEEKFUNCTION, seekCallback);
+    curl_easy_setopt(d->m_handle, CURLOPT_SEEKDATA, job);
 }
 
 void ResourceHandleManager::add(ResourceHandle* job)

Other related posts:

  • » [haiku-webkit-commits] r495 - webkit/trunk/WebCore/platform/network/curl - webkit