3 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* attr.c - routines for dealing with attributes */
18 #include <ac/socket.h>
19 #include <ac/string.h>
26 static void at_index_print( void ) {};
30 attr_free( Attribute *a )
32 ber_bvarray_free( a->a_vals );
37 attrs_free( Attribute *a )
41 for( ; a != NULL ; a = next ) {
47 Attribute *attr_dup( Attribute *a )
51 if( a == NULL) return NULL;
53 tmp = ch_malloc( sizeof(Attribute) );
55 if( a->a_vals != NULL ) {
58 for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
62 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval));
64 for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
65 ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
66 if( tmp->a_vals[i].bv_val == NULL ) break;
69 tmp->a_vals[i].bv_val = NULL;
75 tmp->a_desc = a->a_desc;
82 Attribute *attrs_dup( Attribute *a )
84 Attribute *tmp, **next;
86 if( a == NULL ) return NULL;
91 for( ; a != NULL ; a = a->a_next ) {
92 *next = attr_dup( a );
93 next = &((*next)->a_next);
103 * attr_merge - merge the given type and value with the list of
104 * attributes in attrs.
105 * returns 0 everything went ok
112 AttributeDescription *desc,
117 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
118 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
125 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
132 return( value_add( &(*a)->a_vals, vals ) );
136 * attrs_find - find attribute(s) by AttributeDescription
137 * returns next attribute which is subtype of provided description.
143 AttributeDescription *desc
146 for ( ; a != NULL; a = a->a_next ) {
147 if ( is_ad_subtype( a->a_desc, desc ) ) {
156 * attr_find - find attribute by type
162 AttributeDescription *desc
165 for ( ; a != NULL; a = a->a_next ) {
166 if ( ad_cmp( a->a_desc, desc ) == 0 )
176 * attr_delete - delete the attribute type in list pointed to by attrs
177 * return 0 deleted ok
178 * 1 not found in list a
179 * -1 something bad happened
185 AttributeDescription *desc
190 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
191 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
193 Attribute *save = *a;
201 return LDAP_NO_SUCH_ATTRIBUTE;