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,
587c478bd9Sstevel@tonic-gate "printer-state-reasons", "none");
597c478bd9Sstevel@tonic-gate } else if (status & PS_BUSY) {
607c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
617c478bd9Sstevel@tonic-gate "printer-state", 0x04); /* processing */
627c478bd9Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE,
637c478bd9Sstevel@tonic-gate "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 */
67*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 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) {
79*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE,
80*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India "printer-state", 0x08); /* waiting for auto reply */
81*c7f2fd24Ssonam gupta - Sun Microsystems - Bangalore India 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,
857c478bd9Sstevel@tonic-gate "printer-state", 0x03); /* idle */
867c478bd9Sstevel@tonic-gate }
877c478bd9Sstevel@tonic-gate
887c478bd9Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
897c478bd9Sstevel@tonic-gate "printer-is-accepting-jobs",
907c478bd9Sstevel@tonic-gate ((status & PS_REJECTED) != PS_REJECTED));
917c478bd9Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE,
927c478bd9Sstevel@tonic-gate "printer-is-processing-jobs",
937c478bd9Sstevel@tonic-gate ((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,
1037c478bd9Sstevel@tonic-gate "multiple-document-jobs-supported", PAPI_TRUE);
1047c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
1057c478bd9Sstevel@tonic-gate "multiple-document-handling-supported",
1067c478bd9Sstevel@tonic-gate "seperate-documents-colated-copies");
1077c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
1087c478bd9Sstevel@tonic-gate "pdl-override-supported", "not-attempted");
1097c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1107c478bd9Sstevel@tonic-gate "job-priority-supported", 40);
1117c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1127c478bd9Sstevel@tonic-gate "job-priority-default", 20);
1137c478bd9Sstevel@tonic-gate papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE,
1147c478bd9Sstevel@tonic-gate "copies-supported", 1, 65535);
115355b4669Sjacobs papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
116355b4669Sjacobs "copies-default", 1);
1177c478bd9Sstevel@tonic-gate papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE,
1187c478bd9Sstevel@tonic-gate "page-ranges-supported", PAPI_TRUE);
1197c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1207c478bd9Sstevel@tonic-gate "number-up-supported", 1);
1217c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE,
1227c478bd9Sstevel@tonic-gate "number-up-default", 1);
123355b4669Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
124355b4669Sjacobs "job-hold-until-supported", "no-hold");
125355b4669Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_APPEND,
126355b4669Sjacobs "job-hold-until-supported", "indefinite");
127355b4669Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
128355b4669Sjacobs "job-hold-until-default", "no-hold");
129355b4669Sjacobs papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE,
130355b4669Sjacobs "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,
1507c478bd9Sstevel@tonic-gate 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,
1567c478bd9Sstevel@tonic-gate "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",
161355b4669Sjacobs tmp->name);
1627c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
1637c478bd9Sstevel@tonic-gate "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,
1697c478bd9Sstevel@tonic-gate "job-sheets-supported", "optional");
1707c478bd9Sstevel@tonic-gate else if (tmp->banner & BAN_NEVER)
1717c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1727c478bd9Sstevel@tonic-gate "job-sheets-supported", "none");
1737c478bd9Sstevel@tonic-gate else if (tmp->banner & BAN_ALWAYS)
1747c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND,
1757c478bd9Sstevel@tonic-gate "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,
1837c478bd9Sstevel@tonic-gate PAPI_ATTR_APPEND, "document-format-supported",
1847c478bd9Sstevel@tonic-gate 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,
1897c478bd9Sstevel@tonic-gate "printer-info", tmp->description);
1907c478bd9Sstevel@tonic-gate
1917c478bd9Sstevel@tonic-gate /* add lpsched specific attributes */
192355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1937c478bd9Sstevel@tonic-gate "device-uri", tmp->device);
194355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1957c478bd9Sstevel@tonic-gate "lpsched-dial-info", tmp->dial_info);
196355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1977c478bd9Sstevel@tonic-gate "lpsched-fault-recovery", tmp->fault_rec);
198355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
1997c478bd9Sstevel@tonic-gate "lpsched-interface-script", tmp->interface);
200355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2017c478bd9Sstevel@tonic-gate "lpsched-data-rate", tmp->speed);
202355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2037c478bd9Sstevel@tonic-gate "lpsched-stty", tmp->stty);
2047c478bd9Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
2057c478bd9Sstevel@tonic-gate "lpsched-login-term", tmp->login);
2067c478bd9Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE,
2077c478bd9Sstevel@tonic-gate "lpsched-daisy", tmp->daisy);
208355b4669Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2097c478bd9Sstevel@tonic-gate "lpsched-charsets", tmp->char_sets);
2107c478bd9Sstevel@tonic-gate #ifdef CAN_DO_MODULES
211355b4669Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2127c478bd9Sstevel@tonic-gate "lpsched-modules", tmp->modules);
2137c478bd9Sstevel@tonic-gate #endif /* CAN_DO_MODULES */
214355b4669Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2157c478bd9Sstevel@tonic-gate "lpsched-options", tmp->options);
216355b4669Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
2177c478bd9Sstevel@tonic-gate "lpsched-printer-type", tmp->printer_types);
218355b4669Sjacobs if (tmp->fault_alert.shcmd != NULL) {
219355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
2207c478bd9Sstevel@tonic-gate "lpsched-fault-alert-command",
2217c478bd9Sstevel@tonic-gate tmp->fault_alert.shcmd);
2227c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2237c478bd9Sstevel@tonic-gate "lpsched-fault-alert-threshold",
2247c478bd9Sstevel@tonic-gate tmp->fault_alert.Q);
2257c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2267c478bd9Sstevel@tonic-gate "lpsched-fault-alert-interval",
2277c478bd9Sstevel@tonic-gate tmp->fault_alert.W);
228355b4669Sjacobs }
2297c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2307c478bd9Sstevel@tonic-gate "lpsched-cpi-value", tmp->cpi.val);
2317c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2327c478bd9Sstevel@tonic-gate "lpsched-cpi-unit", tmp->cpi.sc);
2337c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2347c478bd9Sstevel@tonic-gate "lpsched-lpi-value", tmp->lpi.val);
2357c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2367c478bd9Sstevel@tonic-gate "lpsched-lpi-unit", tmp->lpi.sc);
2377c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2387c478bd9Sstevel@tonic-gate "lpsched-plen-value", tmp->plen.val);
2397c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2407c478bd9Sstevel@tonic-gate "lpsched-plen-unit", tmp->plen.sc);
2417c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2427c478bd9Sstevel@tonic-gate "lpsched-pwid-value", tmp->pwid.val);
2437c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
2447c478bd9Sstevel@tonic-gate "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,
249355b4669Sjacobs "requesting-user-name-allowed", allowed);
250355b4669Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE,
251355b4669Sjacobs "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",
2847c478bd9Sstevel@tonic-gate sysname.nodename, ETCDIR, tmp->name);
2857c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
286355b4669Sjacobs "ppd-file-uri", buf);
2877c478bd9Sstevel@tonic-gate
2887c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s",
2897c478bd9Sstevel@tonic-gate sysname.nodename, tmp->ppd);
2907c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
2917c478bd9Sstevel@tonic-gate "lpsched-printer-configure-ppd-uri", buf);
292355b4669Sjacobs papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
293355b4669Sjacobs "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,
320355b4669Sjacobs "form-ready", form);
321355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
3227c478bd9Sstevel@tonic-gate "lpsched-active-job", request_id);
323355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
3247c478bd9Sstevel@tonic-gate "lpsched-mounted-char-set", character_set);
325355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
326355b4669Sjacobs "lpsched-disable-reason", disable_reason);
3277c478bd9Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
328355b4669Sjacobs "lpsched-disable-date", disable_date);
329355b4669Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE,
330355b4669Sjacobs "lpsched-reject-reason", reject_reason);
3317c478bd9Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
3327c478bd9Sstevel@tonic-gate "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,
3367c478bd9Sstevel@tonic-gate "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,
3407c478bd9Sstevel@tonic-gate "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,
3467c478bd9Sstevel@tonic-gate "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,
3707c478bd9Sstevel@tonic-gate 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,
3767c478bd9Sstevel@tonic-gate "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",
381355b4669Sjacobs tmp->name);
3827c478bd9Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE,
3837c478bd9Sstevel@tonic-gate "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,
3927c478bd9Sstevel@tonic-gate PAPI_ATTR_APPEND,
3937c478bd9Sstevel@tonic-gate "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,
409355b4669Sjacobs "lpsched-reject-reason", reject_reason);
4107c478bd9Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE,
4117c478bd9Sstevel@tonic-gate "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,
4157c478bd9Sstevel@tonic-gate "printer-current-time", time(NULL));
4167c478bd9Sstevel@tonic-gate
4177c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE,
4187c478bd9Sstevel@tonic-gate "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,
4247c478bd9Sstevel@tonic-gate "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,
443355b4669Sjacobs "job-sheets-supported", &string);
444355b4669Sjacobs status == PAPI_OK;
445355b4669Sjacobs status = papiAttributeListGetString(attributes, &iter,
446355b4669Sjacobs 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,
457355b4669Sjacobs "document-format-supported", &string);
458355b4669Sjacobs status == PAPI_OK;
459355b4669Sjacobs status = papiAttributeListGetString(attributes, &iter,
460355b4669Sjacobs 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,
469355b4669Sjacobs "device-uri", &tmp->device);
470355b4669Sjacobs papiAttributeListGetLPString(attributes,
471355b4669Sjacobs "printer-info", &tmp->description);
472355b4669Sjacobs papiAttributeListGetLPString(attributes,
473355b4669Sjacobs "lpsched-dial-info", &tmp->dial_info);
474355b4669Sjacobs papiAttributeListGetLPString(attributes,
475355b4669Sjacobs "lpsched-fault-recovery", &tmp->fault_rec);
476355b4669Sjacobs papiAttributeListGetLPString(attributes,
477355b4669Sjacobs "lpsched-interface-script", &tmp->interface);
478355b4669Sjacobs papiAttributeListGetLPString(attributes,
479355b4669Sjacobs "lpsched-data-rate", &tmp->speed);
480355b4669Sjacobs papiAttributeListGetLPString(attributes,
481355b4669Sjacobs "lpsched-stty", &tmp->stty);
482355b4669Sjacobs papiAttributeListGetLPStrings(attributes,
483355b4669Sjacobs "lpsched-charsets", &tmp->char_sets);
484355b4669Sjacobs papiAttributeListGetLPStrings(attributes,
485355b4669Sjacobs "lpsched-printer-types", &tmp->printer_types);
486355b4669Sjacobs papiAttributeListGetLPStrings(attributes,
487355b4669Sjacobs "lpsched-options", &tmp->options);
488355b4669Sjacobs papiAttributeListGetLPStrings(attributes,
489355b4669Sjacobs "lpsched-modules", &tmp->modules);
490355b4669Sjacobs #ifdef LP_USE_PAPI_ATTR
491355b4669Sjacobs papiAttributeListGetLPString(attributes,
492355b4669Sjacobs "lpsched-printer-ppd-uri", &tmp->ppd);
493355b4669Sjacobs #endif
494355b4669Sjacobs
495355b4669Sjacobs return (PAPI_OK);
496355b4669Sjacobs }
497