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 /* 22355b4669Sjacobs * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate /*LINTLIBRARY*/ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #include <stdio.h> 317c478bd9Sstevel@tonic-gate #include <string.h> 327c478bd9Sstevel@tonic-gate #include <stdlib.h> 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <papi_impl.h> 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate papi_status_t 38355b4669Sjacobs papiAttributeListAddLPString(papi_attribute_t ***list, int flags, char *name, 39355b4669Sjacobs char *value) 407c478bd9Sstevel@tonic-gate { 417c478bd9Sstevel@tonic-gate papi_status_t result = PAPI_BAD_ARGUMENT; 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate if ((list != NULL) && (name != NULL) && (value != NULL) && 447c478bd9Sstevel@tonic-gate (value[0] != NULL)) 457c478bd9Sstevel@tonic-gate result = papiAttributeListAddString(list, flags, name, value); 467c478bd9Sstevel@tonic-gate return (result); 477c478bd9Sstevel@tonic-gate } 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate papi_status_t 50355b4669Sjacobs papiAttributeListAddLPStrings(papi_attribute_t ***list, int flags, char *name, 517c478bd9Sstevel@tonic-gate char **values) 527c478bd9Sstevel@tonic-gate { 537c478bd9Sstevel@tonic-gate papi_status_t result = PAPI_OK; 547c478bd9Sstevel@tonic-gate int i, flgs = flags; 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate if ((list == NULL) || (name == NULL) || (values == NULL)) 577c478bd9Sstevel@tonic-gate result = PAPI_BAD_ARGUMENT; 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate for (i = 0; ((result == PAPI_OK) && (values[i] != NULL)); 607c478bd9Sstevel@tonic-gate i++, flgs = PAPI_ATTR_APPEND) 617c478bd9Sstevel@tonic-gate result = papiAttributeListAddString(list, flgs, name, 627c478bd9Sstevel@tonic-gate values[i]); 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate return (result); 657c478bd9Sstevel@tonic-gate } 667c478bd9Sstevel@tonic-gate 67355b4669Sjacobs void 68355b4669Sjacobs papiAttributeListGetLPString(papi_attribute_t **attributes, char *key, 69355b4669Sjacobs char **string) 70355b4669Sjacobs { 71355b4669Sjacobs char *value = NULL; 72355b4669Sjacobs 73355b4669Sjacobs papiAttributeListGetString(attributes, NULL, key, &value); 74355b4669Sjacobs if (value != NULL) { 75355b4669Sjacobs if (*string != NULL) 76355b4669Sjacobs free(*string); 77355b4669Sjacobs *string = strdup(value); 78355b4669Sjacobs } 79355b4669Sjacobs } 80355b4669Sjacobs 81355b4669Sjacobs void 82355b4669Sjacobs papiAttributeListGetLPStrings(papi_attribute_t **attributes, char *key, 83355b4669Sjacobs char ***strings) 84355b4669Sjacobs { 85355b4669Sjacobs papi_status_t status; 86355b4669Sjacobs char **values = NULL; 87355b4669Sjacobs char *value = NULL; 88355b4669Sjacobs void *iter = NULL; 89355b4669Sjacobs 90355b4669Sjacobs for (status = papiAttributeListGetString(attributes, &iter, 91355b4669Sjacobs key, &value); 92355b4669Sjacobs status == PAPI_OK; 93355b4669Sjacobs status = papiAttributeListGetString(attributes, &iter, 94355b4669Sjacobs NULL, &value)) 95355b4669Sjacobs addlist(&values, value); 96355b4669Sjacobs 97355b4669Sjacobs if (values != NULL) { 98355b4669Sjacobs if (*strings != NULL) 99355b4669Sjacobs freelist(*strings); 100355b4669Sjacobs *strings = values; 101355b4669Sjacobs } 102355b4669Sjacobs } 103355b4669Sjacobs 1047c478bd9Sstevel@tonic-gate char * 105355b4669Sjacobs printer_name_from_uri_id(char *uri, int32_t id) 1067c478bd9Sstevel@tonic-gate { 1077c478bd9Sstevel@tonic-gate REQUEST *request = NULL; 1087c478bd9Sstevel@tonic-gate char *result = ""; 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate if (uri != NULL) { 1117c478bd9Sstevel@tonic-gate if ((result = strrchr(uri, '/')) != NULL) { 1127c478bd9Sstevel@tonic-gate result += 1; 1137c478bd9Sstevel@tonic-gate } else 1147c478bd9Sstevel@tonic-gate result = (char *)uri; 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate if ((strcmp(result, "jobs") == 0) || 1177c478bd9Sstevel@tonic-gate (strcmp(result, "any") == 0) || 1187c478bd9Sstevel@tonic-gate (strcmp(result, "all") == 0)) 1197c478bd9Sstevel@tonic-gate result = ""; 1207c478bd9Sstevel@tonic-gate } 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate if ((result[0] == NULL) && (id != -1)) { 1237c478bd9Sstevel@tonic-gate char path[32]; 1247c478bd9Sstevel@tonic-gate 1257c478bd9Sstevel@tonic-gate snprintf(path, sizeof (path), "%d-0", id); 1267c478bd9Sstevel@tonic-gate if ((request = getrequest(path)) != NULL) 1277c478bd9Sstevel@tonic-gate result = request->destination; 1287c478bd9Sstevel@tonic-gate } 1297c478bd9Sstevel@tonic-gate 1307c478bd9Sstevel@tonic-gate result = strdup(result); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate if (request != NULL) 1337c478bd9Sstevel@tonic-gate freerequest(request); 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate return (result); 1367c478bd9Sstevel@tonic-gate } 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate /* 1397c478bd9Sstevel@tonic-gate * LP content type <-> MIME type conversion table. (order dependent) 1407c478bd9Sstevel@tonic-gate */ 1417c478bd9Sstevel@tonic-gate static struct { 1427c478bd9Sstevel@tonic-gate char *mime_type; 1437c478bd9Sstevel@tonic-gate char *lp_type; 1447c478bd9Sstevel@tonic-gate } type_map[] = { 145*39a8b5b3Sjacobs { "text/plain", "simple" }, 1467c478bd9Sstevel@tonic-gate { "application/octet-stream", "raw" }, 1477c478bd9Sstevel@tonic-gate { "application/octet-stream", "any" }, 1487c478bd9Sstevel@tonic-gate { "application/postscript", "postscript" }, 1497c478bd9Sstevel@tonic-gate { "application/postscript", "ps" }, 1507c478bd9Sstevel@tonic-gate { "application/x-cif", "cif" }, 1517c478bd9Sstevel@tonic-gate { "application/x-dvi", "dvi" }, 1527c478bd9Sstevel@tonic-gate { "application/x-plot", "plot" }, 1537c478bd9Sstevel@tonic-gate { "application/x-ditroff", "troff" }, 1547c478bd9Sstevel@tonic-gate { "application/x-troff", "otroff" }, 1557c478bd9Sstevel@tonic-gate { "application/x-pr", "pr" }, 1567c478bd9Sstevel@tonic-gate { "application/x-fortran", "fortran" }, 1577c478bd9Sstevel@tonic-gate { "application/x-raster", "raster" }, 1587c478bd9Sstevel@tonic-gate { NULL, NULL} 1597c478bd9Sstevel@tonic-gate }; 1607c478bd9Sstevel@tonic-gate 1617c478bd9Sstevel@tonic-gate char * 1627c478bd9Sstevel@tonic-gate mime_type_to_lp_type(char *mime_type) 1637c478bd9Sstevel@tonic-gate { 1647c478bd9Sstevel@tonic-gate int i; 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate if (mime_type == NULL) 1677c478bd9Sstevel@tonic-gate return ("simple"); 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate for (i = 0; type_map[i].mime_type != NULL; i++) 1707c478bd9Sstevel@tonic-gate if (strcasecmp(type_map[i].mime_type, mime_type) == 0) 1717c478bd9Sstevel@tonic-gate return (type_map[i].lp_type); 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate return (mime_type); 1747c478bd9Sstevel@tonic-gate } 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate char * 1777c478bd9Sstevel@tonic-gate lp_type_to_mime_type(char *lp_type) 1787c478bd9Sstevel@tonic-gate { 1797c478bd9Sstevel@tonic-gate int i; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate if (lp_type == NULL) 182*39a8b5b3Sjacobs return ("text/plain"); 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate for (i = 0; type_map[i].lp_type != NULL; i++) 1857c478bd9Sstevel@tonic-gate if (strcasecmp(type_map[i].lp_type, lp_type) == 0) 1867c478bd9Sstevel@tonic-gate return (type_map[i].mime_type); 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate return (lp_type); 1897c478bd9Sstevel@tonic-gate } 190