]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
<rdar://problem/13876091> cups.org: ipptool should support validation of hostname...
authormsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Mon, 13 May 2013 21:48:45 +0000 (21:48 +0000)
committermsweet <msweet@a1ca3aef-8c08-0410-bb20-df032aa958be>
Mon, 13 May 2013 21:48:45 +0000 (21:48 +0000)
git-svn-id: svn+ssh://src.apple.com/svn/cups/cups.org/trunk@10982 a1ca3aef-8c08-0410-bb20-df032aa958be

CHANGES.txt
doc/help/man-ipptoolfile.html
man/ipptoolfile.man
test/ipptool.c

index a282705eb8446cdd0f2dcaa47adf4d571951b836..5dda7a86b49a7804f7d510fde42c2a2933c08084 100644 (file)
@@ -7,6 +7,9 @@ CHANGES IN CUPS V1.7b2
          default (<rdar://problem/13875803>)
        - The ipptool program now supports FILE-ID and TEST-ID directives and
          includes their values in its XML output (<rdar://problem/13876038>)
+       - The ipptool program now supports WITH-HOSTNAME, WITH-RESOURCE, and
+         WITH-SCHEME expect predicates to compare the corresponding URI
+         components (<rdar://problem/13876091>)
 
 
 CHANGES IN CUPS V1.7b1
index e0be2dcbe39a225a33db1b8f644e5cc872849e88..1ce4f195dd6a78b95b4abebfe36619c4db807f18 100644 (file)
@@ -368,6 +368,27 @@ matches or does not match.
 <dd>Requires the EXPECT attribute to have the same number of values as the specified
 parallel attribute.
 </dd>
+<dt>WITH-ALL-HOSTNAMES "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-ALL-HOSTNAMES "/regular expression/"
+</dt>
+<dd>Requires that all URI values contain a matching hostname.
+</dd>
+<dt>WITH-ALL-RESOURCES "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-ALL-RESOURCES "/regular expression/"
+</dt>
+<dd>Requires that all URI values contain a matching resource (including leading /).
+</dd>
+<dt>WITH-ALL-SCHEMES "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-ALL-SCHEMES "/regular expression/"
+</dt>
+<dd>Requires that all URI values contain a matching scheme.
+</dd>
 <dt>WITH-ALL-VALUES "literal string"
 </dt>
 <dd>Requires that all values of the EXPECT attribute match the literal string. Comparisons are case-sensitive.
@@ -396,6 +417,27 @@ parallel attribute.
 </dt>
 <dd>Requires that all values of the EXPECT attribute match the regular expression, which must conform to the POSIX regular expression syntax. Comparisons are case-sensitive.
 </dd>
+<dt>WITH-HOSTNAME "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-HOSTNAME "/regular expression/"
+</dt>
+<dd>Requires that at least one URI value contains a matching hostname.
+</dd>
+<dt>WITH-RESOURCE "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-RESOURCE "/regular expression/"
+</dt>
+<dd>Requires that at least one URI value contains a matching resource (including leading /).
+</dd>
+<dt>WITH-SCHEME "literal string"
+</dt>
+<dd></dd>
+<dt>WITH-SCHEME "/regular expression/"
+</dt>
+<dd>Requires that at least one URI value contains a matching scheme.
+</dd>
 <dt>WITH-VALUE "literal string"
 </dt>
 <dd>Requires that at least one value of the EXPECT attribute matches the literal string. Comparisons are case-sensitive.
index 785e204bb9db4da728b2c915008a57ffb9be7761..d3fbfb6724d5ecf798ac8c885cea107504fea77f 100644 (file)
@@ -300,6 +300,21 @@ SAME-COUNT-AS attribute-name
 Requires the EXPECT attribute to have the same number of values as the specified
 parallel attribute.
 .TP 5
+WITH-ALL-HOSTNAMES "literal string"
+.TP 5
+WITH-ALL-HOSTNAMES "/regular expression/"
+Requires that all URI values contain a matching hostname.
+.TP 5
+WITH-ALL-RESOURCES "literal string"
+.TP 5
+WITH-ALL-RESOURCES "/regular expression/"
+Requires that all URI values contain a matching resource (including leading /).
+.TP 5
+WITH-ALL-SCHEMES "literal string"
+.TP 5
+WITH-ALL-SCHEMES "/regular expression/"
+Requires that all URI values contain a matching scheme.
+.TP 5
 WITH-ALL-VALUES "literal string"
 Requires that all values of the EXPECT attribute match the literal string. Comparisons are case-sensitive.
 .TP 5
@@ -320,6 +335,21 @@ Requires that all values of the EXPECT attribute match the boolean value given.
 WITH-ALL-VALUES "/regular expression/"
 Requires that all values of the EXPECT attribute match the regular expression, which must conform to the POSIX regular expression syntax. Comparisons are case-sensitive.
 .TP 5
+WITH-HOSTNAME "literal string"
+.TP 5
+WITH-HOSTNAME "/regular expression/"
+Requires that at least one URI value contains a matching hostname.
+.TP 5
+WITH-RESOURCE "literal string"
+.TP 5
+WITH-RESOURCE "/regular expression/"
+Requires that at least one URI value contains a matching resource (including leading /).
+.TP 5
+WITH-SCHEME "literal string"
+.TP 5
+WITH-SCHEME "/regular expression/"
+Requires that at least one URI value contains a matching scheme.
+.TP 5
 WITH-VALUE "literal string"
 Requires that at least one value of the EXPECT attribute matches the literal string. Comparisons are case-sensitive.
 .TP 5
index a5c34c6e2a7911bdda3d8a5e88353749c67f8e4d..9d6044604e8d721e973fff942333bf4d5f46a367 100644 (file)
@@ -87,7 +87,10 @@ typedef enum _cups_with_e            /**** WITH flags ****/
 {
   _CUPS_WITH_LITERAL = 0,              /* Match string is a literal value */
   _CUPS_WITH_ALL = 1,                  /* Must match all values */
-  _CUPS_WITH_REGEX = 2                 /* Match string is a regular expression */
+  _CUPS_WITH_REGEX = 2,                        /* Match string is a regular expression */
+  _CUPS_WITH_HOSTNAME = 4,             /* Match string is a URI hostname */
+  _CUPS_WITH_RESOURCE = 8,             /* Match string is a URI resource */
+  _CUPS_WITH_SCHEME = 16               /* Match string is a URI scheme */
 } _cups_with_t;
 
 typedef struct _cups_expect_s          /**** Expected attribute info ****/
@@ -197,6 +200,8 @@ static int      expect_matches(_cups_expect_t *expect, ipp_tag_t value_tag);
 static ipp_t   *get_collection(_cups_vars_t *vars, FILE *fp, int *linenum);
 static char    *get_filename(const char *testfile, char *dst, const char *src,
                              size_t dstsize);
+static char    *get_string(ipp_attribute_t *attr, int element, int flags,
+                           char *buffer, size_t bufsize);
 static char    *get_token(FILE *fp, char *buf, int buflen,
                           int *linenum);
 static char    *get_variable(_cups_vars_t *vars, const char *name);
@@ -1254,6 +1259,12 @@ do_tests(_cups_vars_t *vars,             /* I - Variables */
           _cups_strcasecmp(token, "REPEAT-NO-MATCH") &&
           _cups_strcasecmp(token, "SAME-COUNT-AS") &&
           _cups_strcasecmp(token, "WITH-ALL-VALUES") &&
+          _cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") &&
+          _cups_strcasecmp(token, "WITH-ALL-RESOURCES") &&
+          _cups_strcasecmp(token, "WITH-ALL-SCHEMES") &&
+          _cups_strcasecmp(token, "WITH-HOSTNAME") &&
+          _cups_strcasecmp(token, "WITH-RESOURCE") &&
+          _cups_strcasecmp(token, "WITH-SCHEME") &&
           _cups_strcasecmp(token, "WITH-VALUE"))
         last_expect = NULL;
 
@@ -2276,10 +2287,29 @@ do_tests(_cups_vars_t *vars,            /* I - Variables */
        }
       }
       else if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+               !_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+               !_cups_strcasecmp(token, "WITH-HOSTNAME") ||
+               !_cups_strcasecmp(token, "WITH-RESOURCE") ||
+               !_cups_strcasecmp(token, "WITH-SCHEME") ||
                !_cups_strcasecmp(token, "WITH-VALUE"))
       {
-       if (!_cups_strcasecmp(token, "WITH-ALL-VALUES") && last_expect)
-         last_expect->with_flags = _CUPS_WITH_ALL;
+       if (last_expect)
+       {
+         if (!_cups_strcasecmp(token, "WITH-ALL-HOSTNAMES") ||
+             !_cups_strcasecmp(token, "WITH-HOSTNAME"))
+           last_expect->with_flags = _CUPS_WITH_HOSTNAME;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-RESOURCES") ||
+             !_cups_strcasecmp(token, "WITH-RESOURCE"))
+           last_expect->with_flags = _CUPS_WITH_RESOURCE;
+         else if (!_cups_strcasecmp(token, "WITH-ALL-SCHEMES") ||
+             !_cups_strcasecmp(token, "WITH-SCHEME"))
+           last_expect->with_flags = _CUPS_WITH_SCHEME;
+
+         if (!_cups_strncasecmp(token, "WITH-ALL-", 9))
+           last_expect->with_flags |= _CUPS_WITH_ALL;
+        }
 
        if (!get_token(fp, temp, sizeof(temp), &linenum))
        {
@@ -3775,6 +3805,59 @@ get_filename(const char *testfile,       /* I - Current test file */
 }
 
 
+/*
+ * 'get_string()' - Get a pointer to a string value or the portion of interest.
+ */
+
+static char *                          /* O - Pointer to string */
+get_string(ipp_attribute_t *attr,      /* I - IPP attribute */
+           int             element,    /* I - Element to fetch */
+           int             flags,      /* I - Value ("with") flags */
+           char            *buffer,    /* I - Temporary buffer */
+          size_t          bufsize)     /* I - Size of temporary buffer */
+{
+  char *ptr,                           /* Value */
+       scheme[256],                    /* URI scheme */
+       userpass[256],                  /* Username/password */
+       hostname[256],                  /* Hostname */
+       resource[1024];                 /* Resource */
+  int  port;                           /* Port number */
+
+
+  ptr = attr->values[element].string.text;
+
+  if (flags & _CUPS_WITH_HOSTNAME)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme),
+                        userpass, sizeof(userpass), buffer, bufsize, &port,
+                        resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+      return ("");
+    else
+      return (buffer);
+  }
+  else if (flags & _CUPS_WITH_RESOURCE)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, scheme, sizeof(scheme),
+                        userpass, sizeof(userpass), hostname, sizeof(hostname),
+                        &port, buffer, bufsize) < HTTP_URI_STATUS_OK)
+      return ("");
+    else
+      return (buffer);
+  }
+  else if (flags & _CUPS_WITH_SCHEME)
+  {
+    if (httpSeparateURI(HTTP_URI_CODING_ALL, ptr, buffer, bufsize,
+                        userpass, sizeof(userpass), hostname, sizeof(hostname),
+                        &port, resource, sizeof(resource)) < HTTP_URI_STATUS_OK)
+      return ("");
+    else
+      return (buffer);
+  }
+  else
+    return (ptr);
+}
+
+
 /*
  * 'get_token()' - Get a token from a file.
  */
@@ -5390,7 +5473,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
 {
   int  i,                              /* Looping var */
        match;                          /* Match? */
-  char temp[256],                      /* Temporary value string */
+  char temp[1024],                     /* Temporary value string */
        *valptr;                        /* Pointer into value */
 
 
@@ -5669,10 +5752,13 @@ with_value(cups_array_t    *errors,     /* I - Errors array */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!regexec(&re, attr->values[i].string.text, 0, NULL, 0))
+           if (!regexec(&re, get_string(attr, i, flags, temp, sizeof(temp)),
+                        0, NULL, 0))
            {
              if (!matchbuf[0])
-               strlcpy(matchbuf, attr->values[i].string.text, matchlen);
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
 
              if (!(flags & _CUPS_WITH_ALL))
              {
@@ -5697,10 +5783,12 @@ with_value(cups_array_t    *errors,     /* I - Errors array */
 
          for (i = 0; i < attr->num_values; i ++)
          {
-           if (!strcmp(value, attr->values[i].string.text))
+           if (!strcmp(value, get_string(attr, i, flags, temp, sizeof(temp))))
            {
              if (!matchbuf[0])
-               strlcpy(matchbuf, attr->values[i].string.text, matchlen);
+               strlcpy(matchbuf,
+                       get_string(attr, i, flags, temp, sizeof(temp)),
+                       matchlen);
 
              if (!(flags & _CUPS_WITH_ALL))
              {
@@ -5720,7 +5808,7 @@ with_value(cups_array_t    *errors,       /* I - Errors array */
         {
          for (i = 0; i < attr->num_values; i ++)
            add_stringf(errors, "GOT: %s=\"%s\"", attr->name,
-                            attr->values[i].string.text);
+                       attr->values[i].string.text);
         }
        break;