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 545916cd2Sjpk * Common Development and Distribution License (the "License"). 645916cd2Sjpk * 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 /* 223d09a4feSsonam gupta - Sun Microsystems - Bangalore India * Copyright 2009 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 <string.h> 307c478bd9Sstevel@tonic-gate #include <unistd.h> 317c478bd9Sstevel@tonic-gate #include <libintl.h> 327c478bd9Sstevel@tonic-gate #include <pwd.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate /* lpsched include files */ 357c478bd9Sstevel@tonic-gate #include "lp.h" 367c478bd9Sstevel@tonic-gate #include "requests.h" 377c478bd9Sstevel@tonic-gate #include "printers.h" 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate #include <papi_impl.h> 407c478bd9Sstevel@tonic-gate 417c478bd9Sstevel@tonic-gate papi_status_t 427c478bd9Sstevel@tonic-gate job_attributes_to_lpsched_request(papi_service_t svc, REQUEST *r, 437c478bd9Sstevel@tonic-gate papi_attribute_t **attributes) 447c478bd9Sstevel@tonic-gate { 45355b4669Sjacobs papi_status_t status = PAPI_OK; 467c478bd9Sstevel@tonic-gate papi_attribute_t *attr; 47355b4669Sjacobs papi_attribute_t **unmapped = NULL; 4843b9c050Sjacobs papi_attribute_t *tmp[2]; 497c478bd9Sstevel@tonic-gate int i; 507c478bd9Sstevel@tonic-gate char *s; 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate char **options = NULL; 537c478bd9Sstevel@tonic-gate char **modes = NULL; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate char pr_filter = 0; 567c478bd9Sstevel@tonic-gate char *pr_title = NULL; 577c478bd9Sstevel@tonic-gate int pr_width = -1; 587c478bd9Sstevel@tonic-gate int pr_indent = -1; 597c478bd9Sstevel@tonic-gate int numberUp = 0; 607c478bd9Sstevel@tonic-gate int orientation = 0; 61355b4669Sjacobs int lower = 0; 62355b4669Sjacobs int upper = 0; 637c478bd9Sstevel@tonic-gate char buf[256]; 647c478bd9Sstevel@tonic-gate void *iterator = NULL; 65355b4669Sjacobs char *mapped_keys[] = { "copies", "document-format", "form", 66355b4669Sjacobs "job-class", "job-hold-until", "job-host", "job-name", 67355b4669Sjacobs "job-originating-user-name", "job-printer", 68355b4669Sjacobs "job-sheets", "lp-charset", "lp-modes", "number-up", 69355b4669Sjacobs "orienttation-requested", "page-ranges", "pr-filter", 7043b9c050Sjacobs "pr-indent", "pr-title", "pr-width", "job-priority", 710a44ef6dSjacobs "requesting-user-name", "job-originating-host-name", 720a44ef6dSjacobs NULL }; 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate if (attributes == NULL) 757c478bd9Sstevel@tonic-gate return (PAPI_BAD_ARGUMENT); 767c478bd9Sstevel@tonic-gate 77355b4669Sjacobs /* replace the current destination */ 78355b4669Sjacobs papiAttributeListGetLPString(attributes, 79355b4669Sjacobs "job-printer", &r->destination); 807c478bd9Sstevel@tonic-gate 81355b4669Sjacobs /* set the copies. We need at least 1 */ 827c478bd9Sstevel@tonic-gate i = r->copies; 837c478bd9Sstevel@tonic-gate papiAttributeListGetInteger(attributes, NULL, "copies", &i); 847c478bd9Sstevel@tonic-gate if (i <= 0) 857c478bd9Sstevel@tonic-gate i = 1; 867c478bd9Sstevel@tonic-gate r->copies = i; 877c478bd9Sstevel@tonic-gate 88355b4669Sjacobs /* 89355b4669Sjacobs * set the priority. PAPI/IPP uses 1-100, lpsched use 0-39, so we 90355b4669Sjacobs * have to convert it. 91355b4669Sjacobs */ 9243b9c050Sjacobs if (papiAttributeListGetInteger(attributes, NULL, "job-priority", &i) 937c478bd9Sstevel@tonic-gate == PAPI_OK) { 947c478bd9Sstevel@tonic-gate if ((i < 1) || (i > 100)) 957c478bd9Sstevel@tonic-gate i = 50; 9643b9c050Sjacobs i = 40 - (i / 2.5); 977c478bd9Sstevel@tonic-gate r->priority = i; 987c478bd9Sstevel@tonic-gate } 997c478bd9Sstevel@tonic-gate if ((r->priority < 0) || (r->priority > 39)) 1007c478bd9Sstevel@tonic-gate r->priority = 20; 1017c478bd9Sstevel@tonic-gate 102355b4669Sjacobs /* set the requested form to print on */ 103355b4669Sjacobs papiAttributeListGetLPString(attributes, "form", &r->form); 1047c478bd9Sstevel@tonic-gate 105355b4669Sjacobs /* set the page range */ 10643b9c050Sjacobs memset(tmp, NULL, sizeof (tmp)); 10743b9c050Sjacobs tmp[0] = papiAttributeListFind(attributes, "page-ranges"); 10843b9c050Sjacobs if (tmp[0] != NULL) { 10943b9c050Sjacobs char buf[BUFSIZ]; 11043b9c050Sjacobs 11143b9c050Sjacobs papiAttributeListToString(tmp, " ", buf, sizeof (buf)); 11243b9c050Sjacobs if ((s = strchr(buf, '=')) != NULL) 11343b9c050Sjacobs r->pages = (char *)strdup(++s); 1147c478bd9Sstevel@tonic-gate } 1157c478bd9Sstevel@tonic-gate 116355b4669Sjacobs /* 117355b4669Sjacobs * set the document format, converting to old format names as 118355b4669Sjacobs * as needed. 119355b4669Sjacobs */ 1207c478bd9Sstevel@tonic-gate s = NULL; 1217c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, "document-format", &s); 1227c478bd9Sstevel@tonic-gate if (s != NULL) 1237c478bd9Sstevel@tonic-gate r->input_type = strdup(mime_type_to_lp_type(s)); 1247c478bd9Sstevel@tonic-gate 125355b4669Sjacobs 1267c478bd9Sstevel@tonic-gate /* 1277c478bd9Sstevel@tonic-gate * If we don't have an owner, set one. 1287c478bd9Sstevel@tonic-gate */ 1297c478bd9Sstevel@tonic-gate if (r->user == NULL) { 1307c478bd9Sstevel@tonic-gate uid_t uid = getuid(); 1317c478bd9Sstevel@tonic-gate struct passwd *pw; 1327c478bd9Sstevel@tonic-gate char *user = "intruder"; 1337c478bd9Sstevel@tonic-gate char *host = NULL; 1347c478bd9Sstevel@tonic-gate char buf[256]; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate if ((pw = getpwuid(uid)) != NULL) 1377c478bd9Sstevel@tonic-gate user = pw->pw_name; /* default to the process owner */ 1387c478bd9Sstevel@tonic-gate 1397c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, 1400a44ef6dSjacobs "job-originating-host-name", &host); 1410a44ef6dSjacobs papiAttributeListGetString(attributes, NULL, 1427c478bd9Sstevel@tonic-gate "job-host", &host); 1437c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, 1447c478bd9Sstevel@tonic-gate "job-originating-user-name", &user); 1457c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, 1467c478bd9Sstevel@tonic-gate "requesting-user-name", &user); 1477c478bd9Sstevel@tonic-gate 1487c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "%s%s%s", user, 1497c478bd9Sstevel@tonic-gate (host ? "@" : ""), (host ? host : "")); 1507c478bd9Sstevel@tonic-gate user = buf; 1517c478bd9Sstevel@tonic-gate 1527c478bd9Sstevel@tonic-gate r->user = strdup(user); 1537c478bd9Sstevel@tonic-gate } 1547c478bd9Sstevel@tonic-gate 155355b4669Sjacobs /* set any held state */ 1567c478bd9Sstevel@tonic-gate s = NULL; 1577c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, "job-hold-until", &s); 1587c478bd9Sstevel@tonic-gate if (s != NULL) { 15943b9c050Sjacobs r->actions &= ~(ACT_SPECIAL); /* strip immediate/hold/resume */ 16043b9c050Sjacobs if (strcmp(s, "resume") == 0) 1617c478bd9Sstevel@tonic-gate r->actions |= ACT_RESUME; 16243b9c050Sjacobs else if ((strcmp(s, "immediate") == 0) || 16343b9c050Sjacobs (strcmp(s, "no-hold") == 0)) 16443b9c050Sjacobs r->actions |= ACT_IMMEDIATE; 16543b9c050Sjacobs else if ((strcmp(s, "indefinite") == 0) || 16643b9c050Sjacobs (strcmp(s, "hold") == 0)) 1677c478bd9Sstevel@tonic-gate r->actions |= ACT_HOLD; 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 170355b4669Sjacobs /* set lp charset/printwheel */ 171355b4669Sjacobs papiAttributeListGetLPString(attributes, "lp-charset", &r->charset); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* legacy pr(1) filter related garbage "lpr -p" */ 1747c478bd9Sstevel@tonic-gate papiAttributeListGetBoolean(attributes, NULL, "pr-filter", &pr_filter); 1757c478bd9Sstevel@tonic-gate papiAttributeListGetString(attributes, NULL, "pr-title", &pr_title); 1767c478bd9Sstevel@tonic-gate papiAttributeListGetInteger(attributes, NULL, "pr-width", &pr_width); 1777c478bd9Sstevel@tonic-gate papiAttributeListGetInteger(attributes, NULL, "pr-indent", &pr_indent); 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate if (pr_filter != 0) { 1807c478bd9Sstevel@tonic-gate char buf[128]; 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate if (pr_title != NULL) { 1837c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "prtitle='%s'", pr_title); 1847c478bd9Sstevel@tonic-gate appendlist(&modes, buf); 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate 1877c478bd9Sstevel@tonic-gate if (pr_width > 0) { 1887c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "prwidth=%d", pr_width); 1897c478bd9Sstevel@tonic-gate appendlist(&modes, buf); 1907c478bd9Sstevel@tonic-gate } 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate if (pr_indent > 0) { 1937c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "indent=%d", pr_indent); 1947c478bd9Sstevel@tonic-gate appendlist(&modes, buf); 1957c478bd9Sstevel@tonic-gate } 1967c478bd9Sstevel@tonic-gate } else if ((pr_title != NULL) || (pr_width >= 0) || (pr_indent >= 0)) 1977c478bd9Sstevel@tonic-gate detailed_error(svc, gettext( 1987c478bd9Sstevel@tonic-gate "pr(1) filter options specified without enabling pr(1) filter")); 1997c478bd9Sstevel@tonic-gate 2007c478bd9Sstevel@tonic-gate /* add burst page information */ 201355b4669Sjacobs s = NULL; 202355b4669Sjacobs papiAttributeListGetString(attributes, NULL, "job-sheets", &s); 2030a44ef6dSjacobs if ((s != NULL) && (strcasecmp(s, "none") != 0)) { 2047c478bd9Sstevel@tonic-gate char buf[128]; 205355b4669Sjacobs char *class = NULL; 206355b4669Sjacobs char *job_name = NULL; 207355b4669Sjacobs 208355b4669Sjacobs papiAttributeListGetLPString(attributes, "job-class", &class); 209355b4669Sjacobs papiAttributeListGetLPString(attributes, "job-name", &job_name); 210355b4669Sjacobs 2117c478bd9Sstevel@tonic-gate /* burst page is enabled by default, add the title */ 2127c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "%s%s%s", 2137c478bd9Sstevel@tonic-gate (job_name ? job_name : ""), 2147c478bd9Sstevel@tonic-gate (job_name && class ? "\\n#####\\n#####\\t\\t " : ""), 2157c478bd9Sstevel@tonic-gate (class ? class : "")); 2167c478bd9Sstevel@tonic-gate if (buf[0] != '\0') { 2177c478bd9Sstevel@tonic-gate if (r->title != NULL) 2187c478bd9Sstevel@tonic-gate free(r->title); 2197c478bd9Sstevel@tonic-gate r->title = strdup(buf); 2207c478bd9Sstevel@tonic-gate } 2217f79af0bSsonam gupta - Sun Microsystems - Bangalore India } else if ((s != NULL) && (strcasecmp(s, "none") == 0)) { 2227f79af0bSsonam gupta - Sun Microsystems - Bangalore India /* burst page is disabled via lp "option" */ 2237c478bd9Sstevel@tonic-gate appendlist(&options, "nobanner"); 2247f79af0bSsonam gupta - Sun Microsystems - Bangalore India } 2257c478bd9Sstevel@tonic-gate 2267c478bd9Sstevel@tonic-gate /* Convert attribute "number-up" to mode group=n */ 2277c478bd9Sstevel@tonic-gate papiAttributeListGetInteger(attributes, NULL, "number-up", &numberUp); 2287c478bd9Sstevel@tonic-gate if ((numberUp >= 2) && ((numberUp % 2) == 0)) { 2297c478bd9Sstevel@tonic-gate snprintf(buf, sizeof (buf), "group=%d", numberUp); 2307c478bd9Sstevel@tonic-gate appendlist(&modes, buf); 2317c478bd9Sstevel@tonic-gate } 2327c478bd9Sstevel@tonic-gate 2337c478bd9Sstevel@tonic-gate /* 2347c478bd9Sstevel@tonic-gate * Convert attribute "orientation-requested" to modes 2357c478bd9Sstevel@tonic-gate * 'landscape', 'portrait', etc. 2367c478bd9Sstevel@tonic-gate */ 2377c478bd9Sstevel@tonic-gate papiAttributeListGetInteger(attributes, NULL, 2387c478bd9Sstevel@tonic-gate "orientation-requested", &orientation); 2397c478bd9Sstevel@tonic-gate if ((orientation >= 3) && (orientation <= 6)) { 2407c478bd9Sstevel@tonic-gate switch (orientation) { 241355b4669Sjacobs case 4: /* landscape */ 242355b4669Sjacobs case 5: /* reverse-landscape, use landscape instead */ 2437c478bd9Sstevel@tonic-gate appendlist(&modes, "landscape"); 2447c478bd9Sstevel@tonic-gate break; 245355b4669Sjacobs case 3: /* portrait */ 246355b4669Sjacobs case 6: /* reverse-portrait, use portrait instead */ 2477c478bd9Sstevel@tonic-gate default: 2487c478bd9Sstevel@tonic-gate appendlist(&modes, "portrait"); 2497c478bd9Sstevel@tonic-gate break; 2507c478bd9Sstevel@tonic-gate } 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate 2537c478bd9Sstevel@tonic-gate /* add "lp -y" modes */ 2547c478bd9Sstevel@tonic-gate attr = papiAttributeListFind(attributes, "lp-modes"); 2557c478bd9Sstevel@tonic-gate if ((attr != NULL) && (attr->type == PAPI_STRING) && 2567c478bd9Sstevel@tonic-gate (attr->values != NULL)) { 2577c478bd9Sstevel@tonic-gate int i; 2587c478bd9Sstevel@tonic-gate 2597c478bd9Sstevel@tonic-gate for (i = 0; attr->values[i] != NULL; i++) 2607c478bd9Sstevel@tonic-gate appendlist(&modes, attr->values[i]->string); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 2637c478bd9Sstevel@tonic-gate if (modes != NULL) { 2647c478bd9Sstevel@tonic-gate if (r->modes == NULL) 2657c478bd9Sstevel@tonic-gate free(r->modes); 2667c478bd9Sstevel@tonic-gate r->modes = sprintlist(modes); 2677c478bd9Sstevel@tonic-gate freelist(modes); 2687c478bd9Sstevel@tonic-gate } 2697c478bd9Sstevel@tonic-gate 270355b4669Sjacobs /* add any unconsumed attributes to the "options" list */ 271355b4669Sjacobs split_and_copy_attributes(mapped_keys, attributes, NULL, &unmapped); 272355b4669Sjacobs if (unmapped != NULL) { /* convert them to lp options */ 273355b4669Sjacobs char *buf = malloc(1024); 274355b4669Sjacobs ssize_t size = 1024; 275355b4669Sjacobs 27643b9c050Sjacobs while (papiAttributeListToString(unmapped, " ", buf, size) 277355b4669Sjacobs != PAPI_OK) { 278355b4669Sjacobs size += 1024; 279355b4669Sjacobs buf = realloc(buf, size); 280355b4669Sjacobs } 281355b4669Sjacobs appendlist(&options, buf); 282355b4669Sjacobs free(buf); 283355b4669Sjacobs papiAttributeListFree(unmapped); 284355b4669Sjacobs } 285355b4669Sjacobs 286355b4669Sjacobs if (options != NULL) { 287355b4669Sjacobs if (r->options != NULL) 288355b4669Sjacobs free(r->options); 289355b4669Sjacobs r->options = sprintlist(options); 290355b4669Sjacobs freelist(options); 291355b4669Sjacobs } 292355b4669Sjacobs 2937c478bd9Sstevel@tonic-gate return (PAPI_OK); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate 2967c478bd9Sstevel@tonic-gate /* 2977c478bd9Sstevel@tonic-gate * Convert REQUEST->outcome (or R_REQUEST_* state) to the equivalent 2987c478bd9Sstevel@tonic-gate * PAPI attribute representation. 2997c478bd9Sstevel@tonic-gate */ 3007c478bd9Sstevel@tonic-gate static void 3017c478bd9Sstevel@tonic-gate lpsched_request_outcome_to_attributes(papi_attribute_t ***attributes, 3027c478bd9Sstevel@tonic-gate unsigned short state) 3037c478bd9Sstevel@tonic-gate { 3047c478bd9Sstevel@tonic-gate if (attributes == NULL) 3057c478bd9Sstevel@tonic-gate return; 3067c478bd9Sstevel@tonic-gate 307*c389c7f8SGowtham Thommandra if (state & RS_NOTIFYING) { 3087c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 309*c389c7f8SGowtham Thommandra "job-state", 0x0800); /* notifying user */ 310*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 311*c389c7f8SGowtham Thommandra "job-state-reasons", "job-notifying"); 312*c389c7f8SGowtham Thommandra } else if (state & RS_HELD) { 313*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 314*c389c7f8SGowtham Thommandra "job-state", 0x0001); /* held */ 3157c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 3167c478bd9Sstevel@tonic-gate "job-state-reasons", "job-hold-until-specified"); 3177c478bd9Sstevel@tonic-gate } else if (state & RS_CANCELLED) { 3187c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 319*c389c7f8SGowtham Thommandra "job-state", 0x0040); /* job cancelled */ 3207c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 3217c478bd9Sstevel@tonic-gate "job-state-reasons", "job-canceled-by-user"); 3227c478bd9Sstevel@tonic-gate } else if (state & RS_PRINTED) { 3237c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 324*c389c7f8SGowtham Thommandra "job-state", 0x0010); /* finished printing job */ 3257c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 3267c478bd9Sstevel@tonic-gate "job-state-reasons", "job-complete"); 327*c389c7f8SGowtham Thommandra } else if (state & RS_PRINTING) { 328*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 329*c389c7f8SGowtham Thommandra "job-state", 0x0008); /* printing job */ 330*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 331*c389c7f8SGowtham Thommandra "job-state-reasons", "job-printing"); 332*c389c7f8SGowtham Thommandra } else if (state & RS_ADMINHELD) { 333*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 334*c389c7f8SGowtham Thommandra "job-state", 0x2000); /* held by admin */ 335*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 336*c389c7f8SGowtham Thommandra "job-state-reasons", "job-hold-until-specified"); 337*c389c7f8SGowtham Thommandra } else if (state & RS_FILTERED) { 338*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 339*c389c7f8SGowtham Thommandra "job-state", 0x0004); /* filtered */ 340*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 341*c389c7f8SGowtham Thommandra "job-state-reasons", "job-filtered"); 342*c389c7f8SGowtham Thommandra } else if (state & RS_CHANGING) { 343*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 344*c389c7f8SGowtham Thommandra "job-state", 0x0020); /* job held for changing */ 345*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 346*c389c7f8SGowtham Thommandra "job-state-reasons", "job-held-for-change"); 347*c389c7f8SGowtham Thommandra } else if (state & RS_FILTERING) { 348*c389c7f8SGowtham Thommandra papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 349*c389c7f8SGowtham Thommandra "job-state", 0x0002); /* being filtered */ 350*c389c7f8SGowtham Thommandra papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 351*c389c7f8SGowtham Thommandra "job-state-reasons", "job-being-filtered"); 3527c478bd9Sstevel@tonic-gate } else { 3537c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(attributes, PAPI_ATTR_REPLACE, 354*c389c7f8SGowtham Thommandra "job-state", 0x4000); /* else */ 3557c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 3567c478bd9Sstevel@tonic-gate "job-state-reasons", "job-queued"); 3577c478bd9Sstevel@tonic-gate } 358*c389c7f8SGowtham Thommandra 359*c389c7f8SGowtham Thommandra 360*c389c7f8SGowtham Thommandra 3617c478bd9Sstevel@tonic-gate papiAttributeListAddString(attributes, PAPI_ATTR_REPLACE, 3627c478bd9Sstevel@tonic-gate "job-hold-until", 3637c478bd9Sstevel@tonic-gate ((state & RS_HELD) ? "indefinite" : "no-hold")); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate /* 3670a44ef6dSjacobs * convert user[@host] to papi attributes 3680a44ef6dSjacobs */ 3690a44ef6dSjacobs static void 3700a44ef6dSjacobs lpsched_user_to_job_attributes(papi_attribute_t ***list, char *user) 3710a44ef6dSjacobs { 3720a44ef6dSjacobs if ((list != NULL) && (user != NULL) && (user[0] != NULL)) { 3730a44ef6dSjacobs char *host = strrchr(user, '@'); 3740a44ef6dSjacobs 3750a44ef6dSjacobs if (host != NULL) { 3760a44ef6dSjacobs *host = NULL; 3770a44ef6dSjacobs papiAttributeListAddString(list, PAPI_ATTR_REPLACE, 3780a44ef6dSjacobs "job-originating-user-name", user); 3790a44ef6dSjacobs papiAttributeListAddString(list, PAPI_ATTR_REPLACE, 3800a44ef6dSjacobs "job-originating-host-name", host + 1); 3810a44ef6dSjacobs *host = '@'; 3820a44ef6dSjacobs } else 3830a44ef6dSjacobs papiAttributeListAddString(list, PAPI_ATTR_REPLACE, 3840a44ef6dSjacobs "job-originating-user-name", user); 3850a44ef6dSjacobs } 3860a44ef6dSjacobs } 3870a44ef6dSjacobs 3880a44ef6dSjacobs /* 3897c478bd9Sstevel@tonic-gate * Convert REQUEST structure to the equivalent PAPI attribute representation. 3907c478bd9Sstevel@tonic-gate */ 3917c478bd9Sstevel@tonic-gate void 3927c478bd9Sstevel@tonic-gate lpsched_request_to_job_attributes(REQUEST *r, job_t *j) 3937c478bd9Sstevel@tonic-gate { 3947c478bd9Sstevel@tonic-gate char *tmp; 3957c478bd9Sstevel@tonic-gate int i; 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate /* copies */ 3987c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, 3997c478bd9Sstevel@tonic-gate "copies", r->copies); 4007c478bd9Sstevel@tonic-gate 4017c478bd9Sstevel@tonic-gate /* destination */ 402355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 403355b4669Sjacobs "printer-name", r->destination); 4047c478bd9Sstevel@tonic-gate 4057c478bd9Sstevel@tonic-gate /* form */ 406355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 407355b4669Sjacobs "form", r->form); 4087c478bd9Sstevel@tonic-gate 4097c478bd9Sstevel@tonic-gate /* options */ 410355b4669Sjacobs papiAttributeListFromString(&j->attributes, PAPI_ATTR_APPEND, 411355b4669Sjacobs r->options); 4127c478bd9Sstevel@tonic-gate 4137c478bd9Sstevel@tonic-gate tmp = (((r->options != NULL) && (strstr(r->options, "nobanner") 4147c478bd9Sstevel@tonic-gate != NULL)) ? "none" : "standard"); 4157c478bd9Sstevel@tonic-gate papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, 4167c478bd9Sstevel@tonic-gate "job-sheets", tmp); 4177c478bd9Sstevel@tonic-gate 4187c478bd9Sstevel@tonic-gate tmp = (((r->options != NULL) && (strstr(r->options, "duplex") 4197c478bd9Sstevel@tonic-gate != NULL)) ? "two-sized" : "one-sided"); 4207c478bd9Sstevel@tonic-gate papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, 4217c478bd9Sstevel@tonic-gate "sides", tmp); 4227c478bd9Sstevel@tonic-gate 4237c478bd9Sstevel@tonic-gate i = (((r->options != NULL) && (strstr(r->options, "landscape") 4247c478bd9Sstevel@tonic-gate != NULL)) ? 4 : 3); 4257c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, 4267c478bd9Sstevel@tonic-gate "orientation-requested", i); 4277c478bd9Sstevel@tonic-gate 4287c478bd9Sstevel@tonic-gate /* priority (map 0-39 to 1-100) */ 4297c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, 430574e15a0Sjacobs "job-priority", 431574e15a0Sjacobs (int)(100 - (r->priority * 2.5))); 4327c478bd9Sstevel@tonic-gate 4337c478bd9Sstevel@tonic-gate /* pages */ 434355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 435355b4669Sjacobs "page-ranges", r->pages); 4367c478bd9Sstevel@tonic-gate 4377c478bd9Sstevel@tonic-gate /* charset */ 438355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 439355b4669Sjacobs "lp-charset", r->charset); 4407c478bd9Sstevel@tonic-gate 4417c478bd9Sstevel@tonic-gate /* modes */ 442355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 443355b4669Sjacobs "lp-modes", r->modes); 4447c478bd9Sstevel@tonic-gate 4457c478bd9Sstevel@tonic-gate /* title */ 446355b4669Sjacobs papiAttributeListAddLPString(&j->attributes, PAPI_ATTR_REPLACE, 447355b4669Sjacobs "job-name", r->title); 4487c478bd9Sstevel@tonic-gate 4497c478bd9Sstevel@tonic-gate /* input_type */ 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate /* user */ 4520a44ef6dSjacobs lpsched_user_to_job_attributes(&j->attributes, r->user); 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* outcome */ 4557c478bd9Sstevel@tonic-gate lpsched_request_outcome_to_attributes(&j->attributes, r->outcome); 4567c478bd9Sstevel@tonic-gate 4577c478bd9Sstevel@tonic-gate /* constants, (should be derived from options) */ 4587c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&j->attributes, PAPI_ATTR_REPLACE, 4597c478bd9Sstevel@tonic-gate "number-up", 1); 4607c478bd9Sstevel@tonic-gate 4617c478bd9Sstevel@tonic-gate papiAttributeListAddString(&j->attributes, PAPI_ATTR_REPLACE, 4627c478bd9Sstevel@tonic-gate "multiple-document-handling", 4637c478bd9Sstevel@tonic-gate "seperate-documents-collated-copies"); 4647c478bd9Sstevel@tonic-gate } 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate /* 4677c478bd9Sstevel@tonic-gate * Convert R_REQUEST_* results to the equivalent PAPI attribute representation. 4687c478bd9Sstevel@tonic-gate */ 4697c478bd9Sstevel@tonic-gate void 47045916cd2Sjpk job_status_to_attributes(job_t *job, char *req_id, char *user, char *slabel, 47145916cd2Sjpk size_t size, time_t date, short state, char *destination, 47245916cd2Sjpk char *form, char *charset, short rank, char *file) 4737c478bd9Sstevel@tonic-gate { 4747c478bd9Sstevel@tonic-gate char buf[BUFSIZ]; 4757c478bd9Sstevel@tonic-gate char *p; 4767c478bd9Sstevel@tonic-gate 4770a44ef6dSjacobs lpsched_user_to_job_attributes(&job->attributes, user); 4787c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 4797c478bd9Sstevel@tonic-gate "job-k-octets", size/1024); 4807c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 4817c478bd9Sstevel@tonic-gate "job-octets", size); 4827c478bd9Sstevel@tonic-gate if ((p = strrchr(req_id, '-')) != NULL) { 4837c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 4847c478bd9Sstevel@tonic-gate "job-id", atoi(++p)); 4857c478bd9Sstevel@tonic-gate } 486355b4669Sjacobs snprintf(buf, sizeof (buf), "lpsched://localhost/printers/%s/%d", 487355b4669Sjacobs destination, atoi(p)); 4887c478bd9Sstevel@tonic-gate papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE, 4897c478bd9Sstevel@tonic-gate "job-uri", buf); 490355b4669Sjacobs snprintf(buf, sizeof (buf), "lpsched://localhost/printers/%s", 491355b4669Sjacobs destination); 4927c478bd9Sstevel@tonic-gate papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE, 4937c478bd9Sstevel@tonic-gate "job-printer-uri", buf); 4947c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 4957c478bd9Sstevel@tonic-gate "job-printer-up-time", time(NULL)); 4967c478bd9Sstevel@tonic-gate papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE, 4977c478bd9Sstevel@tonic-gate "output-device-assigned", destination); 4987c478bd9Sstevel@tonic-gate papiAttributeListAddString(&job->attributes, PAPI_ATTR_REPLACE, 4997c478bd9Sstevel@tonic-gate "printer-name", destination); 500355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE, 501355b4669Sjacobs "form", form); 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate lpsched_request_outcome_to_attributes(&job->attributes, state); 5047c478bd9Sstevel@tonic-gate 5057c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 5067c478bd9Sstevel@tonic-gate "time-at-creation", date); 507355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE, 5087c478bd9Sstevel@tonic-gate "lpsched-request-id", req_id); 509355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE, 5107c478bd9Sstevel@tonic-gate "lp-charset", charset); 5117c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 5127c478bd9Sstevel@tonic-gate "lpsched-job-state", state); 5137c478bd9Sstevel@tonic-gate papiAttributeListAddInteger(&job->attributes, PAPI_ATTR_REPLACE, 5147c478bd9Sstevel@tonic-gate "number-of-intervening-jobs", rank - 1); 515355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_REPLACE, 5167c478bd9Sstevel@tonic-gate "lpsched-file", file); 517355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_EXCL, 5187c478bd9Sstevel@tonic-gate "job-name", file); 519355b4669Sjacobs papiAttributeListAddLPString(&job->attributes, PAPI_ATTR_EXCL, 52045916cd2Sjpk "tsol-sensitivity-label", slabel); 5217c478bd9Sstevel@tonic-gate } 5227c478bd9Sstevel@tonic-gate 5237c478bd9Sstevel@tonic-gate void 5247c478bd9Sstevel@tonic-gate lpsched_read_job_configuration(service_t *svc, job_t *j, char *file) 5257c478bd9Sstevel@tonic-gate { 5267c478bd9Sstevel@tonic-gate REQUEST *r; 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate if ((r = getrequest(file)) == NULL) { 5297c478bd9Sstevel@tonic-gate detailed_error(svc, gettext("unable to read job data: %s"), 5307c478bd9Sstevel@tonic-gate file); 5317c478bd9Sstevel@tonic-gate return; 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate lpsched_request_to_job_attributes(r, j); 5357c478bd9Sstevel@tonic-gate } 536