/* $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 );
}
}
AttributeDescription *desc,
AttributeName *attrs )
{
- for( ; attrs; attrs=attrs->an_next ) {
+ if (! attrs ) return 0;
+
+ for( ; attrs->an_name.bv_val; attrs++ ) {
ObjectClass *oc;
- const char *text;
int rc;
if ( attrs->an_desc ) {
* EXTENSION: see if requested description is an object class
* if so, return attributes which the class requires/allows
*/
- oc = oc_bvfind( &attrs->an_name );
+ 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;
+ }
}
}
{
if( a == NULL ) return 0;
- for ( ; a; a=a->an_next ) {
+ 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 );
* to an existing list if it was given.
*/
AttributeName *
-str2anlist( AttributeName *an, const char *in, const char *brkstr )
+str2anlist( AttributeName *an, char *in, const char *brkstr )
{
char *str;
char *s;
char *lasts;
+ int i, j;
const char *text;
- AttributeName *a, *anew;
+ 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 );
- /* find last element in list */
- for (a = an; a && a->an_next; a=a->an_next);
-
+ /* 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 = ch_malloc( sizeof( AttributeName ) );
- anew->an_next = NULL;
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 (!an) {
- an = anew;
- } else {
- a->an_next = anew;
+ 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;
+ }
}
- a = anew;
+ anew++;
}
+ anew->an_name.bv_val = NULL;
free( str );
return( an );