(parse_timestamp): Detect ISO 8601 timestamps and try

to convert them.
This commit is contained in:
Werner Koch 2003-10-31 12:07:48 +00:00
parent 2250b42294
commit 2f1226cea9
4 changed files with 53 additions and 3 deletions

5
TODO
View File

@ -26,6 +26,7 @@ Hey Emacs, this is -*- outline -*- mode!
* Thread support: * Thread support:
** When GNU Pth supports sendmsg/recvmsg, wrap them properly. ** When GNU Pth supports sendmsg/recvmsg, wrap them properly.
** Without timegm (3) support our ISO time parser is not thread safe.
* New features: * New features:
** notification system ** notification system
@ -56,6 +57,10 @@ Hey Emacs, this is -*- outline -*- mode!
worked around in a different way worked around in a different way
*** Selecting the symmetric cipher. *** Selecting the symmetric cipher.
*** Exchanging keys with key servers. *** Exchanging keys with key servers.
** Allow selection of subkeys
** Allow to return time stamps in ISO format
This allows us to handle years later than 2037 properly. With the
time_t interface they are all mapped to 2037-12-31
* Documentation * Documentation
** Document validity and trust issues. ** Document validity and trust issues.

View File

@ -1,3 +1,8 @@
2003-10-31 Werner Koch <wk@gnupg.org>
* keylist.c (parse_timestamp): Detect ISO 8601 timestamps and try
to convert them.
2003-10-10 Marcus Brinkmann <marcus@g10code.de> 2003-10-10 Marcus Brinkmann <marcus@g10code.de>
* genkey.c (get_key_parameter): Make a copy of the key parameters. * genkey.c (get_key_parameter): Make a copy of the key parameters.

View File

@ -122,6 +122,44 @@ parse_timestamp (char *timestamp)
if (!*timestamp) if (!*timestamp)
return 0; return 0;
if (strlen (timestamp) >= 15 && timestamp[8] == 'T')
{
struct tm buf;
int year;
year = atoi_4 (timestamp);
if (year < 1900)
return (time_t)(-1);
/* Fixme: We would better use a configure test to see whether
mktime can handle dates beyond 2038. */
if (sizeof (time_t) <= 4 && year >= 2038)
return (time_t)2145914603; /* 2037-12-31 23:23:23 */
memset (&buf, 0, sizeof buf);
buf.tm_year = year - 1900;
buf.tm_mon = atoi_2 (timestamp+4) - 1;
buf.tm_mday = atoi_2 (timestamp+6);
buf.tm_hour = atoi_2 (timestamp+9);
buf.tm_min = atoi_2 (timestamp+11);
buf.tm_sec = atoi_2 (timestamp+13);
#ifdef HAVE_TIMEGM
return timegm (&buf);
#else
{
time_t tim;
putenv ("TZ=UTC");
tim = mktime (&buf);
#ifdef __GNUC__
#warning fixme: we must somehow reset TZ here. It is not threadsafe anyway.
#endif
return tim;
}
#endif /* !HAVE_TIMEGM */
}
else
return (time_t) strtoul (timestamp, NULL, 10); return (time_t) strtoul (timestamp, NULL, 10);
} }

View File

@ -259,6 +259,8 @@ parse_valid_sig (gpgme_signature_t sig, char *args)
{ {
char *tail; char *tail;
errno = 0; errno = 0;
/* FIXME: We need to cope with ISO time strings here. */
sig->timestamp = strtol (end, &tail, 0); sig->timestamp = strtol (end, &tail, 0);
if (errno || end == tail || (*tail && *tail != ' ')) if (errno || end == tail || (*tail && *tail != ' '))
return gpg_error (GPG_ERR_INV_ENGINE); return gpg_error (GPG_ERR_INV_ENGINE);