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*12028SSonam.Gupta@Sun.COM * Copyright 2010 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
lpsched_printer_status_to_attributes(papi_attribute_t *** attrs,unsigned short status)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
44*12028SSonam.Gupta@Sun.COM if (!(status & (PS_DISABLED|PS_LATER))) {
45*12028SSonam.Gupta@Sun.COM if (status & PS_FAULTED) {
46*12028SSonam.Gupta@Sun.COM if (status & PS_BUSY)
47*12028SSonam.Gupta@Sun.COM /* faulted printing */
48*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs,
49*12028SSonam.Gupta@Sun.COM PAPI_ATTR_REPLACE,
50*12028SSonam.Gupta@Sun.COM "printer-state", 0x06);
51*12028SSonam.Gupta@Sun.COM else
52*12028SSonam.Gupta@Sun.COM /* faulted printer */
53*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs,
54*12028SSonam.Gupta@Sun.COM PAPI_ATTR_REPLACE,
55*12028SSonam.Gupta@Sun.COM "printer-state", 0x07);
56*12028SSonam.Gupta@Sun.COM
570Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
58*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "none");
59*12028SSonam.Gupta@Sun.COM } else if (status & PS_BUSY) {
60*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
61*12028SSonam.Gupta@Sun.COM "printer-state", 0x04); /* processing */
620Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
63*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "moving-to-paused");
64*12028SSonam.Gupta@Sun.COM } else if (status & PS_FORM_FAULT) {
65*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
66*12028SSonam.Gupta@Sun.COM "printer-state", 0x05); /* stopped */
670Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
68*12028SSonam.Gupta@Sun.COM "printer-state-reasons",
69*12028SSonam.Gupta@Sun.COM "interpreter-resource-unavailable");
70*12028SSonam.Gupta@Sun.COM } else
71*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
72*12028SSonam.Gupta@Sun.COM "printer-state", 0x03); /* idle */
73*12028SSonam.Gupta@Sun.COM } else if (status & PS_DISABLED) {
740Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
75*12028SSonam.Gupta@Sun.COM "printer-state", 0x05); /* stopped */
760Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
77*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "paused");
78*12028SSonam.Gupta@Sun.COM } else if (status & PS_LATER) {
79*12028SSonam.Gupta@Sun.COM papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
80*12028SSonam.Gupta@Sun.COM "printer-state", 0x08); /* waiting for auto reply */
81*12028SSonam.Gupta@Sun.COM papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
82*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "moving-to-paused");
830Sstevel@tonic-gate } else {
840Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
85*12028SSonam.Gupta@Sun.COM "printer-state", 0x03); /* idle */
860Sstevel@tonic-gate }
870Sstevel@tonic-gate
880Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
89*12028SSonam.Gupta@Sun.COM "printer-is-accepting-jobs",
90*12028SSonam.Gupta@Sun.COM ((status & PS_REJECTED) != PS_REJECTED));
910Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
92*12028SSonam.Gupta@Sun.COM "printer-is-processing-jobs",
93*12028SSonam.Gupta@Sun.COM ((status & PS_DISABLED) != PS_DISABLED));
940Sstevel@tonic-gate }
950Sstevel@tonic-gate
960Sstevel@tonic-gate void
lpsched_printer_defaults(papi_attribute_t *** attributes)970Sstevel@tonic-gate lpsched_printer_defaults(papi_attribute_t ***attributes)
980Sstevel@tonic-gate {
990Sstevel@tonic-gate if (attributes == NULL)
1000Sstevel@tonic-gate return;
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
103*12028SSonam.Gupta@Sun.COM "multiple-document-jobs-supported", PAPI_TRUE);
1040Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
105*12028SSonam.Gupta@Sun.COM "multiple-document-handling-supported",
106*12028SSonam.Gupta@Sun.COM "seperate-documents-colated-copies");
1070Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
108*12028SSonam.Gupta@Sun.COM "pdl-override-supported", "not-attempted");
1090Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
110*12028SSonam.Gupta@Sun.COM "job-priority-supported", 40);
1110Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
112*12028SSonam.Gupta@Sun.COM "job-priority-default", 20);
1130Sstevel@tonic-gate papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
114*12028SSonam.Gupta@Sun.COM "copies-supported", 1, 65535);
1152264Sjacobs papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
116*12028SSonam.Gupta@Sun.COM "copies-default", 1);
1170Sstevel@tonic-gate papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
118*12028SSonam.Gupta@Sun.COM "page-ranges-supported", PAPI_TRUE);
1190Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
120*12028SSonam.Gupta@Sun.COM "number-up-supported", 1);
1210Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
122*12028SSonam.Gupta@Sun.COM "number-up-default", 1);
1232264Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
124*12028SSonam.Gupta@Sun.COM "job-hold-until-supported", "no-hold");
1252264Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
126*12028SSonam.Gupta@Sun.COM "job-hold-until-supported", "indefinite");
1272264Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
128*12028SSonam.Gupta@Sun.COM "job-hold-until-default", "no-hold");
1292264Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
130*12028SSonam.Gupta@Sun.COM "document-format-default", "application/octet-stream");
1312264Sjacobs
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate
1340Sstevel@tonic-gate papi_status_t
lpsched_printer_configuration_to_attributes(service_t * svc,printer_t * p,char * dest)1350Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p,
1360Sstevel@tonic-gate char *dest)
1370Sstevel@tonic-gate {
1380Sstevel@tonic-gate PRINTER *tmp;
1390Sstevel@tonic-gate char buf[BUFSIZ+1];
1400Sstevel@tonic-gate struct utsname sysname;
1412264Sjacobs char **allowed = NULL, **denied = NULL;
1428238SSonam.Gupta@Sun.COM char **f_allowed = NULL, **f_denied = NULL;
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate if ((svc == NULL) || (p == NULL) || (dest == NULL))
1450Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT);
1460Sstevel@tonic-gate
1470Sstevel@tonic-gate /* get the configuration DB data */
1480Sstevel@tonic-gate if ((tmp = getprinter(dest)) == NULL) {
1490Sstevel@tonic-gate detailed_error(svc,
150*12028SSonam.Gupta@Sun.COM gettext("unable to read configuration data"));
1510Sstevel@tonic-gate return (PAPI_DEVICE_ERROR);
1520Sstevel@tonic-gate }
1530Sstevel@tonic-gate
1540Sstevel@tonic-gate /* name */
1552264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
156*12028SSonam.Gupta@Sun.COM "printer-name", tmp->name);
1570Sstevel@tonic-gate if (tmp->name != NULL) {
1580Sstevel@tonic-gate char uri[BUFSIZ];
1590Sstevel@tonic-gate
1602264Sjacobs snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
161*12028SSonam.Gupta@Sun.COM tmp->name);
1620Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
163*12028SSonam.Gupta@Sun.COM "printer-uri-supported", uri);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate
1660Sstevel@tonic-gate /* banner */
1670Sstevel@tonic-gate if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL)
1680Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
169*12028SSonam.Gupta@Sun.COM "job-sheets-supported", "optional");
1700Sstevel@tonic-gate else if (tmp->banner & BAN_NEVER)
1710Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
172*12028SSonam.Gupta@Sun.COM "job-sheets-supported", "none");
1730Sstevel@tonic-gate else if (tmp->banner & BAN_ALWAYS)
1740Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
175*12028SSonam.Gupta@Sun.COM "job-sheets-supported", "standard");
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate /* input_types */
1780Sstevel@tonic-gate if (tmp->input_types != NULL) {
1790Sstevel@tonic-gate int i;
1800Sstevel@tonic-gate
1810Sstevel@tonic-gate for (i = 0; tmp->input_types[i] != NULL; i++)
1822264Sjacobs papiAttributeListAddLPString(&p->attributes,
183*12028SSonam.Gupta@Sun.COM PAPI_ATTR_APPEND, "document-format-supported",
184*12028SSonam.Gupta@Sun.COM lp_type_to_mime_type(tmp->input_types[i]));
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate
1870Sstevel@tonic-gate /* description */
1882264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
189*12028SSonam.Gupta@Sun.COM "printer-info", tmp->description);
1900Sstevel@tonic-gate
1910Sstevel@tonic-gate /* add lpsched specific attributes */
1922264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
193*12028SSonam.Gupta@Sun.COM "device-uri", tmp->device);
1942264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
195*12028SSonam.Gupta@Sun.COM "lpsched-dial-info", tmp->dial_info);
1962264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
197*12028SSonam.Gupta@Sun.COM "lpsched-fault-recovery", tmp->fault_rec);
1982264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
199*12028SSonam.Gupta@Sun.COM "lpsched-interface-script", tmp->interface);
2002264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
201*12028SSonam.Gupta@Sun.COM "lpsched-data-rate", tmp->speed);
2022264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
203*12028SSonam.Gupta@Sun.COM "lpsched-stty", tmp->stty);
2040Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
205*12028SSonam.Gupta@Sun.COM "lpsched-login-term", tmp->login);
2060Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
207*12028SSonam.Gupta@Sun.COM "lpsched-daisy", tmp->daisy);
2082264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
209*12028SSonam.Gupta@Sun.COM "lpsched-charsets", tmp->char_sets);
2100Sstevel@tonic-gate #ifdef CAN_DO_MODULES
2112264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
212*12028SSonam.Gupta@Sun.COM "lpsched-modules", tmp->modules);
2130Sstevel@tonic-gate #endif /* CAN_DO_MODULES */
2142264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
215*12028SSonam.Gupta@Sun.COM "lpsched-options", tmp->options);
2162264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
217*12028SSonam.Gupta@Sun.COM "lpsched-printer-type", tmp->printer_types);
2182264Sjacobs if (tmp->fault_alert.shcmd != NULL) {
2192264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
220*12028SSonam.Gupta@Sun.COM "lpsched-fault-alert-command",
221*12028SSonam.Gupta@Sun.COM tmp->fault_alert.shcmd);
2222264Sjacobs papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
223*12028SSonam.Gupta@Sun.COM "lpsched-fault-alert-threshold",
224*12028SSonam.Gupta@Sun.COM tmp->fault_alert.Q);
2252264Sjacobs papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
226*12028SSonam.Gupta@Sun.COM "lpsched-fault-alert-interval",
227*12028SSonam.Gupta@Sun.COM tmp->fault_alert.W);
2282264Sjacobs }
2290Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
230*12028SSonam.Gupta@Sun.COM "lpsched-cpi-value", tmp->cpi.val);
2310Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
232*12028SSonam.Gupta@Sun.COM "lpsched-cpi-unit", tmp->cpi.sc);
2330Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
234*12028SSonam.Gupta@Sun.COM "lpsched-lpi-value", tmp->lpi.val);
2350Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
236*12028SSonam.Gupta@Sun.COM "lpsched-lpi-unit", tmp->lpi.sc);
2370Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
238*12028SSonam.Gupta@Sun.COM "lpsched-plen-value", tmp->plen.val);
2390Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
240*12028SSonam.Gupta@Sun.COM "lpsched-plen-unit", tmp->plen.sc);
2410Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
242*12028SSonam.Gupta@Sun.COM "lpsched-pwid-value", tmp->pwid.val);
2430Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
244*12028SSonam.Gupta@Sun.COM "lpsched-pwid-unit", tmp->pwid.sc);
2452264Sjacobs
2462264Sjacobs /* allow/deny list */
2472264Sjacobs load_userprinter_access(dest, &allowed, &denied);
2482264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
249*12028SSonam.Gupta@Sun.COM "requesting-user-name-allowed", allowed);
2502264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
251*12028SSonam.Gupta@Sun.COM "requesting-user-name-denied", denied);
2522264Sjacobs
2537322SWendy.Phillips@Sun.COM freelist(allowed);
2547322SWendy.Phillips@Sun.COM freelist(denied);
2557322SWendy.Phillips@Sun.COM
2568238SSonam.Gupta@Sun.COM /* forms allow/deny list */
2578238SSonam.Gupta@Sun.COM load_formprinter_access(dest, &f_allowed, &f_denied);
2588238SSonam.Gupta@Sun.COM papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2598238SSonam.Gupta@Sun.COM "form-supported", f_allowed);
2608238SSonam.Gupta@Sun.COM
2618238SSonam.Gupta@Sun.COM /*
2628238SSonam.Gupta@Sun.COM * All forms allowed case
2638238SSonam.Gupta@Sun.COM * When all forms are allowed forms.allow does not get created but
2648238SSonam.Gupta@Sun.COM * forms.deny file gets created with no entries
2658238SSonam.Gupta@Sun.COM */
2668238SSonam.Gupta@Sun.COM if ((f_allowed == NULL) && (f_denied != NULL) && (f_denied[0] == NULL))
2678238SSonam.Gupta@Sun.COM papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2688238SSonam.Gupta@Sun.COM "form-supported", "all");
2698238SSonam.Gupta@Sun.COM
2708238SSonam.Gupta@Sun.COM freelist(f_allowed);
2718238SSonam.Gupta@Sun.COM freelist(f_denied);
2728238SSonam.Gupta@Sun.COM
2730Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR
2740Sstevel@tonic-gate if (tmp->ppd != NULL) {
2750Sstevel@tonic-gate int fd;
2760Sstevel@tonic-gate struct stat sbuf;
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate /* construct the two URIs for the printer's PPD file */
2790Sstevel@tonic-gate if (uname(&sysname) < 0) {
2800Sstevel@tonic-gate /* failed to get systen name */
2810Sstevel@tonic-gate sysname.nodename[0] = 0;
2820Sstevel@tonic-gate }
2830Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd",
284*12028SSonam.Gupta@Sun.COM sysname.nodename, ETCDIR, tmp->name);
2850Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
286*12028SSonam.Gupta@Sun.COM "ppd-file-uri", buf);
2870Sstevel@tonic-gate
2880Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s",
289*12028SSonam.Gupta@Sun.COM sysname.nodename, tmp->ppd);
2900Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
291*12028SSonam.Gupta@Sun.COM "lpsched-printer-configure-ppd-uri", buf);
2922264Sjacobs papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
293*12028SSonam.Gupta@Sun.COM "lpsched-ppd-source-path", tmp->ppd);
2940Sstevel@tonic-gate
2950Sstevel@tonic-gate snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name);
2960Sstevel@tonic-gate
2970Sstevel@tonic-gate /*
2980Sstevel@tonic-gate * We don't return error on any of the error conditions, we just
2990Sstevel@tonic-gate * silently return without adding the attribute.
3000Sstevel@tonic-gate */
3012264Sjacobs PPDFileToAttributesList(&p->attributes, buf);
3020Sstevel@tonic-gate }
3030Sstevel@tonic-gate #endif
3040Sstevel@tonic-gate
3050Sstevel@tonic-gate freeprinter(tmp);
3060Sstevel@tonic-gate
3070Sstevel@tonic-gate return (PAPI_OK);
3080Sstevel@tonic-gate }
3090Sstevel@tonic-gate
3100Sstevel@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)3110Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form,
3122264Sjacobs char *character_set, char *disable_reason, char *reject_reason,
3130Sstevel@tonic-gate short status, char *request_id,
3142264Sjacobs long disable_date, long reject_date)
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate if (p == NULL)
3170Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT);
3180Sstevel@tonic-gate
3192264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
320*12028SSonam.Gupta@Sun.COM "form-ready", form);
3212264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
322*12028SSonam.Gupta@Sun.COM "lpsched-active-job", request_id);
3232264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
324*12028SSonam.Gupta@Sun.COM "lpsched-mounted-char-set", character_set);
3252264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
326*12028SSonam.Gupta@Sun.COM "lpsched-disable-reason", disable_reason);
3270Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
328*12028SSonam.Gupta@Sun.COM "lpsched-disable-date", disable_date);
3292264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
330*12028SSonam.Gupta@Sun.COM "lpsched-reject-reason", reject_reason);
3310Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
332*12028SSonam.Gupta@Sun.COM "lpsched-reject-date", reject_date);
3330Sstevel@tonic-gate
3340Sstevel@tonic-gate /* add the current system time */
3350Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
336*12028SSonam.Gupta@Sun.COM "printer-current-time", time(NULL));
3370Sstevel@tonic-gate
3380Sstevel@tonic-gate /* add the time since last enabled */
3390Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
340*12028SSonam.Gupta@Sun.COM "printer-up-time", time(NULL));
3410Sstevel@tonic-gate
3420Sstevel@tonic-gate /* add the status information */
3430Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status);
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
346*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "none");
3470Sstevel@tonic-gate
3480Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes);
3490Sstevel@tonic-gate
3500Sstevel@tonic-gate return (PAPI_OK);
3510Sstevel@tonic-gate }
3520Sstevel@tonic-gate
3530Sstevel@tonic-gate
3540Sstevel@tonic-gate /*
3550Sstevel@tonic-gate * This puts the class information in only. It could create a hybrid
3560Sstevel@tonic-gate * printer object to return, but that is problematic at best.
3570Sstevel@tonic-gate */
3580Sstevel@tonic-gate papi_status_t
lpsched_class_configuration_to_attributes(service_t * svc,printer_t * p,char * dest)3590Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p,
3600Sstevel@tonic-gate char *dest)
3610Sstevel@tonic-gate {
3620Sstevel@tonic-gate CLASS *tmp;
3630Sstevel@tonic-gate
3640Sstevel@tonic-gate if ((svc == NULL) || (p == NULL))
3650Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT);
3660Sstevel@tonic-gate
3670Sstevel@tonic-gate /* get the configuration DB data */
3680Sstevel@tonic-gate if ((tmp = getclass(dest)) == NULL) {
3690Sstevel@tonic-gate detailed_error(svc,
370*12028SSonam.Gupta@Sun.COM gettext("unable to read configuration data"));
3710Sstevel@tonic-gate return (PAPI_DEVICE_ERROR);
3720Sstevel@tonic-gate }
3730Sstevel@tonic-gate
3740Sstevel@tonic-gate /* name */
3752264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
376*12028SSonam.Gupta@Sun.COM "printer-name", tmp->name);
3770Sstevel@tonic-gate if (tmp->name != NULL) {
3780Sstevel@tonic-gate char uri[BUFSIZ];
3790Sstevel@tonic-gate
3802264Sjacobs snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s",
381*12028SSonam.Gupta@Sun.COM tmp->name);
3820Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
383*12028SSonam.Gupta@Sun.COM "printer-uri-supported", uri);
3840Sstevel@tonic-gate }
3850Sstevel@tonic-gate
3860Sstevel@tonic-gate if (tmp->members != NULL) {
3870Sstevel@tonic-gate char **members = tmp->members;
3880Sstevel@tonic-gate int i;
3890Sstevel@tonic-gate
3900Sstevel@tonic-gate for (i = 0; members[i] != NULL; i++)
3910Sstevel@tonic-gate papiAttributeListAddString(&p->attributes,
392*12028SSonam.Gupta@Sun.COM PAPI_ATTR_APPEND,
393*12028SSonam.Gupta@Sun.COM "member-names", members[i]);
3940Sstevel@tonic-gate }
3950Sstevel@tonic-gate
3960Sstevel@tonic-gate freeclass(tmp);
3970Sstevel@tonic-gate
3980Sstevel@tonic-gate return (PAPI_OK);
3990Sstevel@tonic-gate }
4000Sstevel@tonic-gate
4010Sstevel@tonic-gate papi_status_t
class_status_to_attributes(printer_t * p,char * printer,short status,char * reject_reason,long reject_date)4020Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status,
4030Sstevel@tonic-gate char *reject_reason, long reject_date)
4040Sstevel@tonic-gate {
4050Sstevel@tonic-gate if (p == NULL)
4060Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT);
4070Sstevel@tonic-gate
4082264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
409*12028SSonam.Gupta@Sun.COM "lpsched-reject-reason", reject_reason);
4100Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
411*12028SSonam.Gupta@Sun.COM "lpsched-reject-date", reject_date);
4120Sstevel@tonic-gate
4130Sstevel@tonic-gate /* add the current system time */
4140Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
415*12028SSonam.Gupta@Sun.COM "printer-current-time", time(NULL));
4160Sstevel@tonic-gate
4170Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
418*12028SSonam.Gupta@Sun.COM "printer-up-time", time(NULL));
4190Sstevel@tonic-gate
4200Sstevel@tonic-gate /* add the status information */
4210Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status);
4220Sstevel@tonic-gate
4230Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL,
424*12028SSonam.Gupta@Sun.COM "printer-state-reasons", "none");
4250Sstevel@tonic-gate
4260Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes);
4270Sstevel@tonic-gate
4280Sstevel@tonic-gate return (PAPI_OK);
4290Sstevel@tonic-gate }
4302264Sjacobs
4312264Sjacobs papi_status_t
attributes_to_printer(papi_attribute_t ** attributes,PRINTER * tmp)4322264Sjacobs attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp)
4332264Sjacobs {
4342264Sjacobs papi_status_t status;
4352264Sjacobs void *iter = NULL;
4362264Sjacobs char *string = NULL;
4372264Sjacobs int flags;
4382264Sjacobs char **list = NULL;
4392264Sjacobs
4402264Sjacobs /* banner needs some conversion to the bitfield */
4412264Sjacobs iter = NULL, string = NULL; flags = 0;
4422264Sjacobs for (status = papiAttributeListGetString(attributes, &iter,
443*12028SSonam.Gupta@Sun.COM "job-sheets-supported", &string);
4442264Sjacobs status == PAPI_OK;
4452264Sjacobs status = papiAttributeListGetString(attributes, &iter,
446*12028SSonam.Gupta@Sun.COM NULL, &string))
4472264Sjacobs if (strcasecmp(string, "none") == 0)
4482264Sjacobs flags |= BAN_NEVER;
4492264Sjacobs else if (strcasecmp(string, "standard") == 0)
4502264Sjacobs flags |= BAN_ALWAYS;
4512264Sjacobs if (flags != 0)
4522264Sjacobs tmp->banner = flags;
4532264Sjacobs
4542264Sjacobs /* input_types needs mime-type conversion */
4552264Sjacobs iter = NULL, string = NULL; list = NULL;
4562264Sjacobs for (status = papiAttributeListGetString(attributes, &iter,
457*12028SSonam.Gupta@Sun.COM "document-format-supported", &string);
4582264Sjacobs status == PAPI_OK;
4592264Sjacobs status = papiAttributeListGetString(attributes, &iter,
460*12028SSonam.Gupta@Sun.COM NULL, &string))
4612264Sjacobs addlist(&list, mime_type_to_lp_type(string));
4622264Sjacobs if (list != NULL) {
4632264Sjacobs if (tmp->input_types != NULL)
4642264Sjacobs freelist(tmp->input_types);
4652264Sjacobs tmp->input_types = list;
4662264Sjacobs }
4672264Sjacobs
4682264Sjacobs papiAttributeListGetLPString(attributes,
469*12028SSonam.Gupta@Sun.COM "device-uri", &tmp->device);
4702264Sjacobs papiAttributeListGetLPString(attributes,
471*12028SSonam.Gupta@Sun.COM "printer-info", &tmp->description);
4722264Sjacobs papiAttributeListGetLPString(attributes,
473*12028SSonam.Gupta@Sun.COM "lpsched-dial-info", &tmp->dial_info);
4742264Sjacobs papiAttributeListGetLPString(attributes,
475*12028SSonam.Gupta@Sun.COM "lpsched-fault-recovery", &tmp->fault_rec);
4762264Sjacobs papiAttributeListGetLPString(attributes,
477*12028SSonam.Gupta@Sun.COM "lpsched-interface-script", &tmp->interface);
4782264Sjacobs papiAttributeListGetLPString(attributes,
479*12028SSonam.Gupta@Sun.COM "lpsched-data-rate", &tmp->speed);
4802264Sjacobs papiAttributeListGetLPString(attributes,
481*12028SSonam.Gupta@Sun.COM "lpsched-stty", &tmp->stty);
4822264Sjacobs papiAttributeListGetLPStrings(attributes,
483*12028SSonam.Gupta@Sun.COM "lpsched-charsets", &tmp->char_sets);
4842264Sjacobs papiAttributeListGetLPStrings(attributes,
485*12028SSonam.Gupta@Sun.COM "lpsched-printer-types", &tmp->printer_types);
4862264Sjacobs papiAttributeListGetLPStrings(attributes,
487*12028SSonam.Gupta@Sun.COM "lpsched-options", &tmp->options);
4882264Sjacobs papiAttributeListGetLPStrings(attributes,
489*12028SSonam.Gupta@Sun.COM "lpsched-modules", &tmp->modules);
4902264Sjacobs #ifdef LP_USE_PAPI_ATTR
4912264Sjacobs papiAttributeListGetLPString(attributes,
492*12028SSonam.Gupta@Sun.COM "lpsched-printer-ppd-uri", &tmp->ppd);
4932264Sjacobs #endif
4942264Sjacobs
4952264Sjacobs return (PAPI_OK);
4962264Sjacobs }
497