3 * Copyright 1998-2002 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;
47 struct berval air_name;
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 int i = air1->air_name.bv_len - air2->air_name.bv_len;
63 return (strcasecmp( air1->air_name.bv_val, air2->air_name.bv_val ));
72 int i = type->bv_len - air->air_name.bv_len;
75 return (strncasecmp( type->bv_val, air->air_name.bv_val,
86 bv.bv_val = (char *)name;
87 bv.bv_len = strlen( name );
89 return at_bvfind( &bv );
97 struct aindexrec *air;
99 air = (struct aindexrec *) avl_find( attr_index, name,
100 (AVL_CMP) attr_index_name_cmp );
102 return air != NULL ? air->air_at : NULL;
108 AttributeType ***listp
111 AttributeType **list;
112 AttributeType **list1;
118 list = ch_calloc(size, sizeof(AttributeType *));
130 list1 = ch_realloc(list, size*sizeof(AttributeType *));
145 AttributeType ***listp
148 AttributeType **list;
149 AttributeType **list1;
157 for ( i=0; list[i]; i++ )
162 for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
166 /* Tell the runtime this can be shrinked */
167 list1 = ch_realloc(list, (i+1)*sizeof(AttributeType **));
186 for ( i=0; list[i]; i++ ) {
187 if ( sat == list[i] ) {
197 AttributeType *a, *n;
198 avl_free(attr_index, ldap_memfree);
200 for (a=attr_list; a; a=n) {
202 if (a->sat_subtypes) ldap_memfree(a->sat_subtypes);
203 ad_destroy(a->sat_ad);
204 ldap_pvt_thread_mutex_destroy(&a->sat_ad_mutex);
205 ldap_attributetype_free((LDAPAttributeType *)a);
207 if ( slap_schema.si_at_undefined )
208 ad_destroy(slap_schema.si_at_undefined->sat_ad);
218 struct aindexrec *air;
222 while ( *atp != NULL ) {
223 atp = &(*atp)->sat_next;
227 if ( sat->sat_oid ) {
228 air = (struct aindexrec *)
229 ch_calloc( 1, sizeof(struct aindexrec) );
230 air->air_name.bv_val = sat->sat_oid;
231 air->air_name.bv_len = strlen(sat->sat_oid);
233 if ( avl_insert( &attr_index, (caddr_t) air,
234 (AVL_CMP) attr_index_cmp,
235 (AVL_DUP) avl_dup_error ) ) {
238 return SLAP_SCHERR_DUP_ATTR;
240 /* FIX: temporal consistency check */
241 at_bvfind(&air->air_name);
244 if ( (names = sat->sat_names) ) {
246 air = (struct aindexrec *)
247 ch_calloc( 1, sizeof(struct aindexrec) );
248 air->air_name.bv_val = *names;
249 air->air_name.bv_len = strlen(*names);
251 if ( avl_insert( &attr_index, (caddr_t) air,
252 (AVL_CMP) attr_index_cmp,
253 (AVL_DUP) avl_dup_error ) ) {
256 return SLAP_SCHERR_DUP_ATTR;
258 /* FIX: temporal consistency check */
259 at_bvfind(&air->air_name);
269 LDAPAttributeType *at,
279 if ( at->at_names && at->at_names[0] ) {
282 for( i=0; at->at_names[i]; i++ ) {
283 if( !slap_valid_descr( at->at_names[i] ) ) {
284 return SLAP_SCHERR_BAD_DESCR;
288 cname = at->at_names[0];
290 } else if ( at->at_oid ) {
293 return SLAP_SCHERR_ATTR_INCOMPLETE;
296 if ( at->at_collective ) {
297 return SLAP_SCHERR_NOT_SUPPORTED;
300 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
301 AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
303 sat->sat_cname.bv_val = cname;
304 sat->sat_cname.bv_len = strlen( cname );
305 ldap_pvt_thread_mutex_init(&sat->sat_ad_mutex);
307 if ( at->at_sup_oid ) {
308 AttributeType *supsat = at_find(at->at_sup_oid);
310 if ( (supsat == NULL ) ) {
311 *err = at->at_sup_oid;
312 return SLAP_SCHERR_ATTR_NOT_FOUND;
315 sat->sat_sup = supsat;
317 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
319 return SLAP_SCHERR_OUTOFMEM;
324 * Inherit definitions from superiors. We only check the
325 * direct superior since that one has already inherited from
328 if ( sat->sat_sup ) {
329 sat->sat_syntax = sat->sat_sup->sat_syntax;
330 sat->sat_equality = sat->sat_sup->sat_equality;
331 sat->sat_approx = sat->sat_sup->sat_approx;
332 sat->sat_ordering = sat->sat_sup->sat_ordering;
333 sat->sat_substr = sat->sat_sup->sat_substr;
336 if ( at->at_syntax_oid ) {
337 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
338 sat->sat_syntax = syn;
340 *err = sat->sat_syntax_oid;
341 return SLAP_SCHERR_SYN_NOT_FOUND;
345 } else if ( sat->sat_syntax == NULL ) {
346 return SLAP_SCHERR_ATTR_INCOMPLETE;
349 if ( sat->sat_equality_oid ) {
350 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
351 sat->sat_equality = mr;
352 sat->sat_approx = mr->smr_associated;
354 *err = sat->sat_equality_oid;
355 return SLAP_SCHERR_MR_NOT_FOUND;
360 if ( sat->sat_ordering_oid ) {
361 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
362 sat->sat_ordering = mr;
364 *err = sat->sat_ordering_oid;
365 return SLAP_SCHERR_MR_NOT_FOUND;
369 if ( sat->sat_substr_oid ) {
370 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
371 sat->sat_substr = mr;
373 *err = sat->sat_substr_oid;
374 return SLAP_SCHERR_MR_NOT_FOUND;
378 code = at_insert(sat,err);
384 at_index_printnode( struct aindexrec *air )
388 air->air_name.bv_val,
389 ldap_attributetype2str(&air->air_at->sat_atype) );
394 at_index_print( void )
396 printf("Printing attribute type index:\n");
397 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
398 0, -1, AVL_INORDER );
402 #if defined( SLAPD_SCHEMA_DN )
404 at_schema_info( Entry *e )
406 struct berval vals[2];
409 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
411 vals[1].bv_val = NULL;
413 for ( at = attr_list; at; at = at->sat_next ) {
414 if ( ldap_attributetype2bv( &at->sat_atype, vals ) == NULL ) {
418 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
419 (long) vals[0].bv_len, vals[0].bv_val, 0 );
421 attr_merge( e, ad_attributeTypes, vals );
422 ldap_memfree( vals[0].bv_val );