xref: /titanic_50/usr/src/lib/print/libpapi-lpd/common/printer.c (revision 999637b1fd707bd54b1bd63fa6979a3673826bd0)
1355b4669Sjacobs /*
2355b4669Sjacobs  * CDDL HEADER START
3355b4669Sjacobs  *
4355b4669Sjacobs  * The contents of this file are subject to the terms of the
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * You may not use this file except in compliance with the License.
7355b4669Sjacobs  *
8355b4669Sjacobs  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9355b4669Sjacobs  * or http://www.opensolaris.org/os/licensing.
10355b4669Sjacobs  * See the License for the specific language governing permissions
11355b4669Sjacobs  * and limitations under the License.
12355b4669Sjacobs  *
13355b4669Sjacobs  * When distributing Covered Code, include this CDDL HEADER in each
14355b4669Sjacobs  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15355b4669Sjacobs  * If applicable, add the following below this CDDL HEADER, with the
16355b4669Sjacobs  * fields enclosed by brackets "[]" replaced with your own identifying
17355b4669Sjacobs  * information: Portions Copyright [yyyy] [name of copyright owner]
18355b4669Sjacobs  *
19355b4669Sjacobs  * CDDL HEADER END
20355b4669Sjacobs  */
21355b4669Sjacobs 
22355b4669Sjacobs /*
23*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India"  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24355b4669Sjacobs  * Use is subject to license terms.
25355b4669Sjacobs  *
26355b4669Sjacobs  */
27355b4669Sjacobs 
28355b4669Sjacobs /* $Id: printer.c 149 2006-04-25 16:55:01Z njacobs $ */
29355b4669Sjacobs 
30355b4669Sjacobs #include <stdlib.h>
31355b4669Sjacobs #include <strings.h>
32355b4669Sjacobs #include <papi_impl.h>
33*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" #include <libintl.h>
34355b4669Sjacobs 
35355b4669Sjacobs static int
contains(char * value,char ** list)36355b4669Sjacobs contains(char *value, char **list)
37355b4669Sjacobs {
38355b4669Sjacobs 	int i;
39355b4669Sjacobs 
40355b4669Sjacobs 	if ((value == NULL) || (list == NULL))
41355b4669Sjacobs 		return (1);
42355b4669Sjacobs 
43355b4669Sjacobs 	for (i = 0; list[i] != NULL; i++)
44355b4669Sjacobs 		if (strcasecmp(value, list[i]) == 0)
45355b4669Sjacobs 			return (1);
46355b4669Sjacobs 
47355b4669Sjacobs 	return (0);
48355b4669Sjacobs }
49355b4669Sjacobs 
50355b4669Sjacobs papi_status_t
papiPrinterQuery(papi_service_t handle,char * name,char ** requested_attrs,papi_attribute_t ** job_attributes,papi_printer_t * printer)51355b4669Sjacobs papiPrinterQuery(papi_service_t handle, char *name,
52355b4669Sjacobs 		char **requested_attrs,
53355b4669Sjacobs 		papi_attribute_t **job_attributes,
54355b4669Sjacobs 		papi_printer_t *printer)
55355b4669Sjacobs {
56355b4669Sjacobs 	papi_status_t status;
57355b4669Sjacobs 	service_t *svc = handle;
58355b4669Sjacobs 	printer_t *p = NULL;
59355b4669Sjacobs 
60355b4669Sjacobs 	if ((svc == NULL) || (name == NULL) || (printer == NULL))
61355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
62355b4669Sjacobs 
63355b4669Sjacobs 	if ((status = service_fill_in(svc, name)) == PAPI_OK) {
64355b4669Sjacobs 		*printer = NULL;
65355b4669Sjacobs 
66355b4669Sjacobs 		if ((contains("printer-state", requested_attrs) == 1) ||
67355b4669Sjacobs 		    (contains("printer-state-reasons", requested_attrs) == 1))
68355b4669Sjacobs 			status = lpd_find_printer_info(svc,
69355b4669Sjacobs 			    (printer_t **)printer);
70355b4669Sjacobs 
71355b4669Sjacobs 		if ((status == PAPI_OK) && (*printer == NULL)) {
72355b4669Sjacobs 			char buf[BUFSIZ];
73355b4669Sjacobs 
74355b4669Sjacobs 			*printer = p = calloc(1, sizeof (*p));
75355b4669Sjacobs 
76355b4669Sjacobs 			papiAttributeListAddString(&(p->attributes),
77355b4669Sjacobs 			    PAPI_ATTR_APPEND, "printer-name",
78355b4669Sjacobs 			    queue_name_from_uri(svc->uri));
79355b4669Sjacobs 
80355b4669Sjacobs 			if (uri_to_string(svc->uri, buf, sizeof (buf)) == 0)
81355b4669Sjacobs 				papiAttributeListAddString(&(p->attributes),
82355b4669Sjacobs 				    PAPI_ATTR_APPEND,
83355b4669Sjacobs 				    "printer-uri-supported", buf);
84355b4669Sjacobs 		}
8522a91421Swendyp 		/* Set printer accepting: mimic prepapi behavior */
8622a91421Swendyp 		if ((p = *printer) != NULL)
8722a91421Swendyp 			papiAttributeListAddBoolean(&(p->attributes),
8822a91421Swendyp 			    PAPI_ATTR_REPLACE,
8922a91421Swendyp 			    "printer-is-accepting-jobs", PAPI_TRUE);
9022a91421Swendyp 
91355b4669Sjacobs 	}
92355b4669Sjacobs 
93355b4669Sjacobs 	return (status);
94355b4669Sjacobs }
95355b4669Sjacobs 
96355b4669Sjacobs papi_status_t
papiPrinterPurgeJobs(papi_service_t handle,char * name,papi_job_t ** jobs)97355b4669Sjacobs papiPrinterPurgeJobs(papi_service_t handle, char *name, papi_job_t **jobs)
98355b4669Sjacobs {
99355b4669Sjacobs 	papi_status_t status;
100355b4669Sjacobs 	service_t *svc = handle;
101355b4669Sjacobs 
102355b4669Sjacobs 	if ((svc == NULL) || (name == NULL))
103355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
104355b4669Sjacobs 
105355b4669Sjacobs 	if ((status = service_fill_in(svc, name)) == PAPI_OK)
106355b4669Sjacobs 		status = lpd_purge_jobs(svc, (job_t ***)jobs);
107355b4669Sjacobs 
108355b4669Sjacobs 	return (status);
109355b4669Sjacobs }
110355b4669Sjacobs 
111355b4669Sjacobs papi_status_t
papiPrinterListJobs(papi_service_t handle,char * name,char ** requested_attrs,int type_mask,int max_num_jobs,papi_job_t ** jobs)112355b4669Sjacobs papiPrinterListJobs(papi_service_t handle, char *name,
113355b4669Sjacobs 		char **requested_attrs, int type_mask,
114355b4669Sjacobs 		int max_num_jobs, papi_job_t **jobs)
115355b4669Sjacobs {
116355b4669Sjacobs 	papi_status_t status;
117355b4669Sjacobs 	service_t *svc = handle;
118355b4669Sjacobs 
119355b4669Sjacobs 	if ((svc == NULL) || (name == NULL) || (jobs == NULL))
120355b4669Sjacobs 		return (PAPI_BAD_ARGUMENT);
121355b4669Sjacobs 
122355b4669Sjacobs 	if ((status = service_fill_in(svc, name)) == PAPI_OK)
123355b4669Sjacobs 		status = lpd_find_jobs_info(svc, (job_t ***)jobs);
124355b4669Sjacobs 
125355b4669Sjacobs 	return (status);
126355b4669Sjacobs }
127355b4669Sjacobs 
128355b4669Sjacobs papi_attribute_t **
papiPrinterGetAttributeList(papi_printer_t printer)129355b4669Sjacobs papiPrinterGetAttributeList(papi_printer_t printer)
130355b4669Sjacobs {
131355b4669Sjacobs 	printer_t *p = printer;
132355b4669Sjacobs 
133355b4669Sjacobs 	if (p == NULL)
134355b4669Sjacobs 		return (NULL);
135355b4669Sjacobs 
136355b4669Sjacobs 	return (p->attributes);
137355b4669Sjacobs }
138355b4669Sjacobs 
139355b4669Sjacobs void
papiPrinterFree(papi_printer_t printer)140355b4669Sjacobs papiPrinterFree(papi_printer_t printer)
141355b4669Sjacobs {
142355b4669Sjacobs 	printer_t *p = printer;
143355b4669Sjacobs 
144355b4669Sjacobs 	if (p != NULL) {
145355b4669Sjacobs 		if (p->attributes != NULL)
146355b4669Sjacobs 			papiAttributeListFree(p->attributes);
147355b4669Sjacobs 		free(p);
148355b4669Sjacobs 	}
149355b4669Sjacobs }
150355b4669Sjacobs 
151355b4669Sjacobs void
papiPrinterListFree(papi_printer_t * printers)152355b4669Sjacobs papiPrinterListFree(papi_printer_t *printers)
153355b4669Sjacobs {
154355b4669Sjacobs 	if (printers != NULL) {
155355b4669Sjacobs 		int i;
156355b4669Sjacobs 
157355b4669Sjacobs 		for (i = 0; printers[i] != NULL; i++)
158355b4669Sjacobs 			papiPrinterFree(printers[i]);
159355b4669Sjacobs 		free(printers);
160355b4669Sjacobs 	}
161355b4669Sjacobs }
162*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
163*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
164*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papi_status_t
papiPrinterDisable(papi_service_t handle,char * name,char * message)165*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papiPrinterDisable(papi_service_t handle, char *name, char *message)
166*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" {
167*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	service_t *svc = handle;
168*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	papi_status_t status;
169*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
170*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	if ((status = service_fill_in(svc, name)) == PAPI_OK) {
171*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		detailed_error(svc,
172*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    gettext("Warning: %s is remote, disable has no meaning."),
173*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    queue_name_from_uri(svc->uri));
174*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	}
175*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	return (PAPI_OPERATION_NOT_SUPPORTED);
176*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" }
177*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
178*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papi_status_t
papiPrinterEnable(papi_service_t handle,char * name)179*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papiPrinterEnable(papi_service_t handle, char *name)
180*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" {
181*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	service_t *svc = handle;
182*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	papi_status_t status;
183*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
184*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	if ((status = service_fill_in(svc, name)) == PAPI_OK) {
185*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		detailed_error(svc,
186*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    gettext("Warning: %s is remote, enable has no meaning."),
187*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    queue_name_from_uri(svc->uri));
188*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	}
189*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	return (PAPI_OPERATION_NOT_SUPPORTED);
190*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" }
191*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
192*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
193*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papi_status_t
papiPrinterResume(papi_service_t handle,char * name)194*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papiPrinterResume(papi_service_t handle, char *name)
195*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" {
196*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	service_t *svc = handle;
197*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	papi_status_t status;
198*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
199*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	if ((status = service_fill_in(svc, name)) == PAPI_OK) {
200*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		detailed_error(svc,
201*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    gettext("Warning: %s is remote, accept has no meaning."),
202*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    queue_name_from_uri(svc->uri));
203*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	}
204*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	return (PAPI_OPERATION_NOT_SUPPORTED);
205*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" }
206*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
207*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
208*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papi_status_t
papiPrinterPause(papi_service_t handle,char * name,char * message)209*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" papiPrinterPause(papi_service_t handle, char *name, char *message)
210*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" {
211*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	service_t *svc = handle;
212*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	papi_status_t status;
213*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 
214*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	if ((status = service_fill_in(svc, name)) == PAPI_OK) {
215*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		detailed_error(svc,
216*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    gettext("Warning: %s is remote, reject has no meaning."),
217*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 		    queue_name_from_uri(svc->uri));
218*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	}
219*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" 	return (PAPI_OPERATION_NOT_SUPPORTED);
220*999637b1S"Nagaraj Yedathore - Sun Microsystems - Bangalore India" }
221