]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Add support for $date-current, $date-start, and ISO-8601 time period values for
authorMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 13 May 2019 21:10:48 +0000 (17:10 -0400)
committerMichael R Sweet <michael.r.sweet@gmail.com>
Mon, 13 May 2019 21:10:48 +0000 (17:10 -0400)
relative date/time values.

cups/ipp-file.c
doc/help/man-ipptoolfile.html
man/ipptoolfile.5
tools/ipptool.c

index ea991b529553c559df08c0a91f94daf45c2b4a3f..15f17d19755682ed6c47290e52343d82c47281ae 100644 (file)
@@ -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);
           }
index 76a57b2267f1dedda9c09aa3f01cbc472dee3fc1..341b1fdcd20c20fb0273a40577e01645d527a54d 100644 (file)
@@ -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)
index fd2aec3327471c0fe4a0ed9faa3ca0e7a6571260..5ef6219795fe6d55e957b2dd9c143a877caf3036 100644 (file)
@@ -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)
index 847dfb586e94c7374273ecfdfcfe87b1e79680a5..aca6d24cb79a1d45c3da949ab044eb5a1077a813 100644 (file)
@@ -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