summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
Diffstat (limited to 'content')
-rw-r--r--content/llcache.c82
-rw-r--r--content/urldb.c23
2 files changed, 64 insertions, 41 deletions
diff --git a/content/llcache.c b/content/llcache.c
index 7144dc585..9381ce958 100644
--- a/content/llcache.c
+++ b/content/llcache.c
@@ -37,7 +37,6 @@
#include <strings.h>
#include <inttypes.h>
-#include <curl/curl.h>
#include <nsutils/time.h>
#include "utils/config.h"
@@ -590,59 +589,79 @@ static nserror llcache_fetch_split_header(const uint8_t *data, size_t len,
static nserror llcache_fetch_parse_header(llcache_object *object,
const uint8_t *data, size_t len, char **name, char **value)
{
- nserror error;
+ nserror res;
/* Set fetch response time if not already set */
- if (object->cache.res_time == 0)
+ if (object->cache.res_time == 0) {
object->cache.res_time = time(NULL);
+ }
/* Decompose header into name-value pair */
- error = llcache_fetch_split_header(data, len, name, value);
- if (error != NSERROR_OK)
- return error;
+ res = llcache_fetch_split_header(data, len, name, value);
+ if (res != NSERROR_OK) {
+ return res;
+ }
/* Parse cache headers to populate cache control data */
-#define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++
- if (5 < len && strcasecmp(*name, "Date") == 0) {
+ if ((5 < len) &&
+ strcasecmp(*name, "Date") == 0) {
/* extract Date header */
- object->cache.date = curl_getdate(*value, NULL);
- } else if (4 < len && strcasecmp(*name, "Age") == 0) {
+ nsc_strntimet(*value,
+ strlen(*value),
+ &object->cache.date);
+ } else if ((4 < len) &&
+ strcasecmp(*name, "Age") == 0) {
/* extract Age header */
- if ('0' <= **value && **value <= '9')
+ if ('0' <= **value && **value <= '9') {
object->cache.age = atoi(*value);
- } else if (8 < len && strcasecmp(*name, "Expires") == 0) {
+ }
+ } else if ((8 < len) &&
+ strcasecmp(*name, "Expires") == 0) {
/* extract Expires header */
- object->cache.expires = curl_getdate(*value, NULL);
- } else if (14 < len && strcasecmp(*name, "Cache-Control") == 0) {
+ res = nsc_strntimet(*value,
+ strlen(*value),
+ &object->cache.expires);
+ if (res != NSERROR_OK) {
+ object->cache.expires = (time_t)0x7fffffff;
+ }
+ } else if ((14 < len) &&
+ strcasecmp(*name, "Cache-Control") == 0) {
/* extract and parse Cache-Control header */
const char *start = *value;
const char *comma = *value;
while (*comma != '\0') {
- while (*comma != '\0' && *comma != ',')
+ while (*comma != '\0' && *comma != ',') {
comma++;
-
- if (8 < comma - start && (strncasecmp(start,
- "no-cache", 8) == 0 ||
- strncasecmp(start, "no-store", 8) == 0))
- /* When we get a disk cache we should
- * distinguish between these two */
+ }
+
+ 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) {
+ } else if ((7 < comma - start) &&
+ strncasecmp(start, "max-age", 7) == 0) {
/* Find '=' */
- while (start < comma && *start != '=')
+ while (start < comma && *start != '=') {
start++;
+ }
/* Skip over it */
start++;
+#define SKIP_ST(p) while (*p != '\0' && (*p == ' ' || *p == '\t')) p++
+
/* Skip whitespace */
SKIP_ST(start);
- if (start < comma)
+ if (start < comma) {
object->cache.max_age = atoi(start);
+ }
}
if (*comma != '\0') {
@@ -652,10 +671,13 @@ static nserror llcache_fetch_parse_header(llcache_object *object,
SKIP_ST(comma);
}
+#undef SKIP_ST
+
/* Set start for next token */
start = comma;
}
- } else if (5 < len && strcasecmp(*name, "ETag") == 0) {
+ } else if ((5 < len) &&
+ (strcasecmp(*name, "ETag") == 0)) {
/* extract ETag header */
free(object->cache.etag);
object->cache.etag = strdup(*value);
@@ -664,12 +686,14 @@ static nserror llcache_fetch_parse_header(llcache_object *object,
free(*value);
return NSERROR_NOMEM;
}
- } else if (14 < len && strcasecmp(*name, "Last-Modified") == 0) {
+ } else if ((14 < len) &&
+ (strcasecmp(*name, "Last-Modified") == 0)) {
/* extract Last-Modified header */
- object->cache.last_modified = curl_getdate(*value, NULL);
+ nsc_strntimet(*value,
+ strlen(*value),
+ &object->cache.last_modified);
}
-#undef SKIP_ST
return NSERROR_OK;
}
diff --git a/content/urldb.c b/content/urldb.c
index edb49b549..d7a7fed1c 100644
--- a/content/urldb.c
+++ b/content/urldb.c
@@ -95,7 +95,6 @@
#include <string.h>
#include <strings.h>
#include <time.h>
-#include <curl/curl.h>
#include "utils/nsoption.h"
#include "utils/log.h"
@@ -103,6 +102,7 @@
#include "utils/url.h"
#include "utils/utils.h"
#include "utils/bloom.h"
+#include "utils/time.h"
#include "image/bitmap.h"
#include "desktop/cookie_manager.h"
#include "desktop/gui_internal.h"
@@ -1587,22 +1587,21 @@ static bool urldb_parse_avpair(struct cookie_internal_data *c, char *n,
} else if (strcasecmp(n, "Expires") == 0) {
char *datenoday;
time_t expires;
+ nserror res;
- /* Strip dayname from date (these are hugely
- * variable and liable to break the parser.
- * They also serve no useful purpose) */
+ /* Strip dayname from date (these are hugely variable
+ * and liable to break the parser. They also serve no
+ * useful purpose) */
for (datenoday = v; *datenoday && !isdigit(*datenoday);
datenoday++)
; /* do nothing */
- expires = curl_getdate(datenoday, NULL);
- if (expires == -1) {
- /* assume we have an unrepresentable
- * date => force it to the maximum
- * possible value of a 32bit time_t
- * (this may break in 2038. We'll
- * deal with that once we come to
- * it) */
+ res = nsc_strntimet(datenoday, strlen(datenoday), &expires);
+ if (res != NSERROR_OK) {
+ /* assume we have an unrepresentable date =>
+ * force it to the maximum possible value of a
+ * 32bit time_t (this may break in 2038. We'll
+ * deal with that once we come to it) */
expires = (time_t)0x7fffffff;
}
c->expires = expires;