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 ber_bvecfree( 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] != NULL; i++ ) {
62 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
64 for( i=0; a->a_vals[i] != NULL; i++ ) {
65 tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
67 if( tmp->a_vals[i] == NULL ) break;
70 tmp->a_vals[i] = NULL;
76 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,
113 struct berval **vals )
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) );
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 )
175 * attr_delete - delete the attribute type in list pointed to by attrs
176 * return 0 deleted ok
177 * 1 not found in list a
178 * -1 something bad happened
184 AttributeDescription *desc
189 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
190 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
192 Attribute *save = *a;
200 return LDAP_NO_SUCH_ATTRIBUTE;