aboutsummaryrefslogtreecommitdiff
path: root/lib/transfer.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2015-10-05 20:39:10 +0200
committerDaniel Stenberg <daniel@haxx.se>2015-10-15 23:32:19 +0200
commitc6aedf680f6923ffbe4dd4fd4e68e7dadcd5fb19 (patch)
tree4f681e394e33c436ea94fd40db2ec126afdc0977 /lib/transfer.c
parent854976ad7b049e3a758d3d0ec33d5c998e36e5af (diff)
fread_func: move callback pointer from set to state struct
... and assign it from the set.fread_func_set pointer in the Curl_init_CONNECT function. This A) avoids that we have code that assigns fields in the 'set' struct (which we always knew was bad) and more importantly B) it makes it impossibly to accidentally leave the wrong value for when the handle is re-used etc. Introducing a state-init functionality in multi.c, so that we can set a specific function to get called when we enter a state. The Curl_init_CONNECT is thus called when switching to the CONNECT state. Bug: https://github.com/bagder/curl/issues/346 Closes #346
Diffstat (limited to 'lib/transfer.c')
-rw-r--r--lib/transfer.c20
1 files changed, 15 insertions, 5 deletions
diff --git a/lib/transfer.c b/lib/transfer.c
index 7bc500cc8..dda235cc7 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -115,8 +115,8 @@ CURLcode Curl_fillreadbuffer(struct connectdata *conn, int bytes, int *nreadp)
/* this function returns a size_t, so we typecast to int to prevent warnings
with picky compilers */
- nread = (int)data->set.fread_func(data->req.upload_fromhere, 1,
- buffersize, data->set.in);
+ nread = (int)data->state.fread_func(data->req.upload_fromhere, 1,
+ buffersize, data->state.in);
if(nread == CURL_READFUNC_ABORT) {
failf(data, "operation aborted by callback");
@@ -289,8 +289,8 @@ CURLcode Curl_readrewind(struct connectdata *conn)
/* If no CURLOPT_READFUNCTION is used, we know that we operate on a
given FILE * stream and we can actually attempt to rewind that
ourselves with fseek() */
- if(data->set.fread_func == (curl_read_callback)fread) {
- if(-1 != fseek(data->set.in, 0, SEEK_SET))
+ if(data->state.fread_func == (curl_read_callback)fread) {
+ if(-1 != fseek(data->state.in, 0, SEEK_SET))
/* successful rewind */
return CURLE_OK;
}
@@ -1286,8 +1286,18 @@ long Curl_sleep_time(curl_off_t rate_bps, curl_off_t cur_rate_bps,
return (long)rv;
}
+/* Curl_init_CONNECT() gets called each time the handle switches to CONNECT
+ which means this gets called once for each subsequent redirect etc */
+void Curl_init_CONNECT(struct SessionHandle *data)
+{
+ data->state.fread_func = data->set.fread_func_set;
+ data->state.in = data->set.in_set;
+}
+
/*
- * Curl_pretransfer() is called immediately before a transfer starts.
+ * Curl_pretransfer() is called immediately before a transfer starts, and only
+ * once for one transfer no matter if it has redirects or do multi-pass
+ * authentication etc.
*/
CURLcode Curl_pretransfer(struct SessionHandle *data)
{