lpstat.c revision 05eb9f24802bcc05bbb6e1ccdd8059b0b00f736b
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*
*/
/* $Id: lpstat.c 173 2006-05-25 04:52:06Z njacobs $ */
#pragma ident "%Z%%M% %I% %E% SMI"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <locale.h>
#include <libintl.h>
#include <ctype.h>
#include <pwd.h>
#include <papi.h>
#include <uri.h>
#include "common.h"
static void
{
char *name;
else
name++;
"[-c [list]] [-o [list] [-l]] [-R [list] [-l]] "
"[-p [list] [-D] [-l]] [-v [list]] [-S [list] [-l]] "
"[-f [list] [-l]] [-u list]\n"),
name);
exit(1);
}
static char *
{
static char buf[64];
return (buf);
}
static char *
{
if (attributes != NULL)
"printer-name", &result);
return (result);
}
static int
{
papi_printer_t p = NULL;
encryption, NULL);
if (p != NULL)
name = printer_name(p);
}
else
papiPrinterFree(p);
return (0);
}
static int
{
int result = 0;
encryption, NULL);
result = -1;
} else
return (result);
}
static char *
{
papi_printer_t p = NULL;
"device-uri", &result);
papiPrinterFree(p);
}
return (result);
}
NULL };
/* ARGSUSED2 */
static int
int verbose, int description)
{
"printer-name", &name);
"printer-uri-supported", &name);
}
return (-1);
"printer-uri-supported", &uri);
char *nodename = localhostname();
return (0);
return (0);
}
uri_free(u);
}
return (0);
}
static char *report_accepting_keys[] = { "printer-name",
"printer-uri-supported", "printer-is-accepting-jobs",
"printer-up-time", "printer-state-time",
/* ARGSUSED2 */
static int
int verbose, int description)
{
char boolean = PAPI_FALSE;
"printer-name", &name);
"printer-uri-supported", &name);
}
return (-1);
"printer-is-accepting-jobs", &boolean);
"printer-up-time", &curr);
"printer-state-time", &curr);
"lpsched-reject-date", &curr);
} else {
char *reason = "unknown reason";
"lpsched-reject-reason", &reason);
}
return (0);
}
"member-names", NULL };
/* ARGSUSED2 */
static int
int verbose, int description)
{
"member-names", &member);
return (0);
"printer-name", &name);
"printer-uri-supported", &name);
}
return (-1);
== PAPI_OK)
return (0);
}
static char *report_printer_keys[] = { "printer-name",
"printer-uri-supported", "printer-state",
"printer-up-time", "printer-state-time",
"lpsched-disable-date", "printer-state-reasons",
"lpsched-disable-reason", NULL };
/* ARGSUSED2 */
static int
int verbose, int description)
{
"member-names", &member);
return (0);
"printer-name", &name);
"printer-uri-supported", &name);
}
return (-1);
"printer-state", &pstat);
switch (pstat) {
case 0x03: /* idle */
break;
case 0x04: { /* processing */
papi_job_t *j = NULL;
jobid = papiJobGetId(j[0]);
papiJobListFree(j);
}
break;
case 0x05: /* stopped */
break;
default:
break;
}
"printer-up-time", &curr);
"printer-state-time", &curr);
"lpsched-disable-date", &curr);
if (pstat == 0x05) {
char *reason = "unknown reason";
"printer-state-reasons", &reason);
"lpsched-disable-reason", &reason);
}
if (verbose == 1) {
void *iter;
char *str;
str = "";
"form-ready", &str);
str = "";
"document-format-supported", &str);
== PAPI_OK)
printf("\n");
str = "";
"printer-info", &str);
str = "";
"lpsched-printer-type", &str);
== PAPI_OK)
printf("\n");
str = "";
"lpsched-dial-info", &str);
str = "";
"lpsched-interface-script", &str);
"ppd-file-uri", &str);
"lpsched-ppd-source-path", &str);
"lpsched-fault-alert-command", &str);
str = "";
"lpsched-fault-recovery", &str);
str = "(all)";
"requesting-user-name-allowed", &str);
"requesting-user-name-denied", &str);
}
str = "(none)";
"form-supported", &str);
str = "";
"media-supported", &str);
str = "";
"job-sheets-supported", &str);
else
str = "";
"lpsched-print-wheels", &str);
str = "";
"lpsched-options", &str);
printf("\n");
}
} else if (description == 1) {
char *str = "";
"printer-description", &str);
} else if (verbose > 1)
if (verbose > 0)
printf("\n");
return (0);
}
static int
int, int), papi_encryption_t encryption,
int verbose, int description)
{
int result = 0;
encryption, NULL);
if (status == PAPI_NOT_FOUND)
else
"Failed to contact service for %s: %s\n"),
return (-1);
}
int i;
}
} else {
/*
* Limit the query to only required data to reduce the need
* to go remote for information.
*/
if (report == report_device)
else if (report == report_class)
else if (report == report_accepting)
"Failed to get printer info for %s: %s\n"),
return (-1);
}
}
return (result);
}
static int
{
int i;
return (0);
}
return (-1);
}
static int
{
char date[24];
char request[26];
char *user = "unknown";
char *destination = "unknown";
"job-originating-user-name", &user);
return (0);
"job-printer-uri", &destination);
"printer-name", &destination);
"job-id", &id);
if (show_rank != 0) {
"number-of-intervening-jobs", &rank);
rank++;
printf("%3d %-21s %-14s %7ld %s",
} else
"job-state", &jstate);
if (jstate == 0x04)
else if (jstate == 0x07)
else if (jstate == 0x09)
if (verbose == 1) {
"output-device-assigned", &destination);
} else if (verbose > 1) {
printf("\n");
}
printf("\n");
return (0);
}
static int
{
int result = 0;
encryption, NULL);
"Failed to contact service for %s: %s\n"),
return (-1);
}
int i;
}
"Failed to get job list: %s\n"),
return (-1);
}
int i;
}
} else { /* a job */
"Failed to get job info for %s: %s\n"),
return (-1);
}
}
return (result);
}
static int
{
"form-supported", &form);
if (verbose != 0) {
"form-supported-detail",
&detail);
}
}
}
return (0);
}
static int
{
"pw-supported", &pw);
if (verbose != 0) {
"pw-supported-extra", &info);
}
}
}
return (0);
}
static int
{
int result = 0;
encryption, NULL);
return (-1);
}
if (verbose > 1) {
printf("\n");
printf("\n");
}
}
return (result);
}
int
{
int exit_code = 0;
int rank = 0;
int verbose = 0;
int description = 0;
int c;
char **argv;
(void) textdomain("SUNW_OST_OSCMD");
for (c = 0; c < ac; c++) {
/* preserve old "-l[po...]" behavior */
argv[c][0] = '-';
verbose = 1;
} else
}
argv[c++] = "--";
ac = c;
/* preprocess argument list looking for '-l' or '-R' so it can trail */
switch (c) {
case 'l':
optarg = "1";
break;
case 'D':
description = 1;
break;
case 'R':
rank = 1;
break;
case 'E':
break;
default:
break;
}
optind = 1;
/* process command line arguments */
switch (c) { /* these may or may not have an option */
case 'a':
case 'c':
case 'p':
case 'o':
case 'R':
case 'u':
case 'v':
case 'l':
case 'f':
case 'S':
if (optarg[0] == '-') {
/* this check stop a possible infinite loop */
optind--;
}
switch (c) {
case 'a':
encryption, verbose, 0);
break;
case 'c':
encryption, verbose, 0);
break;
case 'p':
break;
case 'd':
break;
case 'r':
break;
case 'u':
}
break;
case 'v':
encryption, verbose, 0);
break;
case 'o':
break;
case 'f':
break;
case 'S':
break;
case 's':
encryption, verbose, 0);
encryption, verbose, 0);
break;
case 't':
encryption, verbose, 0);
encryption, verbose, 0);
encryption, verbose, 0);
encryption, verbose, 0);
break;
case 'L': /* local-only, ignored */
case 'l': /* increased verbose level in first pass */
case 'D': /* set "description" flag in first pass */
case 'R': /* set "rank" flag in first pass */
case 'E': /* set encryption in the first pass */
break;
default:
}
}
ac--;
}
} else {
}
if (exit_code != 0)
exit_code = 1;
return (exit_code);
}