12264Sjacobs /* 22264Sjacobs * CDDL HEADER START 32264Sjacobs * 42264Sjacobs * The contents of this file are subject to the terms of the 52264Sjacobs * Common Development and Distribution License (the "License"). 62264Sjacobs * You may not use this file except in compliance with the License. 72264Sjacobs * 82264Sjacobs * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 92264Sjacobs * or http://www.opensolaris.org/os/licensing. 102264Sjacobs * See the License for the specific language governing permissions 112264Sjacobs * and limitations under the License. 122264Sjacobs * 132264Sjacobs * When distributing Covered Code, include this CDDL HEADER in each 142264Sjacobs * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 152264Sjacobs * If applicable, add the following below this CDDL HEADER, with the 162264Sjacobs * fields enclosed by brackets "[]" replaced with your own identifying 172264Sjacobs * information: Portions Copyright [yyyy] [name of copyright owner] 182264Sjacobs * 192264Sjacobs * CDDL HEADER END 202264Sjacobs */ 212264Sjacobs 222264Sjacobs /* 23*4043Swendyp * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 242264Sjacobs * Use is subject to license terms. 252264Sjacobs * 262264Sjacobs */ 272264Sjacobs 282264Sjacobs /* $Id: printer.c 149 2006-04-25 16:55:01Z njacobs $ */ 292264Sjacobs 302264Sjacobs #pragma ident "%Z%%M% %I% %E% SMI" 312264Sjacobs 322264Sjacobs #include <stdlib.h> 332264Sjacobs #include <strings.h> 342264Sjacobs #include <papi_impl.h> 352264Sjacobs 362264Sjacobs static int 372264Sjacobs contains(char *value, char **list) 382264Sjacobs { 392264Sjacobs int i; 402264Sjacobs 412264Sjacobs if ((value == NULL) || (list == NULL)) 422264Sjacobs return (1); 432264Sjacobs 442264Sjacobs for (i = 0; list[i] != NULL; i++) 452264Sjacobs if (strcasecmp(value, list[i]) == 0) 462264Sjacobs return (1); 472264Sjacobs 482264Sjacobs return (0); 492264Sjacobs } 502264Sjacobs 512264Sjacobs papi_status_t 522264Sjacobs papiPrinterQuery(papi_service_t handle, char *name, 532264Sjacobs char **requested_attrs, 542264Sjacobs papi_attribute_t **job_attributes, 552264Sjacobs papi_printer_t *printer) 562264Sjacobs { 572264Sjacobs papi_status_t status; 582264Sjacobs service_t *svc = handle; 592264Sjacobs printer_t *p = NULL; 602264Sjacobs 612264Sjacobs if ((svc == NULL) || (name == NULL) || (printer == NULL)) 622264Sjacobs return (PAPI_BAD_ARGUMENT); 632264Sjacobs 642264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK) { 652264Sjacobs *printer = NULL; 662264Sjacobs 672264Sjacobs if ((contains("printer-state", requested_attrs) == 1) || 682264Sjacobs (contains("printer-state-reasons", requested_attrs) == 1)) 692264Sjacobs status = lpd_find_printer_info(svc, 702264Sjacobs (printer_t **)printer); 712264Sjacobs 722264Sjacobs if ((status == PAPI_OK) && (*printer == NULL)) { 732264Sjacobs char buf[BUFSIZ]; 742264Sjacobs 752264Sjacobs *printer = p = calloc(1, sizeof (*p)); 762264Sjacobs 772264Sjacobs papiAttributeListAddString(&(p->attributes), 782264Sjacobs PAPI_ATTR_APPEND, "printer-name", 792264Sjacobs queue_name_from_uri(svc->uri)); 802264Sjacobs 812264Sjacobs if (uri_to_string(svc->uri, buf, sizeof (buf)) == 0) 822264Sjacobs papiAttributeListAddString(&(p->attributes), 832264Sjacobs PAPI_ATTR_APPEND, 842264Sjacobs "printer-uri-supported", buf); 852264Sjacobs } 86*4043Swendyp /* Set printer accepting: mimic prepapi behavior */ 87*4043Swendyp if ((p = *printer) != NULL) 88*4043Swendyp papiAttributeListAddBoolean(&(p->attributes), 89*4043Swendyp PAPI_ATTR_REPLACE, 90*4043Swendyp "printer-is-accepting-jobs", PAPI_TRUE); 91*4043Swendyp 922264Sjacobs } 932264Sjacobs 942264Sjacobs return (status); 952264Sjacobs } 962264Sjacobs 972264Sjacobs papi_status_t 982264Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs) 992264Sjacobs { 1002264Sjacobs papi_status_t status; 1012264Sjacobs service_t *svc = handle; 1022264Sjacobs 1032264Sjacobs if ((svc == NULL) || (name == NULL)) 1042264Sjacobs return (PAPI_BAD_ARGUMENT); 1052264Sjacobs 1062264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK) 1072264Sjacobs status = lpd_purge_jobs(svc, (job_t ***)jobs); 1082264Sjacobs 1092264Sjacobs return (status); 1102264Sjacobs } 1112264Sjacobs 1122264Sjacobs papi_status_t 1132264Sjacobs papiPrinterListJobs(papi_service_t handle, char *name, 1142264Sjacobs char **requested_attrs, int type_mask, 1152264Sjacobs int max_num_jobs, papi_job_t **jobs) 1162264Sjacobs { 1172264Sjacobs papi_status_t status; 1182264Sjacobs service_t *svc = handle; 1192264Sjacobs 1202264Sjacobs if ((svc == NULL) || (name == NULL) || (jobs == NULL)) 1212264Sjacobs return (PAPI_BAD_ARGUMENT); 1222264Sjacobs 1232264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK) 1242264Sjacobs status = lpd_find_jobs_info(svc, (job_t ***)jobs); 1252264Sjacobs 1262264Sjacobs return (status); 1272264Sjacobs } 1282264Sjacobs 1292264Sjacobs papi_attribute_t ** 1302264Sjacobs papiPrinterGetAttributeList(papi_printer_t printer) 1312264Sjacobs { 1322264Sjacobs printer_t *p = printer; 1332264Sjacobs 1342264Sjacobs if (p == NULL) 1352264Sjacobs return (NULL); 1362264Sjacobs 1372264Sjacobs return (p->attributes); 1382264Sjacobs } 1392264Sjacobs 1402264Sjacobs void 1412264Sjacobs papiPrinterFree(papi_printer_t printer) 1422264Sjacobs { 1432264Sjacobs printer_t *p = printer; 1442264Sjacobs 1452264Sjacobs if (p != NULL) { 1462264Sjacobs if (p->attributes != NULL) 1472264Sjacobs papiAttributeListFree(p->attributes); 1482264Sjacobs free(p); 1492264Sjacobs } 1502264Sjacobs } 1512264Sjacobs 1522264Sjacobs void 1532264Sjacobs papiPrinterListFree(papi_printer_t *printers) 1542264Sjacobs { 1552264Sjacobs if (printers != NULL) { 1562264Sjacobs int i; 1572264Sjacobs 1582264Sjacobs for (i = 0; printers[i] != NULL; i++) 1592264Sjacobs papiPrinterFree(printers[i]); 1602264Sjacobs free(printers); 1612264Sjacobs } 1622264Sjacobs } 163