aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPatrick Monnerat <Patrick.Monnerat@datasphere.ch>2007-10-15 18:32:01 +0000
committerPatrick Monnerat <Patrick.Monnerat@datasphere.ch>2007-10-15 18:32:01 +0000
commita005243908803662d4a05427bc1061db42f4d057 (patch)
treeca68d875dbccc05d8f97c9e3451b9c22977d1350 /lib
parent001a2d9b67f3bf685c5a2df6495b999cc3966acc (diff)
Fix dynamic CURLOPT_POSTFIELDS bug: back to static.
CURLOPT_COPYPOSTFIELDS option added for dynamic. Fix some OS400 features.
Diffstat (limited to 'lib')
-rw-r--r--lib/config-os400.h3
-rw-r--r--lib/http.c11
-rw-r--r--lib/transfer.c2
-rw-r--r--lib/url.c69
-rw-r--r--lib/urldata.h3
5 files changed, 75 insertions, 13 deletions
diff --git a/lib/config-os400.h b/lib/config-os400.h
index 6eccff1e7..5e30e435d 100644
--- a/lib/config-os400.h
+++ b/lib/config-os400.h
@@ -361,6 +361,9 @@
/* The size of a `long double', as computed by sizeof. */
#define SIZEOF_LONG_DOUBLE 8
+/* Define if 64 bit integers are supported. */
+#define HAVE_LONGLONG
+
/* The size of a `long long', as computed by sizeof. */
#define SIZEOF_LONG_LONG 8
diff --git a/lib/http.c b/lib/http.c
index 9839912d7..d3954338f 100644
--- a/lib/http.c
+++ b/lib/http.c
@@ -2554,8 +2554,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* figure out the size of the postfields */
postsize = (data->set.postfieldsize != -1)?
data->set.postfieldsize:
- (data->set.str[STRING_POSTFIELDS]?
- (curl_off_t)strlen(data->set.str[STRING_POSTFIELDS]):0);
+ (data->set.postfields? (curl_off_t)strlen(data->set.postfields):0);
if(!conn->bits.upload_chunky) {
/* We only set Content-Length and allow a custom Content-Length if
@@ -2580,7 +2579,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
return result;
}
- if(data->set.str[STRING_POSTFIELDS]) {
+ if(data->set.postfields) {
/* for really small posts we don't use Expect: headers at all, and for
the somewhat bigger ones we allow the app to disable it */
@@ -2608,7 +2607,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
if(!conn->bits.upload_chunky) {
/* We're not sending it 'chunked', append it to the request
already now to reduce the number if send() calls */
- result = add_buffer(req_buffer, data->set.str[STRING_POSTFIELDS],
+ result = add_buffer(req_buffer, data->set.postfields,
(size_t)postsize);
included_body = postsize;
}
@@ -2616,7 +2615,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
/* Append the POST data chunky-style */
result = add_bufferf(req_buffer, "%x\r\n", (int)postsize);
if(CURLE_OK == result)
- result = add_buffer(req_buffer, data->set.str[STRING_POSTFIELDS],
+ result = add_buffer(req_buffer, data->set.postfields,
(size_t)postsize);
if(CURLE_OK == result)
result = add_buffer(req_buffer,
@@ -2630,7 +2629,7 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
else {
/* A huge POST coming up, do data separate from the request */
http->postsize = postsize;
- http->postdata = data->set.str[STRING_POSTFIELDS];
+ http->postdata = data->set.postfields;
http->sending = HTTPSEND_BODY;
diff --git a/lib/transfer.c b/lib/transfer.c
index 831cb3e98..d36f55f79 100644
--- a/lib/transfer.c
+++ b/lib/transfer.c
@@ -233,7 +233,7 @@ CURLcode Curl_readrewind(struct connectdata *conn)
/* We have sent away data. If not using CURLOPT_POSTFIELDS or
CURLOPT_HTTPPOST, call app to rewind
*/
- if(data->set.str[STRING_POSTFIELDS] ||
+ if(data->set.postfields ||
(data->set.httpreq == HTTPREQ_POST_FORM))
; /* do nothing */
else {
diff --git a/lib/url.c b/lib/url.c
index e6b0d7f27..35dce9541 100644
--- a/lib/url.c
+++ b/lib/url.c
@@ -771,6 +771,7 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
va_list param)
{
char *argptr;
+ curl_off_t bigsize;
CURLcode result = CURLE_OK;
switch(option) {
@@ -1029,12 +1030,52 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
data->set.httpreq = HTTPREQ_GET;
break;
- case CURLOPT_POSTFIELDS:
+ case CURLOPT_COPYPOSTFIELDS:
/*
* A string with POST data. Makes curl HTTP POST. Even if it is NULL.
+ * If needed, CURLOPT_POSTFIELDSIZE must have been set prior to
+ * CURLOPT_COPYPOSTFIELDS and not altered later.
*/
- result = Curl_setstropt(&data->set.str[STRING_POSTFIELDS],
- va_arg(param, char *));
+ argptr = va_arg(param, char *);
+
+ if (!argptr || data->set.postfieldsize == -1)
+ result = Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], argptr);
+ else {
+ /*
+ * Check that request length does not overflow the size_t type.
+ */
+
+ if ((curl_off_t) ((size_t) data->set.postfieldsize) !=
+ data->set.postfieldsize ||
+ data->set.postfieldsize < (curl_off_t) 0 ||
+ (size_t) data->set.postfieldsize < (size_t) 0)
+ result = CURLE_OUT_OF_MEMORY;
+ else {
+ char * p;
+
+ (void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
+ p = malloc(data->set.postfieldsize);
+
+ if (!p)
+ result = CURLE_OUT_OF_MEMORY;
+ else {
+ memcpy(p, argptr, data->set.postfieldsize);
+ data->set.str[STRING_COPYPOSTFIELDS] = p;
+ }
+ }
+ }
+
+ data->set.postfields = data->set.str[STRING_COPYPOSTFIELDS];
+ data->set.httpreq = HTTPREQ_POST;
+ break;
+
+ case CURLOPT_POSTFIELDS:
+ /*
+ * Like above, but use static data instead of copying it.
+ */
+ data->set.postfields = va_arg(param, void *);
+ /* Release old copied data. */
+ (void) Curl_setstropt(&data->set.str[STRING_COPYPOSTFIELDS], NULL);
data->set.httpreq = HTTPREQ_POST;
break;
@@ -1043,7 +1084,16 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
* figure it out. Enables binary posts.
*/
- data->set.postfieldsize = va_arg(param, long);
+ bigsize = va_arg(param, long);
+
+ if (data->set.postfieldsize < 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;
break;
case CURLOPT_POSTFIELDSIZE_LARGE:
@@ -1051,7 +1101,16 @@ CURLcode Curl_setopt(struct SessionHandle *data, CURLoption option,
* The size of the POSTFIELD data to prevent libcurl to do strlen() to
* figure it out. Enables binary posts.
*/
- data->set.postfieldsize = va_arg(param, curl_off_t);
+ bigsize = va_arg(param, curl_off_t);
+
+ if (data->set.postfieldsize < 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;
break;
case CURLOPT_HTTPPOST:
diff --git a/lib/urldata.h b/lib/urldata.h
index ef685e183..8ee1d1989 100644
--- a/lib/urldata.h
+++ b/lib/urldata.h
@@ -1286,7 +1286,7 @@ enum dupstring {
STRING_KRB_LEVEL, /* krb security level */
STRING_NETRC_FILE, /* if not NULL, use this instead of trying to find
$HOME/.netrc */
- STRING_POSTFIELDS, /* if POST, set the fields' values here */
+ STRING_COPYPOSTFIELDS, /* if POST, set the fields' values here */
STRING_PROXY, /* proxy to use */
STRING_PROXYUSERPWD, /* Proxy <user:password>, if used */
STRING_SET_RANGE, /* range, if used */
@@ -1326,6 +1326,7 @@ struct UserDefined {
bool post301; /* Obey RFC 2616/10.3.2 and keep POSTs as POSTs after a 301 */
bool free_referer; /* set TRUE if 'referer' points to a string we
allocated */
+ void *postfields; /* if POST, set the fields' values here */
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) */