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 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 */
27
28 /* $Id: ipp-listener.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 <stdlib.h>
34 #include <string.h>
35 #include <netinet/in.h>
36 #include <assert.h>
37 #include <errno.h>
38 #include <syslog.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <fcntl.h>
42 #include <unistd.h>
43 #include <sys/systeminfo.h>
44
45 #include <papi.h>
46 #include <ipp-listener.h>
47 #include <uri.h>
48
49 typedef papi_status_t (ipp_handler_t)(papi_service_t svc,
50 papi_attribute_t **request,
51 papi_attribute_t ***response,
134 { 0x000d, "release-job", ipp_release_job,
135 OP_OPTIONAL },
136 { 0x000e, "restart-job", ipp_restart_job,
137 OP_OPTIONAL },
138 /* Other Operations */
139 { 0x4001, "cups-get-default", cups_get_default,
140 OP_VENDOR },
141 { 0x4002, "cups-get-printers", cups_get_printers,
142 OP_VENDOR },
143 { 0x4005, "cups-get-classes", cups_get_classes,
144 OP_VENDOR },
145 { 0x4008, "cups-accept-jobs", cups_accept_jobs,
146 OP_VENDOR },
147 { 0x4009, "cups-reject-jobs", cups_reject_jobs,
148 OP_VENDOR },
149 { 0x400D, "cups-move-job", cups_move_job, OP_VENDOR },
150 { 0, NULL, NULL, OP_VENDOR }
151 };
152
153 static int
154 ipp_operation_name_to_index(char *name)
155 {
156 int i;
157
158 for (i = 0; handlers[i].name != NULL; i++)
159 if (strcasecmp(name, handlers[i].name) == 0)
160 return (i);
161
162 return (-1);
163 }
164
165 static int
166 ipp_operation_id_to_index(int16_t id)
167 {
168 int i;
169
170 for (i = 0; handlers[i].name != NULL; i++)
171 if (id == handlers[i].id)
172 return (i);
173
174 return (-1);
216 if (status != PAPI_OK) { /* this should not be possible */
217 ipp_set_status(response, PAPI_INTERNAL_ERROR,
218 "sofware error, no operations configured");
219 return (default_handler);
220 }
221
222 /* check if the requested operation is configured */
223 status = papiAttributeListGetBoolean(ops, NULL,
224 handlers[index].name, &configured);
225 if ((status != PAPI_OK) || (configured != PAPI_TRUE)) {
226 ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
227 "operation (%s 0x%4.4x) not enabled on server",
228 handlers[index].name, id);
229 return (default_handler);
230 }
231
232 return (handlers[index].function);
233 }
234
235 static char
236 type_to_boolean(char *type)
237 {
238 char result = PAPI_FALSE;
239
240 if ((strcasecmp(type, "true") == 0) ||
241 (strcasecmp(type, "yes") == 0) ||
242 (strcasecmp(type, "on") == 0) ||
243 (strcasecmp(type, "enable") == 0))
244 result = PAPI_TRUE;
245
246 return (result);
247 }
248
249 static papi_status_t
250 ipp_configure_required_operations(papi_attribute_t ***list, char boolean)
251 {
252 papi_status_t result = PAPI_OK;
253 int i;
254
255 for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
256 if (handlers[i].type == OP_REQUIRED)
259 boolean);
260
261 return (result);
262
263 }
264
265 static papi_status_t
266 ipp_configure_all_operations(papi_attribute_t ***list, char boolean)
267 {
268 papi_status_t result = PAPI_OK;
269 int i;
270
271 for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
272 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
273 handlers[i].name, boolean);
274
275 return (result);
276 }
277
278 papi_status_t
279 ipp_configure_operation(papi_attribute_t ***list, char *operation, char *type)
280 {
281 papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED;
282 char boolean = PAPI_FALSE;
283
284 if ((list == NULL) || (operation == NULL) || (type == NULL))
285 return (PAPI_BAD_ARGUMENT);
286
287 boolean = type_to_boolean(type);
288
289 if (strcasecmp(operation, "all") == 0) {
290 result = ipp_configure_all_operations(list, boolean);
291 } else if (strcasecmp(operation, "required") == 0) {
292 result = ipp_configure_required_operations(list, boolean);
293 } else if (ipp_operation_name_to_index(operation) != -1) {
294 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
295 operation, boolean);
296 }
297
298 return (result);
299 }
|
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 2008 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 */
27
28 /* $Id: ipp-listener.c 146 2006-03-24 00:26:54Z njacobs $ */
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <string.h>
33 #include <netinet/in.h>
34 #include <assert.h>
35 #include <errno.h>
36 #include <syslog.h>
37 #include <sys/types.h>
38 #include <sys/stat.h>
39 #include <fcntl.h>
40 #include <unistd.h>
41 #include <sys/systeminfo.h>
42
43 #include <papi.h>
44 #include <ipp-listener.h>
45 #include <uri.h>
46
47 typedef papi_status_t (ipp_handler_t)(papi_service_t svc,
48 papi_attribute_t **request,
49 papi_attribute_t ***response,
132 { 0x000d, "release-job", ipp_release_job,
133 OP_OPTIONAL },
134 { 0x000e, "restart-job", ipp_restart_job,
135 OP_OPTIONAL },
136 /* Other Operations */
137 { 0x4001, "cups-get-default", cups_get_default,
138 OP_VENDOR },
139 { 0x4002, "cups-get-printers", cups_get_printers,
140 OP_VENDOR },
141 { 0x4005, "cups-get-classes", cups_get_classes,
142 OP_VENDOR },
143 { 0x4008, "cups-accept-jobs", cups_accept_jobs,
144 OP_VENDOR },
145 { 0x4009, "cups-reject-jobs", cups_reject_jobs,
146 OP_VENDOR },
147 { 0x400D, "cups-move-job", cups_move_job, OP_VENDOR },
148 { 0, NULL, NULL, OP_VENDOR }
149 };
150
151 static int
152 ipp_operation_name_to_index(const char *name)
153 {
154 int i;
155
156 for (i = 0; handlers[i].name != NULL; i++)
157 if (strcasecmp(name, handlers[i].name) == 0)
158 return (i);
159
160 return (-1);
161 }
162
163 static int
164 ipp_operation_id_to_index(int16_t id)
165 {
166 int i;
167
168 for (i = 0; handlers[i].name != NULL; i++)
169 if (id == handlers[i].id)
170 return (i);
171
172 return (-1);
214 if (status != PAPI_OK) { /* this should not be possible */
215 ipp_set_status(response, PAPI_INTERNAL_ERROR,
216 "sofware error, no operations configured");
217 return (default_handler);
218 }
219
220 /* check if the requested operation is configured */
221 status = papiAttributeListGetBoolean(ops, NULL,
222 handlers[index].name, &configured);
223 if ((status != PAPI_OK) || (configured != PAPI_TRUE)) {
224 ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
225 "operation (%s 0x%4.4x) not enabled on server",
226 handlers[index].name, id);
227 return (default_handler);
228 }
229
230 return (handlers[index].function);
231 }
232
233 static char
234 type_to_boolean(const char *type)
235 {
236 char result = PAPI_FALSE;
237
238 if ((strcasecmp(type, "true") == 0) ||
239 (strcasecmp(type, "yes") == 0) ||
240 (strcasecmp(type, "on") == 0) ||
241 (strcasecmp(type, "enable") == 0))
242 result = PAPI_TRUE;
243
244 return (result);
245 }
246
247 static papi_status_t
248 ipp_configure_required_operations(papi_attribute_t ***list, char boolean)
249 {
250 papi_status_t result = PAPI_OK;
251 int i;
252
253 for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
254 if (handlers[i].type == OP_REQUIRED)
257 boolean);
258
259 return (result);
260
261 }
262
263 static papi_status_t
264 ipp_configure_all_operations(papi_attribute_t ***list, char boolean)
265 {
266 papi_status_t result = PAPI_OK;
267 int i;
268
269 for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
270 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
271 handlers[i].name, boolean);
272
273 return (result);
274 }
275
276 papi_status_t
277 ipp_configure_operation(papi_attribute_t ***list, const char *operation, const char *type)
278 {
279 papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED;
280 char boolean = PAPI_FALSE;
281
282 if ((list == NULL) || (operation == NULL) || (type == NULL))
283 return (PAPI_BAD_ARGUMENT);
284
285 boolean = type_to_boolean(type);
286
287 if (strcasecmp(operation, "all") == 0) {
288 result = ipp_configure_all_operations(list, boolean);
289 } else if (strcasecmp(operation, "required") == 0) {
290 result = ipp_configure_required_operations(list, boolean);
291 } else if (ipp_operation_name_to_index(operation) != -1) {
292 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
293 operation, boolean);
294 }
295
296 return (result);
297 }
|