(atoi_1, atoi_2, atoi_4): New.
* keylist.c (parse_timestamp): Removed. Changed all callers to use
the new function.
* verify.c (parse_valid_sig): Ditto. Repalced the errno check.
* sign.c (parse_sig_created): Ditto.
+2003-11-19 Werner Koch <wk@gnupg.org>
+
+ * conversion.c (_gpgme_parse_timestamp): New.
+ (atoi_1, atoi_2, atoi_4): New.
+ * keylist.c (parse_timestamp): Removed. Changed all callers to use
+ the new function.
+ * verify.c (parse_valid_sig): Ditto. Repalced the errno check.
+ * sign.c (parse_sig_created): Ditto.
+
2003-10-31 Werner Koch <wk@gnupg.org>
* keylist.c (parse_timestamp): Detect ISO 8601 timestamps and try
#include <stdlib.h>
#include <string.h>
+#include <time.h>
#include <errno.h>
#include "gpgme.h"
#include "util.h"
+
+#define atoi_1(p) (*(p) - '0' )
+#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
+#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
+
+
\f
/* Convert two hexadecimal digits from STR to the value they
represent. Returns -1 if one of the characters is not a
return 0;
}
+
+/* Parse the string TIMESTAMP into a time_t. The string may either be
+ seconds since Epoch or in the ISO 8601 format like
+ "20390815T143012". Returns 0 for an empty string or seconds since
+ Epoch. Leading spaces are skipped. If ENDP is not NULL, it will
+ point to the next non-parsed character in TIMESTRING. */
+time_t
+_gpgme_parse_timestamp (const char *timestamp, char **endp)
+{
+ /* Need to skip leading spaces, because that is what strtoul does
+ but not our ISO 8601 checking code. */
+ while (*timestamp && *timestamp== ' ')
+ timestamp++;
+ if (!*timestamp)
+ 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);
+
+ if (endp)
+ *endp = (char*)(timestamp + 15);
+#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, endp, 10);
+}
+
+
+
\f
static struct
{
AM_PATH_GPGME macro) check that this header matches the installed
library. Warning: Do not edit the next line. configure will do
that for you! */
-#define GPGME_VERSION "0.4.3"
+#define GPGME_VERSION "0.4.4"
\f
/* Some opaque data types used by GPGME. */
}
\f
-static time_t
-parse_timestamp (char *timestamp)
-{
- if (!*timestamp)
- 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);
-}
-
static void
set_mainkey_trust_info (gpgme_key_t key, const char *src)
/* Field 6 has the timestamp (seconds). */
if (fields >= 6)
- subkey->timestamp = parse_timestamp (field[5]);
+ subkey->timestamp = _gpgme_parse_timestamp (field[5], NULL);
/* Field 7 has the expiration time (seconds). */
if (fields >= 7)
- subkey->expires = parse_timestamp (field[6]);
+ subkey->expires = _gpgme_parse_timestamp (field[6], NULL);
/* Field 8 has the X.509 serial number. */
if (fields >= 8 && (rectype == RT_CRT || rectype == RT_CRS))
/* Field 6 has the timestamp (seconds). */
if (fields >= 6)
- subkey->timestamp = parse_timestamp (field[5]);
+ subkey->timestamp = _gpgme_parse_timestamp (field[5], NULL);
/* Field 7 has the expiration time (seconds). */
if (fields >= 7)
- subkey->expires = parse_timestamp (field[6]);
+ subkey->expires = _gpgme_parse_timestamp (field[6], NULL);
/* Field 8 is reserved (LID). */
/* Field 9 has the ownertrust. */
/* Field 6 has the timestamp (seconds). */
if (fields >= 6)
- keysig->timestamp = parse_timestamp (field[5]);
+ keysig->timestamp = _gpgme_parse_timestamp (field[5], NULL);
/* Field 7 has the expiration time (seconds). */
if (fields >= 7)
- keysig->expires = parse_timestamp (field[6]);
+ keysig->expires = _gpgme_parse_timestamp (field[6], NULL);
/* Field 11 has the signature class (eg, 0x30 means revoked). */
if (fields >= 11)
}
args = tail;
- sig->timestamp = strtol (args, &tail, 0);
- if (errno || args == tail || *tail != ' ')
+ sig->timestamp = _gpgme_parse_timestamp (args, &tail);
+ if (sig->timestamp == -1 || args == tail || *tail != ' ')
{
/* The crypto backend does not behave. */
free (sig);
gpgme_error_t _gpgme_decode_percent_string (const char *src, char **destp,
size_t len);
+
+/* Parse the string TIMESTAMP into a time_t. The string may either be
+ seconds since Epoch or in the ISO 8601 format like
+ "20390815T143012". Returns 0 for an empty string or seconds since
+ Epoch. Leading spaces are skipped. If ENDP is not NULL, it will
+ point to the next non-parsed character in TIMESTRING. */
+time_t _gpgme_parse_timestamp (const char *timestamp, char **endp);
+
+
gpgme_error_t _gpgme_map_gnupg_error (char *err);
\f
if (end)
{
char *tail;
- errno = 0;
- /* FIXME: We need to cope with ISO time strings here. */
- sig->timestamp = strtol (end, &tail, 0);
- if (errno || end == tail || (*tail && *tail != ' '))
+ sig->timestamp = _gpgme_parse_timestamp (end, &tail);
+ if (sig->timestamp == -1 || end == tail || (*tail && *tail != ' '))
return gpg_error (GPG_ERR_INV_ENGINE);
end = tail;
- sig->exp_timestamp = strtol (end, &tail, 0);
- if (errno || end == tail || (*tail && *tail != ' '))
+ sig->exp_timestamp = _gpgme_parse_timestamp (end, &tail);
+ if (sig->exp_timestamp == -1 || end == tail || (*tail && *tail != ' '))
return gpg_error (GPG_ERR_INV_ENGINE);
}
return 0;