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 /* 238534SSonam.Gupta@Sun.COM * Copyright 2009 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" 429669SGowtham.Thommandra@Sun.COM #include "lp.h" 432264Sjacobs 442264Sjacobs static void 452264Sjacobs usage(char *program) 462264Sjacobs { 472264Sjacobs char *name; 482264Sjacobs 492264Sjacobs if ((name = strrchr(program, '/')) == NULL) 502264Sjacobs name = program; 512264Sjacobs else 522264Sjacobs name++; 532264Sjacobs 542264Sjacobs fprintf(stdout, gettext("Usage: %s [-d] [-r] [-s] [-t] [-a [list]] " 558962SSonam.Gupta@Sun.COM "[-c [list]] [-o [list] [-l]] [-R [list] [-l]] " 568962SSonam.Gupta@Sun.COM "[-p [list] [-D] [-l]] [-v [list]] [-S [list] [-l]] " 578962SSonam.Gupta@Sun.COM "[-f [list] [-l]] [-u list]\n"), 588962SSonam.Gupta@Sun.COM name); 592264Sjacobs exit(1); 602264Sjacobs } 612264Sjacobs 622264Sjacobs static char * 632264Sjacobs nctime(time_t *t) 642264Sjacobs { 652264Sjacobs static char buf[64]; 662264Sjacobs struct tm *tm = localtime(t); 672264Sjacobs 682264Sjacobs (void) strftime(buf, sizeof (buf), "%c", tm); 692264Sjacobs 702264Sjacobs return (buf); 712264Sjacobs } 722264Sjacobs 732264Sjacobs static char * 742264Sjacobs printer_name(papi_printer_t printer) 752264Sjacobs { 762264Sjacobs papi_attribute_t **attributes = papiPrinterGetAttributeList(printer); 772264Sjacobs char *result = NULL; 782264Sjacobs 792264Sjacobs if (attributes != NULL) 802264Sjacobs papiAttributeListGetString(attributes, NULL, 818962SSonam.Gupta@Sun.COM "printer-name", &result); 822264Sjacobs 832264Sjacobs return (result); 842264Sjacobs } 852264Sjacobs 862264Sjacobs static int 872264Sjacobs lpstat_default_printer(papi_encryption_t encryption) 882264Sjacobs { 892264Sjacobs papi_status_t status; 902264Sjacobs papi_service_t svc = NULL; 912264Sjacobs papi_printer_t p = NULL; 922264Sjacobs char *name = NULL; 932264Sjacobs 942264Sjacobs status = papiServiceCreate(&svc, NULL, NULL, NULL, cli_auth_callback, 958962SSonam.Gupta@Sun.COM encryption, NULL); 962264Sjacobs if (status == PAPI_OK) { 972264Sjacobs char *req[] = { "printer-name", NULL }; 982264Sjacobs 992264Sjacobs status = papiPrinterQuery(svc, DEFAULT_DEST, req, NULL, &p); 1002264Sjacobs if (p != NULL) 1012264Sjacobs name = printer_name(p); 1022264Sjacobs } 1032264Sjacobs if (name != NULL) 1042264Sjacobs printf(gettext("system default printer: %s\n"), name); 1052264Sjacobs else 1062264Sjacobs printf(gettext("no system default destination\n")); 1072264Sjacobs papiPrinterFree(p); 1082264Sjacobs papiServiceDestroy(svc); 1092264Sjacobs 1102264Sjacobs return (0); 1112264Sjacobs } 1122264Sjacobs 1132264Sjacobs static int 1142264Sjacobs lpstat_service_status(papi_encryption_t encryption) 1152264Sjacobs { 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, 1268962SSonam.Gupta@Sun.COM encryption, NULL); 1272264Sjacobs if (status != PAPI_OK) { 1282264Sjacobs printf(gettext("scheduler is not running\n")); 1292264Sjacobs } else 1302264Sjacobs printf(gettext("scheduler is running\n")); 1312264Sjacobs papiServiceDestroy(svc); 1322264Sjacobs 1339852SGowtham.Thommandra@Sun.COM return (0); 1342264Sjacobs } 1352264Sjacobs 1362264Sjacobs static char * 1372264Sjacobs get_device_uri(papi_service_t svc, char *name) 1382264Sjacobs { 1392264Sjacobs papi_status_t status; 1402264Sjacobs papi_printer_t p = NULL; 1412264Sjacobs char *keys[] = { "device-uri", NULL }; 1422264Sjacobs char *result = NULL; 1432264Sjacobs 1442264Sjacobs status = papiPrinterQuery(svc, name, keys, NULL, &p); 1452264Sjacobs if ((status == PAPI_OK) && (p != NULL)) { 1462264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(p); 1472264Sjacobs 1482264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 1498962SSonam.Gupta@Sun.COM "device-uri", &result); 1502264Sjacobs if (result != NULL) 1512264Sjacobs result = strdup(result); 1522264Sjacobs 1532264Sjacobs papiPrinterFree(p); 1542264Sjacobs } 1552264Sjacobs 1562264Sjacobs return (result); 1572264Sjacobs } 1582264Sjacobs 1598534SSonam.Gupta@Sun.COM static void 1608534SSonam.Gupta@Sun.COM print_description(papi_attribute_t **list, char *printer_name) 1618534SSonam.Gupta@Sun.COM { 1628534SSonam.Gupta@Sun.COM char *str = ""; 1638534SSonam.Gupta@Sun.COM 1648534SSonam.Gupta@Sun.COM (void) papiAttributeListGetString(list, NULL, 1658534SSonam.Gupta@Sun.COM "printer-info", &str); 1668534SSonam.Gupta@Sun.COM 1678534SSonam.Gupta@Sun.COM /* 1688534SSonam.Gupta@Sun.COM * If no printer-info is read then 1698534SSonam.Gupta@Sun.COM * by default the printer-info is <printer-name>@<server> 1708534SSonam.Gupta@Sun.COM */ 1718534SSonam.Gupta@Sun.COM if (str[0] == '\0') { 1728534SSonam.Gupta@Sun.COM char *uri = NULL; 1738534SSonam.Gupta@Sun.COM uri_t *u = NULL; 1748534SSonam.Gupta@Sun.COM 1758534SSonam.Gupta@Sun.COM (void) papiAttributeListGetString(list, NULL, 1768534SSonam.Gupta@Sun.COM "printer-uri-supported", &uri); 1778534SSonam.Gupta@Sun.COM 1788534SSonam.Gupta@Sun.COM if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 1798534SSonam.Gupta@Sun.COM char *nodename = localhostname(); 1808534SSonam.Gupta@Sun.COM 1818534SSonam.Gupta@Sun.COM if ((u->host == NULL) || 1828534SSonam.Gupta@Sun.COM (strcasecmp(u->host, "localhost") == 0) || 1838534SSonam.Gupta@Sun.COM (strcasecmp(u->host, nodename) == 0)) 1848534SSonam.Gupta@Sun.COM printf(gettext("\tDescription:\n")); 1858534SSonam.Gupta@Sun.COM else 1868534SSonam.Gupta@Sun.COM printf(gettext("\tDescription: %s@%s\n"), 1878534SSonam.Gupta@Sun.COM printer_name, u->host); 1888534SSonam.Gupta@Sun.COM 1898534SSonam.Gupta@Sun.COM uri_free(u); 1908534SSonam.Gupta@Sun.COM } else 1918534SSonam.Gupta@Sun.COM printf(gettext("\tDescription:\n")); 1928534SSonam.Gupta@Sun.COM } else 1938534SSonam.Gupta@Sun.COM printf(gettext("\tDescription: %s\n"), str); 1948534SSonam.Gupta@Sun.COM } 1958534SSonam.Gupta@Sun.COM 1962264Sjacobs static char *report_device_keys[] = { "printer-name", "printer-uri-supported", 1972264Sjacobs NULL }; 1982264Sjacobs /* ARGSUSED2 */ 1992264Sjacobs static int 2002264Sjacobs report_device(papi_service_t svc, char *name, papi_printer_t printer, 2012264Sjacobs int verbose, int description) 2022264Sjacobs { 2032264Sjacobs papi_status_t status; 2042264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2052264Sjacobs char *uri = NULL; 2062264Sjacobs char *device = NULL; 2072264Sjacobs uri_t *u = NULL; 2082264Sjacobs 2092264Sjacobs if (name == NULL) { 2102264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2118962SSonam.Gupta@Sun.COM "printer-name", &name); 2122264Sjacobs if (status != PAPI_OK) 2132264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2148962SSonam.Gupta@Sun.COM "printer-uri-supported", &name); 2152264Sjacobs } 2162264Sjacobs 2172264Sjacobs if (name == NULL) 2182264Sjacobs return (-1); 2192264Sjacobs 2202264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 2218962SSonam.Gupta@Sun.COM "printer-uri-supported", &uri); 2222264Sjacobs 2232264Sjacobs if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 2242264Sjacobs char *nodename = localhostname(); 2252264Sjacobs 2262264Sjacobs if ((u->host == NULL) || 2272264Sjacobs (strcasecmp(u->host, "localhost") == 0) || 2282264Sjacobs (strcasecmp(u->host, nodename) == 0)) 2292264Sjacobs device = get_device_uri(svc, name); 2302264Sjacobs 2312264Sjacobs if (device != NULL) { 2322264Sjacobs printf(gettext("device for %s: %s\n"), name, device); 2332264Sjacobs return (0); 2342264Sjacobs } else if (uri != NULL) { 2352264Sjacobs printf(gettext("system for %s: %s (as %s)\n"), name, 2369411SKeerthi.Kondaka@Sun.COM u->host?u->host:"localhost", uri); 2372264Sjacobs return (0); 2382264Sjacobs } 2392264Sjacobs 2402264Sjacobs uri_free(u); 2412264Sjacobs } 2422264Sjacobs 2432264Sjacobs return (0); 2442264Sjacobs } 2452264Sjacobs 2462264Sjacobs static char *report_accepting_keys[] = { "printer-name", 2472264Sjacobs "printer-uri-supported", "printer-is-accepting-jobs", 2482264Sjacobs "printer-up-time", "printer-state-time", 2492264Sjacobs "lpsched-reject-date", "lpsched-reject-reason", NULL }; 2502264Sjacobs /* ARGSUSED2 */ 2512264Sjacobs static int 2522264Sjacobs report_accepting(papi_service_t svc, char *name, papi_printer_t printer, 2532264Sjacobs int verbose, int description) 2542264Sjacobs { 2552264Sjacobs papi_status_t status; 2562264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 2572264Sjacobs time_t curr; 2582264Sjacobs char boolean = PAPI_FALSE; 2592264Sjacobs 2602264Sjacobs if (name == NULL) { 2612264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2628962SSonam.Gupta@Sun.COM "printer-name", &name); 2632264Sjacobs if (status != PAPI_OK) 2642264Sjacobs status = papiAttributeListGetString(attrs, NULL, 2658962SSonam.Gupta@Sun.COM "printer-uri-supported", &name); 2662264Sjacobs } 2672264Sjacobs if (name == NULL) 2682264Sjacobs return (-1); 2692264Sjacobs 2702264Sjacobs (void) papiAttributeListGetBoolean(attrs, NULL, 2718962SSonam.Gupta@Sun.COM "printer-is-accepting-jobs", &boolean); 2722264Sjacobs (void) time(&curr); 2732264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2748962SSonam.Gupta@Sun.COM "printer-up-time", &curr); 2752264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2768962SSonam.Gupta@Sun.COM "printer-state-time", &curr); 2772264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 2788962SSonam.Gupta@Sun.COM "lpsched-reject-date", &curr); 2792264Sjacobs 2802264Sjacobs if (boolean == PAPI_TRUE) { 2812264Sjacobs printf(gettext("%s accepting requests since %s\n"), 2828962SSonam.Gupta@Sun.COM name, nctime(&curr)); 2832264Sjacobs } else { 2842264Sjacobs char *reason = "unknown reason"; 2852264Sjacobs 2862264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 2878962SSonam.Gupta@Sun.COM "lpsched-reject-reason", &reason); 2882264Sjacobs 2892264Sjacobs printf(gettext("%s not accepting requests since %s\n\t%s\n"), 2908962SSonam.Gupta@Sun.COM name, nctime(&curr), reason); 2912264Sjacobs } 2922264Sjacobs 2932264Sjacobs return (0); 2942264Sjacobs } 2952264Sjacobs 2962264Sjacobs static char *report_class_keys[] = { "printer-name", "printer-uri-supported", 2972264Sjacobs "member-names", NULL }; 2982264Sjacobs /* ARGSUSED2 */ 2992264Sjacobs static int 3002264Sjacobs report_class(papi_service_t svc, char *name, papi_printer_t printer, 3012264Sjacobs int verbose, int description) 3022264Sjacobs { 3032264Sjacobs papi_status_t status; 3042264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 3052264Sjacobs char *member = NULL; 3062264Sjacobs void *iter = NULL; 3072264Sjacobs 3082264Sjacobs status = papiAttributeListGetString(attrs, &iter, 3098962SSonam.Gupta@Sun.COM "member-names", &member); 3102264Sjacobs if (status == PAPI_NOT_FOUND) /* it's not a class */ 3112264Sjacobs return (0); 3122264Sjacobs 3132264Sjacobs if (name == NULL) { 3142264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3158962SSonam.Gupta@Sun.COM "printer-name", &name); 3162264Sjacobs if (status != PAPI_OK) 3172264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3188962SSonam.Gupta@Sun.COM "printer-uri-supported", &name); 3192264Sjacobs } 3202264Sjacobs if (name == NULL) 3212264Sjacobs return (-1); 3222264Sjacobs 3232264Sjacobs printf(gettext("members of class %s:\n\t%s\n"), name, member); 3242264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &member) 3258962SSonam.Gupta@Sun.COM == PAPI_OK) 3262264Sjacobs printf("\t%s\n", member); 3272264Sjacobs 3282264Sjacobs return (0); 3292264Sjacobs } 3302264Sjacobs 3319810SKeerthi.Kondaka@Sun.COM static int 3329810SKeerthi.Kondaka@Sun.COM get_remote_hostname(papi_attribute_t **attrs, char **host) 3339810SKeerthi.Kondaka@Sun.COM { 3349810SKeerthi.Kondaka@Sun.COM char *uri = NULL; 3359810SKeerthi.Kondaka@Sun.COM uri_t *u; 3369810SKeerthi.Kondaka@Sun.COM char *nodename; 3379810SKeerthi.Kondaka@Sun.COM 3389810SKeerthi.Kondaka@Sun.COM *host = NULL; 3399810SKeerthi.Kondaka@Sun.COM (void) papiAttributeListGetString(attrs, NULL, 3409810SKeerthi.Kondaka@Sun.COM "job-originating-host-name", host); 3419810SKeerthi.Kondaka@Sun.COM (void) papiAttributeListGetString(attrs, NULL, 3429810SKeerthi.Kondaka@Sun.COM "printer-uri-supported", &uri); 3439810SKeerthi.Kondaka@Sun.COM if (*host == NULL) { 3449810SKeerthi.Kondaka@Sun.COM if (uri != NULL) { 3459810SKeerthi.Kondaka@Sun.COM if (uri_from_string(uri, &u) == 0) { 3469810SKeerthi.Kondaka@Sun.COM if (u->host == NULL) { 3479810SKeerthi.Kondaka@Sun.COM uri_free(u); 3489810SKeerthi.Kondaka@Sun.COM return (0); 3499810SKeerthi.Kondaka@Sun.COM } 3509810SKeerthi.Kondaka@Sun.COM *host = strdup(u->host); 3519810SKeerthi.Kondaka@Sun.COM uri_free(u); 3529810SKeerthi.Kondaka@Sun.COM } else { 3539810SKeerthi.Kondaka@Sun.COM return (0); 3549810SKeerthi.Kondaka@Sun.COM } 3559810SKeerthi.Kondaka@Sun.COM } else { 3569810SKeerthi.Kondaka@Sun.COM return (0); 3579810SKeerthi.Kondaka@Sun.COM } 3589810SKeerthi.Kondaka@Sun.COM } 3599810SKeerthi.Kondaka@Sun.COM nodename = localhostname(); 3609810SKeerthi.Kondaka@Sun.COM if ((strcasecmp(*host, "localhost") == 0) || 3619810SKeerthi.Kondaka@Sun.COM (strcasecmp(*host, nodename) == 0)) { 3629810SKeerthi.Kondaka@Sun.COM return (0); 3639810SKeerthi.Kondaka@Sun.COM } 3649810SKeerthi.Kondaka@Sun.COM return (1); 3659810SKeerthi.Kondaka@Sun.COM } 3669810SKeerthi.Kondaka@Sun.COM 3672264Sjacobs static char *report_printer_keys[] = { "printer-name", 3682264Sjacobs "printer-uri-supported", "printer-state", 3692264Sjacobs "printer-up-time", "printer-state-time", 3702264Sjacobs "lpsched-disable-date", "printer-state-reasons", 3712264Sjacobs "lpsched-disable-reason", NULL }; 3722264Sjacobs /* ARGSUSED2 */ 3732264Sjacobs static int 3742264Sjacobs report_printer(papi_service_t svc, char *name, papi_printer_t printer, 3752264Sjacobs int verbose, int description) 3762264Sjacobs { 3772264Sjacobs papi_status_t status; 3782264Sjacobs papi_attribute_t **attrs = papiPrinterGetAttributeList(printer); 3792264Sjacobs time_t curr; 3802264Sjacobs int32_t pstat = 0; 3812264Sjacobs char *member = NULL; 3828962SSonam.Gupta@Sun.COM papi_job_t *j = NULL; 3832264Sjacobs 3842264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3858962SSonam.Gupta@Sun.COM "member-names", &member); 3862264Sjacobs if (status == PAPI_OK) /* it's a class */ 3872264Sjacobs return (0); 3882264Sjacobs 3892264Sjacobs if (name == NULL) { 3902264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3918962SSonam.Gupta@Sun.COM "printer-name", &name); 3922264Sjacobs if (status != PAPI_OK) 3932264Sjacobs status = papiAttributeListGetString(attrs, NULL, 3948962SSonam.Gupta@Sun.COM "printer-uri-supported", &name); 3952264Sjacobs } 3962264Sjacobs if (name == NULL) 3972264Sjacobs return (-1); 3982264Sjacobs 3992264Sjacobs printf(gettext("printer %s "), name); 4002264Sjacobs 4012264Sjacobs status = papiAttributeListGetInteger(attrs, NULL, 4028962SSonam.Gupta@Sun.COM "printer-state", &pstat); 4032264Sjacobs 4042264Sjacobs switch (pstat) { 4052264Sjacobs case 0x03: /* idle */ 4062264Sjacobs printf(gettext("idle. enabled")); 4072264Sjacobs break; 4088962SSonam.Gupta@Sun.COM case 0x04: /* processing */ 4098962SSonam.Gupta@Sun.COM status = papiPrinterListJobs(svc, name, NULL, 4108962SSonam.Gupta@Sun.COM 0, 0, &j); 4118962SSonam.Gupta@Sun.COM 4128962SSonam.Gupta@Sun.COM if (status == PAPI_OK) { 4138962SSonam.Gupta@Sun.COM if (j != NULL) { 4148962SSonam.Gupta@Sun.COM int i = 0; 4158962SSonam.Gupta@Sun.COM int32_t jobid = 0; 4168962SSonam.Gupta@Sun.COM int32_t jstate = 0; 4178962SSonam.Gupta@Sun.COM 4188962SSonam.Gupta@Sun.COM for (i = 0; j[i] != NULL; ++i) { 4199206SSonam.Gupta@Sun.COM papi_attribute_t **attr = 4209206SSonam.Gupta@Sun.COM papiJobGetAttributeList(j[i]); 4218962SSonam.Gupta@Sun.COM 4229206SSonam.Gupta@Sun.COM papiAttributeListGetInteger(attr, 4238962SSonam.Gupta@Sun.COM NULL, "job-state", &jstate); 4249206SSonam.Gupta@Sun.COM papiAttributeListGetInteger(attr, 4258962SSonam.Gupta@Sun.COM NULL, "job-id", &jobid); 426*10338SSonam.Gupta@Sun.COM /* 427*10338SSonam.Gupta@Sun.COM * For lpd protocol "job-id-requested" 428*10338SSonam.Gupta@Sun.COM * should be read. 429*10338SSonam.Gupta@Sun.COM */ 430*10338SSonam.Gupta@Sun.COM papiAttributeListGetInteger(attr, 431*10338SSonam.Gupta@Sun.COM NULL, "job-id-requested", &jobid); 4322264Sjacobs 4338962SSonam.Gupta@Sun.COM /* 434*10338SSonam.Gupta@Sun.COM * When lpd protocol is used job-state 435*10338SSonam.Gupta@Sun.COM * cannot be retrieved, therefore 436*10338SSonam.Gupta@Sun.COM * job-state will be 0. 437*10338SSonam.Gupta@Sun.COM * When ipp protocol is used, the 438*10338SSonam.Gupta@Sun.COM * active/printing job-state will be 439*10338SSonam.Gupta@Sun.COM * RS_PRINTING (0x0008) post s10u5. 440*10338SSonam.Gupta@Sun.COM * For pre-s10u5 job-state will be 441*10338SSonam.Gupta@Sun.COM * RS_ACTIVE (0x05). So print only when 442*10338SSonam.Gupta@Sun.COM * the job-state is RS_PRINTING (0x0008) 443*10338SSonam.Gupta@Sun.COM * or RS_ACTIVE (0x05) or 0 4448962SSonam.Gupta@Sun.COM */ 445*10338SSonam.Gupta@Sun.COM if ((jstate == 0x0008) || 446*10338SSonam.Gupta@Sun.COM (jstate == 0x05) || 447*10338SSonam.Gupta@Sun.COM (jstate == 0)) { 448*10338SSonam.Gupta@Sun.COM printf(gettext 449*10338SSonam.Gupta@Sun.COM ("now printing"\ 450*10338SSonam.Gupta@Sun.COM " %s-%d. enabled"), 451*10338SSonam.Gupta@Sun.COM name, jobid); 452*10338SSonam.Gupta@Sun.COM break; 4538962SSonam.Gupta@Sun.COM } 4548962SSonam.Gupta@Sun.COM } 4558962SSonam.Gupta@Sun.COM papiJobListFree(j); 4568962SSonam.Gupta@Sun.COM } 4572264Sjacobs } 4582264Sjacobs break; 4592264Sjacobs case 0x05: /* stopped */ 4602264Sjacobs printf(gettext("disabled")); 4612264Sjacobs break; 4622264Sjacobs default: 4632264Sjacobs printf(gettext("unknown state(0x%x)."), pstat); 4642264Sjacobs break; 4652264Sjacobs } 4662264Sjacobs 4672264Sjacobs (void) time(&curr); 4682264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 4698962SSonam.Gupta@Sun.COM "printer-up-time", &curr); 4702264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 4718962SSonam.Gupta@Sun.COM "printer-state-time", &curr); 4722264Sjacobs (void) papiAttributeListGetDatetime(attrs, NULL, 4738962SSonam.Gupta@Sun.COM "lpsched-disable-date", &curr); 4742264Sjacobs printf(gettext(" since %s. available.\n"), nctime(&curr)); 4752264Sjacobs 4762264Sjacobs if (pstat == 0x05) { 4772264Sjacobs char *reason = "unknown reason"; 4782264Sjacobs 4792264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4808962SSonam.Gupta@Sun.COM "printer-state-reasons", &reason); 4812264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 4828962SSonam.Gupta@Sun.COM "lpsched-disable-reason", &reason); 4832264Sjacobs printf(gettext("\t%s\n"), reason); 4842264Sjacobs } 4852264Sjacobs 4862264Sjacobs if (verbose == 1) { 4872264Sjacobs void *iter; 4882264Sjacobs char *str; 4899810SKeerthi.Kondaka@Sun.COM char *host = NULL; 4902264Sjacobs 4919810SKeerthi.Kondaka@Sun.COM if ((get_remote_hostname(attrs, &host)) != 0) { 4929810SKeerthi.Kondaka@Sun.COM (void) printf( 4939810SKeerthi.Kondaka@Sun.COM gettext("\tRemote Name: %s\n\tRemote Server: " 4949810SKeerthi.Kondaka@Sun.COM "%s\n"), name, host); 4959810SKeerthi.Kondaka@Sun.COM free(host); 4969810SKeerthi.Kondaka@Sun.COM return (0); 4979810SKeerthi.Kondaka@Sun.COM } 4982264Sjacobs str = ""; 4992264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5008962SSonam.Gupta@Sun.COM "form-ready", &str); 5012264Sjacobs printf(gettext("\tForm mounted: %s\n"), str); 5022264Sjacobs 5032264Sjacobs str = ""; 5042264Sjacobs iter = NULL; 5052264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5068962SSonam.Gupta@Sun.COM "document-format-supported", &str); 5072264Sjacobs printf(gettext("\tContent types: %s"), str); 5082264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, &str) 5098962SSonam.Gupta@Sun.COM == PAPI_OK) 5102264Sjacobs printf(", %s", str); 5112264Sjacobs printf("\n"); 5122264Sjacobs 5138534SSonam.Gupta@Sun.COM /* Display the printer description */ 5148534SSonam.Gupta@Sun.COM print_description(attrs, name); 5152264Sjacobs 5162264Sjacobs str = ""; 5176676Swendyp iter = NULL; 5186676Swendyp (void) papiAttributeListGetString(attrs, &iter, 5196676Swendyp "lpsched-printer-type", &str); 5206676Swendyp printf(gettext("\tPrinter types: %s"), str); 5216676Swendyp while (papiAttributeListGetString(attrs, &iter, NULL, &str) 5226676Swendyp == PAPI_OK) 5236676Swendyp printf(", %s", str); 5246676Swendyp printf("\n"); 5256676Swendyp 5266676Swendyp str = ""; 5272264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5288962SSonam.Gupta@Sun.COM "lpsched-dial-info", &str); 5292264Sjacobs printf(gettext("\tConnection: %s\n"), 5307653SJonathan.Ca@Sun.COM ((str[0] == '\0') ? gettext("direct") : str)); 5312264Sjacobs 5322264Sjacobs str = ""; 5332264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5348962SSonam.Gupta@Sun.COM "lpsched-interface-script", &str); 5352264Sjacobs printf(gettext("\tInterface: %s\n"), str); 5362264Sjacobs 5372264Sjacobs str = NULL; 5382264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5398962SSonam.Gupta@Sun.COM "ppd-file-uri", &str); 5402264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5418962SSonam.Gupta@Sun.COM "lpsched-ppd-source-path", &str); 5422264Sjacobs if (str != NULL) 5432264Sjacobs printf(gettext("\tPPD: %s\n"), str); 5442264Sjacobs 5452264Sjacobs str = NULL; 5462264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5478962SSonam.Gupta@Sun.COM "lpsched-fault-alert-command", &str); 5482264Sjacobs if (str != NULL) 5492264Sjacobs printf(gettext("\tOn fault: %s\n"), str); 5502264Sjacobs 5512264Sjacobs str = ""; 5522264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 5538962SSonam.Gupta@Sun.COM "lpsched-fault-recovery", &str); 5542264Sjacobs printf(gettext("\tAfter fault: %s\n"), 5558962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("continue") : str)); 5562264Sjacobs 5572264Sjacobs str = "(all)"; 5582264Sjacobs iter = NULL; 5592264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5608962SSonam.Gupta@Sun.COM "requesting-user-name-allowed", &str); 5612264Sjacobs printf(gettext("\tUsers allowed:\n\t\t%s\n"), 5628962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("(none)") : str)); 5632264Sjacobs if ((str != NULL) && (str[0] != '\0')) 5642264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 5658962SSonam.Gupta@Sun.COM &str) == PAPI_OK) 5662264Sjacobs printf("\t\t%s\n", str); 5672264Sjacobs 5682264Sjacobs str = NULL; 5692264Sjacobs iter = NULL; 5702264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5718962SSonam.Gupta@Sun.COM "requesting-user-name-denied", &str); 5722264Sjacobs if (str != NULL) { 5732264Sjacobs printf(gettext("\tUsers denied:\n\t\t%s\n"), 5748962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("(none)") : str)); 5752264Sjacobs if ((str != NULL) && (str[0] != '\0')) 5762264Sjacobs while (papiAttributeListGetString(attrs, &iter, 5778962SSonam.Gupta@Sun.COM NULL, &str) == PAPI_OK) 5782264Sjacobs printf("\t\t%s\n", str); 5792264Sjacobs } 5802264Sjacobs 5818238SSonam.Gupta@Sun.COM str = "none"; 5822264Sjacobs iter = NULL; 5832264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5848962SSonam.Gupta@Sun.COM "form-supported", &str); 5858238SSonam.Gupta@Sun.COM printf(gettext("\tForms allowed:\n\t\t(%s)\n"), 5868962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("none") : str)); 5872264Sjacobs if ((str != NULL) && (str[0] != '\0')) 5882264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 5898962SSonam.Gupta@Sun.COM &str) == PAPI_OK) 5908238SSonam.Gupta@Sun.COM printf("\t\t(%s)\n", str); 5912264Sjacobs 5922264Sjacobs str = ""; 5932264Sjacobs iter = NULL; 5942264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 5958962SSonam.Gupta@Sun.COM "media-supported", &str); 5962264Sjacobs printf(gettext("\tMedia supported:\n\t\t%s\n"), 5978962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("(none)") : str)); 5982264Sjacobs if ((str != NULL) && (str[0] != '\0')) 5992264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 6008962SSonam.Gupta@Sun.COM &str) == PAPI_OK) 6012264Sjacobs printf("\t\t%s\n", str); 6022264Sjacobs 6032264Sjacobs str = ""; 6042264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 6058962SSonam.Gupta@Sun.COM "job-sheets-supported", &str); 6066676Swendyp if ((strcasecmp(str, "none")) == 0) 6076676Swendyp str = gettext("page never printed"); 6086676Swendyp else if (strcasecmp(str, "optional") == 0) 6096676Swendyp str = gettext("not required"); 6106676Swendyp else 6116676Swendyp str = gettext("required"); 6126676Swendyp 6136676Swendyp printf(gettext("\tBanner %s\n"), str); 6146676Swendyp 6152264Sjacobs 6162264Sjacobs str = ""; 6172264Sjacobs iter = NULL; 6182264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 6198962SSonam.Gupta@Sun.COM "lpsched-print-wheels", &str); 6202264Sjacobs printf(gettext("\tCharacter sets:\n\t\t%s\n"), 6218962SSonam.Gupta@Sun.COM ((str[0] == '\0') ? gettext("(none)") : str)); 6222264Sjacobs if ((str != NULL) && (str[0] != '\0')) 6232264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 6248962SSonam.Gupta@Sun.COM &str) == PAPI_OK) 6252264Sjacobs printf("\t\t%s\n", str); 6262264Sjacobs 6272264Sjacobs printf(gettext("\tDefault pitch:\n")); 6282264Sjacobs printf(gettext("\tDefault page size:\n")); 6292264Sjacobs printf(gettext("\tDefault port setting:\n")); 6302264Sjacobs 6312264Sjacobs str = ""; 6322264Sjacobs iter = NULL; 6332264Sjacobs (void) papiAttributeListGetString(attrs, &iter, 6348962SSonam.Gupta@Sun.COM "lpsched-options", &str); 6352264Sjacobs if (str != NULL) { 6362264Sjacobs printf(gettext("\tOptions: %s"), str); 6372264Sjacobs while (papiAttributeListGetString(attrs, &iter, NULL, 6388962SSonam.Gupta@Sun.COM &str) == PAPI_OK) 6392264Sjacobs printf(", %s", str); 6402264Sjacobs printf("\n"); 6412264Sjacobs } 6422264Sjacobs 6438534SSonam.Gupta@Sun.COM } else if (description == 1) 6448534SSonam.Gupta@Sun.COM /* Display printer description */ 6458534SSonam.Gupta@Sun.COM print_description(attrs, name); 6468534SSonam.Gupta@Sun.COM else if (verbose > 1) 6472264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 6482264Sjacobs 6492264Sjacobs if (verbose > 0) 6502264Sjacobs printf("\n"); 6512264Sjacobs 6522264Sjacobs return (0); 6532264Sjacobs } 6542264Sjacobs 6552264Sjacobs static int 6562264Sjacobs printer_query(char *name, int (*report)(papi_service_t, char *, papi_printer_t, 6572264Sjacobs int, int), papi_encryption_t encryption, 6582264Sjacobs int verbose, int description) 6592264Sjacobs { 6609669SGowtham.Thommandra@Sun.COM int result = 0, i = 0; 6612264Sjacobs papi_status_t status; 6622264Sjacobs papi_service_t svc = NULL; 6639669SGowtham.Thommandra@Sun.COM char **list = getlist(name, LP_WS, LP_SEP); 6642264Sjacobs 6659669SGowtham.Thommandra@Sun.COM if (list == NULL) { 6669669SGowtham.Thommandra@Sun.COM list = (char **)malloc(sizeof (char *)); 6679669SGowtham.Thommandra@Sun.COM list[0] = name; 6682264Sjacobs } 6692264Sjacobs 6709669SGowtham.Thommandra@Sun.COM /* 6719669SGowtham.Thommandra@Sun.COM * The for loop executes once for every printer 6729669SGowtham.Thommandra@Sun.COM * entry in list. If list is NULL that implies 6739669SGowtham.Thommandra@Sun.COM * name is also NULL, the loop runs only one time. 6749669SGowtham.Thommandra@Sun.COM */ 6752264Sjacobs 6769669SGowtham.Thommandra@Sun.COM for (i = 0; name == NULL || list[i] != NULL; i++) { 6779669SGowtham.Thommandra@Sun.COM name = list[i]; 6782264Sjacobs 6799669SGowtham.Thommandra@Sun.COM status = papiServiceCreate(&svc, name, NULL, NULL, 6809669SGowtham.Thommandra@Sun.COM cli_auth_callback, encryption, NULL); 6812264Sjacobs if (status != PAPI_OK) { 6829669SGowtham.Thommandra@Sun.COM if (status == PAPI_NOT_FOUND) 6839669SGowtham.Thommandra@Sun.COM fprintf(stderr, 6849669SGowtham.Thommandra@Sun.COM gettext("%s: unknown printer\n"), 6859669SGowtham.Thommandra@Sun.COM name ? name : "(NULL)"); 6869669SGowtham.Thommandra@Sun.COM else 6879669SGowtham.Thommandra@Sun.COM fprintf(stderr, gettext( 6889669SGowtham.Thommandra@Sun.COM "Failed to contact service for %s: %s\n"), 6899669SGowtham.Thommandra@Sun.COM name ? name : "(NULL)", 6909669SGowtham.Thommandra@Sun.COM verbose_papi_message(svc, status)); 6912264Sjacobs papiServiceDestroy(svc); 6929669SGowtham.Thommandra@Sun.COM result--; 6939669SGowtham.Thommandra@Sun.COM continue; 6942264Sjacobs } 6952264Sjacobs 6969669SGowtham.Thommandra@Sun.COM if (name == NULL) { /* all */ 6979669SGowtham.Thommandra@Sun.COM char **interest = interest_list(svc); 6989669SGowtham.Thommandra@Sun.COM 6999669SGowtham.Thommandra@Sun.COM if (interest != NULL) { 7009669SGowtham.Thommandra@Sun.COM int i; 7019669SGowtham.Thommandra@Sun.COM 7029669SGowtham.Thommandra@Sun.COM for (i = 0; interest[i] != NULL; i++) 7039669SGowtham.Thommandra@Sun.COM result += printer_query(interest[i], 7049669SGowtham.Thommandra@Sun.COM report, encryption, verbose, 7059669SGowtham.Thommandra@Sun.COM description); 7069669SGowtham.Thommandra@Sun.COM } 7079669SGowtham.Thommandra@Sun.COM } else { 7089669SGowtham.Thommandra@Sun.COM papi_printer_t printer = NULL; 7099669SGowtham.Thommandra@Sun.COM char **keys = NULL; 7102264Sjacobs 7119669SGowtham.Thommandra@Sun.COM /* 7129669SGowtham.Thommandra@Sun.COM * Limit the query to only required data 7139669SGowtham.Thommandra@Sun.COM * to reduce the need to go remote for 7149669SGowtham.Thommandra@Sun.COM * information. 7159669SGowtham.Thommandra@Sun.COM */ 7169669SGowtham.Thommandra@Sun.COM if (report == report_device) 7179669SGowtham.Thommandra@Sun.COM keys = report_device_keys; 7189669SGowtham.Thommandra@Sun.COM else if (report == report_class) 7199669SGowtham.Thommandra@Sun.COM keys = report_class_keys; 7209669SGowtham.Thommandra@Sun.COM else if (report == report_accepting) 7219669SGowtham.Thommandra@Sun.COM keys = report_accepting_keys; 7229669SGowtham.Thommandra@Sun.COM else if ((report == report_printer) && (verbose == 0)) 7239669SGowtham.Thommandra@Sun.COM keys = report_printer_keys; 7249669SGowtham.Thommandra@Sun.COM 7259669SGowtham.Thommandra@Sun.COM status = papiPrinterQuery(svc, name, keys, 7269669SGowtham.Thommandra@Sun.COM NULL, &printer); 7279669SGowtham.Thommandra@Sun.COM if (status != PAPI_OK) { 7289669SGowtham.Thommandra@Sun.COM fprintf(stderr, gettext( 7299669SGowtham.Thommandra@Sun.COM "Failed to get printer info for %s: %s\n"), 7309669SGowtham.Thommandra@Sun.COM name, verbose_papi_message(svc, status)); 7319669SGowtham.Thommandra@Sun.COM papiServiceDestroy(svc); 7329669SGowtham.Thommandra@Sun.COM result--; 7339669SGowtham.Thommandra@Sun.COM continue; 7349669SGowtham.Thommandra@Sun.COM } 7359669SGowtham.Thommandra@Sun.COM 7369669SGowtham.Thommandra@Sun.COM if (printer != NULL) 7379669SGowtham.Thommandra@Sun.COM result += report(svc, name, printer, verbose, 7389669SGowtham.Thommandra@Sun.COM description); 7399669SGowtham.Thommandra@Sun.COM 7409669SGowtham.Thommandra@Sun.COM papiPrinterFree(printer); 7419669SGowtham.Thommandra@Sun.COM } 7429669SGowtham.Thommandra@Sun.COM 7439669SGowtham.Thommandra@Sun.COM papiServiceDestroy(svc); 7449669SGowtham.Thommandra@Sun.COM 7459669SGowtham.Thommandra@Sun.COM if (name == NULL) 7469669SGowtham.Thommandra@Sun.COM break; 7472264Sjacobs } 7482264Sjacobs 7499669SGowtham.Thommandra@Sun.COM freelist(list); 7502264Sjacobs 7512264Sjacobs return (result); 7522264Sjacobs } 7532264Sjacobs 7542264Sjacobs static int 7552264Sjacobs match_user(char *user, char **list) 7562264Sjacobs { 7572264Sjacobs int i; 7582264Sjacobs 7592264Sjacobs for (i = 0; list[i] != NULL; i++) { 7602264Sjacobs if (strcmp(user, list[i]) == 0) 7612264Sjacobs return (0); 7622264Sjacobs } 7632264Sjacobs 7642264Sjacobs return (-1); 7652264Sjacobs } 7662264Sjacobs 7672264Sjacobs static char **users = NULL; 7682264Sjacobs 7692264Sjacobs static int 7709256SSonam.Gupta@Sun.COM report_job(char *printer, papi_job_t job, int show_rank, int verbose) 7712264Sjacobs { 7722264Sjacobs papi_attribute_t **attrs = papiJobGetAttributeList(job); 7732264Sjacobs time_t clock = 0; 7742264Sjacobs char date[24]; 7752264Sjacobs char request[26]; 7762264Sjacobs char *user = "unknown"; 7778321SSonam.Gupta@Sun.COM char *host = NULL; 7782264Sjacobs int32_t size = 0; 7792264Sjacobs int32_t jstate = 0; 7808321SSonam.Gupta@Sun.COM char User[50]; 7812264Sjacobs 7822264Sjacobs char *destination = "unknown"; 7832264Sjacobs int32_t id = -1; 7849152SSonam.Gupta@Sun.COM static int check = 0; 7859152SSonam.Gupta@Sun.COM static char *uri = NULL; 7862264Sjacobs 7872264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 7888962SSonam.Gupta@Sun.COM "job-originating-user-name", &user); 7892264Sjacobs 7902264Sjacobs if ((users != NULL) && (match_user(user, users) < 0)) 7912264Sjacobs return (0); 7922264Sjacobs 7938321SSonam.Gupta@Sun.COM (void) papiAttributeListGetString(attrs, NULL, 7948321SSonam.Gupta@Sun.COM "job-originating-host-name", &host); 7958321SSonam.Gupta@Sun.COM 7969152SSonam.Gupta@Sun.COM if (check == 0) { 7979152SSonam.Gupta@Sun.COM /* 7989152SSonam.Gupta@Sun.COM * Read the attribute "job-printer-uri" 7999152SSonam.Gupta@Sun.COM * just once 8009152SSonam.Gupta@Sun.COM */ 8019152SSonam.Gupta@Sun.COM (void) papiAttributeListGetString(attrs, NULL, 8029152SSonam.Gupta@Sun.COM "job-printer-uri", &uri); 8039152SSonam.Gupta@Sun.COM check = 1; 8049152SSonam.Gupta@Sun.COM } 8059152SSonam.Gupta@Sun.COM 8069152SSonam.Gupta@Sun.COM if (host) { 8079152SSonam.Gupta@Sun.COM /* Check if it is local printer or remote printer */ 8089152SSonam.Gupta@Sun.COM uri_t *u = NULL; 8099152SSonam.Gupta@Sun.COM 8109152SSonam.Gupta@Sun.COM if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 8119152SSonam.Gupta@Sun.COM char *nodename = localhostname(); 8129152SSonam.Gupta@Sun.COM 8139152SSonam.Gupta@Sun.COM if ((u->host == NULL) || 8149152SSonam.Gupta@Sun.COM (strcasecmp(u->host, "localhost") == 0) || 8159152SSonam.Gupta@Sun.COM (strcasecmp(u->host, nodename) == 0)) { 8168321SSonam.Gupta@Sun.COM 8179152SSonam.Gupta@Sun.COM if (strcasecmp(host, nodename) == 0) { 8189152SSonam.Gupta@Sun.COM /* 8199152SSonam.Gupta@Sun.COM * Request submitted locally 8209152SSonam.Gupta@Sun.COM * for the local queue. 8219152SSonam.Gupta@Sun.COM * Hostname will not be displayed 8229152SSonam.Gupta@Sun.COM */ 8239152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s", 8249152SSonam.Gupta@Sun.COM user); 8259152SSonam.Gupta@Sun.COM } 8269152SSonam.Gupta@Sun.COM else 8279152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s@%s", 8289152SSonam.Gupta@Sun.COM user, host); 8299152SSonam.Gupta@Sun.COM } else if (uri != NULL) { 8309152SSonam.Gupta@Sun.COM /* 8319152SSonam.Gupta@Sun.COM * It's a remote printer. 8329152SSonam.Gupta@Sun.COM * In case of remote printers hostname is 8339152SSonam.Gupta@Sun.COM * always displayed. 8349152SSonam.Gupta@Sun.COM */ 8359152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s@%s", 8369152SSonam.Gupta@Sun.COM user, host); 8379152SSonam.Gupta@Sun.COM } 8389152SSonam.Gupta@Sun.COM uri_free(u); 8399152SSonam.Gupta@Sun.COM } else { 8409152SSonam.Gupta@Sun.COM /* 8419152SSonam.Gupta@Sun.COM * If attribute "job-printer-uri" 8429152SSonam.Gupta@Sun.COM * cannot be read 8439152SSonam.Gupta@Sun.COM * by default append the hostname 8449152SSonam.Gupta@Sun.COM */ 8459152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s@%s", user, host); 8469152SSonam.Gupta@Sun.COM } 8479152SSonam.Gupta@Sun.COM } else { 8489152SSonam.Gupta@Sun.COM /* 8499152SSonam.Gupta@Sun.COM * When print server is s10u4 and ipp service is used 8509152SSonam.Gupta@Sun.COM * "job-originating-hostname" attribute is not set 8519152SSonam.Gupta@Sun.COM * So get the host information from the uri 8529152SSonam.Gupta@Sun.COM */ 8539152SSonam.Gupta@Sun.COM uri_t *u = NULL; 8549152SSonam.Gupta@Sun.COM if ((uri != NULL) && (uri_from_string(uri, &u) == 0)) { 8559152SSonam.Gupta@Sun.COM if ((u != NULL) && (u->host != NULL)) 8569152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s@%s", 8579152SSonam.Gupta@Sun.COM user, u->host); 8589152SSonam.Gupta@Sun.COM else 8599152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s", user); 8609152SSonam.Gupta@Sun.COM 8619152SSonam.Gupta@Sun.COM uri_free(u); 8629152SSonam.Gupta@Sun.COM } else 8639152SSonam.Gupta@Sun.COM snprintf(User, sizeof (User), "%s", user); 8649152SSonam.Gupta@Sun.COM } 8652264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-k-octets", &size); 8662264Sjacobs size *= 1024; /* for the approximate byte size */ 8672264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, "job-octets", &size); 8682264Sjacobs 8692264Sjacobs (void) time(&clock); 8702264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 8718962SSonam.Gupta@Sun.COM "time-at-creation", (int32_t *)&clock); 8722264Sjacobs (void) strftime(date, sizeof (date), "%b %d %R", localtime(&clock)); 8732264Sjacobs 8742264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 8758962SSonam.Gupta@Sun.COM "job-printer-uri", &destination); 8762264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 8778962SSonam.Gupta@Sun.COM "printer-name", &destination); 8782264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 8798962SSonam.Gupta@Sun.COM "job-id", &id); 8809330SSonam.Gupta@Sun.COM (void) papiAttributeListGetInteger(attrs, NULL, 8819330SSonam.Gupta@Sun.COM "job-id-requested", &id); 8829256SSonam.Gupta@Sun.COM 8839331SSonam.Gupta@Sun.COM 8849256SSonam.Gupta@Sun.COM snprintf(request, sizeof (request), "%s-%d", printer, id); 8852264Sjacobs 8862264Sjacobs if (show_rank != 0) { 8872264Sjacobs int32_t rank = -1; 8882264Sjacobs 8892264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 8908962SSonam.Gupta@Sun.COM "number-of-intervening-jobs", &rank); 8912264Sjacobs rank++; 8922264Sjacobs 8932264Sjacobs printf("%3d %-21s %-14s %7ld %s", 8948321SSonam.Gupta@Sun.COM rank, request, User, size, date); 8952264Sjacobs } else 8968321SSonam.Gupta@Sun.COM printf("%-23s %-14s %7ld %s", request, User, size, date); 8972264Sjacobs 8982264Sjacobs (void) papiAttributeListGetInteger(attrs, NULL, 8998962SSonam.Gupta@Sun.COM "job-state", &jstate); 9009331SSonam.Gupta@Sun.COM 9019257SGowtham.Thommandra@Sun.COM if (jstate == 0x0001) 9029257SGowtham.Thommandra@Sun.COM printf(gettext(" being held")); 9039257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0800) 9049257SGowtham.Thommandra@Sun.COM printf(gettext(" notifying user")); 9059257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0040) 9069257SGowtham.Thommandra@Sun.COM printf(gettext(" cancelled")); 9079257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0010) 9089257SGowtham.Thommandra@Sun.COM printf(gettext(" finished printing")); 9099257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0008) 9109257SGowtham.Thommandra@Sun.COM printf(gettext(" on %s"), destination); 9119257SGowtham.Thommandra@Sun.COM else if (jstate == 0x2000) 9129257SGowtham.Thommandra@Sun.COM printf(gettext(" held by admin")); 9139257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0002) 9149257SGowtham.Thommandra@Sun.COM printf(gettext(" being filtered")); 9159257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0004) 9169257SGowtham.Thommandra@Sun.COM printf(gettext(" filtered")); 9179257SGowtham.Thommandra@Sun.COM else if (jstate == 0x0020) 9189257SGowtham.Thommandra@Sun.COM printf(gettext(" held for change")); 9192264Sjacobs 9202264Sjacobs if (verbose == 1) { 9213125Sjacobs char *form = NULL; 9223125Sjacobs 9232264Sjacobs (void) papiAttributeListGetString(attrs, NULL, 9248962SSonam.Gupta@Sun.COM "output-device-assigned", &destination); 9252264Sjacobs printf("\n\t assigned %s", destination); 9263127Sjacobs 9273125Sjacobs (void) papiAttributeListGetString(attrs, NULL, "form", &form); 9283125Sjacobs if (form != NULL) 9293125Sjacobs printf(", form %s", form); 9302264Sjacobs } else if (verbose > 1) { 9312264Sjacobs printf("\n"); 9322264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 9332264Sjacobs } 9342264Sjacobs 9352264Sjacobs printf("\n"); 9362264Sjacobs 9372264Sjacobs return (0); 9382264Sjacobs } 9392264Sjacobs 9402264Sjacobs static int 9419256SSonam.Gupta@Sun.COM job_query(char *request, int (*report)(char *, papi_job_t, int, int), 9422264Sjacobs papi_encryption_t encryption, int show_rank, int verbose) 9432264Sjacobs { 9442264Sjacobs int result = 0; 9452264Sjacobs papi_status_t status; 9462264Sjacobs papi_service_t svc = NULL; 9478295SSonam.Gupta@Sun.COM char *printer = request; 9482264Sjacobs int32_t id = -1; 9498295SSonam.Gupta@Sun.COM int flag1 = 0; 9508295SSonam.Gupta@Sun.COM int flag = 1; 9518295SSonam.Gupta@Sun.COM int print_flag = 0; 9522264Sjacobs 9538295SSonam.Gupta@Sun.COM do { 9548295SSonam.Gupta@Sun.COM status = papiServiceCreate(&svc, printer, NULL, NULL, 9558962SSonam.Gupta@Sun.COM cli_auth_callback, encryption, NULL); 9562264Sjacobs 9578295SSonam.Gupta@Sun.COM if ((status == PAPI_OK) && (printer != NULL)) 9588295SSonam.Gupta@Sun.COM print_flag = 1; 9592264Sjacobs 9608295SSonam.Gupta@Sun.COM /* <name>-# printer name does not exist */ 9618295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 9628295SSonam.Gupta@Sun.COM /* 9638295SSonam.Gupta@Sun.COM * Check if <name>-# is a request-id 9648295SSonam.Gupta@Sun.COM * Once this check is done flag1 is set 9658295SSonam.Gupta@Sun.COM */ 9668295SSonam.Gupta@Sun.COM if (flag1 == 1) 9678295SSonam.Gupta@Sun.COM break; 9688295SSonam.Gupta@Sun.COM 9698295SSonam.Gupta@Sun.COM get_printer_id(printer, &printer, &id); 9702264Sjacobs 9718295SSonam.Gupta@Sun.COM status = papiServiceCreate(&svc, printer, NULL, NULL, 9728962SSonam.Gupta@Sun.COM cli_auth_callback, encryption, NULL); 9732264Sjacobs 9748295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 9758295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 9768295SSonam.Gupta@Sun.COM "Failed to contact service for %s: %s\n"), 9778295SSonam.Gupta@Sun.COM (printer ? printer : "all"), 9788295SSonam.Gupta@Sun.COM verbose_papi_message(svc, status)); 9798295SSonam.Gupta@Sun.COM return (-1); 9808295SSonam.Gupta@Sun.COM } 9812264Sjacobs } 9822264Sjacobs 9838295SSonam.Gupta@Sun.COM if (printer == NULL) { /* all */ 9848295SSonam.Gupta@Sun.COM char **interest = interest_list(svc); 9858295SSonam.Gupta@Sun.COM 9868295SSonam.Gupta@Sun.COM if (interest != NULL) { 9878295SSonam.Gupta@Sun.COM int i; 9888295SSonam.Gupta@Sun.COM 9898295SSonam.Gupta@Sun.COM for (i = 0; interest[i] != NULL; i++) 9908295SSonam.Gupta@Sun.COM result += job_query(interest[i], report, 9918962SSonam.Gupta@Sun.COM encryption, show_rank, verbose); 9928295SSonam.Gupta@Sun.COM } 9938295SSonam.Gupta@Sun.COM } else if (id == -1) { /* a printer */ 9948295SSonam.Gupta@Sun.COM papi_job_t *jobs = NULL; 9958295SSonam.Gupta@Sun.COM 9968295SSonam.Gupta@Sun.COM status = papiPrinterListJobs(svc, printer, NULL, 9978962SSonam.Gupta@Sun.COM 0, 0, &jobs); 9988295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 9998295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 10008295SSonam.Gupta@Sun.COM "Failed to get job list: %s\n"), 10018295SSonam.Gupta@Sun.COM verbose_papi_message(svc, status)); 10028295SSonam.Gupta@Sun.COM papiServiceDestroy(svc); 10038295SSonam.Gupta@Sun.COM return (-1); 10048295SSonam.Gupta@Sun.COM } 10058295SSonam.Gupta@Sun.COM 10068295SSonam.Gupta@Sun.COM if (jobs != NULL) { 10078295SSonam.Gupta@Sun.COM int i; 10082264Sjacobs 10098295SSonam.Gupta@Sun.COM for (i = 0; jobs[i] != NULL; i++) 10109256SSonam.Gupta@Sun.COM result += report(printer, 10119256SSonam.Gupta@Sun.COM jobs[i], show_rank, 10129256SSonam.Gupta@Sun.COM verbose); 10138295SSonam.Gupta@Sun.COM } 10148295SSonam.Gupta@Sun.COM 10158295SSonam.Gupta@Sun.COM papiJobListFree(jobs); 10168295SSonam.Gupta@Sun.COM } else { /* a job */ 10178295SSonam.Gupta@Sun.COM papi_job_t job = NULL; 10189331SSonam.Gupta@Sun.COM int rid = id; 10198295SSonam.Gupta@Sun.COM 10208295SSonam.Gupta@Sun.COM /* Once a job has been found stop processing */ 10218295SSonam.Gupta@Sun.COM flag = 0; 10228295SSonam.Gupta@Sun.COM 10239331SSonam.Gupta@Sun.COM /* 10249331SSonam.Gupta@Sun.COM * Job-id could be the job-id requested 10259331SSonam.Gupta@Sun.COM * Check if it is job-id or job-id-requested 10269331SSonam.Gupta@Sun.COM */ 10279331SSonam.Gupta@Sun.COM id = job_to_be_queried(svc, printer, id); 10289331SSonam.Gupta@Sun.COM 10299331SSonam.Gupta@Sun.COM if (id > 0) 10309669SGowtham.Thommandra@Sun.COM status = papiJobQuery(svc, printer, id, 10319669SGowtham.Thommandra@Sun.COM NULL, &job); 10329331SSonam.Gupta@Sun.COM else 10339669SGowtham.Thommandra@Sun.COM status = papiJobQuery(svc, printer, rid, 10349669SGowtham.Thommandra@Sun.COM NULL, &job); 10359331SSonam.Gupta@Sun.COM 10368295SSonam.Gupta@Sun.COM if (status != PAPI_OK) { 10378295SSonam.Gupta@Sun.COM if (!print_flag) 10388295SSonam.Gupta@Sun.COM fprintf(stderr, gettext( 10398962SSonam.Gupta@Sun.COM "Failed to get job"\ 10408962SSonam.Gupta@Sun.COM " info for %s: %s\n"), 10418962SSonam.Gupta@Sun.COM request, 10428962SSonam.Gupta@Sun.COM verbose_papi_message(svc, status)); 10438295SSonam.Gupta@Sun.COM papiServiceDestroy(svc); 10448295SSonam.Gupta@Sun.COM return (-1); 10458295SSonam.Gupta@Sun.COM } 10468295SSonam.Gupta@Sun.COM 10478295SSonam.Gupta@Sun.COM if (job != NULL) 10489256SSonam.Gupta@Sun.COM result = report(printer, job, 10499256SSonam.Gupta@Sun.COM show_rank, verbose); 10508295SSonam.Gupta@Sun.COM 10518295SSonam.Gupta@Sun.COM papiJobFree(job); 10522264Sjacobs } 10532264Sjacobs 10548295SSonam.Gupta@Sun.COM if (flag) { 10558295SSonam.Gupta@Sun.COM id = -1; 10568295SSonam.Gupta@Sun.COM get_printer_id(printer, &printer, &id); 10578295SSonam.Gupta@Sun.COM if (id == -1) 10588295SSonam.Gupta@Sun.COM flag = 0; 10598295SSonam.Gupta@Sun.COM else 10608295SSonam.Gupta@Sun.COM flag1 = 1; 10612264Sjacobs } 10628295SSonam.Gupta@Sun.COM } while (flag); 10632264Sjacobs 10642264Sjacobs papiServiceDestroy(svc); 10652264Sjacobs 10662264Sjacobs return (result); 10672264Sjacobs } 10682264Sjacobs 10692264Sjacobs static int 10702264Sjacobs report_form(char *name, papi_attribute_t **attrs, int verbose) 10712264Sjacobs { 10722264Sjacobs papi_status_t status; 10732264Sjacobs char *form = NULL; 10742264Sjacobs void *iter = NULL; 10752264Sjacobs 10762264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 10778962SSonam.Gupta@Sun.COM "form-supported", &form); 10788962SSonam.Gupta@Sun.COM status == PAPI_OK; 10798962SSonam.Gupta@Sun.COM status = papiAttributeListGetString(attrs, &iter, 10808962SSonam.Gupta@Sun.COM NULL, &form)) { 10812264Sjacobs if ((name == NULL) || (strcmp(name, form) == 0)) { 10822264Sjacobs printf(gettext("form %s is available to you\n"), form); 10832264Sjacobs if (verbose != 0) { 10842264Sjacobs char *detail = NULL; 10852264Sjacobs status = papiAttributeListGetString(attrs, NULL, 10868962SSonam.Gupta@Sun.COM "form-supported-detail", &detail); 10872264Sjacobs if (status == PAPI_OK) 10882264Sjacobs printf("%s\n", detail); 10892264Sjacobs } 10902264Sjacobs } 10912264Sjacobs } 10922264Sjacobs 10932264Sjacobs return (0); 10942264Sjacobs } 10952264Sjacobs 10962264Sjacobs static int 10972264Sjacobs report_print_wheels(char *name, papi_attribute_t **attrs, int verbose) 10982264Sjacobs { 10992264Sjacobs papi_status_t status; 11002264Sjacobs char *pw = NULL; 11012264Sjacobs void *iter = NULL; 11022264Sjacobs 11032264Sjacobs for (status = papiAttributeListGetString(attrs, &iter, 11048962SSonam.Gupta@Sun.COM "pw-supported", &pw); 11058962SSonam.Gupta@Sun.COM status == PAPI_OK; 11068962SSonam.Gupta@Sun.COM status = papiAttributeListGetString(attrs, &iter, NULL, &pw)) { 11072264Sjacobs if ((name == NULL) || (strcmp(name, pw) == 0)) { 11082264Sjacobs printf(gettext("charset %s is available\n"), pw); 11092264Sjacobs if (verbose != 0) { 11102264Sjacobs char *info = NULL; 11112264Sjacobs status = papiAttributeListGetString(attrs, NULL, 11128962SSonam.Gupta@Sun.COM "pw-supported-extra", &info); 11132264Sjacobs if (status == PAPI_OK) 11142264Sjacobs printf("%s\n", info); 11152264Sjacobs } 11162264Sjacobs } 11172264Sjacobs } 11182264Sjacobs 11192264Sjacobs return (0); 11202264Sjacobs } 11212264Sjacobs 11222264Sjacobs static int 11232264Sjacobs service_query(char *name, int (*report)(char *, papi_attribute_t **, int), 11242264Sjacobs papi_encryption_t encryption, int verbose) 11252264Sjacobs { 11262264Sjacobs int result = 0; 11272264Sjacobs papi_status_t status; 11282264Sjacobs papi_service_t svc = NULL; 11292264Sjacobs papi_attribute_t **attrs = NULL; 11302264Sjacobs 11312264Sjacobs status = papiServiceCreate(&svc, name, NULL, NULL, cli_auth_callback, 11328962SSonam.Gupta@Sun.COM encryption, NULL); 11332264Sjacobs if (status != PAPI_OK) { 11342264Sjacobs papiServiceDestroy(svc); 11352264Sjacobs return (-1); 11362264Sjacobs } 11372264Sjacobs 11382264Sjacobs attrs = papiServiceGetAttributeList(svc); 11392264Sjacobs if (attrs != NULL) { 11402264Sjacobs result = report(name, attrs, verbose); 11412264Sjacobs 11422264Sjacobs if (verbose > 1) { 11432264Sjacobs printf("\n"); 11442264Sjacobs papiAttributeListPrint(stdout, attrs, "\t"); 11452264Sjacobs printf("\n"); 11462264Sjacobs } 11472264Sjacobs } 11482264Sjacobs 11492264Sjacobs papiServiceDestroy(svc); 11502264Sjacobs 11512264Sjacobs return (result); 11522264Sjacobs } 11532264Sjacobs 11542264Sjacobs int 11552264Sjacobs main(int ac, char *av[]) 11562264Sjacobs { 11572264Sjacobs int exit_code = 0; 11582264Sjacobs papi_encryption_t encryption = PAPI_ENCRYPT_NEVER; 11592264Sjacobs int rank = 0; 11602264Sjacobs int verbose = 0; 11612264Sjacobs int description = 0; 11622264Sjacobs int c; 11632264Sjacobs char **argv; 11642264Sjacobs 11652264Sjacobs (void) setlocale(LC_ALL, ""); 11662264Sjacobs (void) textdomain("SUNW_OST_OSCMD"); 11672264Sjacobs 11682264Sjacobs argv = (char **)calloc((ac + 1), sizeof (char *)); 11694286Swendyp for (c = 0; c < ac; c++) { 11704286Swendyp if ((av[c][0] == '-') && (av[c][1] == 'l') && 11718962SSonam.Gupta@Sun.COM (isalpha(av[c][2]) != 0)) { 11724286Swendyp /* preserve old "-l[po...]" behavior */ 11734286Swendyp argv[c] = &av[c][1]; 11744286Swendyp argv[c][0] = '-'; 11754286Swendyp verbose = 1; 11764286Swendyp 11774286Swendyp } else 11784286Swendyp argv[c] = av[c]; 11794286Swendyp } 11804286Swendyp 11812264Sjacobs argv[c++] = "--"; 11822264Sjacobs ac = c; 11832264Sjacobs 11842264Sjacobs /* preprocess argument list looking for '-l' or '-R' so it can trail */ 11859740SKeerthi.Kondaka@Sun.COM while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) { 11869740SKeerthi.Kondaka@Sun.COM switch (c) { /* these may or may not have an option */ 11879740SKeerthi.Kondaka@Sun.COM case 'a': 11889740SKeerthi.Kondaka@Sun.COM case 'c': 11899740SKeerthi.Kondaka@Sun.COM case 'p': 11909740SKeerthi.Kondaka@Sun.COM case 'o': 11919740SKeerthi.Kondaka@Sun.COM case 'R': 11929740SKeerthi.Kondaka@Sun.COM case 'u': 11939740SKeerthi.Kondaka@Sun.COM case 'v': 11949740SKeerthi.Kondaka@Sun.COM case 'l': 11959740SKeerthi.Kondaka@Sun.COM case 'f': 11969740SKeerthi.Kondaka@Sun.COM case 'S': 11979740SKeerthi.Kondaka@Sun.COM if (optarg[0] == '-') { 11989740SKeerthi.Kondaka@Sun.COM /* this check stop a possible infinite loop */ 11999740SKeerthi.Kondaka@Sun.COM if ((optind > 1) && (argv[optind-1][1] != c)) 12009740SKeerthi.Kondaka@Sun.COM optind--; 12019740SKeerthi.Kondaka@Sun.COM optarg = NULL; 12029740SKeerthi.Kondaka@Sun.COM } else if (strcmp(optarg, "all") == 0) 12039740SKeerthi.Kondaka@Sun.COM optarg = NULL; 12049740SKeerthi.Kondaka@Sun.COM } 12059740SKeerthi.Kondaka@Sun.COM 12062264Sjacobs switch (c) { 12072264Sjacobs case 'l': 12082264Sjacobs if ((optarg == NULL) || (optarg[0] == '-')) 12092264Sjacobs optarg = "1"; 12102264Sjacobs verbose = atoi(optarg); 12112264Sjacobs break; 12122264Sjacobs case 'D': 12132264Sjacobs description = 1; 12142264Sjacobs break; 12152264Sjacobs case 'R': 12162264Sjacobs rank = 1; 12172264Sjacobs break; 12182264Sjacobs case 'E': 12192264Sjacobs encryption = PAPI_ENCRYPT_REQUIRED; 12202264Sjacobs break; 12212264Sjacobs default: 12222264Sjacobs break; 12232264Sjacobs } 12249740SKeerthi.Kondaka@Sun.COM } 12252264Sjacobs optind = 1; 12262264Sjacobs 12272264Sjacobs /* process command line arguments */ 12282264Sjacobs while ((c = getopt(ac, argv, "LEDf:S:stc:p:a:drs:v:l:o:R:u:")) != EOF) { 12292264Sjacobs switch (c) { /* these may or may not have an option */ 12302264Sjacobs case 'a': 12312264Sjacobs case 'c': 12322264Sjacobs case 'p': 12332264Sjacobs case 'o': 12342264Sjacobs case 'R': 12352264Sjacobs case 'u': 12362264Sjacobs case 'v': 12372264Sjacobs case 'l': 12382264Sjacobs case 'f': 12392264Sjacobs case 'S': 12402264Sjacobs if (optarg[0] == '-') { 12412264Sjacobs /* this check stop a possible infinite loop */ 12422264Sjacobs if ((optind > 1) && (argv[optind-1][1] != c)) 12432264Sjacobs optind--; 12442264Sjacobs optarg = NULL; 12452264Sjacobs } else if (strcmp(optarg, "all") == 0) 12462264Sjacobs optarg = NULL; 12472264Sjacobs } 12482264Sjacobs 12492264Sjacobs switch (c) { 12502264Sjacobs case 'a': 12512264Sjacobs exit_code += printer_query(optarg, report_accepting, 12528962SSonam.Gupta@Sun.COM encryption, verbose, 0); 12532264Sjacobs break; 12542264Sjacobs case 'c': 12552264Sjacobs exit_code += printer_query(optarg, report_class, 12568962SSonam.Gupta@Sun.COM encryption, verbose, 0); 12572264Sjacobs break; 12582264Sjacobs case 'p': 12592264Sjacobs exit_code += printer_query(optarg, report_printer, 12608962SSonam.Gupta@Sun.COM encryption, verbose, description); 12612264Sjacobs break; 12622264Sjacobs case 'd': 12632264Sjacobs exit_code += lpstat_default_printer(encryption); 12642264Sjacobs break; 12652264Sjacobs case 'r': 12662264Sjacobs exit_code += lpstat_service_status(encryption); 12672264Sjacobs break; 12682264Sjacobs case 'u': 12692264Sjacobs if (optarg != NULL) 12702264Sjacobs users = strsplit(optarg, ", \n"); 12712264Sjacobs exit_code += job_query(NULL, report_job, 12728962SSonam.Gupta@Sun.COM encryption, rank, verbose); 12732264Sjacobs if (users != NULL) { 12742264Sjacobs free(users); 12752264Sjacobs users = NULL; 12762264Sjacobs } 12772264Sjacobs break; 12782264Sjacobs case 'v': 12792264Sjacobs exit_code += printer_query(optarg, report_device, 12808962SSonam.Gupta@Sun.COM encryption, verbose, 0); 12812264Sjacobs break; 12828604SGowtham.Thommandra@Sun.COM case 'R': /* set "rank" flag in first pass */ 12832264Sjacobs case 'o': 12842264Sjacobs exit_code += job_query(optarg, report_job, 12858962SSonam.Gupta@Sun.COM encryption, rank, verbose); 12862264Sjacobs break; 12872264Sjacobs case 'f': 12882264Sjacobs exit_code += service_query(optarg, report_form, 12898962SSonam.Gupta@Sun.COM encryption, verbose); 12902264Sjacobs break; 12912264Sjacobs case 'S': 12922264Sjacobs exit_code += service_query(optarg, report_print_wheels, 12938962SSonam.Gupta@Sun.COM encryption, verbose); 12942264Sjacobs break; 12952264Sjacobs case 's': 12962264Sjacobs exit_code += lpstat_service_status(encryption); 12972264Sjacobs exit_code += lpstat_default_printer(encryption); 12982264Sjacobs exit_code += printer_query(NULL, report_class, 12998962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13002264Sjacobs exit_code += printer_query(NULL, report_device, 13018962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13022264Sjacobs exit_code += service_query(optarg, report_form, 13038962SSonam.Gupta@Sun.COM encryption, verbose); 13042264Sjacobs exit_code += service_query(optarg, report_print_wheels, 13058962SSonam.Gupta@Sun.COM encryption, verbose); 13062264Sjacobs break; 13072264Sjacobs case 't': 13082264Sjacobs exit_code += lpstat_service_status(encryption); 13092264Sjacobs exit_code += lpstat_default_printer(encryption); 13102264Sjacobs exit_code += printer_query(NULL, report_class, 13118962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13122264Sjacobs exit_code += printer_query(NULL, report_device, 13138962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13142264Sjacobs exit_code += printer_query(NULL, report_accepting, 13158962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13162264Sjacobs exit_code += printer_query(NULL, report_printer, 13178962SSonam.Gupta@Sun.COM encryption, verbose, 0); 13182264Sjacobs exit_code += service_query(optarg, report_form, 13198962SSonam.Gupta@Sun.COM encryption, verbose); 13202264Sjacobs exit_code += service_query(optarg, report_print_wheels, 13218962SSonam.Gupta@Sun.COM encryption, verbose); 13222264Sjacobs exit_code += job_query(NULL, report_job, 13238962SSonam.Gupta@Sun.COM encryption, rank, verbose); 13242264Sjacobs break; 13252264Sjacobs case 'L': /* local-only, ignored */ 13262264Sjacobs case 'l': /* increased verbose level in first pass */ 13272264Sjacobs case 'D': /* set "description" flag in first pass */ 13282264Sjacobs case 'E': /* set encryption in the first pass */ 13292264Sjacobs break; 13302264Sjacobs default: 13312264Sjacobs usage(av[0]); 13322264Sjacobs } 13332264Sjacobs } 13342264Sjacobs ac--; 13352264Sjacobs 13362264Sjacobs if (ac == 1) { /* report on my jobs */ 13372264Sjacobs struct passwd *pw = getpwuid(getuid()); 13382264Sjacobs 13392264Sjacobs if (pw != NULL) 13402264Sjacobs users = strsplit(pw->pw_name, ""); 13412264Sjacobs exit_code += job_query(NULL, report_job, encryption, 13428962SSonam.Gupta@Sun.COM rank, verbose); 13432264Sjacobs if (users != NULL) { 13442264Sjacobs free(users); 13452264Sjacobs users = NULL; 13462264Sjacobs } 13472264Sjacobs } else { 13482264Sjacobs for (c = optind; c < ac; c++) 13492264Sjacobs exit_code += job_query(argv[c], report_job, encryption, 13508962SSonam.Gupta@Sun.COM rank, verbose); 13512264Sjacobs } 13522264Sjacobs 13532264Sjacobs 13542264Sjacobs if (exit_code != 0) 13552264Sjacobs exit_code = 1; 13562264Sjacobs 13572264Sjacobs return (exit_code); 13582264Sjacobs } 1359