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;
81 tmpname = (char *)name;
84 if ( (air = (struct aindexrec *) avl_find( attr_index, tmpname,
85 (AVL_CMP) attr_index_name_cmp )) != NULL ) {
86 if ( tmpname != name )
87 ldap_memfree( tmpname );
88 return( air->air_at );
91 if ( tmpname != name )
92 ldap_memfree( tmpname );
99 AttributeType ***listp
102 AttributeType **list;
103 AttributeType **list1;
109 list = calloc(size, sizeof(AttributeType *));
121 list1 = realloc(list, size*sizeof(AttributeType *));
136 AttributeType ***listp
139 AttributeType **list;
140 AttributeType **list1;
148 for ( i=0; list[i]; i++ )
153 for ( i=pos, j=pos+1; list[j]; i++, j++ ) {
157 /* Tell the runtime this can be shrinked */
158 list1 = realloc(list, (i+1)*sizeof(AttributeType **));
177 for ( i=0; list[i]; i++ ) {
178 if ( sat == list[i] ) {
192 struct aindexrec *air;
196 while ( *atp != NULL ) {
197 atp = &(*atp)->sat_next;
201 if ( sat->sat_oid ) {
202 air = (struct aindexrec *)
203 ch_calloc( 1, sizeof(struct aindexrec) );
204 air->air_name = sat->sat_oid;
206 if ( avl_insert( &attr_index, (caddr_t) air,
207 (AVL_CMP) attr_index_cmp,
208 (AVL_DUP) avl_dup_error ) ) {
211 return SLAP_SCHERR_DUP_ATTR;
213 /* FIX: temporal consistency check */
214 at_find(air->air_name);
217 if ( (names = sat->sat_names) ) {
219 air = (struct aindexrec *)
220 ch_calloc( 1, sizeof(struct aindexrec) );
221 air->air_name = ch_strdup(*names);
223 if ( avl_insert( &attr_index, (caddr_t) air,
224 (AVL_CMP) attr_index_cmp,
225 (AVL_DUP) avl_dup_error ) ) {
227 ldap_memfree(air->air_name);
229 return SLAP_SCHERR_DUP_ATTR;
231 /* FIX: temporal consistency check */
232 at_find(air->air_name);
242 LDAP_ATTRIBUTE_TYPE *at,
252 if ( at->at_names && at->at_names[0] ) {
253 cname = at->at_names[0];
254 } else if ( at->at_oid ) {
258 return SLAP_SCHERR_ATTR_INCOMPLETE;
260 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
261 memcpy( &sat->sat_atype, at, sizeof(LDAP_ATTRIBUTE_TYPE));
263 sat->sat_cname = cname;
265 if ( at->at_sup_oid ) {
266 AttributeType *supsat = at_find(at->at_sup_oid);
268 if ( (supsat == NULL ) ) {
269 *err = at->at_sup_oid;
270 return SLAP_SCHERR_ATTR_NOT_FOUND;
273 sat->sat_sup = supsat;
275 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
277 return SLAP_SCHERR_OUTOFMEM;
282 * Inherit definitions from superiors. We only check the
283 * direct superior since that one has already inherited from
286 if ( sat->sat_sup ) {
287 sat->sat_syntax = sat->sat_sup->sat_syntax;
288 sat->sat_equality = sat->sat_sup->sat_equality;
289 sat->sat_ordering = sat->sat_sup->sat_ordering;
290 sat->sat_substr = sat->sat_sup->sat_substr;
293 if ( at->at_syntax_oid ) {
294 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
295 sat->sat_syntax = syn;
297 *err = sat->sat_syntax_oid;
298 return SLAP_SCHERR_SYN_NOT_FOUND;
302 } else if ( sat->sat_syntax == NULL ) {
303 return SLAP_SCHERR_ATTR_INCOMPLETE;
306 if ( sat->sat_equality_oid ) {
307 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
308 sat->sat_equality = mr;
310 *err = sat->sat_equality_oid;
311 return SLAP_SCHERR_MR_NOT_FOUND;
316 if ( sat->sat_ordering_oid ) {
317 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
318 sat->sat_ordering = mr;
320 *err = sat->sat_ordering_oid;
321 return SLAP_SCHERR_MR_NOT_FOUND;
325 if ( sat->sat_substr_oid ) {
326 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
327 sat->sat_substr = mr;
329 *err = sat->sat_substr_oid;
330 return SLAP_SCHERR_MR_NOT_FOUND;
334 code = at_insert(sat,err);
340 at_index_printnode( struct aindexrec *air )
345 ldap_attributetype2str(&air->air_at->sat_atype) );
350 at_index_print( void )
352 printf("Printing attribute type index:\n");
353 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
354 0, -1, AVL_INORDER );
358 #if defined( SLAPD_SCHEMA_DN )
360 at_schema_info( Entry *e )
363 struct berval *vals[2];
366 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
371 for ( at = attr_list; at; at = at->sat_next ) {
372 val.bv_val = ldap_attributetype2str( &at->sat_atype );
373 if ( val.bv_val == NULL ) {
376 val.bv_len = strlen( val.bv_val );
378 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
379 (long) val.bv_len, val.bv_val, 0 );
381 attr_merge( e, ad_attributeTypes, vals );
382 ldap_memfree( val.bv_val );