]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cups/ipp-file.c
Merge pull request #5500 from scootergrisen/patch-5
[thirdparty/cups.git] / cups / ipp-file.c
index 70697082e3a655840875467f94fffa4736a465a6..a0b2bb0c3887f62b502a83da400dc93b6da4eb1d 100644 (file)
@@ -14,7 +14,7 @@
 
 #include "ipp-private.h"
 #include "string-private.h"
-#include "debug-private.h"
+#include "debug-internal.h"
 
 
 /*
@@ -23,7 +23,7 @@
 
 static ipp_t   *parse_collection(_ipp_file_t *f, _ipp_vars_t *v, void *user_data);
 static int     parse_value(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, ipp_t *ipp, ipp_attribute_t **attr, int element);
-static void    report_error(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, const char *message, ...) __attribute((__format__ (__printf__, 4, 5)));
+static void    report_error(_ipp_file_t *f, _ipp_vars_t *v, void *user_data, const char *message, ...) _CUPS_FORMAT(4, 5);
 
 
 /*
@@ -81,8 +81,11 @@ _ippFileParse(
 
       if (_ippFileReadToken(&f, name, sizeof(name)) && _ippFileReadToken(&f, temp, sizeof(temp)))
       {
-        _ippVarsExpand(v, value, temp, sizeof(value));
-        _ippVarsSet(v, name, value);
+        if (_cups_strcasecmp(token, "DEFINE-DEFAULT") || !_ippVarsGet(v, name))
+        {
+         _ippVarsExpand(v, value, temp, sizeof(value));
+         _ippVarsSet(v, name, value);
+       }
       }
       else
       {
@@ -214,6 +217,8 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
   * Skip whitespace and comments...
   */
 
+  DEBUG_printf(("1_ippFileReadToken: linenum=%d, pos=%ld", f->linenum, (long)cupsFileTell(f->fp)));
+
   while ((ch = cupsFileGetChar(f->fp)) != EOF)
   {
     if (_cups_isspace(ch))
@@ -223,7 +228,10 @@ _ippFileReadToken(_ipp_file_t *f,  /* I - File to read from */
       */
 
       if (ch == '\n')
+      {
         f->linenum ++;
+        DEBUG_printf(("1_ippFileReadToken: LF in leading whitespace, linenum=%d, pos=%ld", f->linenum, (long)cupsFileTell(f->fp)));
+      }
     }
     else if (ch == '#')
     {
@@ -231,6 +239,8 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
       * Comment...
       */
 
+      DEBUG_puts("1_ippFileReadToken: Skipping comment in leading whitespace...");
+
       while ((ch = cupsFileGetChar(f->fp)) != EOF)
       {
         if (ch == '\n')
@@ -238,7 +248,10 @@ _ippFileReadToken(_ipp_file_t *f,  /* I - File to read from */
       }
 
       if (ch == '\n')
+      {
         f->linenum ++;
+        DEBUG_printf(("1_ippFileReadToken: LF at end of comment, linenum=%d, pos=%ld", f->linenum, (long)cupsFileTell(f->fp)));
+      }
       else
         break;
     }
@@ -259,7 +272,10 @@ _ippFileReadToken(_ipp_file_t *f,  /* I - File to read from */
   while (ch != EOF)
   {
     if (ch == '\n')
+    {
       f->linenum ++;
+      DEBUG_printf(("1_ippFileReadToken: LF in token, linenum=%d, pos=%ld", f->linenum, (long)cupsFileTell(f->fp)));
+    }
 
     if (ch == quote)
     {
@@ -268,7 +284,7 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
       */
 
       *tokptr = '\0';
-      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\".", token));
+      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\" at closing quote.", token));
       return (1);
     }
     else if (!quote && _cups_isspace(ch))
@@ -278,7 +294,7 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
       */
 
       *tokptr = '\0';
-      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\".", token));
+      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\" before whitespace.", token));
       return (1);
     }
     else if (!quote && (ch == '\'' || ch == '\"'))
@@ -288,6 +304,8 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
       */
 
       quote = ch;
+
+      DEBUG_printf(("1_ippFileReadToken: Start of quoted string, quote=%c, pos=%ld", quote, (long)cupsFileTell(f->fp)));
     }
     else if (!quote && ch == '#')
     {
@@ -297,7 +315,7 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
 
       cupsFileSeek(f->fp, cupsFileTell(f->fp) - 1);
       *tokptr = '\0';
-      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\".", token));
+      DEBUG_printf(("1_ippFileReadToken: Returning \"%s\" before comment.", token));
       return (1);
     }
     else if (!quote && (ch == '{' || ch == '}' || ch == ','))
@@ -335,6 +353,8 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
         * Quoted character...
         */
 
+        DEBUG_printf(("1_ippFileReadToken: Quoted character at pos=%ld", (long)cupsFileTell(f->fp)));
+
         if ((ch = cupsFileGetChar(f->fp)) == EOF)
         {
          *token = '\0';
@@ -342,7 +362,10 @@ _ippFileReadToken(_ipp_file_t *f,  /* I - File to read from */
          return (0);
        }
        else if (ch == '\n')
+       {
          f->linenum ++;
+         DEBUG_printf(("1_ippFileReadToken: quoted LF, linenum=%d, pos=%ld", f->linenum, (long)cupsFileTell(f->fp)));
+       }
       }
 
       if (tokptr < tokend)
@@ -373,7 +396,7 @@ _ippFileReadToken(_ipp_file_t *f,   /* I - File to read from */
   }
 
   *tokptr = '\0';
-  DEBUG_printf(("1_ippFileReadToken: Returning \"%s\".", token));
+  DEBUG_printf(("1_ippFileReadToken: Returning \"%s\" at EOF.", token));
 
   return (tokptr > token);
 }
@@ -535,6 +558,48 @@ parse_value(_ipp_file_t      *f,   /* I  - IPP data file */
         return (ippSetInteger(ipp, attr, element, (int)strtol(value, NULL, 0)));
         break;
 
+    case IPP_TAG_DATE :
+        {
+          int  year,                   /* Year */
+               month,                  /* Month */
+               day,                    /* Day of month */
+               hour,                   /* Hour */
+               minute,                 /* Minute */
+               second,                 /* Second */
+               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)
+          {
+           report_error(f, v, user_data, "Bad dateTime value \"%s\" on line %d of \"%s\".", value, f->linenum, f->filename);
+           return (0);
+          }
+
+          date[0] = (ipp_uchar_t)(year >> 8);
+          date[1] = (ipp_uchar_t)(year & 255);
+          date[2] = (ipp_uchar_t)month;
+          date[3] = (ipp_uchar_t)day;
+          date[4] = (ipp_uchar_t)hour;
+          date[5] = (ipp_uchar_t)minute;
+          date[6] = (ipp_uchar_t)second;
+          date[7] = 0;
+          if (utc_offset < 0)
+          {
+            utc_offset = -utc_offset;
+            date[8]    = (ipp_uchar_t)'-';
+         }
+         else
+         {
+            date[8] = (ipp_uchar_t)'+';
+         }
+
+          date[9]  = (ipp_uchar_t)(utc_offset / 100);
+          date[10] = (ipp_uchar_t)(utc_offset % 100);
+
+          return (ippSetDate(ipp, attr, element, date));
+        }
+        break;
+
     case IPP_TAG_RESOLUTION :
        {
          int   xres,           /* X resolution */