2 * "$Id: lpstat.c 5023 2006-01-29 14:39:44Z 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 setlocale(LC_TIME
, "");
97 which
= "not-completed";
100 for (i
= 1; i
< argc
; i
++)
101 if (argv
[i
][0] == '-')
104 case 'D' : /* Show description */
108 case 'E' : /* Encrypt */
110 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
113 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
115 _cupsLangPrintf(stderr
,
116 _("%s: Sorry, no encryption support compiled in!\n"),
118 #endif /* HAVE_SSL */
121 case 'P' : /* Show paper types */
125 case 'R' : /* Show ranking */
129 case 'S' : /* Show charsets */
135 case 'U' : /* Username */
136 if (argv
[i
][2] != '\0')
137 cupsSetUser(argv
[i
] + 2);
143 _cupsLangPrintf(stderr
,
144 _("%s: Error - expected username after "
150 cupsSetUser(argv
[i
]);
154 case 'W' : /* Show which jobs? */
163 _cupsLangPrintf(stderr
,
164 _("%s: Error - need \"completed\", "
165 "\"not-completed\", or \"all\" after "
174 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
175 strcmp(which
, "all"))
177 _cupsLangPrintf(stderr
,
178 _("%s: Error - need \"completed\", "
179 "\"not-completed\", or \"all\" after "
186 case 'a' : /* Show acceptance status */
188 http
= connect_server(argv
[0], http
);
190 if (argv
[i
][2] != '\0')
192 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
194 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
196 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
200 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
202 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
207 num_dests
= cupsGetDests2(http
, &dests
);
209 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
214 case 'b' : /* Show both the local and remote status */
216 http
= connect_server(argv
[0], http
);
218 if (argv
[i
][2] != '\0')
221 * The local and remote status are separated by a blank line;
222 * since all CUPS jobs are networked, we only output the
223 * second list for now... In the future, we might further
224 * emulate this by listing the remote server's queue, but
225 * for now this is enough to make the SGI printstatus program
229 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
232 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
236 _cupsLangPuts(stderr
,
237 _("%s: Error - expected destination after "
246 case 'c' : /* Show classes and members */
248 http
= connect_server(argv
[0], http
);
250 if (argv
[i
][2] != '\0')
252 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
254 status
|= show_classes(http
, argv
[i
] + 2);
256 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
260 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
262 status
|= show_classes(http
, argv
[i
]);
265 status
|= show_classes(http
, NULL
);
268 case 'd' : /* Show default destination */
270 http
= connect_server(argv
[0], http
);
273 num_dests
= cupsGetDests2(http
, &dests
);
275 show_default(num_dests
, dests
);
278 case 'f' : /* Show forms */
284 case 'h' : /* Connect to host */
291 if (argv
[i
][2] != '\0')
292 cupsSetServer(argv
[i
] + 2);
299 _cupsLangPrintf(stderr
,
300 _("%s: Error - expected hostname after "
306 cupsSetServer(argv
[i
]);
310 case 'l' : /* Long status or long job status */
313 http
= connect_server(argv
[0], http
);
315 if (argv
[i
][2] != '\0')
317 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
319 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
326 case 'o' : /* Show jobs by destination */
328 http
= connect_server(argv
[0], http
);
330 if (argv
[i
][2] != '\0')
332 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
334 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
337 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
341 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
343 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
347 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
351 case 'p' : /* Show printers */
353 http
= connect_server(argv
[0], http
);
355 if (argv
[i
][2] != '\0')
357 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
359 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
361 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
365 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
367 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
372 num_dests
= cupsGetDests2(http
, &dests
);
374 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
378 case 'r' : /* Show scheduler status */
380 http
= connect_server(argv
[0], http
);
382 show_scheduler(http
);
385 case 's' : /* Show summary */
387 http
= connect_server(argv
[0], http
);
390 num_dests
= cupsGetDests2(http
, &dests
);
392 show_default(num_dests
, dests
);
393 status
|= show_classes(http
, NULL
);
394 status
|= show_devices(http
, NULL
, num_dests
, dests
);
397 case 't' : /* Show all info */
399 http
= connect_server(argv
[0], http
);
402 num_dests
= cupsGetDests2(http
, &dests
);
404 show_scheduler(http
);
405 show_default(num_dests
, dests
);
406 status
|= show_classes(http
, NULL
);
407 status
|= show_devices(http
, NULL
, num_dests
, dests
);
408 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
409 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
410 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
413 case 'u' : /* Show jobs by user */
415 http
= connect_server(argv
[0], http
);
417 if (argv
[i
][2] != '\0')
418 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
420 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
423 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
427 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
431 case 'v' : /* Show printer devices */
433 http
= connect_server(argv
[0], http
);
435 if (argv
[i
][2] != '\0')
437 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
439 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
441 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
445 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
447 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
452 num_dests
= cupsGetDests2(http
, &dests
);
454 status
|= show_devices(http
, NULL
, num_dests
, dests
);
460 _cupsLangPrintf(stderr
,
461 _("%s: Error - unknown option \'%c\'!\n"),
462 argv
[0], argv
[i
][1]);
467 http
= connect_server(argv
[0], http
);
469 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
475 http
= connect_server(argv
[0], http
);
477 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
485 * 'check_dest()' - Verify that the named destination(s) exists.
489 check_dest(const char *command
, /* I - Command name */
490 http_t
*http
, /* I - HTTP connection */
491 const char *name
, /* I - Name of printer/class(es) */
492 int *num_dests
, /* IO - Number of destinations */
493 cups_dest_t
**dests
) /* IO - Destinations */
501 * Load the destination list as necessary...
505 *num_dests
= cupsGetDests2(http
, dests
);
508 * Scan the name string for printer/class name(s)...
511 for (dptr
= name
; *dptr
!= '\0';)
514 * Skip leading whitespace and commas...
517 while (isspace(*dptr
& 255) || *dptr
== ',')
524 * Extract a single destination name from the name string...
527 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
529 if ((pptr
- printer
) < (sizeof(printer
) - 1))
533 _cupsLangPrintf(stderr
,
534 _("%s: Invalid destination name in list \"%s\"!\n"),
543 * Check the destination...
546 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
548 _cupsLangPrintf(stderr
,
549 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
557 * 'connect_server()' - Connect to the server as necessary...
560 static http_t
* /* O - New HTTP connection */
561 connect_server(const char *command
, /* I - Command name */
562 http_t
*http
) /* I - Current HTTP connection */
566 http
= httpConnectEncrypt(cupsServer(), ippPort(),
571 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
581 * 'show_accepting()' - Show acceptance status.
584 static int /* O - 0 on success, 1 on fail */
585 show_accepting(http_t
*http
, /* I - HTTP connection to server */
586 const char *printers
, /* I - Destinations */
587 int num_dests
, /* I - Number of user-defined dests */
588 cups_dest_t
*dests
) /* I - User-defined destinations */
590 int i
; /* Looping var */
591 ipp_t
*request
, /* IPP Request */
592 *response
; /* IPP Response */
593 ipp_attribute_t
*attr
; /* Current attribute */
594 const char *printer
, /* Printer name */
595 *message
; /* Printer device URI */
596 int accepting
; /* Accepting requests? */
597 time_t ptime
; /* Printer state time */
598 struct tm
*pdate
; /* Printer state date & time */
599 char printer_state_time
[255];/* Printer state time */
600 const char *dptr
, /* Pointer into destination list */
601 *ptr
; /* Pointer into printer name */
602 int match
; /* Non-zero if this job matches */
603 static const char *pattrs
[] = /* Attributes we need for printers... */
606 "printer-state-change-time",
607 "printer-state-message",
608 "printer-is-accepting-jobs"
612 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
617 if (printers
!= NULL
&& !strcmp(printers
, "all"))
621 * Build a CUPS_GET_PRINTERS request, which requires the following
625 * attributes-natural-language
626 * requested-attributes
627 * requesting-user-name
630 request
= ippNewRequest(CUPS_GET_PRINTERS
);
632 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
633 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
636 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
640 * Do the request and get back a response...
643 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
645 DEBUG_puts("show_accepting: request succeeded...");
647 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
649 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
655 * Loop through the printers returned in the list and display
659 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
662 * Skip leading attributes until we hit a printer...
665 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
672 * Pull the needed attributes from this printer...
680 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
682 if (!strcmp(attr
->name
, "printer-name") &&
683 attr
->value_tag
== IPP_TAG_NAME
)
684 printer
= attr
->values
[0].string
.text
;
685 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
686 attr
->value_tag
== IPP_TAG_INTEGER
)
687 ptime
= (time_t)attr
->values
[0].integer
;
688 else if (!strcmp(attr
->name
, "printer-state-message") &&
689 attr
->value_tag
== IPP_TAG_TEXT
)
690 message
= attr
->values
[0].string
.text
;
691 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
692 attr
->value_tag
== IPP_TAG_BOOLEAN
)
693 accepting
= attr
->values
[0].boolean
;
699 * See if we have everything needed...
711 * See if this is a printer we're interested in...
714 match
= printers
== NULL
;
716 if (printers
!= NULL
)
718 for (dptr
= printers
; *dptr
!= '\0';)
721 * Skip leading whitespace and commas...
724 while (isspace(*dptr
& 255) || *dptr
== ',')
735 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
738 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
745 * Skip trailing junk...
748 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
750 while (isspace(*dptr
& 255) || *dptr
== ',')
759 * Display the printer entry if needed...
764 pdate
= localtime(&ptime
);
765 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
768 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
769 printer
, printer_state_time
);
771 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
773 printer
, printer_state_time
,
774 message
== NULL
? "reason unknown" : message
);
776 for (i
= 0; i
< num_dests
; i
++)
777 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
780 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
781 printer
, dests
[i
].instance
, printer_state_time
);
783 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
785 printer
, dests
[i
].instance
, printer_state_time
,
786 message
== NULL
? "reason unknown" : message
);
798 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
807 * 'show_classes()' - Show printer classes.
810 static int /* O - 0 on success, 1 on fail */
811 show_classes(http_t
*http
, /* I - HTTP connection to server */
812 const char *dests
) /* I - Destinations */
814 int i
; /* Looping var */
815 ipp_t
*request
, /* IPP Request */
816 *response
, /* IPP Response */
817 *response2
; /* IPP response from remote server */
818 http_t
*http2
; /* Remote server */
819 ipp_attribute_t
*attr
; /* Current attribute */
820 const char *printer
, /* Printer class name */
821 *printer_uri
; /* Printer class URI */
822 ipp_attribute_t
*members
; /* Printer members */
823 char method
[HTTP_MAX_URI
], /* Request method */
824 username
[HTTP_MAX_URI
], /* Username:password */
825 server
[HTTP_MAX_URI
], /* Server name */
826 resource
[HTTP_MAX_URI
]; /* Resource name */
827 int port
; /* Port number */
828 const char *dptr
, /* Pointer into destination list */
829 *ptr
; /* Pointer into printer name */
830 int match
; /* Non-zero if this job matches */
831 static const char *cattrs
[] = /* Attributes we need for classes... */
834 "printer-uri-supported",
839 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
844 if (dests
!= NULL
&& !strcmp(dests
, "all"))
848 * Build a CUPS_GET_CLASSES request, which requires the following
852 * attributes-natural-language
853 * requested-attributes
854 * requesting-user-name
857 request
= ippNewRequest(CUPS_GET_CLASSES
);
859 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
860 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
863 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
867 * Do the request and get back a response...
870 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
872 DEBUG_puts("show_classes: request succeeded...");
874 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
876 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
882 * Loop through the printers returned in the list and display
886 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
889 * Skip leading attributes until we hit a job...
892 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
899 * Pull the needed attributes from this job...
906 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
908 if (!strcmp(attr
->name
, "printer-name") &&
909 attr
->value_tag
== IPP_TAG_NAME
)
910 printer
= attr
->values
[0].string
.text
;
912 if (!strcmp(attr
->name
, "printer-uri-supported") &&
913 attr
->value_tag
== IPP_TAG_URI
)
914 printer_uri
= attr
->values
[0].string
.text
;
916 if (!strcmp(attr
->name
, "member-names") &&
917 attr
->value_tag
== IPP_TAG_NAME
)
924 * If this is a remote class, grab the class info from the
929 if (members
== NULL
&& printer_uri
!= NULL
)
931 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
932 username
, sizeof(username
), server
, sizeof(server
),
933 &port
, resource
, sizeof(resource
));
935 if (!strcasecmp(server
, http
->hostname
))
938 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
943 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
944 * following attributes:
947 * attributes-natural-language
949 * requested-attributes
952 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
954 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
955 "printer-uri", NULL
, printer_uri
);
957 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
958 "requested-attributes",
959 sizeof(cattrs
) / sizeof(cattrs
[0]),
962 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
963 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
971 * See if we have everything needed...
977 ippDelete(response2
);
986 * See if this is a printer we're interested in...
989 match
= dests
== NULL
;
993 for (dptr
= dests
; *dptr
!= '\0';)
996 * Skip leading whitespace and commas...
999 while (isspace(*dptr
& 255) || *dptr
== ',')
1010 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1013 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1020 * Skip trailing junk...
1023 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1025 while (isspace(*dptr
& 255) || *dptr
== ',')
1034 * Display the printer entry if needed...
1039 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1043 for (i
= 0; i
< members
->num_values
; i
++)
1044 _cupsLangPrintf(stdout
, "\t%s\n",
1045 members
->values
[i
].string
.text
);
1048 _cupsLangPuts(stdout
, "\tunknown\n");
1052 ippDelete(response2
);
1058 ippDelete(response
);
1062 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1071 * 'show_default()' - Show default destination.
1075 show_default(int num_dests
, /* I - Number of user-defined dests */
1076 cups_dest_t
*dests
) /* I - User-defined destinations */
1078 cups_dest_t
*dest
; /* Destination */
1079 const char *printer
, /* Printer name */
1080 *val
; /* Environment variable name */
1082 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1085 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1086 dest
->name
, dest
->instance
);
1088 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1095 if ((printer
= getenv("LPDEST")) == NULL
)
1097 if ((printer
= getenv("PRINTER")) != NULL
)
1099 if (!strcmp(printer
, "lp"))
1108 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1109 _cupsLangPrintf(stdout
,
1110 _("lpstat: error - %s environment variable names "
1111 "non-existent destination \"%s\"!\n"),
1114 _cupsLangPuts(stdout
, _("no system default destination\n"));
1120 * 'show_devices()' - Show printer devices.
1123 static int /* O - 0 on success, 1 on fail */
1124 show_devices(http_t
*http
, /* I - HTTP connection to server */
1125 const char *printers
, /* I - Destinations */
1126 int num_dests
, /* I - Number of user-defined dests */
1127 cups_dest_t
*dests
) /* I - User-defined destinations */
1129 int i
; /* Looping var */
1130 ipp_t
*request
, /* IPP Request */
1131 *response
; /* IPP Response */
1132 ipp_attribute_t
*attr
; /* Current attribute */
1133 const char *printer
, /* Printer name */
1134 *uri
, /* Printer URI */
1135 *device
, /* Printer device URI */
1136 *dptr
, /* Pointer into destination list */
1137 *ptr
; /* Pointer into printer name */
1138 int match
; /* Non-zero if this job matches */
1139 static const char *pattrs
[] = /* Attributes we need for printers... */
1142 "printer-uri-supported",
1147 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1152 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1156 * Build a CUPS_GET_PRINTERS request, which requires the following
1159 * attributes-charset
1160 * attributes-natural-language
1161 * requested-attributes
1162 * requesting-user-name
1165 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1167 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1168 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1171 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1175 * Do the request and get back a response...
1178 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1180 DEBUG_puts("show_devices: request succeeded...");
1182 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1184 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1185 ippDelete(response
);
1190 * Loop through the printers returned in the list and display
1194 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1197 * Skip leading attributes until we hit a job...
1200 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1207 * Pull the needed attributes from this job...
1214 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1216 if (!strcmp(attr
->name
, "printer-name") &&
1217 attr
->value_tag
== IPP_TAG_NAME
)
1218 printer
= attr
->values
[0].string
.text
;
1220 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1221 attr
->value_tag
== IPP_TAG_URI
)
1222 uri
= attr
->values
[0].string
.text
;
1224 if (!strcmp(attr
->name
, "device-uri") &&
1225 attr
->value_tag
== IPP_TAG_URI
)
1226 device
= attr
->values
[0].string
.text
;
1232 * See if we have everything needed...
1235 if (printer
== NULL
)
1244 * See if this is a printer we're interested in...
1247 match
= printers
== NULL
;
1249 if (printers
!= NULL
)
1251 for (dptr
= printers
; *dptr
!= '\0';)
1254 * Skip leading whitespace and commas...
1257 while (isspace(*dptr
& 255) || *dptr
== ',')
1268 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1271 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1278 * Skip trailing junk...
1281 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1283 while (isspace(*dptr
& 255) || *dptr
== ',')
1292 * Display the printer entry if needed...
1297 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1298 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1299 username
[HTTP_MAX_URI
],
1300 hostname
[HTTP_MAX_URI
],
1301 resource
[HTTP_MAX_URI
];
1307 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1308 username
, sizeof(username
), hostname
,
1309 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1310 _cupsLangPrintf(stdout
,
1311 _("Output for printer %s is sent to remote "
1312 "printer %s on %s\n"),
1313 printer
, strrchr(resource
, '/') + 1, hostname
);
1315 else if (!strncmp(device
, "file:", 5))
1316 _cupsLangPrintf(stdout
,
1317 _("Output for printer %s is sent to %s\n"),
1318 printer
, device
+ 5);
1320 _cupsLangPrintf(stdout
,
1321 _("Output for printer %s is sent to %s\n"),
1324 for (i
= 0; i
< num_dests
; i
++)
1325 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1328 _cupsLangPrintf(stdout
,
1329 _("Output for printer %s/%s is sent to "
1330 "remote printer %s on %s\n"),
1331 printer
, dests
[i
].instance
,
1332 strrchr(resource
, '/') + 1, hostname
);
1333 else if (!strncmp(device
, "file:", 5))
1334 _cupsLangPrintf(stdout
,
1335 _("Output for printer %s/%s is sent to %s\n"),
1336 printer
, dests
[i
].instance
, device
+ 5);
1338 _cupsLangPrintf(stdout
,
1339 _("Output for printer %s/%s is sent to %s\n"),
1340 printer
, dests
[i
].instance
, device
);
1344 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1346 else if (!strncmp(device
, "file:", 5))
1347 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1348 printer
, device
+ 5);
1350 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1353 for (i
= 0; i
< num_dests
; i
++)
1354 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1357 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1358 printer
, dests
[i
].instance
, uri
);
1359 else if (!strncmp(device
, "file:", 5))
1360 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1361 printer
, dests
[i
].instance
, device
+ 5);
1363 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1364 printer
, dests
[i
].instance
, device
);
1366 #endif /* __osf__ */
1373 ippDelete(response
);
1377 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1386 * 'show_jobs()' - Show active print jobs.
1389 static int /* O - 0 on success, 1 on fail */
1390 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1391 const char *dests
, /* I - Destinations */
1392 const char *users
, /* I - Users */
1393 int long_status
, /* I - Show long status? */
1394 int ranking
, /* I - Show job ranking? */
1395 const char *which
) /* I - Show which jobs? */
1397 ipp_t
*request
, /* IPP Request */
1398 *response
; /* IPP Response */
1399 ipp_attribute_t
*attr
; /* Current attribute */
1400 const char *dest
, /* Pointer into job-printer-uri */
1401 *username
, /* Pointer to job-originating-user-name */
1402 *title
; /* Pointer to job-name */
1403 int rank
, /* Rank in queue */
1405 size
; /* job-k-octets */
1406 time_t jobtime
; /* time-at-creation */
1407 struct tm
*jobdate
; /* Date & time */
1408 const char *dptr
, /* Pointer into destination list */
1409 *ptr
; /* Pointer into printer name */
1410 int match
; /* Non-zero if this job matches */
1411 char temp
[255], /* Temporary buffer */
1412 date
[255]; /* Date buffer */
1413 static const char *jattrs
[] = /* Attributes we need for jobs... */
1420 "job-originating-user-name"
1424 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1429 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1433 * Build a IPP_GET_JOBS request, which requires the following
1436 * attributes-charset
1437 * attributes-natural-language
1439 * requested-attributes
1442 request
= ippNewRequest(IPP_GET_JOBS
);
1444 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1445 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1448 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1449 NULL
, "ipp://localhost/jobs/");
1451 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1455 * Do the request and get back a response...
1458 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1461 * Loop through the job list and display them...
1464 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1466 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1467 ippDelete(response
);
1473 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1476 * Skip leading attributes until we hit a job...
1479 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1486 * Pull the needed attributes from this job...
1496 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1498 if (!strcmp(attr
->name
, "job-id") &&
1499 attr
->value_tag
== IPP_TAG_INTEGER
)
1500 jobid
= attr
->values
[0].integer
;
1502 if (!strcmp(attr
->name
, "job-k-octets") &&
1503 attr
->value_tag
== IPP_TAG_INTEGER
)
1504 size
= attr
->values
[0].integer
;
1506 if (!strcmp(attr
->name
, "time-at-creation") &&
1507 attr
->value_tag
== IPP_TAG_INTEGER
)
1508 jobtime
= attr
->values
[0].integer
;
1510 if (!strcmp(attr
->name
, "job-printer-uri") &&
1511 attr
->value_tag
== IPP_TAG_URI
)
1512 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1515 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1516 attr
->value_tag
== IPP_TAG_NAME
)
1517 username
= attr
->values
[0].string
.text
;
1519 if (!strcmp(attr
->name
, "job-name") &&
1520 attr
->value_tag
== IPP_TAG_NAME
)
1521 title
= attr
->values
[0].string
.text
;
1527 * See if we have everything needed...
1530 if (dest
== NULL
|| jobid
== 0)
1539 * See if this is a job we're interested in...
1542 match
= (dests
== NULL
&& users
== NULL
);
1547 for (dptr
= dests
; *dptr
!= '\0';)
1550 * Skip leading whitespace and commas...
1553 while (isspace(*dptr
& 255) || *dptr
== ',')
1564 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1567 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1574 * Skip trailing junk...
1577 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1579 while (isspace(*dptr
& 255) || *dptr
== ',')
1587 if (users
!= NULL
&& username
!= NULL
)
1589 for (dptr
= users
; *dptr
!= '\0';)
1592 * Skip leading whitespace and commas...
1595 while (isspace(*dptr
& 255) || *dptr
== ',')
1605 for (ptr
= username
;
1606 *ptr
!= '\0' && *dptr
!= '\0' && *ptr
== *dptr
;
1609 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1616 * Skip trailing junk...
1619 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1621 while (isspace(*dptr
& 255) || *dptr
== ',')
1630 * Display the job...
1635 jobdate
= localtime(&jobtime
);
1636 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1638 if (long_status
== 3)
1641 * Show the consolidated output format for the SGI tools...
1644 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1645 strcpy(date
, "Unknown");
1647 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s\n",
1648 temp
, username
? username
: "unknown",
1649 size
, title
? title
: "unknown", date
);
1653 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1654 strcpy(date
, "Unknown");
1657 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s\n",
1658 rank
, temp
, username
? username
: "unknown",
1659 1024.0 * size
, date
);
1661 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s\n",
1662 temp
, username
? username
: "unknown",
1663 1024.0 * size
, date
);
1665 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1673 ippDelete(response
);
1677 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1686 * 'show_printers()' - Show printers.
1689 static int /* O - 0 on success, 1 on fail */
1690 show_printers(http_t
*http
, /* I - HTTP connection to server */
1691 const char *printers
, /* I - Destinations */
1692 int num_dests
, /* I - Number of user-defined dests */
1693 cups_dest_t
*dests
, /* I - User-defined destinations */
1694 int long_status
) /* I - Show long status? */
1696 int i
; /* Looping var */
1697 ipp_t
*request
, /* IPP Request */
1698 *response
, /* IPP Response */
1699 *jobs
; /* IPP Get Jobs response */
1700 ipp_attribute_t
*attr
, /* Current attribute */
1701 *jobattr
, /* Job ID attribute */
1702 *reasons
; /* Job state reasons attribute */
1703 const char *printer
, /* Printer name */
1704 *message
, /* Printer state message */
1705 *description
, /* Description of printer */
1706 *location
, /* Location of printer */
1707 *make_model
, /* Make and model of printer */
1708 *uri
; /* URI of printer */
1709 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1710 *denied
; /* requestint-user-name-denied */
1711 ipp_pstate_t pstate
; /* Printer state */
1712 cups_ptype_t ptype
; /* Printer type */
1713 time_t ptime
; /* Printer state time */
1714 struct tm
*pdate
; /* Printer state date & time */
1715 int jobid
; /* Job ID of current job */
1716 const char *dptr
, /* Pointer into destination list */
1717 *ptr
; /* Pointer into printer name */
1718 int match
; /* Non-zero if this job matches */
1719 char printer_uri
[HTTP_MAX_URI
],
1721 printer_state_time
[255];/* Printer state time */
1722 const char *root
; /* Server root directory... */
1723 static const char *pattrs
[] = /* Attributes we need for printers... */
1727 "printer-state-message",
1728 "printer-state-reasons",
1729 "printer-state-change-time",
1733 "printer-make-and-model",
1734 "printer-uri-supported",
1735 "requesting-user-name-allowed",
1736 "requesting-user-name-denied"
1738 static const char *jattrs
[] = /* Attributes we need for jobs... */
1744 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1749 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1750 root
= CUPS_SERVERROOT
;
1752 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1756 * Build a CUPS_GET_PRINTERS request, which requires the following
1759 * attributes-charset
1760 * attributes-natural-language
1761 * requested-attributes
1762 * requesting-user-name
1765 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1767 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1768 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1771 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1775 * Do the request and get back a response...
1778 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1780 DEBUG_puts("show_printers: request succeeded...");
1782 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1784 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1785 ippDelete(response
);
1790 * Loop through the printers returned in the list and display
1794 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1797 * Skip leading attributes until we hit a job...
1800 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1807 * Pull the needed attributes from this job...
1812 ptype
= CUPS_PRINTER_LOCAL
;
1813 pstate
= IPP_PRINTER_IDLE
;
1824 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1826 if (!strcmp(attr
->name
, "printer-name") &&
1827 attr
->value_tag
== IPP_TAG_NAME
)
1828 printer
= attr
->values
[0].string
.text
;
1829 else if (!strcmp(attr
->name
, "printer-state") &&
1830 attr
->value_tag
== IPP_TAG_ENUM
)
1831 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1832 else if (!strcmp(attr
->name
, "printer-type") &&
1833 attr
->value_tag
== IPP_TAG_ENUM
)
1834 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1835 else if (!strcmp(attr
->name
, "printer-state-message") &&
1836 attr
->value_tag
== IPP_TAG_TEXT
)
1837 message
= attr
->values
[0].string
.text
;
1838 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1839 attr
->value_tag
== IPP_TAG_INTEGER
)
1840 ptime
= (time_t)attr
->values
[0].integer
;
1841 else if (!strcmp(attr
->name
, "printer-info") &&
1842 attr
->value_tag
== IPP_TAG_TEXT
)
1843 description
= attr
->values
[0].string
.text
;
1844 else if (!strcmp(attr
->name
, "printer-location") &&
1845 attr
->value_tag
== IPP_TAG_TEXT
)
1846 location
= attr
->values
[0].string
.text
;
1847 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1848 attr
->value_tag
== IPP_TAG_TEXT
)
1849 make_model
= attr
->values
[0].string
.text
;
1850 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1851 attr
->value_tag
== IPP_TAG_URI
)
1852 uri
= attr
->values
[0].string
.text
;
1853 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1854 attr
->value_tag
== IPP_TAG_KEYWORD
)
1856 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1857 attr
->value_tag
== IPP_TAG_NAME
)
1859 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1860 attr
->value_tag
== IPP_TAG_NAME
)
1867 * See if we have everything needed...
1870 if (printer
== NULL
)
1879 * See if this is a printer we're interested in...
1882 match
= printers
== NULL
;
1884 if (printers
!= NULL
)
1886 for (dptr
= printers
; *dptr
!= '\0';)
1889 * Skip leading whitespace and commas...
1892 while (isspace(*dptr
& 255) || *dptr
== ',')
1903 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1906 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1913 * Skip trailing junk...
1916 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1918 while (isspace(*dptr
& 255) || *dptr
== ',')
1927 * Display the printer entry if needed...
1933 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1934 * current job for the printer.
1937 if (pstate
== IPP_PRINTER_PROCESSING
)
1940 * Build an IPP_GET_JOBS request, which requires the following
1943 * attributes-charset
1944 * attributes-natural-language
1947 * requested-attributes
1950 request
= ippNewRequest(IPP_GET_JOBS
);
1952 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1953 request
->request
.op
.request_id
= 1;
1955 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1956 "requested-attributes",
1957 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1959 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1960 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1961 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1962 "printer-uri", NULL
, printer_uri
);
1964 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
1967 * Get the current active job on this queue...
1972 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1977 if (!strcmp(jobattr
->name
, "job-id") &&
1978 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1979 jobid
= jobattr
->values
[0].integer
;
1980 else if (!strcmp(jobattr
->name
, "job-state") &&
1981 jobattr
->value_tag
== IPP_TAG_ENUM
&&
1982 jobattr
->values
[0].integer
== IPP_JOB_PROCESSING
)
1994 pdate
= localtime(&ptime
);
1995 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
1999 case IPP_PRINTER_IDLE
:
2000 _cupsLangPrintf(stdout
,
2001 _("printer %s is idle. enabled since %s\n"),
2002 printer
, printer_state_time
);
2004 case IPP_PRINTER_PROCESSING
:
2005 _cupsLangPrintf(stdout
,
2006 _("printer %s now printing %s-%d. "
2007 "enabled since %s\n"),
2008 printer
, printer
, jobid
, printer_state_time
);
2010 case IPP_PRINTER_STOPPED
:
2011 _cupsLangPrintf(stdout
,
2012 _("printer %s disabled since %s -\n"),
2013 printer
, printer_state_time
);
2017 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2019 if (!message
|| !*message
)
2020 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2022 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2025 if (long_status
> 1)
2026 _cupsLangPuts(stdout
,
2027 _("\tForm mounted:\n"
2028 "\tContent types: any\n"
2029 "\tPrinter types: unknown\n"));
2033 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2034 description
? description
: "");
2038 _cupsLangPuts(stdout
, _("\tAlerts:"));
2039 for (i
= 0; i
< reasons
->num_values
; i
++)
2040 _cupsLangPrintf(stdout
, " %s",
2041 reasons
->values
[i
].string
.text
);
2042 _cupsLangPuts(stdout
, "\n");
2045 if (long_status
> 1)
2047 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2048 location
? location
: "");
2050 if (ptype
& CUPS_PRINTER_REMOTE
)
2052 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2054 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2055 !strstr(make_model
, "Raw Printer") && uri
)
2056 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2061 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2063 if (make_model
&& strstr(make_model
, "System V Printer"))
2064 _cupsLangPrintf(stdout
,
2065 _("\tInterface: %s/interfaces/%s\n"),
2067 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2068 _cupsLangPrintf(stdout
,
2069 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2071 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2072 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2073 // TODO update to use printer-error-policy
2076 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2077 for (i
= 0; i
< allowed
->num_values
; i
++)
2078 _cupsLangPrintf(stdout
, "\t\t%s\n",
2079 allowed
->values
[i
].string
.text
);
2083 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2084 for (i
= 0; i
< denied
->num_values
; i
++)
2085 _cupsLangPrintf(stdout
, "\t\t%s\n",
2086 denied
->values
[i
].string
.text
);
2090 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2091 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2093 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2094 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2095 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2096 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2097 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2098 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2099 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2100 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2103 for (i
= 0; i
< num_dests
; i
++)
2104 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2108 case IPP_PRINTER_IDLE
:
2109 _cupsLangPrintf(stdout
,
2110 _("printer %s/%s is idle. "
2111 "enabled since %s\n"),
2112 printer
, dests
[i
].instance
,
2113 printer_state_time
);
2115 case IPP_PRINTER_PROCESSING
:
2116 _cupsLangPrintf(stdout
,
2117 _("printer %s/%s now printing %s-%d. "
2118 "enabled since %s\n"),
2119 printer
, dests
[i
].instance
, printer
, jobid
,
2120 printer_state_time
);
2122 case IPP_PRINTER_STOPPED
:
2123 _cupsLangPrintf(stdout
,
2124 _("printer %s/%s disabled since %s -\n"),
2125 printer
, dests
[i
].instance
,
2126 printer_state_time
);
2130 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2132 if (!message
|| !*message
)
2133 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2135 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2138 if (long_status
> 1)
2139 _cupsLangPuts(stdout
,
2140 _("\tForm mounted:\n"
2141 "\tContent types: any\n"
2142 "\tPrinter types: unknown\n"));
2146 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2147 description
? description
: "");
2151 _cupsLangPuts(stdout
, _("\tAlerts:"));
2152 for (i
= 0; i
< reasons
->num_values
; i
++)
2153 _cupsLangPrintf(stdout
, " %s",
2154 reasons
->values
[i
].string
.text
);
2155 _cupsLangPuts(stdout
, "\n");
2158 if (long_status
> 1)
2160 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2161 location
? location
: "");
2163 if (ptype
& CUPS_PRINTER_REMOTE
)
2165 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2167 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2168 !strstr(make_model
, "Raw Printer") && uri
)
2169 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2174 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2176 if (make_model
&& strstr(make_model
, "System V Printer"))
2177 _cupsLangPrintf(stdout
,
2178 _("\tInterface: %s/interfaces/%s\n"),
2180 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2181 _cupsLangPrintf(stdout
,
2182 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2184 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2185 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2186 // TODO update to use printer-error-policy
2189 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2190 for (i
= 0; i
< allowed
->num_values
; i
++)
2191 _cupsLangPrintf(stdout
, "\t\t%s\n",
2192 allowed
->values
[i
].string
.text
);
2196 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2197 for (i
= 0; i
< denied
->num_values
; i
++)
2198 _cupsLangPrintf(stdout
, "\t\t%s\n",
2199 denied
->values
[i
].string
.text
);
2203 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2204 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2206 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2207 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2208 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2209 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2210 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2211 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2212 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2213 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2222 ippDelete(response
);
2226 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2235 * 'show_scheduler()' - Show scheduler status.
2239 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2242 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2244 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2249 * End of "$Id: lpstat.c 5023 2006-01-29 14:39:44Z mike $".