]> git.ipfire.org Git - thirdparty/cups.git/blobdiff - cgi-bin/template.c
Import CUPS 1.4svn r7023 into easysw/current.
[thirdparty/cups.git] / cgi-bin / template.c
index 021de82f53ca4903074924bfd65d066a0f2b5d4b..0d301e11ae2733e4013e321288a7fbe465648de1 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * "$Id: template.c 6799 2007-08-15 19:33:36Z mike $"
+ * "$Id: template.c 6986 2007-09-25 15:34:52Z mike $"
  *
  *   CGI template function.
  *
@@ -26,6 +26,7 @@
 
 #include "cgi-private.h"
 #include <errno.h>
+#include <regex.h>
 
 
 /*
@@ -229,6 +230,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
                compare[1024];          /* Comparison string */
   int          result;                 /* Result of comparison */
   int          uriencode;              /* Encode as URI */
+  regex_t      re;                     /* Regular expression to match */
 
 
   fprintf(stderr, "DEBUG2: %*sStarting at file position %ld...\n", indent, "",
@@ -250,7 +252,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
       uriencode = 0;
 
       for (s = name; (ch = getc(in)) != EOF;)
-        if (strchr("}]<>=! \t\n", ch))
+        if (strchr("}]<>=!~ \t\n", ch))
           break;
        else if (s == name && ch == '%')
          uriencode = 1;
@@ -417,6 +419,7 @@ cgi_copy(FILE *out,                 /* I - Output file */
       *   {name<value?true:false}    Less than
       *   {name>value?true:false}    Greater than
       *   {name!value?true:false}    Not equal
+      *   {name~refex?true:false}    Regex match
       */
 
       op = ch;
@@ -516,6 +519,39 @@ cgi_copy(FILE *out,                        /* I - Output file */
          case '!' :
              result = 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",
+                       compare);
+               result = 0;
+             }
+             else
+             {
+               regmatch_t matches[10];
+
+               result = 0;
+
+               if (!regexec(&re, outptr, 10, matches, 0))
+               {
+                 int i;
+                 for (i = 0; i < 10; i ++)
+                 {
+                   fprintf(stderr, "DEBUG: matches[%d].rm_so=%d\n", i,
+                           (int)matches[i].rm_so);
+                   if (matches[i].rm_so < 0)
+                     break;
+
+                   result ++;
+                 }
+               }
+
+               regfree(&re);
+             }
+             break;
          default :
              result = 1;
              break;
@@ -663,5 +699,5 @@ cgi_puturi(const char *s,           /* I - String to output */
 
 
 /*
- * End of "$Id: template.c 6799 2007-08-15 19:33:36Z mike $".
+ * End of "$Id: template.c 6986 2007-09-25 15:34:52Z mike $".
  */