2 * "$Id: lpstat.c 6084 2006-11-14 14:35:53Z 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/http-private.h>
46 #include <cups/string.h>
47 #include <cups/cups.h>
48 #include <cups/i18n.h>
49 #include <cups/debug.h>
56 static void check_dest(const char *, http_t
*, const char *, int *,
58 static http_t
*connect_server(const char *, http_t
*);
59 static int show_accepting(http_t
*, const char *, int, cups_dest_t
*);
60 static int show_classes(http_t
*, const char *);
61 static void show_default(int, cups_dest_t
*);
62 static int show_devices(http_t
*, const char *, int, cups_dest_t
*);
63 static int show_jobs(http_t
*, const char *, const char *, int, int,
65 static int show_printers(http_t
*, const char *, int, cups_dest_t
*, int);
66 static void show_scheduler(http_t
*);
70 * 'main()' - Parse options and show status information.
74 main(int argc
, /* I - Number of command-line arguments */
75 char *argv
[]) /* I - Command-line arguments */
77 int i
, /* Looping var */
78 status
; /* Exit status */
79 http_t
*http
; /* Connection to server */
80 int num_dests
; /* Number of user destinations */
81 cups_dest_t
*dests
; /* User destinations */
82 int long_status
; /* Long status report? */
83 int ranking
; /* Show job ranking? */
84 const char *which
; /* Which jobs to show? */
85 char op
; /* Last operation on command-line */
91 * Parse command-line options...
100 which
= "not-completed";
103 for (i
= 1; i
< argc
; i
++)
104 if (argv
[i
][0] == '-')
107 case 'D' : /* Show description */
111 case 'E' : /* Encrypt */
113 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
116 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
118 _cupsLangPrintf(stderr
,
119 _("%s: Sorry, no encryption support compiled in!\n"),
121 #endif /* HAVE_SSL */
124 case 'P' : /* Show paper types */
128 case 'R' : /* Show ranking */
132 case 'S' : /* Show charsets */
138 case 'U' : /* Username */
139 if (argv
[i
][2] != '\0')
140 cupsSetUser(argv
[i
] + 2);
146 _cupsLangPrintf(stderr
,
147 _("%s: Error - expected username after "
153 cupsSetUser(argv
[i
]);
157 case 'W' : /* Show which jobs? */
166 _cupsLangPrintf(stderr
,
167 _("%s: Error - need \"completed\", "
168 "\"not-completed\", or \"all\" after "
177 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
178 strcmp(which
, "all"))
180 _cupsLangPrintf(stderr
,
181 _("%s: Error - need \"completed\", "
182 "\"not-completed\", or \"all\" after "
189 case 'a' : /* Show acceptance status */
191 http
= connect_server(argv
[0], http
);
193 if (argv
[i
][2] != '\0')
195 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
197 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
199 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
203 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
205 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
210 num_dests
= cupsGetDests2(http
, &dests
);
212 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
217 case 'b' : /* Show both the local and remote status */
219 http
= connect_server(argv
[0], http
);
221 if (argv
[i
][2] != '\0')
224 * The local and remote status are separated by a blank line;
225 * since all CUPS jobs are networked, we only output the
226 * second list for now... In the future, we might further
227 * emulate this by listing the remote server's queue, but
228 * for now this is enough to make the SGI printstatus program
232 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
235 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
239 _cupsLangPrintf(stderr
,
240 _("%s: Error - expected destination after "
249 case 'c' : /* Show classes and members */
251 http
= connect_server(argv
[0], http
);
253 if (argv
[i
][2] != '\0')
255 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
257 status
|= show_classes(http
, argv
[i
] + 2);
259 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
263 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
265 status
|= show_classes(http
, argv
[i
]);
268 status
|= show_classes(http
, NULL
);
271 case 'd' : /* Show default destination */
273 http
= connect_server(argv
[0], http
);
276 num_dests
= cupsGetDests2(http
, &dests
);
278 show_default(num_dests
, dests
);
281 case 'f' : /* Show forms */
287 case 'h' : /* Connect to host */
294 if (argv
[i
][2] != '\0')
295 cupsSetServer(argv
[i
] + 2);
302 _cupsLangPrintf(stderr
,
303 _("%s: Error - expected hostname after "
309 cupsSetServer(argv
[i
]);
313 case 'l' : /* Long status or long job status */
316 http
= connect_server(argv
[0], http
);
318 if (argv
[i
][2] != '\0')
320 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
322 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
329 case 'o' : /* Show jobs by destination */
331 http
= connect_server(argv
[0], http
);
333 if (argv
[i
][2] != '\0')
335 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
337 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
340 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
344 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
346 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
350 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
354 case 'p' : /* Show printers */
356 http
= connect_server(argv
[0], http
);
358 if (argv
[i
][2] != '\0')
360 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
362 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
364 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
368 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
370 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
375 num_dests
= cupsGetDests2(http
, &dests
);
377 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
381 case 'r' : /* Show scheduler status */
383 http
= connect_server(argv
[0], http
);
385 show_scheduler(http
);
388 case 's' : /* Show summary */
390 http
= connect_server(argv
[0], http
);
393 num_dests
= cupsGetDests2(http
, &dests
);
395 show_default(num_dests
, dests
);
396 status
|= show_classes(http
, NULL
);
397 status
|= show_devices(http
, NULL
, num_dests
, dests
);
400 case 't' : /* Show all info */
402 http
= connect_server(argv
[0], http
);
405 num_dests
= cupsGetDests2(http
, &dests
);
407 show_scheduler(http
);
408 show_default(num_dests
, dests
);
409 status
|= show_classes(http
, NULL
);
410 status
|= show_devices(http
, NULL
, num_dests
, dests
);
411 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
412 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
413 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
416 case 'u' : /* Show jobs by user */
418 http
= connect_server(argv
[0], http
);
420 if (argv
[i
][2] != '\0')
421 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
423 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
426 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
430 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
434 case 'v' : /* Show printer devices */
436 http
= connect_server(argv
[0], http
);
438 if (argv
[i
][2] != '\0')
440 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
442 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
444 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
448 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
450 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
455 num_dests
= cupsGetDests2(http
, &dests
);
457 status
|= show_devices(http
, NULL
, num_dests
, dests
);
463 _cupsLangPrintf(stderr
,
464 _("%s: Error - unknown option \'%c\'!\n"),
465 argv
[0], argv
[i
][1]);
470 http
= connect_server(argv
[0], http
);
472 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
478 http
= connect_server(argv
[0], http
);
480 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
488 * 'check_dest()' - Verify that the named destination(s) exists.
492 check_dest(const char *command
, /* I - Command name */
493 http_t
*http
, /* I - HTTP connection */
494 const char *name
, /* I - Name of printer/class(es) */
495 int *num_dests
, /* IO - Number of destinations */
496 cups_dest_t
**dests
) /* IO - Destinations */
504 * Load the destination list as necessary...
508 *num_dests
= cupsGetDests2(http
, dests
);
511 * Scan the name string for printer/class name(s)...
514 for (dptr
= name
; *dptr
!= '\0';)
517 * Skip leading whitespace and commas...
520 while (isspace(*dptr
& 255) || *dptr
== ',')
527 * Extract a single destination name from the name string...
530 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
532 if ((pptr
- printer
) < (sizeof(printer
) - 1))
536 _cupsLangPrintf(stderr
,
537 _("%s: Invalid destination name in list \"%s\"!\n"),
546 * Check the destination...
549 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
551 _cupsLangPrintf(stderr
,
552 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
560 * 'connect_server()' - Connect to the server as necessary...
563 static http_t
* /* O - New HTTP connection */
564 connect_server(const char *command
, /* I - Command name */
565 http_t
*http
) /* I - Current HTTP connection */
569 http
= httpConnectEncrypt(cupsServer(), ippPort(),
574 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
584 * 'show_accepting()' - Show acceptance status.
587 static int /* O - 0 on success, 1 on fail */
588 show_accepting(http_t
*http
, /* I - HTTP connection to server */
589 const char *printers
, /* I - Destinations */
590 int num_dests
, /* I - Number of user-defined dests */
591 cups_dest_t
*dests
) /* I - User-defined destinations */
593 int i
; /* Looping var */
594 ipp_t
*request
, /* IPP Request */
595 *response
; /* IPP Response */
596 ipp_attribute_t
*attr
; /* Current attribute */
597 const char *printer
, /* Printer name */
598 *message
; /* Printer device URI */
599 int accepting
; /* Accepting requests? */
600 time_t ptime
; /* Printer state time */
601 struct tm
*pdate
; /* Printer state date & time */
602 char printer_state_time
[255];/* Printer state time */
603 const char *dptr
, /* Pointer into destination list */
604 *ptr
; /* Pointer into printer name */
605 int match
; /* Non-zero if this job matches */
606 static const char *pattrs
[] = /* Attributes we need for printers... */
609 "printer-state-change-time",
610 "printer-state-message",
611 "printer-is-accepting-jobs"
615 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
620 if (printers
!= NULL
&& !strcmp(printers
, "all"))
624 * Build a CUPS_GET_PRINTERS request, which requires the following
628 * attributes-natural-language
629 * requested-attributes
630 * requesting-user-name
633 request
= ippNewRequest(CUPS_GET_PRINTERS
);
635 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
636 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
639 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
643 * Do the request and get back a response...
646 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
648 DEBUG_puts("show_accepting: request succeeded...");
650 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
652 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
658 * Loop through the printers returned in the list and display
662 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
665 * Skip leading attributes until we hit a printer...
668 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
675 * Pull the needed attributes from this printer...
683 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
685 if (!strcmp(attr
->name
, "printer-name") &&
686 attr
->value_tag
== IPP_TAG_NAME
)
687 printer
= attr
->values
[0].string
.text
;
688 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
689 attr
->value_tag
== IPP_TAG_INTEGER
)
690 ptime
= (time_t)attr
->values
[0].integer
;
691 else if (!strcmp(attr
->name
, "printer-state-message") &&
692 attr
->value_tag
== IPP_TAG_TEXT
)
693 message
= attr
->values
[0].string
.text
;
694 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
695 attr
->value_tag
== IPP_TAG_BOOLEAN
)
696 accepting
= attr
->values
[0].boolean
;
702 * See if we have everything needed...
714 * See if this is a printer we're interested in...
717 match
= printers
== NULL
;
719 if (printers
!= NULL
)
721 for (dptr
= printers
; *dptr
!= '\0';)
724 * Skip leading whitespace and commas...
727 while (isspace(*dptr
& 255) || *dptr
== ',')
738 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
741 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
748 * Skip trailing junk...
751 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
753 while (isspace(*dptr
& 255) || *dptr
== ',')
762 * Display the printer entry if needed...
767 pdate
= localtime(&ptime
);
768 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
771 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
772 printer
, printer_state_time
);
774 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
776 printer
, printer_state_time
,
777 message
== NULL
? "reason unknown" : message
);
779 for (i
= 0; i
< num_dests
; i
++)
780 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
783 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
784 printer
, dests
[i
].instance
, printer_state_time
);
786 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
788 printer
, dests
[i
].instance
, printer_state_time
,
789 message
== NULL
? "reason unknown" : message
);
801 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
810 * 'show_classes()' - Show printer classes.
813 static int /* O - 0 on success, 1 on fail */
814 show_classes(http_t
*http
, /* I - HTTP connection to server */
815 const char *dests
) /* I - Destinations */
817 int i
; /* Looping var */
818 ipp_t
*request
, /* IPP Request */
819 *response
, /* IPP Response */
820 *response2
; /* IPP response from remote server */
821 http_t
*http2
; /* Remote server */
822 ipp_attribute_t
*attr
; /* Current attribute */
823 const char *printer
, /* Printer class name */
824 *printer_uri
; /* Printer class URI */
825 ipp_attribute_t
*members
; /* Printer members */
826 char method
[HTTP_MAX_URI
], /* Request method */
827 username
[HTTP_MAX_URI
], /* Username:password */
828 server
[HTTP_MAX_URI
], /* Server name */
829 resource
[HTTP_MAX_URI
]; /* Resource name */
830 int port
; /* Port number */
831 const char *dptr
, /* Pointer into destination list */
832 *ptr
; /* Pointer into printer name */
833 int match
; /* Non-zero if this job matches */
834 static const char *cattrs
[] = /* Attributes we need for classes... */
837 "printer-uri-supported",
842 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
847 if (dests
!= NULL
&& !strcmp(dests
, "all"))
851 * Build a CUPS_GET_CLASSES request, which requires the following
855 * attributes-natural-language
856 * requested-attributes
857 * requesting-user-name
860 request
= ippNewRequest(CUPS_GET_CLASSES
);
862 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
863 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
866 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
870 * Do the request and get back a response...
873 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
875 DEBUG_puts("show_classes: request succeeded...");
877 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
879 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
885 * Loop through the printers returned in the list and display
889 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
892 * Skip leading attributes until we hit a job...
895 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
902 * Pull the needed attributes from this job...
909 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
911 if (!strcmp(attr
->name
, "printer-name") &&
912 attr
->value_tag
== IPP_TAG_NAME
)
913 printer
= attr
->values
[0].string
.text
;
915 if (!strcmp(attr
->name
, "printer-uri-supported") &&
916 attr
->value_tag
== IPP_TAG_URI
)
917 printer_uri
= attr
->values
[0].string
.text
;
919 if (!strcmp(attr
->name
, "member-names") &&
920 attr
->value_tag
== IPP_TAG_NAME
)
927 * If this is a remote class, grab the class info from the
932 if (members
== NULL
&& printer_uri
!= NULL
)
934 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
935 username
, sizeof(username
), server
, sizeof(server
),
936 &port
, resource
, sizeof(resource
));
938 if (!strcasecmp(server
, http
->hostname
))
941 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
946 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
947 * following attributes:
950 * attributes-natural-language
952 * requested-attributes
955 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
957 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
958 "printer-uri", NULL
, printer_uri
);
960 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
961 "requested-attributes",
962 sizeof(cattrs
) / sizeof(cattrs
[0]),
965 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
966 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
974 * See if we have everything needed...
980 ippDelete(response2
);
989 * See if this is a printer we're interested in...
992 match
= dests
== NULL
;
996 for (dptr
= dests
; *dptr
!= '\0';)
999 * Skip leading whitespace and commas...
1002 while (isspace(*dptr
& 255) || *dptr
== ',')
1013 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1016 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1023 * Skip trailing junk...
1026 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1028 while (isspace(*dptr
& 255) || *dptr
== ',')
1037 * Display the printer entry if needed...
1042 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1046 for (i
= 0; i
< members
->num_values
; i
++)
1047 _cupsLangPrintf(stdout
, "\t%s\n",
1048 members
->values
[i
].string
.text
);
1051 _cupsLangPuts(stdout
, "\tunknown\n");
1055 ippDelete(response2
);
1061 ippDelete(response
);
1065 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1074 * 'show_default()' - Show default destination.
1078 show_default(int num_dests
, /* I - Number of user-defined dests */
1079 cups_dest_t
*dests
) /* I - User-defined destinations */
1081 cups_dest_t
*dest
; /* Destination */
1082 const char *printer
, /* Printer name */
1083 *val
; /* Environment variable name */
1085 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1088 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1089 dest
->name
, dest
->instance
);
1091 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1098 if ((printer
= getenv("LPDEST")) == NULL
)
1100 if ((printer
= getenv("PRINTER")) != NULL
)
1102 if (!strcmp(printer
, "lp"))
1111 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1112 _cupsLangPrintf(stdout
,
1113 _("lpstat: error - %s environment variable names "
1114 "non-existent destination \"%s\"!\n"),
1117 _cupsLangPuts(stdout
, _("no system default destination\n"));
1123 * 'show_devices()' - Show printer devices.
1126 static int /* O - 0 on success, 1 on fail */
1127 show_devices(http_t
*http
, /* I - HTTP connection to server */
1128 const char *printers
, /* I - Destinations */
1129 int num_dests
, /* I - Number of user-defined dests */
1130 cups_dest_t
*dests
) /* I - User-defined destinations */
1132 int i
; /* Looping var */
1133 ipp_t
*request
, /* IPP Request */
1134 *response
; /* IPP Response */
1135 ipp_attribute_t
*attr
; /* Current attribute */
1136 const char *printer
, /* Printer name */
1137 *uri
, /* Printer URI */
1138 *device
, /* Printer device URI */
1139 *dptr
, /* Pointer into destination list */
1140 *ptr
; /* Pointer into printer name */
1141 int match
; /* Non-zero if this job matches */
1142 static const char *pattrs
[] = /* Attributes we need for printers... */
1145 "printer-uri-supported",
1150 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1155 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1159 * Build a CUPS_GET_PRINTERS request, which requires the following
1162 * attributes-charset
1163 * attributes-natural-language
1164 * requested-attributes
1165 * requesting-user-name
1168 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1170 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1171 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1174 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1178 * Do the request and get back a response...
1181 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1183 DEBUG_puts("show_devices: request succeeded...");
1185 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1187 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1188 ippDelete(response
);
1193 * Loop through the printers returned in the list and display
1197 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1200 * Skip leading attributes until we hit a job...
1203 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1210 * Pull the needed attributes from this job...
1217 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1219 if (!strcmp(attr
->name
, "printer-name") &&
1220 attr
->value_tag
== IPP_TAG_NAME
)
1221 printer
= attr
->values
[0].string
.text
;
1223 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1224 attr
->value_tag
== IPP_TAG_URI
)
1225 uri
= attr
->values
[0].string
.text
;
1227 if (!strcmp(attr
->name
, "device-uri") &&
1228 attr
->value_tag
== IPP_TAG_URI
)
1229 device
= attr
->values
[0].string
.text
;
1235 * See if we have everything needed...
1238 if (printer
== NULL
)
1247 * See if this is a printer we're interested in...
1250 match
= printers
== NULL
;
1252 if (printers
!= NULL
)
1254 for (dptr
= printers
; *dptr
!= '\0';)
1257 * Skip leading whitespace and commas...
1260 while (isspace(*dptr
& 255) || *dptr
== ',')
1271 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1274 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1281 * Skip trailing junk...
1284 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1286 while (isspace(*dptr
& 255) || *dptr
== ',')
1295 * Display the printer entry if needed...
1300 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1301 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1302 username
[HTTP_MAX_URI
],
1303 hostname
[HTTP_MAX_URI
],
1304 resource
[HTTP_MAX_URI
];
1310 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1311 username
, sizeof(username
), hostname
,
1312 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1313 _cupsLangPrintf(stdout
,
1314 _("Output for printer %s is sent to remote "
1315 "printer %s on %s\n"),
1316 printer
, strrchr(resource
, '/') + 1, hostname
);
1318 else if (!strncmp(device
, "file:", 5))
1319 _cupsLangPrintf(stdout
,
1320 _("Output for printer %s is sent to %s\n"),
1321 printer
, device
+ 5);
1323 _cupsLangPrintf(stdout
,
1324 _("Output for printer %s is sent to %s\n"),
1327 for (i
= 0; i
< num_dests
; i
++)
1328 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1331 _cupsLangPrintf(stdout
,
1332 _("Output for printer %s/%s is sent to "
1333 "remote printer %s on %s\n"),
1334 printer
, dests
[i
].instance
,
1335 strrchr(resource
, '/') + 1, hostname
);
1336 else if (!strncmp(device
, "file:", 5))
1337 _cupsLangPrintf(stdout
,
1338 _("Output for printer %s/%s is sent to %s\n"),
1339 printer
, dests
[i
].instance
, device
+ 5);
1341 _cupsLangPrintf(stdout
,
1342 _("Output for printer %s/%s is sent to %s\n"),
1343 printer
, dests
[i
].instance
, device
);
1347 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1349 else if (!strncmp(device
, "file:", 5))
1350 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1351 printer
, device
+ 5);
1353 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1356 for (i
= 0; i
< num_dests
; i
++)
1357 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1360 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1361 printer
, dests
[i
].instance
, uri
);
1362 else if (!strncmp(device
, "file:", 5))
1363 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1364 printer
, dests
[i
].instance
, device
+ 5);
1366 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1367 printer
, dests
[i
].instance
, device
);
1369 #endif /* __osf__ */
1376 ippDelete(response
);
1380 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1389 * 'show_jobs()' - Show active print jobs.
1392 static int /* O - 0 on success, 1 on fail */
1393 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1394 const char *dests
, /* I - Destinations */
1395 const char *users
, /* I - Users */
1396 int long_status
, /* I - Show long status? */
1397 int ranking
, /* I - Show job ranking? */
1398 const char *which
) /* I - Show which jobs? */
1400 ipp_t
*request
, /* IPP Request */
1401 *response
; /* IPP Response */
1402 ipp_attribute_t
*attr
; /* Current attribute */
1403 const char *dest
, /* Pointer into job-printer-uri */
1404 *username
, /* Pointer to job-originating-user-name */
1405 *title
; /* Pointer to job-name */
1406 int rank
, /* Rank in queue */
1408 size
; /* job-k-octets */
1409 time_t jobtime
; /* time-at-creation */
1410 struct tm
*jobdate
; /* Date & time */
1411 const char *dptr
, /* Pointer into destination list */
1412 *ptr
; /* Pointer into printer name */
1413 int match
; /* Non-zero if this job matches */
1414 char temp
[255], /* Temporary buffer */
1415 date
[255]; /* Date buffer */
1416 static const char *jattrs
[] = /* Attributes we need for jobs... */
1423 "job-originating-user-name"
1427 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1432 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1436 * Build a IPP_GET_JOBS request, which requires the following
1439 * attributes-charset
1440 * attributes-natural-language
1442 * requested-attributes
1445 request
= ippNewRequest(IPP_GET_JOBS
);
1447 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1448 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1451 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1452 NULL
, "ipp://localhost/jobs/");
1454 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1458 * Do the request and get back a response...
1461 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1464 * Loop through the job list and display them...
1467 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1469 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1470 ippDelete(response
);
1476 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1479 * Skip leading attributes until we hit a job...
1482 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1489 * Pull the needed attributes from this job...
1499 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1501 if (!strcmp(attr
->name
, "job-id") &&
1502 attr
->value_tag
== IPP_TAG_INTEGER
)
1503 jobid
= attr
->values
[0].integer
;
1505 if (!strcmp(attr
->name
, "job-k-octets") &&
1506 attr
->value_tag
== IPP_TAG_INTEGER
)
1507 size
= attr
->values
[0].integer
;
1509 if (!strcmp(attr
->name
, "time-at-creation") &&
1510 attr
->value_tag
== IPP_TAG_INTEGER
)
1511 jobtime
= attr
->values
[0].integer
;
1513 if (!strcmp(attr
->name
, "job-printer-uri") &&
1514 attr
->value_tag
== IPP_TAG_URI
)
1515 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1518 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1519 attr
->value_tag
== IPP_TAG_NAME
)
1520 username
= attr
->values
[0].string
.text
;
1522 if (!strcmp(attr
->name
, "job-name") &&
1523 attr
->value_tag
== IPP_TAG_NAME
)
1524 title
= attr
->values
[0].string
.text
;
1530 * See if we have everything needed...
1533 if (dest
== NULL
|| jobid
== 0)
1542 * See if this is a job we're interested in...
1545 match
= (dests
== NULL
&& users
== NULL
);
1550 for (dptr
= dests
; *dptr
!= '\0';)
1553 * Skip leading whitespace and commas...
1556 while (isspace(*dptr
& 255) || *dptr
== ',')
1567 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1570 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1577 * Skip trailing junk...
1580 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1582 while (isspace(*dptr
& 255) || *dptr
== ',')
1590 if (users
!= NULL
&& username
!= NULL
)
1592 for (dptr
= users
; *dptr
!= '\0';)
1595 * Skip leading whitespace and commas...
1598 while (isspace(*dptr
& 255) || *dptr
== ',')
1608 for (ptr
= username
;
1609 *ptr
!= '\0' && *dptr
!= '\0' && *ptr
== *dptr
;
1612 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1619 * Skip trailing junk...
1622 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1624 while (isspace(*dptr
& 255) || *dptr
== ',')
1633 * Display the job...
1638 jobdate
= localtime(&jobtime
);
1639 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1641 if (long_status
== 3)
1644 * Show the consolidated output format for the SGI tools...
1647 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1648 strcpy(date
, "Unknown");
1650 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s\n",
1651 temp
, username
? username
: "unknown",
1652 size
, title
? title
: "unknown", date
);
1656 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1657 strcpy(date
, "Unknown");
1660 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s\n",
1661 rank
, temp
, username
? username
: "unknown",
1662 1024.0 * size
, date
);
1664 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s\n",
1665 temp
, username
? username
: "unknown",
1666 1024.0 * size
, date
);
1668 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1676 ippDelete(response
);
1680 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1689 * 'show_printers()' - Show printers.
1692 static int /* O - 0 on success, 1 on fail */
1693 show_printers(http_t
*http
, /* I - HTTP connection to server */
1694 const char *printers
, /* I - Destinations */
1695 int num_dests
, /* I - Number of user-defined dests */
1696 cups_dest_t
*dests
, /* I - User-defined destinations */
1697 int long_status
) /* I - Show long status? */
1699 int i
, j
; /* Looping vars */
1700 ipp_t
*request
, /* IPP Request */
1701 *response
, /* IPP Response */
1702 *jobs
; /* IPP Get Jobs response */
1703 ipp_attribute_t
*attr
, /* Current attribute */
1704 *jobattr
, /* Job ID attribute */
1705 *reasons
; /* Job state reasons attribute */
1706 const char *printer
, /* Printer name */
1707 *message
, /* Printer state message */
1708 *description
, /* Description of printer */
1709 *location
, /* Location of printer */
1710 *make_model
, /* Make and model of printer */
1711 *uri
; /* URI of printer */
1712 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1713 *denied
; /* requestint-user-name-denied */
1714 ipp_pstate_t pstate
; /* Printer state */
1715 cups_ptype_t ptype
; /* Printer type */
1716 time_t ptime
; /* Printer state time */
1717 struct tm
*pdate
; /* Printer state date & time */
1718 int jobid
; /* Job ID of current job */
1719 const char *dptr
, /* Pointer into destination list */
1720 *ptr
; /* Pointer into printer name */
1721 int match
; /* Non-zero if this job matches */
1722 char printer_uri
[HTTP_MAX_URI
],
1724 printer_state_time
[255];/* Printer state time */
1725 const char *root
; /* Server root directory... */
1726 static const char *pattrs
[] = /* Attributes we need for printers... */
1730 "printer-state-message",
1731 "printer-state-reasons",
1732 "printer-state-change-time",
1736 "printer-make-and-model",
1737 "printer-uri-supported",
1738 "requesting-user-name-allowed",
1739 "requesting-user-name-denied"
1741 static const char *jattrs
[] = /* Attributes we need for jobs... */
1747 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1752 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1753 root
= CUPS_SERVERROOT
;
1755 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1759 * Build a CUPS_GET_PRINTERS request, which requires the following
1762 * attributes-charset
1763 * attributes-natural-language
1764 * requested-attributes
1765 * requesting-user-name
1768 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1770 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1771 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1774 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1778 * Do the request and get back a response...
1781 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1783 DEBUG_puts("show_printers: request succeeded...");
1785 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1787 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1788 ippDelete(response
);
1793 * Loop through the printers returned in the list and display
1797 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1800 * Skip leading attributes until we hit a job...
1803 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1810 * Pull the needed attributes from this job...
1815 ptype
= CUPS_PRINTER_LOCAL
;
1816 pstate
= IPP_PRINTER_IDLE
;
1827 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1829 if (!strcmp(attr
->name
, "printer-name") &&
1830 attr
->value_tag
== IPP_TAG_NAME
)
1831 printer
= attr
->values
[0].string
.text
;
1832 else if (!strcmp(attr
->name
, "printer-state") &&
1833 attr
->value_tag
== IPP_TAG_ENUM
)
1834 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1835 else if (!strcmp(attr
->name
, "printer-type") &&
1836 attr
->value_tag
== IPP_TAG_ENUM
)
1837 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1838 else if (!strcmp(attr
->name
, "printer-state-message") &&
1839 attr
->value_tag
== IPP_TAG_TEXT
)
1840 message
= attr
->values
[0].string
.text
;
1841 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1842 attr
->value_tag
== IPP_TAG_INTEGER
)
1843 ptime
= (time_t)attr
->values
[0].integer
;
1844 else if (!strcmp(attr
->name
, "printer-info") &&
1845 attr
->value_tag
== IPP_TAG_TEXT
)
1846 description
= attr
->values
[0].string
.text
;
1847 else if (!strcmp(attr
->name
, "printer-location") &&
1848 attr
->value_tag
== IPP_TAG_TEXT
)
1849 location
= attr
->values
[0].string
.text
;
1850 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1851 attr
->value_tag
== IPP_TAG_TEXT
)
1852 make_model
= attr
->values
[0].string
.text
;
1853 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1854 attr
->value_tag
== IPP_TAG_URI
)
1855 uri
= attr
->values
[0].string
.text
;
1856 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1857 attr
->value_tag
== IPP_TAG_KEYWORD
)
1859 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1860 attr
->value_tag
== IPP_TAG_NAME
)
1862 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1863 attr
->value_tag
== IPP_TAG_NAME
)
1870 * See if we have everything needed...
1873 if (printer
== NULL
)
1882 * See if this is a printer we're interested in...
1885 match
= printers
== NULL
;
1887 if (printers
!= NULL
)
1889 for (dptr
= printers
; *dptr
!= '\0';)
1892 * Skip leading whitespace and commas...
1895 while (isspace(*dptr
& 255) || *dptr
== ',')
1906 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1909 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1916 * Skip trailing junk...
1919 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1921 while (isspace(*dptr
& 255) || *dptr
== ',')
1930 * Display the printer entry if needed...
1936 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1937 * current job for the printer.
1940 if (pstate
== IPP_PRINTER_PROCESSING
)
1943 * Build an IPP_GET_JOBS request, which requires the following
1946 * attributes-charset
1947 * attributes-natural-language
1950 * requested-attributes
1953 request
= ippNewRequest(IPP_GET_JOBS
);
1955 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1956 request
->request
.op
.request_id
= 1;
1958 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1959 "requested-attributes",
1960 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1962 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1963 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1964 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1965 "printer-uri", NULL
, printer_uri
);
1967 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
1970 * Get the current active job on this queue...
1975 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1980 if (!strcmp(jobattr
->name
, "job-id") &&
1981 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1982 jobid
= jobattr
->values
[0].integer
;
1983 else if (!strcmp(jobattr
->name
, "job-state") &&
1984 jobattr
->value_tag
== IPP_TAG_ENUM
&&
1985 jobattr
->values
[0].integer
== IPP_JOB_PROCESSING
)
1997 pdate
= localtime(&ptime
);
1998 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
2002 case IPP_PRINTER_IDLE
:
2003 _cupsLangPrintf(stdout
,
2004 _("printer %s is idle. enabled since %s\n"),
2005 printer
, printer_state_time
);
2007 case IPP_PRINTER_PROCESSING
:
2008 _cupsLangPrintf(stdout
,
2009 _("printer %s now printing %s-%d. "
2010 "enabled since %s\n"),
2011 printer
, printer
, jobid
, printer_state_time
);
2013 case IPP_PRINTER_STOPPED
:
2014 _cupsLangPrintf(stdout
,
2015 _("printer %s disabled since %s -\n"),
2016 printer
, printer_state_time
);
2020 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2022 if (!message
|| !*message
)
2023 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2025 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2028 if (long_status
> 1)
2029 _cupsLangPuts(stdout
,
2030 _("\tForm mounted:\n"
2031 "\tContent types: any\n"
2032 "\tPrinter types: unknown\n"));
2036 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2037 description
? description
: "");
2041 _cupsLangPuts(stdout
, _("\tAlerts:"));
2042 for (j
= 0; j
< reasons
->num_values
; j
++)
2043 _cupsLangPrintf(stdout
, " %s",
2044 reasons
->values
[j
].string
.text
);
2045 _cupsLangPuts(stdout
, "\n");
2048 if (long_status
> 1)
2050 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2051 location
? location
: "");
2053 if (ptype
& CUPS_PRINTER_REMOTE
)
2055 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2057 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2058 !strstr(make_model
, "Raw Printer") && uri
)
2059 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2064 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2066 if (make_model
&& strstr(make_model
, "System V Printer"))
2067 _cupsLangPrintf(stdout
,
2068 _("\tInterface: %s/interfaces/%s\n"),
2070 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2071 _cupsLangPrintf(stdout
,
2072 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2074 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2075 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2076 /* TODO update to use printer-error-policy */
2079 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2080 for (j
= 0; j
< allowed
->num_values
; j
++)
2081 _cupsLangPrintf(stdout
, "\t\t%s\n",
2082 allowed
->values
[j
].string
.text
);
2086 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2087 for (j
= 0; j
< denied
->num_values
; j
++)
2088 _cupsLangPrintf(stdout
, "\t\t%s\n",
2089 denied
->values
[j
].string
.text
);
2093 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2094 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2096 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2097 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2098 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2099 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2100 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2101 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2102 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2103 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2106 for (i
= 0; i
< num_dests
; i
++)
2107 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2111 case IPP_PRINTER_IDLE
:
2112 _cupsLangPrintf(stdout
,
2113 _("printer %s/%s is idle. "
2114 "enabled since %s\n"),
2115 printer
, dests
[i
].instance
,
2116 printer_state_time
);
2118 case IPP_PRINTER_PROCESSING
:
2119 _cupsLangPrintf(stdout
,
2120 _("printer %s/%s now printing %s-%d. "
2121 "enabled since %s\n"),
2122 printer
, dests
[i
].instance
, printer
, jobid
,
2123 printer_state_time
);
2125 case IPP_PRINTER_STOPPED
:
2126 _cupsLangPrintf(stdout
,
2127 _("printer %s/%s disabled since %s -\n"),
2128 printer
, dests
[i
].instance
,
2129 printer_state_time
);
2133 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2135 if (!message
|| !*message
)
2136 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2138 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2141 if (long_status
> 1)
2142 _cupsLangPuts(stdout
,
2143 _("\tForm mounted:\n"
2144 "\tContent types: any\n"
2145 "\tPrinter types: unknown\n"));
2149 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2150 description
? description
: "");
2154 _cupsLangPuts(stdout
, _("\tAlerts:"));
2155 for (j
= 0; j
< reasons
->num_values
; j
++)
2156 _cupsLangPrintf(stdout
, " %s",
2157 reasons
->values
[j
].string
.text
);
2158 _cupsLangPuts(stdout
, "\n");
2161 if (long_status
> 1)
2163 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2164 location
? location
: "");
2166 if (ptype
& CUPS_PRINTER_REMOTE
)
2168 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2170 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2171 !strstr(make_model
, "Raw Printer") && uri
)
2172 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2177 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2179 if (make_model
&& strstr(make_model
, "System V Printer"))
2180 _cupsLangPrintf(stdout
,
2181 _("\tInterface: %s/interfaces/%s\n"),
2183 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2184 _cupsLangPrintf(stdout
,
2185 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2187 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2188 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2189 /* TODO update to use printer-error-policy */
2192 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2193 for (j
= 0; j
< allowed
->num_values
; j
++)
2194 _cupsLangPrintf(stdout
, "\t\t%s\n",
2195 allowed
->values
[j
].string
.text
);
2199 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2200 for (j
= 0; j
< denied
->num_values
; j
++)
2201 _cupsLangPrintf(stdout
, "\t\t%s\n",
2202 denied
->values
[j
].string
.text
);
2206 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2207 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2209 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2210 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2211 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2212 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2213 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2214 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2215 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2216 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2225 ippDelete(response
);
2229 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2238 * 'show_scheduler()' - Show scheduler status.
2242 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2245 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2247 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2252 * End of "$Id: lpstat.c 6084 2006-11-14 14:35:53Z mike $".