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 )
32 attr_free( Attribute *a )
34 ber_bvarray_free( a->a_vals );
39 attrs_free( Attribute *a )
43 for( ; a != NULL ; a = next ) {
49 Attribute *attr_dup( Attribute *a )
53 if( a == NULL) return NULL;
55 tmp = ch_malloc( sizeof(Attribute) );
57 if( a->a_vals != NULL ) {
60 for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
64 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval));
66 for( i=0; a->a_vals[i].bv_val != NULL; i++ ) {
67 ber_dupbv( &tmp->a_vals[i], &a->a_vals[i] );
68 if( tmp->a_vals[i].bv_val == NULL ) break;
71 tmp->a_vals[i].bv_val = NULL;
77 tmp->a_desc = a->a_desc;
84 Attribute *attrs_dup( Attribute *a )
86 Attribute *tmp, **next;
88 if( a == NULL ) return NULL;
93 for( ; a != NULL ; a = a->a_next ) {
94 *next = attr_dup( a );
95 next = &((*next)->a_next);
105 * attr_merge - merge the given type and value with the list of
106 * attributes in attrs.
107 * returns 0 everything went ok
114 AttributeDescription *desc,
119 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
120 if ( ad_cmp( (*a)->a_desc, desc ) == 0 ) {
126 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
133 return( value_add( &(*a)->a_vals, vals ) );
137 * attrs_find - find attribute(s) by AttributeDescription
138 * returns next attribute which is subtype of provided description.
144 AttributeDescription *desc
147 for ( ; a != NULL; a = a->a_next ) {
148 if ( is_ad_subtype( a->a_desc, desc ) ) {
157 * attr_find - find attribute by type
163 AttributeDescription *desc
166 for ( ; a != NULL; a = a->a_next ) {
167 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 ) {
192 Attribute *save = *a;
200 return LDAP_NO_SUCH_ATTRIBUTE;