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