diff options
author | Daniel Stenberg <daniel@haxx.se> | 2015-10-24 00:52:25 +0200 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2015-11-02 08:41:46 +0100 |
commit | ca5f9341ef0a941ed478bc5c7e79397b68c2a616 (patch) | |
tree | 0e53c2d2a2c023b961d0baf634259e5e901c66b9 /lib | |
parent | 49a991346e9c6f334d014f16944744a1dac11c64 (diff) |
formadd: support >2GB files on windows
Closes #425
Diffstat (limited to 'lib')
-rw-r--r-- | lib/formdata.c | 41 | ||||
-rw-r--r-- | lib/formdata.h | 4 |
2 files changed, 26 insertions, 19 deletions
diff --git a/lib/formdata.c b/lib/formdata.c index a4e6ab35d..cb061acb7 100644 --- a/lib/formdata.c +++ b/lib/formdata.c @@ -77,7 +77,7 @@ static char *formboundary(struct SessionHandle *data); ***************************************************************************/ static struct curl_httppost * AddHttpPost(char *name, size_t namelength, - char *value, size_t contentslength, + char *value, curl_off_t contentslength, char *buffer, size_t bufferlength, char *contenttype, long flags, @@ -93,14 +93,14 @@ AddHttpPost(char *name, size_t namelength, post->name = name; post->namelength = (long)(name?(namelength?namelength:strlen(name)):0); post->contents = value; - post->contentslength = (long)contentslength; + post->contentlen = contentslength; post->buffer = buffer; post->bufferlength = (long)bufferlength; post->contenttype = contenttype; post->contentheader = contentHeader; post->showfilename = showfilename; post->userp = userp, - post->flags = flags; + post->flags = flags | CURL_HTTPPOST_LARGE; } else return NULL; @@ -380,11 +380,14 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, } break; case CURLFORM_CONTENTSLENGTH: - if(current_form->contentslength) - return_value = CURL_FORMADD_OPTION_TWICE; - else - current_form->contentslength = - array_state?(size_t)array_value:(size_t)va_arg(params, long); + current_form->contentslength = + array_state?(size_t)array_value:(size_t)va_arg(params, long); + break; + + case CURLFORM_CONTENTLEN: + current_form->flags |= CURL_HTTPPOST_LARGE; + current_form->contentslength = + array_state?(curl_off_t)array_value:va_arg(params, curl_off_t); break; /* Get contents from a given file name */ @@ -661,9 +664,12 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, HTTPPOST_PTRCONTENTS | HTTPPOST_PTRBUFFER | HTTPPOST_CALLBACK)) && form->value) { /* copy value (without strdup; possibly contains null characters) */ - form->value = Curl_memdup(form->value, form->contentslength? - form->contentslength: - strlen(form->value)+1); + size_t clen = (size_t) form->contentslength; + if(!clen) + clen = strlen(form->value)+1; + + form->value = Curl_memdup(form->value, clen); + if(!form->value) { return_value = CURL_FORMADD_MEMORY; break; @@ -816,7 +822,7 @@ static curl_off_t VmsSpecialSize(const char * name, static CURLcode AddFormData(struct FormData **formp, enum formtype type, const void *line, - size_t length, + curl_off_t length, curl_off_t *size) { struct FormData *newform = malloc(sizeof(struct FormData)); @@ -1306,15 +1312,16 @@ CURLcode Curl_getformdata(struct SessionHandle *data, result = AddFormData(&form, FORM_CONTENT, post->buffer, post->bufferlength, &size); else if(post->flags & HTTPPOST_CALLBACK) - /* the contents should be read with the callback and the size - is set with the contentslength */ + /* the contents should be read with the callback and the size is set + with the contentslength */ result = AddFormData(&form, FORM_CALLBACK, post->userp, - post->contentslength, &size); + post->flags&CURL_HTTPPOST_LARGE? + post->contentlen:post->contentslength, &size); else /* include the contents we got */ result = AddFormData(&form, FORM_CONTENT, post->contents, - post->contentslength, &size); - + post->flags&CURL_HTTPPOST_LARGE? + post->contentlen:post->contentslength, &size); file = file->more; } while(file && !result); /* for each specified file for this field */ diff --git a/lib/formdata.h b/lib/formdata.h index 22f504bb3..05621e3e8 100644 --- a/lib/formdata.h +++ b/lib/formdata.h @@ -7,7 +7,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2010, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2015, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -54,7 +54,7 @@ typedef struct FormInfo { size_t namelength; char *value; bool value_alloc; - size_t contentslength; + curl_off_t contentslength; char *contenttype; bool contenttype_alloc; long flags; |