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...
586 * Skip leading whitespace and commas...
589 while (isspace(*list
& 255) || *list
== ',')
600 *nameptr
&& *list
&& tolower(*nameptr
& 255) == tolower(*list
& 255);
601 nameptr
++, list
++);
603 if (!*nameptr
&& (!*list
|| *list
== ',' || isspace(*list
& 255)))
606 while (*list
&& !isspace(*list
& 255) && *list
!= ',')
615 * 'show_accepting()' - Show acceptance status.
618 static int /* O - 0 on success, 1 on fail */
619 show_accepting(const char *printers
, /* I - Destinations */
620 int num_dests
, /* I - Number of user-defined dests */
621 cups_dest_t
*dests
) /* I - User-defined destinations */
623 int i
; /* Looping var */
624 ipp_t
*request
, /* IPP Request */
625 *response
; /* IPP Response */
626 ipp_attribute_t
*attr
; /* Current attribute */
627 const char *printer
, /* Printer name */
628 *message
; /* Printer device URI */
629 int accepting
; /* Accepting requests? */
630 time_t ptime
; /* Printer state time */
631 struct tm
*pdate
; /* Printer state date & time */
632 char printer_state_time
[255];/* Printer state time */
633 static const char *pattrs
[] = /* Attributes we need for printers... */
636 "printer-state-change-time",
637 "printer-state-message",
638 "printer-is-accepting-jobs"
642 DEBUG_printf(("show_accepting(printers=\"%s\")\n", printers
));
644 if (printers
!= NULL
&& !strcmp(printers
, "all"))
648 * Build a CUPS_GET_PRINTERS request, which requires the following
652 * attributes-natural-language
653 * requested-attributes
654 * requesting-user-name
657 request
= ippNewRequest(CUPS_GET_PRINTERS
);
659 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
660 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
663 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
667 * Do the request and get back a response...
670 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
672 DEBUG_puts("show_accepting: request succeeded...");
674 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
676 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
682 * Loop through the printers returned in the list and display
686 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
689 * Skip leading attributes until we hit a printer...
692 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
699 * Pull the needed attributes from this printer...
707 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
709 if (!strcmp(attr
->name
, "printer-name") &&
710 attr
->value_tag
== IPP_TAG_NAME
)
711 printer
= attr
->values
[0].string
.text
;
712 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
713 attr
->value_tag
== IPP_TAG_INTEGER
)
714 ptime
= (time_t)attr
->values
[0].integer
;
715 else if (!strcmp(attr
->name
, "printer-state-message") &&
716 attr
->value_tag
== IPP_TAG_TEXT
)
717 message
= attr
->values
[0].string
.text
;
718 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
719 attr
->value_tag
== IPP_TAG_BOOLEAN
)
720 accepting
= attr
->values
[0].boolean
;
726 * See if we have everything needed...
738 * Display the printer entry if needed...
741 if (match_list(printers
, printer
))
743 pdate
= localtime(&ptime
);
744 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
747 _cupsLangPrintf(stdout
, _("%s accepting requests since %s"),
748 printer
, printer_state_time
);
751 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -"),
752 printer
, printer_state_time
);
753 _cupsLangPrintf(stdout
, _("\t%s"),
754 (message
== NULL
|| !*message
) ?
755 "reason unknown" : message
);
758 for (i
= 0; i
< num_dests
; i
++)
759 if (!_cups_strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
762 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s"),
763 printer
, dests
[i
].instance
, printer_state_time
);
766 _cupsLangPrintf(stdout
,
767 _("%s/%s not accepting requests since %s -"),
768 printer
, dests
[i
].instance
, printer_state_time
);
769 _cupsLangPrintf(stdout
, _("\t%s"),
770 (message
== NULL
|| !*message
) ?
771 "reason unknown" : message
);
784 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
793 * 'show_classes()' - Show printer classes.
796 static int /* O - 0 on success, 1 on fail */
797 show_classes(const char *dests
) /* I - Destinations */
799 int i
; /* Looping var */
800 ipp_t
*request
, /* IPP Request */
801 *response
, /* IPP Response */
802 *response2
; /* IPP response from remote server */
803 http_t
*http2
; /* Remote server */
804 ipp_attribute_t
*attr
; /* Current attribute */
805 const char *printer
, /* Printer class name */
806 *printer_uri
; /* Printer class URI */
807 ipp_attribute_t
*members
; /* Printer members */
808 char method
[HTTP_MAX_URI
], /* Request method */
809 username
[HTTP_MAX_URI
], /* Username:password */
810 server
[HTTP_MAX_URI
], /* Server name */
811 resource
[HTTP_MAX_URI
]; /* Resource name */
812 int port
; /* Port number */
813 static const char *cattrs
[] = /* Attributes we need for classes... */
816 "printer-uri-supported",
821 DEBUG_printf(("show_classes(dests=\"%s\")\n", dests
));
823 if (dests
!= NULL
&& !strcmp(dests
, "all"))
827 * Build a CUPS_GET_CLASSES request, which requires the following
831 * attributes-natural-language
832 * requested-attributes
833 * requesting-user-name
836 request
= ippNewRequest(CUPS_GET_CLASSES
);
838 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
839 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
842 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
846 * Do the request and get back a response...
849 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
851 DEBUG_puts("show_classes: request succeeded...");
853 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
855 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
861 * Loop through the printers returned in the list and display
865 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
868 * Skip leading attributes until we hit a job...
871 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
878 * Pull the needed attributes from this job...
885 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
887 if (!strcmp(attr
->name
, "printer-name") &&
888 attr
->value_tag
== IPP_TAG_NAME
)
889 printer
= attr
->values
[0].string
.text
;
891 if (!strcmp(attr
->name
, "printer-uri-supported") &&
892 attr
->value_tag
== IPP_TAG_URI
)
893 printer_uri
= attr
->values
[0].string
.text
;
895 if (!strcmp(attr
->name
, "member-names") &&
896 attr
->value_tag
== IPP_TAG_NAME
)
903 * If this is a remote class, grab the class info from the
908 if (members
== NULL
&& printer_uri
!= NULL
)
910 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
911 username
, sizeof(username
), server
, sizeof(server
),
912 &port
, resource
, sizeof(resource
));
914 if (!_cups_strcasecmp(server
, cupsServer()))
915 http2
= CUPS_HTTP_DEFAULT
;
917 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
920 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
921 * following attributes:
924 * attributes-natural-language
926 * requested-attributes
929 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
931 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
932 "printer-uri", NULL
, printer_uri
);
934 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
935 "requested-attributes",
936 sizeof(cattrs
) / sizeof(cattrs
[0]),
939 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
940 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
947 * See if we have everything needed...
953 ippDelete(response2
);
962 * Display the printer entry if needed...
965 if (match_list(dests
, printer
))
967 _cupsLangPrintf(stdout
, _("members of class %s:"), printer
);
971 for (i
= 0; i
< members
->num_values
; i
++)
972 _cupsLangPrintf(stdout
, "\t%s", members
->values
[i
].string
.text
);
975 _cupsLangPuts(stdout
, "\tunknown");
979 ippDelete(response2
);
989 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
998 * 'show_default()' - Show default destination.
1002 show_default(cups_dest_t
*dest
) /* I - Default destination */
1004 const char *printer
, /* Printer name */
1005 *val
; /* Environment variable name */
1011 _cupsLangPrintf(stdout
, _("system default destination: %s/%s"),
1012 dest
->name
, dest
->instance
);
1014 _cupsLangPrintf(stdout
, _("system default destination: %s"),
1021 if ((printer
= getenv("LPDEST")) == NULL
)
1023 if ((printer
= getenv("PRINTER")) != NULL
)
1025 if (!strcmp(printer
, "lp"))
1035 _cupsLangPrintf(stdout
,
1036 _("lpstat: error - %s environment variable names "
1037 "non-existent destination \"%s\"."),
1040 _cupsLangPuts(stdout
, _("no system default destination"));
1046 * 'show_devices()' - Show printer devices.
1049 static int /* O - 0 on success, 1 on fail */
1050 show_devices(const char *printers
, /* I - Destinations */
1051 int num_dests
, /* I - Number of user-defined dests */
1052 cups_dest_t
*dests
) /* I - User-defined destinations */
1054 int i
; /* Looping var */
1055 ipp_t
*request
, /* IPP Request */
1056 *response
; /* IPP Response */
1057 ipp_attribute_t
*attr
; /* Current attribute */
1058 const char *printer
, /* Printer name */
1059 *uri
, /* Printer URI */
1060 *device
; /* Printer device URI */
1061 static const char *pattrs
[] = /* Attributes we need for printers... */
1064 "printer-uri-supported",
1069 DEBUG_printf(("show_devices(printers=\"%s\")\n", printers
));
1071 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1075 * Build a CUPS_GET_PRINTERS request, which requires the following
1078 * attributes-charset
1079 * attributes-natural-language
1080 * requested-attributes
1081 * requesting-user-name
1084 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1086 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1087 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1090 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1094 * Do the request and get back a response...
1097 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1099 DEBUG_puts("show_devices: request succeeded...");
1101 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1103 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1104 ippDelete(response
);
1109 * Loop through the printers returned in the list and display
1113 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1116 * Skip leading attributes until we hit a job...
1119 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1126 * Pull the needed attributes from this job...
1133 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1135 if (!strcmp(attr
->name
, "printer-name") &&
1136 attr
->value_tag
== IPP_TAG_NAME
)
1137 printer
= attr
->values
[0].string
.text
;
1139 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1140 attr
->value_tag
== IPP_TAG_URI
)
1141 uri
= attr
->values
[0].string
.text
;
1143 if (!strcmp(attr
->name
, "device-uri") &&
1144 attr
->value_tag
== IPP_TAG_URI
)
1145 device
= attr
->values
[0].string
.text
;
1151 * See if we have everything needed...
1154 if (printer
== NULL
)
1163 * Display the printer entry if needed...
1166 if (match_list(printers
, printer
))
1168 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1169 char scheme
[HTTP_MAX_URI
], /* Components of printer URI */
1170 username
[HTTP_MAX_URI
],
1171 hostname
[HTTP_MAX_URI
],
1172 resource
[HTTP_MAX_URI
];
1178 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, scheme
, sizeof(scheme
),
1179 username
, sizeof(username
), hostname
,
1180 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1181 _cupsLangPrintf(stdout
,
1182 _("Output for printer %s is sent to remote "
1183 "printer %s on %s"),
1184 printer
, strrchr(resource
, '/') + 1, hostname
);
1186 else if (!strncmp(device
, "file:", 5))
1187 _cupsLangPrintf(stdout
,
1188 _("Output for printer %s is sent to %s"),
1189 printer
, device
+ 5);
1191 _cupsLangPrintf(stdout
,
1192 _("Output for printer %s is sent to %s"),
1195 for (i
= 0; i
< num_dests
; i
++)
1196 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1199 _cupsLangPrintf(stdout
,
1200 _("Output for printer %s/%s is sent to "
1201 "remote printer %s on %s"),
1202 printer
, dests
[i
].instance
,
1203 strrchr(resource
, '/') + 1, hostname
);
1204 else if (!strncmp(device
, "file:", 5))
1205 _cupsLangPrintf(stdout
,
1206 _("Output for printer %s/%s is sent to %s"),
1207 printer
, dests
[i
].instance
, device
+ 5);
1209 _cupsLangPrintf(stdout
,
1210 _("Output for printer %s/%s is sent to %s"),
1211 printer
, dests
[i
].instance
, device
);
1215 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1217 else if (!strncmp(device
, "file:", 5))
1218 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1219 printer
, device
+ 5);
1221 _cupsLangPrintf(stdout
, _("device for %s: %s"),
1224 for (i
= 0; i
< num_dests
; i
++)
1225 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1228 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1229 printer
, dests
[i
].instance
, uri
);
1230 else if (!strncmp(device
, "file:", 5))
1231 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1232 printer
, dests
[i
].instance
, device
+ 5);
1234 _cupsLangPrintf(stdout
, _("device for %s/%s: %s"),
1235 printer
, dests
[i
].instance
, device
);
1237 #endif /* __osf__ */
1244 ippDelete(response
);
1248 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1257 * 'show_jobs()' - Show active print jobs.
1260 static int /* O - 0 on success, 1 on fail */
1261 show_jobs(const char *dests
, /* I - Destinations */
1262 const char *users
, /* I - Users */
1263 int long_status
, /* I - Show long status? */
1264 int ranking
, /* I - Show job ranking? */
1265 const char *which
) /* I - Show which jobs? */
1267 int i
; /* Looping var */
1268 ipp_t
*request
, /* IPP Request */
1269 *response
; /* IPP Response */
1270 ipp_attribute_t
*attr
, /* Current attribute */
1271 *reasons
; /* Job state reasons attribute */
1272 const char *dest
, /* Pointer into job-printer-uri */
1273 *username
, /* Pointer to job-originating-user-name */
1274 *title
, /* Pointer to job-name */
1275 *message
; /* Pointer to job-printer-state-message */
1276 int rank
, /* Rank in queue */
1278 size
; /* job-k-octets */
1279 time_t jobtime
; /* time-at-creation */
1280 struct tm
*jobdate
; /* Date & time */
1281 char temp
[255], /* Temporary buffer */
1282 date
[255]; /* Date buffer */
1283 static const char *jattrs
[] = /* Attributes we need for jobs... */
1288 "job-originating-user-name",
1289 "job-printer-state-message",
1291 "job-state-reasons",
1296 DEBUG_printf(("show_jobs(dests=\"%s\", users=\"%s\", long_status=%d, "
1297 "ranking=%d, which=\"%s\")\n", dests
, users
, long_status
,
1300 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1304 * Build a IPP_GET_JOBS request, which requires the following
1307 * attributes-charset
1308 * attributes-natural-language
1310 * requested-attributes
1311 * requesting-user-name
1315 request
= ippNewRequest(IPP_GET_JOBS
);
1317 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "printer-uri",
1318 NULL
, "ipp://localhost/");
1320 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1321 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1324 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1327 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1331 * Do the request and get back a response...
1334 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1337 * Loop through the job list and display them...
1340 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1342 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1343 ippDelete(response
);
1349 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1352 * Skip leading attributes until we hit a job...
1355 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1362 * Pull the needed attributes from this job...
1374 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1376 if (!strcmp(attr
->name
, "job-id") &&
1377 attr
->value_tag
== IPP_TAG_INTEGER
)
1378 jobid
= attr
->values
[0].integer
;
1379 else if (!strcmp(attr
->name
, "job-k-octets") &&
1380 attr
->value_tag
== IPP_TAG_INTEGER
)
1381 size
= attr
->values
[0].integer
;
1382 else if (!strcmp(attr
->name
, "time-at-creation") &&
1383 attr
->value_tag
== IPP_TAG_INTEGER
)
1384 jobtime
= attr
->values
[0].integer
;
1385 else if (!strcmp(attr
->name
, "job-printer-state-message") &&
1386 attr
->value_tag
== IPP_TAG_TEXT
)
1387 message
= attr
->values
[0].string
.text
;
1388 else if (!strcmp(attr
->name
, "job-printer-uri") &&
1389 attr
->value_tag
== IPP_TAG_URI
)
1391 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1394 else if (!strcmp(attr
->name
, "job-originating-user-name") &&
1395 attr
->value_tag
== IPP_TAG_NAME
)
1396 username
= attr
->values
[0].string
.text
;
1397 else if (!strcmp(attr
->name
, "job-name") &&
1398 attr
->value_tag
== IPP_TAG_NAME
)
1399 title
= attr
->values
[0].string
.text
;
1400 else if (!strcmp(attr
->name
, "job-state-reasons") &&
1401 attr
->value_tag
== IPP_TAG_KEYWORD
)
1408 * See if we have everything needed...
1411 if (dest
== NULL
|| jobid
== 0)
1420 * Display the job...
1425 if (match_list(dests
, dest
) && match_list(users
, username
))
1427 jobdate
= localtime(&jobtime
);
1428 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1430 if (long_status
== 3)
1433 * Show the consolidated output format for the SGI tools...
1436 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1437 strcpy(date
, "Unknown");
1439 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s",
1440 temp
, username
? username
: "unknown",
1441 size
, title
? title
: "unknown", date
);
1445 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1446 strcpy(date
, "Unknown");
1449 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s",
1450 rank
, temp
, username
? username
: "unknown",
1451 1024.0 * size
, date
);
1453 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s",
1454 temp
, username
? username
: "unknown",
1455 1024.0 * size
, date
);
1459 _cupsLangPrintf(stdout
, _("\tStatus: %s"), message
);
1463 char alerts
[1024], /* Alerts string */
1464 *aptr
; /* Pointer into alerts string */
1466 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1469 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1470 reasons
->values
[i
].string
.text
);
1472 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1475 aptr
+= strlen(aptr
);
1478 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1481 _cupsLangPrintf(stdout
, _("\tqueued for %s"), dest
);
1490 ippDelete(response
);
1494 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1503 * 'show_printers()' - Show printers.
1506 static int /* O - 0 on success, 1 on fail */
1507 show_printers(const char *printers
, /* I - Destinations */
1508 int num_dests
, /* I - Number of user-defined dests */
1509 cups_dest_t
*dests
, /* I - User-defined destinations */
1510 int long_status
) /* I - Show long status? */
1512 int i
, j
; /* Looping vars */
1513 ipp_t
*request
, /* IPP Request */
1514 *response
, /* IPP Response */
1515 *jobs
; /* IPP Get Jobs response */
1516 ipp_attribute_t
*attr
, /* Current attribute */
1517 *jobattr
, /* Job ID attribute */
1518 *reasons
; /* Job state reasons attribute */
1519 const char *printer
, /* Printer name */
1520 *message
, /* Printer state message */
1521 *description
, /* Description of printer */
1522 *location
, /* Location of printer */
1523 *make_model
, /* Make and model of printer */
1524 *uri
; /* URI of printer */
1525 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1526 *denied
; /* requestint-user-name-denied */
1527 ipp_pstate_t pstate
; /* Printer state */
1528 cups_ptype_t ptype
; /* Printer type */
1529 time_t ptime
; /* Printer state time */
1530 struct tm
*pdate
; /* Printer state date & time */
1531 int jobid
; /* Job ID of current job */
1532 char printer_uri
[HTTP_MAX_URI
],
1534 printer_state_time
[255];/* Printer state time */
1535 _cups_globals_t
*cg
= _cupsGlobals(); /* Global data */
1536 static const char *pattrs
[] = /* Attributes we need for printers... */
1540 "printer-state-message",
1541 "printer-state-reasons",
1542 "printer-state-change-time",
1546 "printer-make-and-model",
1547 "printer-uri-supported",
1548 "requesting-user-name-allowed",
1549 "requesting-user-name-denied"
1551 static const char *jattrs
[] = /* Attributes we need for jobs... */
1558 DEBUG_printf(("show_printers(printers=\"%s\", num_dests=%d, dests=%p, "
1559 "long_status=%d)\n", printers
, num_dests
, dests
, long_status
));
1561 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1565 * Build a CUPS_GET_PRINTERS request, which requires the following
1568 * attributes-charset
1569 * attributes-natural-language
1570 * requested-attributes
1571 * requesting-user-name
1574 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1576 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1577 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1580 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1584 * Do the request and get back a response...
1587 if ((response
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1589 DEBUG_puts("show_printers: request succeeded...");
1591 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1593 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
1594 ippDelete(response
);
1599 * Loop through the printers returned in the list and display
1603 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1606 * Skip leading attributes until we hit a job...
1609 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1616 * Pull the needed attributes from this job...
1621 ptype
= CUPS_PRINTER_LOCAL
;
1622 pstate
= IPP_PRINTER_IDLE
;
1633 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1635 if (!strcmp(attr
->name
, "printer-name") &&
1636 attr
->value_tag
== IPP_TAG_NAME
)
1637 printer
= attr
->values
[0].string
.text
;
1638 else if (!strcmp(attr
->name
, "printer-state") &&
1639 attr
->value_tag
== IPP_TAG_ENUM
)
1640 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1641 else if (!strcmp(attr
->name
, "printer-type") &&
1642 attr
->value_tag
== IPP_TAG_ENUM
)
1643 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1644 else if (!strcmp(attr
->name
, "printer-state-message") &&
1645 attr
->value_tag
== IPP_TAG_TEXT
)
1646 message
= attr
->values
[0].string
.text
;
1647 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1648 attr
->value_tag
== IPP_TAG_INTEGER
)
1649 ptime
= (time_t)attr
->values
[0].integer
;
1650 else if (!strcmp(attr
->name
, "printer-info") &&
1651 attr
->value_tag
== IPP_TAG_TEXT
)
1652 description
= attr
->values
[0].string
.text
;
1653 else if (!strcmp(attr
->name
, "printer-location") &&
1654 attr
->value_tag
== IPP_TAG_TEXT
)
1655 location
= attr
->values
[0].string
.text
;
1656 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1657 attr
->value_tag
== IPP_TAG_TEXT
)
1658 make_model
= attr
->values
[0].string
.text
;
1659 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1660 attr
->value_tag
== IPP_TAG_URI
)
1661 uri
= attr
->values
[0].string
.text
;
1662 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1663 attr
->value_tag
== IPP_TAG_KEYWORD
)
1665 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1666 attr
->value_tag
== IPP_TAG_NAME
)
1668 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1669 attr
->value_tag
== IPP_TAG_NAME
)
1676 * See if we have everything needed...
1679 if (printer
== NULL
)
1688 * Display the printer entry if needed...
1691 if (match_list(printers
, printer
))
1694 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1695 * current job for the printer.
1698 if (pstate
== IPP_PRINTER_PROCESSING
)
1701 * Build an IPP_GET_JOBS request, which requires the following
1704 * attributes-charset
1705 * attributes-natural-language
1708 * requested-attributes
1711 request
= ippNewRequest(IPP_GET_JOBS
);
1713 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1714 request
->request
.op
.request_id
= 1;
1716 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1717 "requested-attributes",
1718 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1720 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1721 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1722 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1723 "printer-uri", NULL
, printer_uri
);
1725 if ((jobs
= cupsDoRequest(CUPS_HTTP_DEFAULT
, request
, "/")) != NULL
)
1728 * Get the current active job on this queue...
1731 ipp_jstate_t jobstate
= IPP_JOB_PENDING
;
1734 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1738 if (jobstate
== IPP_JOB_PROCESSING
)
1744 if (!strcmp(jobattr
->name
, "job-id") &&
1745 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1746 jobid
= jobattr
->values
[0].integer
;
1747 else if (!strcmp(jobattr
->name
, "job-state") &&
1748 jobattr
->value_tag
== IPP_TAG_ENUM
)
1749 jobstate
= jobattr
->values
[0].integer
;
1752 if (jobstate
!= IPP_JOB_PROCESSING
)
1763 pdate
= localtime(&ptime
);
1764 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
1768 case IPP_PRINTER_IDLE
:
1769 _cupsLangPrintf(stdout
,
1770 _("printer %s is idle. enabled since %s"),
1771 printer
, printer_state_time
);
1773 case IPP_PRINTER_PROCESSING
:
1774 _cupsLangPrintf(stdout
,
1775 _("printer %s now printing %s-%d. "
1776 "enabled since %s"),
1777 printer
, printer
, jobid
, printer_state_time
);
1779 case IPP_PRINTER_STOPPED
:
1780 _cupsLangPrintf(stdout
,
1781 _("printer %s disabled since %s -"),
1782 printer
, printer_state_time
);
1786 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1788 if (!message
|| !*message
)
1789 _cupsLangPuts(stdout
, _("\treason unknown"));
1791 _cupsLangPrintf(stdout
, "\t%s", message
);
1794 if (long_status
> 1)
1796 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1797 _cupsLangPuts(stdout
, _("\tContent types: any"));
1798 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1803 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1804 description
? description
: "");
1808 char alerts
[1024], /* Alerts string */
1809 *aptr
; /* Pointer into alerts string */
1811 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1814 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1815 reasons
->values
[i
].string
.text
);
1817 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1820 aptr
+= strlen(aptr
);
1823 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1826 if (long_status
> 1)
1828 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1829 location
? location
: "");
1831 if (ptype
& CUPS_PRINTER_REMOTE
)
1833 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1835 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1836 !strstr(make_model
, "Raw Printer") && uri
)
1837 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"),
1842 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1844 if (make_model
&& strstr(make_model
, "System V Printer"))
1845 _cupsLangPrintf(stdout
,
1846 _("\tInterface: %s/interfaces/%s"),
1847 cg
->cups_serverroot
, printer
);
1848 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
1849 _cupsLangPrintf(stdout
,
1850 _("\tInterface: %s/ppd/%s.ppd"),
1851 cg
->cups_serverroot
, printer
);
1853 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1854 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1855 /* TODO update to use printer-error-policy */
1858 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1859 for (j
= 0; j
< allowed
->num_values
; j
++)
1860 _cupsLangPrintf(stdout
, "\t\t%s",
1861 allowed
->values
[j
].string
.text
);
1865 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1866 for (j
= 0; j
< denied
->num_values
; j
++)
1867 _cupsLangPrintf(stdout
, "\t\t%s",
1868 denied
->values
[j
].string
.text
);
1872 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1873 _cupsLangPuts(stdout
, _("\t\t(all)"));
1875 _cupsLangPuts(stdout
, _("\tForms allowed:"));
1876 _cupsLangPuts(stdout
, _("\t\t(none)"));
1877 _cupsLangPuts(stdout
, _("\tBanner required"));
1878 _cupsLangPuts(stdout
, _("\tCharset sets:"));
1879 _cupsLangPuts(stdout
, _("\t\t(none)"));
1880 _cupsLangPuts(stdout
, _("\tDefault pitch:"));
1881 _cupsLangPuts(stdout
, _("\tDefault page size:"));
1882 _cupsLangPuts(stdout
, _("\tDefault port settings:"));
1885 for (i
= 0; i
< num_dests
; i
++)
1886 if (!_cups_strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1890 case IPP_PRINTER_IDLE
:
1891 _cupsLangPrintf(stdout
,
1892 _("printer %s/%s is idle. "
1893 "enabled since %s"),
1894 printer
, dests
[i
].instance
,
1895 printer_state_time
);
1897 case IPP_PRINTER_PROCESSING
:
1898 _cupsLangPrintf(stdout
,
1899 _("printer %s/%s now printing %s-%d. "
1900 "enabled since %s"),
1901 printer
, dests
[i
].instance
, printer
, jobid
,
1902 printer_state_time
);
1904 case IPP_PRINTER_STOPPED
:
1905 _cupsLangPrintf(stdout
,
1906 _("printer %s/%s disabled since %s -"),
1907 printer
, dests
[i
].instance
,
1908 printer_state_time
);
1912 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
1914 if (!message
|| !*message
)
1915 _cupsLangPuts(stdout
, _("\treason unknown"));
1917 _cupsLangPrintf(stdout
, "\t%s", message
);
1920 if (long_status
> 1)
1922 _cupsLangPuts(stdout
, _("\tForm mounted:"));
1923 _cupsLangPuts(stdout
, _("\tContent types: any"));
1924 _cupsLangPuts(stdout
, _("\tPrinter types: unknown"));
1929 _cupsLangPrintf(stdout
, _("\tDescription: %s"),
1930 description
? description
: "");
1934 char alerts
[1024], /* Alerts string */
1935 *aptr
; /* Pointer into alerts string */
1937 for (i
= 0, aptr
= alerts
; i
< reasons
->num_values
; i
++)
1940 snprintf(aptr
, sizeof(alerts
) - (aptr
- alerts
), " %s",
1941 reasons
->values
[i
].string
.text
);
1943 strlcpy(alerts
, reasons
->values
[i
].string
.text
,
1946 aptr
+= strlen(aptr
);
1949 _cupsLangPrintf(stdout
, _("\tAlerts: %s"), alerts
);
1952 if (long_status
> 1)
1954 _cupsLangPrintf(stdout
, _("\tLocation: %s"),
1955 location
? location
: "");
1957 if (ptype
& CUPS_PRINTER_REMOTE
)
1959 _cupsLangPuts(stdout
, _("\tConnection: remote"));
1961 if (make_model
&& !strstr(make_model
, "System V Printer") &&
1962 !strstr(make_model
, "Raw Printer") && uri
)
1963 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd"), uri
);
1967 _cupsLangPuts(stdout
, _("\tConnection: direct"));
1969 if (make_model
&& strstr(make_model
, "System V Printer"))
1970 _cupsLangPrintf(stdout
,
1971 _("\tInterface: %s/interfaces/%s"),
1972 cg
->cups_serverroot
, printer
);
1973 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
1974 _cupsLangPrintf(stdout
,
1975 _("\tInterface: %s/ppd/%s.ppd"),
1976 cg
->cups_serverroot
, printer
);
1978 _cupsLangPuts(stdout
, _("\tOn fault: no alert"));
1979 _cupsLangPuts(stdout
, _("\tAfter fault: continue"));
1980 /* TODO update to use printer-error-policy */
1983 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1984 for (j
= 0; j
< allowed
->num_values
; j
++)
1985 _cupsLangPrintf(stdout
, "\t\t%s",
1986 allowed
->values
[j
].string
.text
);
1990 _cupsLangPuts(stdout
, _("\tUsers denied:"));
1991 for (j
= 0; j
< denied
->num_values
; j
++)
1992 _cupsLangPrintf(stdout
, "\t\t%s",
1993 denied
->values
[j
].string
.text
);
1997 _cupsLangPuts(stdout
, _("\tUsers allowed:"));
1998 _cupsLangPuts(stdout
, _("\t\t(all)"));
2000 _cupsLangPuts(stdout
, _("\tForms allowed:"));
2001 _cupsLangPuts(stdout
, _("\t\t(none)"));
2002 _cupsLangPuts(stdout
, _("\tBanner required"));
2003 _cupsLangPuts(stdout
, _("\tCharset sets:"));
2004 _cupsLangPuts(stdout
, _("\t\t(none)"));
2005 _cupsLangPuts(stdout
, _("\tDefault pitch:"));
2006 _cupsLangPuts(stdout
, _("\tDefault page size:"));
2007 _cupsLangPuts(stdout
, _("\tDefault port settings:"));
2016 ippDelete(response
);
2020 _cupsLangPrintf(stderr
, "lpstat: %s", cupsLastErrorString());
2029 * 'show_scheduler()' - Show scheduler status.
2033 show_scheduler(void)
2035 http_t
*http
; /* Connection to server */
2038 if ((http
= httpConnectEncrypt(cupsServer(), ippPort(),
2039 cupsEncryption())) != NULL
)
2041 _cupsLangPuts(stdout
, _("scheduler is running"));
2045 _cupsLangPuts(stdout
, _("scheduler is not running"));
2050 * End of "$Id: lpstat.c 7921 2008-09-10 15:42:24Z mike $".