aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2006-06-24 21:46:41 +0000
committerDaniel Stenberg <daniel@haxx.se>2006-06-24 21:46:41 +0000
commit37f4877e569cdd0d1afa6bb0d7cd3a463ee75ac9 (patch)
tree92346fb5f8cdc2114f5df2ece56a1544aef380dc /lib
parenta6fc45c02f75467a171f55e5154047c86c0ed85e (diff)
Michael Wallner added curl_formget(), which allows an application to extract
(serialise) a previously built formpost (as with curl_formadd()).
Diffstat (limited to 'lib')
-rw-r--r--lib/formdata.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/lib/formdata.c b/lib/formdata.c
index 86c297745..0fbb23aa7 100644
--- a/lib/formdata.c
+++ b/lib/formdata.c
@@ -5,7 +5,7 @@
* | (__| |_| | _ <| |___
* \___|\___/|_| \_\_____|
*
- * Copyright (C) 1998 - 2005, Daniel Stenberg, <daniel@haxx.se>, et al.
+ * Copyright (C) 1998 - 2006, 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
@@ -137,6 +137,8 @@ Content-Disposition: form-data; name="FILECONTENT"
char *basename(char *path);
#endif
+static size_t readfromfile(struct Form *form, char *buffer, size_t size);
+
/* What kind of Content-Type to use on un-specified files with unrecognized
extensions. */
#define HTTPPOST_CONTENTTYPE_DEFAULT "application/octet-stream"
@@ -886,6 +888,51 @@ void Curl_formclean(struct FormData *form)
}
/*
+ * curl_formget()
+ * Serialize a curl_httppost struct.
+ * Returns 0 on success.
+ */
+int curl_formget(struct curl_httppost *form, void *arg,
+ curl_formget_callback append)
+{
+ CURLFORMcode rc;
+ curl_off_t size;
+ struct FormData *data, *ptr;
+
+ if ((rc = Curl_getFormData(&data, form, &size))) {
+ return (int)rc;
+ }
+
+ for (ptr = data; ptr; ptr = ptr->next) {
+ if (ptr->type == FORM_FILE) {
+ char buffer[8192];
+ size_t read;
+ struct Form temp;
+
+ Curl_FormInit(&temp, ptr);
+
+ do {
+ read = readfromfile(&temp, buffer, sizeof(buffer));
+ if ((read == (size_t) -1) || (read != append(arg, buffer, read))) {
+ if (temp.fp) {
+ fclose(temp.fp);
+ }
+ Curl_formclean(data);
+ return -1;
+ }
+ } while (read == sizeof(buffer));
+ } else {
+ if (ptr->length != append(arg, ptr->line, ptr->length)) {
+ Curl_formclean(data);
+ return -1;
+ }
+ }
+ }
+ Curl_formclean(data);
+ return 0;
+}
+
+/*
* curl_formfree() is an external function to free up a whole form post
* chain
*/
@@ -1284,7 +1331,7 @@ static size_t readfromfile(struct Form *form, char *buffer, size_t size)
nread = fread(buffer, 1, size, form->fp);
if(nread != size) {
- /* this is the last chunk form the file, move on */
+ /* this is the last chunk from the file, move on */
fclose(form->fp);
form->fp = NULL;
form->data = form->data->next;
@@ -1527,6 +1574,15 @@ CURLFORMcode curl_formadd(struct curl_httppost **httppost,
return CURL_FORMADD_DISABLED;
}
+CURLFORMCode curl_formget(struct curl_httppost *post, void *arg,
+ curl_formget_callback append)
+{
+ (void) post;
+ (void) arg;
+ (void) append;
+ return CURL_FORMADD_DISABLED;
+}
+
void curl_formfree(struct curl_httppost *form)
{
(void)form;