2 * "$Id: lpstat.c 6073 2006-11-02 20:01:54Z mike $"
4 * "lpstat" command for the Common UNIX Printing System (CUPS).
6 * Copyright 1997-2006 by Easy Software Products.
8 * These coded instructions, statements, and computer programs are the
9 * property of Easy Software Products and are protected by Federal
10 * copyright law. Distribution and use rights are outlined in the file
11 * "LICENSE.txt" which should have been included with this file. If this
12 * file is missing or damaged please contact Easy Software Products
15 * Attn: CUPS Licensing Information
16 * Easy Software Products
17 * 44141 Airport View Drive, Suite 204
18 * Hollywood, Maryland 20636 USA
20 * Voice: (301) 373-9600
21 * EMail: cups-info@cups.org
22 * WWW: http://www.cups.org
26 * main() - Parse options and show status information.
27 * check_dest() - Verify that the named destination(s) exists.
28 * connect_server() - Connect to the server as necessary...
29 * show_accepting() - Show acceptance status.
30 * show_classes() - Show printer classes.
31 * show_default() - Show default destination.
32 * show_devices() - Show printer devices.
33 * show_jobs() - Show active print jobs.
34 * show_printers() - Show printers.
35 * show_scheduler() - Show scheduler status.
39 * Include necessary headers...
45 #include <cups/string.h>
46 #include <cups/cups.h>
47 #include <cups/i18n.h>
48 #include <cups/debug.h>
55 static void check_dest(const char *, http_t
*, const char *, int *,
57 static http_t
*connect_server(const char *, http_t
*);
58 static int show_accepting(http_t
*, const char *, int, cups_dest_t
*);
59 static int show_classes(http_t
*, const char *);
60 static void show_default(int, cups_dest_t
*);
61 static int show_devices(http_t
*, const char *, int, cups_dest_t
*);
62 static int show_jobs(http_t
*, const char *, const char *, int, int,
64 static int show_printers(http_t
*, const char *, int, cups_dest_t
*, int);
65 static void show_scheduler(http_t
*);
69 * 'main()' - Parse options and show status information.
73 main(int argc
, /* I - Number of command-line arguments */
74 char *argv
[]) /* I - Command-line arguments */
76 int i
, /* Looping var */
77 status
; /* Exit status */
78 http_t
*http
; /* Connection to server */
79 int num_dests
; /* Number of user destinations */
80 cups_dest_t
*dests
; /* User destinations */
81 int long_status
; /* Long status report? */
82 int ranking
; /* Show job ranking? */
83 const char *which
; /* Which jobs to show? */
84 char op
; /* Last operation on command-line */
90 * Parse command-line options...
99 which
= "not-completed";
102 for (i
= 1; i
< argc
; i
++)
103 if (argv
[i
][0] == '-')
106 case 'D' : /* Show description */
110 case 'E' : /* Encrypt */
112 cupsSetEncryption(HTTP_ENCRYPT_REQUIRED
);
115 httpEncryption(http
, HTTP_ENCRYPT_REQUIRED
);
117 _cupsLangPrintf(stderr
,
118 _("%s: Sorry, no encryption support compiled in!\n"),
120 #endif /* HAVE_SSL */
123 case 'P' : /* Show paper types */
127 case 'R' : /* Show ranking */
131 case 'S' : /* Show charsets */
137 case 'U' : /* Username */
138 if (argv
[i
][2] != '\0')
139 cupsSetUser(argv
[i
] + 2);
145 _cupsLangPrintf(stderr
,
146 _("%s: Error - expected username after "
152 cupsSetUser(argv
[i
]);
156 case 'W' : /* Show which jobs? */
165 _cupsLangPrintf(stderr
,
166 _("%s: Error - need \"completed\", "
167 "\"not-completed\", or \"all\" after "
176 if (strcmp(which
, "completed") && strcmp(which
, "not-completed") &&
177 strcmp(which
, "all"))
179 _cupsLangPrintf(stderr
,
180 _("%s: Error - need \"completed\", "
181 "\"not-completed\", or \"all\" after "
188 case 'a' : /* Show acceptance status */
190 http
= connect_server(argv
[0], http
);
192 if (argv
[i
][2] != '\0')
194 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
196 status
|= show_accepting(http
, argv
[i
] + 2, num_dests
, dests
);
198 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
202 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
204 status
|= show_accepting(http
, argv
[i
], num_dests
, dests
);
209 num_dests
= cupsGetDests2(http
, &dests
);
211 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
216 case 'b' : /* Show both the local and remote status */
218 http
= connect_server(argv
[0], http
);
220 if (argv
[i
][2] != '\0')
223 * The local and remote status are separated by a blank line;
224 * since all CUPS jobs are networked, we only output the
225 * second list for now... In the future, we might further
226 * emulate this by listing the remote server's queue, but
227 * for now this is enough to make the SGI printstatus program
231 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
234 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
238 _cupsLangPrintf(stderr
,
239 _("%s: Error - expected destination after "
248 case 'c' : /* Show classes and members */
250 http
= connect_server(argv
[0], http
);
252 if (argv
[i
][2] != '\0')
254 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
256 status
|= show_classes(http
, argv
[i
] + 2);
258 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
262 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
264 status
|= show_classes(http
, argv
[i
]);
267 status
|= show_classes(http
, NULL
);
270 case 'd' : /* Show default destination */
272 http
= connect_server(argv
[0], http
);
275 num_dests
= cupsGetDests2(http
, &dests
);
277 show_default(num_dests
, dests
);
280 case 'f' : /* Show forms */
286 case 'h' : /* Connect to host */
293 if (argv
[i
][2] != '\0')
294 cupsSetServer(argv
[i
] + 2);
301 _cupsLangPrintf(stderr
,
302 _("%s: Error - expected hostname after "
308 cupsSetServer(argv
[i
]);
312 case 'l' : /* Long status or long job status */
315 http
= connect_server(argv
[0], http
);
317 if (argv
[i
][2] != '\0')
319 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
321 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, 3, ranking
, which
);
328 case 'o' : /* Show jobs by destination */
330 http
= connect_server(argv
[0], http
);
332 if (argv
[i
][2] != '\0')
334 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
336 status
|= show_jobs(http
, argv
[i
] + 2, NULL
, long_status
,
339 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
343 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
345 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
,
349 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
353 case 'p' : /* Show printers */
355 http
= connect_server(argv
[0], http
);
357 if (argv
[i
][2] != '\0')
359 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
361 status
|= show_printers(http
, argv
[i
] + 2, num_dests
, dests
, long_status
);
363 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
367 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
369 status
|= show_printers(http
, argv
[i
], num_dests
, dests
, long_status
);
374 num_dests
= cupsGetDests2(http
, &dests
);
376 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
380 case 'r' : /* Show scheduler status */
382 http
= connect_server(argv
[0], http
);
384 show_scheduler(http
);
387 case 's' : /* Show summary */
389 http
= connect_server(argv
[0], http
);
392 num_dests
= cupsGetDests2(http
, &dests
);
394 show_default(num_dests
, dests
);
395 status
|= show_classes(http
, NULL
);
396 status
|= show_devices(http
, NULL
, num_dests
, dests
);
399 case 't' : /* Show all info */
401 http
= connect_server(argv
[0], http
);
404 num_dests
= cupsGetDests2(http
, &dests
);
406 show_scheduler(http
);
407 show_default(num_dests
, dests
);
408 status
|= show_classes(http
, NULL
);
409 status
|= show_devices(http
, NULL
, num_dests
, dests
);
410 status
|= show_accepting(http
, NULL
, num_dests
, dests
);
411 status
|= show_printers(http
, NULL
, num_dests
, dests
, long_status
);
412 status
|= show_jobs(http
, NULL
, NULL
, long_status
, ranking
, which
);
415 case 'u' : /* Show jobs by user */
417 http
= connect_server(argv
[0], http
);
419 if (argv
[i
][2] != '\0')
420 status
|= show_jobs(http
, NULL
, argv
[i
] + 2, long_status
,
422 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
425 status
|= show_jobs(http
, NULL
, argv
[i
], long_status
,
429 status
|= show_jobs(http
, NULL
, NULL
, long_status
,
433 case 'v' : /* Show printer devices */
435 http
= connect_server(argv
[0], http
);
437 if (argv
[i
][2] != '\0')
439 check_dest(argv
[0], http
, argv
[i
] + 2, &num_dests
, &dests
);
441 status
|= show_devices(http
, argv
[i
] + 2, num_dests
, dests
);
443 else if ((i
+ 1) < argc
&& argv
[i
+ 1][0] != '-')
447 check_dest(argv
[0], http
, argv
[i
], &num_dests
, &dests
);
449 status
|= show_devices(http
, argv
[i
], num_dests
, dests
);
454 num_dests
= cupsGetDests2(http
, &dests
);
456 status
|= show_devices(http
, NULL
, num_dests
, dests
);
462 _cupsLangPrintf(stderr
,
463 _("%s: Error - unknown option \'%c\'!\n"),
464 argv
[0], argv
[i
][1]);
469 http
= connect_server(argv
[0], http
);
471 status
|= show_jobs(http
, argv
[i
], NULL
, long_status
, ranking
, which
);
477 http
= connect_server(argv
[0], http
);
479 status
|= show_jobs(http
, NULL
, cupsUser(), long_status
, ranking
, which
);
487 * 'check_dest()' - Verify that the named destination(s) exists.
491 check_dest(const char *command
, /* I - Command name */
492 http_t
*http
, /* I - HTTP connection */
493 const char *name
, /* I - Name of printer/class(es) */
494 int *num_dests
, /* IO - Number of destinations */
495 cups_dest_t
**dests
) /* IO - Destinations */
503 * Load the destination list as necessary...
507 *num_dests
= cupsGetDests2(http
, dests
);
510 * Scan the name string for printer/class name(s)...
513 for (dptr
= name
; *dptr
!= '\0';)
516 * Skip leading whitespace and commas...
519 while (isspace(*dptr
& 255) || *dptr
== ',')
526 * Extract a single destination name from the name string...
529 for (pptr
= printer
; !isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0';)
531 if ((pptr
- printer
) < (sizeof(printer
) - 1))
535 _cupsLangPrintf(stderr
,
536 _("%s: Invalid destination name in list \"%s\"!\n"),
545 * Check the destination...
548 if (cupsGetDest(printer
, NULL
, *num_dests
, *dests
) == NULL
)
550 _cupsLangPrintf(stderr
,
551 _("%s: Unknown destination \"%s\"!\n"), command
, printer
);
559 * 'connect_server()' - Connect to the server as necessary...
562 static http_t
* /* O - New HTTP connection */
563 connect_server(const char *command
, /* I - Command name */
564 http_t
*http
) /* I - Current HTTP connection */
568 http
= httpConnectEncrypt(cupsServer(), ippPort(),
573 _cupsLangPrintf(stderr
, _("%s: Unable to connect to server\n"), command
);
583 * 'show_accepting()' - Show acceptance status.
586 static int /* O - 0 on success, 1 on fail */
587 show_accepting(http_t
*http
, /* I - HTTP connection to server */
588 const char *printers
, /* I - Destinations */
589 int num_dests
, /* I - Number of user-defined dests */
590 cups_dest_t
*dests
) /* I - User-defined destinations */
592 int i
; /* Looping var */
593 ipp_t
*request
, /* IPP Request */
594 *response
; /* IPP Response */
595 ipp_attribute_t
*attr
; /* Current attribute */
596 const char *printer
, /* Printer name */
597 *message
; /* Printer device URI */
598 int accepting
; /* Accepting requests? */
599 time_t ptime
; /* Printer state time */
600 struct tm
*pdate
; /* Printer state date & time */
601 char printer_state_time
[255];/* Printer state time */
602 const char *dptr
, /* Pointer into destination list */
603 *ptr
; /* Pointer into printer name */
604 int match
; /* Non-zero if this job matches */
605 static const char *pattrs
[] = /* Attributes we need for printers... */
608 "printer-state-change-time",
609 "printer-state-message",
610 "printer-is-accepting-jobs"
614 DEBUG_printf(("show_accepting(%p, %p)\n", http
, printers
));
619 if (printers
!= NULL
&& !strcmp(printers
, "all"))
623 * Build a CUPS_GET_PRINTERS request, which requires the following
627 * attributes-natural-language
628 * requested-attributes
629 * requesting-user-name
632 request
= ippNewRequest(CUPS_GET_PRINTERS
);
634 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
635 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
638 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
642 * Do the request and get back a response...
645 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
647 DEBUG_puts("show_accepting: request succeeded...");
649 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
651 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
657 * Loop through the printers returned in the list and display
661 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
664 * Skip leading attributes until we hit a printer...
667 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
674 * Pull the needed attributes from this printer...
682 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
684 if (!strcmp(attr
->name
, "printer-name") &&
685 attr
->value_tag
== IPP_TAG_NAME
)
686 printer
= attr
->values
[0].string
.text
;
687 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
688 attr
->value_tag
== IPP_TAG_INTEGER
)
689 ptime
= (time_t)attr
->values
[0].integer
;
690 else if (!strcmp(attr
->name
, "printer-state-message") &&
691 attr
->value_tag
== IPP_TAG_TEXT
)
692 message
= attr
->values
[0].string
.text
;
693 else if (!strcmp(attr
->name
, "printer-is-accepting-jobs") &&
694 attr
->value_tag
== IPP_TAG_BOOLEAN
)
695 accepting
= attr
->values
[0].boolean
;
701 * See if we have everything needed...
713 * See if this is a printer we're interested in...
716 match
= printers
== NULL
;
718 if (printers
!= NULL
)
720 for (dptr
= printers
; *dptr
!= '\0';)
723 * Skip leading whitespace and commas...
726 while (isspace(*dptr
& 255) || *dptr
== ',')
737 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
740 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
747 * Skip trailing junk...
750 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
752 while (isspace(*dptr
& 255) || *dptr
== ',')
761 * Display the printer entry if needed...
766 pdate
= localtime(&ptime
);
767 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
770 _cupsLangPrintf(stdout
, _("%s accepting requests since %s\n"),
771 printer
, printer_state_time
);
773 _cupsLangPrintf(stdout
, _("%s not accepting requests since %s -\n"
775 printer
, printer_state_time
,
776 message
== NULL
? "reason unknown" : message
);
778 for (i
= 0; i
< num_dests
; i
++)
779 if (!strcasecmp(dests
[i
].name
, printer
) && dests
[i
].instance
)
782 _cupsLangPrintf(stdout
, _("%s/%s accepting requests since %s\n"),
783 printer
, dests
[i
].instance
, printer_state_time
);
785 _cupsLangPrintf(stdout
, _("%s/%s not accepting requests since "
787 printer
, dests
[i
].instance
, printer_state_time
,
788 message
== NULL
? "reason unknown" : message
);
800 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
809 * 'show_classes()' - Show printer classes.
812 static int /* O - 0 on success, 1 on fail */
813 show_classes(http_t
*http
, /* I - HTTP connection to server */
814 const char *dests
) /* I - Destinations */
816 int i
; /* Looping var */
817 ipp_t
*request
, /* IPP Request */
818 *response
, /* IPP Response */
819 *response2
; /* IPP response from remote server */
820 http_t
*http2
; /* Remote server */
821 ipp_attribute_t
*attr
; /* Current attribute */
822 const char *printer
, /* Printer class name */
823 *printer_uri
; /* Printer class URI */
824 ipp_attribute_t
*members
; /* Printer members */
825 char method
[HTTP_MAX_URI
], /* Request method */
826 username
[HTTP_MAX_URI
], /* Username:password */
827 server
[HTTP_MAX_URI
], /* Server name */
828 resource
[HTTP_MAX_URI
]; /* Resource name */
829 int port
; /* Port number */
830 const char *dptr
, /* Pointer into destination list */
831 *ptr
; /* Pointer into printer name */
832 int match
; /* Non-zero if this job matches */
833 static const char *cattrs
[] = /* Attributes we need for classes... */
836 "printer-uri-supported",
841 DEBUG_printf(("show_classes(%p, %p)\n", http
, dests
));
846 if (dests
!= NULL
&& !strcmp(dests
, "all"))
850 * Build a CUPS_GET_CLASSES request, which requires the following
854 * attributes-natural-language
855 * requested-attributes
856 * requesting-user-name
859 request
= ippNewRequest(CUPS_GET_CLASSES
);
861 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
862 "requested-attributes", sizeof(cattrs
) / sizeof(cattrs
[0]),
865 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
869 * Do the request and get back a response...
872 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
874 DEBUG_puts("show_classes: request succeeded...");
876 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
878 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
884 * Loop through the printers returned in the list and display
888 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
891 * Skip leading attributes until we hit a job...
894 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
901 * Pull the needed attributes from this job...
908 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
910 if (!strcmp(attr
->name
, "printer-name") &&
911 attr
->value_tag
== IPP_TAG_NAME
)
912 printer
= attr
->values
[0].string
.text
;
914 if (!strcmp(attr
->name
, "printer-uri-supported") &&
915 attr
->value_tag
== IPP_TAG_URI
)
916 printer_uri
= attr
->values
[0].string
.text
;
918 if (!strcmp(attr
->name
, "member-names") &&
919 attr
->value_tag
== IPP_TAG_NAME
)
926 * If this is a remote class, grab the class info from the
931 if (members
== NULL
&& printer_uri
!= NULL
)
933 httpSeparateURI(HTTP_URI_CODING_ALL
, printer_uri
, method
, sizeof(method
),
934 username
, sizeof(username
), server
, sizeof(server
),
935 &port
, resource
, sizeof(resource
));
937 if (!strcasecmp(server
, http
->hostname
))
940 http2
= httpConnectEncrypt(server
, port
, cupsEncryption());
945 * Build an IPP_GET_PRINTER_ATTRIBUTES request, which requires the
946 * following attributes:
949 * attributes-natural-language
951 * requested-attributes
954 request
= ippNewRequest(IPP_GET_PRINTER_ATTRIBUTES
);
956 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
957 "printer-uri", NULL
, printer_uri
);
959 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
960 "requested-attributes",
961 sizeof(cattrs
) / sizeof(cattrs
[0]),
964 if ((response2
= cupsDoRequest(http2
, request
, "/")) != NULL
)
965 members
= ippFindAttribute(response2
, "member-names", IPP_TAG_NAME
);
973 * See if we have everything needed...
979 ippDelete(response2
);
988 * See if this is a printer we're interested in...
991 match
= dests
== NULL
;
995 for (dptr
= dests
; *dptr
!= '\0';)
998 * Skip leading whitespace and commas...
1001 while (isspace(*dptr
& 255) || *dptr
== ',')
1012 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1015 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1022 * Skip trailing junk...
1025 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1027 while (isspace(*dptr
& 255) || *dptr
== ',')
1036 * Display the printer entry if needed...
1041 _cupsLangPrintf(stdout
, _("members of class %s:\n"), printer
);
1045 for (i
= 0; i
< members
->num_values
; i
++)
1046 _cupsLangPrintf(stdout
, "\t%s\n",
1047 members
->values
[i
].string
.text
);
1050 _cupsLangPuts(stdout
, "\tunknown\n");
1054 ippDelete(response2
);
1060 ippDelete(response
);
1064 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1073 * 'show_default()' - Show default destination.
1077 show_default(int num_dests
, /* I - Number of user-defined dests */
1078 cups_dest_t
*dests
) /* I - User-defined destinations */
1080 cups_dest_t
*dest
; /* Destination */
1081 const char *printer
, /* Printer name */
1082 *val
; /* Environment variable name */
1084 if ((dest
= cupsGetDest(NULL
, NULL
, num_dests
, dests
)) != NULL
)
1087 _cupsLangPrintf(stdout
, _("system default destination: %s/%s\n"),
1088 dest
->name
, dest
->instance
);
1090 _cupsLangPrintf(stdout
, _("system default destination: %s\n"),
1097 if ((printer
= getenv("LPDEST")) == NULL
)
1099 if ((printer
= getenv("PRINTER")) != NULL
)
1101 if (!strcmp(printer
, "lp"))
1110 if (printer
&& !cupsGetDest(printer
, NULL
, num_dests
, dests
))
1111 _cupsLangPrintf(stdout
,
1112 _("lpstat: error - %s environment variable names "
1113 "non-existent destination \"%s\"!\n"),
1116 _cupsLangPuts(stdout
, _("no system default destination\n"));
1122 * 'show_devices()' - Show printer devices.
1125 static int /* O - 0 on success, 1 on fail */
1126 show_devices(http_t
*http
, /* I - HTTP connection to server */
1127 const char *printers
, /* I - Destinations */
1128 int num_dests
, /* I - Number of user-defined dests */
1129 cups_dest_t
*dests
) /* I - User-defined destinations */
1131 int i
; /* Looping var */
1132 ipp_t
*request
, /* IPP Request */
1133 *response
; /* IPP Response */
1134 ipp_attribute_t
*attr
; /* Current attribute */
1135 const char *printer
, /* Printer name */
1136 *uri
, /* Printer URI */
1137 *device
, /* Printer device URI */
1138 *dptr
, /* Pointer into destination list */
1139 *ptr
; /* Pointer into printer name */
1140 int match
; /* Non-zero if this job matches */
1141 static const char *pattrs
[] = /* Attributes we need for printers... */
1144 "printer-uri-supported",
1149 DEBUG_printf(("show_devices(%p, %p)\n", http
, dests
));
1154 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1158 * Build a CUPS_GET_PRINTERS request, which requires the following
1161 * attributes-charset
1162 * attributes-natural-language
1163 * requested-attributes
1164 * requesting-user-name
1167 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1169 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1170 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1173 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1177 * Do the request and get back a response...
1180 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1182 DEBUG_puts("show_devices: request succeeded...");
1184 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1186 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1187 ippDelete(response
);
1192 * Loop through the printers returned in the list and display
1196 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1199 * Skip leading attributes until we hit a job...
1202 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1209 * Pull the needed attributes from this job...
1216 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1218 if (!strcmp(attr
->name
, "printer-name") &&
1219 attr
->value_tag
== IPP_TAG_NAME
)
1220 printer
= attr
->values
[0].string
.text
;
1222 if (!strcmp(attr
->name
, "printer-uri-supported") &&
1223 attr
->value_tag
== IPP_TAG_URI
)
1224 uri
= attr
->values
[0].string
.text
;
1226 if (!strcmp(attr
->name
, "device-uri") &&
1227 attr
->value_tag
== IPP_TAG_URI
)
1228 device
= attr
->values
[0].string
.text
;
1234 * See if we have everything needed...
1237 if (printer
== NULL
)
1246 * See if this is a printer we're interested in...
1249 match
= printers
== NULL
;
1251 if (printers
!= NULL
)
1253 for (dptr
= printers
; *dptr
!= '\0';)
1256 * Skip leading whitespace and commas...
1259 while (isspace(*dptr
& 255) || *dptr
== ',')
1270 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1273 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1280 * Skip trailing junk...
1283 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1285 while (isspace(*dptr
& 255) || *dptr
== ',')
1294 * Display the printer entry if needed...
1299 #ifdef __osf__ /* Compaq/Digital like to do it their own way... */
1300 char method
[HTTP_MAX_URI
], /* Components of printer URI */
1301 username
[HTTP_MAX_URI
],
1302 hostname
[HTTP_MAX_URI
],
1303 resource
[HTTP_MAX_URI
];
1309 httpSeparateURI(HTTP_URI_CODING_ALL
, uri
, method
, sizeof(method
),
1310 username
, sizeof(username
), hostname
,
1311 sizeof(hostname
), &port
, resource
, sizeof(resource
));
1312 _cupsLangPrintf(stdout
,
1313 _("Output for printer %s is sent to remote "
1314 "printer %s on %s\n"),
1315 printer
, strrchr(resource
, '/') + 1, hostname
);
1317 else if (!strncmp(device
, "file:", 5))
1318 _cupsLangPrintf(stdout
,
1319 _("Output for printer %s is sent to %s\n"),
1320 printer
, device
+ 5);
1322 _cupsLangPrintf(stdout
,
1323 _("Output for printer %s is sent to %s\n"),
1326 for (i
= 0; i
< num_dests
; i
++)
1327 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1330 _cupsLangPrintf(stdout
,
1331 _("Output for printer %s/%s is sent to "
1332 "remote printer %s on %s\n"),
1333 printer
, dests
[i
].instance
,
1334 strrchr(resource
, '/') + 1, hostname
);
1335 else if (!strncmp(device
, "file:", 5))
1336 _cupsLangPrintf(stdout
,
1337 _("Output for printer %s/%s is sent to %s\n"),
1338 printer
, dests
[i
].instance
, device
+ 5);
1340 _cupsLangPrintf(stdout
,
1341 _("Output for printer %s/%s is sent to %s\n"),
1342 printer
, dests
[i
].instance
, device
);
1346 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1348 else if (!strncmp(device
, "file:", 5))
1349 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1350 printer
, device
+ 5);
1352 _cupsLangPrintf(stdout
, _("device for %s: %s\n"),
1355 for (i
= 0; i
< num_dests
; i
++)
1356 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
1359 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1360 printer
, dests
[i
].instance
, uri
);
1361 else if (!strncmp(device
, "file:", 5))
1362 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1363 printer
, dests
[i
].instance
, device
+ 5);
1365 _cupsLangPrintf(stdout
, _("device for %s/%s: %s\n"),
1366 printer
, dests
[i
].instance
, device
);
1368 #endif /* __osf__ */
1375 ippDelete(response
);
1379 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1388 * 'show_jobs()' - Show active print jobs.
1391 static int /* O - 0 on success, 1 on fail */
1392 show_jobs(http_t
*http
, /* I - HTTP connection to server */
1393 const char *dests
, /* I - Destinations */
1394 const char *users
, /* I - Users */
1395 int long_status
, /* I - Show long status? */
1396 int ranking
, /* I - Show job ranking? */
1397 const char *which
) /* I - Show which jobs? */
1399 ipp_t
*request
, /* IPP Request */
1400 *response
; /* IPP Response */
1401 ipp_attribute_t
*attr
; /* Current attribute */
1402 const char *dest
, /* Pointer into job-printer-uri */
1403 *username
, /* Pointer to job-originating-user-name */
1404 *title
; /* Pointer to job-name */
1405 int rank
, /* Rank in queue */
1407 size
; /* job-k-octets */
1408 time_t jobtime
; /* time-at-creation */
1409 struct tm
*jobdate
; /* Date & time */
1410 const char *dptr
, /* Pointer into destination list */
1411 *ptr
; /* Pointer into printer name */
1412 int match
; /* Non-zero if this job matches */
1413 char temp
[255], /* Temporary buffer */
1414 date
[255]; /* Date buffer */
1415 static const char *jattrs
[] = /* Attributes we need for jobs... */
1422 "job-originating-user-name"
1426 DEBUG_printf(("show_jobs(%p, %p, %p)\n", http
, dests
, users
));
1431 if (dests
!= NULL
&& !strcmp(dests
, "all"))
1435 * Build a IPP_GET_JOBS request, which requires the following
1438 * attributes-charset
1439 * attributes-natural-language
1441 * requested-attributes
1444 request
= ippNewRequest(IPP_GET_JOBS
);
1446 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1447 "requested-attributes", sizeof(jattrs
) / sizeof(jattrs
[0]),
1450 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
, "job-uri",
1451 NULL
, "ipp://localhost/jobs/");
1453 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
, "which-jobs",
1457 * Do the request and get back a response...
1460 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1463 * Loop through the job list and display them...
1466 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1468 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1469 ippDelete(response
);
1475 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1478 * Skip leading attributes until we hit a job...
1481 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_JOB
)
1488 * Pull the needed attributes from this job...
1498 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_JOB
)
1500 if (!strcmp(attr
->name
, "job-id") &&
1501 attr
->value_tag
== IPP_TAG_INTEGER
)
1502 jobid
= attr
->values
[0].integer
;
1504 if (!strcmp(attr
->name
, "job-k-octets") &&
1505 attr
->value_tag
== IPP_TAG_INTEGER
)
1506 size
= attr
->values
[0].integer
;
1508 if (!strcmp(attr
->name
, "time-at-creation") &&
1509 attr
->value_tag
== IPP_TAG_INTEGER
)
1510 jobtime
= attr
->values
[0].integer
;
1512 if (!strcmp(attr
->name
, "job-printer-uri") &&
1513 attr
->value_tag
== IPP_TAG_URI
)
1514 if ((dest
= strrchr(attr
->values
[0].string
.text
, '/')) != NULL
)
1517 if (!strcmp(attr
->name
, "job-originating-user-name") &&
1518 attr
->value_tag
== IPP_TAG_NAME
)
1519 username
= attr
->values
[0].string
.text
;
1521 if (!strcmp(attr
->name
, "job-name") &&
1522 attr
->value_tag
== IPP_TAG_NAME
)
1523 title
= attr
->values
[0].string
.text
;
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
);
1667 _cupsLangPrintf(stdout
, _("\tqueued for %s\n"), dest
);
1675 ippDelete(response
);
1679 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1688 * 'show_printers()' - Show printers.
1691 static int /* O - 0 on success, 1 on fail */
1692 show_printers(http_t
*http
, /* I - HTTP connection to server */
1693 const char *printers
, /* I - Destinations */
1694 int num_dests
, /* I - Number of user-defined dests */
1695 cups_dest_t
*dests
, /* I - User-defined destinations */
1696 int long_status
) /* I - Show long status? */
1698 int i
, j
; /* Looping vars */
1699 ipp_t
*request
, /* IPP Request */
1700 *response
, /* IPP Response */
1701 *jobs
; /* IPP Get Jobs response */
1702 ipp_attribute_t
*attr
, /* Current attribute */
1703 *jobattr
, /* Job ID attribute */
1704 *reasons
; /* Job state reasons attribute */
1705 const char *printer
, /* Printer name */
1706 *message
, /* Printer state message */
1707 *description
, /* Description of printer */
1708 *location
, /* Location of printer */
1709 *make_model
, /* Make and model of printer */
1710 *uri
; /* URI of printer */
1711 ipp_attribute_t
*allowed
, /* requesting-user-name-allowed */
1712 *denied
; /* requestint-user-name-denied */
1713 ipp_pstate_t pstate
; /* Printer state */
1714 cups_ptype_t ptype
; /* Printer type */
1715 time_t ptime
; /* Printer state time */
1716 struct tm
*pdate
; /* Printer state date & time */
1717 int jobid
; /* Job ID of current job */
1718 const char *dptr
, /* Pointer into destination list */
1719 *ptr
; /* Pointer into printer name */
1720 int match
; /* Non-zero if this job matches */
1721 char printer_uri
[HTTP_MAX_URI
],
1723 printer_state_time
[255];/* Printer state time */
1724 const char *root
; /* Server root directory... */
1725 static const char *pattrs
[] = /* Attributes we need for printers... */
1729 "printer-state-message",
1730 "printer-state-reasons",
1731 "printer-state-change-time",
1735 "printer-make-and-model",
1736 "printer-uri-supported",
1737 "requesting-user-name-allowed",
1738 "requesting-user-name-denied"
1740 static const char *jattrs
[] = /* Attributes we need for jobs... */
1746 DEBUG_printf(("show_printers(%p, %p)\n", http
, dests
));
1751 if ((root
= getenv("CUPS_SERVERROOT")) == NULL
)
1752 root
= CUPS_SERVERROOT
;
1754 if (printers
!= NULL
&& !strcmp(printers
, "all"))
1758 * Build a CUPS_GET_PRINTERS request, which requires the following
1761 * attributes-charset
1762 * attributes-natural-language
1763 * requested-attributes
1764 * requesting-user-name
1767 request
= ippNewRequest(CUPS_GET_PRINTERS
);
1769 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1770 "requested-attributes", sizeof(pattrs
) / sizeof(pattrs
[0]),
1773 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_NAME
, "requesting-user-name",
1777 * Do the request and get back a response...
1780 if ((response
= cupsDoRequest(http
, request
, "/")) != NULL
)
1782 DEBUG_puts("show_printers: request succeeded...");
1784 if (response
->request
.status
.status_code
> IPP_OK_CONFLICT
)
1786 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
1787 ippDelete(response
);
1792 * Loop through the printers returned in the list and display
1796 for (attr
= response
->attrs
; attr
!= NULL
; attr
= attr
->next
)
1799 * Skip leading attributes until we hit a job...
1802 while (attr
!= NULL
&& attr
->group_tag
!= IPP_TAG_PRINTER
)
1809 * Pull the needed attributes from this job...
1814 ptype
= CUPS_PRINTER_LOCAL
;
1815 pstate
= IPP_PRINTER_IDLE
;
1826 while (attr
!= NULL
&& attr
->group_tag
== IPP_TAG_PRINTER
)
1828 if (!strcmp(attr
->name
, "printer-name") &&
1829 attr
->value_tag
== IPP_TAG_NAME
)
1830 printer
= attr
->values
[0].string
.text
;
1831 else if (!strcmp(attr
->name
, "printer-state") &&
1832 attr
->value_tag
== IPP_TAG_ENUM
)
1833 pstate
= (ipp_pstate_t
)attr
->values
[0].integer
;
1834 else if (!strcmp(attr
->name
, "printer-type") &&
1835 attr
->value_tag
== IPP_TAG_ENUM
)
1836 ptype
= (cups_ptype_t
)attr
->values
[0].integer
;
1837 else if (!strcmp(attr
->name
, "printer-state-message") &&
1838 attr
->value_tag
== IPP_TAG_TEXT
)
1839 message
= attr
->values
[0].string
.text
;
1840 else if (!strcmp(attr
->name
, "printer-state-change-time") &&
1841 attr
->value_tag
== IPP_TAG_INTEGER
)
1842 ptime
= (time_t)attr
->values
[0].integer
;
1843 else if (!strcmp(attr
->name
, "printer-info") &&
1844 attr
->value_tag
== IPP_TAG_TEXT
)
1845 description
= attr
->values
[0].string
.text
;
1846 else if (!strcmp(attr
->name
, "printer-location") &&
1847 attr
->value_tag
== IPP_TAG_TEXT
)
1848 location
= attr
->values
[0].string
.text
;
1849 else if (!strcmp(attr
->name
, "printer-make-and-model") &&
1850 attr
->value_tag
== IPP_TAG_TEXT
)
1851 make_model
= attr
->values
[0].string
.text
;
1852 else if (!strcmp(attr
->name
, "printer-uri-supported") &&
1853 attr
->value_tag
== IPP_TAG_URI
)
1854 uri
= attr
->values
[0].string
.text
;
1855 else if (!strcmp(attr
->name
, "printer-state-reasons") &&
1856 attr
->value_tag
== IPP_TAG_KEYWORD
)
1858 else if (!strcmp(attr
->name
, "requesting-user-name-allowed") &&
1859 attr
->value_tag
== IPP_TAG_NAME
)
1861 else if (!strcmp(attr
->name
, "requesting-user-name-denied") &&
1862 attr
->value_tag
== IPP_TAG_NAME
)
1869 * See if we have everything needed...
1872 if (printer
== NULL
)
1881 * See if this is a printer we're interested in...
1884 match
= printers
== NULL
;
1886 if (printers
!= NULL
)
1888 for (dptr
= printers
; *dptr
!= '\0';)
1891 * Skip leading whitespace and commas...
1894 while (isspace(*dptr
& 255) || *dptr
== ',')
1905 *ptr
!= '\0' && *dptr
!= '\0' && tolower(*ptr
& 255) == tolower(*dptr
& 255);
1908 if (*ptr
== '\0' && (*dptr
== '\0' || *dptr
== ',' || isspace(*dptr
& 255)))
1915 * Skip trailing junk...
1918 while (!isspace(*dptr
& 255) && *dptr
!= ',' && *dptr
!= '\0')
1920 while (isspace(*dptr
& 255) || *dptr
== ',')
1929 * Display the printer entry if needed...
1935 * If the printer state is "IPP_PRINTER_PROCESSING", then grab the
1936 * current job for the printer.
1939 if (pstate
== IPP_PRINTER_PROCESSING
)
1942 * Build an IPP_GET_JOBS request, which requires the following
1945 * attributes-charset
1946 * attributes-natural-language
1949 * requested-attributes
1952 request
= ippNewRequest(IPP_GET_JOBS
);
1954 request
->request
.op
.operation_id
= IPP_GET_JOBS
;
1955 request
->request
.op
.request_id
= 1;
1957 ippAddStrings(request
, IPP_TAG_OPERATION
, IPP_TAG_KEYWORD
,
1958 "requested-attributes",
1959 sizeof(jattrs
) / sizeof(jattrs
[0]), NULL
, jattrs
);
1961 httpAssembleURIf(HTTP_URI_CODING_ALL
, printer_uri
, sizeof(printer_uri
),
1962 "ipp", NULL
, "localhost", 0, "/printers/%s", printer
);
1963 ippAddString(request
, IPP_TAG_OPERATION
, IPP_TAG_URI
,
1964 "printer-uri", NULL
, printer_uri
);
1966 if ((jobs
= cupsDoRequest(http
, request
, "/")) != NULL
)
1969 * Get the current active job on this queue...
1974 for (jobattr
= jobs
->attrs
; jobattr
; jobattr
= jobattr
->next
)
1979 if (!strcmp(jobattr
->name
, "job-id") &&
1980 jobattr
->value_tag
== IPP_TAG_INTEGER
)
1981 jobid
= jobattr
->values
[0].integer
;
1982 else if (!strcmp(jobattr
->name
, "job-state") &&
1983 jobattr
->value_tag
== IPP_TAG_ENUM
&&
1984 jobattr
->values
[0].integer
== IPP_JOB_PROCESSING
)
1996 pdate
= localtime(&ptime
);
1997 strftime(printer_state_time
, sizeof(printer_state_time
), "%c", pdate
);
2001 case IPP_PRINTER_IDLE
:
2002 _cupsLangPrintf(stdout
,
2003 _("printer %s is idle. enabled since %s\n"),
2004 printer
, printer_state_time
);
2006 case IPP_PRINTER_PROCESSING
:
2007 _cupsLangPrintf(stdout
,
2008 _("printer %s now printing %s-%d. "
2009 "enabled since %s\n"),
2010 printer
, printer
, jobid
, printer_state_time
);
2012 case IPP_PRINTER_STOPPED
:
2013 _cupsLangPrintf(stdout
,
2014 _("printer %s disabled since %s -\n"),
2015 printer
, printer_state_time
);
2019 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2021 if (!message
|| !*message
)
2022 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2024 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2027 if (long_status
> 1)
2028 _cupsLangPuts(stdout
,
2029 _("\tForm mounted:\n"
2030 "\tContent types: any\n"
2031 "\tPrinter types: unknown\n"));
2035 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2036 description
? description
: "");
2040 _cupsLangPuts(stdout
, _("\tAlerts:"));
2041 for (j
= 0; j
< reasons
->num_values
; i
++)
2042 _cupsLangPrintf(stdout
, " %s",
2043 reasons
->values
[j
].string
.text
);
2044 _cupsLangPuts(stdout
, "\n");
2047 if (long_status
> 1)
2049 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2050 location
? location
: "");
2052 if (ptype
& CUPS_PRINTER_REMOTE
)
2054 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2056 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2057 !strstr(make_model
, "Raw Printer") && uri
)
2058 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2063 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2065 if (make_model
&& strstr(make_model
, "System V Printer"))
2066 _cupsLangPrintf(stdout
,
2067 _("\tInterface: %s/interfaces/%s\n"),
2069 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2070 _cupsLangPrintf(stdout
,
2071 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2073 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2074 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2075 /* TODO update to use printer-error-policy */
2078 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2079 for (j
= 0; j
< allowed
->num_values
; j
++)
2080 _cupsLangPrintf(stdout
, "\t\t%s\n",
2081 allowed
->values
[j
].string
.text
);
2085 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2086 for (j
= 0; j
< denied
->num_values
; j
++)
2087 _cupsLangPrintf(stdout
, "\t\t%s\n",
2088 denied
->values
[j
].string
.text
);
2092 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2093 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2095 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2096 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2097 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2098 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2099 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2100 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2101 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2102 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2105 for (i
= 0; i
< num_dests
; i
++)
2106 if (!strcasecmp(printer
, dests
[i
].name
) && dests
[i
].instance
)
2110 case IPP_PRINTER_IDLE
:
2111 _cupsLangPrintf(stdout
,
2112 _("printer %s/%s is idle. "
2113 "enabled since %s\n"),
2114 printer
, dests
[i
].instance
,
2115 printer_state_time
);
2117 case IPP_PRINTER_PROCESSING
:
2118 _cupsLangPrintf(stdout
,
2119 _("printer %s/%s now printing %s-%d. "
2120 "enabled since %s\n"),
2121 printer
, dests
[i
].instance
, printer
, jobid
,
2122 printer_state_time
);
2124 case IPP_PRINTER_STOPPED
:
2125 _cupsLangPrintf(stdout
,
2126 _("printer %s/%s disabled since %s -\n"),
2127 printer
, dests
[i
].instance
,
2128 printer_state_time
);
2132 if ((message
&& *message
) || pstate
== IPP_PRINTER_STOPPED
)
2134 if (!message
|| !*message
)
2135 _cupsLangPuts(stdout
, _("\treason unknown\n"));
2137 _cupsLangPrintf(stdout
, "\t%s\n", message
);
2140 if (long_status
> 1)
2141 _cupsLangPuts(stdout
,
2142 _("\tForm mounted:\n"
2143 "\tContent types: any\n"
2144 "\tPrinter types: unknown\n"));
2148 _cupsLangPrintf(stdout
, _("\tDescription: %s\n"),
2149 description
? description
: "");
2153 _cupsLangPuts(stdout
, _("\tAlerts:"));
2154 for (j
= 0; j
< reasons
->num_values
; j
++)
2155 _cupsLangPrintf(stdout
, " %s",
2156 reasons
->values
[j
].string
.text
);
2157 _cupsLangPuts(stdout
, "\n");
2160 if (long_status
> 1)
2162 _cupsLangPrintf(stdout
, _("\tLocation: %s\n"),
2163 location
? location
: "");
2165 if (ptype
& CUPS_PRINTER_REMOTE
)
2167 _cupsLangPuts(stdout
, _("\tConnection: remote\n"));
2169 if (make_model
&& !strstr(make_model
, "System V Printer") &&
2170 !strstr(make_model
, "Raw Printer") && uri
)
2171 _cupsLangPrintf(stdout
, _("\tInterface: %s.ppd\n"),
2176 _cupsLangPuts(stdout
, _("\tConnection: direct\n"));
2178 if (make_model
&& strstr(make_model
, "System V Printer"))
2179 _cupsLangPrintf(stdout
,
2180 _("\tInterface: %s/interfaces/%s\n"),
2182 else if (make_model
&& !strstr(make_model
, "Raw Printer"))
2183 _cupsLangPrintf(stdout
,
2184 _("\tInterface: %s/ppd/%s.ppd\n"), root
, printer
);
2186 _cupsLangPuts(stdout
, _("\tOn fault: no alert\n"));
2187 _cupsLangPuts(stdout
, _("\tAfter fault: continue\n"));
2188 /* TODO update to use printer-error-policy */
2191 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2192 for (j
= 0; j
< allowed
->num_values
; j
++)
2193 _cupsLangPrintf(stdout
, "\t\t%s\n",
2194 allowed
->values
[j
].string
.text
);
2198 _cupsLangPuts(stdout
, _("\tUsers denied:\n"));
2199 for (j
= 0; j
< denied
->num_values
; j
++)
2200 _cupsLangPrintf(stdout
, "\t\t%s\n",
2201 denied
->values
[j
].string
.text
);
2205 _cupsLangPuts(stdout
, _("\tUsers allowed:\n"));
2206 _cupsLangPuts(stdout
, _("\t\t(all)\n"));
2208 _cupsLangPuts(stdout
, _("\tForms allowed:\n"));
2209 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2210 _cupsLangPuts(stdout
, _("\tBanner required\n"));
2211 _cupsLangPuts(stdout
, _("\tCharset sets:\n"));
2212 _cupsLangPuts(stdout
, _("\t\t(none)\n"));
2213 _cupsLangPuts(stdout
, _("\tDefault pitch:\n"));
2214 _cupsLangPuts(stdout
, _("\tDefault page size:\n"));
2215 _cupsLangPuts(stdout
, _("\tDefault port settings:\n"));
2224 ippDelete(response
);
2228 _cupsLangPrintf(stderr
, "lpstat: %s\n", cupsLastErrorString());
2237 * 'show_scheduler()' - Show scheduler status.
2241 show_scheduler(http_t
*http
) /* I - HTTP connection to server */
2244 _cupsLangPuts(stdout
, _("scheduler is running\n"));
2246 _cupsLangPuts(stdout
, _("scheduler is not running\n"));
2251 * End of "$Id: lpstat.c 6073 2006-11-02 20:01:54Z mike $".