]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/template.c
Import all of the bug fixes from the OpenPrinting CUPS repository.
[thirdparty/cups.git] / cgi-bin / template.c
index cdf1544bbe65453b96f073db48836ae9a65c012a..0b785b2f677f9b93ce8e8d300c815d8fdd369b32 100644 (file)
@@ -1,27 +1,10 @@
 /*
- * "$Id$"
+ * CGI template function.
  *
- *   CGI template function.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2011 by Apple Inc.
- *   Copyright 1997-2006 by Easy Software Products.
- *
- *   These coded instructions, statements, and computer programs are the
- *   property of Apple Inc. and are protected by Federal copyright
- *   law.  Distribution and use rights are outlined in the file "LICENSE.txt"
- *   which should have been included with this file.  If this file is
- *   file is missing or damaged, see the license at "http://www.cups.org/".
- *
- * Contents:
- *
- *   cgiCopyTemplateFile() - Copy a template file and replace all the
- *                           '{variable}' strings with the variable value.
- *   cgiCopyTemplateLang() - Copy a template file using a language...
- *   cgiGetTemplateDir()   - Get the templates directory...
- *   cgiSetServerVersion() - Set the server name and CUPS version...
- *   cgi_copy()            - Copy the template file, substituting as needed...
- *   cgi_puts()            - Put a string to the output file, quoting as
- *                           needed...
+ * Licensed under Apache License v2.0.  See the file "LICENSE" for more information.
  */
 
 #include "cgi-private.h"
@@ -266,7 +249,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
         else if (s > name && ch == '?')
          break;
        else if (s < (name + sizeof(name) - 1))
-          *s++ = ch;
+          *s++ = (char)ch;
 
       *s = '\0';
 
@@ -324,9 +307,9 @@ cgi_copy(FILE *out,                 /* I - Output file */
        */
 
         if (name[1])
-          sprintf(outval, "%d", cgiGetSize(name + 1));
+          snprintf(outval, sizeof(outval), "%d", cgiGetSize(name + 1));
        else
-         sprintf(outval, "%d", element + 1);
+         snprintf(outval, sizeof(outval), "%d", element + 1);
 
         outptr = outval;
       }
@@ -443,7 +426,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
       *   {name~refex?true:false}    Regex match
       */
 
-      op = ch;
+      op = (char)ch;
 
       if (ch == '?')
       {
@@ -474,7 +457,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
            continue;
          else if (ch == '#')
          {
-           sprintf(s, "%d", element + 1);
+           snprintf(s, sizeof(compare) - (size_t)(s - compare), "%d", element + 1);
            s += strlen(s);
          }
          else if (ch == '{')
@@ -486,11 +469,11 @@ cgi_copy(FILE *out,                       /* I - Output file */
            innerptr = innername;
            while ((ch = getc(in)) != EOF && ch != '}')
              if (innerptr < (innername + sizeof(innername) - 1))
-               *innerptr++ = ch;
+               *innerptr++ = (char)ch;
            *innerptr = '\0';
 
             if (innername[0] == '#')
-             sprintf(s, "%d", cgiGetSize(innername + 1));
+             snprintf(s, sizeof(compare) - (size_t)(s - compare), "%d", cgiGetSize(innername + 1));
            else if ((innerptr = strrchr(innername, '-')) != NULL &&
                     isdigit(innerptr[1] & 255))
             {
@@ -498,26 +481,26 @@ cgi_copy(FILE *out,                       /* I - Output file */
              if ((innerval = cgiGetArray(innername, atoi(innerptr) - 1)) == NULL)
                *s = '\0';
              else
-               strlcpy(s, innerval, sizeof(compare) - (s - compare));
+               strlcpy(s, innerval, sizeof(compare) - (size_t)(s - compare));
            }
            else if (innername[0] == '?')
            {
              if ((innerval = cgiGetArray(innername + 1, element)) == NULL)
                *s = '\0';
              else
-               strlcpy(s, innerval, sizeof(compare) - (s - compare));
+               strlcpy(s, innerval, sizeof(compare) - (size_t)(s - compare));
             }
            else if ((innerval = cgiGetArray(innername, element)) == NULL)
-             snprintf(s, sizeof(compare) - (s - compare), "{%s}", innername);
+             snprintf(s, sizeof(compare) - (size_t)(s - compare), "{%s}", innername);
            else
-             strlcpy(s, innerval, sizeof(compare) - (s - compare));
+             strlcpy(s, innerval, sizeof(compare) - (size_t)(s - compare));
 
             s += strlen(s);
          }
           else if (ch == '\\')
-           *s++ = getc(in);
+           *s++ = (char)getc(in);
          else
-            *s++ = ch;
+            *s++ = (char)ch;
 
         *s = '\0';
 
@@ -553,7 +536,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
              if (regcomp(&re, compare, REG_EXTENDED | REG_ICASE))
              {
                fprintf(stderr,
-                       "ERROR: Unable to compile regular expresion \"%s\"!\n",
+                       "ERROR: Unable to compile regular expression \"%s\"!\n",
                        compare);
                result = 0;
              }
@@ -659,39 +642,7 @@ cgi_puts(const char *s,                    /* I - String to output */
   while (*s)
   {
     if (*s == '<')
-    {
-     /*
-      * Pass <A HREF="url"> and </A>, otherwise quote it...
-      */
-
-      if (!_cups_strncasecmp(s, "<A HREF=\"", 9))
-      {
-        fputs("<A HREF=\"", out);
-       s += 9;
-
-       while (*s && *s != '\"')
-       {
-          if (*s == '&')
-            fputs("&amp;", out);
-         else
-           putc(*s, out);
-
-         s ++;
-       }
-
-        if (*s)
-         s ++;
-
-       fputs("\">", out);
-      }
-      else if (!_cups_strncasecmp(s, "</A>", 4))
-      {
-        fputs("</A>", out);
-       s += 3;
-      }
-      else
-        fputs("&lt;", out);
-    }
+      fputs("&lt;", out);
     else if (*s == '>')
       fputs("&gt;", out);
     else if (*s == '\"')
@@ -726,8 +677,3 @@ cgi_puturi(const char *s,           /* I - String to output */
     s ++;
   }
 }
-
-
-/*
- * End of "$Id$".
- */