3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 /* at.c - routines for dealing with attribute types */
14 #include <ac/socket.h>
15 #include <ac/string.h>
26 for( ; at != NULL; at = at->sat_sup ) {
27 if( at->sat_syntax_oid ) {
28 return ( strcmp( at->sat_syntax_oid, oid ) == 0 );
39 for( ; sub != NULL; sub = sub->sat_sup ) {
40 if( sub == sup ) return 1;
48 AttributeType *air_at;
51 static Avlnode *attr_index = NULL;
52 static AttributeType *attr_list = NULL;
56 struct aindexrec *air1,
57 struct aindexrec *air2
60 return (strcasecmp( air1->air_name, air2->air_name ));
69 return (strcasecmp( type, air->air_name ));
77 struct aindexrec *air;
79 air = (struct aindexrec *) avl_find( attr_index, name,
80 (AVL_CMP) attr_index_name_cmp );
82 return air != NULL ? air->air_at : NULL;
88 AttributeType ***listp
92 AttributeType **list1;
98 list = ch_calloc(size, sizeof(AttributeType *));
110 list1 = ch_realloc(list, size*sizeof(AttributeType *));
125 AttributeType ***listp
128 AttributeType **list;
129 AttributeType **list1;
137 for ( i=0; list[i]; i++ )
142 for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
146 /* Tell the runtime this can be shrinked */
147 list1 = ch_realloc(list, (i+1)*sizeof(AttributeType **));
166 for ( i=0; list[i]; i++ ) {
167 if ( sat == list[i] ) {
177 AttributeType *a, *n;
178 avl_free(attr_index, ldap_memfree);
180 for (a=attr_list; a; a=n) {
182 ldap_memfree(a->sat_subtypes);
183 ad_destroy(a->sat_ad);
184 ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
185 ldap_attributetype_free((LDAPAttributeType *)a);
196 struct aindexrec *air;
200 while ( *atp != NULL ) {
201 atp = &(*atp)->sat_next;
205 if ( sat->sat_oid ) {
206 air = (struct aindexrec *)
207 ch_calloc( 1, sizeof(struct aindexrec) );
208 air->air_name = sat->sat_oid;
210 if ( avl_insert( &attr_index, (caddr_t) air,
211 (AVL_CMP) attr_index_cmp,
212 (AVL_DUP) avl_dup_error ) ) {
215 return SLAP_SCHERR_DUP_ATTR;
217 /* FIX: temporal consistency check */
218 at_find(air->air_name);
221 if ( (names = sat->sat_names) ) {
223 air = (struct aindexrec *)
224 ch_calloc( 1, sizeof(struct aindexrec) );
225 air->air_name = *names;
227 if ( avl_insert( &attr_index, (caddr_t) air,
228 (AVL_CMP) attr_index_cmp,
229 (AVL_DUP) avl_dup_error ) ) {
232 return SLAP_SCHERR_DUP_ATTR;
234 /* FIX: temporal consistency check */
235 at_find(air->air_name);
245 LDAPAttributeType *at,
255 if ( at->at_names && at->at_names[0] ) {
258 for( i=0; at->at_names[i]; i++ ) {
259 if( !slap_valid_descr( at->at_names[i] ) ) {
260 return SLAP_SCHERR_BAD_DESCR;
264 cname = at->at_names[0];
266 } else if ( at->at_oid ) {
269 return SLAP_SCHERR_ATTR_INCOMPLETE;
272 if ( at->at_collective ) {
273 return SLAP_SCHERR_NOT_SUPPORTED;
276 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
277 AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
279 sat->sat_cname.bv_val = cname;
280 sat->sat_cname.bv_len = strlen( cname );
281 ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
283 if ( at->at_sup_oid ) {
284 AttributeType *supsat = at_find(at->at_sup_oid);
286 if ( (supsat == NULL ) ) {
287 *err = at->at_sup_oid;
288 return SLAP_SCHERR_ATTR_NOT_FOUND;
291 sat->sat_sup = supsat;
293 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
295 return SLAP_SCHERR_OUTOFMEM;
300 * Inherit definitions from superiors. We only check the
301 * direct superior since that one has already inherited from
304 if ( sat->sat_sup ) {
305 sat->sat_syntax = sat->sat_sup->sat_syntax;
306 sat->sat_equality = sat->sat_sup->sat_equality;
307 sat->sat_approx = sat->sat_sup->sat_approx;
308 sat->sat_ordering = sat->sat_sup->sat_ordering;
309 sat->sat_substr = sat->sat_sup->sat_substr;
312 if ( at->at_syntax_oid ) {
313 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
314 sat->sat_syntax = syn;
316 *err = sat->sat_syntax_oid;
317 return SLAP_SCHERR_SYN_NOT_FOUND;
321 } else if ( sat->sat_syntax == NULL ) {
322 return SLAP_SCHERR_ATTR_INCOMPLETE;
325 if ( sat->sat_equality_oid ) {
326 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
327 sat->sat_equality = mr;
328 sat->sat_approx = mr->smr_associated;
330 *err = sat->sat_equality_oid;
331 return SLAP_SCHERR_MR_NOT_FOUND;
336 if ( sat->sat_ordering_oid ) {
337 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
338 sat->sat_ordering = mr;
340 *err = sat->sat_ordering_oid;
341 return SLAP_SCHERR_MR_NOT_FOUND;
345 if ( sat->sat_substr_oid ) {
346 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
347 sat->sat_substr = mr;
349 *err = sat->sat_substr_oid;
350 return SLAP_SCHERR_MR_NOT_FOUND;
354 code = at_insert(sat,err);
360 at_index_printnode( struct aindexrec *air )
365 ldap_attributetype2str(&air->air_at->sat_atype) );
370 at_index_print( void )
372 printf("Printing attribute type index:\n");
373 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
374 0, -1, AVL_INORDER );
378 #if defined( SLAPD_SCHEMA_DN )
380 at_schema_info( Entry *e )
383 struct berval *vals[2];
386 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
391 for ( at = attr_list; at; at = at->sat_next ) {
392 val.bv_val = ldap_attributetype2str( &at->sat_atype );
393 if ( val.bv_val == NULL ) {
396 val.bv_len = strlen( val.bv_val );
398 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
399 (long) val.bv_len, val.bv_val, 0 );
401 attr_merge( e, ad_attributeTypes, vals );
402 ldap_memfree( val.bv_val );