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 = calloc(size, sizeof(AttributeType *));
110 list1 = 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 = realloc(list, (i+1)*sizeof(AttributeType **));
166 for ( i=0; list[i]; i++ ) {
167 if ( sat == list[i] ) {
181 struct aindexrec *air;
185 while ( *atp != NULL ) {
186 atp = &(*atp)->sat_next;
190 if ( sat->sat_oid ) {
191 air = (struct aindexrec *)
192 ch_calloc( 1, sizeof(struct aindexrec) );
193 air->air_name = sat->sat_oid;
195 if ( avl_insert( &attr_index, (caddr_t) air,
196 (AVL_CMP) attr_index_cmp,
197 (AVL_DUP) avl_dup_error ) ) {
200 return SLAP_SCHERR_DUP_ATTR;
202 /* FIX: temporal consistency check */
203 at_find(air->air_name);
206 if ( (names = sat->sat_names) ) {
208 air = (struct aindexrec *)
209 ch_calloc( 1, sizeof(struct aindexrec) );
210 air->air_name = ch_strdup(*names);
212 if ( avl_insert( &attr_index, (caddr_t) air,
213 (AVL_CMP) attr_index_cmp,
214 (AVL_DUP) avl_dup_error ) ) {
216 ldap_memfree(air->air_name);
218 return SLAP_SCHERR_DUP_ATTR;
220 /* FIX: temporal consistency check */
221 at_find(air->air_name);
231 LDAPAttributeType *at,
241 if ( at->at_names && at->at_names[0] ) {
242 cname = at->at_names[0];
243 } else if ( at->at_oid ) {
247 return SLAP_SCHERR_ATTR_INCOMPLETE;
249 sat = (AttributeType *) ch_calloc( 1, sizeof(AttributeType) );
250 AC_MEMCPY( &sat->sat_atype, at, sizeof(LDAPAttributeType));
252 sat->sat_cname = cname;
254 if ( at->at_sup_oid ) {
255 AttributeType *supsat = at_find(at->at_sup_oid);
257 if ( (supsat == NULL ) ) {
258 *err = at->at_sup_oid;
259 return SLAP_SCHERR_ATTR_NOT_FOUND;
262 sat->sat_sup = supsat;
264 if ( at_append_to_list(sat, &supsat->sat_subtypes) ) {
266 return SLAP_SCHERR_OUTOFMEM;
271 * Inherit definitions from superiors. We only check the
272 * direct superior since that one has already inherited from
275 if ( sat->sat_sup ) {
276 sat->sat_syntax = sat->sat_sup->sat_syntax;
277 sat->sat_equality = sat->sat_sup->sat_equality;
278 sat->sat_approx = sat->sat_sup->sat_approx;
279 sat->sat_ordering = sat->sat_sup->sat_ordering;
280 sat->sat_substr = sat->sat_sup->sat_substr;
283 if ( at->at_syntax_oid ) {
284 if ( (syn = syn_find(sat->sat_syntax_oid)) ) {
285 sat->sat_syntax = syn;
287 *err = sat->sat_syntax_oid;
288 return SLAP_SCHERR_SYN_NOT_FOUND;
292 } else if ( sat->sat_syntax == NULL ) {
293 return SLAP_SCHERR_ATTR_INCOMPLETE;
296 if ( sat->sat_equality_oid ) {
297 if ( (mr = mr_find(sat->sat_equality_oid)) ) {
298 sat->sat_equality = mr;
299 sat->sat_approx = mr->smr_associated;
301 *err = sat->sat_equality_oid;
302 return SLAP_SCHERR_MR_NOT_FOUND;
307 if ( sat->sat_ordering_oid ) {
308 if ( (mr = mr_find(sat->sat_ordering_oid)) ) {
309 sat->sat_ordering = mr;
311 *err = sat->sat_ordering_oid;
312 return SLAP_SCHERR_MR_NOT_FOUND;
316 if ( sat->sat_substr_oid ) {
317 if ( (mr = mr_find(sat->sat_substr_oid)) ) {
318 sat->sat_substr = mr;
320 *err = sat->sat_substr_oid;
321 return SLAP_SCHERR_MR_NOT_FOUND;
325 code = at_insert(sat,err);
331 at_index_printnode( struct aindexrec *air )
336 ldap_attributetype2str(&air->air_at->sat_atype) );
341 at_index_print( void )
343 printf("Printing attribute type index:\n");
344 (void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
345 0, -1, AVL_INORDER );
349 #if defined( SLAPD_SCHEMA_DN )
351 at_schema_info( Entry *e )
354 struct berval *vals[2];
357 AttributeDescription *ad_attributeTypes = slap_schema.si_ad_attributeTypes;
362 for ( at = attr_list; at; at = at->sat_next ) {
363 val.bv_val = ldap_attributetype2str( &at->sat_atype );
364 if ( val.bv_val == NULL ) {
367 val.bv_len = strlen( val.bv_val );
369 Debug( LDAP_DEBUG_TRACE, "Merging at [%ld] %s\n",
370 (long) val.bv_len, val.bv_val, 0 );
372 attr_merge( e, ad_attributeTypes, vals );
373 ldap_memfree( val.bv_val );