/* $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 );
}
}
}
/* find valid base attribute type; parse in place */
+ desc.ad_cname = *bv;
name = bv->bv_val;
options = strchr(name, ';');
- if (options != NULL) *options = '\0';
- desc.ad_type = at_find( name );
- if (options != NULL) *options = ';';
+ if (options != NULL)
+ desc.ad_cname.bv_len = options - name;
+ desc.ad_type = at_bvfind( &desc.ad_cname );
if( desc.ad_type == NULL ) {
*text = "attribute type undefined";
return rtn;
}
- if (options != NULL) {
- desc.ad_cname.bv_len = options - name;
- } else {
- desc.ad_cname.bv_len = bv->bv_len;
- }
-
desc.ad_flags = SLAP_DESC_NONE;
desc.ad_lang.bv_len = 0;
desc.ad_lang.bv_val = NULL;
if ( options != NULL )
i = options - name;
else
- i = strlen(name);
+ i = bv->bv_len - (name - bv->bv_val);
if( i == sizeof("binary")-1 && strncasecmp( name, "binary", i) == 0 ) {
if( slap_ad_is_binary( &desc ) ) {
}
}
- ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
/* see if a matching description is already cached */
for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
if (d2->ad_flags != desc.ad_flags)
/* Not found, add new one */
while (d2 == NULL) {
int dlen = 0;
+ ldap_pvt_thread_mutex_lock( &desc.ad_type->sat_ad_mutex );
+ /* check again now that we've locked */
+ for (d2 = desc.ad_type->sat_ad; d2; d2=d2->ad_next) {
+ if (d2->ad_flags != desc.ad_flags)
+ continue;
+ if (d2->ad_lang.bv_len != desc.ad_lang.bv_len)
+ continue;
+ if (d2->ad_lang.bv_len == 0)
+ break;
+ if (strncasecmp(d2->ad_lang.bv_val, desc.ad_lang.bv_val,
+ desc.ad_lang.bv_len) == 0)
+ break;
+ }
+ if (d2) {
+ ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
+ break;
+ }
/* Allocate a single contiguous block. If there are no
* options, we just need space for the AttrDesc structure.
d2->ad_next = desc.ad_type->sat_ad->ad_next;
desc.ad_type->sat_ad->ad_next = d2;
}
+ ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
}
- ldap_pvt_thread_mutex_unlock( &desc.ad_type->sat_ad_mutex );
if( *ad == NULL ) {
*ad = d2;
int ad_inlist(
AttributeDescription *desc,
- char **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_str2ad( 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_find( 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 );
+}