1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 */ 27 28 /* $Id: ipp.c 146 2006-03-24 00:26:54Z njacobs $ */ 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 #include <stdio.h> 33 #include <stdarg.h> 34 #include <papi.h> 35 #include "ipp.h" 36 37 /* 38 * IPP requests/responses are represented as attribute lists. An IPP request 39 * attribute list will contain header information attributes: 40 * version-major (int) 41 * version-minor (int) 42 * request-id (int) 43 * operation-id (int) 44 * It will also contain 1 or more attribute groups (collections) 45 * operational-attribute-group 46 * ... 47 * this routine validates that the request falls within the guidelines of 48 * the protocol specification (or some other level of conformance if the 49 * restrictions have been specified at the top level of the request using 50 * a "conformance" attribute. 51 */ 52 papi_status_t 53 ipp_validate_request(papi_attribute_t **request, papi_attribute_t ***response) 54 { 55 papi_attribute_t **attributes = NULL; 56 papi_status_t result = PAPI_OK; 57 char *s; 58 59 if ((request == NULL) || (response == NULL) || (*response == NULL)) 60 return (PAPI_BAD_ARGUMENT); 61 62 /* validate the operational attributes group */ 63 result = papiAttributeListGetCollection(request, NULL, 64 "operational-attributes-group", &attributes); 65 if (result != PAPI_OK) { 66 ipp_set_status(response, result, 67 "operational attribute group: %s", 68 papiStatusString(result)); 69 return (result); 70 } 71 72 result = papiAttributeListGetString(attributes, NULL, 73 "attributes-charset", &s); 74 if (result != PAPI_OK) { 75 ipp_set_status(response, result, "attributes-charset: %s", 76 papiStatusString(result)); 77 return (result); 78 } 79 80 result = papiAttributeListGetString(attributes, NULL, 81 "attributes-natural-language", &s); 82 if (result != PAPI_OK) { 83 ipp_set_status(response, result, 84 "attributes-natural-language: %s", 85 papiStatusString(result)); 86 return (result); 87 } 88 89 return (result); 90 } 91 92 /* 93 * Add/Modify the statuse-code and status-message in an IPP response's 94 * operational attributes group. 95 */ 96 void 97 ipp_set_status(papi_attribute_t ***message, papi_status_t status, 98 char *format, ...) 99 { 100 if (message == NULL) 101 return; 102 103 if (format != NULL) { 104 papi_attribute_t **operational = NULL; 105 papi_attribute_t **saved; 106 char mesg[256]; /* status-message is type text(255) */ 107 va_list ap; 108 109 (void) papiAttributeListGetCollection(*message, NULL, 110 "operational-attributes-group", 111 &operational); 112 saved = operational; 113 114 va_start(ap, format); 115 (void) vsnprintf(mesg, sizeof (mesg), format, ap); 116 va_end(ap); 117 118 (void) papiAttributeListAddString(&operational, 119 PAPI_ATTR_APPEND, "status-message", mesg); 120 121 /* 122 * We need to check and see if adding the status-message caused 123 * the operational attributes group to be relocated in memory. 124 * If it has been, we will need to re-add the collection to 125 * the message. 126 */ 127 if (saved != operational) 128 (void) papiAttributeListAddCollection(message, 129 PAPI_ATTR_REPLACE, 130 "operational-attributes-group", 131 operational); 132 } 133 134 (void) papiAttributeListAddInteger(message, PAPI_ATTR_APPEND, 135 "status-code", status); 136 } 137