Gitweb links:

...log 
http://git.netsurf-browser.org/netsurf.git/shortlog/ad27ed6926499f3381b8e7f6d80e86268919ec6c
...commit 
http://git.netsurf-browser.org/netsurf.git/commit/ad27ed6926499f3381b8e7f6d80e86268919ec6c
...tree 
http://git.netsurf-browser.org/netsurf.git/tree/ad27ed6926499f3381b8e7f6d80e86268919ec6c

The branch, master has been updated
       via  ad27ed6926499f3381b8e7f6d80e86268919ec6c (commit)
       via  26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7 (commit)
       via  c14f01ea442295e2d658a1f9bec866c5638bb3ca (commit)
       via  8d652f1ff453a1d87dfdec9c6c8dd077a707c613 (commit)
       via  b757f941070c1ed21acc388ff834b123e9c40595 (commit)
       via  f0ff18d35c5cb9aa946038422e6f03e2f915938f (commit)
       via  301b0bae002c5cb828713bf5df6af34d8b925ea6 (commit)
       via  66401b7fa6e9ad5b2b3230e6483787c95e727624 (commit)
       via  ab4eab5706ac6df3a282d1e2fa880d2d40a9eead (commit)
       via  0dfbc8058784a63a7a14651f0098b3b391c24dfd (commit)
       via  58094ffaa50ea3fc7e3c21bd8e41eb04133d09d3 (commit)
      from  885897f610b9b3650d061b17ef58d6493287488b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=ad27ed6926499f3381b8e7f6d80e86268919ec6c
commit ad27ed6926499f3381b8e7f6d80e86268919ec6c
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    llcache: Avoid putting local content in the disc cache.

diff --git a/content/llcache.c b/content/llcache.c
index f342866..ccfa61d 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -1520,6 +1520,34 @@ format_error:
 }
 
 /**
+ * Check whether a scheme is persistable.
+ *
+ * \param url  URL to check.
+ * \return true iff url has a persistable scheme.
+ */
+static inline bool llcache__scheme_is_persistable(const nsurl *url)
+{
+       lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME);
+       bool persistable = false;
+       bool match;
+
+       /* nsurl ensures lower case schemes, and corestrings are lower
+        * case, so it's safe to use case-sensitive comparison. */
+       if ((lwc_string_isequal(scheme, corestring_lwc_http,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_https,
+                       &match) == lwc_error_ok &&
+                       (match == true))) {
+               persistable = true;
+       }
+
+       lwc_string_unref(scheme);
+
+       return persistable;
+}
+
+/**
  * Check whether a scheme is cachable.
  *
  * \param url  URL to check.
@@ -1578,6 +1606,12 @@ llcache_object_fetch_persistent(llcache_object *object,
        nsurl *referer_clone = NULL;
        llcache_post_data *post_clone = NULL;
 
+       if (!llcache__scheme_is_persistable(object->url)) {
+               /* Don't bother looking up non-http(s) stuff; we don't
+                * persist it. */
+               return NSERROR_NOT_FOUND;
+       }
+
        object->cache.req_time = time(NULL);
        object->cache.fin_time = object->cache.req_time;
 
@@ -2494,6 +2528,11 @@ build_candidate_list(struct llcache_object ***lst_out, 
int *lst_len_out)
        for (object = llcache->cached_objects; object != NULL; object = next) {
                next = object->next;
 
+               /* Only consider http(s) for the disc cache. */
+               if (!llcache__scheme_is_persistable(object->url)) {
+                       continue;
+               }
+
                remaining_lifetime = llcache_object_rfc2616_remaining_lifetime(
                                &object->cache);
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7
commit 26d7a167ae8e4756c2fb3f0cc5abbbe12934aaf7
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    llcache: Split out scheme is cachable check.

diff --git a/content/llcache.c b/content/llcache.c
index e794112..f342866 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -1520,6 +1520,43 @@ format_error:
 }
 
 /**
+ * Check whether a scheme is cachable.
+ *
+ * \param url  URL to check.
+ * \return true iff url has a cachable scheme.
+ */
+static inline bool llcache__scheme_is_cachable(const nsurl *url)
+{
+       lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME);
+       bool cachable = false;
+       bool match;
+
+       /* nsurl ensures lower case schemes, and corestrings are lower
+        * case, so it's safe to use case-sensitive comparison. */
+       if ((lwc_string_isequal(scheme, corestring_lwc_http,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_https,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_data,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_resource,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_file,
+                       &match) == lwc_error_ok &&
+                       (match == true))) {
+               cachable = true;
+       }
+
+       lwc_string_unref(scheme);
+
+       return cachable;
+}
+
+/**
  * Attempt to retrieve an object from persistent storage.
  *
  * \param object The object to populate from persistent store.
@@ -1792,35 +1829,9 @@ llcache_object_retrieve(nsurl *url,
                /* POST requests are never cached */
                uncachable = true;
        } else {
-               /* only http(s), data, resource, and file schemes are cached */
-               lwc_string *scheme;
-               bool match;
-
-               scheme = nsurl_get_component(defragmented_url, NSURL_SCHEME);
-
-               /* nsurl ensures lower case schemes, and corestrings are lower
-                * case, so it's safe to use case-sensitive comparison. */
-               if (lwc_string_isequal(scheme, corestring_lwc_http,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_https,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_data,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_resource,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_file,
-                               &match) == lwc_error_ok &&
-                               (match == false)) {
-                       uncachable = true;
-               }
-               lwc_string_unref(scheme);
+               uncachable = !llcache__scheme_is_cachable(defragmented_url);
        }
 
-
        if (uncachable) {
                /* Create new object */
                error = llcache_object_new(defragmented_url, &obj);


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=c14f01ea442295e2d658a1f9bec866c5638bb3ca
commit c14f01ea442295e2d658a1f9bec866c5638bb3ca
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    File fetcher: Optimise HTTP header generation.

diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 5c9d158..b5b4221 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -99,19 +99,21 @@ static bool fetch_file_send_header(struct 
fetch_file_context *ctx,
        fetch_msg msg;
        char header[64];
        va_list ap;
+       int len;
 
        va_start(ap, fmt);
-
-       vsnprintf(header, sizeof header, fmt, ap);
-
+       len = vsnprintf(header, sizeof header, fmt, ap);
        va_end(ap);
 
+       if (len >= (int)sizeof(header) || len < 0) {
+               return false;
+       }
+
        msg.type = FETCH_HEADER;
        msg.data.header_or_data.buf = (const uint8_t *) header;
-       msg.data.header_or_data.len = strlen(header);
-       fetch_file_send_callback(&msg, ctx);
+       msg.data.header_or_data.len = len;
 
-       return ctx->aborted;
+       return fetch_file_send_callback(&msg, ctx);
 }
 
 /** callback to initialise the file fetcher. */


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=8d652f1ff453a1d87dfdec9c6c8dd077a707c613
commit 8d652f1ff453a1d87dfdec9c6c8dd077a707c613
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Resource fetcher: Optimise HTTP header generation.

diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index c7cf022..9b3f28c 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -122,19 +122,21 @@ static bool fetch_resource_send_header(struct 
fetch_resource_context *ctx,
        fetch_msg msg;
        char header[64];
        va_list ap;
+       int len;
 
        va_start(ap, fmt);
-
-       vsnprintf(header, sizeof header, fmt, ap);
-
+       len = vsnprintf(header, sizeof header, fmt, ap);
        va_end(ap);
 
+       if (len >= (int)sizeof(header) || len < 0) {
+               return false;
+       }
+
        msg.type = FETCH_HEADER;
        msg.data.header_or_data.buf = (const uint8_t *) header;
-       msg.data.header_or_data.len = strlen(header);
-       fetch_resource_send_callback(&msg, ctx);
+       msg.data.header_or_data.len = len;
 
-       return ctx->aborted;
+       return fetch_resource_send_callback(&msg, ctx);
 }
 
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=b757f941070c1ed21acc388ff834b123e9c40595
commit b757f941070c1ed21acc388ff834b123e9c40595
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Utils: ring: Remove unused code.

diff --git a/utils/ring.h b/utils/ring.h
index b673133..55880a6 100644
--- a/utils/ring.h
+++ b/utils/ring.h
@@ -66,24 +66,6 @@
 /** Find the element (by hostname) in the given ring, leave it in the
  * provided element variable
  */
-#define RING_FINDBYHOST(ring, element, hostname) \
-       /*LOG("RING_FINDBYHOST(%s, %s)", #ring, hostname);*/ \
-       if (ring) { \
-               bool found = false; \
-               element = ring; \
-               do { \
-                       if (strcasecmp(element->host, hostname) == 0) { \
-                               found = true; \
-                               break; \
-                       } \
-                       element = element->r_next; \
-               } while (element != ring); \
-               if (!found) element = 0; \
-       } else element = 0
-
-/** Find the element (by hostname) in the given ring, leave it in the
- * provided element variable
- */
 #define RING_FINDBYLWCHOST(ring, element, lwc_hostname) \
        /*LOG("RING_FINDBYHOST(%s, %s)", #ring, hostname);*/ \
        if (ring) { \
@@ -112,19 +94,6 @@
                } while (p != ring); \
        } else sizevar = 0
 
-/** Count the number of elements in the ring which match the provided hostname 
*/
-#define RING_COUNTBYHOST(ringtype, ring, sizevar, hostname) \
-       /*LOG("RING_COUNTBYHOST(%s, %s)", #ring, hostname);*/ \
-       if (ring) { \
-               ringtype *p = ring; \
-               sizevar = 0; \
-               do { \
-                       if (strcasecmp(p->host, hostname) == 0) \
-                               sizevar++; \
-                       p = p->r_next; \
-               } while (p != ring); \
-       } else sizevar = 0
-
 /** Count the number of elements in the ring which match the provided 
lwc_hostname */
 #define RING_COUNTBYLWCHOST(ringtype, ring, sizevar, lwc_hostname) \
        /*LOG("RING_COUNTBYHOST(%s, %s)", #ring, hostname);*/ \


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=f0ff18d35c5cb9aa946038422e6f03e2f915938f
commit f0ff18d35c5cb9aa946038422e6f03e2f915938f
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Utils: ring: Whitespace fix.

diff --git a/utils/ring.h b/utils/ring.h
index 1802b44..b673133 100644
--- a/utils/ring.h
+++ b/utils/ring.h
@@ -136,7 +136,7 @@
                        /* nsurl guarantees lowercase host */ \
                        if (lwc_string_isequal(p->host, lwc_hostname, \
                                        &matches) == lwc_error_ok) \
-                               if (matches) \
+                               if (matches) \
                                        sizevar++; \
                        p = p->r_next; \
                } while (p != ring); \


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=301b0bae002c5cb828713bf5df6af34d8b925ea6
commit 301b0bae002c5cb828713bf5df6af34d8b925ea6
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    llcache: URLs with data scheme are cachable.

diff --git a/content/llcache.c b/content/llcache.c
index 54848cf..e794112 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -1792,7 +1792,7 @@ llcache_object_retrieve(nsurl *url,
                /* POST requests are never cached */
                uncachable = true;
        } else {
-               /* only http(s), resource, and file schemes are cached */
+               /* only http(s), data, resource, and file schemes are cached */
                lwc_string *scheme;
                bool match;
 
@@ -1806,6 +1806,9 @@ llcache_object_retrieve(nsurl *url,
                    lwc_string_isequal(scheme, corestring_lwc_https,
                                &match) == lwc_error_ok &&
                                (match == false) &&
+                   lwc_string_isequal(scheme, corestring_lwc_data,
+                               &match) == lwc_error_ok &&
+                               (match == false) &&
                    lwc_string_isequal(scheme, corestring_lwc_resource,
                                &match) == lwc_error_ok &&
                                (match == false) &&


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=66401b7fa6e9ad5b2b3230e6483787c95e727624
commit 66401b7fa6e9ad5b2b3230e6483787c95e727624
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Resource fetcher: Add Cache-Control header with max-age of a year.
    
    Resource URLs can't change, we want to assume they're fresh for
    as long as we can.

diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index 94a5140..c7cf022 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -195,6 +195,11 @@ static bool fetch_resource_data_handler(struct 
fetch_resource_context *ctx)
                goto fetch_resource_data_aborted;
        }
 
+       /* create max-age of 1 year */
+       if (fetch_resource_send_header(ctx,
+                       "Cache-Control: max-age=31536000")) {
+               goto fetch_resource_data_aborted;
+       }
 
        msg.type = FETCH_DATA;
        msg.data.header_or_data.buf = (const uint8_t *) ctx->entry->data;


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=ab4eab5706ac6df3a282d1e2fa880d2d40a9eead
commit ab4eab5706ac6df3a282d1e2fa880d2d40a9eead
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Data fetcher: Add Cache-Control header with max-age of a year.
    
    Data URLs can't change, we want to assume they're fresh for
    as long as we can.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 0ebe849..fdcfe64 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -283,6 +283,12 @@ static void fetch_data_poll(lwc_string *scheme)
                        }
 
                        if (c->aborted == false) {
+                               /* Set max-age to 1 year. */
+                               fetch_data_send_header(c, "Cache-Control: "
+                                               "max-age=31536000");
+                       }
+
+                       if (c->aborted == false) {
                                msg.type = FETCH_DATA;
                                msg.data.header_or_data.buf = 
                                                (const uint8_t *) c->data;


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=0dfbc8058784a63a7a14651f0098b3b391c24dfd
commit 0dfbc8058784a63a7a14651f0098b3b391c24dfd
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Data fetcher: Split header emitting out into helper.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 720a663..0ebe849 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -82,6 +82,29 @@ static void fetch_data_send_callback(const fetch_msg *msg,
        c->locked = false;
 }
 
+static void fetch_data_send_header(struct fetch_data_context *ctx,
+               const char *fmt, ...)
+{
+       char header[64];
+       fetch_msg msg = {
+               .type = FETCH_HEADER,
+               .data.header_or_data.buf = (const uint8_t *) header,
+       };
+       va_list ap;
+       int len;
+
+       va_start(ap, fmt);
+       len = vsnprintf(header, sizeof(header), fmt, ap);
+       va_end(ap);
+
+       if (len >= (int)sizeof(header) || len < 0) {
+               return;
+       }
+
+       msg.data.header_or_data.len = len;
+       fetch_data_send_callback(&msg, ctx);
+}
+
 static void *fetch_data_setup(struct fetch *parent_fetch, nsurl *url,
                 bool only_2xx, bool downgrade_tls, const char *post_urlenc,
                 const struct fetch_multipart_data *post_multipart,
@@ -242,8 +265,6 @@ static void fetch_data_poll(lwc_string *scheme)
 
                /* Only process non-aborted fetches */
                if (c->aborted == false && fetch_data_process(c) == true) {
-                       char header[64];
-
                        fetch_set_http_code(c->parent_fetch, 200);
                        NSLOG(netsurf, INFO,
                              "setting data: MIME type to %s, length to 
%"PRIsizet,
@@ -253,22 +274,12 @@ static void fetch_data_poll(lwc_string *scheme)
                         * Therefore, we _must_ check for this after _every_
                         * call to fetch_data_send_callback().
                         */
-                       snprintf(header, sizeof header, "Content-Type: %s",
+                       fetch_data_send_header(c, "Content-Type: %s",
                                        c->mimetype);
-                       msg.type = FETCH_HEADER;
-                       msg.data.header_or_data.buf = (const uint8_t *) header;
-                       msg.data.header_or_data.len = strlen(header);
-                       fetch_data_send_callback(&msg, c); 
 
                        if (c->aborted == false) {
-                               snprintf(header, sizeof header, 
-                                        "Content-Length: %" PRIsizet,
-                                        c->datalen);
-                               msg.type = FETCH_HEADER;
-                               msg.data.header_or_data.buf = 
-                                               (const uint8_t *) header;
-                               msg.data.header_or_data.len = strlen(header);
-                               fetch_data_send_callback(&msg, c);
+                               fetch_data_send_header(c, "Content-Length: %"
+                                               PRIsizet, c->datalen);
                        }
 
                        if (c->aborted == false) {


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=58094ffaa50ea3fc7e3c21bd8e41eb04133d09d3
commit 58094ffaa50ea3fc7e3c21bd8e41eb04133d09d3
Author: Michael Drake <[email protected]>
Commit: Michael Drake <[email protected]>

    Data fetcher: Move fetch_data_send_callback towards top of file.

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 8c04bcf..720a663 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -74,6 +74,14 @@ static bool fetch_data_can_fetch(const nsurl *url)
        return true;
 }
 
+static void fetch_data_send_callback(const fetch_msg *msg,
+               struct fetch_data_context *c)
+{
+       c->locked = true;
+       fetch_send_callback(msg, c->parent_fetch);
+       c->locked = false;
+}
+
 static void *fetch_data_setup(struct fetch *parent_fetch, nsurl *url,
                 bool only_2xx, bool downgrade_tls, const char *post_urlenc,
                 const struct fetch_multipart_data *post_multipart,
@@ -119,14 +127,6 @@ static void fetch_data_abort(void *ctx)
        c->aborted = true;
 }
 
-static void fetch_data_send_callback(const fetch_msg *msg, 
-               struct fetch_data_context *c) 
-{
-       c->locked = true;
-       fetch_send_callback(msg, c->parent_fetch);
-       c->locked = false;
-}
-
 static bool fetch_data_process(struct fetch_data_context *c)
 {
        nserror res;


-----------------------------------------------------------------------

Summary of changes:
 content/fetchers/data.c     |   63 +++++++++++++++++----------
 content/fetchers/file.c     |   14 +++---
 content/fetchers/resource.c |   19 +++++---
 content/llcache.c           |  101 +++++++++++++++++++++++++++++++++----------
 utils/ring.h                |   33 +-------------
 5 files changed, 139 insertions(+), 91 deletions(-)

diff --git a/content/fetchers/data.c b/content/fetchers/data.c
index 8c04bcf..fdcfe64 100644
--- a/content/fetchers/data.c
+++ b/content/fetchers/data.c
@@ -74,6 +74,37 @@ static bool fetch_data_can_fetch(const nsurl *url)
        return true;
 }
 
+static void fetch_data_send_callback(const fetch_msg *msg,
+               struct fetch_data_context *c)
+{
+       c->locked = true;
+       fetch_send_callback(msg, c->parent_fetch);
+       c->locked = false;
+}
+
+static void fetch_data_send_header(struct fetch_data_context *ctx,
+               const char *fmt, ...)
+{
+       char header[64];
+       fetch_msg msg = {
+               .type = FETCH_HEADER,
+               .data.header_or_data.buf = (const uint8_t *) header,
+       };
+       va_list ap;
+       int len;
+
+       va_start(ap, fmt);
+       len = vsnprintf(header, sizeof(header), fmt, ap);
+       va_end(ap);
+
+       if (len >= (int)sizeof(header) || len < 0) {
+               return;
+       }
+
+       msg.data.header_or_data.len = len;
+       fetch_data_send_callback(&msg, ctx);
+}
+
 static void *fetch_data_setup(struct fetch *parent_fetch, nsurl *url,
                 bool only_2xx, bool downgrade_tls, const char *post_urlenc,
                 const struct fetch_multipart_data *post_multipart,
@@ -119,14 +150,6 @@ static void fetch_data_abort(void *ctx)
        c->aborted = true;
 }
 
-static void fetch_data_send_callback(const fetch_msg *msg, 
-               struct fetch_data_context *c) 
-{
-       c->locked = true;
-       fetch_send_callback(msg, c->parent_fetch);
-       c->locked = false;
-}
-
 static bool fetch_data_process(struct fetch_data_context *c)
 {
        nserror res;
@@ -242,8 +265,6 @@ static void fetch_data_poll(lwc_string *scheme)
 
                /* Only process non-aborted fetches */
                if (c->aborted == false && fetch_data_process(c) == true) {
-                       char header[64];
-
                        fetch_set_http_code(c->parent_fetch, 200);
                        NSLOG(netsurf, INFO,
                              "setting data: MIME type to %s, length to 
%"PRIsizet,
@@ -253,22 +274,18 @@ static void fetch_data_poll(lwc_string *scheme)
                         * Therefore, we _must_ check for this after _every_
                         * call to fetch_data_send_callback().
                         */
-                       snprintf(header, sizeof header, "Content-Type: %s",
+                       fetch_data_send_header(c, "Content-Type: %s",
                                        c->mimetype);
-                       msg.type = FETCH_HEADER;
-                       msg.data.header_or_data.buf = (const uint8_t *) header;
-                       msg.data.header_or_data.len = strlen(header);
-                       fetch_data_send_callback(&msg, c); 
 
                        if (c->aborted == false) {
-                               snprintf(header, sizeof header, 
-                                        "Content-Length: %" PRIsizet,
-                                        c->datalen);
-                               msg.type = FETCH_HEADER;
-                               msg.data.header_or_data.buf = 
-                                               (const uint8_t *) header;
-                               msg.data.header_or_data.len = strlen(header);
-                               fetch_data_send_callback(&msg, c);
+                               fetch_data_send_header(c, "Content-Length: %"
+                                               PRIsizet, c->datalen);
+                       }
+
+                       if (c->aborted == false) {
+                               /* Set max-age to 1 year. */
+                               fetch_data_send_header(c, "Cache-Control: "
+                                               "max-age=31536000");
                        }
 
                        if (c->aborted == false) {
diff --git a/content/fetchers/file.c b/content/fetchers/file.c
index 5c9d158..b5b4221 100644
--- a/content/fetchers/file.c
+++ b/content/fetchers/file.c
@@ -99,19 +99,21 @@ static bool fetch_file_send_header(struct 
fetch_file_context *ctx,
        fetch_msg msg;
        char header[64];
        va_list ap;
+       int len;
 
        va_start(ap, fmt);
-
-       vsnprintf(header, sizeof header, fmt, ap);
-
+       len = vsnprintf(header, sizeof header, fmt, ap);
        va_end(ap);
 
+       if (len >= (int)sizeof(header) || len < 0) {
+               return false;
+       }
+
        msg.type = FETCH_HEADER;
        msg.data.header_or_data.buf = (const uint8_t *) header;
-       msg.data.header_or_data.len = strlen(header);
-       fetch_file_send_callback(&msg, ctx);
+       msg.data.header_or_data.len = len;
 
-       return ctx->aborted;
+       return fetch_file_send_callback(&msg, ctx);
 }
 
 /** callback to initialise the file fetcher. */
diff --git a/content/fetchers/resource.c b/content/fetchers/resource.c
index 94a5140..9b3f28c 100644
--- a/content/fetchers/resource.c
+++ b/content/fetchers/resource.c
@@ -122,19 +122,21 @@ static bool fetch_resource_send_header(struct 
fetch_resource_context *ctx,
        fetch_msg msg;
        char header[64];
        va_list ap;
+       int len;
 
        va_start(ap, fmt);
-
-       vsnprintf(header, sizeof header, fmt, ap);
-
+       len = vsnprintf(header, sizeof header, fmt, ap);
        va_end(ap);
 
+       if (len >= (int)sizeof(header) || len < 0) {
+               return false;
+       }
+
        msg.type = FETCH_HEADER;
        msg.data.header_or_data.buf = (const uint8_t *) header;
-       msg.data.header_or_data.len = strlen(header);
-       fetch_resource_send_callback(&msg, ctx);
+       msg.data.header_or_data.len = len;
 
-       return ctx->aborted;
+       return fetch_resource_send_callback(&msg, ctx);
 }
 
 
@@ -195,6 +197,11 @@ static bool fetch_resource_data_handler(struct 
fetch_resource_context *ctx)
                goto fetch_resource_data_aborted;
        }
 
+       /* create max-age of 1 year */
+       if (fetch_resource_send_header(ctx,
+                       "Cache-Control: max-age=31536000")) {
+               goto fetch_resource_data_aborted;
+       }
 
        msg.type = FETCH_DATA;
        msg.data.header_or_data.buf = (const uint8_t *) ctx->entry->data;
diff --git a/content/llcache.c b/content/llcache.c
index 54848cf..ccfa61d 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -1520,6 +1520,71 @@ format_error:
 }
 
 /**
+ * Check whether a scheme is persistable.
+ *
+ * \param url  URL to check.
+ * \return true iff url has a persistable scheme.
+ */
+static inline bool llcache__scheme_is_persistable(const nsurl *url)
+{
+       lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME);
+       bool persistable = false;
+       bool match;
+
+       /* nsurl ensures lower case schemes, and corestrings are lower
+        * case, so it's safe to use case-sensitive comparison. */
+       if ((lwc_string_isequal(scheme, corestring_lwc_http,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_https,
+                       &match) == lwc_error_ok &&
+                       (match == true))) {
+               persistable = true;
+       }
+
+       lwc_string_unref(scheme);
+
+       return persistable;
+}
+
+/**
+ * Check whether a scheme is cachable.
+ *
+ * \param url  URL to check.
+ * \return true iff url has a cachable scheme.
+ */
+static inline bool llcache__scheme_is_cachable(const nsurl *url)
+{
+       lwc_string *scheme = nsurl_get_component(url, NSURL_SCHEME);
+       bool cachable = false;
+       bool match;
+
+       /* nsurl ensures lower case schemes, and corestrings are lower
+        * case, so it's safe to use case-sensitive comparison. */
+       if ((lwc_string_isequal(scheme, corestring_lwc_http,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_https,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_data,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_resource,
+                       &match) == lwc_error_ok &&
+                       (match == true)) ||
+           (lwc_string_isequal(scheme, corestring_lwc_file,
+                       &match) == lwc_error_ok &&
+                       (match == true))) {
+               cachable = true;
+       }
+
+       lwc_string_unref(scheme);
+
+       return cachable;
+}
+
+/**
  * Attempt to retrieve an object from persistent storage.
  *
  * \param object The object to populate from persistent store.
@@ -1541,6 +1606,12 @@ llcache_object_fetch_persistent(llcache_object *object,
        nsurl *referer_clone = NULL;
        llcache_post_data *post_clone = NULL;
 
+       if (!llcache__scheme_is_persistable(object->url)) {
+               /* Don't bother looking up non-http(s) stuff; we don't
+                * persist it. */
+               return NSERROR_NOT_FOUND;
+       }
+
        object->cache.req_time = time(NULL);
        object->cache.fin_time = object->cache.req_time;
 
@@ -1792,32 +1863,9 @@ llcache_object_retrieve(nsurl *url,
                /* POST requests are never cached */
                uncachable = true;
        } else {
-               /* only http(s), resource, and file schemes are cached */
-               lwc_string *scheme;
-               bool match;
-
-               scheme = nsurl_get_component(defragmented_url, NSURL_SCHEME);
-
-               /* nsurl ensures lower case schemes, and corestrings are lower
-                * case, so it's safe to use case-sensitive comparison. */
-               if (lwc_string_isequal(scheme, corestring_lwc_http,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_https,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_resource,
-                               &match) == lwc_error_ok &&
-                               (match == false) &&
-                   lwc_string_isequal(scheme, corestring_lwc_file,
-                               &match) == lwc_error_ok &&
-                               (match == false)) {
-                       uncachable = true;
-               }
-               lwc_string_unref(scheme);
+               uncachable = !llcache__scheme_is_cachable(defragmented_url);
        }
 
-
        if (uncachable) {
                /* Create new object */
                error = llcache_object_new(defragmented_url, &obj);
@@ -2480,6 +2528,11 @@ build_candidate_list(struct llcache_object ***lst_out, 
int *lst_len_out)
        for (object = llcache->cached_objects; object != NULL; object = next) {
                next = object->next;
 
+               /* Only consider http(s) for the disc cache. */
+               if (!llcache__scheme_is_persistable(object->url)) {
+                       continue;
+               }
+
                remaining_lifetime = llcache_object_rfc2616_remaining_lifetime(
                                &object->cache);
 
diff --git a/utils/ring.h b/utils/ring.h
index 1802b44..55880a6 100644
--- a/utils/ring.h
+++ b/utils/ring.h
@@ -66,24 +66,6 @@
 /** Find the element (by hostname) in the given ring, leave it in the
  * provided element variable
  */
-#define RING_FINDBYHOST(ring, element, hostname) \
-       /*LOG("RING_FINDBYHOST(%s, %s)", #ring, hostname);*/ \
-       if (ring) { \
-               bool found = false; \
-               element = ring; \
-               do { \
-                       if (strcasecmp(element->host, hostname) == 0) { \
-                               found = true; \
-                               break; \
-                       } \
-                       element = element->r_next; \
-               } while (element != ring); \
-               if (!found) element = 0; \
-       } else element = 0
-
-/** Find the element (by hostname) in the given ring, leave it in the
- * provided element variable
- */
 #define RING_FINDBYLWCHOST(ring, element, lwc_hostname) \
        /*LOG("RING_FINDBYHOST(%s, %s)", #ring, hostname);*/ \
        if (ring) { \
@@ -112,19 +94,6 @@
                } while (p != ring); \
        } else sizevar = 0
 
-/** Count the number of elements in the ring which match the provided hostname 
*/
-#define RING_COUNTBYHOST(ringtype, ring, sizevar, hostname) \
-       /*LOG("RING_COUNTBYHOST(%s, %s)", #ring, hostname);*/ \
-       if (ring) { \
-               ringtype *p = ring; \
-               sizevar = 0; \
-               do { \
-                       if (strcasecmp(p->host, hostname) == 0) \
-                               sizevar++; \
-                       p = p->r_next; \
-               } while (p != ring); \
-       } else sizevar = 0
-
 /** Count the number of elements in the ring which match the provided 
lwc_hostname */
 #define RING_COUNTBYLWCHOST(ringtype, ring, sizevar, lwc_hostname) \
        /*LOG("RING_COUNTBYHOST(%s, %s)", #ring, hostname);*/ \
@@ -136,7 +105,7 @@
                        /* nsurl guarantees lowercase host */ \
                        if (lwc_string_isequal(p->host, lwc_hostname, \
                                        &matches) == lwc_error_ok) \
-                               if (matches) \
+                               if (matches) \
                                        sizevar++; \
                        p = p->r_next; \
                } while (p != ring); \


-- 
NetSurf Browser

_______________________________________________
netsurf-commits mailing list
[email protected]
http://listmaster.pepperfish.net/cgi-bin/mailman/listinfo/netsurf-commits-netsurf-browser.org

Reply via email to