2 * "$Id: lpstat.c 5638 2006-06-06 20:08:13Z mike $"
4 * "lpstat" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and show status information.
27 * check_dest() - Verify that the named destination(s) exists.
28 * connect_server() - Connect to the server as necessary...
29 * show_accepting() - Show acceptance status.
30 * show_classes() - Show printer classes.
31 * show_default() - Show default destination.
32 * show_devices() - Show printer devices.
33 * show_jobs() - Show active print jobs.
34 * show_printers() - Show printers.
35 * show_scheduler() - Show scheduler status.
39 * Include necessary headers...
45 #include <cups/string.h>
46 #include <cups/cups.h>
47 #include <cups/i18n.h>
48 #include <cups/debug.h>
55 static void check_dest(const char *, http_t
*, const char *, int *,
57 static http_t
*connect_server(const char *, http_t
*);
58 static int show_accepting(http_t
*, const char *, int, cups_dest_t
*);
59 static int show_classes(http_t
*, const char *);
60 static void show_default(int, cups_dest_t
*);
61 static int show_devices(http_t
*, const char *, int, cups_dest_t
*);
62 static int show_jobs(http_t
*, const char *, const char *, int, int,
64 static int show_printers(http_t
*, const char *, int, cups_dest_t
*, int);
65 static void show_scheduler(http_t
*);
69 * 'main()' - Parse options and show status information.
73 main(int argc
, /* I - Number of command-line arguments */
74 char *argv
[]) /* I - Command-line arguments */
76 int i
, /* Looping var */
77 status
; /* Exit status */
78 http_t
*http
; /* Connection to server */
79 int num_dests
; /* Number of user destinations */
80 cups_dest_t
*dests
; /* User destinations */
81 int long_status
; /* Long status report? */
82 int ranking
; /* Show job ranking? */
83 const char *which
; /* Which jobs to show? */
84 char op
; /* Last operation on command-line */
88 * Set the locale so that times, etc. are displayed properly.
90 * Unfortunately, while we need the localized time value, we *don't*
91 * want to use the localized charset for the time value, so we need
92 * to set LC_TIME to the locale name with .UTF-8 on the end (if
93 * the locale includes a character set specifier...)
96 setlocale(LC_ALL
, "");
100 const char *lc_time
; /* Current LC_TIME value */
101 char new_lc_time
[255], /* New LC_TIME value */
102 *charset
; /* Pointer to character set */
104 if ((lc_time
= setlocale(LC_TIME
, NULL
)) == NULL
)
105 lc_time
= setlocale(LC_ALL
, NULL
);
109 strlcpy(new_lc_time
, lc_time
, sizeof(new_lc_time
));
110 if ((charset
= strchr(new_lc_time
, '.')) == NULL
)
111 charset
= new_lc_time
+ strlen(new_lc_time
);
113 strlcpy(charset
, ".UTF-8", sizeof(new_lc_time
) - (charset
- new_lc_time
));
116 strcpy(new_lc_time
, "C");
118 setlocale(LC_TIME
, new_lc_time
);
123 * Parse command-line options...
132 which
= "not-completed";
135 for (i
= 1; i
< argc
; i
++)
136 if (argv
[i
][0] == '-')
139 case 'D' : /* Show description */
143 case 'E' : /* Encrypt */
145 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
148 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
150 _cupsLangPrintf(stderr
,
151 _("%s: Sorry, no encryption support compiled in!\n"),
153 #endif /* HAVE_SSL */
156 case 'P' : /* Show paper types */
160 case 'R' : /* Show ranking */
164 case 'S' : /* Show charsets */
170 case 'U' : /* Username */
171 if (argv
[i
][2] != '\0')
172 cupsSetUser(argv
[i
] + 2);
178 _cupsLangPrintf(stderr
,
179 _("%s: Error - expected username after "
185 cupsSetUser(argv
[i
]);
189 case 'W' : /* Show which jobs? */
198 _cupsLangPrintf(stderr
,
199 _("%s: Error - need \"completed\", "
200 "\"not-completed\", or \"all\" after "
209 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
210 strcmp(which
, "all"))
212 _cupsLangPrintf(stderr
,
213 _("%s: Error - need \"completed\", "
214 "\"not-completed\", or \"all\" after "
221 case 'a' : /* Show acceptance status */
223 http
= connect_server(argv
[0], http
);
225 if (argv
[i
][2] != '\0')
227 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
229 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
231 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
235 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
237 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
242 num_dests
= cupsGetDests2(http
, &dests
);
244 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
249 case 'b' : /* Show both the local and remote status */
251 http
= connect_server(argv
[0], http
);
253 if (argv
[i
][2] != '\0')
256 * The local and remote status are separated by a blank line;
257 * since all CUPS jobs are networked, we only output the
258 * second list for now... In the future, we might further
259 * emulate this by listing the remote server's queue, but
260 * for now this is enough to make the SGI printstatus program
264 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
267 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
271 _cupsLangPrintf(stderr
,
272 _("%s: Error - expected destination after "
281 case 'c' : /* Show classes and members */
283 http
= connect_server(argv
[0], http
);
285 if (argv
[i
][2] != '\0')
287 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
289 status
|= show_classes(http
, argv
[i
] + 2);
291 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
295 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
297 status
|= show_classes(http
, argv
[i
]);
300 status
|= show_classes(http
, NULL
);
303 case 'd' : /* Show default destination */
305 http
= connect_server(argv
[0], http
);
308 num_dests
= cupsGetDests2(http
, &dests
);
310 show_default(num_dests
, dests
);
313 case 'f' : /* Show forms */
319 case 'h' : /* Connect to host */
326 if (argv
[i
][2] != '\0')
327 cupsSetServer(argv
[i
] + 2);
334 _cupsLangPrintf(stderr
,
335 _("%s: Error - expected hostname after "
341 cupsSetServer(argv
[i
]);
345 case 'l' : /* Long status or long job status */
348 http
= connect_server(argv
[0], http
);
350 if (argv
[i
][2] != '\0')
352 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
354 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
361 case 'o' : /* Show jobs by destination */
363 http
= connect_server(argv
[0], http
);
365 if (argv
[i
][2] != '\0')
367 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
369 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
372 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
376 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
378 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
382 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
386 case 'p' : /* Show printers */
388 http
= connect_server(argv
[0], http
);
390 if (argv
[i
][2] != '\0')
392 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
394 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
396 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
400 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
402 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
407 num_dests
= cupsGetDests2(http
, &dests
);
409 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
413 case 'r' : /* Show scheduler status */
415 http
= connect_server(argv
[0], http
);
417 show_scheduler(http
);
420 case 's' : /* Show summary */
422 http
= connect_server(argv
[0], http
);
425 num_dests
= cupsGetDests2(http
, &dests
);
427 show_default(num_dests
, dests
);
428 status
|= show_classes(http
, NULL
);
429 status
|= show_devices(http
, NULL
, num_dests
, dests
);
432 case 't' : /* Show all info */
434 http
= connect_server(argv
[0], http
);
437 num_dests
= cupsGetDests2(http
, &dests
);
439 show_scheduler(http
);
440 show_default(num_dests
, dests
);
441 status
|= show_classes(http
, NULL
);
442 status
|= show_devices(http
, NULL
, num_dests
, dests
);
443 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
444 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
445 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
448 case 'u' : /* Show jobs by user */
450 http
= connect_server(argv
[0], http
);
452 if (argv
[i
][2] != '\0')
453 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
455 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
458 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
462 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
466 case 'v' : /* Show printer devices */
468 http
= connect_server(argv
[0], http
);
470 if (argv
[i
][2] != '\0')
472 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
474 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
476 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
480 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
482 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
487 num_dests
= cupsGetDests2(http
, &dests
);
489 status
|= show_devices(http
, NULL
, num_dests
, dests
);
495 _cupsLangPrintf(stderr
,
496 _("%s: Error - unknown option \'%c\'!\n"),
497 argv
[0], argv
[i
][1]);
502 http
= connect_server(argv
[0], http
);
504 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
510 http
= connect_server(argv
[0], http
);
512 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
520 * 'check_dest()' - Verify that the named destination(s) exists.
524 check_dest(const char *command
, /* I - Command name */
525 http_t
*http
, /* I - HTTP connection */
526 const char *name
, /* I - Name of printer/class(es) */
527 int *num_dests
, /* IO - Number of destinations */
528 cups_dest_t
**dests
) /* IO - Destinations */
536 * Load the destination list as necessary...
540 *num_dests
= cupsGetDests2(http
, dests
);
543 * Scan the name string for printer/class name(s)...
546 for (dptr
= name
; *dptr
!= '\0';)
549 * Skip leading whitespace and commas...
552 while (isspace(*dptr
& 255) || *dptr
== ',')
559 * Extract a single destination name from the name string...
562 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
564 if ((pptr
- printer
) < (sizeof(printer
) - 1))
568 _cupsLangPrintf(stderr
,
569 _("%s: Invalid destination name in list \"%s\"!\n"),
578 * Check the destination...
581 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
583 _cupsLangPrintf(stderr
,
584 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
592 * 'connect_server()' - Connect to the server as necessary...
595 static http_t
* /* O - New HTTP connection */
596 connect_server(const char *command
, /* I - Command name */
597 http_t
*http
) /* I - Current HTTP connection */
601 http
= httpConnectEncrypt(cupsServer(), ippPort(),
606 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
616 * 'show_accepting()' - Show acceptance status.
619 static int /* O - 0 on success, 1 on fail */
620 show_accepting(http_t
*http
, /* I - HTTP connection to server */
621 const char *printers
, /* I - Destinations */
622 int num_dests
, /* I - Number of user-defined dests */
623 cups_dest_t
*dests
) /* I - User-defined destinations */
625 int i
; /* Looping var */
626 ipp_t
*request
, /* IPP Request */
627 *response
; /* IPP Response */
628 ipp_attribute_t
*attr
; /* Current attribute */
629 const char *printer
, /* Printer name */
630 *message
; /* Printer device URI */
631 int accepting
; /* Accepting requests? */
632 time_t ptime
; /* Printer state time */
633 struct tm
*pdate
; /* Printer state date & time */
634 char printer_state_time
[255];/* Printer state time */
635 const char *dptr
, /* Pointer into destination list */
636 *ptr
; /* Pointer into printer name */
637 int match
; /* Non-zero if this job matches */
638 static const char *pattrs
[] = /* Attributes we need for printers... */
641 "printer-state-change-time",
642 "printer-state-message",
643 "printer-is-accepting-jobs"
647 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
652 if (printers
!= NULL
&& !strcmp(printers
, "all"))
656 * Build a CUPS_GET_PRINTERS request, which requires the following
660 * attributes-natural-language
661 * requested-attributes
662 * requesting-user-name
665 request
= ippNewRequest(CUPS_GET_PRINTERS
);
667 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
668 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
671 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
675 * Do the request and get back a response...
678 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
680 DEBUG_puts("show_accepting: request succeeded...");
682 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
684 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
690 * Loop through the printers returned in the list and display
694 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
697 * Skip leading attributes until we hit a printer...
700 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
707 * Pull the needed attributes from this printer...
715 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
717 if (!strcmp(attr
->name
, "printer-name") &&
718 attr
->value_tag
== IPP_TAG_NAME
)
719 printer
= attr
->values
[0].string
.text
;
720 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
721 attr
->value_tag
== IPP_TAG_INTEGER
)
722 ptime
= (time_t)attr
->values
[0].integer
;
723 else if (!strcmp(attr
->name
, "printer-state-message") &&
724 attr
->value_tag
== IPP_TAG_TEXT
)
725 message
= attr
->values
[0].string
.text
;
726 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
727 attr
->value_tag
== IPP_TAG_BOOLEAN
)
728 accepting
= attr
->values
[0].boolean
;
734 * See if we have everything needed...
746 * See if this is a printer we're interested in...
749 match
= printers
== NULL
;
751 if (printers
!= NULL
)
753 for (dptr
= printers
; *dptr
!= '\0';)
756 * Skip leading whitespace and commas...
759 while (isspace(*dptr
& 255) || *dptr
== ',')
770 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
773 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
780 * Skip trailing junk...
783 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
785 while (isspace(*dptr
& 255) || *dptr
== ',')
794 * Display the printer entry if needed...
799 pdate
= localtime(&ptime
);
800 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
803 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
804 printer
, printer_state_time
);
806 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
808 printer
, printer_state_time
,
809 message
== NULL
? "reason unknown" : message
);
811 for (i
= 0; i
< num_dests
; i
++)
812 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
815 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
816 printer
, dests
[i
].instance
, printer_state_time
);
818 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
820 printer
, dests
[i
].instance
, printer_state_time
,
821 message
== NULL
? "reason unknown" : message
);
833 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
842 * 'show_classes()' - Show printer classes.
845 static int /* O - 0 on success, 1 on fail */
846 show_classes(http_t
*http
, /* I - HTTP connection to server */
847 const char *dests
) /* I - Destinations */
849 int i
; /* Looping var */
850 ipp_t
*request
, /* IPP Request */
851 *response
, /* IPP Response */
852 *response2
; /* IPP response from remote server */
853 http_t
*http2
; /* Remote server */
854 ipp_attribute_t
*attr
; /* Current attribute */
855 const char *printer
, /* Printer class name */
856 *printer_uri
; /* Printer class URI */
857 ipp_attribute_t
*members
; /* Printer members */
858 char method
[HTTP_MAX_URI
], /* Request method */
859 username
[HTTP_MAX_URI
], /* Username:password */
860 server
[HTTP_MAX_URI
], /* Server name */
861 resource
[HTTP_MAX_URI
]; /* Resource name */
862 int port
; /* Port number */
863 const char *dptr
, /* Pointer into destination list */
864 *ptr
; /* Pointer into printer name */
865 int match
; /* Non-zero if this job matches */
866 static const char *cattrs
[] = /* Attributes we need for classes... */
869 "printer-uri-supported",
874 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
879 if (dests
!= NULL
&& !strcmp(dests
, "all"))
883 * Build a CUPS_GET_CLASSES request, which requires the following
887 * attributes-natural-language
888 * requested-attributes
889 * requesting-user-name
892 request
= ippNewRequest(CUPS_GET_CLASSES
);
894 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
895 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
898 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
902 * Do the request and get back a response...
905 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
907 DEBUG_puts("show_classes: request succeeded...");
909 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
911 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
917 * Loop through the printers returned in the list and display
921 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
924 * Skip leading attributes until we hit a job...
927 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
934 * Pull the needed attributes from this job...
941 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
943 if (!strcmp(attr
->name
, "printer-name") &&
944 attr
->value_tag
== IPP_TAG_NAME
)
945 printer
= attr
->values
[0].string
.text
;
947 if (!strcmp(attr
->name
, "printer-uri-supported") &&
948 attr
->value_tag
== IPP_TAG_URI
)
949 printer_uri
= attr
->values
[0].string
.text
;
951 if (!strcmp(attr
->name
, "member-names") &&
952 attr
->value_tag
== IPP_TAG_NAME
)
959 * If this is a remote class, grab the class info from the
964 if (members
== NULL
&& printer_uri
!= NULL
)
966 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
967 username
, sizeof(username
), server
, sizeof(server
),
968 &port
, resource
, sizeof(resource
));
970 if (!strcasecmp(server
, http
->hostname
))
973 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
978 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
979 * following attributes:
982 * attributes-natural-language
984 * requested-attributes
987 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
989 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
990 "printer-uri", NULL
, printer_uri
);
992 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
993 "requested-attributes",
994 sizeof(cattrs
) / sizeof(cattrs
[0]),
997 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
998 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
1006 * See if we have everything needed...
1009 if (printer
== NULL
)
1012 ippDelete(response2
);
1021 * See if this is a printer we're interested in...
1024 match
= dests
== NULL
;
1028 for (dptr
= dests
; *dptr
!= '\0';)
1031 * Skip leading whitespace and commas...
1034 while (isspace(*dptr
& 255) || *dptr
== ',')
1045 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1048 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1055 * Skip trailing junk...
1058 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1060 while (isspace(*dptr
& 255) || *dptr
== ',')
1069 * Display the printer entry if needed...
1074 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1078 for (i
= 0; i
< members
->num_values
; i
++)
1079 _cupsLangPrintf(stdout
, "\t%s\n",
1080 members
->values
[i
].string
.text
);
1083 _cupsLangPuts(stdout
, "\tunknown\n");
1087 ippDelete(response2
);
1093 ippDelete(response
);
1097 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1106 * 'show_default()' - Show default destination.
1110 show_default(int num_dests
, /* I - Number of user-defined dests */
1111 cups_dest_t
*dests
) /* I - User-defined destinations */
1113 cups_dest_t
*dest
; /* Destination */
1114 const char *printer
, /* Printer name */
1115 *val
; /* Environment variable name */
1117 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1120 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1121 dest
->name
, dest
->instance
);
1123 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1130 if ((printer
= getenv("LPDEST")) == NULL
)
1132 if ((printer
= getenv("PRINTER")) != NULL
)
1134 if (!strcmp(printer
, "lp"))
1143 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1144 _cupsLangPrintf(stdout
,
1145 _("lpstat: error - %s environment variable names "
1146 "non-existent destination \"%s\"!\n"),
1149 _cupsLangPuts(stdout
, _("no system default destination\n"));
1155 * 'show_devices()' - Show printer devices.
1158 static int /* O - 0 on success, 1 on fail */
1159 show_devices(http_t
*http
, /* I - HTTP connection to server */
1160 const char *printers
, /* I - Destinations */
1161 int num_dests
, /* I - Number of user-defined dests */
1162 cups_dest_t
*dests
) /* I - User-defined destinations */
1164 int i
; /* Looping var */
1165 ipp_t
*request
, /* IPP Request */
1166 *response
; /* IPP Response */
1167 ipp_attribute_t
*attr
; /* Current attribute */
1168 const char *printer
, /* Printer name */
1169 *uri
, /* Printer URI */
1170 *device
, /* Printer device URI */
1171 *dptr
, /* Pointer into destination list */
1172 *ptr
; /* Pointer into printer name */
1173 int match
; /* Non-zero if this job matches */
1174 static const char *pattrs
[] = /* Attributes we need for printers... */
1177 "printer-uri-supported",
1182 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1187 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1191 * Build a CUPS_GET_PRINTERS request, which requires the following
1194 * attributes-charset
1195 * attributes-natural-language
1196 * requested-attributes
1197 * requesting-user-name
1200 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1202 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1203 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1206 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1210 * Do the request and get back a response...
1213 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1215 DEBUG_puts("show_devices: request succeeded...");
1217 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1219 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1220 ippDelete(response
);
1225 * Loop through the printers returned in the list and display
1229 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1232 * Skip leading attributes until we hit a job...
1235 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1242 * Pull the needed attributes from this job...
1249 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1251 if (!strcmp(attr
->name
, "printer-name") &&
1252 attr
->value_tag
== IPP_TAG_NAME
)
1253 printer
= attr
->values
[0].string
.text
;
1255 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1256 attr
->value_tag
== IPP_TAG_URI
)
1257 uri
= attr
->values
[0].string
.text
;
1259 if (!strcmp(attr
->name
, "device-uri") &&
1260 attr
->value_tag
== IPP_TAG_URI
)
1261 device
= attr
->values
[0].string
.text
;
1267 * See if we have everything needed...
1270 if (printer
== NULL
)
1279 * See if this is a printer we're interested in...
1282 match
= printers
== NULL
;
1284 if (printers
!= NULL
)
1286 for (dptr
= printers
; *dptr
!= '\0';)
1289 * Skip leading whitespace and commas...
1292 while (isspace(*dptr
& 255) || *dptr
== ',')
1303 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1306 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1313 * Skip trailing junk...
1316 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1318 while (isspace(*dptr
& 255) || *dptr
== ',')
1327 * Display the printer entry if needed...
1332 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1333 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1334 username
[HTTP_MAX_URI
],
1335 hostname
[HTTP_MAX_URI
],
1336 resource
[HTTP_MAX_URI
];
1342 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1343 username
, sizeof(username
), hostname
,
1344 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1345 _cupsLangPrintf(stdout
,
1346 _("Output for printer %s is sent to remote "
1347 "printer %s on %s\n"),
1348 printer
, strrchr(resource
, '/') + 1, hostname
);
1350 else if (!strncmp(device
, "file:", 5))
1351 _cupsLangPrintf(stdout
,
1352 _("Output for printer %s is sent to %s\n"),
1353 printer
, device
+ 5);
1355 _cupsLangPrintf(stdout
,
1356 _("Output for printer %s is sent to %s\n"),
1359 for (i
= 0; i
< num_dests
; i
++)
1360 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1363 _cupsLangPrintf(stdout
,
1364 _("Output for printer %s/%s is sent to "
1365 "remote printer %s on %s\n"),
1366 printer
, dests
[i
].instance
,
1367 strrchr(resource
, '/') + 1, hostname
);
1368 else if (!strncmp(device
, "file:", 5))
1369 _cupsLangPrintf(stdout
,
1370 _("Output for printer %s/%s is sent to %s\n"),
1371 printer
, dests
[i
].instance
, device
+ 5);
1373 _cupsLangPrintf(stdout
,
1374 _("Output for printer %s/%s is sent to %s\n"),
1375 printer
, dests
[i
].instance
, device
);
1379 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1381 else if (!strncmp(device
, "file:", 5))
1382 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1383 printer
, device
+ 5);
1385 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1388 for (i
= 0; i
< num_dests
; i
++)
1389 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1392 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1393 printer
, dests
[i
].instance
, uri
);
1394 else if (!strncmp(device
, "file:", 5))
1395 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1396 printer
, dests
[i
].instance
, device
+ 5);
1398 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1399 printer
, dests
[i
].instance
, device
);
1401 #endif /* __osf__ */
1408 ippDelete(response
);
1412 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1421 * 'show_jobs()' - Show active print jobs.
1424 static int /* O - 0 on success, 1 on fail */
1425 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1426 const char *dests
, /* I - Destinations */
1427 const char *users
, /* I - Users */
1428 int long_status
, /* I - Show long status? */
1429 int ranking
, /* I - Show job ranking? */
1430 const char *which
) /* I - Show which jobs? */
1432 ipp_t
*request
, /* IPP Request */
1433 *response
; /* IPP Response */
1434 ipp_attribute_t
*attr
; /* Current attribute */
1435 const char *dest
, /* Pointer into job-printer-uri */
1436 *username
, /* Pointer to job-originating-user-name */
1437 *title
; /* Pointer to job-name */
1438 int rank
, /* Rank in queue */
1440 size
; /* job-k-octets */
1441 time_t jobtime
; /* time-at-creation */
1442 struct tm
*jobdate
; /* Date & time */
1443 const char *dptr
, /* Pointer into destination list */
1444 *ptr
; /* Pointer into printer name */
1445 int match
; /* Non-zero if this job matches */
1446 char temp
[255], /* Temporary buffer */
1447 date
[255]; /* Date buffer */
1448 static const char *jattrs
[] = /* Attributes we need for jobs... */
1455 "job-originating-user-name"
1459 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1464 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1468 * Build a IPP_GET_JOBS request, which requires the following
1471 * attributes-charset
1472 * attributes-natural-language
1474 * requested-attributes
1477 request
= ippNewRequest(IPP_GET_JOBS
);
1479 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1480 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1483 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1484 NULL
, "ipp://localhost/jobs/");
1486 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1490 * Do the request and get back a response...
1493 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1496 * Loop through the job list and display them...
1499 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1501 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1502 ippDelete(response
);
1508 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1511 * Skip leading attributes until we hit a job...
1514 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1521 * Pull the needed attributes from this job...
1531 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1533 if (!strcmp(attr
->name
, "job-id") &&
1534 attr
->value_tag
== IPP_TAG_INTEGER
)
1535 jobid
= attr
->values
[0].integer
;
1537 if (!strcmp(attr
->name
, "job-k-octets") &&
1538 attr
->value_tag
== IPP_TAG_INTEGER
)
1539 size
= attr
->values
[0].integer
;
1541 if (!strcmp(attr
->name
, "time-at-creation") &&
1542 attr
->value_tag
== IPP_TAG_INTEGER
)
1543 jobtime
= attr
->values
[0].integer
;
1545 if (!strcmp(attr
->name
, "job-printer-uri") &&
1546 attr
->value_tag
== IPP_TAG_URI
)
1547 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1550 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1551 attr
->value_tag
== IPP_TAG_NAME
)
1552 username
= attr
->values
[0].string
.text
;
1554 if (!strcmp(attr
->name
, "job-name") &&
1555 attr
->value_tag
== IPP_TAG_NAME
)
1556 title
= attr
->values
[0].string
.text
;
1562 * See if we have everything needed...
1565 if (dest
== NULL
|| jobid
== 0)
1574 * See if this is a job we're interested in...
1577 match
= (dests
== NULL
&& users
== NULL
);
1582 for (dptr
= dests
; *dptr
!= '\0';)
1585 * Skip leading whitespace and commas...
1588 while (isspace(*dptr
& 255) || *dptr
== ',')
1599 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1602 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1609 * Skip trailing junk...
1612 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1614 while (isspace(*dptr
& 255) || *dptr
== ',')
1622 if (users
!= NULL
&& username
!= NULL
)
1624 for (dptr
= users
; *dptr
!= '\0';)
1627 * Skip leading whitespace and commas...
1630 while (isspace(*dptr
& 255) || *dptr
== ',')
1640 for (ptr
= username
;
1641 *ptr
!= '\0' && *dptr
!= '\0' && *ptr
== *dptr
;
1644 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1651 * Skip trailing junk...
1654 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1656 while (isspace(*dptr
& 255) || *dptr
== ',')
1665 * Display the job...
1670 jobdate
= localtime(&jobtime
);
1671 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1673 if (long_status
== 3)
1676 * Show the consolidated output format for the SGI tools...
1679 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1680 strcpy(date
, "Unknown");
1682 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s\n",
1683 temp
, username
? username
: "unknown",
1684 size
, title
? title
: "unknown", date
);
1688 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1689 strcpy(date
, "Unknown");
1692 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s\n",
1693 rank
, temp
, username
? username
: "unknown",
1694 1024.0 * size
, date
);
1696 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s\n",
1697 temp
, username
? username
: "unknown",
1698 1024.0 * size
, date
);
1700 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1708 ippDelete(response
);
1712 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1721 * 'show_printers()' - Show printers.
1724 static int /* O - 0 on success, 1 on fail */
1725 show_printers(http_t
*http
, /* I - HTTP connection to server */
1726 const char *printers
, /* I - Destinations */
1727 int num_dests
, /* I - Number of user-defined dests */
1728 cups_dest_t
*dests
, /* I - User-defined destinations */
1729 int long_status
) /* I - Show long status? */
1731 int i
; /* Looping var */
1732 ipp_t
*request
, /* IPP Request */
1733 *response
, /* IPP Response */
1734 *jobs
; /* IPP Get Jobs response */
1735 ipp_attribute_t
*attr
, /* Current attribute */
1736 *jobattr
, /* Job ID attribute */
1737 *reasons
; /* Job state reasons attribute */
1738 const char *printer
, /* Printer name */
1739 *message
, /* Printer state message */
1740 *description
, /* Description of printer */
1741 *location
, /* Location of printer */
1742 *make_model
, /* Make and model of printer */
1743 *uri
; /* URI of printer */
1744 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1745 *denied
; /* requestint-user-name-denied */
1746 ipp_pstate_t pstate
; /* Printer state */
1747 cups_ptype_t ptype
; /* Printer type */
1748 time_t ptime
; /* Printer state time */
1749 struct tm
*pdate
; /* Printer state date & time */
1750 int jobid
; /* Job ID of current job */
1751 const char *dptr
, /* Pointer into destination list */
1752 *ptr
; /* Pointer into printer name */
1753 int match
; /* Non-zero if this job matches */
1754 char printer_uri
[HTTP_MAX_URI
],
1756 printer_state_time
[255];/* Printer state time */
1757 const char *root
; /* Server root directory... */
1758 static const char *pattrs
[] = /* Attributes we need for printers... */
1762 "printer-state-message",
1763 "printer-state-reasons",
1764 "printer-state-change-time",
1768 "printer-make-and-model",
1769 "printer-uri-supported",
1770 "requesting-user-name-allowed",
1771 "requesting-user-name-denied"
1773 static const char *jattrs
[] = /* Attributes we need for jobs... */
1779 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1784 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1785 root
= CUPS_SERVERROOT
;
1787 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1791 * Build a CUPS_GET_PRINTERS request, which requires the following
1794 * attributes-charset
1795 * attributes-natural-language
1796 * requested-attributes
1797 * requesting-user-name
1800 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1802 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1803 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1806 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1810 * Do the request and get back a response...
1813 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1815 DEBUG_puts("show_printers: request succeeded...");
1817 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1819 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1820 ippDelete(response
);
1825 * Loop through the printers returned in the list and display
1829 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1832 * Skip leading attributes until we hit a job...
1835 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1842 * Pull the needed attributes from this job...
1847 ptype
= CUPS_PRINTER_LOCAL
;
1848 pstate
= IPP_PRINTER_IDLE
;
1859 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1861 if (!strcmp(attr
->name
, "printer-name") &&
1862 attr
->value_tag
== IPP_TAG_NAME
)
1863 printer
= attr
->values
[0].string
.text
;
1864 else if (!strcmp(attr
->name
, "printer-state") &&
1865 attr
->value_tag
== IPP_TAG_ENUM
)
1866 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1867 else if (!strcmp(attr
->name
, "printer-type") &&
1868 attr
->value_tag
== IPP_TAG_ENUM
)
1869 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1870 else if (!strcmp(attr
->name
, "printer-state-message") &&
1871 attr
->value_tag
== IPP_TAG_TEXT
)
1872 message
= attr
->values
[0].string
.text
;
1873 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1874 attr
->value_tag
== IPP_TAG_INTEGER
)
1875 ptime
= (time_t)attr
->values
[0].integer
;
1876 else if (!strcmp(attr
->name
, "printer-info") &&
1877 attr
->value_tag
== IPP_TAG_TEXT
)
1878 description
= attr
->values
[0].string
.text
;
1879 else if (!strcmp(attr
->name
, "printer-location") &&
1880 attr
->value_tag
== IPP_TAG_TEXT
)
1881 location
= attr
->values
[0].string
.text
;
1882 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1883 attr
->value_tag
== IPP_TAG_TEXT
)
1884 make_model
= attr
->values
[0].string
.text
;
1885 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1886 attr
->value_tag
== IPP_TAG_URI
)
1887 uri
= attr
->values
[0].string
.text
;
1888 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1889 attr
->value_tag
== IPP_TAG_KEYWORD
)
1891 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1892 attr
->value_tag
== IPP_TAG_NAME
)
1894 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1895 attr
->value_tag
== IPP_TAG_NAME
)
1902 * See if we have everything needed...
1905 if (printer
== NULL
)
1914 * See if this is a printer we're interested in...
1917 match
= printers
== NULL
;
1919 if (printers
!= NULL
)
1921 for (dptr
= printers
; *dptr
!= '\0';)
1924 * Skip leading whitespace and commas...
1927 while (isspace(*dptr
& 255) || *dptr
== ',')
1938 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1941 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1948 * Skip trailing junk...
1951 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1953 while (isspace(*dptr
& 255) || *dptr
== ',')
1962 * Display the printer entry if needed...
1968 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1969 * current job for the printer.
1972 if (pstate
== IPP_PRINTER_PROCESSING
)
1975 * Build an IPP_GET_JOBS request, which requires the following
1978 * attributes-charset
1979 * attributes-natural-language
1982 * requested-attributes
1985 request
= ippNewRequest(IPP_GET_JOBS
);
1987 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1988 request
->request
.op
.request_id
= 1;
1990 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1991 "requested-attributes",
1992 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1994 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1995 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1996 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1997 "printer-uri", NULL
, printer_uri
);
1999 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
2002 * Get the current active job on this queue...
2007 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
2012 if (!strcmp(jobattr
->name
, "job-id") &&
2013 jobattr
->value_tag
== IPP_TAG_INTEGER
)
2014 jobid
= jobattr
->values
[0].integer
;
2015 else if (!strcmp(jobattr
->name
, "job-state") &&
2016 jobattr
->value_tag
== IPP_TAG_ENUM
&&
2017 jobattr
->values
[0].integer
== IPP_JOB_PROCESSING
)
2029 pdate
= localtime(&ptime
);
2030 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
2034 case IPP_PRINTER_IDLE
:
2035 _cupsLangPrintf(stdout
,
2036 _("printer %s is idle. enabled since %s\n"),
2037 printer
, printer_state_time
);
2039 case IPP_PRINTER_PROCESSING
:
2040 _cupsLangPrintf(stdout
,
2041 _("printer %s now printing %s-%d. "
2042 "enabled since %s\n"),
2043 printer
, printer
, jobid
, printer_state_time
);
2045 case IPP_PRINTER_STOPPED
:
2046 _cupsLangPrintf(stdout
,
2047 _("printer %s disabled since %s -\n"),
2048 printer
, printer_state_time
);
2052 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2054 if (!message
|| !*message
)
2055 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2057 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2060 if (long_status
> 1)
2061 _cupsLangPuts(stdout
,
2062 _("\tForm mounted:\n"
2063 "\tContent types: any\n"
2064 "\tPrinter types: unknown\n"));
2068 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2069 description
? description
: "");
2073 _cupsLangPuts(stdout
, _("\tAlerts:"));
2074 for (i
= 0; i
< reasons
->num_values
; i
++)
2075 _cupsLangPrintf(stdout
, " %s",
2076 reasons
->values
[i
].string
.text
);
2077 _cupsLangPuts(stdout
, "\n");
2080 if (long_status
> 1)
2082 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2083 location
? location
: "");
2085 if (ptype
& CUPS_PRINTER_REMOTE
)
2087 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2089 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2090 !strstr(make_model
, "Raw Printer") && uri
)
2091 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2096 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2098 if (make_model
&& strstr(make_model
, "System V Printer"))
2099 _cupsLangPrintf(stdout
,
2100 _("\tInterface: %s/interfaces/%s\n"),
2102 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2103 _cupsLangPrintf(stdout
,
2104 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2106 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2107 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2108 /* TODO update to use printer-error-policy */
2111 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2112 for (i
= 0; i
< allowed
->num_values
; i
++)
2113 _cupsLangPrintf(stdout
, "\t\t%s\n",
2114 allowed
->values
[i
].string
.text
);
2118 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2119 for (i
= 0; i
< denied
->num_values
; i
++)
2120 _cupsLangPrintf(stdout
, "\t\t%s\n",
2121 denied
->values
[i
].string
.text
);
2125 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2126 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2128 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2129 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2130 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2131 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2132 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2133 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2134 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2135 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2138 for (i
= 0; i
< num_dests
; i
++)
2139 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2143 case IPP_PRINTER_IDLE
:
2144 _cupsLangPrintf(stdout
,
2145 _("printer %s/%s is idle. "
2146 "enabled since %s\n"),
2147 printer
, dests
[i
].instance
,
2148 printer_state_time
);
2150 case IPP_PRINTER_PROCESSING
:
2151 _cupsLangPrintf(stdout
,
2152 _("printer %s/%s now printing %s-%d. "
2153 "enabled since %s\n"),
2154 printer
, dests
[i
].instance
, printer
, jobid
,
2155 printer_state_time
);
2157 case IPP_PRINTER_STOPPED
:
2158 _cupsLangPrintf(stdout
,
2159 _("printer %s/%s disabled since %s -\n"),
2160 printer
, dests
[i
].instance
,
2161 printer_state_time
);
2165 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2167 if (!message
|| !*message
)
2168 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2170 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2173 if (long_status
> 1)
2174 _cupsLangPuts(stdout
,
2175 _("\tForm mounted:\n"
2176 "\tContent types: any\n"
2177 "\tPrinter types: unknown\n"));
2181 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2182 description
? description
: "");
2186 _cupsLangPuts(stdout
, _("\tAlerts:"));
2187 for (i
= 0; i
< reasons
->num_values
; i
++)
2188 _cupsLangPrintf(stdout
, " %s",
2189 reasons
->values
[i
].string
.text
);
2190 _cupsLangPuts(stdout
, "\n");
2193 if (long_status
> 1)
2195 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2196 location
? location
: "");
2198 if (ptype
& CUPS_PRINTER_REMOTE
)
2200 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2202 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2203 !strstr(make_model
, "Raw Printer") && uri
)
2204 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2209 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2211 if (make_model
&& strstr(make_model
, "System V Printer"))
2212 _cupsLangPrintf(stdout
,
2213 _("\tInterface: %s/interfaces/%s\n"),
2215 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2216 _cupsLangPrintf(stdout
,
2217 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2219 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2220 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2221 /* TODO update to use printer-error-policy */
2224 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2225 for (i
= 0; i
< allowed
->num_values
; i
++)
2226 _cupsLangPrintf(stdout
, "\t\t%s\n",
2227 allowed
->values
[i
].string
.text
);
2231 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2232 for (i
= 0; i
< denied
->num_values
; i
++)
2233 _cupsLangPrintf(stdout
, "\t\t%s\n",
2234 denied
->values
[i
].string
.text
);
2238 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2239 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2241 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2242 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2243 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2244 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2245 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2246 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2247 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2248 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2257 ippDelete(response
);
2261 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2270 * 'show_scheduler()' - Show scheduler status.
2274 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2277 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2279 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2284 * End of "$Id: lpstat.c 5638 2006-06-06 20:08:13Z mike $".