From e5091f5926f0331bc4cfd778cc557160d79ec123 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 17 Aug 2002 01:29:18 +0000 Subject: [PATCH] Updated register_syntax, register_matching_rule for more convenient calling from other modules --- servers/slapd/mr.c | 56 ++++++++++++++----------------------- servers/slapd/proto-slap.h | 39 +++----------------------- servers/slapd/schema_init.c | 47 ++++--------------------------- servers/slapd/slap.h | 24 ++++++++++++++++ servers/slapd/syntax.c | 39 ++++++++++---------------- 5 files changed, 68 insertions(+), 137 deletions(-) diff --git a/servers/slapd/mr.c b/servers/slapd/mr.c index dfa34c95d8..ee69d0b535 100644 --- a/servers/slapd/mr.c +++ b/servers/slapd/mr.c @@ -137,12 +137,7 @@ mr_insert( int mr_add( LDAPMatchingRule *mr, - unsigned usage, - slap_mr_convert_func *convert, - slap_mr_normalize_func *normalize, - slap_mr_match_func *match, - slap_mr_indexer_func *indexer, - slap_mr_filter_func *filter, + slap_mrule_defs_rec *def, MatchingRule *amr, const char **err ) @@ -155,12 +150,12 @@ mr_add( 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; - smr->smr_match = match; - smr->smr_indexer = indexer; - smr->smr_filter = filter; + smr->smr_usage = def->mrd_usage; + smr->smr_convert = def->mrd_convert; + smr->smr_normalize = def->mrd_normalize; + smr->smr_match = def->mrd_match; + smr->smr_indexer = def->mrd_indexer; + smr->smr_filter = def->mrd_filter; smr->smr_associated = amr; if ( smr->smr_syntax_oid ) { @@ -181,34 +176,27 @@ mr_add( int register_matching_rule( - const char * desc, - unsigned usage, - slap_mr_convert_func *convert, - slap_mr_normalize_func *normalize, - slap_mr_match_func *match, - slap_mr_indexer_func *indexer, - slap_mr_filter_func *filter, - const char* associated ) + slap_mrule_defs_rec *def ) { LDAPMatchingRule *mr; MatchingRule *amr = NULL; int code; const char *err; - if( usage == SLAP_MR_NONE ) { + if( def->mrd_usage == SLAP_MR_NONE ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, - "register_matching_rule: %s not usable\n", desc, 0, 0 ); + "register_matching_rule: %s not usable\n", def->mrd_desc, 0, 0 ); #else Debug( LDAP_DEBUG_ANY, "register_matching_rule: not usable %s\n", - desc, 0, 0 ); + def->mrd_desc, 0, 0 ); #endif return -1; } - if( associated != NULL ) { - amr = mr_find( associated ); + if( def->mrd_associated != NULL ) { + amr = mr_find( def->mrd_associated ); #if 0 /* ignore for now */ @@ -217,11 +205,11 @@ register_matching_rule( #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "register_matching_rule: could not locate associated " - "matching rule %s for %s\n", associated, desc, 0 ); + "matching rule %s for %s\n", def->mrd_associated, def->mrd_desc, 0 ); #else Debug( LDAP_DEBUG_ANY, "register_matching_rule: could not locate " "associated matching rule %s for %s\n", - associated, desc, 0 ); + def->mrd_associated, def->mrd_desc, 0 ); #endif return -1; @@ -230,23 +218,21 @@ register_matching_rule( } - mr = ldap_str2matchingrule( desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL); + mr = ldap_str2matchingrule( def->mrd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL); if ( !mr ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "register_matching_rule: %s before %s in %s.\n", - ldap_scherr2str(code), err, desc ); + ldap_scherr2str(code), err, def->mrd_desc ); #else Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s before %s in %s\n", - ldap_scherr2str(code), err, desc ); + ldap_scherr2str(code), err, def->mrd_desc ); #endif return( -1 ); } - code = mr_add( mr, usage, - convert, normalize, match, indexer, filter, amr, - &err ); + code = mr_add( mr, def, amr, &err ); ldap_memfree( mr ); @@ -254,10 +240,10 @@ register_matching_rule( #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "register_matching_rule: %s for %s in %s.\n", - scherr2str(code), err, desc ); + scherr2str(code), err, def->mrd_desc ); #else Debug( LDAP_DEBUG_ANY, "Error in register_matching_rule: %s for %s in %s\n", - scherr2str(code), err, desc ); + scherr2str(code), err, def->mrd_desc ); #endif return( -1 ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 0118eae768..02097a0352 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -599,25 +599,13 @@ LDAP_SLAPD_F (void) *module_resolve LDAP_P(( 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, - slap_mr_convert_func *convert, - slap_mr_normalize_func *normalize, - slap_mr_match_func *match, - slap_mr_indexer_func *indexer, - slap_mr_filter_func *filter, + slap_mrule_defs_rec *def, MatchingRule * associated, const char **err )); LDAP_SLAPD_F (void) mr_destroy LDAP_P(( void )); LDAP_SLAPD_F (int) register_matching_rule LDAP_P(( - const char * desc, - unsigned usage, - slap_mr_convert_func *convert, - slap_mr_normalize_func *normalize, - slap_mr_match_func *match, - slap_mr_indexer_func *indexer, - slap_mr_filter_func *filter, - const char *associated )); + slap_mrule_defs_rec *def )); LDAP_SLAPD_F (int) mr_schema_info( Entry *e ); LDAP_SLAPD_F (int) mru_schema_info( Entry *e ); @@ -954,33 +942,14 @@ LDAP_SLAPD_F (Syntax *) syn_find LDAP_P(( const char *synname )); LDAP_SLAPD_F (Syntax *) syn_find_desc LDAP_P(( const char *syndesc, int *slen )); -#ifdef SLAPD_BINARY_CONVERSION -LDAP_SLAPD_F (int) syn_add LDAP_P(( - LDAPSyntax *syn, - unsigned flags, - slap_syntax_validate_func *validate, - slap_syntax_transform_func *normalize, - slap_syntax_transform_func *pretty, - slap_syntax_transform_func *ber2str, - slap_syntax_transform_func *str2ber, - const char **err )); -#else LDAP_SLAPD_F (int) syn_add LDAP_P(( LDAPSyntax *syn, - unsigned flags, - slap_syntax_validate_func *validate, - slap_syntax_transform_func *normalize, - slap_syntax_transform_func *pretty, + slap_syntax_defs_rec *def, const char **err )); -#endif LDAP_SLAPD_F (void) syn_destroy LDAP_P(( void )); LDAP_SLAPD_F (int) register_syntax LDAP_P(( - const char *desc, - unsigned flags, - slap_syntax_validate_func *validate, - slap_syntax_transform_func *normalize, - slap_syntax_transform_func *pretty )); + slap_syntax_defs_rec *def )); LDAP_SLAPD_F (int) syn_schema_info( Entry *e ); diff --git a/servers/slapd/schema_init.c b/servers/slapd/schema_init.c index 5e41856b58..eef80beb30 100644 --- a/servers/slapd/schema_init.c +++ b/servers/slapd/schema_init.c @@ -4266,19 +4266,10 @@ bootParameterValidate( return LDAP_SUCCESS; } -static struct syntax_defs_rec { - char *sd_desc; #define X_BINARY "X-BINARY-TRANSFER-REQUIRED 'TRUE' " #define X_NOT_H_R "X-NOT-HUMAN-READABLE 'TRUE' " - int sd_flags; - slap_syntax_validate_func *sd_validate; - slap_syntax_transform_func *sd_normalize; - slap_syntax_transform_func *sd_pretty; -#ifdef SLAPD_BINARY_CONVERSION - slap_syntax_transform_func *sd_ber2str; - slap_syntax_transform_func *sd_str2ber; -#endif -} syntax_defs[] = { + +static slap_syntax_defs_rec syntax_defs[] = { {"( 1.3.6.1.4.1.1466.115.121.1.1 DESC 'ACI Item' " X_BINARY X_NOT_H_R ")", SLAP_SYNTAX_BINARY|SLAP_SYNTAX_BER, NULL, NULL, NULL}, @@ -4456,17 +4447,7 @@ static struct syntax_defs_rec { * 2.5.13.43 readerAndKeyIDMatch * 2.5.13.44 attributeIntegrityMatch */ -static struct mrule_defs_rec { - char * mrd_desc; - slap_mask_t mrd_usage; - slap_mr_convert_func * mrd_convert; - slap_mr_normalize_func * mrd_normalize; - slap_mr_match_func * mrd_match; - slap_mr_indexer_func * mrd_indexer; - slap_mr_filter_func * mrd_filter; - - char * mrd_associated; -} mrule_defs[] = { +static slap_mrule_defs_rec mrule_defs[] = { /* * EQUALITY matching rules must be listed after associated APPROX * matching rules. So, we list all APPROX matching rules first. @@ -4775,17 +4756,7 @@ slap_schema_init( void ) assert( schema_init_done == 0 ); for ( i=0; syntax_defs[i].sd_desc != NULL; i++ ) { - res = register_syntax( syntax_defs[i].sd_desc, - syntax_defs[i].sd_flags, - syntax_defs[i].sd_validate, - syntax_defs[i].sd_normalize, - syntax_defs[i].sd_pretty -#ifdef SLAPD_BINARY_CONVERSION - , - syntax_defs[i].sd_ber2str, - syntax_defs[i].sd_str2ber -#endif - ); + res = register_syntax( &syntax_defs[i] ); if ( res ) { fprintf( stderr, "slap_schema_init: Error registering syntax %s\n", @@ -4802,15 +4773,7 @@ slap_schema_init( void ) continue; } - res = register_matching_rule( - mrule_defs[i].mrd_desc, - mrule_defs[i].mrd_usage, - mrule_defs[i].mrd_convert, - mrule_defs[i].mrd_normalize, - mrule_defs[i].mrd_match, - mrule_defs[i].mrd_indexer, - mrule_defs[i].mrd_filter, - mrule_defs[i].mrd_associated ); + res = register_matching_rule( &mrule_defs[i] ); if ( res ) { fprintf( stderr, diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index fadc1a8431..8ad39c3272 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -307,6 +307,18 @@ typedef struct slap_syntax { #define slap_syntax_is_ber(s) slap_syntax_is_flag((s),SLAP_SYNTAX_BER) #define slap_syntax_is_hidden(s) slap_syntax_is_flag((s),SLAP_SYNTAX_HIDE) +typedef struct slap_syntax_defs_rec { + char *sd_desc; + int sd_flags; + slap_syntax_validate_func *sd_validate; + slap_syntax_transform_func *sd_normalize; + slap_syntax_transform_func *sd_pretty; +#ifdef SLAPD_BINARY_CONVERSION + slap_syntax_transform_func *sd_ber2str; + slap_syntax_transform_func *sd_str2ber; +#endif +} slap_syntax_defs_rec; + /* X -> Y Converter */ typedef int slap_mr_convert_func LDAP_P(( struct berval * in, @@ -414,6 +426,18 @@ typedef struct slap_matching_rule { #define smr_extensions smr_mrule.mr_extensions } MatchingRule; +typedef struct slap_mrule_defs_rec { + char * mrd_desc; + slap_mask_t mrd_usage; + slap_mr_convert_func * mrd_convert; + slap_mr_normalize_func * mrd_normalize; + slap_mr_match_func * mrd_match; + slap_mr_indexer_func * mrd_indexer; + slap_mr_filter_func * mrd_filter; + + char * mrd_associated; +} slap_mrule_defs_rec; + struct slap_backend_db; struct slap_entry; struct slap_attr; diff --git a/servers/slapd/syntax.c b/servers/slapd/syntax.c index 98f53d433b..21fef110ea 100644 --- a/servers/slapd/syntax.c +++ b/servers/slapd/syntax.c @@ -113,14 +113,7 @@ syn_insert( int syn_add( LDAPSyntax *syn, - unsigned flags, - slap_syntax_validate_func *validate, - slap_syntax_transform_func *normalize, - slap_syntax_transform_func *pretty, -#ifdef SLAPD_BINARY_CONVERSION - slap_syntax_transform_func *ber2str, - slap_syntax_transform_func *str2ber, -#endif + slap_syntax_defs_rec *def, const char **err ) { @@ -134,14 +127,14 @@ syn_add( ssyn->ssyn_next = NULL; ssyn->ssyn_oidlen = strlen(syn->syn_oid); - ssyn->ssyn_flags = flags; - ssyn->ssyn_validate = validate; - ssyn->ssyn_normalize = normalize; - ssyn->ssyn_pretty = pretty; + ssyn->ssyn_flags = def->sd_flags; + ssyn->ssyn_validate = def->sd_validate; + ssyn->ssyn_normalize = def->sd_normalize; + ssyn->ssyn_pretty = def->sd_pretty; #ifdef SLAPD_BINARY_CONVERSION - ssyn->ssyn_ber2str = ber2str; - ssyn->ssyn_str2ber = str2ber; + ssyn->ssyn_ber2str = def->sd_ber2str; + ssyn->ssyn_str2ber = def->sd_str2ber; #endif code = syn_insert(ssyn, err); @@ -150,31 +143,27 @@ syn_add( int register_syntax( - const char * desc, - unsigned flags, - slap_syntax_validate_func *validate, - slap_syntax_transform_func *normalize, - slap_syntax_transform_func *pretty ) + slap_syntax_defs_rec *def ) { LDAPSyntax *syn; int code; const char *err; - syn = ldap_str2syntax( desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL); + syn = ldap_str2syntax( def->sd_desc, &code, &err, LDAP_SCHEMA_ALLOW_ALL); if ( !syn ) { #ifdef NEW_LOGGING LDAP_LOG( CONFIG, ERR, "register_syntax: Error - %s before %s in %s.\n", - ldap_scherr2str(code), err, desc ); + ldap_scherr2str(code), err, def->sd_desc ); #else Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s before %s in %s\n", - ldap_scherr2str(code), err, desc ); + ldap_scherr2str(code), err, def->sd_desc ); #endif return( -1 ); } - code = syn_add( syn, flags, validate, normalize, pretty, &err ); + code = syn_add( syn, def, &err ); ldap_memfree( syn ); @@ -182,10 +171,10 @@ register_syntax( #ifdef NEW_LOGGING LDAP_LOG( CONFIG, ERR, "register_syntax: Error - %s %s in %s\n", - scherr2str(code), err, desc ); + scherr2str(code), err, def->sd_desc ); #else Debug( LDAP_DEBUG_ANY, "Error in register_syntax: %s %s in %s\n", - scherr2str(code), err, desc ); + scherr2str(code), err, def->sd_desc ); #endif return( -1 ); -- 2.39.5