2 * "lpstat" command for CUPS.
4 * Copyright © 2007-2018 by Apple Inc.
5 * Copyright © 1997-2006 by Easy Software Products.
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
12 * Include necessary headers...
15 #include <cups/cups-private.h>
22 static void check_dest(const char *command
, const char *name
,
23 int *num_dests
, cups_dest_t
**dests
);
24 static int match_list(const char *list
, const char *name
);
25 static int show_accepting(const char *printers
, int num_dests
,
27 static int show_classes(const char *dests
);
28 static void show_default(cups_dest_t
*dest
);
29 static int show_devices(const char *printers
, int num_dests
,
31 static int show_jobs(const char *dests
, const char *users
, int long_status
,
32 int ranking
, const char *which
);
33 static int show_printers(const char *printers
, int num_dests
,
34 cups_dest_t
*dests
, int long_status
);
35 static void show_scheduler(void);
36 static void usage(void) _CUPS_NORETURN
;
40 * 'main()' - Parse options and show status information.
44 main(int argc
, /* I - Number of command-line arguments */
45 char *argv
[]) /* I - Command-line arguments */
47 int i
, /* Looping var */
48 status
; /* Exit status */
49 char *opt
; /* Option pointer */
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 */
61 * Parse command-line options...
69 which
= "not-completed";
72 for (i
= 1; i
< argc
; i
++)
74 if (!strcmp(argv
[i
], "--help"))
76 else if (argv
[i
][0] == '-')
78 for (opt
= argv
[i
] + 1; *opt
; opt
++)
82 case 'D' : /* Show description */
86 case 'E' : /* Encrypt */
88 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
90 _cupsLangPrintf(stderr
,
91 _("%s: Sorry, no encryption support."),
96 case 'H' : /* Show server and port */
97 if (cupsServer()[0] == '/')
98 _cupsLangPuts(stdout
, cupsServer());
100 _cupsLangPrintf(stdout
, "%s:%d", cupsServer(), ippPort());
104 case 'P' : /* Show paper types */
108 case 'R' : /* Show ranking */
112 case 'S' : /* Show charsets */
118 case 'U' : /* Username */
121 cupsSetUser(opt
+ 1);
122 opt
+= strlen(opt
) - 1;
129 _cupsLangPrintf(stderr
, _("%s: Error - expected username after \"-U\" option."), argv
[0]);
133 cupsSetUser(argv
[i
]);
137 case 'W' : /* Show which jobs? */
141 opt
+= strlen(opt
) - 1;
149 _cupsLangPrintf(stderr
, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv
[0]);
156 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") && strcmp(which
, "all"))
158 _cupsLangPrintf(stderr
, _("%s: Error - need \"completed\", \"not-completed\", or \"all\" after \"-W\" option."), argv
[0]);
163 case 'a' : /* Show acceptance status */
168 check_dest(argv
[0], opt
+ 1, &num_dests
, &dests
);
170 status
|= show_accepting(opt
+ 1, num_dests
, dests
);
171 opt
+= strlen(opt
) - 1;
173 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
177 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
179 status
|= show_accepting(argv
[i
], num_dests
, dests
);
185 cupsFreeDests(num_dests
, dests
);
186 num_dests
= cupsGetDests(&dests
);
188 if (num_dests
== 0 && (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
|| cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
190 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
195 status
|= show_accepting(NULL
, num_dests
, dests
);
199 case 'c' : /* Show classes and members */
204 check_dest(argv
[0], opt
+ 1, &num_dests
, &dests
);
206 status
|= show_classes(opt
+ 1);
207 opt
+= strlen(opt
) - 1;
209 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
213 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
215 status
|= show_classes(argv
[i
]);
218 status
|= show_classes(NULL
);
221 case 'd' : /* Show default destination */
224 if (num_dests
!= 1 || !dests
[0].is_default
)
226 cupsFreeDests(num_dests
, dests
);
228 dests
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
229 num_dests
= dests
? 1 : 0;
231 if (num_dests
== 0 &&
232 (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
233 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
235 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
243 case 'e' : /* List destinations */
245 cups_dest_t
*temp
= NULL
, *dest
;
246 int j
, num_temp
= cupsGetDests(&temp
);
250 for (j
= num_temp
, dest
= temp
; j
> 0; j
--, dest
++)
253 printf("%s/%s", dest
->name
, dest
->instance
);
255 fputs(dest
->name
, stdout
);
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";
263 if (printer_is_temporary
&& !strcmp(printer_is_temporary
, "true"))
265 else if (printer_uri_supported
)
268 printf(" %s %s %s\n", type
, printer_uri_supported
? printer_uri_supported
: "none", cupsGetOption("device-uri", dest
->num_options
, dest
->options
));
274 cupsFreeDests(num_temp
, temp
);
278 case 'f' : /* Show forms */
282 opt
+= strlen(opt
) - 1;
292 case 'h' : /* Connect to host */
295 cupsSetServer(opt
+ 1);
296 opt
+= strlen(opt
) - 1;
304 _cupsLangPrintf(stderr
, _("%s: Error - expected hostname after \"-h\" option."), argv
[0]);
308 cupsSetServer(argv
[i
]);
312 case 'l' : /* Long status or long job status */
316 case 'o' : /* Show jobs by destination */
321 check_dest(argv
[0], opt
+ 1, &num_dests
, &dests
);
323 status
|= show_jobs(opt
+ 1, NULL
, long_status
, ranking
, which
);
324 opt
+= strlen(opt
) - 1;
326 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
330 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
332 status
|= show_jobs(argv
[i
], NULL
, long_status
, ranking
, which
);
335 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
338 case 'p' : /* Show printers */
343 check_dest(argv
[0], opt
+ 1, &num_dests
, &dests
);
345 status
|= show_printers(opt
+ 1, num_dests
, dests
,
347 opt
+= strlen(opt
) - 1;
349 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
353 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
355 status
|= show_printers(argv
[i
], num_dests
, dests
, long_status
);
361 cupsFreeDests(num_dests
, dests
);
362 num_dests
= cupsGetDests(&dests
);
364 if (num_dests
== 0 &&
365 (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
366 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
368 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
373 status
|= show_printers(NULL
, num_dests
, dests
, long_status
);
377 case 'r' : /* Show scheduler status */
383 case 's' : /* Show summary */
388 cupsFreeDests(num_dests
, dests
);
389 num_dests
= cupsGetDests(&dests
);
391 if (num_dests
== 0 &&
392 (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
393 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
395 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
400 show_default(cupsGetDest(NULL
, NULL
, num_dests
, dests
));
401 status
|= show_classes(NULL
);
402 status
|= show_devices(NULL
, num_dests
, dests
);
405 case 't' : /* Show all info */
410 cupsFreeDests(num_dests
, dests
);
411 num_dests
= cupsGetDests(&dests
);
413 if (num_dests
== 0 &&
414 (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
415 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
417 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
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
);
427 status
|= show_printers(NULL
, num_dests
, dests
, long_status
);
428 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
431 case 'u' : /* Show jobs by user */
436 status
|= show_jobs(NULL
, opt
+ 1, long_status
, ranking
, which
);
437 opt
+= strlen(opt
) - 1;
439 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
442 status
|= show_jobs(NULL
, argv
[i
], long_status
, ranking
, which
);
445 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
448 case 'v' : /* Show printer devices */
453 check_dest(argv
[0], opt
+ 1, &num_dests
, &dests
);
455 status
|= show_devices(opt
+ 1, num_dests
, dests
);
456 opt
+= strlen(opt
) - 1;
458 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
462 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
464 status
|= show_devices(argv
[i
], num_dests
, dests
);
470 cupsFreeDests(num_dests
, dests
);
471 num_dests
= cupsGetDests(&dests
);
473 if (num_dests
== 0 &&
474 (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
475 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
))
477 _cupsLangPrintf(stderr
, _("%s: Error - add '/version=1.1' to server name."), argv
[0]);
482 status
|= show_devices(NULL
, num_dests
, dests
);
487 _cupsLangPrintf(stderr
, _("%s: Error - unknown option \"%c\"."), argv
[0], argv
[i
][1]);
494 status
|= show_jobs(argv
[i
], NULL
, long_status
, ranking
, which
);
500 status
|= show_jobs(NULL
, cupsUser(), long_status
, ranking
, which
);
507 * 'check_dest()' - Verify that the named destination(s) exists.
511 check_dest(const char *command
, /* I - Command name */
512 const char *name
, /* I - List of printer/class names */
513 int *num_dests
, /* IO - Number of destinations */
514 cups_dest_t
**dests
) /* IO - Destinations */
516 const char *dptr
; /* Pointer into name */
517 char *pptr
, /* Pointer into printer */
518 printer
[1024]; /* Current printer/class name */
522 * Load the destination list as necessary...
528 cupsFreeDests(*num_dests
, *dests
);
530 if (strchr(name
, ','))
531 *num_dests
= cupsGetDests(dests
);
534 strlcpy(printer
, name
, sizeof(printer
));
535 if ((pptr
= strchr(printer
, '/')) != NULL
)
538 if ((*dests
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, printer
, pptr
)) == NULL
)
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."),
546 _cupsLangPrintf(stderr
,
547 _("%s: Invalid destination name in list \"%s\"."),
561 * Scan the name string for printer/class name(s)...
564 for (dptr
= name
; *dptr
;)
567 * Skip leading whitespace and commas...
570 while (isspace(*dptr
& 255) || *dptr
== ',')
577 * Extract a single destination name from the name string...
580 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
;)
582 if ((size_t)(pptr
- printer
) < (sizeof(printer
) - 1))
586 _cupsLangPrintf(stderr
,
587 _("%s: Invalid destination name in list \"%s\"."),
596 * Check the destination...
599 if (!cupsGetDest(printer
, NULL
, *num_dests
, *dests
))
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."),
607 _cupsLangPrintf(stderr
,
608 _("%s: Unknown destination \"%s\"."), command
, printer
);
617 * 'match_list()' - Match a name from a list of comma or space-separated names.
620 static int /* O - 1 on match, 0 on no match */
621 match_list(const char *list
, /* I - List of names */
622 const char *name
) /* I - Name to find */
624 const char *nameptr
; /* Pointer into name */
628 * An empty list always matches...
640 * Skip leading whitespace and commas...
643 while (isspace(*list
& 255) || *list
== ',')
654 *nameptr
&& *list
&& tolower(*nameptr
& 255) == tolower(*list
& 255);
655 nameptr
++, list
++);
657 if (!*nameptr
&& (!*list
|| *list
== ',' || isspace(*list
& 255)))
660 while (*list
&& !isspace(*list
& 255) && *list
!= ',')
670 * 'show_accepting()' - Show acceptance status.
673 static int /* O - 0 on success, 1 on fail */
674 show_accepting(const char *printers
, /* I - Destinations */
675 int num_dests
, /* I - Number of user-defined dests */
676 cups_dest_t
*dests
) /* I - User-defined destinations */
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? */
685 time_t ptime
; /* Printer state time */
686 char printer_state_time
[255];/* Printer state time */
687 static const char *pattrs
[] = /* Attributes we need for printers... */
690 "printer-state-change-time",
691 "printer-state-message",
692 "printer-is-accepting-jobs"
696 if (printers
!= NULL
&& !strcmp(printers
, "all"))
700 * Build a CUPS_GET_PRINTERS request, which requires the following
704 * attributes-natural-language
705 * requested-attributes
706 * requesting-user-name
709 request
= ippNewRequest(CUPS_GET_PRINTERS
);
711 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
712 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
715 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
719 * Do the request and get back a response...
722 response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/");
724 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
725 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
727 _cupsLangPrintf(stderr
,
728 _("%s: Error - add '/version=1.1' to server name."),
733 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING
)
735 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
743 * Loop through the printers returned in the list and display
747 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
750 * Skip leading attributes until we hit a printer...
753 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
760 * Pull the needed attributes from this printer...
768 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
770 if (!strcmp(attr
->name
, "printer-name") &&
771 attr
->value_tag
== IPP_TAG_NAME
)
772 printer
= attr
->values
[0].string
.text
;
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
)
778 message
= attr
->values
[0].string
.text
;
779 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
780 attr
->value_tag
== IPP_TAG_BOOLEAN
)
781 accepting
= attr
->values
[0].boolean
;
787 * See if we have everything needed...
799 * Display the printer entry if needed...
802 if (match_list(printers
, printer
))
804 _cupsStrDate(printer_state_time
, sizeof(printer_state_time
), ptime
);
807 _cupsLangPrintf(stdout
, _("%s accepting requests since %s"),
808 printer
, printer_state_time
);
811 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -"),
812 printer
, printer_state_time
);
813 _cupsLangPrintf(stdout
, _("\t%s"),
814 (message
&& *message
) ?
815 message
: "reason unknown");
818 for (i
= 0; i
< num_dests
; i
++)
819 if (!_cups_strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
822 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s"),
823 printer
, dests
[i
].instance
, printer_state_time
);
826 _cupsLangPrintf(stdout
,
827 _("%s/%s not accepting requests since %s -"),
828 printer
, dests
[i
].instance
, printer_state_time
);
829 _cupsLangPrintf(stdout
, _("\t%s"),
830 (message
&& *message
) ?
831 message
: "reason unknown");
848 * 'show_classes()' - Show printer classes.
851 static int /* O - 0 on success, 1 on fail */
852 show_classes(const char *dests
) /* I - Destinations */
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 */
868 static const char *cattrs
[] = /* Attributes we need for classes... */
871 "printer-uri-supported",
876 if (dests
!= NULL
&& !strcmp(dests
, "all"))
880 * Build a CUPS_GET_CLASSES request, which requires the following
884 * attributes-natural-language
885 * requested-attributes
886 * requesting-user-name
889 request
= ippNewRequest(CUPS_GET_CLASSES
);
891 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
892 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
895 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
899 * Do the request and get back a response...
902 response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/");
904 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
905 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
907 _cupsLangPrintf(stderr
,
908 _("%s: Error - add '/version=1.1' to server name."),
913 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING
)
915 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
922 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
924 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
930 * Loop through the printers returned in the list and display
934 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
937 * Skip leading attributes until we hit a job...
940 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
947 * Pull the needed attributes from this job...
956 if (!strcmp(attr
->name
, "printer-name") &&
957 attr
->value_tag
== IPP_TAG_NAME
)
958 printer
= attr
->values
[0].string
.text
;
960 if (!strcmp(attr
->name
, "printer-uri-supported") &&
961 attr
->value_tag
== IPP_TAG_URI
)
962 printer_uri
= attr
->values
[0].string
.text
;
964 if (!strcmp(attr
->name
, "member-names") &&
965 attr
->value_tag
== IPP_TAG_NAME
)
970 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
);
973 * If this is a remote class, grab the class info from the
978 if (members
== NULL
&& printer_uri
!= NULL
)
980 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
981 username
, sizeof(username
), server
, sizeof(server
),
982 &port
, resource
, sizeof(resource
));
984 if (!_cups_strcasecmp(server
, cupsServer()))
985 http2
= CUPS_HTTP_DEFAULT
;
987 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
990 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
991 * following attributes:
994 * attributes-natural-language
996 * requested-attributes
999 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
1001 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1002 "printer-uri", NULL
, printer_uri
);
1004 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1005 "requested-attributes",
1006 sizeof(cattrs
) / sizeof(cattrs
[0]),
1009 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
1010 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
1017 * See if we have everything needed...
1020 if (printer
== NULL
)
1023 ippDelete(response2
);
1032 * Display the printer entry if needed...
1035 if (match_list(dests
, printer
))
1037 _cupsLangPrintf(stdout
, _("members of class %s:"), printer
);
1041 for (i
= 0; i
< members
->num_values
; i
++)
1042 _cupsLangPrintf(stdout
, "\t%s", members
->values
[i
].string
.text
);
1045 _cupsLangPuts(stdout
, "\tunknown");
1049 ippDelete(response2
);
1055 ippDelete(response
);
1063 * 'show_default()' - Show default destination.
1067 show_default(cups_dest_t
*dest
) /* I - Default destination */
1069 const char *printer
, /* Printer name */
1070 *val
; /* Environment variable name */
1076 _cupsLangPrintf(stdout
, _("system default destination: %s/%s"),
1077 dest
->name
, dest
->instance
);
1079 _cupsLangPrintf(stdout
, _("system default destination: %s"),
1086 if ((printer
= getenv("LPDEST")) == NULL
)
1088 if ((printer
= getenv("PRINTER")) != NULL
)
1090 if (!strcmp(printer
, "lp"))
1100 _cupsLangPrintf(stdout
,
1101 _("lpstat: error - %s environment variable names "
1102 "non-existent destination \"%s\"."),
1105 _cupsLangPuts(stdout
, _("no system default destination"));
1111 * 'show_devices()' - Show printer devices.
1114 static int /* O - 0 on success, 1 on fail */
1115 show_devices(const char *printers
, /* I - Destinations */
1116 int num_dests
, /* I - Number of user-defined dests */
1117 cups_dest_t
*dests
) /* I - User-defined destinations */
1119 int i
; /* Looping var */
1120 ipp_t
*request
, /* IPP Request */
1121 *response
; /* IPP Response */
1122 ipp_attribute_t
*attr
; /* Current attribute */
1123 const char *printer
, /* Printer name */
1124 *uri
, /* Printer URI */
1125 *device
; /* Printer device URI */
1126 static const char *pattrs
[] = /* Attributes we need for printers... */
1129 "printer-uri-supported",
1134 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1138 * Build a CUPS_GET_PRINTERS request, which requires the following
1141 * attributes-charset
1142 * attributes-natural-language
1143 * requested-attributes
1144 * requesting-user-name
1147 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1149 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1150 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1153 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1157 * Do the request and get back a response...
1160 response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/");
1162 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
1163 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
1165 _cupsLangPrintf(stderr
,
1166 _("%s: Error - add '/version=1.1' to server name."),
1168 ippDelete(response
);
1171 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING
)
1173 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1174 ippDelete(response
);
1181 * Loop through the printers returned in the list and display
1185 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1188 * Skip leading attributes until we hit a job...
1191 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1198 * Pull the needed attributes from this job...
1205 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1207 if (!strcmp(attr
->name
, "printer-name") &&
1208 attr
->value_tag
== IPP_TAG_NAME
)
1209 printer
= attr
->values
[0].string
.text
;
1211 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1212 attr
->value_tag
== IPP_TAG_URI
)
1213 uri
= attr
->values
[0].string
.text
;
1215 if (!strcmp(attr
->name
, "device-uri") &&
1216 attr
->value_tag
== IPP_TAG_URI
)
1217 device
= attr
->values
[0].string
.text
;
1223 * See if we have everything needed...
1226 if (printer
== NULL
)
1235 * Display the printer entry if needed...
1238 if (match_list(printers
, printer
))
1241 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1243 else if (!strncmp(device
, "file:", 5))
1244 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1245 printer
, device
+ 5);
1247 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1250 for (i
= 0; i
< num_dests
; i
++)
1252 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1255 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1256 printer
, dests
[i
].instance
, uri
);
1257 else if (!strncmp(device
, "file:", 5))
1258 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1259 printer
, dests
[i
].instance
, device
+ 5);
1261 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1262 printer
, dests
[i
].instance
, device
);
1271 ippDelete(response
);
1279 * 'show_jobs()' - Show active print jobs.
1282 static int /* O - 0 on success, 1 on fail */
1283 show_jobs(const char *dests
, /* I - Destinations */
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? */
1289 int i
; /* Looping var */
1290 ipp_t
*request
, /* IPP Request */
1291 *response
; /* IPP Response */
1292 ipp_attribute_t
*attr
, /* Current attribute */
1293 *reasons
; /* Job state reasons attribute */
1294 const char *dest
, /* Pointer into job-printer-uri */
1295 *username
, /* Pointer to job-originating-user-name */
1296 *message
, /* Pointer to job-printer-state-message */
1297 *time_at
; /* time-at-xxx attribute name to use */
1298 int rank
, /* Rank in queue */
1300 size
; /* job-k-octets */
1301 time_t jobtime
; /* time-at-creation */
1302 char temp
[255], /* Temporary buffer */
1303 date
[255]; /* Date buffer */
1304 static const char *jattrs
[] = /* Attributes we need for jobs... */
1309 "job-originating-user-name",
1310 "job-printer-state-message",
1312 "job-state-reasons",
1318 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1322 * Build a IPP_GET_JOBS request, which requires the following
1325 * attributes-charset
1326 * attributes-natural-language
1328 * requested-attributes
1329 * requesting-user-name
1333 request
= ippNewRequest(IPP_GET_JOBS
);
1335 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1336 NULL
, "ipp://localhost/");
1338 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1339 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1342 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1345 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1349 * Do the request and get back a response...
1352 response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/");
1354 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
1355 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
1357 _cupsLangPrintf(stderr
,
1358 _("%s: Error - add '/version=1.1' to server name."),
1360 ippDelete(response
);
1363 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING
)
1365 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1366 ippDelete(response
);
1373 * Loop through the job list and display them...
1376 if (!strcmp(which
, "aborted") ||
1377 !strcmp(which
, "canceled") ||
1378 !strcmp(which
, "completed"))
1379 time_at
= "time-at-completed";
1381 time_at
= "time-at-creation";
1385 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1388 * Skip leading attributes until we hit a job...
1391 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1398 * Pull the needed attributes from this job...
1409 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1411 if (!strcmp(attr
->name
, "job-id") &&
1412 attr
->value_tag
== IPP_TAG_INTEGER
)
1413 jobid
= attr
->values
[0].integer
;
1414 else if (!strcmp(attr
->name
, "job-k-octets") &&
1415 attr
->value_tag
== IPP_TAG_INTEGER
)
1416 size
= attr
->values
[0].integer
;
1417 else if (!strcmp(attr
->name
, time_at
) && attr
->value_tag
== IPP_TAG_INTEGER
)
1418 jobtime
= attr
->values
[0].integer
;
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
)
1425 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1428 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
1429 attr
->value_tag
== IPP_TAG_NAME
)
1430 username
= attr
->values
[0].string
.text
;
1431 else if (!strcmp(attr
->name
, "job-state-reasons") &&
1432 attr
->value_tag
== IPP_TAG_KEYWORD
)
1439 * See if we have everything needed...
1442 if (dest
== NULL
|| jobid
== 0)
1451 * Display the job...
1456 if (match_list(dests
, dest
) && match_list(users
, username
))
1458 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1460 _cupsStrDate(date
, sizeof(date
), jobtime
);
1463 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s",
1464 rank
, temp
, username
? username
: "unknown",
1465 1024.0 * size
, date
);
1467 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s",
1468 temp
, username
? username
: "unknown",
1469 1024.0 * size
, date
);
1473 _cupsLangPrintf(stdout
, _("\tStatus: %s"), message
);
1477 char alerts
[1024], /* Alerts string */
1478 *aptr
; /* Pointer into alerts string */
1480 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1483 snprintf(aptr
, sizeof(alerts
) - (size_t)(aptr
- alerts
), " %s", reasons
->values
[i
].string
.text
);
1485 strlcpy(alerts
, reasons
->values
[i
].string
.text
, sizeof(alerts
));
1487 aptr
+= strlen(aptr
);
1490 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1493 _cupsLangPrintf(stdout
, _("\tqueued for %s"), dest
);
1501 ippDelete(response
);
1509 * 'show_printers()' - Show printers.
1512 static int /* O - 0 on success, 1 on fail */
1513 show_printers(const char *printers
, /* I - Destinations */
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? */
1518 int i
, j
; /* Looping vars */
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 */
1536 int jobid
; /* Job ID of current job */
1537 char printer_uri
[HTTP_MAX_URI
],
1539 printer_state_time
[255];/* Printer state time */
1540 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
1541 static const char *pattrs
[] = /* Attributes we need for printers... */
1545 "printer-state-message",
1546 "printer-state-reasons",
1547 "printer-state-change-time",
1551 "printer-make-and-model",
1552 "printer-uri-supported",
1553 "requesting-user-name-allowed",
1554 "requesting-user-name-denied"
1556 static const char *jattrs
[] = /* Attributes we need for jobs... */
1563 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1567 * Build a CUPS_GET_PRINTERS request, which requires the following
1570 * attributes-charset
1571 * attributes-natural-language
1572 * requested-attributes
1573 * requesting-user-name
1576 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1578 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1579 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1582 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1586 * Do the request and get back a response...
1589 response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/");
1591 if (cupsLastError() == IPP_STATUS_ERROR_BAD_REQUEST
||
1592 cupsLastError() == IPP_STATUS_ERROR_VERSION_NOT_SUPPORTED
)
1594 _cupsLangPrintf(stderr
,
1595 _("%s: Error - add '/version=1.1' to server name."),
1597 ippDelete(response
);
1600 else if (cupsLastError() > IPP_STATUS_OK_CONFLICTING
)
1602 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1603 ippDelete(response
);
1610 * Loop through the printers returned in the list and display
1614 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1617 * Skip leading attributes until we hit a job...
1620 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1627 * Pull the needed attributes from this job...
1632 ptype
= CUPS_PRINTER_LOCAL
;
1633 pstate
= IPP_PRINTER_IDLE
;
1644 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
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
)
1676 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1677 attr
->value_tag
== IPP_TAG_NAME
)
1679 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1680 attr
->value_tag
== IPP_TAG_NAME
)
1687 * See if we have everything needed...
1690 if (printer
== NULL
)
1699 * Display the printer entry if needed...
1702 if (match_list(printers
, printer
))
1705 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1706 * current job for the printer.
1709 if (pstate
== IPP_PRINTER_PROCESSING
)
1712 * Build an IPP_GET_JOBS request, which requires the following
1715 * attributes-charset
1716 * attributes-natural-language
1719 * requested-attributes
1722 request
= ippNewRequest(IPP_GET_JOBS
);
1724 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1725 request
->request
.op
.request_id
= 1;
1727 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1728 "requested-attributes",
1729 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1731 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1732 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1733 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1734 "printer-uri", NULL
, printer_uri
);
1736 if ((jobs
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1739 * Get the current active job on this queue...
1742 ipp_jstate_t jobstate
= IPP_JOB_PENDING
;
1745 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1749 if (jobstate
== IPP_JOB_PROCESSING
)
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") &&
1759 jobattr
->value_tag
== IPP_TAG_ENUM
)
1760 jobstate
= (ipp_jstate_t
)jobattr
->values
[0].integer
;
1763 if (jobstate
!= IPP_JOB_PROCESSING
)
1774 _cupsStrDate(printer_state_time
, sizeof(printer_state_time
), ptime
);
1778 case IPP_PRINTER_IDLE
:
1779 if (ippContainsString(reasons
, "hold-new-jobs"))
1780 _cupsLangPrintf(stdout
, _("printer %s is holding new jobs. enabled since %s"), printer
, printer_state_time
);
1782 _cupsLangPrintf(stdout
, _("printer %s is idle. enabled since %s"), printer
, printer_state_time
);
1784 case IPP_PRINTER_PROCESSING
:
1785 _cupsLangPrintf(stdout
, _("printer %s now printing %s-%d. enabled since %s"), printer
, printer
, jobid
, printer_state_time
);
1787 case IPP_PRINTER_STOPPED
:
1788 _cupsLangPrintf(stdout
, _("printer %s disabled since %s -"), printer
, printer_state_time
);
1792 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1794 if (message
&& *message
)
1795 _cupsLangPrintf(stdout
, "\t%s", message
);
1797 _cupsLangPuts(stdout
, _("\treason unknown"));
1800 if (long_status
> 1)
1802 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1803 _cupsLangPuts(stdout
, _("\tContent types: any"));
1804 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1809 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1810 description
? description
: "");
1814 char alerts
[1024], /* Alerts string */
1815 *aptr
; /* Pointer into alerts string */
1817 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1820 snprintf(aptr
, sizeof(alerts
) - (size_t)(aptr
- alerts
), " %s", reasons
->values
[i
].string
.text
);
1822 strlcpy(alerts
, reasons
->values
[i
].string
.text
, sizeof(alerts
));
1824 aptr
+= strlen(aptr
);
1827 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1830 if (long_status
> 1)
1832 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1833 location
? location
: "");
1835 if (ptype
& CUPS_PRINTER_REMOTE
)
1837 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1839 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1840 !strstr(make_model
, "Raw Printer") && uri
)
1841 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"),
1846 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1848 if (make_model
&& !strstr(make_model
, "Raw Printer"))
1849 _cupsLangPrintf(stdout
,
1850 _("\tInterface: %s/ppd/%s.ppd"),
1851 cg
->cups_serverroot
, printer
);
1853 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1854 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1855 /* TODO update to use printer-error-policy */
1858 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1859 for (j
= 0; j
< allowed
->num_values
; j
++)
1860 _cupsLangPrintf(stdout
, "\t\t%s",
1861 allowed
->values
[j
].string
.text
);
1865 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1866 for (j
= 0; j
< denied
->num_values
; j
++)
1867 _cupsLangPrintf(stdout
, "\t\t%s",
1868 denied
->values
[j
].string
.text
);
1872 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1873 _cupsLangPuts(stdout
, _("\t\t(all)"));
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:"));
1885 for (i
= 0; i
< num_dests
; i
++)
1886 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1890 case IPP_PRINTER_IDLE
:
1891 _cupsLangPrintf(stdout
,
1892 _("printer %s/%s is idle. "
1893 "enabled since %s"),
1894 printer
, dests
[i
].instance
,
1895 printer_state_time
);
1897 case IPP_PRINTER_PROCESSING
:
1898 _cupsLangPrintf(stdout
,
1899 _("printer %s/%s now printing %s-%d. "
1900 "enabled since %s"),
1901 printer
, dests
[i
].instance
, printer
, jobid
,
1902 printer_state_time
);
1904 case IPP_PRINTER_STOPPED
:
1905 _cupsLangPrintf(stdout
,
1906 _("printer %s/%s disabled since %s -"),
1907 printer
, dests
[i
].instance
,
1908 printer_state_time
);
1912 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1914 if (message
&& *message
)
1915 _cupsLangPrintf(stdout
, "\t%s", message
);
1917 _cupsLangPuts(stdout
, _("\treason unknown"));
1920 if (long_status
> 1)
1922 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1923 _cupsLangPuts(stdout
, _("\tContent types: any"));
1924 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1929 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1930 description
? description
: "");
1934 char alerts
[1024], /* Alerts string */
1935 *aptr
; /* Pointer into alerts string */
1937 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1940 snprintf(aptr
, sizeof(alerts
) - (size_t)(aptr
- alerts
), " %s", reasons
->values
[i
].string
.text
);
1942 strlcpy(alerts
, reasons
->values
[i
].string
.text
, sizeof(alerts
));
1944 aptr
+= strlen(aptr
);
1947 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1950 if (long_status
> 1)
1952 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1953 location
? location
: "");
1955 if (ptype
& CUPS_PRINTER_REMOTE
)
1957 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1959 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1960 !strstr(make_model
, "Raw Printer") && uri
)
1961 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"), uri
);
1965 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1967 if (make_model
&& !strstr(make_model
, "Raw Printer"))
1968 _cupsLangPrintf(stdout
,
1969 _("\tInterface: %s/ppd/%s.ppd"),
1970 cg
->cups_serverroot
, printer
);
1972 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1973 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1974 /* TODO update to use printer-error-policy */
1977 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1978 for (j
= 0; j
< allowed
->num_values
; j
++)
1979 _cupsLangPrintf(stdout
, "\t\t%s",
1980 allowed
->values
[j
].string
.text
);
1984 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1985 for (j
= 0; j
< denied
->num_values
; j
++)
1986 _cupsLangPrintf(stdout
, "\t\t%s",
1987 denied
->values
[j
].string
.text
);
1991 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1992 _cupsLangPuts(stdout
, _("\t\t(all)"));
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:"));
2010 ippDelete(response
);
2018 * 'show_scheduler()' - Show scheduler status.
2022 show_scheduler(void)
2024 http_t
*http
; /* Connection to server */
2027 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
2028 cupsEncryption())) != NULL
)
2030 _cupsLangPuts(stdout
, _("scheduler is running"));
2034 _cupsLangPuts(stdout
, _("scheduler is not running"));
2039 * 'usage()' - Show program usage and exit.
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"));
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"));