From 028c176c85a2ac77a05a8ff428ee90a77cb0ecd8 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Wed, 23 Feb 2011 03:44:54 +0000 Subject: [PATCH] ITS#6815 delimited verbstring parsing --- servers/slapd/config.c | 60 ++++++++++++++++++++++++++++++++++++++ servers/slapd/proto-slap.h | 4 +++ 2 files changed, 64 insertions(+) diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 08beabde38..199955871a 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -935,6 +935,66 @@ mask_to_verbs(slap_verbmasks *v, slap_mask_t m, BerVarray *bva) { return rc; } +/* Return the verbs as a single string, separated by delim */ +int +mask_to_verbstring(slap_verbmasks *v, slap_mask_t m0, char delim, struct berval *bv) +{ + int i, rc = 1; + + BER_BVZERO( bv ); + if (m0) { + slap_mask_t m = m0; + char *ptr; + for (i=0; !BER_BVISNULL(&v[i].word); i++) { + if (!v[i].mask) continue; + if (( m & v[i].mask ) == v[i].mask ) { + bv->bv_len += v[i].word.bv_len + 1; + rc = 0; + m ^= v[i].mask; + if ( !m ) break; + } + } + bv->bv_val = ch_malloc(bv->bv_len); + bv->bv_len--; + ptr = bv->bv_val; + m = m0; + for (i=0; !BER_BVISNULL(&v[i].word); i++) { + if (!v[i].mask) continue; + if (( m & v[i].mask ) == v[i].mask ) { + ptr = lutil_strcopy(ptr, v[i].word.bv_val); + *ptr++ = delim; + m ^= v[i].mask; + if ( !m ) break; + } + } + ptr[-1] = '\0'; + } + return rc; +} + +/* Parse a verbstring */ +int +verbstring_to_mask(slap_verbmasks *v, char *str, char delim, slap_mask_t *m) { + int j; + char *d; + struct berval bv; + + do { + bv.bv_val = str; + d = strchr( str, delim ); + if ( d ) + bv.bv_len = d - str; + else + bv.bv_len = strlen( str ); + j = bverb_to_mask( &bv, v ); + if(BER_BVISNULL(&v[j].word)) return 1; + while (!v[j].mask) j--; + *m |= v[j].mask; + str += bv.bv_len + 1; + } while ( d ); + return(0); +} + int slap_verbmasks_init( slap_verbmasks **vp, slap_verbmasks *v ) { diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index a4846b97d4..d28bdc23e1 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -720,6 +720,10 @@ LDAP_SLAPD_F (int) verbs_to_mask LDAP_P(( int argc, char *argv[], slap_verbmasks *v, slap_mask_t *m )); LDAP_SLAPD_F (int) mask_to_verbs LDAP_P(( slap_verbmasks *v, slap_mask_t m, BerVarray *bva )); +LDAP_SLAPD_F (int) mask_to_verbstring LDAP_P(( + slap_verbmasks *v, slap_mask_t m, char delim, struct berval *bv )); +LDAP_SLAPD_F (int) verbstring_to_mask LDAP_P(( + slap_verbmasks *v, char *str, char delim, slap_mask_t *m )); LDAP_SLAPD_F (int) enum_to_verb LDAP_P(( slap_verbmasks *v, slap_mask_t m, struct berval *bv )); LDAP_SLAPD_F (int) slap_verbmasks_init LDAP_P(( slap_verbmasks **vp, slap_verbmasks *v )); -- 2.39.5