12264Sjacobs /* 22264Sjacobs * CDDL HEADER START 32264Sjacobs * 42264Sjacobs * The contents of this file are subject to the terms of the 52264Sjacobs * Common Development and Distribution License (the "License"). 62264Sjacobs * You may not use this file except in compliance with the License. 72264Sjacobs * 82264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92264Sjacobs * or http://www.opensolaris.org/os/licensing. 102264Sjacobs * See the License for the specific language governing permissions 112264Sjacobs * and limitations under the License. 122264Sjacobs * 132264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 142264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 162264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 172264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 182264Sjacobs * 192264Sjacobs * CDDL HEADER END 202264Sjacobs */ 212264Sjacobs 222264Sjacobs /* 236676Swendyp * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 242264Sjacobs * Use is subject to license terms. 252264Sjacobs * 262264Sjacobs */ 272264Sjacobs 282264Sjacobs /* $Id: lpstat.c 173 2006-05-25 04:52:06Z njacobs $ */ 292264Sjacobs 302264Sjacobs 312264Sjacobs #include <stdio.h> 322264Sjacobs #include <stdlib.h> 332264Sjacobs #include <unistd.h> 342264Sjacobs #include <string.h> 352264Sjacobs #include <locale.h> 362264Sjacobs #include <libintl.h> 374286Swendyp #include <ctype.h> 382264Sjacobs #include <pwd.h> 392264Sjacobs #include <papi.h> 402264Sjacobs #include <uri.h> 412264Sjacobs #include "common.h" 422264Sjacobs 432264Sjacobs static void 442264Sjacobs usage(char *program) 452264Sjacobs { 462264Sjacobs char *name; 472264Sjacobs 482264Sjacobs if ((name = strrchr(program, '/')) == NULL) 492264Sjacobs name = program; 502264Sjacobs else 512264Sjacobs name++; 522264Sjacobs 532264Sjacobs fprintf(stdout, gettext("Usage: %s [-d] [-r] [-s] [-t] [-a [list]] " 542264Sjacobs "[-c [list]] [-o [list] [-l]] [-R [list] [-l]] " 552264Sjacobs "[-p [list] [-D] [-l]] [-v [list]] [-S [list] [-l]] " 562264Sjacobs "[-f [list] [-l]] [-u list]\n"), 572264Sjacobs name); 582264Sjacobs exit(1); 592264Sjacobs } 602264Sjacobs 612264Sjacobs static char * 622264Sjacobs nctime(time_t *t) 632264Sjacobs { 642264Sjacobs static char buf[64]; 652264Sjacobs struct tm *tm = localtime(t); 662264Sjacobs 672264Sjacobs (void) strftime(buf, sizeof (buf), "%c", tm); 682264Sjacobs 692264Sjacobs return (buf); 702264Sjacobs } 712264Sjacobs 722264Sjacobs static char * 732264Sjacobs printer_name(papi_printer_t printer) 742264Sjacobs { 752264Sjacobs papi_attribute_t **attributes = papiPrinterGetAttributeList(printer); 762264Sjacobs char *result = NULL; 772264Sjacobs 782264Sjacobs if (attributes != NULL) 792264Sjacobs papiAttributeListGetString(attributes, NULL, 802264Sjacobs "printer-name", &result); 812264Sjacobs 822264Sjacobs return (result); 832264Sjacobs } 842264Sjacobs 852264Sjacobs static int 862264Sjacobs lpstat_default_printer(papi_encryption_t encryption) 872264Sjacobs { 882264Sjacobs papi_status_t status; 892264Sjacobs papi_service_t svc = NULL; 902264Sjacobs papi_printer_t p = NULL; 912264Sjacobs char *name = NULL; 922264Sjacobs 932264Sjacobs status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, 942264Sjacobs encryption, NULL); 952264Sjacobs if (status == PAPI_OK) { 962264Sjacobs char *req[] = { "printer-name", NULL }; 972264Sjacobs 982264Sjacobs status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p); 992264Sjacobs if (p != NULL) 1002264Sjacobs name = printer_name(p); 1012264Sjacobs } 1022264Sjacobs if (name != NULL) 1032264Sjacobs printf(gettext("system default printer: %s\n"), name); 1042264Sjacobs else 1052264Sjacobs printf(gettext("no system default destination\n")); 1062264Sjacobs papiPrinterFree(p); 1072264Sjacobs papiServiceDestroy(svc); 1082264Sjacobs 1092264Sjacobs return (0); 1102264Sjacobs } 1112264Sjacobs 1122264Sjacobs static int 1132264Sjacobs lpstat_service_status(papi_encryption_t encryption) 1142264Sjacobs { 1152264Sjacobs int result = 0; 1162264Sjacobs papi_status_t status; 1172264Sjacobs papi_service_t svc = NULL; 1182264Sjacobs char *name = NULL; 1192264Sjacobs 1202264Sjacobs if (((name = getenv("PAPI_SERVICE_URI")) == NULL) && 1212264Sjacobs ((name = getenv("IPP_SERVER")) == NULL) && 1222264Sjacobs ((name = getenv("CUPS_SERVER")) == NULL)) 1232264Sjacobs name = DEFAULT_SERVICE_URI; 1242264Sjacobs 1252264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 1262264Sjacobs encryption, NULL); 1272264Sjacobs if (status != PAPI_OK) { 1282264Sjacobs printf(gettext("scheduler is not running\n")); 1292264Sjacobs result = -1; 1302264Sjacobs } else 1312264Sjacobs printf(gettext("scheduler is running\n")); 1322264Sjacobs papiServiceDestroy(svc); 1332264Sjacobs 1342264Sjacobs return (result); 1352264Sjacobs } 1362264Sjacobs 1372264Sjacobs static char * 1382264Sjacobs get_device_uri(papi_service_t svc, char *name) 1392264Sjacobs { 1402264Sjacobs papi_status_t status; 1412264Sjacobs papi_printer_t p = NULL; 1422264Sjacobs char *keys[] = { "device-uri", NULL }; 1432264Sjacobs char *result = NULL; 1442264Sjacobs 1452264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &p); 1462264Sjacobs if ((status == PAPI_OK) && (p != NULL)) { 1472264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(p); 1482264Sjacobs 1492264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 1502264Sjacobs "device-uri", &result); 1512264Sjacobs if (result != NULL) 1522264Sjacobs result = strdup(result); 1532264Sjacobs 1542264Sjacobs papiPrinterFree(p); 1552264Sjacobs } 1562264Sjacobs 1572264Sjacobs return (result); 1582264Sjacobs } 1592264Sjacobs 1602264Sjacobs static char *report_device_keys[] = { "printer-name", "printer-uri-supported", 1612264Sjacobs NULL }; 1622264Sjacobs /* ARGSUSED2 */ 1632264Sjacobs static int 1642264Sjacobs report_device(papi_service_t svc, char *name, papi_printer_t printer, 1652264Sjacobs int verbose, int description) 1662264Sjacobs { 1672264Sjacobs papi_status_t status; 1682264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 1692264Sjacobs char *uri = NULL; 1702264Sjacobs char *device = NULL; 1712264Sjacobs uri_t *u = NULL; 1722264Sjacobs 1732264Sjacobs if (name == NULL) { 1742264Sjacobs status = papiAttributeListGetString(attrs, NULL, 1752264Sjacobs "printer-name", &name); 1762264Sjacobs if (status != PAPI_OK) 1772264Sjacobs status = papiAttributeListGetString(attrs, NULL, 1782264Sjacobs "printer-uri-supported", &name); 1792264Sjacobs } 1802264Sjacobs 1812264Sjacobs if (name == NULL) 1822264Sjacobs return (-1); 1832264Sjacobs 1842264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 1852264Sjacobs "printer-uri-supported", &uri); 1862264Sjacobs 1872264Sjacobs if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 1882264Sjacobs char *nodename = localhostname(); 1892264Sjacobs 1902264Sjacobs if ((u->host == NULL) || 1912264Sjacobs (strcasecmp(u->host, "localhost") == 0) || 1922264Sjacobs (strcasecmp(u->host, nodename) == 0)) 1932264Sjacobs device = get_device_uri(svc, name); 1942264Sjacobs 1952264Sjacobs if (device != NULL) { 1962264Sjacobs printf(gettext("device for %s: %s\n"), name, device); 1972264Sjacobs return (0); 1982264Sjacobs } else if (uri != NULL) { 1992264Sjacobs printf(gettext("system for %s: %s (as %s)\n"), name, 2002264Sjacobs u->host, uri); 2012264Sjacobs return (0); 2022264Sjacobs } 2032264Sjacobs 2042264Sjacobs uri_free(u); 2052264Sjacobs } 2062264Sjacobs 2072264Sjacobs return (0); 2082264Sjacobs } 2092264Sjacobs 2102264Sjacobs static char *report_accepting_keys[] = { "printer-name", 2112264Sjacobs "printer-uri-supported", "printer-is-accepting-jobs", 2122264Sjacobs "printer-up-time", "printer-state-time", 2132264Sjacobs "lpsched-reject-date", "lpsched-reject-reason", NULL }; 2142264Sjacobs /* ARGSUSED2 */ 2152264Sjacobs static int 2162264Sjacobs report_accepting(papi_service_t svc, char *name, papi_printer_t printer, 2172264Sjacobs int verbose, int description) 2182264Sjacobs { 2192264Sjacobs papi_status_t status; 2202264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2212264Sjacobs time_t curr; 2222264Sjacobs char boolean = PAPI_FALSE; 2232264Sjacobs 2242264Sjacobs if (name == NULL) { 2252264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2262264Sjacobs "printer-name", &name); 2272264Sjacobs if (status != PAPI_OK) 2282264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2292264Sjacobs "printer-uri-supported", &name); 2302264Sjacobs } 2312264Sjacobs if (name == NULL) 2322264Sjacobs return (-1); 2332264Sjacobs 2342264Sjacobs (void) papiAttributeListGetBoolean(attrs, NULL, 2352264Sjacobs "printer-is-accepting-jobs", &boolean); 2362264Sjacobs (void) time(&curr); 2372264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2382264Sjacobs "printer-up-time", &curr); 2392264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2402264Sjacobs "printer-state-time", &curr); 2412264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2422264Sjacobs "lpsched-reject-date", &curr); 2432264Sjacobs 2442264Sjacobs if (boolean == PAPI_TRUE) { 2452264Sjacobs printf(gettext("%s accepting requests since %s\n"), 2462264Sjacobs name, nctime(&curr)); 2472264Sjacobs } else { 2482264Sjacobs char *reason = "unknown reason"; 2492264Sjacobs 2502264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 2512264Sjacobs "lpsched-reject-reason", &reason); 2522264Sjacobs 2532264Sjacobs printf(gettext("%s not accepting requests since %s\n\t%s\n"), 2542264Sjacobs name, nctime(&curr), reason); 2552264Sjacobs } 2562264Sjacobs 2572264Sjacobs return (0); 2582264Sjacobs } 2592264Sjacobs 2602264Sjacobs static char *report_class_keys[] = { "printer-name", "printer-uri-supported", 2612264Sjacobs "member-names", NULL }; 2622264Sjacobs /* ARGSUSED2 */ 2632264Sjacobs static int 2642264Sjacobs report_class(papi_service_t svc, char *name, papi_printer_t printer, 2652264Sjacobs int verbose, int description) 2662264Sjacobs { 2672264Sjacobs papi_status_t status; 2682264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2692264Sjacobs char *member = NULL; 2702264Sjacobs void *iter = NULL; 2712264Sjacobs 2722264Sjacobs status = papiAttributeListGetString(attrs, &iter, 2732264Sjacobs "member-names", &member); 2742264Sjacobs if (status == PAPI_NOT_FOUND) /* it's not a class */ 2752264Sjacobs return (0); 2762264Sjacobs 2772264Sjacobs if (name == NULL) { 2782264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2792264Sjacobs "printer-name", &name); 2802264Sjacobs if (status != PAPI_OK) 2812264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2822264Sjacobs "printer-uri-supported", &name); 2832264Sjacobs } 2842264Sjacobs if (name == NULL) 2852264Sjacobs return (-1); 2862264Sjacobs 2872264Sjacobs printf(gettext("members of class %s:\n\t%s\n"), name, member); 2882264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &member) 2892264Sjacobs == PAPI_OK) 2902264Sjacobs printf("\t%s\n", member); 2912264Sjacobs 2922264Sjacobs return (0); 2932264Sjacobs } 2942264Sjacobs 2952264Sjacobs static char *report_printer_keys[] = { "printer-name", 2962264Sjacobs "printer-uri-supported", "printer-state", 2972264Sjacobs "printer-up-time", "printer-state-time", 2982264Sjacobs "lpsched-disable-date", "printer-state-reasons", 2992264Sjacobs "lpsched-disable-reason", NULL }; 3002264Sjacobs /* ARGSUSED2 */ 3012264Sjacobs static int 3022264Sjacobs report_printer(papi_service_t svc, char *name, papi_printer_t printer, 3032264Sjacobs int verbose, int description) 3042264Sjacobs { 3052264Sjacobs papi_status_t status; 3062264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 3072264Sjacobs time_t curr; 3082264Sjacobs int32_t pstat = 0; 3092264Sjacobs char *member = NULL; 3102264Sjacobs 3112264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3122264Sjacobs "member-names", &member); 3132264Sjacobs if (status == PAPI_OK) /* it's a class */ 3142264Sjacobs return (0); 3152264Sjacobs 3162264Sjacobs if (name == NULL) { 3172264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3182264Sjacobs "printer-name", &name); 3192264Sjacobs if (status != PAPI_OK) 3202264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3212264Sjacobs "printer-uri-supported", &name); 3222264Sjacobs } 3232264Sjacobs if (name == NULL) 3242264Sjacobs return (-1); 3252264Sjacobs 3262264Sjacobs printf(gettext("printer %s "), name); 3272264Sjacobs 3282264Sjacobs status = papiAttributeListGetInteger(attrs, NULL, 3292264Sjacobs "printer-state", &pstat); 3302264Sjacobs 3312264Sjacobs switch (pstat) { 3322264Sjacobs case 0x03: /* idle */ 3332264Sjacobs printf(gettext("idle. enabled")); 3342264Sjacobs break; 3352264Sjacobs case 0x04: { /* processing */ 3362264Sjacobs char *requested[] = { "job-id", NULL }; 3372264Sjacobs papi_job_t *j = NULL; 3382264Sjacobs int32_t jobid = 0; 3392264Sjacobs 3402264Sjacobs (void) papiPrinterListJobs(svc, name, requested, 0, 1, &j); 3412264Sjacobs if ((j != NULL) && (j[0] != NULL)) 3422264Sjacobs jobid = papiJobGetId(j[0]); 3432264Sjacobs papiJobListFree(j); 3442264Sjacobs 3452264Sjacobs printf(gettext("now printing %s-%d. enabled"), name, jobid); 3462264Sjacobs } 3472264Sjacobs break; 3482264Sjacobs case 0x05: /* stopped */ 3492264Sjacobs printf(gettext("disabled")); 3502264Sjacobs break; 3512264Sjacobs default: 3522264Sjacobs printf(gettext("unknown state(0x%x)."), pstat); 3532264Sjacobs break; 3542264Sjacobs } 3552264Sjacobs 3562264Sjacobs (void) time(&curr); 3572264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3582264Sjacobs "printer-up-time", &curr); 3592264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3602264Sjacobs "printer-state-time", &curr); 3612264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 3622264Sjacobs "lpsched-disable-date", &curr); 3632264Sjacobs printf(gettext(" since %s. available.\n"), nctime(&curr)); 3642264Sjacobs 3652264Sjacobs if (pstat == 0x05) { 3662264Sjacobs char *reason = "unknown reason"; 3672264Sjacobs 3682264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3692264Sjacobs "printer-state-reasons", &reason); 3702264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3712264Sjacobs "lpsched-disable-reason", &reason); 3722264Sjacobs printf(gettext("\t%s\n"), reason); 3732264Sjacobs } 3742264Sjacobs 3752264Sjacobs if (verbose == 1) { 3762264Sjacobs void *iter; 3772264Sjacobs char *str; 3782264Sjacobs 3792264Sjacobs str = ""; 3802264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3812264Sjacobs "form-ready", &str); 3822264Sjacobs printf(gettext("\tForm mounted: %s\n"), str); 3832264Sjacobs 3842264Sjacobs str = ""; 3852264Sjacobs iter = NULL; 3862264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 3872264Sjacobs "document-format-supported", &str); 3882264Sjacobs printf(gettext("\tContent types: %s"), str); 3892264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &str) 3906679Swendyp == PAPI_OK) 3912264Sjacobs printf(", %s", str); 3922264Sjacobs printf("\n"); 3932264Sjacobs 3942264Sjacobs str = ""; 3952264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 3962264Sjacobs "printer-info", &str); 3972264Sjacobs printf(gettext("\tDescription: %s\n"), str); 3982264Sjacobs 3992264Sjacobs str = ""; 4006676Swendyp iter = NULL; 4016676Swendyp (void) papiAttributeListGetString(attrs, &iter, 4026676Swendyp "lpsched-printer-type", &str); 4036676Swendyp printf(gettext("\tPrinter types: %s"), str); 4046676Swendyp while (papiAttributeListGetString(attrs, &iter, NULL, &str) 4056676Swendyp == PAPI_OK) 4066676Swendyp printf(", %s", str); 4076676Swendyp printf("\n"); 4086676Swendyp 4096676Swendyp str = ""; 4102264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4112264Sjacobs "lpsched-dial-info", &str); 4122264Sjacobs printf(gettext("\tConnection: %s\n"), 4137653SJonathan.Ca@Sun.COM ((str[0] == '\0') ? gettext("direct") : str)); 4142264Sjacobs 4152264Sjacobs str = ""; 4162264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4172264Sjacobs "lpsched-interface-script", &str); 4182264Sjacobs printf(gettext("\tInterface: %s\n"), str); 4192264Sjacobs 4202264Sjacobs str = NULL; 4212264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4222264Sjacobs "ppd-file-uri", &str); 4232264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4242264Sjacobs "lpsched-ppd-source-path", &str); 4252264Sjacobs if (str != NULL) 4262264Sjacobs printf(gettext("\tPPD: %s\n"), str); 4272264Sjacobs 4282264Sjacobs str = NULL; 4292264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4302264Sjacobs "lpsched-fault-alert-command", &str); 4312264Sjacobs if (str != NULL) 4322264Sjacobs printf(gettext("\tOn fault: %s\n"), str); 4332264Sjacobs 4342264Sjacobs str = ""; 4352264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4362264Sjacobs "lpsched-fault-recovery", &str); 4372264Sjacobs printf(gettext("\tAfter fault: %s\n"), 4382264Sjacobs ((str[0] == '\0') ? gettext("continue") : str)); 4392264Sjacobs 4402264Sjacobs str = "(all)"; 4412264Sjacobs iter = NULL; 4422264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4432264Sjacobs "requesting-user-name-allowed", &str); 4442264Sjacobs printf(gettext("\tUsers allowed:\n\t\t%s\n"), 4452264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4462264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4472264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4482264Sjacobs &str) == PAPI_OK) 4492264Sjacobs printf("\t\t%s\n", str); 4502264Sjacobs 4512264Sjacobs str = NULL; 4522264Sjacobs iter = NULL; 4532264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4542264Sjacobs "requesting-user-name-denied", &str); 4552264Sjacobs if (str != NULL) { 4562264Sjacobs printf(gettext("\tUsers denied:\n\t\t%s\n"), 4572264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4582264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4592264Sjacobs while (papiAttributeListGetString(attrs, &iter, 4602264Sjacobs NULL, &str) == PAPI_OK) 4612264Sjacobs printf("\t\t%s\n", str); 4622264Sjacobs } 4632264Sjacobs 4648238SSonam.Gupta@Sun.COM str = "none"; 4652264Sjacobs iter = NULL; 4662264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4672264Sjacobs "form-supported", &str); 4688238SSonam.Gupta@Sun.COM printf(gettext("\tForms allowed:\n\t\t(%s)\n"), 4698238SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("none") : str)); 4702264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4712264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4722264Sjacobs &str) == PAPI_OK) 4738238SSonam.Gupta@Sun.COM printf("\t\t(%s)\n", str); 4742264Sjacobs 4752264Sjacobs str = ""; 4762264Sjacobs iter = NULL; 4772264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 4782264Sjacobs "media-supported", &str); 4792264Sjacobs printf(gettext("\tMedia supported:\n\t\t%s\n"), 4802264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 4812264Sjacobs if ((str != NULL) && (str[0] != '\0')) 4822264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 4832264Sjacobs &str) == PAPI_OK) 4842264Sjacobs printf("\t\t%s\n", str); 4852264Sjacobs 4862264Sjacobs str = ""; 4872264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4882264Sjacobs "job-sheets-supported", &str); 4896676Swendyp if ((strcasecmp(str, "none")) == 0) 4906676Swendyp str = gettext("page never printed"); 4916676Swendyp else if (strcasecmp(str, "optional") == 0) 4926676Swendyp str = gettext("not required"); 4936676Swendyp else 4946676Swendyp str = gettext("required"); 4956676Swendyp 4966676Swendyp printf(gettext("\tBanner %s\n"), str); 4976676Swendyp 4982264Sjacobs 4992264Sjacobs str = ""; 5002264Sjacobs iter = NULL; 5012264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5022264Sjacobs "lpsched-print-wheels", &str); 5032264Sjacobs printf(gettext("\tCharacter sets:\n\t\t%s\n"), 5042264Sjacobs ((str[0] == '\0') ? gettext("(none)") : str)); 5052264Sjacobs if ((str != NULL) && (str[0] != '\0')) 5062264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 5072264Sjacobs &str) == PAPI_OK) 5082264Sjacobs printf("\t\t%s\n", str); 5092264Sjacobs 5102264Sjacobs printf(gettext("\tDefault pitch:\n")); 5112264Sjacobs printf(gettext("\tDefault page size:\n")); 5122264Sjacobs printf(gettext("\tDefault port setting:\n")); 5132264Sjacobs 5142264Sjacobs str = ""; 5152264Sjacobs iter = NULL; 5162264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5172264Sjacobs "lpsched-options", &str); 5182264Sjacobs if (str != NULL) { 5192264Sjacobs printf(gettext("\tOptions: %s"), str); 5202264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 5212264Sjacobs &str) == PAPI_OK) 5222264Sjacobs printf(", %s", str); 5232264Sjacobs printf("\n"); 5242264Sjacobs } 5252264Sjacobs 5262264Sjacobs } else if (description == 1) { 5272264Sjacobs char *str = ""; 5282264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5292264Sjacobs "printer-description", &str); 5302264Sjacobs printf(gettext("\tDescription: %s\n"), str); 5312264Sjacobs } else if (verbose > 1) 5322264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 5332264Sjacobs 5342264Sjacobs if (verbose > 0) 5352264Sjacobs printf("\n"); 5362264Sjacobs 5372264Sjacobs return (0); 5382264Sjacobs } 5392264Sjacobs 5402264Sjacobs static int 5412264Sjacobs printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t, 5422264Sjacobs int, int), papi_encryption_t encryption, 5432264Sjacobs int verbose, int description) 5442264Sjacobs { 5452264Sjacobs int result = 0; 5462264Sjacobs papi_status_t status; 5472264Sjacobs papi_service_t svc = NULL; 5482264Sjacobs 5492264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 5502264Sjacobs encryption, NULL); 5512264Sjacobs if (status != PAPI_OK) { 5524062Sjacobs if (status == PAPI_NOT_FOUND) 5534062Sjacobs fprintf(stderr, gettext("%s: unknown printer\n"), 5544062Sjacobs name ? name : "(NULL)"); 5554062Sjacobs else 5564062Sjacobs fprintf(stderr, gettext( 5574062Sjacobs "Failed to contact service for %s: %s\n"), 5584062Sjacobs name ? name : "(NULL)", 5594062Sjacobs verbose_papi_message(svc, status)); 5602264Sjacobs papiServiceDestroy(svc); 5612264Sjacobs return (-1); 5622264Sjacobs } 5632264Sjacobs 5642264Sjacobs if (name == NULL) { /* all */ 5652264Sjacobs char **interest = interest_list(svc); 5662264Sjacobs 5672264Sjacobs if (interest != NULL) { 5682264Sjacobs int i; 5692264Sjacobs 5702264Sjacobs for (i = 0; interest[i] != NULL; i++) 5712264Sjacobs result += printer_query(interest[i], report, 5722264Sjacobs encryption, verbose, 5732264Sjacobs description); 5742264Sjacobs } 5752264Sjacobs } else { 5762264Sjacobs papi_printer_t printer = NULL; 5772264Sjacobs char **keys = NULL; 5782264Sjacobs 5792264Sjacobs /* 5802264Sjacobs * Limit the query to only required data to reduce the need 5812264Sjacobs * to go remote for information. 5822264Sjacobs */ 5832264Sjacobs if (report == report_device) 5842264Sjacobs keys = report_device_keys; 5852264Sjacobs else if (report == report_class) 5862264Sjacobs keys = report_class_keys; 5872264Sjacobs else if (report == report_accepting) 5882264Sjacobs keys = report_accepting_keys; 5892264Sjacobs else if ((report == report_printer) && (verbose == 0)) 5902264Sjacobs keys = report_printer_keys; 5912264Sjacobs 5922264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &printer); 5932264Sjacobs if (status != PAPI_OK) { 5942264Sjacobs fprintf(stderr, gettext( 5952264Sjacobs "Failed to get printer info for %s: %s\n"), 5962264Sjacobs name, verbose_papi_message(svc, status)); 5972264Sjacobs papiServiceDestroy(svc); 5982264Sjacobs return (-1); 5992264Sjacobs } 6002264Sjacobs 6012264Sjacobs if (printer != NULL) 6022264Sjacobs result = report(svc, name, printer, verbose, 6032264Sjacobs description); 6042264Sjacobs 6052264Sjacobs papiPrinterFree(printer); 6062264Sjacobs } 6072264Sjacobs 6082264Sjacobs papiServiceDestroy(svc); 6092264Sjacobs 6102264Sjacobs return (result); 6112264Sjacobs } 6122264Sjacobs 6132264Sjacobs static int 6142264Sjacobs match_user(char *user, char **list) 6152264Sjacobs { 6162264Sjacobs int i; 6172264Sjacobs 6182264Sjacobs for (i = 0; list[i] != NULL; i++) { 6192264Sjacobs if (strcmp(user, list[i]) == 0) 6202264Sjacobs return (0); 6212264Sjacobs } 6222264Sjacobs 6232264Sjacobs return (-1); 6242264Sjacobs } 6252264Sjacobs 6262264Sjacobs static char **users = NULL; 6272264Sjacobs 6282264Sjacobs static int 6292264Sjacobs report_job(papi_job_t job, int show_rank, int verbose) 6302264Sjacobs { 6312264Sjacobs papi_attribute_t **attrs = papiJobGetAttributeList(job); 6322264Sjacobs time_t clock = 0; 6332264Sjacobs char date[24]; 6342264Sjacobs char request[26]; 6352264Sjacobs char *user = "unknown"; 636*8321SSonam.Gupta@Sun.COM char *host = NULL; 6372264Sjacobs int32_t size = 0; 6382264Sjacobs int32_t jstate = 0; 639*8321SSonam.Gupta@Sun.COM char User[50]; 6402264Sjacobs 6412264Sjacobs char *destination = "unknown"; 6422264Sjacobs int32_t id = -1; 6432264Sjacobs 6442264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6452264Sjacobs "job-originating-user-name", &user); 6462264Sjacobs 6472264Sjacobs if ((users != NULL) && (match_user(user, users) < 0)) 6482264Sjacobs return (0); 6492264Sjacobs 650*8321SSonam.Gupta@Sun.COM (void) papiAttributeListGetString(attrs, NULL, 651*8321SSonam.Gupta@Sun.COM "job-originating-host-name", &host); 652*8321SSonam.Gupta@Sun.COM 653*8321SSonam.Gupta@Sun.COM if (host) 654*8321SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s@%s", user, host); 655*8321SSonam.Gupta@Sun.COM else 656*8321SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s", user); 657*8321SSonam.Gupta@Sun.COM 6582264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size); 6592264Sjacobs size *= 1024; /* for the approximate byte size */ 6602264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size); 6612264Sjacobs 6622264Sjacobs (void) time(&clock); 6632264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6642264Sjacobs "time-at-creation", (int32_t *)&clock); 6652264Sjacobs (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock)); 6662264Sjacobs 6672264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6682264Sjacobs "job-printer-uri", &destination); 6692264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6702264Sjacobs "printer-name", &destination); 6712264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6722264Sjacobs "job-id", &id); 6732264Sjacobs snprintf(request, sizeof (request), "%s-%d", destination, id); 6742264Sjacobs 6752264Sjacobs if (show_rank != 0) { 6762264Sjacobs int32_t rank = -1; 6772264Sjacobs 6782264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6792264Sjacobs "number-of-intervening-jobs", &rank); 6802264Sjacobs rank++; 6812264Sjacobs 6822264Sjacobs printf("%3d %-21s %-14s %7ld %s", 683*8321SSonam.Gupta@Sun.COM rank, request, User, size, date); 6842264Sjacobs } else 685*8321SSonam.Gupta@Sun.COM printf("%-23s %-14s %7ld %s", request, User, size, date); 6862264Sjacobs 6872264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 6882264Sjacobs "job-state", &jstate); 6892264Sjacobs if (jstate == 0x04) 6902264Sjacobs printf(gettext(", being held")); 6912264Sjacobs else if (jstate == 0x07) 6922264Sjacobs printf(gettext(", cancelled")); 6932264Sjacobs else if (jstate == 0x09) 6942264Sjacobs printf(gettext(", complete")); 6952264Sjacobs 6962264Sjacobs if (verbose == 1) { 6973125Sjacobs char *form = NULL; 6983125Sjacobs 6992264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 7002264Sjacobs "output-device-assigned", &destination); 7012264Sjacobs printf("\n\t assigned %s", destination); 7023127Sjacobs 7033125Sjacobs (void) papiAttributeListGetString(attrs, NULL, "form", &form); 7043125Sjacobs if (form != NULL) 7053125Sjacobs printf(", form %s", form); 7062264Sjacobs } else if (verbose > 1) { 7072264Sjacobs printf("\n"); 7082264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 7092264Sjacobs } 7102264Sjacobs 7112264Sjacobs printf("\n"); 7122264Sjacobs 7132264Sjacobs return (0); 7142264Sjacobs } 7152264Sjacobs 7162264Sjacobs static int 7172264Sjacobs job_query(char *request, int (*report)(papi_job_t, int, int), 7182264Sjacobs papi_encryption_t encryption, int show_rank, int verbose) 7192264Sjacobs { 7202264Sjacobs int result = 0; 7212264Sjacobs papi_status_t status; 7222264Sjacobs papi_service_t svc = NULL; 7238295SSonam.Gupta@Sun.COM char *printer = request; 7242264Sjacobs int32_t id = -1; 7258295SSonam.Gupta@Sun.COM int flag1 = 0; 7268295SSonam.Gupta@Sun.COM int flag = 1; 7278295SSonam.Gupta@Sun.COM int print_flag = 0; 7282264Sjacobs 7298295SSonam.Gupta@Sun.COM do { 7308295SSonam.Gupta@Sun.COM status = papiServiceCreate(&svc, printer, NULL, NULL, 7318295SSonam.Gupta@Sun.COM cli_auth_callback, encryption, NULL); 7322264Sjacobs 7338295SSonam.Gupta@Sun.COM if ((status == PAPI_OK) && (printer != NULL)) 7348295SSonam.Gupta@Sun.COM print_flag = 1; 7352264Sjacobs 7368295SSonam.Gupta@Sun.COM /* <name>-# printer name does not exist */ 7378295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 7388295SSonam.Gupta@Sun.COM /* 7398295SSonam.Gupta@Sun.COM * Check if <name>-# is a request-id 7408295SSonam.Gupta@Sun.COM * Once this check is done flag1 is set 7418295SSonam.Gupta@Sun.COM */ 7428295SSonam.Gupta@Sun.COM if (flag1 == 1) 7438295SSonam.Gupta@Sun.COM break; 7448295SSonam.Gupta@Sun.COM 7458295SSonam.Gupta@Sun.COM get_printer_id(printer, &printer, &id); 7462264Sjacobs 7478295SSonam.Gupta@Sun.COM status = papiServiceCreate(&svc, printer, NULL, NULL, 7488295SSonam.Gupta@Sun.COM cli_auth_callback, encryption, NULL); 7492264Sjacobs 7508295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 7518295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 7528295SSonam.Gupta@Sun.COM "Failed to contact service for %s: %s\n"), 7538295SSonam.Gupta@Sun.COM (printer ? printer : "all"), 7548295SSonam.Gupta@Sun.COM verbose_papi_message(svc, status)); 7558295SSonam.Gupta@Sun.COM return (-1); 7568295SSonam.Gupta@Sun.COM } 7572264Sjacobs } 7582264Sjacobs 7598295SSonam.Gupta@Sun.COM if (printer == NULL) { /* all */ 7608295SSonam.Gupta@Sun.COM char **interest = interest_list(svc); 7618295SSonam.Gupta@Sun.COM 7628295SSonam.Gupta@Sun.COM if (interest != NULL) { 7638295SSonam.Gupta@Sun.COM int i; 7648295SSonam.Gupta@Sun.COM 7658295SSonam.Gupta@Sun.COM for (i = 0; interest[i] != NULL; i++) 7668295SSonam.Gupta@Sun.COM result += job_query(interest[i], report, 7678295SSonam.Gupta@Sun.COM encryption, show_rank, verbose); 7688295SSonam.Gupta@Sun.COM } 7698295SSonam.Gupta@Sun.COM } else if (id == -1) { /* a printer */ 7708295SSonam.Gupta@Sun.COM papi_job_t *jobs = NULL; 7718295SSonam.Gupta@Sun.COM 7728295SSonam.Gupta@Sun.COM status = papiPrinterListJobs(svc, printer, NULL, 7738295SSonam.Gupta@Sun.COM 0, 0, &jobs); 7748295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 7758295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 7768295SSonam.Gupta@Sun.COM "Failed to get job list: %s\n"), 7778295SSonam.Gupta@Sun.COM verbose_papi_message(svc, status)); 7788295SSonam.Gupta@Sun.COM papiServiceDestroy(svc); 7798295SSonam.Gupta@Sun.COM return (-1); 7808295SSonam.Gupta@Sun.COM } 7818295SSonam.Gupta@Sun.COM 7828295SSonam.Gupta@Sun.COM if (jobs != NULL) { 7838295SSonam.Gupta@Sun.COM int i; 7842264Sjacobs 7858295SSonam.Gupta@Sun.COM for (i = 0; jobs[i] != NULL; i++) 7868295SSonam.Gupta@Sun.COM result += report(jobs[i], 7878295SSonam.Gupta@Sun.COM show_rank, verbose); 7888295SSonam.Gupta@Sun.COM } 7898295SSonam.Gupta@Sun.COM 7908295SSonam.Gupta@Sun.COM papiJobListFree(jobs); 7918295SSonam.Gupta@Sun.COM } else { /* a job */ 7928295SSonam.Gupta@Sun.COM papi_job_t job = NULL; 7938295SSonam.Gupta@Sun.COM 7948295SSonam.Gupta@Sun.COM /* Once a job has been found stop processing */ 7958295SSonam.Gupta@Sun.COM flag = 0; 7968295SSonam.Gupta@Sun.COM 7978295SSonam.Gupta@Sun.COM status = papiJobQuery(svc, printer, id, NULL, &job); 7988295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 7998295SSonam.Gupta@Sun.COM if (!print_flag) 8008295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 8018295SSonam.Gupta@Sun.COM "Failed to get job info for %s: %s\n"), 8028295SSonam.Gupta@Sun.COM request, verbose_papi_message(svc, status)); 8038295SSonam.Gupta@Sun.COM papiServiceDestroy(svc); 8048295SSonam.Gupta@Sun.COM return (-1); 8058295SSonam.Gupta@Sun.COM } 8068295SSonam.Gupta@Sun.COM 8078295SSonam.Gupta@Sun.COM if (job != NULL) 8088295SSonam.Gupta@Sun.COM result = report(job, show_rank, verbose); 8098295SSonam.Gupta@Sun.COM 8108295SSonam.Gupta@Sun.COM papiJobFree(job); 8112264Sjacobs } 8122264Sjacobs 8138295SSonam.Gupta@Sun.COM if (flag) { 8148295SSonam.Gupta@Sun.COM id = -1; 8158295SSonam.Gupta@Sun.COM get_printer_id(printer, &printer, &id); 8168295SSonam.Gupta@Sun.COM if (id == -1) 8178295SSonam.Gupta@Sun.COM flag = 0; 8188295SSonam.Gupta@Sun.COM else 8198295SSonam.Gupta@Sun.COM flag1 = 1; 8202264Sjacobs } 8218295SSonam.Gupta@Sun.COM } while (flag); 8222264Sjacobs 8232264Sjacobs papiServiceDestroy(svc); 8242264Sjacobs 8252264Sjacobs return (result); 8262264Sjacobs } 8272264Sjacobs 8282264Sjacobs static int 8292264Sjacobs report_form(char *name, papi_attribute_t **attrs, int verbose) 8302264Sjacobs { 8312264Sjacobs papi_status_t status; 8322264Sjacobs char *form = NULL; 8332264Sjacobs void *iter = NULL; 8342264Sjacobs 8352264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 8362264Sjacobs "form-supported", &form); 8372264Sjacobs status == PAPI_OK; 8382264Sjacobs status = papiAttributeListGetString(attrs, &iter, 8392264Sjacobs NULL, &form)) { 8402264Sjacobs if ((name == NULL) || (strcmp(name, form) == 0)) { 8412264Sjacobs printf(gettext("form %s is available to you\n"), form); 8422264Sjacobs if (verbose != 0) { 8432264Sjacobs char *detail = NULL; 8442264Sjacobs status = papiAttributeListGetString(attrs, NULL, 8452264Sjacobs "form-supported-detail", 8462264Sjacobs &detail); 8472264Sjacobs if (status == PAPI_OK) 8482264Sjacobs printf("%s\n", detail); 8492264Sjacobs } 8502264Sjacobs } 8512264Sjacobs } 8522264Sjacobs 8532264Sjacobs return (0); 8542264Sjacobs } 8552264Sjacobs 8562264Sjacobs static int 8572264Sjacobs report_print_wheels(char *name, papi_attribute_t **attrs, int verbose) 8582264Sjacobs { 8592264Sjacobs papi_status_t status; 8602264Sjacobs char *pw = NULL; 8612264Sjacobs void *iter = NULL; 8622264Sjacobs 8632264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 8642264Sjacobs "pw-supported", &pw); 8652264Sjacobs status == PAPI_OK; 8662264Sjacobs status = papiAttributeListGetString(attrs, &iter, NULL, &pw)) { 8672264Sjacobs if ((name == NULL) || (strcmp(name, pw) == 0)) { 8682264Sjacobs printf(gettext("charset %s is available\n"), pw); 8692264Sjacobs if (verbose != 0) { 8702264Sjacobs char *info = NULL; 8712264Sjacobs status = papiAttributeListGetString(attrs, NULL, 8722264Sjacobs "pw-supported-extra", &info); 8732264Sjacobs if (status == PAPI_OK) 8742264Sjacobs printf("%s\n", info); 8752264Sjacobs } 8762264Sjacobs } 8772264Sjacobs } 8782264Sjacobs 8792264Sjacobs return (0); 8802264Sjacobs } 8812264Sjacobs 8822264Sjacobs static int 8832264Sjacobs service_query(char *name, int (*report)(char *, papi_attribute_t **, int), 8842264Sjacobs papi_encryption_t encryption, int verbose) 8852264Sjacobs { 8862264Sjacobs int result = 0; 8872264Sjacobs papi_status_t status; 8882264Sjacobs papi_service_t svc = NULL; 8892264Sjacobs papi_attribute_t **attrs = NULL; 8902264Sjacobs 8912264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 8922264Sjacobs encryption, NULL); 8932264Sjacobs if (status != PAPI_OK) { 8942264Sjacobs papiServiceDestroy(svc); 8952264Sjacobs return (-1); 8962264Sjacobs } 8972264Sjacobs 8982264Sjacobs attrs = papiServiceGetAttributeList(svc); 8992264Sjacobs if (attrs != NULL) { 9002264Sjacobs result = report(name, attrs, verbose); 9012264Sjacobs 9022264Sjacobs if (verbose > 1) { 9032264Sjacobs printf("\n"); 9042264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 9052264Sjacobs printf("\n"); 9062264Sjacobs } 9072264Sjacobs } 9082264Sjacobs 9092264Sjacobs papiServiceDestroy(svc); 9102264Sjacobs 9112264Sjacobs return (result); 9122264Sjacobs } 9132264Sjacobs 9142264Sjacobs int 9152264Sjacobs main(int ac, char *av[]) 9162264Sjacobs { 9172264Sjacobs int exit_code = 0; 9182264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 9192264Sjacobs int rank = 0; 9202264Sjacobs int verbose = 0; 9212264Sjacobs int description = 0; 9222264Sjacobs int c; 9232264Sjacobs char **argv; 9242264Sjacobs 9252264Sjacobs (void) setlocale(LC_ALL, ""); 9262264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 9272264Sjacobs 9282264Sjacobs argv = (char **)calloc((ac + 1), sizeof (char *)); 9294286Swendyp for (c = 0; c < ac; c++) { 9304286Swendyp if ((av[c][0] == '-') && (av[c][1] == 'l') && 9314286Swendyp (isalpha(av[c][2]) != 0)) { 9324286Swendyp /* preserve old "-l[po...]" behavior */ 9334286Swendyp argv[c] = &av[c][1]; 9344286Swendyp argv[c][0] = '-'; 9354286Swendyp verbose = 1; 9364286Swendyp 9374286Swendyp } else 9384286Swendyp argv[c] = av[c]; 9394286Swendyp } 9404286Swendyp 9412264Sjacobs argv[c++] = "--"; 9422264Sjacobs ac = c; 9432264Sjacobs 9442264Sjacobs /* preprocess argument list looking for '-l' or '-R' so it can trail */ 9452264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) 9462264Sjacobs switch (c) { 9472264Sjacobs case 'l': 9482264Sjacobs if ((optarg == NULL) || (optarg[0] == '-')) 9492264Sjacobs optarg = "1"; 9502264Sjacobs verbose = atoi(optarg); 9512264Sjacobs break; 9522264Sjacobs case 'D': 9532264Sjacobs description = 1; 9542264Sjacobs break; 9552264Sjacobs case 'R': 9562264Sjacobs rank = 1; 9572264Sjacobs break; 9582264Sjacobs case 'E': 9592264Sjacobs encryption = PAPI_ENCRYPT_REQUIRED; 9602264Sjacobs break; 9612264Sjacobs default: 9622264Sjacobs break; 9632264Sjacobs } 9642264Sjacobs optind = 1; 9652264Sjacobs 9662264Sjacobs /* process command line arguments */ 9672264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) { 9682264Sjacobs switch (c) { /* these may or may not have an option */ 9692264Sjacobs case 'a': 9702264Sjacobs case 'c': 9712264Sjacobs case 'p': 9722264Sjacobs case 'o': 9732264Sjacobs case 'R': 9742264Sjacobs case 'u': 9752264Sjacobs case 'v': 9762264Sjacobs case 'l': 9772264Sjacobs case 'f': 9782264Sjacobs case 'S': 9792264Sjacobs if (optarg[0] == '-') { 9802264Sjacobs /* this check stop a possible infinite loop */ 9812264Sjacobs if ((optind > 1) && (argv[optind-1][1] != c)) 9822264Sjacobs optind--; 9832264Sjacobs optarg = NULL; 9842264Sjacobs } else if (strcmp(optarg, "all") == 0) 9852264Sjacobs optarg = NULL; 9862264Sjacobs } 9872264Sjacobs 9882264Sjacobs switch (c) { 9892264Sjacobs case 'a': 9902264Sjacobs exit_code += printer_query(optarg, report_accepting, 9912264Sjacobs encryption, verbose, 0); 9922264Sjacobs break; 9932264Sjacobs case 'c': 9942264Sjacobs exit_code += printer_query(optarg, report_class, 9952264Sjacobs encryption, verbose, 0); 9962264Sjacobs break; 9972264Sjacobs case 'p': 9982264Sjacobs exit_code += printer_query(optarg, report_printer, 9992264Sjacobs encryption, verbose, 10002264Sjacobs description); 10012264Sjacobs break; 10022264Sjacobs case 'd': 10032264Sjacobs exit_code += lpstat_default_printer(encryption); 10042264Sjacobs break; 10052264Sjacobs case 'r': 10062264Sjacobs exit_code += lpstat_service_status(encryption); 10072264Sjacobs break; 10082264Sjacobs case 'u': 10092264Sjacobs if (optarg != NULL) 10102264Sjacobs users = strsplit(optarg, ", \n"); 10112264Sjacobs exit_code += job_query(NULL, report_job, 10122264Sjacobs encryption, rank, verbose); 10132264Sjacobs if (users != NULL) { 10142264Sjacobs free(users); 10152264Sjacobs users = NULL; 10162264Sjacobs } 10172264Sjacobs break; 10182264Sjacobs case 'v': 10192264Sjacobs exit_code += printer_query(optarg, report_device, 10202264Sjacobs encryption, verbose, 0); 10212264Sjacobs break; 10222264Sjacobs case 'o': 10232264Sjacobs exit_code += job_query(optarg, report_job, 10242264Sjacobs encryption, rank, verbose); 10252264Sjacobs break; 10262264Sjacobs case 'f': 10272264Sjacobs exit_code += service_query(optarg, report_form, 10282264Sjacobs encryption, verbose); 10292264Sjacobs break; 10302264Sjacobs case 'S': 10312264Sjacobs exit_code += service_query(optarg, report_print_wheels, 10322264Sjacobs encryption, verbose); 10332264Sjacobs break; 10342264Sjacobs case 's': 10352264Sjacobs exit_code += lpstat_service_status(encryption); 10362264Sjacobs exit_code += lpstat_default_printer(encryption); 10372264Sjacobs exit_code += printer_query(NULL, report_class, 10382264Sjacobs encryption, verbose, 0); 10392264Sjacobs exit_code += printer_query(NULL, report_device, 10402264Sjacobs encryption, verbose, 0); 10412264Sjacobs exit_code += service_query(optarg, report_form, 10422264Sjacobs encryption, verbose); 10432264Sjacobs exit_code += service_query(optarg, report_print_wheels, 10442264Sjacobs encryption, verbose); 10452264Sjacobs break; 10462264Sjacobs case 't': 10472264Sjacobs exit_code += lpstat_service_status(encryption); 10482264Sjacobs exit_code += lpstat_default_printer(encryption); 10492264Sjacobs exit_code += printer_query(NULL, report_class, 10502264Sjacobs encryption, verbose, 0); 10512264Sjacobs exit_code += printer_query(NULL, report_device, 10522264Sjacobs encryption, verbose, 0); 10532264Sjacobs exit_code += printer_query(NULL, report_accepting, 10542264Sjacobs encryption, verbose, 0); 10552264Sjacobs exit_code += printer_query(NULL, report_printer, 10562264Sjacobs encryption, verbose, 0); 10572264Sjacobs exit_code += service_query(optarg, report_form, 10582264Sjacobs encryption, verbose); 10592264Sjacobs exit_code += service_query(optarg, report_print_wheels, 10602264Sjacobs encryption, verbose); 10612264Sjacobs exit_code += job_query(NULL, report_job, 10622264Sjacobs encryption, rank, verbose); 10632264Sjacobs break; 10642264Sjacobs case 'L': /* local-only, ignored */ 10652264Sjacobs case 'l': /* increased verbose level in first pass */ 10662264Sjacobs case 'D': /* set "description" flag in first pass */ 10672264Sjacobs case 'R': /* set "rank" flag in first pass */ 10682264Sjacobs case 'E': /* set encryption in the first pass */ 10692264Sjacobs break; 10702264Sjacobs default: 10712264Sjacobs usage(av[0]); 10722264Sjacobs } 10732264Sjacobs } 10742264Sjacobs ac--; 10752264Sjacobs 10762264Sjacobs if (ac == 1) { /* report on my jobs */ 10772264Sjacobs struct passwd *pw = getpwuid(getuid()); 10782264Sjacobs 10792264Sjacobs if (pw != NULL) 10802264Sjacobs users = strsplit(pw->pw_name, ""); 10812264Sjacobs exit_code += job_query(NULL, report_job, encryption, 10822264Sjacobs rank, verbose); 10832264Sjacobs if (users != NULL) { 10842264Sjacobs free(users); 10852264Sjacobs users = NULL; 10862264Sjacobs } 10872264Sjacobs } else { 10882264Sjacobs for (c = optind; c < ac; c++) 10892264Sjacobs exit_code += job_query(argv[c], report_job, encryption, 10902264Sjacobs rank, verbose); 10912264Sjacobs } 10922264Sjacobs 10932264Sjacobs 10942264Sjacobs if (exit_code != 0) 10952264Sjacobs exit_code = 1; 10962264Sjacobs 10972264Sjacobs return (exit_code); 10982264Sjacobs } 1099