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 ) );
125 * attr_merge_fast - merge the given type and value with the list of
126 * attributes in attrs. called from str2entry(), where we can make some
127 * assumptions to make things faster.
128 * returns 0 everything went ok
132 #ifdef SLAPD_SCHEMA_NOT_COMPAT
133 /* not yet implemented */
139 struct berval **vals,
147 for ( *a = &e->e_attrs; **a != NULL; *a = &(**a)->a_next ) {
148 #ifdef SLAPD_SCHEMA_NOT_COMPAT
149 /* not yet implemented */
151 if ( strcasecmp( (**a)->a_type, type ) == 0 ) {
159 **a = (Attribute *) ch_malloc( sizeof(Attribute) );
160 (**a)->a_vals = NULL;
161 #ifndef SLAPD_SCHEMA_NOT_COMPAT
162 (**a)->a_type = attr_normalize( ch_strdup( type ) );
163 (**a)->a_syntax = attr_syntax( type );
165 (**a)->a_next = NULL;
168 return( value_add_fast( &(**a)->a_vals, vals, nvals, naddvals,
175 * attr_merge - merge the given type and value with the list of
176 * attributes in attrs.
177 * returns 0 everything went ok
184 #ifdef SLAPD_SCHEMA_NOT_COMPAT
185 AttributeDescription *desc,
189 struct berval **vals )
193 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
194 #ifdef SLAPD_SCHEMA_NOT_COMPAT
195 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
197 if ( strcasecmp( (*a)->a_type, type ) == 0 )
205 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
206 #ifdef SLAPD_SCHEMA_NOT_COMPAT
207 (*a)->a_desc = ad_dup( desc );
209 (*a)->a_type = attr_normalize( ch_strdup( type ) );
210 (*a)->a_syntax = attr_syntax( type );
216 return( value_add( &(*a)->a_vals, vals ) );
219 #ifdef SLAPD_SCHEMA_NOT_COMPAT
221 * attrs_find - find attribute(s) by AttributeDescription
222 * returns next attribute which is subtype of provided description.
228 AttributeDescription *desc
231 for ( ; a != NULL; a = a->a_next ) {
232 if ( is_ad_subtype( a->a_desc, desc ) == 0 ) {
242 * attr_find - find attribute by type
248 #ifdef SLAPD_SCHEMA_NOT_COMPAT
249 AttributeDescription *desc
255 for ( ; a != NULL; a = a->a_next ) {
256 #ifdef SLAPD_SCHEMA_NOT_COMPAT
257 if ( ad_cmp( a->a_desc, desc ) == 0 )
259 if ( strcasecmp( a->a_type, type ) == 0 )
270 * attr_delete - delete the attribute type in list pointed to by attrs
271 * return 0 deleted ok
272 * 1 not found in list a
273 * -1 something bad happened
279 #ifdef SLAPD_SCHEMA_NOT_COMPAT
280 AttributeDescription *desc
289 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
290 #ifdef SLAPD_SCHEMA_NOT_COMPAT
291 if ( ad_cmp( (*a)->a_desc, desc ) == 0 )
293 if ( strcasecmp( (*a)->a_type, type ) == 0 )