1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate /*LINTLIBRARY*/ 30*0Sstevel@tonic-gate 31*0Sstevel@tonic-gate #include <stdlib.h> 32*0Sstevel@tonic-gate #include <libintl.h> 33*0Sstevel@tonic-gate #include <unistd.h> 34*0Sstevel@tonic-gate #include <sys/utsname.h> 35*0Sstevel@tonic-gate #include <papi_impl.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #include "class.h" 38*0Sstevel@tonic-gate 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate void 41*0Sstevel@tonic-gate lpsched_printer_status_to_attributes(papi_attribute_t ***attrs, 42*0Sstevel@tonic-gate unsigned short status) 43*0Sstevel@tonic-gate { 44*0Sstevel@tonic-gate if (attrs == NULL) 45*0Sstevel@tonic-gate return; 46*0Sstevel@tonic-gate 47*0Sstevel@tonic-gate if (status & (PS_DISABLED|PS_LATER|PS_FAULTED|PS_FORM_FAULT)) { 48*0Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, 49*0Sstevel@tonic-gate "printer-state", 0x05); /* stopped */ 50*0Sstevel@tonic-gate if (status & PS_LATER) 51*0Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, 52*0Sstevel@tonic-gate "printer-state-reasons", "moving-to-paused"); 53*0Sstevel@tonic-gate else if (status & PS_FAULTED) 54*0Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, 55*0Sstevel@tonic-gate "printer-state-reasons", "none"); 56*0Sstevel@tonic-gate else if (status & PS_FORM_FAULT) 57*0Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, 58*0Sstevel@tonic-gate "printer-state-reasons", 59*0Sstevel@tonic-gate "interpreter-resource-unavailable"); 60*0Sstevel@tonic-gate else 61*0Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, 62*0Sstevel@tonic-gate "printer-state-reasons", "paused"); 63*0Sstevel@tonic-gate } else if (status & PS_BUSY) { 64*0Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, 65*0Sstevel@tonic-gate "printer-state", 0x04); /* processing */ 66*0Sstevel@tonic-gate papiAttributeListAddString(attrs, PAPI_ATTR_REPLACE, 67*0Sstevel@tonic-gate "printer-state-reasons", "moving-to-paused"); 68*0Sstevel@tonic-gate } else { 69*0Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, 70*0Sstevel@tonic-gate "printer-state", 0x03); /* idle */ 71*0Sstevel@tonic-gate } 72*0Sstevel@tonic-gate 73*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 74*0Sstevel@tonic-gate "printer-is-accepting-jobs", 75*0Sstevel@tonic-gate ((status & PS_REJECTED) != PS_REJECTED)); 76*0Sstevel@tonic-gate papiAttributeListAddInteger(attrs, PAPI_ATTR_REPLACE, 77*0Sstevel@tonic-gate "lpsched-status", status); 78*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 79*0Sstevel@tonic-gate "printer-is-processing-jobs", 80*0Sstevel@tonic-gate ((status & PS_DISABLED) != PS_DISABLED)); 81*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 82*0Sstevel@tonic-gate "lpsched-faulted", (status & PS_FAULTED)); 83*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 84*0Sstevel@tonic-gate "lpsched-busy", (status & PS_BUSY)); 85*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 86*0Sstevel@tonic-gate "lpsched-later", (status & PS_LATER)); 87*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 88*0Sstevel@tonic-gate "lpsched-remote", (status & PS_REMOTE)); 89*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 90*0Sstevel@tonic-gate "lpsched-show-fault", (status & PS_SHOW_FAULT)); 91*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 92*0Sstevel@tonic-gate "lpsched-use-as-key", (status & PS_USE_AS_KEY)); 93*0Sstevel@tonic-gate papiAttributeListAddBoolean(attrs, PAPI_ATTR_REPLACE, 94*0Sstevel@tonic-gate "lpsched-form-fault", (status & PS_FORM_FAULT)); 95*0Sstevel@tonic-gate } 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate void 98*0Sstevel@tonic-gate lpsched_printer_defaults(papi_attribute_t ***attributes) 99*0Sstevel@tonic-gate { 100*0Sstevel@tonic-gate if (attributes == NULL) 101*0Sstevel@tonic-gate return; 102*0Sstevel@tonic-gate 103*0Sstevel@tonic-gate papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE, 104*0Sstevel@tonic-gate "multiple-document-jobs-supported", PAPI_TRUE); 105*0Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 106*0Sstevel@tonic-gate "multiple-document-handling-supported", 107*0Sstevel@tonic-gate "seperate-documents-colated-copies"); 108*0Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 109*0Sstevel@tonic-gate "pdl-override-supported", "not-attempted"); 110*0Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 111*0Sstevel@tonic-gate "job-priority-supported", 40); 112*0Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 113*0Sstevel@tonic-gate "job-priority-default", 20); 114*0Sstevel@tonic-gate papiAttributeListAddRange(attributes, PAPI_ATTR_REPLACE, 115*0Sstevel@tonic-gate "copies-supported", 1, 65535); 116*0Sstevel@tonic-gate papiAttributeListAddBoolean(attributes, PAPI_ATTR_REPLACE, 117*0Sstevel@tonic-gate "page-ranges-supported", PAPI_TRUE); 118*0Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 119*0Sstevel@tonic-gate "number-up-supported", 1); 120*0Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 121*0Sstevel@tonic-gate "number-up-default", 1); 122*0Sstevel@tonic-gate } 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate papi_status_t 125*0Sstevel@tonic-gate lpsched_printer_configuration_to_attributes(service_t *svc, printer_t *p, 126*0Sstevel@tonic-gate char *dest) 127*0Sstevel@tonic-gate { 128*0Sstevel@tonic-gate PRINTER *tmp; 129*0Sstevel@tonic-gate char buf[BUFSIZ+1]; 130*0Sstevel@tonic-gate struct utsname sysname; 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate if ((svc == NULL) || (p == NULL) || (dest == NULL)) 133*0Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 134*0Sstevel@tonic-gate 135*0Sstevel@tonic-gate /* get the configuration DB data */ 136*0Sstevel@tonic-gate if ((tmp = getprinter(dest)) == NULL) { 137*0Sstevel@tonic-gate detailed_error(svc, 138*0Sstevel@tonic-gate gettext("unable to read configuration data")); 139*0Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 140*0Sstevel@tonic-gate } 141*0Sstevel@tonic-gate 142*0Sstevel@tonic-gate /* name */ 143*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 144*0Sstevel@tonic-gate "printer-name", tmp->name); 145*0Sstevel@tonic-gate if (tmp->name != NULL) { 146*0Sstevel@tonic-gate char uri[BUFSIZ]; 147*0Sstevel@tonic-gate 148*0Sstevel@tonic-gate snprintf(uri, sizeof (uri), "lpsched://%s", tmp->name); 149*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 150*0Sstevel@tonic-gate "printer-uri-supported", uri); 151*0Sstevel@tonic-gate } 152*0Sstevel@tonic-gate 153*0Sstevel@tonic-gate /* banner */ 154*0Sstevel@tonic-gate if ((tmp->banner & BAN_OPTIONAL) == BAN_OPTIONAL) 155*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 156*0Sstevel@tonic-gate "job-sheets-supported", "optional"); 157*0Sstevel@tonic-gate else if (tmp->banner & BAN_NEVER) 158*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 159*0Sstevel@tonic-gate "job-sheets-supported", "none"); 160*0Sstevel@tonic-gate else if (tmp->banner & BAN_ALWAYS) 161*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_APPEND, 162*0Sstevel@tonic-gate "job-sheets-supported", "standard"); 163*0Sstevel@tonic-gate 164*0Sstevel@tonic-gate /* input_types */ 165*0Sstevel@tonic-gate if (tmp->input_types != NULL) { 166*0Sstevel@tonic-gate int i; 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate for (i = 0; tmp->input_types[i] != NULL; i++) 169*0Sstevel@tonic-gate addLPString(&p->attributes, 170*0Sstevel@tonic-gate PAPI_ATTR_APPEND, "document-format-supported", 171*0Sstevel@tonic-gate lp_type_to_mime_type(tmp->input_types[i])); 172*0Sstevel@tonic-gate } 173*0Sstevel@tonic-gate 174*0Sstevel@tonic-gate /* description */ 175*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 176*0Sstevel@tonic-gate "printer-info", tmp->description); 177*0Sstevel@tonic-gate 178*0Sstevel@tonic-gate /* add lpsched specific attributes */ 179*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 180*0Sstevel@tonic-gate "device-uri", tmp->device); 181*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 182*0Sstevel@tonic-gate "lpsched-dial-info", tmp->dial_info); 183*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 184*0Sstevel@tonic-gate "lpsched-fault-recovery", tmp->fault_rec); 185*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 186*0Sstevel@tonic-gate "lpsched-interface-script", tmp->interface); 187*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 188*0Sstevel@tonic-gate "lpsched-data-rate", tmp->speed); 189*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 190*0Sstevel@tonic-gate "lpsched-stty", tmp->stty); 191*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 192*0Sstevel@tonic-gate "lpsched-remote", tmp->remote); 193*0Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, 194*0Sstevel@tonic-gate "lpsched-login-term", tmp->login); 195*0Sstevel@tonic-gate papiAttributeListAddBoolean(&p->attributes, PAPI_ATTR_REPLACE, 196*0Sstevel@tonic-gate "lpsched-daisy", tmp->daisy); 197*0Sstevel@tonic-gate addLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 198*0Sstevel@tonic-gate "lpsched-charsets", tmp->char_sets); 199*0Sstevel@tonic-gate #ifdef CAN_DO_MODULES 200*0Sstevel@tonic-gate addLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 201*0Sstevel@tonic-gate "lpsched-modules", tmp->modules); 202*0Sstevel@tonic-gate #endif /* CAN_DO_MODULES */ 203*0Sstevel@tonic-gate addLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 204*0Sstevel@tonic-gate "lpsched-options", tmp->options); 205*0Sstevel@tonic-gate addLPStrings(&p->attributes, PAPI_ATTR_REPLACE, 206*0Sstevel@tonic-gate "lpsched-printer-type", tmp->printer_types); 207*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 208*0Sstevel@tonic-gate "lpsched-fault-alert-command", 209*0Sstevel@tonic-gate tmp->fault_alert.shcmd); 210*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 211*0Sstevel@tonic-gate "lpsched-fault-alert-threshold", 212*0Sstevel@tonic-gate tmp->fault_alert.Q); 213*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 214*0Sstevel@tonic-gate "lpsched-fault-alert-interval", 215*0Sstevel@tonic-gate tmp->fault_alert.W); 216*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 217*0Sstevel@tonic-gate "lpsched-cpi-value", tmp->cpi.val); 218*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 219*0Sstevel@tonic-gate "lpsched-cpi-unit", tmp->cpi.sc); 220*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 221*0Sstevel@tonic-gate "lpsched-lpi-value", tmp->lpi.val); 222*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 223*0Sstevel@tonic-gate "lpsched-lpi-unit", tmp->lpi.sc); 224*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 225*0Sstevel@tonic-gate "lpsched-plen-value", tmp->plen.val); 226*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 227*0Sstevel@tonic-gate "lpsched-plen-unit", tmp->plen.sc); 228*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 229*0Sstevel@tonic-gate "lpsched-pwid-value", tmp->pwid.val); 230*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 231*0Sstevel@tonic-gate "lpsched-pwid-unit", tmp->pwid.sc); 232*0Sstevel@tonic-gate #ifdef LP_USE_PAPI_ATTR 233*0Sstevel@tonic-gate if (tmp->ppd != NULL) { 234*0Sstevel@tonic-gate int fd; 235*0Sstevel@tonic-gate struct stat sbuf; 236*0Sstevel@tonic-gate 237*0Sstevel@tonic-gate /* construct the two URIs for the printer's PPD file */ 238*0Sstevel@tonic-gate if (uname(&sysname) < 0) { 239*0Sstevel@tonic-gate /* failed to get systen name */ 240*0Sstevel@tonic-gate sysname.nodename[0] = 0; 241*0Sstevel@tonic-gate } 242*0Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s/ppd/%s.ppd", 243*0Sstevel@tonic-gate sysname.nodename, ETCDIR, tmp->name); 244*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 245*0Sstevel@tonic-gate "lpsched-printer-ppd-uri", buf); 246*0Sstevel@tonic-gate 247*0Sstevel@tonic-gate snprintf(buf, sizeof (buf), "file://%s%s", 248*0Sstevel@tonic-gate sysname.nodename, tmp->ppd); 249*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 250*0Sstevel@tonic-gate "lpsched-printer-configure-ppd-uri", buf); 251*0Sstevel@tonic-gate 252*0Sstevel@tonic-gate snprintf(buf, sizeof (buf), "%s/ppd/%s.ppd", ETCDIR, tmp->name); 253*0Sstevel@tonic-gate 254*0Sstevel@tonic-gate /* 255*0Sstevel@tonic-gate * We don't return error on any of the error conditions, we just 256*0Sstevel@tonic-gate * silently return without adding the attribute. 257*0Sstevel@tonic-gate */ 258*0Sstevel@tonic-gate if (((fd = open(buf, O_RDONLY)) >= 0) && 259*0Sstevel@tonic-gate (fstat(fd, &sbuf) == 0)) { 260*0Sstevel@tonic-gate char *contents; 261*0Sstevel@tonic-gate 262*0Sstevel@tonic-gate if ((contents = malloc(sbuf.st_size + 1)) != NULL) { 263*0Sstevel@tonic-gate int pos = 0, rd, rdsize; 264*0Sstevel@tonic-gate 265*0Sstevel@tonic-gate rdsize = sbuf.st_blksize; 266*0Sstevel@tonic-gate 267*0Sstevel@tonic-gate while (rd = read(fd, contents + pos, rdsize)) { 268*0Sstevel@tonic-gate if (rd < 0) { 269*0Sstevel@tonic-gate if (errno == EINTR) { 270*0Sstevel@tonic-gate continue; 271*0Sstevel@tonic-gate } else { 272*0Sstevel@tonic-gate break; 273*0Sstevel@tonic-gate } 274*0Sstevel@tonic-gate } 275*0Sstevel@tonic-gate pos += rd; 276*0Sstevel@tonic-gate 277*0Sstevel@tonic-gate /* 278*0Sstevel@tonic-gate * Don't write past the end of our 279*0Sstevel@tonic-gate * buffer. This is paranoid, in case 280*0Sstevel@tonic-gate * the file increased size while we were 281*0Sstevel@tonic-gate * reading it. 282*0Sstevel@tonic-gate */ 283*0Sstevel@tonic-gate if (pos + rdsize > sbuf.st_size) { 284*0Sstevel@tonic-gate rdsize = sbuf.st_size - pos; 285*0Sstevel@tonic-gate } 286*0Sstevel@tonic-gate } 287*0Sstevel@tonic-gate 288*0Sstevel@tonic-gate /* File didn't change size while reading. */ 289*0Sstevel@tonic-gate if (pos + rd == sbuf.st_size) { 290*0Sstevel@tonic-gate /* 291*0Sstevel@tonic-gate * Terminate the buffer and set 292*0Sstevel@tonic-gate * attribute. This assume that there 293*0Sstevel@tonic-gate * are no null bytes in the ppd file. 294*0Sstevel@tonic-gate */ 295*0Sstevel@tonic-gate contents[pos + rd] = '\0'; 296*0Sstevel@tonic-gate 297*0Sstevel@tonic-gate papiAttributeListAddString( 298*0Sstevel@tonic-gate &p->attributes, 299*0Sstevel@tonic-gate PAPI_ATTR_REPLACE, 300*0Sstevel@tonic-gate "lpsched-printer-ppd-contents", 301*0Sstevel@tonic-gate contents); 302*0Sstevel@tonic-gate } 303*0Sstevel@tonic-gate 304*0Sstevel@tonic-gate free(contents); 305*0Sstevel@tonic-gate } 306*0Sstevel@tonic-gate } 307*0Sstevel@tonic-gate close(fd); 308*0Sstevel@tonic-gate } 309*0Sstevel@tonic-gate #endif 310*0Sstevel@tonic-gate 311*0Sstevel@tonic-gate freeprinter(tmp); 312*0Sstevel@tonic-gate 313*0Sstevel@tonic-gate return (PAPI_OK); 314*0Sstevel@tonic-gate } 315*0Sstevel@tonic-gate 316*0Sstevel@tonic-gate papi_status_t 317*0Sstevel@tonic-gate printer_status_to_attributes(printer_t *p, char *printer, char *form, 318*0Sstevel@tonic-gate char *character_set, char *reject_reason, char *disable_reason, 319*0Sstevel@tonic-gate short status, char *request_id, 320*0Sstevel@tonic-gate long enable_date, long reject_date) 321*0Sstevel@tonic-gate { 322*0Sstevel@tonic-gate if (p == NULL) 323*0Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 324*0Sstevel@tonic-gate 325*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 326*0Sstevel@tonic-gate "media-ready", form); 327*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 328*0Sstevel@tonic-gate "lpsched-active-job", request_id); 329*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 330*0Sstevel@tonic-gate "lpsched-mounted-char-set", character_set); 331*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 332*0Sstevel@tonic-gate "printer-reject-reason", reject_reason); 333*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 334*0Sstevel@tonic-gate "printer-disable-reason", disable_reason); 335*0Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 336*0Sstevel@tonic-gate "lpsched-enable-date", enable_date); 337*0Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 338*0Sstevel@tonic-gate "lpsched-reject-date", reject_date); 339*0Sstevel@tonic-gate 340*0Sstevel@tonic-gate /* add the current system time */ 341*0Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 342*0Sstevel@tonic-gate "printer-current-time", time(NULL)); 343*0Sstevel@tonic-gate 344*0Sstevel@tonic-gate /* add the time since last enabled */ 345*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 346*0Sstevel@tonic-gate "printer-up-time", time(NULL)); 347*0Sstevel@tonic-gate 348*0Sstevel@tonic-gate /* add the status information */ 349*0Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status); 350*0Sstevel@tonic-gate 351*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, 352*0Sstevel@tonic-gate "printer-state-reasons", "none"); 353*0Sstevel@tonic-gate 354*0Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes); 355*0Sstevel@tonic-gate 356*0Sstevel@tonic-gate return (PAPI_OK); 357*0Sstevel@tonic-gate } 358*0Sstevel@tonic-gate 359*0Sstevel@tonic-gate 360*0Sstevel@tonic-gate /* 361*0Sstevel@tonic-gate * This puts the class information in only. It could create a hybrid 362*0Sstevel@tonic-gate * printer object to return, but that is problematic at best. 363*0Sstevel@tonic-gate */ 364*0Sstevel@tonic-gate papi_status_t 365*0Sstevel@tonic-gate lpsched_class_configuration_to_attributes(service_t *svc, printer_t *p, 366*0Sstevel@tonic-gate char *dest) 367*0Sstevel@tonic-gate { 368*0Sstevel@tonic-gate CLASS *tmp; 369*0Sstevel@tonic-gate 370*0Sstevel@tonic-gate if ((svc == NULL) || (p == NULL)) 371*0Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 372*0Sstevel@tonic-gate 373*0Sstevel@tonic-gate /* get the configuration DB data */ 374*0Sstevel@tonic-gate if ((tmp = getclass(dest)) == NULL) { 375*0Sstevel@tonic-gate detailed_error(svc, 376*0Sstevel@tonic-gate gettext("unable to read configuration data")); 377*0Sstevel@tonic-gate return (PAPI_DEVICE_ERROR); 378*0Sstevel@tonic-gate } 379*0Sstevel@tonic-gate 380*0Sstevel@tonic-gate /* name */ 381*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 382*0Sstevel@tonic-gate "printer-name", tmp->name); 383*0Sstevel@tonic-gate if (tmp->name != NULL) { 384*0Sstevel@tonic-gate char uri[BUFSIZ]; 385*0Sstevel@tonic-gate 386*0Sstevel@tonic-gate snprintf(uri, sizeof (uri), "lpsched://%s", tmp->name); 387*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_REPLACE, 388*0Sstevel@tonic-gate "printer-uri-supported", uri); 389*0Sstevel@tonic-gate } 390*0Sstevel@tonic-gate 391*0Sstevel@tonic-gate if (tmp->members != NULL) { 392*0Sstevel@tonic-gate char **members = tmp->members; 393*0Sstevel@tonic-gate int i; 394*0Sstevel@tonic-gate 395*0Sstevel@tonic-gate for (i = 0; members[i] != NULL; i++) 396*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, 397*0Sstevel@tonic-gate PAPI_ATTR_APPEND, 398*0Sstevel@tonic-gate "member-names", members[i]); 399*0Sstevel@tonic-gate } 400*0Sstevel@tonic-gate 401*0Sstevel@tonic-gate freeclass(tmp); 402*0Sstevel@tonic-gate 403*0Sstevel@tonic-gate return (PAPI_OK); 404*0Sstevel@tonic-gate } 405*0Sstevel@tonic-gate 406*0Sstevel@tonic-gate papi_status_t 407*0Sstevel@tonic-gate class_status_to_attributes(printer_t *p, char *printer, short status, 408*0Sstevel@tonic-gate char *reject_reason, long reject_date) 409*0Sstevel@tonic-gate { 410*0Sstevel@tonic-gate if (p == NULL) 411*0Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 412*0Sstevel@tonic-gate 413*0Sstevel@tonic-gate addLPString(&p->attributes, PAPI_ATTR_REPLACE, 414*0Sstevel@tonic-gate "printer-reject-reason", reject_reason); 415*0Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 416*0Sstevel@tonic-gate "lpsched-reject-date", reject_date); 417*0Sstevel@tonic-gate 418*0Sstevel@tonic-gate /* add the current system time */ 419*0Sstevel@tonic-gate papiAttributeListAddDatetime(&p->attributes, PAPI_ATTR_REPLACE, 420*0Sstevel@tonic-gate "printer-current-time", time(NULL)); 421*0Sstevel@tonic-gate 422*0Sstevel@tonic-gate papiAttributeListAddInteger(&p->attributes, PAPI_ATTR_REPLACE, 423*0Sstevel@tonic-gate "printer-up-time", time(NULL)); 424*0Sstevel@tonic-gate 425*0Sstevel@tonic-gate /* add the status information */ 426*0Sstevel@tonic-gate lpsched_printer_status_to_attributes(&p->attributes, status); 427*0Sstevel@tonic-gate 428*0Sstevel@tonic-gate papiAttributeListAddString(&p->attributes, PAPI_ATTR_EXCL, 429*0Sstevel@tonic-gate "printer-state-reasons", "none"); 430*0Sstevel@tonic-gate 431*0Sstevel@tonic-gate lpsched_printer_defaults(&p->attributes); 432*0Sstevel@tonic-gate 433*0Sstevel@tonic-gate return (PAPI_OK); 434*0Sstevel@tonic-gate } 435