2 * "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $"
4 * "lpstat" command for CUPS.
6 * Copyright 2007-2011 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 * match_list() - Match a name from a list of comma or space-separated
21 * show_accepting() - Show acceptance status.
22 * show_classes() - Show printer classes.
23 * show_default() - Show default destination.
24 * show_devices() - Show printer devices.
25 * show_jobs() - Show active print jobs.
26 * show_printers() - Show printers.
27 * show_scheduler() - Show scheduler status.
31 * Include necessary headers...
34 #include <cups/cups-private.h>
41 static void check_dest(const char *command
, const char *name
,
42 int *num_dests
, cups_dest_t
**dests
);
43 static int match_list(const char *list
, const char *name
);
44 static int show_accepting(const char *printers
, int num_dests
,
46 static int show_classes(const char *dests
);
47 static void show_default(cups_dest_t
*dest
);
48 static int show_devices(const char *printers
, int num_dests
,
50 static int show_jobs(const char *dests
, const char *users
, int long_status
,
51 int ranking
, const char *which
);
52 static int show_printers(const char *printers
, int num_dests
,
53 cups_dest_t
*dests
, int long_status
);
54 static void show_scheduler(void);
58 * 'main()' - Parse options and show status information.
62 main(int argc
, /* I - Number of command-line arguments */
63 char *argv
[]) /* I - Command-line arguments */
65 int i
, /* Looping var */
66 status
; /* Exit status */
67 int num_dests
; /* Number of user destinations */
68 cups_dest_t
*dests
; /* User destinations */
69 int long_status
; /* Long status report? */
70 int ranking
; /* Show job ranking? */
71 const char *which
; /* Which jobs to show? */
72 char op
; /* Last operation on command-line */
78 * Parse command-line options...
86 which
= "not-completed";
89 for (i
= 1; i
< argc
; i
++)
90 if (argv
[i
][0] == '-')
93 case 'D' : /* Show description */
97 case 'E' : /* Encrypt */
99 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
101 _cupsLangPrintf(stderr
,
102 _("%s: Sorry, no encryption support."),
104 #endif /* HAVE_SSL */
107 case 'H' : /* Show server and port */
108 if (cupsServer()[0] == '/')
109 _cupsLangPuts(stdout
, cupsServer());
111 _cupsLangPrintf(stdout
, "%s:%d", cupsServer(), ippPort());
114 case 'P' : /* Show paper types */
118 case 'R' : /* Show ranking */
122 case 'S' : /* Show charsets */
128 case 'U' : /* Username */
130 cupsSetUser(argv
[i
] + 2);
136 _cupsLangPrintf(stderr
,
137 _("%s: Error - expected username after "
143 cupsSetUser(argv
[i
]);
147 case 'W' : /* Show which jobs? */
156 _cupsLangPrintf(stderr
,
157 _("%s: Error - need \"completed\", "
158 "\"not-completed\", or \"all\" after "
167 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
168 strcmp(which
, "all"))
170 _cupsLangPrintf(stderr
,
171 _("%s: Error - need \"completed\", "
172 "\"not-completed\", or \"all\" after "
179 case 'a' : /* Show acceptance status */
184 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
186 status
|= show_accepting(argv
[i
] + 2, num_dests
, dests
);
188 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
192 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
194 status
|= show_accepting(argv
[i
], num_dests
, dests
);
200 cupsFreeDests(num_dests
, dests
);
201 num_dests
= cupsGetDests(&dests
);
204 status
|= show_accepting(NULL
, num_dests
, dests
);
209 case 'b' : /* Show both the local and remote status */
215 * The local and remote status are separated by a blank line;
216 * since all CUPS jobs are networked, we only output the
217 * second list for now... In the future, we might further
218 * emulate this by listing the remote server's queue, but
219 * for now this is enough to make the SGI printstatus program
223 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
226 status
|= show_jobs(argv
[i
] + 2, NULL
, 3, ranking
, which
);
230 _cupsLangPrintf(stderr
,
231 _("%s: Error - expected destination after "
240 case 'c' : /* Show classes and members */
245 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
247 status
|= show_classes(argv
[i
] + 2);
249 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
253 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
255 status
|= show_classes(argv
[i
]);
258 status
|= show_classes(NULL
);
261 case 'd' : /* Show default destination */
264 if (num_dests
!= 1 || !dests
[0].is_default
)
266 cupsFreeDests(num_dests
, dests
);
268 dests
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, NULL
, NULL
);
269 num_dests
= dests
? 1 : 0;
275 case 'f' : /* Show forms */
281 case 'h' : /* Connect to host */
283 cupsSetServer(argv
[i
] + 2);
290 _cupsLangPrintf(stderr
,
291 _("%s: Error - expected hostname after "
297 cupsSetServer(argv
[i
]);
301 case 'l' : /* Long status or long job status */
307 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
309 status
|= show_jobs(argv
[i
] + 2, NULL
, 3, ranking
, which
);
316 case 'o' : /* Show jobs by destination */
321 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
323 status
|= show_jobs(argv
[i
] + 2, NULL
, long_status
, ranking
,
326 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
330 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
332 status
|= show_jobs(argv
[i
], NULL
, long_status
, ranking
, which
);
335 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
338 case 'p' : /* Show printers */
343 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
345 status
|= show_printers(argv
[i
] + 2, num_dests
, dests
,
348 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
352 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
354 status
|= show_printers(argv
[i
], num_dests
, dests
, long_status
);
360 cupsFreeDests(num_dests
, dests
);
361 num_dests
= cupsGetDests(&dests
);
364 status
|= show_printers(NULL
, num_dests
, dests
, long_status
);
368 case 'r' : /* Show scheduler status */
374 case 's' : /* Show summary */
379 cupsFreeDests(num_dests
, dests
);
380 num_dests
= cupsGetDests(&dests
);
383 show_default(cupsGetDest(NULL
, NULL
, num_dests
, dests
));
384 status
|= show_classes(NULL
);
385 status
|= show_devices(NULL
, num_dests
, dests
);
388 case 't' : /* Show all info */
393 cupsFreeDests(num_dests
, dests
);
394 num_dests
= cupsGetDests(&dests
);
398 show_default(cupsGetDest(NULL
, NULL
, num_dests
, dests
));
399 status
|= show_classes(NULL
);
400 status
|= show_devices(NULL
, num_dests
, dests
);
401 status
|= show_accepting(NULL
, num_dests
, dests
);
402 status
|= show_printers(NULL
, num_dests
, dests
, long_status
);
403 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
406 case 'u' : /* Show jobs by user */
410 status
|= show_jobs(NULL
, argv
[i
] + 2, long_status
, ranking
,
412 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
415 status
|= show_jobs(NULL
, argv
[i
], long_status
, ranking
, which
);
418 status
|= show_jobs(NULL
, NULL
, long_status
, ranking
, which
);
421 case 'v' : /* Show printer devices */
426 check_dest(argv
[0], argv
[i
] + 2, &num_dests
, &dests
);
428 status
|= show_devices(argv
[i
] + 2, num_dests
, dests
);
430 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
434 check_dest(argv
[0], argv
[i
], &num_dests
, &dests
);
436 status
|= show_devices(argv
[i
], num_dests
, dests
);
442 cupsFreeDests(num_dests
, dests
);
443 num_dests
= cupsGetDests(&dests
);
446 status
|= show_devices(NULL
, num_dests
, dests
);
451 _cupsLangPrintf(stderr
,
452 _("%s: Error - unknown option \"%c\"."),
453 argv
[0], argv
[i
][1]);
458 status
|= show_jobs(argv
[i
], NULL
, long_status
, ranking
, which
);
463 status
|= show_jobs(NULL
, cupsUser(), long_status
, ranking
, which
);
470 * 'check_dest()' - Verify that the named destination(s) exists.
474 check_dest(const char *command
, /* I - Command name */
475 const char *name
, /* I - List of printer/class names */
476 int *num_dests
, /* IO - Number of destinations */
477 cups_dest_t
**dests
) /* IO - Destinations */
479 const char *dptr
; /* Pointer into name */
480 char *pptr
, /* Pointer into printer */
481 printer
[1024]; /* Current printer/class name */
485 * Load the destination list as necessary...
491 cupsFreeDests(*num_dests
, *dests
);
493 if (strchr(name
, ','))
494 *num_dests
= cupsGetDests(dests
);
497 strlcpy(printer
, name
, sizeof(printer
));
498 if ((pptr
= strchr(printer
, '/')) != NULL
)
501 if ((*dests
= cupsGetNamedDest(CUPS_HTTP_DEFAULT
, printer
, pptr
)) == NULL
)
503 _cupsLangPrintf(stderr
,
504 _("%s: Invalid destination name in list \"%s\"."),
517 * Scan the name string for printer/class name(s)...
520 for (dptr
= name
; *dptr
;)
523 * Skip leading whitespace and commas...
526 while (isspace(*dptr
& 255) || *dptr
== ',')
533 * Extract a single destination name from the name string...
536 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
;)
538 if ((pptr
- printer
) < (sizeof(printer
) - 1))
542 _cupsLangPrintf(stderr
,
543 _("%s: Invalid destination name in list \"%s\"."),
552 * Check the destination...
555 if (!cupsGetDest(printer
, NULL
, *num_dests
, *dests
))
557 _cupsLangPrintf(stderr
,
558 _("%s: Unknown destination \"%s\"."), command
, printer
);
566 * 'match_list()' - Match a name from a list of comma or space-separated names.
569 static int /* O - 1 on match, 0 on no match */
570 match_list(const char *list
, /* I - List of names */
571 const char *name
) /* I - Name to find */
573 const char *nameptr
; /* Pointer into name */
577 * An empty list always matches...
589 * Skip leading whitespace and commas...
592 while (isspace(*list
& 255) || *list
== ',')
603 *nameptr
&& *list
&& tolower(*nameptr
& 255) == tolower(*list
& 255);
604 nameptr
++, list
++);
606 if (!*nameptr
&& (!*list
|| *list
== ',' || isspace(*list
& 255)))
609 while (*list
&& !isspace(*list
& 255) && *list
!= ',')
618 * 'show_accepting()' - Show acceptance status.
621 static int /* O - 0 on success, 1 on fail */
622 show_accepting(const char *printers
, /* I - Destinations */
623 int num_dests
, /* I - Number of user-defined dests */
624 cups_dest_t
*dests
) /* I - User-defined destinations */
626 int i
; /* Looping var */
627 ipp_t
*request
, /* IPP Request */
628 *response
; /* IPP Response */
629 ipp_attribute_t
*attr
; /* Current attribute */
630 const char *printer
, /* Printer name */
631 *message
; /* Printer device URI */
632 int accepting
; /* Accepting requests? */
633 time_t ptime
; /* Printer state time */
634 struct tm
*pdate
; /* Printer state date & time */
635 char printer_state_time
[255];/* Printer state time */
636 static const char *pattrs
[] = /* Attributes we need for printers... */
639 "printer-state-change-time",
640 "printer-state-message",
641 "printer-is-accepting-jobs"
645 DEBUG_printf(("show_accepting(printers=\"%s\")\n", printers
));
647 if (printers
!= NULL
&& !strcmp(printers
, "all"))
651 * Build a CUPS_GET_PRINTERS request, which requires the following
655 * attributes-natural-language
656 * requested-attributes
657 * requesting-user-name
660 request
= ippNewRequest(CUPS_GET_PRINTERS
);
662 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
663 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
666 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
670 * Do the request and get back a response...
673 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
675 DEBUG_puts("show_accepting: request succeeded...");
677 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
679 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
685 * Loop through the printers returned in the list and display
689 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
692 * Skip leading attributes until we hit a printer...
695 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
702 * Pull the needed attributes from this printer...
710 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
712 if (!strcmp(attr
->name
, "printer-name") &&
713 attr
->value_tag
== IPP_TAG_NAME
)
714 printer
= attr
->values
[0].string
.text
;
715 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
716 attr
->value_tag
== IPP_TAG_INTEGER
)
717 ptime
= (time_t)attr
->values
[0].integer
;
718 else if (!strcmp(attr
->name
, "printer-state-message") &&
719 attr
->value_tag
== IPP_TAG_TEXT
)
720 message
= attr
->values
[0].string
.text
;
721 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
722 attr
->value_tag
== IPP_TAG_BOOLEAN
)
723 accepting
= attr
->values
[0].boolean
;
729 * See if we have everything needed...
741 * Display the printer entry if needed...
744 if (match_list(printers
, printer
))
746 pdate
= localtime(&ptime
);
747 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
750 _cupsLangPrintf(stdout
, _("%s accepting requests since %s"),
751 printer
, printer_state_time
);
754 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -"),
755 printer
, printer_state_time
);
756 _cupsLangPrintf(stdout
, _("\t%s"),
757 (message
== NULL
|| !*message
) ?
758 "reason unknown" : message
);
761 for (i
= 0; i
< num_dests
; i
++)
762 if (!_cups_strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
765 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s"),
766 printer
, dests
[i
].instance
, printer_state_time
);
769 _cupsLangPrintf(stdout
,
770 _("%s/%s not accepting requests since %s -"),
771 printer
, dests
[i
].instance
, printer_state_time
);
772 _cupsLangPrintf(stdout
, _("\t%s"),
773 (message
== NULL
|| !*message
) ?
774 "reason unknown" : message
);
787 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
796 * 'show_classes()' - Show printer classes.
799 static int /* O - 0 on success, 1 on fail */
800 show_classes(const char *dests
) /* I - Destinations */
802 int i
; /* Looping var */
803 ipp_t
*request
, /* IPP Request */
804 *response
, /* IPP Response */
805 *response2
; /* IPP response from remote server */
806 http_t
*http2
; /* Remote server */
807 ipp_attribute_t
*attr
; /* Current attribute */
808 const char *printer
, /* Printer class name */
809 *printer_uri
; /* Printer class URI */
810 ipp_attribute_t
*members
; /* Printer members */
811 char method
[HTTP_MAX_URI
], /* Request method */
812 username
[HTTP_MAX_URI
], /* Username:password */
813 server
[HTTP_MAX_URI
], /* Server name */
814 resource
[HTTP_MAX_URI
]; /* Resource name */
815 int port
; /* Port number */
816 static const char *cattrs
[] = /* Attributes we need for classes... */
819 "printer-uri-supported",
824 DEBUG_printf(("show_classes(dests=\"%s\")\n", dests
));
826 if (dests
!= NULL
&& !strcmp(dests
, "all"))
830 * Build a CUPS_GET_CLASSES request, which requires the following
834 * attributes-natural-language
835 * requested-attributes
836 * requesting-user-name
839 request
= ippNewRequest(CUPS_GET_CLASSES
);
841 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
842 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
845 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
849 * Do the request and get back a response...
852 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
854 DEBUG_puts("show_classes: request succeeded...");
856 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
858 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
864 * Loop through the printers returned in the list and display
868 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
871 * Skip leading attributes until we hit a job...
874 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
881 * Pull the needed attributes from this job...
888 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
890 if (!strcmp(attr
->name
, "printer-name") &&
891 attr
->value_tag
== IPP_TAG_NAME
)
892 printer
= attr
->values
[0].string
.text
;
894 if (!strcmp(attr
->name
, "printer-uri-supported") &&
895 attr
->value_tag
== IPP_TAG_URI
)
896 printer_uri
= attr
->values
[0].string
.text
;
898 if (!strcmp(attr
->name
, "member-names") &&
899 attr
->value_tag
== IPP_TAG_NAME
)
906 * If this is a remote class, grab the class info from the
911 if (members
== NULL
&& printer_uri
!= NULL
)
913 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
914 username
, sizeof(username
), server
, sizeof(server
),
915 &port
, resource
, sizeof(resource
));
917 if (!_cups_strcasecmp(server
, cupsServer()))
918 http2
= CUPS_HTTP_DEFAULT
;
920 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
923 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
924 * following attributes:
927 * attributes-natural-language
929 * requested-attributes
932 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
934 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
935 "printer-uri", NULL
, printer_uri
);
937 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
938 "requested-attributes",
939 sizeof(cattrs
) / sizeof(cattrs
[0]),
942 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
943 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
950 * See if we have everything needed...
956 ippDelete(response2
);
965 * Display the printer entry if needed...
968 if (match_list(dests
, printer
))
970 _cupsLangPrintf(stdout
, _("members of class %s:"), printer
);
974 for (i
= 0; i
< members
->num_values
; i
++)
975 _cupsLangPrintf(stdout
, "\t%s", members
->values
[i
].string
.text
);
978 _cupsLangPuts(stdout
, "\tunknown");
982 ippDelete(response2
);
992 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1001 * 'show_default()' - Show default destination.
1005 show_default(cups_dest_t
*dest
) /* I - Default destination */
1007 const char *printer
, /* Printer name */
1008 *val
; /* Environment variable name */
1014 _cupsLangPrintf(stdout
, _("system default destination: %s/%s"),
1015 dest
->name
, dest
->instance
);
1017 _cupsLangPrintf(stdout
, _("system default destination: %s"),
1024 if ((printer
= getenv("LPDEST")) == NULL
)
1026 if ((printer
= getenv("PRINTER")) != NULL
)
1028 if (!strcmp(printer
, "lp"))
1038 _cupsLangPrintf(stdout
,
1039 _("lpstat: error - %s environment variable names "
1040 "non-existent destination \"%s\"."),
1043 _cupsLangPuts(stdout
, _("no system default destination"));
1049 * 'show_devices()' - Show printer devices.
1052 static int /* O - 0 on success, 1 on fail */
1053 show_devices(const char *printers
, /* I - Destinations */
1054 int num_dests
, /* I - Number of user-defined dests */
1055 cups_dest_t
*dests
) /* I - User-defined destinations */
1057 int i
; /* Looping var */
1058 ipp_t
*request
, /* IPP Request */
1059 *response
; /* IPP Response */
1060 ipp_attribute_t
*attr
; /* Current attribute */
1061 const char *printer
, /* Printer name */
1062 *uri
, /* Printer URI */
1063 *device
; /* Printer device URI */
1064 static const char *pattrs
[] = /* Attributes we need for printers... */
1067 "printer-uri-supported",
1072 DEBUG_printf(("show_devices(printers=\"%s\")\n", printers
));
1074 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1078 * Build a CUPS_GET_PRINTERS request, which requires the following
1081 * attributes-charset
1082 * attributes-natural-language
1083 * requested-attributes
1084 * requesting-user-name
1087 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1089 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1090 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1093 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1097 * Do the request and get back a response...
1100 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1102 DEBUG_puts("show_devices: request succeeded...");
1104 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1106 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1107 ippDelete(response
);
1112 * Loop through the printers returned in the list and display
1116 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1119 * Skip leading attributes until we hit a job...
1122 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1129 * Pull the needed attributes from this job...
1136 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1138 if (!strcmp(attr
->name
, "printer-name") &&
1139 attr
->value_tag
== IPP_TAG_NAME
)
1140 printer
= attr
->values
[0].string
.text
;
1142 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1143 attr
->value_tag
== IPP_TAG_URI
)
1144 uri
= attr
->values
[0].string
.text
;
1146 if (!strcmp(attr
->name
, "device-uri") &&
1147 attr
->value_tag
== IPP_TAG_URI
)
1148 device
= attr
->values
[0].string
.text
;
1154 * See if we have everything needed...
1157 if (printer
== NULL
)
1166 * Display the printer entry if needed...
1169 if (match_list(printers
, printer
))
1171 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1172 char scheme
[HTTP_MAX_URI
], /* Components of printer URI */
1173 username
[HTTP_MAX_URI
],
1174 hostname
[HTTP_MAX_URI
],
1175 resource
[HTTP_MAX_URI
];
1181 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
1182 username
, sizeof(username
), hostname
,
1183 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1184 _cupsLangPrintf(stdout
,
1185 _("Output for printer %s is sent to remote "
1186 "printer %s on %s"),
1187 printer
, strrchr(resource
, '/') + 1, hostname
);
1189 else if (!strncmp(device
, "file:", 5))
1190 _cupsLangPrintf(stdout
,
1191 _("Output for printer %s is sent to %s"),
1192 printer
, device
+ 5);
1194 _cupsLangPrintf(stdout
,
1195 _("Output for printer %s is sent to %s"),
1198 for (i
= 0; i
< num_dests
; i
++)
1199 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1202 _cupsLangPrintf(stdout
,
1203 _("Output for printer %s/%s is sent to "
1204 "remote printer %s on %s"),
1205 printer
, dests
[i
].instance
,
1206 strrchr(resource
, '/') + 1, hostname
);
1207 else if (!strncmp(device
, "file:", 5))
1208 _cupsLangPrintf(stdout
,
1209 _("Output for printer %s/%s is sent to %s"),
1210 printer
, dests
[i
].instance
, device
+ 5);
1212 _cupsLangPrintf(stdout
,
1213 _("Output for printer %s/%s is sent to %s"),
1214 printer
, dests
[i
].instance
, device
);
1218 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1220 else if (!strncmp(device
, "file:", 5))
1221 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1222 printer
, device
+ 5);
1224 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1227 for (i
= 0; i
< num_dests
; i
++)
1228 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1231 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1232 printer
, dests
[i
].instance
, uri
);
1233 else if (!strncmp(device
, "file:", 5))
1234 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1235 printer
, dests
[i
].instance
, device
+ 5);
1237 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1238 printer
, dests
[i
].instance
, device
);
1240 #endif /* __osf__ */
1247 ippDelete(response
);
1251 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1260 * 'show_jobs()' - Show active print jobs.
1263 static int /* O - 0 on success, 1 on fail */
1264 show_jobs(const char *dests
, /* I - Destinations */
1265 const char *users
, /* I - Users */
1266 int long_status
, /* I - Show long status? */
1267 int ranking
, /* I - Show job ranking? */
1268 const char *which
) /* I - Show which jobs? */
1270 int i
; /* Looping var */
1271 ipp_t
*request
, /* IPP Request */
1272 *response
; /* IPP Response */
1273 ipp_attribute_t
*attr
, /* Current attribute */
1274 *reasons
; /* Job state reasons attribute */
1275 const char *dest
, /* Pointer into job-printer-uri */
1276 *username
, /* Pointer to job-originating-user-name */
1277 *title
, /* Pointer to job-name */
1278 *message
; /* Pointer to job-printer-state-message */
1279 int rank
, /* Rank in queue */
1281 size
; /* job-k-octets */
1282 time_t jobtime
; /* time-at-creation */
1283 struct tm
*jobdate
; /* Date & time */
1284 char temp
[255], /* Temporary buffer */
1285 date
[255]; /* Date buffer */
1286 static const char *jattrs
[] = /* Attributes we need for jobs... */
1291 "job-originating-user-name",
1292 "job-printer-state-message",
1294 "job-state-reasons",
1299 DEBUG_printf(("show_jobs(dests=\"%s\", users=\"%s\", long_status=%d, "
1300 "ranking=%d, which=\"%s\")\n", dests
, users
, long_status
,
1303 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1307 * Build a IPP_GET_JOBS request, which requires the following
1310 * attributes-charset
1311 * attributes-natural-language
1313 * requested-attributes
1314 * requesting-user-name
1318 request
= ippNewRequest(IPP_GET_JOBS
);
1320 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1321 NULL
, "ipp://localhost/");
1323 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1324 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1327 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1330 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1334 * Do the request and get back a response...
1337 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1340 * Loop through the job list and display them...
1343 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1345 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1346 ippDelete(response
);
1352 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1355 * Skip leading attributes until we hit a job...
1358 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1365 * Pull the needed attributes from this job...
1377 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1379 if (!strcmp(attr
->name
, "job-id") &&
1380 attr
->value_tag
== IPP_TAG_INTEGER
)
1381 jobid
= attr
->values
[0].integer
;
1382 else if (!strcmp(attr
->name
, "job-k-octets") &&
1383 attr
->value_tag
== IPP_TAG_INTEGER
)
1384 size
= attr
->values
[0].integer
;
1385 else if (!strcmp(attr
->name
, "time-at-creation") &&
1386 attr
->value_tag
== IPP_TAG_INTEGER
)
1387 jobtime
= attr
->values
[0].integer
;
1388 else if (!strcmp(attr
->name
, "job-printer-state-message") &&
1389 attr
->value_tag
== IPP_TAG_TEXT
)
1390 message
= attr
->values
[0].string
.text
;
1391 else if (!strcmp(attr
->name
, "job-printer-uri") &&
1392 attr
->value_tag
== IPP_TAG_URI
)
1394 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1397 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
1398 attr
->value_tag
== IPP_TAG_NAME
)
1399 username
= attr
->values
[0].string
.text
;
1400 else if (!strcmp(attr
->name
, "job-name") &&
1401 attr
->value_tag
== IPP_TAG_NAME
)
1402 title
= attr
->values
[0].string
.text
;
1403 else if (!strcmp(attr
->name
, "job-state-reasons") &&
1404 attr
->value_tag
== IPP_TAG_KEYWORD
)
1411 * See if we have everything needed...
1414 if (dest
== NULL
|| jobid
== 0)
1423 * Display the job...
1428 if (match_list(dests
, dest
) && match_list(users
, username
))
1430 jobdate
= localtime(&jobtime
);
1431 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1433 if (long_status
== 3)
1436 * Show the consolidated output format for the SGI tools...
1439 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1440 strcpy(date
, "Unknown");
1442 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s",
1443 temp
, username
? username
: "unknown",
1444 size
, title
? title
: "unknown", date
);
1448 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1449 strcpy(date
, "Unknown");
1452 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s",
1453 rank
, temp
, username
? username
: "unknown",
1454 1024.0 * size
, date
);
1456 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s",
1457 temp
, username
? username
: "unknown",
1458 1024.0 * size
, date
);
1462 _cupsLangPrintf(stdout
, _("\tStatus: %s"), message
);
1466 char alerts
[1024], /* Alerts string */
1467 *aptr
; /* Pointer into alerts string */
1469 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1472 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1473 reasons
->values
[i
].string
.text
);
1475 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1478 aptr
+= strlen(aptr
);
1481 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1484 _cupsLangPrintf(stdout
, _("\tqueued for %s"), dest
);
1493 ippDelete(response
);
1497 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1506 * 'show_printers()' - Show printers.
1509 static int /* O - 0 on success, 1 on fail */
1510 show_printers(const char *printers
, /* I - Destinations */
1511 int num_dests
, /* I - Number of user-defined dests */
1512 cups_dest_t
*dests
, /* I - User-defined destinations */
1513 int long_status
) /* I - Show long status? */
1515 int i
, j
; /* Looping vars */
1516 ipp_t
*request
, /* IPP Request */
1517 *response
, /* IPP Response */
1518 *jobs
; /* IPP Get Jobs response */
1519 ipp_attribute_t
*attr
, /* Current attribute */
1520 *jobattr
, /* Job ID attribute */
1521 *reasons
; /* Job state reasons attribute */
1522 const char *printer
, /* Printer name */
1523 *message
, /* Printer state message */
1524 *description
, /* Description of printer */
1525 *location
, /* Location of printer */
1526 *make_model
, /* Make and model of printer */
1527 *uri
; /* URI of printer */
1528 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1529 *denied
; /* requestint-user-name-denied */
1530 ipp_pstate_t pstate
; /* Printer state */
1531 cups_ptype_t ptype
; /* Printer type */
1532 time_t ptime
; /* Printer state time */
1533 struct tm
*pdate
; /* Printer state date & time */
1534 int jobid
; /* Job ID of current job */
1535 char printer_uri
[HTTP_MAX_URI
],
1537 printer_state_time
[255];/* Printer state time */
1538 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
1539 static const char *pattrs
[] = /* Attributes we need for printers... */
1543 "printer-state-message",
1544 "printer-state-reasons",
1545 "printer-state-change-time",
1549 "printer-make-and-model",
1550 "printer-uri-supported",
1551 "requesting-user-name-allowed",
1552 "requesting-user-name-denied"
1554 static const char *jattrs
[] = /* Attributes we need for jobs... */
1561 DEBUG_printf(("show_printers(printers=\"%s\", num_dests=%d, dests=%p, "
1562 "long_status=%d)\n", printers
, num_dests
, dests
, long_status
));
1564 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1568 * Build a CUPS_GET_PRINTERS request, which requires the following
1571 * attributes-charset
1572 * attributes-natural-language
1573 * requested-attributes
1574 * requesting-user-name
1577 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1579 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1580 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1583 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1587 * Do the request and get back a response...
1590 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1592 DEBUG_puts("show_printers: request succeeded...");
1594 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1596 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1597 ippDelete(response
);
1602 * Loop through the printers returned in the list and display
1606 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1609 * Skip leading attributes until we hit a job...
1612 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1619 * Pull the needed attributes from this job...
1624 ptype
= CUPS_PRINTER_LOCAL
;
1625 pstate
= IPP_PRINTER_IDLE
;
1636 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1638 if (!strcmp(attr
->name
, "printer-name") &&
1639 attr
->value_tag
== IPP_TAG_NAME
)
1640 printer
= attr
->values
[0].string
.text
;
1641 else if (!strcmp(attr
->name
, "printer-state") &&
1642 attr
->value_tag
== IPP_TAG_ENUM
)
1643 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1644 else if (!strcmp(attr
->name
, "printer-type") &&
1645 attr
->value_tag
== IPP_TAG_ENUM
)
1646 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1647 else if (!strcmp(attr
->name
, "printer-state-message") &&
1648 attr
->value_tag
== IPP_TAG_TEXT
)
1649 message
= attr
->values
[0].string
.text
;
1650 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1651 attr
->value_tag
== IPP_TAG_INTEGER
)
1652 ptime
= (time_t)attr
->values
[0].integer
;
1653 else if (!strcmp(attr
->name
, "printer-info") &&
1654 attr
->value_tag
== IPP_TAG_TEXT
)
1655 description
= attr
->values
[0].string
.text
;
1656 else if (!strcmp(attr
->name
, "printer-location") &&
1657 attr
->value_tag
== IPP_TAG_TEXT
)
1658 location
= attr
->values
[0].string
.text
;
1659 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1660 attr
->value_tag
== IPP_TAG_TEXT
)
1661 make_model
= attr
->values
[0].string
.text
;
1662 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1663 attr
->value_tag
== IPP_TAG_URI
)
1664 uri
= attr
->values
[0].string
.text
;
1665 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1666 attr
->value_tag
== IPP_TAG_KEYWORD
)
1668 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1669 attr
->value_tag
== IPP_TAG_NAME
)
1671 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1672 attr
->value_tag
== IPP_TAG_NAME
)
1679 * See if we have everything needed...
1682 if (printer
== NULL
)
1691 * Display the printer entry if needed...
1694 if (match_list(printers
, printer
))
1697 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1698 * current job for the printer.
1701 if (pstate
== IPP_PRINTER_PROCESSING
)
1704 * Build an IPP_GET_JOBS request, which requires the following
1707 * attributes-charset
1708 * attributes-natural-language
1711 * requested-attributes
1714 request
= ippNewRequest(IPP_GET_JOBS
);
1716 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1717 request
->request
.op
.request_id
= 1;
1719 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1720 "requested-attributes",
1721 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1723 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1724 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1725 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1726 "printer-uri", NULL
, printer_uri
);
1728 if ((jobs
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1731 * Get the current active job on this queue...
1734 ipp_jstate_t jobstate
= IPP_JOB_PENDING
;
1737 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1741 if (jobstate
== IPP_JOB_PROCESSING
)
1747 if (!strcmp(jobattr
->name
, "job-id") &&
1748 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1749 jobid
= jobattr
->values
[0].integer
;
1750 else if (!strcmp(jobattr
->name
, "job-state") &&
1751 jobattr
->value_tag
== IPP_TAG_ENUM
)
1752 jobstate
= jobattr
->values
[0].integer
;
1755 if (jobstate
!= IPP_JOB_PROCESSING
)
1766 pdate
= localtime(&ptime
);
1767 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
1771 case IPP_PRINTER_IDLE
:
1772 _cupsLangPrintf(stdout
,
1773 _("printer %s is idle. enabled since %s"),
1774 printer
, printer_state_time
);
1776 case IPP_PRINTER_PROCESSING
:
1777 _cupsLangPrintf(stdout
,
1778 _("printer %s now printing %s-%d. "
1779 "enabled since %s"),
1780 printer
, printer
, jobid
, printer_state_time
);
1782 case IPP_PRINTER_STOPPED
:
1783 _cupsLangPrintf(stdout
,
1784 _("printer %s disabled since %s -"),
1785 printer
, printer_state_time
);
1789 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1791 if (!message
|| !*message
)
1792 _cupsLangPuts(stdout
, _("\treason unknown"));
1794 _cupsLangPrintf(stdout
, "\t%s", message
);
1797 if (long_status
> 1)
1799 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1800 _cupsLangPuts(stdout
, _("\tContent types: any"));
1801 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1806 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1807 description
? description
: "");
1811 char alerts
[1024], /* Alerts string */
1812 *aptr
; /* Pointer into alerts string */
1814 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1817 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1818 reasons
->values
[i
].string
.text
);
1820 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1823 aptr
+= strlen(aptr
);
1826 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1829 if (long_status
> 1)
1831 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1832 location
? location
: "");
1834 if (ptype
& CUPS_PRINTER_REMOTE
)
1836 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1838 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1839 !strstr(make_model
, "Raw Printer") && uri
)
1840 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"),
1845 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1847 if (make_model
&& strstr(make_model
, "System V Printer"))
1848 _cupsLangPrintf(stdout
,
1849 _("\tInterface: %s/interfaces/%s"),
1850 cg
->cups_serverroot
, printer
);
1851 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
1852 _cupsLangPrintf(stdout
,
1853 _("\tInterface: %s/ppd/%s.ppd"),
1854 cg
->cups_serverroot
, printer
);
1856 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1857 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1858 /* TODO update to use printer-error-policy */
1861 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1862 for (j
= 0; j
< allowed
->num_values
; j
++)
1863 _cupsLangPrintf(stdout
, "\t\t%s",
1864 allowed
->values
[j
].string
.text
);
1868 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1869 for (j
= 0; j
< denied
->num_values
; j
++)
1870 _cupsLangPrintf(stdout
, "\t\t%s",
1871 denied
->values
[j
].string
.text
);
1875 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1876 _cupsLangPuts(stdout
, _("\t\t(all)"));
1878 _cupsLangPuts(stdout
, _("\tForms allowed:"));
1879 _cupsLangPuts(stdout
, _("\t\t(none)"));
1880 _cupsLangPuts(stdout
, _("\tBanner required"));
1881 _cupsLangPuts(stdout
, _("\tCharset sets:"));
1882 _cupsLangPuts(stdout
, _("\t\t(none)"));
1883 _cupsLangPuts(stdout
, _("\tDefault pitch:"));
1884 _cupsLangPuts(stdout
, _("\tDefault page size:"));
1885 _cupsLangPuts(stdout
, _("\tDefault port settings:"));
1888 for (i
= 0; i
< num_dests
; i
++)
1889 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1893 case IPP_PRINTER_IDLE
:
1894 _cupsLangPrintf(stdout
,
1895 _("printer %s/%s is idle. "
1896 "enabled since %s"),
1897 printer
, dests
[i
].instance
,
1898 printer_state_time
);
1900 case IPP_PRINTER_PROCESSING
:
1901 _cupsLangPrintf(stdout
,
1902 _("printer %s/%s now printing %s-%d. "
1903 "enabled since %s"),
1904 printer
, dests
[i
].instance
, printer
, jobid
,
1905 printer_state_time
);
1907 case IPP_PRINTER_STOPPED
:
1908 _cupsLangPrintf(stdout
,
1909 _("printer %s/%s disabled since %s -"),
1910 printer
, dests
[i
].instance
,
1911 printer_state_time
);
1915 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1917 if (!message
|| !*message
)
1918 _cupsLangPuts(stdout
, _("\treason unknown"));
1920 _cupsLangPrintf(stdout
, "\t%s", message
);
1923 if (long_status
> 1)
1925 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1926 _cupsLangPuts(stdout
, _("\tContent types: any"));
1927 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1932 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1933 description
? description
: "");
1937 char alerts
[1024], /* Alerts string */
1938 *aptr
; /* Pointer into alerts string */
1940 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1943 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1944 reasons
->values
[i
].string
.text
);
1946 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1949 aptr
+= strlen(aptr
);
1952 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1955 if (long_status
> 1)
1957 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1958 location
? location
: "");
1960 if (ptype
& CUPS_PRINTER_REMOTE
)
1962 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1964 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1965 !strstr(make_model
, "Raw Printer") && uri
)
1966 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"), uri
);
1970 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1972 if (make_model
&& strstr(make_model
, "System V Printer"))
1973 _cupsLangPrintf(stdout
,
1974 _("\tInterface: %s/interfaces/%s"),
1975 cg
->cups_serverroot
, printer
);
1976 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
1977 _cupsLangPrintf(stdout
,
1978 _("\tInterface: %s/ppd/%s.ppd"),
1979 cg
->cups_serverroot
, printer
);
1981 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1982 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1983 /* TODO update to use printer-error-policy */
1986 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1987 for (j
= 0; j
< allowed
->num_values
; j
++)
1988 _cupsLangPrintf(stdout
, "\t\t%s",
1989 allowed
->values
[j
].string
.text
);
1993 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1994 for (j
= 0; j
< denied
->num_values
; j
++)
1995 _cupsLangPrintf(stdout
, "\t\t%s",
1996 denied
->values
[j
].string
.text
);
2000 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
2001 _cupsLangPuts(stdout
, _("\t\t(all)"));
2003 _cupsLangPuts(stdout
, _("\tForms allowed:"));
2004 _cupsLangPuts(stdout
, _("\t\t(none)"));
2005 _cupsLangPuts(stdout
, _("\tBanner required"));
2006 _cupsLangPuts(stdout
, _("\tCharset sets:"));
2007 _cupsLangPuts(stdout
, _("\t\t(none)"));
2008 _cupsLangPuts(stdout
, _("\tDefault pitch:"));
2009 _cupsLangPuts(stdout
, _("\tDefault page size:"));
2010 _cupsLangPuts(stdout
, _("\tDefault port settings:"));
2019 ippDelete(response
);
2023 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
2032 * 'show_scheduler()' - Show scheduler status.
2036 show_scheduler(void)
2038 http_t
*http
; /* Connection to server */
2041 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
2042 cupsEncryption())) != NULL
)
2044 _cupsLangPuts(stdout
, _("scheduler is running"));
2048 _cupsLangPuts(stdout
, _("scheduler is not running"));
2053 * End of "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $".