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 /* 221676Sjpk * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate /*LINTLIBRARY*/ 290Sstevel@tonic-gate 300Sstevel@tonic-gate #include <stdlib.h> 310Sstevel@tonic-gate #include <string.h> 320Sstevel@tonic-gate #include <libintl.h> 330Sstevel@tonic-gate #include <papi_impl.h> 340Sstevel@tonic-gate #include <lp.h> 350Sstevel@tonic-gate 360Sstevel@tonic-gate extern int isclass(char *); 370Sstevel@tonic-gate 380Sstevel@tonic-gate void 390Sstevel@tonic-gate papiPrinterFree(papi_printer_t printer) 400Sstevel@tonic-gate { 410Sstevel@tonic-gate printer_t *tmp = printer; 420Sstevel@tonic-gate 430Sstevel@tonic-gate if (tmp != NULL) { 440Sstevel@tonic-gate papiAttributeListFree(tmp->attributes); 450Sstevel@tonic-gate free(tmp); 460Sstevel@tonic-gate } 470Sstevel@tonic-gate } 480Sstevel@tonic-gate 490Sstevel@tonic-gate void 500Sstevel@tonic-gate papiPrinterListFree(papi_printer_t *printers) 510Sstevel@tonic-gate { 520Sstevel@tonic-gate if (printers != NULL) { 530Sstevel@tonic-gate int i; 540Sstevel@tonic-gate 550Sstevel@tonic-gate for (i = 0; printers[i] != NULL; i++) 560Sstevel@tonic-gate papiPrinterFree(printers[i]); 570Sstevel@tonic-gate free(printers); 580Sstevel@tonic-gate } 590Sstevel@tonic-gate } 600Sstevel@tonic-gate 610Sstevel@tonic-gate papi_status_t 62*2264Sjacobs papiPrintersList(papi_service_t handle, char **requested_attrs, 63*2264Sjacobs papi_filter_t *filter, papi_printer_t **printers) 640Sstevel@tonic-gate { 650Sstevel@tonic-gate service_t *svc = handle; 660Sstevel@tonic-gate printer_t *p = NULL; 670Sstevel@tonic-gate short status = MOK; 680Sstevel@tonic-gate char *printer = NULL, 690Sstevel@tonic-gate *form = NULL, 700Sstevel@tonic-gate *request_id = NULL, 710Sstevel@tonic-gate *character_set = NULL, 720Sstevel@tonic-gate *reject_reason = NULL, 730Sstevel@tonic-gate *disable_reason = NULL; 740Sstevel@tonic-gate short printer_status = 0; 750Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 760Sstevel@tonic-gate 770Sstevel@tonic-gate if ((handle == NULL) || (printers == NULL)) 780Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 790Sstevel@tonic-gate 800Sstevel@tonic-gate if ((filter == NULL) || 810Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) == 820Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_LOCAL))) { 830Sstevel@tonic-gate /* ask the spooler for the printer(s) and state */ 840Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, NAME_ALL) < 0) 850Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 860Sstevel@tonic-gate 870Sstevel@tonic-gate do { 880Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, 890Sstevel@tonic-gate &printer, &form, &character_set, 900Sstevel@tonic-gate &disable_reason, &reject_reason, 910Sstevel@tonic-gate &printer_status, &request_id, 920Sstevel@tonic-gate &enable_date, &reject_date) < 0) 930Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 940Sstevel@tonic-gate 950Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 960Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 970Sstevel@tonic-gate 980Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(svc, p, 990Sstevel@tonic-gate printer); 1000Sstevel@tonic-gate 1010Sstevel@tonic-gate printer_status_to_attributes(p, printer, form, 1020Sstevel@tonic-gate character_set, disable_reason, 1030Sstevel@tonic-gate reject_reason, printer_status, 1040Sstevel@tonic-gate request_id, enable_date, reject_date); 1050Sstevel@tonic-gate 1060Sstevel@tonic-gate list_append(printers, p); 1070Sstevel@tonic-gate 1080Sstevel@tonic-gate } while (status == MOKMORE); 1090Sstevel@tonic-gate } 1100Sstevel@tonic-gate 1110Sstevel@tonic-gate if ((filter == NULL) || 1120Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) == 1130Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_CLASS))) { 1140Sstevel@tonic-gate /* ask the spooler for the class(es) and state */ 1150Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, NAME_ALL) < 0) 1160Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1170Sstevel@tonic-gate 1180Sstevel@tonic-gate do { 1190Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &printer, 1200Sstevel@tonic-gate &printer_status, &reject_reason, 1210Sstevel@tonic-gate &reject_date) < 0) 1220Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1230Sstevel@tonic-gate 1240Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 1250Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1260Sstevel@tonic-gate 1270Sstevel@tonic-gate lpsched_class_configuration_to_attributes(svc, p, 1280Sstevel@tonic-gate printer); 1290Sstevel@tonic-gate 1300Sstevel@tonic-gate class_status_to_attributes(p, printer, printer_status, 1310Sstevel@tonic-gate reject_reason, reject_date); 1320Sstevel@tonic-gate 1330Sstevel@tonic-gate list_append(printers, p); 1340Sstevel@tonic-gate 1350Sstevel@tonic-gate } while (status == MOKMORE); 1360Sstevel@tonic-gate } 1370Sstevel@tonic-gate 1380Sstevel@tonic-gate return (PAPI_OK); 1390Sstevel@tonic-gate } 1400Sstevel@tonic-gate 1410Sstevel@tonic-gate papi_status_t 142*2264Sjacobs papiPrinterQuery(papi_service_t handle, char *name, 143*2264Sjacobs char **requested_attrs, 144*2264Sjacobs papi_attribute_t **job_attrs, 1450Sstevel@tonic-gate papi_printer_t *printer) 1460Sstevel@tonic-gate { 1470Sstevel@tonic-gate papi_status_t pst; 1480Sstevel@tonic-gate service_t *svc = handle; 1490Sstevel@tonic-gate printer_t *p = NULL; 1500Sstevel@tonic-gate char *dest; 1510Sstevel@tonic-gate short status = MOK; 1520Sstevel@tonic-gate char *pname = NULL, 1530Sstevel@tonic-gate *form = NULL, 1540Sstevel@tonic-gate *request_id = NULL, 1550Sstevel@tonic-gate *character_set = NULL, 1560Sstevel@tonic-gate *reject_reason = NULL, 1570Sstevel@tonic-gate *disable_reason = NULL; 1580Sstevel@tonic-gate short printer_status = 0; 1590Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 1600Sstevel@tonic-gate 1610Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (printer == NULL)) 1620Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 1630Sstevel@tonic-gate 1640Sstevel@tonic-gate if ((*printer = p = calloc(1, sizeof (*p))) == NULL) 1650Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1660Sstevel@tonic-gate 1670Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 1680Sstevel@tonic-gate 169*2264Sjacobs if (strcmp(dest, "_default") == 0) { 170*2264Sjacobs static char *_default; 171*2264Sjacobs 172*2264Sjacobs if (_default == NULL) { 173*2264Sjacobs int fd; 174*2264Sjacobs static char buf[128]; 175*2264Sjacobs 176*2264Sjacobs if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) { 177*2264Sjacobs read(fd, buf, sizeof (buf)); 178*2264Sjacobs close(fd); 179*2264Sjacobs _default = strtok(buf, " \t\n"); 180*2264Sjacobs } 181*2264Sjacobs } 182*2264Sjacobs dest = _default; 183*2264Sjacobs } 184*2264Sjacobs 1850Sstevel@tonic-gate if (isprinter(dest) != 0) { 1860Sstevel@tonic-gate pst = lpsched_printer_configuration_to_attributes(svc, p, dest); 1870Sstevel@tonic-gate if (pst != PAPI_OK) 1880Sstevel@tonic-gate return (pst); 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate /* get the spooler status data now */ 1910Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, dest) < 0) 1920Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, &pname, 1950Sstevel@tonic-gate &form, &character_set, &disable_reason, 1960Sstevel@tonic-gate &reject_reason, &printer_status, &request_id, 1970Sstevel@tonic-gate &enable_date, &reject_date) < 0) 1980Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1990Sstevel@tonic-gate 2000Sstevel@tonic-gate printer_status_to_attributes(p, pname, form, character_set, 2010Sstevel@tonic-gate disable_reason, reject_reason, printer_status, 2020Sstevel@tonic-gate request_id, enable_date, reject_date); 2030Sstevel@tonic-gate } else if (isclass(dest) != 0) { 2040Sstevel@tonic-gate pst = lpsched_class_configuration_to_attributes(svc, p, dest); 2050Sstevel@tonic-gate if (pst != PAPI_OK) 2060Sstevel@tonic-gate return (pst); 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate /* get the spooler status data now */ 2090Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, dest) < 0) 2100Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &pname, 2130Sstevel@tonic-gate &printer_status, &reject_reason, 2140Sstevel@tonic-gate &reject_date) < 0) 2150Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2160Sstevel@tonic-gate 2170Sstevel@tonic-gate class_status_to_attributes(p, pname, printer_status, 2180Sstevel@tonic-gate reject_reason, reject_date); 2190Sstevel@tonic-gate } else if (strcmp(dest, "PrintService") == 0) { 2200Sstevel@tonic-gate /* fill the printer object with service information */ 221*2264Sjacobs lpsched_service_information(&p->attributes); 2220Sstevel@tonic-gate } else 2230Sstevel@tonic-gate return (PAPI_NOT_FOUND); 2240Sstevel@tonic-gate 2250Sstevel@tonic-gate free(dest); 2260Sstevel@tonic-gate 2270Sstevel@tonic-gate return (PAPI_OK); 2280Sstevel@tonic-gate } 2290Sstevel@tonic-gate 2300Sstevel@tonic-gate papi_status_t 231*2264Sjacobs papiPrinterAdd(papi_service_t handle, char *name, 232*2264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2330Sstevel@tonic-gate { 234*2264Sjacobs papi_status_t status; 235*2264Sjacobs printer_t *p = NULL; 236*2264Sjacobs char *dest; 2370Sstevel@tonic-gate 238*2264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2390Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 2400Sstevel@tonic-gate 241*2264Sjacobs dest = printer_name_from_uri_id(name, -1); 242*2264Sjacobs 243*2264Sjacobs if (isprinter(dest) != 0) { 244*2264Sjacobs status = lpsched_add_modify_printer(handle, dest, 245*2264Sjacobs attributes, 0); 246*2264Sjacobs 247*2264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 248*2264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 249*2264Sjacobs dest); 250*2264Sjacobs else 251*2264Sjacobs status = PAPI_TEMPORARY_ERROR; 252*2264Sjacobs 253*2264Sjacobs } else if (isclass(dest) != 0) { 254*2264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 255*2264Sjacobs 256*2264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 257*2264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 258*2264Sjacobs dest); 259*2264Sjacobs else 260*2264Sjacobs status = PAPI_TEMPORARY_ERROR; 261*2264Sjacobs 262*2264Sjacobs } else 263*2264Sjacobs status = PAPI_NOT_FOUND; 264*2264Sjacobs 265*2264Sjacobs free(dest); 266*2264Sjacobs 267*2264Sjacobs return (status); 2680Sstevel@tonic-gate } 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate papi_status_t 271*2264Sjacobs papiPrinterModify(papi_service_t handle, char *name, 272*2264Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 273*2264Sjacobs { 274*2264Sjacobs papi_status_t status; 275*2264Sjacobs printer_t *p = NULL; 276*2264Sjacobs char *dest; 277*2264Sjacobs 278*2264Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 279*2264Sjacobs return (PAPI_BAD_ARGUMENT); 280*2264Sjacobs 281*2264Sjacobs dest = printer_name_from_uri_id(name, -1); 282*2264Sjacobs 283*2264Sjacobs if (isprinter(dest) != 0) { 284*2264Sjacobs status = lpsched_add_modify_printer(handle, dest, 285*2264Sjacobs attributes, 1); 286*2264Sjacobs 287*2264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 288*2264Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 289*2264Sjacobs dest); 290*2264Sjacobs else 291*2264Sjacobs status = PAPI_TEMPORARY_ERROR; 292*2264Sjacobs } else if (isclass(dest) != 0) { 293*2264Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 294*2264Sjacobs 295*2264Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 296*2264Sjacobs lpsched_class_configuration_to_attributes(handle, p, 297*2264Sjacobs dest); 298*2264Sjacobs else 299*2264Sjacobs status = PAPI_TEMPORARY_ERROR; 300*2264Sjacobs } else 301*2264Sjacobs status = PAPI_NOT_FOUND; 302*2264Sjacobs 303*2264Sjacobs free(dest); 304*2264Sjacobs 305*2264Sjacobs return (status); 306*2264Sjacobs } 307*2264Sjacobs 308*2264Sjacobs papi_status_t 309*2264Sjacobs papiPrinterRemove(papi_service_t handle, char *name) 310*2264Sjacobs { 311*2264Sjacobs papi_status_t result; 312*2264Sjacobs char *dest; 313*2264Sjacobs 314*2264Sjacobs if ((handle == NULL) || (name == NULL)) 315*2264Sjacobs return (PAPI_BAD_ARGUMENT); 316*2264Sjacobs 317*2264Sjacobs dest = printer_name_from_uri_id(name, -1); 318*2264Sjacobs 319*2264Sjacobs if (isprinter(dest) != 0) { 320*2264Sjacobs result = lpsched_remove_printer(handle, dest); 321*2264Sjacobs } else if (isclass(dest) != 0) { 322*2264Sjacobs result = lpsched_remove_class(handle, dest); 323*2264Sjacobs } else 324*2264Sjacobs result = PAPI_NOT_FOUND; 325*2264Sjacobs 326*2264Sjacobs free(dest); 327*2264Sjacobs 328*2264Sjacobs return (result); 329*2264Sjacobs } 330*2264Sjacobs 331*2264Sjacobs papi_status_t 332*2264Sjacobs papiPrinterDisable(papi_service_t handle, char *name, char *message) 3330Sstevel@tonic-gate { 3340Sstevel@tonic-gate papi_status_t result; 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3370Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3380Sstevel@tonic-gate 3390Sstevel@tonic-gate result = lpsched_disable_printer(handle, name, message); 3400Sstevel@tonic-gate 3410Sstevel@tonic-gate return (result); 3420Sstevel@tonic-gate } 3430Sstevel@tonic-gate 3440Sstevel@tonic-gate papi_status_t 345*2264Sjacobs papiPrinterEnable(papi_service_t handle, char *name) 3460Sstevel@tonic-gate { 3470Sstevel@tonic-gate papi_status_t result; 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3500Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3510Sstevel@tonic-gate 3520Sstevel@tonic-gate result = lpsched_enable_printer(handle, name); 3530Sstevel@tonic-gate 3540Sstevel@tonic-gate return (result); 3550Sstevel@tonic-gate } 3560Sstevel@tonic-gate 3570Sstevel@tonic-gate papi_status_t 358*2264Sjacobs papiPrinterPause(papi_service_t handle, char *name, char *message) 359*2264Sjacobs { 360*2264Sjacobs papi_status_t result; 361*2264Sjacobs 362*2264Sjacobs if ((handle == NULL) || (name == NULL)) 363*2264Sjacobs return (PAPI_BAD_ARGUMENT); 364*2264Sjacobs 365*2264Sjacobs result = lpsched_reject_printer(handle, name, message); 366*2264Sjacobs 367*2264Sjacobs return (result); 368*2264Sjacobs } 369*2264Sjacobs 370*2264Sjacobs papi_status_t 371*2264Sjacobs papiPrinterResume(papi_service_t handle, char *name) 372*2264Sjacobs { 373*2264Sjacobs papi_status_t result; 374*2264Sjacobs 375*2264Sjacobs if ((handle == NULL) || (name == NULL)) 376*2264Sjacobs return (PAPI_BAD_ARGUMENT); 377*2264Sjacobs 378*2264Sjacobs result = lpsched_accept_printer(handle, name); 379*2264Sjacobs 380*2264Sjacobs return (result); 381*2264Sjacobs } 382*2264Sjacobs 383*2264Sjacobs papi_status_t 384*2264Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) 3850Sstevel@tonic-gate { 3860Sstevel@tonic-gate service_t *svc = handle; 3870Sstevel@tonic-gate papi_status_t result = PAPI_OK_SUBST; 3880Sstevel@tonic-gate short more; 3890Sstevel@tonic-gate long status; 3900Sstevel@tonic-gate char *dest; 3910Sstevel@tonic-gate char *req_id; 3920Sstevel@tonic-gate 3930Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3940Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3950Sstevel@tonic-gate 3960Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 397*2264Sjacobs more = snd_msg(svc, S_CANCEL, dest, "", ""); 398*2264Sjacobs free(dest); 399*2264Sjacobs if (more < 0) 4000Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate do { 4030Sstevel@tonic-gate if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0) 4040Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4050Sstevel@tonic-gate 4060Sstevel@tonic-gate switch (status) { 4070Sstevel@tonic-gate case MOK: 4080Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4090Sstevel@tonic-gate "canceled-jobs", req_id); 4100Sstevel@tonic-gate break; 4110Sstevel@tonic-gate case M2LATE: 4120Sstevel@tonic-gate case MUNKNOWN: 4130Sstevel@tonic-gate case MNOINFO: 4140Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4150Sstevel@tonic-gate "cancel-failed", req_id); 4160Sstevel@tonic-gate result = PAPI_DEVICE_ERROR; 4170Sstevel@tonic-gate break; 4180Sstevel@tonic-gate case MNOPERM: 4190Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4200Sstevel@tonic-gate "cancel-failed", req_id); 4210Sstevel@tonic-gate result = PAPI_NOT_AUTHORIZED; 4220Sstevel@tonic-gate break; 4230Sstevel@tonic-gate default: 4240Sstevel@tonic-gate detailed_error(svc, gettext("cancel failed, bad status (%d)\n"), 4250Sstevel@tonic-gate status); 4260Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 4270Sstevel@tonic-gate } 4280Sstevel@tonic-gate } while (more == MOKMORE); 4290Sstevel@tonic-gate 4300Sstevel@tonic-gate return (result); 4310Sstevel@tonic-gate } 4320Sstevel@tonic-gate 4330Sstevel@tonic-gate papi_status_t 434*2264Sjacobs papiPrinterListJobs(papi_service_t handle, char *name, 435*2264Sjacobs char **requested_attrs, int type_mask, 436*2264Sjacobs int max_num_jobs, papi_job_t **jobs) 4370Sstevel@tonic-gate { 4380Sstevel@tonic-gate service_t *svc = handle; 4390Sstevel@tonic-gate char *dest; 4400Sstevel@tonic-gate short rc; 4410Sstevel@tonic-gate int count = 1; 4420Sstevel@tonic-gate 4430Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (jobs == NULL)) 4440Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 4450Sstevel@tonic-gate 4460Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate rc = snd_msg(svc, S_INQUIRE_REQUEST_RANK, 0, "", dest, "", "", ""); 4490Sstevel@tonic-gate free(dest); 4500Sstevel@tonic-gate if (rc < 0) 4510Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4520Sstevel@tonic-gate 4530Sstevel@tonic-gate do { 4540Sstevel@tonic-gate job_t *job = NULL; 4550Sstevel@tonic-gate char *dest = NULL, 4560Sstevel@tonic-gate *ptr, 4570Sstevel@tonic-gate *form = NULL, 4580Sstevel@tonic-gate *req_id = NULL, 4590Sstevel@tonic-gate *charset = NULL, 4600Sstevel@tonic-gate *owner = NULL, 4611676Sjpk *slabel = NULL, 4620Sstevel@tonic-gate *file = NULL; 4630Sstevel@tonic-gate time_t date = 0; 4640Sstevel@tonic-gate size_t size = 0; 4650Sstevel@tonic-gate short rank = 0, state = 0; 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_REQUEST_RANK, &rc, &req_id, 4681676Sjpk &owner, &slabel, &size, &date, &state, &dest, 4691676Sjpk &form, &charset, &rank, &file) < 0) 4700Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4710Sstevel@tonic-gate 4720Sstevel@tonic-gate if ((rc != MOK) && (rc != MOKMORE)) 4730Sstevel@tonic-gate continue; 4740Sstevel@tonic-gate /* 4750Sstevel@tonic-gate * at this point, we should check to see if the job matches the 4760Sstevel@tonic-gate * selection criterion defined in "type_mask". 4770Sstevel@tonic-gate */ 4780Sstevel@tonic-gate 4790Sstevel@tonic-gate /* too many yet? */ 4800Sstevel@tonic-gate if ((max_num_jobs != 0) && (count++ > max_num_jobs)) 4810Sstevel@tonic-gate continue; 4820Sstevel@tonic-gate 4830Sstevel@tonic-gate if ((job = calloc(1, sizeof (*job))) == NULL) 4840Sstevel@tonic-gate continue; 4850Sstevel@tonic-gate 4861676Sjpk job_status_to_attributes(job, req_id, owner, slabel, size, 4871676Sjpk date, state, dest, form, charset, rank, file); 4880Sstevel@tonic-gate 4890Sstevel@tonic-gate if ((ptr = strrchr(file, '-')) != NULL) { 4900Sstevel@tonic-gate *++ptr = '0'; 4910Sstevel@tonic-gate *++ptr = NULL; 4920Sstevel@tonic-gate } 4930Sstevel@tonic-gate 4940Sstevel@tonic-gate lpsched_read_job_configuration(svc, job, file); 4950Sstevel@tonic-gate 4960Sstevel@tonic-gate list_append(jobs, job); 4970Sstevel@tonic-gate 4980Sstevel@tonic-gate } while (rc == MOKMORE); 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate if (rc == MNOINFO) /* If no jobs are found, it's still ok */ 5010Sstevel@tonic-gate rc = MOK; 5020Sstevel@tonic-gate 5030Sstevel@tonic-gate return (lpsched_status_to_papi_status(rc)); 5040Sstevel@tonic-gate } 5050Sstevel@tonic-gate 5060Sstevel@tonic-gate papi_attribute_t ** 5070Sstevel@tonic-gate papiPrinterGetAttributeList(papi_printer_t printer) 5080Sstevel@tonic-gate { 5090Sstevel@tonic-gate printer_t *tmp = printer; 5100Sstevel@tonic-gate 5110Sstevel@tonic-gate if (tmp == NULL) 5120Sstevel@tonic-gate return (NULL); 5130Sstevel@tonic-gate 5140Sstevel@tonic-gate return (tmp->attributes); 5150Sstevel@tonic-gate } 516