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
52264Sjacobs  * Common Development and Distribution License (the "License").
62264Sjacobs  * 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*7322SWendy.Phillips@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate /*LINTLIBRARY*/
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdlib.h>
290Sstevel@tonic-gate #include <libintl.h>
300Sstevel@tonic-gate #include <unistd.h>
312264Sjacobs #include <string.h>
320Sstevel@tonic-gate #include <sys/utsname.h>
330Sstevel@tonic-gate #include <papi_impl.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include "class.h"
360Sstevel@tonic-gate 
370Sstevel@tonic-gate void
380Sstevel@tonic-gate lpsched_printer_status_to_attributes(papi_attribute_t ***attrs,
390Sstevel@tonic-gate 	unsigned short status)
400Sstevel@tonic-gate {
410Sstevel@tonic-gate 	if (attrs == NULL)
420Sstevel@tonic-gate 		return;
430Sstevel@tonic-gate 
440Sstevel@tonic-gate 	if (status & (PS_DISABLED|PS_LATER|PS_FAULTED|PS_FORM_FAULT)) {
450Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
460Sstevel@tonic-gate 				"printer-state", 0x05); /* stopped */
470Sstevel@tonic-gate 		if (status & PS_LATER)
480Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
490Sstevel@tonic-gate 				"printer-state-reasons", "moving-to-paused");
500Sstevel@tonic-gate 		else if (status & PS_FAULTED)
510Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
520Sstevel@tonic-gate 				"printer-state-reasons", "none");
530Sstevel@tonic-gate 		else if (status & PS_FORM_FAULT)
540Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
550Sstevel@tonic-gate 				"printer-state-reasons",
560Sstevel@tonic-gate 				"interpreter-resource-unavailable");
570Sstevel@tonic-gate 		else
580Sstevel@tonic-gate 			papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
590Sstevel@tonic-gate 				"printer-state-reasons", "paused");
600Sstevel@tonic-gate 	} else if (status & PS_BUSY) {
610Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
620Sstevel@tonic-gate 				"printer-state", 0x04); /* processing */
630Sstevel@tonic-gate 		papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
640Sstevel@tonic-gate 				"printer-state-reasons", "moving-to-paused");
650Sstevel@tonic-gate 	} else {
660Sstevel@tonic-gate 		papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
670Sstevel@tonic-gate 				"printer-state", 0x03); /* idle */
680Sstevel@tonic-gate 	}
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
710Sstevel@tonic-gate 			"printer-is-accepting-jobs",
720Sstevel@tonic-gate 			((status & PS_REJECTED) != PS_REJECTED));
730Sstevel@tonic-gate 	papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
740Sstevel@tonic-gate 			"printer-is-processing-jobs",
750Sstevel@tonic-gate 			((status & PS_DISABLED) != PS_DISABLED));
760Sstevel@tonic-gate }
770Sstevel@tonic-gate 
780Sstevel@tonic-gate void
790Sstevel@tonic-gate lpsched_printer_defaults(papi_attribute_t ***attributes)
800Sstevel@tonic-gate {
810Sstevel@tonic-gate 	if (attributes == NULL)
820Sstevel@tonic-gate 		return;
830Sstevel@tonic-gate 
840Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
850Sstevel@tonic-gate 			"multiple-document-jobs-supported", PAPI_TRUE);
860Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
870Sstevel@tonic-gate 			"multiple-document-handling-supported",
880Sstevel@tonic-gate 			"seperate-documents-colated-copies");
890Sstevel@tonic-gate 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
900Sstevel@tonic-gate 			"pdl-override-supported", "not-attempted");
910Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
920Sstevel@tonic-gate 			"job-priority-supported", 40);
930Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
940Sstevel@tonic-gate 			"job-priority-default", 20);
950Sstevel@tonic-gate 	papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
960Sstevel@tonic-gate 			"copies-supported", 1, 65535);
972264Sjacobs 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
982264Sjacobs 			"copies-default", 1);
990Sstevel@tonic-gate 	papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
1000Sstevel@tonic-gate 			"page-ranges-supported", PAPI_TRUE);
1010Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1020Sstevel@tonic-gate 			"number-up-supported", 1);
1030Sstevel@tonic-gate 	papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1040Sstevel@tonic-gate 			"number-up-default", 1);
1052264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
1062264Sjacobs 			"job-hold-until-supported", "no-hold");
1072264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
1082264Sjacobs 			"job-hold-until-supported", "indefinite");
1092264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
1102264Sjacobs 			"job-hold-until-default", "no-hold");
1112264Sjacobs 	papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
1122264Sjacobs 			"document-format-default", "application/octet-stream");
1132264Sjacobs 
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate papi_status_t
1170Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
1180Sstevel@tonic-gate 	char *dest)
1190Sstevel@tonic-gate {
1200Sstevel@tonic-gate 	PRINTER *tmp;
1210Sstevel@tonic-gate 	char buf[BUFSIZ+1];
1220Sstevel@tonic-gate 	struct utsname sysname;
1232264Sjacobs 	char **allowed = NULL, **denied = NULL;
1240Sstevel@tonic-gate 
1250Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL) || (dest == NULL))
1260Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	/* get the configuration DB data */
1290Sstevel@tonic-gate 	if ((tmp = getprinter(dest)) == NULL) {
1300Sstevel@tonic-gate 		detailed_error(svc,
1310Sstevel@tonic-gate 			gettext("unable to read configuration data"));
1320Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
1330Sstevel@tonic-gate 	}
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate 	/* name */
1362264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1370Sstevel@tonic-gate 				"printer-name", tmp->name);
1380Sstevel@tonic-gate 	if (tmp->name != NULL) {
1390Sstevel@tonic-gate 		char uri[BUFSIZ];
1400Sstevel@tonic-gate 
1412264Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
1422264Sjacobs 				tmp->name);
1430Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
1440Sstevel@tonic-gate 				"printer-uri-supported", uri);
1450Sstevel@tonic-gate 	}
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate 	/* banner */
1480Sstevel@tonic-gate 	if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL)
1490Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1500Sstevel@tonic-gate 				"job-sheets-supported", "optional");
1510Sstevel@tonic-gate 	else if (tmp->banner & BAN_NEVER)
1520Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1530Sstevel@tonic-gate 				"job-sheets-supported", "none");
1540Sstevel@tonic-gate 	else if (tmp->banner & BAN_ALWAYS)
1550Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1560Sstevel@tonic-gate 				"job-sheets-supported", "standard");
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	/* input_types */
1590Sstevel@tonic-gate 	if (tmp->input_types != NULL) {
1600Sstevel@tonic-gate 		int i;
1610Sstevel@tonic-gate 
1620Sstevel@tonic-gate 		for (i = 0; tmp->input_types[i] != NULL; i++)
1632264Sjacobs 			papiAttributeListAddLPString(&p->attributes,
1640Sstevel@tonic-gate 				PAPI_ATTR_APPEND, "document-format-supported",
1650Sstevel@tonic-gate 				lp_type_to_mime_type(tmp->input_types[i]));
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	/* description */
1692264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1700Sstevel@tonic-gate 			"printer-info", tmp->description);
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate 	/* add lpsched specific attributes */
1732264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1740Sstevel@tonic-gate 				"device-uri", tmp->device);
1752264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1760Sstevel@tonic-gate 				"lpsched-dial-info", tmp->dial_info);
1772264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1780Sstevel@tonic-gate 				"lpsched-fault-recovery", tmp->fault_rec);
1792264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1800Sstevel@tonic-gate 				"lpsched-interface-script", tmp->interface);
1812264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1820Sstevel@tonic-gate 				"lpsched-data-rate", tmp->speed);
1832264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1840Sstevel@tonic-gate 				"lpsched-stty", tmp->stty);
1850Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
1860Sstevel@tonic-gate 				"lpsched-login-term", tmp->login);
1870Sstevel@tonic-gate 	papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
1880Sstevel@tonic-gate 				"lpsched-daisy", tmp->daisy);
1892264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1900Sstevel@tonic-gate 				"lpsched-charsets", tmp->char_sets);
1910Sstevel@tonic-gate #ifdef CAN_DO_MODULES
1922264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1930Sstevel@tonic-gate 				"lpsched-modules", tmp->modules);
1940Sstevel@tonic-gate #endif /* CAN_DO_MODULES */
1952264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1960Sstevel@tonic-gate 				"lpsched-options", tmp->options);
1972264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
1980Sstevel@tonic-gate 				"lpsched-printer-type", tmp->printer_types);
1992264Sjacobs 	if (tmp->fault_alert.shcmd != NULL) {
2002264Sjacobs 		papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2010Sstevel@tonic-gate 				"lpsched-fault-alert-command",
2020Sstevel@tonic-gate 				tmp->fault_alert.shcmd);
2032264Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2040Sstevel@tonic-gate 				"lpsched-fault-alert-threshold",
2050Sstevel@tonic-gate 				tmp->fault_alert.Q);
2062264Sjacobs 		papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2070Sstevel@tonic-gate 				"lpsched-fault-alert-interval",
2080Sstevel@tonic-gate 				tmp->fault_alert.W);
2092264Sjacobs 	}
2100Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2110Sstevel@tonic-gate 				"lpsched-cpi-value", tmp->cpi.val);
2120Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2130Sstevel@tonic-gate 				"lpsched-cpi-unit", tmp->cpi.sc);
2140Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2150Sstevel@tonic-gate 				"lpsched-lpi-value", tmp->lpi.val);
2160Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2170Sstevel@tonic-gate 				"lpsched-lpi-unit", tmp->lpi.sc);
2180Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2190Sstevel@tonic-gate 				"lpsched-plen-value", tmp->plen.val);
2200Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2210Sstevel@tonic-gate 				"lpsched-plen-unit", tmp->plen.sc);
2220Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2230Sstevel@tonic-gate 				"lpsched-pwid-value", tmp->pwid.val);
2240Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2250Sstevel@tonic-gate 				"lpsched-pwid-unit", tmp->pwid.sc);
2262264Sjacobs 
2272264Sjacobs 	/* allow/deny list */
2282264Sjacobs 	load_userprinter_access(dest, &allowed, &denied);
2292264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2302264Sjacobs 				"requesting-user-name-allowed", allowed);
2312264Sjacobs 	papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2322264Sjacobs 				"requesting-user-name-denied", denied);
2332264Sjacobs 
234*7322SWendy.Phillips@Sun.COM 	freelist(allowed);
235*7322SWendy.Phillips@Sun.COM 	freelist(denied);
236*7322SWendy.Phillips@Sun.COM 
2370Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2380Sstevel@tonic-gate 	if (tmp->ppd != NULL) {
2390Sstevel@tonic-gate 		int fd;
2400Sstevel@tonic-gate 		struct stat sbuf;
2410Sstevel@tonic-gate 
2420Sstevel@tonic-gate 		/* construct the two URIs for the printer's PPD file */
2430Sstevel@tonic-gate 		if (uname(&sysname) < 0) {
2440Sstevel@tonic-gate 			/* failed to get systen name */
2450Sstevel@tonic-gate 			sysname.nodename[0] = 0;
2460Sstevel@tonic-gate 		}
2470Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd",
2480Sstevel@tonic-gate 			sysname.nodename, ETCDIR, tmp->name);
2490Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
2502264Sjacobs 			"ppd-file-uri", buf);
2510Sstevel@tonic-gate 
2520Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "file://%s%s",
2530Sstevel@tonic-gate 			sysname.nodename, tmp->ppd);
2540Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
2550Sstevel@tonic-gate 			"lpsched-printer-configure-ppd-uri", buf);
2562264Sjacobs 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
2572264Sjacobs 			"lpsched-ppd-source-path", tmp->ppd);
2580Sstevel@tonic-gate 
2590Sstevel@tonic-gate 		snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name);
2600Sstevel@tonic-gate 
2610Sstevel@tonic-gate 		/*
2620Sstevel@tonic-gate 		 * We don't return error on any of the error conditions, we just
2630Sstevel@tonic-gate 		 * silently return without adding the attribute.
2640Sstevel@tonic-gate 		 */
2652264Sjacobs 		PPDFileToAttributesList(&p->attributes, buf);
2660Sstevel@tonic-gate 	}
2670Sstevel@tonic-gate #endif
2680Sstevel@tonic-gate 
2690Sstevel@tonic-gate 	freeprinter(tmp);
2700Sstevel@tonic-gate 
2710Sstevel@tonic-gate 	return (PAPI_OK);
2720Sstevel@tonic-gate }
2730Sstevel@tonic-gate 
2740Sstevel@tonic-gate papi_status_t
2750Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form,
2762264Sjacobs 		char *character_set, char *disable_reason, char *reject_reason,
2770Sstevel@tonic-gate 		short status, char *request_id,
2782264Sjacobs 		long disable_date, long reject_date)
2790Sstevel@tonic-gate {
2800Sstevel@tonic-gate 	if (p == NULL)
2810Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
2820Sstevel@tonic-gate 
2832264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2842264Sjacobs 			"form-ready", form);
2852264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2860Sstevel@tonic-gate 			"lpsched-active-job", request_id);
2872264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2880Sstevel@tonic-gate 			"lpsched-mounted-char-set", character_set);
2892264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2902264Sjacobs 			"lpsched-disable-reason", disable_reason);
2910Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
2922264Sjacobs 			"lpsched-disable-date", disable_date);
2932264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2942264Sjacobs 			"lpsched-reject-reason", reject_reason);
2950Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
2960Sstevel@tonic-gate 			"lpsched-reject-date", reject_date);
2970Sstevel@tonic-gate 
2980Sstevel@tonic-gate 	/* add the current system time */
2990Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3000Sstevel@tonic-gate 			"printer-current-time", time(NULL));
3010Sstevel@tonic-gate 
3020Sstevel@tonic-gate 	/* add the time since last enabled */
3030Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
3040Sstevel@tonic-gate 			"printer-up-time", time(NULL));
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate 	/* add the status information */
3070Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
3080Sstevel@tonic-gate 
3090Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
3100Sstevel@tonic-gate 			"printer-state-reasons", "none");
3110Sstevel@tonic-gate 
3120Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate 	return (PAPI_OK);
3150Sstevel@tonic-gate }
3160Sstevel@tonic-gate 
3170Sstevel@tonic-gate 
3180Sstevel@tonic-gate /*
3190Sstevel@tonic-gate  * This puts the class information in only.  It could create a hybrid
3200Sstevel@tonic-gate  * printer object to return, but that is problematic at best.
3210Sstevel@tonic-gate  */
3220Sstevel@tonic-gate papi_status_t
3230Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p,
3240Sstevel@tonic-gate 	char *dest)
3250Sstevel@tonic-gate {
3260Sstevel@tonic-gate 	CLASS *tmp;
3270Sstevel@tonic-gate 
3280Sstevel@tonic-gate 	if ((svc == NULL) || (p == NULL))
3290Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3300Sstevel@tonic-gate 
3310Sstevel@tonic-gate 	/* get the configuration DB data */
3320Sstevel@tonic-gate 	if ((tmp = getclass(dest)) == NULL) {
3330Sstevel@tonic-gate 		detailed_error(svc,
3340Sstevel@tonic-gate 			gettext("unable to read configuration data"));
3350Sstevel@tonic-gate 		return (PAPI_DEVICE_ERROR);
3360Sstevel@tonic-gate 	}
3370Sstevel@tonic-gate 
3380Sstevel@tonic-gate 	/* name */
3392264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
3400Sstevel@tonic-gate 				"printer-name", tmp->name);
3410Sstevel@tonic-gate 	if (tmp->name != NULL) {
3420Sstevel@tonic-gate 		char uri[BUFSIZ];
3430Sstevel@tonic-gate 
3442264Sjacobs 		snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
3452264Sjacobs 				tmp->name);
3460Sstevel@tonic-gate 		papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
3470Sstevel@tonic-gate 				"printer-uri-supported", uri);
3480Sstevel@tonic-gate 	}
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate 	if (tmp->members != NULL) {
3510Sstevel@tonic-gate 		char **members = tmp->members;
3520Sstevel@tonic-gate 		int i;
3530Sstevel@tonic-gate 
3540Sstevel@tonic-gate 		for (i = 0; members[i] != NULL; i++)
3550Sstevel@tonic-gate 			papiAttributeListAddString(&p->attributes,
3560Sstevel@tonic-gate 					PAPI_ATTR_APPEND,
3570Sstevel@tonic-gate 					"member-names", members[i]);
3580Sstevel@tonic-gate 	}
3590Sstevel@tonic-gate 
3600Sstevel@tonic-gate 	freeclass(tmp);
3610Sstevel@tonic-gate 
3620Sstevel@tonic-gate 	return (PAPI_OK);
3630Sstevel@tonic-gate }
3640Sstevel@tonic-gate 
3650Sstevel@tonic-gate papi_status_t
3660Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status,
3670Sstevel@tonic-gate 		char *reject_reason, long reject_date)
3680Sstevel@tonic-gate {
3690Sstevel@tonic-gate 	if (p == NULL)
3700Sstevel@tonic-gate 		return (PAPI_BAD_ARGUMENT);
3710Sstevel@tonic-gate 
3722264Sjacobs 	papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
3732264Sjacobs 			"lpsched-reject-reason", reject_reason);
3740Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3750Sstevel@tonic-gate 			"lpsched-reject-date", reject_date);
3760Sstevel@tonic-gate 
3770Sstevel@tonic-gate 	/* add the current system time */
3780Sstevel@tonic-gate 	papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3790Sstevel@tonic-gate 			"printer-current-time", time(NULL));
3800Sstevel@tonic-gate 
3810Sstevel@tonic-gate 	papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
3820Sstevel@tonic-gate 			"printer-up-time", time(NULL));
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate 	/* add the status information */
3850Sstevel@tonic-gate 	lpsched_printer_status_to_attributes(&p->attributes, status);
3860Sstevel@tonic-gate 
3870Sstevel@tonic-gate 	papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
3880Sstevel@tonic-gate 			"printer-state-reasons", "none");
3890Sstevel@tonic-gate 
3900Sstevel@tonic-gate 	lpsched_printer_defaults(&p->attributes);
3910Sstevel@tonic-gate 
3920Sstevel@tonic-gate 	return (PAPI_OK);
3930Sstevel@tonic-gate }
3942264Sjacobs 
3952264Sjacobs papi_status_t
3962264Sjacobs attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp)
3972264Sjacobs {
3982264Sjacobs 	papi_status_t status;
3992264Sjacobs 	void *iter = NULL;
4002264Sjacobs 	char *string = NULL;
4012264Sjacobs 	int flags;
4022264Sjacobs 	char **list = NULL;
4032264Sjacobs 
4042264Sjacobs 	/* banner needs some conversion to the bitfield */
4052264Sjacobs 	iter = NULL, string = NULL; flags = 0;
4062264Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
4072264Sjacobs 				"job-sheets-supported", &string);
4082264Sjacobs 	    status == PAPI_OK;
4092264Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
4102264Sjacobs 				NULL, &string))
4112264Sjacobs 		if (strcasecmp(string, "none") == 0)
4122264Sjacobs 			flags |= BAN_NEVER;
4132264Sjacobs 		else if (strcasecmp(string, "standard") == 0)
4142264Sjacobs 			flags |= BAN_ALWAYS;
4152264Sjacobs 	if (flags != 0)
4162264Sjacobs 		tmp->banner = flags;
4172264Sjacobs 
4182264Sjacobs 	/* input_types needs mime-type conversion */
4192264Sjacobs 	iter = NULL, string = NULL; list = NULL;
4202264Sjacobs 	for (status = papiAttributeListGetString(attributes, &iter,
4212264Sjacobs 				"document-format-supported", &string);
4222264Sjacobs 	    status == PAPI_OK;
4232264Sjacobs 	    status = papiAttributeListGetString(attributes, &iter,
4242264Sjacobs 				NULL, &string))
4252264Sjacobs 		addlist(&list, mime_type_to_lp_type(string));
4262264Sjacobs 	if (list != NULL) {
4272264Sjacobs 		if (tmp->input_types != NULL)
4282264Sjacobs 			freelist(tmp->input_types);
4292264Sjacobs 		tmp->input_types = list;
4302264Sjacobs 	}
4312264Sjacobs 
4322264Sjacobs 	papiAttributeListGetLPString(attributes,
4332264Sjacobs 				"device-uri", &tmp->device);
4342264Sjacobs 	papiAttributeListGetLPString(attributes,
4352264Sjacobs 				"printer-info", &tmp->description);
4362264Sjacobs 	papiAttributeListGetLPString(attributes,
4372264Sjacobs 				"lpsched-dial-info", &tmp->dial_info);
4382264Sjacobs 	papiAttributeListGetLPString(attributes,
4392264Sjacobs 				"lpsched-fault-recovery", &tmp->fault_rec);
4402264Sjacobs 	papiAttributeListGetLPString(attributes,
4412264Sjacobs 				"lpsched-interface-script", &tmp->interface);
4422264Sjacobs 	papiAttributeListGetLPString(attributes,
4432264Sjacobs 				"lpsched-data-rate", &tmp->speed);
4442264Sjacobs 	papiAttributeListGetLPString(attributes,
4452264Sjacobs 				"lpsched-stty", &tmp->stty);
4462264Sjacobs 	papiAttributeListGetLPStrings(attributes,
4472264Sjacobs 				"lpsched-charsets", &tmp->char_sets);
4482264Sjacobs 	papiAttributeListGetLPStrings(attributes,
4492264Sjacobs 				"lpsched-printer-types", &tmp->printer_types);
4502264Sjacobs 	papiAttributeListGetLPStrings(attributes,
4512264Sjacobs 				"lpsched-options", &tmp->options);
4522264Sjacobs 	papiAttributeListGetLPStrings(attributes,
4532264Sjacobs 				"lpsched-modules", &tmp->modules);
4542264Sjacobs #ifdef LP_USE_PAPI_ATTR
4552264Sjacobs 	papiAttributeListGetLPString(attributes,
4562264Sjacobs 				"lpsched-printer-ppd-uri", &tmp->ppd);
4572264Sjacobs #endif
4582264Sjacobs 
4592264Sjacobs 	return (PAPI_OK);
4602264Sjacobs }
461