Gitweb links:

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

The branch, master has been updated
       via  047c82cfce53102aced0f76f5ca13fe3c56b4db2 (commit)
       via  04b790643b9e45a1ba8919481f3c4beb80a66c31 (commit)
      from  9893b05b084980ff498eee6dd17853d8df807f27 (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=047c82cfce53102aced0f76f5ca13fe3c56b4db2
commit 047c82cfce53102aced0f76f5ca13fe3c56b4db2
Author: John-Mark Bell <[email protected]>
Commit: John-Mark Bell <[email protected]>

    LLCache: use Cache-Control parser

diff --git a/content/llcache.c b/content/llcache.c
index 0bf3979..d78d5bb 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -45,6 +45,7 @@
 #include "utils/nsurl.h"
 #include "utils/utils.h"
 #include "utils/time.h"
+#include "utils/http.h"
 #include "netsurf/misc.h"
 #include "desktop/gui_internal.h"
 
@@ -583,59 +584,28 @@ static nserror llcache_fetch_split_header(const uint8_t 
*data, size_t len,
 static nserror
 llcache_fetch_parse_cache_control(llcache_object *object, char *value)
 {
-       const char *start = value;
-       const char *comma = value;
-
-       while (*comma != '\0') {
-               while (*comma != '\0' && *comma != ',') {
-                       comma++;
-               }
-
-               if ((8 < comma - start) &&
-                   (strncasecmp(start, "no-cache", 8) == 0 ||
-                    strncasecmp(start, "no-store", 8) == 0)) {
-                       /**
-                        * \todo When we get a disk cache we should
-                        *  distinguish between these two.
-                        */
-                       object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
-               } else if ((7 < comma - start) &&
-                          strncasecmp(start, "max-age", 7) == 0) {
-                       start += 7; /* skip max-age */
-
-                       /* Find '=' */
-                       while (start < comma && *start != '=') {
-                               start++;
-                       }
-
-                       /* Skip over '=' */
-                       start++;
-
-#define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++
-
-                       if (start < comma) {
-                                 /* Skip whitespace */
-                                 SKIP_ST(start);
-                       }
+       http_cache_control *cc;
+       nserror error;
 
-                       if (start < comma) {
-                               object->cache.max_age = atoi(start);
+       error = http_parse_cache_control(value, &cc);
+       if (error != NSERROR_OK) {
+               /* Ignore parse errors */
+               return NSERROR_OK;
+       }
 
-                       }
-               }
+       if (http_cache_control_no_cache(cc) ||
+                       http_cache_control_no_store(cc)) {
+               /**
+                * \todo When we get a disk cache we should
+                *  distinguish between these two.
+                */
+               object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
+       }
 
-               if (*comma != '\0') {
-                       /* Skip past comma */
-                       comma++;
-                       /* Skip whitespace */
-                       SKIP_ST(comma);
-               }
+       object->cache.max_age = http_cache_control_max_age(cc);
 
-#undef SKIP_ST
+       http_cache_control_destroy(cc);
 
-               /* Set start for next token */
-               start = comma;
-       }
        return NSERROR_OK;
 }
 


commitdiff 
http://git.netsurf-browser.org/netsurf.git/commit/?id=04b790643b9e45a1ba8919481f3c4beb80a66c31
commit 04b790643b9e45a1ba8919481f3c4beb80a66c31
Author: John-Mark Bell <[email protected]>
Commit: John-Mark Bell <[email protected]>

    HTTP: add minimal parser for Cache-Control

diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index ea8d7de..4261f4d 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -144,6 +144,8 @@ CORESTRING_LWC_STRING(_top);
 CORESTRING_LWC_VALUE(shortcut_icon, "shortcut icon");
 CORESTRING_LWC_VALUE(slash_, "/");
 CORESTRING_LWC_VALUE(max_age, "max-age");
+CORESTRING_LWC_VALUE(no_cache, "no-cache");
+CORESTRING_LWC_VALUE(no_store, "no-store");
 
 /* mime types */
 CORESTRING_LWC_VALUE(multipart_form_data, "multipart/form-data");
diff --git a/utils/http.h b/utils/http.h
index 00caf89..8da4f3f 100644
--- a/utils/http.h
+++ b/utils/http.h
@@ -27,6 +27,7 @@
 
 #include "utils/errors.h"
 
+#include "utils/http/cache-control.h"
 #include "utils/http/content-disposition.h"
 #include "utils/http/content-type.h"
 #include "utils/http/strict-transport-security.h"
diff --git a/utils/http/Makefile b/utils/http/Makefile
index f3bb765..b60f8f6 100644
--- a/utils/http/Makefile
+++ b/utils/http/Makefile
@@ -1,7 +1,7 @@
 # http utils sources
 
 S_HTTP := challenge.c generics.c primitives.c parameter.c              \
-       content-disposition.c content-type.c \
+       cache-control.c content-disposition.c content-type.c \
        strict-transport-security.c www-authenticate.c
 
 S_HTTP := $(addprefix utils/http/,$(S_HTTP))
diff --git a/utils/http/cache-control.c b/utils/http/cache-control.c
new file mode 100644
index 0000000..f348f16
--- /dev/null
+++ b/utils/http/cache-control.c
@@ -0,0 +1,343 @@
+/*
+ * Copyright 2019 John-Mark Bell <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <limits.h>
+#include <stdlib.h>
+
+#include "utils/corestrings.h"
+#include "utils/http.h"
+
+#include "utils/http/generics.h"
+#include "utils/http/primitives.h"
+
+/**
+ * Representation of a Cache-Control
+ */
+struct http_cache_control {
+       uint32_t max_age;               /**< Max age (delta seconds) */
+       bool no_cache;                  /**< Whether caching is forbidden */
+       bool no_store;                  /**< Whether persistent caching is 
forbidden */
+};
+
+/**
+ * Representation of a directive
+ */
+typedef struct http_directive {
+       http__item base;
+
+       lwc_string *name;               /**< Parameter name */
+       lwc_string *value;              /**< Parameter value (optional) */
+} http_directive;
+
+
+static void http_destroy_directive(http_directive *self)
+{
+       lwc_string_unref(self->name);
+       if (self->value != NULL) {
+               lwc_string_unref(self->value);
+       }
+       free(self);
+}
+
+static nserror http__parse_directive(const char **input,
+               http_directive **result)
+{
+       const char *pos = *input;
+       lwc_string *name;
+       lwc_string *value = NULL;
+       http_directive *directive;
+       nserror error;
+
+       /* token [ "=" ( token | quoted-string ) ] */
+
+       error = http__parse_token(&pos, &name);
+       if (error != NSERROR_OK)
+               return error;
+
+       http__skip_LWS(&pos);
+
+       if (*pos == '=') {
+               pos++;
+
+               http__skip_LWS(&pos);
+
+               if (*pos == '"')
+                       error = http__parse_quoted_string(&pos, &value);
+               else
+                       error = http__parse_token(&pos, &value);
+
+               if (error != NSERROR_OK) {
+                       lwc_string_unref(name);
+                       return error;
+               }
+       }
+
+       directive = malloc(sizeof(*directive));
+       if (directive == NULL) {
+               if (value != NULL) {
+                       lwc_string_unref(value);
+               }
+               lwc_string_unref(name);
+               return NSERROR_NOMEM;
+       }
+
+       HTTP__ITEM_INIT(directive, NULL, http_destroy_directive);
+       directive->name = name;
+       directive->value = value;
+
+       *result = directive;
+       *input = pos;
+
+       return NSERROR_OK;
+}
+
+static void http_directive_list_destroy(http_directive *list)
+{
+       http__item_list_destroy(list);
+}
+
+static nserror http_directive_list_find_item(const http_directive *list,
+               lwc_string *name, lwc_string **value)
+{
+       bool match;
+
+       while (list != NULL) {
+               if (lwc_string_caseless_isequal(name, list->name,
+                               &match) == lwc_error_ok && match)
+                       break;
+
+               list = (http_directive *) list->base.next;
+       }
+
+       if (list == NULL)
+               return NSERROR_NOT_FOUND;
+
+       if (list->value != NULL) {
+               *value = lwc_string_ref(list->value);
+       } else {
+               *value = NULL;
+       }
+
+       return NSERROR_OK;
+}
+
+static const http_directive *http_directive_list_iterate(
+               const http_directive *cur,
+               lwc_string **name, lwc_string **value)
+{
+       if (cur == NULL)
+               return NULL;
+
+       *name = lwc_string_ref(cur->name);
+       if (cur->value != NULL) {
+               *value = lwc_string_ref(cur->value);
+       } else {
+               *value = NULL;
+       }
+
+       return (http_directive *) cur->base.next;
+}
+
+static uint32_t count(const http_directive *list, lwc_string *key)
+{
+       uint32_t count = 0;
+       bool match;
+
+       while (list != NULL) {
+               if (lwc_string_caseless_isequal(key, list->name,
+                               &match) == lwc_error_ok && match) {
+                       count++;
+               }
+
+               list = (http_directive *) list->base.next;
+       }
+
+       return count;
+}
+
+static bool check_duplicates(const http_directive *directives)
+{
+       bool result = true;
+       const http_directive *key = directives;
+
+       if (key == NULL) {
+               /* No directives, so there can't be any duplicates */
+               return true;
+       }
+
+       do {
+               lwc_string *name = NULL, *value = NULL;
+
+               key = http_directive_list_iterate(key, &name, &value);
+
+               result &= (count(directives, name) == 1);
+
+               lwc_string_unref(name);
+               if (value != NULL) {
+                       lwc_string_unref(value);
+               }
+       } while (key != NULL);
+
+       return result;
+}
+
+static nserror parse_max_age(lwc_string *value, uint32_t *result)
+{
+       const char *pos = lwc_string_data(value);
+       const char *end = pos + lwc_string_length(value);
+       uint32_t val = 0;
+
+       /* 1*DIGIT */
+
+       if (pos == end) {
+               /* Blank value */
+               return NSERROR_NOT_FOUND;
+       }
+
+       while (pos < end) {
+               if ('0' <= *pos && *pos <= '9') {
+                       uint32_t nv = val * 10 + (*pos - '0');
+                       if (nv < val) {
+                               val = UINT_MAX;
+                       } else {
+                               val = nv;
+                       }
+               } else {
+                       /* Non-digit */
+                       return NSERROR_NOT_FOUND;
+               }
+
+               pos++;
+       }
+
+       *result = val;
+
+       return NSERROR_OK;
+}
+
+/* See cache-control.h for documentation */
+nserror http_parse_cache_control(const char *header_value,
+               http_cache_control **result)
+{
+       const char *pos = header_value;
+       http_cache_control *cc;
+       http_directive *first = NULL;
+       http_directive *directives = NULL;
+       lwc_string *value_str = NULL;
+       uint32_t max_age = 0;
+       bool no_cache = false;
+       bool no_store = false;
+       nserror error;
+
+       /* 1#cache-directive */
+
+       http__skip_LWS(&pos);
+
+       error = http__parse_directive(&pos, &first);
+       if (error != NSERROR_OK) {
+               return error;
+       }
+
+       http__skip_LWS(&pos);
+
+       if (*pos == ',') {
+               error = http__item_list_parse(&pos,
+                               http__parse_directive, first, &directives);
+               if (error != NSERROR_OK) {
+                       if (directives != NULL) {
+                               http_directive_list_destroy(directives);
+                       }
+                       return error;
+               }
+       } else {
+               directives = first;
+       }
+
+       /* Each directive must only appear once */
+       if (check_duplicates(directives) == false) {
+               http_directive_list_destroy(directives);
+               return NSERROR_NOT_FOUND;
+       }
+
+       /* Find max-age */
+       error = http_directive_list_find_item(directives,
+                       corestring_lwc_max_age, &value_str);
+       if (error == NSERROR_OK && value_str != NULL) {
+               error = parse_max_age(value_str, &max_age);
+               lwc_string_unref(value_str);
+       }
+
+       /* Find no-cache */
+       error = http_directive_list_find_item(directives,
+                       corestring_lwc_no_cache, &value_str);
+       if (error == NSERROR_OK) {
+               no_cache = true;
+               if (value_str != NULL) {
+                       lwc_string_unref(value_str);
+               }
+       }
+
+       /* Find no-store */
+       error = http_directive_list_find_item(directives,
+                       corestring_lwc_no_store, &value_str);
+       if (error == NSERROR_OK) {
+               no_store = true;
+               if (value_str != NULL) {
+                       lwc_string_unref(value_str);
+               }
+       }
+
+       http_directive_list_destroy(directives);
+
+       cc = malloc(sizeof(*cc));
+       if (cc == NULL) {
+               return NSERROR_NOMEM;
+       }
+
+       cc->max_age = max_age;
+       cc->no_cache = no_cache;
+       cc->no_store = no_store;
+
+       *result = cc;
+
+       return NSERROR_OK;
+}
+
+/* See cache-control.h for documentation */
+void http_cache_control_destroy(http_cache_control *victim)
+{
+       free(victim);
+}
+
+/* See cache-control.h for documentation */
+uint32_t http_cache_control_max_age(http_cache_control *cc)
+{
+       return cc->max_age;
+}
+
+/* See cache-control.h for documentation */
+bool http_cache_control_no_cache(http_cache_control *cc)
+{
+       return cc->no_cache;
+}
+
+/* See cache-control.h for documentation */
+bool http_cache_control_no_store(http_cache_control *cc)
+{
+       return cc->no_store;
+}
diff --git a/utils/http/cache-control.h b/utils/http/cache-control.h
new file mode 100644
index 0000000..22c5f97
--- /dev/null
+++ b/utils/http/cache-control.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright 2019 John-Mark Bell <[email protected]>
+ *
+ * This file is part of NetSurf, http://www.netsurf-browser.org/
+ *
+ * NetSurf is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * NetSurf is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef NETSURF_UTILS_HTTP_CACHE_CONTROL_H_
+#define NETSURF_UTILS_HTTP_CACHE_CONTROL_H_
+
+#include <libwapcaplet/libwapcaplet.h>
+
+typedef struct http_cache_control http_cache_control;
+
+/**
+ * Parse an HTTP Cache-Control header value
+ *
+ * \param header_value  Header value to parse
+ * \param result        Pointer to location to receive result
+ * \return NSERROR_OK on success,
+ *         NSERROR_NOMEM on memory exhaustion,
+ *         appropriate error otherwise
+ */
+nserror http_parse_cache_control(const char *header_value,
+               http_cache_control **result);
+
+/**
+ * Destroy a cache_control object
+ *
+ * \param victim  Object to destroy
+ */
+void http_cache_control_destroy(http_cache_control *victim);
+
+/**
+ * Get the value of a cache control's max-age
+ *
+ * \param cc Object to inspect
+ * \return Max age, in delta-seconds
+ */
+uint32_t http_cache_control_max_age(http_cache_control *cc);
+
+/**
+ * Get the value of a cache control's no-cache flag
+ *
+ * \param cc Object to inspect
+ * \return Whether caching is forbidden
+ */
+bool http_cache_control_no_cache(http_cache_control *cc);
+
+/**
+ * Get the value of a cache control's no-store flag
+ *
+ * \param cc Object to inspect
+ * \return Whether persistent caching is forbidden
+ */
+bool http_cache_control_no_store(http_cache_control *cc);
+
+#endif


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

Summary of changes:
 content/llcache.c                                  |   66 ++++--------
 utils/corestringlist.h                             |    2 +
 utils/http.h                                       |    1 +
 utils/http/Makefile                                |    2 +-
 ...strict-transport-security.c => cache-control.c} |  106 ++++++++++----------
 ...strict-transport-security.h => cache-control.h} |   43 ++++----
 6 files changed, 100 insertions(+), 120 deletions(-)
 copy utils/http/{strict-transport-security.c => cache-control.c} (72%)
 copy utils/http/{strict-transport-security.h => cache-control.h} (51%)

diff --git a/content/llcache.c b/content/llcache.c
index 0bf3979..d78d5bb 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -45,6 +45,7 @@
 #include "utils/nsurl.h"
 #include "utils/utils.h"
 #include "utils/time.h"
+#include "utils/http.h"
 #include "netsurf/misc.h"
 #include "desktop/gui_internal.h"
 
@@ -583,59 +584,28 @@ static nserror llcache_fetch_split_header(const uint8_t 
*data, size_t len,
 static nserror
 llcache_fetch_parse_cache_control(llcache_object *object, char *value)
 {
-       const char *start = value;
-       const char *comma = value;
-
-       while (*comma != '\0') {
-               while (*comma != '\0' && *comma != ',') {
-                       comma++;
-               }
-
-               if ((8 < comma - start) &&
-                   (strncasecmp(start, "no-cache", 8) == 0 ||
-                    strncasecmp(start, "no-store", 8) == 0)) {
-                       /**
-                        * \todo When we get a disk cache we should
-                        *  distinguish between these two.
-                        */
-                       object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
-               } else if ((7 < comma - start) &&
-                          strncasecmp(start, "max-age", 7) == 0) {
-                       start += 7; /* skip max-age */
-
-                       /* Find '=' */
-                       while (start < comma && *start != '=') {
-                               start++;
-                       }
-
-                       /* Skip over '=' */
-                       start++;
-
-#define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++
-
-                       if (start < comma) {
-                                 /* Skip whitespace */
-                                 SKIP_ST(start);
-                       }
+       http_cache_control *cc;
+       nserror error;
 
-                       if (start < comma) {
-                               object->cache.max_age = atoi(start);
+       error = http_parse_cache_control(value, &cc);
+       if (error != NSERROR_OK) {
+               /* Ignore parse errors */
+               return NSERROR_OK;
+       }
 
-                       }
-               }
+       if (http_cache_control_no_cache(cc) ||
+                       http_cache_control_no_store(cc)) {
+               /**
+                * \todo When we get a disk cache we should
+                *  distinguish between these two.
+                */
+               object->cache.no_cache = LLCACHE_VALIDATE_ALWAYS;
+       }
 
-               if (*comma != '\0') {
-                       /* Skip past comma */
-                       comma++;
-                       /* Skip whitespace */
-                       SKIP_ST(comma);
-               }
+       object->cache.max_age = http_cache_control_max_age(cc);
 
-#undef SKIP_ST
+       http_cache_control_destroy(cc);
 
-               /* Set start for next token */
-               start = comma;
-       }
        return NSERROR_OK;
 }
 
diff --git a/utils/corestringlist.h b/utils/corestringlist.h
index ea8d7de..4261f4d 100644
--- a/utils/corestringlist.h
+++ b/utils/corestringlist.h
@@ -144,6 +144,8 @@ CORESTRING_LWC_STRING(_top);
 CORESTRING_LWC_VALUE(shortcut_icon, "shortcut icon");
 CORESTRING_LWC_VALUE(slash_, "/");
 CORESTRING_LWC_VALUE(max_age, "max-age");
+CORESTRING_LWC_VALUE(no_cache, "no-cache");
+CORESTRING_LWC_VALUE(no_store, "no-store");
 
 /* mime types */
 CORESTRING_LWC_VALUE(multipart_form_data, "multipart/form-data");
diff --git a/utils/http.h b/utils/http.h
index 00caf89..8da4f3f 100644
--- a/utils/http.h
+++ b/utils/http.h
@@ -27,6 +27,7 @@
 
 #include "utils/errors.h"
 
+#include "utils/http/cache-control.h"
 #include "utils/http/content-disposition.h"
 #include "utils/http/content-type.h"
 #include "utils/http/strict-transport-security.h"
diff --git a/utils/http/Makefile b/utils/http/Makefile
index f3bb765..b60f8f6 100644
--- a/utils/http/Makefile
+++ b/utils/http/Makefile
@@ -1,7 +1,7 @@
 # http utils sources
 
 S_HTTP := challenge.c generics.c primitives.c parameter.c              \
-       content-disposition.c content-type.c \
+       cache-control.c content-disposition.c content-type.c \
        strict-transport-security.c www-authenticate.c
 
 S_HTTP := $(addprefix utils/http/,$(S_HTTP))
diff --git a/utils/http/strict-transport-security.c b/utils/http/cache-control.c
similarity index 72%
copy from utils/http/strict-transport-security.c
copy to utils/http/cache-control.c
index 9de610c..f348f16 100644
--- a/utils/http/strict-transport-security.c
+++ b/utils/http/cache-control.c
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 John-Mark Bell <[email protected]>
+ * Copyright 2019 John-Mark Bell <[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -26,11 +26,12 @@
 #include "utils/http/primitives.h"
 
 /**
- * Representation of a Strict-Transport-Security
+ * Representation of a Cache-Control
  */
-struct http_strict_transport_security {
+struct http_cache_control {
        uint32_t max_age;               /**< Max age (delta seconds) */
-       bool include_sub_domains;       /**< Whether subdomains are included */
+       bool no_cache;                  /**< Whether caching is forbidden */
+       bool no_store;                  /**< Whether persistent caching is 
forbidden */
 };
 
 /**
@@ -229,20 +230,21 @@ static nserror parse_max_age(lwc_string *value, uint32_t 
*result)
        return NSERROR_OK;
 }
 
-/* See strict-transport-security.h for documentation */
-nserror http_parse_strict_transport_security(const char *header_value,
-               http_strict_transport_security **result)
+/* See cache-control.h for documentation */
+nserror http_parse_cache_control(const char *header_value,
+               http_cache_control **result)
 {
        const char *pos = header_value;
-       http_strict_transport_security *sts;
+       http_cache_control *cc;
        http_directive *first = NULL;
        http_directive *directives = NULL;
-       lwc_string *max_age_str = NULL, *isd_str = NULL;
-       uint32_t max_age;
-       bool include_sub_domains = false;
+       lwc_string *value_str = NULL;
+       uint32_t max_age = 0;
+       bool no_cache = false;
+       bool no_store = false;
        nserror error;
 
-       /* directive *( ";" directive ) */
+       /* 1#cache-directive */
 
        http__skip_LWS(&pos);
 
@@ -253,7 +255,7 @@ nserror http_parse_strict_transport_security(const char 
*header_value,
 
        http__skip_LWS(&pos);
 
-       if (*pos == ';') {
+       if (*pos == ',') {
                error = http__item_list_parse(&pos,
                                http__parse_directive, first, &directives);
                if (error != NSERROR_OK) {
@@ -272,70 +274,70 @@ nserror http_parse_strict_transport_security(const char 
*header_value,
                return NSERROR_NOT_FOUND;
        }
 
-       /* max-age is required */
+       /* Find max-age */
        error = http_directive_list_find_item(directives,
-                       corestring_lwc_max_age, &max_age_str);
-       if (error != NSERROR_OK || max_age_str == NULL) {
-               http_directive_list_destroy(directives);
-               return NSERROR_NOT_FOUND;
+                       corestring_lwc_max_age, &value_str);
+       if (error == NSERROR_OK && value_str != NULL) {
+               error = parse_max_age(value_str, &max_age);
+               lwc_string_unref(value_str);
        }
 
-       error = parse_max_age(max_age_str, &max_age);
-       if (error != NSERROR_OK) {
-               lwc_string_unref(max_age_str);
-               http_directive_list_destroy(directives);
-               return NSERROR_NOT_FOUND;
+       /* Find no-cache */
+       error = http_directive_list_find_item(directives,
+                       corestring_lwc_no_cache, &value_str);
+       if (error == NSERROR_OK) {
+               no_cache = true;
+               if (value_str != NULL) {
+                       lwc_string_unref(value_str);
+               }
        }
-       lwc_string_unref(max_age_str);
 
-       /* includeSubDomains is optional and valueless */
+       /* Find no-store */
        error = http_directive_list_find_item(directives,
-                       corestring_lwc_includesubdomains, &isd_str);
-       if (error != NSERROR_OK && error != NSERROR_NOT_FOUND) {
-               http_directive_list_destroy(directives);
-               return NSERROR_NOT_FOUND;
-       } else if (error == NSERROR_OK) {
-               if (isd_str != NULL) {
-                       /* Present, but not valueless: invalid */
-                       lwc_string_unref(isd_str);
-                       http_directive_list_destroy(directives);
-                       return NSERROR_NOT_FOUND;
+                       corestring_lwc_no_store, &value_str);
+       if (error == NSERROR_OK) {
+               no_store = true;
+               if (value_str != NULL) {
+                       lwc_string_unref(value_str);
                }
-               include_sub_domains = true;
        }
+
        http_directive_list_destroy(directives);
 
-       sts = malloc(sizeof(*sts));
-       if (sts == NULL) {
+       cc = malloc(sizeof(*cc));
+       if (cc == NULL) {
                return NSERROR_NOMEM;
        }
 
-       sts->max_age = max_age;
-       sts->include_sub_domains = include_sub_domains;
+       cc->max_age = max_age;
+       cc->no_cache = no_cache;
+       cc->no_store = no_store;
 
-       *result = sts;
+       *result = cc;
 
        return NSERROR_OK;
 }
 
-/* See strict-transport-security.h for documentation */
-void http_strict_transport_security_destroy(
-               http_strict_transport_security *victim)
+/* See cache-control.h for documentation */
+void http_cache_control_destroy(http_cache_control *victim)
 {
        free(victim);
 }
 
-/* See strict-transport-security.h for documentation */
-uint32_t http_strict_transport_security_max_age(
-               http_strict_transport_security *sts)
+/* See cache-control.h for documentation */
+uint32_t http_cache_control_max_age(http_cache_control *cc)
 {
-       return sts->max_age;
+       return cc->max_age;
 }
 
-/* See strict-transport-security.h for documentation */
-bool http_strict_transport_security_include_subdomains(
-               http_strict_transport_security *sts)
+/* See cache-control.h for documentation */
+bool http_cache_control_no_cache(http_cache_control *cc)
 {
-       return sts->include_sub_domains;
+       return cc->no_cache;
 }
 
+/* See cache-control.h for documentation */
+bool http_cache_control_no_store(http_cache_control *cc)
+{
+       return cc->no_store;
+}
diff --git a/utils/http/strict-transport-security.h b/utils/http/cache-control.h
similarity index 51%
copy from utils/http/strict-transport-security.h
copy to utils/http/cache-control.h
index 4e52419..22c5f97 100644
--- a/utils/http/strict-transport-security.h
+++ b/utils/http/cache-control.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2018 John-Mark Bell <[email protected]>
+ * Copyright 2019 John-Mark Bell <[email protected]>
  *
  * This file is part of NetSurf, http://www.netsurf-browser.org/
  *
@@ -16,15 +16,15 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef NETSURF_UTILS_HTTP_STRICT_TRANSPORT_SECURITY_H_
-#define NETSURF_UTILS_HTTP_STRICT_TRANSPORT_SECURITY_H_
+#ifndef NETSURF_UTILS_HTTP_CACHE_CONTROL_H_
+#define NETSURF_UTILS_HTTP_CACHE_CONTROL_H_
 
 #include <libwapcaplet/libwapcaplet.h>
 
-typedef struct http_strict_transport_security http_strict_transport_security;
+typedef struct http_cache_control http_cache_control;
 
 /**
- * Parse an HTTP Strict-Transport-Security header value
+ * Parse an HTTP Cache-Control header value
  *
  * \param header_value  Header value to parse
  * \param result        Pointer to location to receive result
@@ -32,33 +32,38 @@ typedef struct http_strict_transport_security 
http_strict_transport_security;
  *         NSERROR_NOMEM on memory exhaustion,
  *         appropriate error otherwise
  */
-nserror http_parse_strict_transport_security(const char *header_value,
-               http_strict_transport_security **result);
+nserror http_parse_cache_control(const char *header_value,
+               http_cache_control **result);
 
 /**
- * Destroy a strict transport security object
+ * Destroy a cache_control object
  *
  * \param victim  Object to destroy
  */
-void http_strict_transport_security_destroy(
-               http_strict_transport_security *victim);
+void http_cache_control_destroy(http_cache_control *victim);
 
 /**
- * Get the value of a strict transport security's max-age
+ * Get the value of a cache control's max-age
  *
- * \param sts Object to inspect
+ * \param cc Object to inspect
  * \return Max age, in delta-seconds
  */
-uint32_t http_strict_transport_security_max_age(
-               http_strict_transport_security *sts);
+uint32_t http_cache_control_max_age(http_cache_control *cc);
 
 /**
- * Get the value of a strict transport security's includeSubDomains flag
+ * Get the value of a cache control's no-cache flag
  *
- * \param sts Object to inspect
- * \return Whether subdomains should be included
+ * \param cc Object to inspect
+ * \return Whether caching is forbidden
  */
-bool http_strict_transport_security_include_subdomains(
-               http_strict_transport_security *sts);
+bool http_cache_control_no_cache(http_cache_control *cc);
+
+/**
+ * Get the value of a cache control's no-store flag
+ *
+ * \param cc Object to inspect
+ * \return Whether persistent caching is forbidden
+ */
+bool http_cache_control_no_store(http_cache_control *cc);
 
 #endif


-- 
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