Commit 92c6c9c2 authored by Howard Chu's avatar Howard Chu
Browse files

Misc berval stuff.

parent 65636e08
......@@ -154,7 +154,6 @@ int slap_bv2ad(
}
}
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)
......@@ -171,6 +170,23 @@ int slap_bv2ad(
/* 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.
......@@ -225,8 +241,8 @@ int slap_bv2ad(
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;
......
......@@ -44,7 +44,7 @@ int is_at_subtype(
}
struct aindexrec {
char *air_name;
struct berval air_name;
AttributeType *air_at;
};
......@@ -57,29 +57,23 @@ attr_index_cmp(
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 *
......@@ -87,12 +81,12 @@ at_find(
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 *
......@@ -103,7 +97,7 @@ at_bvfind(
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;
}
......@@ -231,7 +225,8 @@ at_insert(
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,
......@@ -241,14 +236,15 @@ at_insert(
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,
......@@ -258,7 +254,7 @@ at_insert(
return SLAP_SCHERR_DUP_ATTR;
}
/* FIX: temporal consistency check */
at_find(air->air_name);
at_bvfind(&air->air_name);
names++;
}
}
......@@ -387,7 +383,7 @@ at_index_printnode( struct aindexrec *air )
{
printf("%s = %s\n",
air->air_name,
air->air_name.bv_val,
ldap_attributetype2str(&air->air_at->sat_atype) );
return( 0 );
}
......
......@@ -18,7 +18,7 @@
struct mindexrec {
char *mir_name;
struct berval mir_name;
MatchingRule *mir_mr;
};
......@@ -31,20 +31,34 @@ mr_index_cmp(
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;
......@@ -86,7 +100,8 @@ mr_insert(
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,
......@@ -96,13 +111,14 @@ mr_insert(
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,
......@@ -112,7 +128,7 @@ mr_insert(
return SLAP_SCHERR_DUP_RULE;
}
/* FIX: temporal consistency check */
mr_find(mir->mir_name);
mr_bvfind(&mir->mir_name);
names++;
}
}
......
......@@ -77,7 +77,7 @@ get_mra(
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 );
......
......@@ -82,7 +82,7 @@ int is_entry_objectclass(
}
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;
......@@ -95,7 +95,7 @@ int is_entry_objectclass(
struct oindexrec {
char *oir_name;
struct berval oir_name;
ObjectClass *oir_oc;
};
......@@ -107,56 +107,32 @@ oc_index_cmp(
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 *
......@@ -165,12 +141,9 @@ oc_bvfind( struct berval *ocname )
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 );
}
......@@ -347,10 +320,11 @@ oc_insert(
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,
......@@ -363,17 +337,18 @@ oc_insert(
}
/* 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,
......@@ -386,7 +361,7 @@ oc_insert(
}
/* FIX: temporal consistency check */
assert( oc_find(oir->oir_name) != NULL );
assert( oc_bvfind(&oir->oir_name) != NULL );
names++;
}
......
......@@ -749,6 +749,7 @@ LDAP_SLAPD_F (int) syn_add LDAP_P((
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,
......
......@@ -100,7 +100,7 @@ entry_schema_check(
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'",
......@@ -165,7 +165,7 @@ entry_schema_check(
*text = textbuf;
oc = oc_find( nsc.bv_val );
oc = oc_bvfind( &nsc );
if ( oc == NULL ) {
snprintf( textbuf, textlen,
"unrecognized objectClass '%s'",
......@@ -181,7 +181,7 @@ entry_schema_check(
/* 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 );
......@@ -207,7 +207,7 @@ entry_schema_check(
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'",
......@@ -415,7 +415,7 @@ int oc_check_allowed(
/* 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 ))
{
......@@ -460,7 +460,7 @@ int structural_class(
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,
......@@ -481,7 +481,7 @@ int structural_class(
/* 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,
......
......@@ -3296,13 +3296,9 @@ objectIdentifierFirstComponentMatch(
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;
......@@ -3313,8 +3309,8 @@ objectIdentifierFirstComponentMatch(
} 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;
......@@ -3325,8 +3321,8 @@ objectIdentifierFirstComponentMatch(
} 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;
......@@ -3334,8 +3330,6 @@ objectIdentifierFirstComponentMatch(
match = asserted_oc != stored_oc;
}
}
ch_free( stored );
}
#ifdef NEW_LOGGING
......
......@@ -34,8 +34,8 @@ objectClassMatch(
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 ) ) {
......@@ -87,8 +87,8 @@ structuralObjectClassMatch(
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 ) ) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment