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 );
29 #ifdef SLAPD_SCHEMA_NOT_COMPAT
31 ad_free( AttributeDescription *ad, int freeit )
33 if( ad == NULL ) return;
35 ber_bvfree( ad->ad_cname );
38 if( freeit ) free( ad );
43 attr_free( Attribute *a )
45 #ifdef SLAPD_SCHEMA_NOT_COMPAT
46 /* not yet implemented */
47 ad_free( &a->a_desc, 0 );
51 ber_bvecfree( a->a_vals );
56 attrs_free( Attribute *a )
60 for( ; a != NULL ; a = next ) {
66 Attribute *attr_dup( Attribute *a )
70 if( a == NULL) return NULL;
72 tmp = ch_malloc( sizeof(Attribute) );
74 if( a->a_vals != NULL ) {
77 for( i=0; a->a_vals[i] != NULL; i++ ) {
81 tmp->a_vals = ch_malloc((i+1) * sizeof(struct berval*));
83 for( i=0; a->a_vals[i] != NULL; i++ ) {
84 tmp->a_vals[i] = ber_bvdup( a->a_vals[i] );
86 if( tmp->a_vals[i] == NULL ) break;
89 tmp->a_vals[i] = NULL;
95 #ifdef SLAPD_SCHEMA_NOT_COMPAT
96 /* not yet implemented */
97 tmp->a_desc = a->a_desc;
98 tmp->a_desc.ad_cname = ber_bvdup( a->a_desc.ad_cname );
99 tmp->a_desc.ad_lang = ch_strdup( a->a_desc.ad_lang );
101 tmp->a_type = ch_strdup( a->a_type );
102 tmp->a_syntax = a->a_syntax;
109 Attribute *attrs_dup( Attribute *a )
111 Attribute *tmp, **next;
113 if( a == NULL ) return NULL;
118 for( ; a != NULL ; a = a->a_next ) {
119 *next = attr_dup( a );
120 next = &((*next)->a_next);
127 #ifndef SLAPD_SCHEMA_NOT_COMPAT
129 * attr_normalize - normalize an attribute name (make it all lowercase)
133 attr_normalize( char *s )
137 return( ldap_pvt_str2lower( s ) );
141 #ifndef SLAPD_SCHEMA_NOT_COMPAT
143 * attr_merge_fast - merge the given type and value with the list of
144 * attributes in attrs. called from str2entry(), where we can make some
145 * assumptions to make things faster.
146 * returns 0 everything went ok
154 struct berval **vals,
162 for ( *a = &e->e_attrs; **a != NULL; *a = &(**a)->a_next ) {
163 #ifdef SLAPD_SCHEMA_NOT_COMPAT
164 /* not yet implemented */
166 if ( strcasecmp( (**a)->a_type, type ) == 0 ) {
174 **a = (Attribute *) ch_malloc( sizeof(Attribute) );
175 (**a)->a_vals = NULL;
176 #ifndef SLAPD_SCHEMA_NOT_COMPAT
177 (**a)->a_type = attr_normalize( ch_strdup( type ) );
178 (**a)->a_syntax = attr_syntax( type );
180 (**a)->a_next = NULL;
183 return( value_add_fast( &(**a)->a_vals, vals, nvals, naddvals,
189 * attr_merge - merge the given type and value with the list of
190 * attributes in attrs.
191 * returns 0 everything went ok
204 for ( a = &e->e_attrs; *a != NULL; a = &(*a)->a_next ) {
205 #ifdef SLAPD_SCHEMA_NOT_COMPAT
206 /* not yet implemented */
208 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {
215 *a = (Attribute *) ch_malloc( sizeof(Attribute) );
216 #ifdef SLAPD_SCHEMA_NOT_COMPAT
217 /* not yet implemented */
219 (*a)->a_type = attr_normalize( ch_strdup( type ) );
220 (*a)->a_syntax = attr_syntax( type );
226 return( value_add( &(*a)->a_vals, vals ) );
230 * attr_find - find attribute by type
239 for ( ; a != NULL; a = a->a_next ) {
240 #ifdef SLAPD_SCHEMA_NOT_COMPAT
241 /* not yet implemented */
243 if ( strcasecmp( a->a_type, type ) == 0 ) {
253 * attr_delete - delete the attribute type in list pointed to by attrs
254 * return 0 deleted ok
255 * 1 not found in list a
256 * -1 something bad happened
268 for ( a = attrs; *a != NULL; a = &(*a)->a_next ) {
269 #ifdef SLAPD_SCHEMA_NOT_COMPAT
270 /* not yet implemented */
272 if ( strcasecmp( (*a)->a_type, type ) == 0 ) {