10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 51676Sjpk * Common Development and Distribution License (the "License"). 61676Sjpk * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*9257SGowtham.Thommandra@Sun.COM * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate 270Sstevel@tonic-gate /*LINTLIBRARY*/ 280Sstevel@tonic-gate 290Sstevel@tonic-gate #include <stdlib.h> 300Sstevel@tonic-gate #include <string.h> 310Sstevel@tonic-gate #include <libintl.h> 320Sstevel@tonic-gate #include <papi_impl.h> 330Sstevel@tonic-gate #include <lp.h> 340Sstevel@tonic-gate 350Sstevel@tonic-gate extern int isclass(char *); 360Sstevel@tonic-gate 370Sstevel@tonic-gate void 380Sstevel@tonic-gate papiPrinterFree(papi_printer_t printer) 390Sstevel@tonic-gate { 400Sstevel@tonic-gate printer_t *tmp = printer; 410Sstevel@tonic-gate 420Sstevel@tonic-gate if (tmp != NULL) { 430Sstevel@tonic-gate papiAttributeListFree(tmp->attributes); 440Sstevel@tonic-gate free(tmp); 450Sstevel@tonic-gate } 460Sstevel@tonic-gate } 470Sstevel@tonic-gate 480Sstevel@tonic-gate void 490Sstevel@tonic-gate papiPrinterListFree(papi_printer_t *printers) 500Sstevel@tonic-gate { 510Sstevel@tonic-gate if (printers != NULL) { 520Sstevel@tonic-gate int i; 530Sstevel@tonic-gate 540Sstevel@tonic-gate for (i = 0; printers[i] != NULL; i++) 550Sstevel@tonic-gate papiPrinterFree(printers[i]); 560Sstevel@tonic-gate free(printers); 570Sstevel@tonic-gate } 580Sstevel@tonic-gate } 590Sstevel@tonic-gate 600Sstevel@tonic-gate papi_status_t 612264Sjacobs papiPrintersList(papi_service_t handle, char **requested_attrs, 622264Sjacobs papi_filter_t *filter, papi_printer_t **printers) 630Sstevel@tonic-gate { 640Sstevel@tonic-gate service_t *svc = handle; 650Sstevel@tonic-gate printer_t *p = NULL; 660Sstevel@tonic-gate short status = MOK; 670Sstevel@tonic-gate char *printer = NULL, 68*9257SGowtham.Thommandra@Sun.COM *form = NULL, 69*9257SGowtham.Thommandra@Sun.COM *request_id = NULL, 70*9257SGowtham.Thommandra@Sun.COM *character_set = NULL, 71*9257SGowtham.Thommandra@Sun.COM *reject_reason = NULL, 72*9257SGowtham.Thommandra@Sun.COM *disable_reason = NULL; 730Sstevel@tonic-gate short printer_status = 0; 740Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 750Sstevel@tonic-gate 760Sstevel@tonic-gate if ((handle == NULL) || (printers == NULL)) 770Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 780Sstevel@tonic-gate 790Sstevel@tonic-gate if ((filter == NULL) || 800Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) == 810Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_LOCAL))) { 820Sstevel@tonic-gate /* ask the spooler for the printer(s) and state */ 830Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, NAME_ALL) < 0) 840Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 850Sstevel@tonic-gate 860Sstevel@tonic-gate do { 870Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, 88*9257SGowtham.Thommandra@Sun.COM &printer, &form, &character_set, 89*9257SGowtham.Thommandra@Sun.COM &disable_reason, &reject_reason, 90*9257SGowtham.Thommandra@Sun.COM &printer_status, &request_id, 91*9257SGowtham.Thommandra@Sun.COM &enable_date, &reject_date) < 0) 920Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 930Sstevel@tonic-gate 940Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 950Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 960Sstevel@tonic-gate 970Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(svc, p, 98*9257SGowtham.Thommandra@Sun.COM printer); 990Sstevel@tonic-gate 1000Sstevel@tonic-gate printer_status_to_attributes(p, printer, form, 101*9257SGowtham.Thommandra@Sun.COM character_set, disable_reason, 102*9257SGowtham.Thommandra@Sun.COM reject_reason, printer_status, 103*9257SGowtham.Thommandra@Sun.COM request_id, enable_date, reject_date); 1040Sstevel@tonic-gate 1050Sstevel@tonic-gate list_append(printers, p); 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate } while (status == MOKMORE); 1080Sstevel@tonic-gate } 1090Sstevel@tonic-gate 1100Sstevel@tonic-gate if ((filter == NULL) || 1110Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) == 1120Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_CLASS))) { 1130Sstevel@tonic-gate /* ask the spooler for the class(es) and state */ 1140Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, NAME_ALL) < 0) 1150Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1160Sstevel@tonic-gate 1170Sstevel@tonic-gate do { 1180Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &printer, 119*9257SGowtham.Thommandra@Sun.COM &printer_status, &reject_reason, 120*9257SGowtham.Thommandra@Sun.COM &reject_date) < 0) 1210Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1220Sstevel@tonic-gate 1230Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 1240Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate lpsched_class_configuration_to_attributes(svc, p, 127*9257SGowtham.Thommandra@Sun.COM printer); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate class_status_to_attributes(p, printer, printer_status, 130*9257SGowtham.Thommandra@Sun.COM reject_reason, reject_date); 1310Sstevel@tonic-gate 1320Sstevel@tonic-gate list_append(printers, p); 1330Sstevel@tonic-gate 1340Sstevel@tonic-gate } while (status == MOKMORE); 1350Sstevel@tonic-gate } 1360Sstevel@tonic-gate 1370Sstevel@tonic-gate return (PAPI_OK); 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate papi_status_t 1412264Sjacobs papiPrinterQuery(papi_service_t handle, char *name, 1422264Sjacobs char **requested_attrs, 1432264Sjacobs papi_attribute_t **job_attrs, 1440Sstevel@tonic-gate papi_printer_t *printer) 1450Sstevel@tonic-gate { 1460Sstevel@tonic-gate papi_status_t pst; 1470Sstevel@tonic-gate service_t *svc = handle; 1480Sstevel@tonic-gate printer_t *p = NULL; 1490Sstevel@tonic-gate char *dest; 1500Sstevel@tonic-gate short status = MOK; 1510Sstevel@tonic-gate char *pname = NULL, 152*9257SGowtham.Thommandra@Sun.COM *form = NULL, 153*9257SGowtham.Thommandra@Sun.COM *request_id = NULL, 154*9257SGowtham.Thommandra@Sun.COM *character_set = NULL, 155*9257SGowtham.Thommandra@Sun.COM *reject_reason = NULL, 156*9257SGowtham.Thommandra@Sun.COM *disable_reason = NULL; 1570Sstevel@tonic-gate short printer_status = 0; 1580Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 1590Sstevel@tonic-gate 1600Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (printer == NULL)) 1610Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate if ((*printer = p = calloc(1, sizeof (*p))) == NULL) 1640Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1650Sstevel@tonic-gate 1660Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 1670Sstevel@tonic-gate 1682264Sjacobs if (strcmp(dest, "_default") == 0) { 1692264Sjacobs static char *_default; 1702264Sjacobs 1712264Sjacobs if (_default == NULL) { 1722264Sjacobs int fd; 1732264Sjacobs static char buf[128]; 1742264Sjacobs 1752264Sjacobs if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) { 1762264Sjacobs read(fd, buf, sizeof (buf)); 1772264Sjacobs close(fd); 1782264Sjacobs _default = strtok(buf, " \t\n"); 1792264Sjacobs } 1802264Sjacobs } 1812264Sjacobs dest = _default; 1822264Sjacobs } 1832264Sjacobs 1840Sstevel@tonic-gate if (isprinter(dest) != 0) { 1850Sstevel@tonic-gate pst = lpsched_printer_configuration_to_attributes(svc, p, dest); 1860Sstevel@tonic-gate if (pst != PAPI_OK) 1870Sstevel@tonic-gate return (pst); 1880Sstevel@tonic-gate 1890Sstevel@tonic-gate /* get the spooler status data now */ 1900Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, dest) < 0) 1910Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, &pname, 194*9257SGowtham.Thommandra@Sun.COM &form, &character_set, &disable_reason, 195*9257SGowtham.Thommandra@Sun.COM &reject_reason, &printer_status, &request_id, 196*9257SGowtham.Thommandra@Sun.COM &enable_date, &reject_date) < 0) 1970Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1980Sstevel@tonic-gate 1990Sstevel@tonic-gate printer_status_to_attributes(p, pname, form, character_set, 200*9257SGowtham.Thommandra@Sun.COM disable_reason, reject_reason, printer_status, 201*9257SGowtham.Thommandra@Sun.COM request_id, enable_date, reject_date); 2020Sstevel@tonic-gate } else if (isclass(dest) != 0) { 2030Sstevel@tonic-gate pst = lpsched_class_configuration_to_attributes(svc, p, dest); 2040Sstevel@tonic-gate if (pst != PAPI_OK) 2050Sstevel@tonic-gate return (pst); 2060Sstevel@tonic-gate 2070Sstevel@tonic-gate /* get the spooler status data now */ 2080Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, dest) < 0) 2090Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &pname, 212*9257SGowtham.Thommandra@Sun.COM &printer_status, &reject_reason, 213*9257SGowtham.Thommandra@Sun.COM &reject_date) < 0) 2140Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2150Sstevel@tonic-gate 2160Sstevel@tonic-gate class_status_to_attributes(p, pname, printer_status, 217*9257SGowtham.Thommandra@Sun.COM reject_reason, reject_date); 2180Sstevel@tonic-gate } else if (strcmp(dest, "PrintService") == 0) { 2190Sstevel@tonic-gate /* fill the printer object with service information */ 2202264Sjacobs lpsched_service_information(&p->attributes); 2210Sstevel@tonic-gate } else 2220Sstevel@tonic-gate return (PAPI_NOT_FOUND); 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate free(dest); 2250Sstevel@tonic-gate 2260Sstevel@tonic-gate return (PAPI_OK); 2270Sstevel@tonic-gate } 2280Sstevel@tonic-gate 2290Sstevel@tonic-gate papi_status_t 2302264Sjacobs papiPrinterAdd(papi_service_t handle, char *name, 2312264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2320Sstevel@tonic-gate { 2332264Sjacobs papi_status_t status; 2342264Sjacobs printer_t *p = NULL; 2352264Sjacobs char *dest; 2360Sstevel@tonic-gate 2372264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2380Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 2390Sstevel@tonic-gate 2402264Sjacobs dest = printer_name_from_uri_id(name, -1); 2412264Sjacobs 2422264Sjacobs if (isprinter(dest) != 0) { 2432264Sjacobs status = lpsched_add_modify_printer(handle, dest, 244*9257SGowtham.Thommandra@Sun.COM attributes, 0); 2452264Sjacobs 2462264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2472264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 248*9257SGowtham.Thommandra@Sun.COM dest); 2492264Sjacobs else 2502264Sjacobs status = PAPI_TEMPORARY_ERROR; 2512264Sjacobs 2522264Sjacobs } else if (isclass(dest) != 0) { 2532264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 2542264Sjacobs 2552264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2562264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 257*9257SGowtham.Thommandra@Sun.COM dest); 2582264Sjacobs else 2592264Sjacobs status = PAPI_TEMPORARY_ERROR; 2602264Sjacobs 2612264Sjacobs } else 2622264Sjacobs status = PAPI_NOT_FOUND; 2632264Sjacobs 2642264Sjacobs free(dest); 2652264Sjacobs 2662264Sjacobs return (status); 2670Sstevel@tonic-gate } 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate papi_status_t 2702264Sjacobs papiPrinterModify(papi_service_t handle, char *name, 2712264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2722264Sjacobs { 2732264Sjacobs papi_status_t status; 2742264Sjacobs printer_t *p = NULL; 2752264Sjacobs char *dest; 2762264Sjacobs 2772264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2782264Sjacobs return (PAPI_BAD_ARGUMENT); 2792264Sjacobs 2802264Sjacobs dest = printer_name_from_uri_id(name, -1); 2812264Sjacobs 2822264Sjacobs if (isprinter(dest) != 0) { 2832264Sjacobs status = lpsched_add_modify_printer(handle, dest, 284*9257SGowtham.Thommandra@Sun.COM attributes, 1); 2852264Sjacobs 2862264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2872264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 288*9257SGowtham.Thommandra@Sun.COM dest); 2892264Sjacobs else 2902264Sjacobs status = PAPI_TEMPORARY_ERROR; 2912264Sjacobs } else if (isclass(dest) != 0) { 2922264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 2932264Sjacobs 2942264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2952264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 296*9257SGowtham.Thommandra@Sun.COM dest); 2972264Sjacobs else 2982264Sjacobs status = PAPI_TEMPORARY_ERROR; 2992264Sjacobs } else 3002264Sjacobs status = PAPI_NOT_FOUND; 3012264Sjacobs 3022264Sjacobs free(dest); 3032264Sjacobs 3042264Sjacobs return (status); 3052264Sjacobs } 3062264Sjacobs 3072264Sjacobs papi_status_t 3082264Sjacobs papiPrinterRemove(papi_service_t handle, char *name) 3092264Sjacobs { 3102264Sjacobs papi_status_t result; 3112264Sjacobs char *dest; 3122264Sjacobs 3132264Sjacobs if ((handle == NULL) || (name == NULL)) 3142264Sjacobs return (PAPI_BAD_ARGUMENT); 3152264Sjacobs 3162264Sjacobs dest = printer_name_from_uri_id(name, -1); 3172264Sjacobs 3182264Sjacobs if (isprinter(dest) != 0) { 3192264Sjacobs result = lpsched_remove_printer(handle, dest); 3202264Sjacobs } else if (isclass(dest) != 0) { 3212264Sjacobs result = lpsched_remove_class(handle, dest); 3222264Sjacobs } else 3232264Sjacobs result = PAPI_NOT_FOUND; 3242264Sjacobs 3252264Sjacobs free(dest); 3262264Sjacobs 3272264Sjacobs return (result); 3282264Sjacobs } 3292264Sjacobs 3302264Sjacobs papi_status_t 3312264Sjacobs papiPrinterDisable(papi_service_t handle, char *name, char *message) 3320Sstevel@tonic-gate { 3330Sstevel@tonic-gate papi_status_t result; 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3360Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3370Sstevel@tonic-gate 3380Sstevel@tonic-gate result = lpsched_disable_printer(handle, name, message); 3390Sstevel@tonic-gate 3400Sstevel@tonic-gate return (result); 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate 3430Sstevel@tonic-gate papi_status_t 3442264Sjacobs papiPrinterEnable(papi_service_t handle, char *name) 3450Sstevel@tonic-gate { 3460Sstevel@tonic-gate papi_status_t result; 3470Sstevel@tonic-gate 3480Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3490Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3500Sstevel@tonic-gate 3510Sstevel@tonic-gate result = lpsched_enable_printer(handle, name); 3520Sstevel@tonic-gate 3530Sstevel@tonic-gate return (result); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate papi_status_t 3572264Sjacobs papiPrinterPause(papi_service_t handle, char *name, char *message) 3582264Sjacobs { 3592264Sjacobs papi_status_t result; 3602264Sjacobs 3612264Sjacobs if ((handle == NULL) || (name == NULL)) 3622264Sjacobs return (PAPI_BAD_ARGUMENT); 3632264Sjacobs 3642264Sjacobs result = lpsched_reject_printer(handle, name, message); 3652264Sjacobs 3662264Sjacobs return (result); 3672264Sjacobs } 3682264Sjacobs 3692264Sjacobs papi_status_t 3702264Sjacobs papiPrinterResume(papi_service_t handle, char *name) 3712264Sjacobs { 3722264Sjacobs papi_status_t result; 3732264Sjacobs 3742264Sjacobs if ((handle == NULL) || (name == NULL)) 3752264Sjacobs return (PAPI_BAD_ARGUMENT); 3762264Sjacobs 3772264Sjacobs result = lpsched_accept_printer(handle, name); 3782264Sjacobs 3792264Sjacobs return (result); 3802264Sjacobs } 3812264Sjacobs 3822264Sjacobs papi_status_t 3832264Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) 3840Sstevel@tonic-gate { 3850Sstevel@tonic-gate service_t *svc = handle; 3860Sstevel@tonic-gate papi_status_t result = PAPI_OK_SUBST; 3870Sstevel@tonic-gate short more; 3880Sstevel@tonic-gate long status; 3890Sstevel@tonic-gate char *dest; 3900Sstevel@tonic-gate char *req_id; 3910Sstevel@tonic-gate 3920Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3930Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 3962264Sjacobs more = snd_msg(svc, S_CANCEL, dest, "", ""); 3972264Sjacobs free(dest); 3982264Sjacobs if (more < 0) 3990Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4000Sstevel@tonic-gate 4010Sstevel@tonic-gate do { 4020Sstevel@tonic-gate if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0) 4030Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate switch (status) { 4060Sstevel@tonic-gate case MOK: 4070Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 408*9257SGowtham.Thommandra@Sun.COM "canceled-jobs", req_id); 4090Sstevel@tonic-gate break; 4100Sstevel@tonic-gate case M2LATE: 4110Sstevel@tonic-gate case MUNKNOWN: 4120Sstevel@tonic-gate case MNOINFO: 4130Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 414*9257SGowtham.Thommandra@Sun.COM "cancel-failed", req_id); 4150Sstevel@tonic-gate result = PAPI_DEVICE_ERROR; 4160Sstevel@tonic-gate break; 4170Sstevel@tonic-gate case MNOPERM: 4180Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 419*9257SGowtham.Thommandra@Sun.COM "cancel-failed", req_id); 4200Sstevel@tonic-gate result = PAPI_NOT_AUTHORIZED; 4210Sstevel@tonic-gate break; 4220Sstevel@tonic-gate default: 4230Sstevel@tonic-gate detailed_error(svc, gettext("cancel failed, bad status (%d)\n"), 424*9257SGowtham.Thommandra@Sun.COM status); 4250Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 4260Sstevel@tonic-gate } 4270Sstevel@tonic-gate } while (more == MOKMORE); 4280Sstevel@tonic-gate 4290Sstevel@tonic-gate return (result); 4300Sstevel@tonic-gate } 4310Sstevel@tonic-gate 4320Sstevel@tonic-gate papi_status_t 4332264Sjacobs papiPrinterListJobs(papi_service_t handle, char *name, 4342264Sjacobs char **requested_attrs, int type_mask, 4352264Sjacobs int max_num_jobs, papi_job_t **jobs) 4360Sstevel@tonic-gate { 4370Sstevel@tonic-gate service_t *svc = handle; 4380Sstevel@tonic-gate char *dest; 4390Sstevel@tonic-gate short rc; 4400Sstevel@tonic-gate int count = 1; 4410Sstevel@tonic-gate 4420Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (jobs == NULL)) 4430Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 4440Sstevel@tonic-gate 4450Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 4460Sstevel@tonic-gate 4470Sstevel@tonic-gate rc = snd_msg(svc, S_INQUIRE_REQUEST_RANK, 0, "", dest, "", "", ""); 4480Sstevel@tonic-gate free(dest); 4490Sstevel@tonic-gate if (rc < 0) 4500Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4510Sstevel@tonic-gate 4520Sstevel@tonic-gate do { 4530Sstevel@tonic-gate job_t *job = NULL; 4540Sstevel@tonic-gate char *dest = NULL, 455*9257SGowtham.Thommandra@Sun.COM *ptr, 456*9257SGowtham.Thommandra@Sun.COM *form = NULL, 457*9257SGowtham.Thommandra@Sun.COM *req_id = NULL, 458*9257SGowtham.Thommandra@Sun.COM *charset = NULL, 459*9257SGowtham.Thommandra@Sun.COM *owner = NULL, 460*9257SGowtham.Thommandra@Sun.COM *slabel = NULL, 461*9257SGowtham.Thommandra@Sun.COM *file = NULL; 4620Sstevel@tonic-gate time_t date = 0; 4630Sstevel@tonic-gate size_t size = 0; 4640Sstevel@tonic-gate short rank = 0, state = 0; 4650Sstevel@tonic-gate 4660Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_REQUEST_RANK, &rc, &req_id, 467*9257SGowtham.Thommandra@Sun.COM &owner, &slabel, &size, &date, &state, &dest, 468*9257SGowtham.Thommandra@Sun.COM &form, &charset, &rank, &file) < 0) 4690Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4700Sstevel@tonic-gate 4710Sstevel@tonic-gate if ((rc != MOK) && (rc != MOKMORE)) 4720Sstevel@tonic-gate continue; 4730Sstevel@tonic-gate /* 4740Sstevel@tonic-gate * at this point, we should check to see if the job matches the 4750Sstevel@tonic-gate * selection criterion defined in "type_mask". 4760Sstevel@tonic-gate */ 4770Sstevel@tonic-gate 4780Sstevel@tonic-gate /* too many yet? */ 4790Sstevel@tonic-gate if ((max_num_jobs != 0) && (count++ > max_num_jobs)) 4800Sstevel@tonic-gate continue; 4810Sstevel@tonic-gate 4820Sstevel@tonic-gate if ((job = calloc(1, sizeof (*job))) == NULL) 4830Sstevel@tonic-gate continue; 4840Sstevel@tonic-gate 4850Sstevel@tonic-gate if ((ptr = strrchr(file, '-')) != NULL) { 4860Sstevel@tonic-gate *++ptr = '0'; 4870Sstevel@tonic-gate *++ptr = NULL; 4880Sstevel@tonic-gate } 4890Sstevel@tonic-gate 4900Sstevel@tonic-gate lpsched_read_job_configuration(svc, job, file); 4910Sstevel@tonic-gate 492*9257SGowtham.Thommandra@Sun.COM job_status_to_attributes(job, req_id, owner, slabel, size, 493*9257SGowtham.Thommandra@Sun.COM date, state, dest, form, charset, rank, file); 494*9257SGowtham.Thommandra@Sun.COM 4950Sstevel@tonic-gate list_append(jobs, job); 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate } while (rc == MOKMORE); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate if (rc == MNOINFO) /* If no jobs are found, it's still ok */ 5000Sstevel@tonic-gate rc = MOK; 5010Sstevel@tonic-gate 5020Sstevel@tonic-gate return (lpsched_status_to_papi_status(rc)); 5030Sstevel@tonic-gate } 5040Sstevel@tonic-gate 5050Sstevel@tonic-gate papi_attribute_t ** 5060Sstevel@tonic-gate papiPrinterGetAttributeList(papi_printer_t printer) 5070Sstevel@tonic-gate { 5080Sstevel@tonic-gate printer_t *tmp = printer; 5090Sstevel@tonic-gate 5100Sstevel@tonic-gate if (tmp == NULL) 5110Sstevel@tonic-gate return (NULL); 5120Sstevel@tonic-gate 5130Sstevel@tonic-gate return (tmp->attributes); 5140Sstevel@tonic-gate } 515