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