]> git.ipfire.org Git - thirdparty/cups.git/blame - systemv/lpstat.c
Update ipp documentation to reflect the behavior of configuring WiFi on IPP USB printers.
[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
baa764fa 637 do
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 }
baa764fa 663 while (*list);
ef416fc2 664
61cf44e2 665 return (0);
ef416fc2 666}
667
668
669/*
670 * 'show_accepting()' - Show acceptance status.
671 */
672
673static int /* O - 0 on success, 1 on fail */
61cf44e2 674show_accepting(const char *printers, /* I - Destinations */
ef416fc2 675 int num_dests, /* I - Number of user-defined dests */
676 cups_dest_t *dests) /* I - User-defined destinations */
677{
678 int i; /* Looping var */
679 ipp_t *request, /* IPP Request */
680 *response; /* IPP Response */
681 ipp_attribute_t *attr; /* Current attribute */
682 const char *printer, /* Printer name */
683 *message; /* Printer device URI */
684 int accepting; /* Accepting requests? */
fa73b229 685 time_t ptime; /* Printer state time */
fa73b229 686 char printer_state_time[255];/* Printer state time */
ef416fc2 687 static const char *pattrs[] = /* Attributes we need for printers... */
688 {
689 "printer-name",
fa73b229 690 "printer-state-change-time",
ef416fc2 691 "printer-state-message",
692 "printer-is-accepting-jobs"
693 };
694
695
fa73b229 696 if (printers != NULL && !strcmp(printers, "all"))
ef416fc2 697 printers = NULL;
698
699 /*
700 * Build a CUPS_GET_PRINTERS request, which requires the following
701 * attributes:
702 *
703 * attributes-charset
704 * attributes-natural-language
705 * requested-attributes
fa73b229 706 * requesting-user-name
ef416fc2 707 */
708
709 request = ippNewRequest(CUPS_GET_PRINTERS);
710
711 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
712 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]),
713 NULL, pattrs);
714
fa73b229 715 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
716 NULL, cupsUser());
717
ef416fc2 718 /*
719 * Do the request and get back a response...
720 */
721
c606bcae
MS
722 response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
723
724 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
725 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
ef416fc2 726 {
c606bcae
MS
727 _cupsLangPrintf(stderr,
728 _("%s: Error - add '/version=1.1' to server name."),
729 "lpstat");
730 ippDelete(response);
731 return (1);
732 }
733 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
734 {
735 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
736 ippDelete(response);
737 return (1);
738 }
ef416fc2 739
c606bcae
MS
740 if (response)
741 {
ef416fc2 742 /*
743 * Loop through the printers returned in the list and display
744 * their devices...
745 */
746
747 for (attr = response->attrs; attr != NULL; attr = attr->next)
748 {
749 /*
750 * Skip leading attributes until we hit a printer...
751 */
752
753 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
754 attr = attr->next;
755
756 if (attr == NULL)
757 break;
758
759 /*
760 * Pull the needed attributes from this printer...
761 */
762
763 printer = NULL;
764 message = NULL;
765 accepting = 1;
fa73b229 766 ptime = 0;
ef416fc2 767
768 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
769 {
770 if (!strcmp(attr->name, "printer-name") &&
771 attr->value_tag == IPP_TAG_NAME)
772 printer = attr->values[0].string.text;
fa73b229 773 else if (!strcmp(attr->name, "printer-state-change-time") &&
774 attr->value_tag == IPP_TAG_INTEGER)
775 ptime = (time_t)attr->values[0].integer;
776 else if (!strcmp(attr->name, "printer-state-message") &&
777 attr->value_tag == IPP_TAG_TEXT)
ef416fc2 778 message = attr->values[0].string.text;
fa73b229 779 else if (!strcmp(attr->name, "printer-is-accepting-jobs") &&
780 attr->value_tag == IPP_TAG_BOOLEAN)
ef416fc2 781 accepting = attr->values[0].boolean;
782
783 attr = attr->next;
784 }
785
786 /*
787 * See if we have everything needed...
788 */
789
790 if (printer == NULL)
791 {
792 if (attr == NULL)
793 break;
794 else
795 continue;
796 }
797
ef416fc2 798 /*
799 * Display the printer entry if needed...
800 */
801
61cf44e2 802 if (match_list(printers, printer))
ef416fc2 803 {
554aa7b7 804 _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
fa73b229 805
ef416fc2 806 if (accepting)
0837b7e8 807 _cupsLangPrintf(stdout, _("%s accepting requests since %s"),
fa73b229 808 printer, printer_state_time);
ef416fc2 809 else
0837b7e8
MS
810 {
811 _cupsLangPrintf(stdout, _("%s not accepting requests since %s -"),
812 printer, printer_state_time);
813 _cupsLangPrintf(stdout, _("\t%s"),
baa764fa
AG
814 (message && *message) ?
815 message : "reason unknown");
0837b7e8 816 }
ef416fc2 817
818 for (i = 0; i < num_dests; i ++)
88f9aafc 819 if (!_cups_strcasecmp(dests[i].name, printer) && dests[i].instance)
ef416fc2 820 {
821 if (accepting)
0837b7e8 822 _cupsLangPrintf(stdout, _("%s/%s accepting requests since %s"),
fa73b229 823 printer, dests[i].instance, printer_state_time);
ef416fc2 824 else
0837b7e8
MS
825 {
826 _cupsLangPrintf(stdout,
827 _("%s/%s not accepting requests since %s -"),
828 printer, dests[i].instance, printer_state_time);
829 _cupsLangPrintf(stdout, _("\t%s"),
baa764fa
AG
830 (message && *message) ?
831 message : "reason unknown");
0837b7e8 832 }
ef416fc2 833 }
834 }
835
836 if (attr == NULL)
837 break;
838 }
839
840 ippDelete(response);
841 }
ef416fc2 842
843 return (0);
844}
845
846
847/*
848 * 'show_classes()' - Show printer classes.
849 */
850
851static int /* O - 0 on success, 1 on fail */
61cf44e2 852show_classes(const char *dests) /* I - Destinations */
ef416fc2 853{
854 int i; /* Looping var */
855 ipp_t *request, /* IPP Request */
856 *response, /* IPP Response */
857 *response2; /* IPP response from remote server */
858 http_t *http2; /* Remote server */
859 ipp_attribute_t *attr; /* Current attribute */
860 const char *printer, /* Printer class name */
861 *printer_uri; /* Printer class URI */
862 ipp_attribute_t *members; /* Printer members */
863 char method[HTTP_MAX_URI], /* Request method */
864 username[HTTP_MAX_URI], /* Username:password */
865 server[HTTP_MAX_URI], /* Server name */
866 resource[HTTP_MAX_URI]; /* Resource name */
867 int port; /* Port number */
ef416fc2 868 static const char *cattrs[] = /* Attributes we need for classes... */
869 {
870 "printer-name",
871 "printer-uri-supported",
872 "member-names"
873 };
874
875
fa73b229 876 if (dests != NULL && !strcmp(dests, "all"))
ef416fc2 877 dests = NULL;
878
879 /*
880 * Build a CUPS_GET_CLASSES request, which requires the following
881 * attributes:
882 *
883 * attributes-charset
884 * attributes-natural-language
885 * requested-attributes
fa73b229 886 * requesting-user-name
ef416fc2 887 */
888
889 request = ippNewRequest(CUPS_GET_CLASSES);
890
891 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
892 "requested-attributes", sizeof(cattrs) / sizeof(cattrs[0]),
893 NULL, cattrs);
894
fa73b229 895 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
896 NULL, cupsUser());
897
ef416fc2 898 /*
899 * Do the request and get back a response...
900 */
901
c606bcae
MS
902 response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
903
904 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
905 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
906 {
907 _cupsLangPrintf(stderr,
908 _("%s: Error - add '/version=1.1' to server name."),
909 "lpstat");
910 ippDelete(response);
911 return (1);
912 }
913 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
914 {
915 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
916 ippDelete(response);
917 return (1);
918 }
919
920 if (response)
ef416fc2 921 {
ef416fc2 922 if (response->request.status.status_code > IPP_OK_CONFLICT)
923 {
0837b7e8 924 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
ef416fc2 925 ippDelete(response);
926 return (1);
927 }
928
929 /*
930 * Loop through the printers returned in the list and display
931 * their devices...
932 */
933
934 for (attr = response->attrs; attr != NULL; attr = attr->next)
935 {
936 /*
937 * Skip leading attributes until we hit a job...
938 */
939
940 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
941 attr = attr->next;
942
943 if (attr == NULL)
944 break;
945
946 /*
947 * Pull the needed attributes from this job...
948 */
949
950 printer = NULL;
951 printer_uri = NULL;
952 members = NULL;
953
baa764fa 954 do
ef416fc2 955 {
956 if (!strcmp(attr->name, "printer-name") &&
957 attr->value_tag == IPP_TAG_NAME)
958 printer = attr->values[0].string.text;
959
960 if (!strcmp(attr->name, "printer-uri-supported") &&
961 attr->value_tag == IPP_TAG_URI)
962 printer_uri = attr->values[0].string.text;
963
964 if (!strcmp(attr->name, "member-names") &&
965 attr->value_tag == IPP_TAG_NAME)
966 members = attr;
967
968 attr = attr->next;
969 }
baa764fa 970 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER);
ef416fc2 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 {
a4d04587 980 httpSeparateURI(HTTP_URI_CODING_ALL, printer_uri, method, sizeof(method),
ef416fc2 981 username, sizeof(username), server, sizeof(server),
982 &port, resource, sizeof(resource));
983
88f9aafc 984 if (!_cups_strcasecmp(server, cupsServer()))
61cf44e2 985 http2 = CUPS_HTTP_DEFAULT;
ef416fc2 986 else
987 http2 = httpConnectEncrypt(server, port, cupsEncryption());
988
61cf44e2
MS
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 */
ef416fc2 998
61cf44e2 999 request = ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES);
ef416fc2 1000
61cf44e2
MS
1001 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1002 "printer-uri", NULL, printer_uri);
ef416fc2 1003
61cf44e2
MS
1004 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1005 "requested-attributes",
1006 sizeof(cattrs) / sizeof(cattrs[0]),
1007 NULL, cattrs);
ef416fc2 1008
61cf44e2
MS
1009 if ((response2 = cupsDoRequest(http2, request, "/")) != NULL)
1010 members = ippFindAttribute(response2, "member-names", IPP_TAG_NAME);
ef416fc2 1011
61cf44e2
MS
1012 if (http2)
1013 httpClose(http2);
ef416fc2 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
ef416fc2 1031 /*
1032 * Display the printer entry if needed...
1033 */
1034
61cf44e2 1035 if (match_list(dests, printer))
ef416fc2 1036 {
0837b7e8 1037 _cupsLangPrintf(stdout, _("members of class %s:"), printer);
ef416fc2 1038
1039 if (members)
1040 {
1041 for (i = 0; i < members->num_values; i ++)
0837b7e8 1042 _cupsLangPrintf(stdout, "\t%s", members->values[i].string.text);
ef416fc2 1043 }
1044 else
0837b7e8 1045 _cupsLangPuts(stdout, "\tunknown");
ef416fc2 1046 }
1047
1048 if (response2)
1049 ippDelete(response2);
1050
1051 if (attr == NULL)
1052 break;
1053 }
1054
1055 ippDelete(response);
1056 }
ef416fc2 1057
1058 return (0);
1059}
1060
1061
1062/*
1063 * 'show_default()' - Show default destination.
1064 */
1065
1066static void
61cf44e2 1067show_default(cups_dest_t *dest) /* I - Default destination */
ef416fc2 1068{
ef416fc2 1069 const char *printer, /* Printer name */
1070 *val; /* Environment variable name */
1071
61cf44e2
MS
1072
1073 if (dest)
ef416fc2 1074 {
1075 if (dest->instance)
0837b7e8 1076 _cupsLangPrintf(stdout, _("system default destination: %s/%s"),
ef416fc2 1077 dest->name, dest->instance);
1078 else
0837b7e8 1079 _cupsLangPrintf(stdout, _("system default destination: %s"),
ef416fc2 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
61cf44e2 1099 if (printer)
fa73b229 1100 _cupsLangPrintf(stdout,
ef416fc2 1101 _("lpstat: error - %s environment variable names "
0837b7e8 1102 "non-existent destination \"%s\"."),
ef416fc2 1103 val, printer);
1104 else
0837b7e8 1105 _cupsLangPuts(stdout, _("no system default destination"));
ef416fc2 1106 }
1107}
1108
1109
1110/*
1111 * 'show_devices()' - Show printer devices.
1112 */
1113
1114static int /* O - 0 on success, 1 on fail */
61cf44e2 1115show_devices(const char *printers, /* I - Destinations */
ef416fc2 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 */
61cf44e2 1125 *device; /* Printer device URI */
ef416fc2 1126 static const char *pattrs[] = /* Attributes we need for printers... */
1127 {
1128 "printer-name",
1129 "printer-uri-supported",
1130 "device-uri"
1131 };
1132
1133
fa73b229 1134 if (printers != NULL && !strcmp(printers, "all"))
ef416fc2 1135 printers = NULL;
1136
1137 /*
1138 * Build a CUPS_GET_PRINTERS request, which requires the following
1139 * attributes:
1140 *
1141 * attributes-charset
1142 * attributes-natural-language
1143 * requested-attributes
fa73b229 1144 * requesting-user-name
ef416fc2 1145 */
1146
1147 request = ippNewRequest(CUPS_GET_PRINTERS);
1148
1149 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1150 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]),
1151 NULL, pattrs);
1152
fa73b229 1153 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1154 NULL, cupsUser());
1155
ef416fc2 1156 /*
1157 * Do the request and get back a response...
1158 */
1159
c606bcae
MS
1160 response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
1161
1162 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
1163 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
ef416fc2 1164 {
c606bcae
MS
1165 _cupsLangPrintf(stderr,
1166 _("%s: Error - add '/version=1.1' to server name."),
1167 "lpstat");
1168 ippDelete(response);
1169 return (1);
1170 }
1171 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
1172 {
1173 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
1174 ippDelete(response);
1175 return (1);
1176 }
ef416fc2 1177
c606bcae
MS
1178 if (response)
1179 {
ef416fc2 1180 /*
1181 * Loop through the printers returned in the list and display
1182 * their devices...
1183 */
1184
1185 for (attr = response->attrs; attr != NULL; attr = attr->next)
1186 {
1187 /*
1188 * Skip leading attributes until we hit a job...
1189 */
1190
1191 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1192 attr = attr->next;
1193
1194 if (attr == NULL)
1195 break;
1196
1197 /*
1198 * Pull the needed attributes from this job...
1199 */
1200
1201 printer = NULL;
1202 device = NULL;
1203 uri = NULL;
1204
1205 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
1206 {
1207 if (!strcmp(attr->name, "printer-name") &&
1208 attr->value_tag == IPP_TAG_NAME)
1209 printer = attr->values[0].string.text;
1210
1211 if (!strcmp(attr->name, "printer-uri-supported") &&
1212 attr->value_tag == IPP_TAG_URI)
1213 uri = attr->values[0].string.text;
1214
1215 if (!strcmp(attr->name, "device-uri") &&
1216 attr->value_tag == IPP_TAG_URI)
1217 device = attr->values[0].string.text;
1218
1219 attr = attr->next;
1220 }
1221
1222 /*
1223 * See if we have everything needed...
1224 */
1225
1226 if (printer == NULL)
1227 {
1228 if (attr == NULL)
1229 break;
1230 else
1231 continue;
1232 }
1233
ef416fc2 1234 /*
1235 * Display the printer entry if needed...
1236 */
1237
61cf44e2 1238 if (match_list(printers, printer))
ef416fc2 1239 {
ef416fc2 1240 if (device == NULL)
0837b7e8 1241 _cupsLangPrintf(stdout, _("device for %s: %s"),
ef416fc2 1242 printer, uri);
1243 else if (!strncmp(device, "file:", 5))
0837b7e8 1244 _cupsLangPrintf(stdout, _("device for %s: %s"),
ef416fc2 1245 printer, device + 5);
1246 else
0837b7e8 1247 _cupsLangPrintf(stdout, _("device for %s: %s"),
ef416fc2 1248 printer, device);
1249
1250 for (i = 0; i < num_dests; i ++)
5a1d7a17 1251 {
88f9aafc 1252 if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
ef416fc2 1253 {
1254 if (device == NULL)
0837b7e8 1255 _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
ef416fc2 1256 printer, dests[i].instance, uri);
1257 else if (!strncmp(device, "file:", 5))
0837b7e8 1258 _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
ef416fc2 1259 printer, dests[i].instance, device + 5);
1260 else
0837b7e8 1261 _cupsLangPrintf(stdout, _("device for %s/%s: %s"),
ef416fc2 1262 printer, dests[i].instance, device);
1263 }
5a1d7a17 1264 }
ef416fc2 1265 }
1266
1267 if (attr == NULL)
1268 break;
1269 }
1270
1271 ippDelete(response);
1272 }
ef416fc2 1273
1274 return (0);
1275}
1276
1277
1278/*
1279 * 'show_jobs()' - Show active print jobs.
1280 */
1281
1282static int /* O - 0 on success, 1 on fail */
61cf44e2 1283show_jobs(const char *dests, /* I - Destinations */
ef416fc2 1284 const char *users, /* I - Users */
1285 int long_status, /* I - Show long status? */
1286 int ranking, /* I - Show job ranking? */
1287 const char *which) /* I - Show which jobs? */
1288{
09a101d6 1289 int i; /* Looping var */
ef416fc2 1290 ipp_t *request, /* IPP Request */
1291 *response; /* IPP Response */
09a101d6 1292 ipp_attribute_t *attr, /* Current attribute */
1293 *reasons; /* Job state reasons attribute */
ef416fc2 1294 const char *dest, /* Pointer into job-printer-uri */
1295 *username, /* Pointer to job-originating-user-name */
eec1fbc3
MS
1296 *message, /* Pointer to job-printer-state-message */
1297 *time_at; /* time-at-xxx attribute name to use */
ef416fc2 1298 int rank, /* Rank in queue */
1299 jobid, /* job-id */
1300 size; /* job-k-octets */
1301 time_t jobtime; /* time-at-creation */
ef416fc2 1302 char temp[255], /* Temporary buffer */
1303 date[255]; /* Date buffer */
1304 static const char *jattrs[] = /* Attributes we need for jobs... */
1305 {
1306 "job-id",
1307 "job-k-octets",
1308 "job-name",
09a101d6 1309 "job-originating-user-name",
229681c1 1310 "job-printer-state-message",
5a662dc0
MS
1311 "job-printer-uri",
1312 "job-state-reasons",
eec1fbc3
MS
1313 "time-at-creation",
1314 "time-at-completed"
ef416fc2 1315 };
1316
1317
fa73b229 1318 if (dests != NULL && !strcmp(dests, "all"))
ef416fc2 1319 dests = NULL;
1320
1321 /*
1322 * Build a IPP_GET_JOBS request, which requires the following
1323 * attributes:
1324 *
1325 * attributes-charset
1326 * attributes-natural-language
52f6f666 1327 * printer-uri
ef416fc2 1328 * requested-attributes
52f6f666
MS
1329 * requesting-user-name
1330 * which-jobs
ef416fc2 1331 */
1332
1333 request = ippNewRequest(IPP_GET_JOBS);
1334
52f6f666
MS
1335 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI, "printer-uri",
1336 NULL, "ipp://localhost/");
1337
ef416fc2 1338 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1339 "requested-attributes", sizeof(jattrs) / sizeof(jattrs[0]),
1340 NULL, jattrs);
1341
52f6f666
MS
1342 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1343 NULL, cupsUser());
ef416fc2 1344
1345 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD, "which-jobs",
1346 NULL, which);
1347
1348 /*
1349 * Do the request and get back a response...
1350 */
1351
c606bcae
MS
1352 response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
1353
1354 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
1355 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
1356 {
1357 _cupsLangPrintf(stderr,
1358 _("%s: Error - add '/version=1.1' to server name."),
1359 "lpstat");
1360 ippDelete(response);
1361 return (1);
1362 }
1363 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
1364 {
1365 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
1366 ippDelete(response);
1367 return (1);
1368 }
1369
1370 if (response)
ef416fc2 1371 {
1372 /*
1373 * Loop through the job list and display them...
1374 */
1375
eec1fbc3
MS
1376 if (!strcmp(which, "aborted") ||
1377 !strcmp(which, "canceled") ||
1378 !strcmp(which, "completed"))
1379 time_at = "time-at-completed";
1380 else
1381 time_at = "time-at-creation";
1382
ef416fc2 1383 rank = -1;
1384
1385 for (attr = response->attrs; attr != NULL; attr = attr->next)
1386 {
1387 /*
1388 * Skip leading attributes until we hit a job...
1389 */
1390
1391 while (attr != NULL && attr->group_tag != IPP_TAG_JOB)
1392 attr = attr->next;
1393
1394 if (attr == NULL)
1395 break;
1396
1397 /*
1398 * Pull the needed attributes from this job...
1399 */
1400
1401 jobid = 0;
1402 size = 0;
1403 username = NULL;
1404 dest = NULL;
1405 jobtime = 0;
229681c1 1406 message = NULL;
09a101d6 1407 reasons = NULL;
ef416fc2 1408
1409 while (attr != NULL && attr->group_tag == IPP_TAG_JOB)
1410 {
fa73b229 1411 if (!strcmp(attr->name, "job-id") &&
ef416fc2 1412 attr->value_tag == IPP_TAG_INTEGER)
1413 jobid = attr->values[0].integer;
229681c1
MS
1414 else if (!strcmp(attr->name, "job-k-octets") &&
1415 attr->value_tag == IPP_TAG_INTEGER)
ef416fc2 1416 size = attr->values[0].integer;
eec1fbc3 1417 else if (!strcmp(attr->name, time_at) && attr->value_tag == IPP_TAG_INTEGER)
ef416fc2 1418 jobtime = attr->values[0].integer;
229681c1
MS
1419 else if (!strcmp(attr->name, "job-printer-state-message") &&
1420 attr->value_tag == IPP_TAG_TEXT)
1421 message = attr->values[0].string.text;
1422 else if (!strcmp(attr->name, "job-printer-uri") &&
1423 attr->value_tag == IPP_TAG_URI)
1424 {
ef416fc2 1425 if ((dest = strrchr(attr->values[0].string.text, '/')) != NULL)
1426 dest ++;
229681c1
MS
1427 }
1428 else if (!strcmp(attr->name, "job-originating-user-name") &&
1429 attr->value_tag == IPP_TAG_NAME)
ef416fc2 1430 username = attr->values[0].string.text;
229681c1
MS
1431 else if (!strcmp(attr->name, "job-state-reasons") &&
1432 attr->value_tag == IPP_TAG_KEYWORD)
09a101d6 1433 reasons = attr;
1434
ef416fc2 1435 attr = attr->next;
1436 }
1437
1438 /*
1439 * See if we have everything needed...
1440 */
1441
1442 if (dest == NULL || jobid == 0)
1443 {
1444 if (attr == NULL)
1445 break;
1446 else
1447 continue;
1448 }
1449
1450 /*
61cf44e2 1451 * Display the job...
ef416fc2 1452 */
1453
ef416fc2 1454 rank ++;
1455
cc754834 1456 if (match_list(dests, dest) && match_list(users, username))
ef416fc2 1457 {
ef416fc2 1458 snprintf(temp, sizeof(temp), "%s-%d", dest, jobid);
1459
554aa7b7 1460 _cupsStrDate(date, sizeof(date), jobtime);
ef416fc2 1461
554aa7b7
MS
1462 if (ranking)
1463 _cupsLangPrintf(stdout, "%3d %-21s %-13s %8.0f %s",
1464 rank, temp, username ? username : "unknown",
1465 1024.0 * size, date);
ef416fc2 1466 else
554aa7b7
MS
1467 _cupsLangPrintf(stdout, "%-23s %-13s %8.0f %s",
1468 temp, username ? username : "unknown",
1469 1024.0 * size, date);
1470 if (long_status)
ef416fc2 1471 {
554aa7b7
MS
1472 if (message)
1473 _cupsLangPrintf(stdout, _("\tStatus: %s"), message);
0837b7e8 1474
554aa7b7
MS
1475 if (reasons)
1476 {
1477 char alerts[1024], /* Alerts string */
1478 *aptr; /* Pointer into alerts string */
0837b7e8 1479
554aa7b7
MS
1480 for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
1481 {
1482 if (i)
1483 snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
1484 else
1485 strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
0837b7e8 1486
554aa7b7 1487 aptr += strlen(aptr);
09a101d6 1488 }
0837b7e8 1489
554aa7b7 1490 _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
09a101d6 1491 }
554aa7b7
MS
1492
1493 _cupsLangPrintf(stdout, _("\tqueued for %s"), dest);
ef416fc2 1494 }
1495 }
1496
1497 if (attr == NULL)
1498 break;
1499 }
1500
1501 ippDelete(response);
1502 }
ef416fc2 1503
1504 return (0);
1505}
1506
1507
1508/*
1509 * 'show_printers()' - Show printers.
1510 */
1511
1512static int /* O - 0 on success, 1 on fail */
61cf44e2 1513show_printers(const char *printers, /* I - Destinations */
ef416fc2 1514 int num_dests, /* I - Number of user-defined dests */
1515 cups_dest_t *dests, /* I - User-defined destinations */
1516 int long_status) /* I - Show long status? */
1517{
26d47ec6 1518 int i, j; /* Looping vars */
ef416fc2 1519 ipp_t *request, /* IPP Request */
1520 *response, /* IPP Response */
1521 *jobs; /* IPP Get Jobs response */
1522 ipp_attribute_t *attr, /* Current attribute */
1523 *jobattr, /* Job ID attribute */
1524 *reasons; /* Job state reasons attribute */
1525 const char *printer, /* Printer name */
1526 *message, /* Printer state message */
1527 *description, /* Description of printer */
1528 *location, /* Location of printer */
1529 *make_model, /* Make and model of printer */
1530 *uri; /* URI of printer */
1531 ipp_attribute_t *allowed, /* requesting-user-name-allowed */
1532 *denied; /* requestint-user-name-denied */
1533 ipp_pstate_t pstate; /* Printer state */
1534 cups_ptype_t ptype; /* Printer type */
1535 time_t ptime; /* Printer state time */
ef416fc2 1536 int jobid; /* Job ID of current job */
ef416fc2 1537 char printer_uri[HTTP_MAX_URI],
1538 /* Printer URI */
1539 printer_state_time[255];/* Printer state time */
f8b3a85b 1540 _cups_globals_t *cg = _cupsGlobals(); /* Global data */
ef416fc2 1541 static const char *pattrs[] = /* Attributes we need for printers... */
1542 {
1543 "printer-name",
1544 "printer-state",
1545 "printer-state-message",
1546 "printer-state-reasons",
1547 "printer-state-change-time",
1548 "printer-type",
1549 "printer-info",
1550 "printer-location",
1551 "printer-make-and-model",
1552 "printer-uri-supported",
1553 "requesting-user-name-allowed",
1554 "requesting-user-name-denied"
1555 };
1556 static const char *jattrs[] = /* Attributes we need for jobs... */
1557 {
7cf5915e
MS
1558 "job-id",
1559 "job-state"
ef416fc2 1560 };
1561
1562
fa73b229 1563 if (printers != NULL && !strcmp(printers, "all"))
ef416fc2 1564 printers = NULL;
1565
1566 /*
1567 * Build a CUPS_GET_PRINTERS request, which requires the following
1568 * attributes:
1569 *
1570 * attributes-charset
1571 * attributes-natural-language
1572 * requested-attributes
fa73b229 1573 * requesting-user-name
ef416fc2 1574 */
1575
1576 request = ippNewRequest(CUPS_GET_PRINTERS);
1577
1578 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1579 "requested-attributes", sizeof(pattrs) / sizeof(pattrs[0]),
1580 NULL, pattrs);
1581
fa73b229 1582 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_NAME, "requesting-user-name",
1583 NULL, cupsUser());
1584
ef416fc2 1585 /*
1586 * Do the request and get back a response...
1587 */
1588
c606bcae
MS
1589 response = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/");
1590
1591 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST ||
1592 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED)
ef416fc2 1593 {
c606bcae
MS
1594 _cupsLangPrintf(stderr,
1595 _("%s: Error - add '/version=1.1' to server name."),
1596 "lpstat");
1597 ippDelete(response);
1598 return (1);
1599 }
1600 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING)
1601 {
1602 _cupsLangPrintf(stderr, "lpstat: %s", cupsLastErrorString());
1603 ippDelete(response);
1604 return (1);
1605 }
ef416fc2 1606
c606bcae
MS
1607 if (response)
1608 {
ef416fc2 1609 /*
1610 * Loop through the printers returned in the list and display
1611 * their status...
1612 */
1613
1614 for (attr = response->attrs; attr != NULL; attr = attr->next)
1615 {
1616 /*
1617 * Skip leading attributes until we hit a job...
1618 */
1619
1620 while (attr != NULL && attr->group_tag != IPP_TAG_PRINTER)
1621 attr = attr->next;
1622
1623 if (attr == NULL)
1624 break;
1625
1626 /*
1627 * Pull the needed attributes from this job...
1628 */
1629
1630 printer = NULL;
1631 ptime = 0;
1632 ptype = CUPS_PRINTER_LOCAL;
1633 pstate = IPP_PRINTER_IDLE;
1634 message = NULL;
1635 description = NULL;
1636 location = NULL;
1637 make_model = NULL;
1638 reasons = NULL;
1639 uri = NULL;
1640 jobid = 0;
1641 allowed = NULL;
1642 denied = NULL;
1643
1644 while (attr != NULL && attr->group_tag == IPP_TAG_PRINTER)
1645 {
1646 if (!strcmp(attr->name, "printer-name") &&
1647 attr->value_tag == IPP_TAG_NAME)
1648 printer = attr->values[0].string.text;
1649 else if (!strcmp(attr->name, "printer-state") &&
1650 attr->value_tag == IPP_TAG_ENUM)
1651 pstate = (ipp_pstate_t)attr->values[0].integer;
1652 else if (!strcmp(attr->name, "printer-type") &&
1653 attr->value_tag == IPP_TAG_ENUM)
1654 ptype = (cups_ptype_t)attr->values[0].integer;
1655 else if (!strcmp(attr->name, "printer-state-message") &&
1656 attr->value_tag == IPP_TAG_TEXT)
1657 message = attr->values[0].string.text;
1658 else if (!strcmp(attr->name, "printer-state-change-time") &&
1659 attr->value_tag == IPP_TAG_INTEGER)
1660 ptime = (time_t)attr->values[0].integer;
1661 else if (!strcmp(attr->name, "printer-info") &&
1662 attr->value_tag == IPP_TAG_TEXT)
1663 description = attr->values[0].string.text;
1664 else if (!strcmp(attr->name, "printer-location") &&
1665 attr->value_tag == IPP_TAG_TEXT)
1666 location = attr->values[0].string.text;
1667 else if (!strcmp(attr->name, "printer-make-and-model") &&
1668 attr->value_tag == IPP_TAG_TEXT)
1669 make_model = attr->values[0].string.text;
1670 else if (!strcmp(attr->name, "printer-uri-supported") &&
1671 attr->value_tag == IPP_TAG_URI)
1672 uri = attr->values[0].string.text;
1673 else if (!strcmp(attr->name, "printer-state-reasons") &&
1674 attr->value_tag == IPP_TAG_KEYWORD)
1675 reasons = attr;
1676 else if (!strcmp(attr->name, "requesting-user-name-allowed") &&
1677 attr->value_tag == IPP_TAG_NAME)
1678 allowed = attr;
1679 else if (!strcmp(attr->name, "requesting-user-name-denied") &&
1680 attr->value_tag == IPP_TAG_NAME)
1681 denied = attr;
1682
1683 attr = attr->next;
1684 }
1685
1686 /*
1687 * See if we have everything needed...
1688 */
1689
1690 if (printer == NULL)
1691 {
1692 if (attr == NULL)
1693 break;
1694 else
1695 continue;
1696 }
1697
ef416fc2 1698 /*
1699 * Display the printer entry if needed...
1700 */
1701
61cf44e2 1702 if (match_list(printers, printer))
ef416fc2 1703 {
1704 /*
1705 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1706 * current job for the printer.
1707 */
1708
1709 if (pstate == IPP_PRINTER_PROCESSING)
1710 {
1711 /*
1712 * Build an IPP_GET_JOBS request, which requires the following
1713 * attributes:
1714 *
1715 * attributes-charset
1716 * attributes-natural-language
1717 * printer-uri
1718 * limit
1719 * requested-attributes
1720 */
1721
1722 request = ippNewRequest(IPP_GET_JOBS);
1723
1724 request->request.op.operation_id = IPP_GET_JOBS;
1725 request->request.op.request_id = 1;
1726
1727 ippAddStrings(request, IPP_TAG_OPERATION, IPP_TAG_KEYWORD,
1728 "requested-attributes",
1729 sizeof(jattrs) / sizeof(jattrs[0]), NULL, jattrs);
1730
a4d04587 1731 httpAssembleURIf(HTTP_URI_CODING_ALL, printer_uri, sizeof(printer_uri),
1732 "ipp", NULL, "localhost", 0, "/printers/%s", printer);
ef416fc2 1733 ippAddString(request, IPP_TAG_OPERATION, IPP_TAG_URI,
1734 "printer-uri", NULL, printer_uri);
1735
61cf44e2 1736 if ((jobs = cupsDoRequest(CUPS_HTTP_DEFAULT, request, "/")) != NULL)
ef416fc2 1737 {
1738 /*
1739 * Get the current active job on this queue...
1740 */
1741
c934a06c 1742 ipp_jstate_t jobstate = IPP_JOB_PENDING;
ef416fc2 1743 jobid = 0;
1744
1745 for (jobattr = jobs->attrs; jobattr; jobattr = jobattr->next)
1746 {
1747 if (!jobattr->name)
c934a06c
MS
1748 {
1749 if (jobstate == IPP_JOB_PROCESSING)
1750 break;
1751 else
1752 continue;
1753 }
ef416fc2 1754
1755 if (!strcmp(jobattr->name, "job-id") &&
1756 jobattr->value_tag == IPP_TAG_INTEGER)
1757 jobid = jobattr->values[0].integer;
1758 else if (!strcmp(jobattr->name, "job-state") &&
c934a06c 1759 jobattr->value_tag == IPP_TAG_ENUM)
7e86f2f6 1760 jobstate = (ipp_jstate_t)jobattr->values[0].integer;
ef416fc2 1761 }
1762
c934a06c
MS
1763 if (jobstate != IPP_JOB_PROCESSING)
1764 jobid = 0;
1765
ef416fc2 1766 ippDelete(jobs);
1767 }
1768 }
1769
1770 /*
1771 * Display it...
1772 */
1773
554aa7b7 1774 _cupsStrDate(printer_state_time, sizeof(printer_state_time), ptime);
ef416fc2 1775
1776 switch (pstate)
1777 {
1778 case IPP_PRINTER_IDLE :
87de8b54
MS
1779 if (ippContainsString(reasons, "hold-new-jobs"))
1780 _cupsLangPrintf(stdout, _("printer %s is holding new jobs. enabled since %s"), printer, printer_state_time);
1781 else
1782 _cupsLangPrintf(stdout, _("printer %s is idle. enabled since %s"), printer, printer_state_time);
ef416fc2 1783 break;
1784 case IPP_PRINTER_PROCESSING :
87de8b54 1785 _cupsLangPrintf(stdout, _("printer %s now printing %s-%d. enabled since %s"), printer, printer, jobid, printer_state_time);
ef416fc2 1786 break;
1787 case IPP_PRINTER_STOPPED :
87de8b54 1788 _cupsLangPrintf(stdout, _("printer %s disabled since %s -"), printer, printer_state_time);
ef416fc2 1789 break;
1790 }
1791
1792 if ((message && *message) || pstate == IPP_PRINTER_STOPPED)
1793 {
baa764fa
AG
1794 if (message && *message)
1795 _cupsLangPrintf(stdout, "\t%s", message);
ef416fc2 1796 else
baa764fa 1797 _cupsLangPuts(stdout, _("\treason unknown"));
ef416fc2 1798 }
1799
1800 if (long_status > 1)
0837b7e8
MS
1801 {
1802 _cupsLangPuts(stdout, _("\tForm mounted:"));
1803 _cupsLangPuts(stdout, _("\tContent types: any"));
1804 _cupsLangPuts(stdout, _("\tPrinter types: unknown"));
1805 }
ef416fc2 1806
1807 if (long_status)
1808 {
0837b7e8 1809 _cupsLangPrintf(stdout, _("\tDescription: %s"),
ef416fc2 1810 description ? description : "");
1811
1812 if (reasons)
1813 {
0837b7e8
MS
1814 char alerts[1024], /* Alerts string */
1815 *aptr; /* Pointer into alerts string */
1816
1817 for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
1818 {
1819 if (i)
7e86f2f6 1820 snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
0837b7e8 1821 else
7e86f2f6 1822 strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
0837b7e8
MS
1823
1824 aptr += strlen(aptr);
1825 }
1826
1827 _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
ef416fc2 1828 }
1829 }
1830 if (long_status > 1)
1831 {
0837b7e8 1832 _cupsLangPrintf(stdout, _("\tLocation: %s"),
ef416fc2 1833 location ? location : "");
1834
1835 if (ptype & CUPS_PRINTER_REMOTE)
1836 {
0837b7e8 1837 _cupsLangPuts(stdout, _("\tConnection: remote"));
ef416fc2 1838
1839 if (make_model && !strstr(make_model, "System V Printer") &&
1840 !strstr(make_model, "Raw Printer") && uri)
0837b7e8 1841 _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"),
ef416fc2 1842 uri);
1843 }
1844 else
1845 {
0837b7e8 1846 _cupsLangPuts(stdout, _("\tConnection: direct"));
ef416fc2 1847
e67e2f9e 1848 if (make_model && !strstr(make_model, "Raw Printer"))
fa73b229 1849 _cupsLangPrintf(stdout,
0837b7e8 1850 _("\tInterface: %s/ppd/%s.ppd"),
f8b3a85b 1851 cg->cups_serverroot, printer);
ef416fc2 1852 }
0837b7e8
MS
1853 _cupsLangPuts(stdout, _("\tOn fault: no alert"));
1854 _cupsLangPuts(stdout, _("\tAfter fault: continue"));
b423cd4c 1855 /* TODO update to use printer-error-policy */
ef416fc2 1856 if (allowed)
1857 {
0837b7e8 1858 _cupsLangPuts(stdout, _("\tUsers allowed:"));
26d47ec6 1859 for (j = 0; j < allowed->num_values; j ++)
0837b7e8 1860 _cupsLangPrintf(stdout, "\t\t%s",
26d47ec6 1861 allowed->values[j].string.text);
ef416fc2 1862 }
1863 else if (denied)
1864 {
0837b7e8 1865 _cupsLangPuts(stdout, _("\tUsers denied:"));
26d47ec6 1866 for (j = 0; j < denied->num_values; j ++)
0837b7e8 1867 _cupsLangPrintf(stdout, "\t\t%s",
26d47ec6 1868 denied->values[j].string.text);
ef416fc2 1869 }
1870 else
1871 {
0837b7e8
MS
1872 _cupsLangPuts(stdout, _("\tUsers allowed:"));
1873 _cupsLangPuts(stdout, _("\t\t(all)"));
ef416fc2 1874 }
0837b7e8
MS
1875 _cupsLangPuts(stdout, _("\tForms allowed:"));
1876 _cupsLangPuts(stdout, _("\t\t(none)"));
1877 _cupsLangPuts(stdout, _("\tBanner required"));
1878 _cupsLangPuts(stdout, _("\tCharset sets:"));
1879 _cupsLangPuts(stdout, _("\t\t(none)"));
1880 _cupsLangPuts(stdout, _("\tDefault pitch:"));
1881 _cupsLangPuts(stdout, _("\tDefault page size:"));
1882 _cupsLangPuts(stdout, _("\tDefault port settings:"));
ef416fc2 1883 }
1884
1885 for (i = 0; i < num_dests; i ++)
88f9aafc 1886 if (!_cups_strcasecmp(printer, dests[i].name) && dests[i].instance)
ef416fc2 1887 {
1888 switch (pstate)
1889 {
1890 case IPP_PRINTER_IDLE :
fa73b229 1891 _cupsLangPrintf(stdout,
ef416fc2 1892 _("printer %s/%s is idle. "
0837b7e8 1893 "enabled since %s"),
ef416fc2 1894 printer, dests[i].instance,
1895 printer_state_time);
1896 break;
1897 case IPP_PRINTER_PROCESSING :
fa73b229 1898 _cupsLangPrintf(stdout,
ef416fc2 1899 _("printer %s/%s now printing %s-%d. "
0837b7e8 1900 "enabled since %s"),
ef416fc2 1901 printer, dests[i].instance, printer, jobid,
1902 printer_state_time);
1903 break;
1904 case IPP_PRINTER_STOPPED :
fa73b229 1905 _cupsLangPrintf(stdout,
0837b7e8 1906 _("printer %s/%s disabled since %s -"),
ef416fc2 1907 printer, dests[i].instance,
1908 printer_state_time);
1909 break;
1910 }
1911
1912 if ((message && *message) || pstate == IPP_PRINTER_STOPPED)
1913 {
baa764fa 1914 if (message && *message)
0837b7e8 1915 _cupsLangPrintf(stdout, "\t%s", message);
baa764fa
AG
1916 else
1917 _cupsLangPuts(stdout, _("\treason unknown"));
ef416fc2 1918 }
1919
1920 if (long_status > 1)
0837b7e8
MS
1921 {
1922 _cupsLangPuts(stdout, _("\tForm mounted:"));
1923 _cupsLangPuts(stdout, _("\tContent types: any"));
1924 _cupsLangPuts(stdout, _("\tPrinter types: unknown"));
1925 }
ef416fc2 1926
1927 if (long_status)
1928 {
0837b7e8 1929 _cupsLangPrintf(stdout, _("\tDescription: %s"),
ef416fc2 1930 description ? description : "");
1931
1932 if (reasons)
1933 {
0837b7e8
MS
1934 char alerts[1024], /* Alerts string */
1935 *aptr; /* Pointer into alerts string */
1936
1937 for (i = 0, aptr = alerts; i < reasons->num_values; i ++)
1938 {
1939 if (i)
7e86f2f6 1940 snprintf(aptr, sizeof(alerts) - (size_t)(aptr - alerts), " %s", reasons->values[i].string.text);
0837b7e8 1941 else
7e86f2f6 1942 strlcpy(alerts, reasons->values[i].string.text, sizeof(alerts));
0837b7e8
MS
1943
1944 aptr += strlen(aptr);
1945 }
1946
1947 _cupsLangPrintf(stdout, _("\tAlerts: %s"), alerts);
ef416fc2 1948 }
1949 }
1950 if (long_status > 1)
1951 {
0837b7e8 1952 _cupsLangPrintf(stdout, _("\tLocation: %s"),
ef416fc2 1953 location ? location : "");
1954
1955 if (ptype & CUPS_PRINTER_REMOTE)
1956 {
0837b7e8 1957 _cupsLangPuts(stdout, _("\tConnection: remote"));
ef416fc2 1958
1959 if (make_model && !strstr(make_model, "System V Printer") &&
1960 !strstr(make_model, "Raw Printer") && uri)
0837b7e8 1961 _cupsLangPrintf(stdout, _("\tInterface: %s.ppd"), uri);
ef416fc2 1962 }
1963 else
1964 {
0837b7e8 1965 _cupsLangPuts(stdout, _("\tConnection: direct"));
ef416fc2 1966
e67e2f9e 1967 if (make_model && !strstr(make_model, "Raw Printer"))
fa73b229 1968 _cupsLangPrintf(stdout,
0837b7e8 1969 _("\tInterface: %s/ppd/%s.ppd"),
f8b3a85b 1970 cg->cups_serverroot, printer);
ef416fc2 1971 }
0837b7e8
MS
1972 _cupsLangPuts(stdout, _("\tOn fault: no alert"));
1973 _cupsLangPuts(stdout, _("\tAfter fault: continue"));
b423cd4c 1974 /* TODO update to use printer-error-policy */
ef416fc2 1975 if (allowed)
1976 {
0837b7e8 1977 _cupsLangPuts(stdout, _("\tUsers allowed:"));
26d47ec6 1978 for (j = 0; j < allowed->num_values; j ++)
0837b7e8 1979 _cupsLangPrintf(stdout, "\t\t%s",
26d47ec6 1980 allowed->values[j].string.text);
ef416fc2 1981 }
1982 else if (denied)
1983 {
0837b7e8 1984 _cupsLangPuts(stdout, _("\tUsers denied:"));
26d47ec6 1985 for (j = 0; j < denied->num_values; j ++)
0837b7e8 1986 _cupsLangPrintf(stdout, "\t\t%s",
26d47ec6 1987 denied->values[j].string.text);
ef416fc2 1988 }
1989 else
1990 {
0837b7e8
MS
1991 _cupsLangPuts(stdout, _("\tUsers allowed:"));
1992 _cupsLangPuts(stdout, _("\t\t(all)"));
ef416fc2 1993 }
0837b7e8
MS
1994 _cupsLangPuts(stdout, _("\tForms allowed:"));
1995 _cupsLangPuts(stdout, _("\t\t(none)"));
1996 _cupsLangPuts(stdout, _("\tBanner required"));
1997 _cupsLangPuts(stdout, _("\tCharset sets:"));
1998 _cupsLangPuts(stdout, _("\t\t(none)"));
1999 _cupsLangPuts(stdout, _("\tDefault pitch:"));
2000 _cupsLangPuts(stdout, _("\tDefault page size:"));
2001 _cupsLangPuts(stdout, _("\tDefault port settings:"));
ef416fc2 2002 }
2003 }
2004 }
2005
2006 if (attr == NULL)
2007 break;
2008 }
2009
2010 ippDelete(response);
2011 }
ef416fc2 2012
2013 return (0);
2014}
2015
2016
2017/*
2018 * 'show_scheduler()' - Show scheduler status.
2019 */
2020
2021static void
61cf44e2 2022show_scheduler(void)
ef416fc2 2023{
61cf44e2
MS
2024 http_t *http; /* Connection to server */
2025
2026
2027 if ((http = httpConnectEncrypt(cupsServer(), ippPort(),
2028 cupsEncryption())) != NULL)
2029 {
0837b7e8 2030 _cupsLangPuts(stdout, _("scheduler is running"));
61cf44e2
MS
2031 httpClose(http);
2032 }
ef416fc2 2033 else
0837b7e8 2034 _cupsLangPuts(stdout, _("scheduler is not running"));
ef416fc2 2035}
8e52928c
MS
2036
2037
2038/*
2039 * 'usage()' - Show program usage and exit.
2040 */
2041
2042static void
2043usage(void)
2044{
2045 _cupsLangPuts(stdout, _("Usage: lpstat [options]"));
2046 _cupsLangPuts(stdout, _("Options:"));
2047 _cupsLangPuts(stdout, _("-E Encrypt the connection to the server"));
2048 _cupsLangPuts(stdout, _("-h server[:port] Connect to the named server and port"));
2049 _cupsLangPuts(stdout, _("-l Show verbose (long) output"));
2050 _cupsLangPuts(stdout, _("-U username Specify the username to use for authentication"));
2051
2052 _cupsLangPuts(stdout, _("-H Show the default server and port"));
2053 _cupsLangPuts(stdout, _("-W completed Show completed jobs"));
2054 _cupsLangPuts(stdout, _("-W not-completed Show pending jobs"));
2055 _cupsLangPuts(stdout, _("-a [destination(s)] Show the accepting state of destinations"));
2056 _cupsLangPuts(stdout, _("-c [class(es)] Show classes and their member printers"));
2057 _cupsLangPuts(stdout, _("-d Show the default destination"));
2058 _cupsLangPuts(stdout, _("-e Show available destinations on the network"));
2059 _cupsLangPuts(stdout, _("-o [destination(s)] Show jobs"));
2060 _cupsLangPuts(stdout, _("-p [printer(s)] Show the processing state of destinations"));
2061 _cupsLangPuts(stdout, _("-r Show whether the CUPS server is running"));
2062 _cupsLangPuts(stdout, _("-R Show the ranking of jobs"));
2063 _cupsLangPuts(stdout, _("-s Show a status summary"));
2064 _cupsLangPuts(stdout, _("-t Show all status information"));
2065 _cupsLangPuts(stdout, _("-u [user(s)] Show jobs queued by the current or specified users"));
2066 _cupsLangPuts(stdout, _("-v [printer(s)] Show the devices for each destination"));
2067
2068 exit(1);
2069}