}
}
- 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;
}
struct aindexrec {
- char *air_name;
+ struct berval air_name;
AttributeType *air_at;
};
struct aindexrec *air2
)
{
- return (strcasecmp( air1->air_name, air2->air_name ));
+ int i = air1->air_name.bv_len - air2->air_name.bv_len;
+ if (i)
+ return i;
+ return (strcasecmp( air1->air_name.bv_val, air2->air_name.bv_val ));
}
static int
attr_index_name_cmp(
- const char *type,
- struct aindexrec *air
-)
-{
- return (strcasecmp( type, air->air_name ));
-}
-
-/* Uses strncasecmp to allow the input type to be non-terminated */
-static int
-attr_index_bvname_cmp(
struct berval *type,
struct aindexrec *air
)
{
- int rc = strncasecmp( type->bv_val, air->air_name, type->bv_len );
- if (rc)
- return rc;
- return air->air_name[type->bv_len] ? -1 : 0;
+ int i = type->bv_len - air->air_name.bv_len;
+ if (i)
+ return i;
+ return (strncasecmp( type->bv_val, air->air_name.bv_val,
+ type->bv_len ));
}
AttributeType *
const char *name
)
{
- struct aindexrec *air;
+ struct berval bv;
- air = (struct aindexrec *) avl_find( attr_index, name,
- (AVL_CMP) attr_index_name_cmp );
+ bv.bv_val = (char *)name;
+ bv.bv_len = strlen( name );
- return air != NULL ? air->air_at : NULL;
+ return at_bvfind( &bv );
}
AttributeType *
struct aindexrec *air;
air = (struct aindexrec *) avl_find( attr_index, name,
- (AVL_CMP) attr_index_bvname_cmp );
+ (AVL_CMP) attr_index_name_cmp );
return air != NULL ? air->air_at : NULL;
}
if ( sat->sat_oid ) {
air = (struct aindexrec *)
ch_calloc( 1, sizeof(struct aindexrec) );
- air->air_name = sat->sat_oid;
+ air->air_name.bv_val = sat->sat_oid;
+ air->air_name.bv_len = strlen(sat->sat_oid);
air->air_at = sat;
if ( avl_insert( &attr_index, (caddr_t) air,
(AVL_CMP) attr_index_cmp,
return SLAP_SCHERR_DUP_ATTR;
}
/* FIX: temporal consistency check */
- at_find(air->air_name);
+ at_bvfind(&air->air_name);
}
if ( (names = sat->sat_names) ) {
while ( *names ) {
air = (struct aindexrec *)
ch_calloc( 1, sizeof(struct aindexrec) );
- air->air_name = *names;
+ air->air_name.bv_val = *names;
+ air->air_name.bv_len = strlen(*names);
air->air_at = sat;
if ( avl_insert( &attr_index, (caddr_t) air,
(AVL_CMP) attr_index_cmp,
return SLAP_SCHERR_DUP_ATTR;
}
/* FIX: temporal consistency check */
- at_find(air->air_name);
+ at_bvfind(&air->air_name);
names++;
}
}
{
printf("%s = %s\n",
- air->air_name,
+ air->air_name.bv_val,
ldap_attributetype2str(&air->air_at->sat_atype) );
return( 0 );
}
struct mindexrec {
- char *mir_name;
+ struct berval mir_name;
MatchingRule *mir_mr;
};
struct mindexrec *mir2
)
{
- return (strcmp( mir1->mir_name, mir2->mir_name ));
+ int i = mir1->mir_name.bv_len - mir2->mir_name.bv_len;
+ if (i) return i;
+ return (strcmp( mir1->mir_name.bv_val, mir2->mir_name.bv_val ));
}
static int
mr_index_name_cmp(
- char *name,
+ struct berval *name,
struct mindexrec *mir
)
{
- return (strcmp( name, mir->mir_name ));
+ int i = name->bv_len - mir->mir_name.bv_len;
+ if (i) return i;
+ return (strncmp( name->bv_val, mir->mir_name.bv_val, name->bv_len ));
}
MatchingRule *
mr_find( const char *mrname )
+{
+ struct berval bv;
+
+ bv.bv_val = mrname;
+ bv.bv_len = strlen( mrname );
+ return mr_bvfind( &bv );
+}
+
+MatchingRule *
+mr_bvfind( struct berval *mrname )
{
struct mindexrec *mir = NULL;
if ( smr->smr_oid ) {
mir = (struct mindexrec *)
ch_calloc( 1, sizeof(struct mindexrec) );
- mir->mir_name = smr->smr_oid;
+ mir->mir_name.bv_val = smr->smr_oid;
+ mir->mir_name.bv_len = strlen( smr->smr_oid );
mir->mir_mr = smr;
if ( avl_insert( &mr_index, (caddr_t) mir,
(AVL_CMP) mr_index_cmp,
return SLAP_SCHERR_DUP_RULE;
}
/* FIX: temporal consistency check */
- mr_find(mir->mir_name);
+ mr_bvfind(&mir->mir_name);
}
if ( (names = smr->smr_names) ) {
while ( *names ) {
mir = (struct mindexrec *)
ch_calloc( 1, sizeof(struct mindexrec) );
- mir->mir_name = *names;
+ mir->mir_name.bv_val = *names;
+ mir->mir_name.bv_len = strlen( *names );
mir->mir_mr = smr;
if ( avl_insert( &mr_index, (caddr_t) mir,
(AVL_CMP) mr_index_cmp,
return SLAP_SCHERR_DUP_RULE;
}
/* FIX: temporal consistency check */
- mr_find(mir->mir_name);
+ mr_bvfind(&mir->mir_name);
names++;
}
}
mra_free( ma, 1 );
return SLAPD_DISCONNECT;
}
- ma->ma_rule = mr_find( ma->ma_rule_text.bv_val );
+ ma->ma_rule = mr_bvfind( &ma->ma_rule_text );
rc = ber_scanf( ber, "t", &tag );
}
for( i=0; attr->a_vals[i]; i++ ) {
- ObjectClass *objectClass = oc_find( attr->a_vals[i]->bv_val );
+ ObjectClass *objectClass = oc_bvfind( attr->a_vals[i] );
if( objectClass == oc ) {
return 1;
struct oindexrec {
- char *oir_name;
+ struct berval oir_name;
ObjectClass *oir_oc;
};
struct oindexrec *oir1,
struct oindexrec *oir2 )
{
- assert( oir1->oir_name );
- assert( oir1->oir_oc );
- assert( oir2->oir_name );
- assert( oir2->oir_oc );
-
- return strcasecmp( oir1->oir_name, oir2->oir_name );
-}
-
-static int
-oc_index_bvname_cmp(
- struct berval *name,
- struct oindexrec *oir )
-{
- int rc;
-
- assert( oir->oir_name );
- assert( oir->oir_oc );
-
- rc = strncasecmp( name->bv_val, oir->oir_name, name->bv_len );
- if (rc) return rc;
- return oir->oir_name[name->bv_len] ? -1 : 0;
+ int i = oir1->oir_name.bv_len - oir2->oir_name.bv_len;
+ if (i)
+ return i;
+ return strcasecmp( oir1->oir_name.bv_val, oir2->oir_name.bv_val );
}
static int
oc_index_name_cmp(
- char *name,
+ struct berval *name,
struct oindexrec *oir )
{
- assert( oir->oir_name );
- assert( oir->oir_oc );
-
- return (strcasecmp( name, oir->oir_name ));
+ int i = name->bv_len - oir->oir_name.bv_len;
+ if (i)
+ return i;
+ return strncasecmp( name->bv_val, oir->oir_name.bv_val, name->bv_len );
}
ObjectClass *
oc_find( const char *ocname )
{
- struct oindexrec *oir;
+ struct berval bv;
- oir = (struct oindexrec *) avl_find( oc_index, ocname,
- (AVL_CMP) oc_index_name_cmp );
-
- if ( oir != NULL ) {
- assert( oir->oir_name );
- assert( oir->oir_oc );
-
- return( oir->oir_oc );
- }
+ bv.bv_val = (char *)ocname;
+ bv.bv_len = strlen( ocname );
- return( NULL );
+ return( oc_bvfind( &bv ) );
}
ObjectClass *
struct oindexrec *oir;
oir = (struct oindexrec *) avl_find( oc_index, ocname,
- (AVL_CMP) oc_index_bvname_cmp );
+ (AVL_CMP) oc_index_name_cmp );
if ( oir != NULL ) {
- assert( oir->oir_name );
- assert( oir->oir_oc );
-
return( oir->oir_oc );
}
if ( soc->soc_oid ) {
oir = (struct oindexrec *)
ch_calloc( 1, sizeof(struct oindexrec) );
- oir->oir_name = soc->soc_oid;
+ oir->oir_name.bv_val = soc->soc_oid;
+ oir->oir_name.bv_len = strlen( soc->soc_oid );
oir->oir_oc = soc;
- assert( oir->oir_name );
+ assert( oir->oir_name.bv_val );
assert( oir->oir_oc );
if ( avl_insert( &oc_index, (caddr_t) oir,
}
/* FIX: temporal consistency check */
- assert( oc_find(oir->oir_name) != NULL );
+ assert( oc_bvfind(&oir->oir_name) != NULL );
}
if ( (names = soc->soc_names) ) {
while ( *names ) {
oir = (struct oindexrec *)
ch_calloc( 1, sizeof(struct oindexrec) );
- oir->oir_name = *names;
+ oir->oir_name.bv_val = *names;
+ oir->oir_name.bv_len = strlen( *names );
oir->oir_oc = soc;
- assert( oir->oir_name );
+ assert( oir->oir_name.bv_val );
assert( oir->oir_oc );
if ( avl_insert( &oc_index, (caddr_t) oir,
}
/* FIX: temporal consistency check */
- assert( oc_find(oir->oir_name) != NULL );
+ assert( oc_bvfind(&oir->oir_name) != NULL );
names++;
}
const char **err ));
#endif
+LDAP_SLAPD_F (MatchingRule *) mr_bvfind LDAP_P((struct berval *mrname));
LDAP_SLAPD_F (MatchingRule *) mr_find LDAP_P((const char *mrname));
LDAP_SLAPD_F (int) mr_add LDAP_P(( LDAPMatchingRule *mr,
unsigned usage,
assert( asc->a_vals[0] != NULL );
assert( asc->a_vals[1] == NULL );
- sc = oc_find( asc->a_vals[0]->bv_val );
+ sc = oc_bvfind( asc->a_vals[0] );
if( sc == NULL ) {
snprintf( textbuf, textlen,
"unrecognized structuralObjectClass '%s'",
*text = textbuf;
- oc = oc_find( nsc.bv_val );
+ oc = oc_bvfind( &nsc );
if ( oc == NULL ) {
snprintf( textbuf, textlen,
"unrecognized objectClass '%s'",
/* check that the entry has required attrs for each oc */
for ( i = 0; aoc->a_vals[i] != NULL; i++ ) {
- if ( (oc = oc_find( aoc->a_vals[i]->bv_val )) == NULL ) {
+ if ( (oc = oc_bvfind( aoc->a_vals[i] )) == NULL ) {
snprintf( textbuf, textlen,
"unrecognized objectClass '%s'",
aoc->a_vals[i]->bv_val );
ObjectClass *xc = NULL;
for( j=0; aoc->a_vals[j]; j++ ) {
if( i != j ) {
- xc = oc_find( aoc->a_vals[i]->bv_val );
+ xc = oc_bvfind( aoc->a_vals[i] );
if( xc == NULL ) {
snprintf( textbuf, textlen,
"unrecognized objectClass '%s'",
/* check that the type appears as req or opt in at least one oc */
for ( i = 0; ocl[i] != NULL; i++ ) {
/* if we know about the oc */
- ObjectClass *oc = oc_find( ocl[i]->bv_val );
+ ObjectClass *oc = oc_bvfind( ocl[i] );
if ( oc != NULL && oc->soc_kind != LDAP_SCHEMA_ABSTRACT &&
( sc == NULL || oc->soc_kind == LDAP_SCHEMA_AUXILIARY ))
{
scbv->bv_len = 0;
for( i=0; ocs[i]; i++ ) {
- oc = oc_find( ocs[i]->bv_val );
+ oc = oc_bvfind( ocs[i] );
if( oc == NULL ) {
snprintf( textbuf, textlen,
/* find common superior */
for( j=i+1; ocs[j]; j++ ) {
- xc = oc_find( ocs[j]->bv_val );
+ xc = oc_bvfind( ocs[j] );
if( xc == NULL ) {
snprintf( textbuf, textlen,
rc = objectIdentifierMatch( &match, flags, syntax, mr, &oid, asserted );
} else {
- char *stored = ch_malloc( oid.bv_len + 1 );
- AC_MEMCPY( stored, oid.bv_val, oid.bv_len );
- stored[oid.bv_len] = '\0';
-
if ( !strcmp( syntax->ssyn_oid, SLAP_SYNTAX_MATCHINGRULES_OID ) ) {
- MatchingRule *asserted_mr = mr_find( asserted->bv_val );
- MatchingRule *stored_mr = mr_find( stored );
+ MatchingRule *asserted_mr = mr_bvfind( asserted );
+ MatchingRule *stored_mr = mr_bvfind( &oid );
if( asserted_mr == NULL ) {
rc = SLAPD_COMPARE_UNDEFINED;
} else if ( !strcmp( syntax->ssyn_oid,
SLAP_SYNTAX_ATTRIBUTETYPES_OID ) )
{
- AttributeType *asserted_at = at_find( asserted->bv_val );
- AttributeType *stored_at = at_find( stored );
+ AttributeType *asserted_at = at_bvfind( asserted );
+ AttributeType *stored_at = at_bvfind( &oid );
if( asserted_at == NULL ) {
rc = SLAPD_COMPARE_UNDEFINED;
} else if ( !strcmp( syntax->ssyn_oid,
SLAP_SYNTAX_OBJECTCLASSES_OID ) )
{
- ObjectClass *asserted_oc = oc_find( asserted->bv_val );
- ObjectClass *stored_oc = oc_find( stored );
+ ObjectClass *asserted_oc = oc_bvfind( asserted );
+ ObjectClass *stored_oc = oc_bvfind( &oid );
if( asserted_oc == NULL ) {
rc = SLAPD_COMPARE_UNDEFINED;
match = asserted_oc != stored_oc;
}
}
-
- ch_free( stored );
}
#ifdef NEW_LOGGING
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
- ObjectClass *oc = oc_find( value->bv_val );
- ObjectClass *asserted = oc_find( a->bv_val );
+ ObjectClass *oc = oc_bvfind( value );
+ ObjectClass *asserted = oc_bvfind( a );
if( asserted == NULL ) {
if( OID_LEADCHAR( *a->bv_val ) ) {
void *assertedValue )
{
struct berval *a = (struct berval *) assertedValue;
- ObjectClass *oc = oc_find( value->bv_val );
- ObjectClass *asserted = oc_find( a->bv_val );
+ ObjectClass *oc = oc_bvfind( value );
+ ObjectClass *asserted = oc_bvfind( a );
if( asserted == NULL ) {
if( OID_LEADCHAR( *a->bv_val ) ) {