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 #ifdef SLAPD_SCHEMA_NOT_COMPAT
33 ad_free( a->a_desc, 1 );
37 ber_bvecfree( a->a_vals );
42 attrs_free( Attribute *a )
46 for( ; a != NULL ; a = next ) {
52 Attribute *attr_dup( Attribute *a )
56 if( a == NULL) return NULL;
58 tmp = ch_malloc( sizeof(Attribute) );
60 if( a->a_vals != NULL ) {
63 for( i=0; a->a_vals[i] != NULL; i++ ) {
67 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
69 for( i=0; a->a_vals[i] != NULL; i++ ) {
70 tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
72 if( tmp->a_vals[i] == NULL ) break;
75 tmp->a_vals[i] = NULL;
81 #ifdef SLAPD_SCHEMA_NOT_COMPAT
82 tmp->a_desc = ad_dup( a->a_desc );
84 tmp->a_type = ch_strdup( a->a_type );
85 tmp->a_syntax = a->a_syntax;
92 Attribute *attrs_dup( Attribute *a )
94 Attribute *tmp, **next;
96 if( a == NULL ) return NULL;
101 for( ; a != NULL ; a = a->a_next ) {
102 *next = attr_dup( a );
103 next = &((*next)->a_next);
110 #ifndef SLAPD_SCHEMA_NOT_COMPAT
112 * attr_normalize - normalize an attribute name (make it all lowercase)
116 attr_normalize( char *s )
120 return( ldap_pvt_str2lower( s ) );
124 #ifndef SLAPD_SCHEMA_NOT_COMPAT
126 * attr_merge_fast - merge the given type and value with the list of
127 * attributes in attrs. called from str2entry(), where we can make some
128 * assumptions to make things faster.
129 * returns 0 everything went ok
137 struct berval **vals,
145 for ( *a = &e->e_attrs; **a != NULL; *a = &(**a)->a_next ) {
146 #ifdef SLAPD_SCHEMA_NOT_COMPAT
147 /* not yet implemented */
149 if ( strcasecmp( (**a)->a_type, type ) == 0 ) {
157 **a = (Attribute *) ch_malloc( sizeof(Attribute) );
158 (**a)->a_vals = NULL;
159 #ifndef SLAPD_SCHEMA_NOT_COMPAT
160 (**a)->a_type = attr_normalize( ch_strdup( type ) );
161 (**a)->a_syntax = attr_syntax( type );
163 (**a)->a_next = NULL;
166 return( value_add_fast( &(**a)->a_vals, vals, nvals, naddvals,
172 * attr_merge - merge the given type and value with the list of
173 * attributes in attrs.
174 * returns 0 everything went ok
181 #ifdef SLAPD_SCHEMA_NOT_COMPAT
182 AttributeDescription *desc,
186 struct berval **vals )
190 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
191 #ifdef SLAPD_SCHEMA_NOT_COMPAT
192 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
194 if ( strcasecmp( (*a)->a_type, type ) == 0 )
202 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
203 #ifdef SLAPD_SCHEMA_NOT_COMPAT
204 (*a)->a_desc = ad_dup( desc );
206 (*a)->a_type = attr_normalize( ch_strdup( type ) );
207 (*a)->a_syntax = attr_syntax( type );
213 return( value_add( &(*a)->a_vals, vals ) );
216 #ifdef SLAPD_SCHEMA_NOT_COMPAT
218 * attrs_find - find attribute(s) by AttributeDescription
219 * returns next attribute which is subtype of provided description.
225 AttributeDescription *desc
228 for ( ; a != NULL; a = a->a_next ) {
229 if ( is_ad_subtype( a->a_desc, desc ) == 0 ) {
239 * attr_find - find attribute by type
245 #ifdef SLAPD_SCHEMA_NOT_COMPAT
246 AttributeDescription *desc
252 for ( ; a != NULL; a = a->a_next ) {
253 #ifdef SLAPD_SCHEMA_NOT_COMPAT
254 if ( ad_cmp( a->a_desc, desc ) == 0 )
256 if ( strcasecmp( a->a_type, type ) == 0 )
267 * attr_delete - delete the attribute type in list pointed to by attrs
268 * return 0 deleted ok
269 * 1 not found in list a
270 * -1 something bad happened
276 #ifdef SLAPD_SCHEMA_NOT_COMPAT
277 AttributeDescription *desc
286 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
287 #ifdef SLAPD_SCHEMA_NOT_COMPAT
288 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
290 if ( strcasecmp( (*a)->a_type, type ) == 0 )