From 30fbf95de1039e55f75678b35ba49f4574fbaee5 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Fri, 24 Aug 2007 20:05:30 +0000 Subject: [PATCH] allow to register further syntax/mr compatibility --- servers/slapd/mr.c | 66 ++++++++++++++++++++++++++++++++++++-- servers/slapd/proto-slap.h | 14 +++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c index 8a49f4f6c5..f85c08af06 100644 --- a/servers/slapd/mr.c +++ b/servers/slapd/mr.c @@ -145,6 +145,67 @@ mr_insert( return 0; } +int +mr_make_syntax_compat_with_mr( + Syntax *syn, + MatchingRule *mr ) +{ + int n = 0; + + assert( syn != NULL ); + assert( mr != NULL ); + + if ( mr->smr_compat_syntaxes ) { + /* count esisting */ + for ( n = 0; + mr->smr_compat_syntaxes[ n ]; + n++ ) + { + if ( mr->smr_compat_syntaxes[ n ] == syn ) { + /* already compatible; mmmmh... */ + return 1; + } + } + } + + mr->smr_compat_syntaxes = ch_realloc( + mr->smr_compat_syntaxes, + sizeof( Syntax * )*(n + 2) ); + mr->smr_compat_syntaxes[ n ] = syn; + mr->smr_compat_syntaxes[ n + 1 ] = NULL; + + return 0; +} + +int +mr_make_syntax_compat_with_mrs( + const char *syntax, + char *const *mrs ) +{ + int r, rc = 0; + Syntax *syn; + + assert( syntax != NULL ); + assert( mrs != NULL ); + + syn = syn_find( syntax ); + if ( syn == NULL ) { + return -1; + } + + for ( r = 0; mrs[ r ] != NULL; r++ ) { + MatchingRule *mr = mr_find( mrs[ r ] ); + if ( mr == NULL ) { + /* matchingRule not found -- ignore by now */ + continue; + } + + rc += mr_make_syntax_compat_with_mr( syn, mr ); + } + + return rc; +} + int mr_add( LDAPMatchingRule *mr, @@ -316,7 +377,8 @@ matching_rule_use_init( void ) LDAP_SLIST_FOREACH( mr, &mr_list, smr_next ) { AttributeType *at; - MatchingRuleUse mru_storage, *mru = &mru_storage; + MatchingRuleUse mru_storage = { 0 }, + *mru = &mru_storage; char **applies_oids = NULL; @@ -341,8 +403,6 @@ matching_rule_use_init( void ) continue; } - memset( mru, 0, sizeof( MatchingRuleUse ) ); - /* * Note: we're using the same values of the corresponding * MatchingRule structure; maybe we'd copy them ... diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 9eb6c9a86d..7e2e596c0a 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1238,11 +1238,17 @@ LDAP_SLAPD_F (int) register_matching_rule LDAP_P(( LDAP_SLAPD_F (void) mru_destroy LDAP_P(( void )); LDAP_SLAPD_F (int) matching_rule_use_init LDAP_P(( void )); -LDAP_SLAPD_F (int) mr_schema_info( Entry *e ); -LDAP_SLAPD_F (int) mru_schema_info( Entry *e ); +LDAP_SLAPD_F (int) mr_schema_info LDAP_P(( Entry *e )); +LDAP_SLAPD_F (int) mru_schema_info LDAP_P(( Entry *e )); -LDAP_SLAPD_F (int) mr_usable_with_at( MatchingRule *mr, - AttributeType *at ); +LDAP_SLAPD_F (int) mr_usable_with_at LDAP_P(( MatchingRule *mr, + AttributeType *at )); +LDAP_SLAPD_F (int) mr_make_syntax_compat_with_mr LDAP_P(( + Syntax *syn, + MatchingRule *mr )); +LDAP_SLAPD_F (int) mr_make_syntax_compat_with_mrs LDAP_P(( + const char *syntax, + char *const *mrs )); /* * mra.c -- 2.39.5