From: Werner Koch Date: Tue, 18 Nov 2003 17:29:19 +0000 (+0000) Subject: * configure.ac: Check for timegm. X-Git-Tag: gpgme-1.2.0@1385~510 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=477ccb567369023d260871208928636728bc5912;p=gpgme.git * configure.ac: Check for timegm. * mkerrors: Prettier error formating for gpg-error style codes. * conversion.c (_gpgme_parse_timestamp): New. Now also handles ISO 8601 timestamps as used by gnupg 1.9.2. * keylist.c (parse_timestamp): Removed. Replaced calls by _gpgme_parse_timestamp. * verify.c (_gpgme_verify_status_handler): Replaced strtoul by _gpgme_parse_timestamp. * sign.c (append_xml_siginfo): Ditto. --- diff --git a/branches/gpgme-0-3-branch/ChangeLog b/branches/gpgme-0-3-branch/ChangeLog index fc7888a..ef4e39b 100644 --- a/branches/gpgme-0-3-branch/ChangeLog +++ b/branches/gpgme-0-3-branch/ChangeLog @@ -1,3 +1,7 @@ +2003-11-18 Werner Koch + + * configure.ac: Check for timegm. + 2003-02-18 Marcus Brinkmann Released 0.3.15. diff --git a/branches/gpgme-0-3-branch/NEWS b/branches/gpgme-0-3-branch/NEWS index e450dff..925c607 100644 --- a/branches/gpgme-0-3-branch/NEWS +++ b/branches/gpgme-0-3-branch/NEWS @@ -1,3 +1,8 @@ +Noteworthy changes in version 0.3.16 +------------------------------------------------- + + * Compatibility fixes for GnuPG 1.9. + Noteworthy changes in version 0.3.15 (2003-02-18) ------------------------------------------------- diff --git a/branches/gpgme-0-3-branch/assuan/ChangeLog b/branches/gpgme-0-3-branch/assuan/ChangeLog index 0cf53b8..76cbcab 100644 --- a/branches/gpgme-0-3-branch/assuan/ChangeLog +++ b/branches/gpgme-0-3-branch/assuan/ChangeLog @@ -1,3 +1,7 @@ +2003-11-18 Werner Koch + + * mkerrors: Prettier error formating for gpg-error style codes. + 2002-05-03 Werner Koch * assuan-pipe-connect.c (assuan_pipe_connect2): New to extend diff --git a/branches/gpgme-0-3-branch/assuan/mkerrors b/branches/gpgme-0-3-branch/assuan/mkerrors index 13eabde..ef51c5d 100755 --- a/branches/gpgme-0-3-branch/assuan/mkerrors +++ b/branches/gpgme-0-3-branch/assuan/mkerrors @@ -40,7 +40,7 @@ const char * assuan_strerror (AssuanError err) { const char *s; - static char buf[25]; + static char buf[50]; switch (err) { @@ -62,7 +62,18 @@ printf "%s\"; break;\n", tolower(substr(s,8)); ' cat <> 24) & 0xff); + code = (err & 0x00ffffff); + if (source) /* Assume this is an libgpg-error. */ + sprintf (buf, "ec=%u.%u", source, code ); + else + sprintf (buf, "ec=%d", err ); + s=buf; break; + } } return s; diff --git a/branches/gpgme-0-3-branch/configure.ac b/branches/gpgme-0-3-branch/configure.ac index 36584c5..96e885d 100644 --- a/branches/gpgme-0-3-branch/configure.ac +++ b/branches/gpgme-0-3-branch/configure.ac @@ -154,6 +154,8 @@ fi dnl dnl Checks for library functions. dnl +AC_CHECK_FUNCS(timegm) + AC_REPLACE_FUNCS(stpcpy) diff --git a/branches/gpgme-0-3-branch/gpgme/ChangeLog b/branches/gpgme-0-3-branch/gpgme/ChangeLog index abd0dbb..7820787 100644 --- a/branches/gpgme-0-3-branch/gpgme/ChangeLog +++ b/branches/gpgme-0-3-branch/gpgme/ChangeLog @@ -1,3 +1,13 @@ +2003-11-18 Werner Koch + + * conversion.c (_gpgme_parse_timestamp): New. Now also handles ISO + 8601 timestamps as used by gnupg 1.9.2. + * keylist.c (parse_timestamp): Removed. Replaced calls by + _gpgme_parse_timestamp. + * verify.c (_gpgme_verify_status_handler): Replaced strtoul by + _gpgme_parse_timestamp. + * sign.c (append_xml_siginfo): Ditto. + 2003-02-18 Marcus Brinkmann * engine-gpgsm.c (_gpgme_gpgsm_op_sign): Call diff --git a/branches/gpgme-0-3-branch/gpgme/conversion.c b/branches/gpgme-0-3-branch/gpgme/conversion.c index ad85a8a..dcbf025 100644 --- a/branches/gpgme-0-3-branch/gpgme/conversion.c +++ b/branches/gpgme-0-3-branch/gpgme/conversion.c @@ -1,6 +1,6 @@ /* conversion.c - String conversion helper functions. * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 g10 Code GmbH + * Copyright (C) 2001, 2002, 2003 g10 Code GmbH * * This file is part of GPGME. * @@ -23,11 +23,17 @@ #include #endif +#include #include #include +#include #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)) + int _gpgme_hextobyte (const byte *str) @@ -138,3 +144,56 @@ _gpgme_decode_c_string (const char *src, char **destp) return 0; } + + +time_t +_gpgme_parse_timestamp (const char *timestamp) +{ + /* Need toskip leading spaces, becuase 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); + +#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); +} + diff --git a/branches/gpgme-0-3-branch/gpgme/gpgme.h b/branches/gpgme-0-3-branch/gpgme/gpgme.h index c97cab0..053a0a1 100644 --- a/branches/gpgme-0-3-branch/gpgme/gpgme.h +++ b/branches/gpgme-0-3-branch/gpgme/gpgme.h @@ -44,7 +44,7 @@ extern "C" { 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.3.15" +#define GPGME_VERSION "0.3.16-cvs" /* The opaque data types used by GPGME. */ diff --git a/branches/gpgme-0-3-branch/gpgme/keylist.c b/branches/gpgme-0-3-branch/gpgme/keylist.c index e7c211e..3fbabae 100644 --- a/branches/gpgme-0-3-branch/gpgme/keylist.c +++ b/branches/gpgme-0-3-branch/gpgme/keylist.c @@ -1,6 +1,6 @@ /* keylist.c - key listing * Copyright (C) 2000 Werner Koch (dd9jn) - * Copyright (C) 2001, 2002 g10 Code GmbH + * Copyright (C) 2001, 2002, 2003 g10 Code GmbH * * This file is part of GPGME. * @@ -118,16 +118,6 @@ keylist_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) } -static time_t -parse_timestamp (char *p) -{ - if (!*p) - return 0; - - return (time_t)strtoul (p, NULL, 10); -} - - static void set_mainkey_trust_info (GpgmeKey key, const char *s) { @@ -389,10 +379,10 @@ keylist_colon_handler (GpgmeCtx ctx, char *line) strcpy (key->keys.keyid, p); break; case 6: /* timestamp (seconds) */ - key->keys.timestamp = parse_timestamp (p); + key->keys.timestamp = _gpgme_parse_timestamp (p); break; case 7: /* expiration time (seconds) */ - key->keys.expires_at = parse_timestamp (p); + key->keys.expires_at = _gpgme_parse_timestamp (p); break; case 8: /* X.509 serial number */ if (rectype == RT_CRT || rectype == RT_CRS) @@ -444,10 +434,10 @@ keylist_colon_handler (GpgmeCtx ctx, char *line) strcpy (sk->keyid, p); break; case 6: /* timestamp (seconds) */ - sk->timestamp = parse_timestamp (p); + sk->timestamp = _gpgme_parse_timestamp (p); break; case 7: /* expiration time (seconds) */ - sk->expires_at = parse_timestamp (p); + sk->expires_at = _gpgme_parse_timestamp (p); break; case 8: /* reserved (LID) */ break; diff --git a/branches/gpgme-0-3-branch/gpgme/sign.c b/branches/gpgme-0-3-branch/gpgme/sign.c index 9b9a6b2..3f9ca53 100644 --- a/branches/gpgme-0-3-branch/gpgme/sign.c +++ b/branches/gpgme-0-3-branch/gpgme/sign.c @@ -122,7 +122,7 @@ append_xml_siginfo (GpgmeData *rdh, char *args) _gpgme_data_append_string (dh, helpbuf); SKIP_TOKEN_OR_RETURN (args); - ul = strtoul (args, NULL, 10); + ul = _gpgme_parse_timestamp (args); sprintf (helpbuf, " %lu\n", ul); _gpgme_data_append_string (dh, helpbuf); SKIP_TOKEN_OR_RETURN (args); diff --git a/branches/gpgme-0-3-branch/gpgme/util.h b/branches/gpgme-0-3-branch/gpgme/util.h index 09e0832..90ff1f5 100644 --- a/branches/gpgme-0-3-branch/gpgme/util.h +++ b/branches/gpgme-0-3-branch/gpgme/util.h @@ -100,5 +100,6 @@ FILE *fopencookie (void *cookie, const char *opentype, /*-- conversion.c --*/ GpgmeError _gpgme_decode_c_string (const char *src, char **destp); int _gpgme_hextobyte (const byte *str); +time_t _gpgme_parse_timestamp (const char *p); #endif /* UTIL_H */ diff --git a/branches/gpgme-0-3-branch/gpgme/verify.c b/branches/gpgme-0-3-branch/gpgme/verify.c index 0206fe5..3ec63f3 100644 --- a/branches/gpgme-0-3-branch/gpgme/verify.c +++ b/branches/gpgme-0-3-branch/gpgme/verify.c @@ -251,9 +251,14 @@ _gpgme_verify_status_handler (GpgmeCtx ctx, GpgmeStatusCode code, char *args) while (args[i] && args[i] != ' ') i++; /* And get the timestamp. */ - ctx->result.verify->timestamp = strtoul (args+i, &p, 10); + ctx->result.verify->timestamp = _gpgme_parse_timestamp (args+i); if (args[i]) - ctx->result.verify->exptimestamp = strtoul (p, NULL, 10); + { + /* Skip that timestamp. */ + while (args[i] && args[i] != ' ') + i++; + ctx->result.verify->exptimestamp = _gpgme_parse_timestamp (args+i); + } break; case GPGME_STATUS_BADSIG: