/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
/* ad.c - routines for dealing with attribute descriptions */
return 0;
}
-void ad_destroy( void *in )
+void ad_destroy( AttributeDescription *ad )
{
- AttributeDescription *ad = in, *n;
+ AttributeDescription *n;
- for (;ad;ad = n) {
+ for (; ad != NULL; ad = n) {
n = ad->ad_next;
- ldap_memfree(ad);
+ ldap_memfree( ad );
}
}
int ad_inlist(
AttributeDescription *desc,
- struct berval **attrs )
+ AttributeName *attrs )
{
- int i;
- for( i=0; attrs[i] != NULL; i++ ) {
+ if (! attrs ) return 0;
+
+ for( ; attrs->an_name.bv_val; attrs++ ) {
ObjectClass *oc;
- AttributeDescription *ad = NULL;
- const char *text;
int rc;
- rc = slap_bv2ad( attrs[i], &ad, &text );
- if( rc == LDAP_SUCCESS ) {
- rc = is_ad_subtype( desc, ad );
- if( rc ) return 1;
+ if ( attrs->an_desc ) {
+ if ( is_ad_subtype( desc, attrs->an_desc ))
+ return 1;
continue;
}
+
/*
* EXTENSION: see if requested description is an object class
* if so, return attributes which the class requires/allows
*/
- oc = oc_bvfind( attrs[i] );
+ oc = attrs->an_oc;
+ if( oc == NULL ) {
+ oc = oc_bvfind( &attrs->an_name );
+ attrs->an_oc = oc;
+ }
if( oc != NULL ) {
if ( oc == slap_schema.si_oc_extensibleObject ) {
/* extensibleObject allows the return of anything */
if( rc ) return 1;
}
}
+ } else {
+ /* short-circuit this search next time around */
+ if (!slap_schema.si_at_undefined->sat_ad) {
+ const char *text;
+ slap_bv2undef_ad(&attrs->an_name,
+ &attrs->an_desc, &text);
+ } else {
+ attrs->an_desc =
+ slap_schema.si_at_undefined->sat_ad;
+ }
}
}
return LDAP_SUCCESS;
}
+
+int
+an_find(
+ AttributeName *a,
+ struct berval *s
+)
+{
+ if( a == NULL ) return 0;
+
+ for ( ; a->an_name.bv_val; a++ ) {
+ if ( a->an_name.bv_len != s->bv_len) continue;
+ if ( strcasecmp( s->bv_val, a->an_name.bv_val ) == 0 ) {
+ return( 1 );
+ }
+ }
+
+ return( 0 );
+}
+
+/* Convert a delimited string into a list of AttributeNames; Add on
+ * to an existing list if it was given.
+ */
+AttributeName *
+str2anlist( AttributeName *an, char *in, const char *brkstr )
+{
+ char *str;
+ char *s;
+ char *lasts;
+ int i, j;
+ const char *text;
+ AttributeName *anew;
+
+ /* find last element in list */
+ for (i = 0; an && an[i].an_name.bv_val; i++);
+
+ /* protect the input string from strtok */
+ str = ch_strdup( in );
+
+ /* Count words in string */
+ j=1;
+ for ( s = str; *s; s++ ) {
+ if ( strchr( brkstr, *s ) != NULL ) {
+ j++;
+ }
+ }
+
+ an = ch_realloc( an, ( i + j + 1 ) * sizeof( AttributeName ) );
+ anew = an + i;
+ for ( s = ldap_pvt_strtok( str, brkstr, &lasts );
+ s != NULL;
+ s = ldap_pvt_strtok( NULL, brkstr, &lasts ) )
+ {
+ anew->an_desc = NULL;
+ anew->an_oc = NULL;
+ ber_str2bv(s, 0, 1, &anew->an_name);
+ slap_bv2ad(&anew->an_name, &anew->an_desc, &text);
+ if ( !anew->an_desc ) {
+ anew->an_oc = oc_bvfind( &anew->an_name );
+ if ( !anew->an_oc ) {
+ free( an );
+ /* overwrites input string on error! */
+ strcpy( in, s );
+ return NULL;
+ }
+ }
+ anew++;
+ }
+ anew->an_name.bv_val = NULL;
+
+ free( str );
+ return( an );
+}