From: Michael R Sweet Date: Mon, 13 May 2019 21:10:48 +0000 (-0400) Subject: Add support for $date-current, $date-start, and ISO-8601 time period values for X-Git-Tag: v2.3rc1~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c8d7d4bf5555898ad53dd69694dba20a9a1aa493;p=thirdparty%2Fcups.git Add support for $date-current, $date-start, and ISO-8601 time period values for relative date/time values. --- diff --git a/cups/ipp-file.c b/cups/ipp-file.c index ea991b5295..15f17d1975 100644 --- a/cups/ipp-file.c +++ b/cups/ipp-file.c @@ -592,8 +592,80 @@ parse_value(_ipp_file_t *f, /* I - IPP data file */ utc_offset = 0; /* Timezone offset from UTC */ ipp_uchar_t date[11]; /* dateTime value */ - if (sscanf(value, "%d-%d-%dT%d:%d:%d%d", &year, &month, &day, &hour, &minute, &second, &utc_offset) < 6) + if (*value == 'P') { + /* + * Time period... + */ + + time_t curtime; /* Current time in seconds */ + int period = 0, /* Current period value */ + saw_T = 0; /* Saw time separator */ + + curtime = time(NULL); + + for (valueptr = value + 1; *valueptr; valueptr ++) + { + if (isdigit(*valueptr & 255)) + { + period = strtol(valueptr, &valueptr, 10); + + if (!valueptr || period < 0) + { + report_error(f, v, user_data, "Bad dateTime value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename); + return (0); + } + } + + if (*valueptr == 'Y') + { + curtime += 365 * 86400 * period; + period = 0; + } + else if (*valueptr == 'M') + { + if (saw_T) + curtime += 60 * period; + else + curtime += 30 * 86400 * period; + + period = 0; + } + else if (*valueptr == 'D') + { + curtime += 86400 * period; + period = 0; + } + else if (*valueptr == 'H') + { + curtime += 3600 * period; + period = 0; + } + else if (*valueptr == 'S') + { + curtime += period; + period = 0; + } + else if (*valueptr == 'T') + { + saw_T = 1; + period = 0; + } + else + { + report_error(f, v, user_data, "Bad dateTime value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename); + return (0); + } + } + + return (ippSetDate(ipp, attr, element, ippTimeToDate(curtime))); + } + else if (sscanf(value, "%d-%d-%dT%d:%d:%d%d", &year, &month, &day, &hour, &minute, &second, &utc_offset) < 6) + { + /* + * Date/time value did not parse... + */ + report_error(f, v, user_data, "Bad dateTime value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename); return (0); } diff --git a/doc/help/man-ipptoolfile.html b/doc/help/man-ipptoolfile.html index 76a57b2267..341b1fdcd2 100644 --- a/doc/help/man-ipptoolfile.html +++ b/doc/help/man-ipptoolfile.html @@ -490,6 +490,10 @@ program maintains a list of variables that can be used in any literal string or
Inserts a single "$" character.
$ENV[name]
Inserts the value of the named environment variable, or an empty string if the environment variable is not defined. +
$date-current +
Inserts the current date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ"). +
$date-start +
Inserts the starting date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ").
$filename
Inserts the filename provided to ipptool(8) diff --git a/man/ipptoolfile.5 b/man/ipptoolfile.5 index fd2aec3327..5ef6219795 100644 --- a/man/ipptoolfile.5 +++ b/man/ipptoolfile.5 @@ -6,7 +6,7 @@ .\" Licensed under Apache License v2.0. See the file "LICENSE" for more .\" information. .\" -.TH ipptoolfile 5 "CUPS" "26 April 2019" "Apple Inc." +.TH ipptoolfile 5 "CUPS" "13 May 2019" "Apple Inc." .SH NAME ipptoolfile \- ipptool file format .SH DESCRIPTION @@ -594,6 +594,12 @@ Inserts a single "$" character. \fB$ENV[\fIname\fB]\fR Inserts the value of the named environment variable, or an empty string if the environment variable is not defined. .TP 5 +\fB$date-current\fR +Inserts the current date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ"). +.TP 5 +\fB$date-start\fR +Inserts the starting date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ"). +.TP 5 \fB$filename\fR Inserts the filename provided to .BR ipptool (8) diff --git a/tools/ipptool.c b/tools/ipptool.c index 847dfb586e..aca6d24cb7 100644 --- a/tools/ipptool.c +++ b/tools/ipptool.c @@ -240,6 +240,8 @@ main(int argc, /* I - Number of command-line args */ _ippVarsInit(&vars, NULL, (_ipp_ferror_cb_t)error_cb, (_ipp_ftoken_cb_t)token_cb); + _ippVarsSet(&vars, "date-start", iso_date(ippTimeToDate(time(NULL)))); + /* * We need at least: * @@ -3992,6 +3994,8 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ data->transfer = data->def_transfer; data->version = data->def_version; + _ippVarsSet(vars, "date-current", iso_date(ippTimeToDate(time(NULL)))); + f->attrs = ippNew(); f->group_tag = IPP_TAG_ZERO; } @@ -4003,6 +4007,7 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ if (_ippFileReadToken(f, name, sizeof(name)) && _ippFileReadToken(f, temp, sizeof(temp))) { + _ippVarsSet(vars, "date-current", iso_date(ippTimeToDate(time(NULL)))); _ippVarsExpand(vars, value, temp, sizeof(value)); _ippVarsSet(vars, name, value); } @@ -4022,6 +4027,7 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ { if (!_ippVarsGet(vars, name)) { + _ippVarsSet(vars, "date-current", iso_date(ippTimeToDate(time(NULL)))); _ippVarsExpand(vars, value, temp, sizeof(value)); _ippVarsSet(vars, name, value); } @@ -4040,6 +4046,7 @@ token_cb(_ipp_file_t *f, /* I - IPP file data */ if (_ippFileReadToken(f, temp, sizeof(temp))) { + _ippVarsSet(vars, "date-current", iso_date(ippTimeToDate(time(NULL)))); _ippVarsExpand(vars, data->file_id, temp, sizeof(data->file_id)); } else