summaryrefslogtreecommitdiff
path: root/content/fetch.c
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2008-01-30 19:56:41 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2008-01-30 19:56:41 +0000
commitcc3481a2ff3fcf65317e035cb20ac632e5e0c149 (patch)
treea1b7befa9cde8a7e57dfcd4169a4deee219ff96c /content/fetch.c
parent087516561f16f995a3d87ae6f7f95103b40d9a3e (diff)
downloadnetsurf-cc3481a2ff3fcf65317e035cb20ac632e5e0c149.tar.gz
netsurf-cc3481a2ff3fcf65317e035cb20ac632e5e0c149.tar.bz2
Make core fetching code handle verifiability of transactions
Make core fetching code be responsible for inserting cookies into the urldb Provide accessor to a fetch's parent url (this is defined as being the URL of the verifiable fetch which caused this one to occur) Make fetchcache's 3xx handling use the parent url when spawning new fetches svn path=/trunk/netsurf/; revision=3809
Diffstat (limited to 'content/fetch.c')
-rw-r--r--content/fetch.c45
1 files changed, 42 insertions, 3 deletions
diff --git a/content/fetch.c b/content/fetch.c
index 5813e9c1b..632e04505 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -81,6 +81,8 @@ struct fetch {
char *url; /**< URL. */
char *referer; /**< Referer URL. */
bool send_referer; /**< Valid to send the referer */
+ bool verifiable; /**< Transaction is verifiable */
+ char *parent_fetch_url; /**< URL of parent fetch */
void *p; /**< Private data for callback. */
char *host; /**< Host part of URL. */
long http_code; /**< HTTP response code, or 0. */
@@ -266,6 +268,8 @@ struct fetch * fetch_start(const char *url, const char *referer,
fetch->abort = false;
fetch->stopped = false;
fetch->url = strdup(url);
+ fetch->verifiable = verifiable;
+ fetch->parent_fetch_url = parent_url ? strdup(parent_url) : 0;
fetch->p = p;
fetch->host = host;
fetch->http_code = 0;
@@ -286,7 +290,8 @@ struct fetch * fetch_start(const char *url, const char *referer,
fetch->send_referer = true;
}
- if (!fetch->url)
+ if (!fetch->url ||
+ (parent_url && !fetch->parent_fetch_url))
goto failed;
/* Pick the scheme ops */
@@ -304,8 +309,7 @@ struct fetch * fetch_start(const char *url, const char *referer,
/* Got a scheme fetcher, try and set up the fetch */
fetch->fetcher_handle =
fetch->ops->setup_fetch(fetch, url, only_2xx, post_urlenc,
- post_multipart, verifiable, parent_url,
- (const char **)headers);
+ post_multipart, (const char **)headers);
if (fetch->fetcher_handle == NULL)
goto failed;
@@ -333,6 +337,7 @@ failed:
free(host);
if (ref1)
free(ref1);
+ free(fetch->parent_fetch_url);
free(fetch->url);
if (fetch->referer)
free(fetch->referer);
@@ -454,6 +459,7 @@ void fetch_free(struct fetch *f)
LOG(("Freeing fetch %p, fetcher %p", f, f->fetcher_handle));
f->ops->free_fetch(f->fetcher_handle);
fetch_unref_fetcher(f->ops);
+ free(f->parent_fetch_url);
free(f->url);
free(f->host);
if (f->referer)
@@ -549,6 +555,20 @@ const char *fetch_get_referer(struct fetch *fetch)
return fetch->referer;
}
+/**
+ * Get the parent URL for this fetch
+ *
+ * \param fetch fetch to retrieve parent url from
+ * \return Pointer to parent url, or NULL if none.
+ */
+const char *fetch_get_parent_url(struct fetch *fetch)
+{
+ assert(fetch);
+
+ /* If the fetch is verifiable, then its own URL suffices */
+ return fetch->verifiable ? fetch->url : fetch->parent_fetch_url;
+}
+
void
fetch_send_callback(fetch_msg msg, struct fetch *fetch, const void *data,
unsigned long size)
@@ -596,3 +616,22 @@ fetch_get_referer_to_send(struct fetch *fetch)
return fetch->referer;
return NULL;
}
+
+void
+fetch_set_cookie(struct fetch *fetch, const char *data)
+{
+ assert(fetch && data);
+
+ /* If the fetch is unverifiable and there's no parent fetch
+ * url, err on the side of caution and do not set the cookie */
+
+ if (fetch->verifiable || fetch->parent_fetch_url) {
+ /* If the transaction's verifiable, we don't require
+ * that the request uri and the parent domain match,
+ * so don't pass in the parent in this case. */
+ urldb_set_cookie(data, fetch->url,
+ fetch->verifiable ? 0
+ : fetch->parent_fetch_url);
+ }
+}
+