17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*c389c7f8SGowtham Thommandra * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <string.h> 317c478bd9Sstevel@tonic-gate #include <libintl.h> 327c478bd9Sstevel@tonic-gate #include <papi_impl.h> 337c478bd9Sstevel@tonic-gate #include <lp.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate extern int isclass(char *); 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate void 387c478bd9Sstevel@tonic-gate papiPrinterFree(papi_printer_t printer) 397c478bd9Sstevel@tonic-gate { 407c478bd9Sstevel@tonic-gate printer_t *tmp = printer; 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate if (tmp != NULL) { 437c478bd9Sstevel@tonic-gate papiAttributeListFree(tmp->attributes); 447c478bd9Sstevel@tonic-gate free(tmp); 457c478bd9Sstevel@tonic-gate } 467c478bd9Sstevel@tonic-gate } 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate void 497c478bd9Sstevel@tonic-gate papiPrinterListFree(papi_printer_t *printers) 507c478bd9Sstevel@tonic-gate { 517c478bd9Sstevel@tonic-gate if (printers != NULL) { 527c478bd9Sstevel@tonic-gate int i; 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate for (i = 0; printers[i] != NULL; i++) 557c478bd9Sstevel@tonic-gate papiPrinterFree(printers[i]); 567c478bd9Sstevel@tonic-gate free(printers); 577c478bd9Sstevel@tonic-gate } 587c478bd9Sstevel@tonic-gate } 597c478bd9Sstevel@tonic-gate 607c478bd9Sstevel@tonic-gate papi_status_t 61355b4669Sjacobs papiPrintersList(papi_service_t handle, char **requested_attrs, 62355b4669Sjacobs papi_filter_t *filter, papi_printer_t **printers) 637c478bd9Sstevel@tonic-gate { 647c478bd9Sstevel@tonic-gate service_t *svc = handle; 657c478bd9Sstevel@tonic-gate printer_t *p = NULL; 667c478bd9Sstevel@tonic-gate short status = MOK; 677c478bd9Sstevel@tonic-gate char *printer = NULL, 687c478bd9Sstevel@tonic-gate *form = NULL, 697c478bd9Sstevel@tonic-gate *request_id = NULL, 707c478bd9Sstevel@tonic-gate *character_set = NULL, 717c478bd9Sstevel@tonic-gate *reject_reason = NULL, 727c478bd9Sstevel@tonic-gate *disable_reason = NULL; 737c478bd9Sstevel@tonic-gate short printer_status = 0; 747c478bd9Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 757c478bd9Sstevel@tonic-gate 767c478bd9Sstevel@tonic-gate if ((handle == NULL) || (printers == NULL)) 777c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate if ((filter == NULL) || 807c478bd9Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_LOCAL) == 817c478bd9Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_LOCAL))) { 827c478bd9Sstevel@tonic-gate /* ask the spooler for the printer(s) and state */ 837c478bd9Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, NAME_ALL) < 0) 847c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 857c478bd9Sstevel@tonic-gate 867c478bd9Sstevel@tonic-gate do { 877c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, 887c478bd9Sstevel@tonic-gate &printer, &form, &character_set, 897c478bd9Sstevel@tonic-gate &disable_reason, &reject_reason, 907c478bd9Sstevel@tonic-gate &printer_status, &request_id, 917c478bd9Sstevel@tonic-gate &enable_date, &reject_date) < 0) 927c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 957c478bd9Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(svc, p, 987c478bd9Sstevel@tonic-gate printer); 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate printer_status_to_attributes(p, printer, form, 1017c478bd9Sstevel@tonic-gate character_set, disable_reason, 1027c478bd9Sstevel@tonic-gate reject_reason, printer_status, 1037c478bd9Sstevel@tonic-gate request_id, enable_date, reject_date); 1047c478bd9Sstevel@tonic-gate 1057c478bd9Sstevel@tonic-gate list_append(printers, p); 1067c478bd9Sstevel@tonic-gate 1077c478bd9Sstevel@tonic-gate } while (status == MOKMORE); 1087c478bd9Sstevel@tonic-gate } 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if ((filter == NULL) || 1117c478bd9Sstevel@tonic-gate ((filter->filter.bitmask.mask & PAPI_PRINTER_CLASS) == 1127c478bd9Sstevel@tonic-gate (filter->filter.bitmask.value & PAPI_PRINTER_CLASS))) { 1137c478bd9Sstevel@tonic-gate /* ask the spooler for the class(es) and state */ 1147c478bd9Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, NAME_ALL) < 0) 1157c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1167c478bd9Sstevel@tonic-gate 1177c478bd9Sstevel@tonic-gate do { 1187c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &printer, 1197c478bd9Sstevel@tonic-gate &printer_status, &reject_reason, 1207c478bd9Sstevel@tonic-gate &reject_date) < 0) 1217c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate if ((p = calloc(1, sizeof (*p))) == NULL) 1247c478bd9Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1257c478bd9Sstevel@tonic-gate 1267c478bd9Sstevel@tonic-gate lpsched_class_configuration_to_attributes(svc, p, 1277c478bd9Sstevel@tonic-gate printer); 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate class_status_to_attributes(p, printer, printer_status, 1307c478bd9Sstevel@tonic-gate reject_reason, reject_date); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate list_append(printers, p); 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate } while (status == MOKMORE); 1357c478bd9Sstevel@tonic-gate } 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate return (PAPI_OK); 1387c478bd9Sstevel@tonic-gate } 1397c478bd9Sstevel@tonic-gate 1407c478bd9Sstevel@tonic-gate papi_status_t 141355b4669Sjacobs papiPrinterQuery(papi_service_t handle, char *name, 142355b4669Sjacobs char **requested_attrs, 143355b4669Sjacobs papi_attribute_t **job_attrs, 1447c478bd9Sstevel@tonic-gate papi_printer_t *printer) 1457c478bd9Sstevel@tonic-gate { 1467c478bd9Sstevel@tonic-gate papi_status_t pst; 1477c478bd9Sstevel@tonic-gate service_t *svc = handle; 1487c478bd9Sstevel@tonic-gate printer_t *p = NULL; 1497c478bd9Sstevel@tonic-gate char *dest; 1507c478bd9Sstevel@tonic-gate short status = MOK; 1517c478bd9Sstevel@tonic-gate char *pname = NULL, 1527c478bd9Sstevel@tonic-gate *form = NULL, 1537c478bd9Sstevel@tonic-gate *request_id = NULL, 1547c478bd9Sstevel@tonic-gate *character_set = NULL, 1557c478bd9Sstevel@tonic-gate *reject_reason = NULL, 1567c478bd9Sstevel@tonic-gate *disable_reason = NULL; 1577c478bd9Sstevel@tonic-gate short printer_status = 0; 1587c478bd9Sstevel@tonic-gate long enable_date = 0, reject_date = 0; 1597c478bd9Sstevel@tonic-gate 1607c478bd9Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (printer == NULL)) 1617c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate if ((*printer = p = calloc(1, sizeof (*p))) == NULL) 1647c478bd9Sstevel@tonic-gate return (PAPI_TEMPORARY_ERROR); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 1677c478bd9Sstevel@tonic-gate 168355b4669Sjacobs if (strcmp(dest, "_default") == 0) { 169355b4669Sjacobs static char *_default; 170355b4669Sjacobs 171355b4669Sjacobs if (_default == NULL) { 172355b4669Sjacobs int fd; 173355b4669Sjacobs static char buf[128]; 174355b4669Sjacobs 175355b4669Sjacobs if ((fd = open("/etc/lp/default", O_RDONLY)) >= 0) { 176355b4669Sjacobs read(fd, buf, sizeof (buf)); 177355b4669Sjacobs close(fd); 178355b4669Sjacobs _default = strtok(buf, " \t\n"); 179355b4669Sjacobs } 180355b4669Sjacobs } 181355b4669Sjacobs dest = _default; 182355b4669Sjacobs } 183355b4669Sjacobs 1847c478bd9Sstevel@tonic-gate if (isprinter(dest) != 0) { 1857c478bd9Sstevel@tonic-gate pst = lpsched_printer_configuration_to_attributes(svc, p, dest); 1867c478bd9Sstevel@tonic-gate if (pst != PAPI_OK) 1877c478bd9Sstevel@tonic-gate return (pst); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate /* get the spooler status data now */ 1907c478bd9Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_PRINTER_STATUS, dest) < 0) 1917c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_PRINTER_STATUS, &status, &pname, 1947c478bd9Sstevel@tonic-gate &form, &character_set, &disable_reason, 1957c478bd9Sstevel@tonic-gate &reject_reason, &printer_status, &request_id, 1967c478bd9Sstevel@tonic-gate &enable_date, &reject_date) < 0) 1977c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 1987c478bd9Sstevel@tonic-gate 1997c478bd9Sstevel@tonic-gate printer_status_to_attributes(p, pname, form, character_set, 2007c478bd9Sstevel@tonic-gate disable_reason, reject_reason, printer_status, 2017c478bd9Sstevel@tonic-gate request_id, enable_date, reject_date); 2027c478bd9Sstevel@tonic-gate } else if (isclass(dest) != 0) { 2037c478bd9Sstevel@tonic-gate pst = lpsched_class_configuration_to_attributes(svc, p, dest); 2047c478bd9Sstevel@tonic-gate if (pst != PAPI_OK) 2057c478bd9Sstevel@tonic-gate return (pst); 2067c478bd9Sstevel@tonic-gate 2077c478bd9Sstevel@tonic-gate /* get the spooler status data now */ 2087c478bd9Sstevel@tonic-gate if (snd_msg(svc, S_INQUIRE_CLASS, dest) < 0) 2097c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2107c478bd9Sstevel@tonic-gate 2117c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_CLASS, &status, &pname, 2127c478bd9Sstevel@tonic-gate &printer_status, &reject_reason, 2137c478bd9Sstevel@tonic-gate &reject_date) < 0) 2147c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate class_status_to_attributes(p, pname, printer_status, 2177c478bd9Sstevel@tonic-gate reject_reason, reject_date); 2187c478bd9Sstevel@tonic-gate } else if (strcmp(dest, "PrintService") == 0) { 2197c478bd9Sstevel@tonic-gate /* fill the printer object with service information */ 220355b4669Sjacobs lpsched_service_information(&p->attributes); 2217c478bd9Sstevel@tonic-gate } else 2227c478bd9Sstevel@tonic-gate return (PAPI_NOT_FOUND); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate free(dest); 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate return (PAPI_OK); 2277c478bd9Sstevel@tonic-gate } 2287c478bd9Sstevel@tonic-gate 2297c478bd9Sstevel@tonic-gate papi_status_t 230355b4669Sjacobs papiPrinterAdd(papi_service_t handle, char *name, 231355b4669Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 2327c478bd9Sstevel@tonic-gate { 233355b4669Sjacobs papi_status_t status; 234355b4669Sjacobs printer_t *p = NULL; 235355b4669Sjacobs char *dest; 2367c478bd9Sstevel@tonic-gate 237355b4669Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 2387c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 2397c478bd9Sstevel@tonic-gate 240355b4669Sjacobs dest = printer_name_from_uri_id(name, -1); 241355b4669Sjacobs 242355b4669Sjacobs if (isprinter(dest) != 0) { 243355b4669Sjacobs status = lpsched_add_modify_printer(handle, dest, 244355b4669Sjacobs attributes, 0); 245355b4669Sjacobs 246355b4669Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 247355b4669Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 248355b4669Sjacobs dest); 249355b4669Sjacobs else 250355b4669Sjacobs status = PAPI_TEMPORARY_ERROR; 251355b4669Sjacobs 252355b4669Sjacobs } else if (isclass(dest) != 0) { 253355b4669Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 254355b4669Sjacobs 255355b4669Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 256355b4669Sjacobs lpsched_class_configuration_to_attributes(handle, p, 257355b4669Sjacobs dest); 258355b4669Sjacobs else 259355b4669Sjacobs status = PAPI_TEMPORARY_ERROR; 260355b4669Sjacobs 261355b4669Sjacobs } else 262355b4669Sjacobs status = PAPI_NOT_FOUND; 263355b4669Sjacobs 264355b4669Sjacobs free(dest); 265355b4669Sjacobs 266355b4669Sjacobs return (status); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate 2697c478bd9Sstevel@tonic-gate papi_status_t 270355b4669Sjacobs papiPrinterModify(papi_service_t handle, char *name, 271355b4669Sjacobs papi_attribute_t **attributes, papi_printer_t *result) 272355b4669Sjacobs { 273355b4669Sjacobs papi_status_t status; 274355b4669Sjacobs printer_t *p = NULL; 275355b4669Sjacobs char *dest; 276355b4669Sjacobs 277355b4669Sjacobs if ((handle == NULL) || (name == NULL) || (attributes == NULL)) 278355b4669Sjacobs return (PAPI_BAD_ARGUMENT); 279355b4669Sjacobs 280355b4669Sjacobs dest = printer_name_from_uri_id(name, -1); 281355b4669Sjacobs 282355b4669Sjacobs if (isprinter(dest) != 0) { 283355b4669Sjacobs status = lpsched_add_modify_printer(handle, dest, 284355b4669Sjacobs attributes, 1); 285355b4669Sjacobs 286355b4669Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 287355b4669Sjacobs lpsched_printer_configuration_to_attributes(handle, p, 288355b4669Sjacobs dest); 289355b4669Sjacobs else 290355b4669Sjacobs status = PAPI_TEMPORARY_ERROR; 291355b4669Sjacobs } else if (isclass(dest) != 0) { 292355b4669Sjacobs status = lpsched_add_modify_class(handle, dest, attributes); 293355b4669Sjacobs 294355b4669Sjacobs if ((*result = p = calloc(1, sizeof (*p))) != NULL) 295355b4669Sjacobs lpsched_class_configuration_to_attributes(handle, p, 296355b4669Sjacobs dest); 297355b4669Sjacobs else 298355b4669Sjacobs status = PAPI_TEMPORARY_ERROR; 299355b4669Sjacobs } else 300355b4669Sjacobs status = PAPI_NOT_FOUND; 301355b4669Sjacobs 302355b4669Sjacobs free(dest); 303355b4669Sjacobs 304355b4669Sjacobs return (status); 305355b4669Sjacobs } 306355b4669Sjacobs 307355b4669Sjacobs papi_status_t 308355b4669Sjacobs papiPrinterRemove(papi_service_t handle, char *name) 309355b4669Sjacobs { 310355b4669Sjacobs papi_status_t result; 311355b4669Sjacobs char *dest; 312355b4669Sjacobs 313355b4669Sjacobs if ((handle == NULL) || (name == NULL)) 314355b4669Sjacobs return (PAPI_BAD_ARGUMENT); 315355b4669Sjacobs 316355b4669Sjacobs dest = printer_name_from_uri_id(name, -1); 317355b4669Sjacobs 318355b4669Sjacobs if (isprinter(dest) != 0) { 319355b4669Sjacobs result = lpsched_remove_printer(handle, dest); 320355b4669Sjacobs } else if (isclass(dest) != 0) { 321355b4669Sjacobs result = lpsched_remove_class(handle, dest); 322355b4669Sjacobs } else 323355b4669Sjacobs result = PAPI_NOT_FOUND; 324355b4669Sjacobs 325355b4669Sjacobs free(dest); 326355b4669Sjacobs 327355b4669Sjacobs return (result); 328355b4669Sjacobs } 329355b4669Sjacobs 330355b4669Sjacobs papi_status_t 331355b4669Sjacobs papiPrinterDisable(papi_service_t handle, char *name, char *message) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate papi_status_t result; 3347c478bd9Sstevel@tonic-gate 3357c478bd9Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3367c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3377c478bd9Sstevel@tonic-gate 3387c478bd9Sstevel@tonic-gate result = lpsched_disable_printer(handle, name, message); 3397c478bd9Sstevel@tonic-gate 3407c478bd9Sstevel@tonic-gate return (result); 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate 3437c478bd9Sstevel@tonic-gate papi_status_t 344355b4669Sjacobs papiPrinterEnable(papi_service_t handle, char *name) 3457c478bd9Sstevel@tonic-gate { 3467c478bd9Sstevel@tonic-gate papi_status_t result; 3477c478bd9Sstevel@tonic-gate 3487c478bd9Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3497c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3507c478bd9Sstevel@tonic-gate 3517c478bd9Sstevel@tonic-gate result = lpsched_enable_printer(handle, name); 3527c478bd9Sstevel@tonic-gate 3537c478bd9Sstevel@tonic-gate return (result); 3547c478bd9Sstevel@tonic-gate } 3557c478bd9Sstevel@tonic-gate 3567c478bd9Sstevel@tonic-gate papi_status_t 357355b4669Sjacobs papiPrinterPause(papi_service_t handle, char *name, char *message) 358355b4669Sjacobs { 359355b4669Sjacobs papi_status_t result; 360355b4669Sjacobs 361355b4669Sjacobs if ((handle == NULL) || (name == NULL)) 362355b4669Sjacobs return (PAPI_BAD_ARGUMENT); 363355b4669Sjacobs 364355b4669Sjacobs result = lpsched_reject_printer(handle, name, message); 365355b4669Sjacobs 366355b4669Sjacobs return (result); 367355b4669Sjacobs } 368355b4669Sjacobs 369355b4669Sjacobs papi_status_t 370355b4669Sjacobs papiPrinterResume(papi_service_t handle, char *name) 371355b4669Sjacobs { 372355b4669Sjacobs papi_status_t result; 373355b4669Sjacobs 374355b4669Sjacobs if ((handle == NULL) || (name == NULL)) 375355b4669Sjacobs return (PAPI_BAD_ARGUMENT); 376355b4669Sjacobs 377355b4669Sjacobs result = lpsched_accept_printer(handle, name); 378355b4669Sjacobs 379355b4669Sjacobs return (result); 380355b4669Sjacobs } 381355b4669Sjacobs 382355b4669Sjacobs papi_status_t 383355b4669Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) 3847c478bd9Sstevel@tonic-gate { 3857c478bd9Sstevel@tonic-gate service_t *svc = handle; 3867c478bd9Sstevel@tonic-gate papi_status_t result = PAPI_OK_SUBST; 3877c478bd9Sstevel@tonic-gate short more; 3887c478bd9Sstevel@tonic-gate long status; 3897c478bd9Sstevel@tonic-gate char *dest; 3907c478bd9Sstevel@tonic-gate char *req_id; 3917c478bd9Sstevel@tonic-gate 3927c478bd9Sstevel@tonic-gate if ((handle == NULL) || (name == NULL)) 3937c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 396355b4669Sjacobs more = snd_msg(svc, S_CANCEL, dest, "", ""); 3977c478bd9Sstevel@tonic-gate free(dest); 398355b4669Sjacobs if (more < 0) 399355b4669Sjacobs return (PAPI_SERVICE_UNAVAILABLE); 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate do { 4027c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_CANCEL, &more, &status, &req_id) < 0) 4037c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate switch (status) { 4067c478bd9Sstevel@tonic-gate case MOK: 4077c478bd9Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4087c478bd9Sstevel@tonic-gate "canceled-jobs", req_id); 4097c478bd9Sstevel@tonic-gate break; 4107c478bd9Sstevel@tonic-gate case M2LATE: 4117c478bd9Sstevel@tonic-gate case MUNKNOWN: 4127c478bd9Sstevel@tonic-gate case MNOINFO: 4137c478bd9Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4147c478bd9Sstevel@tonic-gate "cancel-failed", req_id); 4157c478bd9Sstevel@tonic-gate result = PAPI_DEVICE_ERROR; 4167c478bd9Sstevel@tonic-gate break; 4177c478bd9Sstevel@tonic-gate case MNOPERM: 4187c478bd9Sstevel@tonic-gate papiAttributeListAddString(&svc->attributes, PAPI_ATTR_APPEND, 4197c478bd9Sstevel@tonic-gate "cancel-failed", req_id); 4207c478bd9Sstevel@tonic-gate result = PAPI_NOT_AUTHORIZED; 4217c478bd9Sstevel@tonic-gate break; 4227c478bd9Sstevel@tonic-gate default: 4237c478bd9Sstevel@tonic-gate detailed_error(svc, gettext("cancel failed, bad status (%d)\n"), 4247c478bd9Sstevel@tonic-gate status); 4257c478bd9Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 4267c478bd9Sstevel@tonic-gate } 4277c478bd9Sstevel@tonic-gate } while (more == MOKMORE); 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate return (result); 4307c478bd9Sstevel@tonic-gate } 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate papi_status_t 433355b4669Sjacobs papiPrinterListJobs(papi_service_t handle, char *name, 434355b4669Sjacobs char **requested_attrs, int type_mask, 435355b4669Sjacobs int max_num_jobs, papi_job_t **jobs) 4367c478bd9Sstevel@tonic-gate { 4377c478bd9Sstevel@tonic-gate service_t *svc = handle; 4387c478bd9Sstevel@tonic-gate char *dest; 4397c478bd9Sstevel@tonic-gate short rc; 4407c478bd9Sstevel@tonic-gate int count = 1; 4417c478bd9Sstevel@tonic-gate 4427c478bd9Sstevel@tonic-gate if ((handle == NULL) || (name == NULL) || (jobs == NULL)) 4437c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate dest = printer_name_from_uri_id(name, -1); 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate rc = snd_msg(svc, S_INQUIRE_REQUEST_RANK, 0, "", dest, "", "", ""); 4487c478bd9Sstevel@tonic-gate free(dest); 4497c478bd9Sstevel@tonic-gate if (rc < 0) 4507c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate do { 4537c478bd9Sstevel@tonic-gate job_t *job = NULL; 4547c478bd9Sstevel@tonic-gate char *dest = NULL, 4557c478bd9Sstevel@tonic-gate *ptr, 4567c478bd9Sstevel@tonic-gate *form = NULL, 4577c478bd9Sstevel@tonic-gate *req_id = NULL, 4587c478bd9Sstevel@tonic-gate *charset = NULL, 4597c478bd9Sstevel@tonic-gate *owner = NULL, 46045916cd2Sjpk *slabel = NULL, 4617c478bd9Sstevel@tonic-gate *file = NULL; 4627c478bd9Sstevel@tonic-gate time_t date = 0; 4637c478bd9Sstevel@tonic-gate size_t size = 0; 4647c478bd9Sstevel@tonic-gate short rank = 0, state = 0; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate if (rcv_msg(svc, R_INQUIRE_REQUEST_RANK, &rc, &req_id, 46745916cd2Sjpk &owner, &slabel, &size, &date, &state, &dest, 46845916cd2Sjpk &form, &charset, &rank, &file) < 0) 4697c478bd9Sstevel@tonic-gate return (PAPI_SERVICE_UNAVAILABLE); 4707c478bd9Sstevel@tonic-gate 4717c478bd9Sstevel@tonic-gate if ((rc != MOK) && (rc != MOKMORE)) 4727c478bd9Sstevel@tonic-gate continue; 4737c478bd9Sstevel@tonic-gate /* 4747c478bd9Sstevel@tonic-gate * at this point, we should check to see if the job matches the 4757c478bd9Sstevel@tonic-gate * selection criterion defined in "type_mask". 4767c478bd9Sstevel@tonic-gate */ 4777c478bd9Sstevel@tonic-gate 4787c478bd9Sstevel@tonic-gate /* too many yet? */ 4797c478bd9Sstevel@tonic-gate if ((max_num_jobs != 0) && (count++ > max_num_jobs)) 4807c478bd9Sstevel@tonic-gate continue; 4817c478bd9Sstevel@tonic-gate 4827c478bd9Sstevel@tonic-gate if ((job = calloc(1, sizeof (*job))) == NULL) 4837c478bd9Sstevel@tonic-gate continue; 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate if ((ptr = strrchr(file, '-')) != NULL) { 4867c478bd9Sstevel@tonic-gate *++ptr = '0'; 4877c478bd9Sstevel@tonic-gate *++ptr = NULL; 4887c478bd9Sstevel@tonic-gate } 4897c478bd9Sstevel@tonic-gate 4907c478bd9Sstevel@tonic-gate lpsched_read_job_configuration(svc, job, file); 4917c478bd9Sstevel@tonic-gate 492*c389c7f8SGowtham Thommandra job_status_to_attributes(job, req_id, owner, slabel, size, 493*c389c7f8SGowtham Thommandra date, state, dest, form, charset, rank, file); 494*c389c7f8SGowtham Thommandra 4957c478bd9Sstevel@tonic-gate list_append(jobs, job); 4967c478bd9Sstevel@tonic-gate 4977c478bd9Sstevel@tonic-gate } while (rc == MOKMORE); 4987c478bd9Sstevel@tonic-gate 4997c478bd9Sstevel@tonic-gate if (rc == MNOINFO) /* If no jobs are found, it's still ok */ 5007c478bd9Sstevel@tonic-gate rc = MOK; 5017c478bd9Sstevel@tonic-gate 5027c478bd9Sstevel@tonic-gate return (lpsched_status_to_papi_status(rc)); 5037c478bd9Sstevel@tonic-gate } 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate papi_attribute_t ** 5067c478bd9Sstevel@tonic-gate papiPrinterGetAttributeList(papi_printer_t printer) 5077c478bd9Sstevel@tonic-gate { 5087c478bd9Sstevel@tonic-gate printer_t *tmp = printer; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate if (tmp == NULL) 5117c478bd9Sstevel@tonic-gate return (NULL); 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate return (tmp->attributes); 5147c478bd9Sstevel@tonic-gate } 515