Skip to content

Commit

Permalink
urldata: simplify bytecounters
Browse files Browse the repository at this point in the history
- no need to have them protocol specific

- no need to set pointers to them with the Curl_setup_transfer() call

- make Curl_setup_transfer() operate on a transfer pointer, not
  connection

- switch some counters from long to the more proper curl_off_t type

Closes #3627
  • Loading branch information
bagder committed Mar 1, 2019
1 parent 8cf6c17 commit 65eb65f
Show file tree
Hide file tree
Showing 22 changed files with 111 additions and 176 deletions.
9 changes: 5 additions & 4 deletions lib/curl_rtmp.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 2012 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 2012 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* Copyright (C) 2010, Howard Chu, <hyc@highlandsun.com> * Copyright (C) 2010, Howard Chu, <hyc@highlandsun.com>
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
Expand Down Expand Up @@ -239,17 +239,18 @@ static CURLcode rtmp_connect(struct connectdata *conn, bool *done)


static CURLcode rtmp_do(struct connectdata *conn, bool *done) static CURLcode rtmp_do(struct connectdata *conn, bool *done)
{ {
struct Curl_easy *data = conn->data;
RTMP *r = conn->proto.generic; RTMP *r = conn->proto.generic;


if(!RTMP_ConnectStream(r, 0)) if(!RTMP_ConnectStream(r, 0))
return CURLE_FAILED_INIT; return CURLE_FAILED_INIT;


if(conn->data->set.upload) { if(conn->data->set.upload) {
Curl_pgrsSetUploadSize(conn->data, conn->data->state.infilesize); Curl_pgrsSetUploadSize(data, data->state.infilesize);
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, FIRSTSOCKET, NULL); Curl_setup_transfer(data, -1, -1, FALSE, FIRSTSOCKET);
} }
else else
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
*done = TRUE; *done = TRUE;
return CURLE_OK; return CURLE_OK;
} }
Expand Down
11 changes: 4 additions & 7 deletions lib/dict.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -137,7 +137,6 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; curl_socket_t sockfd = conn->sock[FIRSTSOCKET];


char *path = data->state.up.path; char *path = data->state.up.path;
curl_off_t *bytecount = &data->req.bytecount;


*done = TRUE; /* unconditionally */ *done = TRUE; /* unconditionally */


Expand Down Expand Up @@ -200,8 +199,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
failf(data, "Failed sending DICT request"); failf(data, "Failed sending DICT request");
return result; return result;
} }
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1); /* no upload */
-1, NULL); /* no upload */
} }
else if(strncasecompare(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) || else if(strncasecompare(path, DICT_DEFINE, sizeof(DICT_DEFINE)-1) ||
strncasecompare(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) || strncasecompare(path, DICT_DEFINE2, sizeof(DICT_DEFINE2)-1) ||
Expand Down Expand Up @@ -247,8 +245,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
failf(data, "Failed sending DICT request"); failf(data, "Failed sending DICT request");
return result; return result;
} }
Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
-1, NULL); /* no upload */
} }
else { else {


Expand All @@ -270,7 +267,7 @@ static CURLcode dict_do(struct connectdata *conn, bool *done)
return result; return result;
} }


Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, -1, NULL); Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
} }
} }


Expand Down
35 changes: 14 additions & 21 deletions lib/ftp.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -448,7 +448,6 @@ static CURLcode ReceivedServerConnect(struct connectdata *conn, bool *received)
static CURLcode InitiateTransfer(struct connectdata *conn) static CURLcode InitiateTransfer(struct connectdata *conn)
{ {
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
struct FTP *ftp = data->req.protop;
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;


if(conn->bits.ftp_use_data_ssl) { if(conn->bits.ftp_use_data_ssl) {
Expand All @@ -461,24 +460,19 @@ static CURLcode InitiateTransfer(struct connectdata *conn)
} }


if(conn->proto.ftpc.state_saved == FTP_STOR) { if(conn->proto.ftpc.state_saved == FTP_STOR) {
*(ftp->bytecountp) = 0;

/* When we know we're uploading a specified file, we can get the file /* When we know we're uploading a specified file, we can get the file
size prior to the actual upload. */ size prior to the actual upload. */

Curl_pgrsSetUploadSize(data, data->state.infilesize); Curl_pgrsSetUploadSize(data, data->state.infilesize);


/* set the SO_SNDBUF for the secondary socket for those who need it */ /* set the SO_SNDBUF for the secondary socket for those who need it */
Curl_sndbufset(conn->sock[SECONDARYSOCKET]); Curl_sndbufset(conn->sock[SECONDARYSOCKET]);


Curl_setup_transfer(conn, -1, -1, FALSE, NULL, /* no download */ Curl_setup_transfer(data, -1, -1, FALSE, SECONDARYSOCKET);
SECONDARYSOCKET, ftp->bytecountp);
} }
else { else {
/* FTP download: */ /* FTP download: */
Curl_setup_transfer(conn, SECONDARYSOCKET, Curl_setup_transfer(data, SECONDARYSOCKET,
conn->proto.ftpc.retr_size_saved, FALSE, conn->proto.ftpc.retr_size_saved, FALSE, -1);
ftp->bytecountp, -1, NULL); /* no upload here */
} }


conn->proto.ftpc.pp.pending_resp = TRUE; /* expect server response */ conn->proto.ftpc.pp.pending_resp = TRUE; /* expect server response */
Expand Down Expand Up @@ -1658,7 +1652,7 @@ static CURLcode ftp_state_ul_setup(struct connectdata *conn,
infof(data, "File already completely uploaded\n"); infof(data, "File already completely uploaded\n");


/* no data to transfer */ /* no data to transfer */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(data, -1, -1, FALSE, -1);


/* Set ->transfer so that we won't get any error in /* Set ->transfer so that we won't get any error in
* ftp_done() because we didn't transfer anything! */ * ftp_done() because we didn't transfer anything! */
Expand Down Expand Up @@ -2230,7 +2224,7 @@ static CURLcode ftp_state_retr(struct connectdata *conn,


if(ftp->downloadsize == 0) { if(ftp->downloadsize == 0) {
/* no data to transfer */ /* no data to transfer */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(data, -1, -1, FALSE, -1);
infof(data, "File already completely downloaded\n"); infof(data, "File already completely downloaded\n");


/* Set ->transfer so that we won't get any error in ftp_done() /* Set ->transfer so that we won't get any error in ftp_done()
Expand Down Expand Up @@ -3308,33 +3302,33 @@ static CURLcode ftp_done(struct connectdata *conn, CURLcode status,
; ;
else if(data->set.upload) { else if(data->set.upload) {
if((-1 != data->state.infilesize) && if((-1 != data->state.infilesize) &&
(data->state.infilesize != *ftp->bytecountp) && (data->state.infilesize != data->req.writebytecount) &&
!data->set.crlf && !data->set.crlf &&
(ftp->transfer == FTPTRANSFER_BODY)) { (ftp->transfer == FTPTRANSFER_BODY)) {
failf(data, "Uploaded unaligned file size (%" CURL_FORMAT_CURL_OFF_T failf(data, "Uploaded unaligned file size (%" CURL_FORMAT_CURL_OFF_T
" out of %" CURL_FORMAT_CURL_OFF_T " bytes)", " out of %" CURL_FORMAT_CURL_OFF_T " bytes)",
*ftp->bytecountp, data->state.infilesize); data->req.bytecount, data->state.infilesize);
result = CURLE_PARTIAL_FILE; result = CURLE_PARTIAL_FILE;
} }
} }
else { else {
if((-1 != data->req.size) && if((-1 != data->req.size) &&
(data->req.size != *ftp->bytecountp) && (data->req.size != data->req.bytecount) &&
#ifdef CURL_DO_LINEEND_CONV #ifdef CURL_DO_LINEEND_CONV
/* Most FTP servers don't adjust their file SIZE response for CRLFs, so /* Most FTP servers don't adjust their file SIZE response for CRLFs, so
* we'll check to see if the discrepancy can be explained by the number * we'll check to see if the discrepancy can be explained by the number
* of CRLFs we've changed to LFs. * of CRLFs we've changed to LFs.
*/ */
((data->req.size + data->state.crlf_conversions) != ((data->req.size + data->state.crlf_conversions) !=
*ftp->bytecountp) && data->req.bytecount) &&
#endif /* CURL_DO_LINEEND_CONV */ #endif /* CURL_DO_LINEEND_CONV */
(data->req.maxdownload != *ftp->bytecountp)) { (data->req.maxdownload != data->req.bytecount)) {
failf(data, "Received only partial file: %" CURL_FORMAT_CURL_OFF_T failf(data, "Received only partial file: %" CURL_FORMAT_CURL_OFF_T
" bytes", *ftp->bytecountp); " bytes", data->req.bytecount);
result = CURLE_PARTIAL_FILE; result = CURLE_PARTIAL_FILE;
} }
else if(!ftpc->dont_check && else if(!ftpc->dont_check &&
!*ftp->bytecountp && !data->req.bytecount &&
(data->req.size>0)) { (data->req.size>0)) {
failf(data, "No data was received!"); failf(data, "No data was received!");
result = CURLE_FTP_COULDNT_RETR_FILE; result = CURLE_FTP_COULDNT_RETR_FILE;
Expand Down Expand Up @@ -3629,7 +3623,7 @@ static CURLcode ftp_do_more(struct connectdata *conn, int *completep)
if(!result && (ftp->transfer != FTPTRANSFER_BODY)) if(!result && (ftp->transfer != FTPTRANSFER_BODY))
/* no data to transfer. FIX: it feels like a kludge to have this here /* no data to transfer. FIX: it feels like a kludge to have this here
too! */ too! */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(data, -1, -1, FALSE, -1);


if(!ftpc->wait_data_conn) { if(!ftpc->wait_data_conn) {
/* no waiting for the data connection so this is now complete */ /* no waiting for the data connection so this is now complete */
Expand Down Expand Up @@ -4308,7 +4302,7 @@ static CURLcode ftp_dophase_done(struct connectdata *conn,


if(ftp->transfer != FTPTRANSFER_BODY) if(ftp->transfer != FTPTRANSFER_BODY)
/* no data to transfer */ /* no data to transfer */
Curl_setup_transfer(conn, -1, -1, FALSE, NULL, -1, NULL); Curl_setup_transfer(conn->data, -1, -1, FALSE, -1);
else if(!connected) else if(!connected)
/* since we didn't connect now, we want do_more to get called */ /* since we didn't connect now, we want do_more to get called */
conn->bits.do_more = TRUE; conn->bits.do_more = TRUE;
Expand Down Expand Up @@ -4427,7 +4421,6 @@ static CURLcode ftp_setup_connection(struct connectdata *conn)
} }


/* get some initial data into the ftp struct */ /* get some initial data into the ftp struct */
ftp->bytecountp = &conn->data->req.bytecount;
ftp->transfer = FTPTRANSFER_BODY; ftp->transfer = FTPTRANSFER_BODY;
ftp->downloadsize = 0; ftp->downloadsize = 0;


Expand Down
3 changes: 1 addition & 2 deletions lib/ftp.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -102,7 +102,6 @@ typedef enum {
perhaps the Curl_easy is changed between the times the connection is perhaps the Curl_easy is changed between the times the connection is
used. */ used. */
struct FTP { struct FTP {
curl_off_t *bytecountp;
char *user; /* user name string */ char *user; /* user name string */
char *passwd; /* password string */ char *passwd; /* password string */
char *path; /* points to the urlpieces struct field */ char *path; /* points to the urlpieces struct field */
Expand Down
4 changes: 2 additions & 2 deletions lib/getinfo.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ static CURLcode getinfo_long(struct Curl_easy *data, CURLINFO info,
*param_longp = (long)data->info.filetime; *param_longp = (long)data->info.filetime;
break; break;
case CURLINFO_HEADER_SIZE: case CURLINFO_HEADER_SIZE:
*param_longp = data->info.header_size; *param_longp = (long)data->info.header_size;
break; break;
case CURLINFO_REQUEST_SIZE: case CURLINFO_REQUEST_SIZE:
*param_longp = data->info.request_size; *param_longp = (long)data->info.request_size;
break; break;
case CURLINFO_SSL_VERIFYRESULT: case CURLINFO_SSL_VERIFYRESULT:
*param_longp = data->set.ssl.certverifyresult; *param_longp = data->set.ssl.certverifyresult;
Expand Down
7 changes: 2 additions & 5 deletions lib/gopher.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___ * | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____| * \___|\___/|_| \_\_____|
* *
* Copyright (C) 1998 - 2018, Daniel Stenberg, <daniel@haxx.se>, et al. * Copyright (C) 1998 - 2019, Daniel Stenberg, <daniel@haxx.se>, et al.
* *
* This software is licensed as described in the file COPYING, which * This software is licensed as described in the file COPYING, which
* you should have received as part of this distribution. The terms * you should have received as part of this distribution. The terms
Expand Down Expand Up @@ -78,8 +78,6 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
CURLcode result = CURLE_OK; CURLcode result = CURLE_OK;
struct Curl_easy *data = conn->data; struct Curl_easy *data = conn->data;
curl_socket_t sockfd = conn->sock[FIRSTSOCKET]; curl_socket_t sockfd = conn->sock[FIRSTSOCKET];

curl_off_t *bytecount = &data->req.bytecount;
char *gopherpath; char *gopherpath;
char *path = data->state.up.path; char *path = data->state.up.path;
char *query = data->state.up.query; char *query = data->state.up.query;
Expand Down Expand Up @@ -167,8 +165,7 @@ static CURLcode gopher_do(struct connectdata *conn, bool *done)
if(result) if(result)
return result; return result;


Curl_setup_transfer(conn, FIRSTSOCKET, -1, FALSE, bytecount, Curl_setup_transfer(data, FIRSTSOCKET, -1, FALSE, -1);
-1, NULL); /* no upload */
return CURLE_OK; return CURLE_OK;
} }
#endif /*CURL_DISABLE_GOPHER*/ #endif /*CURL_DISABLE_GOPHER*/
Loading

0 comments on commit 65eb65f

Please sign in to comment.