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*9855SNagaraj.Yedathore@Sun.COM * Copyright 2009 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 #include <stdlib.h>
312264Sjacobs #include <strings.h>
322264Sjacobs #include <papi_impl.h>
33*9855SNagaraj.Yedathore@Sun.COM #include <libintl.h>
342264Sjacobs
352264Sjacobs static int
contains(char * value,char ** list)362264Sjacobs contains(char *value, char **list)
372264Sjacobs {
382264Sjacobs int i;
392264Sjacobs
402264Sjacobs if ((value == NULL) || (list == NULL))
412264Sjacobs return (1);
422264Sjacobs
432264Sjacobs for (i = 0; list[i] != NULL; i++)
442264Sjacobs if (strcasecmp(value, list[i]) == 0)
452264Sjacobs return (1);
462264Sjacobs
472264Sjacobs return (0);
482264Sjacobs }
492264Sjacobs
502264Sjacobs papi_status_t
papiPrinterQuery(papi_service_t handle,char * name,char ** requested_attrs,papi_attribute_t ** job_attributes,papi_printer_t * printer)512264Sjacobs papiPrinterQuery(papi_service_t handle, char *name,
522264Sjacobs char **requested_attrs,
532264Sjacobs papi_attribute_t **job_attributes,
542264Sjacobs papi_printer_t *printer)
552264Sjacobs {
562264Sjacobs papi_status_t status;
572264Sjacobs service_t *svc = handle;
582264Sjacobs printer_t *p = NULL;
592264Sjacobs
602264Sjacobs if ((svc == NULL) || (name == NULL) || (printer == NULL))
612264Sjacobs return (PAPI_BAD_ARGUMENT);
622264Sjacobs
632264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK) {
642264Sjacobs *printer = NULL;
652264Sjacobs
662264Sjacobs if ((contains("printer-state", requested_attrs) == 1) ||
672264Sjacobs (contains("printer-state-reasons", requested_attrs) == 1))
682264Sjacobs status = lpd_find_printer_info(svc,
69*9855SNagaraj.Yedathore@Sun.COM (printer_t **)printer);
702264Sjacobs
712264Sjacobs if ((status == PAPI_OK) && (*printer == NULL)) {
722264Sjacobs char buf[BUFSIZ];
732264Sjacobs
742264Sjacobs *printer = p = calloc(1, sizeof (*p));
752264Sjacobs
762264Sjacobs papiAttributeListAddString(&(p->attributes),
77*9855SNagaraj.Yedathore@Sun.COM PAPI_ATTR_APPEND, "printer-name",
78*9855SNagaraj.Yedathore@Sun.COM queue_name_from_uri(svc->uri));
792264Sjacobs
802264Sjacobs if (uri_to_string(svc->uri, buf, sizeof (buf)) == 0)
812264Sjacobs papiAttributeListAddString(&(p->attributes),
82*9855SNagaraj.Yedathore@Sun.COM PAPI_ATTR_APPEND,
83*9855SNagaraj.Yedathore@Sun.COM "printer-uri-supported", buf);
842264Sjacobs }
854043Swendyp /* Set printer accepting: mimic prepapi behavior */
864043Swendyp if ((p = *printer) != NULL)
874043Swendyp papiAttributeListAddBoolean(&(p->attributes),
88*9855SNagaraj.Yedathore@Sun.COM PAPI_ATTR_REPLACE,
89*9855SNagaraj.Yedathore@Sun.COM "printer-is-accepting-jobs", PAPI_TRUE);
904043Swendyp
912264Sjacobs }
922264Sjacobs
932264Sjacobs return (status);
942264Sjacobs }
952264Sjacobs
962264Sjacobs papi_status_t
papiPrinterPurgeJobs(papi_service_t handle,char * name,papi_job_t ** jobs)972264Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs)
982264Sjacobs {
992264Sjacobs papi_status_t status;
1002264Sjacobs service_t *svc = handle;
1012264Sjacobs
1022264Sjacobs if ((svc == NULL) || (name == NULL))
1032264Sjacobs return (PAPI_BAD_ARGUMENT);
1042264Sjacobs
1052264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK)
1062264Sjacobs status = lpd_purge_jobs(svc, (job_t ***)jobs);
1072264Sjacobs
1082264Sjacobs return (status);
1092264Sjacobs }
1102264Sjacobs
1112264Sjacobs papi_status_t
papiPrinterListJobs(papi_service_t handle,char * name,char ** requested_attrs,int type_mask,int max_num_jobs,papi_job_t ** jobs)1122264Sjacobs papiPrinterListJobs(papi_service_t handle, char *name,
1132264Sjacobs char **requested_attrs, int type_mask,
1142264Sjacobs int max_num_jobs, papi_job_t **jobs)
1152264Sjacobs {
1162264Sjacobs papi_status_t status;
1172264Sjacobs service_t *svc = handle;
1182264Sjacobs
1192264Sjacobs if ((svc == NULL) || (name == NULL) || (jobs == NULL))
1202264Sjacobs return (PAPI_BAD_ARGUMENT);
1212264Sjacobs
1222264Sjacobs if ((status = service_fill_in(svc, name)) == PAPI_OK)
1232264Sjacobs status = lpd_find_jobs_info(svc, (job_t ***)jobs);
1242264Sjacobs
1252264Sjacobs return (status);
1262264Sjacobs }
1272264Sjacobs
1282264Sjacobs papi_attribute_t **
papiPrinterGetAttributeList(papi_printer_t printer)1292264Sjacobs papiPrinterGetAttributeList(papi_printer_t printer)
1302264Sjacobs {
1312264Sjacobs printer_t *p = printer;
1322264Sjacobs
1332264Sjacobs if (p == NULL)
1342264Sjacobs return (NULL);
1352264Sjacobs
1362264Sjacobs return (p->attributes);
1372264Sjacobs }
1382264Sjacobs
1392264Sjacobs void
papiPrinterFree(papi_printer_t printer)1402264Sjacobs papiPrinterFree(papi_printer_t printer)
1412264Sjacobs {
1422264Sjacobs printer_t *p = printer;
1432264Sjacobs
1442264Sjacobs if (p != NULL) {
1452264Sjacobs if (p->attributes != NULL)
1462264Sjacobs papiAttributeListFree(p->attributes);
1472264Sjacobs free(p);
1482264Sjacobs }
1492264Sjacobs }
1502264Sjacobs
1512264Sjacobs void
papiPrinterListFree(papi_printer_t * printers)1522264Sjacobs papiPrinterListFree(papi_printer_t *printers)
1532264Sjacobs {
1542264Sjacobs if (printers != NULL) {
1552264Sjacobs int i;
1562264Sjacobs
1572264Sjacobs for (i = 0; printers[i] != NULL; i++)
1582264Sjacobs papiPrinterFree(printers[i]);
1592264Sjacobs free(printers);
1602264Sjacobs }
1612264Sjacobs }
162*9855SNagaraj.Yedathore@Sun.COM
163*9855SNagaraj.Yedathore@Sun.COM
164*9855SNagaraj.Yedathore@Sun.COM papi_status_t
papiPrinterDisable(papi_service_t handle,char * name,char * message)165*9855SNagaraj.Yedathore@Sun.COM papiPrinterDisable(papi_service_t handle, char *name, char *message)
166*9855SNagaraj.Yedathore@Sun.COM {
167*9855SNagaraj.Yedathore@Sun.COM service_t *svc = handle;
168*9855SNagaraj.Yedathore@Sun.COM papi_status_t status;
169*9855SNagaraj.Yedathore@Sun.COM
170*9855SNagaraj.Yedathore@Sun.COM if ((status = service_fill_in(svc, name)) == PAPI_OK) {
171*9855SNagaraj.Yedathore@Sun.COM detailed_error(svc,
172*9855SNagaraj.Yedathore@Sun.COM gettext("Warning: %s is remote, disable has no meaning."),
173*9855SNagaraj.Yedathore@Sun.COM queue_name_from_uri(svc->uri));
174*9855SNagaraj.Yedathore@Sun.COM }
175*9855SNagaraj.Yedathore@Sun.COM return (PAPI_OPERATION_NOT_SUPPORTED);
176*9855SNagaraj.Yedathore@Sun.COM }
177*9855SNagaraj.Yedathore@Sun.COM
178*9855SNagaraj.Yedathore@Sun.COM papi_status_t
papiPrinterEnable(papi_service_t handle,char * name)179*9855SNagaraj.Yedathore@Sun.COM papiPrinterEnable(papi_service_t handle, char *name)
180*9855SNagaraj.Yedathore@Sun.COM {
181*9855SNagaraj.Yedathore@Sun.COM service_t *svc = handle;
182*9855SNagaraj.Yedathore@Sun.COM papi_status_t status;
183*9855SNagaraj.Yedathore@Sun.COM
184*9855SNagaraj.Yedathore@Sun.COM if ((status = service_fill_in(svc, name)) == PAPI_OK) {
185*9855SNagaraj.Yedathore@Sun.COM detailed_error(svc,
186*9855SNagaraj.Yedathore@Sun.COM gettext("Warning: %s is remote, enable has no meaning."),
187*9855SNagaraj.Yedathore@Sun.COM queue_name_from_uri(svc->uri));
188*9855SNagaraj.Yedathore@Sun.COM }
189*9855SNagaraj.Yedathore@Sun.COM return (PAPI_OPERATION_NOT_SUPPORTED);
190*9855SNagaraj.Yedathore@Sun.COM }
191*9855SNagaraj.Yedathore@Sun.COM
192*9855SNagaraj.Yedathore@Sun.COM
193*9855SNagaraj.Yedathore@Sun.COM papi_status_t
papiPrinterResume(papi_service_t handle,char * name)194*9855SNagaraj.Yedathore@Sun.COM papiPrinterResume(papi_service_t handle, char *name)
195*9855SNagaraj.Yedathore@Sun.COM {
196*9855SNagaraj.Yedathore@Sun.COM service_t *svc = handle;
197*9855SNagaraj.Yedathore@Sun.COM papi_status_t status;
198*9855SNagaraj.Yedathore@Sun.COM
199*9855SNagaraj.Yedathore@Sun.COM if ((status = service_fill_in(svc, name)) == PAPI_OK) {
200*9855SNagaraj.Yedathore@Sun.COM detailed_error(svc,
201*9855SNagaraj.Yedathore@Sun.COM gettext("Warning: %s is remote, accept has no meaning."),
202*9855SNagaraj.Yedathore@Sun.COM queue_name_from_uri(svc->uri));
203*9855SNagaraj.Yedathore@Sun.COM }
204*9855SNagaraj.Yedathore@Sun.COM return (PAPI_OPERATION_NOT_SUPPORTED);
205*9855SNagaraj.Yedathore@Sun.COM }
206*9855SNagaraj.Yedathore@Sun.COM
207*9855SNagaraj.Yedathore@Sun.COM
208*9855SNagaraj.Yedathore@Sun.COM papi_status_t
papiPrinterPause(papi_service_t handle,char * name,char * message)209*9855SNagaraj.Yedathore@Sun.COM papiPrinterPause(papi_service_t handle, char *name, char *message)
210*9855SNagaraj.Yedathore@Sun.COM {
211*9855SNagaraj.Yedathore@Sun.COM service_t *svc = handle;
212*9855SNagaraj.Yedathore@Sun.COM papi_status_t status;
213*9855SNagaraj.Yedathore@Sun.COM
214*9855SNagaraj.Yedathore@Sun.COM if ((status = service_fill_in(svc, name)) == PAPI_OK) {
215*9855SNagaraj.Yedathore@Sun.COM detailed_error(svc,
216*9855SNagaraj.Yedathore@Sun.COM gettext("Warning: %s is remote, reject has no meaning."),
217*9855SNagaraj.Yedathore@Sun.COM queue_name_from_uri(svc->uri));
218*9855SNagaraj.Yedathore@Sun.COM }
219*9855SNagaraj.Yedathore@Sun.COM return (PAPI_OPERATION_NOT_SUPPORTED);
220*9855SNagaraj.Yedathore@Sun.COM }
221