diff options
author | corvid <corvid@lavabit.com> | 2010-01-09 20:20:43 +0000 |
---|---|---|
committer | corvid <corvid@lavabit.com> | 2010-01-09 20:20:43 +0000 |
commit | fed42d15a0d2358fd6766c6f0e230ef15c46795a (patch) | |
tree | 9a021c96461ccb41ba3c16c1395f2dfb4b76de5f | |
parent | c9e62a3b4b93a444617c14b42251e5fe617cc94d (diff) |
timestamps a little less strict
-rw-r--r-- | dpi/cookies.c | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/dpi/cookies.c b/dpi/cookies.c index 936d594f..50c50c2e 100644 --- a/dpi/cookies.c +++ b/dpi/cookies.c @@ -389,20 +389,19 @@ static void Cookies_save_and_free() fclose(file_stream); } -static char *months[] = -{ "", - "Jan", "Feb", "Mar", - "Apr", "May", "Jun", - "Jul", "Aug", "Sep", - "Oct", "Nov", "Dec" -}; - /* * Take a months name and return a number between 1-12. * E.g. 'April' -> 4 */ static int Cookies_get_month(const char *month_name) { + static const char *const months[] = + { "", + "Jan", "Feb", "Mar", + "Apr", "May", "Jun", + "Jul", "Aug", "Sep", + "Oct", "Nov", "Dec" + }; int i; for (i = 1; i <= 12; i++) { @@ -423,20 +422,29 @@ static int Cookies_get_month(const char *month_name) * Tue May 21 13:46:22 1991\n * Tue May 21 13:46:22 1991 * + * Let's add: + * Mon Jan 11 08:00:00 2010 GMT + * * (return 0 on malformed date string syntax) + * + * NOTE that the draft spec wants user agents to be more flexible in what + * they accept. For now, let's hack in special cases when they're encountered. + * Why? Because this function is currently understandable, and I don't want to + * abandon that (or at best decrease that -- see section 5.1.1) until there + * is known to be good reason. */ static time_t Cookies_create_timestamp(const char *expires) { time_t ret; int day, month, year, hour, minutes, seconds; char *cp; - char *E_msg = + const char *const E_msg = "Expire date is malformed!\n" " (should be RFC-1123 | RFC-850 | ANSI asctime)\n" - " Ignoring cookie: "; + " Discarding cookie: "; cp = strchr(expires, ','); - if (!cp && (strlen(expires) == 24 || strlen(expires) == 25)) { + if (!cp && strlen(expires)>20 && expires[13] == ':' && expires[16] == ':') { /* Looks like ANSI asctime format... */ cp = (char *)expires; day = strtol(cp + 8, NULL, 10); /* day */ @@ -486,9 +494,6 @@ static time_t Cookies_create_timestamp(const char *expires) (minutes * 60) + seconds); - MSG("Expires in %ld seconds, at %s", - (long)ret - time(NULL), ctime(&ret)); - return ret; } |