X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Findex.c;h=2edd9a916355c6366e0a9c1598a331c964e62b0c;hb=2189c9e1a91519428cc9f8be08f238b5079a64ad;hp=786ccb388a1fa7b66420e58633ad7745253918b1;hpb=11802791040bd26db101ac5486dafa56bfd3877e;p=openldap diff --git a/servers/slapd/index.c b/servers/slapd/index.c index 786ccb388a..2edd9a9163 100644 --- a/servers/slapd/index.c +++ b/servers/slapd/index.c @@ -1,66 +1,91 @@ /* index.c - index utilities */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2006 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . */ #include "portable.h" #include +#include +#include #include "slap.h" -int -slap_index2prefix( int indextype ) +static slap_verbmasks idxstr[] = { + { BER_BVC("pres"), SLAP_INDEX_PRESENT }, + { BER_BVC("eq"), SLAP_INDEX_EQUALITY }, + { BER_BVC("approx"), SLAP_INDEX_APPROX }, + { BER_BVC("subinitial"), SLAP_INDEX_SUBSTR_INITIAL }, + { BER_BVC("subany"), SLAP_INDEX_SUBSTR_ANY }, + { BER_BVC("subfinal"), SLAP_INDEX_SUBSTR_FINAL }, + { BER_BVC("sub"), SLAP_INDEX_SUBSTR_DEFAULT }, + { BER_BVC("substr"), 0 }, + { BER_BVC("notags"), SLAP_INDEX_NOTAGS }, + { BER_BVC("nolang"), 0 }, /* backwards compat */ + { BER_BVC("nosubtypes"), SLAP_INDEX_NOSUBTYPES }, + { BER_BVNULL, 0 } +}; + + +int slap_str2index( const char *str, slap_mask_t *idx ) { - int prefix; + int i; - switch ( indextype ) { - case SLAP_INDEX_EQUALITY: - prefix = SLAP_INDEX_EQUALITY_PREFIX; - break; - case SLAP_INDEX_APPROX: - prefix = SLAP_INDEX_APPROX_PREFIX; - break; - case SLAP_INDEX_SUBSTR: - prefix = SLAP_INDEX_SUBSTR_PREFIX; - break; - default: - prefix = SLAP_INDEX_UNKNOWN_PREFIX; - break; - } + i = verb_to_mask( str, idxstr ); + if ( BER_BVISNULL(&idxstr[i].word) ) return LDAP_OTHER; + while ( !idxstr[i].mask ) i--; + *idx = idxstr[i].mask; - return( prefix ); + + return LDAP_SUCCESS; } -int slap_str2index( const char *str, slap_mask_t *idx ) +void slap_index2bvlen( slap_mask_t idx, struct berval *bv ) { - if ( strcasecmp( str, "pres" ) == 0 ) { - *idx = SLAP_INDEX_PRESENT; - } else if ( strcasecmp( str, "eq" ) == 0 ) { - *idx = SLAP_INDEX_EQUALITY; - } else if ( strcasecmp( str, "approx" ) == 0 ) { - *idx = SLAP_INDEX_APPROX; - } else if ( strcasecmp( str, "subinitial" ) == 0 ) { - *idx = SLAP_INDEX_SUBSTR_INITIAL; - } else if ( strcasecmp( str, "subany" ) == 0 ) { - *idx = SLAP_INDEX_SUBSTR_ANY; - } else if ( strcasecmp( str, "subfinal" ) == 0 ) { - *idx = SLAP_INDEX_SUBSTR_FINAL; - } else if ( strcasecmp( str, "substr" ) == 0 || - strcasecmp( str, "sub" ) == 0 ) - { - *idx = SLAP_INDEX_SUBSTR_DEFAULT; - } else if ( strcasecmp( str, "nolang" ) == 0 ) { - *idx = SLAP_INDEX_NOLANG; - } else if ( strcasecmp( str, "nosubtypes" ) == 0 ) { - *idx = SLAP_INDEX_NOSUBTYPES; - } else if ( strcasecmp( str, "autosubtypes" ) == 0 ) { - *idx = SLAP_INDEX_AUTO_SUBTYPES; - } else { - return LDAP_OTHER; + int i; + + bv->bv_len = 0; + + for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) { + if ( !idxstr[i].mask ) continue; + if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) { + if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) && + ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask)) + continue; + if ( bv->bv_len ) bv->bv_len++; + bv->bv_len += idxstr[i].word.bv_len; + } } +} - return LDAP_SUCCESS; +/* caller must provide buffer space, after calling index2bvlen */ +void slap_index2bv( slap_mask_t idx, struct berval *bv ) +{ + int i; + char *ptr; + + if ( !bv->bv_len ) return; + + ptr = bv->bv_val; + for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) { + if ( !idxstr[i].mask ) continue; + if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) { + if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) && + ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask)) + continue; + if ( ptr != bv->bv_val ) *ptr++ = ','; + ptr = lutil_strcopy( ptr, idxstr[i].word.bv_val ); + } + } }