aboutsummaryrefslogtreecommitdiff
path: root/lib/formdata.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2010-10-20 14:57:43 +0200
committerDaniel Stenberg <daniel@haxx.se>2010-10-20 14:57:43 +0200
commite8c442952d53d493e347a784d53d602359b4331c (patch)
tree55badc6bfb21ea296aa795ac6ab2d8cef0bd376e /lib/formdata.c
parent98d9dc78407eff15ebf566fe08df2e1b4fd18baf (diff)
formdata: provide error message
When failing to build form post due to an error, the code now does a proper failf(). Previously libcurl would report an error like "failed creating formpost data" when a file wasn't possible to open which was not easy for users to figure out. I also lower cased a function name to be named more curl-style and removed some unnecessary code.
Diffstat (limited to 'lib/formdata.c')
-rw-r--r--lib/formdata.c72
1 files changed, 21 insertions, 51 deletions
diff --git a/lib/formdata.c b/lib/formdata.c
index c98246e20..07d7a6b42 100644
--- a/lib/formdata.c
+++ b/lib/formdata.c
@@ -123,6 +123,7 @@ Content-Disposition: form-data; name="FILECONTENT"
#include "curl_rand.h"
#include "strequal.h"
#include "curl_memory.h"
+#include "sendf.h"
#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -975,7 +976,7 @@ int curl_formget(struct curl_httppost *form, void *arg,
curl_off_t size;
struct FormData *data, *ptr;
- rc = Curl_getFormData(&data, form, NULL, &size);
+ rc = Curl_getformdata(NULL, &data, form, NULL, &size);
if(rc != CURLE_OK)
return (int)rc;
@@ -1105,15 +1106,20 @@ static char *strippath(const char *fullfile)
}
/*
- * Curl_getFormData() converts a linked list of "meta data" into a complete
+ * 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.
* A multipart/form_data content-type is built, unless a custom content-type
* is passed in 'custom_content_type'.
+ *
+ * This function will not do a failf() for the potential memory failures but
+ * should for all other errors it spots. Just note that this function MAY get
+ * a NULL pointer in the 'data' argument.
*/
-CURLcode Curl_getFormData(struct FormData **finalform,
+CURLcode Curl_getformdata(struct SessionHandle *data,
+ struct FormData **finalform,
struct curl_httppost *post,
const char *custom_content_type,
curl_off_t *sizep)
@@ -1271,23 +1277,6 @@ CURLcode Curl_getFormData(struct FormData **finalform,
return result;
}
-#if 0
- /* The header Content-Transfer-Encoding: seems to confuse some receivers
- * (like the built-in PHP engine). While I can't see any reason why it
- * should, I can just as well skip this to the benefit of the users who
- * are using such confused receivers.
- */
-
- if(file->contenttype &&
- !checkprefix("text/", file->contenttype)) {
- /* this is not a text content, mention our binary encoding */
- result = AddFormDataf(&form, &size,
- "\r\nContent-Transfer-Encoding: binary");
- if(result)
- break;
- }
-#endif
-
result = AddFormDataf(&form, &size, "\r\n\r\n");
if(result)
break;
@@ -1327,50 +1316,31 @@ CURLcode Curl_getFormData(struct FormData **finalform,
break;
}
}
-
- if(result) {
- Curl_formclean(&firstform);
- free(boundary);
- return result;
- }
-
}
else {
-#ifdef _FORM_DEBUG
- fprintf(stderr,
- "\n==> Curl_getFormData couldn't open/read \"%s\"\n",
- file->contents);
-#endif
- Curl_formclean(&firstform);
- free(boundary);
+ if(data)
+ failf(data, "couldn't open file \"%s\"\n", file->contents);
*finalform = NULL;
- return CURLE_READ_ERROR;
+ result = CURLE_READ_ERROR;
}
-
}
- else if(post->flags & HTTPPOST_BUFFER) {
+ else if(post->flags & HTTPPOST_BUFFER)
/* include contents of buffer */
result = AddFormData(&form, FORM_CONTENT, post->buffer,
post->bufferlength, &size);
- if(result)
- break;
- }
- else if(post->flags & HTTPPOST_CALLBACK) {
+ else if(post->flags & HTTPPOST_CALLBACK)
/* 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);
- if(result)
- break;
- }
- else {
+ else
/* include the contents we got */
result = AddFormData(&form, FORM_CONTENT, post->contents,
post->contentslength, &size);
- if(result)
- break;
- }
- } while((file = file->more) != NULL); /* for each specified file for this field */
+
+ file = file->more;
+ } while(file && !result); /* for each specified file for this field */
+
if(result) {
Curl_formclean(&firstform);
free(boundary);
@@ -1666,11 +1636,11 @@ int main(int argc, argv_item_t argv[])
CURLFORM_END))
++errors;
- rc = Curl_getFormData(&form, httppost, NULL, &size);
+ rc = Curl_getformdata(NULL, &form, httppost, NULL, &size);
if(rc != CURLE_OK) {
if(rc != CURLE_READ_ERROR) {
const char *errortext = curl_easy_strerror(rc);
- fprintf(stdout, "\n==> Curl_getFormData error: %s\n", errortext);
+ fprintf(stdout, "\n==> Curl_getformdata error: %s\n", errortext);
}
return 0;
}