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 /* 227322SWendy.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; 124*8238SSonam.Gupta@Sun.COM char **f_allowed = NULL, **f_denied = NULL; 1250Sstevel@tonic-gate 1260Sstevel@tonic-gate if ((svc == NULL) || (p == NULL) || (dest == NULL)) 1270Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 1280Sstevel@tonic-gate 1290Sstevel@tonic-gate /* get the configuration DB data */ 1300Sstevel@tonic-gate if ((tmp = getprinter(dest)) == NULL) { 1310Sstevel@tonic-gate detailed_error(svc, 1320Sstevel@tonic-gate gettext("unable to read configuration data")); 1330Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 1340Sstevel@tonic-gate } 1350Sstevel@tonic-gate 1360Sstevel@tonic-gate /* name */ 1372264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1380Sstevel@tonic-gate "printer-name", tmp->name); 1390Sstevel@tonic-gate if (tmp->name != NULL) { 1400Sstevel@tonic-gate char uri[BUFSIZ]; 1410Sstevel@tonic-gate 1422264Sjacobs snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s", 1432264Sjacobs tmp->name); 1440Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 1450Sstevel@tonic-gate "printer-uri-supported", uri); 1460Sstevel@tonic-gate } 1470Sstevel@tonic-gate 1480Sstevel@tonic-gate /* banner */ 1490Sstevel@tonic-gate if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL) 1500Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 1510Sstevel@tonic-gate "job-sheets-supported", "optional"); 1520Sstevel@tonic-gate else if (tmp->banner & BAN_NEVER) 1530Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 1540Sstevel@tonic-gate "job-sheets-supported", "none"); 1550Sstevel@tonic-gate else if (tmp->banner & BAN_ALWAYS) 1560Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 1570Sstevel@tonic-gate "job-sheets-supported", "standard"); 1580Sstevel@tonic-gate 1590Sstevel@tonic-gate /* input_types */ 1600Sstevel@tonic-gate if (tmp->input_types != NULL) { 1610Sstevel@tonic-gate int i; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate for (i = 0; tmp->input_types[i] != NULL; i++) 1642264Sjacobs papiAttributeListAddLPString(&p->attributes, 1650Sstevel@tonic-gate PAPI_ATTR_APPEND, "document-format-supported", 1660Sstevel@tonic-gate lp_type_to_mime_type(tmp->input_types[i])); 1670Sstevel@tonic-gate } 1680Sstevel@tonic-gate 1690Sstevel@tonic-gate /* description */ 1702264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1710Sstevel@tonic-gate "printer-info", tmp->description); 1720Sstevel@tonic-gate 1730Sstevel@tonic-gate /* add lpsched specific attributes */ 1742264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1750Sstevel@tonic-gate "device-uri", tmp->device); 1762264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1770Sstevel@tonic-gate "lpsched-dial-info", tmp->dial_info); 1782264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1790Sstevel@tonic-gate "lpsched-fault-recovery", tmp->fault_rec); 1802264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1810Sstevel@tonic-gate "lpsched-interface-script", tmp->interface); 1822264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1830Sstevel@tonic-gate "lpsched-data-rate", tmp->speed); 1842264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 1850Sstevel@tonic-gate "lpsched-stty", tmp->stty); 1860Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, 1870Sstevel@tonic-gate "lpsched-login-term", tmp->login); 1880Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, 1890Sstevel@tonic-gate "lpsched-daisy", tmp->daisy); 1902264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 1910Sstevel@tonic-gate "lpsched-charsets", tmp->char_sets); 1920Sstevel@tonic-gate #ifdef CAN_DO_MODULES 1932264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 1940Sstevel@tonic-gate "lpsched-modules", tmp->modules); 1950Sstevel@tonic-gate #endif /* CAN_DO_MODULES */ 1962264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 1970Sstevel@tonic-gate "lpsched-options", tmp->options); 1982264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 1990Sstevel@tonic-gate "lpsched-printer-type", tmp->printer_types); 2002264Sjacobs if (tmp->fault_alert.shcmd != NULL) { 2012264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 2020Sstevel@tonic-gate "lpsched-fault-alert-command", 2030Sstevel@tonic-gate tmp->fault_alert.shcmd); 2042264Sjacobs papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2050Sstevel@tonic-gate "lpsched-fault-alert-threshold", 2060Sstevel@tonic-gate tmp->fault_alert.Q); 2072264Sjacobs papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2080Sstevel@tonic-gate "lpsched-fault-alert-interval", 2090Sstevel@tonic-gate tmp->fault_alert.W); 2102264Sjacobs } 2110Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2120Sstevel@tonic-gate "lpsched-cpi-value", tmp->cpi.val); 2130Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2140Sstevel@tonic-gate "lpsched-cpi-unit", tmp->cpi.sc); 2150Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2160Sstevel@tonic-gate "lpsched-lpi-value", tmp->lpi.val); 2170Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2180Sstevel@tonic-gate "lpsched-lpi-unit", tmp->lpi.sc); 2190Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2200Sstevel@tonic-gate "lpsched-plen-value", tmp->plen.val); 2210Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2220Sstevel@tonic-gate "lpsched-plen-unit", tmp->plen.sc); 2230Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2240Sstevel@tonic-gate "lpsched-pwid-value", tmp->pwid.val); 2250Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 2260Sstevel@tonic-gate "lpsched-pwid-unit", tmp->pwid.sc); 2272264Sjacobs 2282264Sjacobs /* allow/deny list */ 2292264Sjacobs load_userprinter_access(dest, &allowed, &denied); 2302264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 2312264Sjacobs "requesting-user-name-allowed", allowed); 2322264Sjacobs papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 2332264Sjacobs "requesting-user-name-denied", denied); 2342264Sjacobs 2357322SWendy.Phillips@Sun.COM freelist(allowed); 2367322SWendy.Phillips@Sun.COM freelist(denied); 2377322SWendy.Phillips@Sun.COM 238*8238SSonam.Gupta@Sun.COM /* forms allow/deny list */ 239*8238SSonam.Gupta@Sun.COM load_formprinter_access(dest, &f_allowed, &f_denied); 240*8238SSonam.Gupta@Sun.COM papiAttributeListAddLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 241*8238SSonam.Gupta@Sun.COM "form-supported", f_allowed); 242*8238SSonam.Gupta@Sun.COM 243*8238SSonam.Gupta@Sun.COM /* 244*8238SSonam.Gupta@Sun.COM * All forms allowed case 245*8238SSonam.Gupta@Sun.COM * When all forms are allowed forms.allow does not get created but 246*8238SSonam.Gupta@Sun.COM * forms.deny file gets created with no entries 247*8238SSonam.Gupta@Sun.COM */ 248*8238SSonam.Gupta@Sun.COM if ((f_allowed == NULL) && (f_denied != NULL) && (f_denied[0] == NULL)) 249*8238SSonam.Gupta@Sun.COM papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 250*8238SSonam.Gupta@Sun.COM "form-supported", "all"); 251*8238SSonam.Gupta@Sun.COM 252*8238SSonam.Gupta@Sun.COM freelist(f_allowed); 253*8238SSonam.Gupta@Sun.COM freelist(f_denied); 254*8238SSonam.Gupta@Sun.COM 2550Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 2560Sstevel@tonic-gate if (tmp->ppd != NULL) { 2570Sstevel@tonic-gate int fd; 2580Sstevel@tonic-gate struct stat sbuf; 2590Sstevel@tonic-gate 2600Sstevel@tonic-gate /* construct the two URIs for the printer's PPD file */ 2610Sstevel@tonic-gate if (uname(&sysname) < 0) { 2620Sstevel@tonic-gate /* failed to get systen name */ 2630Sstevel@tonic-gate sysname.nodename[0] = 0; 2640Sstevel@tonic-gate } 2650Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd", 2660Sstevel@tonic-gate sysname.nodename, ETCDIR, tmp->name); 2670Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 2682264Sjacobs "ppd-file-uri", buf); 2690Sstevel@tonic-gate 2700Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s", 2710Sstevel@tonic-gate sysname.nodename, tmp->ppd); 2720Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 2730Sstevel@tonic-gate "lpsched-printer-configure-ppd-uri", buf); 2742264Sjacobs papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 2752264Sjacobs "lpsched-ppd-source-path", tmp->ppd); 2760Sstevel@tonic-gate 2770Sstevel@tonic-gate snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name); 2780Sstevel@tonic-gate 2790Sstevel@tonic-gate /* 2800Sstevel@tonic-gate * We don't return error on any of the error conditions, we just 2810Sstevel@tonic-gate * silently return without adding the attribute. 2820Sstevel@tonic-gate */ 2832264Sjacobs PPDFileToAttributesList(&p->attributes, buf); 2840Sstevel@tonic-gate } 2850Sstevel@tonic-gate #endif 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate freeprinter(tmp); 2880Sstevel@tonic-gate 2890Sstevel@tonic-gate return (PAPI_OK); 2900Sstevel@tonic-gate } 2910Sstevel@tonic-gate 2920Sstevel@tonic-gate papi_status_t 2930Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form, 2942264Sjacobs char *character_set, char *disable_reason, char *reject_reason, 2950Sstevel@tonic-gate short status, char *request_id, 2962264Sjacobs long disable_date, long reject_date) 2970Sstevel@tonic-gate { 2980Sstevel@tonic-gate if (p == NULL) 2990Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3000Sstevel@tonic-gate 3012264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3022264Sjacobs "form-ready", form); 3032264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3040Sstevel@tonic-gate "lpsched-active-job", request_id); 3052264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3060Sstevel@tonic-gate "lpsched-mounted-char-set", character_set); 3072264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3082264Sjacobs "lpsched-disable-reason", disable_reason); 3090Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 3102264Sjacobs "lpsched-disable-date", disable_date); 3112264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3122264Sjacobs "lpsched-reject-reason", reject_reason); 3130Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 3140Sstevel@tonic-gate "lpsched-reject-date", reject_date); 3150Sstevel@tonic-gate 3160Sstevel@tonic-gate /* add the current system time */ 3170Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 3180Sstevel@tonic-gate "printer-current-time", time(NULL)); 3190Sstevel@tonic-gate 3200Sstevel@tonic-gate /* add the time since last enabled */ 3210Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 3220Sstevel@tonic-gate "printer-up-time", time(NULL)); 3230Sstevel@tonic-gate 3240Sstevel@tonic-gate /* add the status information */ 3250Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status); 3260Sstevel@tonic-gate 3270Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, 3280Sstevel@tonic-gate "printer-state-reasons", "none"); 3290Sstevel@tonic-gate 3300Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes); 3310Sstevel@tonic-gate 3320Sstevel@tonic-gate return (PAPI_OK); 3330Sstevel@tonic-gate } 3340Sstevel@tonic-gate 3350Sstevel@tonic-gate 3360Sstevel@tonic-gate /* 3370Sstevel@tonic-gate * This puts the class information in only. It could create a hybrid 3380Sstevel@tonic-gate * printer object to return, but that is problematic at best. 3390Sstevel@tonic-gate */ 3400Sstevel@tonic-gate papi_status_t 3410Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p, 3420Sstevel@tonic-gate char *dest) 3430Sstevel@tonic-gate { 3440Sstevel@tonic-gate CLASS *tmp; 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate if ((svc == NULL) || (p == NULL)) 3470Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3480Sstevel@tonic-gate 3490Sstevel@tonic-gate /* get the configuration DB data */ 3500Sstevel@tonic-gate if ((tmp = getclass(dest)) == NULL) { 3510Sstevel@tonic-gate detailed_error(svc, 3520Sstevel@tonic-gate gettext("unable to read configuration data")); 3530Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 3540Sstevel@tonic-gate } 3550Sstevel@tonic-gate 3560Sstevel@tonic-gate /* name */ 3572264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3580Sstevel@tonic-gate "printer-name", tmp->name); 3590Sstevel@tonic-gate if (tmp->name != NULL) { 3600Sstevel@tonic-gate char uri[BUFSIZ]; 3610Sstevel@tonic-gate 3622264Sjacobs snprintf(uri, sizeof (uri), "lpsched://localhost/printers/%s", 3632264Sjacobs tmp->name); 3640Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 3650Sstevel@tonic-gate "printer-uri-supported", uri); 3660Sstevel@tonic-gate } 3670Sstevel@tonic-gate 3680Sstevel@tonic-gate if (tmp->members != NULL) { 3690Sstevel@tonic-gate char **members = tmp->members; 3700Sstevel@tonic-gate int i; 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate for (i = 0; members[i] != NULL; i++) 3730Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, 3740Sstevel@tonic-gate PAPI_ATTR_APPEND, 3750Sstevel@tonic-gate "member-names", members[i]); 3760Sstevel@tonic-gate } 3770Sstevel@tonic-gate 3780Sstevel@tonic-gate freeclass(tmp); 3790Sstevel@tonic-gate 3800Sstevel@tonic-gate return (PAPI_OK); 3810Sstevel@tonic-gate } 3820Sstevel@tonic-gate 3830Sstevel@tonic-gate papi_status_t 3840Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status, 3850Sstevel@tonic-gate char *reject_reason, long reject_date) 3860Sstevel@tonic-gate { 3870Sstevel@tonic-gate if (p == NULL) 3880Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 3890Sstevel@tonic-gate 3902264Sjacobs papiAttributeListAddLPString(&p->attributes, PAPI_ATTR_REPLACE, 3912264Sjacobs "lpsched-reject-reason", reject_reason); 3920Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 3930Sstevel@tonic-gate "lpsched-reject-date", reject_date); 3940Sstevel@tonic-gate 3950Sstevel@tonic-gate /* add the current system time */ 3960Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 3970Sstevel@tonic-gate "printer-current-time", time(NULL)); 3980Sstevel@tonic-gate 3990Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 4000Sstevel@tonic-gate "printer-up-time", time(NULL)); 4010Sstevel@tonic-gate 4020Sstevel@tonic-gate /* add the status information */ 4030Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, 4060Sstevel@tonic-gate "printer-state-reasons", "none"); 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes); 4090Sstevel@tonic-gate 4100Sstevel@tonic-gate return (PAPI_OK); 4110Sstevel@tonic-gate } 4122264Sjacobs 4132264Sjacobs papi_status_t 4142264Sjacobs attributes_to_printer(papi_attribute_t **attributes, PRINTER *tmp) 4152264Sjacobs { 4162264Sjacobs papi_status_t status; 4172264Sjacobs void *iter = NULL; 4182264Sjacobs char *string = NULL; 4192264Sjacobs int flags; 4202264Sjacobs char **list = NULL; 4212264Sjacobs 4222264Sjacobs /* banner needs some conversion to the bitfield */ 4232264Sjacobs iter = NULL, string = NULL; flags = 0; 4242264Sjacobs for (status = papiAttributeListGetString(attributes, &iter, 4252264Sjacobs "job-sheets-supported", &string); 4262264Sjacobs status == PAPI_OK; 4272264Sjacobs status = papiAttributeListGetString(attributes, &iter, 4282264Sjacobs NULL, &string)) 4292264Sjacobs if (strcasecmp(string, "none") == 0) 4302264Sjacobs flags |= BAN_NEVER; 4312264Sjacobs else if (strcasecmp(string, "standard") == 0) 4322264Sjacobs flags |= BAN_ALWAYS; 4332264Sjacobs if (flags != 0) 4342264Sjacobs tmp->banner = flags; 4352264Sjacobs 4362264Sjacobs /* input_types needs mime-type conversion */ 4372264Sjacobs iter = NULL, string = NULL; list = NULL; 4382264Sjacobs for (status = papiAttributeListGetString(attributes, &iter, 4392264Sjacobs "document-format-supported", &string); 4402264Sjacobs status == PAPI_OK; 4412264Sjacobs status = papiAttributeListGetString(attributes, &iter, 4422264Sjacobs NULL, &string)) 4432264Sjacobs addlist(&list, mime_type_to_lp_type(string)); 4442264Sjacobs if (list != NULL) { 4452264Sjacobs if (tmp->input_types != NULL) 4462264Sjacobs freelist(tmp->input_types); 4472264Sjacobs tmp->input_types = list; 4482264Sjacobs } 4492264Sjacobs 4502264Sjacobs papiAttributeListGetLPString(attributes, 4512264Sjacobs "device-uri", &tmp->device); 4522264Sjacobs papiAttributeListGetLPString(attributes, 4532264Sjacobs "printer-info", &tmp->description); 4542264Sjacobs papiAttributeListGetLPString(attributes, 4552264Sjacobs "lpsched-dial-info", &tmp->dial_info); 4562264Sjacobs papiAttributeListGetLPString(attributes, 4572264Sjacobs "lpsched-fault-recovery", &tmp->fault_rec); 4582264Sjacobs papiAttributeListGetLPString(attributes, 4592264Sjacobs "lpsched-interface-script", &tmp->interface); 4602264Sjacobs papiAttributeListGetLPString(attributes, 4612264Sjacobs "lpsched-data-rate", &tmp->speed); 4622264Sjacobs papiAttributeListGetLPString(attributes, 4632264Sjacobs "lpsched-stty", &tmp->stty); 4642264Sjacobs papiAttributeListGetLPStrings(attributes, 4652264Sjacobs "lpsched-charsets", &tmp->char_sets); 4662264Sjacobs papiAttributeListGetLPStrings(attributes, 4672264Sjacobs "lpsched-printer-types", &tmp->printer_types); 4682264Sjacobs papiAttributeListGetLPStrings(attributes, 4692264Sjacobs "lpsched-options", &tmp->options); 4702264Sjacobs papiAttributeListGetLPStrings(attributes, 4712264Sjacobs "lpsched-modules", &tmp->modules); 4722264Sjacobs #ifdef LP_USE_PAPI_ATTR 4732264Sjacobs papiAttributeListGetLPString(attributes, 4742264Sjacobs "lpsched-printer-ppd-uri", &tmp->ppd); 4752264Sjacobs #endif 4762264Sjacobs 4772264Sjacobs return (PAPI_OK); 4782264Sjacobs } 479