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