2 * "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $"
4 * "lpstat" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007-2008 by Apple Inc.
7 * Copyright 1997-2006 by Easy Software Products.
9 * These coded instructions, statements, and computer programs are the
10 * property of Apple Inc. and are protected by Federal copyright
11 * law. Distribution and use rights are outlined in the file "LICENSE.txt"
12 * which should have been included with this file. If this file is
13 * file is missing or damaged, see the license at "http://www.cups.org/".
17 * main() - Parse options and show status information.
18 * check_dest() - Verify that the named destination(s) exists.
19 * connect_server() - Connect to the server as necessary...
20 * show_accepting() - Show acceptance status.
21 * show_classes() - Show printer classes.
22 * show_default() - Show default destination.
23 * show_devices() - Show printer devices.
24 * show_jobs() - Show active print jobs.
25 * show_printers() - Show printers.
26 * show_scheduler() - Show scheduler status.
30 * Include necessary headers...
36 #include <cups/http-private.h>
37 #include <cups/string.h>
38 #include <cups/cups.h>
39 #include <cups/i18n.h>
40 #include <cups/debug.h>
47 static void check_dest(const char *, http_t
*, const char *, int *,
49 static http_t
*connect_server(const char *, http_t
*);
50 static int show_accepting(http_t
*, const char *, int, cups_dest_t
*);
51 static int show_classes(http_t
*, const char *);
52 static void show_default(int, cups_dest_t
*);
53 static int show_devices(http_t
*, const char *, int, cups_dest_t
*);
54 static int show_jobs(http_t
*, const char *, const char *, int, int,
56 static int show_printers(http_t
*, const char *, int, cups_dest_t
*, int);
57 static void show_scheduler(http_t
*);
61 * 'main()' - Parse options and show status information.
65 main(int argc
, /* I - Number of command-line arguments */
66 char *argv
[]) /* I - Command-line arguments */
68 int i
, /* Looping var */
69 status
; /* Exit status */
70 http_t
*http
; /* Connection to server */
71 int num_dests
; /* Number of user destinations */
72 cups_dest_t
*dests
; /* User destinations */
73 int long_status
; /* Long status report? */
74 int ranking
; /* Show job ranking? */
75 const char *which
; /* Which jobs to show? */
76 char op
; /* Last operation on command-line */
82 * Parse command-line options...
91 which
= "not-completed";
94 for (i
= 1; i
< argc
; i
++)
95 if (argv
[i
][0] == '-')
98 case 'D' : /* Show description */
102 case 'E' : /* Encrypt */
104 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
107 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
109 _cupsLangPrintf(stderr
,
110 _("%s: Sorry, no encryption support compiled in!\n"),
112 #endif /* HAVE_SSL */
115 case 'H' : /* Show server and port */
116 if (cupsServer()[0] == '/')
117 _cupsLangPrintf(stdout
, "%s\n", cupsServer());
119 _cupsLangPrintf(stdout
, "%s:%d\n", cupsServer(), ippPort());
122 case 'P' : /* Show paper types */
126 case 'R' : /* Show ranking */
130 case 'S' : /* Show charsets */
136 case 'U' : /* Username */
137 if (argv
[i
][2] != '\0')
138 cupsSetUser(argv
[i
] + 2);
144 _cupsLangPrintf(stderr
,
145 _("%s: Error - expected username after "
151 cupsSetUser(argv
[i
]);
155 case 'W' : /* Show which jobs? */
164 _cupsLangPrintf(stderr
,
165 _("%s: Error - need \"completed\", "
166 "\"not-completed\", or \"all\" after "
175 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
176 strcmp(which
, "all"))
178 _cupsLangPrintf(stderr
,
179 _("%s: Error - need \"completed\", "
180 "\"not-completed\", or \"all\" after "
187 case 'a' : /* Show acceptance status */
189 http
= connect_server(argv
[0], http
);
191 if (argv
[i
][2] != '\0')
193 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
195 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
197 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
201 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
203 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
208 num_dests
= cupsGetDests2(http
, &dests
);
210 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
215 case 'b' : /* Show both the local and remote status */
217 http
= connect_server(argv
[0], http
);
219 if (argv
[i
][2] != '\0')
222 * The local and remote status are separated by a blank line;
223 * since all CUPS jobs are networked, we only output the
224 * second list for now... In the future, we might further
225 * emulate this by listing the remote server's queue, but
226 * for now this is enough to make the SGI printstatus program
230 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
233 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
237 _cupsLangPrintf(stderr
,
238 _("%s: Error - expected destination after "
247 case 'c' : /* Show classes and members */
249 http
= connect_server(argv
[0], http
);
251 if (argv
[i
][2] != '\0')
253 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
255 status
|= show_classes(http
, argv
[i
] + 2);
257 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
261 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
263 status
|= show_classes(http
, argv
[i
]);
266 status
|= show_classes(http
, NULL
);
269 case 'd' : /* Show default destination */
271 http
= connect_server(argv
[0], http
);
274 num_dests
= cupsGetDests2(http
, &dests
);
276 show_default(num_dests
, dests
);
279 case 'f' : /* Show forms */
285 case 'h' : /* Connect to host */
292 if (argv
[i
][2] != '\0')
293 cupsSetServer(argv
[i
] + 2);
300 _cupsLangPrintf(stderr
,
301 _("%s: Error - expected hostname after "
307 cupsSetServer(argv
[i
]);
311 case 'l' : /* Long status or long job status */
314 http
= connect_server(argv
[0], http
);
316 if (argv
[i
][2] != '\0')
318 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
320 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
327 case 'o' : /* Show jobs by destination */
329 http
= connect_server(argv
[0], http
);
331 if (argv
[i
][2] != '\0')
333 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
335 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
338 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
342 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
344 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
348 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
352 case 'p' : /* Show printers */
354 http
= connect_server(argv
[0], http
);
356 if (argv
[i
][2] != '\0')
358 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
360 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
362 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
366 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
368 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
373 num_dests
= cupsGetDests2(http
, &dests
);
375 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
379 case 'r' : /* Show scheduler status */
381 http
= connect_server(argv
[0], http
);
383 show_scheduler(http
);
386 case 's' : /* Show summary */
388 http
= connect_server(argv
[0], http
);
391 num_dests
= cupsGetDests2(http
, &dests
);
393 show_default(num_dests
, dests
);
394 status
|= show_classes(http
, NULL
);
395 status
|= show_devices(http
, NULL
, num_dests
, dests
);
398 case 't' : /* Show all info */
400 http
= connect_server(argv
[0], http
);
403 num_dests
= cupsGetDests2(http
, &dests
);
405 show_scheduler(http
);
406 show_default(num_dests
, dests
);
407 status
|= show_classes(http
, NULL
);
408 status
|= show_devices(http
, NULL
, num_dests
, dests
);
409 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
410 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
411 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
414 case 'u' : /* Show jobs by user */
416 http
= connect_server(argv
[0], http
);
418 if (argv
[i
][2] != '\0')
419 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
421 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
424 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
428 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
432 case 'v' : /* Show printer devices */
434 http
= connect_server(argv
[0], http
);
436 if (argv
[i
][2] != '\0')
438 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
440 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
442 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
446 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
448 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
453 num_dests
= cupsGetDests2(http
, &dests
);
455 status
|= show_devices(http
, NULL
, num_dests
, dests
);
461 _cupsLangPrintf(stderr
,
462 _("%s: Error - unknown option \'%c\'!\n"),
463 argv
[0], argv
[i
][1]);
468 http
= connect_server(argv
[0], http
);
470 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
476 http
= connect_server(argv
[0], http
);
478 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
486 * 'check_dest()' - Verify that the named destination(s) exists.
490 check_dest(const char *command
, /* I - Command name */
491 http_t
*http
, /* I - HTTP connection */
492 const char *name
, /* I - Name of printer/class(es) */
493 int *num_dests
, /* IO - Number of destinations */
494 cups_dest_t
**dests
) /* IO - Destinations */
502 * Load the destination list as necessary...
506 *num_dests
= cupsGetDests2(http
, dests
);
509 * Scan the name string for printer/class name(s)...
512 for (dptr
= name
; *dptr
!= '\0';)
515 * Skip leading whitespace and commas...
518 while (isspace(*dptr
& 255) || *dptr
== ',')
525 * Extract a single destination name from the name string...
528 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
530 if ((pptr
- printer
) < (sizeof(printer
) - 1))
534 _cupsLangPrintf(stderr
,
535 _("%s: Invalid destination name in list \"%s\"!\n"),
544 * Check the destination...
547 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
549 _cupsLangPrintf(stderr
,
550 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
558 * 'connect_server()' - Connect to the server as necessary...
561 static http_t
* /* O - New HTTP connection */
562 connect_server(const char *command
, /* I - Command name */
563 http_t
*http
) /* I - Current HTTP connection */
567 http
= httpConnectEncrypt(cupsServer(), ippPort(),
572 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
582 * 'show_accepting()' - Show acceptance status.
585 static int /* O - 0 on success, 1 on fail */
586 show_accepting(http_t
*http
, /* I - HTTP connection to server */
587 const char *printers
, /* I - Destinations */
588 int num_dests
, /* I - Number of user-defined dests */
589 cups_dest_t
*dests
) /* I - User-defined destinations */
591 int i
; /* Looping var */
592 ipp_t
*request
, /* IPP Request */
593 *response
; /* IPP Response */
594 ipp_attribute_t
*attr
; /* Current attribute */
595 const char *printer
, /* Printer name */
596 *message
; /* Printer device URI */
597 int accepting
; /* Accepting requests? */
598 time_t ptime
; /* Printer state time */
599 struct tm
*pdate
; /* Printer state date & time */
600 char printer_state_time
[255];/* Printer state time */
601 const char *dptr
, /* Pointer into destination list */
602 *ptr
; /* Pointer into printer name */
603 int match
; /* Non-zero if this job matches */
604 static const char *pattrs
[] = /* Attributes we need for printers... */
607 "printer-state-change-time",
608 "printer-state-message",
609 "printer-is-accepting-jobs"
613 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
618 if (printers
!= NULL
&& !strcmp(printers
, "all"))
622 * Build a CUPS_GET_PRINTERS request, which requires the following
626 * attributes-natural-language
627 * requested-attributes
628 * requesting-user-name
631 request
= ippNewRequest(CUPS_GET_PRINTERS
);
633 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
634 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
637 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
641 * Do the request and get back a response...
644 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
646 DEBUG_puts("show_accepting: request succeeded...");
648 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
650 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
656 * Loop through the printers returned in the list and display
660 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
663 * Skip leading attributes until we hit a printer...
666 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
673 * Pull the needed attributes from this printer...
681 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
683 if (!strcmp(attr
->name
, "printer-name") &&
684 attr
->value_tag
== IPP_TAG_NAME
)
685 printer
= attr
->values
[0].string
.text
;
686 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
687 attr
->value_tag
== IPP_TAG_INTEGER
)
688 ptime
= (time_t)attr
->values
[0].integer
;
689 else if (!strcmp(attr
->name
, "printer-state-message") &&
690 attr
->value_tag
== IPP_TAG_TEXT
)
691 message
= attr
->values
[0].string
.text
;
692 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
693 attr
->value_tag
== IPP_TAG_BOOLEAN
)
694 accepting
= attr
->values
[0].boolean
;
700 * See if we have everything needed...
712 * See if this is a printer we're interested in...
715 match
= printers
== NULL
;
717 if (printers
!= NULL
)
719 for (dptr
= printers
; *dptr
!= '\0';)
722 * Skip leading whitespace and commas...
725 while (isspace(*dptr
& 255) || *dptr
== ',')
736 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
739 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
746 * Skip trailing junk...
749 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
751 while (isspace(*dptr
& 255) || *dptr
== ',')
760 * Display the printer entry if needed...
765 pdate
= localtime(&ptime
);
766 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
769 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
770 printer
, printer_state_time
);
772 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
774 printer
, printer_state_time
,
775 message
== NULL
? "reason unknown" : message
);
777 for (i
= 0; i
< num_dests
; i
++)
778 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
781 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
782 printer
, dests
[i
].instance
, printer_state_time
);
784 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
786 printer
, dests
[i
].instance
, printer_state_time
,
787 message
== NULL
? "reason unknown" : message
);
799 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
808 * 'show_classes()' - Show printer classes.
811 static int /* O - 0 on success, 1 on fail */
812 show_classes(http_t
*http
, /* I - HTTP connection to server */
813 const char *dests
) /* I - Destinations */
815 int i
; /* Looping var */
816 ipp_t
*request
, /* IPP Request */
817 *response
, /* IPP Response */
818 *response2
; /* IPP response from remote server */
819 http_t
*http2
; /* Remote server */
820 ipp_attribute_t
*attr
; /* Current attribute */
821 const char *printer
, /* Printer class name */
822 *printer_uri
; /* Printer class URI */
823 ipp_attribute_t
*members
; /* Printer members */
824 char method
[HTTP_MAX_URI
], /* Request method */
825 username
[HTTP_MAX_URI
], /* Username:password */
826 server
[HTTP_MAX_URI
], /* Server name */
827 resource
[HTTP_MAX_URI
]; /* Resource name */
828 int port
; /* Port number */
829 const char *dptr
, /* Pointer into destination list */
830 *ptr
; /* Pointer into printer name */
831 int match
; /* Non-zero if this job matches */
832 static const char *cattrs
[] = /* Attributes we need for classes... */
835 "printer-uri-supported",
840 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
845 if (dests
!= NULL
&& !strcmp(dests
, "all"))
849 * Build a CUPS_GET_CLASSES request, which requires the following
853 * attributes-natural-language
854 * requested-attributes
855 * requesting-user-name
858 request
= ippNewRequest(CUPS_GET_CLASSES
);
860 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
861 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
864 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
868 * Do the request and get back a response...
871 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
873 DEBUG_puts("show_classes: request succeeded...");
875 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
877 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
883 * Loop through the printers returned in the list and display
887 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
890 * Skip leading attributes until we hit a job...
893 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
900 * Pull the needed attributes from this job...
907 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
909 if (!strcmp(attr
->name
, "printer-name") &&
910 attr
->value_tag
== IPP_TAG_NAME
)
911 printer
= attr
->values
[0].string
.text
;
913 if (!strcmp(attr
->name
, "printer-uri-supported") &&
914 attr
->value_tag
== IPP_TAG_URI
)
915 printer_uri
= attr
->values
[0].string
.text
;
917 if (!strcmp(attr
->name
, "member-names") &&
918 attr
->value_tag
== IPP_TAG_NAME
)
925 * If this is a remote class, grab the class info from the
930 if (members
== NULL
&& printer_uri
!= NULL
)
932 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
933 username
, sizeof(username
), server
, sizeof(server
),
934 &port
, resource
, sizeof(resource
));
936 if (!strcasecmp(server
, http
->hostname
))
939 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
944 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
945 * following attributes:
948 * attributes-natural-language
950 * requested-attributes
953 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
955 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
956 "printer-uri", NULL
, printer_uri
);
958 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
959 "requested-attributes",
960 sizeof(cattrs
) / sizeof(cattrs
[0]),
963 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
964 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
972 * See if we have everything needed...
978 ippDelete(response2
);
987 * See if this is a printer we're interested in...
990 match
= dests
== NULL
;
994 for (dptr
= dests
; *dptr
!= '\0';)
997 * Skip leading whitespace and commas...
1000 while (isspace(*dptr
& 255) || *dptr
== ',')
1011 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1014 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1021 * Skip trailing junk...
1024 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1026 while (isspace(*dptr
& 255) || *dptr
== ',')
1035 * Display the printer entry if needed...
1040 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1044 for (i
= 0; i
< members
->num_values
; i
++)
1045 _cupsLangPrintf(stdout
, "\t%s\n",
1046 members
->values
[i
].string
.text
);
1049 _cupsLangPuts(stdout
, "\tunknown\n");
1053 ippDelete(response2
);
1059 ippDelete(response
);
1063 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1072 * 'show_default()' - Show default destination.
1076 show_default(int num_dests
, /* I - Number of user-defined dests */
1077 cups_dest_t
*dests
) /* I - User-defined destinations */
1079 cups_dest_t
*dest
; /* Destination */
1080 const char *printer
, /* Printer name */
1081 *val
; /* Environment variable name */
1083 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1086 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1087 dest
->name
, dest
->instance
);
1089 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1096 if ((printer
= getenv("LPDEST")) == NULL
)
1098 if ((printer
= getenv("PRINTER")) != NULL
)
1100 if (!strcmp(printer
, "lp"))
1109 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1110 _cupsLangPrintf(stdout
,
1111 _("lpstat: error - %s environment variable names "
1112 "non-existent destination \"%s\"!\n"),
1115 _cupsLangPuts(stdout
, _("no system default destination\n"));
1121 * 'show_devices()' - Show printer devices.
1124 static int /* O - 0 on success, 1 on fail */
1125 show_devices(http_t
*http
, /* I - HTTP connection to server */
1126 const char *printers
, /* I - Destinations */
1127 int num_dests
, /* I - Number of user-defined dests */
1128 cups_dest_t
*dests
) /* I - User-defined destinations */
1130 int i
; /* Looping var */
1131 ipp_t
*request
, /* IPP Request */
1132 *response
; /* IPP Response */
1133 ipp_attribute_t
*attr
; /* Current attribute */
1134 const char *printer
, /* Printer name */
1135 *uri
, /* Printer URI */
1136 *device
, /* Printer device URI */
1137 *dptr
, /* Pointer into destination list */
1138 *ptr
; /* Pointer into printer name */
1139 int match
; /* Non-zero if this job matches */
1140 static const char *pattrs
[] = /* Attributes we need for printers... */
1143 "printer-uri-supported",
1148 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1153 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1157 * Build a CUPS_GET_PRINTERS request, which requires the following
1160 * attributes-charset
1161 * attributes-natural-language
1162 * requested-attributes
1163 * requesting-user-name
1166 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1168 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1169 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1172 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1176 * Do the request and get back a response...
1179 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1181 DEBUG_puts("show_devices: request succeeded...");
1183 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1185 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1186 ippDelete(response
);
1191 * Loop through the printers returned in the list and display
1195 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1198 * Skip leading attributes until we hit a job...
1201 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1208 * Pull the needed attributes from this job...
1215 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1217 if (!strcmp(attr
->name
, "printer-name") &&
1218 attr
->value_tag
== IPP_TAG_NAME
)
1219 printer
= attr
->values
[0].string
.text
;
1221 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1222 attr
->value_tag
== IPP_TAG_URI
)
1223 uri
= attr
->values
[0].string
.text
;
1225 if (!strcmp(attr
->name
, "device-uri") &&
1226 attr
->value_tag
== IPP_TAG_URI
)
1227 device
= attr
->values
[0].string
.text
;
1233 * See if we have everything needed...
1236 if (printer
== NULL
)
1245 * See if this is a printer we're interested in...
1248 match
= printers
== NULL
;
1250 if (printers
!= NULL
)
1252 for (dptr
= printers
; *dptr
!= '\0';)
1255 * Skip leading whitespace and commas...
1258 while (isspace(*dptr
& 255) || *dptr
== ',')
1269 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1272 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1279 * Skip trailing junk...
1282 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1284 while (isspace(*dptr
& 255) || *dptr
== ',')
1293 * Display the printer entry if needed...
1298 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1299 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1300 username
[HTTP_MAX_URI
],
1301 hostname
[HTTP_MAX_URI
],
1302 resource
[HTTP_MAX_URI
];
1308 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1309 username
, sizeof(username
), hostname
,
1310 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1311 _cupsLangPrintf(stdout
,
1312 _("Output for printer %s is sent to remote "
1313 "printer %s on %s\n"),
1314 printer
, strrchr(resource
, '/') + 1, hostname
);
1316 else if (!strncmp(device
, "file:", 5))
1317 _cupsLangPrintf(stdout
,
1318 _("Output for printer %s is sent to %s\n"),
1319 printer
, device
+ 5);
1321 _cupsLangPrintf(stdout
,
1322 _("Output for printer %s is sent to %s\n"),
1325 for (i
= 0; i
< num_dests
; i
++)
1326 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1329 _cupsLangPrintf(stdout
,
1330 _("Output for printer %s/%s is sent to "
1331 "remote printer %s on %s\n"),
1332 printer
, dests
[i
].instance
,
1333 strrchr(resource
, '/') + 1, hostname
);
1334 else if (!strncmp(device
, "file:", 5))
1335 _cupsLangPrintf(stdout
,
1336 _("Output for printer %s/%s is sent to %s\n"),
1337 printer
, dests
[i
].instance
, device
+ 5);
1339 _cupsLangPrintf(stdout
,
1340 _("Output for printer %s/%s is sent to %s\n"),
1341 printer
, dests
[i
].instance
, device
);
1345 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1347 else if (!strncmp(device
, "file:", 5))
1348 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1349 printer
, device
+ 5);
1351 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1354 for (i
= 0; i
< num_dests
; i
++)
1355 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1358 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1359 printer
, dests
[i
].instance
, uri
);
1360 else if (!strncmp(device
, "file:", 5))
1361 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1362 printer
, dests
[i
].instance
, device
+ 5);
1364 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1365 printer
, dests
[i
].instance
, device
);
1367 #endif /* __osf__ */
1374 ippDelete(response
);
1378 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1387 * 'show_jobs()' - Show active print jobs.
1390 static int /* O - 0 on success, 1 on fail */
1391 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1392 const char *dests
, /* I - Destinations */
1393 const char *users
, /* I - Users */
1394 int long_status
, /* I - Show long status? */
1395 int ranking
, /* I - Show job ranking? */
1396 const char *which
) /* I - Show which jobs? */
1398 int i
; /* Looping var */
1399 ipp_t
*request
, /* IPP Request */
1400 *response
; /* IPP Response */
1401 ipp_attribute_t
*attr
, /* Current attribute */
1402 *reasons
; /* Job state reasons 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",
1428 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1433 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1437 * Build a IPP_GET_JOBS request, which requires the following
1440 * attributes-charset
1441 * attributes-natural-language
1443 * requested-attributes
1446 request
= ippNewRequest(IPP_GET_JOBS
);
1448 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1449 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1452 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1453 NULL
, "ipp://localhost/jobs/");
1455 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1459 * Do the request and get back a response...
1462 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1465 * Loop through the job list and display them...
1468 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1470 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1471 ippDelete(response
);
1477 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1480 * Skip leading attributes until we hit a job...
1483 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1490 * Pull the needed attributes from this job...
1501 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1503 if (!strcmp(attr
->name
, "job-id") &&
1504 attr
->value_tag
== IPP_TAG_INTEGER
)
1505 jobid
= attr
->values
[0].integer
;
1507 if (!strcmp(attr
->name
, "job-k-octets") &&
1508 attr
->value_tag
== IPP_TAG_INTEGER
)
1509 size
= attr
->values
[0].integer
;
1511 if (!strcmp(attr
->name
, "time-at-creation") &&
1512 attr
->value_tag
== IPP_TAG_INTEGER
)
1513 jobtime
= attr
->values
[0].integer
;
1515 if (!strcmp(attr
->name
, "job-printer-uri") &&
1516 attr
->value_tag
== IPP_TAG_URI
)
1517 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1520 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1521 attr
->value_tag
== IPP_TAG_NAME
)
1522 username
= attr
->values
[0].string
.text
;
1524 if (!strcmp(attr
->name
, "job-name") &&
1525 attr
->value_tag
== IPP_TAG_NAME
)
1526 title
= attr
->values
[0].string
.text
;
1528 if (!strcmp(attr
->name
, "job-state-reasons") &&
1529 attr
->value_tag
== IPP_TAG_KEYWORD
)
1536 * See if we have everything needed...
1539 if (dest
== NULL
|| jobid
== 0)
1548 * See if this is a job we're interested in...
1551 match
= (dests
== NULL
&& users
== NULL
);
1556 for (dptr
= dests
; *dptr
!= '\0';)
1559 * Skip leading whitespace and commas...
1562 while (isspace(*dptr
& 255) || *dptr
== ',')
1573 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1576 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1583 * Skip trailing junk...
1586 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1588 while (isspace(*dptr
& 255) || *dptr
== ',')
1596 if (users
!= NULL
&& username
!= NULL
)
1598 for (dptr
= users
; *dptr
!= '\0';)
1601 * Skip leading whitespace and commas...
1604 while (isspace(*dptr
& 255) || *dptr
== ',')
1614 for (ptr
= username
;
1615 *ptr
!= '\0' && *dptr
!= '\0' && *ptr
== *dptr
;
1618 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1625 * Skip trailing junk...
1628 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1630 while (isspace(*dptr
& 255) || *dptr
== ',')
1639 * Display the job...
1644 jobdate
= localtime(&jobtime
);
1645 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1647 if (long_status
== 3)
1650 * Show the consolidated output format for the SGI tools...
1653 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1654 strcpy(date
, "Unknown");
1656 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s\n",
1657 temp
, username
? username
: "unknown",
1658 size
, title
? title
: "unknown", date
);
1662 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1663 strcpy(date
, "Unknown");
1666 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s\n",
1667 rank
, temp
, username
? username
: "unknown",
1668 1024.0 * size
, date
);
1670 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s\n",
1671 temp
, username
? username
: "unknown",
1672 1024.0 * size
, date
);
1677 _cupsLangPuts(stdout
, _("\tAlerts:"));
1678 for (i
= 0; i
< reasons
->num_values
; i
++)
1679 _cupsLangPrintf(stdout
, " %s",
1680 reasons
->values
[i
].string
.text
);
1681 _cupsLangPuts(stdout
, "\n");
1683 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1692 ippDelete(response
);
1696 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1705 * 'show_printers()' - Show printers.
1708 static int /* O - 0 on success, 1 on fail */
1709 show_printers(http_t
*http
, /* I - HTTP connection to server */
1710 const char *printers
, /* I - Destinations */
1711 int num_dests
, /* I - Number of user-defined dests */
1712 cups_dest_t
*dests
, /* I - User-defined destinations */
1713 int long_status
) /* I - Show long status? */
1715 int i
, j
; /* Looping vars */
1716 ipp_t
*request
, /* IPP Request */
1717 *response
, /* IPP Response */
1718 *jobs
; /* IPP Get Jobs response */
1719 ipp_attribute_t
*attr
, /* Current attribute */
1720 *jobattr
, /* Job ID attribute */
1721 *reasons
; /* Job state reasons attribute */
1722 const char *printer
, /* Printer name */
1723 *message
, /* Printer state message */
1724 *description
, /* Description of printer */
1725 *location
, /* Location of printer */
1726 *make_model
, /* Make and model of printer */
1727 *uri
; /* URI of printer */
1728 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1729 *denied
; /* requestint-user-name-denied */
1730 ipp_pstate_t pstate
; /* Printer state */
1731 cups_ptype_t ptype
; /* Printer type */
1732 time_t ptime
; /* Printer state time */
1733 struct tm
*pdate
; /* Printer state date & time */
1734 int jobid
; /* Job ID of current job */
1735 const char *dptr
, /* Pointer into destination list */
1736 *ptr
; /* Pointer into printer name */
1737 int match
; /* Non-zero if this job matches */
1738 char printer_uri
[HTTP_MAX_URI
],
1740 printer_state_time
[255];/* Printer state time */
1741 const char *root
; /* Server root directory... */
1742 static const char *pattrs
[] = /* Attributes we need for printers... */
1746 "printer-state-message",
1747 "printer-state-reasons",
1748 "printer-state-change-time",
1752 "printer-make-and-model",
1753 "printer-uri-supported",
1754 "requesting-user-name-allowed",
1755 "requesting-user-name-denied"
1757 static const char *jattrs
[] = /* Attributes we need for jobs... */
1763 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1768 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1769 root
= CUPS_SERVERROOT
;
1771 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1775 * Build a CUPS_GET_PRINTERS request, which requires the following
1778 * attributes-charset
1779 * attributes-natural-language
1780 * requested-attributes
1781 * requesting-user-name
1784 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1786 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1787 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1790 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1794 * Do the request and get back a response...
1797 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1799 DEBUG_puts("show_printers: request succeeded...");
1801 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1803 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1804 ippDelete(response
);
1809 * Loop through the printers returned in the list and display
1813 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1816 * Skip leading attributes until we hit a job...
1819 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1826 * Pull the needed attributes from this job...
1831 ptype
= CUPS_PRINTER_LOCAL
;
1832 pstate
= IPP_PRINTER_IDLE
;
1843 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1845 if (!strcmp(attr
->name
, "printer-name") &&
1846 attr
->value_tag
== IPP_TAG_NAME
)
1847 printer
= attr
->values
[0].string
.text
;
1848 else if (!strcmp(attr
->name
, "printer-state") &&
1849 attr
->value_tag
== IPP_TAG_ENUM
)
1850 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1851 else if (!strcmp(attr
->name
, "printer-type") &&
1852 attr
->value_tag
== IPP_TAG_ENUM
)
1853 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1854 else if (!strcmp(attr
->name
, "printer-state-message") &&
1855 attr
->value_tag
== IPP_TAG_TEXT
)
1856 message
= attr
->values
[0].string
.text
;
1857 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1858 attr
->value_tag
== IPP_TAG_INTEGER
)
1859 ptime
= (time_t)attr
->values
[0].integer
;
1860 else if (!strcmp(attr
->name
, "printer-info") &&
1861 attr
->value_tag
== IPP_TAG_TEXT
)
1862 description
= attr
->values
[0].string
.text
;
1863 else if (!strcmp(attr
->name
, "printer-location") &&
1864 attr
->value_tag
== IPP_TAG_TEXT
)
1865 location
= attr
->values
[0].string
.text
;
1866 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1867 attr
->value_tag
== IPP_TAG_TEXT
)
1868 make_model
= attr
->values
[0].string
.text
;
1869 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1870 attr
->value_tag
== IPP_TAG_URI
)
1871 uri
= attr
->values
[0].string
.text
;
1872 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1873 attr
->value_tag
== IPP_TAG_KEYWORD
)
1875 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1876 attr
->value_tag
== IPP_TAG_NAME
)
1878 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1879 attr
->value_tag
== IPP_TAG_NAME
)
1886 * See if we have everything needed...
1889 if (printer
== NULL
)
1898 * See if this is a printer we're interested in...
1901 match
= printers
== NULL
;
1903 if (printers
!= NULL
)
1905 for (dptr
= printers
; *dptr
!= '\0';)
1908 * Skip leading whitespace and commas...
1911 while (isspace(*dptr
& 255) || *dptr
== ',')
1922 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1925 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1932 * Skip trailing junk...
1935 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1937 while (isspace(*dptr
& 255) || *dptr
== ',')
1946 * Display the printer entry if needed...
1952 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1953 * current job for the printer.
1956 if (pstate
== IPP_PRINTER_PROCESSING
)
1959 * Build an IPP_GET_JOBS request, which requires the following
1962 * attributes-charset
1963 * attributes-natural-language
1966 * requested-attributes
1969 request
= ippNewRequest(IPP_GET_JOBS
);
1971 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1972 request
->request
.op
.request_id
= 1;
1974 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1975 "requested-attributes",
1976 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1978 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1979 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1980 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1981 "printer-uri", NULL
, printer_uri
);
1983 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
1986 * Get the current active job on this queue...
1989 ipp_jstate_t jobstate
= IPP_JOB_PENDING
;
1992 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1996 if (jobstate
== IPP_JOB_PROCESSING
)
2002 if (!strcmp(jobattr
->name
, "job-id") &&
2003 jobattr
->value_tag
== IPP_TAG_INTEGER
)
2004 jobid
= jobattr
->values
[0].integer
;
2005 else if (!strcmp(jobattr
->name
, "job-state") &&
2006 jobattr
->value_tag
== IPP_TAG_ENUM
)
2007 jobstate
= jobattr
->values
[0].integer
;
2010 if (jobstate
!= IPP_JOB_PROCESSING
)
2021 pdate
= localtime(&ptime
);
2022 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
2026 case IPP_PRINTER_IDLE
:
2027 _cupsLangPrintf(stdout
,
2028 _("printer %s is idle. enabled since %s\n"),
2029 printer
, printer_state_time
);
2031 case IPP_PRINTER_PROCESSING
:
2032 _cupsLangPrintf(stdout
,
2033 _("printer %s now printing %s-%d. "
2034 "enabled since %s\n"),
2035 printer
, printer
, jobid
, printer_state_time
);
2037 case IPP_PRINTER_STOPPED
:
2038 _cupsLangPrintf(stdout
,
2039 _("printer %s disabled since %s -\n"),
2040 printer
, printer_state_time
);
2044 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2046 if (!message
|| !*message
)
2047 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2049 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2052 if (long_status
> 1)
2053 _cupsLangPuts(stdout
,
2054 _("\tForm mounted:\n"
2055 "\tContent types: any\n"
2056 "\tPrinter types: unknown\n"));
2060 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2061 description
? description
: "");
2065 _cupsLangPuts(stdout
, _("\tAlerts:"));
2066 for (j
= 0; j
< reasons
->num_values
; j
++)
2067 _cupsLangPrintf(stdout
, " %s",
2068 reasons
->values
[j
].string
.text
);
2069 _cupsLangPuts(stdout
, "\n");
2072 if (long_status
> 1)
2074 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2075 location
? location
: "");
2077 if (ptype
& CUPS_PRINTER_REMOTE
)
2079 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2081 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2082 !strstr(make_model
, "Raw Printer") && uri
)
2083 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2088 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2090 if (make_model
&& strstr(make_model
, "System V Printer"))
2091 _cupsLangPrintf(stdout
,
2092 _("\tInterface: %s/interfaces/%s\n"),
2094 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2095 _cupsLangPrintf(stdout
,
2096 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2098 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2099 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2100 /* TODO update to use printer-error-policy */
2103 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2104 for (j
= 0; j
< allowed
->num_values
; j
++)
2105 _cupsLangPrintf(stdout
, "\t\t%s\n",
2106 allowed
->values
[j
].string
.text
);
2110 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2111 for (j
= 0; j
< denied
->num_values
; j
++)
2112 _cupsLangPrintf(stdout
, "\t\t%s\n",
2113 denied
->values
[j
].string
.text
);
2117 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2118 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2120 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2121 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2122 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2123 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2124 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2125 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2126 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2127 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2130 for (i
= 0; i
< num_dests
; i
++)
2131 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2135 case IPP_PRINTER_IDLE
:
2136 _cupsLangPrintf(stdout
,
2137 _("printer %s/%s is idle. "
2138 "enabled since %s\n"),
2139 printer
, dests
[i
].instance
,
2140 printer_state_time
);
2142 case IPP_PRINTER_PROCESSING
:
2143 _cupsLangPrintf(stdout
,
2144 _("printer %s/%s now printing %s-%d. "
2145 "enabled since %s\n"),
2146 printer
, dests
[i
].instance
, printer
, jobid
,
2147 printer_state_time
);
2149 case IPP_PRINTER_STOPPED
:
2150 _cupsLangPrintf(stdout
,
2151 _("printer %s/%s disabled since %s -\n"),
2152 printer
, dests
[i
].instance
,
2153 printer_state_time
);
2157 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2159 if (!message
|| !*message
)
2160 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2162 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2165 if (long_status
> 1)
2166 _cupsLangPuts(stdout
,
2167 _("\tForm mounted:\n"
2168 "\tContent types: any\n"
2169 "\tPrinter types: unknown\n"));
2173 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2174 description
? description
: "");
2178 _cupsLangPuts(stdout
, _("\tAlerts:"));
2179 for (j
= 0; j
< reasons
->num_values
; j
++)
2180 _cupsLangPrintf(stdout
, " %s",
2181 reasons
->values
[j
].string
.text
);
2182 _cupsLangPuts(stdout
, "\n");
2185 if (long_status
> 1)
2187 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2188 location
? location
: "");
2190 if (ptype
& CUPS_PRINTER_REMOTE
)
2192 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2194 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2195 !strstr(make_model
, "Raw Printer") && uri
)
2196 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2201 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2203 if (make_model
&& strstr(make_model
, "System V Printer"))
2204 _cupsLangPrintf(stdout
,
2205 _("\tInterface: %s/interfaces/%s\n"),
2207 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2208 _cupsLangPrintf(stdout
,
2209 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2211 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2212 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2213 /* TODO update to use printer-error-policy */
2216 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2217 for (j
= 0; j
< allowed
->num_values
; j
++)
2218 _cupsLangPrintf(stdout
, "\t\t%s\n",
2219 allowed
->values
[j
].string
.text
);
2223 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2224 for (j
= 0; j
< denied
->num_values
; j
++)
2225 _cupsLangPrintf(stdout
, "\t\t%s\n",
2226 denied
->values
[j
].string
.text
);
2230 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2231 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2233 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2234 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2235 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2236 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2237 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2238 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2239 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2240 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2249 ippDelete(response
);
2253 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2262 * 'show_scheduler()' - Show scheduler status.
2266 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2269 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2271 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2276 * End of "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $".