/* XDSHLI_UTILS.C V5.6-3 *%COPYRIGHT_START% * * Copyright Digital Equipment Corporation 1993. All rights reserved * * Restricted Rights: Use, duplication, or disclosure by the U.S Government is * subject to restrictions as set forth in subparagraph (C) (1) (ii) of DFARS * 252.227-7013, or in FAR 52.227-19, or in FAR 52.227-14 Alt, III, as * applicable. Unpublished rights reserved under applicable copyright laws. * * This software is proprietary to and embodies the confidential technology of * Digital Equipment Corporation. Possession, use, or copying of this software * and media is authorized only pursuant to a valid written license from * Digital or an authorized sublicensor. * *%COPYRIGHT_END% */ /* **++ ** FACILITY: XDSHLI - extension to X.500 XDS/OM interface ** ** The XDS High Level Interface (XDSHLI) helps build XDS/OM applications ** by providing a set of useful services. XDSHLI complements the XDS/OM API ** by hiding some of its complexities, but allowing access to these ** features if they are required. ** ** See XDSHLI.H for more information. ** ** MODULE DESCRIPTION: ** ** This module contains the XDSHLI utility routines. ** They are ** xdshli_check_om_status() - checks status returned by om_* call ** xdshli_check_mem_alloc() - checks sucess of memory allocation call ** omX_compare_om_strings() - compares two OM_strings for equivalence ** omX_find_om_type() - finds an OM_descriptor in a public object ** ** ** XDSHLI.H contains the functionality description of these routines, ** and other related information. ** ** AUTHORS: ** ** IRD ** ** CREATION DATE: 7-Aug-1993 ** ** MODIFICATION HISTORY: ** ** 000 7-Aug-1993 IRD Creation ** 001 13-Oct-1993 CMB Minor changes to comments ** 002 12-Nov-1993 IRD Change include statements **-- */ /* ** ** INCLUDE FILES ** */ #include #include #include "xdshli.h" #include "xdshli_private.h" /* xdshli_check_om_status() **++ ** Checks an OM status and returns OM_TRUE if no error; otherwise, returns ** OM_FALSE and prints out message to 'stderr'. **-- */ extern OM_boolean xdshli_check_om_status( OM_return_code om_status ) { if ( om_status == OM_SUCCESS ) { return OM_TRUE ; } fprintf( stderr, "OM Error returned with status %i\n", om_status ); return OM_FALSE ; } /* xdshli_check_mem_alloc() **++ ** Checks address returned from a memory allocation operation, ** prints out a message to 'stderr' if it failed, and returns the status. **-- */ extern void * xdshli_check_mem_alloc( void* alloc_status ) { /* * Checks whether memory allocation has succeeded. Returns * value passed into routine. */ if ( alloc_status == NULL ) { printf( "Memory allocation failed\n" ); } return( alloc_status ); } /* omX_compare_om_strings() **++ ** Compare the length of the given strings, and if equal, compare the ** contents of the string. Returns OM_TRUE if both length and contents are ** equal, and OM_FALSE if they are not. **-- */ extern OM_boolean omX_compare_om_strings( OM_string *string1, OM_string *string2) { if ( string1->length == string2->length ) { if ( memcmp( string1->elements, string2->elements, string1->length )== 0) { return OM_TRUE ; } } return OM_FALSE ; } /* omX_find_om_type() **++ ** ** Steps through the given public object, returns the address of the first ** OM descriptor found which matches the given type, or returns NULL ** if no match is found. **-- */ extern OM_descriptor *omX_find_om_type( OM_public_object object, OM_type type ) { while ( object->type != type && object->type != OM_NO_MORE_TYPES ) { *object++ ; } if ( object->type != OM_NO_MORE_TYPES ) { return( object ) ; } else { return NULL ; } } /* omX_count_om_types() **++ ** This function returns the number of OM Attributes of the given ** type in the given OM public object. ** ** See XDSHLI.H for more information. **-- */ extern unsigned int omX_count_om_types( OM_public_object object,/* IN - object to be searched */ OM_type type ) /* IN - type to be counted */ { unsigned int count = 0 ; OM_descriptor *desc ; /* * Find the first instance of the OM Attribute in the given OM public * object. */ if ( (desc = omX_find_om_type(object, type)) != NULL ) { /* * There is at least one instance of this OM Attribute in the object. * Count the number of occurances from the first decriptor. */ while ( desc->type == type ) { desc++ ; count++ ; } } return count ; }