return -1;
}
-/**
- * tls_make_date - Create a TLS date string
- * @param t Time to convert
- * @param s Buffer for the string
- * @param len Length of the buffer
- * @retval ptr Pointer to s
- */
-static char *tls_make_date(time_t t, char *s, size_t len)
-{
- struct tm *l = gmtime(&t);
-
- if (l)
- snprintf(s, len, "%s, %d %s %d %02d:%02d:%02d UTC", Weekdays[l->tm_wday], l->tm_mday,
- Months[l->tm_mon], l->tm_year + 1900, l->tm_hour, l->tm_min, l->tm_sec);
- else
- mutt_str_strfcpy(s, _("[invalid date]"), len);
-
- return s;
-}
-
/**
* tls_check_one_certificate - Check a GnuTLS certificate
* @param certdata List of GnuTLS certificates
snprintf(menu->dialog[row++], SHORT_STRING, _("This certificate is valid"));
t = gnutls_x509_crt_get_activation_time(cert);
- snprintf(menu->dialog[row++], SHORT_STRING, _(" from %s"),
- tls_make_date(t, datestr, 30));
+ mutt_date_make_tls(datestr, sizeof(datestr), t);
+ snprintf(menu->dialog[row++], SHORT_STRING, _(" from %s"), datestr);
t = gnutls_x509_crt_get_expiration_time(cert);
- snprintf(menu->dialog[row++], SHORT_STRING, _(" to %s"),
- tls_make_date(t, datestr, 30));
+ mutt_date_make_tls(datestr, sizeof(datestr), t);
+ snprintf(menu->dialog[row++], SHORT_STRING, _(" to %s"), datestr);
fpbuf[0] = '\0';
tls_fingerprint(GNUTLS_DIG_SHA, fpbuf, sizeof(fpbuf), certdata);
*
* Some commonly used time and date functions.
*
- * | Data | Description
- * | :------------------------ | :--------------------------------------------------
- * | #Months | Months of the year (abbreviated)
- * | #TimeZones | Lookup table of Time Zones
- * | #Weekdays | Day of the week (abbreviated)
- *
* | Function | Description
* | :------------------------- | :--------------------------------------------------
* | mutt_date_check_month() | Is the string a valid month name
* | mutt_date_make_date() | Write a date in RFC822 format to a buffer
* | mutt_date_make_imap() | Format date in IMAP style: DD-MMM-YYYY HH:MM:SS +ZZzz
* | mutt_date_make_time() | Convert `struct tm` to `time_t`
+ * | mutt_date_make_tls() | Format date in TLS certificate verification style
* | mutt_date_normalize_time() | Fix the contents of a struct tm
* | mutt_date_parse_date() | Parse a date string in RFC822 format
* | mutt_date_parse_imap() | Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
/**
* Weekdays - Day of the week (abbreviated)
*/
-const char *const Weekdays[] = {
+static const char *const Weekdays[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat",
};
/**
* Months - Months of the year (abbreviated)
*/
-const char *const Months[] = {
+static const char *const Months[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul",
"Aug", "Sep", "Oct", "Nov", "Dec", "ERR",
};
*
* @note Keep in alphabetical order
*/
-const struct Tz TimeZones[] = {
+static const struct Tz TimeZones[] = {
{ "aat", 1, 0, true }, /* Atlantic Africa Time */
{ "adt", 4, 0, false }, /* Arabia DST */
{ "ast", 3, 0, false }, /* Arabia */
tm->tm_sec, (int) tz / 60, (int) abs((int) tz) % 60);
}
+/**
+ * mutt_date_make_tls - Format date in TLS certificate verification style
+ * @param buf Buffer to store the results
+ * @param buflen Length of buffer
+ * @param timestamp Time to format
+ * @retval int Number of characters written to buf
+ *
+ * e.g., Mar 17 16:40:46 2016 UTC. The time is always in UTC.
+ *
+ * Caller should provide a buffer of at least 27 bytes.
+ */
+int mutt_date_make_tls(char *buf, size_t buflen, time_t timestamp)
+{
+ struct tm *tm = gmtime(×tamp);
+ return snprintf(buf, buflen, "%s, %d %s %d %02d:%02d:%02d UTC",
+ Weekdays[tm->tm_wday], tm->tm_mday, Months[tm->tm_mon],
+ tm->tm_year + 1900, tm->tm_hour, tm->tm_min, tm->tm_sec);
+}
+
/**
* mutt_date_parse_imap - Parse date of the form: DD-MMM-YYYY HH:MM:SS +ZZzz
* @param s Date in string form
bool zoccident; /**< True if west of UTC, False if East */
};
-extern const char *const Weekdays[];
-extern const char *const Months[];
-extern const struct Tz TimeZones[];
-
int mutt_date_check_month(const char *s);
bool mutt_date_is_day_name(const char *s);
time_t mutt_date_local_tz(time_t t);
char *mutt_date_make_date(char *buf, size_t buflen);
int mutt_date_make_imap(char *buf, size_t buflen, time_t timestamp);
time_t mutt_date_make_time(struct tm *t, int local);
+int mutt_date_make_tls(char *buf, size_t buflen, time_t timestamp);
void mutt_date_normalize_time(struct tm *tm);
time_t mutt_date_parse_date(const char *s, struct Tz *tz_out);
time_t mutt_date_parse_imap(char *s);