2 * "$Id: ipptool.c 12031 2014-07-15 19:57:59Z msweet $"
4 * ipptool command for CUPS.
6 * Copyright 2007-2014 by Apple Inc.
7 * Copyright 1997-2007 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
15 * This file is subject to the Apple OS-Developed Software exception.
19 * Include necessary headers...
22 #include <cups/cups-private.h>
23 #include <cups/file-private.h>
37 #endif /* !O_BINARY */
44 typedef enum _cups_transfer_e
/**** How to send request data ****/
46 _CUPS_TRANSFER_AUTO
, /* Chunk for files, length for static */
47 _CUPS_TRANSFER_CHUNKED
, /* Chunk always */
48 _CUPS_TRANSFER_LENGTH
/* Length always */
51 typedef enum _cups_output_e
/**** Output mode ****/
53 _CUPS_OUTPUT_QUIET
, /* No output */
54 _CUPS_OUTPUT_TEST
, /* Traditional CUPS test output */
55 _CUPS_OUTPUT_PLIST
, /* XML plist test output */
56 _CUPS_OUTPUT_LIST
, /* Tabular list output */
57 _CUPS_OUTPUT_CSV
/* Comma-separated values output */
60 typedef enum _cups_with_e
/**** WITH flags ****/
62 _CUPS_WITH_LITERAL
= 0, /* Match string is a literal value */
63 _CUPS_WITH_ALL
= 1, /* Must match all values */
64 _CUPS_WITH_REGEX
= 2, /* Match string is a regular expression */
65 _CUPS_WITH_HOSTNAME
= 4, /* Match string is a URI hostname */
66 _CUPS_WITH_RESOURCE
= 8, /* Match string is a URI resource */
67 _CUPS_WITH_SCHEME
= 16 /* Match string is a URI scheme */
70 typedef struct _cups_expect_s
/**** Expected attribute info ****/
72 int optional
, /* Optional attribute? */
73 not_expect
; /* Don't expect attribute? */
74 char *name
, /* Attribute name */
75 *of_type
, /* Type name */
76 *same_count_as
, /* Parallel attribute name */
77 *if_defined
, /* Only required if variable defined */
78 *if_not_defined
, /* Only required if variable is not defined */
79 *with_value
, /* Attribute must include this value */
80 *define_match
, /* Variable to define on match */
81 *define_no_match
, /* Variable to define on no-match */
82 *define_value
; /* Variable to define with value */
83 int repeat_limit
, /* Maximum number of times to repeat */
84 repeat_match
, /* Repeat test on match */
85 repeat_no_match
, /* Repeat test on no match */
86 with_flags
, /* WITH flags */
87 count
; /* Expected count if > 0 */
88 ipp_tag_t in_group
; /* IN-GROUP value */
91 typedef struct _cups_status_s
/**** Status info ****/
93 ipp_status_t status
; /* Expected status code */
94 char *if_defined
, /* Only if variable is defined */
95 *if_not_defined
, /* Only if variable is not defined */
96 *define_match
, /* Variable to define on match */
97 *define_no_match
, /* Variable to define on no-match */
98 *define_value
; /* Variable to define with value */
99 int repeat_limit
, /* Maximum number of times to repeat */
100 repeat_match
, /* Repeat the test when it does not match */
101 repeat_no_match
; /* Repeat the test when it matches */
104 typedef struct _cups_var_s
/**** Variable ****/
106 char *name
, /* Name of variable */
107 *value
; /* Value of variable */
110 typedef struct _cups_vars_s
/**** Set of variables ****/
112 char *uri
, /* URI for printer */
113 *filename
, /* Filename */
114 scheme
[64], /* Scheme from URI */
115 userpass
[256], /* Username/password from URI */
116 hostname
[256], /* Hostname from URI */
117 resource
[1024]; /* Resource path from URI */
118 int port
; /* Port number from URI */
119 http_encryption_t encryption
; /* Encryption for connection? */
120 double timeout
; /* Timeout for connection */
121 int family
; /* Address family */
122 cups_array_t
*vars
; /* Array of variables */
130 static _cups_transfer_t Transfer
= _CUPS_TRANSFER_AUTO
;
131 /* How to transfer requests */
132 static _cups_output_t Output
= _CUPS_OUTPUT_LIST
;
134 static int Cancel
= 0, /* Cancel test? */
135 IgnoreErrors
= 0, /* Ignore errors? */
136 StopAfterIncludeError
= 0,
137 /* Stop after include errors? */
138 Verbosity
= 0, /* Show all attributes? */
139 Version
= 11, /* Default IPP version */
140 XMLHeader
= 0, /* 1 if header is written */
141 TestCount
= 0, /* Number of tests run */
142 PassCount
= 0, /* Number of passing tests */
143 FailCount
= 0, /* Number of failing tests */
144 SkipCount
= 0; /* Number of skipped tests */
145 static char *Username
= NULL
, /* Username from URI */
146 *Password
= NULL
; /* Password from URI */
147 static int PasswordTries
= 0; /* Number of tries with password */
154 static void add_stringf(cups_array_t
*a
, const char *s
, ...)
155 __attribute__ ((__format__ (__printf__
, 2, 3)));
156 static int compare_vars(_cups_var_t
*a
, _cups_var_t
*b
);
157 static int do_tests(FILE *outfile
, _cups_vars_t
*vars
, const char *testfile
);
158 static void expand_variables(_cups_vars_t
*vars
, char *dst
, const char *src
,
159 size_t dstsize
) __attribute__((nonnull(1,2,3)));
160 static int expect_matches(_cups_expect_t
*expect
, ipp_tag_t value_tag
);
161 static ipp_t
*get_collection(FILE *outfile
, _cups_vars_t
*vars
, FILE *fp
, int *linenum
);
162 static char *get_filename(const char *testfile
, char *dst
, const char *src
,
164 static char *get_string(ipp_attribute_t
*attr
, int element
, int flags
,
165 char *buffer
, size_t bufsize
);
166 static char *get_token(FILE *fp
, char *buf
, int buflen
,
168 static char *get_variable(_cups_vars_t
*vars
, const char *name
);
169 static char *iso_date(ipp_uchar_t
*date
);
170 static const char *password_cb(const char *prompt
);
171 static void pause_message(const char *message
);
172 static void print_attr(FILE *outfile
, int format
, ipp_attribute_t
*attr
, ipp_tag_t
*group
);
173 static void print_csv(FILE *outfile
, ipp_attribute_t
*attr
, int num_displayed
,
174 char **displayed
, size_t *widths
);
175 static void print_fatal_error(FILE *outfile
, const char *s
, ...)
176 __attribute__ ((__format__ (__printf__
, 2, 3)));
177 static void print_line(FILE *outfile
, ipp_attribute_t
*attr
, int num_displayed
,
178 char **displayed
, size_t *widths
);
179 static void print_xml_header(FILE *outfile
);
180 static void print_xml_string(FILE *outfile
, const char *element
, const char *s
);
181 static void print_xml_trailer(FILE *outfile
, int success
, const char *message
);
182 static void set_variable(FILE *outfile
, _cups_vars_t
*vars
, const char *name
, const char *value
);
184 static void sigterm_handler(int sig
);
186 static int timeout_cb(http_t
*http
, void *user_data
);
187 static void usage(void) __attribute__((noreturn
));
188 static int validate_attr(FILE *outfile
, cups_array_t
*errors
, ipp_attribute_t
*attr
);
189 static int with_value(FILE *outfile
, cups_array_t
*errors
, char *value
, int flags
,
190 ipp_attribute_t
*attr
, char *matchbuf
,
195 * 'main()' - Parse options and do tests.
198 int /* O - Exit status */
199 main(int argc
, /* I - Number of command-line args */
200 char *argv
[]) /* I - Command-line arguments */
202 int i
; /* Looping var */
203 int status
; /* Status of tests... */
204 FILE *outfile
= stdout
;
206 char *opt
, /* Current option */
207 name
[1024], /* Name/value buffer */
208 *value
, /* Pointer to value */
209 filename
[1024], /* Real filename */
210 testname
[1024], /* Real test filename */
211 uri
[1024]; /* Copy of printer URI */
212 const char *ext
, /* Extension on filename */
213 *testfile
; /* Test file to use */
214 int interval
, /* Test interval in microseconds */
215 repeat
; /* Repeat count */
216 _cups_vars_t vars
; /* Variables */
217 http_uri_status_t uri_status
; /* URI separation status */
218 _cups_globals_t
*cg
= _cupsGlobals();
224 * Catch SIGINT and SIGTERM...
227 signal(SIGINT
, sigterm_handler
);
228 signal(SIGTERM
, sigterm_handler
);
232 * Initialize the locale and variables...
235 _cupsSetLocale(argv
);
237 memset(&vars
, 0, sizeof(vars
));
238 vars
.family
= AF_UNSPEC
;
239 vars
.vars
= cupsArrayNew((cups_array_func_t
)compare_vars
, NULL
);
244 * ipptool URI testfile
252 for (i
= 1; i
< argc
; i
++)
254 if (!strcmp(argv
[i
], "--help"))
258 else if (!strcmp(argv
[i
], "--stop-after-include-error"))
260 StopAfterIncludeError
= 1;
262 else if (!strcmp(argv
[i
], "--version"))
267 else if (argv
[i
][0] == '-')
269 for (opt
= argv
[i
] + 1; *opt
; opt
++)
273 case '4' : /* Connect using IPv4 only */
274 vars
.family
= AF_INET
;
278 case '6' : /* Connect using IPv6 only */
279 vars
.family
= AF_INET6
;
281 #endif /* AF_INET6 */
283 case 'C' : /* Enable HTTP chunking */
284 Transfer
= _CUPS_TRANSFER_CHUNKED
;
287 case 'E' : /* Encrypt with TLS */
289 vars
.encryption
= HTTP_ENCRYPT_REQUIRED
;
291 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."),
293 #endif /* HAVE_SSL */
296 case 'I' : /* Ignore errors */
300 case 'L' : /* Disable HTTP chunking */
301 Transfer
= _CUPS_TRANSFER_LENGTH
;
304 case 'P' : /* Output to plist file */
309 _cupsLangPrintf(stderr
, _("%s: Missing filename for \"-P\"."), "ipptool");
313 if (outfile
!= stdout
)
316 if ((outfile
= fopen(argv
[i
], "w")) == NULL
)
318 _cupsLangPrintf(stderr
, _("%s: Unable to open \"%s\": %s"), "ipptool", argv
[i
], strerror(errno
));
322 Output
= _CUPS_OUTPUT_PLIST
;
324 if (interval
|| repeat
)
326 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
331 case 'S' : /* Encrypt with SSL */
333 vars
.encryption
= HTTP_ENCRYPT_ALWAYS
;
335 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."),
337 #endif /* HAVE_SSL */
340 case 'T' : /* Set timeout */
345 _cupsLangPrintf(stderr
,
346 _("%s: Missing timeout for \"-T\"."),
351 vars
.timeout
= _cupsStrScand(argv
[i
], NULL
, localeconv());
354 case 'V' : /* Set IPP version */
359 _cupsLangPrintf(stderr
,
360 _("%s: Missing version for \"-V\"."),
365 if (!strcmp(argv
[i
], "1.0"))
367 else if (!strcmp(argv
[i
], "1.1"))
369 else if (!strcmp(argv
[i
], "2.0"))
371 else if (!strcmp(argv
[i
], "2.1"))
373 else if (!strcmp(argv
[i
], "2.2"))
377 _cupsLangPrintf(stderr
,
378 _("%s: Bad version %s for \"-V\"."),
384 case 'X' : /* Produce XML output */
385 Output
= _CUPS_OUTPUT_PLIST
;
387 if (interval
|| repeat
)
389 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
394 case 'c' : /* CSV output */
395 Output
= _CUPS_OUTPUT_CSV
;
398 case 'd' : /* Define a variable */
403 _cupsLangPuts(stderr
,
404 _("ipptool: Missing name=value for \"-d\"."));
408 strlcpy(name
, argv
[i
], sizeof(name
));
409 if ((value
= strchr(name
, '=')) != NULL
)
412 value
= name
+ strlen(name
);
414 set_variable(outfile
, &vars
, name
, value
);
417 case 'f' : /* Set the default test filename */
422 _cupsLangPuts(stderr
,
423 _("ipptool: Missing filename for \"-f\"."));
430 vars
.filename
= NULL
;
433 if (access(argv
[i
], 0))
439 snprintf(filename
, sizeof(filename
), "%s.gz", argv
[i
]);
440 if (access(filename
, 0) && filename
[0] != '/'
442 && (!isalpha(filename
[0] & 255) || filename
[1] != ':')
446 snprintf(filename
, sizeof(filename
), "%s/ipptool/%s",
447 cg
->cups_datadir
, argv
[i
]);
448 if (access(filename
, 0))
450 snprintf(filename
, sizeof(filename
), "%s/ipptool/%s.gz",
451 cg
->cups_datadir
, argv
[i
]);
452 if (access(filename
, 0))
453 vars
.filename
= strdup(argv
[i
]);
455 vars
.filename
= strdup(filename
);
458 vars
.filename
= strdup(filename
);
461 vars
.filename
= strdup(filename
);
464 vars
.filename
= strdup(argv
[i
]);
466 if ((ext
= strrchr(vars
.filename
, '.')) != NULL
)
469 * Guess the MIME media type based on the extension...
472 if (!_cups_strcasecmp(ext
, ".gif"))
473 set_variable(outfile
, &vars
, "filetype", "image/gif");
474 else if (!_cups_strcasecmp(ext
, ".htm") ||
475 !_cups_strcasecmp(ext
, ".htm.gz") ||
476 !_cups_strcasecmp(ext
, ".html") ||
477 !_cups_strcasecmp(ext
, ".html.gz"))
478 set_variable(outfile
, &vars
, "filetype", "text/html");
479 else if (!_cups_strcasecmp(ext
, ".jpg") ||
480 !_cups_strcasecmp(ext
, ".jpeg"))
481 set_variable(outfile
, &vars
, "filetype", "image/jpeg");
482 else if (!_cups_strcasecmp(ext
, ".pcl") ||
483 !_cups_strcasecmp(ext
, ".pcl.gz"))
484 set_variable(outfile
, &vars
, "filetype", "application/vnd.hp-PCL");
485 else if (!_cups_strcasecmp(ext
, ".pdf"))
486 set_variable(outfile
, &vars
, "filetype", "application/pdf");
487 else if (!_cups_strcasecmp(ext
, ".png"))
488 set_variable(outfile
, &vars
, "filetype", "image/png");
489 else if (!_cups_strcasecmp(ext
, ".ps") ||
490 !_cups_strcasecmp(ext
, ".ps.gz"))
491 set_variable(outfile
, &vars
, "filetype", "application/postscript");
492 else if (!_cups_strcasecmp(ext
, ".pwg") ||
493 !_cups_strcasecmp(ext
, ".pwg.gz") ||
494 !_cups_strcasecmp(ext
, ".ras") ||
495 !_cups_strcasecmp(ext
, ".ras.gz"))
496 set_variable(outfile
, &vars
, "filetype", "image/pwg-raster");
497 else if (!_cups_strcasecmp(ext
, ".tif") ||
498 !_cups_strcasecmp(ext
, ".tiff"))
499 set_variable(outfile
, &vars
, "filetype", "image/tiff");
500 else if (!_cups_strcasecmp(ext
, ".txt") ||
501 !_cups_strcasecmp(ext
, ".txt.gz"))
502 set_variable(outfile
, &vars
, "filetype", "text/plain");
503 else if (!_cups_strcasecmp(ext
, ".urf") ||
504 !_cups_strcasecmp(ext
, ".urf.gz"))
505 set_variable(outfile
, &vars
, "filetype", "image/urf");
506 else if (!_cups_strcasecmp(ext
, ".xps"))
507 set_variable(outfile
, &vars
, "filetype", "application/openxps");
509 set_variable(outfile
, &vars
, "filetype", "application/octet-stream");
514 * Use the "auto-type" MIME media type...
517 set_variable(outfile
, &vars
, "filetype", "application/octet-stream");
521 case 'i' : /* Test every N seconds */
526 _cupsLangPuts(stderr
,
527 _("ipptool: Missing seconds for \"-i\"."));
532 interval
= (int)(_cupsStrScand(argv
[i
], NULL
, localeconv()) *
536 _cupsLangPuts(stderr
,
537 _("ipptool: Invalid seconds for \"-i\"."));
542 if (Output
== _CUPS_OUTPUT_PLIST
&& interval
)
544 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
549 case 'l' : /* List as a table */
550 Output
= _CUPS_OUTPUT_LIST
;
553 case 'n' : /* Repeat count */
558 _cupsLangPuts(stderr
,
559 _("ipptool: Missing count for \"-n\"."));
563 repeat
= atoi(argv
[i
]);
565 if (Output
== _CUPS_OUTPUT_PLIST
&& repeat
)
567 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
572 case 'q' : /* Be quiet */
573 Output
= _CUPS_OUTPUT_QUIET
;
576 case 't' : /* CUPS test output */
577 Output
= _CUPS_OUTPUT_TEST
;
580 case 'v' : /* Be verbose */
585 _cupsLangPrintf(stderr
, _("ipptool: Unknown option \"-%c\"."),
591 else if (!strncmp(argv
[i
], "ipp://", 6) || !strncmp(argv
[i
], "http://", 7)
593 || !strncmp(argv
[i
], "ipps://", 7)
594 || !strncmp(argv
[i
], "https://", 8)
595 #endif /* HAVE_SSL */
604 _cupsLangPuts(stderr
, _("ipptool: May only specify a single URI."));
609 if (!strncmp(argv
[i
], "ipps://", 7) || !strncmp(argv
[i
], "https://", 8))
610 vars
.encryption
= HTTP_ENCRYPT_ALWAYS
;
611 #endif /* HAVE_SSL */
614 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, vars
.uri
,
615 vars
.scheme
, sizeof(vars
.scheme
),
616 vars
.userpass
, sizeof(vars
.userpass
),
617 vars
.hostname
, sizeof(vars
.hostname
),
619 vars
.resource
, sizeof(vars
.resource
));
621 if (uri_status
!= HTTP_URI_OK
)
623 _cupsLangPrintf(stderr
, _("ipptool: Bad URI - %s."), httpURIStatusString(uri_status
));
627 if (vars
.userpass
[0])
629 if ((Password
= strchr(vars
.userpass
, ':')) != NULL
)
632 Username
= vars
.userpass
;
633 cupsSetPasswordCB(password_cb
);
634 set_variable(outfile
, &vars
, "uriuser", vars
.userpass
);
637 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), vars
.scheme
, NULL
,
638 vars
.hostname
, vars
.port
, vars
.resource
);
649 _cupsLangPuts(stderr
, _("ipptool: URI required before test file."));
653 if (access(argv
[i
], 0) && argv
[i
][0] != '/'
655 && (!isalpha(argv
[i
][0] & 255) || argv
[i
][1] != ':')
659 snprintf(testname
, sizeof(testname
), "%s/ipptool/%s", cg
->cups_datadir
,
661 if (access(testname
, 0))
669 if (!do_tests(outfile
, &vars
, testfile
))
674 if (!vars
.uri
|| !testfile
)
678 * Loop if the interval is set...
681 if (Output
== _CUPS_OUTPUT_PLIST
)
682 print_xml_trailer(outfile
, !status
, NULL
);
683 else if (interval
> 0 && repeat
> 0)
687 usleep((useconds_t
)interval
);
688 do_tests(outfile
, &vars
, testfile
);
692 else if (interval
> 0)
696 usleep((useconds_t
)interval
);
697 do_tests(outfile
, &vars
, testfile
);
701 if ((Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
)) && TestCount
> 1)
704 * Show a summary report if there were multiple tests...
707 printf("\nSummary: %d tests, %d passed, %d failed, %d skipped\n"
708 "Score: %d%%\n", TestCount
, PassCount
, FailCount
, SkipCount
,
709 100 * (PassCount
+ SkipCount
) / TestCount
);
721 * 'add_stringf()' - Add a formatted string to an array.
725 add_stringf(cups_array_t
*a
, /* I - Array */
726 const char *s
, /* I - Printf-style format string */
727 ...) /* I - Additional args as needed */
729 char buffer
[10240]; /* Format buffer */
730 va_list ap
; /* Argument pointer */
734 * Don't bother is the array is NULL...
741 * Format the message...
745 vsnprintf(buffer
, sizeof(buffer
), s
, ap
);
749 * Add it to the array...
752 cupsArrayAdd(a
, buffer
);
757 * 'compare_vars()' - Compare two variables.
760 static int /* O - Result of comparison */
761 compare_vars(_cups_var_t
*a
, /* I - First variable */
762 _cups_var_t
*b
) /* I - Second variable */
764 return (_cups_strcasecmp(a
->name
, b
->name
));
769 * 'do_tests()' - Do tests as specified in the test file.
772 static int /* 1 = success, 0 = failure */
773 do_tests(FILE *outfile
, /* I - Output file */
774 _cups_vars_t
*vars
, /* I - Variables */
775 const char *testfile
) /* I - Test file to use */
777 int i
, /* Looping var */
778 linenum
, /* Current line number */
779 pass
, /* Did we pass the test? */
780 prev_pass
= 1, /* Did we pass the previous test? */
781 request_id
, /* Current request ID */
782 show_header
= 1, /* Show the test header? */
783 ignore_errors
, /* Ignore test failures? */
784 skip_previous
= 0, /* Skip on previous test failure? */
785 repeat_count
, /* Repeat count */
786 repeat_interval
, /* Repeat interval */
787 repeat_prev
, /* Previous repeat interval */
788 repeat_test
; /* Repeat a test? */
789 http_t
*http
= NULL
; /* HTTP connection to server */
790 FILE *fp
= NULL
; /* Test file */
791 char resource
[512], /* Resource for request */
792 token
[1024], /* Token from file */
793 *tokenptr
, /* Pointer into token */
794 temp
[1024], /* Temporary string */
795 buffer
[8192], /* Copy buffer */
796 compression
[16]; /* COMPRESSION value */
797 ipp_t
*request
= NULL
, /* IPP request */
798 *response
= NULL
; /* IPP response */
799 size_t length
; /* Length of IPP request */
800 http_status_t status
; /* HTTP status */
801 cups_file_t
*reqfile
; /* File to send */
802 ssize_t bytes
; /* Bytes read/written */
803 char attr
[128]; /* Attribute name */
804 ipp_op_t op
; /* Operation */
805 ipp_tag_t group
; /* Current group */
806 ipp_tag_t value
; /* Current value type */
807 ipp_attribute_t
*attrptr
, /* Attribute pointer */
808 *found
, /* Found attribute */
809 *lastcol
= NULL
; /* Last collection attribute */
810 char name
[1024], /* Name of test */
811 file_id
[1024], /* File identifier */
812 test_id
[1024]; /* Test identifier */
813 char filename
[1024]; /* Filename */
814 _cups_transfer_t transfer
; /* To chunk or not to chunk */
815 int version
, /* IPP version number to use */
816 skip_test
; /* Skip this test? */
817 int num_statuses
= 0; /* Number of valid status codes */
818 _cups_status_t statuses
[100], /* Valid status codes */
819 *last_status
; /* Last STATUS (for predicates) */
820 int num_expects
= 0; /* Number of expected attributes */
821 _cups_expect_t expects
[200], /* Expected attributes */
822 *expect
, /* Current expected attribute */
823 *last_expect
; /* Last EXPECT (for predicates) */
824 int num_displayed
= 0; /* Number of displayed attributes */
825 char *displayed
[200]; /* Displayed attributes */
826 size_t widths
[200]; /* Width of columns */
827 cups_array_t
*a
, /* Duplicate attribute array */
828 *errors
= NULL
; /* Errors array */
829 const char *error
; /* Current error */
833 * Open the test file...
836 if ((fp
= fopen(testfile
, "r")) == NULL
)
838 print_fatal_error(outfile
, "Unable to open test file %s - %s", testfile
,
845 * Connect to the server...
848 if ((http
= httpConnect2(vars
->hostname
, vars
->port
, NULL
, vars
->family
,
849 vars
->encryption
, 1, 30000, NULL
)) == NULL
)
851 print_fatal_error(outfile
, "Unable to connect to %s on port %d - %s", vars
->hostname
,
852 vars
->port
, cupsLastErrorString());
858 httpSetDefaultField(http
, HTTP_FIELD_ACCEPT_ENCODING
,
859 "deflate, gzip, identity");
861 httpSetDefaultField(http
, HTTP_FIELD_ACCEPT_ENCODING
, "identity");
862 #endif /* HAVE_LIBZ */
864 if (vars
->timeout
> 0.0)
865 httpSetTimeout(http
, vars
->timeout
, timeout_cb
, NULL
);
871 CUPS_SRAND(time(NULL
));
873 errors
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
,
874 (cups_afree_func_t
)free
);
878 request_id
= (CUPS_RAND() % 1000) * 137 + 1;
880 while (!Cancel
&& get_token(fp
, token
, sizeof(token
), &linenum
) != NULL
)
883 * Expect an open brace...
886 if (!strcmp(token
, "DEFINE"))
892 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
893 get_token(fp
, temp
, sizeof(temp
), &linenum
))
895 expand_variables(vars
, token
, temp
, sizeof(token
));
896 set_variable(outfile
, vars
, attr
, token
);
900 print_fatal_error(outfile
, "Missing DEFINE name and/or value on line %d.",
908 else if (!strcmp(token
, "DEFINE-DEFAULT"))
911 * DEFINE-DEFAULT name value
914 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
915 get_token(fp
, temp
, sizeof(temp
), &linenum
))
917 expand_variables(vars
, token
, temp
, sizeof(token
));
918 if (!get_variable(vars
, attr
))
919 set_variable(outfile
, vars
, attr
, token
);
923 print_fatal_error(outfile
, "Missing DEFINE-DEFAULT name and/or value on line "
931 else if (!strcmp(token
, "FILE-ID"))
937 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
939 expand_variables(vars
, file_id
, temp
, sizeof(file_id
));
943 print_fatal_error(outfile
, "Missing FILE-ID value on line %d.", linenum
);
950 else if (!strcmp(token
, "IGNORE-ERRORS"))
957 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
958 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
960 IgnoreErrors
= !_cups_strcasecmp(temp
, "yes");
964 print_fatal_error(outfile
, "Missing IGNORE-ERRORS value on line %d.", linenum
);
971 else if (!strcmp(token
, "INCLUDE"))
978 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
981 * Map the filename to and then run the tests...
984 if (!do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
988 if (StopAfterIncludeError
)
994 print_fatal_error(outfile
, "Missing INCLUDE filename on line %d.", linenum
);
1002 else if (!strcmp(token
, "INCLUDE-IF-DEFINED"))
1005 * INCLUDE-IF-DEFINED name "filename"
1006 * INCLUDE-IF-DEFINED name <filename>
1009 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1010 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1013 * Map the filename to and then run the tests...
1016 if (get_variable(vars
, attr
) &&
1017 !do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
1021 if (StopAfterIncludeError
)
1027 print_fatal_error(outfile
, "Missing INCLUDE-IF-DEFINED name or filename on line "
1036 else if (!strcmp(token
, "INCLUDE-IF-NOT-DEFINED"))
1039 * INCLUDE-IF-NOT-DEFINED name "filename"
1040 * INCLUDE-IF-NOT-DEFINED name <filename>
1043 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1044 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1047 * Map the filename to and then run the tests...
1050 if (!get_variable(vars
, attr
) &&
1051 !do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
1055 if (StopAfterIncludeError
)
1061 print_fatal_error(outfile
, "Missing INCLUDE-IF-NOT-DEFINED name or filename on "
1062 "line %d.", linenum
);
1070 else if (!strcmp(token
, "SKIP-IF-DEFINED"))
1073 * SKIP-IF-DEFINED variable
1076 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1078 if (get_variable(vars
, temp
))
1083 print_fatal_error(outfile
, "Missing SKIP-IF-DEFINED variable on line %d.",
1089 else if (!strcmp(token
, "SKIP-IF-NOT-DEFINED"))
1092 * SKIP-IF-NOT-DEFINED variable
1095 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1097 if (!get_variable(vars
, temp
))
1102 print_fatal_error(outfile
, "Missing SKIP-IF-NOT-DEFINED variable on line %d.",
1108 else if (!strcmp(token
, "STOP-AFTER-INCLUDE-ERROR"))
1111 * STOP-AFTER-INCLUDE-ERROR yes
1112 * STOP-AFTER-INCLUDE-ERROR no
1115 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1116 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1118 StopAfterIncludeError
= !_cups_strcasecmp(temp
, "yes");
1122 print_fatal_error(outfile
, "Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
1130 else if (!strcmp(token
, "TRANSFER"))
1138 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1140 if (!strcmp(temp
, "auto"))
1141 Transfer
= _CUPS_TRANSFER_AUTO
;
1142 else if (!strcmp(temp
, "chunked"))
1143 Transfer
= _CUPS_TRANSFER_CHUNKED
;
1144 else if (!strcmp(temp
, "length"))
1145 Transfer
= _CUPS_TRANSFER_LENGTH
;
1148 print_fatal_error(outfile
, "Bad TRANSFER value \"%s\" on line %d.", temp
,
1156 print_fatal_error(outfile
, "Missing TRANSFER value on line %d.", linenum
);
1163 else if (!strcmp(token
, "VERSION"))
1165 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1167 if (!strcmp(temp
, "1.0"))
1169 else if (!strcmp(temp
, "1.1"))
1171 else if (!strcmp(temp
, "2.0"))
1173 else if (!strcmp(temp
, "2.1"))
1175 else if (!strcmp(temp
, "2.2"))
1179 print_fatal_error(outfile
, "Bad VERSION \"%s\" on line %d.", temp
, linenum
);
1186 print_fatal_error(outfile
, "Missing VERSION number on line %d.", linenum
);
1193 else if (strcmp(token
, "{"))
1195 print_fatal_error(outfile
, "Unexpected token %s seen on line %d.", token
, linenum
);
1201 * Initialize things...
1206 if (Output
== _CUPS_OUTPUT_PLIST
)
1207 print_xml_header(outfile
);
1208 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
1209 printf("\"%s\":\n", testfile
);
1214 strlcpy(resource
, vars
->resource
, sizeof(resource
));
1219 group
= IPP_TAG_ZERO
;
1220 ignore_errors
= IgnoreErrors
;
1228 transfer
= Transfer
;
1229 compression
[0] = '\0';
1231 strlcpy(name
, testfile
, sizeof(name
));
1232 if (strrchr(name
, '.') != NULL
)
1233 *strrchr(name
, '.') = '\0';
1236 * Parse until we see a close brace...
1239 while (get_token(fp
, token
, sizeof(token
), &linenum
) != NULL
)
1241 if (_cups_strcasecmp(token
, "COUNT") &&
1242 _cups_strcasecmp(token
, "DEFINE-MATCH") &&
1243 _cups_strcasecmp(token
, "DEFINE-NO-MATCH") &&
1244 _cups_strcasecmp(token
, "DEFINE-VALUE") &&
1245 _cups_strcasecmp(token
, "IF-DEFINED") &&
1246 _cups_strcasecmp(token
, "IF-NOT-DEFINED") &&
1247 _cups_strcasecmp(token
, "IN-GROUP") &&
1248 _cups_strcasecmp(token
, "OF-TYPE") &&
1249 _cups_strcasecmp(token
, "REPEAT-LIMIT") &&
1250 _cups_strcasecmp(token
, "REPEAT-MATCH") &&
1251 _cups_strcasecmp(token
, "REPEAT-NO-MATCH") &&
1252 _cups_strcasecmp(token
, "SAME-COUNT-AS") &&
1253 _cups_strcasecmp(token
, "WITH-ALL-VALUES") &&
1254 _cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") &&
1255 _cups_strcasecmp(token
, "WITH-ALL-RESOURCES") &&
1256 _cups_strcasecmp(token
, "WITH-ALL-SCHEMES") &&
1257 _cups_strcasecmp(token
, "WITH-HOSTNAME") &&
1258 _cups_strcasecmp(token
, "WITH-RESOURCE") &&
1259 _cups_strcasecmp(token
, "WITH-SCHEME") &&
1260 _cups_strcasecmp(token
, "WITH-VALUE"))
1263 if (_cups_strcasecmp(token
, "DEFINE-MATCH") &&
1264 _cups_strcasecmp(token
, "DEFINE-NO-MATCH") &&
1265 _cups_strcasecmp(token
, "IF-DEFINED") &&
1266 _cups_strcasecmp(token
, "IF-NOT-DEFINED") &&
1267 _cups_strcasecmp(token
, "REPEAT-LIMIT") &&
1268 _cups_strcasecmp(token
, "REPEAT-MATCH") &&
1269 _cups_strcasecmp(token
, "REPEAT-NO-MATCH"))
1272 if (!strcmp(token
, "}"))
1274 else if (!strcmp(token
, "{") && lastcol
)
1277 * Another collection value
1280 ipp_t
*col
= get_collection(outfile
, vars
, fp
, &linenum
);
1281 /* Collection value */
1285 ippSetCollection(request
, &lastcol
, ippGetCount(lastcol
), col
);
1293 else if (!strcmp(token
, "COMPRESSION"))
1297 * COMPRESSION deflate
1301 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1303 expand_variables(vars
, compression
, temp
, sizeof(compression
));
1305 if (strcmp(compression
, "none") && strcmp(compression
, "deflate") &&
1306 strcmp(compression
, "gzip"))
1308 if (strcmp(compression
, "none"))
1309 #endif /* HAVE_LIBZ */
1311 print_fatal_error(outfile
, "Unsupported COMPRESSION value '%s' on line %d.",
1312 compression
, linenum
);
1317 if (!strcmp(compression
, "none"))
1318 compression
[0] = '\0';
1322 print_fatal_error(outfile
, "Missing COMPRESSION value on line %d.", linenum
);
1327 else if (!strcmp(token
, "DEFINE"))
1333 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1334 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1336 expand_variables(vars
, token
, temp
, sizeof(token
));
1337 set_variable(outfile
, vars
, attr
, token
);
1341 print_fatal_error(outfile
, "Missing DEFINE name and/or value on line %d.",
1347 else if (!strcmp(token
, "IGNORE-ERRORS"))
1354 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1355 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1357 ignore_errors
= !_cups_strcasecmp(temp
, "yes");
1361 print_fatal_error(outfile
, "Missing IGNORE-ERRORS value on line %d.", linenum
);
1368 else if (!_cups_strcasecmp(token
, "NAME"))
1374 get_token(fp
, name
, sizeof(name
), &linenum
);
1376 else if (!_cups_strcasecmp(token
, "PAUSE"))
1379 * Pause with a message...
1382 get_token(fp
, token
, sizeof(token
), &linenum
);
1383 pause_message(token
);
1385 else if (!strcmp(token
, "REQUEST-ID"))
1392 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1394 if (isdigit(temp
[0] & 255))
1395 request_id
= atoi(temp
);
1396 else if (!_cups_strcasecmp(temp
, "random"))
1397 request_id
= (CUPS_RAND() % 1000) * 137 + 1;
1400 print_fatal_error(outfile
, "Bad REQUEST-ID value \"%s\" on line %d.", temp
,
1408 print_fatal_error(outfile
, "Missing REQUEST-ID value on line %d.", linenum
);
1413 else if (!strcmp(token
, "SKIP-IF-DEFINED"))
1416 * SKIP-IF-DEFINED variable
1419 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1421 if (get_variable(vars
, temp
))
1426 print_fatal_error(outfile
, "Missing SKIP-IF-DEFINED value on line %d.",
1432 else if (!strcmp(token
, "SKIP-IF-MISSING"))
1435 * SKIP-IF-MISSING filename
1438 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1440 expand_variables(vars
, token
, temp
, sizeof(token
));
1441 get_filename(testfile
, filename
, token
, sizeof(filename
));
1443 if (access(filename
, R_OK
))
1448 print_fatal_error(outfile
, "Missing SKIP-IF-MISSING filename on line %d.",
1454 else if (!strcmp(token
, "SKIP-IF-NOT-DEFINED"))
1457 * SKIP-IF-NOT-DEFINED variable
1460 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1462 if (!get_variable(vars
, temp
))
1467 print_fatal_error(outfile
, "Missing SKIP-IF-NOT-DEFINED value on line %d.",
1473 else if (!strcmp(token
, "SKIP-PREVIOUS-ERROR"))
1476 * SKIP-PREVIOUS-ERROR yes
1477 * SKIP-PREVIOUS-ERROR no
1480 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1481 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1483 skip_previous
= !_cups_strcasecmp(temp
, "yes");
1487 print_fatal_error(outfile
, "Missing SKIP-PREVIOUS-ERROR value on line %d.", linenum
);
1494 else if (!strcmp(token
, "TEST-ID"))
1500 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1502 expand_variables(vars
, test_id
, temp
, sizeof(test_id
));
1506 print_fatal_error(outfile
, "Missing TEST-ID value on line %d.", linenum
);
1513 else if (!strcmp(token
, "TRANSFER"))
1521 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1523 if (!strcmp(temp
, "auto"))
1524 transfer
= _CUPS_TRANSFER_AUTO
;
1525 else if (!strcmp(temp
, "chunked"))
1526 transfer
= _CUPS_TRANSFER_CHUNKED
;
1527 else if (!strcmp(temp
, "length"))
1528 transfer
= _CUPS_TRANSFER_LENGTH
;
1531 print_fatal_error(outfile
, "Bad TRANSFER value \"%s\" on line %d.", temp
,
1539 print_fatal_error(outfile
, "Missing TRANSFER value on line %d.", linenum
);
1544 else if (!_cups_strcasecmp(token
, "VERSION"))
1546 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1548 if (!strcmp(temp
, "0.0"))
1550 else if (!strcmp(temp
, "1.0"))
1552 else if (!strcmp(temp
, "1.1"))
1554 else if (!strcmp(temp
, "2.0"))
1556 else if (!strcmp(temp
, "2.1"))
1558 else if (!strcmp(temp
, "2.2"))
1562 print_fatal_error(outfile
, "Bad VERSION \"%s\" on line %d.", temp
, linenum
);
1569 print_fatal_error(outfile
, "Missing VERSION number on line %d.", linenum
);
1574 else if (!_cups_strcasecmp(token
, "RESOURCE"))
1580 if (!get_token(fp
, resource
, sizeof(resource
), &linenum
))
1582 print_fatal_error(outfile
, "Missing RESOURCE path on line %d.", linenum
);
1587 else if (!_cups_strcasecmp(token
, "OPERATION"))
1593 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1595 print_fatal_error(outfile
, "Missing OPERATION code on line %d.", linenum
);
1600 expand_variables(vars
, token
, temp
, sizeof(token
));
1602 if ((op
= ippOpValue(token
)) == (ipp_op_t
)-1 &&
1603 (op
= (ipp_op_t
)strtol(token
, NULL
, 0)) == 0)
1605 print_fatal_error(outfile
, "Bad OPERATION code \"%s\" on line %d.", token
,
1611 else if (!_cups_strcasecmp(token
, "GROUP"))
1614 * Attribute group...
1617 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1619 print_fatal_error(outfile
, "Missing GROUP tag on line %d.", linenum
);
1624 if ((value
= ippTagValue(token
)) < 0)
1626 print_fatal_error(outfile
, "Bad GROUP tag \"%s\" on line %d.", token
, linenum
);
1632 ippAddSeparator(request
);
1636 else if (!_cups_strcasecmp(token
, "DELAY"))
1639 * Delay before operation...
1644 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1646 print_fatal_error(outfile
, "Missing DELAY value on line %d.", linenum
);
1651 expand_variables(vars
, token
, temp
, sizeof(token
));
1653 if ((delay
= _cupsStrScand(token
, NULL
, localeconv())) <= 0.0)
1655 print_fatal_error(outfile
, "Bad DELAY value \"%s\" on line %d.", token
,
1662 if (Output
== _CUPS_OUTPUT_TEST
)
1663 printf(" [%g second delay]\n", delay
);
1665 usleep((useconds_t
)(1000000.0 * delay
));
1668 else if (!_cups_strcasecmp(token
, "ATTR"))
1674 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1676 print_fatal_error(outfile
, "Missing ATTR value tag on line %d.", linenum
);
1681 if ((value
= ippTagValue(token
)) == IPP_TAG_ZERO
)
1683 print_fatal_error(outfile
, "Bad ATTR value tag \"%s\" on line %d.", token
,
1689 if (!get_token(fp
, attr
, sizeof(attr
), &linenum
))
1691 print_fatal_error(outfile
, "Missing ATTR name on line %d.", linenum
);
1696 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1698 print_fatal_error(outfile
, "Missing ATTR value on line %d.", linenum
);
1703 expand_variables(vars
, token
, temp
, sizeof(token
));
1708 case IPP_TAG_BOOLEAN
:
1709 if (!_cups_strcasecmp(token
, "true"))
1710 attrptr
= ippAddBoolean(request
, group
, attr
, 1);
1712 attrptr
= ippAddBoolean(request
, group
, attr
, (char)atoi(token
));
1715 case IPP_TAG_INTEGER
:
1717 if (!strchr(token
, ','))
1718 attrptr
= ippAddInteger(request
, group
, value
, attr
, (int)strtol(token
, &tokenptr
, 0));
1721 int values
[100], /* Values */
1722 num_values
= 1; /* Number of values */
1724 values
[0] = (int)strtol(token
, &tokenptr
, 10);
1725 while (tokenptr
&& *tokenptr
&&
1726 num_values
< (int)(sizeof(values
) / sizeof(values
[0])))
1728 if (*tokenptr
== ',')
1730 else if (!isdigit(*tokenptr
& 255) && *tokenptr
!= '-')
1733 values
[num_values
] = (int)strtol(tokenptr
, &tokenptr
, 0);
1737 attrptr
= ippAddIntegers(request
, group
, value
, attr
, num_values
, values
);
1740 if (!tokenptr
|| *tokenptr
)
1742 print_fatal_error(outfile
, "Bad %s value \"%s\" on line %d.",
1743 ippTagString(value
), token
, linenum
);
1749 case IPP_TAG_RESOLUTION
:
1751 int xres
, /* X resolution */
1752 yres
; /* Y resolution */
1753 char *ptr
; /* Pointer into value */
1755 xres
= yres
= (int)strtol(token
, (char **)&ptr
, 10);
1756 if (ptr
> token
&& xres
> 0)
1759 yres
= (int)strtol(ptr
+ 1, (char **)&ptr
, 10);
1762 if (ptr
<= token
|| xres
<= 0 || yres
<= 0 || !ptr
||
1763 (_cups_strcasecmp(ptr
, "dpi") &&
1764 _cups_strcasecmp(ptr
, "dpc") &&
1765 _cups_strcasecmp(ptr
, "dpcm") &&
1766 _cups_strcasecmp(ptr
, "other")))
1768 print_fatal_error(outfile
, "Bad resolution value \"%s\" on line %d.",
1774 if (!_cups_strcasecmp(ptr
, "dpi"))
1775 attrptr
= ippAddResolution(request
, group
, attr
, IPP_RES_PER_INCH
, xres
, yres
);
1776 else if (!_cups_strcasecmp(ptr
, "dpc") ||
1777 !_cups_strcasecmp(ptr
, "dpcm"))
1778 attrptr
= ippAddResolution(request
, group
, attr
, IPP_RES_PER_CM
, xres
, yres
);
1780 attrptr
= ippAddResolution(request
, group
, attr
, (ipp_res_t
)0, xres
, yres
);
1784 case IPP_TAG_RANGE
:
1786 int lowers
[4], /* Lower value */
1787 uppers
[4], /* Upper values */
1788 num_vals
; /* Number of values */
1791 num_vals
= sscanf(token
, "%d-%d,%d-%d,%d-%d,%d-%d",
1792 lowers
+ 0, uppers
+ 0,
1793 lowers
+ 1, uppers
+ 1,
1794 lowers
+ 2, uppers
+ 2,
1795 lowers
+ 3, uppers
+ 3);
1797 if ((num_vals
& 1) || num_vals
== 0)
1799 print_fatal_error(outfile
, "Bad rangeOfInteger value \"%s\" on line "
1800 "%d.", token
, linenum
);
1805 attrptr
= ippAddRanges(request
, group
, attr
, num_vals
/ 2, lowers
,
1810 case IPP_TAG_BEGIN_COLLECTION
:
1811 if (!strcmp(token
, "{"))
1813 ipp_t
*col
= get_collection(outfile
, vars
, fp
, &linenum
);
1814 /* Collection value */
1818 attrptr
= lastcol
= ippAddCollection(request
, group
, attr
, col
);
1829 print_fatal_error(outfile
, "Bad ATTR collection value on line %d.",
1837 ipp_t
*col
; /* Collection value */
1838 long pos
= ftell(fp
); /* Save position of file */
1840 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1843 if (strcmp(token
, ","))
1845 fseek(fp
, pos
, SEEK_SET
);
1849 if (!get_token(fp
, token
, sizeof(token
), &linenum
) || strcmp(token
, "{"))
1851 print_fatal_error(outfile
, "Unexpected \"%s\" on line %d.", token
, linenum
);
1857 if ((col
= get_collection(outfile
, vars
, fp
, &linenum
)) == NULL
)
1860 ippSetCollection(request
, &attrptr
, ippGetCount(attrptr
), col
);
1863 while (!strcmp(token
, "{"));
1866 case IPP_TAG_STRING
:
1867 attrptr
= ippAddOctetString(request
, group
, attr
, token
, (int)strlen(token
));
1871 print_fatal_error(outfile
, "Unsupported ATTR value tag %s on line %d.",
1872 ippTagString(value
), linenum
);
1876 case IPP_TAG_TEXTLANG
:
1877 case IPP_TAG_NAMELANG
:
1880 case IPP_TAG_KEYWORD
:
1882 case IPP_TAG_URISCHEME
:
1883 case IPP_TAG_CHARSET
:
1884 case IPP_TAG_LANGUAGE
:
1885 case IPP_TAG_MIMETYPE
:
1886 if (!strchr(token
, ','))
1887 attrptr
= ippAddString(request
, group
, value
, attr
, NULL
, token
);
1891 * Multiple string values...
1894 int num_values
; /* Number of values */
1895 char *values
[100], /* Values */
1896 *ptr
; /* Pointer to next value */
1902 for (ptr
= strchr(token
, ','); ptr
; ptr
= strchr(ptr
, ','))
1904 if (ptr
> token
&& ptr
[-1] == '\\')
1905 _cups_strcpy(ptr
- 1, ptr
);
1909 values
[num_values
] = ptr
;
1914 attrptr
= ippAddStrings(request
, group
, value
, attr
, num_values
,
1915 NULL
, (const char **)values
);
1922 print_fatal_error(outfile
, "Unable to add attribute on line %d: %s", linenum
,
1923 cupsLastErrorString());
1928 else if (!_cups_strcasecmp(token
, "FILE"))
1934 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1936 print_fatal_error(outfile
, "Missing FILE filename on line %d.", linenum
);
1941 expand_variables(vars
, token
, temp
, sizeof(token
));
1942 get_filename(testfile
, filename
, token
, sizeof(filename
));
1944 if (access(filename
, R_OK
))
1946 print_fatal_error(outfile
, "Filename \"%s\" on line %d cannot be read.",
1948 print_fatal_error(outfile
, "Filename mapped to \"%s\".", filename
);
1953 else if (!_cups_strcasecmp(token
, "STATUS"))
1959 if (num_statuses
>= (int)(sizeof(statuses
) / sizeof(statuses
[0])))
1961 print_fatal_error(outfile
, "Too many STATUS's on line %d.", linenum
);
1966 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1968 print_fatal_error(outfile
, "Missing STATUS code on line %d.", linenum
);
1973 if ((statuses
[num_statuses
].status
= ippErrorValue(token
))
1974 == (ipp_status_t
)-1 &&
1975 (statuses
[num_statuses
].status
= (ipp_status_t
)strtol(token
, NULL
, 0)) == 0)
1977 print_fatal_error(outfile
, "Bad STATUS code \"%s\" on line %d.", token
,
1983 last_status
= statuses
+ num_statuses
;
1986 last_status
->define_match
= NULL
;
1987 last_status
->define_no_match
= NULL
;
1988 last_status
->if_defined
= NULL
;
1989 last_status
->if_not_defined
= NULL
;
1990 last_status
->repeat_limit
= 1000;
1991 last_status
->repeat_match
= 0;
1992 last_status
->repeat_no_match
= 0;
1994 else if (!_cups_strcasecmp(token
, "EXPECT"))
1997 * Expected attributes...
2000 if (num_expects
>= (int)(sizeof(expects
) / sizeof(expects
[0])))
2002 print_fatal_error(outfile
, "Too many EXPECT's on line %d.", linenum
);
2007 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2009 print_fatal_error(outfile
, "Missing EXPECT name on line %d.", linenum
);
2014 last_expect
= expects
+ num_expects
;
2017 memset(last_expect
, 0, sizeof(_cups_expect_t
));
2018 last_expect
->repeat_limit
= 1000;
2020 if (token
[0] == '!')
2022 last_expect
->not_expect
= 1;
2023 last_expect
->name
= strdup(token
+ 1);
2025 else if (token
[0] == '?')
2027 last_expect
->optional
= 1;
2028 last_expect
->name
= strdup(token
+ 1);
2031 last_expect
->name
= strdup(token
);
2033 else if (!_cups_strcasecmp(token
, "COUNT"))
2035 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2037 print_fatal_error(outfile
, "Missing COUNT number on line %d.", linenum
);
2042 if ((i
= atoi(token
)) <= 0)
2044 print_fatal_error(outfile
, "Bad COUNT \"%s\" on line %d.", token
, linenum
);
2050 last_expect
->count
= i
;
2053 print_fatal_error(outfile
, "COUNT without a preceding EXPECT on line %d.",
2059 else if (!_cups_strcasecmp(token
, "DEFINE-MATCH"))
2061 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2063 print_fatal_error(outfile
, "Missing DEFINE-MATCH variable on line %d.",
2070 last_expect
->define_match
= strdup(token
);
2071 else if (last_status
)
2072 last_status
->define_match
= strdup(token
);
2075 print_fatal_error(outfile
, "DEFINE-MATCH without a preceding EXPECT or STATUS "
2076 "on line %d.", linenum
);
2081 else if (!_cups_strcasecmp(token
, "DEFINE-NO-MATCH"))
2083 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2085 print_fatal_error(outfile
, "Missing DEFINE-NO-MATCH variable on line %d.",
2092 last_expect
->define_no_match
= strdup(token
);
2093 else if (last_status
)
2094 last_status
->define_no_match
= strdup(token
);
2097 print_fatal_error(outfile
, "DEFINE-NO-MATCH without a preceding EXPECT or "
2098 "STATUS on line %d.", linenum
);
2103 else if (!_cups_strcasecmp(token
, "DEFINE-VALUE"))
2105 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2107 print_fatal_error(outfile
, "Missing DEFINE-VALUE variable on line %d.",
2114 last_expect
->define_value
= strdup(token
);
2117 print_fatal_error(outfile
, "DEFINE-VALUE without a preceding EXPECT on "
2118 "line %d.", linenum
);
2123 else if (!_cups_strcasecmp(token
, "OF-TYPE"))
2125 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2127 print_fatal_error(outfile
, "Missing OF-TYPE value tag(s) on line %d.",
2134 last_expect
->of_type
= strdup(token
);
2137 print_fatal_error(outfile
, "OF-TYPE without a preceding EXPECT on line %d.",
2143 else if (!_cups_strcasecmp(token
, "IN-GROUP"))
2145 ipp_tag_t in_group
; /* IN-GROUP value */
2148 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2150 print_fatal_error(outfile
, "Missing IN-GROUP group tag on line %d.", linenum
);
2155 if ((in_group
= ippTagValue(token
)) == (ipp_tag_t
)-1)
2158 else if (last_expect
)
2159 last_expect
->in_group
= in_group
;
2162 print_fatal_error(outfile
, "IN-GROUP without a preceding EXPECT on line %d.",
2168 else if (!_cups_strcasecmp(token
, "REPEAT-LIMIT"))
2170 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2172 print_fatal_error(outfile
, "Missing REPEAT-LIMIT value on line %d.", linenum
);
2176 else if (atoi(token
) <= 0)
2178 print_fatal_error(outfile
, "Bad REPEAT-LIMIT value on line %d.", linenum
);
2184 last_status
->repeat_limit
= atoi(token
);
2185 else if (last_expect
)
2186 last_expect
->repeat_limit
= atoi(token
);
2189 print_fatal_error(outfile
, "REPEAT-LIMIT without a preceding EXPECT or STATUS "
2190 "on line %d.", linenum
);
2195 else if (!_cups_strcasecmp(token
, "REPEAT-MATCH"))
2198 last_status
->repeat_match
= 1;
2199 else if (last_expect
)
2200 last_expect
->repeat_match
= 1;
2203 print_fatal_error(outfile
, "REPEAT-MATCH without a preceding EXPECT or STATUS "
2204 "on line %d.", linenum
);
2209 else if (!_cups_strcasecmp(token
, "REPEAT-NO-MATCH"))
2212 last_status
->repeat_no_match
= 1;
2213 else if (last_expect
)
2214 last_expect
->repeat_no_match
= 1;
2217 print_fatal_error(outfile
, "REPEAT-NO-MATCH without a preceding EXPECT or "
2218 "STATUS on ine %d.", linenum
);
2223 else if (!_cups_strcasecmp(token
, "SAME-COUNT-AS"))
2225 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2227 print_fatal_error(outfile
, "Missing SAME-COUNT-AS name on line %d.", linenum
);
2233 last_expect
->same_count_as
= strdup(token
);
2236 print_fatal_error(outfile
, "SAME-COUNT-AS without a preceding EXPECT on line "
2242 else if (!_cups_strcasecmp(token
, "IF-DEFINED"))
2244 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2246 print_fatal_error(outfile
, "Missing IF-DEFINED name on line %d.", linenum
);
2252 last_expect
->if_defined
= strdup(token
);
2253 else if (last_status
)
2254 last_status
->if_defined
= strdup(token
);
2257 print_fatal_error(outfile
, "IF-DEFINED without a preceding EXPECT or STATUS "
2258 "on line %d.", linenum
);
2263 else if (!_cups_strcasecmp(token
, "IF-NOT-DEFINED"))
2265 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2267 print_fatal_error(outfile
, "Missing IF-NOT-DEFINED name on line %d.", linenum
);
2273 last_expect
->if_not_defined
= strdup(token
);
2274 else if (last_status
)
2275 last_status
->if_not_defined
= strdup(token
);
2278 print_fatal_error(outfile
, "IF-NOT-DEFINED without a preceding EXPECT or STATUS "
2279 "on line %d.", linenum
);
2284 else if (!_cups_strcasecmp(token
, "WITH-ALL-VALUES") ||
2285 !_cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") ||
2286 !_cups_strcasecmp(token
, "WITH-ALL-RESOURCES") ||
2287 !_cups_strcasecmp(token
, "WITH-ALL-SCHEMES") ||
2288 !_cups_strcasecmp(token
, "WITH-HOSTNAME") ||
2289 !_cups_strcasecmp(token
, "WITH-RESOURCE") ||
2290 !_cups_strcasecmp(token
, "WITH-SCHEME") ||
2291 !_cups_strcasecmp(token
, "WITH-VALUE"))
2295 if (!_cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") ||
2296 !_cups_strcasecmp(token
, "WITH-HOSTNAME"))
2297 last_expect
->with_flags
= _CUPS_WITH_HOSTNAME
;
2298 else if (!_cups_strcasecmp(token
, "WITH-ALL-RESOURCES") ||
2299 !_cups_strcasecmp(token
, "WITH-RESOURCE"))
2300 last_expect
->with_flags
= _CUPS_WITH_RESOURCE
;
2301 else if (!_cups_strcasecmp(token
, "WITH-ALL-SCHEMES") ||
2302 !_cups_strcasecmp(token
, "WITH-SCHEME"))
2303 last_expect
->with_flags
= _CUPS_WITH_SCHEME
;
2305 if (!_cups_strncasecmp(token
, "WITH-ALL-", 9))
2306 last_expect
->with_flags
|= _CUPS_WITH_ALL
;
2309 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
2311 print_fatal_error(outfile
, "Missing %s value on line %d.", token
, linenum
);
2319 * Expand any variables in the value and then save it.
2322 expand_variables(vars
, token
, temp
, sizeof(token
));
2324 tokenptr
= token
+ strlen(token
) - 1;
2326 if (token
[0] == '/' && tokenptr
> token
&& *tokenptr
== '/')
2329 * WITH-VALUE is a POSIX extended regular expression.
2332 last_expect
->with_value
= calloc(1, (size_t)(tokenptr
- token
));
2333 last_expect
->with_flags
|= _CUPS_WITH_REGEX
;
2335 if (last_expect
->with_value
)
2336 memcpy(last_expect
->with_value
, token
+ 1, (size_t)(tokenptr
- token
- 1));
2341 * WITH-VALUE is a literal value...
2344 char *ptr
; /* Pointer into value */
2346 for (ptr
= token
; *ptr
; ptr
++)
2348 if (*ptr
== '\\' && ptr
[1])
2351 * Remove \ from \foo...
2354 _cups_strcpy(ptr
, ptr
+ 1);
2358 last_expect
->with_value
= strdup(token
);
2359 last_expect
->with_flags
|= _CUPS_WITH_LITERAL
;
2364 print_fatal_error(outfile
, "%s without a preceding EXPECT on line %d.", token
,
2370 else if (!_cups_strcasecmp(token
, "DISPLAY"))
2373 * Display attributes...
2376 if (num_displayed
>= (int)(sizeof(displayed
) / sizeof(displayed
[0])))
2378 print_fatal_error(outfile
, "Too many DISPLAY's on line %d", linenum
);
2383 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2385 print_fatal_error(outfile
, "Missing DISPLAY name on line %d.", linenum
);
2390 displayed
[num_displayed
] = strdup(token
);
2395 print_fatal_error(outfile
, "Unexpected token %s seen on line %d.", token
,
2403 * Submit the IPP request...
2408 ippSetVersion(request
, version
/ 10, version
% 10);
2409 ippSetOperation(request
, op
);
2410 ippSetRequestId(request
, request_id
);
2412 if (Output
== _CUPS_OUTPUT_PLIST
)
2414 fputs("<dict>\n", outfile
);
2415 fputs("<key>Name</key>\n", outfile
);
2416 print_xml_string(outfile
, "string", name
);
2419 fputs("<key>FileId</key>\n", outfile
);
2420 print_xml_string(outfile
, "string", file_id
);
2424 fputs("<key>TestId</key>\n", outfile
);
2425 print_xml_string(outfile
, "string", test_id
);
2427 fputs("<key>Version</key>\n", outfile
);
2428 fprintf(outfile
, "<string>%d.%d</string>\n", version
/ 10, version
% 10);
2429 fputs("<key>Operation</key>\n", outfile
);
2430 print_xml_string(outfile
, "string", ippOpString(op
));
2431 fputs("<key>RequestId</key>\n", outfile
);
2432 fprintf(outfile
, "<integer>%d</integer>\n", request_id
);
2433 fputs("<key>RequestAttributes</key>\n", outfile
);
2434 fputs("<array>\n", outfile
);
2437 fputs("<dict>\n", outfile
);
2438 for (attrptr
= request
->attrs
,
2439 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
2441 attrptr
= attrptr
->next
)
2442 print_attr(outfile
, Output
, attrptr
, &group
);
2443 fputs("</dict>\n", outfile
);
2445 fputs("</array>\n", outfile
);
2448 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
2452 printf(" %s:\n", ippOpString(op
));
2454 for (attrptr
= request
->attrs
; attrptr
; attrptr
= attrptr
->next
)
2455 print_attr(stdout
, _CUPS_OUTPUT_TEST
, attrptr
, NULL
);
2458 printf(" %-68.68s [", name
);
2462 if ((skip_previous
&& !prev_pass
) || skip_test
)
2469 if (Output
== _CUPS_OUTPUT_PLIST
)
2471 fputs("<key>Successful</key>\n", outfile
);
2472 fputs("<true />\n", outfile
);
2473 fputs("<key>StatusCode</key>\n", outfile
);
2474 print_xml_string(outfile
, "string", "skip");
2475 fputs("<key>ResponseAttributes</key>\n", outfile
);
2476 fputs("<dict />\n", outfile
);
2479 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
2487 repeat_interval
= 1;
2494 status
= HTTP_STATUS_OK
;
2496 if (transfer
== _CUPS_TRANSFER_CHUNKED
||
2497 (transfer
== _CUPS_TRANSFER_AUTO
&& filename
[0]))
2500 * Send request using chunking - a 0 length means "chunk".
2508 * Send request using content length...
2511 length
= ippLength(request
);
2513 if (filename
[0] && (reqfile
= cupsFileOpen(filename
, "r")) != NULL
)
2516 * Read the file to get the uncompressed file size...
2519 while ((bytes
= cupsFileRead(reqfile
, buffer
, sizeof(buffer
))) > 0)
2520 length
+= (size_t)bytes
;
2522 cupsFileClose(reqfile
);
2527 * Send the request...
2534 if (status
!= HTTP_STATUS_ERROR
)
2536 while (!response
&& !Cancel
&& prev_pass
)
2538 status
= cupsSendRequest(http
, request
, resource
, length
);
2542 httpSetField(http
, HTTP_FIELD_CONTENT_ENCODING
, compression
);
2543 #endif /* HAVE_LIBZ */
2545 if (!Cancel
&& status
== HTTP_STATUS_CONTINUE
&&
2546 request
->state
== IPP_DATA
&& filename
[0])
2548 if ((reqfile
= cupsFileOpen(filename
, "r")) != NULL
)
2551 (bytes
= cupsFileRead(reqfile
, buffer
, sizeof(buffer
))) > 0)
2552 if ((status
= cupsWriteRequestData(http
, buffer
, (size_t)bytes
)) != HTTP_STATUS_CONTINUE
)
2555 cupsFileClose(reqfile
);
2559 snprintf(buffer
, sizeof(buffer
), "%s: %s", filename
,
2561 _cupsSetError(IPP_INTERNAL_ERROR
, buffer
, 0);
2563 status
= HTTP_STATUS_ERROR
;
2568 * Get the server's response...
2571 if (!Cancel
&& status
!= HTTP_STATUS_ERROR
)
2573 response
= cupsGetResponse(http
, resource
);
2574 status
= httpGetStatus(http
);
2577 if (!Cancel
&& status
== HTTP_STATUS_ERROR
&& http
->error
!= EINVAL
&&
2579 http
->error
!= WSAETIMEDOUT
)
2581 http
->error
!= ETIMEDOUT
)
2584 if (httpReconnect(http
))
2587 else if (status
== HTTP_STATUS_ERROR
|| status
== HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
)
2592 else if (status
!= HTTP_STATUS_OK
)
2596 if (status
== HTTP_STATUS_UNAUTHORIZED
)
2604 if (!Cancel
&& status
== HTTP_STATUS_ERROR
&& http
->error
!= EINVAL
&&
2606 http
->error
!= WSAETIMEDOUT
)
2608 http
->error
!= ETIMEDOUT
)
2611 if (httpReconnect(http
))
2614 else if (status
== HTTP_STATUS_ERROR
)
2617 httpReconnect(http
);
2621 else if (status
!= HTTP_STATUS_OK
)
2628 * Check results of request...
2631 cupsArrayClear(errors
);
2633 if (http
->version
!= HTTP_1_1
)
2634 add_stringf(errors
, "Bad HTTP version (%d.%d)", http
->version
/ 100,
2635 http
->version
% 100);
2640 * No response, log error...
2643 add_stringf(errors
, "IPP request failed with status %s (%s)",
2644 ippErrorString(cupsLastError()),
2645 cupsLastErrorString());
2650 * Collect common attribute values...
2653 if ((attrptr
= ippFindAttribute(response
, "job-id",
2654 IPP_TAG_INTEGER
)) != NULL
)
2656 snprintf(temp
, sizeof(temp
), "%d", attrptr
->values
[0].integer
);
2657 set_variable(outfile
, vars
, "job-id", temp
);
2660 if ((attrptr
= ippFindAttribute(response
, "job-uri",
2661 IPP_TAG_URI
)) != NULL
)
2662 set_variable(outfile
, vars
, "job-uri", attrptr
->values
[0].string
.text
);
2664 if ((attrptr
= ippFindAttribute(response
, "notify-subscription-id",
2665 IPP_TAG_INTEGER
)) != NULL
)
2667 snprintf(temp
, sizeof(temp
), "%d", attrptr
->values
[0].integer
);
2668 set_variable(outfile
, vars
, "notify-subscription-id", temp
);
2672 * Check response, validating groups and attributes and logging errors
2676 if (response
->state
!= IPP_DATA
)
2678 "Missing end-of-attributes-tag in response "
2679 "(RFC 2910 section 3.5.1)");
2682 (response
->request
.status
.version
[0] != (version
/ 10) ||
2683 response
->request
.status
.version
[1] != (version
% 10)))
2685 "Bad version %d.%d in response - expected %d.%d "
2686 "(RFC 2911 section 3.1.8).",
2687 response
->request
.status
.version
[0],
2688 response
->request
.status
.version
[1],
2689 version
/ 10, version
% 10);
2691 if (response
->request
.status
.request_id
!= request_id
)
2693 "Bad request ID %d in response - expected %d "
2694 "(RFC 2911 section 3.1.1)",
2695 response
->request
.status
.request_id
, request_id
);
2697 attrptr
= response
->attrs
;
2700 "Missing first attribute \"attributes-charset "
2701 "(charset)\" in group operation-attributes-tag "
2702 "(RFC 2911 section 3.1.4).");
2705 if (!attrptr
->name
||
2706 attrptr
->value_tag
!= IPP_TAG_CHARSET
||
2707 attrptr
->group_tag
!= IPP_TAG_OPERATION
||
2708 attrptr
->num_values
!= 1 ||
2709 strcmp(attrptr
->name
, "attributes-charset"))
2711 "Bad first attribute \"%s (%s%s)\" in group %s, "
2712 "expected \"attributes-charset (charset)\" in "
2713 "group operation-attributes-tag (RFC 2911 section "
2715 attrptr
->name
? attrptr
->name
: "(null)",
2716 attrptr
->num_values
> 1 ? "1setOf " : "",
2717 ippTagString(attrptr
->value_tag
),
2718 ippTagString(attrptr
->group_tag
));
2720 attrptr
= attrptr
->next
;
2723 "Missing second attribute \"attributes-natural-"
2724 "language (naturalLanguage)\" in group "
2725 "operation-attributes-tag (RFC 2911 section "
2727 else if (!attrptr
->name
||
2728 attrptr
->value_tag
!= IPP_TAG_LANGUAGE
||
2729 attrptr
->group_tag
!= IPP_TAG_OPERATION
||
2730 attrptr
->num_values
!= 1 ||
2731 strcmp(attrptr
->name
, "attributes-natural-language"))
2733 "Bad first attribute \"%s (%s%s)\" in group %s, "
2734 "expected \"attributes-natural-language "
2735 "(naturalLanguage)\" in group "
2736 "operation-attributes-tag (RFC 2911 section "
2738 attrptr
->name
? attrptr
->name
: "(null)",
2739 attrptr
->num_values
> 1 ? "1setOf " : "",
2740 ippTagString(attrptr
->value_tag
),
2741 ippTagString(attrptr
->group_tag
));
2744 if ((attrptr
= ippFindAttribute(response
, "status-message",
2745 IPP_TAG_ZERO
)) != NULL
)
2747 if (attrptr
->value_tag
!= IPP_TAG_TEXT
)
2749 "status-message (text(255)) has wrong value tag "
2750 "%s (RFC 2911 section 3.1.6.2).",
2751 ippTagString(attrptr
->value_tag
));
2752 if (attrptr
->group_tag
!= IPP_TAG_OPERATION
)
2754 "status-message (text(255)) has wrong group tag "
2755 "%s (RFC 2911 section 3.1.6.2).",
2756 ippTagString(attrptr
->group_tag
));
2757 if (attrptr
->num_values
!= 1)
2759 "status-message (text(255)) has %d values "
2760 "(RFC 2911 section 3.1.6.2).",
2761 attrptr
->num_values
);
2762 if (attrptr
->value_tag
== IPP_TAG_TEXT
&&
2763 strlen(attrptr
->values
[0].string
.text
) > 255)
2765 "status-message (text(255)) has bad length %d"
2766 " (RFC 2911 section 3.1.6.2).",
2767 (int)strlen(attrptr
->values
[0].string
.text
));
2770 if ((attrptr
= ippFindAttribute(response
, "detailed-status-message",
2771 IPP_TAG_ZERO
)) != NULL
)
2773 if (attrptr
->value_tag
!= IPP_TAG_TEXT
)
2775 "detailed-status-message (text(MAX)) has wrong "
2776 "value tag %s (RFC 2911 section 3.1.6.3).",
2777 ippTagString(attrptr
->value_tag
));
2778 if (attrptr
->group_tag
!= IPP_TAG_OPERATION
)
2780 "detailed-status-message (text(MAX)) has wrong "
2781 "group tag %s (RFC 2911 section 3.1.6.3).",
2782 ippTagString(attrptr
->group_tag
));
2783 if (attrptr
->num_values
!= 1)
2785 "detailed-status-message (text(MAX)) has %d values"
2786 " (RFC 2911 section 3.1.6.3).",
2787 attrptr
->num_values
);
2788 if (attrptr
->value_tag
== IPP_TAG_TEXT
&&
2789 strlen(attrptr
->values
[0].string
.text
) > 1023)
2791 "detailed-status-message (text(MAX)) has bad "
2792 "length %d (RFC 2911 section 3.1.6.3).",
2793 (int)strlen(attrptr
->values
[0].string
.text
));
2796 a
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
2798 for (attrptr
= response
->attrs
,
2799 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
2801 attrptr
= attrptr
->next
)
2803 if (attrptr
->group_tag
!= group
)
2805 int out_of_order
= 0; /* Are attribute groups out-of-order? */
2808 switch (attrptr
->group_tag
)
2813 case IPP_TAG_OPERATION
:
2817 case IPP_TAG_UNSUPPORTED_GROUP
:
2818 if (group
!= IPP_TAG_OPERATION
)
2823 case IPP_TAG_PRINTER
:
2824 if (group
!= IPP_TAG_OPERATION
&&
2825 group
!= IPP_TAG_UNSUPPORTED_GROUP
)
2829 case IPP_TAG_SUBSCRIPTION
:
2830 if (group
> attrptr
->group_tag
&&
2831 group
!= IPP_TAG_DOCUMENT
)
2836 if (group
> attrptr
->group_tag
)
2842 add_stringf(errors
, "Attribute groups out of order (%s < %s)",
2843 ippTagString(attrptr
->group_tag
),
2844 ippTagString(group
));
2846 if (attrptr
->group_tag
!= IPP_TAG_ZERO
)
2847 group
= attrptr
->group_tag
;
2850 validate_attr(outfile
, errors
, attrptr
);
2854 if (cupsArrayFind(a
, attrptr
->name
))
2855 add_stringf(errors
, "Duplicate \"%s\" attribute in %s group",
2856 attrptr
->name
, ippTagString(group
));
2858 cupsArrayAdd(a
, attrptr
->name
);
2865 * Now check the test-defined expected status-code and attribute
2869 for (i
= 0; i
< num_statuses
; i
++)
2871 if (statuses
[i
].if_defined
&&
2872 !get_variable(vars
, statuses
[i
].if_defined
))
2875 if (statuses
[i
].if_not_defined
&&
2876 get_variable(vars
, statuses
[i
].if_not_defined
))
2879 if (response
->request
.status
.status_code
== statuses
[i
].status
)
2881 if (statuses
[i
].repeat_match
&&
2882 repeat_count
< statuses
[i
].repeat_limit
)
2885 if (statuses
[i
].define_match
)
2886 set_variable(outfile
, vars
, statuses
[i
].define_match
, "1");
2892 if (statuses
[i
].repeat_no_match
&&
2893 repeat_count
< statuses
[i
].repeat_limit
)
2896 if (statuses
[i
].define_no_match
)
2898 set_variable(outfile
, vars
, statuses
[i
].define_no_match
, "1");
2904 if (i
== num_statuses
&& num_statuses
> 0)
2906 for (i
= 0; i
< num_statuses
; i
++)
2908 if (statuses
[i
].if_defined
&&
2909 !get_variable(vars
, statuses
[i
].if_defined
))
2912 if (statuses
[i
].if_not_defined
&&
2913 get_variable(vars
, statuses
[i
].if_not_defined
))
2916 if (!statuses
[i
].repeat_match
)
2917 add_stringf(errors
, "EXPECTED: STATUS %s (got %s)",
2918 ippErrorString(statuses
[i
].status
),
2919 ippErrorString(cupsLastError()));
2922 if ((attrptr
= ippFindAttribute(response
, "status-message",
2923 IPP_TAG_TEXT
)) != NULL
)
2924 add_stringf(errors
, "status-message=\"%s\"",
2925 attrptr
->values
[0].string
.text
);
2928 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
2930 if (expect
->if_defined
&& !get_variable(vars
, expect
->if_defined
))
2933 if (expect
->if_not_defined
&&
2934 get_variable(vars
, expect
->if_not_defined
))
2937 found
= ippFindAttribute(response
, expect
->name
, IPP_TAG_ZERO
);
2939 if ((found
&& expect
->not_expect
) ||
2940 (!found
&& !(expect
->not_expect
|| expect
->optional
)) ||
2941 (found
&& !expect_matches(expect
, found
->value_tag
)) ||
2942 (found
&& expect
->in_group
&&
2943 found
->group_tag
!= expect
->in_group
))
2945 if (expect
->define_no_match
)
2946 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
2947 else if (!expect
->define_match
&& !expect
->define_value
)
2949 if (found
&& expect
->not_expect
)
2950 add_stringf(errors
, "NOT EXPECTED: %s", expect
->name
);
2951 else if (!found
&& !(expect
->not_expect
|| expect
->optional
))
2952 add_stringf(errors
, "EXPECTED: %s", expect
->name
);
2955 if (!expect_matches(expect
, found
->value_tag
))
2956 add_stringf(errors
, "EXPECTED: %s OF-TYPE %s (got %s)",
2957 expect
->name
, expect
->of_type
,
2958 ippTagString(found
->value_tag
));
2960 if (expect
->in_group
&& found
->group_tag
!= expect
->in_group
)
2961 add_stringf(errors
, "EXPECTED: %s IN-GROUP %s (got %s).",
2962 expect
->name
, ippTagString(expect
->in_group
),
2963 ippTagString(found
->group_tag
));
2967 if (expect
->repeat_no_match
&&
2968 repeat_count
< expect
->repeat_limit
)
2975 ippAttributeString(found
, buffer
, sizeof(buffer
));
2978 !with_value(outfile
, NULL
, expect
->with_value
, expect
->with_flags
, found
,
2979 buffer
, sizeof(buffer
)))
2981 if (expect
->define_no_match
)
2982 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
2983 else if (!expect
->define_match
&& !expect
->define_value
&&
2984 !expect
->repeat_match
&& !expect
->repeat_no_match
)
2986 if (expect
->with_flags
& _CUPS_WITH_REGEX
)
2987 add_stringf(errors
, "EXPECTED: %s %s /%s/",
2989 (expect
->with_flags
& _CUPS_WITH_ALL
) ?
2990 "WITH-ALL-VALUES" : "WITH-VALUE",
2991 expect
->with_value
);
2993 add_stringf(errors
, "EXPECTED: %s %s \"%s\"",
2995 (expect
->with_flags
& _CUPS_WITH_ALL
) ?
2996 "WITH-ALL-VALUES" : "WITH-VALUE",
2997 expect
->with_value
);
2999 with_value(outfile
, errors
, expect
->with_value
, expect
->with_flags
, found
,
3000 buffer
, sizeof(buffer
));
3003 if (expect
->repeat_no_match
&&
3004 repeat_count
< expect
->repeat_limit
)
3010 if (found
&& expect
->count
> 0 &&
3011 found
->num_values
!= expect
->count
)
3013 if (expect
->define_no_match
)
3014 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3015 else if (!expect
->define_match
&& !expect
->define_value
)
3017 add_stringf(errors
, "EXPECTED: %s COUNT %d (got %d)", expect
->name
,
3018 expect
->count
, found
->num_values
);
3021 if (expect
->repeat_no_match
&&
3022 repeat_count
< expect
->repeat_limit
)
3028 if (found
&& expect
->same_count_as
)
3030 attrptr
= ippFindAttribute(response
, expect
->same_count_as
,
3033 if (!attrptr
|| attrptr
->num_values
!= found
->num_values
)
3035 if (expect
->define_no_match
)
3036 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3037 else if (!expect
->define_match
&& !expect
->define_value
)
3041 "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
3042 "(not returned)", expect
->name
,
3043 found
->num_values
, expect
->same_count_as
);
3044 else if (attrptr
->num_values
!= found
->num_values
)
3046 "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
3047 "(%d values)", expect
->name
, found
->num_values
,
3048 expect
->same_count_as
, attrptr
->num_values
);
3051 if (expect
->repeat_no_match
&&
3052 repeat_count
< expect
->repeat_limit
)
3059 if (found
&& expect
->define_match
)
3060 set_variable(outfile
, vars
, expect
->define_match
, "1");
3062 if (found
&& expect
->define_value
)
3063 set_variable(outfile
, vars
, expect
->define_value
, buffer
);
3065 if (found
&& expect
->repeat_match
&&
3066 repeat_count
< expect
->repeat_limit
)
3072 * If we are going to repeat this test, sleep 1 second so we don't flood
3073 * the printer with requests...
3078 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
3080 printf("%04d]\n", repeat_count
);
3084 sleep((unsigned)repeat_interval
);
3085 repeat_interval
= _cupsNextDelay(repeat_interval
, &repeat_prev
);
3087 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
3089 printf(" %-68.68s [", name
);
3094 while (repeat_test
);
3100 if (cupsArrayCount(errors
) > 0)
3101 prev_pass
= pass
= 0;
3108 if (Output
== _CUPS_OUTPUT_PLIST
)
3110 fputs("<key>Successful</key>\n", outfile
);
3111 fputs(prev_pass
? "<true />\n" : "<false />\n", outfile
);
3112 fputs("<key>StatusCode</key>\n", outfile
);
3113 print_xml_string(outfile
, "string", ippErrorString(cupsLastError()));
3114 fputs("<key>ResponseAttributes</key>\n", outfile
);
3115 fputs("<array>\n", outfile
);
3116 fputs("<dict>\n", outfile
);
3117 for (attrptr
= response
? response
->attrs
: NULL
,
3118 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
3120 attrptr
= attrptr
->next
)
3121 print_attr(outfile
, Output
, attrptr
, &group
);
3122 fputs("</dict>\n", outfile
);
3123 fputs("</array>\n", outfile
);
3126 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
3128 puts(prev_pass
? "PASS]" : "FAIL]");
3130 if (!prev_pass
|| (Verbosity
&& response
))
3132 printf(" RECEIVED: %lu bytes in response\n",
3133 (unsigned long)ippLength(response
));
3134 printf(" status-code = %s (%s)\n", ippErrorString(cupsLastError()),
3135 cupsLastErrorString());
3139 for (attrptr
= response
->attrs
;
3141 attrptr
= attrptr
->next
)
3142 print_attr(stdout
, _CUPS_OUTPUT_TEST
, attrptr
, NULL
);
3146 else if (!prev_pass
)
3147 fprintf(stderr
, "%s\n", cupsLastErrorString());
3149 if (prev_pass
&& Output
>= _CUPS_OUTPUT_LIST
&& !Verbosity
&&
3152 size_t width
; /* Length of value */
3154 for (i
= 0; i
< num_displayed
; i
++)
3156 widths
[i
] = strlen(displayed
[i
]);
3158 for (attrptr
= ippFindAttribute(response
, displayed
[i
], IPP_TAG_ZERO
);
3160 attrptr
= ippFindNextAttribute(response
, displayed
[i
],
3163 width
= ippAttributeString(attrptr
, NULL
, 0);
3164 if (width
> widths
[i
])
3169 if (Output
== _CUPS_OUTPUT_CSV
)
3170 print_csv(outfile
, NULL
, num_displayed
, displayed
, widths
);
3172 print_line(outfile
, NULL
, num_displayed
, displayed
, widths
);
3174 attrptr
= response
->attrs
;
3178 while (attrptr
&& attrptr
->group_tag
<= IPP_TAG_OPERATION
)
3179 attrptr
= attrptr
->next
;
3183 if (Output
== _CUPS_OUTPUT_CSV
)
3184 print_csv(outfile
, attrptr
, num_displayed
, displayed
, widths
);
3186 print_line(outfile
, attrptr
, num_displayed
, displayed
, widths
);
3188 while (attrptr
&& attrptr
->group_tag
> IPP_TAG_OPERATION
)
3189 attrptr
= attrptr
->next
;
3193 else if (!prev_pass
)
3195 if (Output
== _CUPS_OUTPUT_PLIST
)
3197 fputs("<key>Errors</key>\n", outfile
);
3198 fputs("<array>\n", outfile
);
3200 for (error
= (char *)cupsArrayFirst(errors
);
3202 error
= (char *)cupsArrayNext(errors
))
3203 print_xml_string(outfile
, "string", error
);
3205 fputs("</array>\n", outfile
);
3208 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= stdout
))
3210 for (error
= (char *)cupsArrayFirst(errors
);
3212 error
= (char *)cupsArrayNext(errors
))
3213 printf(" %s\n", error
);
3217 if (num_displayed
> 0 && !Verbosity
&& response
&& Output
== _CUPS_OUTPUT_TEST
)
3219 for (attrptr
= response
->attrs
;
3221 attrptr
= attrptr
->next
)
3225 for (i
= 0; i
< num_displayed
; i
++)
3227 if (!strcmp(displayed
[i
], attrptr
->name
))
3229 print_attr(outfile
, Output
, attrptr
, NULL
);
3239 if (Output
== _CUPS_OUTPUT_PLIST
)
3240 fputs("</dict>\n", outfile
);
3244 ippDelete(response
);
3247 for (i
= 0; i
< num_statuses
; i
++)
3249 if (statuses
[i
].if_defined
)
3250 free(statuses
[i
].if_defined
);
3251 if (statuses
[i
].if_not_defined
)
3252 free(statuses
[i
].if_not_defined
);
3253 if (statuses
[i
].define_match
)
3254 free(statuses
[i
].define_match
);
3255 if (statuses
[i
].define_no_match
)
3256 free(statuses
[i
].define_no_match
);
3260 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
3263 if (expect
->of_type
)
3264 free(expect
->of_type
);
3265 if (expect
->same_count_as
)
3266 free(expect
->same_count_as
);
3267 if (expect
->if_defined
)
3268 free(expect
->if_defined
);
3269 if (expect
->if_not_defined
)
3270 free(expect
->if_not_defined
);
3271 if (expect
->with_value
)
3272 free(expect
->with_value
);
3273 if (expect
->define_match
)
3274 free(expect
->define_match
);
3275 if (expect
->define_no_match
)
3276 free(expect
->define_no_match
);
3277 if (expect
->define_value
)
3278 free(expect
->define_value
);
3282 for (i
= 0; i
< num_displayed
; i
++)
3286 if (!ignore_errors
&& !prev_pass
)
3292 cupsArrayDelete(errors
);
3299 ippDelete(response
);
3301 for (i
= 0; i
< num_statuses
; i
++)
3303 if (statuses
[i
].if_defined
)
3304 free(statuses
[i
].if_defined
);
3305 if (statuses
[i
].if_not_defined
)
3306 free(statuses
[i
].if_not_defined
);
3307 if (statuses
[i
].define_match
)
3308 free(statuses
[i
].define_match
);
3309 if (statuses
[i
].define_no_match
)
3310 free(statuses
[i
].define_no_match
);
3313 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
3316 if (expect
->of_type
)
3317 free(expect
->of_type
);
3318 if (expect
->same_count_as
)
3319 free(expect
->same_count_as
);
3320 if (expect
->if_defined
)
3321 free(expect
->if_defined
);
3322 if (expect
->if_not_defined
)
3323 free(expect
->if_not_defined
);
3324 if (expect
->with_value
)
3325 free(expect
->with_value
);
3326 if (expect
->define_match
)
3327 free(expect
->define_match
);
3328 if (expect
->define_no_match
)
3329 free(expect
->define_no_match
);
3330 if (expect
->define_value
)
3331 free(expect
->define_value
);
3334 for (i
= 0; i
< num_displayed
; i
++)
3342 * 'expand_variables()' - Expand variables in a string.
3346 expand_variables(_cups_vars_t
*vars
, /* I - Variables */
3347 char *dst
, /* I - Destination string buffer */
3348 const char *src
, /* I - Source string */
3349 size_t dstsize
) /* I - Size of destination buffer */
3351 char *dstptr
, /* Pointer into destination */
3352 *dstend
, /* End of destination */
3353 temp
[256], /* Temporary string */
3354 *tempptr
; /* Pointer into temporary string */
3355 const char *value
; /* Value to substitute */
3359 dstend
= dst
+ dstsize
- 1;
3361 while (*src
&& dstptr
< dstend
)
3366 * Substitute a string/number...
3369 if (!strncmp(src
, "$$", 2))
3374 else if (!strncmp(src
, "$ENV[", 5))
3376 strlcpy(temp
, src
+ 5, sizeof(temp
));
3378 for (tempptr
= temp
; *tempptr
; tempptr
++)
3379 if (*tempptr
== ']')
3385 value
= getenv(temp
);
3386 src
+= tempptr
- temp
+ 5;
3390 strlcpy(temp
, src
+ 1, sizeof(temp
));
3392 for (tempptr
= temp
; *tempptr
; tempptr
++)
3393 if (!isalnum(*tempptr
& 255) && *tempptr
!= '-' && *tempptr
!= '_')
3399 if (!strcmp(temp
, "uri"))
3401 else if (!strcmp(temp
, "filename"))
3402 value
= vars
->filename
;
3403 else if (!strcmp(temp
, "scheme") || !strcmp(temp
, "method"))
3404 value
= vars
->scheme
;
3405 else if (!strcmp(temp
, "username"))
3406 value
= vars
->userpass
;
3407 else if (!strcmp(temp
, "hostname"))
3408 value
= vars
->hostname
;
3409 else if (!strcmp(temp
, "port"))
3411 snprintf(temp
, sizeof(temp
), "%d", vars
->port
);
3414 else if (!strcmp(temp
, "resource"))
3415 value
= vars
->resource
;
3416 else if (!strcmp(temp
, "user"))
3419 value
= get_variable(vars
, temp
);
3421 src
+= tempptr
- temp
+ 1;
3431 strlcpy(dstptr
, value
, (size_t)(dstend
- dstptr
+ 1));
3432 dstptr
+= strlen(dstptr
);
3444 * 'expect_matches()' - Return true if the tag matches the specification.
3447 static int /* O - 1 if matches, 0 otherwise */
3449 _cups_expect_t
*expect
, /* I - Expected attribute */
3450 ipp_tag_t value_tag
) /* I - Value tag for attribute */
3452 int match
; /* Match? */
3453 char *of_type
, /* Type name to match */
3454 *next
, /* Next name to match */
3455 sep
; /* Separator character */
3459 * If we don't expect a particular type, return immediately...
3462 if (!expect
->of_type
)
3466 * Parse the "of_type" value since the string can contain multiple attribute
3467 * types separated by "," or "|"...
3470 for (of_type
= expect
->of_type
, match
= 0; !match
&& *of_type
; of_type
= next
)
3473 * Find the next separator, and set it (temporarily) to nul if present.
3476 for (next
= of_type
; *next
&& *next
!= '|' && *next
!= ','; next
++);
3478 if ((sep
= *next
) != '\0')
3482 * Support some meta-types to make it easier to write the test file.
3485 if (!strcmp(of_type
, "text"))
3486 match
= value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_TEXT
;
3487 else if (!strcmp(of_type
, "name"))
3488 match
= value_tag
== IPP_TAG_NAMELANG
|| value_tag
== IPP_TAG_NAME
;
3489 else if (!strcmp(of_type
, "collection"))
3490 match
= value_tag
== IPP_TAG_BEGIN_COLLECTION
;
3492 match
= value_tag
== ippTagValue(of_type
);
3495 * Restore the separator if we have one...
3507 * 'get_collection()' - Get a collection value from the current test file.
3510 static ipp_t
* /* O - Collection value */
3511 get_collection(FILE *outfile
, /* I - Output file */
3512 _cups_vars_t
*vars
, /* I - Variables */
3513 FILE *fp
, /* I - File to read from */
3514 int *linenum
) /* IO - Line number */
3516 char token
[1024], /* Token from file */
3517 temp
[1024], /* Temporary string */
3518 attr
[128]; /* Attribute name */
3519 ipp_tag_t value
; /* Current value type */
3520 ipp_t
*col
= ippNew(); /* Collection value */
3521 ipp_attribute_t
*lastcol
= NULL
; /* Last collection attribute */
3524 while (get_token(fp
, token
, sizeof(token
), linenum
) != NULL
)
3526 if (!strcmp(token
, "}"))
3528 else if (!strcmp(token
, "{") && lastcol
)
3531 * Another collection value
3534 ipp_t
*subcol
= get_collection(outfile
, vars
, fp
, linenum
);
3535 /* Collection value */
3538 ippSetCollection(col
, &lastcol
, ippGetCount(lastcol
), subcol
);
3542 else if (!_cups_strcasecmp(token
, "MEMBER"))
3550 if (!get_token(fp
, token
, sizeof(token
), linenum
))
3552 print_fatal_error(outfile
, "Missing MEMBER value tag on line %d.", *linenum
);
3556 if ((value
= ippTagValue(token
)) == IPP_TAG_ZERO
)
3558 print_fatal_error(outfile
, "Bad MEMBER value tag \"%s\" on line %d.", token
,
3563 if (!get_token(fp
, attr
, sizeof(attr
), linenum
))
3565 print_fatal_error(outfile
, "Missing MEMBER name on line %d.", *linenum
);
3569 if (!get_token(fp
, temp
, sizeof(temp
), linenum
))
3571 print_fatal_error(outfile
, "Missing MEMBER value on line %d.", *linenum
);
3575 expand_variables(vars
, token
, temp
, sizeof(token
));
3579 case IPP_TAG_BOOLEAN
:
3580 if (!_cups_strcasecmp(token
, "true"))
3581 ippAddBoolean(col
, IPP_TAG_ZERO
, attr
, 1);
3583 ippAddBoolean(col
, IPP_TAG_ZERO
, attr
, (char)atoi(token
));
3586 case IPP_TAG_INTEGER
:
3588 ippAddInteger(col
, IPP_TAG_ZERO
, value
, attr
, atoi(token
));
3591 case IPP_TAG_RESOLUTION
:
3593 int xres
, /* X resolution */
3594 yres
; /* Y resolution */
3595 char units
[6]; /* Units */
3597 if (sscanf(token
, "%dx%d%5s", &xres
, &yres
, units
) != 3 ||
3598 (_cups_strcasecmp(units
, "dpi") &&
3599 _cups_strcasecmp(units
, "dpc") &&
3600 _cups_strcasecmp(units
, "dpcm") &&
3601 _cups_strcasecmp(units
, "other")))
3603 print_fatal_error(outfile
, "Bad resolution value \"%s\" on line %d.",
3608 if (!_cups_strcasecmp(units
, "dpi"))
3609 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, IPP_RES_PER_INCH
, xres
, yres
);
3610 else if (!_cups_strcasecmp(units
, "dpc") ||
3611 !_cups_strcasecmp(units
, "dpcm"))
3612 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, IPP_RES_PER_CM
, xres
, yres
);
3614 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, (ipp_res_t
)0, xres
, yres
);
3618 case IPP_TAG_RANGE
:
3620 int lowers
[4], /* Lower value */
3621 uppers
[4], /* Upper values */
3622 num_vals
; /* Number of values */
3625 num_vals
= sscanf(token
, "%d-%d,%d-%d,%d-%d,%d-%d",
3626 lowers
+ 0, uppers
+ 0,
3627 lowers
+ 1, uppers
+ 1,
3628 lowers
+ 2, uppers
+ 2,
3629 lowers
+ 3, uppers
+ 3);
3631 if ((num_vals
& 1) || num_vals
== 0)
3633 print_fatal_error(outfile
, "Bad rangeOfInteger value \"%s\" on line %d.",
3638 ippAddRanges(col
, IPP_TAG_ZERO
, attr
, num_vals
/ 2, lowers
,
3643 case IPP_TAG_BEGIN_COLLECTION
:
3644 if (!strcmp(token
, "{"))
3646 ipp_t
*subcol
= get_collection(outfile
, vars
, fp
, linenum
);
3647 /* Collection value */
3651 lastcol
= ippAddCollection(col
, IPP_TAG_ZERO
, attr
, subcol
);
3659 print_fatal_error(outfile
, "Bad collection value on line %d.", *linenum
);
3663 case IPP_TAG_STRING
:
3664 ippAddOctetString(col
, IPP_TAG_ZERO
, attr
, token
, (int)strlen(token
));
3668 if (!strchr(token
, ','))
3669 ippAddString(col
, IPP_TAG_ZERO
, value
, attr
, NULL
, token
);
3673 * Multiple string values...
3676 int num_values
; /* Number of values */
3677 char *values
[100], /* Values */
3678 *ptr
; /* Pointer to next value */
3684 for (ptr
= strchr(token
, ','); ptr
; ptr
= strchr(ptr
, ','))
3687 values
[num_values
] = ptr
;
3691 ippAddStrings(col
, IPP_TAG_ZERO
, value
, attr
, num_values
,
3692 NULL
, (const char **)values
);
3702 * If we get here there was a parse error; free memory and return.
3714 * 'get_filename()' - Get a filename based on the current test file.
3717 static char * /* O - Filename */
3718 get_filename(const char *testfile
, /* I - Current test file */
3719 char *dst
, /* I - Destination filename */
3720 const char *src
, /* I - Source filename */
3721 size_t dstsize
) /* I - Size of destination buffer */
3723 char *dstptr
; /* Pointer into destination */
3724 _cups_globals_t
*cg
= _cupsGlobals();
3728 if (*src
== '<' && src
[strlen(src
) - 1] == '>')
3731 * Map <filename> to CUPS_DATADIR/ipptool/filename...
3734 snprintf(dst
, dstsize
, "%s/ipptool/%s", cg
->cups_datadir
, src
+ 1);
3735 dstptr
= dst
+ strlen(dst
) - 1;
3739 else if (*src
== '/' || !strchr(testfile
, '/')
3741 || (isalpha(*src
& 255) && src
[1] == ':')
3746 * Use the path as-is...
3749 strlcpy(dst
, src
, dstsize
);
3754 * Make path relative to testfile...
3757 strlcpy(dst
, testfile
, dstsize
);
3758 if ((dstptr
= strrchr(dst
, '/')) != NULL
)
3761 dstptr
= dst
; /* Should never happen */
3763 strlcpy(dstptr
, src
, dstsize
- (size_t)(dstptr
- dst
));
3771 * 'get_string()' - Get a pointer to a string value or the portion of interest.
3774 static char * /* O - Pointer to string */
3775 get_string(ipp_attribute_t
*attr
, /* I - IPP attribute */
3776 int element
, /* I - Element to fetch */
3777 int flags
, /* I - Value ("with") flags */
3778 char *buffer
, /* I - Temporary buffer */
3779 size_t bufsize
) /* I - Size of temporary buffer */
3781 char *ptr
, /* Value */
3782 scheme
[256], /* URI scheme */
3783 userpass
[256], /* Username/password */
3784 hostname
[256], /* Hostname */
3785 resource
[1024]; /* Resource */
3786 int port
; /* Port number */
3789 ptr
= attr
->values
[element
].string
.text
;
3791 if (flags
& _CUPS_WITH_HOSTNAME
)
3793 if (httpSeparateURI(HTTP_URI_CODING_ALL
, ptr
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), buffer
, (int)bufsize
, &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
3798 else if (flags
& _CUPS_WITH_RESOURCE
)
3800 if (httpSeparateURI(HTTP_URI_CODING_ALL
, ptr
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, buffer
, (int)bufsize
) < HTTP_URI_STATUS_OK
)
3805 else if (flags
& _CUPS_WITH_SCHEME
)
3807 if (httpSeparateURI(HTTP_URI_CODING_ALL
, ptr
, buffer
, (int)bufsize
, userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
3818 * 'get_token()' - Get a token from a file.
3821 static char * /* O - Token from file or NULL on EOF */
3822 get_token(FILE *fp
, /* I - File to read from */
3823 char *buf
, /* I - Buffer to read into */
3824 int buflen
, /* I - Length of buffer */
3825 int *linenum
) /* IO - Current line number */
3827 int ch
, /* Character from file */
3828 quote
; /* Quoting character */
3829 char *bufptr
, /* Pointer into buffer */
3830 *bufend
; /* End of buffer */
3836 * Skip whitespace...
3839 while (isspace(ch
= getc(fp
)))
3851 else if (ch
== '\'' || ch
== '\"')
3854 * Quoted text or regular expression...
3859 bufend
= buf
+ buflen
- 1;
3861 while ((ch
= getc(fp
)) != EOF
)
3866 * Escape next character...
3869 if (bufptr
< bufend
)
3870 *bufptr
++ = (char)ch
;
3872 if ((ch
= getc(fp
)) != EOF
&& bufptr
< bufend
)
3873 *bufptr
++ = (char)ch
;
3875 else if (ch
== quote
)
3877 else if (bufptr
< bufend
)
3878 *bufptr
++ = (char)ch
;
3891 while ((ch
= getc(fp
)) != EOF
)
3897 else if (ch
== '{' || ch
== '}' || ch
== ',')
3907 * Whitespace delimited text...
3913 bufend
= buf
+ buflen
- 1;
3915 while ((ch
= getc(fp
)) != EOF
)
3916 if (isspace(ch
) || ch
== '#')
3918 else if (bufptr
< bufend
)
3919 *bufptr
++ = (char)ch
;
3923 else if (ch
== '\n')
3935 * 'get_variable()' - Get the value of a variable.
3938 static char * /* O - Value or NULL */
3939 get_variable(_cups_vars_t
*vars
, /* I - Variables */
3940 const char *name
) /* I - Variable name */
3942 _cups_var_t key
, /* Search key */
3943 *match
; /* Matching variable, if any */
3946 key
.name
= (char *)name
;
3947 match
= cupsArrayFind(vars
->vars
, &key
);
3949 return (match
? match
->value
: NULL
);
3954 * 'iso_date()' - Return an ISO 8601 date/time string for the given IPP dateTime
3958 static char * /* O - ISO 8601 date/time string */
3959 iso_date(ipp_uchar_t
*date
) /* I - IPP (RFC 1903) date/time value */
3961 time_t utctime
; /* UTC time since 1970 */
3962 struct tm
*utcdate
; /* UTC date/time */
3963 static char buffer
[255]; /* String buffer */
3966 utctime
= ippDateToTime(date
);
3967 utcdate
= gmtime(&utctime
);
3969 snprintf(buffer
, sizeof(buffer
), "%04d-%02d-%02dT%02d:%02d:%02dZ",
3970 utcdate
->tm_year
+ 1900, utcdate
->tm_mon
+ 1, utcdate
->tm_mday
,
3971 utcdate
->tm_hour
, utcdate
->tm_min
, utcdate
->tm_sec
);
3978 * 'password_cb()' - Password callback for authenticated tests.
3981 static const char * /* O - Password */
3982 password_cb(const char *prompt
) /* I - Prompt (unused) */
3986 if (PasswordTries
< 3)
3990 cupsSetUser(Username
);
4000 * 'pause_message()' - Display the message and pause until the user presses a key.
4004 pause_message(const char *message
) /* I - Message */
4007 HANDLE tty
; /* Console handle */
4008 DWORD mode
; /* Console mode */
4009 char key
; /* Key press */
4010 DWORD bytes
; /* Bytes read for key press */
4014 * Disable input echo and set raw input...
4017 if ((tty
= GetStdHandle(STD_INPUT_HANDLE
)) == INVALID_HANDLE_VALUE
)
4020 if (!GetConsoleMode(tty
, &mode
))
4023 if (!SetConsoleMode(tty
, 0))
4027 int tty
; /* /dev/tty - never read from stdin */
4028 struct termios original
, /* Original input mode */
4029 noecho
; /* No echo input mode */
4030 char key
; /* Current key press */
4034 * Disable input echo and set raw input...
4037 if ((tty
= open("/dev/tty", O_RDONLY
)) < 0)
4040 if (tcgetattr(tty
, &original
))
4047 noecho
.c_lflag
&= (tcflag_t
)~(ICANON
| ECHO
| ECHOE
| ISIG
);
4049 if (tcsetattr(tty
, TCSAFLUSH
, &noecho
))
4057 * Display the prompt...
4060 printf("%s\n---- PRESS ANY KEY ----", message
);
4068 ReadFile(tty
, &key
, 1, &bytes
, NULL
);
4074 SetConsoleMode(tty
, mode
);
4087 tcsetattr(tty
, TCSAFLUSH
, &original
);
4092 * Erase the "press any key" prompt...
4095 fputs("\r \r", stdout
);
4101 * 'print_attr()' - Print an attribute on the screen.
4105 print_attr(FILE *outfile
, /* I - Output file */
4106 int format
, /* I - Output format */
4107 ipp_attribute_t
*attr
, /* I - Attribute to print */
4108 ipp_tag_t
*group
) /* IO - Current group */
4110 int i
; /* Looping var */
4111 ipp_attribute_t
*colattr
; /* Collection attribute */
4114 if (format
== _CUPS_OUTPUT_PLIST
)
4116 if (!attr
->name
|| (group
&& *group
!= attr
->group_tag
))
4118 if (attr
->group_tag
!= IPP_TAG_ZERO
)
4120 fputs("</dict>\n", outfile
);
4121 fputs("<dict>\n", outfile
);
4125 *group
= attr
->group_tag
;
4131 print_xml_string(outfile
, "key", attr
->name
);
4132 if (attr
->num_values
> 1)
4133 fputs("<array>\n", outfile
);
4135 switch (attr
->value_tag
)
4137 case IPP_TAG_INTEGER
:
4139 for (i
= 0; i
< attr
->num_values
; i
++)
4140 fprintf(outfile
, "<integer>%d</integer>\n", attr
->values
[i
].integer
);
4143 case IPP_TAG_BOOLEAN
:
4144 for (i
= 0; i
< attr
->num_values
; i
++)
4145 fputs(attr
->values
[i
].boolean
? "<true />\n" : "<false />\n", outfile
);
4148 case IPP_TAG_RANGE
:
4149 for (i
= 0; i
< attr
->num_values
; i
++)
4150 fprintf(outfile
, "<dict><key>lower</key><integer>%d</integer>"
4151 "<key>upper</key><integer>%d</integer></dict>\n",
4152 attr
->values
[i
].range
.lower
, attr
->values
[i
].range
.upper
);
4155 case IPP_TAG_RESOLUTION
:
4156 for (i
= 0; i
< attr
->num_values
; i
++)
4157 fprintf(outfile
, "<dict><key>xres</key><integer>%d</integer>"
4158 "<key>yres</key><integer>%d</integer>"
4159 "<key>units</key><string>%s</string></dict>\n",
4160 attr
->values
[i
].resolution
.xres
,
4161 attr
->values
[i
].resolution
.yres
,
4162 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4167 for (i
= 0; i
< attr
->num_values
; i
++)
4168 fprintf(outfile
, "<date>%s</date>\n", iso_date(attr
->values
[i
].date
));
4171 case IPP_TAG_STRING
:
4172 for (i
= 0; i
< attr
->num_values
; i
++)
4174 char buffer
[IPP_MAX_LENGTH
* 5 / 4 + 1];
4177 fprintf(outfile
, "<data>%s</data>\n",
4178 httpEncode64_2(buffer
, sizeof(buffer
),
4179 attr
->values
[i
].unknown
.data
,
4180 attr
->values
[i
].unknown
.length
));
4186 case IPP_TAG_KEYWORD
:
4187 case IPP_TAG_CHARSET
:
4189 case IPP_TAG_MIMETYPE
:
4190 case IPP_TAG_LANGUAGE
:
4191 for (i
= 0; i
< attr
->num_values
; i
++)
4192 print_xml_string(outfile
, "string", attr
->values
[i
].string
.text
);
4195 case IPP_TAG_TEXTLANG
:
4196 case IPP_TAG_NAMELANG
:
4197 for (i
= 0; i
< attr
->num_values
; i
++)
4199 fputs("<dict><key>language</key><string>", outfile
);
4200 print_xml_string(outfile
, NULL
, attr
->values
[i
].string
.language
);
4201 fputs("</string><key>string</key><string>", outfile
);
4202 print_xml_string(outfile
, NULL
, attr
->values
[i
].string
.text
);
4203 fputs("</string></dict>\n", outfile
);
4207 case IPP_TAG_BEGIN_COLLECTION
:
4208 for (i
= 0; i
< attr
->num_values
; i
++)
4210 fputs("<dict>\n", outfile
);
4211 for (colattr
= attr
->values
[i
].collection
->attrs
;
4213 colattr
= colattr
->next
)
4214 print_attr(outfile
, format
, colattr
, NULL
);
4215 fputs("</dict>\n", outfile
);
4220 fprintf(outfile
, "<string><<%s>></string>\n", ippTagString(attr
->value_tag
));
4224 if (attr
->num_values
> 1)
4225 fputs("</array>\n", outfile
);
4229 char buffer
[8192]; /* Value buffer */
4231 if (format
== _CUPS_OUTPUT_TEST
)
4235 fputs(" -- separator --\n", outfile
);
4239 fprintf(outfile
, " %s (%s%s) = ", attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
));
4242 ippAttributeString(attr
, buffer
, sizeof(buffer
));
4243 fprintf(outfile
, "%s\n", buffer
);
4249 * 'print_csv()' - Print a line of CSV text.
4254 FILE *outfile
, /* I - Output file */
4255 ipp_attribute_t
*attr
, /* I - First attribute for line */
4256 int num_displayed
, /* I - Number of attributes to display */
4257 char **displayed
, /* I - Attributes to display */
4258 size_t *widths
) /* I - Column widths */
4260 int i
; /* Looping var */
4261 size_t maxlength
; /* Max length of all columns */
4262 char *buffer
, /* String buffer */
4263 *bufptr
; /* Pointer into buffer */
4264 ipp_attribute_t
*current
; /* Current attribute */
4268 * Get the maximum string length we have to show and allocate...
4271 for (i
= 1, maxlength
= widths
[0]; i
< num_displayed
; i
++)
4272 if (widths
[i
] > maxlength
)
4273 maxlength
= widths
[i
];
4277 if ((buffer
= malloc(maxlength
)) == NULL
)
4281 * Loop through the attributes to display...
4286 for (i
= 0; i
< num_displayed
; i
++)
4289 fputc(',', outfile
);
4293 for (current
= attr
; current
; current
= current
->next
)
4297 else if (!strcmp(current
->name
, displayed
[i
]))
4299 ippAttributeString(current
, buffer
, maxlength
);
4304 if (strchr(buffer
, ',') != NULL
|| strchr(buffer
, '\"') != NULL
||
4305 strchr(buffer
, '\\') != NULL
)
4307 putc('\"', outfile
);
4308 for (bufptr
= buffer
; *bufptr
; bufptr
++)
4310 if (*bufptr
== '\\' || *bufptr
== '\"')
4311 putc('\\', outfile
);
4312 putc(*bufptr
, outfile
);
4314 putc('\"', outfile
);
4317 fputs(buffer
, outfile
);
4319 putc('\n', outfile
);
4323 for (i
= 0; i
< num_displayed
; i
++)
4328 fputs(displayed
[i
], outfile
);
4330 putc('\n', outfile
);
4338 * 'print_fatal_error()' - Print a fatal error message.
4342 print_fatal_error(FILE *outfile
, /* I - Output file */
4343 const char *s
, /* I - Printf-style format string */
4344 ...) /* I - Additional arguments as needed */
4346 char buffer
[10240]; /* Format buffer */
4347 va_list ap
; /* Pointer to arguments */
4351 * Format the error message...
4355 vsnprintf(buffer
, sizeof(buffer
), s
, ap
);
4362 if (Output
== _CUPS_OUTPUT_PLIST
)
4364 print_xml_header(outfile
);
4365 print_xml_trailer(outfile
, 0, buffer
);
4368 _cupsLangPrintf(stderr
, "ipptool: %s", buffer
);
4373 * 'print_line()' - Print a line of formatted or CSV text.
4378 FILE *outfile
, /* I - Output file */
4379 ipp_attribute_t
*attr
, /* I - First attribute for line */
4380 int num_displayed
, /* I - Number of attributes to display */
4381 char **displayed
, /* I - Attributes to display */
4382 size_t *widths
) /* I - Column widths */
4384 int i
; /* Looping var */
4385 size_t maxlength
; /* Max length of all columns */
4386 char *buffer
; /* String buffer */
4387 ipp_attribute_t
*current
; /* Current attribute */
4391 * Get the maximum string length we have to show and allocate...
4394 for (i
= 1, maxlength
= widths
[0]; i
< num_displayed
; i
++)
4395 if (widths
[i
] > maxlength
)
4396 maxlength
= widths
[i
];
4400 if ((buffer
= malloc(maxlength
)) == NULL
)
4404 * Loop through the attributes to display...
4409 for (i
= 0; i
< num_displayed
; i
++)
4416 for (current
= attr
; current
; current
= current
->next
)
4420 else if (!strcmp(current
->name
, displayed
[i
]))
4422 ippAttributeString(current
, buffer
, maxlength
);
4427 fprintf(outfile
, "%*s", (int)-widths
[i
], buffer
);
4429 putc('\n', outfile
);
4433 for (i
= 0; i
< num_displayed
; i
++)
4438 fprintf(outfile
, "%*s", (int)-widths
[i
], displayed
[i
]);
4440 putc('\n', outfile
);
4442 for (i
= 0; i
< num_displayed
; i
++)
4447 memset(buffer
, '-', widths
[i
]);
4448 buffer
[widths
[i
]] = '\0';
4449 fputs(buffer
, outfile
);
4451 putc('\n', outfile
);
4459 * 'print_xml_header()' - Print a standard XML plist header.
4463 print_xml_header(FILE *outfile
) /* I - Output file */
4467 fputs("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n", outfile
);
4468 fputs("<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
4469 "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n", outfile
);
4470 fputs("<plist version=\"1.0\">\n", outfile
);
4471 fputs("<dict>\n", outfile
);
4472 fputs("<key>ipptoolVersion</key>\n", outfile
);
4473 fputs("<string>" CUPS_SVERSION
"</string>\n", outfile
);
4474 fputs("<key>Transfer</key>\n", outfile
);
4475 fprintf(outfile
, "<string>%s</string>\n",
4476 Transfer
== _CUPS_TRANSFER_AUTO
? "auto" :
4477 Transfer
== _CUPS_TRANSFER_CHUNKED
? "chunked" : "length");
4478 fputs("<key>Tests</key>\n", outfile
);
4479 fputs("<array>\n", outfile
);
4487 * 'print_xml_string()' - Print an XML string with escaping.
4491 print_xml_string(FILE *outfile
, /* I - Output file */
4492 const char *element
, /* I - Element name or NULL */
4493 const char *s
) /* I - String to print */
4496 fprintf(outfile
, "<%s>", element
);
4501 fputs("&", outfile
);
4503 fputs("<", outfile
);
4505 fputs(">", outfile
);
4506 else if ((*s
& 0xe0) == 0xc0)
4509 * Validate UTF-8 two-byte sequence...
4512 if ((s
[1] & 0xc0) != 0x80)
4519 putc(*s
++, outfile
);
4523 else if ((*s
& 0xf0) == 0xe0)
4526 * Validate UTF-8 three-byte sequence...
4529 if ((s
[1] & 0xc0) != 0x80 || (s
[2] & 0xc0) != 0x80)
4536 putc(*s
++, outfile
);
4537 putc(*s
++, outfile
);
4541 else if ((*s
& 0xf8) == 0xf0)
4544 * Validate UTF-8 four-byte sequence...
4547 if ((s
[1] & 0xc0) != 0x80 || (s
[2] & 0xc0) != 0x80 ||
4548 (s
[3] & 0xc0) != 0x80)
4555 putc(*s
++, outfile
);
4556 putc(*s
++, outfile
);
4557 putc(*s
++, outfile
);
4561 else if ((*s
& 0x80) || (*s
< ' ' && !isspace(*s
& 255)))
4564 * Invalid control character...
4576 fprintf(outfile
, "</%s>\n", element
);
4581 * 'print_xml_trailer()' - Print the XML trailer with success/fail value.
4585 print_xml_trailer(FILE *outfile
, /* I - Output file */
4586 int success
, /* I - 1 on success, 0 on failure */
4587 const char *message
) /* I - Error message or NULL */
4591 fputs("</array>\n", outfile
);
4592 fputs("<key>Successful</key>\n", outfile
);
4593 fputs(success
? "<true />\n" : "<false />\n", outfile
);
4596 fputs("<key>ErrorMessage</key>\n", outfile
);
4597 print_xml_string(outfile
, "string", message
);
4599 fputs("</dict>\n", outfile
);
4600 fputs("</plist>\n", outfile
);
4608 * 'set_variable()' - Set a variable value.
4612 set_variable(FILE *outfile
, /* I - Output file */
4613 _cups_vars_t
*vars
, /* I - Variables */
4614 const char *name
, /* I - Variable name */
4615 const char *value
) /* I - Value string */
4617 _cups_var_t key
, /* Search key */
4618 *var
; /* New variable */
4621 if (!_cups_strcasecmp(name
, "filename"))
4624 free(vars
->filename
);
4626 vars
->filename
= strdup(value
);
4630 key
.name
= (char *)name
;
4631 if ((var
= cupsArrayFind(vars
->vars
, &key
)) != NULL
)
4634 var
->value
= strdup(value
);
4636 else if ((var
= malloc(sizeof(_cups_var_t
))) == NULL
)
4638 print_fatal_error(outfile
, "Unable to allocate memory for variable \"%s\".", name
);
4643 var
->name
= strdup(name
);
4644 var
->value
= strdup(value
);
4646 cupsArrayAdd(vars
->vars
, var
);
4653 * 'sigterm_handler()' - Handle SIGINT and SIGTERM.
4657 sigterm_handler(int sig
) /* I - Signal number (unused) */
4663 signal(SIGINT
, SIG_DFL
);
4664 signal(SIGTERM
, SIG_DFL
);
4670 * 'timeout_cb()' - Handle HTTP timeouts.
4673 static int /* O - 1 to continue, 0 to cancel */
4674 timeout_cb(http_t
*http
, /* I - Connection to server */
4675 void *user_data
) /* I - User data (unused) */
4677 int buffered
= 0; /* Bytes buffered but not yet sent */
4683 * If the socket still have data waiting to be sent to the printer (as can
4684 * happen if the printer runs out of paper), continue to wait until the output
4685 * buffer is empty...
4688 #ifdef SO_NWRITE /* OS X and some versions of Linux */
4689 socklen_t len
= sizeof(buffered
); /* Size of return value */
4691 if (getsockopt(httpGetFd(http
), SOL_SOCKET
, SO_NWRITE
, &buffered
, &len
))
4694 #elif defined(SIOCOUTQ) /* Others except Windows */
4695 if (ioctl(httpGetFd(http
), SIOCOUTQ
, &buffered
))
4698 #else /* Windows (not possible) */
4700 #endif /* SO_NWRITE */
4702 return (buffered
> 0);
4707 * 'usage()' - Show program usage.
4713 _cupsLangPuts(stderr
, _("Usage: ipptool [options] URI filename [ ... "
4715 _cupsLangPuts(stderr
, _("Options:"));
4716 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
4717 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
4718 _cupsLangPuts(stderr
, _(" -C Send requests using "
4719 "chunking (default)."));
4720 _cupsLangPuts(stdout
, _(" -E Test with HTTP Upgrade to "
4722 _cupsLangPuts(stderr
, _(" -I Ignore errors."));
4723 _cupsLangPuts(stderr
, _(" -L Send requests using "
4724 "content-length."));
4725 _cupsLangPuts(stderr
, _(" -S Test with SSL "
4727 _cupsLangPuts(stderr
, _(" -T seconds Set the receive/send "
4728 "timeout in seconds."));
4729 _cupsLangPuts(stderr
, _(" -V version Set default IPP "
4731 _cupsLangPuts(stderr
, _(" -X Produce XML plist instead "
4733 _cupsLangPuts(stderr
, _(" -d name=value Set named variable to "
4735 _cupsLangPuts(stderr
, _(" -f filename Set default request "
4737 _cupsLangPuts(stderr
, _(" -i seconds Repeat the last file with "
4738 "the given time interval."));
4739 _cupsLangPuts(stderr
, _(" -n count Repeat the last file the "
4740 "given number of times."));
4741 _cupsLangPuts(stderr
, _(" -q Run silently."));
4742 _cupsLangPuts(stderr
, _(" -t Produce a test report."));
4743 _cupsLangPuts(stderr
, _(" -v Be verbose."));
4750 * 'validate_attr()' - Determine whether an attribute is valid.
4753 static int /* O - 1 if valid, 0 otherwise */
4754 validate_attr(FILE *outfile
, /* I - Output file */
4755 cups_array_t
*errors
, /* I - Errors array */
4756 ipp_attribute_t
*attr
) /* I - Attribute to validate */
4758 int i
; /* Looping var */
4759 char scheme
[64], /* Scheme from URI */
4760 userpass
[256], /* Username/password from URI */
4761 hostname
[256], /* Hostname from URI */
4762 resource
[1024]; /* Resource from URI */
4763 int port
, /* Port number from URI */
4764 uri_status
, /* URI separation status */
4765 valid
= 1; /* Is the attribute valid? */
4766 const char *ptr
; /* Pointer into string */
4767 ipp_attribute_t
*colattr
; /* Collection attribute */
4768 regex_t re
; /* Regular expression */
4769 ipp_uchar_t
*date
; /* Current date value */
4780 * Validate the attribute name.
4783 for (ptr
= attr
->name
; *ptr
; ptr
++)
4784 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
4787 if (*ptr
|| ptr
== attr
->name
)
4792 "\"%s\": Bad attribute name - invalid character "
4793 "(RFC 2911 section 4.1.3).", attr
->name
);
4796 if ((ptr
- attr
->name
) > 255)
4801 "\"%s\": Bad attribute name - bad length "
4802 "(RFC 2911 section 4.1.3).", attr
->name
);
4805 switch (attr
->value_tag
)
4807 case IPP_TAG_INTEGER
:
4810 case IPP_TAG_BOOLEAN
:
4811 for (i
= 0; i
< attr
->num_values
; i
++)
4813 if (attr
->values
[i
].boolean
!= 0 &&
4814 attr
->values
[i
].boolean
!= 1)
4819 "\"%s\": Bad boolen value %d "
4820 "(RFC 2911 section 4.1.11).", attr
->name
,
4821 attr
->values
[i
].boolean
);
4827 for (i
= 0; i
< attr
->num_values
; i
++)
4829 if (attr
->values
[i
].integer
< 1)
4834 "\"%s\": Bad enum value %d - out of range "
4835 "(RFC 2911 section 4.1.4).", attr
->name
,
4836 attr
->values
[i
].integer
);
4841 case IPP_TAG_STRING
:
4842 for (i
= 0; i
< attr
->num_values
; i
++)
4844 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
4849 "\"%s\": Bad octetString value - bad length %d "
4850 "(RFC 2911 section 4.1.10).", attr
->name
,
4851 attr
->values
[i
].unknown
.length
);
4857 for (i
= 0; i
< attr
->num_values
; i
++)
4859 date
= attr
->values
[i
].date
;
4861 if (date
[2] < 1 || date
[2] > 12)
4866 "\"%s\": Bad dateTime month %u "
4867 "(RFC 2911 section 4.1.14).", attr
->name
, date
[2]);
4870 if (date
[3] < 1 || date
[3] > 31)
4875 "\"%s\": Bad dateTime day %u "
4876 "(RFC 2911 section 4.1.14).", attr
->name
, date
[3]);
4884 "\"%s\": Bad dateTime hours %u "
4885 "(RFC 2911 section 4.1.14).", attr
->name
, date
[4]);
4893 "\"%s\": Bad dateTime minutes %u "
4894 "(RFC 2911 section 4.1.14).", attr
->name
, date
[5]);
4902 "\"%s\": Bad dateTime seconds %u "
4903 "(RFC 2911 section 4.1.14).", attr
->name
, date
[6]);
4911 "\"%s\": Bad dateTime deciseconds %u "
4912 "(RFC 2911 section 4.1.14).", attr
->name
, date
[7]);
4915 if (date
[8] != '-' && date
[8] != '+')
4920 "\"%s\": Bad dateTime UTC sign '%c' "
4921 "(RFC 2911 section 4.1.14).", attr
->name
, date
[8]);
4929 "\"%s\": Bad dateTime UTC hours %u "
4930 "(RFC 2911 section 4.1.14).", attr
->name
, date
[9]);
4938 "\"%s\": Bad dateTime UTC minutes %u "
4939 "(RFC 2911 section 4.1.14).", attr
->name
, date
[10]);
4944 case IPP_TAG_RESOLUTION
:
4945 for (i
= 0; i
< attr
->num_values
; i
++)
4947 if (attr
->values
[i
].resolution
.xres
<= 0)
4952 "\"%s\": Bad resolution value %dx%d%s - cross "
4953 "feed resolution must be positive "
4954 "(RFC 2911 section 4.1.15).", attr
->name
,
4955 attr
->values
[i
].resolution
.xres
,
4956 attr
->values
[i
].resolution
.yres
,
4957 attr
->values
[i
].resolution
.units
==
4958 IPP_RES_PER_INCH
? "dpi" :
4959 attr
->values
[i
].resolution
.units
==
4960 IPP_RES_PER_CM
? "dpcm" : "unknown");
4963 if (attr
->values
[i
].resolution
.yres
<= 0)
4968 "\"%s\": Bad resolution value %dx%d%s - feed "
4969 "resolution must be positive "
4970 "(RFC 2911 section 4.1.15).", attr
->name
,
4971 attr
->values
[i
].resolution
.xres
,
4972 attr
->values
[i
].resolution
.yres
,
4973 attr
->values
[i
].resolution
.units
==
4974 IPP_RES_PER_INCH
? "dpi" :
4975 attr
->values
[i
].resolution
.units
==
4976 IPP_RES_PER_CM
? "dpcm" : "unknown");
4979 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
4980 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
4985 "\"%s\": Bad resolution value %dx%d%s - bad "
4986 "units value (RFC 2911 section 4.1.15).",
4987 attr
->name
, attr
->values
[i
].resolution
.xres
,
4988 attr
->values
[i
].resolution
.yres
,
4989 attr
->values
[i
].resolution
.units
==
4990 IPP_RES_PER_INCH
? "dpi" :
4991 attr
->values
[i
].resolution
.units
==
4992 IPP_RES_PER_CM
? "dpcm" : "unknown");
4997 case IPP_TAG_RANGE
:
4998 for (i
= 0; i
< attr
->num_values
; i
++)
5000 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5005 "\"%s\": Bad rangeOfInteger value %d-%d - lower "
5006 "greater than upper (RFC 2911 section 4.1.13).",
5007 attr
->name
, attr
->values
[i
].range
.lower
,
5008 attr
->values
[i
].range
.upper
);
5013 case IPP_TAG_BEGIN_COLLECTION
:
5014 for (i
= 0; i
< attr
->num_values
; i
++)
5016 for (colattr
= attr
->values
[i
].collection
->attrs
;
5018 colattr
= colattr
->next
)
5020 if (!validate_attr(outfile
, NULL
, colattr
))
5027 if (colattr
&& errors
)
5029 add_stringf(errors
, "\"%s\": Bad collection value.", attr
->name
);
5033 validate_attr(outfile
, errors
, colattr
);
5034 colattr
= colattr
->next
;
5041 case IPP_TAG_TEXTLANG
:
5042 for (i
= 0; i
< attr
->num_values
; i
++)
5044 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5046 if ((*ptr
& 0xe0) == 0xc0)
5049 if ((*ptr
& 0xc0) != 0x80)
5052 else if ((*ptr
& 0xf0) == 0xe0)
5055 if ((*ptr
& 0xc0) != 0x80)
5058 if ((*ptr
& 0xc0) != 0x80)
5061 else if ((*ptr
& 0xf8) == 0xf0)
5064 if ((*ptr
& 0xc0) != 0x80)
5067 if ((*ptr
& 0xc0) != 0x80)
5070 if ((*ptr
& 0xc0) != 0x80)
5073 else if (*ptr
& 0x80)
5082 "\"%s\": Bad text value \"%s\" - bad UTF-8 "
5083 "sequence (RFC 2911 section 4.1.1).", attr
->name
,
5084 attr
->values
[i
].string
.text
);
5087 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5092 "\"%s\": Bad text value \"%s\" - bad length %d "
5093 "(RFC 2911 section 4.1.1).", attr
->name
,
5094 attr
->values
[i
].string
.text
,
5095 (int)strlen(attr
->values
[i
].string
.text
));
5101 case IPP_TAG_NAMELANG
:
5102 for (i
= 0; i
< attr
->num_values
; i
++)
5104 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5106 if ((*ptr
& 0xe0) == 0xc0)
5109 if ((*ptr
& 0xc0) != 0x80)
5112 else if ((*ptr
& 0xf0) == 0xe0)
5115 if ((*ptr
& 0xc0) != 0x80)
5118 if ((*ptr
& 0xc0) != 0x80)
5121 else if ((*ptr
& 0xf8) == 0xf0)
5124 if ((*ptr
& 0xc0) != 0x80)
5127 if ((*ptr
& 0xc0) != 0x80)
5130 if ((*ptr
& 0xc0) != 0x80)
5133 else if (*ptr
& 0x80)
5142 "\"%s\": Bad name value \"%s\" - bad UTF-8 "
5143 "sequence (RFC 2911 section 4.1.2).", attr
->name
,
5144 attr
->values
[i
].string
.text
);
5147 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5152 "\"%s\": Bad name value \"%s\" - bad length %d "
5153 "(RFC 2911 section 4.1.2).", attr
->name
,
5154 attr
->values
[i
].string
.text
,
5155 (int)strlen(attr
->values
[i
].string
.text
));
5160 case IPP_TAG_KEYWORD
:
5161 for (i
= 0; i
< attr
->num_values
; i
++)
5163 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5164 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5168 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5173 "\"%s\": Bad keyword value \"%s\" - invalid "
5174 "character (RFC 2911 section 4.1.3).",
5175 attr
->name
, attr
->values
[i
].string
.text
);
5178 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5183 "\"%s\": Bad keyword value \"%s\" - bad "
5184 "length %d (RFC 2911 section 4.1.3).",
5185 attr
->name
, attr
->values
[i
].string
.text
,
5186 (int)strlen(attr
->values
[i
].string
.text
));
5192 for (i
= 0; i
< attr
->num_values
; i
++)
5194 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5195 attr
->values
[i
].string
.text
,
5196 scheme
, sizeof(scheme
),
5197 userpass
, sizeof(userpass
),
5198 hostname
, sizeof(hostname
),
5199 &port
, resource
, sizeof(resource
));
5201 if (uri_status
< HTTP_URI_OK
)
5206 "\"%s\": Bad URI value \"%s\" - %s "
5207 "(RFC 2911 section 4.1.5).", attr
->name
,
5208 attr
->values
[i
].string
.text
,
5209 httpURIStatusString(uri_status
));
5212 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5217 "\"%s\": Bad URI value \"%s\" - bad length %d "
5218 "(RFC 2911 section 4.1.5).", attr
->name
,
5219 attr
->values
[i
].string
.text
,
5220 (int)strlen(attr
->values
[i
].string
.text
));
5225 case IPP_TAG_URISCHEME
:
5226 for (i
= 0; i
< attr
->num_values
; i
++)
5228 ptr
= attr
->values
[i
].string
.text
;
5229 if (islower(*ptr
& 255))
5231 for (ptr
++; *ptr
; ptr
++)
5232 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5233 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5237 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5242 "\"%s\": Bad uriScheme value \"%s\" - bad "
5243 "characters (RFC 2911 section 4.1.6).",
5244 attr
->name
, attr
->values
[i
].string
.text
);
5247 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5252 "\"%s\": Bad uriScheme value \"%s\" - bad "
5253 "length %d (RFC 2911 section 4.1.6).",
5254 attr
->name
, attr
->values
[i
].string
.text
,
5255 (int)strlen(attr
->values
[i
].string
.text
));
5260 case IPP_TAG_CHARSET
:
5261 for (i
= 0; i
< attr
->num_values
; i
++)
5263 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5264 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5265 isspace(*ptr
& 255))
5268 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5273 "\"%s\": Bad charset value \"%s\" - bad "
5274 "characters (RFC 2911 section 4.1.7).",
5275 attr
->name
, attr
->values
[i
].string
.text
);
5278 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5283 "\"%s\": Bad charset value \"%s\" - bad "
5284 "length %d (RFC 2911 section 4.1.7).",
5285 attr
->name
, attr
->values
[i
].string
.text
,
5286 (int)strlen(attr
->values
[i
].string
.text
));
5291 case IPP_TAG_LANGUAGE
:
5293 * The following regular expression is derived from the ABNF for
5294 * language tags in RFC 4646. All I can say is that this is the
5295 * easiest way to check the values...
5298 if ((i
= regcomp(&re
,
5300 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5302 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5303 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5304 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5305 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5306 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5308 "x(-[a-z0-9]{1,8})+" /* privateuse */
5310 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5312 REG_NOSUB
| REG_EXTENDED
)) != 0)
5314 char temp
[256]; /* Temporary error string */
5316 regerror(i
, &re
, temp
, sizeof(temp
));
5317 print_fatal_error(outfile
, "Unable to compile naturalLanguage regular "
5318 "expression: %s.", temp
);
5322 for (i
= 0; i
< attr
->num_values
; i
++)
5324 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5329 "\"%s\": Bad naturalLanguage value \"%s\" - bad "
5330 "characters (RFC 2911 section 4.1.8).",
5331 attr
->name
, attr
->values
[i
].string
.text
);
5334 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5339 "\"%s\": Bad naturalLanguage value \"%s\" - bad "
5340 "length %d (RFC 2911 section 4.1.8).",
5341 attr
->name
, attr
->values
[i
].string
.text
,
5342 (int)strlen(attr
->values
[i
].string
.text
));
5349 case IPP_TAG_MIMETYPE
:
5351 * The following regular expression is derived from the ABNF for
5352 * language tags in RFC 2045 and 4288. All I can say is that this is
5353 * the easiest way to check the values...
5356 if ((i
= regcomp(&re
,
5358 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5360 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5361 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5362 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5365 REG_NOSUB
| REG_EXTENDED
)) != 0)
5367 char temp
[256]; /* Temporary error string */
5369 regerror(i
, &re
, temp
, sizeof(temp
));
5370 print_fatal_error(outfile
, "Unable to compile mimeMediaType regular "
5371 "expression: %s.", temp
);
5375 for (i
= 0; i
< attr
->num_values
; i
++)
5377 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5382 "\"%s\": Bad mimeMediaType value \"%s\" - bad "
5383 "characters (RFC 2911 section 4.1.9).",
5384 attr
->name
, attr
->values
[i
].string
.text
);
5387 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5392 "\"%s\": Bad mimeMediaType value \"%s\" - bad "
5393 "length %d (RFC 2911 section 4.1.9).",
5394 attr
->name
, attr
->values
[i
].string
.text
,
5395 (int)strlen(attr
->values
[i
].string
.text
));
5411 * 'with_value()' - Test a WITH-VALUE predicate.
5414 static int /* O - 1 on match, 0 on non-match */
5415 with_value(FILE *outfile
, /* I - Output file */
5416 cups_array_t
*errors
, /* I - Errors array */
5417 char *value
, /* I - Value string */
5418 int flags
, /* I - Flags for match */
5419 ipp_attribute_t
*attr
, /* I - Attribute to compare */
5420 char *matchbuf
, /* I - Buffer to hold matching value */
5421 size_t matchlen
) /* I - Length of match buffer */
5423 int i
, /* Looping var */
5425 char temp
[1024], /* Temporary value string */
5426 *valptr
; /* Pointer into value */
5430 match
= (flags
& _CUPS_WITH_ALL
) ? 1 : 0;
5433 * NULL matches everything.
5436 if (!value
|| !*value
)
5440 * Compare the value string to the attribute value.
5443 switch (attr
->value_tag
)
5445 case IPP_TAG_INTEGER
:
5447 for (i
= 0; i
< attr
->num_values
; i
++)
5449 char op
, /* Comparison operator */
5450 *nextptr
; /* Next pointer */
5451 int intvalue
, /* Integer value */
5452 valmatch
= 0; /* Does the current value match? */
5456 while (isspace(*valptr
& 255) || isdigit(*valptr
& 255) ||
5457 *valptr
== '-' || *valptr
== ',' || *valptr
== '<' ||
5458 *valptr
== '=' || *valptr
== '>')
5461 while (*valptr
&& !isdigit(*valptr
& 255) && *valptr
!= '-')
5463 if (*valptr
== '<' || *valptr
== '>' || *valptr
== '=')
5471 intvalue
= (int)strtol(valptr
, &nextptr
, 0);
5472 if (nextptr
== valptr
)
5476 if ((op
== '=' && attr
->values
[i
].integer
== intvalue
) ||
5477 (op
== '<' && attr
->values
[i
].integer
< intvalue
) ||
5478 (op
== '>' && attr
->values
[i
].integer
> intvalue
))
5481 snprintf(matchbuf
, matchlen
, "%d", attr
->values
[i
].integer
);
5488 if (flags
& _CUPS_WITH_ALL
)
5503 if (!match
&& errors
)
5505 for (i
= 0; i
< attr
->num_values
; i
++)
5506 add_stringf(errors
, "GOT: %s=%d", attr
->name
,
5507 attr
->values
[i
].integer
);
5511 case IPP_TAG_RANGE
:
5512 for (i
= 0; i
< attr
->num_values
; i
++)
5514 char op
, /* Comparison operator */
5515 *nextptr
; /* Next pointer */
5516 int intvalue
, /* Integer value */
5517 valmatch
= 0; /* Does the current value match? */
5521 while (isspace(*valptr
& 255) || isdigit(*valptr
& 255) ||
5522 *valptr
== '-' || *valptr
== ',' || *valptr
== '<' ||
5523 *valptr
== '=' || *valptr
== '>')
5526 while (*valptr
&& !isdigit(*valptr
& 255) && *valptr
!= '-')
5528 if (*valptr
== '<' || *valptr
== '>' || *valptr
== '=')
5536 intvalue
= (int)strtol(valptr
, &nextptr
, 0);
5537 if (nextptr
== valptr
)
5541 if ((op
== '=' && (attr
->values
[i
].range
.lower
== intvalue
||
5542 attr
->values
[i
].range
.upper
== intvalue
)) ||
5543 (op
== '<' && attr
->values
[i
].range
.upper
< intvalue
) ||
5544 (op
== '>' && attr
->values
[i
].range
.upper
> intvalue
))
5547 snprintf(matchbuf
, matchlen
, "%d-%d",
5548 attr
->values
[0].range
.lower
,
5549 attr
->values
[0].range
.upper
);
5556 if (flags
& _CUPS_WITH_ALL
)
5571 if (!match
&& errors
)
5573 for (i
= 0; i
< attr
->num_values
; i
++)
5574 add_stringf(errors
, "GOT: %s=%d-%d", attr
->name
,
5575 attr
->values
[i
].range
.lower
,
5576 attr
->values
[i
].range
.upper
);
5580 case IPP_TAG_BOOLEAN
:
5581 for (i
= 0; i
< attr
->num_values
; i
++)
5583 if (!strcmp(value
, "true") == attr
->values
[i
].boolean
)
5586 strlcpy(matchbuf
, value
, matchlen
);
5588 if (!(flags
& _CUPS_WITH_ALL
))
5594 else if (flags
& _CUPS_WITH_ALL
)
5601 if (!match
&& errors
)
5603 for (i
= 0; i
< attr
->num_values
; i
++)
5604 add_stringf(errors
, "GOT: %s=%s", attr
->name
,
5605 attr
->values
[i
].boolean
? "true" : "false");
5609 case IPP_TAG_RESOLUTION
:
5610 for (i
= 0; i
< attr
->num_values
; i
++)
5612 if (attr
->values
[i
].resolution
.xres
==
5613 attr
->values
[i
].resolution
.yres
)
5614 snprintf(temp
, sizeof(temp
), "%d%s",
5615 attr
->values
[i
].resolution
.xres
,
5616 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5619 snprintf(temp
, sizeof(temp
), "%dx%d%s",
5620 attr
->values
[i
].resolution
.xres
,
5621 attr
->values
[i
].resolution
.yres
,
5622 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5625 if (!strcmp(value
, temp
))
5628 strlcpy(matchbuf
, value
, matchlen
);
5630 if (!(flags
& _CUPS_WITH_ALL
))
5636 else if (flags
& _CUPS_WITH_ALL
)
5643 if (!match
&& errors
)
5645 for (i
= 0; i
< attr
->num_values
; i
++)
5647 if (attr
->values
[i
].resolution
.xres
==
5648 attr
->values
[i
].resolution
.yres
)
5649 snprintf(temp
, sizeof(temp
), "%d%s",
5650 attr
->values
[i
].resolution
.xres
,
5651 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5654 snprintf(temp
, sizeof(temp
), "%dx%d%s",
5655 attr
->values
[i
].resolution
.xres
,
5656 attr
->values
[i
].resolution
.yres
,
5657 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5660 if (strcmp(value
, temp
))
5661 add_stringf(errors
, "GOT: %s=%s", attr
->name
, temp
);
5666 case IPP_TAG_NOVALUE
:
5667 case IPP_TAG_UNKNOWN
:
5670 case IPP_TAG_CHARSET
:
5671 case IPP_TAG_KEYWORD
:
5672 case IPP_TAG_LANGUAGE
:
5673 case IPP_TAG_MIMETYPE
:
5675 case IPP_TAG_NAMELANG
:
5677 case IPP_TAG_TEXTLANG
:
5679 case IPP_TAG_URISCHEME
:
5680 if (flags
& _CUPS_WITH_REGEX
)
5683 * Value is an extended, case-sensitive POSIX regular expression...
5686 regex_t re
; /* Regular expression */
5688 if ((i
= regcomp(&re
, value
, REG_EXTENDED
| REG_NOSUB
)) != 0)
5690 regerror(i
, &re
, temp
, sizeof(temp
));
5692 print_fatal_error(outfile
, "Unable to compile WITH-VALUE regular expression "
5693 "\"%s\" - %s", value
, temp
);
5698 * See if ALL of the values match the given regular expression.
5701 for (i
= 0; i
< attr
->num_values
; i
++)
5703 if (!regexec(&re
, get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
5708 get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
5711 if (!(flags
& _CUPS_WITH_ALL
))
5717 else if (flags
& _CUPS_WITH_ALL
)
5729 * Value is a literal string, see if the value(s) match...
5732 for (i
= 0; i
< attr
->num_values
; i
++)
5734 if (!strcmp(value
, get_string(attr
, i
, flags
, temp
, sizeof(temp
))))
5738 get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
5741 if (!(flags
& _CUPS_WITH_ALL
))
5747 else if (flags
& _CUPS_WITH_ALL
)
5755 if (!match
&& errors
)
5757 for (i
= 0; i
< attr
->num_values
; i
++)
5758 add_stringf(errors
, "GOT: %s=\"%s\"", attr
->name
,
5759 attr
->values
[i
].string
.text
);
5772 * End of "$Id: ipptool.c 12031 2014-07-15 19:57:59Z msweet $".