10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*2264Sjacobs  * Common Development and Distribution License (the "License").
6*2264Sjacobs  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*2264Sjacobs  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*LINTLIBRARY*/
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <stdlib.h>
310Sstevel@tonic-gate #include <libintl.h>
320Sstevel@tonic-gate #include <unistd.h>
33*2264Sjacobs #include <string.h>
340Sstevel@tonic-gate #include <sys/utsname.h>
350Sstevel@tonic-gate #include <papi_impl.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include "class.h"
380Sstevel@tonic-gate 
390Sstevel@tonic-gate void
400Sstevel@tonic-gate lpsched_printer_status_to_attributes(papi_attribute_t ***attrs,
410Sstevel@tonic-gate 	unsigned short status)
420Sstevel@tonic-gate {
430Sstevel@tonic-gate 	if (attrs == NULL)
440Sstevel@tonic-gate 		return;
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 	if (status & (PS_DISABLED|PS_LATER|PS_FAULTED|PS_FORM_FAULT)) {
470Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
480Sstevel@tonic-gate 				"printer-state", 0x05); /* stopped */
490Sstevel@tonic-gate 		if (status & PS_LATER)
500Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
510Sstevel@tonic-gate 				"printer-state-reasons", "moving-to-paused");
520Sstevel@tonic-gate 		else if (status & PS_FAULTED)
530Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
540Sstevel@tonic-gate 				"printer-state-reasons", "none");
550Sstevel@tonic-gate 		else if (status & PS_FORM_FAULT)
560Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
570Sstevel@tonic-gate 				"printer-state-reasons",
580Sstevel@tonic-gate 				"interpreter-resource-unavailable");
590Sstevel@tonic-gate 		else
600Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
610Sstevel@tonic-gate 				"printer-state-reasons", "paused");
620Sstevel@tonic-gate 	} else if (status & PS_BUSY) {
630Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
640Sstevel@tonic-gate 				"printer-state", 0x04); /* processing */
650Sstevel@tonic-gate 		papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
660Sstevel@tonic-gate 				"printer-state-reasons", "moving-to-paused");
670Sstevel@tonic-gate 	} else {
680Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
690Sstevel@tonic-gate 				"printer-state", 0x03); /* idle */
700Sstevel@tonic-gate 	}
710Sstevel@tonic-gate 
720Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
730Sstevel@tonic-gate 			"printer-is-accepting-jobs",
740Sstevel@tonic-gate 			((status & PS_REJECTED) != PS_REJECTED));
750Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
760Sstevel@tonic-gate 			"printer-is-processing-jobs",
770Sstevel@tonic-gate 			((status & PS_DISABLED) != PS_DISABLED));
780Sstevel@tonic-gate }
790Sstevel@tonic-gate 
800Sstevel@tonic-gate void
810Sstevel@tonic-gate lpsched_printer_defaults(papi_attribute_t ***attributes)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	if (attributes == NULL)
840Sstevel@tonic-gate 		return;
850Sstevel@tonic-gate 
860Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
870Sstevel@tonic-gate 			"multiple-document-jobs-supported", PAPI_TRUE);
880Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
890Sstevel@tonic-gate 			"multiple-document-handling-supported",
900Sstevel@tonic-gate 			"seperate-documents-colated-copies");
910Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
920Sstevel@tonic-gate 			"pdl-override-supported", "not-attempted");
930Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
940Sstevel@tonic-gate 			"job-priority-supported", 40);
950Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
960Sstevel@tonic-gate 			"job-priority-default", 20);
970Sstevel@tonic-gate 	papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
980Sstevel@tonic-gate 			"copies-supported", 1, 65535);
99*2264Sjacobs 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
100*2264Sjacobs 			"copies-default", 1);
1010Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
1020Sstevel@tonic-gate 			"page-ranges-supported", PAPI_TRUE);
1030Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1040Sstevel@tonic-gate 			"number-up-supported", 1);
1050Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1060Sstevel@tonic-gate 			"number-up-default", 1);
107*2264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
108*2264Sjacobs 			"job-hold-until-supported", "no-hold");
109*2264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
110*2264Sjacobs 			"job-hold-until-supported", "indefinite");
111*2264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
112*2264Sjacobs 			"job-hold-until-default", "no-hold");
113*2264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
114*2264Sjacobs 			"document-format-default", "application/octet-stream");
115*2264Sjacobs 
1160Sstevel@tonic-gate }
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate papi_status_t
1190Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
1200Sstevel@tonic-gate 	char *dest)
1210Sstevel@tonic-gate {
1220Sstevel@tonic-gate 	PRINTER *tmp;
1230Sstevel@tonic-gate 	char buf[BUFSIZ+1];
1240Sstevel@tonic-gate 	struct utsname sysname;
125*2264Sjacobs 	char **allowed = NULL, **denied = NULL;
1260Sstevel@tonic-gate 
1270Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL) || (dest == NULL))
1280Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
1290Sstevel@tonic-gate 
1300Sstevel@tonic-gate 	/* get the configuration DB data */
1310Sstevel@tonic-gate 	if ((tmp = getprinter(dest)) == NULL) {
1320Sstevel@tonic-gate 		detailed_error(svc,
1330Sstevel@tonic-gate 			gettext("unable to read configuration data"));
1340Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
1350Sstevel@tonic-gate 	}
1360Sstevel@tonic-gate 
1370Sstevel@tonic-gate 	/* name */
138*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1390Sstevel@tonic-gate 				"printer-name", tmp->name);
1400Sstevel@tonic-gate 	if (tmp->name != NULL) {
1410Sstevel@tonic-gate 		char uri[BUFSIZ];
1420Sstevel@tonic-gate 
143*2264Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
144*2264Sjacobs 				tmp->name);
1450Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
1460Sstevel@tonic-gate 				"printer-uri-supported", uri);
1470Sstevel@tonic-gate 	}
1480Sstevel@tonic-gate 
1490Sstevel@tonic-gate 	/* banner */
1500Sstevel@tonic-gate 	if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL)
1510Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1520Sstevel@tonic-gate 				"job-sheets-supported", "optional");
1530Sstevel@tonic-gate 	else if (tmp->banner & BAN_NEVER)
1540Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1550Sstevel@tonic-gate 				"job-sheets-supported", "none");
1560Sstevel@tonic-gate 	else if (tmp->banner & BAN_ALWAYS)
1570Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1580Sstevel@tonic-gate 				"job-sheets-supported", "standard");
1590Sstevel@tonic-gate 
1600Sstevel@tonic-gate 	/* input_types */
1610Sstevel@tonic-gate 	if (tmp->input_types != NULL) {
1620Sstevel@tonic-gate 		int i;
1630Sstevel@tonic-gate 
1640Sstevel@tonic-gate 		for (i = 0; tmp->input_types[i] != NULL; i++)
165*2264Sjacobs 			papiAttributeListAddLPString(&p->attributes,
1660Sstevel@tonic-gate 				PAPI_ATTR_APPEND, "document-format-supported",
1670Sstevel@tonic-gate 				lp_type_to_mime_type(tmp->input_types[i]));
1680Sstevel@tonic-gate 	}
1690Sstevel@tonic-gate 
1700Sstevel@tonic-gate 	/* description */
171*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1720Sstevel@tonic-gate 			"printer-info", tmp->description);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	/* add lpsched specific attributes */
175*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1760Sstevel@tonic-gate 				"device-uri", tmp->device);
177*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1780Sstevel@tonic-gate 				"lpsched-dial-info", tmp->dial_info);
179*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1800Sstevel@tonic-gate 				"lpsched-fault-recovery", tmp->fault_rec);
181*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1820Sstevel@tonic-gate 				"lpsched-interface-script", tmp->interface);
183*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1840Sstevel@tonic-gate 				"lpsched-data-rate", tmp->speed);
185*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1860Sstevel@tonic-gate 				"lpsched-stty", tmp->stty);
1870Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
1880Sstevel@tonic-gate 				"lpsched-login-term", tmp->login);
1890Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
1900Sstevel@tonic-gate 				"lpsched-daisy", tmp->daisy);
191*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1920Sstevel@tonic-gate 				"lpsched-charsets", tmp->char_sets);
1930Sstevel@tonic-gate #ifdef CAN_DO_MODULES
194*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1950Sstevel@tonic-gate 				"lpsched-modules", tmp->modules);
1960Sstevel@tonic-gate #endif /* CAN_DO_MODULES */
197*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1980Sstevel@tonic-gate 				"lpsched-options", tmp->options);
199*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2000Sstevel@tonic-gate 				"lpsched-printer-type", tmp->printer_types);
201*2264Sjacobs 	if (tmp->fault_alert.shcmd != NULL) {
202*2264Sjacobs 		papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2030Sstevel@tonic-gate 				"lpsched-fault-alert-command",
2040Sstevel@tonic-gate 				tmp->fault_alert.shcmd);
205*2264Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2060Sstevel@tonic-gate 				"lpsched-fault-alert-threshold",
2070Sstevel@tonic-gate 				tmp->fault_alert.Q);
208*2264Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2090Sstevel@tonic-gate 				"lpsched-fault-alert-interval",
2100Sstevel@tonic-gate 				tmp->fault_alert.W);
211*2264Sjacobs 	}
2120Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2130Sstevel@tonic-gate 				"lpsched-cpi-value", tmp->cpi.val);
2140Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2150Sstevel@tonic-gate 				"lpsched-cpi-unit", tmp->cpi.sc);
2160Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2170Sstevel@tonic-gate 				"lpsched-lpi-value", tmp->lpi.val);
2180Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2190Sstevel@tonic-gate 				"lpsched-lpi-unit", tmp->lpi.sc);
2200Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2210Sstevel@tonic-gate 				"lpsched-plen-value", tmp->plen.val);
2220Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2230Sstevel@tonic-gate 				"lpsched-plen-unit", tmp->plen.sc);
2240Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2250Sstevel@tonic-gate 				"lpsched-pwid-value", tmp->pwid.val);
2260Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2270Sstevel@tonic-gate 				"lpsched-pwid-unit", tmp->pwid.sc);
228*2264Sjacobs 
229*2264Sjacobs 	/* allow/deny list */
230*2264Sjacobs 	load_userprinter_access(dest, &allowed, &denied);
231*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
232*2264Sjacobs 				"requesting-user-name-allowed", allowed);
233*2264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
234*2264Sjacobs 				"requesting-user-name-denied", denied);
235*2264Sjacobs 
2360Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2370Sstevel@tonic-gate 	if (tmp->ppd != NULL) {
2380Sstevel@tonic-gate 		int fd;
2390Sstevel@tonic-gate 		struct stat sbuf;
2400Sstevel@tonic-gate 
2410Sstevel@tonic-gate 		/* construct the two URIs for the printer's PPD file */
2420Sstevel@tonic-gate 		if (uname(&sysname) < 0) {
2430Sstevel@tonic-gate 			/* failed to get systen name */
2440Sstevel@tonic-gate 			sysname.nodename[0] = 0;
2450Sstevel@tonic-gate 		}
2460Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd",
2470Sstevel@tonic-gate 			sysname.nodename, ETCDIR, tmp->name);
2480Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
249*2264Sjacobs 			"ppd-file-uri", buf);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s",
2520Sstevel@tonic-gate 			sysname.nodename, tmp->ppd);
2530Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
2540Sstevel@tonic-gate 			"lpsched-printer-configure-ppd-uri", buf);
255*2264Sjacobs 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
256*2264Sjacobs 			"lpsched-ppd-source-path", tmp->ppd);
2570Sstevel@tonic-gate 
2580Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name);
2590Sstevel@tonic-gate 
2600Sstevel@tonic-gate 		/*
2610Sstevel@tonic-gate 		 * We don't return error on any of the error conditions, we just
2620Sstevel@tonic-gate 		 * silently return without adding the attribute.
2630Sstevel@tonic-gate 		 */
264*2264Sjacobs 		PPDFileToAttributesList(&p->attributes, buf);
2650Sstevel@tonic-gate 	}
2660Sstevel@tonic-gate #endif
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	freeprinter(tmp);
2690Sstevel@tonic-gate 
2700Sstevel@tonic-gate 	return (PAPI_OK);
2710Sstevel@tonic-gate }
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate papi_status_t
2740Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form,
275*2264Sjacobs 		char *character_set, char *disable_reason, char *reject_reason,
2760Sstevel@tonic-gate 		short status, char *request_id,
277*2264Sjacobs 		long disable_date, long reject_date)
2780Sstevel@tonic-gate {
2790Sstevel@tonic-gate 	if (p == NULL)
2800Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
2810Sstevel@tonic-gate 
282*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
283*2264Sjacobs 			"form-ready", form);
284*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2850Sstevel@tonic-gate 			"lpsched-active-job", request_id);
286*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2870Sstevel@tonic-gate 			"lpsched-mounted-char-set", character_set);
288*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
289*2264Sjacobs 			"lpsched-disable-reason", disable_reason);
2900Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
291*2264Sjacobs 			"lpsched-disable-date", disable_date);
292*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
293*2264Sjacobs 			"lpsched-reject-reason", reject_reason);
2940Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
2950Sstevel@tonic-gate 			"lpsched-reject-date", reject_date);
2960Sstevel@tonic-gate 
2970Sstevel@tonic-gate 	/* add the current system time */
2980Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
2990Sstevel@tonic-gate 			"printer-current-time", time(NULL));
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	/* add the time since last enabled */
3020Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
3030Sstevel@tonic-gate 			"printer-up-time", time(NULL));
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	/* add the status information */
3060Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
3070Sstevel@tonic-gate 
3080Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
3090Sstevel@tonic-gate 			"printer-state-reasons", "none");
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
3120Sstevel@tonic-gate 
3130Sstevel@tonic-gate 	return (PAPI_OK);
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate 
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate /*
3180Sstevel@tonic-gate  * This puts the class information in only.  It could create a hybrid
3190Sstevel@tonic-gate  * printer object to return, but that is problematic at best.
3200Sstevel@tonic-gate  */
3210Sstevel@tonic-gate papi_status_t
3220Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p,
3230Sstevel@tonic-gate 	char *dest)
3240Sstevel@tonic-gate {
3250Sstevel@tonic-gate 	CLASS *tmp;
3260Sstevel@tonic-gate 
3270Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL))
3280Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3290Sstevel@tonic-gate 
3300Sstevel@tonic-gate 	/* get the configuration DB data */
3310Sstevel@tonic-gate 	if ((tmp = getclass(dest)) == NULL) {
3320Sstevel@tonic-gate 		detailed_error(svc,
3330Sstevel@tonic-gate 			gettext("unable to read configuration data"));
3340Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
3350Sstevel@tonic-gate 	}
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate 	/* name */
338*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
3390Sstevel@tonic-gate 				"printer-name", tmp->name);
3400Sstevel@tonic-gate 	if (tmp->name != NULL) {
3410Sstevel@tonic-gate 		char uri[BUFSIZ];
3420Sstevel@tonic-gate 
343*2264Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
344*2264Sjacobs 				tmp->name);
3450Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
3460Sstevel@tonic-gate 				"printer-uri-supported", uri);
3470Sstevel@tonic-gate 	}
3480Sstevel@tonic-gate 
3490Sstevel@tonic-gate 	if (tmp->members != NULL) {
3500Sstevel@tonic-gate 		char **members = tmp->members;
3510Sstevel@tonic-gate 		int i;
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate 		for (i = 0; members[i] != NULL; i++)
3540Sstevel@tonic-gate 			papiAttributeListAddString(&p->attributes,
3550Sstevel@tonic-gate 					PAPI_ATTR_APPEND,
3560Sstevel@tonic-gate 					"member-names", members[i]);
3570Sstevel@tonic-gate 	}
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate 	freeclass(tmp);
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate 	return (PAPI_OK);
3620Sstevel@tonic-gate }
3630Sstevel@tonic-gate 
3640Sstevel@tonic-gate papi_status_t
3650Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status,
3660Sstevel@tonic-gate 		char *reject_reason, long reject_date)
3670Sstevel@tonic-gate {
3680Sstevel@tonic-gate 	if (p == NULL)
3690Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3700Sstevel@tonic-gate 
371*2264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
372*2264Sjacobs 			"lpsched-reject-reason", reject_reason);
3730Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3740Sstevel@tonic-gate 			"lpsched-reject-date", reject_date);
3750Sstevel@tonic-gate 
3760Sstevel@tonic-gate 	/* add the current system time */
3770Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3780Sstevel@tonic-gate 			"printer-current-time", time(NULL));
3790Sstevel@tonic-gate 
3800Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
3810Sstevel@tonic-gate 			"printer-up-time", time(NULL));
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 	/* add the status information */
3840Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
3870Sstevel@tonic-gate 			"printer-state-reasons", "none");
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
3900Sstevel@tonic-gate 
3910Sstevel@tonic-gate 	return (PAPI_OK);
3920Sstevel@tonic-gate }
393*2264Sjacobs 
394*2264Sjacobs papi_status_t
395*2264Sjacobs attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp)
396*2264Sjacobs {
397*2264Sjacobs 	papi_status_t status;
398*2264Sjacobs 	void *iter = NULL;
399*2264Sjacobs 	char *string = NULL;
400*2264Sjacobs 	int flags;
401*2264Sjacobs 	char **list = NULL;
402*2264Sjacobs 
403*2264Sjacobs 	/* banner needs some conversion to the bitfield */
404*2264Sjacobs 	iter = NULL, string = NULL; flags = 0;
405*2264Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
406*2264Sjacobs 				"job-sheets-supported", &string);
407*2264Sjacobs 	    status == PAPI_OK;
408*2264Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
409*2264Sjacobs 				NULL, &string))
410*2264Sjacobs 		if (strcasecmp(string, "none") == 0)
411*2264Sjacobs 			flags |= BAN_NEVER;
412*2264Sjacobs 		else if (strcasecmp(string, "standard") == 0)
413*2264Sjacobs 			flags |= BAN_ALWAYS;
414*2264Sjacobs 	if (flags != 0)
415*2264Sjacobs 		tmp->banner = flags;
416*2264Sjacobs 
417*2264Sjacobs 	/* input_types needs mime-type conversion */
418*2264Sjacobs 	iter = NULL, string = NULL; list = NULL;
419*2264Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
420*2264Sjacobs 				"document-format-supported", &string);
421*2264Sjacobs 	    status == PAPI_OK;
422*2264Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
423*2264Sjacobs 				NULL, &string))
424*2264Sjacobs 		addlist(&list, mime_type_to_lp_type(string));
425*2264Sjacobs 	if (list != NULL) {
426*2264Sjacobs 		if (tmp->input_types != NULL)
427*2264Sjacobs 			freelist(tmp->input_types);
428*2264Sjacobs 		tmp->input_types = list;
429*2264Sjacobs 	}
430*2264Sjacobs 
431*2264Sjacobs 	papiAttributeListGetLPString(attributes,
432*2264Sjacobs 				"device-uri", &tmp->device);
433*2264Sjacobs 	papiAttributeListGetLPString(attributes,
434*2264Sjacobs 				"printer-info", &tmp->description);
435*2264Sjacobs 	papiAttributeListGetLPString(attributes,
436*2264Sjacobs 				"lpsched-dial-info", &tmp->dial_info);
437*2264Sjacobs 	papiAttributeListGetLPString(attributes,
438*2264Sjacobs 				"lpsched-fault-recovery", &tmp->fault_rec);
439*2264Sjacobs 	papiAttributeListGetLPString(attributes,
440*2264Sjacobs 				"lpsched-interface-script", &tmp->interface);
441*2264Sjacobs 	papiAttributeListGetLPString(attributes,
442*2264Sjacobs 				"lpsched-data-rate", &tmp->speed);
443*2264Sjacobs 	papiAttributeListGetLPString(attributes,
444*2264Sjacobs 				"lpsched-stty", &tmp->stty);
445*2264Sjacobs 	papiAttributeListGetLPStrings(attributes,
446*2264Sjacobs 				"lpsched-charsets", &tmp->char_sets);
447*2264Sjacobs 	papiAttributeListGetLPStrings(attributes,
448*2264Sjacobs 				"lpsched-printer-types", &tmp->printer_types);
449*2264Sjacobs 	papiAttributeListGetLPStrings(attributes,
450*2264Sjacobs 				"lpsched-options", &tmp->options);
451*2264Sjacobs 	papiAttributeListGetLPStrings(attributes,
452*2264Sjacobs 				"lpsched-modules", &tmp->modules);
453*2264Sjacobs #ifdef LP_USE_PAPI_ATTR
454*2264Sjacobs 	papiAttributeListGetLPString(attributes,
455*2264Sjacobs 				"lpsched-printer-ppd-uri", &tmp->ppd);
456*2264Sjacobs #endif
457*2264Sjacobs 
458*2264Sjacobs 	return (PAPI_OK);
459*2264Sjacobs }
460