From 0f228ada91a9460d1042b1a854fb1a0a32ed3f10 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Mon, 6 Feb 2006 00:10:09 +0000 Subject: [project @ 2006-02-06 00:10:09 by jmb] Implement HTTP caching algorithm; this should avoid stale cache entries being used. svn path=/import/netsurf/; revision=2059 --- utils/utils.c | 23 +++++++++++++++++++++++ utils/utils.h | 1 + 2 files changed, 24 insertions(+) (limited to 'utils') diff --git a/utils/utils.c b/utils/utils.c index 0632b2318..d2cab2aa5 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -268,3 +268,26 @@ char *human_friendly_bytesize(unsigned long bsize) { return curbuffer; } + +/** + * Create an RFC 1123 compliant date string from a Unix timestamp + * + * \param t The timestamp to consider + * \return Pointer to buffer containing string - invalidated by next call. + */ +const char *rfc1123_date(time_t t) +{ + static char ret[30]; + + struct tm *tm = gmtime(&t); + const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }, + *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", + "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; + + snprintf(ret, sizeof ret, "%s, %02d %s %d %02d:%02d:%02d GMT", + days[tm->tm_wday], tm->tm_mday, months[tm->tm_mon], + tm->tm_year + 1900, tm->tm_hour, tm->tm_min, + tm->tm_sec); + + return ret; +} diff --git a/utils/utils.h b/utils/utils.h index 50623670e..4eaf02666 100644 --- a/utils/utils.h +++ b/utils/utils.h @@ -56,6 +56,7 @@ void regcomp_wrapper(regex_t *preg, const char *regex, int cflags); void clean_cookiejar(void); void unicode_transliterate(unsigned int c, char **r); char *human_friendly_bytesize(unsigned long bytesize); +const char *rfc1123_date(time_t t); /* Platform specific functions */ void die(const char * const error); -- cgit v1.2.3