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 ad_free( a->a_desc, 1 );
33 ber_bvecfree( a->a_vals );
38 attrs_free( Attribute *a )
42 for( ; a != NULL ; a = next ) {
48 Attribute *attr_dup( Attribute *a )
52 if( a == NULL) return NULL;
54 tmp = ch_malloc( sizeof(Attribute) );
56 if( a->a_vals != NULL ) {
59 for( i=0; a->a_vals[i] != NULL; i++ ) {
63 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
65 for( i=0; a->a_vals[i] != NULL; i++ ) {
66 tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
68 if( tmp->a_vals[i] == NULL ) break;
71 tmp->a_vals[i] = NULL;
77 tmp->a_desc = ad_dup( a->a_desc );
83 Attribute *attrs_dup( Attribute *a )
85 Attribute *tmp, **next;
87 if( a == NULL ) return NULL;
92 for( ; a != NULL ; a = a->a_next ) {
93 *next = attr_dup( a );
94 next = &((*next)->a_next);
104 * attr_merge - merge the given type and value with the list of
105 * attributes in attrs.
106 * returns 0 everything went ok
113 AttributeDescription *desc,
114 struct berval **vals )
118 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
119 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
126 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
127 (*a)->a_desc = ad_dup( desc );
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;