3 * Copyright 1998-2000 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 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;
81 Attribute *attrs_dup( Attribute *a )
83 Attribute *tmp, **next;
85 if( a == NULL ) return NULL;
90 for( ; a != NULL ; a = a->a_next ) {
91 *next = attr_dup( a );
92 next = &((*next)->a_next);
102 * attr_merge - merge the given type and value with the list of
103 * attributes in attrs.
104 * returns 0 everything went ok
111 AttributeDescription *desc,
116 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
117 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
124 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
130 return( value_add( &(*a)->a_vals, vals ) );
134 * attrs_find - find attribute(s) by AttributeDescription
135 * returns next attribute which is subtype of provided description.
141 AttributeDescription *desc
144 for ( ; a != NULL; a = a->a_next ) {
145 if ( is_ad_subtype( a->a_desc, desc ) ) {
154 * attr_find - find attribute by type
160 AttributeDescription *desc
163 for ( ; a != NULL; a = a->a_next ) {
164 if ( ad_cmp( a->a_desc, desc ) == 0 )
174 * attr_delete - delete the attribute type in list pointed to by attrs
175 * return 0 deleted ok
176 * 1 not found in list a
177 * -1 something bad happened
183 AttributeDescription *desc
188 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
189 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
191 Attribute *save = *a;
199 return LDAP_NO_SUCH_ATTRIBUTE;