DT_NONE = 0,
DT_BOOL,
DT_NUMBER,
+ DT_LONG,
DT_STRING,
DT_PATH,
DT_QUAD,
{ "DT_NONE", "-none-" },
{ "DT_BOOL", "boolean" },
{ "DT_NUMBER", "number" },
+ { "DT_LONG", "number (long)" },
{ "DT_STRING", "string" },
{ "DT_PATH", "path" },
{ "DT_QUAD", "quadoption" },
</para>
</listitem>
</varlistentry>
+ <varlistentry>
+ <term>number (long)</term>
+ <listitem>
+ <para>
+ A signed integer number in the range -2147483648 to 2147483647.
+ </para>
+ </listitem>
+ </varlistentry>
<varlistentry>
<term>string</term>
<listitem>
WHERE struct Regex *PgpDecryptionOkay;
WHERE char *PgpDefaultKey;
WHERE char *PgpSignAs;
-WHERE short PgpTimeout;
+WHERE long PgpTimeout;
WHERE char *PgpEntryFormat;
WHERE char *PgpClearsignCommand;
WHERE char *PgpDecodeCommand;
/* -- formerly in smime.h -- */
WHERE char *SmimeDefaultKey;
WHERE char *SmimeSignAs;
-WHERE short SmimeTimeout;
+WHERE long SmimeTimeout;
WHERE char *SmimeCertificates;
WHERE char *SmimeKeys;
WHERE char *SmimeEncryptWith;
else
*((short *) p->var) = p->initial;
break;
+ case DT_LONG:
+ *((long *) p->var) = p->initial;
+ break;
case DT_REGEX:
{
struct Regex **ptr = (struct Regex **) p->var;
}
#endif
}
+ else if (DTYPE(MuttVars[idx].type) == DT_LONG)
+ {
+ long *ptr = (long *) MuttVars[idx].var;
+ long val;
+
+ if (query || *s->dptr != '=')
+ {
+ val = *ptr;
+
+ /* user requested the value of this variable */
+ snprintf(err->data, err->dsize, "%s=%ld", MuttVars[idx].name, val);
+ break;
+ }
+
+ CHECK_PAGER;
+ s->dptr++;
+
+ mutt_extract_token(buf, s, 0);
+ int rc = mutt_str_atol(buf->data, (long *) &val);
+
+ if (rc < 0 || !*buf->data)
+ {
+ snprintf(err->data, err->dsize, _("%s: invalid value (%s)"), buf->data,
+ rc == -1 ? _("format error") : _("number overflow"));
+ r = -1;
+ break;
+ }
+ else
+ *ptr = val;
+ }
else if ((idx >= 0) && (DTYPE(MuttVars[idx].type) == DT_QUAD))
{
if (query)
snprintf(tmp, sizeof(tmp), "%d", sval);
}
+ else if (DTYPE(MuttVars[idx].type) == DT_LONG)
+ {
+ long sval = *((long *) MuttVars[idx].var);
+
+ snprintf(tmp, sizeof(tmp), "%ld", sval);
+ }
else if (DTYPE(MuttVars[idx].type) == DT_SORT)
{
const struct Mapping *map = NULL;
** this if you know what you are doing.
** (PGP only)
*/
- { "pgp_timeout", DT_NUMBER, R_NONE, &PgpTimeout, 300 },
+ { "pgp_timeout", DT_LONG, R_NONE, &PgpTimeout, 300 },
/*
** .pp
** The number of seconds after which a cached passphrase will expire if
** Valid choices are ``md5'', ``sha1'', ``sha224'', ``sha256'', ``sha384'', ``sha512''.
** (S/MIME only)
*/
- { "smime_timeout", DT_NUMBER, R_NONE, &SmimeTimeout, 300 },
+ { "smime_timeout", DT_LONG, R_NONE, &SmimeTimeout, 300 },
/*
** .pp
** The number of seconds after which a cached passphrase will expire if
return (mutt_date_make_time(&t, 0) + tz);
}
+
+/**
+ * mutt_date_add_timeout - Safely add a timeout to a given time_t value
+ * @param now Time now
+ * @param timeout Timeout in seconds
+ * @retval num Unix time to timeout
+ *
+ * This will truncate instead of overflowing.
+ */
+time_t mutt_date_add_timeout(time_t now, long timeout)
+{
+ if (timeout < 0)
+ return now;
+
+ if ((TIME_T_MAX - now) < timeout)
+ return TIME_T_MAX;
+
+ return (now + timeout);
+}
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);
+time_t mutt_date_add_timeout(time_t now, long timeout);
+
#endif /* _MUTT_DATE_H */
#define DT_MASK 0x0f
#define DT_BOOL 1 /**< boolean option */
-#define DT_NUMBER 2 /**< a number */
+#define DT_NUMBER 2 /**< a number (short) */
#define DT_STRING 3 /**< a string */
#define DT_PATH 4 /**< a pathname */
#define DT_QUAD 5 /**< quad-option (yes/no/ask-yes/ask-no) */
#define DT_SYNONYM 9 /**< synonym for another variable */
#define DT_ADDRESS 10 /**< e-mail address */
#define DT_MBTABLE 11 /**< multibyte char table */
-#define DT_HCACHE 12 /**< header cache backend */
+#define DT_LONG 12 /* a number (long) */
+#define DT_HCACHE 13 /**< header cache backend */
#define DTYPE(x) ((x) &DT_MASK)
if (mutt_get_password(_("Enter PGP passphrase:"), PgpPass, sizeof(PgpPass)) == 0)
{
- PgpExptime = time(NULL) + PgpTimeout;
+ PgpExptime = mutt_date_add_timeout(time(NULL), PgpTimeout);
return 1;
}
else
if (mutt_get_password(_("Enter S/MIME passphrase:"), SmimePass, sizeof(SmimePass)) == 0)
{
- SmimeExptime = time(NULL) + SmimeTimeout;
+ SmimeExptime = mutt_date_add_timeout(time(NULL), SmimeTimeout);
return 1;
}
else