/*
- * "$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"
*locptr = '\0'; /* Strip charset */
}
- fprintf(stderr, "DEBUG: lang=\"%s\", locale=\"%s\"...\n",
+ fprintf(stderr, "DEBUG2: lang=\"%s\", locale=\"%s\"...\n",
lang ? lang : "(null)", locale);
/*
else if (s > name && ch == '?')
break;
else if (s < (name + sizeof(name) - 1))
- *s++ = ch;
+ *s++ = (char)ch;
*s = '\0';
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
{
/*
{
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);
* {name~refex?true:false} Regex match
*/
- op = ch;
+ op = (char)ch;
if (ch == '?')
{
* 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
innerptr = innername;
while ((ch = getc(in)) != EOF && ch != '}')
if (innerptr < (innername + sizeof(innername) - 1))
- *innerptr++ = ch;
+ *innerptr++ = (char)ch;
*innerptr = '\0';
if (innername[0] == '#')
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';
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);
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;
}
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("&", out);
- else
- putc(*s, out);
-
- s ++;
- }
-
- if (*s)
- s ++;
-
- fputs("\">", out);
- }
- else if (!strncasecmp(s, "</A>", 4))
- {
- fputs("</A>", out);
- s += 3;
- }
- else
- fputs("<", out);
- }
+ fputs("<", out);
else if (*s == '>')
fputs(">", out);
else if (*s == '\"')
fputs(""", out);
+ else if (*s == '\'')
+ fputs("'", out);
else if (*s == '&')
fputs("&", out);
else
{
while (*s)
{
- if (strchr("%&+ <>#=", *s) || *s & 128)
+ if (strchr("%@&+ <>#=", *s) || *s < ' ' || *s & 128)
fprintf(out, "%%%02X", *s & 255);
else
putc(*s, out);
s ++;
}
}
-
-
-/*
- * End of "$Id: template.c 6986 2007-09-25 15:34:52Z mike $".
- */