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 /* 229257SGowtham.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 /*LINTLIBRARY*/ 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include <stdlib.h> 290Sstevel@tonic-gate #include <string.h> 300Sstevel@tonic-gate #include <libintl.h> 310Sstevel@tonic-gate #include <papi_impl.h> 320Sstevel@tonic-gate #include <lp.h> 330Sstevel@tonic-gate 340Sstevel@tonic-gate extern int isclass(char *); 350Sstevel@tonic-gate 360Sstevel@tonic-gate void 370Sstevel@tonic-gate papiPrinterFree(papi_printer_t printer) 380Sstevel@tonic-gate { 390Sstevel@tonic-gate printer_t *tmp = printer; 400Sstevel@tonic-gate 410Sstevel@tonic-gate if (tmp != NULL) { 420Sstevel@tonic-gate papiAttributeListFree(tmp->attributes); 430Sstevel@tonic-gate free(tmp); 440Sstevel@tonic-gate } 450Sstevel@tonic-gate } 460Sstevel@tonic-gate 470Sstevel@tonic-gate void 480Sstevel@tonic-gate papiPrinterListFree(papi_printer_t *printers) 490Sstevel@tonic-gate { 500Sstevel@tonic-gate if (printers != NULL) { 510Sstevel@tonic-gate int i; 520Sstevel@tonic-gate 530Sstevel@tonic-gate for (i = 0; printers[i] != NULL; i++) 540Sstevel@tonic-gate papiPrinterFree(printers[i]); 550Sstevel@tonic-gate free(printers); 560Sstevel@tonic-gate } 570Sstevel@tonic-gate } 580Sstevel@tonic-gate 590Sstevel@tonic-gate papi_status_t 602264Sjacobs papiPrintersList(papi_service_t handle, char **requested_attrs, 612264Sjacobs papi_filter_t *filter, papi_printer_t **printers) 620Sstevel@tonic-gate { 630Sstevel@tonic-gate service_t *svc = handle; 640Sstevel@tonic-gate printer_t *p = NULL; 650Sstevel@tonic-gate short status = MOK; 660Sstevel@tonic-gate char *printer = NULL, 679257SGowtham.Thommandra@Sun.COM *form = NULL, 689257SGowtham.Thommandra@Sun.COM *request_id = NULL, 699257SGowtham.Thommandra@Sun.COM *character_set = NULL, 709257SGowtham.Thommandra@Sun.COM *reject_reason = NULL, 719257SGowtham.Thommandra@Sun.COM *disable_reason = NULL; 720Sstevel@tonic-gate short printer_status = 0; 730Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 740Sstevel@tonic-gate 750Sstevel@tonic-gate if ((handle == NULL) || (printers == NULL)) 760Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 770Sstevel@tonic-gate 780Sstevel@tonic-gate if ((filter == NULL) || 790Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) == 800Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_LOCAL))) { 810Sstevel@tonic-gate /* ask the spooler for the printer(s) and state */ 820Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, NAME_ALL) < 0) 830Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 840Sstevel@tonic-gate 850Sstevel@tonic-gate do { 860Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, 879257SGowtham.Thommandra@Sun.COM &printer, &form, &character_set, 889257SGowtham.Thommandra@Sun.COM &disable_reason, &reject_reason, 899257SGowtham.Thommandra@Sun.COM &printer_status, &request_id, 909257SGowtham.Thommandra@Sun.COM &enable_date, &reject_date) < 0) 910Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 920Sstevel@tonic-gate 930Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 940Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 950Sstevel@tonic-gate 960Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(svc, p, 979257SGowtham.Thommandra@Sun.COM printer); 980Sstevel@tonic-gate 990Sstevel@tonic-gate printer_status_to_attributes(p, printer, form, 1009257SGowtham.Thommandra@Sun.COM character_set, disable_reason, 1019257SGowtham.Thommandra@Sun.COM reject_reason, printer_status, 1029257SGowtham.Thommandra@Sun.COM request_id, enable_date, reject_date); 1030Sstevel@tonic-gate 1040Sstevel@tonic-gate list_append(printers, p); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate } while (status == MOKMORE); 1070Sstevel@tonic-gate } 1080Sstevel@tonic-gate 1090Sstevel@tonic-gate if ((filter == NULL) || 1100Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) == 1110Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_CLASS))) { 1120Sstevel@tonic-gate /* ask the spooler for the class(es) and state */ 1130Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, NAME_ALL) < 0) 1140Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1150Sstevel@tonic-gate 1160Sstevel@tonic-gate do { 1170Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &printer, 1189257SGowtham.Thommandra@Sun.COM &printer_status, &reject_reason, 1199257SGowtham.Thommandra@Sun.COM &reject_date) < 0) 1200Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1210Sstevel@tonic-gate 1220Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 1230Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1240Sstevel@tonic-gate 1250Sstevel@tonic-gate lpsched_class_configuration_to_attributes(svc, p, 1269257SGowtham.Thommandra@Sun.COM printer); 1270Sstevel@tonic-gate 1280Sstevel@tonic-gate class_status_to_attributes(p, printer, printer_status, 1299257SGowtham.Thommandra@Sun.COM reject_reason, reject_date); 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate list_append(printers, p); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate } while (status == MOKMORE); 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate return (PAPI_OK); 1370Sstevel@tonic-gate } 1380Sstevel@tonic-gate 1390Sstevel@tonic-gate papi_status_t 1402264Sjacobs papiPrinterQuery(papi_service_t handle, char *name, 1412264Sjacobs char **requested_attrs, 1422264Sjacobs papi_attribute_t **job_attrs, 1430Sstevel@tonic-gate papi_printer_t *printer) 1440Sstevel@tonic-gate { 1450Sstevel@tonic-gate papi_status_t pst; 1460Sstevel@tonic-gate service_t *svc = handle; 1470Sstevel@tonic-gate printer_t *p = NULL; 1480Sstevel@tonic-gate char *dest; 1490Sstevel@tonic-gate short status = MOK; 1500Sstevel@tonic-gate char *pname = NULL, 1519257SGowtham.Thommandra@Sun.COM *form = NULL, 1529257SGowtham.Thommandra@Sun.COM *request_id = NULL, 1539257SGowtham.Thommandra@Sun.COM *character_set = NULL, 1549257SGowtham.Thommandra@Sun.COM *reject_reason = NULL, 1559257SGowtham.Thommandra@Sun.COM *disable_reason = NULL; 1560Sstevel@tonic-gate short printer_status = 0; 1570Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (printer == NULL)) 1600Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 1610Sstevel@tonic-gate 1620Sstevel@tonic-gate if ((*printer = p = calloc(1, sizeof (*p))) == NULL) 1630Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1640Sstevel@tonic-gate 1650Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 1660Sstevel@tonic-gate 1672264Sjacobs if (strcmp(dest, "_default") == 0) { 1682264Sjacobs static char *_default; 1692264Sjacobs 1702264Sjacobs if (_default == NULL) { 1712264Sjacobs int fd; 1722264Sjacobs static char buf[128]; 1732264Sjacobs 1742264Sjacobs if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) { 1752264Sjacobs read(fd, buf, sizeof (buf)); 1762264Sjacobs close(fd); 1772264Sjacobs _default = strtok(buf, " \t\n"); 1782264Sjacobs } 1792264Sjacobs } 1802264Sjacobs dest = _default; 1812264Sjacobs } 1822264Sjacobs 1830Sstevel@tonic-gate if (isprinter(dest) != 0) { 1840Sstevel@tonic-gate pst = lpsched_printer_configuration_to_attributes(svc, p, dest); 1850Sstevel@tonic-gate if (pst != PAPI_OK) 1860Sstevel@tonic-gate return (pst); 1870Sstevel@tonic-gate 1880Sstevel@tonic-gate /* get the spooler status data now */ 1890Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, dest) < 0) 1900Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, &pname, 1939257SGowtham.Thommandra@Sun.COM &form, &character_set, &disable_reason, 1949257SGowtham.Thommandra@Sun.COM &reject_reason, &printer_status, &request_id, 1959257SGowtham.Thommandra@Sun.COM &enable_date, &reject_date) < 0) 1960Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate printer_status_to_attributes(p, pname, form, character_set, 1999257SGowtham.Thommandra@Sun.COM disable_reason, reject_reason, printer_status, 2009257SGowtham.Thommandra@Sun.COM request_id, enable_date, reject_date); 2010Sstevel@tonic-gate } else if (isclass(dest) != 0) { 2020Sstevel@tonic-gate pst = lpsched_class_configuration_to_attributes(svc, p, dest); 2030Sstevel@tonic-gate if (pst != PAPI_OK) 2040Sstevel@tonic-gate return (pst); 2050Sstevel@tonic-gate 2060Sstevel@tonic-gate /* get the spooler status data now */ 2070Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, dest) < 0) 2080Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2090Sstevel@tonic-gate 2100Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &pname, 2119257SGowtham.Thommandra@Sun.COM &printer_status, &reject_reason, 2129257SGowtham.Thommandra@Sun.COM &reject_date) < 0) 2130Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2140Sstevel@tonic-gate 2150Sstevel@tonic-gate class_status_to_attributes(p, pname, printer_status, 2169257SGowtham.Thommandra@Sun.COM reject_reason, reject_date); 2170Sstevel@tonic-gate } else if (strcmp(dest, "PrintService") == 0) { 2180Sstevel@tonic-gate /* fill the printer object with service information */ 2192264Sjacobs lpsched_service_information(&p->attributes); 2200Sstevel@tonic-gate } else 2210Sstevel@tonic-gate return (PAPI_NOT_FOUND); 2220Sstevel@tonic-gate 2230Sstevel@tonic-gate free(dest); 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate return (PAPI_OK); 2260Sstevel@tonic-gate } 2270Sstevel@tonic-gate 2280Sstevel@tonic-gate papi_status_t 2292264Sjacobs papiPrinterAdd(papi_service_t handle, char *name, 2302264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2310Sstevel@tonic-gate { 2322264Sjacobs papi_status_t status; 2332264Sjacobs printer_t *p = NULL; 2342264Sjacobs char *dest; 2350Sstevel@tonic-gate 2362264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2370Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 2380Sstevel@tonic-gate 2392264Sjacobs dest = printer_name_from_uri_id(name, -1); 2402264Sjacobs 2412264Sjacobs if (isprinter(dest) != 0) { 2422264Sjacobs status = lpsched_add_modify_printer(handle, dest, 2439257SGowtham.Thommandra@Sun.COM attributes, 0); 2442264Sjacobs 2452264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2462264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 2479257SGowtham.Thommandra@Sun.COM dest); 2482264Sjacobs else 2492264Sjacobs status = PAPI_TEMPORARY_ERROR; 2502264Sjacobs 2512264Sjacobs } else if (isclass(dest) != 0) { 2522264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 2532264Sjacobs 2542264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2552264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 2569257SGowtham.Thommandra@Sun.COM dest); 2572264Sjacobs else 2582264Sjacobs status = PAPI_TEMPORARY_ERROR; 2592264Sjacobs 2602264Sjacobs } else 2612264Sjacobs status = PAPI_NOT_FOUND; 2622264Sjacobs 2632264Sjacobs free(dest); 2642264Sjacobs 2652264Sjacobs return (status); 2660Sstevel@tonic-gate } 2670Sstevel@tonic-gate 2680Sstevel@tonic-gate papi_status_t 2692264Sjacobs papiPrinterModify(papi_service_t handle, char *name, 2702264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2712264Sjacobs { 2722264Sjacobs papi_status_t status; 2732264Sjacobs printer_t *p = NULL; 2742264Sjacobs char *dest; 2752264Sjacobs 2762264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2772264Sjacobs return (PAPI_BAD_ARGUMENT); 2782264Sjacobs 2792264Sjacobs dest = printer_name_from_uri_id(name, -1); 2802264Sjacobs 2812264Sjacobs if (isprinter(dest) != 0) { 2822264Sjacobs status = lpsched_add_modify_printer(handle, dest, 2839257SGowtham.Thommandra@Sun.COM attributes, 1); 2842264Sjacobs 2852264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2862264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 2879257SGowtham.Thommandra@Sun.COM dest); 2882264Sjacobs else 2892264Sjacobs status = PAPI_TEMPORARY_ERROR; 2902264Sjacobs } else if (isclass(dest) != 0) { 2912264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 2922264Sjacobs 2932264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 2942264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 2959257SGowtham.Thommandra@Sun.COM dest); 2962264Sjacobs else 2972264Sjacobs status = PAPI_TEMPORARY_ERROR; 2982264Sjacobs } else 2992264Sjacobs status = PAPI_NOT_FOUND; 3002264Sjacobs 3012264Sjacobs free(dest); 3022264Sjacobs 3032264Sjacobs return (status); 3042264Sjacobs } 3052264Sjacobs 3062264Sjacobs papi_status_t 3072264Sjacobs papiPrinterRemove(papi_service_t handle, char *name) 3082264Sjacobs { 3092264Sjacobs papi_status_t result; 3102264Sjacobs char *dest; 3112264Sjacobs 3122264Sjacobs if ((handle == NULL) || (name == NULL)) 3132264Sjacobs return (PAPI_BAD_ARGUMENT); 3142264Sjacobs 3152264Sjacobs dest = printer_name_from_uri_id(name, -1); 3162264Sjacobs 3172264Sjacobs if (isprinter(dest) != 0) { 3182264Sjacobs result = lpsched_remove_printer(handle, dest); 3192264Sjacobs } else if (isclass(dest) != 0) { 3202264Sjacobs result = lpsched_remove_class(handle, dest); 3212264Sjacobs } else 3222264Sjacobs result = PAPI_NOT_FOUND; 3232264Sjacobs 3242264Sjacobs free(dest); 3252264Sjacobs 3262264Sjacobs return (result); 3272264Sjacobs } 3282264Sjacobs 3292264Sjacobs papi_status_t 3302264Sjacobs papiPrinterDisable(papi_service_t handle, char *name, char *message) 3310Sstevel@tonic-gate { 3320Sstevel@tonic-gate papi_status_t result; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3350Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3360Sstevel@tonic-gate 3370Sstevel@tonic-gate result = lpsched_disable_printer(handle, name, message); 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate return (result); 3400Sstevel@tonic-gate } 3410Sstevel@tonic-gate 3420Sstevel@tonic-gate papi_status_t 3432264Sjacobs papiPrinterEnable(papi_service_t handle, char *name) 3440Sstevel@tonic-gate { 3450Sstevel@tonic-gate papi_status_t result; 3460Sstevel@tonic-gate 3470Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3480Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3490Sstevel@tonic-gate 3500Sstevel@tonic-gate result = lpsched_enable_printer(handle, name); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate return (result); 3530Sstevel@tonic-gate } 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate papi_status_t 3562264Sjacobs papiPrinterPause(papi_service_t handle, char *name, char *message) 3572264Sjacobs { 3582264Sjacobs papi_status_t result; 3592264Sjacobs 3602264Sjacobs if ((handle == NULL) || (name == NULL)) 3612264Sjacobs return (PAPI_BAD_ARGUMENT); 3622264Sjacobs 3632264Sjacobs result = lpsched_reject_printer(handle, name, message); 3642264Sjacobs 3652264Sjacobs return (result); 3662264Sjacobs } 3672264Sjacobs 3682264Sjacobs papi_status_t 3692264Sjacobs papiPrinterResume(papi_service_t handle, char *name) 3702264Sjacobs { 3712264Sjacobs papi_status_t result; 3722264Sjacobs 3732264Sjacobs if ((handle == NULL) || (name == NULL)) 3742264Sjacobs return (PAPI_BAD_ARGUMENT); 3752264Sjacobs 3762264Sjacobs result = lpsched_accept_printer(handle, name); 3772264Sjacobs 3782264Sjacobs return (result); 3792264Sjacobs } 3802264Sjacobs 3812264Sjacobs papi_status_t 3822264Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) 3830Sstevel@tonic-gate { 3840Sstevel@tonic-gate service_t *svc = handle; 3850Sstevel@tonic-gate papi_status_t result = PAPI_OK_SUBST; 3860Sstevel@tonic-gate short more; 3870Sstevel@tonic-gate long status; 3880Sstevel@tonic-gate char *dest; 3890Sstevel@tonic-gate char *req_id; 3900Sstevel@tonic-gate 3910Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3920Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3930Sstevel@tonic-gate 3940Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 3952264Sjacobs more = snd_msg(svc, S_CANCEL, dest, "", ""); 3962264Sjacobs free(dest); 3972264Sjacobs if (more < 0) 3980Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 3990Sstevel@tonic-gate 4000Sstevel@tonic-gate do { 4010Sstevel@tonic-gate if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0) 4020Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4030Sstevel@tonic-gate 4040Sstevel@tonic-gate switch (status) { 4050Sstevel@tonic-gate case MOK: 4060Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4079257SGowtham.Thommandra@Sun.COM "canceled-jobs", req_id); 4080Sstevel@tonic-gate break; 4090Sstevel@tonic-gate case M2LATE: 4100Sstevel@tonic-gate case MUNKNOWN: 4110Sstevel@tonic-gate case MNOINFO: 4120Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4139257SGowtham.Thommandra@Sun.COM "cancel-failed", req_id); 4140Sstevel@tonic-gate result = PAPI_DEVICE_ERROR; 4150Sstevel@tonic-gate break; 4160Sstevel@tonic-gate case MNOPERM: 4170Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4189257SGowtham.Thommandra@Sun.COM "cancel-failed", req_id); 4190Sstevel@tonic-gate result = PAPI_NOT_AUTHORIZED; 4200Sstevel@tonic-gate break; 4210Sstevel@tonic-gate default: 4220Sstevel@tonic-gate detailed_error(svc, gettext("cancel failed, bad status (%d)\n"), 4239257SGowtham.Thommandra@Sun.COM status); 4240Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 4250Sstevel@tonic-gate } 4260Sstevel@tonic-gate } while (more == MOKMORE); 4270Sstevel@tonic-gate 4280Sstevel@tonic-gate return (result); 4290Sstevel@tonic-gate } 4300Sstevel@tonic-gate 4310Sstevel@tonic-gate papi_status_t 4322264Sjacobs papiPrinterListJobs(papi_service_t handle, char *name, 4332264Sjacobs char **requested_attrs, int type_mask, 4342264Sjacobs int max_num_jobs, papi_job_t **jobs) 4350Sstevel@tonic-gate { 4360Sstevel@tonic-gate service_t *svc = handle; 4370Sstevel@tonic-gate char *dest; 4380Sstevel@tonic-gate short rc; 4390Sstevel@tonic-gate int count = 1; 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (jobs == NULL)) 4420Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 4430Sstevel@tonic-gate 4440Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate rc = snd_msg(svc, S_INQUIRE_REQUEST_RANK, 0, "", dest, "", "", ""); 4470Sstevel@tonic-gate free(dest); 4480Sstevel@tonic-gate if (rc < 0) 4490Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate do { 4520Sstevel@tonic-gate job_t *job = NULL; 4530Sstevel@tonic-gate char *dest = NULL, 4549257SGowtham.Thommandra@Sun.COM *ptr, 4559257SGowtham.Thommandra@Sun.COM *form = NULL, 4569257SGowtham.Thommandra@Sun.COM *req_id = NULL, 4579257SGowtham.Thommandra@Sun.COM *charset = NULL, 4589257SGowtham.Thommandra@Sun.COM *owner = NULL, 4599257SGowtham.Thommandra@Sun.COM *slabel = NULL, 4609257SGowtham.Thommandra@Sun.COM *file = NULL; 461*9330SSonam.Gupta@Sun.COM char request_file[128]; 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, 4679257SGowtham.Thommandra@Sun.COM &owner, &slabel, &size, &date, &state, &dest, 4689257SGowtham.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 485*9330SSonam.Gupta@Sun.COM /* Request file is <req_id>-0 */ 486*9330SSonam.Gupta@Sun.COM if ((ptr = strrchr(req_id, '-')) != NULL) { 487*9330SSonam.Gupta@Sun.COM ++ptr; 488*9330SSonam.Gupta@Sun.COM snprintf(request_file, sizeof (request_file), 489*9330SSonam.Gupta@Sun.COM "%s-0", ptr); 4900Sstevel@tonic-gate } 4910Sstevel@tonic-gate 492*9330SSonam.Gupta@Sun.COM lpsched_read_job_configuration(svc, job, request_file); 4930Sstevel@tonic-gate 4949257SGowtham.Thommandra@Sun.COM job_status_to_attributes(job, req_id, owner, slabel, size, 4959257SGowtham.Thommandra@Sun.COM date, state, dest, form, charset, rank, file); 4969257SGowtham.Thommandra@Sun.COM 4970Sstevel@tonic-gate list_append(jobs, job); 4980Sstevel@tonic-gate 4990Sstevel@tonic-gate } while (rc == MOKMORE); 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate if (rc == MNOINFO) /* If no jobs are found, it's still ok */ 5020Sstevel@tonic-gate rc = MOK; 5030Sstevel@tonic-gate 5040Sstevel@tonic-gate return (lpsched_status_to_papi_status(rc)); 5050Sstevel@tonic-gate } 5060Sstevel@tonic-gate 5070Sstevel@tonic-gate papi_attribute_t ** 5080Sstevel@tonic-gate papiPrinterGetAttributeList(papi_printer_t printer) 5090Sstevel@tonic-gate { 5100Sstevel@tonic-gate printer_t *tmp = printer; 5110Sstevel@tonic-gate 5120Sstevel@tonic-gate if (tmp == NULL) 5130Sstevel@tonic-gate return (NULL); 5140Sstevel@tonic-gate 5150Sstevel@tonic-gate return (tmp->attributes); 5160Sstevel@tonic-gate } 517