summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2003-10-25 16:22:11 +0000
committerJames Bursa <james@netsurf-browser.org>2003-10-25 16:22:11 +0000
commit146011f919db768f3f580f1976bfede88c645824 (patch)
treeef2810cfc851f4b9299c89a8b950db3417184879 /content
parentb514f9e1e35c6ce25a7bdf9b014759c915b77222 (diff)
downloadnetsurf-146011f919db768f3f580f1976bfede88c645824.tar.gz
netsurf-146011f919db768f3f580f1976bfede88c645824.tar.bz2
[project @ 2003-10-25 16:22:11 by bursa]
Implement multipart/formdata POST. svn path=/import/netsurf/; revision=377
Diffstat (limited to 'content')
-rw-r--r--content/fetch.c40
-rw-r--r--content/fetchcache.c24
2 files changed, 55 insertions, 9 deletions
diff --git a/content/fetch.c b/content/fetch.c
index f95d7138b..b7f48b506 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -54,6 +54,7 @@ struct fetch {
unsigned long content_length; /**< Response Content-Length, or 0. */
char *realm; /**< HTTP Auth Realm */
char *post_urlenc; /**< Url encoded POST string, or 0. */
+ struct HttpPost *post_multipart; /**< Multipart post data, or 0. */
struct fetch *queue; /**< Next fetch for this host. */
struct fetch *prev; /**< Previous active fetch in ::fetch_list. */
struct fetch *next; /**< Next active fetch in ::fetch_list. */
@@ -66,6 +67,7 @@ static struct fetch *fetch_list = 0; /**< List of active fetches. */
static size_t fetch_curl_data(void * data, size_t size, size_t nmemb, struct fetch *f);
static size_t fetch_curl_header(char * data, size_t size, size_t nmemb, struct fetch *f);
static bool fetch_process_headers(struct fetch *f);
+static struct HttpPost *fetch_post_convert(struct form_successful_control *control);
#ifdef riscos
static char * ca_bundle; /**< SSL certificate bundle filename. */
@@ -174,8 +176,11 @@ struct fetch * fetch_start(char *url, char *referer,
fetch->host = xstrdup(uri->server);
fetch->content_length = 0;
fetch->post_urlenc = 0;
+ fetch->post_multipart = 0;
if (post_urlenc)
fetch->post_urlenc = xstrdup(post_urlenc);
+ else if (post_multipart)
+ fetch->post_multipart = fetch_post_convert(post_multipart);
fetch->queue = 0;
fetch->prev = 0;
fetch->next = 0;
@@ -275,6 +280,10 @@ struct fetch * fetch_start(char *url, char *referer,
code = curl_easy_setopt(fetch->curl_handle,
CURLOPT_POSTFIELDS, fetch->post_urlenc);
assert(code == CURLE_OK);
+ } else if (fetch->post_multipart) {
+ code = curl_easy_setopt(fetch->curl_handle,
+ CURLOPT_HTTPPOST, fetch->post_multipart);
+ assert(code == CURLE_OK);
}
/* add to the global curl multi handle */
@@ -352,6 +361,15 @@ void fetch_abort(struct fetch *f)
code = curl_easy_setopt(fetch->curl_handle,
CURLOPT_POSTFIELDS, fetch->post_urlenc);
assert(code == CURLE_OK);
+ } else if (fetch->post_multipart) {
+ code = curl_easy_setopt(fetch->curl_handle,
+ CURLOPT_HTTPPOST, fetch->post_multipart);
+ assert(code == CURLE_OK);
+ } else {
+ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_POST, 0);
+ assert(code == CURLE_OK);
+ code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPPOST, 0);
+ assert(code == CURLE_OK);
}
/* add to the global curl multi handle */
@@ -369,6 +387,8 @@ void fetch_abort(struct fetch *f)
free(f->location);
free(f->realm);
free(f->post_urlenc);
+ if (f->post_multipart)
+ curl_formfree(f->post_multipart);
xfree(f);
}
@@ -567,6 +587,26 @@ bool fetch_process_headers(struct fetch *f)
/**
+ * Convert a list of struct ::form_successful_control to a list of
+ * struct HttpPost for libcurl.
+ */
+
+struct HttpPost *fetch_post_convert(struct form_successful_control *control)
+{
+ struct HttpPost *post = 0, *last = 0;
+
+ for (; control; control = control->next) {
+ curl_formadd(&post, &last,
+ CURLFORM_COPYNAME, control->name,
+ CURLFORM_COPYCONTENTS, control->value,
+ CURLFORM_END);
+ }
+
+ return post;
+}
+
+
+/**
* testing framework
*/
diff --git a/content/fetchcache.c b/content/fetchcache.c
index 942f38773..13ddbc9c5 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -55,16 +55,19 @@ struct content * fetchcache(const char *url0, char *referer,
LOG(("url %s", url));
- c = cache_get(url);
- if (c != 0) {
- free(url);
- content_add_user(c, callback, p1, p2);
- return c;
+ if (!post_urlenc && !post_multipart) {
+ c = cache_get(url);
+ if (c != 0) {
+ free(url);
+ content_add_user(c, callback, p1, p2);
+ return c;
+ }
}
c = content_create(url);
content_add_user(c, callback, p1, p2);
- cache_put(c);
+ if (!post_urlenc && !post_multipart)
+ cache_put(c);
c->fetch_size = 0;
c->width = width;
c->height = height;
@@ -73,7 +76,8 @@ struct content * fetchcache(const char *url0, char *referer,
free(url);
if (c->fetch == 0) {
LOG(("warning: fetch_start failed"));
- cache_destroy(c);
+ if (c->cache)
+ cache_destroy(c);
content_destroy(c);
return 0;
}
@@ -132,7 +136,8 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
LOG(("FETCH_ERROR, '%s'", data));
c->fetch = 0;
content_broadcast(c, CONTENT_MSG_ERROR, data);
- cache_destroy(c);
+ if (c->cache)
+ cache_destroy(c);
content_destroy(c);
break;
@@ -144,7 +149,8 @@ void fetchcache_callback(fetch_msg msg, void *p, char *data, unsigned long size)
url = url_join(data, c->url);
content_broadcast(c, CONTENT_MSG_REDIRECT, url);
xfree(url);
- cache_destroy(c);
+ if (c->cache)
+ cache_destroy(c);
content_destroy(c);
break;