8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / lib / print / libipp-core / common / ipp.c
blob133fb0ad13569b98a9510e079d6bc5c11d3e5c43
1 /*
2 * CDDL HEADER START
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.
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.
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]
19 * CDDL HEADER END
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
28 /* $Id: ipp.c 146 2006-03-24 00:26:54Z njacobs $ */
30 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <stdio.h>
33 #include <stdarg.h>
34 #include <papi.h>
35 #include "ipp.h"
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.
52 papi_status_t
53 ipp_validate_request(papi_attribute_t **request, papi_attribute_t ***response)
55 papi_attribute_t **attributes = NULL;
56 papi_status_t result = PAPI_OK;
57 char *s;
59 if ((request == NULL) || (response == NULL) || (*response == NULL))
60 return (PAPI_BAD_ARGUMENT);
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);
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);
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);
89 return (result);
93 * Add/Modify the statuse-code and status-message in an IPP response's
94 * operational attributes group.
96 void
97 ipp_set_status(papi_attribute_t ***message, papi_status_t status,
98 char *format, ...)
100 if (message == NULL)
101 return;
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;
109 (void) papiAttributeListGetCollection(*message, NULL,
110 "operational-attributes-group",
111 &operational);
112 saved = operational;
114 va_start(ap, format);
115 (void) vsnprintf(mesg, sizeof (mesg), format, ap);
116 va_end(ap);
118 (void) papiAttributeListAddString(&operational,
119 PAPI_ATTR_APPEND, "status-message", mesg);
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.
127 if (saved != operational)
128 (void) papiAttributeListAddCollection(message,
129 PAPI_ATTR_REPLACE,
130 "operational-attributes-group",
131 operational);
134 (void) papiAttributeListAddInteger(message, PAPI_ATTR_APPEND,
135 "status-code", status);