2 * ipptool command for CUPS.
4 * Copyright 2007-2017 by Apple Inc.
5 * Copyright 1997-2007 by Easy Software Products.
7 * These coded instructions, statements, and computer programs are the
8 * property of Apple Inc. and are protected by Federal copyright
9 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
10 * which should have been included with this file. If this file is
11 * missing or damaged, see the license at "http://www.cups.org/".
13 * This file is subject to the Apple OS-Developed Software exception.
17 * Include necessary headers...
20 #include <cups/cups-private.h>
21 #include <cups/file-private.h>
35 #endif /* !O_BINARY */
42 typedef enum _cups_transfer_e
/**** How to send request data ****/
44 _CUPS_TRANSFER_AUTO
, /* Chunk for files, length for static */
45 _CUPS_TRANSFER_CHUNKED
, /* Chunk always */
46 _CUPS_TRANSFER_LENGTH
/* Length always */
49 typedef enum _cups_output_e
/**** Output mode ****/
51 _CUPS_OUTPUT_QUIET
, /* No output */
52 _CUPS_OUTPUT_TEST
, /* Traditional CUPS test output */
53 _CUPS_OUTPUT_PLIST
, /* XML plist test output */
54 _CUPS_OUTPUT_LIST
, /* Tabular list output */
55 _CUPS_OUTPUT_CSV
/* Comma-separated values output */
58 typedef enum _cups_with_e
/**** WITH flags ****/
60 _CUPS_WITH_LITERAL
= 0, /* Match string is a literal value */
61 _CUPS_WITH_ALL
= 1, /* Must match all values */
62 _CUPS_WITH_REGEX
= 2, /* Match string is a regular expression */
63 _CUPS_WITH_HOSTNAME
= 4, /* Match string is a URI hostname */
64 _CUPS_WITH_RESOURCE
= 8, /* Match string is a URI resource */
65 _CUPS_WITH_SCHEME
= 16 /* Match string is a URI scheme */
68 typedef struct _cups_expect_s
/**** Expected attribute info ****/
70 int optional
, /* Optional attribute? */
71 not_expect
, /* Don't expect attribute? */
72 expect_all
; /* Expect all attributes to match/not match */
73 char *name
, /* Attribute name */
74 *of_type
, /* Type name */
75 *same_count_as
, /* Parallel attribute name */
76 *if_defined
, /* Only required if variable defined */
77 *if_not_defined
, /* Only required if variable is not defined */
78 *with_value
, /* Attribute must include this value */
79 *with_value_from
, /* Attribute must have one of the values in this attribute */
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
, ...) __attribute__ ((__format__ (__printf__
, 2, 3)));
155 static int compare_uris(const char *a
, const char *b
);
156 static int compare_vars(_cups_var_t
*a
, _cups_var_t
*b
);
157 static int do_tests(cups_file_t
*outfile
, _cups_vars_t
*vars
, const char *testfile
);
158 static void expand_variables(_cups_vars_t
*vars
, char *dst
, const char *src
, size_t dstsize
) __attribute__((nonnull(1,2,3)));
159 static int expect_matches(_cups_expect_t
*expect
, ipp_tag_t value_tag
);
160 static ipp_t
*get_collection(cups_file_t
*outfile
, _cups_vars_t
*vars
, cups_file_t
*fp
, int *linenum
);
161 static char *get_filename(const char *testfile
, char *dst
, const char *src
, size_t dstsize
);
162 static const char *get_string(ipp_attribute_t
*attr
, int element
, int flags
, char *buffer
, size_t bufsize
);
163 static char *get_token(cups_file_t
*fp
, char *buf
, int buflen
, int *linenum
);
164 static char *get_variable(_cups_vars_t
*vars
, const char *name
);
165 static char *iso_date(ipp_uchar_t
*date
);
166 static const char *password_cb(const char *prompt
);
167 static void pause_message(const char *message
);
168 static void print_attr(cups_file_t
*outfile
, int format
, ipp_attribute_t
*attr
, ipp_tag_t
*group
);
169 static void print_csv(cups_file_t
*outfile
, ipp_attribute_t
*attr
, int num_displayed
, char **displayed
, size_t *widths
);
170 static void print_fatal_error(cups_file_t
*outfile
, const char *s
, ...) __attribute__ ((__format__ (__printf__
, 2, 3)));
171 static void print_line(cups_file_t
*outfile
, ipp_attribute_t
*attr
, int num_displayed
, char **displayed
, size_t *widths
);
172 static void print_xml_header(cups_file_t
*outfile
);
173 static void print_xml_string(cups_file_t
*outfile
, const char *element
, const char *s
);
174 static void print_xml_trailer(cups_file_t
*outfile
, int success
, const char *message
);
175 static void set_variable(cups_file_t
*outfile
, _cups_vars_t
*vars
, const char *name
, const char *value
);
177 static void sigterm_handler(int sig
);
179 static int timeout_cb(http_t
*http
, void *user_data
);
180 static void usage(void) __attribute__((noreturn
));
181 static int validate_attr(cups_file_t
*outfile
, cups_array_t
*errors
, ipp_attribute_t
*attr
);
182 static int with_value(cups_file_t
*outfile
, cups_array_t
*errors
, char *value
, int flags
, ipp_attribute_t
*attr
, char *matchbuf
, size_t matchlen
);
183 static int with_value_from(cups_array_t
*errors
, ipp_attribute_t
*fromattr
, ipp_attribute_t
*attr
, char *matchbuf
, size_t matchlen
);
187 * 'main()' - Parse options and do tests.
190 int /* O - Exit status */
191 main(int argc
, /* I - Number of command-line args */
192 char *argv
[]) /* I - Command-line arguments */
194 int i
; /* Looping var */
195 int status
; /* Status of tests... */
196 cups_file_t
*outfile
= cupsFileStdout();
198 char *opt
, /* Current option */
199 name
[1024], /* Name/value buffer */
200 *value
, /* Pointer to value */
201 filename
[1024], /* Real filename */
202 testname
[1024], /* Real test filename */
203 uri
[1024]; /* Copy of printer URI */
204 const char *ext
, /* Extension on filename */
205 *testfile
; /* Test file to use */
206 int interval
, /* Test interval in microseconds */
207 repeat
; /* Repeat count */
208 _cups_vars_t vars
; /* Variables */
209 http_uri_status_t uri_status
; /* URI separation status */
210 _cups_globals_t
*cg
= _cupsGlobals();
216 * Catch SIGINT and SIGTERM...
219 signal(SIGINT
, sigterm_handler
);
220 signal(SIGTERM
, sigterm_handler
);
224 * Initialize the locale and variables...
227 _cupsSetLocale(argv
);
229 memset(&vars
, 0, sizeof(vars
));
230 vars
.family
= AF_UNSPEC
;
231 vars
.vars
= cupsArrayNew((cups_array_func_t
)compare_vars
, NULL
);
236 * ipptool URI testfile
244 for (i
= 1; i
< argc
; i
++)
246 if (!strcmp(argv
[i
], "--help"))
250 else if (!strcmp(argv
[i
], "--stop-after-include-error"))
252 StopAfterIncludeError
= 1;
254 else if (!strcmp(argv
[i
], "--version"))
259 else if (argv
[i
][0] == '-')
261 for (opt
= argv
[i
] + 1; *opt
; opt
++)
265 case '4' : /* Connect using IPv4 only */
266 vars
.family
= AF_INET
;
270 case '6' : /* Connect using IPv6 only */
271 vars
.family
= AF_INET6
;
273 #endif /* AF_INET6 */
275 case 'C' : /* Enable HTTP chunking */
276 Transfer
= _CUPS_TRANSFER_CHUNKED
;
279 case 'E' : /* Encrypt with TLS */
281 vars
.encryption
= HTTP_ENCRYPT_REQUIRED
;
283 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."),
285 #endif /* HAVE_SSL */
288 case 'I' : /* Ignore errors */
292 case 'L' : /* Disable HTTP chunking */
293 Transfer
= _CUPS_TRANSFER_LENGTH
;
296 case 'P' : /* Output to plist file */
301 _cupsLangPrintf(stderr
, _("%s: Missing filename for \"-P\"."), "ipptool");
305 if (outfile
!= cupsFileStdout())
308 if ((outfile
= cupsFileOpen(argv
[i
], "w")) == NULL
)
310 _cupsLangPrintf(stderr
, _("%s: Unable to open \"%s\": %s"), "ipptool", argv
[i
], strerror(errno
));
314 Output
= _CUPS_OUTPUT_PLIST
;
316 if (interval
|| repeat
)
318 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
323 case 'S' : /* Encrypt with SSL */
325 vars
.encryption
= HTTP_ENCRYPT_ALWAYS
;
327 _cupsLangPrintf(stderr
, _("%s: Sorry, no encryption support."),
329 #endif /* HAVE_SSL */
332 case 'T' : /* Set timeout */
337 _cupsLangPrintf(stderr
,
338 _("%s: Missing timeout for \"-T\"."),
343 vars
.timeout
= _cupsStrScand(argv
[i
], NULL
, localeconv());
346 case 'V' : /* Set IPP version */
351 _cupsLangPrintf(stderr
,
352 _("%s: Missing version for \"-V\"."),
357 if (!strcmp(argv
[i
], "1.0"))
359 else if (!strcmp(argv
[i
], "1.1"))
361 else if (!strcmp(argv
[i
], "2.0"))
363 else if (!strcmp(argv
[i
], "2.1"))
365 else if (!strcmp(argv
[i
], "2.2"))
369 _cupsLangPrintf(stderr
,
370 _("%s: Bad version %s for \"-V\"."),
376 case 'X' : /* Produce XML output */
377 Output
= _CUPS_OUTPUT_PLIST
;
379 if (interval
|| repeat
)
381 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
386 case 'c' : /* CSV output */
387 Output
= _CUPS_OUTPUT_CSV
;
390 case 'd' : /* Define a variable */
395 _cupsLangPuts(stderr
,
396 _("ipptool: Missing name=value for \"-d\"."));
400 strlcpy(name
, argv
[i
], sizeof(name
));
401 if ((value
= strchr(name
, '=')) != NULL
)
404 value
= name
+ strlen(name
);
406 set_variable(outfile
, &vars
, name
, value
);
409 case 'f' : /* Set the default test filename */
414 _cupsLangPuts(stderr
,
415 _("ipptool: Missing filename for \"-f\"."));
422 vars
.filename
= NULL
;
425 if (access(argv
[i
], 0))
431 snprintf(filename
, sizeof(filename
), "%s.gz", argv
[i
]);
432 if (access(filename
, 0) && filename
[0] != '/'
434 && (!isalpha(filename
[0] & 255) || filename
[1] != ':')
438 snprintf(filename
, sizeof(filename
), "%s/ipptool/%s",
439 cg
->cups_datadir
, argv
[i
]);
440 if (access(filename
, 0))
442 snprintf(filename
, sizeof(filename
), "%s/ipptool/%s.gz",
443 cg
->cups_datadir
, argv
[i
]);
444 if (access(filename
, 0))
445 vars
.filename
= strdup(argv
[i
]);
447 vars
.filename
= strdup(filename
);
450 vars
.filename
= strdup(filename
);
453 vars
.filename
= strdup(filename
);
456 vars
.filename
= strdup(argv
[i
]);
458 if ((ext
= strrchr(vars
.filename
, '.')) != NULL
)
461 * Guess the MIME media type based on the extension...
464 if (!_cups_strcasecmp(ext
, ".gif"))
465 set_variable(outfile
, &vars
, "filetype", "image/gif");
466 else if (!_cups_strcasecmp(ext
, ".htm") ||
467 !_cups_strcasecmp(ext
, ".htm.gz") ||
468 !_cups_strcasecmp(ext
, ".html") ||
469 !_cups_strcasecmp(ext
, ".html.gz"))
470 set_variable(outfile
, &vars
, "filetype", "text/html");
471 else if (!_cups_strcasecmp(ext
, ".jpg") ||
472 !_cups_strcasecmp(ext
, ".jpeg"))
473 set_variable(outfile
, &vars
, "filetype", "image/jpeg");
474 else if (!_cups_strcasecmp(ext
, ".pcl") ||
475 !_cups_strcasecmp(ext
, ".pcl.gz"))
476 set_variable(outfile
, &vars
, "filetype", "application/vnd.hp-PCL");
477 else if (!_cups_strcasecmp(ext
, ".pdf"))
478 set_variable(outfile
, &vars
, "filetype", "application/pdf");
479 else if (!_cups_strcasecmp(ext
, ".png"))
480 set_variable(outfile
, &vars
, "filetype", "image/png");
481 else if (!_cups_strcasecmp(ext
, ".ps") ||
482 !_cups_strcasecmp(ext
, ".ps.gz"))
483 set_variable(outfile
, &vars
, "filetype", "application/postscript");
484 else if (!_cups_strcasecmp(ext
, ".pwg") ||
485 !_cups_strcasecmp(ext
, ".pwg.gz") ||
486 !_cups_strcasecmp(ext
, ".ras") ||
487 !_cups_strcasecmp(ext
, ".ras.gz"))
488 set_variable(outfile
, &vars
, "filetype", "image/pwg-raster");
489 else if (!_cups_strcasecmp(ext
, ".tif") ||
490 !_cups_strcasecmp(ext
, ".tiff"))
491 set_variable(outfile
, &vars
, "filetype", "image/tiff");
492 else if (!_cups_strcasecmp(ext
, ".txt") ||
493 !_cups_strcasecmp(ext
, ".txt.gz"))
494 set_variable(outfile
, &vars
, "filetype", "text/plain");
495 else if (!_cups_strcasecmp(ext
, ".urf") ||
496 !_cups_strcasecmp(ext
, ".urf.gz"))
497 set_variable(outfile
, &vars
, "filetype", "image/urf");
498 else if (!_cups_strcasecmp(ext
, ".xps"))
499 set_variable(outfile
, &vars
, "filetype", "application/openxps");
501 set_variable(outfile
, &vars
, "filetype", "application/octet-stream");
506 * Use the "auto-type" MIME media type...
509 set_variable(outfile
, &vars
, "filetype", "application/octet-stream");
513 case 'i' : /* Test every N seconds */
518 _cupsLangPuts(stderr
,
519 _("ipptool: Missing seconds for \"-i\"."));
524 interval
= (int)(_cupsStrScand(argv
[i
], NULL
, localeconv()) *
528 _cupsLangPuts(stderr
,
529 _("ipptool: Invalid seconds for \"-i\"."));
534 if (Output
== _CUPS_OUTPUT_PLIST
&& interval
)
536 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
541 case 'l' : /* List as a table */
542 Output
= _CUPS_OUTPUT_LIST
;
545 case 'n' : /* Repeat count */
550 _cupsLangPuts(stderr
,
551 _("ipptool: Missing count for \"-n\"."));
555 repeat
= atoi(argv
[i
]);
557 if (Output
== _CUPS_OUTPUT_PLIST
&& repeat
)
559 _cupsLangPuts(stderr
, _("ipptool: \"-i\" and \"-n\" are incompatible with \"-P\" and \"-X\"."));
564 case 'q' : /* Be quiet */
565 Output
= _CUPS_OUTPUT_QUIET
;
568 case 't' : /* CUPS test output */
569 Output
= _CUPS_OUTPUT_TEST
;
572 case 'v' : /* Be verbose */
577 _cupsLangPrintf(stderr
, _("ipptool: Unknown option \"-%c\"."),
583 else if (!strncmp(argv
[i
], "ipp://", 6) || !strncmp(argv
[i
], "http://", 7)
585 || !strncmp(argv
[i
], "ipps://", 7)
586 || !strncmp(argv
[i
], "https://", 8)
587 #endif /* HAVE_SSL */
596 _cupsLangPuts(stderr
, _("ipptool: May only specify a single URI."));
601 if (!strncmp(argv
[i
], "ipps://", 7) || !strncmp(argv
[i
], "https://", 8))
602 vars
.encryption
= HTTP_ENCRYPT_ALWAYS
;
603 #endif /* HAVE_SSL */
606 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
, vars
.uri
,
607 vars
.scheme
, sizeof(vars
.scheme
),
608 vars
.userpass
, sizeof(vars
.userpass
),
609 vars
.hostname
, sizeof(vars
.hostname
),
611 vars
.resource
, sizeof(vars
.resource
));
613 if (uri_status
!= HTTP_URI_OK
)
615 _cupsLangPrintf(stderr
, _("ipptool: Bad URI - %s."), httpURIStatusString(uri_status
));
619 if (vars
.userpass
[0])
621 if ((Password
= strchr(vars
.userpass
, ':')) != NULL
)
624 Username
= vars
.userpass
;
625 cupsSetPasswordCB(password_cb
);
626 set_variable(outfile
, &vars
, "uriuser", vars
.userpass
);
629 httpAssembleURI(HTTP_URI_CODING_ALL
, uri
, sizeof(uri
), vars
.scheme
, NULL
,
630 vars
.hostname
, vars
.port
, vars
.resource
);
641 _cupsLangPuts(stderr
, _("ipptool: URI required before test file."));
642 _cupsLangPuts(stderr
, argv
[i
]);
646 if (access(argv
[i
], 0) && argv
[i
][0] != '/'
648 && (!isalpha(argv
[i
][0] & 255) || argv
[i
][1] != ':')
652 snprintf(testname
, sizeof(testname
), "%s/ipptool/%s", cg
->cups_datadir
,
654 if (access(testname
, 0))
662 if (!do_tests(outfile
, &vars
, testfile
))
667 if (!vars
.uri
|| !testfile
)
671 * Loop if the interval is set...
674 if (Output
== _CUPS_OUTPUT_PLIST
)
675 print_xml_trailer(outfile
, !status
, NULL
);
676 else if (interval
> 0 && repeat
> 0)
680 usleep((useconds_t
)interval
);
681 do_tests(outfile
, &vars
, testfile
);
685 else if (interval
> 0)
689 usleep((useconds_t
)interval
);
690 do_tests(outfile
, &vars
, testfile
);
694 if ((Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
)) && TestCount
> 1)
697 * Show a summary report if there were multiple tests...
700 printf("\nSummary: %d tests, %d passed, %d failed, %d skipped\n"
701 "Score: %d%%\n", TestCount
, PassCount
, FailCount
, SkipCount
,
702 100 * (PassCount
+ SkipCount
) / TestCount
);
714 * 'add_stringf()' - Add a formatted string to an array.
718 add_stringf(cups_array_t
*a
, /* I - Array */
719 const char *s
, /* I - Printf-style format string */
720 ...) /* I - Additional args as needed */
722 char buffer
[10240]; /* Format buffer */
723 va_list ap
; /* Argument pointer */
727 * Don't bother is the array is NULL...
734 * Format the message...
738 vsnprintf(buffer
, sizeof(buffer
), s
, ap
);
742 * Add it to the array...
745 cupsArrayAdd(a
, buffer
);
750 * 'compare_uris()' - Compare two URIs...
753 static int /* O - Result of comparison */
754 compare_uris(const char *a
, /* I - First URI */
755 const char *b
) /* I - Second URI */
757 char ascheme
[32], /* Components of first URI */
762 char bscheme
[32], /* Components of second URI */
767 char *ptr
; /* Pointer into string */
768 int result
; /* Result of comparison */
772 * Separate the URIs into their components...
775 if (httpSeparateURI(HTTP_URI_CODING_ALL
, a
, ascheme
, sizeof(ascheme
), auserpass
, sizeof(auserpass
), ahost
, sizeof(ahost
), &aport
, aresource
, sizeof(aresource
)) < HTTP_URI_STATUS_OK
)
778 if (httpSeparateURI(HTTP_URI_CODING_ALL
, b
, bscheme
, sizeof(bscheme
), buserpass
, sizeof(buserpass
), bhost
, sizeof(bhost
), &bport
, bresource
, sizeof(bresource
)) < HTTP_URI_STATUS_OK
)
782 * Strip trailing dots from the host components, if present...
785 if ((ptr
= ahost
+ strlen(ahost
) - 1) > ahost
&& *ptr
== '.')
788 if ((ptr
= bhost
+ strlen(bhost
) - 1) > bhost
&& *ptr
== '.')
792 * Compare each component...
795 if ((result
= _cups_strcasecmp(ascheme
, bscheme
)) != 0)
798 if ((result
= strcmp(auserpass
, buserpass
)) != 0)
801 if ((result
= _cups_strcasecmp(ahost
, bhost
)) != 0)
805 return (aport
- bport
);
807 if (!_cups_strcasecmp(ascheme
, "mailto") || !_cups_strcasecmp(ascheme
, "urn"))
808 return (_cups_strcasecmp(aresource
, bresource
));
810 return (strcmp(aresource
, bresource
));
815 * 'compare_vars()' - Compare two variables.
818 static int /* O - Result of comparison */
819 compare_vars(_cups_var_t
*a
, /* I - First variable */
820 _cups_var_t
*b
) /* I - Second variable */
822 return (_cups_strcasecmp(a
->name
, b
->name
));
827 * 'do_tests()' - Do tests as specified in the test file.
830 static int /* 1 = success, 0 = failure */
831 do_tests(cups_file_t
*outfile
, /* I - Output file */
832 _cups_vars_t
*vars
, /* I - Variables */
833 const char *testfile
) /* I - Test file to use */
835 int i
, /* Looping var */
836 linenum
, /* Current line number */
837 pass
, /* Did we pass the test? */
838 prev_pass
= 1, /* Did we pass the previous test? */
839 request_id
, /* Current request ID */
840 show_header
= 1, /* Show the test header? */
841 ignore_errors
, /* Ignore test failures? */
842 skip_previous
= 0, /* Skip on previous test failure? */
843 repeat_count
, /* Repeat count */
844 repeat_test
; /* Repeat a test? */
845 useconds_t delay
, /* Initial delay */
846 repeat_interval
; /* Repeat interval (delay) */
847 http_t
*http
= NULL
; /* HTTP connection to server */
848 cups_file_t
*fp
= NULL
; /* Test file */
849 char resource
[512], /* Resource for request */
850 token
[1024], /* Token from file */
851 *tokenptr
, /* Pointer into token */
852 temp
[1024], /* Temporary string */
853 buffer
[131072], /* Copy buffer */
854 compression
[16]; /* COMPRESSION value */
855 ipp_t
*request
= NULL
, /* IPP request */
856 *response
= NULL
; /* IPP response */
857 size_t length
; /* Length of IPP request */
858 http_status_t status
; /* HTTP status */
859 cups_file_t
*reqfile
; /* File to send */
860 ssize_t bytes
; /* Bytes read/written */
861 char attr
[128]; /* Attribute name */
862 ipp_op_t op
; /* Operation */
863 ipp_tag_t group
; /* Current group */
864 ipp_tag_t value
; /* Current value type */
865 ipp_attribute_t
*attrptr
, /* Attribute pointer */
866 *found
, /* Found attribute */
867 *lastcol
= NULL
; /* Last collection attribute */
868 char name
[1024], /* Name of test */
869 file_id
[1024], /* File identifier */
870 test_id
[1024]; /* Test identifier */
871 char filename
[1024]; /* Filename */
872 _cups_transfer_t transfer
; /* To chunk or not to chunk */
873 int version
, /* IPP version number to use */
874 skip_test
; /* Skip this test? */
875 int num_statuses
= 0; /* Number of valid status codes */
876 _cups_status_t statuses
[100], /* Valid status codes */
877 *last_status
; /* Last STATUS (for predicates) */
878 int status_ok
, /* Did we get a matching status? */
879 num_expects
= 0; /* Number of expected attributes */
880 _cups_expect_t expects
[200], /* Expected attributes */
881 *expect
, /* Current expected attribute */
882 *last_expect
; /* Last EXPECT (for predicates) */
883 int num_displayed
= 0; /* Number of displayed attributes */
884 char *displayed
[200]; /* Displayed attributes */
885 size_t widths
[200]; /* Width of columns */
886 cups_array_t
*a
, /* Duplicate attribute array */
887 *errors
= NULL
; /* Errors array */
888 const char *error
; /* Current error */
892 * Open the test file...
895 if ((fp
= cupsFileOpen(testfile
, "r")) == NULL
)
897 print_fatal_error(outfile
, "Unable to open test file %s - %s", testfile
,
904 * Connect to the server...
907 if ((http
= httpConnect2(vars
->hostname
, vars
->port
, NULL
, vars
->family
,
908 vars
->encryption
, 1, 30000, NULL
)) == NULL
)
910 print_fatal_error(outfile
, "Unable to connect to %s on port %d - %s", vars
->hostname
,
911 vars
->port
, cupsLastErrorString());
917 httpSetDefaultField(http
, HTTP_FIELD_ACCEPT_ENCODING
,
918 "deflate, gzip, identity");
920 httpSetDefaultField(http
, HTTP_FIELD_ACCEPT_ENCODING
, "identity");
921 #endif /* HAVE_LIBZ */
923 if (vars
->timeout
> 0.0)
924 httpSetTimeout(http
, vars
->timeout
, timeout_cb
, NULL
);
930 CUPS_SRAND((unsigned)time(NULL
));
932 errors
= cupsArrayNew3(NULL
, NULL
, NULL
, 0, (cups_acopy_func_t
)strdup
,
933 (cups_afree_func_t
)free
);
937 request_id
= (CUPS_RAND() % 1000) * 137 + 1;
939 while (!Cancel
&& get_token(fp
, token
, sizeof(token
), &linenum
) != NULL
)
942 * Expect an open brace...
945 if (!strcmp(token
, "DEFINE"))
951 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
952 get_token(fp
, temp
, sizeof(temp
), &linenum
))
954 expand_variables(vars
, token
, temp
, sizeof(token
));
955 set_variable(outfile
, vars
, attr
, token
);
959 print_fatal_error(outfile
, "Missing DEFINE name and/or value on line %d.",
967 else if (!strcmp(token
, "DEFINE-DEFAULT"))
970 * DEFINE-DEFAULT name value
973 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
974 get_token(fp
, temp
, sizeof(temp
), &linenum
))
976 expand_variables(vars
, token
, temp
, sizeof(token
));
977 if (!get_variable(vars
, attr
))
978 set_variable(outfile
, vars
, attr
, token
);
982 print_fatal_error(outfile
, "Missing DEFINE-DEFAULT name and/or value on line "
990 else if (!strcmp(token
, "FILE-ID"))
996 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
998 expand_variables(vars
, file_id
, temp
, sizeof(file_id
));
1002 print_fatal_error(outfile
, "Missing FILE-ID value on line %d.", linenum
);
1009 else if (!strcmp(token
, "IGNORE-ERRORS"))
1016 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1017 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1019 IgnoreErrors
= !_cups_strcasecmp(temp
, "yes");
1023 print_fatal_error(outfile
, "Missing IGNORE-ERRORS value on line %d.", linenum
);
1030 else if (!strcmp(token
, "INCLUDE"))
1033 * INCLUDE "filename"
1034 * INCLUDE <filename>
1037 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1040 * Map the filename to and then run the tests...
1043 if (!do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
1047 if (StopAfterIncludeError
)
1053 print_fatal_error(outfile
, "Missing INCLUDE filename on line %d.", linenum
);
1061 else if (!strcmp(token
, "INCLUDE-IF-DEFINED"))
1064 * INCLUDE-IF-DEFINED name "filename"
1065 * INCLUDE-IF-DEFINED name <filename>
1068 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1069 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1072 * Map the filename to and then run the tests...
1075 if (get_variable(vars
, attr
) &&
1076 !do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
1080 if (StopAfterIncludeError
)
1086 print_fatal_error(outfile
, "Missing INCLUDE-IF-DEFINED name or filename on line "
1095 else if (!strcmp(token
, "INCLUDE-IF-NOT-DEFINED"))
1098 * INCLUDE-IF-NOT-DEFINED name "filename"
1099 * INCLUDE-IF-NOT-DEFINED name <filename>
1102 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1103 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1106 * Map the filename to and then run the tests...
1109 if (!get_variable(vars
, attr
) &&
1110 !do_tests(outfile
, vars
, get_filename(testfile
, filename
, temp
, sizeof(filename
))))
1114 if (StopAfterIncludeError
)
1120 print_fatal_error(outfile
, "Missing INCLUDE-IF-NOT-DEFINED name or filename on "
1121 "line %d.", linenum
);
1129 else if (!strcmp(token
, "SKIP-IF-DEFINED"))
1132 * SKIP-IF-DEFINED variable
1135 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1137 if (get_variable(vars
, temp
))
1142 print_fatal_error(outfile
, "Missing SKIP-IF-DEFINED variable on line %d.",
1148 else if (!strcmp(token
, "SKIP-IF-NOT-DEFINED"))
1151 * SKIP-IF-NOT-DEFINED variable
1154 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1156 if (!get_variable(vars
, temp
))
1161 print_fatal_error(outfile
, "Missing SKIP-IF-NOT-DEFINED variable on line %d.",
1167 else if (!strcmp(token
, "STOP-AFTER-INCLUDE-ERROR"))
1170 * STOP-AFTER-INCLUDE-ERROR yes
1171 * STOP-AFTER-INCLUDE-ERROR no
1174 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1175 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1177 StopAfterIncludeError
= !_cups_strcasecmp(temp
, "yes");
1181 print_fatal_error(outfile
, "Missing STOP-AFTER-INCLUDE-ERROR value on line %d.",
1189 else if (!strcmp(token
, "TRANSFER"))
1197 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1199 if (!strcmp(temp
, "auto"))
1200 Transfer
= _CUPS_TRANSFER_AUTO
;
1201 else if (!strcmp(temp
, "chunked"))
1202 Transfer
= _CUPS_TRANSFER_CHUNKED
;
1203 else if (!strcmp(temp
, "length"))
1204 Transfer
= _CUPS_TRANSFER_LENGTH
;
1207 print_fatal_error(outfile
, "Bad TRANSFER value \"%s\" on line %d.", temp
,
1215 print_fatal_error(outfile
, "Missing TRANSFER value on line %d.", linenum
);
1222 else if (!strcmp(token
, "VERSION"))
1224 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1226 if (!strcmp(temp
, "1.0"))
1228 else if (!strcmp(temp
, "1.1"))
1230 else if (!strcmp(temp
, "2.0"))
1232 else if (!strcmp(temp
, "2.1"))
1234 else if (!strcmp(temp
, "2.2"))
1238 print_fatal_error(outfile
, "Bad VERSION \"%s\" on line %d.", temp
, linenum
);
1245 print_fatal_error(outfile
, "Missing VERSION number on line %d.", linenum
);
1252 else if (strcmp(token
, "{"))
1254 print_fatal_error(outfile
, "Unexpected token %s seen on line %d.", token
, linenum
);
1260 * Initialize things...
1265 if (Output
== _CUPS_OUTPUT_PLIST
)
1266 print_xml_header(outfile
);
1267 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
1268 printf("\"%s\":\n", testfile
);
1273 strlcpy(resource
, vars
->resource
, sizeof(resource
));
1278 group
= IPP_TAG_ZERO
;
1279 ignore_errors
= IgnoreErrors
;
1287 transfer
= Transfer
;
1288 compression
[0] = '\0';
1291 repeat_interval
= 5000000;
1293 strlcpy(name
, testfile
, sizeof(name
));
1294 if (strrchr(name
, '.') != NULL
)
1295 *strrchr(name
, '.') = '\0';
1298 * Parse until we see a close brace...
1301 while (get_token(fp
, token
, sizeof(token
), &linenum
) != NULL
)
1303 if (_cups_strcasecmp(token
, "COUNT") &&
1304 _cups_strcasecmp(token
, "DEFINE-MATCH") &&
1305 _cups_strcasecmp(token
, "DEFINE-NO-MATCH") &&
1306 _cups_strcasecmp(token
, "DEFINE-VALUE") &&
1307 _cups_strcasecmp(token
, "IF-DEFINED") &&
1308 _cups_strcasecmp(token
, "IF-NOT-DEFINED") &&
1309 _cups_strcasecmp(token
, "IN-GROUP") &&
1310 _cups_strcasecmp(token
, "OF-TYPE") &&
1311 _cups_strcasecmp(token
, "REPEAT-LIMIT") &&
1312 _cups_strcasecmp(token
, "REPEAT-MATCH") &&
1313 _cups_strcasecmp(token
, "REPEAT-NO-MATCH") &&
1314 _cups_strcasecmp(token
, "SAME-COUNT-AS") &&
1315 _cups_strcasecmp(token
, "WITH-ALL-VALUES") &&
1316 _cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") &&
1317 _cups_strcasecmp(token
, "WITH-ALL-RESOURCES") &&
1318 _cups_strcasecmp(token
, "WITH-ALL-SCHEMES") &&
1319 _cups_strcasecmp(token
, "WITH-HOSTNAME") &&
1320 _cups_strcasecmp(token
, "WITH-RESOURCE") &&
1321 _cups_strcasecmp(token
, "WITH-SCHEME") &&
1322 _cups_strcasecmp(token
, "WITH-VALUE") &&
1323 _cups_strcasecmp(token
, "WITH-VALUE-FROM"))
1326 if (_cups_strcasecmp(token
, "DEFINE-MATCH") &&
1327 _cups_strcasecmp(token
, "DEFINE-NO-MATCH") &&
1328 _cups_strcasecmp(token
, "IF-DEFINED") &&
1329 _cups_strcasecmp(token
, "IF-NOT-DEFINED") &&
1330 _cups_strcasecmp(token
, "REPEAT-LIMIT") &&
1331 _cups_strcasecmp(token
, "REPEAT-MATCH") &&
1332 _cups_strcasecmp(token
, "REPEAT-NO-MATCH"))
1335 if (!strcmp(token
, "}"))
1337 else if (!strcmp(token
, "{") && lastcol
)
1340 * Another collection value
1343 ipp_t
*col
= get_collection(outfile
, vars
, fp
, &linenum
);
1344 /* Collection value */
1348 ippSetCollection(request
, &lastcol
, ippGetCount(lastcol
), col
);
1356 else if (!strcmp(token
, "COMPRESSION"))
1360 * COMPRESSION deflate
1364 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1366 expand_variables(vars
, compression
, temp
, sizeof(compression
));
1368 if (strcmp(compression
, "none") && strcmp(compression
, "deflate") &&
1369 strcmp(compression
, "gzip"))
1371 if (strcmp(compression
, "none"))
1372 #endif /* HAVE_LIBZ */
1374 print_fatal_error(outfile
, "Unsupported COMPRESSION value '%s' on line %d.",
1375 compression
, linenum
);
1380 if (!strcmp(compression
, "none"))
1381 compression
[0] = '\0';
1385 print_fatal_error(outfile
, "Missing COMPRESSION value on line %d.", linenum
);
1390 else if (!strcmp(token
, "DEFINE"))
1396 if (get_token(fp
, attr
, sizeof(attr
), &linenum
) &&
1397 get_token(fp
, temp
, sizeof(temp
), &linenum
))
1399 expand_variables(vars
, token
, temp
, sizeof(token
));
1400 set_variable(outfile
, vars
, attr
, token
);
1404 print_fatal_error(outfile
, "Missing DEFINE name and/or value on line %d.",
1410 else if (!strcmp(token
, "IGNORE-ERRORS"))
1417 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1418 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1420 ignore_errors
= !_cups_strcasecmp(temp
, "yes");
1424 print_fatal_error(outfile
, "Missing IGNORE-ERRORS value on line %d.", linenum
);
1431 else if (!_cups_strcasecmp(token
, "NAME"))
1437 get_token(fp
, temp
, sizeof(temp
), &linenum
);
1438 expand_variables(vars
, name
, temp
, sizeof(name
));
1440 else if (!_cups_strcasecmp(token
, "PAUSE"))
1443 * Pause with a message...
1446 get_token(fp
, token
, sizeof(token
), &linenum
);
1447 pause_message(token
);
1449 else if (!strcmp(token
, "REQUEST-ID"))
1456 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1458 if (isdigit(temp
[0] & 255))
1459 request_id
= atoi(temp
);
1460 else if (!_cups_strcasecmp(temp
, "random"))
1461 request_id
= (CUPS_RAND() % 1000) * 137 + 1;
1464 print_fatal_error(outfile
, "Bad REQUEST-ID value \"%s\" on line %d.", temp
,
1472 print_fatal_error(outfile
, "Missing REQUEST-ID value on line %d.", linenum
);
1477 else if (!strcmp(token
, "SKIP-IF-DEFINED"))
1480 * SKIP-IF-DEFINED variable
1483 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1485 if (get_variable(vars
, temp
))
1490 print_fatal_error(outfile
, "Missing SKIP-IF-DEFINED value on line %d.",
1496 else if (!strcmp(token
, "SKIP-IF-MISSING"))
1499 * SKIP-IF-MISSING filename
1502 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1504 expand_variables(vars
, token
, temp
, sizeof(token
));
1505 get_filename(testfile
, filename
, token
, sizeof(filename
));
1507 if (access(filename
, R_OK
))
1512 print_fatal_error(outfile
, "Missing SKIP-IF-MISSING filename on line %d.",
1518 else if (!strcmp(token
, "SKIP-IF-NOT-DEFINED"))
1521 * SKIP-IF-NOT-DEFINED variable
1524 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1526 if (!get_variable(vars
, temp
))
1531 print_fatal_error(outfile
, "Missing SKIP-IF-NOT-DEFINED value on line %d.",
1537 else if (!strcmp(token
, "SKIP-PREVIOUS-ERROR"))
1540 * SKIP-PREVIOUS-ERROR yes
1541 * SKIP-PREVIOUS-ERROR no
1544 if (get_token(fp
, temp
, sizeof(temp
), &linenum
) &&
1545 (!_cups_strcasecmp(temp
, "yes") || !_cups_strcasecmp(temp
, "no")))
1547 skip_previous
= !_cups_strcasecmp(temp
, "yes");
1551 print_fatal_error(outfile
, "Missing SKIP-PREVIOUS-ERROR value on line %d.", linenum
);
1558 else if (!strcmp(token
, "TEST-ID"))
1564 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1566 expand_variables(vars
, test_id
, temp
, sizeof(test_id
));
1570 print_fatal_error(outfile
, "Missing TEST-ID value on line %d.", linenum
);
1577 else if (!strcmp(token
, "TRANSFER"))
1585 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1587 if (!strcmp(temp
, "auto"))
1588 transfer
= _CUPS_TRANSFER_AUTO
;
1589 else if (!strcmp(temp
, "chunked"))
1590 transfer
= _CUPS_TRANSFER_CHUNKED
;
1591 else if (!strcmp(temp
, "length"))
1592 transfer
= _CUPS_TRANSFER_LENGTH
;
1595 print_fatal_error(outfile
, "Bad TRANSFER value \"%s\" on line %d.", temp
,
1603 print_fatal_error(outfile
, "Missing TRANSFER value on line %d.", linenum
);
1608 else if (!_cups_strcasecmp(token
, "VERSION"))
1610 if (get_token(fp
, temp
, sizeof(temp
), &linenum
))
1612 if (!strcmp(temp
, "0.0"))
1614 else if (!strcmp(temp
, "1.0"))
1616 else if (!strcmp(temp
, "1.1"))
1618 else if (!strcmp(temp
, "2.0"))
1620 else if (!strcmp(temp
, "2.1"))
1622 else if (!strcmp(temp
, "2.2"))
1626 print_fatal_error(outfile
, "Bad VERSION \"%s\" on line %d.", temp
, linenum
);
1633 print_fatal_error(outfile
, "Missing VERSION number on line %d.", linenum
);
1638 else if (!_cups_strcasecmp(token
, "RESOURCE"))
1644 if (!get_token(fp
, resource
, sizeof(resource
), &linenum
))
1646 print_fatal_error(outfile
, "Missing RESOURCE path on line %d.", linenum
);
1651 else if (!_cups_strcasecmp(token
, "OPERATION"))
1657 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1659 print_fatal_error(outfile
, "Missing OPERATION code on line %d.", linenum
);
1664 expand_variables(vars
, token
, temp
, sizeof(token
));
1666 if ((op
= ippOpValue(token
)) == (ipp_op_t
)-1 &&
1667 (op
= (ipp_op_t
)strtol(token
, NULL
, 0)) == 0)
1669 print_fatal_error(outfile
, "Bad OPERATION code \"%s\" on line %d.", token
,
1675 else if (!_cups_strcasecmp(token
, "GROUP"))
1678 * Attribute group...
1681 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1683 print_fatal_error(outfile
, "Missing GROUP tag on line %d.", linenum
);
1688 if ((value
= ippTagValue(token
)) == IPP_TAG_ZERO
|| value
>= IPP_TAG_UNSUPPORTED_VALUE
)
1690 print_fatal_error(outfile
, "Bad GROUP tag \"%s\" on line %d.", token
, linenum
);
1696 ippAddSeparator(request
);
1700 else if (!_cups_strcasecmp(token
, "DELAY"))
1703 * Delay before operation...
1706 double dval
; /* Delay value */
1708 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1710 print_fatal_error(outfile
, "Missing DELAY value on line %d.", linenum
);
1715 expand_variables(vars
, token
, temp
, sizeof(token
));
1717 if ((dval
= _cupsStrScand(token
, &tokenptr
, localeconv())) <= 0.0 || (*tokenptr
&& *tokenptr
!= ','))
1719 print_fatal_error(outfile
, "Bad DELAY value \"%s\" on line %d.", token
,
1725 delay
= (useconds_t
)(1000000.0 * dval
);
1727 if (*tokenptr
== ',')
1729 if ((dval
= _cupsStrScand(tokenptr
+ 1, &tokenptr
, localeconv())) <= 0.0 || *tokenptr
)
1731 print_fatal_error(outfile
, "Bad DELAY value \"%s\" on line %d.", token
,
1737 repeat_interval
= (useconds_t
)(1000000.0 * dval
);
1740 repeat_interval
= delay
;
1742 else if (!_cups_strcasecmp(token
, "ATTR"))
1748 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1750 print_fatal_error(outfile
, "Missing ATTR value tag on line %d.", linenum
);
1755 if ((value
= ippTagValue(token
)) < IPP_TAG_UNSUPPORTED_VALUE
)
1757 print_fatal_error(outfile
, "Bad ATTR value tag \"%s\" on line %d.", token
,
1763 if (!get_token(fp
, attr
, sizeof(attr
), &linenum
))
1765 print_fatal_error(outfile
, "Missing ATTR name on line %d.", linenum
);
1770 if (value
< IPP_TAG_INTEGER
)
1773 * Add out-of-band value - no value string needed...
1778 else if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
1780 print_fatal_error(outfile
, "Missing ATTR value on line %d.", linenum
);
1786 expand_variables(vars
, token
, temp
, sizeof(token
));
1794 if (value
< IPP_TAG_INTEGER
)
1797 * Add out-of-band value...
1800 attrptr
= ippAddOutOfBand(request
, group
, value
, attr
);
1804 print_fatal_error(outfile
, "Unsupported ATTR value tag %s for \"%s\" on line %d.", ippTagString(value
), attr
, linenum
);
1810 case IPP_TAG_BOOLEAN
:
1811 if (!_cups_strcasecmp(token
, "true"))
1812 attrptr
= ippAddBoolean(request
, group
, attr
, 1);
1814 attrptr
= ippAddBoolean(request
, group
, attr
, (char)atoi(token
));
1817 case IPP_TAG_INTEGER
:
1819 if (!strchr(token
, ','))
1821 if (isdigit(token
[0] & 255) || token
[0] == '-')
1822 attrptr
= ippAddInteger(request
, group
, value
, attr
, (int)strtol(token
, &tokenptr
, 0));
1826 if ((i
= ippEnumValue(attr
, tokenptr
)) >= 0)
1828 attrptr
= ippAddInteger(request
, group
, value
, attr
, i
);
1829 tokenptr
+= strlen(tokenptr
);
1835 int values
[100], /* Values */
1836 num_values
= 1; /* Number of values */
1838 if (!isdigit(token
[0] & 255) && token
[0] != '-' && value
== IPP_TAG_ENUM
)
1840 char *ptr
; /* Pointer to next terminator */
1842 if ((ptr
= strchr(token
, ',')) != NULL
)
1845 ptr
= token
+ strlen(token
);
1847 if ((i
= ippEnumValue(attr
, token
)) < 0)
1853 i
= (int)strtol(token
, &tokenptr
, 0);
1857 while (tokenptr
&& *tokenptr
&&
1858 num_values
< (int)(sizeof(values
) / sizeof(values
[0])))
1860 if (*tokenptr
== ',')
1863 if (!isdigit(*tokenptr
& 255) && *tokenptr
!= '-')
1865 char *ptr
; /* Pointer to next terminator */
1867 if (value
!= IPP_TAG_ENUM
)
1870 if ((ptr
= strchr(tokenptr
, ',')) != NULL
)
1873 ptr
= tokenptr
+ strlen(tokenptr
);
1875 if ((i
= ippEnumValue(attr
, tokenptr
)) < 0)
1881 i
= (int)strtol(tokenptr
, &tokenptr
, 0);
1883 values
[num_values
++] = i
;
1886 attrptr
= ippAddIntegers(request
, group
, value
, attr
, num_values
, values
);
1889 if ((!token
[0] || !tokenptr
|| *tokenptr
) && !skip_test
)
1891 print_fatal_error(outfile
, "Bad %s value \'%s\' for \"%s\" on line %d.",
1892 ippTagString(value
), token
, attr
, linenum
);
1898 case IPP_TAG_RESOLUTION
:
1900 int xres
, /* X resolution */
1901 yres
; /* Y resolution */
1902 char *ptr
; /* Pointer into value */
1904 xres
= yres
= (int)strtol(token
, (char **)&ptr
, 10);
1905 if (ptr
> token
&& xres
> 0)
1908 yres
= (int)strtol(ptr
+ 1, (char **)&ptr
, 10);
1911 if (ptr
<= token
|| xres
<= 0 || yres
<= 0 || !ptr
||
1912 (_cups_strcasecmp(ptr
, "dpi") &&
1913 _cups_strcasecmp(ptr
, "dpc") &&
1914 _cups_strcasecmp(ptr
, "dpcm") &&
1915 _cups_strcasecmp(ptr
, "other")))
1920 print_fatal_error(outfile
, "Bad resolution value \'%s\' for \"%s\" on line %d.", token
, attr
, linenum
);
1925 if (!_cups_strcasecmp(ptr
, "dpi"))
1926 attrptr
= ippAddResolution(request
, group
, attr
, IPP_RES_PER_INCH
, xres
, yres
);
1927 else if (!_cups_strcasecmp(ptr
, "dpc") ||
1928 !_cups_strcasecmp(ptr
, "dpcm"))
1929 attrptr
= ippAddResolution(request
, group
, attr
, IPP_RES_PER_CM
, xres
, yres
);
1931 attrptr
= ippAddResolution(request
, group
, attr
, (ipp_res_t
)0, xres
, yres
);
1935 case IPP_TAG_RANGE
:
1937 int lowers
[4], /* Lower value */
1938 uppers
[4], /* Upper values */
1939 num_vals
; /* Number of values */
1942 num_vals
= sscanf(token
, "%d-%d,%d-%d,%d-%d,%d-%d",
1943 lowers
+ 0, uppers
+ 0,
1944 lowers
+ 1, uppers
+ 1,
1945 lowers
+ 2, uppers
+ 2,
1946 lowers
+ 3, uppers
+ 3);
1948 if ((num_vals
& 1) || num_vals
== 0)
1953 print_fatal_error(outfile
, "Bad rangeOfInteger value \'%s\' for \"%s\" on line %d.", token
, attr
, linenum
);
1958 attrptr
= ippAddRanges(request
, group
, attr
, num_vals
/ 2, lowers
,
1963 case IPP_TAG_BEGIN_COLLECTION
:
1964 if (!strcmp(token
, "{"))
1966 ipp_t
*col
= get_collection(outfile
, vars
, fp
, &linenum
);
1967 /* Collection value */
1971 attrptr
= lastcol
= ippAddCollection(request
, group
, attr
, col
);
1984 print_fatal_error(outfile
, "Bad ATTR collection value for \"%s\" on line %d.", attr
, linenum
);
1991 ipp_t
*col
; /* Collection value */
1992 off_t savepos
= cupsFileTell(fp
); /* Save position of file */
1993 int savelinenum
= linenum
; /* Save line number */
1995 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
1998 if (strcmp(token
, ","))
2000 cupsFileSeek(fp
, savepos
);
2001 linenum
= savelinenum
;
2005 if (!get_token(fp
, token
, sizeof(token
), &linenum
) || strcmp(token
, "{"))
2007 print_fatal_error(outfile
, "Unexpected \"%s\" on line %d.", token
, linenum
);
2013 if ((col
= get_collection(outfile
, vars
, fp
, &linenum
)) == NULL
)
2016 ippSetCollection(request
, &attrptr
, ippGetCount(attrptr
), col
);
2019 while (!strcmp(token
, "{"));
2022 case IPP_TAG_STRING
:
2023 attrptr
= ippAddOctetString(request
, group
, attr
, token
, (int)strlen(token
));
2026 case IPP_TAG_TEXTLANG
:
2027 case IPP_TAG_NAMELANG
:
2030 case IPP_TAG_KEYWORD
:
2032 case IPP_TAG_URISCHEME
:
2033 case IPP_TAG_CHARSET
:
2034 case IPP_TAG_LANGUAGE
:
2035 case IPP_TAG_MIMETYPE
:
2036 if (!strchr(token
, ','))
2037 attrptr
= ippAddString(request
, group
, value
, attr
, NULL
, token
);
2041 * Multiple string values...
2044 int num_values
; /* Number of values */
2045 char *values
[100], /* Values */
2046 *ptr
; /* Pointer to next value */
2052 for (ptr
= strchr(token
, ','); ptr
; ptr
= strchr(ptr
, ','))
2054 if (ptr
> token
&& ptr
[-1] == '\\')
2055 _cups_strcpy(ptr
- 1, ptr
);
2059 values
[num_values
] = ptr
;
2064 attrptr
= ippAddStrings(request
, group
, value
, attr
, num_values
,
2065 NULL
, (const char **)values
);
2070 if (!attrptr
&& !skip_test
)
2072 print_fatal_error(outfile
, "Unable to add attribute \"%s\" on line %d.", attr
, linenum
);
2077 else if (!_cups_strcasecmp(token
, "FILE"))
2083 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
2085 print_fatal_error(outfile
, "Missing FILE filename on line %d.", linenum
);
2090 expand_variables(vars
, token
, temp
, sizeof(token
));
2091 get_filename(testfile
, filename
, token
, sizeof(filename
));
2093 if (access(filename
, R_OK
))
2095 print_fatal_error(outfile
, "Filename \"%s\" on line %d cannot be read.",
2097 print_fatal_error(outfile
, "Filename mapped to \"%s\".", filename
);
2102 else if (!_cups_strcasecmp(token
, "STATUS"))
2108 if (num_statuses
>= (int)(sizeof(statuses
) / sizeof(statuses
[0])))
2110 print_fatal_error(outfile
, "Too many STATUS's on line %d.", linenum
);
2115 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2117 print_fatal_error(outfile
, "Missing STATUS code on line %d.", linenum
);
2122 if ((statuses
[num_statuses
].status
= ippErrorValue(token
))
2123 == (ipp_status_t
)-1 &&
2124 (statuses
[num_statuses
].status
= (ipp_status_t
)strtol(token
, NULL
, 0)) == 0)
2126 print_fatal_error(outfile
, "Bad STATUS code \"%s\" on line %d.", token
,
2132 last_status
= statuses
+ num_statuses
;
2135 last_status
->define_match
= NULL
;
2136 last_status
->define_no_match
= NULL
;
2137 last_status
->if_defined
= NULL
;
2138 last_status
->if_not_defined
= NULL
;
2139 last_status
->repeat_limit
= 1000;
2140 last_status
->repeat_match
= 0;
2141 last_status
->repeat_no_match
= 0;
2143 else if (!_cups_strcasecmp(token
, "EXPECT") || !_cups_strcasecmp(token
, "EXPECT-ALL"))
2146 * Expected attributes...
2149 int expect_all
= !_cups_strcasecmp(token
, "EXPECT-ALL");
2151 if (num_expects
>= (int)(sizeof(expects
) / sizeof(expects
[0])))
2153 print_fatal_error(outfile
, "Too many EXPECT's on line %d.", linenum
);
2158 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2160 print_fatal_error(outfile
, "Missing EXPECT name on line %d.", linenum
);
2165 last_expect
= expects
+ num_expects
;
2168 memset(last_expect
, 0, sizeof(_cups_expect_t
));
2169 last_expect
->repeat_limit
= 1000;
2170 last_expect
->expect_all
= expect_all
;
2172 if (token
[0] == '!')
2174 last_expect
->not_expect
= 1;
2175 last_expect
->name
= strdup(token
+ 1);
2177 else if (token
[0] == '?')
2179 last_expect
->optional
= 1;
2180 last_expect
->name
= strdup(token
+ 1);
2183 last_expect
->name
= strdup(token
);
2185 else if (!_cups_strcasecmp(token
, "COUNT"))
2187 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2189 print_fatal_error(outfile
, "Missing COUNT number on line %d.", linenum
);
2194 if ((i
= atoi(token
)) <= 0)
2196 print_fatal_error(outfile
, "Bad COUNT \"%s\" on line %d.", token
, linenum
);
2202 last_expect
->count
= i
;
2205 print_fatal_error(outfile
, "COUNT without a preceding EXPECT on line %d.",
2211 else if (!_cups_strcasecmp(token
, "DEFINE-MATCH"))
2213 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2215 print_fatal_error(outfile
, "Missing DEFINE-MATCH variable on line %d.",
2222 last_expect
->define_match
= strdup(token
);
2223 else if (last_status
)
2224 last_status
->define_match
= strdup(token
);
2227 print_fatal_error(outfile
, "DEFINE-MATCH without a preceding EXPECT or STATUS "
2228 "on line %d.", linenum
);
2233 else if (!_cups_strcasecmp(token
, "DEFINE-NO-MATCH"))
2235 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2237 print_fatal_error(outfile
, "Missing DEFINE-NO-MATCH variable on line %d.",
2244 last_expect
->define_no_match
= strdup(token
);
2245 else if (last_status
)
2246 last_status
->define_no_match
= strdup(token
);
2249 print_fatal_error(outfile
, "DEFINE-NO-MATCH without a preceding EXPECT or "
2250 "STATUS on line %d.", linenum
);
2255 else if (!_cups_strcasecmp(token
, "DEFINE-VALUE"))
2257 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2259 print_fatal_error(outfile
, "Missing DEFINE-VALUE variable on line %d.",
2266 last_expect
->define_value
= strdup(token
);
2269 print_fatal_error(outfile
, "DEFINE-VALUE without a preceding EXPECT on "
2270 "line %d.", linenum
);
2275 else if (!_cups_strcasecmp(token
, "OF-TYPE"))
2277 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2279 print_fatal_error(outfile
, "Missing OF-TYPE value tag(s) on line %d.",
2286 last_expect
->of_type
= strdup(token
);
2289 print_fatal_error(outfile
, "OF-TYPE without a preceding EXPECT on line %d.",
2295 else if (!_cups_strcasecmp(token
, "IN-GROUP"))
2297 ipp_tag_t in_group
; /* IN-GROUP value */
2300 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2302 print_fatal_error(outfile
, "Missing IN-GROUP group tag on line %d.", linenum
);
2307 if ((in_group
= ippTagValue(token
)) == IPP_TAG_ZERO
|| in_group
>= IPP_TAG_UNSUPPORTED_VALUE
)
2309 print_fatal_error(outfile
, "Bad IN-GROUP group tag \"%s\" on line %d.", token
, linenum
);
2313 else if (last_expect
)
2314 last_expect
->in_group
= in_group
;
2317 print_fatal_error(outfile
, "IN-GROUP without a preceding EXPECT on line %d.", linenum
);
2322 else if (!_cups_strcasecmp(token
, "REPEAT-LIMIT"))
2324 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2326 print_fatal_error(outfile
, "Missing REPEAT-LIMIT value on line %d.", linenum
);
2330 else if (atoi(token
) <= 0)
2332 print_fatal_error(outfile
, "Bad REPEAT-LIMIT value on line %d.", linenum
);
2338 last_status
->repeat_limit
= atoi(token
);
2339 else if (last_expect
)
2340 last_expect
->repeat_limit
= atoi(token
);
2343 print_fatal_error(outfile
, "REPEAT-LIMIT without a preceding EXPECT or STATUS on line %d.", linenum
);
2348 else if (!_cups_strcasecmp(token
, "REPEAT-MATCH"))
2351 last_status
->repeat_match
= 1;
2352 else if (last_expect
)
2353 last_expect
->repeat_match
= 1;
2356 print_fatal_error(outfile
, "REPEAT-MATCH without a preceding EXPECT or STATUS on line %d.", linenum
);
2361 else if (!_cups_strcasecmp(token
, "REPEAT-NO-MATCH"))
2364 last_status
->repeat_no_match
= 1;
2365 else if (last_expect
)
2366 last_expect
->repeat_no_match
= 1;
2369 print_fatal_error(outfile
, "REPEAT-NO-MATCH without a preceding EXPECT or STATUS on ine %d.", linenum
);
2374 else if (!_cups_strcasecmp(token
, "SAME-COUNT-AS"))
2376 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2378 print_fatal_error(outfile
, "Missing SAME-COUNT-AS name on line %d.", linenum
);
2384 last_expect
->same_count_as
= strdup(token
);
2387 print_fatal_error(outfile
, "SAME-COUNT-AS without a preceding EXPECT on line "
2393 else if (!_cups_strcasecmp(token
, "IF-DEFINED"))
2395 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2397 print_fatal_error(outfile
, "Missing IF-DEFINED name on line %d.", linenum
);
2403 last_expect
->if_defined
= strdup(token
);
2404 else if (last_status
)
2405 last_status
->if_defined
= strdup(token
);
2408 print_fatal_error(outfile
, "IF-DEFINED without a preceding EXPECT or STATUS on line %d.", linenum
);
2413 else if (!_cups_strcasecmp(token
, "IF-NOT-DEFINED"))
2415 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2417 print_fatal_error(outfile
, "Missing IF-NOT-DEFINED name on line %d.", linenum
);
2423 last_expect
->if_not_defined
= strdup(token
);
2424 else if (last_status
)
2425 last_status
->if_not_defined
= strdup(token
);
2428 print_fatal_error(outfile
, "IF-NOT-DEFINED without a preceding EXPECT or STATUS on line %d.", linenum
);
2433 else if (!_cups_strcasecmp(token
, "WITH-ALL-VALUES") ||
2434 !_cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") ||
2435 !_cups_strcasecmp(token
, "WITH-ALL-RESOURCES") ||
2436 !_cups_strcasecmp(token
, "WITH-ALL-SCHEMES") ||
2437 !_cups_strcasecmp(token
, "WITH-HOSTNAME") ||
2438 !_cups_strcasecmp(token
, "WITH-RESOURCE") ||
2439 !_cups_strcasecmp(token
, "WITH-SCHEME") ||
2440 !_cups_strcasecmp(token
, "WITH-VALUE"))
2444 if (!_cups_strcasecmp(token
, "WITH-ALL-HOSTNAMES") ||
2445 !_cups_strcasecmp(token
, "WITH-HOSTNAME"))
2446 last_expect
->with_flags
= _CUPS_WITH_HOSTNAME
;
2447 else if (!_cups_strcasecmp(token
, "WITH-ALL-RESOURCES") ||
2448 !_cups_strcasecmp(token
, "WITH-RESOURCE"))
2449 last_expect
->with_flags
= _CUPS_WITH_RESOURCE
;
2450 else if (!_cups_strcasecmp(token
, "WITH-ALL-SCHEMES") ||
2451 !_cups_strcasecmp(token
, "WITH-SCHEME"))
2452 last_expect
->with_flags
= _CUPS_WITH_SCHEME
;
2454 if (!_cups_strncasecmp(token
, "WITH-ALL-", 9))
2455 last_expect
->with_flags
|= _CUPS_WITH_ALL
;
2458 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
2460 print_fatal_error(outfile
, "Missing %s value on line %d.", token
, linenum
);
2468 * Expand any variables in the value and then save it.
2471 expand_variables(vars
, token
, temp
, sizeof(token
));
2473 tokenptr
= token
+ strlen(token
) - 1;
2475 if (token
[0] == '/' && tokenptr
> token
&& *tokenptr
== '/')
2478 * WITH-VALUE is a POSIX extended regular expression.
2481 last_expect
->with_value
= calloc(1, (size_t)(tokenptr
- token
));
2482 last_expect
->with_flags
|= _CUPS_WITH_REGEX
;
2484 if (last_expect
->with_value
)
2485 memcpy(last_expect
->with_value
, token
+ 1, (size_t)(tokenptr
- token
- 1));
2490 * WITH-VALUE is a literal value...
2493 char *ptr
; /* Pointer into value */
2495 for (ptr
= token
; *ptr
; ptr
++)
2497 if (*ptr
== '\\' && ptr
[1])
2500 * Remove \ from \foo...
2503 _cups_strcpy(ptr
, ptr
+ 1);
2507 last_expect
->with_value
= strdup(token
);
2508 last_expect
->with_flags
|= _CUPS_WITH_LITERAL
;
2513 print_fatal_error(outfile
, "%s without a preceding EXPECT on line %d.", token
, linenum
);
2518 else if (!_cups_strcasecmp(token
, "WITH-VALUE-FROM"))
2520 if (!get_token(fp
, temp
, sizeof(temp
), &linenum
))
2522 print_fatal_error(outfile
, "Missing %s value on line %d.", token
, linenum
);
2530 * Expand any variables in the value and then save it.
2533 expand_variables(vars
, token
, temp
, sizeof(token
));
2535 last_expect
->with_value_from
= strdup(token
);
2536 last_expect
->with_flags
= _CUPS_WITH_LITERAL
;
2540 print_fatal_error(outfile
, "%s without a preceding EXPECT on line %d.", token
, linenum
);
2545 else if (!_cups_strcasecmp(token
, "DISPLAY"))
2548 * Display attributes...
2551 if (num_displayed
>= (int)(sizeof(displayed
) / sizeof(displayed
[0])))
2553 print_fatal_error(outfile
, "Too many DISPLAY's on line %d", linenum
);
2558 if (!get_token(fp
, token
, sizeof(token
), &linenum
))
2560 print_fatal_error(outfile
, "Missing DISPLAY name on line %d.", linenum
);
2565 displayed
[num_displayed
] = strdup(token
);
2570 print_fatal_error(outfile
, "Unexpected token %s seen on line %d.", token
, linenum
);
2577 * Submit the IPP request...
2582 ippSetVersion(request
, version
/ 10, version
% 10);
2583 ippSetOperation(request
, op
);
2584 ippSetRequestId(request
, request_id
);
2586 if (Output
== _CUPS_OUTPUT_PLIST
)
2588 cupsFilePuts(outfile
, "<dict>\n");
2589 cupsFilePuts(outfile
, "<key>Name</key>\n");
2590 print_xml_string(outfile
, "string", name
);
2593 cupsFilePuts(outfile
, "<key>FileId</key>\n");
2594 print_xml_string(outfile
, "string", file_id
);
2598 cupsFilePuts(outfile
, "<key>TestId</key>\n");
2599 print_xml_string(outfile
, "string", test_id
);
2601 cupsFilePuts(outfile
, "<key>Version</key>\n");
2602 cupsFilePrintf(outfile
, "<string>%d.%d</string>\n", version
/ 10, version
% 10);
2603 cupsFilePuts(outfile
, "<key>Operation</key>\n");
2604 print_xml_string(outfile
, "string", ippOpString(op
));
2605 cupsFilePuts(outfile
, "<key>RequestId</key>\n");
2606 cupsFilePrintf(outfile
, "<integer>%d</integer>\n", request_id
);
2607 cupsFilePuts(outfile
, "<key>RequestAttributes</key>\n");
2608 cupsFilePuts(outfile
, "<array>\n");
2611 cupsFilePuts(outfile
, "<dict>\n");
2612 for (attrptr
= request
->attrs
,
2613 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
2615 attrptr
= attrptr
->next
)
2616 print_attr(outfile
, Output
, attrptr
, &group
);
2617 cupsFilePuts(outfile
, "</dict>\n");
2619 cupsFilePuts(outfile
, "</array>\n");
2622 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
2626 printf(" %s:\n", ippOpString(op
));
2628 for (attrptr
= request
->attrs
; attrptr
; attrptr
= attrptr
->next
)
2629 print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST
, attrptr
, NULL
);
2632 cupsFilePrintf(cupsFileStdout(), " %-68.68s [", name
);
2633 cupsFileFlush(cupsFileStdout());
2636 if ((skip_previous
&& !prev_pass
) || skip_test
)
2643 if (Output
== _CUPS_OUTPUT_PLIST
)
2645 cupsFilePuts(outfile
, "<key>Successful</key>\n");
2646 cupsFilePuts(outfile
, "<true />\n");
2647 cupsFilePuts(outfile
, "<key>Skipped</key>\n");
2648 cupsFilePuts(outfile
, "<true />\n");
2649 cupsFilePuts(outfile
, "<key>StatusCode</key>\n");
2650 print_xml_string(outfile
, "string", "skip");
2651 cupsFilePuts(outfile
, "<key>ResponseAttributes</key>\n");
2652 cupsFilePuts(outfile
, "<dict />\n");
2655 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
2656 cupsFilePuts(cupsFileStdout(), "SKIP]");
2668 delay
= repeat_interval
;
2671 status
= HTTP_STATUS_OK
;
2673 if (transfer
== _CUPS_TRANSFER_CHUNKED
||
2674 (transfer
== _CUPS_TRANSFER_AUTO
&& filename
[0]))
2677 * Send request using chunking - a 0 length means "chunk".
2685 * Send request using content length...
2688 length
= ippLength(request
);
2690 if (filename
[0] && (reqfile
= cupsFileOpen(filename
, "r")) != NULL
)
2693 * Read the file to get the uncompressed file size...
2696 while ((bytes
= cupsFileRead(reqfile
, buffer
, sizeof(buffer
))) > 0)
2697 length
+= (size_t)bytes
;
2699 cupsFileClose(reqfile
);
2704 * Send the request...
2711 if (status
!= HTTP_STATUS_ERROR
)
2713 while (!response
&& !Cancel
&& prev_pass
)
2715 status
= cupsSendRequest(http
, request
, resource
, length
);
2719 httpSetField(http
, HTTP_FIELD_CONTENT_ENCODING
, compression
);
2720 #endif /* HAVE_LIBZ */
2722 if (!Cancel
&& status
== HTTP_STATUS_CONTINUE
&&
2723 request
->state
== IPP_DATA
&& filename
[0])
2725 if ((reqfile
= cupsFileOpen(filename
, "r")) != NULL
)
2728 (bytes
= cupsFileRead(reqfile
, buffer
, sizeof(buffer
))) > 0)
2729 if ((status
= cupsWriteRequestData(http
, buffer
, (size_t)bytes
)) != HTTP_STATUS_CONTINUE
)
2732 cupsFileClose(reqfile
);
2736 snprintf(buffer
, sizeof(buffer
), "%s: %s", filename
,
2738 _cupsSetError(IPP_INTERNAL_ERROR
, buffer
, 0);
2740 status
= HTTP_STATUS_ERROR
;
2745 * Get the server's response...
2748 if (!Cancel
&& status
!= HTTP_STATUS_ERROR
)
2750 response
= cupsGetResponse(http
, resource
);
2751 status
= httpGetStatus(http
);
2754 if (!Cancel
&& status
== HTTP_STATUS_ERROR
&& http
->error
!= EINVAL
&&
2756 http
->error
!= WSAETIMEDOUT
)
2758 http
->error
!= ETIMEDOUT
)
2761 if (httpReconnect2(http
, 30000, NULL
))
2764 else if (status
== HTTP_STATUS_ERROR
|| status
== HTTP_STATUS_CUPS_AUTHORIZATION_CANCELED
)
2769 else if (status
!= HTTP_STATUS_OK
)
2773 if (status
== HTTP_STATUS_UNAUTHORIZED
)
2781 if (!Cancel
&& status
== HTTP_STATUS_ERROR
&& http
->error
!= EINVAL
&&
2783 http
->error
!= WSAETIMEDOUT
)
2785 http
->error
!= ETIMEDOUT
)
2788 if (httpReconnect2(http
, 30000, NULL
))
2791 else if (status
== HTTP_STATUS_ERROR
)
2794 httpReconnect2(http
, 30000, NULL
);
2798 else if (status
!= HTTP_STATUS_OK
)
2805 * Check results of request...
2808 cupsArrayClear(errors
);
2810 if (http
->version
!= HTTP_1_1
)
2811 add_stringf(errors
, "Bad HTTP version (%d.%d)", http
->version
/ 100,
2812 http
->version
% 100);
2817 * No response, log error...
2820 add_stringf(errors
, "IPP request failed with status %s (%s)",
2821 ippErrorString(cupsLastError()),
2822 cupsLastErrorString());
2827 * Collect common attribute values...
2830 if ((attrptr
= ippFindAttribute(response
, "job-id",
2831 IPP_TAG_INTEGER
)) != NULL
)
2833 snprintf(temp
, sizeof(temp
), "%d", attrptr
->values
[0].integer
);
2834 set_variable(outfile
, vars
, "job-id", temp
);
2837 if ((attrptr
= ippFindAttribute(response
, "job-uri",
2838 IPP_TAG_URI
)) != NULL
)
2839 set_variable(outfile
, vars
, "job-uri", attrptr
->values
[0].string
.text
);
2841 if ((attrptr
= ippFindAttribute(response
, "notify-subscription-id",
2842 IPP_TAG_INTEGER
)) != NULL
)
2844 snprintf(temp
, sizeof(temp
), "%d", attrptr
->values
[0].integer
);
2845 set_variable(outfile
, vars
, "notify-subscription-id", temp
);
2849 * Check response, validating groups and attributes and logging errors
2853 if (response
->state
!= IPP_DATA
)
2855 "Missing end-of-attributes-tag in response "
2856 "(RFC 2910 section 3.5.1)");
2859 (response
->request
.status
.version
[0] != (version
/ 10) ||
2860 response
->request
.status
.version
[1] != (version
% 10)))
2862 "Bad version %d.%d in response - expected %d.%d "
2863 "(RFC 2911 section 3.1.8).",
2864 response
->request
.status
.version
[0],
2865 response
->request
.status
.version
[1],
2866 version
/ 10, version
% 10);
2868 if (response
->request
.status
.request_id
!= request_id
)
2870 "Bad request ID %d in response - expected %d "
2871 "(RFC 2911 section 3.1.1)",
2872 response
->request
.status
.request_id
, request_id
);
2874 attrptr
= response
->attrs
;
2877 "Missing first attribute \"attributes-charset "
2878 "(charset)\" in group operation-attributes-tag "
2879 "(RFC 2911 section 3.1.4).");
2882 if (!attrptr
->name
||
2883 attrptr
->value_tag
!= IPP_TAG_CHARSET
||
2884 attrptr
->group_tag
!= IPP_TAG_OPERATION
||
2885 attrptr
->num_values
!= 1 ||
2886 strcmp(attrptr
->name
, "attributes-charset"))
2888 "Bad first attribute \"%s (%s%s)\" in group %s, "
2889 "expected \"attributes-charset (charset)\" in "
2890 "group operation-attributes-tag (RFC 2911 section "
2892 attrptr
->name
? attrptr
->name
: "(null)",
2893 attrptr
->num_values
> 1 ? "1setOf " : "",
2894 ippTagString(attrptr
->value_tag
),
2895 ippTagString(attrptr
->group_tag
));
2897 attrptr
= attrptr
->next
;
2900 "Missing second attribute \"attributes-natural-"
2901 "language (naturalLanguage)\" in group "
2902 "operation-attributes-tag (RFC 2911 section "
2904 else if (!attrptr
->name
||
2905 attrptr
->value_tag
!= IPP_TAG_LANGUAGE
||
2906 attrptr
->group_tag
!= IPP_TAG_OPERATION
||
2907 attrptr
->num_values
!= 1 ||
2908 strcmp(attrptr
->name
, "attributes-natural-language"))
2910 "Bad first attribute \"%s (%s%s)\" in group %s, "
2911 "expected \"attributes-natural-language "
2912 "(naturalLanguage)\" in group "
2913 "operation-attributes-tag (RFC 2911 section "
2915 attrptr
->name
? attrptr
->name
: "(null)",
2916 attrptr
->num_values
> 1 ? "1setOf " : "",
2917 ippTagString(attrptr
->value_tag
),
2918 ippTagString(attrptr
->group_tag
));
2921 if ((attrptr
= ippFindAttribute(response
, "status-message",
2922 IPP_TAG_ZERO
)) != NULL
)
2924 if (attrptr
->value_tag
!= IPP_TAG_TEXT
)
2926 "status-message (text(255)) has wrong value tag "
2927 "%s (RFC 2911 section 3.1.6.2).",
2928 ippTagString(attrptr
->value_tag
));
2929 if (attrptr
->group_tag
!= IPP_TAG_OPERATION
)
2931 "status-message (text(255)) has wrong group tag "
2932 "%s (RFC 2911 section 3.1.6.2).",
2933 ippTagString(attrptr
->group_tag
));
2934 if (attrptr
->num_values
!= 1)
2936 "status-message (text(255)) has %d values "
2937 "(RFC 2911 section 3.1.6.2).",
2938 attrptr
->num_values
);
2939 if (attrptr
->value_tag
== IPP_TAG_TEXT
&&
2940 strlen(attrptr
->values
[0].string
.text
) > 255)
2942 "status-message (text(255)) has bad length %d"
2943 " (RFC 2911 section 3.1.6.2).",
2944 (int)strlen(attrptr
->values
[0].string
.text
));
2947 if ((attrptr
= ippFindAttribute(response
, "detailed-status-message",
2948 IPP_TAG_ZERO
)) != NULL
)
2950 if (attrptr
->value_tag
!= IPP_TAG_TEXT
)
2952 "detailed-status-message (text(MAX)) has wrong "
2953 "value tag %s (RFC 2911 section 3.1.6.3).",
2954 ippTagString(attrptr
->value_tag
));
2955 if (attrptr
->group_tag
!= IPP_TAG_OPERATION
)
2957 "detailed-status-message (text(MAX)) has wrong "
2958 "group tag %s (RFC 2911 section 3.1.6.3).",
2959 ippTagString(attrptr
->group_tag
));
2960 if (attrptr
->num_values
!= 1)
2962 "detailed-status-message (text(MAX)) has %d values"
2963 " (RFC 2911 section 3.1.6.3).",
2964 attrptr
->num_values
);
2965 if (attrptr
->value_tag
== IPP_TAG_TEXT
&&
2966 strlen(attrptr
->values
[0].string
.text
) > 1023)
2968 "detailed-status-message (text(MAX)) has bad "
2969 "length %d (RFC 2911 section 3.1.6.3).",
2970 (int)strlen(attrptr
->values
[0].string
.text
));
2973 a
= cupsArrayNew((cups_array_func_t
)strcmp
, NULL
);
2975 for (attrptr
= response
->attrs
,
2976 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
2978 attrptr
= attrptr
->next
)
2980 if (attrptr
->group_tag
!= group
)
2982 int out_of_order
= 0; /* Are attribute groups out-of-order? */
2985 switch (attrptr
->group_tag
)
2990 case IPP_TAG_OPERATION
:
2994 case IPP_TAG_UNSUPPORTED_GROUP
:
2995 if (group
!= IPP_TAG_OPERATION
)
3000 case IPP_TAG_PRINTER
:
3001 if (group
!= IPP_TAG_OPERATION
&&
3002 group
!= IPP_TAG_UNSUPPORTED_GROUP
)
3006 case IPP_TAG_SUBSCRIPTION
:
3007 if (group
> attrptr
->group_tag
&&
3008 group
!= IPP_TAG_DOCUMENT
)
3013 if (group
> attrptr
->group_tag
)
3019 add_stringf(errors
, "Attribute groups out of order (%s < %s)",
3020 ippTagString(attrptr
->group_tag
),
3021 ippTagString(group
));
3023 if (attrptr
->group_tag
!= IPP_TAG_ZERO
)
3024 group
= attrptr
->group_tag
;
3027 validate_attr(outfile
, errors
, attrptr
);
3031 if (cupsArrayFind(a
, attrptr
->name
))
3032 add_stringf(errors
, "Duplicate \"%s\" attribute in %s group",
3033 attrptr
->name
, ippTagString(group
));
3035 cupsArrayAdd(a
, attrptr
->name
);
3042 * Now check the test-defined expected status-code and attribute
3046 for (i
= 0, status_ok
= 0; i
< num_statuses
; i
++)
3048 if (statuses
[i
].if_defined
&&
3049 !get_variable(vars
, statuses
[i
].if_defined
))
3052 if (statuses
[i
].if_not_defined
&&
3053 get_variable(vars
, statuses
[i
].if_not_defined
))
3056 if (ippGetStatusCode(response
) == statuses
[i
].status
)
3060 if (statuses
[i
].repeat_match
&& repeat_count
< statuses
[i
].repeat_limit
)
3063 if (statuses
[i
].define_match
)
3064 set_variable(outfile
, vars
, statuses
[i
].define_match
, "1");
3068 if (statuses
[i
].repeat_no_match
&& repeat_count
< statuses
[i
].repeat_limit
)
3071 if (statuses
[i
].define_no_match
)
3073 set_variable(outfile
, vars
, statuses
[i
].define_no_match
, "1");
3079 if (!status_ok
&& num_statuses
> 0)
3081 for (i
= 0; i
< num_statuses
; i
++)
3083 if (statuses
[i
].if_defined
&&
3084 !get_variable(vars
, statuses
[i
].if_defined
))
3087 if (statuses
[i
].if_not_defined
&&
3088 get_variable(vars
, statuses
[i
].if_not_defined
))
3091 if (!statuses
[i
].repeat_match
|| repeat_count
>= statuses
[i
].repeat_limit
)
3092 add_stringf(errors
, "EXPECTED: STATUS %s (got %s)",
3093 ippErrorString(statuses
[i
].status
),
3094 ippErrorString(cupsLastError()));
3097 if ((attrptr
= ippFindAttribute(response
, "status-message",
3098 IPP_TAG_TEXT
)) != NULL
)
3099 add_stringf(errors
, "status-message=\"%s\"",
3100 attrptr
->values
[0].string
.text
);
3103 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
3105 if (expect
->if_defined
&& !get_variable(vars
, expect
->if_defined
))
3108 if (expect
->if_not_defined
&&
3109 get_variable(vars
, expect
->if_not_defined
))
3112 found
= ippFindAttribute(response
, expect
->name
, IPP_TAG_ZERO
);
3116 if ((found
&& expect
->not_expect
) ||
3117 (!found
&& !(expect
->not_expect
|| expect
->optional
)) ||
3118 (found
&& !expect_matches(expect
, found
->value_tag
)) ||
3119 (found
&& expect
->in_group
&&
3120 found
->group_tag
!= expect
->in_group
))
3122 if (expect
->define_no_match
)
3123 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3124 else if (!expect
->define_match
&& !expect
->define_value
)
3126 if (found
&& expect
->not_expect
)
3127 add_stringf(errors
, "NOT EXPECTED: %s", expect
->name
);
3128 else if (!found
&& !(expect
->not_expect
|| expect
->optional
))
3129 add_stringf(errors
, "EXPECTED: %s", expect
->name
);
3132 if (!expect_matches(expect
, found
->value_tag
))
3133 add_stringf(errors
, "EXPECTED: %s OF-TYPE %s (got %s)",
3134 expect
->name
, expect
->of_type
,
3135 ippTagString(found
->value_tag
));
3137 if (expect
->in_group
&& found
->group_tag
!= expect
->in_group
)
3138 add_stringf(errors
, "EXPECTED: %s IN-GROUP %s (got %s).",
3139 expect
->name
, ippTagString(expect
->in_group
),
3140 ippTagString(found
->group_tag
));
3144 if (expect
->repeat_no_match
&& repeat_count
< expect
->repeat_limit
)
3151 ippAttributeString(found
, buffer
, sizeof(buffer
));
3153 if (found
&& expect
->with_value_from
&& !with_value_from(NULL
, ippFindAttribute(response
, expect
->with_value_from
, IPP_TAG_ZERO
), found
, buffer
, sizeof(buffer
)))
3155 if (expect
->define_no_match
)
3156 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3157 else if (!expect
->define_match
&& !expect
->define_value
&& ((!expect
->repeat_match
&& !expect
->repeat_no_match
) || repeat_count
>= expect
->repeat_limit
))
3159 add_stringf(errors
, "EXPECTED: %s WITH-VALUES-FROM %s", expect
->name
, expect
->with_value_from
);
3161 with_value_from(errors
, ippFindAttribute(response
, expect
->with_value_from
, IPP_TAG_ZERO
), found
, buffer
, sizeof(buffer
));
3164 if (expect
->repeat_no_match
&& repeat_count
< expect
->repeat_limit
)
3169 else if (found
&& !with_value(outfile
, NULL
, expect
->with_value
, expect
->with_flags
, found
, buffer
, sizeof(buffer
)))
3171 if (expect
->define_no_match
)
3172 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3173 else if (!expect
->define_match
&& !expect
->define_value
&&
3174 !expect
->repeat_match
&& (!expect
->repeat_no_match
|| repeat_count
>= expect
->repeat_limit
))
3176 if (expect
->with_flags
& _CUPS_WITH_REGEX
)
3177 add_stringf(errors
, "EXPECTED: %s %s /%s/",
3179 (expect
->with_flags
& _CUPS_WITH_ALL
) ?
3180 "WITH-ALL-VALUES" : "WITH-VALUE",
3181 expect
->with_value
);
3183 add_stringf(errors
, "EXPECTED: %s %s \"%s\"",
3185 (expect
->with_flags
& _CUPS_WITH_ALL
) ?
3186 "WITH-ALL-VALUES" : "WITH-VALUE",
3187 expect
->with_value
);
3189 with_value(outfile
, errors
, expect
->with_value
, expect
->with_flags
, found
,
3190 buffer
, sizeof(buffer
));
3193 if (expect
->repeat_no_match
&&
3194 repeat_count
< expect
->repeat_limit
)
3200 if (found
&& expect
->count
> 0 &&
3201 found
->num_values
!= expect
->count
)
3203 if (expect
->define_no_match
)
3204 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3205 else if (!expect
->define_match
&& !expect
->define_value
)
3207 add_stringf(errors
, "EXPECTED: %s COUNT %d (got %d)", expect
->name
,
3208 expect
->count
, found
->num_values
);
3211 if (expect
->repeat_no_match
&&
3212 repeat_count
< expect
->repeat_limit
)
3218 if (found
&& expect
->same_count_as
)
3220 attrptr
= ippFindAttribute(response
, expect
->same_count_as
,
3223 if (!attrptr
|| attrptr
->num_values
!= found
->num_values
)
3225 if (expect
->define_no_match
)
3226 set_variable(outfile
, vars
, expect
->define_no_match
, "1");
3227 else if (!expect
->define_match
&& !expect
->define_value
)
3231 "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
3232 "(not returned)", expect
->name
,
3233 found
->num_values
, expect
->same_count_as
);
3234 else if (attrptr
->num_values
!= found
->num_values
)
3236 "EXPECTED: %s (%d values) SAME-COUNT-AS %s "
3237 "(%d values)", expect
->name
, found
->num_values
,
3238 expect
->same_count_as
, attrptr
->num_values
);
3241 if (expect
->repeat_no_match
&&
3242 repeat_count
< expect
->repeat_limit
)
3249 if (found
&& expect
->define_match
)
3250 set_variable(outfile
, vars
, expect
->define_match
, "1");
3252 if (found
&& expect
->define_value
)
3254 if (!expect
->with_value
)
3256 int last
= ippGetCount(found
) - 1;
3257 /* Last element in attribute */
3259 switch (ippGetValueTag(found
))
3262 case IPP_TAG_INTEGER
:
3263 snprintf(buffer
, sizeof(buffer
), "%d", ippGetInteger(found
, last
));
3266 case IPP_TAG_BOOLEAN
:
3267 if (ippGetBoolean(found
, last
))
3268 strlcpy(buffer
, "true", sizeof(buffer
));
3270 strlcpy(buffer
, "false", sizeof(buffer
));
3273 case IPP_TAG_RESOLUTION
:
3275 int xres
, /* Horizontal resolution */
3276 yres
; /* Vertical resolution */
3277 ipp_res_t units
; /* Resolution units */
3279 xres
= ippGetResolution(found
, last
, &yres
, &units
);
3282 snprintf(buffer
, sizeof(buffer
), "%d%s", xres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
3284 snprintf(buffer
, sizeof(buffer
), "%dx%d%s", xres
, yres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
3288 case IPP_TAG_CHARSET
:
3289 case IPP_TAG_KEYWORD
:
3290 case IPP_TAG_LANGUAGE
:
3291 case IPP_TAG_MIMETYPE
:
3293 case IPP_TAG_NAMELANG
:
3295 case IPP_TAG_TEXTLANG
:
3297 case IPP_TAG_URISCHEME
:
3298 strlcpy(buffer
, ippGetString(found
, last
, NULL
), sizeof(buffer
));
3302 ippAttributeString(found
, buffer
, sizeof(buffer
));
3307 set_variable(outfile
, vars
, expect
->define_value
, buffer
);
3310 if (found
&& expect
->repeat_match
&&
3311 repeat_count
< expect
->repeat_limit
)
3314 while (expect
->expect_all
&& (found
= ippFindNextAttribute(response
, expect
->name
, IPP_TAG_ZERO
)) != NULL
);
3319 * If we are going to repeat this test, sleep 1 second so we don't flood
3320 * the printer with requests...
3325 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
3327 cupsFilePrintf(cupsFileStdout(), "%04d]\n", repeat_count
);
3328 cupsFileFlush(cupsFileStdout());
3330 if (num_displayed
> 0)
3332 for (attrptr
= ippFirstAttribute(response
); attrptr
; attrptr
= ippNextAttribute(response
))
3334 const char *attrname
= ippGetName(attrptr
);
3337 for (i
= 0; i
< num_displayed
; i
++)
3339 if (!strcmp(displayed
[i
], attrname
))
3341 print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST
, attrptr
, NULL
);
3350 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
3352 cupsFilePrintf(cupsFileStdout(), " %-68.68s [", name
);
3353 cupsFileFlush(cupsFileStdout());
3357 while (repeat_test
);
3363 if (cupsArrayCount(errors
) > 0)
3364 prev_pass
= pass
= 0;
3371 if (Output
== _CUPS_OUTPUT_PLIST
)
3373 cupsFilePuts(outfile
, "<key>Successful</key>\n");
3374 cupsFilePuts(outfile
, prev_pass
? "<true />\n" : "<false />\n");
3375 cupsFilePuts(outfile
, "<key>StatusCode</key>\n");
3376 print_xml_string(outfile
, "string", ippErrorString(cupsLastError()));
3377 cupsFilePuts(outfile
, "<key>ResponseAttributes</key>\n");
3378 cupsFilePuts(outfile
, "<array>\n");
3379 cupsFilePuts(outfile
, "<dict>\n");
3380 for (attrptr
= response
? response
->attrs
: NULL
,
3381 group
= attrptr
? attrptr
->group_tag
: IPP_TAG_ZERO
;
3383 attrptr
= attrptr
->next
)
3384 print_attr(outfile
, Output
, attrptr
, &group
);
3385 cupsFilePuts(outfile
, "</dict>\n");
3386 cupsFilePuts(outfile
, "</array>\n");
3389 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
3391 cupsFilePuts(cupsFileStdout(), prev_pass
? "PASS]" : "FAIL]");
3393 if (!prev_pass
|| (Verbosity
&& response
))
3395 cupsFilePrintf(cupsFileStdout(), " RECEIVED: %lu bytes in response\n", (unsigned long)ippLength(response
));
3396 cupsFilePrintf(cupsFileStdout(), " status-code = %s (%s)\n", ippErrorString(cupsLastError()), cupsLastErrorString());
3398 if (Verbosity
&& response
)
3400 for (attrptr
= response
->attrs
;
3402 attrptr
= attrptr
->next
)
3403 print_attr(cupsFileStdout(), _CUPS_OUTPUT_TEST
, attrptr
, NULL
);
3407 else if (!prev_pass
&& Output
!= _CUPS_OUTPUT_QUIET
)
3408 fprintf(stderr
, "%s\n", cupsLastErrorString());
3410 if (prev_pass
&& Output
>= _CUPS_OUTPUT_LIST
&& !Verbosity
&&
3413 size_t width
; /* Length of value */
3415 for (i
= 0; i
< num_displayed
; i
++)
3417 widths
[i
] = strlen(displayed
[i
]);
3419 for (attrptr
= ippFindAttribute(response
, displayed
[i
], IPP_TAG_ZERO
);
3421 attrptr
= ippFindNextAttribute(response
, displayed
[i
],
3424 width
= ippAttributeString(attrptr
, NULL
, 0);
3425 if (width
> widths
[i
])
3430 if (Output
== _CUPS_OUTPUT_CSV
)
3431 print_csv(outfile
, NULL
, num_displayed
, displayed
, widths
);
3433 print_line(outfile
, NULL
, num_displayed
, displayed
, widths
);
3435 attrptr
= response
->attrs
;
3439 while (attrptr
&& attrptr
->group_tag
<= IPP_TAG_OPERATION
)
3440 attrptr
= attrptr
->next
;
3444 if (Output
== _CUPS_OUTPUT_CSV
)
3445 print_csv(outfile
, attrptr
, num_displayed
, displayed
, widths
);
3447 print_line(outfile
, attrptr
, num_displayed
, displayed
, widths
);
3449 while (attrptr
&& attrptr
->group_tag
> IPP_TAG_OPERATION
)
3450 attrptr
= attrptr
->next
;
3454 else if (!prev_pass
)
3456 if (Output
== _CUPS_OUTPUT_PLIST
)
3458 cupsFilePuts(outfile
, "<key>Errors</key>\n");
3459 cupsFilePuts(outfile
, "<array>\n");
3461 for (error
= (char *)cupsArrayFirst(errors
);
3463 error
= (char *)cupsArrayNext(errors
))
3464 print_xml_string(outfile
, "string", error
);
3466 cupsFilePuts(outfile
, "</array>\n");
3469 if (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout()))
3471 for (error
= (char *)cupsArrayFirst(errors
);
3473 error
= (char *)cupsArrayNext(errors
))
3474 cupsFilePrintf(cupsFileStdout(), " %s\n", error
);
3478 if (num_displayed
> 0 && !Verbosity
&& response
&& (Output
== _CUPS_OUTPUT_TEST
|| (Output
== _CUPS_OUTPUT_PLIST
&& outfile
!= cupsFileStdout())))
3480 for (attrptr
= response
->attrs
;
3482 attrptr
= attrptr
->next
)
3486 for (i
= 0; i
< num_displayed
; i
++)
3488 if (!strcmp(displayed
[i
], attrptr
->name
))
3490 print_attr(outfile
, Output
, attrptr
, NULL
);
3500 if (Output
== _CUPS_OUTPUT_PLIST
)
3501 cupsFilePuts(outfile
, "</dict>\n");
3503 cupsFileFlush(cupsFileStdout());
3505 ippDelete(response
);
3508 for (i
= 0; i
< num_statuses
; i
++)
3510 if (statuses
[i
].if_defined
)
3511 free(statuses
[i
].if_defined
);
3512 if (statuses
[i
].if_not_defined
)
3513 free(statuses
[i
].if_not_defined
);
3514 if (statuses
[i
].define_match
)
3515 free(statuses
[i
].define_match
);
3516 if (statuses
[i
].define_no_match
)
3517 free(statuses
[i
].define_no_match
);
3521 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
3524 if (expect
->of_type
)
3525 free(expect
->of_type
);
3526 if (expect
->same_count_as
)
3527 free(expect
->same_count_as
);
3528 if (expect
->if_defined
)
3529 free(expect
->if_defined
);
3530 if (expect
->if_not_defined
)
3531 free(expect
->if_not_defined
);
3532 if (expect
->with_value
)
3533 free(expect
->with_value
);
3534 if (expect
->define_match
)
3535 free(expect
->define_match
);
3536 if (expect
->define_no_match
)
3537 free(expect
->define_no_match
);
3538 if (expect
->define_value
)
3539 free(expect
->define_value
);
3543 for (i
= 0; i
< num_displayed
; i
++)
3547 if (!ignore_errors
&& !prev_pass
)
3553 cupsArrayDelete(errors
);
3560 ippDelete(response
);
3562 for (i
= 0; i
< num_statuses
; i
++)
3564 if (statuses
[i
].if_defined
)
3565 free(statuses
[i
].if_defined
);
3566 if (statuses
[i
].if_not_defined
)
3567 free(statuses
[i
].if_not_defined
);
3568 if (statuses
[i
].define_match
)
3569 free(statuses
[i
].define_match
);
3570 if (statuses
[i
].define_no_match
)
3571 free(statuses
[i
].define_no_match
);
3574 for (i
= num_expects
, expect
= expects
; i
> 0; i
--, expect
++)
3577 if (expect
->of_type
)
3578 free(expect
->of_type
);
3579 if (expect
->same_count_as
)
3580 free(expect
->same_count_as
);
3581 if (expect
->if_defined
)
3582 free(expect
->if_defined
);
3583 if (expect
->if_not_defined
)
3584 free(expect
->if_not_defined
);
3585 if (expect
->with_value
)
3586 free(expect
->with_value
);
3587 if (expect
->define_match
)
3588 free(expect
->define_match
);
3589 if (expect
->define_no_match
)
3590 free(expect
->define_no_match
);
3591 if (expect
->define_value
)
3592 free(expect
->define_value
);
3595 for (i
= 0; i
< num_displayed
; i
++)
3603 * 'expand_variables()' - Expand variables in a string.
3607 expand_variables(_cups_vars_t
*vars
, /* I - Variables */
3608 char *dst
, /* I - Destination string buffer */
3609 const char *src
, /* I - Source string */
3610 size_t dstsize
) /* I - Size of destination buffer */
3612 char *dstptr
, /* Pointer into destination */
3613 *dstend
, /* End of destination */
3614 temp
[256], /* Temporary string */
3615 *tempptr
; /* Pointer into temporary string */
3616 const char *value
; /* Value to substitute */
3620 dstend
= dst
+ dstsize
- 1;
3622 while (*src
&& dstptr
< dstend
)
3627 * Substitute a string/number...
3630 if (!strncmp(src
, "$$", 2))
3635 else if (!strncmp(src
, "$ENV[", 5))
3637 strlcpy(temp
, src
+ 5, sizeof(temp
));
3639 for (tempptr
= temp
; *tempptr
; tempptr
++)
3640 if (*tempptr
== ']')
3646 value
= getenv(temp
);
3647 src
+= tempptr
- temp
+ 5;
3654 strlcpy(temp
, src
, sizeof(temp
));
3655 if ((tempptr
= strchr(temp
, '}')) != NULL
)
3658 tempptr
= temp
+ strlen(temp
);
3662 strlcpy(temp
, src
+ 1, sizeof(temp
));
3664 for (tempptr
= temp
; *tempptr
; tempptr
++)
3665 if (!isalnum(*tempptr
& 255) && *tempptr
!= '-' && *tempptr
!= '_')
3672 if (!strcmp(temp
, "uri"))
3674 else if (!strcmp(temp
, "filename"))
3675 value
= vars
->filename
;
3676 else if (!strcmp(temp
, "scheme") || !strcmp(temp
, "method"))
3677 value
= vars
->scheme
;
3678 else if (!strcmp(temp
, "username"))
3679 value
= vars
->userpass
;
3680 else if (!strcmp(temp
, "hostname"))
3681 value
= vars
->hostname
;
3682 else if (!strcmp(temp
, "port"))
3684 snprintf(temp
, sizeof(temp
), "%d", vars
->port
);
3687 else if (!strcmp(temp
, "resource"))
3688 value
= vars
->resource
;
3689 else if (!strcmp(temp
, "user"))
3692 value
= get_variable(vars
, temp
);
3694 src
+= tempptr
- temp
+ 1;
3699 strlcpy(dstptr
, value
, (size_t)(dstend
- dstptr
+ 1));
3700 dstptr
+= strlen(dstptr
);
3712 * 'expect_matches()' - Return true if the tag matches the specification.
3715 static int /* O - 1 if matches, 0 otherwise */
3717 _cups_expect_t
*expect
, /* I - Expected attribute */
3718 ipp_tag_t value_tag
) /* I - Value tag for attribute */
3720 int match
; /* Match? */
3721 char *of_type
, /* Type name to match */
3722 *next
, /* Next name to match */
3723 sep
; /* Separator character */
3727 * If we don't expect a particular type, return immediately...
3730 if (!expect
->of_type
)
3734 * Parse the "of_type" value since the string can contain multiple attribute
3735 * types separated by "," or "|"...
3738 for (of_type
= expect
->of_type
, match
= 0; !match
&& *of_type
; of_type
= next
)
3741 * Find the next separator, and set it (temporarily) to nul if present.
3744 for (next
= of_type
; *next
&& *next
!= '|' && *next
!= ','; next
++);
3746 if ((sep
= *next
) != '\0')
3750 * Support some meta-types to make it easier to write the test file.
3753 if (!strcmp(of_type
, "text"))
3754 match
= value_tag
== IPP_TAG_TEXTLANG
|| value_tag
== IPP_TAG_TEXT
;
3755 else if (!strcmp(of_type
, "name"))
3756 match
= value_tag
== IPP_TAG_NAMELANG
|| value_tag
== IPP_TAG_NAME
;
3757 else if (!strcmp(of_type
, "collection"))
3758 match
= value_tag
== IPP_TAG_BEGIN_COLLECTION
;
3760 match
= value_tag
== ippTagValue(of_type
);
3763 * Restore the separator if we have one...
3775 * 'get_collection()' - Get a collection value from the current test file.
3778 static ipp_t
* /* O - Collection value */
3779 get_collection(cups_file_t
*outfile
, /* I - Output file */
3780 _cups_vars_t
*vars
, /* I - Variables */
3781 cups_file_t
*fp
, /* I - File to read from */
3782 int *linenum
) /* IO - Line number */
3784 char token
[1024], /* Token from file */
3785 temp
[1024], /* Temporary string */
3786 attr
[128]; /* Attribute name */
3787 ipp_tag_t value
; /* Current value type */
3788 ipp_t
*col
= ippNew(); /* Collection value */
3789 ipp_attribute_t
*lastcol
= NULL
; /* Last collection attribute */
3792 while (get_token(fp
, token
, sizeof(token
), linenum
) != NULL
)
3794 if (!strcmp(token
, "}"))
3796 else if (!strcmp(token
, "{") && lastcol
)
3799 * Another collection value
3802 ipp_t
*subcol
= get_collection(outfile
, vars
, fp
, linenum
);
3803 /* Collection value */
3806 ippSetCollection(col
, &lastcol
, ippGetCount(lastcol
), subcol
);
3810 else if (!_cups_strcasecmp(token
, "MEMBER"))
3818 if (!get_token(fp
, token
, sizeof(token
), linenum
))
3820 print_fatal_error(outfile
, "Missing MEMBER value tag on line %d.", *linenum
);
3824 if ((value
= ippTagValue(token
)) < IPP_TAG_UNSUPPORTED_VALUE
)
3826 print_fatal_error(outfile
, "Bad MEMBER value tag \"%s\" on line %d.", token
,
3831 if (!get_token(fp
, attr
, sizeof(attr
), linenum
))
3833 print_fatal_error(outfile
, "Missing MEMBER name on line %d.", *linenum
);
3837 if (value
< IPP_TAG_INTEGER
)
3840 * Out-of-band member attributes have no value...
3845 else if (!get_token(fp
, temp
, sizeof(temp
), linenum
))
3847 print_fatal_error(outfile
, "Missing MEMBER value on line %d.", *linenum
);
3852 expand_variables(vars
, token
, temp
, sizeof(token
));
3858 if (value
< IPP_TAG_INTEGER
)
3861 * Add out-of-band value...
3864 ippAddOutOfBand(col
, IPP_TAG_ZERO
, value
, attr
);
3868 print_fatal_error(outfile
, "Unsupported MEMBER value tag %s for \"%s\" on line %d.", ippTagString(value
), attr
, *linenum
);
3873 case IPP_TAG_BOOLEAN
:
3874 if (!_cups_strcasecmp(token
, "true"))
3875 ippAddBoolean(col
, IPP_TAG_ZERO
, attr
, 1);
3877 ippAddBoolean(col
, IPP_TAG_ZERO
, attr
, (char)atoi(token
));
3880 case IPP_TAG_INTEGER
:
3882 ippAddInteger(col
, IPP_TAG_ZERO
, value
, attr
, atoi(token
));
3885 case IPP_TAG_RESOLUTION
:
3887 int xres
, /* X resolution */
3888 yres
; /* Y resolution */
3889 char units
[6]; /* Units */
3891 if (sscanf(token
, "%dx%d%5s", &xres
, &yres
, units
) != 3 ||
3892 (_cups_strcasecmp(units
, "dpi") &&
3893 _cups_strcasecmp(units
, "dpc") &&
3894 _cups_strcasecmp(units
, "dpcm") &&
3895 _cups_strcasecmp(units
, "other")))
3897 print_fatal_error(outfile
, "Bad resolution value \"%s\" on line %d.",
3902 if (!_cups_strcasecmp(units
, "dpi"))
3903 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, IPP_RES_PER_INCH
, xres
, yres
);
3904 else if (!_cups_strcasecmp(units
, "dpc") ||
3905 !_cups_strcasecmp(units
, "dpcm"))
3906 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, IPP_RES_PER_CM
, xres
, yres
);
3908 ippAddResolution(col
, IPP_TAG_ZERO
, attr
, (ipp_res_t
)0, xres
, yres
);
3912 case IPP_TAG_RANGE
:
3914 int lowers
[4], /* Lower value */
3915 uppers
[4], /* Upper values */
3916 num_vals
; /* Number of values */
3919 num_vals
= sscanf(token
, "%d-%d,%d-%d,%d-%d,%d-%d",
3920 lowers
+ 0, uppers
+ 0,
3921 lowers
+ 1, uppers
+ 1,
3922 lowers
+ 2, uppers
+ 2,
3923 lowers
+ 3, uppers
+ 3);
3925 if ((num_vals
& 1) || num_vals
== 0)
3927 print_fatal_error(outfile
, "Bad rangeOfInteger value \"%s\" on line %d.",
3932 ippAddRanges(col
, IPP_TAG_ZERO
, attr
, num_vals
/ 2, lowers
,
3937 case IPP_TAG_BEGIN_COLLECTION
:
3938 if (!strcmp(token
, "{"))
3940 ipp_t
*subcol
= get_collection(outfile
, vars
, fp
, linenum
);
3941 /* Collection value */
3945 lastcol
= ippAddCollection(col
, IPP_TAG_ZERO
, attr
, subcol
);
3953 print_fatal_error(outfile
, "Bad collection value on line %d.", *linenum
);
3958 case IPP_TAG_STRING
:
3959 ippAddOctetString(col
, IPP_TAG_ZERO
, attr
, token
, (int)strlen(token
));
3962 case IPP_TAG_TEXTLANG
:
3963 case IPP_TAG_NAMELANG
:
3966 case IPP_TAG_KEYWORD
:
3968 case IPP_TAG_URISCHEME
:
3969 case IPP_TAG_CHARSET
:
3970 case IPP_TAG_LANGUAGE
:
3971 case IPP_TAG_MIMETYPE
:
3972 if (!strchr(token
, ','))
3973 ippAddString(col
, IPP_TAG_ZERO
, value
, attr
, NULL
, token
);
3977 * Multiple string values...
3980 int num_values
; /* Number of values */
3981 char *values
[100], /* Values */
3982 *ptr
; /* Pointer to next value */
3988 for (ptr
= strchr(token
, ','); ptr
; ptr
= strchr(ptr
, ','))
3990 if (ptr
> token
&& ptr
[-1] == '\\')
3991 _cups_strcpy(ptr
- 1, ptr
);
3995 values
[num_values
] = ptr
;
4000 ippAddStrings(col
, IPP_TAG_ZERO
, value
, attr
, num_values
,
4001 NULL
, (const char **)values
);
4008 print_fatal_error(outfile
, "Unexpected token %s seen on line %d.", token
, *linenum
);
4016 * If we get here there was a parse error; free memory and return.
4028 * 'get_filename()' - Get a filename based on the current test file.
4031 static char * /* O - Filename */
4032 get_filename(const char *testfile
, /* I - Current test file */
4033 char *dst
, /* I - Destination filename */
4034 const char *src
, /* I - Source filename */
4035 size_t dstsize
) /* I - Size of destination buffer */
4037 char *dstptr
; /* Pointer into destination */
4038 _cups_globals_t
*cg
= _cupsGlobals();
4042 if (*src
== '<' && src
[strlen(src
) - 1] == '>')
4045 * Map <filename> to CUPS_DATADIR/ipptool/filename...
4048 snprintf(dst
, dstsize
, "%s/ipptool/%s", cg
->cups_datadir
, src
+ 1);
4049 dstptr
= dst
+ strlen(dst
) - 1;
4053 else if (*src
== '/' || !strchr(testfile
, '/')
4055 || (isalpha(*src
& 255) && src
[1] == ':')
4060 * Use the path as-is...
4063 strlcpy(dst
, src
, dstsize
);
4068 * Make path relative to testfile...
4071 strlcpy(dst
, testfile
, dstsize
);
4072 if ((dstptr
= strrchr(dst
, '/')) != NULL
)
4075 dstptr
= dst
; /* Should never happen */
4077 strlcpy(dstptr
, src
, dstsize
- (size_t)(dstptr
- dst
));
4085 * 'get_string()' - Get a pointer to a string value or the portion of interest.
4088 static const char * /* O - Pointer to string */
4089 get_string(ipp_attribute_t
*attr
, /* I - IPP attribute */
4090 int element
, /* I - Element to fetch */
4091 int flags
, /* I - Value ("with") flags */
4092 char *buffer
, /* I - Temporary buffer */
4093 size_t bufsize
) /* I - Size of temporary buffer */
4095 const char *value
; /* Value */
4096 char *ptr
, /* Pointer into value */
4097 scheme
[256], /* URI scheme */
4098 userpass
[256], /* Username/password */
4099 hostname
[256], /* Hostname */
4100 resource
[1024]; /* Resource */
4101 int port
; /* Port number */
4104 value
= ippGetString(attr
, element
, NULL
);
4106 if (flags
& _CUPS_WITH_HOSTNAME
)
4108 if (httpSeparateURI(HTTP_URI_CODING_ALL
, value
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), buffer
, (int)bufsize
, &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4111 ptr
= buffer
+ strlen(buffer
) - 1;
4112 if (ptr
>= buffer
&& *ptr
== '.')
4113 *ptr
= '\0'; /* Drop trailing "." */
4117 else if (flags
& _CUPS_WITH_RESOURCE
)
4119 if (httpSeparateURI(HTTP_URI_CODING_ALL
, value
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, buffer
, (int)bufsize
) < HTTP_URI_STATUS_OK
)
4124 else if (flags
& _CUPS_WITH_SCHEME
)
4126 if (httpSeparateURI(HTTP_URI_CODING_ALL
, value
, buffer
, (int)bufsize
, userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
)) < HTTP_URI_STATUS_OK
)
4131 else if (ippGetValueTag(attr
) == IPP_TAG_URI
&& (!strncmp(value
, "ipp://", 6) || !strncmp(value
, "http://", 7) || !strncmp(value
, "ipps://", 7) || !strncmp(value
, "https://", 8)))
4133 http_uri_status_t status
= httpSeparateURI(HTTP_URI_CODING_ALL
, value
, scheme
, sizeof(scheme
), userpass
, sizeof(userpass
), hostname
, sizeof(hostname
), &port
, resource
, sizeof(resource
));
4135 if (status
< HTTP_URI_STATUS_OK
)
4146 * Normalize URI with no trailing dot...
4149 if ((ptr
= hostname
+ strlen(hostname
) - 1) >= hostname
&& *ptr
== '.')
4152 httpAssembleURI(HTTP_URI_CODING_ALL
, buffer
, (int)bufsize
, scheme
, userpass
, hostname
, port
, resource
);
4163 * 'get_token()' - Get a token from a file.
4166 static char * /* O - Token from file or NULL on EOF */
4167 get_token(cups_file_t
*fp
, /* I - File to read from */
4168 char *buf
, /* I - Buffer to read into */
4169 int buflen
, /* I - Length of buffer */
4170 int *linenum
) /* IO - Current line number */
4172 int ch
, /* Character from file */
4173 quote
; /* Quoting character */
4174 char *bufptr
, /* Pointer into buffer */
4175 *bufend
; /* End of buffer */
4181 * Skip whitespace...
4184 while (isspace(ch
= cupsFileGetChar(fp
)))
4196 else if (ch
== '\'' || ch
== '\"')
4199 * Quoted text or regular expression...
4204 bufend
= buf
+ buflen
- 1;
4206 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
4211 * Escape next character...
4214 if (bufptr
< bufend
)
4215 *bufptr
++ = (char)ch
;
4217 if ((ch
= cupsFileGetChar(fp
)) != EOF
&& bufptr
< bufend
)
4218 *bufptr
++ = (char)ch
;
4220 else if (ch
== quote
)
4222 else if (bufptr
< bufend
)
4223 *bufptr
++ = (char)ch
;
4236 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
4242 else if (ch
== '{' || ch
== '}' || ch
== ',')
4252 * Whitespace delimited text...
4255 cupsFileSeek(fp
, cupsFileTell(fp
) - 1);
4258 bufend
= buf
+ buflen
- 1;
4260 while ((ch
= cupsFileGetChar(fp
)) != EOF
)
4261 if (isspace(ch
) || ch
== '#')
4263 else if (bufptr
< bufend
)
4264 *bufptr
++ = (char)ch
;
4267 cupsFileSeek(fp
, cupsFileTell(fp
) - 1);
4268 else if (ch
== '\n')
4280 * 'get_variable()' - Get the value of a variable.
4283 static char * /* O - Value or NULL */
4284 get_variable(_cups_vars_t
*vars
, /* I - Variables */
4285 const char *name
) /* I - Variable name */
4287 _cups_var_t key
, /* Search key */
4288 *match
; /* Matching variable, if any */
4291 key
.name
= (char *)name
;
4292 match
= cupsArrayFind(vars
->vars
, &key
);
4294 return (match
? match
->value
: NULL
);
4299 * 'iso_date()' - Return an ISO 8601 date/time string for the given IPP dateTime
4303 static char * /* O - ISO 8601 date/time string */
4304 iso_date(ipp_uchar_t
*date
) /* I - IPP (RFC 1903) date/time value */
4306 time_t utctime
; /* UTC time since 1970 */
4307 struct tm
*utcdate
; /* UTC date/time */
4308 static char buffer
[255]; /* String buffer */
4311 utctime
= ippDateToTime(date
);
4312 utcdate
= gmtime(&utctime
);
4314 snprintf(buffer
, sizeof(buffer
), "%04d-%02d-%02dT%02d:%02d:%02dZ",
4315 utcdate
->tm_year
+ 1900, utcdate
->tm_mon
+ 1, utcdate
->tm_mday
,
4316 utcdate
->tm_hour
, utcdate
->tm_min
, utcdate
->tm_sec
);
4323 * 'password_cb()' - Password callback for authenticated tests.
4326 static const char * /* O - Password */
4327 password_cb(const char *prompt
) /* I - Prompt (unused) */
4331 if (PasswordTries
< 3)
4335 cupsSetUser(Username
);
4345 * 'pause_message()' - Display the message and pause until the user presses a key.
4349 pause_message(const char *message
) /* I - Message */
4352 HANDLE tty
; /* Console handle */
4353 DWORD mode
; /* Console mode */
4354 char key
; /* Key press */
4355 DWORD bytes
; /* Bytes read for key press */
4359 * Disable input echo and set raw input...
4362 if ((tty
= GetStdHandle(STD_INPUT_HANDLE
)) == INVALID_HANDLE_VALUE
)
4365 if (!GetConsoleMode(tty
, &mode
))
4368 if (!SetConsoleMode(tty
, 0))
4372 int tty
; /* /dev/tty - never read from stdin */
4373 struct termios original
, /* Original input mode */
4374 noecho
; /* No echo input mode */
4375 char key
; /* Current key press */
4379 * Disable input echo and set raw input...
4382 if ((tty
= open("/dev/tty", O_RDONLY
)) < 0)
4385 if (tcgetattr(tty
, &original
))
4392 noecho
.c_lflag
&= (tcflag_t
)~(ICANON
| ECHO
| ECHOE
| ISIG
);
4394 if (tcsetattr(tty
, TCSAFLUSH
, &noecho
))
4402 * Display the prompt...
4405 printf("%s\n---- PRESS ANY KEY ----", message
);
4406 cupsFileFlush(cupsFileStdout());
4413 ReadFile(tty
, &key
, 1, &bytes
, NULL
);
4419 SetConsoleMode(tty
, mode
);
4432 tcsetattr(tty
, TCSAFLUSH
, &original
);
4437 * Erase the "press any key" prompt...
4440 cupsFilePuts(cupsFileStdout(), "\r \r");
4441 cupsFileFlush(cupsFileStdout());
4446 * 'print_attr()' - Print an attribute on the screen.
4450 print_attr(cups_file_t
*outfile
, /* I - Output file */
4451 int format
, /* I - Output format */
4452 ipp_attribute_t
*attr
, /* I - Attribute to print */
4453 ipp_tag_t
*group
) /* IO - Current group */
4455 int i
; /* Looping var */
4456 ipp_attribute_t
*colattr
; /* Collection attribute */
4459 if (format
== _CUPS_OUTPUT_PLIST
)
4461 if (!attr
->name
|| (group
&& *group
!= attr
->group_tag
))
4463 if (attr
->group_tag
!= IPP_TAG_ZERO
)
4465 cupsFilePuts(outfile
, "</dict>\n");
4466 cupsFilePuts(outfile
, "<dict>\n");
4470 *group
= attr
->group_tag
;
4476 print_xml_string(outfile
, "key", attr
->name
);
4477 if (attr
->num_values
> 1)
4478 cupsFilePuts(outfile
, "<array>\n");
4480 switch (attr
->value_tag
)
4482 case IPP_TAG_INTEGER
:
4484 for (i
= 0; i
< attr
->num_values
; i
++)
4485 cupsFilePrintf(outfile
, "<integer>%d</integer>\n", attr
->values
[i
].integer
);
4488 case IPP_TAG_BOOLEAN
:
4489 for (i
= 0; i
< attr
->num_values
; i
++)
4490 cupsFilePuts(outfile
, attr
->values
[i
].boolean
? "<true />\n" : "<false />\n");
4493 case IPP_TAG_RANGE
:
4494 for (i
= 0; i
< attr
->num_values
; i
++)
4495 cupsFilePrintf(outfile
, "<dict><key>lower</key><integer>%d</integer>"
4496 "<key>upper</key><integer>%d</integer></dict>\n",
4497 attr
->values
[i
].range
.lower
, attr
->values
[i
].range
.upper
);
4500 case IPP_TAG_RESOLUTION
:
4501 for (i
= 0; i
< attr
->num_values
; i
++)
4502 cupsFilePrintf(outfile
, "<dict><key>xres</key><integer>%d</integer>"
4503 "<key>yres</key><integer>%d</integer>"
4504 "<key>units</key><string>%s</string></dict>\n",
4505 attr
->values
[i
].resolution
.xres
,
4506 attr
->values
[i
].resolution
.yres
,
4507 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
4512 for (i
= 0; i
< attr
->num_values
; i
++)
4513 cupsFilePrintf(outfile
, "<date>%s</date>\n", iso_date(attr
->values
[i
].date
));
4516 case IPP_TAG_STRING
:
4517 for (i
= 0; i
< attr
->num_values
; i
++)
4519 char buffer
[IPP_MAX_LENGTH
* 5 / 4 + 1];
4522 cupsFilePrintf(outfile
, "<data>%s</data>\n",
4523 httpEncode64_2(buffer
, sizeof(buffer
),
4524 attr
->values
[i
].unknown
.data
,
4525 attr
->values
[i
].unknown
.length
));
4531 case IPP_TAG_KEYWORD
:
4533 case IPP_TAG_URISCHEME
:
4534 case IPP_TAG_CHARSET
:
4535 case IPP_TAG_LANGUAGE
:
4536 case IPP_TAG_MIMETYPE
:
4537 for (i
= 0; i
< attr
->num_values
; i
++)
4538 print_xml_string(outfile
, "string", attr
->values
[i
].string
.text
);
4541 case IPP_TAG_TEXTLANG
:
4542 case IPP_TAG_NAMELANG
:
4543 for (i
= 0; i
< attr
->num_values
; i
++)
4545 cupsFilePuts(outfile
, "<dict><key>language</key><string>");
4546 print_xml_string(outfile
, NULL
, attr
->values
[i
].string
.language
);
4547 cupsFilePuts(outfile
, "</string><key>string</key><string>");
4548 print_xml_string(outfile
, NULL
, attr
->values
[i
].string
.text
);
4549 cupsFilePuts(outfile
, "</string></dict>\n");
4553 case IPP_TAG_BEGIN_COLLECTION
:
4554 for (i
= 0; i
< attr
->num_values
; i
++)
4556 cupsFilePuts(outfile
, "<dict>\n");
4557 for (colattr
= attr
->values
[i
].collection
->attrs
;
4559 colattr
= colattr
->next
)
4560 print_attr(outfile
, format
, colattr
, NULL
);
4561 cupsFilePuts(outfile
, "</dict>\n");
4566 cupsFilePrintf(outfile
, "<string><<%s>></string>\n", ippTagString(attr
->value_tag
));
4570 if (attr
->num_values
> 1)
4571 cupsFilePuts(outfile
, "</array>\n");
4575 char buffer
[131072]; /* Value buffer */
4577 if (format
== _CUPS_OUTPUT_TEST
)
4581 cupsFilePuts(outfile
, " -- separator --\n");
4585 cupsFilePrintf(outfile
, " %s (%s%s) = ", attr
->name
, attr
->num_values
> 1 ? "1setOf " : "", ippTagString(attr
->value_tag
));
4588 ippAttributeString(attr
, buffer
, sizeof(buffer
));
4589 cupsFilePrintf(outfile
, "%s\n", buffer
);
4595 * 'print_csv()' - Print a line of CSV text.
4600 cups_file_t
*outfile
, /* I - Output file */
4601 ipp_attribute_t
*attr
, /* I - First attribute for line */
4602 int num_displayed
, /* I - Number of attributes to display */
4603 char **displayed
, /* I - Attributes to display */
4604 size_t *widths
) /* I - Column widths */
4606 int i
; /* Looping var */
4607 size_t maxlength
; /* Max length of all columns */
4608 char *buffer
, /* String buffer */
4609 *bufptr
; /* Pointer into buffer */
4610 ipp_attribute_t
*current
; /* Current attribute */
4614 * Get the maximum string length we have to show and allocate...
4617 for (i
= 1, maxlength
= widths
[0]; i
< num_displayed
; i
++)
4618 if (widths
[i
] > maxlength
)
4619 maxlength
= widths
[i
];
4623 if ((buffer
= malloc(maxlength
)) == NULL
)
4627 * Loop through the attributes to display...
4632 for (i
= 0; i
< num_displayed
; i
++)
4635 cupsFilePutChar(outfile
, ',');
4639 for (current
= attr
; current
; current
= current
->next
)
4643 else if (!strcmp(current
->name
, displayed
[i
]))
4645 ippAttributeString(current
, buffer
, maxlength
);
4650 if (strchr(buffer
, ',') != NULL
|| strchr(buffer
, '\"') != NULL
||
4651 strchr(buffer
, '\\') != NULL
)
4653 cupsFilePutChar(cupsFileStdout(), '\"');
4654 for (bufptr
= buffer
; *bufptr
; bufptr
++)
4656 if (*bufptr
== '\\' || *bufptr
== '\"')
4657 cupsFilePutChar(cupsFileStdout(), '\\');
4658 cupsFilePutChar(cupsFileStdout(), *bufptr
);
4660 cupsFilePutChar(cupsFileStdout(), '\"');
4663 cupsFilePuts(outfile
, buffer
);
4665 cupsFilePutChar(cupsFileStdout(), '\n');
4669 for (i
= 0; i
< num_displayed
; i
++)
4672 cupsFilePutChar(cupsFileStdout(), ',');
4674 cupsFilePuts(outfile
, displayed
[i
]);
4676 cupsFilePutChar(cupsFileStdout(), '\n');
4684 * 'print_fatal_error()' - Print a fatal error message.
4688 print_fatal_error(cups_file_t
*outfile
, /* I - Output file */
4689 const char *s
, /* I - Printf-style format string */
4690 ...) /* I - Additional arguments as needed */
4692 char buffer
[10240]; /* Format buffer */
4693 va_list ap
; /* Pointer to arguments */
4697 * Format the error message...
4701 vsnprintf(buffer
, sizeof(buffer
), s
, ap
);
4708 if (Output
== _CUPS_OUTPUT_PLIST
)
4710 print_xml_header(outfile
);
4711 print_xml_trailer(outfile
, 0, buffer
);
4714 _cupsLangPrintf(stderr
, "ipptool: %s", buffer
);
4719 * 'print_line()' - Print a line of formatted or CSV text.
4724 cups_file_t
*outfile
, /* I - Output file */
4725 ipp_attribute_t
*attr
, /* I - First attribute for line */
4726 int num_displayed
, /* I - Number of attributes to display */
4727 char **displayed
, /* I - Attributes to display */
4728 size_t *widths
) /* I - Column widths */
4730 int i
; /* Looping var */
4731 size_t maxlength
; /* Max length of all columns */
4732 char *buffer
; /* String buffer */
4733 ipp_attribute_t
*current
; /* Current attribute */
4737 * Get the maximum string length we have to show and allocate...
4740 for (i
= 1, maxlength
= widths
[0]; i
< num_displayed
; i
++)
4741 if (widths
[i
] > maxlength
)
4742 maxlength
= widths
[i
];
4746 if ((buffer
= malloc(maxlength
)) == NULL
)
4750 * Loop through the attributes to display...
4755 for (i
= 0; i
< num_displayed
; i
++)
4758 cupsFilePutChar(cupsFileStdout(), ' ');
4762 for (current
= attr
; current
; current
= current
->next
)
4766 else if (!strcmp(current
->name
, displayed
[i
]))
4768 ippAttributeString(current
, buffer
, maxlength
);
4773 cupsFilePrintf(outfile
, "%*s", (int)-widths
[i
], buffer
);
4775 cupsFilePutChar(cupsFileStdout(), '\n');
4779 for (i
= 0; i
< num_displayed
; i
++)
4782 cupsFilePutChar(cupsFileStdout(), ' ');
4784 cupsFilePrintf(outfile
, "%*s", (int)-widths
[i
], displayed
[i
]);
4786 cupsFilePutChar(cupsFileStdout(), '\n');
4788 for (i
= 0; i
< num_displayed
; i
++)
4791 cupsFilePutChar(cupsFileStdout(), ' ');
4793 memset(buffer
, '-', widths
[i
]);
4794 buffer
[widths
[i
]] = '\0';
4795 cupsFilePuts(outfile
, buffer
);
4797 cupsFilePutChar(cupsFileStdout(), '\n');
4805 * 'print_xml_header()' - Print a standard XML plist header.
4809 print_xml_header(cups_file_t
*outfile
) /* I - Output file */
4813 cupsFilePuts(outfile
, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
4814 cupsFilePuts(outfile
, "<!DOCTYPE plist PUBLIC \"-//Apple Computer//DTD PLIST 1.0//EN\" "
4815 "\"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">\n");
4816 cupsFilePuts(outfile
, "<plist version=\"1.0\">\n");
4817 cupsFilePuts(outfile
, "<dict>\n");
4818 cupsFilePuts(outfile
, "<key>ipptoolVersion</key>\n");
4819 cupsFilePuts(outfile
, "<string>" CUPS_SVERSION
"</string>\n");
4820 cupsFilePuts(outfile
, "<key>Transfer</key>\n");
4821 cupsFilePrintf(outfile
, "<string>%s</string>\n",
4822 Transfer
== _CUPS_TRANSFER_AUTO
? "auto" :
4823 Transfer
== _CUPS_TRANSFER_CHUNKED
? "chunked" : "length");
4824 cupsFilePuts(outfile
, "<key>Tests</key>\n");
4825 cupsFilePuts(outfile
, "<array>\n");
4833 * 'print_xml_string()' - Print an XML string with escaping.
4837 print_xml_string(cups_file_t
*outfile
, /* I - Output file */
4838 const char *element
, /* I - Element name or NULL */
4839 const char *s
) /* I - String to print */
4842 cupsFilePrintf(outfile
, "<%s>", element
);
4847 cupsFilePuts(outfile
, "&");
4849 cupsFilePuts(outfile
, "<");
4851 cupsFilePuts(outfile
, ">");
4852 else if ((*s
& 0xe0) == 0xc0)
4855 * Validate UTF-8 two-byte sequence...
4858 if ((s
[1] & 0xc0) != 0x80)
4860 cupsFilePutChar(cupsFileStdout(), '?');
4865 cupsFilePutChar(cupsFileStdout(), *s
++);
4866 cupsFilePutChar(cupsFileStdout(), *s
);
4869 else if ((*s
& 0xf0) == 0xe0)
4872 * Validate UTF-8 three-byte sequence...
4875 if ((s
[1] & 0xc0) != 0x80 || (s
[2] & 0xc0) != 0x80)
4877 cupsFilePutChar(cupsFileStdout(), '?');
4882 cupsFilePutChar(cupsFileStdout(), *s
++);
4883 cupsFilePutChar(cupsFileStdout(), *s
++);
4884 cupsFilePutChar(cupsFileStdout(), *s
);
4887 else if ((*s
& 0xf8) == 0xf0)
4890 * Validate UTF-8 four-byte sequence...
4893 if ((s
[1] & 0xc0) != 0x80 || (s
[2] & 0xc0) != 0x80 ||
4894 (s
[3] & 0xc0) != 0x80)
4896 cupsFilePutChar(cupsFileStdout(), '?');
4901 cupsFilePutChar(cupsFileStdout(), *s
++);
4902 cupsFilePutChar(cupsFileStdout(), *s
++);
4903 cupsFilePutChar(cupsFileStdout(), *s
++);
4904 cupsFilePutChar(cupsFileStdout(), *s
);
4907 else if ((*s
& 0x80) || (*s
< ' ' && !isspace(*s
& 255)))
4910 * Invalid control character...
4913 cupsFilePutChar(cupsFileStdout(), '?');
4916 cupsFilePutChar(cupsFileStdout(), *s
);
4922 cupsFilePrintf(outfile
, "</%s>\n", element
);
4927 * 'print_xml_trailer()' - Print the XML trailer with success/fail value.
4931 print_xml_trailer(cups_file_t
*outfile
, /* I - Output file */
4932 int success
, /* I - 1 on success, 0 on failure */
4933 const char *message
) /* I - Error message or NULL */
4937 cupsFilePuts(outfile
, "</array>\n");
4938 cupsFilePuts(outfile
, "<key>Successful</key>\n");
4939 cupsFilePuts(outfile
, success
? "<true />\n" : "<false />\n");
4942 cupsFilePuts(outfile
, "<key>ErrorMessage</key>\n");
4943 print_xml_string(outfile
, "string", message
);
4945 cupsFilePuts(outfile
, "</dict>\n");
4946 cupsFilePuts(outfile
, "</plist>\n");
4954 * 'set_variable()' - Set a variable value.
4958 set_variable(cups_file_t
*outfile
, /* I - Output file */
4959 _cups_vars_t
*vars
, /* I - Variables */
4960 const char *name
, /* I - Variable name */
4961 const char *value
) /* I - Value string */
4963 _cups_var_t key
, /* Search key */
4964 *var
; /* New variable */
4967 if (!_cups_strcasecmp(name
, "filename"))
4970 free(vars
->filename
);
4972 vars
->filename
= strdup(value
);
4976 key
.name
= (char *)name
;
4977 if ((var
= cupsArrayFind(vars
->vars
, &key
)) != NULL
)
4980 var
->value
= strdup(value
);
4982 else if ((var
= malloc(sizeof(_cups_var_t
))) == NULL
)
4984 print_fatal_error(outfile
, "Unable to allocate memory for variable \"%s\".", name
);
4989 var
->name
= strdup(name
);
4990 var
->value
= strdup(value
);
4992 cupsArrayAdd(vars
->vars
, var
);
4999 * 'sigterm_handler()' - Handle SIGINT and SIGTERM.
5003 sigterm_handler(int sig
) /* I - Signal number (unused) */
5009 signal(SIGINT
, SIG_DFL
);
5010 signal(SIGTERM
, SIG_DFL
);
5016 * 'timeout_cb()' - Handle HTTP timeouts.
5019 static int /* O - 1 to continue, 0 to cancel */
5020 timeout_cb(http_t
*http
, /* I - Connection to server */
5021 void *user_data
) /* I - User data (unused) */
5023 int buffered
= 0; /* Bytes buffered but not yet sent */
5029 * If the socket still have data waiting to be sent to the printer (as can
5030 * happen if the printer runs out of paper), continue to wait until the output
5031 * buffer is empty...
5034 #ifdef SO_NWRITE /* macOS and some versions of Linux */
5035 socklen_t len
= sizeof(buffered
); /* Size of return value */
5037 if (getsockopt(httpGetFd(http
), SOL_SOCKET
, SO_NWRITE
, &buffered
, &len
))
5040 #elif defined(SIOCOUTQ) /* Others except Windows */
5041 if (ioctl(httpGetFd(http
), SIOCOUTQ
, &buffered
))
5044 #else /* Windows (not possible) */
5046 #endif /* SO_NWRITE */
5048 return (buffered
> 0);
5053 * 'usage()' - Show program usage.
5059 _cupsLangPuts(stderr
, _("Usage: ipptool [options] URI filename [ ... filenameN ]"));
5060 _cupsLangPuts(stderr
, _("Options:"));
5061 _cupsLangPuts(stderr
, _(" --help Show help."));
5062 _cupsLangPuts(stderr
, _(" --stop-after-include-error\n"
5063 " Stop tests after a failed INCLUDE."));
5064 _cupsLangPuts(stderr
, _(" --version Show version."));
5065 _cupsLangPuts(stderr
, _(" -4 Connect using IPv4."));
5066 _cupsLangPuts(stderr
, _(" -6 Connect using IPv6."));
5067 _cupsLangPuts(stderr
, _(" -C Send requests using "
5068 "chunking (default)."));
5069 _cupsLangPuts(stderr
, _(" -E Test with encryption using HTTP Upgrade to TLS."));
5070 _cupsLangPuts(stderr
, _(" -I Ignore errors."));
5071 _cupsLangPuts(stderr
, _(" -L Send requests using content-length."));
5072 _cupsLangPuts(stderr
, _(" -P filename.plist Produce XML plist to a file and test report to standard output."));
5073 _cupsLangPuts(stderr
, _(" -S Test with encryption using HTTPS."));
5074 _cupsLangPuts(stderr
, _(" -T seconds Set the receive/send timeout in seconds."));
5075 _cupsLangPuts(stderr
, _(" -V version Set default IPP version."));
5076 _cupsLangPuts(stderr
, _(" -X Produce XML plist instead of plain text."));
5077 _cupsLangPuts(stderr
, _(" -c Produce CSV output."));
5078 _cupsLangPuts(stderr
, _(" -d name=value Set named variable to value."));
5079 _cupsLangPuts(stderr
, _(" -f filename Set default request filename."));
5080 _cupsLangPuts(stderr
, _(" -i seconds Repeat the last file with the given time interval."));
5081 _cupsLangPuts(stderr
, _(" -l Produce plain text output."));
5082 _cupsLangPuts(stderr
, _(" -n count Repeat the last file the given number of times."));
5083 _cupsLangPuts(stderr
, _(" -q Run silently."));
5084 _cupsLangPuts(stderr
, _(" -t Produce a test report."));
5085 _cupsLangPuts(stderr
, _(" -v Be verbose."));
5092 * 'validate_attr()' - Determine whether an attribute is valid.
5095 static int /* O - 1 if valid, 0 otherwise */
5096 validate_attr(cups_file_t
*outfile
, /* I - Output file */
5097 cups_array_t
*errors
, /* I - Errors array */
5098 ipp_attribute_t
*attr
) /* I - Attribute to validate */
5100 int i
; /* Looping var */
5101 char scheme
[64], /* Scheme from URI */
5102 userpass
[256], /* Username/password from URI */
5103 hostname
[256], /* Hostname from URI */
5104 resource
[1024]; /* Resource from URI */
5105 int port
, /* Port number from URI */
5106 uri_status
, /* URI separation status */
5107 valid
= 1; /* Is the attribute valid? */
5108 const char *ptr
; /* Pointer into string */
5109 ipp_attribute_t
*colattr
; /* Collection attribute */
5110 regex_t re
; /* Regular expression */
5111 ipp_uchar_t
*date
; /* Current date value */
5122 * Validate the attribute name.
5125 for (ptr
= attr
->name
; *ptr
; ptr
++)
5126 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' && *ptr
!= '_')
5129 if (*ptr
|| ptr
== attr
->name
)
5134 "\"%s\": Bad attribute name - invalid character "
5135 "(RFC 2911 section 4.1.3).", attr
->name
);
5138 if ((ptr
- attr
->name
) > 255)
5143 "\"%s\": Bad attribute name - bad length "
5144 "(RFC 2911 section 4.1.3).", attr
->name
);
5147 switch (attr
->value_tag
)
5149 case IPP_TAG_INTEGER
:
5152 case IPP_TAG_BOOLEAN
:
5153 for (i
= 0; i
< attr
->num_values
; i
++)
5155 if (attr
->values
[i
].boolean
!= 0 &&
5156 attr
->values
[i
].boolean
!= 1)
5161 "\"%s\": Bad boolen value %d "
5162 "(RFC 2911 section 4.1.11).", attr
->name
,
5163 attr
->values
[i
].boolean
);
5169 for (i
= 0; i
< attr
->num_values
; i
++)
5171 if (attr
->values
[i
].integer
< 1)
5176 "\"%s\": Bad enum value %d - out of range "
5177 "(RFC 2911 section 4.1.4).", attr
->name
,
5178 attr
->values
[i
].integer
);
5183 case IPP_TAG_STRING
:
5184 for (i
= 0; i
< attr
->num_values
; i
++)
5186 if (attr
->values
[i
].unknown
.length
> IPP_MAX_OCTETSTRING
)
5191 "\"%s\": Bad octetString value - bad length %d "
5192 "(RFC 2911 section 4.1.10).", attr
->name
,
5193 attr
->values
[i
].unknown
.length
);
5199 for (i
= 0; i
< attr
->num_values
; i
++)
5201 date
= attr
->values
[i
].date
;
5203 if (date
[2] < 1 || date
[2] > 12)
5208 "\"%s\": Bad dateTime month %u "
5209 "(RFC 2911 section 4.1.14).", attr
->name
, date
[2]);
5212 if (date
[3] < 1 || date
[3] > 31)
5217 "\"%s\": Bad dateTime day %u "
5218 "(RFC 2911 section 4.1.14).", attr
->name
, date
[3]);
5226 "\"%s\": Bad dateTime hours %u "
5227 "(RFC 2911 section 4.1.14).", attr
->name
, date
[4]);
5235 "\"%s\": Bad dateTime minutes %u "
5236 "(RFC 2911 section 4.1.14).", attr
->name
, date
[5]);
5244 "\"%s\": Bad dateTime seconds %u "
5245 "(RFC 2911 section 4.1.14).", attr
->name
, date
[6]);
5253 "\"%s\": Bad dateTime deciseconds %u "
5254 "(RFC 2911 section 4.1.14).", attr
->name
, date
[7]);
5257 if (date
[8] != '-' && date
[8] != '+')
5262 "\"%s\": Bad dateTime UTC sign '%c' "
5263 "(RFC 2911 section 4.1.14).", attr
->name
, date
[8]);
5271 "\"%s\": Bad dateTime UTC hours %u "
5272 "(RFC 2911 section 4.1.14).", attr
->name
, date
[9]);
5280 "\"%s\": Bad dateTime UTC minutes %u "
5281 "(RFC 2911 section 4.1.14).", attr
->name
, date
[10]);
5286 case IPP_TAG_RESOLUTION
:
5287 for (i
= 0; i
< attr
->num_values
; i
++)
5289 if (attr
->values
[i
].resolution
.xres
<= 0)
5294 "\"%s\": Bad resolution value %dx%d%s - cross "
5295 "feed resolution must be positive "
5296 "(RFC 2911 section 4.1.15).", attr
->name
,
5297 attr
->values
[i
].resolution
.xres
,
5298 attr
->values
[i
].resolution
.yres
,
5299 attr
->values
[i
].resolution
.units
==
5300 IPP_RES_PER_INCH
? "dpi" :
5301 attr
->values
[i
].resolution
.units
==
5302 IPP_RES_PER_CM
? "dpcm" : "unknown");
5305 if (attr
->values
[i
].resolution
.yres
<= 0)
5310 "\"%s\": Bad resolution value %dx%d%s - feed "
5311 "resolution must be positive "
5312 "(RFC 2911 section 4.1.15).", attr
->name
,
5313 attr
->values
[i
].resolution
.xres
,
5314 attr
->values
[i
].resolution
.yres
,
5315 attr
->values
[i
].resolution
.units
==
5316 IPP_RES_PER_INCH
? "dpi" :
5317 attr
->values
[i
].resolution
.units
==
5318 IPP_RES_PER_CM
? "dpcm" : "unknown");
5321 if (attr
->values
[i
].resolution
.units
!= IPP_RES_PER_INCH
&&
5322 attr
->values
[i
].resolution
.units
!= IPP_RES_PER_CM
)
5327 "\"%s\": Bad resolution value %dx%d%s - bad "
5328 "units value (RFC 2911 section 4.1.15).",
5329 attr
->name
, attr
->values
[i
].resolution
.xres
,
5330 attr
->values
[i
].resolution
.yres
,
5331 attr
->values
[i
].resolution
.units
==
5332 IPP_RES_PER_INCH
? "dpi" :
5333 attr
->values
[i
].resolution
.units
==
5334 IPP_RES_PER_CM
? "dpcm" : "unknown");
5339 case IPP_TAG_RANGE
:
5340 for (i
= 0; i
< attr
->num_values
; i
++)
5342 if (attr
->values
[i
].range
.lower
> attr
->values
[i
].range
.upper
)
5347 "\"%s\": Bad rangeOfInteger value %d-%d - lower "
5348 "greater than upper (RFC 2911 section 4.1.13).",
5349 attr
->name
, attr
->values
[i
].range
.lower
,
5350 attr
->values
[i
].range
.upper
);
5355 case IPP_TAG_BEGIN_COLLECTION
:
5356 for (i
= 0; i
< attr
->num_values
; i
++)
5358 for (colattr
= attr
->values
[i
].collection
->attrs
;
5360 colattr
= colattr
->next
)
5362 if (!validate_attr(outfile
, NULL
, colattr
))
5369 if (colattr
&& errors
)
5371 add_stringf(errors
, "\"%s\": Bad collection value.", attr
->name
);
5375 validate_attr(outfile
, errors
, colattr
);
5376 colattr
= colattr
->next
;
5383 case IPP_TAG_TEXTLANG
:
5384 for (i
= 0; i
< attr
->num_values
; i
++)
5386 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5388 if ((*ptr
& 0xe0) == 0xc0)
5391 if ((*ptr
& 0xc0) != 0x80)
5394 else if ((*ptr
& 0xf0) == 0xe0)
5397 if ((*ptr
& 0xc0) != 0x80)
5400 if ((*ptr
& 0xc0) != 0x80)
5403 else if ((*ptr
& 0xf8) == 0xf0)
5406 if ((*ptr
& 0xc0) != 0x80)
5409 if ((*ptr
& 0xc0) != 0x80)
5412 if ((*ptr
& 0xc0) != 0x80)
5415 else if (*ptr
& 0x80)
5424 "\"%s\": Bad text value \"%s\" - bad UTF-8 "
5425 "sequence (RFC 2911 section 4.1.1).", attr
->name
,
5426 attr
->values
[i
].string
.text
);
5429 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_TEXT
- 1))
5434 "\"%s\": Bad text value \"%s\" - bad length %d "
5435 "(RFC 2911 section 4.1.1).", attr
->name
,
5436 attr
->values
[i
].string
.text
,
5437 (int)strlen(attr
->values
[i
].string
.text
));
5443 case IPP_TAG_NAMELANG
:
5444 for (i
= 0; i
< attr
->num_values
; i
++)
5446 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5448 if ((*ptr
& 0xe0) == 0xc0)
5451 if ((*ptr
& 0xc0) != 0x80)
5454 else if ((*ptr
& 0xf0) == 0xe0)
5457 if ((*ptr
& 0xc0) != 0x80)
5460 if ((*ptr
& 0xc0) != 0x80)
5463 else if ((*ptr
& 0xf8) == 0xf0)
5466 if ((*ptr
& 0xc0) != 0x80)
5469 if ((*ptr
& 0xc0) != 0x80)
5472 if ((*ptr
& 0xc0) != 0x80)
5475 else if (*ptr
& 0x80)
5484 "\"%s\": Bad name value \"%s\" - bad UTF-8 "
5485 "sequence (RFC 2911 section 4.1.2).", attr
->name
,
5486 attr
->values
[i
].string
.text
);
5489 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_NAME
- 1))
5494 "\"%s\": Bad name value \"%s\" - bad length %d "
5495 "(RFC 2911 section 4.1.2).", attr
->name
,
5496 attr
->values
[i
].string
.text
,
5497 (int)strlen(attr
->values
[i
].string
.text
));
5502 case IPP_TAG_KEYWORD
:
5503 for (i
= 0; i
< attr
->num_values
; i
++)
5505 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5506 if (!isalnum(*ptr
& 255) && *ptr
!= '-' && *ptr
!= '.' &&
5510 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5515 "\"%s\": Bad keyword value \"%s\" - invalid "
5516 "character (RFC 2911 section 4.1.3).",
5517 attr
->name
, attr
->values
[i
].string
.text
);
5520 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_KEYWORD
- 1))
5525 "\"%s\": Bad keyword value \"%s\" - bad "
5526 "length %d (RFC 2911 section 4.1.3).",
5527 attr
->name
, attr
->values
[i
].string
.text
,
5528 (int)strlen(attr
->values
[i
].string
.text
));
5534 for (i
= 0; i
< attr
->num_values
; i
++)
5536 uri_status
= httpSeparateURI(HTTP_URI_CODING_ALL
,
5537 attr
->values
[i
].string
.text
,
5538 scheme
, sizeof(scheme
),
5539 userpass
, sizeof(userpass
),
5540 hostname
, sizeof(hostname
),
5541 &port
, resource
, sizeof(resource
));
5543 if (uri_status
< HTTP_URI_OK
)
5548 "\"%s\": Bad URI value \"%s\" - %s "
5549 "(RFC 2911 section 4.1.5).", attr
->name
,
5550 attr
->values
[i
].string
.text
,
5551 httpURIStatusString(uri_status
));
5554 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_URI
- 1))
5559 "\"%s\": Bad URI value \"%s\" - bad length %d "
5560 "(RFC 2911 section 4.1.5).", attr
->name
,
5561 attr
->values
[i
].string
.text
,
5562 (int)strlen(attr
->values
[i
].string
.text
));
5567 case IPP_TAG_URISCHEME
:
5568 for (i
= 0; i
< attr
->num_values
; i
++)
5570 ptr
= attr
->values
[i
].string
.text
;
5571 if (islower(*ptr
& 255))
5573 for (ptr
++; *ptr
; ptr
++)
5574 if (!islower(*ptr
& 255) && !isdigit(*ptr
& 255) &&
5575 *ptr
!= '+' && *ptr
!= '-' && *ptr
!= '.')
5579 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5584 "\"%s\": Bad uriScheme value \"%s\" - bad "
5585 "characters (RFC 2911 section 4.1.6).",
5586 attr
->name
, attr
->values
[i
].string
.text
);
5589 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_URISCHEME
- 1))
5594 "\"%s\": Bad uriScheme value \"%s\" - bad "
5595 "length %d (RFC 2911 section 4.1.6).",
5596 attr
->name
, attr
->values
[i
].string
.text
,
5597 (int)strlen(attr
->values
[i
].string
.text
));
5602 case IPP_TAG_CHARSET
:
5603 for (i
= 0; i
< attr
->num_values
; i
++)
5605 for (ptr
= attr
->values
[i
].string
.text
; *ptr
; ptr
++)
5606 if (!isprint(*ptr
& 255) || isupper(*ptr
& 255) ||
5607 isspace(*ptr
& 255))
5610 if (*ptr
|| ptr
== attr
->values
[i
].string
.text
)
5615 "\"%s\": Bad charset value \"%s\" - bad "
5616 "characters (RFC 2911 section 4.1.7).",
5617 attr
->name
, attr
->values
[i
].string
.text
);
5620 if ((ptr
- attr
->values
[i
].string
.text
) > (IPP_MAX_CHARSET
- 1))
5625 "\"%s\": Bad charset value \"%s\" - bad "
5626 "length %d (RFC 2911 section 4.1.7).",
5627 attr
->name
, attr
->values
[i
].string
.text
,
5628 (int)strlen(attr
->values
[i
].string
.text
));
5633 case IPP_TAG_LANGUAGE
:
5635 * The following regular expression is derived from the ABNF for
5636 * language tags in RFC 4646. All I can say is that this is the
5637 * easiest way to check the values...
5640 if ((i
= regcomp(&re
,
5642 "(([a-z]{2,3}(-[a-z][a-z][a-z]){0,3})|[a-z]{4,8})"
5644 "(-[a-z][a-z][a-z][a-z]){0,1}" /* script */
5645 "(-([a-z][a-z]|[0-9][0-9][0-9])){0,1}" /* region */
5646 "(-([a-z]{5,8}|[0-9][0-9][0-9]))*" /* variant */
5647 "(-[a-wy-z](-[a-z0-9]{2,8})+)*" /* extension */
5648 "(-x(-[a-z0-9]{1,8})+)*" /* privateuse */
5650 "x(-[a-z0-9]{1,8})+" /* privateuse */
5652 "[a-z]{1,3}(-[a-z][0-9]{2,8}){1,2}" /* grandfathered */
5654 REG_NOSUB
| REG_EXTENDED
)) != 0)
5656 char temp
[256]; /* Temporary error string */
5658 regerror(i
, &re
, temp
, sizeof(temp
));
5659 print_fatal_error(outfile
, "Unable to compile naturalLanguage regular "
5660 "expression: %s.", temp
);
5664 for (i
= 0; i
< attr
->num_values
; i
++)
5666 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5671 "\"%s\": Bad naturalLanguage value \"%s\" - bad "
5672 "characters (RFC 2911 section 4.1.8).",
5673 attr
->name
, attr
->values
[i
].string
.text
);
5676 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_LANGUAGE
- 1))
5681 "\"%s\": Bad naturalLanguage value \"%s\" - bad "
5682 "length %d (RFC 2911 section 4.1.8).",
5683 attr
->name
, attr
->values
[i
].string
.text
,
5684 (int)strlen(attr
->values
[i
].string
.text
));
5691 case IPP_TAG_MIMETYPE
:
5693 * The following regular expression is derived from the ABNF for
5694 * language tags in RFC 2045 and 4288. All I can say is that this is
5695 * the easiest way to check the values...
5698 if ((i
= regcomp(&re
,
5700 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* type-name */
5702 "[-a-zA-Z0-9!#$&.+^_]{1,127}" /* subtype-name */
5703 "(;[-a-zA-Z0-9!#$&.+^_]{1,127}=" /* parameter= */
5704 "([-a-zA-Z0-9!#$&.+^_]{1,127}|\"[^\"]*\"))*"
5707 REG_NOSUB
| REG_EXTENDED
)) != 0)
5709 char temp
[256]; /* Temporary error string */
5711 regerror(i
, &re
, temp
, sizeof(temp
));
5712 print_fatal_error(outfile
, "Unable to compile mimeMediaType regular "
5713 "expression: %s.", temp
);
5717 for (i
= 0; i
< attr
->num_values
; i
++)
5719 if (regexec(&re
, attr
->values
[i
].string
.text
, 0, NULL
, 0))
5724 "\"%s\": Bad mimeMediaType value \"%s\" - bad "
5725 "characters (RFC 2911 section 4.1.9).",
5726 attr
->name
, attr
->values
[i
].string
.text
);
5729 if (strlen(attr
->values
[i
].string
.text
) > (IPP_MAX_MIMETYPE
- 1))
5734 "\"%s\": Bad mimeMediaType value \"%s\" - bad "
5735 "length %d (RFC 2911 section 4.1.9).",
5736 attr
->name
, attr
->values
[i
].string
.text
,
5737 (int)strlen(attr
->values
[i
].string
.text
));
5753 * 'with_value()' - Test a WITH-VALUE predicate.
5756 static int /* O - 1 on match, 0 on non-match */
5757 with_value(cups_file_t
*outfile
, /* I - Output file */
5758 cups_array_t
*errors
, /* I - Errors array */
5759 char *value
, /* I - Value string */
5760 int flags
, /* I - Flags for match */
5761 ipp_attribute_t
*attr
, /* I - Attribute to compare */
5762 char *matchbuf
, /* I - Buffer to hold matching value */
5763 size_t matchlen
) /* I - Length of match buffer */
5765 int i
, /* Looping var */
5767 char temp
[1024], /* Temporary value string */
5768 *valptr
; /* Pointer into value */
5772 match
= (flags
& _CUPS_WITH_ALL
) ? 1 : 0;
5775 * NULL matches everything.
5778 if (!value
|| !*value
)
5782 * Compare the value string to the attribute value.
5785 switch (attr
->value_tag
)
5787 case IPP_TAG_INTEGER
:
5789 for (i
= 0; i
< attr
->num_values
; i
++)
5791 char op
, /* Comparison operator */
5792 *nextptr
; /* Next pointer */
5793 int intvalue
, /* Integer value */
5794 valmatch
= 0; /* Does the current value match? */
5798 while (isspace(*valptr
& 255) || isdigit(*valptr
& 255) ||
5799 *valptr
== '-' || *valptr
== ',' || *valptr
== '<' ||
5800 *valptr
== '=' || *valptr
== '>')
5803 while (*valptr
&& !isdigit(*valptr
& 255) && *valptr
!= '-')
5805 if (*valptr
== '<' || *valptr
== '>' || *valptr
== '=')
5813 intvalue
= (int)strtol(valptr
, &nextptr
, 0);
5814 if (nextptr
== valptr
)
5818 if ((op
== '=' && attr
->values
[i
].integer
== intvalue
) ||
5819 (op
== '<' && attr
->values
[i
].integer
< intvalue
) ||
5820 (op
== '>' && attr
->values
[i
].integer
> intvalue
))
5823 snprintf(matchbuf
, matchlen
, "%d", attr
->values
[i
].integer
);
5830 if (flags
& _CUPS_WITH_ALL
)
5845 if (!match
&& errors
)
5847 for (i
= 0; i
< attr
->num_values
; i
++)
5848 add_stringf(errors
, "GOT: %s=%d", attr
->name
,
5849 attr
->values
[i
].integer
);
5853 case IPP_TAG_RANGE
:
5854 for (i
= 0; i
< attr
->num_values
; i
++)
5856 char op
, /* Comparison operator */
5857 *nextptr
; /* Next pointer */
5858 int intvalue
, /* Integer value */
5859 valmatch
= 0; /* Does the current value match? */
5863 while (isspace(*valptr
& 255) || isdigit(*valptr
& 255) ||
5864 *valptr
== '-' || *valptr
== ',' || *valptr
== '<' ||
5865 *valptr
== '=' || *valptr
== '>')
5868 while (*valptr
&& !isdigit(*valptr
& 255) && *valptr
!= '-')
5870 if (*valptr
== '<' || *valptr
== '>' || *valptr
== '=')
5878 intvalue
= (int)strtol(valptr
, &nextptr
, 0);
5879 if (nextptr
== valptr
)
5883 if ((op
== '=' && (attr
->values
[i
].range
.lower
== intvalue
||
5884 attr
->values
[i
].range
.upper
== intvalue
)) ||
5885 (op
== '<' && attr
->values
[i
].range
.upper
< intvalue
) ||
5886 (op
== '>' && attr
->values
[i
].range
.upper
> intvalue
))
5889 snprintf(matchbuf
, matchlen
, "%d-%d",
5890 attr
->values
[0].range
.lower
,
5891 attr
->values
[0].range
.upper
);
5898 if (flags
& _CUPS_WITH_ALL
)
5913 if (!match
&& errors
)
5915 for (i
= 0; i
< attr
->num_values
; i
++)
5916 add_stringf(errors
, "GOT: %s=%d-%d", attr
->name
,
5917 attr
->values
[i
].range
.lower
,
5918 attr
->values
[i
].range
.upper
);
5922 case IPP_TAG_BOOLEAN
:
5923 for (i
= 0; i
< attr
->num_values
; i
++)
5925 if ((!strcmp(value
, "true")) == attr
->values
[i
].boolean
)
5928 strlcpy(matchbuf
, value
, matchlen
);
5930 if (!(flags
& _CUPS_WITH_ALL
))
5936 else if (flags
& _CUPS_WITH_ALL
)
5943 if (!match
&& errors
)
5945 for (i
= 0; i
< attr
->num_values
; i
++)
5946 add_stringf(errors
, "GOT: %s=%s", attr
->name
,
5947 attr
->values
[i
].boolean
? "true" : "false");
5951 case IPP_TAG_RESOLUTION
:
5952 for (i
= 0; i
< attr
->num_values
; i
++)
5954 if (attr
->values
[i
].resolution
.xres
==
5955 attr
->values
[i
].resolution
.yres
)
5956 snprintf(temp
, sizeof(temp
), "%d%s",
5957 attr
->values
[i
].resolution
.xres
,
5958 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5961 snprintf(temp
, sizeof(temp
), "%dx%d%s",
5962 attr
->values
[i
].resolution
.xres
,
5963 attr
->values
[i
].resolution
.yres
,
5964 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5967 if (!strcmp(value
, temp
))
5970 strlcpy(matchbuf
, value
, matchlen
);
5972 if (!(flags
& _CUPS_WITH_ALL
))
5978 else if (flags
& _CUPS_WITH_ALL
)
5985 if (!match
&& errors
)
5987 for (i
= 0; i
< attr
->num_values
; i
++)
5989 if (attr
->values
[i
].resolution
.xres
==
5990 attr
->values
[i
].resolution
.yres
)
5991 snprintf(temp
, sizeof(temp
), "%d%s",
5992 attr
->values
[i
].resolution
.xres
,
5993 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
5996 snprintf(temp
, sizeof(temp
), "%dx%d%s",
5997 attr
->values
[i
].resolution
.xres
,
5998 attr
->values
[i
].resolution
.yres
,
5999 attr
->values
[i
].resolution
.units
== IPP_RES_PER_INCH
?
6002 if (strcmp(value
, temp
))
6003 add_stringf(errors
, "GOT: %s=%s", attr
->name
, temp
);
6008 case IPP_TAG_NOVALUE
:
6009 case IPP_TAG_UNKNOWN
:
6012 case IPP_TAG_CHARSET
:
6013 case IPP_TAG_KEYWORD
:
6014 case IPP_TAG_LANGUAGE
:
6015 case IPP_TAG_MIMETYPE
:
6017 case IPP_TAG_NAMELANG
:
6019 case IPP_TAG_TEXTLANG
:
6021 case IPP_TAG_URISCHEME
:
6022 if (flags
& _CUPS_WITH_REGEX
)
6025 * Value is an extended, case-sensitive POSIX regular expression...
6028 regex_t re
; /* Regular expression */
6030 if ((i
= regcomp(&re
, value
, REG_EXTENDED
| REG_NOSUB
)) != 0)
6032 regerror(i
, &re
, temp
, sizeof(temp
));
6034 print_fatal_error(outfile
, "Unable to compile WITH-VALUE regular expression "
6035 "\"%s\" - %s", value
, temp
);
6040 * See if ALL of the values match the given regular expression.
6043 for (i
= 0; i
< attr
->num_values
; i
++)
6045 if (!regexec(&re
, get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
6050 get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
6053 if (!(flags
& _CUPS_WITH_ALL
))
6059 else if (flags
& _CUPS_WITH_ALL
)
6068 else if (ippGetValueTag(attr
) == IPP_TAG_URI
)
6071 * Value is a literal URI string, see if the value(s) match...
6074 for (i
= 0; i
< attr
->num_values
; i
++)
6076 if (!compare_uris(value
, get_string(attr
, i
, flags
, temp
, sizeof(temp
))))
6080 get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
6083 if (!(flags
& _CUPS_WITH_ALL
))
6089 else if (flags
& _CUPS_WITH_ALL
)
6099 * Value is a literal string, see if the value(s) match...
6102 for (i
= 0; i
< attr
->num_values
; i
++)
6104 if (!strcmp(value
, get_string(attr
, i
, flags
, temp
, sizeof(temp
))))
6108 get_string(attr
, i
, flags
, temp
, sizeof(temp
)),
6111 if (!(flags
& _CUPS_WITH_ALL
))
6117 else if (flags
& _CUPS_WITH_ALL
)
6125 if (!match
&& errors
)
6127 for (i
= 0; i
< attr
->num_values
; i
++)
6128 add_stringf(errors
, "GOT: %s=\"%s\"", attr
->name
,
6129 attr
->values
[i
].string
.text
);
6142 * 'with_value_from()' - Test a WITH-VALUE-FROM predicate.
6145 static int /* O - 1 on match, 0 on non-match */
6147 cups_array_t
*errors
, /* I - Errors array */
6148 ipp_attribute_t
*fromattr
, /* I - "From" attribute */
6149 ipp_attribute_t
*attr
, /* I - Attribute to compare */
6150 char *matchbuf
, /* I - Buffer to hold matching value */
6151 size_t matchlen
) /* I - Length of match buffer */
6153 int i
, j
, /* Looping vars */
6154 count
= ippGetCount(attr
), /* Number of attribute values */
6155 match
= 1; /* Match? */
6161 * Compare the from value(s) to the attribute value(s)...
6164 switch (ippGetValueTag(attr
))
6166 case IPP_TAG_INTEGER
:
6167 if (ippGetValueTag(fromattr
) != IPP_TAG_INTEGER
&& ippGetValueTag(fromattr
) != IPP_TAG_RANGE
)
6168 goto wrong_value_tag
;
6170 for (i
= 0; i
< count
; i
++)
6172 int value
= ippGetInteger(attr
, i
);
6173 /* Current integer value */
6175 if (ippContainsInteger(fromattr
, value
))
6178 snprintf(matchbuf
, matchlen
, "%d", value
);
6182 add_stringf(errors
, "GOT: %s=%d", ippGetName(attr
), value
);
6189 if (ippGetValueTag(fromattr
) != IPP_TAG_ENUM
)
6190 goto wrong_value_tag
;
6192 for (i
= 0; i
< count
; i
++)
6194 int value
= ippGetInteger(attr
, i
);
6195 /* Current integer value */
6197 if (ippContainsInteger(fromattr
, value
))
6200 snprintf(matchbuf
, matchlen
, "%d", value
);
6204 add_stringf(errors
, "GOT: %s=%d", ippGetName(attr
), value
);
6210 case IPP_TAG_RESOLUTION
:
6211 if (ippGetValueTag(fromattr
) != IPP_TAG_RESOLUTION
)
6212 goto wrong_value_tag
;
6214 for (i
= 0; i
< count
; i
++)
6218 int fromcount
= ippGetCount(fromattr
);
6219 int fromxres
, fromyres
;
6220 ipp_res_t fromunits
;
6222 xres
= ippGetResolution(attr
, i
, &yres
, &units
);
6224 for (j
= 0; j
< fromcount
; j
++)
6226 fromxres
= ippGetResolution(fromattr
, j
, &fromyres
, &fromunits
);
6227 if (fromxres
== xres
&& fromyres
== yres
&& fromunits
== units
)
6236 snprintf(matchbuf
, matchlen
, "%d%s", xres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
6238 snprintf(matchbuf
, matchlen
, "%dx%d%s", xres
, yres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
6244 add_stringf(errors
, "GOT: %s=%d%s", ippGetName(attr
), xres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
6246 add_stringf(errors
, "GOT: %s=%dx%d%s", ippGetName(attr
), xres
, yres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
6253 case IPP_TAG_NOVALUE
:
6254 case IPP_TAG_UNKNOWN
:
6257 case IPP_TAG_CHARSET
:
6258 case IPP_TAG_KEYWORD
:
6259 case IPP_TAG_LANGUAGE
:
6260 case IPP_TAG_MIMETYPE
:
6262 case IPP_TAG_NAMELANG
:
6264 case IPP_TAG_TEXTLANG
:
6266 case IPP_TAG_URISCHEME
:
6267 for (i
= 0; i
< count
; i
++)
6269 const char *value
= ippGetString(attr
, i
, NULL
);
6270 /* Current string value */
6272 if (ippContainsString(fromattr
, value
))
6275 strlcpy(matchbuf
, value
, matchlen
);
6279 add_stringf(errors
, "GOT: %s='%s'", ippGetName(attr
), value
);
6292 /* value tag mismatch between fromattr and attr */
6295 add_stringf(errors
, "GOT: %s OF-TYPE %s", ippGetName(attr
), ippTagString(ippGetValueTag(attr
)));