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, 0 );
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 = a->a_desc;
83 tmp->a_desc.ad_cname = ber_bvdup( a->a_desc.ad_cname );
84 tmp->a_desc.ad_lang = ch_strdup( a->a_desc.ad_lang );
86 tmp->a_type = ch_strdup( a->a_type );
87 tmp->a_syntax = a->a_syntax;
94 Attribute *attrs_dup( Attribute *a )
96 Attribute *tmp, **next;
98 if( a == NULL ) return NULL;
103 for( ; a != NULL ; a = a->a_next ) {
104 *next = attr_dup( a );
105 next = &((*next)->a_next);
112 #ifndef SLAPD_SCHEMA_NOT_COMPAT
114 * attr_normalize - normalize an attribute name (make it all lowercase)
118 attr_normalize( char *s )
122 return( ldap_pvt_str2lower( s ) );
126 #ifndef SLAPD_SCHEMA_NOT_COMPAT
128 * attr_merge_fast - merge the given type and value with the list of
129 * attributes in attrs. called from str2entry(), where we can make some
130 * assumptions to make things faster.
131 * returns 0 everything went ok
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,
174 * attr_merge - merge the given type and value with the list of
175 * attributes in attrs.
176 * returns 0 everything went ok
184 struct berval **vals )
188 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
189 #ifdef SLAPD_SCHEMA_NOT_COMPAT
190 /* not yet implemented */
192 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {
199 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
200 #ifdef SLAPD_SCHEMA_NOT_COMPAT
201 /* not yet implemented */
203 (*a)->a_type = attr_normalize( ch_strdup( type ) );
204 (*a)->a_syntax = attr_syntax( type );
210 return( value_add( &(*a)->a_vals, vals ) );
214 * attr_find - find attribute by type
220 #ifdef SLAPD_SCHEMA_NOT_COMPAT
221 AttributeDescription *desc
227 for ( ; a != NULL; a = a->a_next ) {
228 #ifdef SLAPD_SCHEMA_NOT_COMPAT
229 /* not yet implemented */
231 if ( strcasecmp( a->a_type, type ) == 0 ) {
241 * attr_delete - delete the attribute type in list pointed to by attrs
242 * return 0 deleted ok
243 * 1 not found in list a
244 * -1 something bad happened
250 #ifdef SLAPD_SCHEMA_NOT_COMPAT
251 AttributeDescription *desc
260 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
261 #ifdef SLAPD_SCHEMA_NOT_COMPAT
262 /* not yet implemented */
264 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {