summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2020-06-24 15:48:39 +0200
committerDaniel Stenberg <daniel@haxx.se>2020-06-24 15:48:39 +0200
commit62241fa99f73d4d99d1af50c402a67701e0e5d79 (patch)
treeae452d7b7d688816f117561a0b82a609a6594c35
parent7fb33ee871a04d2e4f6ffedba0808635efb1ef53 (diff)
downloadcurl-bagder/filesize-unite.tar.gz
setopt: make INFILESIZE and POSTFIELDSIZE do the same thingbagder/filesize-unite
They're both used to set the size of the request body so let's treat them as identical internally.
-rw-r--r--lib/easy.c6
-rw-r--r--lib/mqtt.c2
-rw-r--r--lib/setopt.c44
-rw-r--r--lib/transfer.c2
-rw-r--r--lib/url.c1
-rw-r--r--lib/urldata.h3
6 files changed, 18 insertions, 40 deletions
diff --git a/lib/easy.c b/lib/easy.c
index 292cca7f6..4c8fa3455 100644
--- a/lib/easy.c
+++ b/lib/easy.c
@@ -793,10 +793,10 @@ static CURLcode dupset(struct Curl_easy *dst, struct Curl_easy *src)
/* duplicate memory areas pointed to */
i = STRING_COPYPOSTFIELDS;
- if(src->set.postfieldsize && src->set.str[i]) {
- /* postfieldsize is curl_off_t, Curl_memdup() takes a size_t ... */
+ if(src->set.filesize && src->set.str[i]) {
+ /* filesize is curl_off_t, Curl_memdup() takes a size_t ... */
dst->set.str[i] = Curl_memdup(src->set.str[i],
- curlx_sotouz(src->set.postfieldsize));
+ curlx_sotouz(src->set.filesize));
if(!dst->set.str[i])
return CURLE_OUT_OF_MEMORY;
/* point to the new copy */
diff --git a/lib/mqtt.c b/lib/mqtt.c
index d09aab4ee..c8f011a14 100644
--- a/lib/mqtt.c
+++ b/lib/mqtt.c
@@ -319,7 +319,7 @@ static CURLcode mqtt_publish(struct connectdata *conn)
{
CURLcode result;
char *payload = conn->data->set.postfields;
- size_t payloadlen = (size_t)conn->data->set.postfieldsize;
+ size_t payloadlen = (size_t)conn->data->set.filesize;
char *topic = NULL;
size_t topiclen;
unsigned char *pkt = NULL;
diff --git a/lib/setopt.c b/lib/setopt.c
index 90edf6aa7..82233a41b 100644
--- a/lib/setopt.c
+++ b/lib/setopt.c
@@ -534,16 +534,16 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
*/
argptr = va_arg(param, char *);
- if(!argptr || data->set.postfieldsize == -1)
+ if(!argptr || data->set.filesize == -1)
result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
else {
/*
* Check that requested length does not overflow the size_t type.
*/
- if((data->set.postfieldsize < 0) ||
+ if((data->set.filesize < 0) ||
((sizeof(curl_off_t) != sizeof(size_t)) &&
- (data->set.postfieldsize > (curl_off_t)((size_t)-1))))
+ (data->set.filesize > (curl_off_t)((size_t)-1))))
result = CURLE_OUT_OF_MEMORY;
else {
char *p;
@@ -555,14 +555,14 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
to mark that postfields is used rather than read function or
form data.
*/
- p = malloc((size_t)(data->set.postfieldsize?
- data->set.postfieldsize:1));
+ p = malloc((size_t)(data->set.filesize?
+ data->set.filesize:1));
if(!p)
result = CURLE_OUT_OF_MEMORY;
else {
- if(data->set.postfieldsize)
- memcpy(p, argptr, (size_t)data->set.postfieldsize);
+ if(data->set.filesize)
+ memcpy(p, argptr, (size_t)data->set.filesize);
data->set.str[STRING_COPYPOSTFIELDS] = p;
}
@@ -583,6 +583,7 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
data->set.method = HTTPREQ_POST;
break;
+ case CURLOPT_INFILESIZE:
case CURLOPT_POSTFIELDSIZE:
/*
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
@@ -592,16 +593,17 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
if(bigsize < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
- if(data->set.postfieldsize < bigsize &&
+ if(data->set.filesize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
data->set.postfields = NULL;
}
- data->set.postfieldsize = bigsize;
+ data->set.filesize = bigsize;
break;
+ case CURLOPT_INFILESIZE_LARGE:
case CURLOPT_POSTFIELDSIZE_LARGE:
/*
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
@@ -611,14 +613,14 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
if(bigsize < -1)
return CURLE_BAD_FUNCTION_ARGUMENT;
- if(data->set.postfieldsize < bigsize &&
+ if(data->set.filesize < bigsize &&
data->set.postfields == data->set.str[STRING_COPYPOSTFIELDS]) {
/* Previous CURLOPT_COPYPOSTFIELDS is no longer valid. */
(void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
data->set.postfields = NULL;
}
- data->set.postfieldsize = bigsize;
+ data->set.filesize = bigsize;
break;
case CURLOPT_HTTPPOST:
@@ -1243,26 +1245,6 @@ CURLcode Curl_vsetopt(struct Curl_easy *data, CURLoption option, va_list param)
*/
data->set.in_set = va_arg(param, void *);
break;
- case CURLOPT_INFILESIZE:
- /*
- * If known, this should inform curl about the file size of the
- * to-be-uploaded file.
- */
- arg = va_arg(param, long);
- if(arg < -1)
- return CURLE_BAD_FUNCTION_ARGUMENT;
- data->set.filesize = arg;
- break;
- case CURLOPT_INFILESIZE_LARGE:
- /*
- * If known, this should inform curl about the file size of the
- * to-be-uploaded file.
- */
- bigsize = va_arg(param, curl_off_t);
- if(bigsize < -1)
- return CURLE_BAD_FUNCTION_ARGUMENT;
- data->set.filesize = bigsize;
- break;
case CURLOPT_LOW_SPEED_LIMIT:
/*
* The low speed limit that if transfers are below this for
diff --git a/lib/transfer.c b/lib/transfer.c
index 133a4783c..514cb1423 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -1474,7 +1474,7 @@ CURLcode Curl_pretransfer(struct Curl_easy *data)
data->state.infilesize = data->set.filesize;
else if((data->state.httpreq != HTTPREQ_GET) &&
(data->state.httpreq != HTTPREQ_HEAD)) {
- data->state.infilesize = data->set.postfieldsize;
+ data->state.infilesize = data->set.filesize;
if(data->set.postfields && (data->state.infilesize == -1))
data->state.infilesize = (curl_off_t)strlen(data->set.postfields);
}
diff --git a/lib/url.c b/lib/url.c
index 8225e617a..be4b95f45 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -470,7 +470,6 @@ CURLcode Curl_init_userdefined(struct Curl_easy *data)
set->convfromutf8 = ZERO_NULL;
set->filesize = -1; /* we don't know the size */
- set->postfieldsize = -1; /* unknown size */
set->maxredirs = -1; /* allow any amount by default */
set->method = HTTPREQ_GET; /* Default HTTP request */
diff --git a/lib/urldata.h b/lib/urldata.h
index 74b43abaa..0daa6d432 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1612,9 +1612,6 @@ struct UserDefined {
bit represents a request, from 301 to 303 */
void *postfields; /* if POST, set the fields' values here */
curl_seek_callback seek_func; /* function that seeks the input */
- curl_off_t postfieldsize; /* if POST, this might have a size to use instead
- of strlen(), and then the data *may* be binary
- (contain zero bytes) */
unsigned short localport; /* local port number to bind to */
int localportrange; /* number of additional port numbers to test in case the
'localport' one can't be bind()ed */