Print this page
Bump Apache dependency to Apache 2


   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 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 }




   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 2012 Nexenta Systems, Inc.  All rights reserved.
  24  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
  25  * Use is subject to license terms.
  26  *
  27  */
  28 
  29 /* $Id: ipp-listener.c 146 2006-03-24 00:26:54Z njacobs $ */
  30 


  31 #include <stdio.h>
  32 #include <stdlib.h>
  33 #include <string.h>
  34 #include <netinet/in.h>
  35 #include <assert.h>
  36 #include <errno.h>
  37 #include <syslog.h>
  38 #include <sys/types.h>
  39 #include <sys/stat.h>
  40 #include <fcntl.h>
  41 #include <unistd.h>
  42 #include <sys/systeminfo.h>
  43 
  44 #include <papi.h>
  45 #include <ipp-listener.h>
  46 #include <uri.h>
  47 
  48 typedef papi_status_t (ipp_handler_t)(papi_service_t svc,
  49                                         papi_attribute_t **request,
  50                                         papi_attribute_t ***response,


 133         { 0x000d, "release-job",                ipp_release_job,
 134                                                                 OP_OPTIONAL },
 135         { 0x000e, "restart-job",                ipp_restart_job,
 136                                                                 OP_OPTIONAL },
 137         /* Other Operations */
 138         { 0x4001, "cups-get-default",           cups_get_default,
 139                                                                 OP_VENDOR },
 140         { 0x4002, "cups-get-printers",          cups_get_printers,
 141                                                                 OP_VENDOR },
 142         { 0x4005, "cups-get-classes",           cups_get_classes,
 143                                                                 OP_VENDOR },
 144         { 0x4008, "cups-accept-jobs",           cups_accept_jobs,
 145                                                                 OP_VENDOR },
 146         { 0x4009, "cups-reject-jobs",           cups_reject_jobs,
 147                                                                 OP_VENDOR },
 148         { 0x400D, "cups-move-job",              cups_move_job,  OP_VENDOR },
 149         { 0, NULL, NULL, OP_VENDOR }
 150 };
 151 
 152 static int
 153 ipp_operation_name_to_index(const char *name)
 154 {
 155         int i;
 156 
 157         for (i = 0; handlers[i].name != NULL; i++)
 158                 if (strcasecmp(name, handlers[i].name) == 0)
 159                         return (i);
 160 
 161         return (-1);
 162 }
 163 
 164 static int
 165 ipp_operation_id_to_index(int16_t id)
 166 {
 167         int i;
 168 
 169         for (i = 0; handlers[i].name != NULL; i++)
 170                 if (id == handlers[i].id)
 171                         return (i);
 172 
 173         return (-1);


 215         if (status != PAPI_OK) {        /* this should not be possible */
 216                 ipp_set_status(response, PAPI_INTERNAL_ERROR,
 217                         "sofware error, no operations configured");
 218                 return (default_handler);
 219         }
 220 
 221         /* check if the requested operation is configured */
 222         status = papiAttributeListGetBoolean(ops, NULL,
 223                                 handlers[index].name, &configured);
 224         if ((status != PAPI_OK) || (configured != PAPI_TRUE)) {
 225                 ipp_set_status(response, PAPI_OPERATION_NOT_SUPPORTED,
 226                         "operation (%s 0x%4.4x) not enabled on server",
 227                         handlers[index].name, id);
 228                 return (default_handler);
 229         }
 230 
 231         return (handlers[index].function);
 232 }
 233 
 234 static char
 235 type_to_boolean(const char *type)
 236 {
 237         char result = PAPI_FALSE;
 238 
 239         if ((strcasecmp(type, "true") == 0) ||
 240             (strcasecmp(type, "yes") == 0) ||
 241             (strcasecmp(type, "on") == 0) ||
 242             (strcasecmp(type, "enable") == 0))
 243                 result = PAPI_TRUE;
 244 
 245         return (result);
 246 }
 247 
 248 static papi_status_t
 249 ipp_configure_required_operations(papi_attribute_t ***list, char boolean)
 250 {
 251         papi_status_t result = PAPI_OK;
 252         int i;
 253 
 254         for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
 255                 if (handlers[i].type == OP_REQUIRED)


 258                                         boolean);
 259 
 260         return (result);
 261 
 262 }
 263 
 264 static papi_status_t
 265 ipp_configure_all_operations(papi_attribute_t ***list, char boolean)
 266 {
 267         papi_status_t result = PAPI_OK;
 268         int i;
 269 
 270         for (i = 0; ((result == PAPI_OK) && (handlers[i].name != NULL)); i++)
 271                 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
 272                                 handlers[i].name, boolean);
 273 
 274         return (result);
 275 }
 276 
 277 papi_status_t
 278 ipp_configure_operation(papi_attribute_t ***list, const char *operation, const char *type)
 279 {
 280         papi_status_t result = PAPI_OPERATION_NOT_SUPPORTED;
 281         char boolean = PAPI_FALSE;
 282 
 283         if ((list == NULL) || (operation == NULL) || (type == NULL))
 284                 return (PAPI_BAD_ARGUMENT);
 285 
 286         boolean = type_to_boolean(type);
 287 
 288         if (strcasecmp(operation, "all") == 0) {
 289                 result = ipp_configure_all_operations(list, boolean);
 290         } else if (strcasecmp(operation, "required") == 0) {
 291                 result = ipp_configure_required_operations(list, boolean);
 292         } else if (ipp_operation_name_to_index(operation) != -1) {
 293                 result = papiAttributeListAddBoolean(list, PAPI_ATTR_REPLACE,
 294                                                         operation, boolean);
 295         }
 296 
 297         return (result);
 298 }