On 16 Jan 2002 at 17:45, Hrvoje Niksic wrote:
> Aside from google, ~0UL is Wget's default value for the expiry time,
> meaning the cookie is non-permanent and valid throughout the session.
> Since Wget sets the value, Wget should be able to print it in DEBUG
> mode.
>
> Do you think this patch would fix the printing problem:
>
> Index: src/cookies.c
> ===================================================================
> RCS file: /pack/anoncvs/wget/src/cookies.c,v
> retrieving revision 1.18
> diff -u -r1.18 cookies.c
> --- src/cookies.c 2001/12/10 02:29:11 1.18
> +++ src/cookies.c 2002/01/16 16:43:21
> @@ -241,7 +241,9 @@
> cookie->domain, cookie->port, cookie->path,
> cookie->permanent ? "permanent" : "nonpermanent",
> cookie->secure,
> - asctime (localtime ((time_t *)&cookie->expiry_time)),
> + (cookie->expiry_time != ~0UL ?
> + asctime (localtime ((time_t *)&cookie->expiry_time))
> + : "UNKNOWN"),
> cookie->attr, cookie->value));
> }
Yes, except for any other values of cookie->expiry_time that would
cause localtime() to return a NULL pointer (in the case of Windows,
anything before 1970). Perhaps the return value of localtime()
should be checked before passing it to asctime() as in the
modified version of your patch I have attached below.
I'm also a little worried about the (time_t *)&cookie->expiry_time
cast, as cookie->expiry time is of type unsigned long. Is a time_t
guaranteed to be the same size as an unsigned long?
Index: src/cookies.c
===================================================================
RCS file: /pack/anoncvs/wget/src/cookies.c,v
retrieving revision 1.18
diff -u -r1.18 cookies.c
--- src/cookies.c 2001/12/10 02:29:11 1.18
+++ src/cookies.c 2002/01/17 11:29:00
@@ -184,6 +184,9 @@
struct cookie *chain_head;
char *hostport;
char *chain_key;
+#ifdef DEBUG
+ struct tm *local_expiry;
+#endif
if (!cookies_hash_table)
/* If the hash table is not initialized, do so now, because we'll
@@ -241,7 +244,10 @@
cookie->domain, cookie->port, cookie->path,
cookie->permanent ? "permanent" : "nonpermanent",
cookie->secure,
- asctime (localtime ((time_t *)&cookie->expiry_time)),
+ (cookie->expiry_time != ~0UL &&
+ NULL != (local_expiry = localtime ((time_t *)&cookie->expiry_time))
+ ? asctime (local_expiry)
+ : "UNKNOWN"),
cookie->attr, cookie->value));
}