]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/template.c
Remove all of the Subversion keywords from various source files.
[thirdparty/cups.git] / cgi-bin / template.c
index 661f6395b9d737086ec05cb7fba43fd788e3724b..c7d2144f8cfb6603e2a5d8705d9578f5d3766ce8 100644 (file)
@@ -1,27 +1,14 @@
 /*
- * "$Id: template.c 6986 2007-09-25 15:34:52Z mike $"
+ * CGI template function.
  *
- *   CGI template function.
+ * Copyright 2007-2015 by Apple Inc.
+ * Copyright 1997-2006 by Easy Software Products.
  *
- *   Copyright 2007-2008 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...
+ * 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/".
  */
 
 #include "cgi-private.h"
@@ -119,7 +106,7 @@ cgiCopyTemplateLang(const char *tmpl)       /* I - Base filename */
       *locptr = '\0';                  /* Strip charset */
   }
 
-  fprintf(stderr, "DEBUG: lang=\"%s\", locale=\"%s\"...\n",
+  fprintf(stderr, "DEBUG2: lang=\"%s\", locale=\"%s\"...\n",
           lang ? lang : "(null)", locale);
 
  /*
@@ -266,7 +253,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';
 
@@ -369,6 +356,20 @@ cgi_copy(FILE *out,                        /* I - Output file */
 
         continue;
       }
+      else if (name[0] == '$')
+      {
+       /*
+        * Insert cookie value or nothing if not defined.
+       */
+
+        if ((value = cgiGetCookie(name + 1)) != NULL)
+         outptr = value;
+       else
+       {
+         outval[0] = '\0';
+         outptr    = outval;
+       }
+      }
       else
       {
        /*
@@ -409,7 +410,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
        {
          if (uriencode)
            cgi_puturi(outptr, out);
-         else if (!strcasecmp(name, "?cupsdconf_default"))
+         else if (!_cups_strcasecmp(name, "?cupsdconf_default"))
            fputs(outptr, stdout);
          else
            cgi_puts(outptr, out);
@@ -429,7 +430,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
       *   {name~refex?true:false}    Regex match
       */
 
-      op = ch;
+      op = (char)ch;
 
       if (ch == '?')
       {
@@ -437,7 +438,14 @@ cgi_copy(FILE *out,                        /* I - Output file */
         * Test for existance...
        */
 
-        result     = cgiGetArray(name, element) != NULL && outptr[0];
+        if (name[0] == '?')
+         result = cgiGetArray(name + 1, element) != NULL;
+       else if (name[0] == '#')
+         result = cgiGetVariable(name + 1) != NULL;
+        else
+          result = cgiGetArray(name, element) != NULL;
+
+       result     = result && outptr[0];
        compare[0] = '\0';
       }
       else
@@ -465,7 +473,7 @@ 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] == '#')
@@ -477,26 +485,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';
 
@@ -515,16 +523,16 @@ cgi_copy(FILE *out,                       /* I - Output file */
         switch (op)
        {
          case '<' :
-             result = strcasecmp(outptr, compare) < 0;
+             result = _cups_strcasecmp(outptr, compare) < 0;
              break;
          case '>' :
-             result = strcasecmp(outptr, compare) > 0;
+             result = _cups_strcasecmp(outptr, compare) > 0;
              break;
          case '=' :
-             result = strcasecmp(outptr, compare) == 0;
+             result = _cups_strcasecmp(outptr, compare) == 0;
              break;
          case '!' :
-             result = strcasecmp(outptr, compare) != 0;
+             result = _cups_strcasecmp(outptr, compare) != 0;
              break;
          case '~' :
              fprintf(stderr, "DEBUG: Regular expression \"%s\"\n", compare);
@@ -532,7 +540,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;
              }
@@ -638,43 +646,13 @@ cgi_puts(const char *s,                   /* I - String to output */
   while (*s)
   {
     if (*s == '<')
-    {
-     /*
-      * Pass <A HREF="url"> and </A>, otherwise quote it...
-      */
-
-      if (!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 (!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 == '\"')
       fputs("&quot;", out);
+    else if (*s == '\'')
+      fputs("&#39;", out);
     else if (*s == '&')
       fputs("&amp;", out);
     else
@@ -695,7 +673,7 @@ cgi_puturi(const char *s,           /* I - String to output */
 {
   while (*s)
   {
-    if (strchr("%&+ <>#=", *s) || *s & 128)
+    if (strchr("%@&+ <>#=", *s) || *s < ' ' || *s & 128)
       fprintf(out, "%%%02X", *s & 255);
     else
       putc(*s, out);
@@ -703,8 +681,3 @@ cgi_puturi(const char *s,           /* I - String to output */
     s ++;
   }
 }
-
-
-/*
- * End of "$Id: template.c 6986 2007-09-25 15:34:52Z mike $".
- */