summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/content.c5
-rw-r--r--content/fetch.c28
-rw-r--r--content/fetch.h11
-rw-r--r--content/fetchcache.c57
-rw-r--r--content/fetchcache.h2
5 files changed, 32 insertions, 71 deletions
diff --git a/content/content.c b/content/content.c
index 72ed2f292..bda652fad 100644
--- a/content/content.c
+++ b/content/content.c
@@ -596,6 +596,8 @@ bool content_set_type(struct content *c, content_type type,
* a content per user */
const char *referer =
c->fetch ? fetch_get_referer(c->fetch) : NULL;
+ struct content *parent =
+ c->fetch ? fetch_get_parent(c->fetch) : NULL;
while (c->user_list->next->next) {
clone = content_create(c->url);
@@ -630,8 +632,7 @@ bool content_set_type(struct content *c, content_type type,
fetchcache_go(clone, referer,
callback, p1, p2,
clone->width, clone->height,
- 0, 0, false,
- referer ? referer : c->url);
+ 0, 0, false, parent);
}
}
diff --git a/content/fetch.c b/content/fetch.c
index 31c1fd3cd..f9414172b 100644
--- a/content/fetch.c
+++ b/content/fetch.c
@@ -77,7 +77,7 @@ struct fetch {
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 */
+ struct content *parent; /**< Parent content, or NULL */
void *p; /**< Private data for callback. */
char *host; /**< Host part of URL. */
long http_code; /**< HTTP response code, or 0. */
@@ -215,7 +215,7 @@ struct fetch * fetch_start(const char *url, const char *referer,
fetch_callback callback,
void *p, bool only_2xx, const char *post_urlenc,
struct form_successful_control *post_multipart,
- bool verifiable, const char *parent_url,
+ bool verifiable, struct content *parent,
char *headers[])
{
char *host;
@@ -263,7 +263,7 @@ struct fetch * fetch_start(const char *url, const char *referer,
fetch->callback = callback;
fetch->url = strdup(url);
fetch->verifiable = verifiable;
- fetch->parent_fetch_url = parent_url ? strdup(parent_url) : NULL;
+ fetch->parent = parent;
fetch->p = p;
fetch->host = host;
fetch->http_code = 0;
@@ -299,8 +299,7 @@ struct fetch * fetch_start(const char *url, const char *referer,
}
}
- if (fetch->url == NULL ||
- (parent_url && fetch->parent_fetch_url == NULL))
+ if (fetch->url == NULL)
goto failed;
/* Pick the scheme ops */
@@ -340,7 +339,6 @@ failed:
free(host);
free(ref_scheme);
free(scheme);
- free(fetch->parent_fetch_url);
free(fetch->url);
free(fetch->referer);
free(fetch);
@@ -478,7 +476,6 @@ void fetch_free(struct fetch *f)
#endif
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)
@@ -578,14 +575,13 @@ const char *fetch_get_referer(struct fetch *fetch)
* Get the parent URL for this fetch
*
* \param fetch fetch to retrieve parent url from
- * \return Pointer to parent url, or NULL if none.
+ * \return Pointer to parent content, or NULL if none.
*/
-const char *fetch_get_parent_url(struct fetch *fetch)
+struct content *fetch_get_parent(struct fetch *fetch)
{
assert(fetch);
- /* If the fetch is verifiable, then its own URL suffices */
- return fetch->verifiable ? fetch->url : fetch->parent_fetch_url;
+ return fetch->parent;
}
/**
@@ -660,16 +656,16 @@ 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 the fetch is unverifiable and there's no parent content,
+ * err on the side of caution and do not set the cookie */
- if (fetch->verifiable || fetch->parent_fetch_url) {
+ if (fetch->verifiable || fetch->parent) {
/* 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);
+ fetch->verifiable ? NULL
+ : fetch->parent->url);
}
}
diff --git a/content/fetch.h b/content/fetch.h
index 42b6323c5..3206acc39 100644
--- a/content/fetch.h
+++ b/content/fetch.h
@@ -63,10 +63,11 @@ typedef void (*fetch_callback)(fetch_msg msg, void *p, const void *data,
void fetch_init(void);
struct fetch * fetch_start(const char *url, const char *referer,
- fetch_callback callback,
- void *p, bool only_2xx, const char *post_urlenc,
- struct form_successful_control *post_multipart,
- bool verifiable, const char *parent_url, char *headers[]);
+ fetch_callback callback,
+ void *p, bool only_2xx, const char *post_urlenc,
+ struct form_successful_control *post_multipart,
+ bool verifiable, struct content *parent,
+ char *headers[]);
void fetch_abort(struct fetch *f);
void fetch_poll(void);
void fetch_quit(void);
@@ -78,7 +79,7 @@ void fetch_change_callback(struct fetch *fetch,
void *p);
long fetch_http_code(struct fetch *fetch);
const char *fetch_get_referer(struct fetch *fetch);
-const char *fetch_get_parent_url(struct fetch *fetch);
+struct content *fetch_get_parent(struct fetch *fetch);
bool fetch_get_verifiable(struct fetch *fetch);
/* API for fetchers themselves */
diff --git a/content/fetchcache.c b/content/fetchcache.c
index a606be6d5..cb5cc9132 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -228,7 +228,7 @@ struct content * fetchcache(const char *url,
* \param post_urlenc url encoded post data, or 0 if none
* \param post_multipart multipart post data, or 0 if none
* \param verifiable this transaction is verifiable
- * \param parent_url URL of fetch which spawned this one, or 0 if none
+ * \param parent Content which spawned this one, or NULL if none
*
* Errors will be sent back through the callback.
*/
@@ -240,7 +240,7 @@ void fetchcache_go(struct content *content, const char *referer,
int width, int height,
char *post_urlenc,
struct form_successful_control *post_multipart,
- bool verifiable, const char *parent_url)
+ bool verifiable, struct content *parent)
{
char error_message[500];
union content_msg_data msg_data;
@@ -348,7 +348,7 @@ void fetchcache_go(struct content *content, const char *referer,
fetchcache_callback, content,
content->no_error_pages,
post_urlenc, post_multipart, verifiable,
- parent_url, headers);
+ parent, headers);
for (i = 0; headers[i]; i++)
free(headers[i]);
free(headers);
@@ -884,9 +884,8 @@ void fetchcache_notmodified(struct content *c, const void *data)
/* No cached content, so unconditionally refetch */
struct content_user *u;
const char *ref = fetch_get_referer(c->fetch);
- const char *parent = fetch_get_parent_url(c->fetch);
+ struct content *parent = fetch_get_parent(c->fetch);
char *referer = NULL;
- char *parent_url = NULL;
if (ref) {
referer = strdup(ref);
@@ -900,19 +899,6 @@ void fetchcache_notmodified(struct content *c, const void *data)
}
}
- if (parent) {
- parent_url = strdup(parent);
- if (!parent_url) {
- c->type = CONTENT_UNKNOWN;
- c->status = CONTENT_STATUS_ERROR;
- msg_data.error = messages_get("NoMemory");
- content_broadcast(c, CONTENT_MSG_ERROR,
- msg_data);
- free(referer);
- return;
- }
- }
-
fetch_abort(c->fetch);
c->fetch = 0;
@@ -923,10 +909,9 @@ void fetchcache_notmodified(struct content *c, const void *data)
for (u = c->user_list->next; u; u = u->next) {
fetchcache_go(c, referer, u->callback, u->p1, u->p2,
c->width, c->height, 0, 0,
- false, parent_url);
+ false, parent);
}
- free(parent_url);
free(referer);
}
}
@@ -939,11 +924,11 @@ void fetchcache_redirect(struct content *c, const void *data,
unsigned long size)
{
char *url, *url1;
- char *referer, *parent_url;
+ char *referer;
char *scheme;
long http_code;
const char *ref;
- const char *parent;
+ struct content *parent;
bool can_fetch;
bool parent_was_verifiable;
union content_msg_data msg_data;
@@ -956,7 +941,7 @@ void fetchcache_redirect(struct content *c, const void *data,
/* Extract fetch details */
http_code = fetch_http_code(c->fetch);
ref = fetch_get_referer(c->fetch);
- parent = fetch_get_parent_url(c->fetch);
+ parent = fetch_get_parent(c->fetch);
parent_was_verifiable = fetch_get_verifiable(c->fetch);
/* Ensure a redirect happened */
@@ -964,10 +949,8 @@ void fetchcache_redirect(struct content *c, const void *data,
/* 304 is handled by fetch_notmodified() */
assert(http_code != 304);
- /* Clone referer and parent url
- * originals are destroyed in fetch_abort() */
+ /* Clone referer -- original is destroyed in fetch_abort() */
referer = ref ? strdup(ref) : NULL;
- parent_url = parent ? strdup(parent) : NULL;
/* set the status to ERROR so that this content is
* destroyed in content_clean() */
@@ -986,18 +969,6 @@ void fetchcache_redirect(struct content *c, const void *data,
return;
}
- /* Ensure parent url cloning succeeded
- * _must_ be after content invalidation */
- if (parent && !parent_url) {
- LOG(("Failed cloning parent url"));
-
- msg_data.error = messages_get("BadRedirect");
- content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
-
- free(referer);
- return;
- }
-
/** \todo 300, 305, 307
* More specifically:
* + 300 needs to serve up the fetch body to the user
@@ -1018,7 +989,6 @@ void fetchcache_redirect(struct content *c, const void *data,
msg_data.error = messages_get("BadRedirect");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- free(parent_url);
free(referer);
return;
}
@@ -1031,7 +1001,6 @@ void fetchcache_redirect(struct content *c, const void *data,
msg_data.error = messages_get("BadRedirect");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- free(parent_url);
free(referer);
return;
}
@@ -1045,7 +1014,6 @@ void fetchcache_redirect(struct content *c, const void *data,
msg_data.error = messages_get("BadRedirect");
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
- free(parent_url);
free(referer);
return;
}
@@ -1058,7 +1026,6 @@ void fetchcache_redirect(struct content *c, const void *data,
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
free(url1);
- free(parent_url);
free(referer);
return;
}
@@ -1073,7 +1040,6 @@ void fetchcache_redirect(struct content *c, const void *data,
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
free(url);
- free(parent_url);
free(referer);
return;
}
@@ -1084,7 +1050,6 @@ void fetchcache_redirect(struct content *c, const void *data,
free(scheme);
free(url);
- free(parent_url);
free(referer);
return;
}
@@ -1143,7 +1108,6 @@ void fetchcache_redirect(struct content *c, const void *data,
msg_data);
free(url);
- free(parent_url);
free(referer);
return;
}
@@ -1160,13 +1124,12 @@ void fetchcache_redirect(struct content *c, const void *data,
/* Start fetching the replacement content */
fetchcache_go(replacement, referer, callback, p1, p2,
c->width, c->height, NULL, NULL,
- parent_was_verifiable, parent_url);
+ parent_was_verifiable, parent);
}
}
/* Clean up */
free(url);
- free(parent_url);
free(referer);
}
diff --git a/content/fetchcache.h b/content/fetchcache.h
index 93e40b00d..24ed564ad 100644
--- a/content/fetchcache.h
+++ b/content/fetchcache.h
@@ -50,6 +50,6 @@ void fetchcache_go(struct content *content, const char *referer,
int width, int height,
char *post_urlenc,
struct form_successful_control *post_multipart,
- bool verifiable, const char *parent_url);
+ bool verifiable, struct content *parent);
#endif