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