From: Howard Chu Date: Tue, 18 Aug 2009 02:47:28 +0000 (+0000) Subject: For ITS#6152 add slapd_str2scope(), slapd_scope2bv() X-Git-Tag: ACLCHECK_0~303 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=7442e58dc202cce93f581caec112419a63d32e34;p=openldap For ITS#6152 add slapd_str2scope(), slapd_scope2bv() --- diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index e97fc5e2c0..e14431cdfc 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -1778,6 +1778,8 @@ LDAP_SLAPD_F (Filter *) str2filter_x LDAP_P(( Operation *op, const char *str )); * syncrepl.c */ +LDAP_SLAPD_F (int) slapd_str2scope LDAP_P(( char *str )); +LDAP_SLAPD_F (struct berval *) slapd_scope2bv LDAP_P(( int scope )); LDAP_SLAPD_F (int) syncrepl_add_glue LDAP_P(( Operation*, Entry* )); LDAP_SLAPD_F (void) syncrepl_diff_entry LDAP_P(( diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index d2d2dbcb41..9b8c546b12 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -3830,6 +3830,29 @@ static slap_verbmasks datamodes[] = { { BER_BVNULL, 0 } }; +int +slapd_str2scope( char *str ) +{ + int i; + for ( i = 0; !BER_BVISNULL(&scopes[i].key); i++ ) { + if (!strcasecmp( str, scopes[i].key.bv_val ) ) { + return scopes[i].val; + } + } + return -1; +} + +struct berval * +slapd_scope2bv( int scope ) +{ + int i; + for (i=0; !BER_BVISNULL(&scopes[i].key);i++) { + if ( scope == scopes[i].val ) + return &scopes[i].key; + } + return NULL; +} + static int parse_syncrepl_retry( ConfigArgs *c, @@ -4040,19 +4063,15 @@ parse_syncrepl_line( { int j; val = c->argv[ i ] + STRLENOF( SCOPESTR "=" ); - for ( j = 0; !BER_BVISNULL(&scopes[j].key); j++ ) { - if (!strcasecmp( val, scopes[j].key.bv_val ) ) { - si->si_scope = scopes[j].val; - break; - } - } - if ( BER_BVISNULL(&scopes[j].key) ) { + j = slapd_str2scope( val ); + if ( j < 0 ) { snprintf( c->cr_msg, sizeof( c->cr_msg ), "Error: parse_syncrepl_line: " "unknown scope \"%s\"", val); Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg, 0 ); return -1; } + si->si_scope = j; si->si_got |= GOT_SCOPE; } else if ( !strncasecmp( c->argv[ i ], ATTRSONLYSTR, STRLENOF( ATTRSONLYSTR ) ) ) @@ -4456,7 +4475,7 @@ add_syncrepl( static void syncrepl_unparse( syncinfo_t *si, struct berval *bv ) { - struct berval bc, uri; + struct berval bc, uri, *bs; char buf[BUFSIZ*2], *ptr; ber_len_t len; int i; @@ -4510,13 +4529,11 @@ syncrepl_unparse( syncinfo_t *si, struct berval *bv ) ptr = lutil_strcopy( ptr, si->si_logbase.bv_val ); *ptr++ = '"'; } - for (i=0; !BER_BVISNULL(&scopes[i].key);i++) { - if ( si->si_scope == scopes[i].val ) { - if ( WHATSLEFT <= STRLENOF( " " SCOPESTR "=" ) + scopes[i].key.bv_len ) return; - ptr = lutil_strcopy( ptr, " " SCOPESTR "=" ); - ptr = lutil_strcopy( ptr, scopes[i].key.bv_val ); - break; - } + bs = slapd_scope2bv( si->si_scope ); + if ( bs ) { + if ( WHATSLEFT <= STRLENOF( " " SCOPESTR "=" ) + bs->bv_len ) return; + ptr = lutil_strcopy( ptr, " " SCOPESTR "=" ); + ptr = lutil_strcopy( ptr, bs->bv_val ); } if ( si->si_attrsonly ) { if ( WHATSLEFT <= STRLENOF( " " ATTRSONLYSTR "=\"" "\"" ) ) return;