1 /* index.c - index utilities */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
24 static slap_verbmasks idxstr[] = {
25 { BER_BVC("pres"), SLAP_INDEX_PRESENT },
26 { BER_BVC("eq"), SLAP_INDEX_EQUALITY },
27 { BER_BVC("approx"), SLAP_INDEX_APPROX },
28 { BER_BVC("subinitial"), SLAP_INDEX_SUBSTR_INITIAL },
29 { BER_BVC("subany"), SLAP_INDEX_SUBSTR_ANY },
30 { BER_BVC("subfinal"), SLAP_INDEX_SUBSTR_FINAL },
31 { BER_BVC("sub"), SLAP_INDEX_SUBSTR_DEFAULT },
32 { BER_BVC("substr"), 0 },
33 { BER_BVC("notags"), SLAP_INDEX_NOTAGS },
34 { BER_BVC("nolang"), 0 }, /* backwards compat */
35 { BER_BVC("nosubtypes"), SLAP_INDEX_NOSUBTYPES },
40 int slap_str2index( const char *str, slap_mask_t *idx )
44 i = verb_to_mask( str, idxstr );
45 if ( BER_BVISNULL(&idxstr[i].word) ) return LDAP_OTHER;
46 while ( !idxstr[i].mask ) i--;
47 *idx = idxstr[i].mask;
53 void slap_index2bvlen( slap_mask_t idx, struct berval *bv )
59 for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
60 if ( !idxstr[i].mask ) continue;
61 if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
62 if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
63 ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
65 if ( bv->bv_len ) bv->bv_len++;
66 bv->bv_len += idxstr[i].word.bv_len;
71 /* caller must provide buffer space, after calling index2bvlen */
72 void slap_index2bv( slap_mask_t idx, struct berval *bv )
77 if ( !bv->bv_len ) return;
80 for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
81 if ( !idxstr[i].mask ) continue;
82 if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
83 if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
84 ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
86 if ( ptr != bv->bv_val ) *ptr++ = ',';
87 ptr = lutil_strcopy( ptr, idxstr[i].word.bv_val );