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: attribute.c 157 2006-04-26 15:07:55Z ktou $ */
  29 
  30 #pragma ident   "%Z%%M% %I%     %E% SMI"
  31 
  32 /*LINTLIBRARY*/
  33 
  34 #include <stdio.h>
  35 #include <stdlib.h>
  36 #include <stdarg.h>
  37 #include <string.h>
  38 #include <ctype.h>
  39 #include <alloca.h>
  40 #include <papi.h>
  41 #include <regex.h>
  42 
  43 #define MAX_PAGES 32767
  44 /*
  45  * Assuming the maximum number of pages in
  46  * a document to be 32767
  47  */
  48 
  49 static void papiAttributeFree(papi_attribute_t *attribute);
  50 
  51 static void


 186                         break;
 187                 case PAPI_DATETIME:
 188                         result->datetime = v->datetime;
 189                         break;
 190                 case PAPI_COLLECTION:
 191                         result->collection = collection_dup(v->collection);
 192                         break;
 193                 case PAPI_METADATA:
 194                         result->metadata = v->metadata;
 195                         break;
 196                 default:        /* unknown type, fail to duplicate */
 197                         free(result);
 198                         result = NULL;
 199                 }
 200         }
 201 
 202         return (result);
 203 }
 204 
 205 static papi_attribute_t *
 206 papiAttributeAlloc(char *name, papi_attribute_value_type_t type)
 207 {
 208         papi_attribute_t *result = NULL;
 209 
 210         if ((result = calloc(1, sizeof (*result))) != NULL) {
 211                 result->name = strdup(name);
 212                 result->type = type;
 213         }
 214 
 215         return (result);
 216 }
 217 
 218 static papi_status_t
 219 papiAttributeListAppendValue(papi_attribute_value_t ***values,
 220                 papi_attribute_value_type_t type,
 221                 papi_attribute_value_t *value)
 222 {
 223 
 224         if (values == NULL)
 225                 return (PAPI_BAD_ARGUMENT);
 226 
 227         if (value != NULL) {    /* this allows "empty" attributes */
 228                 papi_attribute_value_t *tmp = NULL;
 229 
 230                 if ((tmp = papiAttributeValueDup(type, value)) == NULL)
 231                         return (PAPI_TEMPORARY_ERROR);
 232 
 233                 list_append(values, tmp);
 234         }
 235 
 236         return (PAPI_OK);
 237 }
 238 
 239 papi_status_t
 240 papiAttributeListAddValue(papi_attribute_t ***list, int flgs,
 241                 char *name, papi_attribute_value_type_t type,
 242                 papi_attribute_value_t *value)
 243 {
 244         papi_status_t result;
 245         int flags = flgs;
 246         papi_attribute_t *attribute = NULL;
 247         papi_attribute_value_t **values = NULL;
 248 
 249         if ((list == NULL) || (name == NULL))
 250                 return (PAPI_BAD_ARGUMENT);
 251 
 252         if ((type == PAPI_RANGE) && (value != NULL) &&
 253             (value->range.lower > value->range.upper))
 254                 return (PAPI_BAD_ARGUMENT);     /* RANGE must have min <= max */
 255 
 256         if (flags == 0) /* if it wasn't set, set a default behaviour */
 257                 flags = PAPI_ATTR_APPEND;
 258 
 259         /* look for an existing one */
 260         attribute = papiAttributeListFind(*list, name);
 261 


 301                         char *name, char *string)
 302 {
 303         papi_attribute_value_t v;
 304 
 305         v.string = (char *)string;
 306         return (papiAttributeListAddValue(list, flags, name, PAPI_STRING, &v));
 307 }
 308 
 309 papi_status_t
 310 papiAttributeListAddInteger(papi_attribute_t ***list, int flags,
 311                         char *name, int integer)
 312 {
 313         papi_attribute_value_t v;
 314 
 315         v.integer = integer;
 316         return (papiAttributeListAddValue(list, flags, name, PAPI_INTEGER, &v));
 317 }
 318 
 319 papi_status_t
 320 papiAttributeListAddBoolean(papi_attribute_t ***list, int flags,
 321                         char *name, char boolean)
 322 {
 323         papi_attribute_value_t v;
 324 
 325         v.boolean = boolean;
 326         return (papiAttributeListAddValue(list, flags, name, PAPI_BOOLEAN, &v));
 327 }
 328 
 329 papi_status_t
 330 papiAttributeListAddRange(papi_attribute_t ***list, int flags,
 331                         char *name, int lower, int upper)
 332 {
 333         papi_attribute_value_t v;
 334 
 335         v.range.lower = lower;
 336         v.range.upper = upper;
 337         return (papiAttributeListAddValue(list, flags, name, PAPI_RANGE, &v));
 338 }
 339 
 340 papi_status_t
 341 papiAttributeListAddResolution(papi_attribute_t ***list, int flags,


 385 }
 386 
 387 papi_status_t
 388 papiAttributeListDelete(papi_attribute_t ***list, char *name)
 389 {
 390         papi_attribute_t *attribute;
 391 
 392         if ((list == NULL) || (name == NULL))
 393                 return (PAPI_BAD_ARGUMENT);
 394 
 395         if ((attribute = papiAttributeListFind(*list, name)) == NULL)
 396                 return (PAPI_NOT_FOUND);
 397 
 398         list_remove(list, attribute);
 399         papiAttributeFree(attribute);
 400 
 401         return (PAPI_OK);
 402 }
 403 
 404 papi_attribute_t *
 405 papiAttributeListFind(papi_attribute_t **list, char *name)
 406 {
 407         int i;
 408         if ((list == NULL) || (name == NULL))
 409                 return (NULL);
 410 
 411         for (i = 0; list[i] != NULL; i++)
 412                 if (strcasecmp(list[i]->name, name) == 0)
 413                         return ((papi_attribute_t *)list[i]);
 414 
 415         return (NULL);
 416 }
 417 
 418 papi_attribute_t *
 419 papiAttributeListGetNext(papi_attribute_t **list, void **iter)
 420 {
 421         papi_attribute_t **tmp, *result;
 422 
 423         if ((list == NULL) && (iter == NULL))
 424                 return (NULL);
 425 




   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: attribute.c 157 2006-04-26 15:07:55Z ktou $ */
  30 


  31 /*LINTLIBRARY*/
  32 
  33 #include <stdio.h>
  34 #include <stdlib.h>
  35 #include <stdarg.h>
  36 #include <string.h>
  37 #include <ctype.h>
  38 #include <alloca.h>
  39 #include <papi.h>
  40 #include <regex.h>
  41 
  42 #define MAX_PAGES 32767
  43 /*
  44  * Assuming the maximum number of pages in
  45  * a document to be 32767
  46  */
  47 
  48 static void papiAttributeFree(papi_attribute_t *attribute);
  49 
  50 static void


 185                         break;
 186                 case PAPI_DATETIME:
 187                         result->datetime = v->datetime;
 188                         break;
 189                 case PAPI_COLLECTION:
 190                         result->collection = collection_dup(v->collection);
 191                         break;
 192                 case PAPI_METADATA:
 193                         result->metadata = v->metadata;
 194                         break;
 195                 default:        /* unknown type, fail to duplicate */
 196                         free(result);
 197                         result = NULL;
 198                 }
 199         }
 200 
 201         return (result);
 202 }
 203 
 204 static papi_attribute_t *
 205 papiAttributeAlloc(const char *name, papi_attribute_value_type_t type)
 206 {
 207         papi_attribute_t *result = NULL;
 208 
 209         if ((result = calloc(1, sizeof (*result))) != NULL) {
 210                 result->name = strdup(name);
 211                 result->type = type;
 212         }
 213 
 214         return (result);
 215 }
 216 
 217 static papi_status_t
 218 papiAttributeListAppendValue(papi_attribute_value_t ***values,
 219                 papi_attribute_value_type_t type,
 220                 papi_attribute_value_t *value)
 221 {
 222 
 223         if (values == NULL)
 224                 return (PAPI_BAD_ARGUMENT);
 225 
 226         if (value != NULL) {    /* this allows "empty" attributes */
 227                 papi_attribute_value_t *tmp = NULL;
 228 
 229                 if ((tmp = papiAttributeValueDup(type, value)) == NULL)
 230                         return (PAPI_TEMPORARY_ERROR);
 231 
 232                 list_append(values, tmp);
 233         }
 234 
 235         return (PAPI_OK);
 236 }
 237 
 238 papi_status_t
 239 papiAttributeListAddValue(papi_attribute_t ***list, int flgs,
 240                 const char *name, papi_attribute_value_type_t type,
 241                 papi_attribute_value_t *value)
 242 {
 243         papi_status_t result;
 244         int flags = flgs;
 245         papi_attribute_t *attribute = NULL;
 246         papi_attribute_value_t **values = NULL;
 247 
 248         if ((list == NULL) || (name == NULL))
 249                 return (PAPI_BAD_ARGUMENT);
 250 
 251         if ((type == PAPI_RANGE) && (value != NULL) &&
 252             (value->range.lower > value->range.upper))
 253                 return (PAPI_BAD_ARGUMENT);     /* RANGE must have min <= max */
 254 
 255         if (flags == 0) /* if it wasn't set, set a default behaviour */
 256                 flags = PAPI_ATTR_APPEND;
 257 
 258         /* look for an existing one */
 259         attribute = papiAttributeListFind(*list, name);
 260 


 300                         char *name, char *string)
 301 {
 302         papi_attribute_value_t v;
 303 
 304         v.string = (char *)string;
 305         return (papiAttributeListAddValue(list, flags, name, PAPI_STRING, &v));
 306 }
 307 
 308 papi_status_t
 309 papiAttributeListAddInteger(papi_attribute_t ***list, int flags,
 310                         char *name, int integer)
 311 {
 312         papi_attribute_value_t v;
 313 
 314         v.integer = integer;
 315         return (papiAttributeListAddValue(list, flags, name, PAPI_INTEGER, &v));
 316 }
 317 
 318 papi_status_t
 319 papiAttributeListAddBoolean(papi_attribute_t ***list, int flags,
 320                         const char *name, char boolean)
 321 {
 322         papi_attribute_value_t v;
 323 
 324         v.boolean = boolean;
 325         return (papiAttributeListAddValue(list, flags, name, PAPI_BOOLEAN, &v));
 326 }
 327 
 328 papi_status_t
 329 papiAttributeListAddRange(papi_attribute_t ***list, int flags,
 330                         char *name, int lower, int upper)
 331 {
 332         papi_attribute_value_t v;
 333 
 334         v.range.lower = lower;
 335         v.range.upper = upper;
 336         return (papiAttributeListAddValue(list, flags, name, PAPI_RANGE, &v));
 337 }
 338 
 339 papi_status_t
 340 papiAttributeListAddResolution(papi_attribute_t ***list, int flags,


 384 }
 385 
 386 papi_status_t
 387 papiAttributeListDelete(papi_attribute_t ***list, char *name)
 388 {
 389         papi_attribute_t *attribute;
 390 
 391         if ((list == NULL) || (name == NULL))
 392                 return (PAPI_BAD_ARGUMENT);
 393 
 394         if ((attribute = papiAttributeListFind(*list, name)) == NULL)
 395                 return (PAPI_NOT_FOUND);
 396 
 397         list_remove(list, attribute);
 398         papiAttributeFree(attribute);
 399 
 400         return (PAPI_OK);
 401 }
 402 
 403 papi_attribute_t *
 404 papiAttributeListFind(papi_attribute_t **list, const char *name)
 405 {
 406         int i;
 407         if ((list == NULL) || (name == NULL))
 408                 return (NULL);
 409 
 410         for (i = 0; list[i] != NULL; i++)
 411                 if (strcasecmp(list[i]->name, name) == 0)
 412                         return ((papi_attribute_t *)list[i]);
 413 
 414         return (NULL);
 415 }
 416 
 417 papi_attribute_t *
 418 papiAttributeListGetNext(papi_attribute_t **list, void **iter)
 419 {
 420         papi_attribute_t **tmp, *result;
 421 
 422         if ((list == NULL) && (iter == NULL))
 423                 return (NULL);
 424