diff options
Diffstat (limited to 'content')
-rw-r--r-- | content/fetch.c | 31 | ||||
-rw-r--r-- | content/fetch.h | 4 | ||||
-rw-r--r-- | content/fetchcache.c | 6 | ||||
-rw-r--r-- | content/fetchcache.h | 5 |
4 files changed, 39 insertions, 7 deletions
diff --git a/content/fetch.c b/content/fetch.c index 88b451523..f95d7138b 100644 --- a/content/fetch.c +++ b/content/fetch.c @@ -29,6 +29,7 @@ #endif #include "netsurf/desktop/options.h" #include "netsurf/desktop/401login.h" +#include "netsurf/render/form.h" #include "netsurf/utils/log.h" #include "netsurf/utils/messages.h" #include "netsurf/utils/utils.h" @@ -52,6 +53,7 @@ struct fetch { char *location; /**< Response Location header, or 0. */ unsigned long content_length; /**< Response Content-Length, or 0. */ char *realm; /**< HTTP Auth Realm */ + char *post_urlenc; /**< Url encoded POST string, 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. */ @@ -138,8 +140,9 @@ void fetch_quit(void) */ struct fetch * fetch_start(char *url, char *referer, - void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size), - void *p, bool only_2xx) + void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size), + void *p, bool only_2xx, char *post_urlenc, + struct form_successful_control *post_multipart) { struct fetch *fetch = xcalloc(1, sizeof(*fetch)), *host_fetch; CURLcode code; @@ -170,6 +173,9 @@ struct fetch * fetch_start(char *url, char *referer, if (uri->server != 0) fetch->host = xstrdup(uri->server); fetch->content_length = 0; + fetch->post_urlenc = 0; + if (post_urlenc) + fetch->post_urlenc = xstrdup(post_urlenc); fetch->queue = 0; fetch->prev = 0; fetch->next = 0; @@ -257,10 +263,19 @@ struct fetch * fetch_start(char *url, char *referer, code = curl_easy_setopt(fetch->curl_handle, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC); assert(code == CURLE_OK); +#ifdef riscos if (LOGIN.string != NULL) { code = curl_easy_setopt(fetch->curl_handle, CURLOPT_USERPWD, LOGIN.string); assert(code == CURLE_OK); } +#endif + + /* POST */ + if (fetch->post_urlenc) { + code = curl_easy_setopt(fetch->curl_handle, + CURLOPT_POSTFIELDS, fetch->post_urlenc); + assert(code == CURLE_OK); + } /* add to the global curl multi handle */ codem = curl_multi_add_handle(curl_multi, fetch->curl_handle); @@ -327,11 +342,18 @@ void fetch_abort(struct fetch *f) code = curl_easy_setopt(fetch->curl_handle, CURLOPT_WRITEHEADER, fetch); assert(code == CURLE_OK); /* TODO: remove referer header if fetch->referer == 0 */ - if (fetch->referer != 0) { + /*if (fetch->referer != 0)*/ { code = curl_easy_setopt(fetch->curl_handle, CURLOPT_REFERER, fetch->referer); assert(code == CURLE_OK); } + /* POST */ + if (fetch->post_urlenc) { + code = curl_easy_setopt(fetch->curl_handle, + CURLOPT_POSTFIELDS, fetch->post_urlenc); + assert(code == CURLE_OK); + } + /* add to the global curl multi handle */ codem = curl_multi_add_handle(curl_multi, fetch->curl_handle); assert(codem == CURLM_OK || codem == CURLM_CALL_MULTI_PERFORM); @@ -346,6 +368,7 @@ void fetch_abort(struct fetch *f) free(f->referer); free(f->location); free(f->realm); + free(f->post_urlenc); xfree(f); } @@ -502,6 +525,7 @@ bool fetch_process_headers(struct fetch *f) return true; } +#ifdef riscos /* handle HTTP 401 (Authentication errors) */ if (http_code == 401) { /* this shouldn't be here... */ @@ -510,6 +534,7 @@ bool fetch_process_headers(struct fetch *f) f->callback(FETCH_ERROR, f->p, "",0); return true; } +#endif /* handle HTTP errors (non 2xx response codes) */ if (f->only_2xx && strncmp(f->url, "http", 4) == 0 && diff --git a/content/fetch.h b/content/fetch.h index ed469de04..762664923 100644 --- a/content/fetch.h +++ b/content/fetch.h @@ -18,11 +18,13 @@ typedef enum {FETCH_TYPE, FETCH_DATA, FETCH_FINISHED, FETCH_ERROR, FETCH_REDIREC struct content; struct fetch; +struct form_successful_control; void fetch_init(void); struct fetch * fetch_start(char *url, char *referer, void (*callback)(fetch_msg msg, void *p, char *data, unsigned long size), - void *p, bool only_2xx); + void *p, bool only_2xx, char *post_urlenc, + struct form_successful_control *post_multipart); void fetch_abort(struct fetch *f); void fetch_poll(void); void fetch_quit(void); diff --git a/content/fetchcache.c b/content/fetchcache.c index cf5bccf47..942f38773 100644 --- a/content/fetchcache.c +++ b/content/fetchcache.c @@ -42,7 +42,8 @@ struct content * fetchcache(const char *url0, char *referer, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, const char *error), void *p1, void *p2, unsigned long width, unsigned long height, - bool only_2xx) + bool only_2xx, char *post_urlenc, + struct form_successful_control *post_multipart) { struct content *c; char *url = xstrdup(url0); @@ -67,7 +68,8 @@ struct content * fetchcache(const char *url0, char *referer, c->fetch_size = 0; c->width = width; c->height = height; - c->fetch = fetch_start(url, referer, fetchcache_callback, c, only_2xx); + c->fetch = fetch_start(url, referer, fetchcache_callback, c, only_2xx, + post_urlenc, post_multipart); free(url); if (c->fetch == 0) { LOG(("warning: fetch_start failed")); diff --git a/content/fetchcache.h b/content/fetchcache.h index bd7c09933..a0a25c2f8 100644 --- a/content/fetchcache.h +++ b/content/fetchcache.h @@ -18,10 +18,13 @@ #include <stdbool.h> #include "netsurf/content/content.h" +struct form_successful_control; + struct content * fetchcache(const char *url, char *referer, void (*callback)(content_msg msg, struct content *c, void *p1, void *p2, const char *error), void *p1, void *p2, unsigned long width, unsigned long height, - bool only_2xx); + bool only_2xx, char *post_urlenc, + struct form_successful_control *post_multipart); #endif |