2 * "$Id: testdest.c 11884 2014-05-16 21:54:22Z msweet $"
4 * CUPS destination API test program for CUPS.
6 * Copyright 2014 by Apple Inc.
8 * These coded instructions, statements, and computer programs are the
9 * property of Apple Inc. and are protected by Federal copyright
10 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
11 * which should have been included with this file. If this file is
12 * file is missing or damaged, see the license at "http://www.cups.org/".
14 * This file is subject to the Apple OS-Developed Software exception.
18 * Include necessary headers...
29 static void localize(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, const char *option
, const char *value
);
30 static void print_file(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, const char *filename
, int num_options
, cups_option_t
*options
);
31 static void show_conflicts(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, int num_options
, cups_option_t
*options
);
32 static void show_default(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, const char *option
);
33 static void show_media(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, unsigned flags
, const char *name
);
34 static void show_supported(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, const char *option
, const char *value
);
35 static void usage(const char *arg
) __attribute__((noreturn
));
39 * 'main()' - Main entry.
42 int /* O - Exit status */
43 main(int argc
, /* I - Number of command-line arguments */
44 char *argv
[]) /* I - Command-line arguments */
46 http_t
*http
; /* Connection to destination */
47 cups_dest_t
*dest
= NULL
; /* Destination */
48 cups_dinfo_t
*dinfo
; /* Destination info */
54 if (!strcmp(argv
[1], "--enum"))
58 else if (!strncmp(argv
[1], "ipp://", 6) || !strncmp(argv
[1], "ipps://", 7))
59 dest
= cupsGetDestWithURI(NULL
, argv
[1]);
61 dest
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, argv
[1], NULL
);
65 printf("testdest: Unable to get destination \"%s\": %s\n", argv
[1], cupsLastErrorString());
69 if ((http
= cupsConnectDest(dest
, CUPS_DEST_FLAGS_NONE
, 30000, NULL
, NULL
, 0, NULL
, NULL
)) == NULL
)
71 printf("testdest: Unable to connect to destination \"%s\": %s\n", argv
[1], cupsLastErrorString());
75 if ((dinfo
= cupsCopyDestInfo(http
, dest
)) == NULL
)
77 printf("testdest: Unable to get information for destination \"%s\": %s\n", argv
[1], cupsLastErrorString());
81 if (argc
== 2 || (!strcmp(argv
[2], "supported") && argc
< 6))
84 show_supported(http
, dest
, dinfo
, argv
[3], argv
[4]);
86 show_supported(http
, dest
, dinfo
, argv
[3], NULL
);
88 show_supported(http
, dest
, dinfo
, NULL
, NULL
);
90 else if (!strcmp(argv
[2], "conflicts") && argc
> 3)
92 int i
, /* Looping var */
93 num_options
= 0;/* Number of options */
94 cups_option_t
*options
= NULL
;/* Options */
96 for (i
= 3; i
< argc
; i
++)
97 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
99 show_conflicts(http
, dest
, dinfo
, num_options
, options
);
101 else if (!strcmp(argv
[2], "default") && argc
== 4)
103 show_default(http
, dest
, dinfo
, argv
[3]);
105 else if (!strcmp(argv
[2], "localize") && argc
> 3 && argc
< 6)
107 localize(http
, dest
, dinfo
, argv
[3], argv
[4]);
109 else if (!strcmp(argv
[2], "media"))
111 int i
; /* Looping var */
112 const char *name
= NULL
; /* Media name, if any */
113 unsigned flags
= CUPS_MEDIA_FLAGS_DEFAULT
;
114 /* Media selection flags */
116 for (i
= 3; i
< argc
; i
++)
118 if (!strcmp(argv
[i
], "borderless"))
119 flags
= CUPS_MEDIA_FLAGS_BORDERLESS
;
120 else if (!strcmp(argv
[i
], "duplex"))
121 flags
= CUPS_MEDIA_FLAGS_DUPLEX
;
122 else if (!strcmp(argv
[i
], "exact"))
123 flags
= CUPS_MEDIA_FLAGS_EXACT
;
124 else if (!strcmp(argv
[i
], "ready"))
125 flags
= CUPS_MEDIA_FLAGS_READY
;
132 show_media(http
, dest
, dinfo
, flags
, name
);
134 else if (!strcmp(argv
[2], "print") && argc
> 3)
136 int i
, /* Looping var */
137 num_options
= 0;/* Number of options */
138 cups_option_t
*options
= NULL
;/* Options */
140 for (i
= 4; i
< argc
; i
++)
141 num_options
= cupsParseOptions(argv
[i
], num_options
, &options
);
143 print_file(http
, dest
, dinfo
, argv
[3], num_options
, options
);
153 * 'localize()' - Localize an option and value.
157 localize(http_t
*http
, /* I - Connection to destination */
158 cups_dest_t
*dest
, /* I - Destination */
159 cups_dinfo_t
*dinfo
, /* I - Destination information */
160 const char *option
, /* I - Option */
161 const char *value
) /* I - Value, if any */
172 * 'print_file()' - Print a file.
176 print_file(http_t
*http
, /* I - Connection to destination */
177 cups_dest_t
*dest
, /* I - Destination */
178 cups_dinfo_t
*dinfo
, /* I - Destination information */
179 const char *filename
, /* I - File to print */
180 int num_options
, /* I - Number of options */
181 cups_option_t
*options
) /* I - Options */
193 * 'show_conflicts()' - Show conflicts for selected options.
198 http_t
*http
, /* I - Connection to destination */
199 cups_dest_t
*dest
, /* I - Destination */
200 cups_dinfo_t
*dinfo
, /* I - Destination information */
201 int num_options
, /* I - Number of options */
202 cups_option_t
*options
) /* I - Options */
213 * 'show_default()' - Show default value for option.
217 show_default(http_t
*http
, /* I - Connection to destination */
218 cups_dest_t
*dest
, /* I - Destination */
219 cups_dinfo_t
*dinfo
, /* I - Destination information */
220 const char *option
) /* I - Option */
230 * 'show_media()' - Show available media.
234 show_media(http_t
*http
, /* I - Connection to destination */
235 cups_dest_t
*dest
, /* I - Destination */
236 cups_dinfo_t
*dinfo
, /* I - Destination information */
237 unsigned flags
, /* I - Media flags */
238 const char *name
) /* I - Size name */
240 int i
, /* Looping var */
241 count
; /* Number of sizes */
242 cups_size_t size
; /* Media size info */
247 double dw
, dl
; /* Width and length from name */
248 char units
[32]; /* Units */
249 int width
, /* Width in 100ths of millimeters */
250 length
; /* Length in 100ths of millimeters */
253 if (sscanf(name
, "%lfx%lf%31s", &dw
, &dl
, units
) == 3)
255 if (!strcmp(units
, "in"))
257 width
= (int)(dw
* 2540.0);
258 length
= (int)(dl
* 2540.0);
260 else if (!strcmp(units
, "mm"))
262 width
= (int)(dw
* 100.0);
263 length
= (int)(dl
* 100.0);
267 puts(" bad units in size");
271 if (cupsGetDestMediaBySize(http
, dest
, dinfo
, width
, length
, flags
, &size
))
273 printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size
.media
, cupsLocalizeDestMedia(http
, dest
, dinfo
, flags
, &size
), size
.width
, size
.length
, size
.bottom
, size
.left
, size
.right
, size
.top
);
277 puts(" not supported");
280 else if (cupsGetDestMediaByName(http
, dest
, dinfo
, name
, flags
, &size
))
282 printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size
.media
, cupsLocalizeDestMedia(http
, dest
, dinfo
, flags
, &size
), size
.width
, size
.length
, size
.bottom
, size
.left
, size
.right
, size
.top
);
286 puts(" not supported");
291 count
= cupsGetDestMediaCount(http
, dest
, dinfo
, flags
);
292 printf("%d size%s:\n", count
, count
== 1 ? "" : "s");
294 for (i
= 0; i
< count
; i
++)
296 if (cupsGetDestMediaByIndex(http
, dest
, dinfo
, i
, flags
, &size
))
297 printf(" %s (%s) %dx%d B%d L%d R%d T%d\n", size
.media
, cupsLocalizeDestMedia(http
, dest
, dinfo
, flags
, &size
), size
.width
, size
.length
, size
.bottom
, size
.left
, size
.right
, size
.top
);
306 * 'show_supported()' - Show supported options, values, etc.
310 show_supported(http_t
*http
, /* I - Connection to destination */
311 cups_dest_t
*dest
, /* I - Destination */
312 cups_dinfo_t
*dinfo
, /* I - Destination information */
313 const char *option
, /* I - Option, if any */
314 const char *value
) /* I - Value, if any */
316 ipp_attribute_t
*attr
; /* Attribute */
317 int i
, /* Looping var */
318 count
; /* Number of values */
323 attr
= cupsFindDestSupported(http
, dest
, dinfo
, "job-creation-attributes");
326 count
= ippGetCount(attr
);
327 for (i
= 0; i
< count
; i
++)
328 show_supported(http
, dest
, dinfo
, ippGetString(attr
, i
, NULL
), NULL
);
332 static const char * const options
[] =
333 { /* List of standard options */
339 CUPS_PRINT_COLOR_MODE
,
344 puts("No job-creation-attributes-supported attribute, probing instead.");
346 for (i
= 0; i
< (int)(sizeof(options
) / sizeof(options
[0])); i
++)
347 if (cupsCheckDestSupported(http
, dest
, dinfo
, options
[i
], NULL
))
348 show_supported(http
, dest
, dinfo
, options
[i
], NULL
);
354 if ((attr
= cupsFindDestSupported(http
, dest
, dinfo
, option
)) != NULL
)
356 count
= ippGetCount(attr
);
358 switch (ippGetValueTag(attr
))
360 case IPP_TAG_INTEGER
:
361 for (i
= 0; i
< count
; i
++)
362 printf(" %d\n", ippGetInteger(attr
, i
));
366 for (i
= 0; i
< count
; i
++)
367 printf(" %s\n", ippEnumString(option
, ippGetInteger(attr
, i
)));
371 for (i
= 0; i
< count
; i
++)
373 int upper
, lower
= ippGetRange(attr
, i
, &upper
);
375 printf(" %d-%d\n", lower
, upper
);
379 case IPP_TAG_TEXTLANG
:
380 case IPP_TAG_NAMELANG
:
383 case IPP_TAG_KEYWORD
:
385 case IPP_TAG_URISCHEME
:
386 case IPP_TAG_CHARSET
:
387 case IPP_TAG_LANGUAGE
:
388 case IPP_TAG_MIMETYPE
:
389 for (i
= 0; i
< count
; i
++)
390 printf(" %s\n", ippGetString(attr
, i
, NULL
));
393 case IPP_TAG_STRING
:
394 for (i
= 0; i
< count
; i
++)
397 unsigned char *data
= ippGetOctetString(attr
, i
, &len
);
400 for (j
= 0; j
< len
; j
++)
402 if (data
[j
] < ' ' || data
[j
] >= 0x7f)
403 printf("<%02X>", data
[j
]);
411 case IPP_TAG_BOOLEAN
:
415 printf(" %s\n", ippTagString(ippGetValueTag(attr
)));
421 else if (cupsCheckDestSupported(http
, dest
, dinfo
, option
, value
))
430 * 'usage()' - Show program usage.
434 usage(const char *arg
) /* I - Argument for usage message */
437 printf("testdest: Unknown option \"%s\".\n", arg
);
440 puts(" ./testdest name [operation ...]");
441 puts(" ./testdest ipp://... [operation ...]");
442 puts(" ./testdest ipps://... [operation ...]");
443 puts(" ./testdest --enum [grayscale] [color] [duplex] [staple] [small]\n"
444 " [medium] [large]");
447 puts(" conflicts options");
448 puts(" default option");
449 puts(" localize option [value]");
450 puts(" media [borderless] [duplex] [exact] [ready] [name or size]");
451 puts(" print filename [options]");
452 puts(" supported [option [value]]");
459 * End of "$Id: testdest.c 11884 2014-05-16 21:54:22Z msweet $".