3 * Copyright 1998-1999 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
182 struct berval **vals )
186 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
187 #ifdef SLAPD_SCHEMA_NOT_COMPAT
188 /* not yet implemented */
190 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {
197 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
198 #ifdef SLAPD_SCHEMA_NOT_COMPAT
199 /* not yet implemented */
201 (*a)->a_type = attr_normalize( ch_strdup( type ) );
202 (*a)->a_syntax = attr_syntax( type );
208 return( value_add( &(*a)->a_vals, vals ) );
211 #ifdef SLAPD_SCHEMA_NOT_COMPAT
213 * attrs_find - find attribute(s) by AttributeDescription
214 * returns next attribute which is subtype of provided description.
220 AttributeDescription *desc
223 for ( ; a != NULL; a = a->a_next ) {
224 if ( is_ad_subtype( a->a_desc, desc ) == 0 ) {
234 * attr_find - find attribute by type
240 #ifdef SLAPD_SCHEMA_NOT_COMPAT
241 AttributeDescription *desc
247 for ( ; a != NULL; a = a->a_next ) {
248 #ifdef SLAPD_SCHEMA_NOT_COMPAT
249 if ( ad_cmp( a->a_desc, desc ) == 0 )
251 if ( strcasecmp( a->a_type, type ) == 0 )
262 * attr_delete - delete the attribute type in list pointed to by attrs
263 * return 0 deleted ok
264 * 1 not found in list a
265 * -1 something bad happened
271 #ifdef SLAPD_SCHEMA_NOT_COMPAT
272 AttributeDescription *desc
281 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
282 #ifdef SLAPD_SCHEMA_NOT_COMPAT
283 /* not yet implemented */
285 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {