summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cups/ipp-file.c74
-rw-r--r--doc/help/man-ipptoolfile.html4
-rw-r--r--man/ipptoolfile.58
-rw-r--r--tools/ipptool.c7
4 files changed, 91 insertions, 2 deletions
diff --git a/cups/ipp-file.c b/cups/ipp-file.c
index ea991b529..15f17d197 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 76a57b226..341b1fdcd 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
<dd style="margin-left: 5.0em">Inserts a single "$" character.
<dt><b>$ENV[</b><i>name</i><b>]</b>
<dd style="margin-left: 5.0em">Inserts the value of the named environment variable, or an empty string if the environment variable is not defined.
+<dt><b>$date-current</b>
+<dd style="margin-left: 5.0em">Inserts the current date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ").
+<dt><b>$date-start</b>
+<dd style="margin-left: 5.0em">Inserts the starting date and time using the ISO-8601 format ("yyyy-mm-ddThh:mm:ssZ").
<dt><b>$filename</b>
<dd style="margin-left: 5.0em">Inserts the filename provided to
<b>ipptool</b>(8)
diff --git a/man/ipptoolfile.5 b/man/ipptoolfile.5
index fd2aec332..5ef621979 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 847dfb586..aca6d24cb 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