2 * "$Id: lpstat.c 6649 2007-07-11 21:46:42Z mike $"
4 * "lpstat" command for the Common UNIX Printing System (CUPS).
6 * Copyright 2007 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 'P' : /* Show paper types */
119 case 'R' : /* Show ranking */
123 case 'S' : /* Show charsets */
129 case 'U' : /* Username */
130 if (argv
[i
][2] != '\0')
131 cupsSetUser(argv
[i
] + 2);
137 _cupsLangPrintf(stderr
,
138 _("%s: Error - expected username after "
144 cupsSetUser(argv
[i
]);
148 case 'W' : /* Show which jobs? */
157 _cupsLangPrintf(stderr
,
158 _("%s: Error - need \"completed\", "
159 "\"not-completed\", or \"all\" after "
168 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
169 strcmp(which
, "all"))
171 _cupsLangPrintf(stderr
,
172 _("%s: Error - need \"completed\", "
173 "\"not-completed\", or \"all\" after "
180 case 'a' : /* Show acceptance status */
182 http
= connect_server(argv
[0], http
);
184 if (argv
[i
][2] != '\0')
186 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
188 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
190 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
194 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
196 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
201 num_dests
= cupsGetDests2(http
, &dests
);
203 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
208 case 'b' : /* Show both the local and remote status */
210 http
= connect_server(argv
[0], http
);
212 if (argv
[i
][2] != '\0')
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], http
, argv
[i
] + 2, &num_dests
, &dests
);
226 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
230 _cupsLangPrintf(stderr
,
231 _("%s: Error - expected destination after "
240 case 'c' : /* Show classes and members */
242 http
= connect_server(argv
[0], http
);
244 if (argv
[i
][2] != '\0')
246 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
248 status
|= show_classes(http
, argv
[i
] + 2);
250 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
254 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
256 status
|= show_classes(http
, argv
[i
]);
259 status
|= show_classes(http
, NULL
);
262 case 'd' : /* Show default destination */
264 http
= connect_server(argv
[0], http
);
267 num_dests
= cupsGetDests2(http
, &dests
);
269 show_default(num_dests
, dests
);
272 case 'f' : /* Show forms */
278 case 'h' : /* Connect to host */
285 if (argv
[i
][2] != '\0')
286 cupsSetServer(argv
[i
] + 2);
293 _cupsLangPrintf(stderr
,
294 _("%s: Error - expected hostname after "
300 cupsSetServer(argv
[i
]);
304 case 'l' : /* Long status or long job status */
307 http
= connect_server(argv
[0], http
);
309 if (argv
[i
][2] != '\0')
311 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
313 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
320 case 'o' : /* Show jobs by destination */
322 http
= connect_server(argv
[0], http
);
324 if (argv
[i
][2] != '\0')
326 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
328 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
331 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
335 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
337 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
341 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
345 case 'p' : /* Show printers */
347 http
= connect_server(argv
[0], http
);
349 if (argv
[i
][2] != '\0')
351 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
353 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
355 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
359 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
361 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
366 num_dests
= cupsGetDests2(http
, &dests
);
368 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
372 case 'r' : /* Show scheduler status */
374 http
= connect_server(argv
[0], http
);
376 show_scheduler(http
);
379 case 's' : /* Show summary */
381 http
= connect_server(argv
[0], http
);
384 num_dests
= cupsGetDests2(http
, &dests
);
386 show_default(num_dests
, dests
);
387 status
|= show_classes(http
, NULL
);
388 status
|= show_devices(http
, NULL
, num_dests
, dests
);
391 case 't' : /* Show all info */
393 http
= connect_server(argv
[0], http
);
396 num_dests
= cupsGetDests2(http
, &dests
);
398 show_scheduler(http
);
399 show_default(num_dests
, dests
);
400 status
|= show_classes(http
, NULL
);
401 status
|= show_devices(http
, NULL
, num_dests
, dests
);
402 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
403 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
404 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
407 case 'u' : /* Show jobs by user */
409 http
= connect_server(argv
[0], http
);
411 if (argv
[i
][2] != '\0')
412 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
414 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
417 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
421 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
425 case 'v' : /* Show printer devices */
427 http
= connect_server(argv
[0], http
);
429 if (argv
[i
][2] != '\0')
431 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
433 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
435 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
439 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
441 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
446 num_dests
= cupsGetDests2(http
, &dests
);
448 status
|= show_devices(http
, NULL
, num_dests
, dests
);
454 _cupsLangPrintf(stderr
,
455 _("%s: Error - unknown option \'%c\'!\n"),
456 argv
[0], argv
[i
][1]);
461 http
= connect_server(argv
[0], http
);
463 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
469 http
= connect_server(argv
[0], http
);
471 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
479 * 'check_dest()' - Verify that the named destination(s) exists.
483 check_dest(const char *command
, /* I - Command name */
484 http_t
*http
, /* I - HTTP connection */
485 const char *name
, /* I - Name of printer/class(es) */
486 int *num_dests
, /* IO - Number of destinations */
487 cups_dest_t
**dests
) /* IO - Destinations */
495 * Load the destination list as necessary...
499 *num_dests
= cupsGetDests2(http
, dests
);
502 * Scan the name string for printer/class name(s)...
505 for (dptr
= name
; *dptr
!= '\0';)
508 * Skip leading whitespace and commas...
511 while (isspace(*dptr
& 255) || *dptr
== ',')
518 * Extract a single destination name from the name string...
521 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
523 if ((pptr
- printer
) < (sizeof(printer
) - 1))
527 _cupsLangPrintf(stderr
,
528 _("%s: Invalid destination name in list \"%s\"!\n"),
537 * Check the destination...
540 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
542 _cupsLangPrintf(stderr
,
543 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
551 * 'connect_server()' - Connect to the server as necessary...
554 static http_t
* /* O - New HTTP connection */
555 connect_server(const char *command
, /* I - Command name */
556 http_t
*http
) /* I - Current HTTP connection */
560 http
= httpConnectEncrypt(cupsServer(), ippPort(),
565 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
575 * 'show_accepting()' - Show acceptance status.
578 static int /* O - 0 on success, 1 on fail */
579 show_accepting(http_t
*http
, /* I - HTTP connection to server */
580 const char *printers
, /* I - Destinations */
581 int num_dests
, /* I - Number of user-defined dests */
582 cups_dest_t
*dests
) /* I - User-defined destinations */
584 int i
; /* Looping var */
585 ipp_t
*request
, /* IPP Request */
586 *response
; /* IPP Response */
587 ipp_attribute_t
*attr
; /* Current attribute */
588 const char *printer
, /* Printer name */
589 *message
; /* Printer device URI */
590 int accepting
; /* Accepting requests? */
591 time_t ptime
; /* Printer state time */
592 struct tm
*pdate
; /* Printer state date & time */
593 char printer_state_time
[255];/* Printer state time */
594 const char *dptr
, /* Pointer into destination list */
595 *ptr
; /* Pointer into printer name */
596 int match
; /* Non-zero if this job matches */
597 static const char *pattrs
[] = /* Attributes we need for printers... */
600 "printer-state-change-time",
601 "printer-state-message",
602 "printer-is-accepting-jobs"
606 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
611 if (printers
!= NULL
&& !strcmp(printers
, "all"))
615 * Build a CUPS_GET_PRINTERS request, which requires the following
619 * attributes-natural-language
620 * requested-attributes
621 * requesting-user-name
624 request
= ippNewRequest(CUPS_GET_PRINTERS
);
626 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
627 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
630 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
634 * Do the request and get back a response...
637 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
639 DEBUG_puts("show_accepting: request succeeded...");
641 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
643 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
649 * Loop through the printers returned in the list and display
653 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
656 * Skip leading attributes until we hit a printer...
659 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
666 * Pull the needed attributes from this printer...
674 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
676 if (!strcmp(attr
->name
, "printer-name") &&
677 attr
->value_tag
== IPP_TAG_NAME
)
678 printer
= attr
->values
[0].string
.text
;
679 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
680 attr
->value_tag
== IPP_TAG_INTEGER
)
681 ptime
= (time_t)attr
->values
[0].integer
;
682 else if (!strcmp(attr
->name
, "printer-state-message") &&
683 attr
->value_tag
== IPP_TAG_TEXT
)
684 message
= attr
->values
[0].string
.text
;
685 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
686 attr
->value_tag
== IPP_TAG_BOOLEAN
)
687 accepting
= attr
->values
[0].boolean
;
693 * See if we have everything needed...
705 * See if this is a printer we're interested in...
708 match
= printers
== NULL
;
710 if (printers
!= NULL
)
712 for (dptr
= printers
; *dptr
!= '\0';)
715 * Skip leading whitespace and commas...
718 while (isspace(*dptr
& 255) || *dptr
== ',')
729 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
732 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
739 * Skip trailing junk...
742 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
744 while (isspace(*dptr
& 255) || *dptr
== ',')
753 * Display the printer entry if needed...
758 pdate
= localtime(&ptime
);
759 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
762 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
763 printer
, printer_state_time
);
765 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
767 printer
, printer_state_time
,
768 message
== NULL
? "reason unknown" : message
);
770 for (i
= 0; i
< num_dests
; i
++)
771 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
774 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
775 printer
, dests
[i
].instance
, printer_state_time
);
777 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
779 printer
, dests
[i
].instance
, printer_state_time
,
780 message
== NULL
? "reason unknown" : message
);
792 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
801 * 'show_classes()' - Show printer classes.
804 static int /* O - 0 on success, 1 on fail */
805 show_classes(http_t
*http
, /* I - HTTP connection to server */
806 const char *dests
) /* I - Destinations */
808 int i
; /* Looping var */
809 ipp_t
*request
, /* IPP Request */
810 *response
, /* IPP Response */
811 *response2
; /* IPP response from remote server */
812 http_t
*http2
; /* Remote server */
813 ipp_attribute_t
*attr
; /* Current attribute */
814 const char *printer
, /* Printer class name */
815 *printer_uri
; /* Printer class URI */
816 ipp_attribute_t
*members
; /* Printer members */
817 char method
[HTTP_MAX_URI
], /* Request method */
818 username
[HTTP_MAX_URI
], /* Username:password */
819 server
[HTTP_MAX_URI
], /* Server name */
820 resource
[HTTP_MAX_URI
]; /* Resource name */
821 int port
; /* Port number */
822 const char *dptr
, /* Pointer into destination list */
823 *ptr
; /* Pointer into printer name */
824 int match
; /* Non-zero if this job matches */
825 static const char *cattrs
[] = /* Attributes we need for classes... */
828 "printer-uri-supported",
833 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
838 if (dests
!= NULL
&& !strcmp(dests
, "all"))
842 * Build a CUPS_GET_CLASSES request, which requires the following
846 * attributes-natural-language
847 * requested-attributes
848 * requesting-user-name
851 request
= ippNewRequest(CUPS_GET_CLASSES
);
853 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
854 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
857 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
861 * Do the request and get back a response...
864 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
866 DEBUG_puts("show_classes: request succeeded...");
868 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
870 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
876 * Loop through the printers returned in the list and display
880 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
883 * Skip leading attributes until we hit a job...
886 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
893 * Pull the needed attributes from this job...
900 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
902 if (!strcmp(attr
->name
, "printer-name") &&
903 attr
->value_tag
== IPP_TAG_NAME
)
904 printer
= attr
->values
[0].string
.text
;
906 if (!strcmp(attr
->name
, "printer-uri-supported") &&
907 attr
->value_tag
== IPP_TAG_URI
)
908 printer_uri
= attr
->values
[0].string
.text
;
910 if (!strcmp(attr
->name
, "member-names") &&
911 attr
->value_tag
== IPP_TAG_NAME
)
918 * If this is a remote class, grab the class info from the
923 if (members
== NULL
&& printer_uri
!= NULL
)
925 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
926 username
, sizeof(username
), server
, sizeof(server
),
927 &port
, resource
, sizeof(resource
));
929 if (!strcasecmp(server
, http
->hostname
))
932 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
937 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
938 * following attributes:
941 * attributes-natural-language
943 * requested-attributes
946 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
948 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
949 "printer-uri", NULL
, printer_uri
);
951 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
952 "requested-attributes",
953 sizeof(cattrs
) / sizeof(cattrs
[0]),
956 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
957 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
965 * See if we have everything needed...
971 ippDelete(response2
);
980 * See if this is a printer we're interested in...
983 match
= dests
== NULL
;
987 for (dptr
= dests
; *dptr
!= '\0';)
990 * Skip leading whitespace and commas...
993 while (isspace(*dptr
& 255) || *dptr
== ',')
1004 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1007 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1014 * Skip trailing junk...
1017 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1019 while (isspace(*dptr
& 255) || *dptr
== ',')
1028 * Display the printer entry if needed...
1033 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1037 for (i
= 0; i
< members
->num_values
; i
++)
1038 _cupsLangPrintf(stdout
, "\t%s\n",
1039 members
->values
[i
].string
.text
);
1042 _cupsLangPuts(stdout
, "\tunknown\n");
1046 ippDelete(response2
);
1052 ippDelete(response
);
1056 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1065 * 'show_default()' - Show default destination.
1069 show_default(int num_dests
, /* I - Number of user-defined dests */
1070 cups_dest_t
*dests
) /* I - User-defined destinations */
1072 cups_dest_t
*dest
; /* Destination */
1073 const char *printer
, /* Printer name */
1074 *val
; /* Environment variable name */
1076 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1079 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1080 dest
->name
, dest
->instance
);
1082 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1089 if ((printer
= getenv("LPDEST")) == NULL
)
1091 if ((printer
= getenv("PRINTER")) != NULL
)
1093 if (!strcmp(printer
, "lp"))
1102 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1103 _cupsLangPrintf(stdout
,
1104 _("lpstat: error - %s environment variable names "
1105 "non-existent destination \"%s\"!\n"),
1108 _cupsLangPuts(stdout
, _("no system default destination\n"));
1114 * 'show_devices()' - Show printer devices.
1117 static int /* O - 0 on success, 1 on fail */
1118 show_devices(http_t
*http
, /* I - HTTP connection to server */
1119 const char *printers
, /* I - Destinations */
1120 int num_dests
, /* I - Number of user-defined dests */
1121 cups_dest_t
*dests
) /* I - User-defined destinations */
1123 int i
; /* Looping var */
1124 ipp_t
*request
, /* IPP Request */
1125 *response
; /* IPP Response */
1126 ipp_attribute_t
*attr
; /* Current attribute */
1127 const char *printer
, /* Printer name */
1128 *uri
, /* Printer URI */
1129 *device
, /* Printer device URI */
1130 *dptr
, /* Pointer into destination list */
1131 *ptr
; /* Pointer into printer name */
1132 int match
; /* Non-zero if this job matches */
1133 static const char *pattrs
[] = /* Attributes we need for printers... */
1136 "printer-uri-supported",
1141 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1146 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1150 * Build a CUPS_GET_PRINTERS request, which requires the following
1153 * attributes-charset
1154 * attributes-natural-language
1155 * requested-attributes
1156 * requesting-user-name
1159 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1161 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1162 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1165 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1169 * Do the request and get back a response...
1172 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1174 DEBUG_puts("show_devices: request succeeded...");
1176 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1178 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1179 ippDelete(response
);
1184 * Loop through the printers returned in the list and display
1188 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1191 * Skip leading attributes until we hit a job...
1194 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1201 * Pull the needed attributes from this job...
1208 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1210 if (!strcmp(attr
->name
, "printer-name") &&
1211 attr
->value_tag
== IPP_TAG_NAME
)
1212 printer
= attr
->values
[0].string
.text
;
1214 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1215 attr
->value_tag
== IPP_TAG_URI
)
1216 uri
= attr
->values
[0].string
.text
;
1218 if (!strcmp(attr
->name
, "device-uri") &&
1219 attr
->value_tag
== IPP_TAG_URI
)
1220 device
= attr
->values
[0].string
.text
;
1226 * See if we have everything needed...
1229 if (printer
== NULL
)
1238 * See if this is a printer we're interested in...
1241 match
= printers
== NULL
;
1243 if (printers
!= NULL
)
1245 for (dptr
= printers
; *dptr
!= '\0';)
1248 * Skip leading whitespace and commas...
1251 while (isspace(*dptr
& 255) || *dptr
== ',')
1262 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1265 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1272 * Skip trailing junk...
1275 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1277 while (isspace(*dptr
& 255) || *dptr
== ',')
1286 * Display the printer entry if needed...
1291 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1292 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1293 username
[HTTP_MAX_URI
],
1294 hostname
[HTTP_MAX_URI
],
1295 resource
[HTTP_MAX_URI
];
1301 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1302 username
, sizeof(username
), hostname
,
1303 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1304 _cupsLangPrintf(stdout
,
1305 _("Output for printer %s is sent to remote "
1306 "printer %s on %s\n"),
1307 printer
, strrchr(resource
, '/') + 1, hostname
);
1309 else if (!strncmp(device
, "file:", 5))
1310 _cupsLangPrintf(stdout
,
1311 _("Output for printer %s is sent to %s\n"),
1312 printer
, device
+ 5);
1314 _cupsLangPrintf(stdout
,
1315 _("Output for printer %s is sent to %s\n"),
1318 for (i
= 0; i
< num_dests
; i
++)
1319 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1322 _cupsLangPrintf(stdout
,
1323 _("Output for printer %s/%s is sent to "
1324 "remote printer %s on %s\n"),
1325 printer
, dests
[i
].instance
,
1326 strrchr(resource
, '/') + 1, hostname
);
1327 else if (!strncmp(device
, "file:", 5))
1328 _cupsLangPrintf(stdout
,
1329 _("Output for printer %s/%s is sent to %s\n"),
1330 printer
, dests
[i
].instance
, device
+ 5);
1332 _cupsLangPrintf(stdout
,
1333 _("Output for printer %s/%s is sent to %s\n"),
1334 printer
, dests
[i
].instance
, device
);
1338 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1340 else if (!strncmp(device
, "file:", 5))
1341 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1342 printer
, device
+ 5);
1344 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1347 for (i
= 0; i
< num_dests
; i
++)
1348 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1351 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1352 printer
, dests
[i
].instance
, uri
);
1353 else if (!strncmp(device
, "file:", 5))
1354 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1355 printer
, dests
[i
].instance
, device
+ 5);
1357 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1358 printer
, dests
[i
].instance
, device
);
1360 #endif /* __osf__ */
1367 ippDelete(response
);
1371 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1380 * 'show_jobs()' - Show active print jobs.
1383 static int /* O - 0 on success, 1 on fail */
1384 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1385 const char *dests
, /* I - Destinations */
1386 const char *users
, /* I - Users */
1387 int long_status
, /* I - Show long status? */
1388 int ranking
, /* I - Show job ranking? */
1389 const char *which
) /* I - Show which jobs? */
1391 int i
; /* Looping var */
1392 ipp_t
*request
, /* IPP Request */
1393 *response
; /* IPP Response */
1394 ipp_attribute_t
*attr
, /* Current attribute */
1395 *reasons
; /* Job state reasons attribute */
1396 const char *dest
, /* Pointer into job-printer-uri */
1397 *username
, /* Pointer to job-originating-user-name */
1398 *title
; /* Pointer to job-name */
1399 int rank
, /* Rank in queue */
1401 size
; /* job-k-octets */
1402 time_t jobtime
; /* time-at-creation */
1403 struct tm
*jobdate
; /* Date & time */
1404 const char *dptr
, /* Pointer into destination list */
1405 *ptr
; /* Pointer into printer name */
1406 int match
; /* Non-zero if this job matches */
1407 char temp
[255], /* Temporary buffer */
1408 date
[255]; /* Date buffer */
1409 static const char *jattrs
[] = /* Attributes we need for jobs... */
1416 "job-originating-user-name",
1421 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1426 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1430 * Build a IPP_GET_JOBS request, which requires the following
1433 * attributes-charset
1434 * attributes-natural-language
1436 * requested-attributes
1439 request
= ippNewRequest(IPP_GET_JOBS
);
1441 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1442 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1445 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1446 NULL
, "ipp://localhost/jobs/");
1448 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1452 * Do the request and get back a response...
1455 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1458 * Loop through the job list and display them...
1461 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1463 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1464 ippDelete(response
);
1470 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1473 * Skip leading attributes until we hit a job...
1476 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1483 * Pull the needed attributes from this job...
1494 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1496 if (!strcmp(attr
->name
, "job-id") &&
1497 attr
->value_tag
== IPP_TAG_INTEGER
)
1498 jobid
= attr
->values
[0].integer
;
1500 if (!strcmp(attr
->name
, "job-k-octets") &&
1501 attr
->value_tag
== IPP_TAG_INTEGER
)
1502 size
= attr
->values
[0].integer
;
1504 if (!strcmp(attr
->name
, "time-at-creation") &&
1505 attr
->value_tag
== IPP_TAG_INTEGER
)
1506 jobtime
= attr
->values
[0].integer
;
1508 if (!strcmp(attr
->name
, "job-printer-uri") &&
1509 attr
->value_tag
== IPP_TAG_URI
)
1510 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1513 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1514 attr
->value_tag
== IPP_TAG_NAME
)
1515 username
= attr
->values
[0].string
.text
;
1517 if (!strcmp(attr
->name
, "job-name") &&
1518 attr
->value_tag
== IPP_TAG_NAME
)
1519 title
= attr
->values
[0].string
.text
;
1521 if (!strcmp(attr
->name
, "job-state-reasons") &&
1522 attr
->value_tag
== IPP_TAG_KEYWORD
)
1529 * See if we have everything needed...
1532 if (dest
== NULL
|| jobid
== 0)
1541 * See if this is a job we're interested in...
1544 match
= (dests
== NULL
&& users
== NULL
);
1549 for (dptr
= dests
; *dptr
!= '\0';)
1552 * Skip leading whitespace and commas...
1555 while (isspace(*dptr
& 255) || *dptr
== ',')
1566 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1569 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1576 * Skip trailing junk...
1579 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1581 while (isspace(*dptr
& 255) || *dptr
== ',')
1589 if (users
!= NULL
&& username
!= NULL
)
1591 for (dptr
= users
; *dptr
!= '\0';)
1594 * Skip leading whitespace and commas...
1597 while (isspace(*dptr
& 255) || *dptr
== ',')
1607 for (ptr
= username
;
1608 *ptr
!= '\0' && *dptr
!= '\0' && *ptr
== *dptr
;
1611 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1618 * Skip trailing junk...
1621 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1623 while (isspace(*dptr
& 255) || *dptr
== ',')
1632 * Display the job...
1637 jobdate
= localtime(&jobtime
);
1638 snprintf(temp
, sizeof(temp
), "%s-%d", dest
, jobid
);
1640 if (long_status
== 3)
1643 * Show the consolidated output format for the SGI tools...
1646 if (!strftime(date
, sizeof(date
), "%b %d %H:%M", jobdate
))
1647 strcpy(date
, "Unknown");
1649 _cupsLangPrintf(stdout
, "%s;%s;%d;%s;%s\n",
1650 temp
, username
? username
: "unknown",
1651 size
, title
? title
: "unknown", date
);
1655 if (!strftime(date
, sizeof(date
), "%c", jobdate
))
1656 strcpy(date
, "Unknown");
1659 _cupsLangPrintf(stdout
, "%3d %-21s %-13s %8.0f %s\n",
1660 rank
, temp
, username
? username
: "unknown",
1661 1024.0 * size
, date
);
1663 _cupsLangPrintf(stdout
, "%-23s %-13s %8.0f %s\n",
1664 temp
, username
? username
: "unknown",
1665 1024.0 * size
, date
);
1670 _cupsLangPuts(stdout
, _("\tAlerts:"));
1671 for (i
= 0; i
< reasons
->num_values
; i
++)
1672 _cupsLangPrintf(stdout
, " %s",
1673 reasons
->values
[i
].string
.text
);
1674 _cupsLangPuts(stdout
, "\n");
1676 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1685 ippDelete(response
);
1689 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1698 * 'show_printers()' - Show printers.
1701 static int /* O - 0 on success, 1 on fail */
1702 show_printers(http_t
*http
, /* I - HTTP connection to server */
1703 const char *printers
, /* I - Destinations */
1704 int num_dests
, /* I - Number of user-defined dests */
1705 cups_dest_t
*dests
, /* I - User-defined destinations */
1706 int long_status
) /* I - Show long status? */
1708 int i
, j
; /* Looping vars */
1709 ipp_t
*request
, /* IPP Request */
1710 *response
, /* IPP Response */
1711 *jobs
; /* IPP Get Jobs response */
1712 ipp_attribute_t
*attr
, /* Current attribute */
1713 *jobattr
, /* Job ID attribute */
1714 *reasons
; /* Job state reasons attribute */
1715 const char *printer
, /* Printer name */
1716 *message
, /* Printer state message */
1717 *description
, /* Description of printer */
1718 *location
, /* Location of printer */
1719 *make_model
, /* Make and model of printer */
1720 *uri
; /* URI of printer */
1721 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1722 *denied
; /* requestint-user-name-denied */
1723 ipp_pstate_t pstate
; /* Printer state */
1724 cups_ptype_t ptype
; /* Printer type */
1725 time_t ptime
; /* Printer state time */
1726 struct tm
*pdate
; /* Printer state date & time */
1727 int jobid
; /* Job ID of current job */
1728 const char *dptr
, /* Pointer into destination list */
1729 *ptr
; /* Pointer into printer name */
1730 int match
; /* Non-zero if this job matches */
1731 char printer_uri
[HTTP_MAX_URI
],
1733 printer_state_time
[255];/* Printer state time */
1734 const char *root
; /* Server root directory... */
1735 static const char *pattrs
[] = /* Attributes we need for printers... */
1739 "printer-state-message",
1740 "printer-state-reasons",
1741 "printer-state-change-time",
1745 "printer-make-and-model",
1746 "printer-uri-supported",
1747 "requesting-user-name-allowed",
1748 "requesting-user-name-denied"
1750 static const char *jattrs
[] = /* Attributes we need for jobs... */
1756 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1761 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1762 root
= CUPS_SERVERROOT
;
1764 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1768 * Build a CUPS_GET_PRINTERS request, which requires the following
1771 * attributes-charset
1772 * attributes-natural-language
1773 * requested-attributes
1774 * requesting-user-name
1777 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1779 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1780 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1783 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1787 * Do the request and get back a response...
1790 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1792 DEBUG_puts("show_printers: request succeeded...");
1794 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1796 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1797 ippDelete(response
);
1802 * Loop through the printers returned in the list and display
1806 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1809 * Skip leading attributes until we hit a job...
1812 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1819 * Pull the needed attributes from this job...
1824 ptype
= CUPS_PRINTER_LOCAL
;
1825 pstate
= IPP_PRINTER_IDLE
;
1836 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1838 if (!strcmp(attr
->name
, "printer-name") &&
1839 attr
->value_tag
== IPP_TAG_NAME
)
1840 printer
= attr
->values
[0].string
.text
;
1841 else if (!strcmp(attr
->name
, "printer-state") &&
1842 attr
->value_tag
== IPP_TAG_ENUM
)
1843 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1844 else if (!strcmp(attr
->name
, "printer-type") &&
1845 attr
->value_tag
== IPP_TAG_ENUM
)
1846 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1847 else if (!strcmp(attr
->name
, "printer-state-message") &&
1848 attr
->value_tag
== IPP_TAG_TEXT
)
1849 message
= attr
->values
[0].string
.text
;
1850 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1851 attr
->value_tag
== IPP_TAG_INTEGER
)
1852 ptime
= (time_t)attr
->values
[0].integer
;
1853 else if (!strcmp(attr
->name
, "printer-info") &&
1854 attr
->value_tag
== IPP_TAG_TEXT
)
1855 description
= attr
->values
[0].string
.text
;
1856 else if (!strcmp(attr
->name
, "printer-location") &&
1857 attr
->value_tag
== IPP_TAG_TEXT
)
1858 location
= attr
->values
[0].string
.text
;
1859 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1860 attr
->value_tag
== IPP_TAG_TEXT
)
1861 make_model
= attr
->values
[0].string
.text
;
1862 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1863 attr
->value_tag
== IPP_TAG_URI
)
1864 uri
= attr
->values
[0].string
.text
;
1865 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1866 attr
->value_tag
== IPP_TAG_KEYWORD
)
1868 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1869 attr
->value_tag
== IPP_TAG_NAME
)
1871 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1872 attr
->value_tag
== IPP_TAG_NAME
)
1879 * See if we have everything needed...
1882 if (printer
== NULL
)
1891 * See if this is a printer we're interested in...
1894 match
= printers
== NULL
;
1896 if (printers
!= NULL
)
1898 for (dptr
= printers
; *dptr
!= '\0';)
1901 * Skip leading whitespace and commas...
1904 while (isspace(*dptr
& 255) || *dptr
== ',')
1915 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1918 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1925 * Skip trailing junk...
1928 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1930 while (isspace(*dptr
& 255) || *dptr
== ',')
1939 * Display the printer entry if needed...
1945 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1946 * current job for the printer.
1949 if (pstate
== IPP_PRINTER_PROCESSING
)
1952 * Build an IPP_GET_JOBS request, which requires the following
1955 * attributes-charset
1956 * attributes-natural-language
1959 * requested-attributes
1962 request
= ippNewRequest(IPP_GET_JOBS
);
1964 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1965 request
->request
.op
.request_id
= 1;
1967 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1968 "requested-attributes",
1969 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1971 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1972 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1973 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1974 "printer-uri", NULL
, printer_uri
);
1976 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
1979 * Get the current active job on this queue...
1984 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1989 if (!strcmp(jobattr
->name
, "job-id") &&
1990 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1991 jobid
= jobattr
->values
[0].integer
;
1992 else if (!strcmp(jobattr
->name
, "job-state") &&
1993 jobattr
->value_tag
== IPP_TAG_ENUM
&&
1994 jobattr
->values
[0].integer
== IPP_JOB_PROCESSING
)
2006 pdate
= localtime(&ptime
);
2007 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
2011 case IPP_PRINTER_IDLE
:
2012 _cupsLangPrintf(stdout
,
2013 _("printer %s is idle. enabled since %s\n"),
2014 printer
, printer_state_time
);
2016 case IPP_PRINTER_PROCESSING
:
2017 _cupsLangPrintf(stdout
,
2018 _("printer %s now printing %s-%d. "
2019 "enabled since %s\n"),
2020 printer
, printer
, jobid
, printer_state_time
);
2022 case IPP_PRINTER_STOPPED
:
2023 _cupsLangPrintf(stdout
,
2024 _("printer %s disabled since %s -\n"),
2025 printer
, printer_state_time
);
2029 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2031 if (!message
|| !*message
)
2032 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2034 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2037 if (long_status
> 1)
2038 _cupsLangPuts(stdout
,
2039 _("\tForm mounted:\n"
2040 "\tContent types: any\n"
2041 "\tPrinter types: unknown\n"));
2045 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2046 description
? description
: "");
2050 _cupsLangPuts(stdout
, _("\tAlerts:"));
2051 for (j
= 0; j
< reasons
->num_values
; j
++)
2052 _cupsLangPrintf(stdout
, " %s",
2053 reasons
->values
[j
].string
.text
);
2054 _cupsLangPuts(stdout
, "\n");
2057 if (long_status
> 1)
2059 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2060 location
? location
: "");
2062 if (ptype
& CUPS_PRINTER_REMOTE
)
2064 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2066 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2067 !strstr(make_model
, "Raw Printer") && uri
)
2068 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2073 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2075 if (make_model
&& strstr(make_model
, "System V Printer"))
2076 _cupsLangPrintf(stdout
,
2077 _("\tInterface: %s/interfaces/%s\n"),
2079 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2080 _cupsLangPrintf(stdout
,
2081 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2083 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2084 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2085 /* TODO update to use printer-error-policy */
2088 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2089 for (j
= 0; j
< allowed
->num_values
; j
++)
2090 _cupsLangPrintf(stdout
, "\t\t%s\n",
2091 allowed
->values
[j
].string
.text
);
2095 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2096 for (j
= 0; j
< denied
->num_values
; j
++)
2097 _cupsLangPrintf(stdout
, "\t\t%s\n",
2098 denied
->values
[j
].string
.text
);
2102 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2103 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2105 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2106 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2107 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2108 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2109 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2110 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2111 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2112 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2115 for (i
= 0; i
< num_dests
; i
++)
2116 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2120 case IPP_PRINTER_IDLE
:
2121 _cupsLangPrintf(stdout
,
2122 _("printer %s/%s is idle. "
2123 "enabled since %s\n"),
2124 printer
, dests
[i
].instance
,
2125 printer_state_time
);
2127 case IPP_PRINTER_PROCESSING
:
2128 _cupsLangPrintf(stdout
,
2129 _("printer %s/%s now printing %s-%d. "
2130 "enabled since %s\n"),
2131 printer
, dests
[i
].instance
, printer
, jobid
,
2132 printer_state_time
);
2134 case IPP_PRINTER_STOPPED
:
2135 _cupsLangPrintf(stdout
,
2136 _("printer %s/%s disabled since %s -\n"),
2137 printer
, dests
[i
].instance
,
2138 printer_state_time
);
2142 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2144 if (!message
|| !*message
)
2145 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2147 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2150 if (long_status
> 1)
2151 _cupsLangPuts(stdout
,
2152 _("\tForm mounted:\n"
2153 "\tContent types: any\n"
2154 "\tPrinter types: unknown\n"));
2158 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2159 description
? description
: "");
2163 _cupsLangPuts(stdout
, _("\tAlerts:"));
2164 for (j
= 0; j
< reasons
->num_values
; j
++)
2165 _cupsLangPrintf(stdout
, " %s",
2166 reasons
->values
[j
].string
.text
);
2167 _cupsLangPuts(stdout
, "\n");
2170 if (long_status
> 1)
2172 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2173 location
? location
: "");
2175 if (ptype
& CUPS_PRINTER_REMOTE
)
2177 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2179 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2180 !strstr(make_model
, "Raw Printer") && uri
)
2181 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2186 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2188 if (make_model
&& strstr(make_model
, "System V Printer"))
2189 _cupsLangPrintf(stdout
,
2190 _("\tInterface: %s/interfaces/%s\n"),
2192 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2193 _cupsLangPrintf(stdout
,
2194 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2196 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2197 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2198 /* TODO update to use printer-error-policy */
2201 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2202 for (j
= 0; j
< allowed
->num_values
; j
++)
2203 _cupsLangPrintf(stdout
, "\t\t%s\n",
2204 allowed
->values
[j
].string
.text
);
2208 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2209 for (j
= 0; j
< denied
->num_values
; j
++)
2210 _cupsLangPrintf(stdout
, "\t\t%s\n",
2211 denied
->values
[j
].string
.text
);
2215 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2216 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2218 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2219 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2220 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2221 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2222 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2223 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2224 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2225 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2234 ippDelete(response
);
2238 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2247 * 'show_scheduler()' - Show scheduler status.
2251 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2254 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2256 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2261 * End of "$Id: lpstat.c 6649 2007-07-11 21:46:42Z mike $".