Loading lib/formdata.c +54 −44 Original line number Diff line number Diff line Loading @@ -176,7 +176,7 @@ int FormParse(char *input, struct curl_httppost **httppost, struct curl_httppost **last_post) { /* nextarg MUST be a string in the format 'name=contents' and we'll /* 'input' MUST be a string in the format 'name=contents' and we'll build a linked list with the info */ char name[256]; char *contents; Loading Loading @@ -975,6 +975,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, return return_value; } /* * curl_formadd() is a public API to add a section to the multipart formpost. */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...) Loading @@ -987,6 +991,9 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost, return result; } /* * AddFormData() adds a chunk of data to the FormData linked list. */ static size_t AddFormData(struct FormData **formp, const void *line, size_t length) Loading Loading @@ -1014,6 +1021,9 @@ static size_t AddFormData(struct FormData **formp, return length; } /* * AddFormDataf() adds printf()-style formatted data to the formdata chain. */ static size_t AddFormDataf(struct FormData **formp, const char *fmt, ...) Loading @@ -1027,7 +1037,10 @@ static size_t AddFormDataf(struct FormData **formp, return AddFormData(formp, s, 0); } /* * Curl_FormBoundary() creates a suitable boundary string and returns an * allocated one. */ char *Curl_FormBoundary(void) { char *retstring; Loading Loading @@ -1056,7 +1069,10 @@ char *Curl_FormBoundary(void) return retstring; } /* Used from http.c, this cleans a built FormData linked list */ /* * Curl_formclean() is used from http.c, this cleans a built FormData linked * list */ void Curl_formclean(struct FormData *form) { struct FormData *next; Loading @@ -1069,7 +1085,10 @@ void Curl_formclean(struct FormData *form) } while((form=next)); /* continue */ } /* external function to free up a whole form post chain */ /* * curl_formfree() is an external function to free up a whole form post * chain */ void curl_formfree(struct curl_httppost *form) { struct curl_httppost *next; Loading Loading @@ -1098,6 +1117,13 @@ void curl_formfree(struct curl_httppost *form) } while((form=next)); /* continue */ } /* * Curl_getFormData() converts a linked list of "meta data" into a complete * (possibly huge) multipart formdata. The input list is in 'post', while the * output resulting linked lists gets stored in '*finalform'. *sizep will get * the total size of the whole POST. */ CURLcode Curl_getFormData(struct FormData **finalform, struct curl_httppost *post, curl_off_t *sizep) Loading Loading @@ -1278,6 +1304,10 @@ CURLcode Curl_getFormData(struct FormData **finalform, return result; } /* * Curl_FormInit() inits the struct 'form' points to with the 'formdata' * and resets the 'sent' counter. */ int Curl_FormInit(struct Form *form, struct FormData *formdata ) { if(!formdata) Loading @@ -1289,7 +1319,10 @@ int Curl_FormInit(struct Form *form, struct FormData *formdata ) return 0; } /* fread() emulation */ /* * Curl_FormReader() is the fread() emulation function that will be used to * deliver the formdata to the transfer loop and then sent away to the peer. */ size_t Curl_FormReader(char *buffer, size_t size, size_t nitems, Loading Loading @@ -1335,48 +1368,25 @@ size_t Curl_FormReader(char *buffer, return gotsize; } /* possible (old) fread() emulation that copies at most one line */ size_t Curl_FormReadOneLine(char *buffer, size_t size, size_t nitems, FILE *mydata) /* * Curl_formpostheader() returns the first line of the formpost, the * request-header part (which is not part of the request-body like the rest of * the post). */ char *Curl_formpostheader(void *formp, size_t *len) { struct Form *form; size_t wantedsize; size_t gotsize; form=(struct Form *)mydata; wantedsize = size * nitems; char *header; struct Form *form=(struct Form *)formp; if(!form->data) return 0; /* nothing, error, empty */ do { if( (form->data->length - form->sent ) > wantedsize ) { memcpy(buffer, form->data->line + form->sent, wantedsize); return 0; /* nothing, ERROR! */ form->sent += wantedsize; return wantedsize; } memcpy(buffer, form->data->line + form->sent, gotsize = (form->data->length - form->sent) ); form->sent = 0; header = form->data->line; *len = form->data->length; form->data = form->data->next; /* advance */ } while(!gotsize && form->data); /* If we got an empty line and we have more data, we proceed to the next line immediately to avoid returning zero before we've reached the end. This is the bug reported November 22 1999 on curl 6.3. (Daniel) */ return gotsize; return header; } Loading lib/formdata.h +6 −5 Original line number Diff line number Diff line Loading @@ -65,11 +65,12 @@ size_t Curl_FormReader(char *buffer, size_t nitems, FILE *mydata); /* possible (old) fread() emulation that copies at most one line */ size_t Curl_FormReadOneLine(char *buffer, size_t size, size_t nitems, FILE *mydata); /* * Curl_formpostheader() returns the first line of the formpost, the * request-header part (which is not part of the request-body like the rest of * the post). */ char *Curl_formpostheader(void *formp, size_t *len); char *Curl_FormBoundary(void); Loading lib/http.c +5 −7 Original line number Diff line number Diff line Loading @@ -1686,7 +1686,7 @@ CURLcode Curl_http(struct connectdata *conn) } if(!checkheaders(data, "Content-Type:")) { /* Get Content-Type: line from Curl_FormReadOneLine, which happens /* Get Content-Type: line from Curl_formpostheader, which happens to always be the first line. We can know this for sure since we always build the formpost linked list the same way! Loading @@ -1694,13 +1694,11 @@ CURLcode Curl_http(struct connectdata *conn) string etc why disabling this header is likely to not make things work, but we support it anyway. */ char contentType[256]; char *contentType; size_t linelength=0; linelength = Curl_FormReadOneLine(contentType, sizeof(contentType), 1, (FILE *)&http->form); if(!linelength) { contentType = Curl_formpostheader((void *)&http->form, &linelength); if(!contentType) { failf(data, "Could not get Content-Type header line!"); return CURLE_HTTP_POST_ERROR; } Loading Loading
lib/formdata.c +54 −44 Original line number Diff line number Diff line Loading @@ -176,7 +176,7 @@ int FormParse(char *input, struct curl_httppost **httppost, struct curl_httppost **last_post) { /* nextarg MUST be a string in the format 'name=contents' and we'll /* 'input' MUST be a string in the format 'name=contents' and we'll build a linked list with the info */ char name[256]; char *contents; Loading Loading @@ -975,6 +975,10 @@ CURLFORMcode FormAdd(struct curl_httppost **httppost, return return_value; } /* * curl_formadd() is a public API to add a section to the multipart formpost. */ CURLFORMcode curl_formadd(struct curl_httppost **httppost, struct curl_httppost **last_post, ...) Loading @@ -987,6 +991,9 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost, return result; } /* * AddFormData() adds a chunk of data to the FormData linked list. */ static size_t AddFormData(struct FormData **formp, const void *line, size_t length) Loading Loading @@ -1014,6 +1021,9 @@ static size_t AddFormData(struct FormData **formp, return length; } /* * AddFormDataf() adds printf()-style formatted data to the formdata chain. */ static size_t AddFormDataf(struct FormData **formp, const char *fmt, ...) Loading @@ -1027,7 +1037,10 @@ static size_t AddFormDataf(struct FormData **formp, return AddFormData(formp, s, 0); } /* * Curl_FormBoundary() creates a suitable boundary string and returns an * allocated one. */ char *Curl_FormBoundary(void) { char *retstring; Loading Loading @@ -1056,7 +1069,10 @@ char *Curl_FormBoundary(void) return retstring; } /* Used from http.c, this cleans a built FormData linked list */ /* * Curl_formclean() is used from http.c, this cleans a built FormData linked * list */ void Curl_formclean(struct FormData *form) { struct FormData *next; Loading @@ -1069,7 +1085,10 @@ void Curl_formclean(struct FormData *form) } while((form=next)); /* continue */ } /* external function to free up a whole form post chain */ /* * curl_formfree() is an external function to free up a whole form post * chain */ void curl_formfree(struct curl_httppost *form) { struct curl_httppost *next; Loading Loading @@ -1098,6 +1117,13 @@ void curl_formfree(struct curl_httppost *form) } while((form=next)); /* continue */ } /* * Curl_getFormData() converts a linked list of "meta data" into a complete * (possibly huge) multipart formdata. The input list is in 'post', while the * output resulting linked lists gets stored in '*finalform'. *sizep will get * the total size of the whole POST. */ CURLcode Curl_getFormData(struct FormData **finalform, struct curl_httppost *post, curl_off_t *sizep) Loading Loading @@ -1278,6 +1304,10 @@ CURLcode Curl_getFormData(struct FormData **finalform, return result; } /* * Curl_FormInit() inits the struct 'form' points to with the 'formdata' * and resets the 'sent' counter. */ int Curl_FormInit(struct Form *form, struct FormData *formdata ) { if(!formdata) Loading @@ -1289,7 +1319,10 @@ int Curl_FormInit(struct Form *form, struct FormData *formdata ) return 0; } /* fread() emulation */ /* * Curl_FormReader() is the fread() emulation function that will be used to * deliver the formdata to the transfer loop and then sent away to the peer. */ size_t Curl_FormReader(char *buffer, size_t size, size_t nitems, Loading Loading @@ -1335,48 +1368,25 @@ size_t Curl_FormReader(char *buffer, return gotsize; } /* possible (old) fread() emulation that copies at most one line */ size_t Curl_FormReadOneLine(char *buffer, size_t size, size_t nitems, FILE *mydata) /* * Curl_formpostheader() returns the first line of the formpost, the * request-header part (which is not part of the request-body like the rest of * the post). */ char *Curl_formpostheader(void *formp, size_t *len) { struct Form *form; size_t wantedsize; size_t gotsize; form=(struct Form *)mydata; wantedsize = size * nitems; char *header; struct Form *form=(struct Form *)formp; if(!form->data) return 0; /* nothing, error, empty */ do { if( (form->data->length - form->sent ) > wantedsize ) { memcpy(buffer, form->data->line + form->sent, wantedsize); return 0; /* nothing, ERROR! */ form->sent += wantedsize; return wantedsize; } memcpy(buffer, form->data->line + form->sent, gotsize = (form->data->length - form->sent) ); form->sent = 0; header = form->data->line; *len = form->data->length; form->data = form->data->next; /* advance */ } while(!gotsize && form->data); /* If we got an empty line and we have more data, we proceed to the next line immediately to avoid returning zero before we've reached the end. This is the bug reported November 22 1999 on curl 6.3. (Daniel) */ return gotsize; return header; } Loading
lib/formdata.h +6 −5 Original line number Diff line number Diff line Loading @@ -65,11 +65,12 @@ size_t Curl_FormReader(char *buffer, size_t nitems, FILE *mydata); /* possible (old) fread() emulation that copies at most one line */ size_t Curl_FormReadOneLine(char *buffer, size_t size, size_t nitems, FILE *mydata); /* * Curl_formpostheader() returns the first line of the formpost, the * request-header part (which is not part of the request-body like the rest of * the post). */ char *Curl_formpostheader(void *formp, size_t *len); char *Curl_FormBoundary(void); Loading
lib/http.c +5 −7 Original line number Diff line number Diff line Loading @@ -1686,7 +1686,7 @@ CURLcode Curl_http(struct connectdata *conn) } if(!checkheaders(data, "Content-Type:")) { /* Get Content-Type: line from Curl_FormReadOneLine, which happens /* Get Content-Type: line from Curl_formpostheader, which happens to always be the first line. We can know this for sure since we always build the formpost linked list the same way! Loading @@ -1694,13 +1694,11 @@ CURLcode Curl_http(struct connectdata *conn) string etc why disabling this header is likely to not make things work, but we support it anyway. */ char contentType[256]; char *contentType; size_t linelength=0; linelength = Curl_FormReadOneLine(contentType, sizeof(contentType), 1, (FILE *)&http->form); if(!linelength) { contentType = Curl_formpostheader((void *)&http->form, &linelength); if(!contentType) { failf(data, "Could not get Content-Type header line!"); return CURLE_HTTP_POST_ERROR; } Loading