curl-library
[PATCH] Use -1, not 0, to reset values of progress.size_dl and progress.size_ul
Date: Wed, 27 Aug 2014 03:09:40 -0700
Commit 223d8481 changed the behavior of Curl_pgrsSetDownloadSize() and
Curl_pgrsSetUploadSize() to allow a size of 0 to be interpreted as
valid and set the "KNOWN" bit in the progress.flags. But, the call
sites that passed 0 to these functions as a way of resetting them and
clearing the "KNOWN" bit were not updated. This has gone unnoticed for
a long time.
Recently commit c44d45db added a call to each of these functions in
Curl_pgrsResetTimesSizes() to reset them after each HTTP redirect, and
again, 0 was passed in as the initialization value.
Since 0 no longer resets the "KNOWN" bit in progress.flags, this
makes it impossible to distinguish between a redirected HTTP request
that did not supply a content-length field in the HTTP header and
one that supplied a value of 0. Instead of passing in 0 to reset
the download size and the upload size, let's pass in -1. This will
make Curl_pgrsSetDownloadSize() and Curl_pgrsSetUploadSize() clear
their respective "KNOWN" bits in progress.flags and will allow
curl_easy_getinfo() to return -1 appropriately when
CURLINFO_CONTENT_LENGTH_DOWNLOAD or CURLINFO_CONTENT_LENGTH_UPLOAD
is requested.
Adjust test599 to test this behavior.
Signed-off-by: Brandon Casey <drafnel_at_gmail.com>
---
lib/ftp.c | 4 ++--
lib/http.c | 2 +-
lib/imap.c | 6 +++---
lib/pop3.c | 4 ++--
lib/progress.c | 4 ++--
lib/smtp.c | 4 ++--
lib/ssh.c | 4 ++--
tests/data/test599 | 6 ++++--
tests/libtest/lib599.c | 12 ++++++++++++
9 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/lib/ftp.c b/lib/ftp.c
index 4c4396a..715afc2 100644
--- a/lib/ftp.c
+++ b/lib/ftp.c
@@ -4470,8 +4470,8 @@ CURLcode ftp_regular_transfer(struct connectdata *conn,
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetUploadSize(data, -1);
+ Curl_pgrsSetDownloadSize(data, -1);
ftpc->ctl_valid = TRUE; /* starts good */
diff --git a/lib/http.c b/lib/http.c
index 3fdab27..35baa34 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2351,7 +2351,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
return result;
http->postdata = NULL; /* nothing to post at this point */
- Curl_pgrsSetUploadSize(data, 0); /* upload size is 0 atm */
+ Curl_pgrsSetUploadSize(data, -1); /* upload size is unknown atm */
/* If 'authdone' is FALSE, we must not set the write socket index to the
Curl_transfer() call below, as we're not ready to actually upload any
diff --git a/lib/imap.c b/lib/imap.c
index e80bc03..9fc4728 100644
--- a/lib/imap.c
+++ b/lib/imap.c
@@ -1662,7 +1662,7 @@ static CURLcode imap_state_fetch_resp(struct connectdata *conn, int imapcode,
(void)instate; /* no use for this yet */
if(imapcode != '*') {
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetDownloadSize(data, -1);
state(conn, IMAP_STOP);
return CURLE_REMOTE_FILE_NOT_FOUND; /* TODO: Fix error code */
}
@@ -2336,8 +2336,8 @@ static CURLcode imap_regular_transfer(struct connectdata *conn,
/* Set the progress data */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetUploadSize(data, -1);
+ Curl_pgrsSetDownloadSize(data, -1);
/* Carry out the perform */
result = imap_perform(conn, &connected, dophase_done);
diff --git a/lib/pop3.c b/lib/pop3.c
index e69f5c5..dc64f81 100644
--- a/lib/pop3.c
+++ b/lib/pop3.c
@@ -1935,8 +1935,8 @@ static CURLcode pop3_regular_transfer(struct connectdata *conn,
/* Set the progress data */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetUploadSize(data, -1);
+ Curl_pgrsSetDownloadSize(data, -1);
/* Carry out the perform */
result = pop3_perform(conn, &connected, dophase_done);
diff --git a/lib/progress.c b/lib/progress.c
index e6a8d82..f7c0507 100644
--- a/lib/progress.c
+++ b/lib/progress.c
@@ -159,8 +159,8 @@ void Curl_pgrsResetTimesSizes(struct SessionHandle *data)
data->progress.t_pretransfer = 0.0;
data->progress.t_starttransfer = 0.0;
- Curl_pgrsSetDownloadSize(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
+ Curl_pgrsSetDownloadSize(data, -1);
+ Curl_pgrsSetUploadSize(data, -1);
}
void Curl_pgrsTime(struct SessionHandle *data, timerid timer)
diff --git a/lib/smtp.c b/lib/smtp.c
index 4dc7849..9aa8b15 100644
--- a/lib/smtp.c
+++ b/lib/smtp.c
@@ -2031,8 +2031,8 @@ static CURLcode smtp_regular_transfer(struct connectdata *conn,
/* Set the progress data */
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetUploadSize(data, -1);
+ Curl_pgrsSetDownloadSize(data, -1);
/* Carry out the perform */
result = smtp_perform(conn, &connected, dophase_done);
diff --git a/lib/ssh.c b/lib/ssh.c
index b248b43..887e10f 100644
--- a/lib/ssh.c
+++ b/lib/ssh.c
@@ -2878,8 +2878,8 @@ static CURLcode ssh_do(struct connectdata *conn, bool *done)
Curl_pgrsSetUploadCounter(data, 0);
Curl_pgrsSetDownloadCounter(data, 0);
- Curl_pgrsSetUploadSize(data, 0);
- Curl_pgrsSetDownloadSize(data, 0);
+ Curl_pgrsSetUploadSize(data, -1);
+ Curl_pgrsSetDownloadSize(data, -1);
if(conn->handler->protocol & CURLPROTO_SCP)
res = scp_perform(conn, &connected, done);
diff --git a/tests/data/test599 b/tests/data/test599
index c57fe5c..9ce8b23 100644
--- a/tests/data/test599
+++ b/tests/data/test599
@@ -71,13 +71,15 @@ lib599
HTTP GET with progress callback and redirects changing content sizes
</name>
<command>
-http://%HOSTIP:%HTTPPORT/599
+http://%HOSTIP:%HTTPPORT/599 log/ip599
</command>
</client>
#
# Verify data after the test has been "shot"
<verify>
-
+<file name="log/ip599">
+CL: -1
+</file>
</verify>
</testcase>
diff --git a/tests/libtest/lib599.c b/tests/libtest/lib599.c
index 6b09267..08c536c 100644
--- a/tests/libtest/lib599.c
+++ b/tests/libtest/lib599.c
@@ -43,6 +43,7 @@ int test(char *URL)
{
CURL *curl;
CURLcode res=CURLE_OK;
+ double content_length = 0.0;
if (curl_global_init(CURL_GLOBAL_ALL) != CURLE_OK) {
fprintf(stderr, "curl_global_init() failed\n");
@@ -74,6 +75,17 @@ int test(char *URL)
/* Perform the request, res will get the return code */
res = curl_easy_perform(curl);
+ if (!res) {
+ FILE *moo;
+ res = curl_easy_getinfo(curl, CURLINFO_CONTENT_LENGTH_DOWNLOAD,
+ &content_length);
+ moo = fopen(libtest_arg2, "wb");
+ if (moo) {
+ fprintf(moo, "CL: %.0f\n", content_length);
+ fclose(moo);
+ }
+ }
+
test_cleanup:
/* always cleanup */
--
2.0.0.rc2
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2014-08-27