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
5355b4669Sjacobs  * Common Development and Distribution License (the "License").
6355b4669Sjacobs  * 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*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India  * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate #include <stdlib.h>
297c478bd9Sstevel@tonic-gate #include <libintl.h>
307c478bd9Sstevel@tonic-gate #include <unistd.h>
31355b4669Sjacobs #include <string.h>
327c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
337c478bd9Sstevel@tonic-gate #include <papi_impl.h>
347c478bd9Sstevel@tonic-gate 
357c478bd9Sstevel@tonic-gate #include "class.h"
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate void
lpsched_printer_status_to_attributes(papi_attribute_t *** attrs,unsigned short status)387c478bd9Sstevel@tonic-gate lpsched_printer_status_to_attributes(papi_attribute_t ***attrs,
397c478bd9Sstevel@tonic-gate 	unsigned short status)
407c478bd9Sstevel@tonic-gate {
417c478bd9Sstevel@tonic-gate 	if (attrs == NULL)
427c478bd9Sstevel@tonic-gate 		return;
437c478bd9Sstevel@tonic-gate 
44*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	if (!(status & (PS_DISABLED|PS_LATER))) {
45*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		if (status & PS_FAULTED) {
46*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			if (status & PS_BUSY)
47*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				/* faulted printing */
48*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				papiAttributeListAddInteger(attrs,
49*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				    PAPI_ATTR_REPLACE,
50*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				    "printer-state", 0x06);
51*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			else
52*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				/* faulted printer */
53*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				papiAttributeListAddInteger(attrs,
54*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				    PAPI_ATTR_REPLACE,
55*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 				    "printer-state", 0x07);
56*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 
577c478bd9Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
58*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state-reasons", "none");
59*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		} else if (status & PS_BUSY) {
60*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
61*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state", 0x04); /* processing */
627c478bd9Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
63*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state-reasons", "moving-to-paused");
64*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		} else if (status & PS_FORM_FAULT) {
65*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
66*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state", 0x05); /* stopped */
677c478bd9Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
68*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state-reasons",
69*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "interpreter-resource-unavailable");
70*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		} else
71*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
72*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "printer-state", 0x03); /* idle */
73*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	} else if (status & PS_DISABLED) {
74*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
75*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-state", 0x05); /* stopped */
76*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
77*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-state-reasons", "paused");
78*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	} else if (status & PS_LATER) {
797c478bd9Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
80*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-state", 0x08); /* waiting for auto reply */
817c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
82*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-state-reasons", "moving-to-paused");
837c478bd9Sstevel@tonic-gate 	} else {
847c478bd9Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
85*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-state", 0x03); /* idle */
867c478bd9Sstevel@tonic-gate 	}
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
89*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-is-accepting-jobs",
90*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    ((status & PS_REJECTED) != PS_REJECTED));
917c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
92*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-is-processing-jobs",
93*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    ((status & PS_DISABLED) != PS_DISABLED));
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate void
lpsched_printer_defaults(papi_attribute_t *** attributes)977c478bd9Sstevel@tonic-gate lpsched_printer_defaults(papi_attribute_t ***attributes)
987c478bd9Sstevel@tonic-gate {
997c478bd9Sstevel@tonic-gate 	if (attributes == NULL)
1007c478bd9Sstevel@tonic-gate 		return;
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
103*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "multiple-document-jobs-supported", PAPI_TRUE);
1047c478bd9Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
105*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "multiple-document-handling-supported",
106*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "seperate-documents-colated-copies");
1077c478bd9Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
108*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "pdl-override-supported", "not-attempted");
1097c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
110*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-priority-supported", 40);
1117c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
112*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-priority-default", 20);
1137c478bd9Sstevel@tonic-gate 	papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
114*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "copies-supported", 1, 65535);
115355b4669Sjacobs 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
116*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "copies-default", 1);
1177c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
118*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "page-ranges-supported", PAPI_TRUE);
1197c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
120*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "number-up-supported", 1);
1217c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
122*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "number-up-default", 1);
123355b4669Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
124*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-hold-until-supported", "no-hold");
125355b4669Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
126*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-hold-until-supported", "indefinite");
127355b4669Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
128*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-hold-until-default", "no-hold");
129355b4669Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
130*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "document-format-default", "application/octet-stream");
131355b4669Sjacobs 
1327c478bd9Sstevel@tonic-gate }
1337c478bd9Sstevel@tonic-gate 
1347c478bd9Sstevel@tonic-gate papi_status_t
lpsched_printer_configuration_to_attributes(service_t * svc,printer_t * p,char * dest)1357c478bd9Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
1367c478bd9Sstevel@tonic-gate 	char *dest)
1377c478bd9Sstevel@tonic-gate {
1387c478bd9Sstevel@tonic-gate 	PRINTER *tmp;
1397c478bd9Sstevel@tonic-gate 	char buf[BUFSIZ+1];
1407c478bd9Sstevel@tonic-gate 	struct utsname sysname;
141355b4669Sjacobs 	char **allowed = NULL, **denied = NULL;
142f06271beSsonam gupta - Sun Microsystems - Bangalore India 	char **f_allowed = NULL, **f_denied = NULL;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL) || (dest == NULL))
1457c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	/* get the configuration DB data */
1487c478bd9Sstevel@tonic-gate 	if ((tmp = getprinter(dest)) == NULL) {
1497c478bd9Sstevel@tonic-gate 		detailed_error(svc,
150*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    gettext("unable to read configuration data"));
1517c478bd9Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
1527c478bd9Sstevel@tonic-gate 	}
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/* name */
155355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
156*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	"printer-name", tmp->name);
1577c478bd9Sstevel@tonic-gate 	if (tmp->name != NULL) {
1587c478bd9Sstevel@tonic-gate 		char uri[BUFSIZ];
1597c478bd9Sstevel@tonic-gate 
160355b4669Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
161*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    tmp->name);
1627c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
163*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-uri-supported", uri);
1647c478bd9Sstevel@tonic-gate 	}
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate 	/* banner */
1677c478bd9Sstevel@tonic-gate 	if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL)
1687c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
169*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "job-sheets-supported", "optional");
1707c478bd9Sstevel@tonic-gate 	else if (tmp->banner & BAN_NEVER)
1717c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
172*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "job-sheets-supported", "none");
1737c478bd9Sstevel@tonic-gate 	else if (tmp->banner & BAN_ALWAYS)
1747c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
175*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "job-sheets-supported", "standard");
1767c478bd9Sstevel@tonic-gate 
1777c478bd9Sstevel@tonic-gate 	/* input_types */
1787c478bd9Sstevel@tonic-gate 	if (tmp->input_types != NULL) {
1797c478bd9Sstevel@tonic-gate 		int i;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 		for (i = 0; tmp->input_types[i] != NULL; i++)
182355b4669Sjacobs 			papiAttributeListAddLPString(&p->attributes,
183*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    PAPI_ATTR_APPEND, "document-format-supported",
184*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    lp_type_to_mime_type(tmp->input_types[i]));
1857c478bd9Sstevel@tonic-gate 	}
1867c478bd9Sstevel@tonic-gate 
1877c478bd9Sstevel@tonic-gate 	/* description */
188355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
189*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-info", tmp->description);
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 	/* add lpsched specific attributes */
192355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
193*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "device-uri", tmp->device);
194355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
195*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-dial-info", tmp->dial_info);
196355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
197*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-fault-recovery", tmp->fault_rec);
198355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
199*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-interface-script", tmp->interface);
200355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
201*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-data-rate", tmp->speed);
202355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
203*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-stty", tmp->stty);
2047c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
205*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-login-term", tmp->login);
2067c478bd9Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
207*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-daisy", tmp->daisy);
208355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
209*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-charsets", tmp->char_sets);
2107c478bd9Sstevel@tonic-gate #ifdef CAN_DO_MODULES
211355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
212*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-modules", tmp->modules);
2137c478bd9Sstevel@tonic-gate #endif /* CAN_DO_MODULES */
214355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
215*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-options", tmp->options);
216355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
217*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-printer-type", tmp->printer_types);
218355b4669Sjacobs 	if (tmp->fault_alert.shcmd != NULL) {
219355b4669Sjacobs 		papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
220*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "lpsched-fault-alert-command",
221*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    tmp->fault_alert.shcmd);
222355b4669Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
223*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "lpsched-fault-alert-threshold",
224*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    tmp->fault_alert.Q);
225355b4669Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
226*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "lpsched-fault-alert-interval",
227*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    tmp->fault_alert.W);
228355b4669Sjacobs 	}
2297c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
230*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-cpi-value", tmp->cpi.val);
2317c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
232*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-cpi-unit", tmp->cpi.sc);
2337c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
234*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-lpi-value", tmp->lpi.val);
2357c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
236*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-lpi-unit", tmp->lpi.sc);
2377c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
238*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-plen-value", tmp->plen.val);
2397c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
240*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-plen-unit", tmp->plen.sc);
2417c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
242*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-pwid-value", tmp->pwid.val);
2437c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
244*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-pwid-unit", tmp->pwid.sc);
245355b4669Sjacobs 
246355b4669Sjacobs 	/* allow/deny list */
247355b4669Sjacobs 	load_userprinter_access(dest, &allowed, &denied);
248355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
249*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "requesting-user-name-allowed", allowed);
250355b4669Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
251*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "requesting-user-name-denied", denied);
252355b4669Sjacobs 
2538c8a8d17SWendy Phillips 	freelist(allowed);
2548c8a8d17SWendy Phillips 	freelist(denied);
2558c8a8d17SWendy Phillips 
256f06271beSsonam gupta - Sun Microsystems - Bangalore India 	/* forms allow/deny list */
257f06271beSsonam gupta - Sun Microsystems - Bangalore India 	load_formprinter_access(dest, &f_allowed, &f_denied);
258f06271beSsonam gupta - Sun Microsystems - Bangalore India 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
259f06271beSsonam gupta - Sun Microsystems - Bangalore India 	    "form-supported", f_allowed);
260f06271beSsonam gupta - Sun Microsystems - Bangalore India 
261f06271beSsonam gupta - Sun Microsystems - Bangalore India 	/*
262f06271beSsonam gupta - Sun Microsystems - Bangalore India 	 * All forms allowed case
263f06271beSsonam gupta - Sun Microsystems - Bangalore India 	 * When all forms are allowed forms.allow does not get created but
264f06271beSsonam gupta - Sun Microsystems - Bangalore India 	 * forms.deny file gets created with no entries
265f06271beSsonam gupta - Sun Microsystems - Bangalore India 	 */
266f06271beSsonam gupta - Sun Microsystems - Bangalore India 	if ((f_allowed == NULL) && (f_denied != NULL) && (f_denied[0] == NULL))
267f06271beSsonam gupta - Sun Microsystems - Bangalore India 		papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
268f06271beSsonam gupta - Sun Microsystems - Bangalore India 		    "form-supported", "all");
269f06271beSsonam gupta - Sun Microsystems - Bangalore India 
270f06271beSsonam gupta - Sun Microsystems - Bangalore India 	freelist(f_allowed);
271f06271beSsonam gupta - Sun Microsystems - Bangalore India 	freelist(f_denied);
272f06271beSsonam gupta - Sun Microsystems - Bangalore India 
2737c478bd9Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2747c478bd9Sstevel@tonic-gate 	if (tmp->ppd != NULL) {
2757c478bd9Sstevel@tonic-gate 		int fd;
2767c478bd9Sstevel@tonic-gate 		struct stat sbuf;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 		/* construct the two URIs for the printer's PPD file */
2797c478bd9Sstevel@tonic-gate 		if (uname(&sysname) < 0) {
2807c478bd9Sstevel@tonic-gate 			/* failed to get systen name */
2817c478bd9Sstevel@tonic-gate 			sysname.nodename[0] = 0;
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd",
284*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    sysname.nodename, ETCDIR, tmp->name);
2857c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
286*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "ppd-file-uri", buf);
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s",
289*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    sysname.nodename, tmp->ppd);
2907c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
291*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "lpsched-printer-configure-ppd-uri", buf);
292355b4669Sjacobs 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
293*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "lpsched-ppd-source-path", tmp->ppd);
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name);
2967c478bd9Sstevel@tonic-gate 
2977c478bd9Sstevel@tonic-gate 		/*
2987c478bd9Sstevel@tonic-gate 		 * We don't return error on any of the error conditions, we just
2997c478bd9Sstevel@tonic-gate 		 * silently return without adding the attribute.
3007c478bd9Sstevel@tonic-gate 		 */
301355b4669Sjacobs 		PPDFileToAttributesList(&p->attributes, buf);
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate #endif
3047c478bd9Sstevel@tonic-gate 
3057c478bd9Sstevel@tonic-gate 	freeprinter(tmp);
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
3087c478bd9Sstevel@tonic-gate }
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate papi_status_t
printer_status_to_attributes(printer_t * p,char * printer,char * form,char * character_set,char * disable_reason,char * reject_reason,short status,char * request_id,long disable_date,long reject_date)3117c478bd9Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form,
312355b4669Sjacobs 		char *character_set, char *disable_reason, char *reject_reason,
3137c478bd9Sstevel@tonic-gate 		short status, char *request_id,
314355b4669Sjacobs 		long disable_date, long reject_date)
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate 	if (p == NULL)
3177c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3187c478bd9Sstevel@tonic-gate 
319355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
320*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "form-ready", form);
321355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
322*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-active-job", request_id);
323355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
324*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-mounted-char-set", character_set);
325355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
326*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-disable-reason", disable_reason);
3277c478bd9Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
328*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-disable-date", disable_date);
329355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
330*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-reject-reason", reject_reason);
3317c478bd9Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
332*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-reject-date", reject_date);
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	/* add the current system time */
3357c478bd9Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
336*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-current-time", time(NULL));
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 	/* add the time since last enabled */
3397c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
340*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-up-time", time(NULL));
3417c478bd9Sstevel@tonic-gate 
3427c478bd9Sstevel@tonic-gate 	/* add the status information */
3437c478bd9Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
3447c478bd9Sstevel@tonic-gate 
3457c478bd9Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
346*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-state-reasons", "none");
3477c478bd9Sstevel@tonic-gate 
3487c478bd9Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
3497c478bd9Sstevel@tonic-gate 
3507c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
3517c478bd9Sstevel@tonic-gate }
3527c478bd9Sstevel@tonic-gate 
3537c478bd9Sstevel@tonic-gate 
3547c478bd9Sstevel@tonic-gate /*
3557c478bd9Sstevel@tonic-gate  * This puts the class information in only.  It could create a hybrid
3567c478bd9Sstevel@tonic-gate  * printer object to return, but that is problematic at best.
3577c478bd9Sstevel@tonic-gate  */
3587c478bd9Sstevel@tonic-gate papi_status_t
lpsched_class_configuration_to_attributes(service_t * svc,printer_t * p,char * dest)3597c478bd9Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p,
3607c478bd9Sstevel@tonic-gate 	char *dest)
3617c478bd9Sstevel@tonic-gate {
3627c478bd9Sstevel@tonic-gate 	CLASS *tmp;
3637c478bd9Sstevel@tonic-gate 
3647c478bd9Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL))
3657c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	/* get the configuration DB data */
3687c478bd9Sstevel@tonic-gate 	if ((tmp = getclass(dest)) == NULL) {
3697c478bd9Sstevel@tonic-gate 		detailed_error(svc,
370*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    gettext("unable to read configuration data"));
3717c478bd9Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
3727c478bd9Sstevel@tonic-gate 	}
3737c478bd9Sstevel@tonic-gate 
3747c478bd9Sstevel@tonic-gate 	/* name */
375355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
376*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-name", tmp->name);
3777c478bd9Sstevel@tonic-gate 	if (tmp->name != NULL) {
3787c478bd9Sstevel@tonic-gate 		char uri[BUFSIZ];
3797c478bd9Sstevel@tonic-gate 
380355b4669Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
381*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    tmp->name);
3827c478bd9Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
383*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 		    "printer-uri-supported", uri);
3847c478bd9Sstevel@tonic-gate 	}
3857c478bd9Sstevel@tonic-gate 
3867c478bd9Sstevel@tonic-gate 	if (tmp->members != NULL) {
3877c478bd9Sstevel@tonic-gate 		char **members = tmp->members;
3887c478bd9Sstevel@tonic-gate 		int i;
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate 		for (i = 0; members[i] != NULL; i++)
3917c478bd9Sstevel@tonic-gate 			papiAttributeListAddString(&p->attributes,
392*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    PAPI_ATTR_APPEND,
393*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 			    "member-names", members[i]);
3947c478bd9Sstevel@tonic-gate 	}
3957c478bd9Sstevel@tonic-gate 
3967c478bd9Sstevel@tonic-gate 	freeclass(tmp);
3977c478bd9Sstevel@tonic-gate 
3987c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
3997c478bd9Sstevel@tonic-gate }
4007c478bd9Sstevel@tonic-gate 
4017c478bd9Sstevel@tonic-gate papi_status_t
class_status_to_attributes(printer_t * p,char * printer,short status,char * reject_reason,long reject_date)4027c478bd9Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status,
4037c478bd9Sstevel@tonic-gate 		char *reject_reason, long reject_date)
4047c478bd9Sstevel@tonic-gate {
4057c478bd9Sstevel@tonic-gate 	if (p == NULL)
4067c478bd9Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
4077c478bd9Sstevel@tonic-gate 
408355b4669Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
409*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-reject-reason", reject_reason);
4107c478bd9Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
411*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-reject-date", reject_date);
4127c478bd9Sstevel@tonic-gate 
4137c478bd9Sstevel@tonic-gate 	/* add the current system time */
4147c478bd9Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
415*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-current-time", time(NULL));
4167c478bd9Sstevel@tonic-gate 
4177c478bd9Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
418*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-up-time", time(NULL));
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	/* add the status information */
4217c478bd9Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
4227c478bd9Sstevel@tonic-gate 
4237c478bd9Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
424*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-state-reasons", "none");
4257c478bd9Sstevel@tonic-gate 
4267c478bd9Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
4277c478bd9Sstevel@tonic-gate 
4287c478bd9Sstevel@tonic-gate 	return (PAPI_OK);
4297c478bd9Sstevel@tonic-gate }
430355b4669Sjacobs 
431355b4669Sjacobs papi_status_t
attributes_to_printer(papi_attribute_t ** attributes,PRINTER * tmp)432355b4669Sjacobs attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp)
433355b4669Sjacobs {
434355b4669Sjacobs 	papi_status_t status;
435355b4669Sjacobs 	void *iter = NULL;
436355b4669Sjacobs 	char *string = NULL;
437355b4669Sjacobs 	int flags;
438355b4669Sjacobs 	char **list = NULL;
439355b4669Sjacobs 
440355b4669Sjacobs 	/* banner needs some conversion to the bitfield */
441355b4669Sjacobs 	iter = NULL, string = NULL; flags = 0;
442355b4669Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
443*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "job-sheets-supported", &string);
444355b4669Sjacobs 	    status == PAPI_OK;
445355b4669Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
446*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    NULL, &string))
447355b4669Sjacobs 		if (strcasecmp(string, "none") == 0)
448355b4669Sjacobs 			flags |= BAN_NEVER;
449355b4669Sjacobs 		else if (strcasecmp(string, "standard") == 0)
450355b4669Sjacobs 			flags |= BAN_ALWAYS;
451355b4669Sjacobs 	if (flags != 0)
452355b4669Sjacobs 		tmp->banner = flags;
453355b4669Sjacobs 
454355b4669Sjacobs 	/* input_types needs mime-type conversion */
455355b4669Sjacobs 	iter = NULL, string = NULL; list = NULL;
456355b4669Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
457*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "document-format-supported", &string);
458355b4669Sjacobs 	    status == PAPI_OK;
459355b4669Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
460*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    NULL, &string))
461355b4669Sjacobs 		addlist(&list, mime_type_to_lp_type(string));
462355b4669Sjacobs 	if (list != NULL) {
463355b4669Sjacobs 		if (tmp->input_types != NULL)
464355b4669Sjacobs 			freelist(tmp->input_types);
465355b4669Sjacobs 		tmp->input_types = list;
466355b4669Sjacobs 	}
467355b4669Sjacobs 
468355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
469*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "device-uri", &tmp->device);
470355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
471*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "printer-info", &tmp->description);
472355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
473*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-dial-info", &tmp->dial_info);
474355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
475*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-fault-recovery", &tmp->fault_rec);
476355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
477*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-interface-script", &tmp->interface);
478355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
479*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-data-rate", &tmp->speed);
480355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
481*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-stty", &tmp->stty);
482355b4669Sjacobs 	papiAttributeListGetLPStrings(attributes,
483*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-charsets", &tmp->char_sets);
484355b4669Sjacobs 	papiAttributeListGetLPStrings(attributes,
485*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-printer-types", &tmp->printer_types);
486355b4669Sjacobs 	papiAttributeListGetLPStrings(attributes,
487*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-options", &tmp->options);
488355b4669Sjacobs 	papiAttributeListGetLPStrings(attributes,
489*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-modules", &tmp->modules);
490355b4669Sjacobs #ifdef LP_USE_PAPI_ATTR
491355b4669Sjacobs 	papiAttributeListGetLPString(attributes,
492*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 	    "lpsched-printer-ppd-uri", &tmp->ppd);
493355b4669Sjacobs #endif
494355b4669Sjacobs 
495355b4669Sjacobs 	return (PAPI_OK);
496355b4669Sjacobs }
497