]>
git.ipfire.org Git - thirdparty/cups.git/blob - cups/testthreads.c
2 * Threaded test program for CUPS.
4 * Copyright © 2012-2019 by Apple Inc.
6 * Licensed under Apache License v2.0. See the file "LICENSE" for more
11 * Include necessary headers...
16 #include <cups/cups.h>
17 #include <cups/thread-private.h>
24 static int enum_dests_cb(void *_name
, unsigned flags
, cups_dest_t
*dest
);
25 static void *run_query(cups_dest_t
*dest
);
26 static void show_supported(http_t
*http
, cups_dest_t
*dest
, cups_dinfo_t
*dinfo
, const char *option
, const char *value
);
30 * 'main()' - Main entry.
33 int /* O - Exit status */
34 main(int argc
, /* I - Number of command-line arguments */
35 char *argv
[]) /* I - Command-line arguments */
38 * Go through all the available destinations to find the requested one...
43 cupsEnumDests(CUPS_DEST_FLAGS_NONE
, -1, NULL
, 0, 0, enum_dests_cb
, argv
[1]);
50 * 'enum_dests_cb()' - Destination enumeration function...
53 static int /* O - 1 to continue, 0 to stop */
54 enum_dests_cb(void *_name
, /* I - Printer name, if any */
55 unsigned flags
, /* I - Enumeration flags */
56 cups_dest_t
*dest
) /* I - Found destination */
58 const char *name
= (const char *)_name
;
60 cups_dest_t
*cdest
; /* Copied destination */
66 * If a name was specified, compare it...
69 if (name
&& strcasecmp(name
, dest
->name
))
70 return (1); /* Continue */
73 * Copy the destination and run the query on a separate thread...
76 cupsCopyDest(dest
, 0, &cdest
);
77 _cupsThreadWait(_cupsThreadCreate((_cups_thread_func_t
)run_query
, cdest
));
79 cupsFreeDests(1, cdest
);
82 * Continue if no name was specified or the name matches...
85 return (!name
|| !strcasecmp(name
, dest
->name
));
90 * 'run_query()' - Query printer capabilities on a separate thread.
93 static void * /* O - Return value (not used) */
94 run_query(cups_dest_t
*dest
) /* I - Destination to query */
96 http_t
*http
; /* Connection to destination */
97 cups_dinfo_t
*dinfo
; /* Destination info */
98 unsigned dflags
= CUPS_DEST_FLAGS_NONE
;
99 /* Destination flags */
102 if ((http
= cupsConnectDest(dest
, dflags
, 300, NULL
, NULL
, 0, NULL
, NULL
)) == NULL
)
104 printf("testthreads: Unable to connect to destination \"%s\": %s\n", dest
->name
, cupsLastErrorString());
108 if ((dinfo
= cupsCopyDestInfo(http
, dest
)) == NULL
)
110 printf("testdest: Unable to get information for destination \"%s\": %s\n", dest
->name
, cupsLastErrorString());
114 printf("\n%s:\n", dest
->name
);
116 show_supported(http
, dest
, dinfo
, NULL
, NULL
);
124 * 'show_supported()' - Show supported options, values, etc.
128 show_supported(http_t
*http
, /* I - Connection to destination */
129 cups_dest_t
*dest
, /* I - Destination */
130 cups_dinfo_t
*dinfo
, /* I - Destination information */
131 const char *option
, /* I - Option, if any */
132 const char *value
) /* I - Value, if any */
134 ipp_attribute_t
*attr
; /* Attribute */
135 int i
, /* Looping var */
136 count
; /* Number of values */
141 attr
= cupsFindDestSupported(http
, dest
, dinfo
, "job-creation-attributes");
144 count
= ippGetCount(attr
);
145 for (i
= 0; i
< count
; i
++)
146 show_supported(http
, dest
, dinfo
, ippGetString(attr
, i
, NULL
), NULL
);
150 static const char * const options
[] =
151 { /* List of standard options */
157 CUPS_PRINT_COLOR_MODE
,
162 puts(" No job-creation-attributes-supported attribute, probing instead.");
164 for (i
= 0; i
< (int)(sizeof(options
) / sizeof(options
[0])); i
++)
165 if (cupsCheckDestSupported(http
, dest
, dinfo
, options
[i
], NULL
))
166 show_supported(http
, dest
, dinfo
, options
[i
], NULL
);
171 printf(" %s (%s - %s)\n", option
, cupsLocalizeDestOption(http
, dest
, dinfo
, option
), cupsCheckDestSupported(http
, dest
, dinfo
, option
, NULL
) ? "supported" : "not-supported");
173 if ((attr
= cupsFindDestSupported(http
, dest
, dinfo
, option
)) != NULL
)
175 count
= ippGetCount(attr
);
177 switch (ippGetValueTag(attr
))
179 case IPP_TAG_INTEGER
:
180 for (i
= 0; i
< count
; i
++)
181 printf(" %d\n", ippGetInteger(attr
, i
));
185 for (i
= 0; i
< count
; i
++)
187 int val
= ippGetInteger(attr
, i
);
190 snprintf(valstr
, sizeof(valstr
), "%d", val
);
191 printf(" %s (%s)\n", ippEnumString(option
, ippGetInteger(attr
, i
)), cupsLocalizeDestValue(http
, dest
, dinfo
, option
, valstr
));
196 for (i
= 0; i
< count
; i
++)
198 int upper
, lower
= ippGetRange(attr
, i
, &upper
);
200 printf(" %d-%d\n", lower
, upper
);
204 case IPP_TAG_RESOLUTION
:
205 for (i
= 0; i
< count
; i
++)
209 xres
= ippGetResolution(attr
, i
, &yres
, &units
);
212 printf(" %d%s\n", xres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
214 printf(" %dx%d%s\n", xres
, yres
, units
== IPP_RES_PER_INCH
? "dpi" : "dpcm");
218 case IPP_TAG_KEYWORD
:
219 for (i
= 0; i
< count
; i
++)
220 printf(" %s (%s)\n", ippGetString(attr
, i
, NULL
), cupsLocalizeDestValue(http
, dest
, dinfo
, option
, ippGetString(attr
, i
, NULL
)));
223 case IPP_TAG_TEXTLANG
:
224 case IPP_TAG_NAMELANG
:
228 case IPP_TAG_URISCHEME
:
229 case IPP_TAG_CHARSET
:
230 case IPP_TAG_LANGUAGE
:
231 case IPP_TAG_MIMETYPE
:
232 for (i
= 0; i
< count
; i
++)
233 printf(" %s\n", ippGetString(attr
, i
, NULL
));
236 case IPP_TAG_STRING
:
237 for (i
= 0; i
< count
; i
++)
240 unsigned char *data
= ippGetOctetString(attr
, i
, &len
);
243 for (j
= 0; j
< len
; j
++)
245 if (data
[j
] < ' ' || data
[j
] >= 0x7f)
246 printf("<%02X>", data
[j
]);
254 case IPP_TAG_BOOLEAN
:
258 printf(" %s\n", ippTagString(ippGetValueTag(attr
)));
264 else if (cupsCheckDestSupported(http
, dest
, dinfo
, option
, value
))