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 ));
72 /* Uses strncasecmp to allow the input type to be non-terminated */
74 attr_index_bvname_cmp(
79 int rc = strncasecmp( type->bv_val, air->air_name, type->bv_len );
82 return air->air_name[type->bv_len] ? -1 : 0;
90 struct aindexrec *air;
92 air = (struct aindexrec *) avl_find( attr_index, name,
93 (AVL_CMP) attr_index_name_cmp );
95 return air != NULL ? air->air_at : NULL;
103 struct aindexrec *air;
105 air = (struct aindexrec *) avl_find( attr_index, name,
106 (AVL_CMP) attr_index_bvname_cmp );
108 return air != NULL ? air->air_at : NULL;
114 AttributeType ***listp
117 AttributeType **list;
118 AttributeType **list1;
124 list = ch_calloc(size, sizeof(AttributeType *));
136 list1 = ch_realloc(list, size*sizeof(AttributeType *));
151 AttributeType ***listp
154 AttributeType **list;
155 AttributeType **list1;
163 for ( i=0; list[i]; i++ )
168 for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
172 /* Tell the runtime this can be shrinked */
173 list1 = ch_realloc(list, (i+1)*sizeof(AttributeType **));
192 for ( i=0; list[i]; i++ ) {
193 if ( sat == list[i] ) {
203 AttributeType *a, *n;
204 avl_free(attr_index, ldap_memfree);
206 for (a=attr_list; a; a=n) {
208 ldap_memfree(a->sat_subtypes);
209 ad_destroy(a->sat_ad);
210 ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
211 ldap_attributetype_free((LDAPAttributeType *)a);
222 struct aindexrec *air;
226 while ( *atp != NULL ) {
227 atp = &(*atp)->sat_next;
231 if ( sat->sat_oid ) {
232 air = (struct aindexrec *)
233 ch_calloc( 1, sizeof(struct aindexrec) );
234 air->air_name = sat->sat_oid;
236 if ( avl_insert( &attr_index, (caddr_t) air,
237 (AVL_CMP) attr_index_cmp,
238 (AVL_DUP) avl_dup_error ) ) {
241 return SLAP_SCHERR_DUP_ATTR;
243 /* FIX: temporal consistency check */
244 at_find(air->air_name);
247 if ( (names = sat->sat_names) ) {
249 air = (struct aindexrec *)
250 ch_calloc( 1, sizeof(struct aindexrec) );
251 air->air_name = *names;
253 if ( avl_insert( &attr_index, (caddr_t) air,
254 (AVL_CMP) attr_index_cmp,
255 (AVL_DUP) avl_dup_error ) ) {
258 return SLAP_SCHERR_DUP_ATTR;
260 /* FIX: temporal consistency check */
261 at_find(air->air_name);
271 LDAPAttributeType *at,
281 if ( at->at_names && at->at_names[0] ) {
284 for( i=0; at->at_names[i]; i++ ) {
285 if( !slap_valid_descr( at->at_names[i] ) ) {
286 return SLAP_SCHERR_BAD_DESCR;
290 cname = at->at_names[0];
292 } else if ( at->at_oid ) {
295 return SLAP_SCHERR_ATTR_INCOMPLETE;
298 if ( at->at_collective ) {
299 return SLAP_SCHERR_NOT_SUPPORTED;
302 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
303 AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
305 sat->sat_cname.bv_val = cname;
306 sat->sat_cname.bv_len = strlen( cname );
307 ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
309 if ( at->at_sup_oid ) {
310 AttributeType *supsat = at_find(at->at_sup_oid);
312 if ( (supsat == NULL ) ) {
313 *err = at->at_sup_oid;
314 return SLAP_SCHERR_ATTR_NOT_FOUND;
317 sat->sat_sup = supsat;
319 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
321 return SLAP_SCHERR_OUTOFMEM;
326 * Inherit definitions from superiors. We only check the
327 * direct superior since that one has already inherited from
330 if ( sat->sat_sup ) {
331 sat->sat_syntax = sat->sat_sup->sat_syntax;
332 sat->sat_equality = sat->sat_sup->sat_equality;
333 sat->sat_approx = sat->sat_sup->sat_approx;
334 sat->sat_ordering = sat->sat_sup->sat_ordering;
335 sat->sat_substr = sat->sat_sup->sat_substr;
338 if ( at->at_syntax_oid ) {
339 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
340 sat->sat_syntax = syn;
342 *err = sat->sat_syntax_oid;
343 return SLAP_SCHERR_SYN_NOT_FOUND;
347 } else if ( sat->sat_syntax == NULL ) {
348 return SLAP_SCHERR_ATTR_INCOMPLETE;
351 if ( sat->sat_equality_oid ) {
352 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
353 sat->sat_equality = mr;
354 sat->sat_approx = mr->smr_associated;
356 *err = sat->sat_equality_oid;
357 return SLAP_SCHERR_MR_NOT_FOUND;
362 if ( sat->sat_ordering_oid ) {
363 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
364 sat->sat_ordering = mr;
366 *err = sat->sat_ordering_oid;
367 return SLAP_SCHERR_MR_NOT_FOUND;
371 if ( sat->sat_substr_oid ) {
372 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
373 sat->sat_substr = mr;
375 *err = sat->sat_substr_oid;
376 return SLAP_SCHERR_MR_NOT_FOUND;
380 code = at_insert(sat,err);
386 at_index_printnode( struct aindexrec *air )
391 ldap_attributetype2str(&air->air_at->sat_atype) );
396 at_index_print( void )
398 printf("Printing attribute type index:\n");
399 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
400 0, -1, AVL_INORDER );
404 #if defined( SLAPD_SCHEMA_DN )
406 at_schema_info( Entry *e )
409 struct berval *vals[2];
412 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
417 for ( at = attr_list; at; at = at->sat_next ) {
418 val.bv_val = ldap_attributetype2str( &at->sat_atype );
419 if ( val.bv_val == NULL ) {
422 val.bv_len = strlen( val.bv_val );
424 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
425 (long) val.bv_len, val.bv_val, 0 );
427 attr_merge( e, ad_attributeTypes, vals );
428 ldap_memfree( val.bv_val );