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 ) {
124 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
131 return( value_add( &(*a)->a_vals, vals ) );
135 * attrs_find - find attribute(s) by AttributeDescription
136 * returns next attribute which is subtype of provided description.
142 AttributeDescription *desc
145 for ( ; a != NULL; a = a->a_next ) {
146 if ( is_ad_subtype( a->a_desc, desc ) ) {
155 * attr_find - find attribute by type
161 AttributeDescription *desc
164 for ( ; a != NULL; a = a->a_next ) {
165 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 ) {
190 Attribute *save = *a;
198 return LDAP_NO_SUCH_ATTRIBUTE;