Blob Blame History Raw
From ca4705dab05371c40f398b97277024332ed44651 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Tue, 26 Feb 2013 16:58:55 +0100
Subject: [PATCH 3/4] pycurl.c: allow to return -1 from write callback

... to abort the transfer and WRITEFUNC_PAUSE to pause the transfer

Reported By: Zdenek Pavlas
Bug: https://bugzilla.redhat.com/857875
---
 src/pycurl.c |   11 +++++------
 1 files changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/pycurl.c b/src/pycurl.c
index f197145..b59eeb8 100644
--- a/src/pycurl.c
+++ b/src/pycurl.c
@@ -1081,12 +1081,8 @@ util_write_callback(int flags, char *ptr, size_t size, size_t nmemb, void *strea
         ret = total_size;           /* None means success */
     }
     else if (PyInt_Check(result) || PyLong_Check(result)) {
-        long obj_size = PyLong_AsLong(result);
-        if (obj_size < 0 || obj_size > total_size) {
-            PyErr_Format(ErrorObject, "invalid return value for write callback %ld %ld", (long)obj_size, (long)total_size);
-            goto verbose_error;
-        }
-        ret = (size_t) obj_size;    /* success */
+        /* if the cast to long fails, PyLong_AsLong() returns -1L */
+        ret = (size_t) PyLong_AsLong(result);
     }
     else {
         PyErr_SetString(ErrorObject, "write callback must return int or None");
@@ -3423,6 +3419,9 @@ initpycurl(void)
     /* Abort curl_read_callback(). */
     insint_c(d, "READFUNC_ABORT", CURL_READFUNC_ABORT);
 
+    /* Pause curl_write_callback(). */
+    insint_c(d, "WRITEFUNC_PAUSE", CURL_WRITEFUNC_PAUSE);
+
     /* constants for ioctl callback return values */
     insint_c(d, "IOE_OK", CURLIOE_OK);
     insint_c(d, "IOE_UNKNOWNCMD", CURLIOE_UNKNOWNCMD);
-- 
1.7.1