summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJames Bursa <james@netsurf-browser.org>2008-06-03 01:10:46 +0000
committerJames Bursa <james@netsurf-browser.org>2008-06-03 01:10:46 +0000
commit8282253a5415263e2385d47d9416a611a00eea0f (patch)
treecc7f829f95d164de024821ab8766c136dbd81916 /content
parentf59d4a3626301e9eb5ae56edf050337e8f6fb4d1 (diff)
downloadnetsurf-8282253a5415263e2385d47d9416a611a00eea0f.tar.gz
netsurf-8282253a5415263e2385d47d9416a611a00eea0f.tar.bz2
Move struct cache_data from fetch to content as it is no longer needed by fetch. Make it a member instead of pointer in struct content.
svn path=/trunk/netsurf/; revision=4246
Diffstat (limited to 'content')
-rw-r--r--content/content.c23
-rw-r--r--content/content.h16
-rw-r--r--content/fetch.h13
-rw-r--r--content/fetchcache.c102
4 files changed, 74 insertions, 80 deletions
diff --git a/content/content.c b/content/content.c
index 6d8ed22e7..e4431453a 100644
--- a/content/content.c
+++ b/content/content.c
@@ -398,11 +398,6 @@ struct content * content_create(const char *url)
talloc_free(c);
return 0;
}
- c->cache_data = talloc(c, struct cache_data);
- if (!c->cache_data) {
- talloc_free(c);
- return 0;
- }
talloc_set_name_const(c, c->url);
c->type = CONTENT_UNKNOWN;
c->mime_type = 0;
@@ -433,15 +428,15 @@ struct content * content_create(const char *url)
c->download = false;
c->redirect_count = 0;
c->error_count = 0;
- c->cache_data->req_time = 0;
- c->cache_data->res_time = 0;
- c->cache_data->date = 0;
- c->cache_data->expires = 0;
- c->cache_data->age = INVALID_AGE;
- c->cache_data->max_age = INVALID_AGE;
- c->cache_data->no_cache = false;
- c->cache_data->etag = 0;
- c->cache_data->last_modified = 0;
+ c->cache_data.req_time = 0;
+ c->cache_data.res_time = 0;
+ c->cache_data.date = 0;
+ c->cache_data.expires = 0;
+ c->cache_data.age = INVALID_AGE;
+ c->cache_data.max_age = INVALID_AGE;
+ c->cache_data.no_cache = false;
+ c->cache_data.etag = 0;
+ c->cache_data.last_modified = 0;
content_set_status(c, messages_get("Loading"));
diff --git a/content/content.h b/content/content.h
index f2f3f4de2..ae43b933e 100644
--- a/content/content.h
+++ b/content/content.h
@@ -71,7 +71,6 @@
struct bitmap;
struct box;
struct browser_window;
-struct cache_data;
struct content;
struct fetch;
struct object_params;
@@ -126,6 +125,19 @@ union content_msg_data {
} ssl;
};
+struct cache_data {
+ time_t req_time; /**< Time of request */
+ time_t res_time; /**< Time of response */
+ time_t date; /**< Date: response header */
+ time_t expires; /**< Expires: response header */
+#define INVALID_AGE -1
+ int age; /**< Age: response header */
+ int max_age; /**< Max-age Cache-control parameter */
+ bool no_cache; /**< no-cache Cache-control parameter */
+ char *etag; /**< Etag: response header */
+ time_t last_modified; /**< Last-Modified: response header */
+};
+
/** Linked list of users of a content. */
struct content_user
{
@@ -208,7 +220,7 @@ struct content {
* was fetched using a simple GET, has not expired, and may be
* shared between users. */
bool fresh;
- struct cache_data *cache_data; /**< Cache control data */
+ struct cache_data cache_data; /**< Cache control data */
unsigned int time; /**< Creation time, if TYPE_UNKNOWN,
LOADING or READY,
otherwise total time. */
diff --git a/content/fetch.h b/content/fetch.h
index 4306e65da..6bf83636d 100644
--- a/content/fetch.h
+++ b/content/fetch.h
@@ -48,19 +48,6 @@ struct content;
struct fetch;
struct form_successful_control;
-struct cache_data {
- time_t req_time; /**< Time of request */
- time_t res_time; /**< Time of response */
- time_t date; /**< Date: response header */
- time_t expires; /**< Expires: response header */
-#define INVALID_AGE -1
- int age; /**< Age: response header */
- int max_age; /**< Max-age Cache-control parameter */
- bool no_cache; /**< no-cache Cache-control parameter */
- char *etag; /**< Etag: response header */
- time_t last_modified; /**< Last-Modified: response header */
-};
-
#ifdef WITH_SSL
struct ssl_cert_info {
long version; /**< Certificate version */
diff --git a/content/fetchcache.c b/content/fetchcache.c
index ca657cb8e..7f222ff1d 100644
--- a/content/fetchcache.c
+++ b/content/fetchcache.c
@@ -136,7 +136,7 @@ struct content * fetchcache(const char *url,
if (!post_urlenc && !post_multipart && !download && !query) {
if ((c = content_get(url1)) != NULL) {
- struct cache_data *cd = c->cache_data;
+ struct cache_data *cd = &c->cache_data;
int current_age, freshness_lifetime;
/* Calculate staleness of cached content as per
@@ -171,8 +171,8 @@ struct content * fetchcache(const char *url,
if (cd->last_modified)
date = cd->last_modified;
else
- date = c->cache_data->date;
- etag = c->cache_data->etag;
+ date = c->cache_data.date;
+ etag = c->cache_data.etag;
}
}
@@ -183,10 +183,10 @@ struct content * fetchcache(const char *url,
/* Fill in cache validation fields (if present) */
if (date)
- c->cache_data->date = date;
+ c->cache_data.date = date;
if (etag) {
- c->cache_data->etag = talloc_strdup(c, etag);
- if (!c->cache_data->etag)
+ c->cache_data.etag = talloc_strdup(c, etag);
+ if (!c->cache_data.etag)
return NULL;
}
@@ -280,18 +280,18 @@ void fetchcache_go(struct content *content, const char *referer,
/* brand new content: start fetch */
char **headers;
int i = 0;
- char *etag = content->cache_data->etag;
- time_t date = content->cache_data->date;
-
- content->cache_data->req_time = time(NULL);
- content->cache_data->res_time = 0;
- content->cache_data->date = 0;
- content->cache_data->expires = 0;
- content->cache_data->age = INVALID_AGE;
- content->cache_data->max_age = INVALID_AGE;
- content->cache_data->no_cache = false;
- content->cache_data->etag = 0;
- content->cache_data->last_modified = 0;
+ char *etag = content->cache_data.etag;
+ time_t date = content->cache_data.date;
+
+ content->cache_data.req_time = time(NULL);
+ content->cache_data.res_time = 0;
+ content->cache_data.date = 0;
+ content->cache_data.expires = 0;
+ content->cache_data.age = INVALID_AGE;
+ content->cache_data.max_age = INVALID_AGE;
+ content->cache_data.no_cache = false;
+ content->cache_data.etag = 0;
+ content->cache_data.last_modified = 0;
headers = malloc(3 * sizeof(char *));
if (!headers) {
@@ -425,7 +425,7 @@ void fetchcache_callback(fetch_msg msg, void *p, const void *data,
c->fetch = 0;
}
- if (c->cache_data->date || c->cache_data->etag) {
+ if (c->cache_data.date || c->cache_data.etag) {
/* We've just made a conditional request
* that returned with something other
* than 304. Therefore, there's a stale
@@ -634,24 +634,24 @@ void fetchcache_parse_header(struct content *c, const char *data,
#define SKIP_ST(o) for (i = (o); i < size && (data[i] == ' ' || data[i] == '\t'); i++)
/* Set fetch response time if not already set */
- if (c->cache_data->res_time == 0)
- c->cache_data->res_time = time(NULL);
+ if (c->cache_data.res_time == 0)
+ c->cache_data.res_time = time(NULL);
if (5 < size && strncasecmp(data, "Date:", 5) == 0) {
/* extract Date header */
SKIP_ST(5);
if (i < size)
- c->cache_data->date = curl_getdate(&data[i], NULL);
+ c->cache_data.date = curl_getdate(&data[i], NULL);
} else if (4 < size && strncasecmp(data, "Age:", 4) == 0) {
/* extract Age header */
SKIP_ST(4);
if (i < size && '0' <= data[i] && data[i] <= '9')
- c->cache_data->age = atoi(data + i);
+ c->cache_data.age = atoi(data + i);
} else if (8 < size && strncasecmp(data, "Expires:", 8) == 0) {
/* extract Expires header */
SKIP_ST(8);
if (i < size)
- c->cache_data->expires = curl_getdate(&data[i], NULL);
+ c->cache_data.expires = curl_getdate(&data[i], NULL);
} else if (14 < size && strncasecmp(data, "Cache-Control:", 14) == 0) {
/* extract and parse Cache-Control header */
size_t comma;
@@ -667,14 +667,14 @@ void fetchcache_parse_header(struct content *c, const char *data,
if (8 < comma - i && (strncasecmp(data + i, "no-cache", 8) == 0 || strncasecmp(data + i, "no-store", 8) == 0))
/* When we get a disk cache we should
* distinguish between these two */
- c->cache_data->no_cache = true;
+ c->cache_data.no_cache = true;
else if (7 < comma - i && strncasecmp(data + i, "max-age", 7) == 0) {
for (; i < comma; i++)
if (data[i] == '=')
break;
SKIP_ST(i+1);
if (i < comma)
- c->cache_data->max_age =
+ c->cache_data.max_age =
atoi(data + i);
}
@@ -682,26 +682,26 @@ void fetchcache_parse_header(struct content *c, const char *data,
}
} else if (5 < size && strncasecmp(data, "ETag:", 5) == 0) {
/* extract ETag header */
- talloc_free(c->cache_data->etag);
- c->cache_data->etag = talloc_array(c, char, size);
- if (!c->cache_data->etag) {
+ talloc_free(c->cache_data.etag);
+ c->cache_data.etag = talloc_array(c, char, size);
+ if (!c->cache_data.etag) {
LOG(("malloc failed"));
return;
}
SKIP_ST(5);
- strncpy(c->cache_data->etag, data + i, size - i);
- c->cache_data->etag[size - i] = '\0';
+ strncpy(c->cache_data.etag, data + i, size - i);
+ c->cache_data.etag[size - i] = '\0';
for (i = size - i - 1; i >= 0 &&
- (c->cache_data->etag[i] == ' ' ||
- c->cache_data->etag[i] == '\t' ||
- c->cache_data->etag[i] == '\r' ||
- c->cache_data->etag[i] == '\n'); --i)
- c->cache_data->etag[i] = '\0';
+ (c->cache_data.etag[i] == ' ' ||
+ c->cache_data.etag[i] == '\t' ||
+ c->cache_data.etag[i] == '\r' ||
+ c->cache_data.etag[i] == '\n'); --i)
+ c->cache_data.etag[i] = '\0';
} else if (14 < size && strncasecmp(data, "Last-Modified:", 14) == 0) {
/* extract Last-Modified header */
SKIP_ST(14);
if (i < size) {
- c->cache_data->last_modified =
+ c->cache_data.last_modified =
curl_getdate(&data[i], NULL);
}
}
@@ -749,33 +749,33 @@ void fetchcache_cache_update(struct content *c,
{
assert(c && data);
- c->cache_data->req_time = data->req_time;
- c->cache_data->res_time = data->res_time;
+ c->cache_data.req_time = data->req_time;
+ c->cache_data.res_time = data->res_time;
if (data->date != 0)
- c->cache_data->date = data->date;
+ c->cache_data.date = data->date;
else
- c->cache_data->date = time(0);
+ c->cache_data.date = time(0);
if (data->expires != 0)
- c->cache_data->expires = data->expires;
+ c->cache_data.expires = data->expires;
if (data->age != INVALID_AGE)
- c->cache_data->age = data->age;
+ c->cache_data.age = data->age;
if (data->max_age != INVALID_AGE)
- c->cache_data->max_age = data->max_age;
+ c->cache_data.max_age = data->max_age;
if (data->no_cache)
c->fresh = false;
if (data->etag) {
- talloc_free(c->cache_data->etag);
- c->cache_data->etag = talloc_strdup(c, data->etag);
+ talloc_free(c->cache_data.etag);
+ c->cache_data.etag = talloc_strdup(c, data->etag);
}
if (data->last_modified)
- c->cache_data->last_modified = data->last_modified;
+ c->cache_data.last_modified = data->last_modified;
}
@@ -854,7 +854,7 @@ void fetchcache_notmodified(struct content *c, const void *data)
c->status = CONTENT_STATUS_ERROR;
/* and update fallback's cache control data */
- fetchcache_cache_update(fb, c->cache_data);
+ fetchcache_cache_update(fb, &c->cache_data);
}
else {
/* No cached content, so unconditionally refetch */
@@ -892,9 +892,9 @@ void fetchcache_notmodified(struct content *c, const void *data)
fetch_abort(c->fetch);
c->fetch = 0;
- c->cache_data->date = 0;
- talloc_free(c->cache_data->etag);
- c->cache_data->etag = 0;
+ c->cache_data.date = 0;
+ talloc_free(c->cache_data.etag);
+ c->cache_data.etag = 0;
for (u = c->user_list->next; u; u = u->next) {
fetchcache_go(c, referer, u->callback, u->p1, u->p2,