/* mr.c - routines to manage matching rule definitions */
/* $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
*/
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 = (char *)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,
(AVL_DUP) avl_dup_error ) ) {
*err = smr->smr_oid;
ldap_memfree(mir);
- return SLAP_SCHERR_DUP_RULE;
+ return SLAP_SCHERR_MR_DUP;
}
/* 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,
(AVL_DUP) avl_dup_error ) ) {
*err = *names;
ldap_memfree(mir);
- return SLAP_SCHERR_DUP_RULE;
+ return SLAP_SCHERR_MR_DUP;
}
/* FIX: temporal consistency check */
- mr_find(mir->mir_name);
+ mr_bvfind(&mir->mir_name);
names++;
}
}
smr = (MatchingRule *) ch_calloc( 1, sizeof(MatchingRule) );
AC_MEMCPY( &smr->smr_mrule, mr, sizeof(LDAPMatchingRule));
+ smr->smr_oidlen = strlen( mr->mr_oid );
smr->smr_usage = usage;
smr->smr_convert = convert;
smr->smr_normalize = normalize;
int
register_matching_rule(
- char * desc,
+ const char * desc,
unsigned usage,
slap_mr_convert_func *convert,
slap_mr_normalize_func *normalize,
int mr_schema_info( Entry *e )
{
- struct berval val;
- struct berval *vals[2];
+ struct berval vals[2];
MatchingRule *mr;
AttributeDescription *ad_matchingRules = slap_schema.si_ad_matchingRules;
- vals[0] = &val;
- vals[1] = NULL;
+ vals[1].bv_val = NULL;
for ( mr = mr_list; mr; mr = mr->smr_next ) {
+ if ( mr->smr_usage & SLAP_MR_HIDE ) {
+ /* skip hidden rules */
+ continue;
+ }
+
if ( ! mr->smr_match ) {
/* skip rules without matching functions */
continue;
}
- val.bv_val = ldap_matchingrule2str( &mr->smr_mrule );
-
- if ( val.bv_val == NULL ) {
+ if ( ldap_matchingrule2bv( &mr->smr_mrule, vals ) == NULL ) {
return -1;
}
-
- val.bv_len = strlen( val.bv_val );
#if 0
Debug( LDAP_DEBUG_TRACE, "Merging mr [%ld] %s\n",
- (long) val.bv_len, val.bv_val, 0 );
+ (long) vals[0].bv_len, vals[0].bv_val, 0 );
#endif
attr_merge( e, ad_matchingRules, vals );
- ldap_memfree( val.bv_val );
+ ldap_memfree( vals[0].bv_val );
}
return 0;
}
+int mru_schema_info( Entry *e )
+{
+ return 0;
+}
+
#endif