]>
Commit | Line | Data |
---|---|---|
ef416fc2 | 1 | /* |
f2d18633 | 2 | * "$Id$" |
ef416fc2 | 3 | * |
5a1d7a17 | 4 | * "lpstat" command for CUPS. |
ef416fc2 | 5 | * |
7e86f2f6 | 6 | * Copyright 2007-2014 by Apple Inc. |
5a1d7a17 | 7 | * Copyright 1997-2006 by Easy Software Products. |
ef416fc2 | 8 | * |
5a1d7a17 MS |
9 | * These coded instructions, statements, and computer programs are the |
10 | * property of Apple Inc. and are protected by Federal copyright | |
11 | * law. Distribution and use rights are outlined in the file "LICENSE.txt" | |
12 | * which should have been included with this file. If this file is | |
13 | * file is missing or damaged, see the license at "http://www.cups.org/". | |
ef416fc2 | 14 | */ |
15 | ||
16 | /* | |
17 | * Include necessary headers... | |
18 | */ | |
19 | ||
71e16022 | 20 | #include <cups/cups-private.h> |
ef416fc2 | 21 | |
22 | ||
23 | /* | |
24 | * Local functions... | |
25 | */ | |
26 | ||
61cf44e2 MS |
27 | static void check_dest(const char *command, const char *name, |
28 | int *num_dests, cups_dest_t **dests); | |
29 | static int match_list(const char *list, const char *name); | |
30 | static int show_accepting(const char *printers, int num_dests, | |
31 | cups_dest_t *dests); | |
32 | static int show_classes(const char *dests); | |
33 | static void show_default(cups_dest_t *dest); | |
34 | static int show_devices(const char *printers, int num_dests, | |
35 | cups_dest_t *dests); | |
36 | static int show_jobs(const char *dests, const char *users, int long_status, | |
37 | int ranking, const char *which); | |
38 | static int show_printers(const char *printers, int num_dests, | |
39 | cups_dest_t *dests, int long_status); | |
40 | static void show_scheduler(void); | |
ef416fc2 | 41 | |
42 | ||
43 | /* | |
44 | * 'main()' - Parse options and show status information. | |
45 | */ | |
46 | ||
47 | int | |
ed486911 | 48 | main(int argc, /* I - Number of command-line arguments */ |
49 | char *argv[]) /* I - Command-line arguments */ | |
ef416fc2 | 50 | { |
ed486911 | 51 | int i, /* Looping var */ |
52 | status; /* Exit status */ | |
ed486911 | 53 | int num_dests; /* Number of user destinations */ |
54 | cups_dest_t *dests; /* User destinations */ | |
55 | int long_status; /* Long status report? */ | |
56 | int ranking; /* Show job ranking? */ | |
57 | const char *which; /* Which jobs to show? */ | |
58 | char op; /* Last operation on command-line */ | |
ef416fc2 | 59 | |
60 | ||
07725fee | 61 | _cupsSetLocale(argv); |
ed486911 | 62 | |
ed486911 | 63 | /* |
64 | * Parse command-line options... | |
65 | */ | |
66 | ||
ef416fc2 | 67 | num_dests = 0; |
68 | dests = NULL; | |
69 | long_status = 0; | |
70 | ranking = 0; | |
71 | status = 0; | |
72 | which = "not-completed"; | |
73 | op = 0; | |
74 | ||
75 | for (i = 1; i < argc; i ++) | |
76 | if (argv[i][0] == '-') | |
77 | switch (argv[i][1]) | |
78 | { | |
79 | case 'D' : /* Show description */ | |
80 | long_status = 1; | |
81 | break; | |
82 | ||
83 | case 'E' : /* Encrypt */ | |
84 | #ifdef HAVE_SSL | |
85 | cupsSetEncryption(HTTP_ENCRYPT_REQUIRED); | |
ef416fc2 | 86 | #else |
fa73b229 | 87 | _cupsLangPrintf(stderr, |
0837b7e8 | 88 | _("%s: Sorry, no encryption support."), |
ef416fc2 | 89 | argv[0]); |
90 | #endif /* HAVE_SSL */ | |
91 | break; | |
92 | ||
49d87452 MS |
93 | case 'H' : /* Show server and port */ |
94 | if (cupsServer()[0] == '/') | |
0837b7e8 | 95 | _cupsLangPuts(stdout, cupsServer()); |
49d87452 | 96 | else |
0837b7e8 | 97 | _cupsLangPrintf(stdout, "%s:%d", cupsServer(), ippPort()); |
e200616a | 98 | op = 'H'; |
49d87452 MS |
99 | break; |
100 | ||
ef416fc2 | 101 | case 'P' : /* Show paper types */ |
102 | op = 'P'; | |
103 | break; | |
104 | ||
105 | case 'R' : /* Show ranking */ | |
106 | ranking = 1; | |
107 | break; | |
108 | ||
109 | case 'S' : /* Show charsets */ | |
110 | op = 'S'; | |
111 | if (!argv[i][2]) | |
112 | i ++; | |
113 | break; | |
114 | ||
fa73b229 | 115 | case 'U' : /* Username */ |
61cf44e2 | 116 | if (argv[i][2]) |
fa73b229 | 117 | cupsSetUser(argv[i] + 2); |
118 | else | |
119 | { | |
120 | i ++; | |
121 | if (i >= argc) | |
122 | { | |
123 | _cupsLangPrintf(stderr, | |
124 | _("%s: Error - expected username after " | |
0837b7e8 | 125 | "\"-U\" option."), |
fa73b229 | 126 | argv[0]); |
127 | return (1); | |
128 | } | |
129 | ||
130 | cupsSetUser(argv[i]); | |
131 | } | |
132 | break; | |
88f9aafc | 133 | |
ef416fc2 | 134 | case 'W' : /* Show which jobs? */ |
135 | if (argv[i][2]) | |
136 | which = argv[i] + 2; | |
137 | else | |
138 | { | |
139 | i ++; | |
140 | ||
141 | if (i >= argc) | |
142 | { | |
fa73b229 | 143 | _cupsLangPrintf(stderr, |
144 | _("%s: Error - need \"completed\", " | |
145 | "\"not-completed\", or \"all\" after " | |
0837b7e8 | 146 | "\"-W\" option."), |
fa73b229 | 147 | argv[0]); |
ef416fc2 | 148 | return (1); |
149 | } | |
150 | ||
151 | which = argv[i]; | |
152 | } | |
153 | ||
fa73b229 | 154 | if (strcmp(which, "completed") && strcmp(which, "not-completed") && |
155 | strcmp(which, "all")) | |
ef416fc2 | 156 | { |
fa73b229 | 157 | _cupsLangPrintf(stderr, |
158 | _("%s: Error - need \"completed\", " | |
159 | "\"not-completed\", or \"all\" after " | |
0837b7e8 | 160 | "\"-W\" option."), |
fa73b229 | 161 | argv[0]); |
ef416fc2 | 162 | return (1); |
163 | } | |
164 | break; | |
165 | ||
166 | case 'a' : /* Show acceptance status */ | |
61cf44e2 | 167 | op = 'a'; |
ef416fc2 | 168 | |
61cf44e2 | 169 | if (argv[i][2]) |
ef416fc2 | 170 | { |
61cf44e2 | 171 | check_dest(argv[0], argv[i] + 2, &num_dests, &dests); |
ef416fc2 | 172 | |
61cf44e2 | 173 | status |= show_accepting(argv[i] + 2, num_dests, dests); |
ef416fc2 | 174 | } |
175 | else if ((i + 1) < argc && argv[i + 1][0] != '-') | |
176 | { | |
177 | i ++; | |
178 | ||
61cf44e2 | 179 | check_dest(argv[0], argv[i], &num_dests, &dests); |
ef416fc2 | 180 | |
61cf44e2 | 181 | status |= show_accepting(argv[i], num_dests, dests); |
ef416fc2 | 182 | } |
183 | else | |
184 | { | |
61cf44e2 MS |
185 | if (num_dests <= 1) |
186 | { | |
187 | cupsFreeDests(num_dests, dests); | |
188 | num_dests = cupsGetDests(&dests); | |
c606bcae MS |
189 | |
190 | if (num_dests == 0 && | |
191 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
192 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
193 | { | |
194 | _cupsLangPrintf(stderr, | |
195 | _("%s: Error - add '/version=1.1' to server " | |
196 | "name."), argv[0]); | |
197 | return (1); | |
198 | } | |
61cf44e2 | 199 | } |
ef416fc2 | 200 | |
61cf44e2 | 201 | status |= show_accepting(NULL, num_dests, dests); |
ef416fc2 | 202 | } |
203 | break; | |
204 | ||
ef416fc2 | 205 | case 'c' : /* Show classes and members */ |
61cf44e2 | 206 | op = 'c'; |
ef416fc2 | 207 | |
61cf44e2 | 208 | if (argv[i][2]) |
ef416fc2 | 209 | { |
61cf44e2 | 210 | check_dest(argv[0], argv[i] + 2, &num_dests, &dests); |
ef416fc2 | 211 | |
61cf44e2 | 212 | status |= show_classes(argv[i] + 2); |
ef416fc2 | 213 | } |
214 | else if ((i + 1) < argc && argv[i + 1][0] != '-') | |
215 | { | |
216 | i ++; | |
217 | ||
61cf44e2 | 218 | check_dest(argv[0], argv[i], &num_dests, &dests); |
ef416fc2 | 219 | |
61cf44e2 | 220 | status |= show_classes(argv[i]); |
ef416fc2 | 221 | } |
222 | else | |
61cf44e2 | 223 | status |= show_classes(NULL); |
ef416fc2 | 224 | break; |
225 | ||
226 | case 'd' : /* Show default destination */ | |
61cf44e2 | 227 | op = 'd'; |
ef416fc2 | 228 | |
61cf44e2 MS |
229 | if (num_dests != 1 || !dests[0].is_default) |
230 | { | |
231 | cupsFreeDests(num_dests, dests); | |
ef416fc2 | 232 | |
61cf44e2 MS |
233 | dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, NULL, NULL); |
234 | num_dests = dests ? 1 : 0; | |
c606bcae MS |
235 | |
236 | if (num_dests == 0 && | |
237 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
238 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
239 | { | |
240 | _cupsLangPrintf(stderr, | |
241 | _("%s: Error - add '/version=1.1' to server " | |
242 | "name."), argv[0]); | |
243 | return (1); | |
244 | } | |
61cf44e2 MS |
245 | } |
246 | ||
247 | show_default(dests); | |
ef416fc2 | 248 | break; |
249 | ||
250 | case 'f' : /* Show forms */ | |
251 | op = 'f'; | |
252 | if (!argv[i][2]) | |
253 | i ++; | |
254 | break; | |
255 | ||
256 | case 'h' : /* Connect to host */ | |
61cf44e2 | 257 | if (argv[i][2]) |
ef416fc2 | 258 | cupsSetServer(argv[i] + 2); |
259 | else | |
260 | { | |
261 | i ++; | |
262 | ||
263 | if (i >= argc) | |
264 | { | |
fa73b229 | 265 | _cupsLangPrintf(stderr, |
266 | _("%s: Error - expected hostname after " | |
0837b7e8 | 267 | "\"-h\" option."), |
fa73b229 | 268 | argv[0]); |
ef416fc2 | 269 | return (1); |
270 | } | |
271 | ||
272 | cupsSetServer(argv[i]); | |
273 | } | |
274 | break; | |
275 | ||
276 | case 'l' : /* Long status or long job status */ | |
3dd9c340 | 277 | long_status = 2; |
ef416fc2 | 278 | break; |
279 | ||
280 | case 'o' : /* Show jobs by destination */ | |
61cf44e2 | 281 | op = 'o'; |
ef416fc2 | 282 | |
61cf44e2 | 283 | if (argv[i][2]) |
ef416fc2 | 284 | { |
61cf44e2 | 285 | check_dest(argv[0], argv[i] + 2, &num_dests, &dests); |
ef416fc2 | 286 | |
61cf44e2 MS |
287 | status |= show_jobs(argv[i] + 2, NULL, long_status, ranking, |
288 | which); | |
ef416fc2 | 289 | } |
290 | else if ((i + 1) < argc && argv[i + 1][0] != '-') | |
291 | { | |
292 | i ++; | |
293 | ||
61cf44e2 | 294 | check_dest(argv[0], argv[i], &num_dests, &dests); |
ef416fc2 | 295 | |
61cf44e2 | 296 | status |= show_jobs(argv[i], NULL, long_status, ranking, which); |
ef416fc2 | 297 | } |
298 | else | |
61cf44e2 | 299 | status |= show_jobs(NULL, NULL, long_status, ranking, which); |
ef416fc2 | 300 | break; |
301 | ||
302 | case 'p' : /* Show printers */ | |
61cf44e2 | 303 | op = 'p'; |
ef416fc2 | 304 | |
61cf44e2 | 305 | if (argv[i][2]) |
ef416fc2 | 306 | { |
61cf44e2 | 307 | check_dest(argv[0], argv[i] + 2, &num_dests, &dests); |
ef416fc2 | 308 | |
61cf44e2 MS |
309 | status |= show_printers(argv[i] + 2, num_dests, dests, |
310 | long_status); | |
ef416fc2 | 311 | } |
312 | else if ((i + 1) < argc && argv[i + 1][0] != '-') | |
313 | { | |
314 | i ++; | |
315 | ||
61cf44e2 | 316 | check_dest(argv[0], argv[i], &num_dests, &dests); |
ef416fc2 | 317 | |
61cf44e2 | 318 | status |= show_printers(argv[i], num_dests, dests, long_status); |
ef416fc2 | 319 | } |
320 | else | |
321 | { | |
61cf44e2 MS |
322 | if (num_dests <= 1) |
323 | { | |
324 | cupsFreeDests(num_dests, dests); | |
325 | num_dests = cupsGetDests(&dests); | |
c606bcae MS |
326 | |
327 | if (num_dests == 0 && | |
328 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
329 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
330 | { | |
331 | _cupsLangPrintf(stderr, | |
332 | _("%s: Error - add '/version=1.1' to server " | |
333 | "name."), argv[0]); | |
334 | return (1); | |
335 | } | |
61cf44e2 | 336 | } |
ef416fc2 | 337 | |
61cf44e2 | 338 | status |= show_printers(NULL, num_dests, dests, long_status); |
ef416fc2 | 339 | } |
340 | break; | |
341 | ||
342 | case 'r' : /* Show scheduler status */ | |
61cf44e2 | 343 | op = 'r'; |
ef416fc2 | 344 | |
61cf44e2 | 345 | show_scheduler(); |
ef416fc2 | 346 | break; |
347 | ||
348 | case 's' : /* Show summary */ | |
61cf44e2 | 349 | op = 's'; |
ef416fc2 | 350 | |
61cf44e2 MS |
351 | if (num_dests <= 1) |
352 | { | |
353 | cupsFreeDests(num_dests, dests); | |
354 | num_dests = cupsGetDests(&dests); | |
c606bcae MS |
355 | |
356 | if (num_dests == 0 && | |
357 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
358 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
359 | { | |
360 | _cupsLangPrintf(stderr, | |
361 | _("%s: Error - add '/version=1.1' to server " | |
362 | "name."), argv[0]); | |
363 | return (1); | |
364 | } | |
61cf44e2 | 365 | } |
ef416fc2 | 366 | |
61cf44e2 MS |
367 | show_default(cupsGetDest(NULL, NULL, num_dests, dests)); |
368 | status |= show_classes(NULL); | |
369 | status |= show_devices(NULL, num_dests, dests); | |
ef416fc2 | 370 | break; |
371 | ||
372 | case 't' : /* Show all info */ | |
61cf44e2 MS |
373 | op = 't'; |
374 | ||
375 | if (num_dests <= 1) | |
376 | { | |
377 | cupsFreeDests(num_dests, dests); | |
378 | num_dests = cupsGetDests(&dests); | |
c606bcae MS |
379 | |
380 | if (num_dests == 0 && | |
381 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
382 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
383 | { | |
384 | _cupsLangPrintf(stderr, | |
385 | _("%s: Error - add '/version=1.1' to server " | |
386 | "name."), argv[0]); | |
387 | return (1); | |
388 | } | |
61cf44e2 MS |
389 | } |
390 | ||
391 | show_scheduler(); | |
392 | show_default(cupsGetDest(NULL, NULL, num_dests, dests)); | |
393 | status |= show_classes(NULL); | |
394 | status |= show_devices(NULL, num_dests, dests); | |
395 | status |= show_accepting(NULL, num_dests, dests); | |
396 | status |= show_printers(NULL, num_dests, dests, long_status); | |
397 | status |= show_jobs(NULL, NULL, long_status, ranking, which); | |
ef416fc2 | 398 | break; |
399 | ||
400 | case 'u' : /* Show jobs by user */ | |
61cf44e2 | 401 | op = 'u'; |
ef416fc2 | 402 | |
61cf44e2 MS |
403 | if (argv[i][2]) |
404 | status |= show_jobs(NULL, argv[i] + 2, long_status, ranking, | |
405 | which); | |
ef416fc2 | 406 | else if ((i + 1) < argc && argv[i + 1][0] != '-') |
407 | { | |
408 | i ++; | |
61cf44e2 | 409 | status |= show_jobs(NULL, argv[i], long_status, ranking, which); |
ef416fc2 | 410 | } |
411 | else | |
61cf44e2 | 412 | status |= show_jobs(NULL, NULL, long_status, ranking, which); |
ef416fc2 | 413 | break; |
414 | ||
415 | case 'v' : /* Show printer devices */ | |
61cf44e2 | 416 | op = 'v'; |
ef416fc2 | 417 | |
61cf44e2 | 418 | if (argv[i][2]) |
ef416fc2 | 419 | { |
61cf44e2 | 420 | check_dest(argv[0], argv[i] + 2, &num_dests, &dests); |
ef416fc2 | 421 | |
61cf44e2 | 422 | status |= show_devices(argv[i] + 2, num_dests, dests); |
ef416fc2 | 423 | } |
424 | else if ((i + 1) < argc && argv[i + 1][0] != '-') | |
425 | { | |
426 | i ++; | |
427 | ||
61cf44e2 | 428 | check_dest(argv[0], argv[i], &num_dests, &dests); |
ef416fc2 | 429 | |
61cf44e2 | 430 | status |= show_devices(argv[i], num_dests, dests); |
ef416fc2 | 431 | } |
432 | else | |
433 | { | |
61cf44e2 MS |
434 | if (num_dests <= 1) |
435 | { | |
436 | cupsFreeDests(num_dests, dests); | |
437 | num_dests = cupsGetDests(&dests); | |
c606bcae MS |
438 | |
439 | if (num_dests == 0 && | |
440 | (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
441 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)) | |
442 | { | |
443 | _cupsLangPrintf(stderr, | |
444 | _("%s: Error - add '/version=1.1' to server " | |
445 | "name."), argv[0]); | |
446 | return (1); | |
447 | } | |
61cf44e2 | 448 | } |
ef416fc2 | 449 | |
61cf44e2 | 450 | status |= show_devices(NULL, num_dests, dests); |
ef416fc2 | 451 | } |
452 | break; | |
453 | ||
ef416fc2 | 454 | default : |
fa73b229 | 455 | _cupsLangPrintf(stderr, |
0837b7e8 | 456 | _("%s: Error - unknown option \"%c\"."), |
fa73b229 | 457 | argv[0], argv[i][1]); |
ef416fc2 | 458 | return (1); |
459 | } | |
460 | else | |
461 | { | |
61cf44e2 | 462 | status |= show_jobs(argv[i], NULL, long_status, ranking, which); |
ef416fc2 | 463 | op = 'o'; |
464 | } | |
465 | ||
466 | if (!op) | |
61cf44e2 | 467 | status |= show_jobs(NULL, cupsUser(), long_status, ranking, which); |
ef416fc2 | 468 | |
469 | return (status); | |
470 | } | |
471 | ||
472 | ||
473 | /* | |
474 | * 'check_dest()' - Verify that the named destination(s) exists. | |
475 | */ | |
476 | ||
477 | static void | |
fa73b229 | 478 | check_dest(const char *command, /* I - Command name */ |
61cf44e2 | 479 | const char *name, /* I - List of printer/class names */ |
ef416fc2 | 480 | int *num_dests, /* IO - Number of destinations */ |
481 | cups_dest_t **dests) /* IO - Destinations */ | |
482 | { | |
61cf44e2 MS |
483 | const char *dptr; /* Pointer into name */ |
484 | char *pptr, /* Pointer into printer */ | |
485 | printer[1024]; /* Current printer/class name */ | |
ef416fc2 | 486 | |
487 | ||
488 | /* | |
489 | * Load the destination list as necessary... | |
490 | */ | |
491 | ||
61cf44e2 MS |
492 | if (*num_dests <= 1) |
493 | { | |
494 | if (*num_dests) | |
495 | cupsFreeDests(*num_dests, *dests); | |
496 | ||
497 | if (strchr(name, ',')) | |
498 | *num_dests = cupsGetDests(dests); | |
499 | else | |
500 | { | |
501 | strlcpy(printer, name, sizeof(printer)); | |
502 | if ((pptr = strchr(printer, '/')) != NULL) | |
503 | *pptr++ = '\0'; | |
504 | ||
505 | if ((*dests = cupsGetNamedDest(CUPS_HTTP_DEFAULT, printer, pptr)) == NULL) | |
506 | { | |
c606bcae MS |
507 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
508 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
509 | _cupsLangPrintf(stderr, | |
510 | _("%s: Error - add '/version=1.1' to server name."), | |
511 | command); | |
512 | else | |
513 | _cupsLangPrintf(stderr, | |
514 | _("%s: Invalid destination name in list \"%s\"."), | |
515 | command, name); | |
516 | ||
61cf44e2 MS |
517 | exit(1); |
518 | } | |
519 | else | |
520 | { | |
521 | *num_dests = 1; | |
522 | return; | |
523 | } | |
524 | } | |
525 | } | |
ef416fc2 | 526 | |
527 | /* | |
528 | * Scan the name string for printer/class name(s)... | |
529 | */ | |
530 | ||
88f9aafc | 531 | for (dptr = name; *dptr;) |
ef416fc2 | 532 | { |
533 | /* | |
534 | * Skip leading whitespace and commas... | |
535 | */ | |
536 | ||
537 | while (isspace(*dptr & 255) || *dptr == ',') | |
538 | dptr ++; | |
539 | ||
61cf44e2 | 540 | if (!*dptr) |
ef416fc2 | 541 | break; |
542 | ||
543 | /* | |
544 | * Extract a single destination name from the name string... | |
545 | */ | |
546 | ||
61cf44e2 | 547 | for (pptr = printer; !isspace(*dptr & 255) && *dptr != ',' && *dptr;) |
ef416fc2 | 548 | { |
549 | if ((pptr - printer) < (sizeof(printer) - 1)) | |
550 | *pptr++ = *dptr++; | |
551 | else | |
552 | { | |
fa73b229 | 553 | _cupsLangPrintf(stderr, |
0837b7e8 | 554 | _("%s: Invalid destination name in list \"%s\"."), |
fa73b229 | 555 | command, name); |
ef416fc2 | 556 | exit(1); |
557 | } | |
558 | } | |
559 | ||
560 | *pptr = '\0'; | |
561 | ||
562 | /* | |
563 | * Check the destination... | |
564 | */ | |
565 | ||
61cf44e2 | 566 | if (!cupsGetDest(printer, NULL, *num_dests, *dests)) |
ef416fc2 | 567 | { |
c606bcae MS |
568 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || |
569 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
570 | _cupsLangPrintf(stderr, | |
571 | _("%s: Error - add '/version=1.1' to server name."), | |
572 | command); | |
573 | else | |
574 | _cupsLangPrintf(stderr, | |
575 | _("%s: Unknown destination \"%s\"."), command, printer); | |
576 | ||
ef416fc2 | 577 | exit(1); |
578 | } | |
579 | } | |
580 | } | |
581 | ||
582 | ||
583 | /* | |
61cf44e2 | 584 | * 'match_list()' - Match a name from a list of comma or space-separated names. |
ef416fc2 | 585 | */ |
586 | ||
61cf44e2 MS |
587 | static int /* O - 1 on match, 0 on no match */ |
588 | match_list(const char *list, /* I - List of names */ | |
589 | const char *name) /* I - Name to find */ | |
ef416fc2 | 590 | { |
61cf44e2 MS |
591 | const char *nameptr; /* Pointer into name */ |
592 | ||
593 | ||
594 | /* | |
cc754834 | 595 | * An empty list always matches... |
61cf44e2 MS |
596 | */ |
597 | ||
598 | if (!list || !*list) | |
cc754834 | 599 | return (1); |
61cf44e2 | 600 | |
a2326b5b MS |
601 | if (!name) |
602 | return (0); | |
603 | ||
61cf44e2 | 604 | while (*list) |
ef416fc2 | 605 | { |
61cf44e2 MS |
606 | /* |
607 | * Skip leading whitespace and commas... | |
608 | */ | |
ef416fc2 | 609 | |
61cf44e2 MS |
610 | while (isspace(*list & 255) || *list == ',') |
611 | list ++; | |
612 | ||
613 | if (!*list) | |
614 | break; | |
615 | ||
616 | /* | |
617 | * Compare names... | |
618 | */ | |
619 | ||
620 | for (nameptr = name; | |
621 | *nameptr && *list && tolower(*nameptr & 255) == tolower(*list & 255); | |
622 | nameptr ++, list ++); | |
623 | ||
624 | if (!*nameptr && (!*list || *list == ',' || isspace(*list & 255))) | |
625 | return (1); | |
626 | ||
627 | while (*list && !isspace(*list & 255) && *list != ',') | |
628 | list ++; | |
ef416fc2 | 629 | } |
630 | ||
61cf44e2 | 631 | return (0); |
ef416fc2 | 632 | } |
633 | ||
634 | ||
635 | /* | |
636 | * 'show_accepting()' - Show acceptance status. | |
637 | */ | |
638 | ||
639 | static int /* O - 0 on success, 1 on fail */ | |
61cf44e2 | 640 | show_accepting(const char *printers, /* I - Destinations */ |
ef416fc2 | 641 | int num_dests, /* I - Number of user-defined dests */ |
642 | cups_dest_t *dests) /* I - User-defined destinations */ | |
643 | { | |
644 | int i; /* Looping var */ | |
645 | ipp_t *request, /* IPP Request */ | |
646 | *response; /* IPP Response */ | |
647 | ipp_attribute_t *attr; /* Current attribute */ | |
648 | const char *printer, /* Printer name */ | |
649 | *message; /* Printer device URI */ | |
650 | int accepting; /* Accepting requests? */ | |
fa73b229 | 651 | time_t ptime; /* Printer state time */ |
652 | struct tm *pdate; /* Printer state date & time */ | |
653 | char printer_state_time[255];/* Printer state time */ | |
ef416fc2 | 654 | static const char *pattrs[] = /* Attributes we need for printers... */ |
655 | { | |
656 | "printer-name", | |
fa73b229 | 657 | "printer-state-change-time", |
ef416fc2 | 658 | "printer-state-message", |
659 | "printer-is-accepting-jobs" | |
660 | }; | |
661 | ||
662 | ||
61cf44e2 | 663 | DEBUG_printf(("show_accepting(printers=\"%s\")\n", printers)); |
ef416fc2 | 664 | |
fa73b229 | 665 | if (printers != NULL && !strcmp(printers, "all")) |
ef416fc2 | 666 | printers = NULL; |
667 | ||
668 | /* | |
669 | * Build a CUPS_GET_PRINTERS request, which requires the following | |
670 | * attributes: | |
671 | * | |
672 | * attributes-charset | |
673 | * attributes-natural-language | |
674 | * requested-attributes | |
fa73b229 | 675 | * requesting-user-name |
ef416fc2 | 676 | */ |
677 | ||
678 | request = ippNewRequest(CUPS_GET_PRINTERS); | |
679 | ||
680 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
681 | "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), | |
682 | NULL, pattrs); | |
683 | ||
fa73b229 | 684 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", |
685 | NULL, cupsUser()); | |
686 | ||
ef416fc2 | 687 | /* |
688 | * Do the request and get back a response... | |
689 | */ | |
690 | ||
c606bcae MS |
691 | response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); |
692 | ||
693 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
694 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
ef416fc2 | 695 | { |
c606bcae MS |
696 | _cupsLangPrintf(stderr, |
697 | _("%s: Error - add '/version=1.1' to server name."), | |
698 | "lpstat"); | |
699 | ippDelete(response); | |
700 | return (1); | |
701 | } | |
702 | else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) | |
703 | { | |
704 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); | |
705 | ippDelete(response); | |
706 | return (1); | |
707 | } | |
ef416fc2 | 708 | |
c606bcae MS |
709 | if (response) |
710 | { | |
711 | DEBUG_puts("show_accepting: request succeeded..."); | |
ef416fc2 | 712 | |
713 | /* | |
714 | * Loop through the printers returned in the list and display | |
715 | * their devices... | |
716 | */ | |
717 | ||
718 | for (attr = response->attrs; attr != NULL; attr = attr->next) | |
719 | { | |
720 | /* | |
721 | * Skip leading attributes until we hit a printer... | |
722 | */ | |
723 | ||
724 | while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) | |
725 | attr = attr->next; | |
726 | ||
727 | if (attr == NULL) | |
728 | break; | |
729 | ||
730 | /* | |
731 | * Pull the needed attributes from this printer... | |
732 | */ | |
733 | ||
734 | printer = NULL; | |
735 | message = NULL; | |
736 | accepting = 1; | |
fa73b229 | 737 | ptime = 0; |
ef416fc2 | 738 | |
739 | while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) | |
740 | { | |
741 | if (!strcmp(attr->name, "printer-name") && | |
742 | attr->value_tag == IPP_TAG_NAME) | |
743 | printer = attr->values[0].string.text; | |
fa73b229 | 744 | else if (!strcmp(attr->name, "printer-state-change-time") && |
745 | attr->value_tag == IPP_TAG_INTEGER) | |
746 | ptime = (time_t)attr->values[0].integer; | |
747 | else if (!strcmp(attr->name, "printer-state-message") && | |
748 | attr->value_tag == IPP_TAG_TEXT) | |
ef416fc2 | 749 | message = attr->values[0].string.text; |
fa73b229 | 750 | else if (!strcmp(attr->name, "printer-is-accepting-jobs") && |
751 | attr->value_tag == IPP_TAG_BOOLEAN) | |
ef416fc2 | 752 | accepting = attr->values[0].boolean; |
753 | ||
754 | attr = attr->next; | |
755 | } | |
756 | ||
757 | /* | |
758 | * See if we have everything needed... | |
759 | */ | |
760 | ||
761 | if (printer == NULL) | |
762 | { | |
763 | if (attr == NULL) | |
764 | break; | |
765 | else | |
766 | continue; | |
767 | } | |
768 | ||
ef416fc2 | 769 | /* |
770 | * Display the printer entry if needed... | |
771 | */ | |
772 | ||
61cf44e2 | 773 | if (match_list(printers, printer)) |
ef416fc2 | 774 | { |
fa73b229 | 775 | pdate = localtime(&ptime); |
776 | strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate); | |
777 | ||
ef416fc2 | 778 | if (accepting) |
0837b7e8 | 779 | _cupsLangPrintf(stdout, _("%s accepting requests since %s"), |
fa73b229 | 780 | printer, printer_state_time); |
ef416fc2 | 781 | else |
0837b7e8 MS |
782 | { |
783 | _cupsLangPrintf(stdout, _("%s not accepting requests since %s -"), | |
784 | printer, printer_state_time); | |
785 | _cupsLangPrintf(stdout, _("\t%s"), | |
61cf44e2 MS |
786 | (message == NULL || !*message) ? |
787 | "reason unknown" : message); | |
0837b7e8 | 788 | } |
ef416fc2 | 789 | |
790 | for (i = 0; i < num_dests; i ++) | |
88f9aafc | 791 | if (!_cups_strcasecmp(dests[i].name, printer) && dests[i].instance) |
ef416fc2 | 792 | { |
793 | if (accepting) | |
0837b7e8 | 794 | _cupsLangPrintf(stdout, _("%s/%s accepting requests since %s"), |
fa73b229 | 795 | printer, dests[i].instance, printer_state_time); |
ef416fc2 | 796 | else |
0837b7e8 MS |
797 | { |
798 | _cupsLangPrintf(stdout, | |
799 | _("%s/%s not accepting requests since %s -"), | |
800 | printer, dests[i].instance, printer_state_time); | |
801 | _cupsLangPrintf(stdout, _("\t%s"), | |
61cf44e2 MS |
802 | (message == NULL || !*message) ? |
803 | "reason unknown" : message); | |
0837b7e8 | 804 | } |
ef416fc2 | 805 | } |
806 | } | |
807 | ||
808 | if (attr == NULL) | |
809 | break; | |
810 | } | |
811 | ||
812 | ippDelete(response); | |
813 | } | |
ef416fc2 | 814 | |
815 | return (0); | |
816 | } | |
817 | ||
818 | ||
819 | /* | |
820 | * 'show_classes()' - Show printer classes. | |
821 | */ | |
822 | ||
823 | static int /* O - 0 on success, 1 on fail */ | |
61cf44e2 | 824 | show_classes(const char *dests) /* I - Destinations */ |
ef416fc2 | 825 | { |
826 | int i; /* Looping var */ | |
827 | ipp_t *request, /* IPP Request */ | |
828 | *response, /* IPP Response */ | |
829 | *response2; /* IPP response from remote server */ | |
830 | http_t *http2; /* Remote server */ | |
831 | ipp_attribute_t *attr; /* Current attribute */ | |
832 | const char *printer, /* Printer class name */ | |
833 | *printer_uri; /* Printer class URI */ | |
834 | ipp_attribute_t *members; /* Printer members */ | |
835 | char method[HTTP_MAX_URI], /* Request method */ | |
836 | username[HTTP_MAX_URI], /* Username:password */ | |
837 | server[HTTP_MAX_URI], /* Server name */ | |
838 | resource[HTTP_MAX_URI]; /* Resource name */ | |
839 | int port; /* Port number */ | |
ef416fc2 | 840 | static const char *cattrs[] = /* Attributes we need for classes... */ |
841 | { | |
842 | "printer-name", | |
843 | "printer-uri-supported", | |
844 | "member-names" | |
845 | }; | |
846 | ||
847 | ||
61cf44e2 | 848 | DEBUG_printf(("show_classes(dests=\"%s\")\n", dests)); |
ef416fc2 | 849 | |
fa73b229 | 850 | if (dests != NULL && !strcmp(dests, "all")) |
ef416fc2 | 851 | dests = NULL; |
852 | ||
853 | /* | |
854 | * Build a CUPS_GET_CLASSES request, which requires the following | |
855 | * attributes: | |
856 | * | |
857 | * attributes-charset | |
858 | * attributes-natural-language | |
859 | * requested-attributes | |
fa73b229 | 860 | * requesting-user-name |
ef416fc2 | 861 | */ |
862 | ||
863 | request = ippNewRequest(CUPS_GET_CLASSES); | |
864 | ||
865 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
866 | "requested-attributes", sizeof(cattrs) / sizeof(cattrs[0]), | |
867 | NULL, cattrs); | |
868 | ||
fa73b229 | 869 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", |
870 | NULL, cupsUser()); | |
871 | ||
ef416fc2 | 872 | /* |
873 | * Do the request and get back a response... | |
874 | */ | |
875 | ||
c606bcae MS |
876 | response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); |
877 | ||
878 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
879 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
880 | { | |
881 | _cupsLangPrintf(stderr, | |
882 | _("%s: Error - add '/version=1.1' to server name."), | |
883 | "lpstat"); | |
884 | ippDelete(response); | |
885 | return (1); | |
886 | } | |
887 | else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) | |
888 | { | |
889 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); | |
890 | ippDelete(response); | |
891 | return (1); | |
892 | } | |
893 | ||
894 | if (response) | |
ef416fc2 | 895 | { |
896 | DEBUG_puts("show_classes: request succeeded..."); | |
897 | ||
898 | if (response->request.status.status_code > IPP_OK_CONFLICT) | |
899 | { | |
0837b7e8 | 900 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); |
ef416fc2 | 901 | ippDelete(response); |
902 | return (1); | |
903 | } | |
904 | ||
905 | /* | |
906 | * Loop through the printers returned in the list and display | |
907 | * their devices... | |
908 | */ | |
909 | ||
910 | for (attr = response->attrs; attr != NULL; attr = attr->next) | |
911 | { | |
912 | /* | |
913 | * Skip leading attributes until we hit a job... | |
914 | */ | |
915 | ||
916 | while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) | |
917 | attr = attr->next; | |
918 | ||
919 | if (attr == NULL) | |
920 | break; | |
921 | ||
922 | /* | |
923 | * Pull the needed attributes from this job... | |
924 | */ | |
925 | ||
926 | printer = NULL; | |
927 | printer_uri = NULL; | |
928 | members = NULL; | |
929 | ||
930 | while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) | |
931 | { | |
932 | if (!strcmp(attr->name, "printer-name") && | |
933 | attr->value_tag == IPP_TAG_NAME) | |
934 | printer = attr->values[0].string.text; | |
935 | ||
936 | if (!strcmp(attr->name, "printer-uri-supported") && | |
937 | attr->value_tag == IPP_TAG_URI) | |
938 | printer_uri = attr->values[0].string.text; | |
939 | ||
940 | if (!strcmp(attr->name, "member-names") && | |
941 | attr->value_tag == IPP_TAG_NAME) | |
942 | members = attr; | |
943 | ||
944 | attr = attr->next; | |
945 | } | |
946 | ||
947 | /* | |
948 | * If this is a remote class, grab the class info from the | |
949 | * remote server... | |
950 | */ | |
951 | ||
952 | response2 = NULL; | |
953 | if (members == NULL && printer_uri != NULL) | |
954 | { | |
a4d04587 | 955 | httpSeparateURI(HTTP_URI_CODING_ALL, printer_uri, method, sizeof(method), |
ef416fc2 | 956 | username, sizeof(username), server, sizeof(server), |
957 | &port, resource, sizeof(resource)); | |
958 | ||
88f9aafc | 959 | if (!_cups_strcasecmp(server, cupsServer())) |
61cf44e2 | 960 | http2 = CUPS_HTTP_DEFAULT; |
ef416fc2 | 961 | else |
962 | http2 = httpConnectEncrypt(server, port, cupsEncryption()); | |
963 | ||
61cf44e2 MS |
964 | /* |
965 | * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the | |
966 | * following attributes: | |
967 | * | |
968 | * attributes-charset | |
969 | * attributes-natural-language | |
970 | * printer-uri | |
971 | * requested-attributes | |
972 | */ | |
ef416fc2 | 973 | |
61cf44e2 | 974 | request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES); |
ef416fc2 | 975 | |
61cf44e2 MS |
976 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, |
977 | "printer-uri", NULL, printer_uri); | |
ef416fc2 | 978 | |
61cf44e2 MS |
979 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, |
980 | "requested-attributes", | |
981 | sizeof(cattrs) / sizeof(cattrs[0]), | |
982 | NULL, cattrs); | |
ef416fc2 | 983 | |
61cf44e2 MS |
984 | if ((response2 = cupsDoRequest(http2, request, "/")) != NULL) |
985 | members = ippFindAttribute(response2, "member-names", IPP_TAG_NAME); | |
ef416fc2 | 986 | |
61cf44e2 MS |
987 | if (http2) |
988 | httpClose(http2); | |
ef416fc2 | 989 | } |
990 | ||
991 | /* | |
992 | * See if we have everything needed... | |
993 | */ | |
994 | ||
995 | if (printer == NULL) | |
996 | { | |
997 | if (response2) | |
998 | ippDelete(response2); | |
999 | ||
1000 | if (attr == NULL) | |
1001 | break; | |
1002 | else | |
1003 | continue; | |
1004 | } | |
1005 | ||
ef416fc2 | 1006 | /* |
1007 | * Display the printer entry if needed... | |
1008 | */ | |
1009 | ||
61cf44e2 | 1010 | if (match_list(dests, printer)) |
ef416fc2 | 1011 | { |
0837b7e8 | 1012 | _cupsLangPrintf(stdout, _("members of class %s:"), printer); |
ef416fc2 | 1013 | |
1014 | if (members) | |
1015 | { | |
1016 | for (i = 0; i < members->num_values; i ++) | |
0837b7e8 | 1017 | _cupsLangPrintf(stdout, "\t%s", members->values[i].string.text); |
ef416fc2 | 1018 | } |
1019 | else | |
0837b7e8 | 1020 | _cupsLangPuts(stdout, "\tunknown"); |
ef416fc2 | 1021 | } |
1022 | ||
1023 | if (response2) | |
1024 | ippDelete(response2); | |
1025 | ||
1026 | if (attr == NULL) | |
1027 | break; | |
1028 | } | |
1029 | ||
1030 | ippDelete(response); | |
1031 | } | |
ef416fc2 | 1032 | |
1033 | return (0); | |
1034 | } | |
1035 | ||
1036 | ||
1037 | /* | |
1038 | * 'show_default()' - Show default destination. | |
1039 | */ | |
1040 | ||
1041 | static void | |
61cf44e2 | 1042 | show_default(cups_dest_t *dest) /* I - Default destination */ |
ef416fc2 | 1043 | { |
ef416fc2 | 1044 | const char *printer, /* Printer name */ |
1045 | *val; /* Environment variable name */ | |
1046 | ||
61cf44e2 MS |
1047 | |
1048 | if (dest) | |
ef416fc2 | 1049 | { |
1050 | if (dest->instance) | |
0837b7e8 | 1051 | _cupsLangPrintf(stdout, _("system default destination: %s/%s"), |
ef416fc2 | 1052 | dest->name, dest->instance); |
1053 | else | |
0837b7e8 | 1054 | _cupsLangPrintf(stdout, _("system default destination: %s"), |
ef416fc2 | 1055 | dest->name); |
1056 | } | |
1057 | else | |
1058 | { | |
1059 | val = NULL; | |
1060 | ||
1061 | if ((printer = getenv("LPDEST")) == NULL) | |
1062 | { | |
1063 | if ((printer = getenv("PRINTER")) != NULL) | |
1064 | { | |
1065 | if (!strcmp(printer, "lp")) | |
1066 | printer = NULL; | |
1067 | else | |
1068 | val = "PRINTER"; | |
1069 | } | |
1070 | } | |
1071 | else | |
1072 | val = "LPDEST"; | |
1073 | ||
61cf44e2 | 1074 | if (printer) |
fa73b229 | 1075 | _cupsLangPrintf(stdout, |
ef416fc2 | 1076 | _("lpstat: error - %s environment variable names " |
0837b7e8 | 1077 | "non-existent destination \"%s\"."), |
ef416fc2 | 1078 | val, printer); |
1079 | else | |
0837b7e8 | 1080 | _cupsLangPuts(stdout, _("no system default destination")); |
ef416fc2 | 1081 | } |
1082 | } | |
1083 | ||
1084 | ||
1085 | /* | |
1086 | * 'show_devices()' - Show printer devices. | |
1087 | */ | |
1088 | ||
1089 | static int /* O - 0 on success, 1 on fail */ | |
61cf44e2 | 1090 | show_devices(const char *printers, /* I - Destinations */ |
ef416fc2 | 1091 | int num_dests, /* I - Number of user-defined dests */ |
1092 | cups_dest_t *dests) /* I - User-defined destinations */ | |
1093 | { | |
1094 | int i; /* Looping var */ | |
1095 | ipp_t *request, /* IPP Request */ | |
1096 | *response; /* IPP Response */ | |
1097 | ipp_attribute_t *attr; /* Current attribute */ | |
1098 | const char *printer, /* Printer name */ | |
1099 | *uri, /* Printer URI */ | |
61cf44e2 | 1100 | *device; /* Printer device URI */ |
ef416fc2 | 1101 | static const char *pattrs[] = /* Attributes we need for printers... */ |
1102 | { | |
1103 | "printer-name", | |
1104 | "printer-uri-supported", | |
1105 | "device-uri" | |
1106 | }; | |
1107 | ||
1108 | ||
61cf44e2 | 1109 | DEBUG_printf(("show_devices(printers=\"%s\")\n", printers)); |
ef416fc2 | 1110 | |
fa73b229 | 1111 | if (printers != NULL && !strcmp(printers, "all")) |
ef416fc2 | 1112 | printers = NULL; |
1113 | ||
1114 | /* | |
1115 | * Build a CUPS_GET_PRINTERS request, which requires the following | |
1116 | * attributes: | |
1117 | * | |
1118 | * attributes-charset | |
1119 | * attributes-natural-language | |
1120 | * requested-attributes | |
fa73b229 | 1121 | * requesting-user-name |
ef416fc2 | 1122 | */ |
1123 | ||
1124 | request = ippNewRequest(CUPS_GET_PRINTERS); | |
1125 | ||
1126 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
1127 | "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), | |
1128 | NULL, pattrs); | |
1129 | ||
fa73b229 | 1130 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", |
1131 | NULL, cupsUser()); | |
1132 | ||
ef416fc2 | 1133 | /* |
1134 | * Do the request and get back a response... | |
1135 | */ | |
1136 | ||
c606bcae MS |
1137 | response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); |
1138 | ||
1139 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
1140 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
ef416fc2 | 1141 | { |
c606bcae MS |
1142 | _cupsLangPrintf(stderr, |
1143 | _("%s: Error - add '/version=1.1' to server name."), | |
1144 | "lpstat"); | |
1145 | ippDelete(response); | |
1146 | return (1); | |
1147 | } | |
1148 | else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) | |
1149 | { | |
1150 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); | |
1151 | ippDelete(response); | |
1152 | return (1); | |
1153 | } | |
ef416fc2 | 1154 | |
c606bcae MS |
1155 | if (response) |
1156 | { | |
1157 | DEBUG_puts("show_devices: request succeeded..."); | |
ef416fc2 | 1158 | |
1159 | /* | |
1160 | * Loop through the printers returned in the list and display | |
1161 | * their devices... | |
1162 | */ | |
1163 | ||
1164 | for (attr = response->attrs; attr != NULL; attr = attr->next) | |
1165 | { | |
1166 | /* | |
1167 | * Skip leading attributes until we hit a job... | |
1168 | */ | |
1169 | ||
1170 | while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) | |
1171 | attr = attr->next; | |
1172 | ||
1173 | if (attr == NULL) | |
1174 | break; | |
1175 | ||
1176 | /* | |
1177 | * Pull the needed attributes from this job... | |
1178 | */ | |
1179 | ||
1180 | printer = NULL; | |
1181 | device = NULL; | |
1182 | uri = NULL; | |
1183 | ||
1184 | while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) | |
1185 | { | |
1186 | if (!strcmp(attr->name, "printer-name") && | |
1187 | attr->value_tag == IPP_TAG_NAME) | |
1188 | printer = attr->values[0].string.text; | |
1189 | ||
1190 | if (!strcmp(attr->name, "printer-uri-supported") && | |
1191 | attr->value_tag == IPP_TAG_URI) | |
1192 | uri = attr->values[0].string.text; | |
1193 | ||
1194 | if (!strcmp(attr->name, "device-uri") && | |
1195 | attr->value_tag == IPP_TAG_URI) | |
1196 | device = attr->values[0].string.text; | |
1197 | ||
1198 | attr = attr->next; | |
1199 | } | |
1200 | ||
1201 | /* | |
1202 | * See if we have everything needed... | |
1203 | */ | |
1204 | ||
1205 | if (printer == NULL) | |
1206 | { | |
1207 | if (attr == NULL) | |
1208 | break; | |
1209 | else | |
1210 | continue; | |
1211 | } | |
1212 | ||
ef416fc2 | 1213 | /* |
1214 | * Display the printer entry if needed... | |
1215 | */ | |
1216 | ||
61cf44e2 | 1217 | if (match_list(printers, printer)) |
ef416fc2 | 1218 | { |
ef416fc2 | 1219 | if (device == NULL) |
0837b7e8 | 1220 | _cupsLangPrintf(stdout, _("device for %s: %s"), |
ef416fc2 | 1221 | printer, uri); |
1222 | else if (!strncmp(device, "file:", 5)) | |
0837b7e8 | 1223 | _cupsLangPrintf(stdout, _("device for %s: %s"), |
ef416fc2 | 1224 | printer, device + 5); |
1225 | else | |
0837b7e8 | 1226 | _cupsLangPrintf(stdout, _("device for %s: %s"), |
ef416fc2 | 1227 | printer, device); |
1228 | ||
1229 | for (i = 0; i < num_dests; i ++) | |
5a1d7a17 | 1230 | { |
88f9aafc | 1231 | if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance) |
ef416fc2 | 1232 | { |
1233 | if (device == NULL) | |
0837b7e8 | 1234 | _cupsLangPrintf(stdout, _("device for %s/%s: %s"), |
ef416fc2 | 1235 | printer, dests[i].instance, uri); |
1236 | else if (!strncmp(device, "file:", 5)) | |
0837b7e8 | 1237 | _cupsLangPrintf(stdout, _("device for %s/%s: %s"), |
ef416fc2 | 1238 | printer, dests[i].instance, device + 5); |
1239 | else | |
0837b7e8 | 1240 | _cupsLangPrintf(stdout, _("device for %s/%s: %s"), |
ef416fc2 | 1241 | printer, dests[i].instance, device); |
1242 | } | |
5a1d7a17 | 1243 | } |
ef416fc2 | 1244 | } |
1245 | ||
1246 | if (attr == NULL) | |
1247 | break; | |
1248 | } | |
1249 | ||
1250 | ippDelete(response); | |
1251 | } | |
ef416fc2 | 1252 | |
1253 | return (0); | |
1254 | } | |
1255 | ||
1256 | ||
1257 | /* | |
1258 | * 'show_jobs()' - Show active print jobs. | |
1259 | */ | |
1260 | ||
1261 | static int /* O - 0 on success, 1 on fail */ | |
61cf44e2 | 1262 | show_jobs(const char *dests, /* I - Destinations */ |
ef416fc2 | 1263 | const char *users, /* I - Users */ |
1264 | int long_status, /* I - Show long status? */ | |
1265 | int ranking, /* I - Show job ranking? */ | |
1266 | const char *which) /* I - Show which jobs? */ | |
1267 | { | |
09a101d6 | 1268 | int i; /* Looping var */ |
ef416fc2 | 1269 | ipp_t *request, /* IPP Request */ |
1270 | *response; /* IPP Response */ | |
09a101d6 | 1271 | ipp_attribute_t *attr, /* Current attribute */ |
1272 | *reasons; /* Job state reasons attribute */ | |
ef416fc2 | 1273 | const char *dest, /* Pointer into job-printer-uri */ |
1274 | *username, /* Pointer to job-originating-user-name */ | |
229681c1 MS |
1275 | *title, /* Pointer to job-name */ |
1276 | *message; /* Pointer to job-printer-state-message */ | |
ef416fc2 | 1277 | int rank, /* Rank in queue */ |
1278 | jobid, /* job-id */ | |
1279 | size; /* job-k-octets */ | |
1280 | time_t jobtime; /* time-at-creation */ | |
1281 | struct tm *jobdate; /* Date & time */ | |
ef416fc2 | 1282 | char temp[255], /* Temporary buffer */ |
1283 | date[255]; /* Date buffer */ | |
1284 | static const char *jattrs[] = /* Attributes we need for jobs... */ | |
1285 | { | |
1286 | "job-id", | |
1287 | "job-k-octets", | |
1288 | "job-name", | |
09a101d6 | 1289 | "job-originating-user-name", |
229681c1 | 1290 | "job-printer-state-message", |
5a662dc0 MS |
1291 | "job-printer-uri", |
1292 | "job-state-reasons", | |
1293 | "time-at-creation" | |
ef416fc2 | 1294 | }; |
1295 | ||
1296 | ||
61cf44e2 MS |
1297 | DEBUG_printf(("show_jobs(dests=\"%s\", users=\"%s\", long_status=%d, " |
1298 | "ranking=%d, which=\"%s\")\n", dests, users, long_status, | |
1299 | ranking, which)); | |
ef416fc2 | 1300 | |
fa73b229 | 1301 | if (dests != NULL && !strcmp(dests, "all")) |
ef416fc2 | 1302 | dests = NULL; |
1303 | ||
1304 | /* | |
1305 | * Build a IPP_GET_JOBS request, which requires the following | |
1306 | * attributes: | |
1307 | * | |
1308 | * attributes-charset | |
1309 | * attributes-natural-language | |
52f6f666 | 1310 | * printer-uri |
ef416fc2 | 1311 | * requested-attributes |
52f6f666 MS |
1312 | * requesting-user-name |
1313 | * which-jobs | |
ef416fc2 | 1314 | */ |
1315 | ||
1316 | request = ippNewRequest(IPP_GET_JOBS); | |
1317 | ||
52f6f666 MS |
1318 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri", |
1319 | NULL, "ipp://localhost/"); | |
1320 | ||
ef416fc2 | 1321 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, |
1322 | "requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]), | |
1323 | NULL, jattrs); | |
1324 | ||
52f6f666 MS |
1325 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", |
1326 | NULL, cupsUser()); | |
ef416fc2 | 1327 | |
1328 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs", | |
1329 | NULL, which); | |
1330 | ||
1331 | /* | |
1332 | * Do the request and get back a response... | |
1333 | */ | |
1334 | ||
c606bcae MS |
1335 | response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); |
1336 | ||
1337 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
1338 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
1339 | { | |
1340 | _cupsLangPrintf(stderr, | |
1341 | _("%s: Error - add '/version=1.1' to server name."), | |
1342 | "lpstat"); | |
1343 | ippDelete(response); | |
1344 | return (1); | |
1345 | } | |
1346 | else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) | |
1347 | { | |
1348 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); | |
1349 | ippDelete(response); | |
1350 | return (1); | |
1351 | } | |
1352 | ||
1353 | if (response) | |
ef416fc2 | 1354 | { |
1355 | /* | |
1356 | * Loop through the job list and display them... | |
1357 | */ | |
1358 | ||
ef416fc2 | 1359 | rank = -1; |
1360 | ||
1361 | for (attr = response->attrs; attr != NULL; attr = attr->next) | |
1362 | { | |
1363 | /* | |
1364 | * Skip leading attributes until we hit a job... | |
1365 | */ | |
1366 | ||
1367 | while (attr != NULL && attr->group_tag != IPP_TAG_JOB) | |
1368 | attr = attr->next; | |
1369 | ||
1370 | if (attr == NULL) | |
1371 | break; | |
1372 | ||
1373 | /* | |
1374 | * Pull the needed attributes from this job... | |
1375 | */ | |
1376 | ||
1377 | jobid = 0; | |
1378 | size = 0; | |
1379 | username = NULL; | |
1380 | dest = NULL; | |
1381 | jobtime = 0; | |
1382 | title = "no title"; | |
229681c1 | 1383 | message = NULL; |
09a101d6 | 1384 | reasons = NULL; |
ef416fc2 | 1385 | |
1386 | while (attr != NULL && attr->group_tag == IPP_TAG_JOB) | |
1387 | { | |
fa73b229 | 1388 | if (!strcmp(attr->name, "job-id") && |
ef416fc2 | 1389 | attr->value_tag == IPP_TAG_INTEGER) |
1390 | jobid = attr->values[0].integer; | |
229681c1 MS |
1391 | else if (!strcmp(attr->name, "job-k-octets") && |
1392 | attr->value_tag == IPP_TAG_INTEGER) | |
ef416fc2 | 1393 | size = attr->values[0].integer; |
229681c1 MS |
1394 | else if (!strcmp(attr->name, "time-at-creation") && |
1395 | attr->value_tag == IPP_TAG_INTEGER) | |
ef416fc2 | 1396 | jobtime = attr->values[0].integer; |
229681c1 MS |
1397 | else if (!strcmp(attr->name, "job-printer-state-message") && |
1398 | attr->value_tag == IPP_TAG_TEXT) | |
1399 | message = attr->values[0].string.text; | |
1400 | else if (!strcmp(attr->name, "job-printer-uri") && | |
1401 | attr->value_tag == IPP_TAG_URI) | |
1402 | { | |
ef416fc2 | 1403 | if ((dest = strrchr(attr->values[0].string.text, '/')) != NULL) |
1404 | dest ++; | |
229681c1 MS |
1405 | } |
1406 | else if (!strcmp(attr->name, "job-originating-user-name") && | |
1407 | attr->value_tag == IPP_TAG_NAME) | |
ef416fc2 | 1408 | username = attr->values[0].string.text; |
229681c1 MS |
1409 | else if (!strcmp(attr->name, "job-name") && |
1410 | attr->value_tag == IPP_TAG_NAME) | |
ef416fc2 | 1411 | title = attr->values[0].string.text; |
229681c1 MS |
1412 | else if (!strcmp(attr->name, "job-state-reasons") && |
1413 | attr->value_tag == IPP_TAG_KEYWORD) | |
09a101d6 | 1414 | reasons = attr; |
1415 | ||
ef416fc2 | 1416 | attr = attr->next; |
1417 | } | |
1418 | ||
1419 | /* | |
1420 | * See if we have everything needed... | |
1421 | */ | |
1422 | ||
1423 | if (dest == NULL || jobid == 0) | |
1424 | { | |
1425 | if (attr == NULL) | |
1426 | break; | |
1427 | else | |
1428 | continue; | |
1429 | } | |
1430 | ||
1431 | /* | |
61cf44e2 | 1432 | * Display the job... |
ef416fc2 | 1433 | */ |
1434 | ||
ef416fc2 | 1435 | rank ++; |
1436 | ||
cc754834 | 1437 | if (match_list(dests, dest) && match_list(users, username)) |
ef416fc2 | 1438 | { |
1439 | jobdate = localtime(&jobtime); | |
1440 | snprintf(temp, sizeof(temp), "%s-%d", dest, jobid); | |
1441 | ||
1442 | if (long_status == 3) | |
1443 | { | |
1444 | /* | |
1445 | * Show the consolidated output format for the SGI tools... | |
1446 | */ | |
1447 | ||
1448 | if (!strftime(date, sizeof(date), "%b %d %H:%M", jobdate)) | |
5a9febac | 1449 | strlcpy(date, "Unknown", sizeof(date)); |
ef416fc2 | 1450 | |
0837b7e8 | 1451 | _cupsLangPrintf(stdout, "%s;%s;%d;%s;%s", |
ef416fc2 | 1452 | temp, username ? username : "unknown", |
1453 | size, title ? title : "unknown", date); | |
1454 | } | |
1455 | else | |
1456 | { | |
1457 | if (!strftime(date, sizeof(date), "%c", jobdate)) | |
5a9febac | 1458 | strlcpy(date, "Unknown", sizeof(date)); |
ef416fc2 | 1459 | |
1460 | if (ranking) | |
0837b7e8 | 1461 | _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s", |
ef416fc2 | 1462 | rank, temp, username ? username : "unknown", |
1463 | 1024.0 * size, date); | |
1464 | else | |
0837b7e8 | 1465 | _cupsLangPrintf(stdout, "%-23s %-13s %8.0f %s", |
ef416fc2 | 1466 | temp, username ? username : "unknown", |
1467 | 1024.0 * size, date); | |
1468 | if (long_status) | |
09a101d6 | 1469 | { |
229681c1 MS |
1470 | if (message) |
1471 | _cupsLangPrintf(stdout, _("\tStatus: %s"), message); | |
1472 | ||
09a101d6 | 1473 | if (reasons) |
1474 | { | |
0837b7e8 MS |
1475 | char alerts[1024], /* Alerts string */ |
1476 | *aptr; /* Pointer into alerts string */ | |
1477 | ||
1478 | for (i = 0, aptr = alerts; i < reasons->num_values; i ++) | |
1479 | { | |
1480 | if (i) | |
7e86f2f6 | 1481 | snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text); |
0837b7e8 | 1482 | else |
7e86f2f6 | 1483 | strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts)); |
0837b7e8 MS |
1484 | |
1485 | aptr += strlen(aptr); | |
1486 | } | |
1487 | ||
1488 | _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts); | |
09a101d6 | 1489 | } |
0837b7e8 MS |
1490 | |
1491 | _cupsLangPrintf(stdout, _("\tqueued for %s"), dest); | |
09a101d6 | 1492 | } |
ef416fc2 | 1493 | } |
1494 | } | |
1495 | ||
1496 | if (attr == NULL) | |
1497 | break; | |
1498 | } | |
1499 | ||
1500 | ippDelete(response); | |
1501 | } | |
ef416fc2 | 1502 | |
1503 | return (0); | |
1504 | } | |
1505 | ||
1506 | ||
1507 | /* | |
1508 | * 'show_printers()' - Show printers. | |
1509 | */ | |
1510 | ||
1511 | static int /* O - 0 on success, 1 on fail */ | |
61cf44e2 | 1512 | show_printers(const char *printers, /* I - Destinations */ |
ef416fc2 | 1513 | int num_dests, /* I - Number of user-defined dests */ |
1514 | cups_dest_t *dests, /* I - User-defined destinations */ | |
1515 | int long_status) /* I - Show long status? */ | |
1516 | { | |
26d47ec6 | 1517 | int i, j; /* Looping vars */ |
ef416fc2 | 1518 | ipp_t *request, /* IPP Request */ |
1519 | *response, /* IPP Response */ | |
1520 | *jobs; /* IPP Get Jobs response */ | |
1521 | ipp_attribute_t *attr, /* Current attribute */ | |
1522 | *jobattr, /* Job ID attribute */ | |
1523 | *reasons; /* Job state reasons attribute */ | |
1524 | const char *printer, /* Printer name */ | |
1525 | *message, /* Printer state message */ | |
1526 | *description, /* Description of printer */ | |
1527 | *location, /* Location of printer */ | |
1528 | *make_model, /* Make and model of printer */ | |
1529 | *uri; /* URI of printer */ | |
1530 | ipp_attribute_t *allowed, /* requesting-user-name-allowed */ | |
1531 | *denied; /* requestint-user-name-denied */ | |
1532 | ipp_pstate_t pstate; /* Printer state */ | |
1533 | cups_ptype_t ptype; /* Printer type */ | |
1534 | time_t ptime; /* Printer state time */ | |
1535 | struct tm *pdate; /* Printer state date & time */ | |
1536 | int jobid; /* Job ID of current job */ | |
ef416fc2 | 1537 | char printer_uri[HTTP_MAX_URI], |
1538 | /* Printer URI */ | |
1539 | printer_state_time[255];/* Printer state time */ | |
f8b3a85b | 1540 | _cups_globals_t *cg = _cupsGlobals(); /* Global data */ |
ef416fc2 | 1541 | static const char *pattrs[] = /* Attributes we need for printers... */ |
1542 | { | |
1543 | "printer-name", | |
1544 | "printer-state", | |
1545 | "printer-state-message", | |
1546 | "printer-state-reasons", | |
1547 | "printer-state-change-time", | |
1548 | "printer-type", | |
1549 | "printer-info", | |
1550 | "printer-location", | |
1551 | "printer-make-and-model", | |
1552 | "printer-uri-supported", | |
1553 | "requesting-user-name-allowed", | |
1554 | "requesting-user-name-denied" | |
1555 | }; | |
1556 | static const char *jattrs[] = /* Attributes we need for jobs... */ | |
1557 | { | |
7cf5915e MS |
1558 | "job-id", |
1559 | "job-state" | |
ef416fc2 | 1560 | }; |
1561 | ||
1562 | ||
bf3816c7 MS |
1563 | DEBUG_printf(("show_printers(printers=\"%s\", num_dests=%d, dests=%p, " |
1564 | "long_status=%d)\n", printers, num_dests, dests, long_status)); | |
ef416fc2 | 1565 | |
fa73b229 | 1566 | if (printers != NULL && !strcmp(printers, "all")) |
ef416fc2 | 1567 | printers = NULL; |
1568 | ||
1569 | /* | |
1570 | * Build a CUPS_GET_PRINTERS request, which requires the following | |
1571 | * attributes: | |
1572 | * | |
1573 | * attributes-charset | |
1574 | * attributes-natural-language | |
1575 | * requested-attributes | |
fa73b229 | 1576 | * requesting-user-name |
ef416fc2 | 1577 | */ |
1578 | ||
1579 | request = ippNewRequest(CUPS_GET_PRINTERS); | |
1580 | ||
1581 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
1582 | "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]), | |
1583 | NULL, pattrs); | |
1584 | ||
fa73b229 | 1585 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name", |
1586 | NULL, cupsUser()); | |
1587 | ||
ef416fc2 | 1588 | /* |
1589 | * Do the request and get back a response... | |
1590 | */ | |
1591 | ||
c606bcae MS |
1592 | response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/"); |
1593 | ||
1594 | if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST || | |
1595 | cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED) | |
ef416fc2 | 1596 | { |
c606bcae MS |
1597 | _cupsLangPrintf(stderr, |
1598 | _("%s: Error - add '/version=1.1' to server name."), | |
1599 | "lpstat"); | |
1600 | ippDelete(response); | |
1601 | return (1); | |
1602 | } | |
1603 | else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING) | |
1604 | { | |
1605 | _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString()); | |
1606 | ippDelete(response); | |
1607 | return (1); | |
1608 | } | |
ef416fc2 | 1609 | |
c606bcae MS |
1610 | if (response) |
1611 | { | |
1612 | DEBUG_puts("show_printers: request succeeded..."); | |
ef416fc2 | 1613 | |
1614 | /* | |
1615 | * Loop through the printers returned in the list and display | |
1616 | * their status... | |
1617 | */ | |
1618 | ||
1619 | for (attr = response->attrs; attr != NULL; attr = attr->next) | |
1620 | { | |
1621 | /* | |
1622 | * Skip leading attributes until we hit a job... | |
1623 | */ | |
1624 | ||
1625 | while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER) | |
1626 | attr = attr->next; | |
1627 | ||
1628 | if (attr == NULL) | |
1629 | break; | |
1630 | ||
1631 | /* | |
1632 | * Pull the needed attributes from this job... | |
1633 | */ | |
1634 | ||
1635 | printer = NULL; | |
1636 | ptime = 0; | |
1637 | ptype = CUPS_PRINTER_LOCAL; | |
1638 | pstate = IPP_PRINTER_IDLE; | |
1639 | message = NULL; | |
1640 | description = NULL; | |
1641 | location = NULL; | |
1642 | make_model = NULL; | |
1643 | reasons = NULL; | |
1644 | uri = NULL; | |
1645 | jobid = 0; | |
1646 | allowed = NULL; | |
1647 | denied = NULL; | |
1648 | ||
1649 | while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER) | |
1650 | { | |
1651 | if (!strcmp(attr->name, "printer-name") && | |
1652 | attr->value_tag == IPP_TAG_NAME) | |
1653 | printer = attr->values[0].string.text; | |
1654 | else if (!strcmp(attr->name, "printer-state") && | |
1655 | attr->value_tag == IPP_TAG_ENUM) | |
1656 | pstate = (ipp_pstate_t)attr->values[0].integer; | |
1657 | else if (!strcmp(attr->name, "printer-type") && | |
1658 | attr->value_tag == IPP_TAG_ENUM) | |
1659 | ptype = (cups_ptype_t)attr->values[0].integer; | |
1660 | else if (!strcmp(attr->name, "printer-state-message") && | |
1661 | attr->value_tag == IPP_TAG_TEXT) | |
1662 | message = attr->values[0].string.text; | |
1663 | else if (!strcmp(attr->name, "printer-state-change-time") && | |
1664 | attr->value_tag == IPP_TAG_INTEGER) | |
1665 | ptime = (time_t)attr->values[0].integer; | |
1666 | else if (!strcmp(attr->name, "printer-info") && | |
1667 | attr->value_tag == IPP_TAG_TEXT) | |
1668 | description = attr->values[0].string.text; | |
1669 | else if (!strcmp(attr->name, "printer-location") && | |
1670 | attr->value_tag == IPP_TAG_TEXT) | |
1671 | location = attr->values[0].string.text; | |
1672 | else if (!strcmp(attr->name, "printer-make-and-model") && | |
1673 | attr->value_tag == IPP_TAG_TEXT) | |
1674 | make_model = attr->values[0].string.text; | |
1675 | else if (!strcmp(attr->name, "printer-uri-supported") && | |
1676 | attr->value_tag == IPP_TAG_URI) | |
1677 | uri = attr->values[0].string.text; | |
1678 | else if (!strcmp(attr->name, "printer-state-reasons") && | |
1679 | attr->value_tag == IPP_TAG_KEYWORD) | |
1680 | reasons = attr; | |
1681 | else if (!strcmp(attr->name, "requesting-user-name-allowed") && | |
1682 | attr->value_tag == IPP_TAG_NAME) | |
1683 | allowed = attr; | |
1684 | else if (!strcmp(attr->name, "requesting-user-name-denied") && | |
1685 | attr->value_tag == IPP_TAG_NAME) | |
1686 | denied = attr; | |
1687 | ||
1688 | attr = attr->next; | |
1689 | } | |
1690 | ||
1691 | /* | |
1692 | * See if we have everything needed... | |
1693 | */ | |
1694 | ||
1695 | if (printer == NULL) | |
1696 | { | |
1697 | if (attr == NULL) | |
1698 | break; | |
1699 | else | |
1700 | continue; | |
1701 | } | |
1702 | ||
ef416fc2 | 1703 | /* |
1704 | * Display the printer entry if needed... | |
1705 | */ | |
1706 | ||
61cf44e2 | 1707 | if (match_list(printers, printer)) |
ef416fc2 | 1708 | { |
1709 | /* | |
1710 | * If the printer state is "IPP_PRINTER_PROCESSING", then grab the | |
1711 | * current job for the printer. | |
1712 | */ | |
1713 | ||
1714 | if (pstate == IPP_PRINTER_PROCESSING) | |
1715 | { | |
1716 | /* | |
1717 | * Build an IPP_GET_JOBS request, which requires the following | |
1718 | * attributes: | |
1719 | * | |
1720 | * attributes-charset | |
1721 | * attributes-natural-language | |
1722 | * printer-uri | |
1723 | * limit | |
1724 | * requested-attributes | |
1725 | */ | |
1726 | ||
1727 | request = ippNewRequest(IPP_GET_JOBS); | |
1728 | ||
1729 | request->request.op.operation_id = IPP_GET_JOBS; | |
1730 | request->request.op.request_id = 1; | |
1731 | ||
1732 | ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, | |
1733 | "requested-attributes", | |
1734 | sizeof(jattrs) / sizeof(jattrs[0]), NULL, jattrs); | |
1735 | ||
a4d04587 | 1736 | httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri), |
1737 | "ipp", NULL, "localhost", 0, "/printers/%s", printer); | |
ef416fc2 | 1738 | ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, |
1739 | "printer-uri", NULL, printer_uri); | |
1740 | ||
61cf44e2 | 1741 | if ((jobs = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL) |
ef416fc2 | 1742 | { |
1743 | /* | |
1744 | * Get the current active job on this queue... | |
1745 | */ | |
1746 | ||
c934a06c | 1747 | ipp_jstate_t jobstate = IPP_JOB_PENDING; |
ef416fc2 | 1748 | jobid = 0; |
1749 | ||
1750 | for (jobattr = jobs->attrs; jobattr; jobattr = jobattr->next) | |
1751 | { | |
1752 | if (!jobattr->name) | |
c934a06c MS |
1753 | { |
1754 | if (jobstate == IPP_JOB_PROCESSING) | |
1755 | break; | |
1756 | else | |
1757 | continue; | |
1758 | } | |
ef416fc2 | 1759 | |
1760 | if (!strcmp(jobattr->name, "job-id") && | |
1761 | jobattr->value_tag == IPP_TAG_INTEGER) | |
1762 | jobid = jobattr->values[0].integer; | |
1763 | else if (!strcmp(jobattr->name, "job-state") && | |
c934a06c | 1764 | jobattr->value_tag == IPP_TAG_ENUM) |
7e86f2f6 | 1765 | jobstate = (ipp_jstate_t)jobattr->values[0].integer; |
ef416fc2 | 1766 | } |
1767 | ||
c934a06c MS |
1768 | if (jobstate != IPP_JOB_PROCESSING) |
1769 | jobid = 0; | |
1770 | ||
ef416fc2 | 1771 | ippDelete(jobs); |
1772 | } | |
1773 | } | |
1774 | ||
1775 | /* | |
1776 | * Display it... | |
1777 | */ | |
1778 | ||
1779 | pdate = localtime(&ptime); | |
1780 | strftime(printer_state_time, sizeof(printer_state_time), "%c", pdate); | |
1781 | ||
1782 | switch (pstate) | |
1783 | { | |
1784 | case IPP_PRINTER_IDLE : | |
fa73b229 | 1785 | _cupsLangPrintf(stdout, |
0837b7e8 | 1786 | _("printer %s is idle. enabled since %s"), |
ef416fc2 | 1787 | printer, printer_state_time); |
1788 | break; | |
1789 | case IPP_PRINTER_PROCESSING : | |
fa73b229 | 1790 | _cupsLangPrintf(stdout, |
ef416fc2 | 1791 | _("printer %s now printing %s-%d. " |
0837b7e8 | 1792 | "enabled since %s"), |
ef416fc2 | 1793 | printer, printer, jobid, printer_state_time); |
1794 | break; | |
1795 | case IPP_PRINTER_STOPPED : | |
fa73b229 | 1796 | _cupsLangPrintf(stdout, |
0837b7e8 | 1797 | _("printer %s disabled since %s -"), |
ef416fc2 | 1798 | printer, printer_state_time); |
1799 | break; | |
1800 | } | |
1801 | ||
1802 | if ((message && *message) || pstate == IPP_PRINTER_STOPPED) | |
1803 | { | |
1804 | if (!message || !*message) | |
0837b7e8 | 1805 | _cupsLangPuts(stdout, _("\treason unknown")); |
ef416fc2 | 1806 | else |
0837b7e8 | 1807 | _cupsLangPrintf(stdout, "\t%s", message); |
ef416fc2 | 1808 | } |
1809 | ||
1810 | if (long_status > 1) | |
0837b7e8 MS |
1811 | { |
1812 | _cupsLangPuts(stdout, _("\tForm mounted:")); | |
1813 | _cupsLangPuts(stdout, _("\tContent types: any")); | |
1814 | _cupsLangPuts(stdout, _("\tPrinter types: unknown")); | |
1815 | } | |
ef416fc2 | 1816 | |
1817 | if (long_status) | |
1818 | { | |
0837b7e8 | 1819 | _cupsLangPrintf(stdout, _("\tDescription: %s"), |
ef416fc2 | 1820 | description ? description : ""); |
1821 | ||
1822 | if (reasons) | |
1823 | { | |
0837b7e8 MS |
1824 | char alerts[1024], /* Alerts string */ |
1825 | *aptr; /* Pointer into alerts string */ | |
1826 | ||
1827 | for (i = 0, aptr = alerts; i < reasons->num_values; i ++) | |
1828 | { | |
1829 | if (i) | |
7e86f2f6 | 1830 | snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text); |
0837b7e8 | 1831 | else |
7e86f2f6 | 1832 | strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts)); |
0837b7e8 MS |
1833 | |
1834 | aptr += strlen(aptr); | |
1835 | } | |
1836 | ||
1837 | _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts); | |
ef416fc2 | 1838 | } |
1839 | } | |
1840 | if (long_status > 1) | |
1841 | { | |
0837b7e8 | 1842 | _cupsLangPrintf(stdout, _("\tLocation: %s"), |
ef416fc2 | 1843 | location ? location : ""); |
1844 | ||
1845 | if (ptype & CUPS_PRINTER_REMOTE) | |
1846 | { | |
0837b7e8 | 1847 | _cupsLangPuts(stdout, _("\tConnection: remote")); |
ef416fc2 | 1848 | |
1849 | if (make_model && !strstr(make_model, "System V Printer") && | |
1850 | !strstr(make_model, "Raw Printer") && uri) | |
0837b7e8 | 1851 | _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"), |
ef416fc2 | 1852 | uri); |
1853 | } | |
1854 | else | |
1855 | { | |
0837b7e8 | 1856 | _cupsLangPuts(stdout, _("\tConnection: direct")); |
ef416fc2 | 1857 | |
1858 | if (make_model && strstr(make_model, "System V Printer")) | |
fa73b229 | 1859 | _cupsLangPrintf(stdout, |
0837b7e8 | 1860 | _("\tInterface: %s/interfaces/%s"), |
f8b3a85b | 1861 | cg->cups_serverroot, printer); |
ef416fc2 | 1862 | else if (make_model && !strstr(make_model, "Raw Printer")) |
fa73b229 | 1863 | _cupsLangPrintf(stdout, |
0837b7e8 | 1864 | _("\tInterface: %s/ppd/%s.ppd"), |
f8b3a85b | 1865 | cg->cups_serverroot, printer); |
ef416fc2 | 1866 | } |
0837b7e8 MS |
1867 | _cupsLangPuts(stdout, _("\tOn fault: no alert")); |
1868 | _cupsLangPuts(stdout, _("\tAfter fault: continue")); | |
b423cd4c | 1869 | /* TODO update to use printer-error-policy */ |
ef416fc2 | 1870 | if (allowed) |
1871 | { | |
0837b7e8 | 1872 | _cupsLangPuts(stdout, _("\tUsers allowed:")); |
26d47ec6 | 1873 | for (j = 0; j < allowed->num_values; j ++) |
0837b7e8 | 1874 | _cupsLangPrintf(stdout, "\t\t%s", |
26d47ec6 | 1875 | allowed->values[j].string.text); |
ef416fc2 | 1876 | } |
1877 | else if (denied) | |
1878 | { | |
0837b7e8 | 1879 | _cupsLangPuts(stdout, _("\tUsers denied:")); |
26d47ec6 | 1880 | for (j = 0; j < denied->num_values; j ++) |
0837b7e8 | 1881 | _cupsLangPrintf(stdout, "\t\t%s", |
26d47ec6 | 1882 | denied->values[j].string.text); |
ef416fc2 | 1883 | } |
1884 | else | |
1885 | { | |
0837b7e8 MS |
1886 | _cupsLangPuts(stdout, _("\tUsers allowed:")); |
1887 | _cupsLangPuts(stdout, _("\t\t(all)")); | |
ef416fc2 | 1888 | } |
0837b7e8 MS |
1889 | _cupsLangPuts(stdout, _("\tForms allowed:")); |
1890 | _cupsLangPuts(stdout, _("\t\t(none)")); | |
1891 | _cupsLangPuts(stdout, _("\tBanner required")); | |
1892 | _cupsLangPuts(stdout, _("\tCharset sets:")); | |
1893 | _cupsLangPuts(stdout, _("\t\t(none)")); | |
1894 | _cupsLangPuts(stdout, _("\tDefault pitch:")); | |
1895 | _cupsLangPuts(stdout, _("\tDefault page size:")); | |
1896 | _cupsLangPuts(stdout, _("\tDefault port settings:")); | |
ef416fc2 | 1897 | } |
1898 | ||
1899 | for (i = 0; i < num_dests; i ++) | |
88f9aafc | 1900 | if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance) |
ef416fc2 | 1901 | { |
1902 | switch (pstate) | |
1903 | { | |
1904 | case IPP_PRINTER_IDLE : | |
fa73b229 | 1905 | _cupsLangPrintf(stdout, |
ef416fc2 | 1906 | _("printer %s/%s is idle. " |
0837b7e8 | 1907 | "enabled since %s"), |
ef416fc2 | 1908 | printer, dests[i].instance, |
1909 | printer_state_time); | |
1910 | break; | |
1911 | case IPP_PRINTER_PROCESSING : | |
fa73b229 | 1912 | _cupsLangPrintf(stdout, |
ef416fc2 | 1913 | _("printer %s/%s now printing %s-%d. " |
0837b7e8 | 1914 | "enabled since %s"), |
ef416fc2 | 1915 | printer, dests[i].instance, printer, jobid, |
1916 | printer_state_time); | |
1917 | break; | |
1918 | case IPP_PRINTER_STOPPED : | |
fa73b229 | 1919 | _cupsLangPrintf(stdout, |
0837b7e8 | 1920 | _("printer %s/%s disabled since %s -"), |
ef416fc2 | 1921 | printer, dests[i].instance, |
1922 | printer_state_time); | |
1923 | break; | |
1924 | } | |
1925 | ||
1926 | if ((message && *message) || pstate == IPP_PRINTER_STOPPED) | |
1927 | { | |
1928 | if (!message || !*message) | |
0837b7e8 | 1929 | _cupsLangPuts(stdout, _("\treason unknown")); |
ef416fc2 | 1930 | else |
0837b7e8 | 1931 | _cupsLangPrintf(stdout, "\t%s", message); |
ef416fc2 | 1932 | } |
1933 | ||
1934 | if (long_status > 1) | |
0837b7e8 MS |
1935 | { |
1936 | _cupsLangPuts(stdout, _("\tForm mounted:")); | |
1937 | _cupsLangPuts(stdout, _("\tContent types: any")); | |
1938 | _cupsLangPuts(stdout, _("\tPrinter types: unknown")); | |
1939 | } | |
ef416fc2 | 1940 | |
1941 | if (long_status) | |
1942 | { | |
0837b7e8 | 1943 | _cupsLangPrintf(stdout, _("\tDescription: %s"), |
ef416fc2 | 1944 | description ? description : ""); |
1945 | ||
1946 | if (reasons) | |
1947 | { | |
0837b7e8 MS |
1948 | char alerts[1024], /* Alerts string */ |
1949 | *aptr; /* Pointer into alerts string */ | |
1950 | ||
1951 | for (i = 0, aptr = alerts; i < reasons->num_values; i ++) | |
1952 | { | |
1953 | if (i) | |
7e86f2f6 | 1954 | snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text); |
0837b7e8 | 1955 | else |
7e86f2f6 | 1956 | strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts)); |
0837b7e8 MS |
1957 | |
1958 | aptr += strlen(aptr); | |
1959 | } | |
1960 | ||
1961 | _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts); | |
ef416fc2 | 1962 | } |
1963 | } | |
1964 | if (long_status > 1) | |
1965 | { | |
0837b7e8 | 1966 | _cupsLangPrintf(stdout, _("\tLocation: %s"), |
ef416fc2 | 1967 | location ? location : ""); |
1968 | ||
1969 | if (ptype & CUPS_PRINTER_REMOTE) | |
1970 | { | |
0837b7e8 | 1971 | _cupsLangPuts(stdout, _("\tConnection: remote")); |
ef416fc2 | 1972 | |
1973 | if (make_model && !strstr(make_model, "System V Printer") && | |
1974 | !strstr(make_model, "Raw Printer") && uri) | |
0837b7e8 | 1975 | _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"), uri); |
ef416fc2 | 1976 | } |
1977 | else | |
1978 | { | |
0837b7e8 | 1979 | _cupsLangPuts(stdout, _("\tConnection: direct")); |
ef416fc2 | 1980 | |
1981 | if (make_model && strstr(make_model, "System V Printer")) | |
fa73b229 | 1982 | _cupsLangPrintf(stdout, |
0837b7e8 | 1983 | _("\tInterface: %s/interfaces/%s"), |
f8b3a85b | 1984 | cg->cups_serverroot, printer); |
ef416fc2 | 1985 | else if (make_model && !strstr(make_model, "Raw Printer")) |
fa73b229 | 1986 | _cupsLangPrintf(stdout, |
0837b7e8 | 1987 | _("\tInterface: %s/ppd/%s.ppd"), |
f8b3a85b | 1988 | cg->cups_serverroot, printer); |
ef416fc2 | 1989 | } |
0837b7e8 MS |
1990 | _cupsLangPuts(stdout, _("\tOn fault: no alert")); |
1991 | _cupsLangPuts(stdout, _("\tAfter fault: continue")); | |
b423cd4c | 1992 | /* TODO update to use printer-error-policy */ |
ef416fc2 | 1993 | if (allowed) |
1994 | { | |
0837b7e8 | 1995 | _cupsLangPuts(stdout, _("\tUsers allowed:")); |
26d47ec6 | 1996 | for (j = 0; j < allowed->num_values; j ++) |
0837b7e8 | 1997 | _cupsLangPrintf(stdout, "\t\t%s", |
26d47ec6 | 1998 | allowed->values[j].string.text); |
ef416fc2 | 1999 | } |
2000 | else if (denied) | |
2001 | { | |
0837b7e8 | 2002 | _cupsLangPuts(stdout, _("\tUsers denied:")); |
26d47ec6 | 2003 | for (j = 0; j < denied->num_values; j ++) |
0837b7e8 | 2004 | _cupsLangPrintf(stdout, "\t\t%s", |
26d47ec6 | 2005 | denied->values[j].string.text); |
ef416fc2 | 2006 | } |
2007 | else | |
2008 | { | |
0837b7e8 MS |
2009 | _cupsLangPuts(stdout, _("\tUsers allowed:")); |
2010 | _cupsLangPuts(stdout, _("\t\t(all)")); | |
ef416fc2 | 2011 | } |
0837b7e8 MS |
2012 | _cupsLangPuts(stdout, _("\tForms allowed:")); |
2013 | _cupsLangPuts(stdout, _("\t\t(none)")); | |
2014 | _cupsLangPuts(stdout, _("\tBanner required")); | |
2015 | _cupsLangPuts(stdout, _("\tCharset sets:")); | |
2016 | _cupsLangPuts(stdout, _("\t\t(none)")); | |
2017 | _cupsLangPuts(stdout, _("\tDefault pitch:")); | |
2018 | _cupsLangPuts(stdout, _("\tDefault page size:")); | |
2019 | _cupsLangPuts(stdout, _("\tDefault port settings:")); | |
ef416fc2 | 2020 | } |
2021 | } | |
2022 | } | |
2023 | ||
2024 | if (attr == NULL) | |
2025 | break; | |
2026 | } | |
2027 | ||
2028 | ippDelete(response); | |
2029 | } | |
ef416fc2 | 2030 | |
2031 | return (0); | |
2032 | } | |
2033 | ||
2034 | ||
2035 | /* | |
2036 | * 'show_scheduler()' - Show scheduler status. | |
2037 | */ | |
2038 | ||
2039 | static void | |
61cf44e2 | 2040 | show_scheduler(void) |
ef416fc2 | 2041 | { |
61cf44e2 MS |
2042 | http_t *http; /* Connection to server */ |
2043 | ||
2044 | ||
2045 | if ((http = httpConnectEncrypt(cupsServer(), ippPort(), | |
2046 | cupsEncryption())) != NULL) | |
2047 | { | |
0837b7e8 | 2048 | _cupsLangPuts(stdout, _("scheduler is running")); |
61cf44e2 MS |
2049 | httpClose(http); |
2050 | } | |
ef416fc2 | 2051 | else |
0837b7e8 | 2052 | _cupsLangPuts(stdout, _("scheduler is not running")); |
ef416fc2 | 2053 | } |
2054 | ||
2055 | ||
2056 | /* | |
f2d18633 | 2057 | * End of "$Id$". |
ef416fc2 | 2058 | */ |