1 /* index.c - index utilities */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2010 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>
25 static slap_verbmasks idxstr[] = {
26 { BER_BVC("pres"), SLAP_INDEX_PRESENT },
27 { BER_BVC("eq"), SLAP_INDEX_EQUALITY },
28 { BER_BVC("approx"), SLAP_INDEX_APPROX },
29 { BER_BVC("subinitial"), SLAP_INDEX_SUBSTR_INITIAL },
30 { BER_BVC("subany"), SLAP_INDEX_SUBSTR_ANY },
31 { BER_BVC("subfinal"), SLAP_INDEX_SUBSTR_FINAL },
32 { BER_BVC("sub"), SLAP_INDEX_SUBSTR_DEFAULT },
33 { BER_BVC("substr"), 0 },
34 { BER_BVC("notags"), SLAP_INDEX_NOTAGS },
35 { BER_BVC("nolang"), 0 }, /* backwards compat */
36 { BER_BVC("nosubtypes"), SLAP_INDEX_NOSUBTYPES },
41 int slap_str2index( const char *str, slap_mask_t *idx )
45 i = verb_to_mask( str, idxstr );
46 if ( BER_BVISNULL(&idxstr[i].word) ) return LDAP_OTHER;
47 while ( !idxstr[i].mask ) i--;
48 *idx = idxstr[i].mask;
54 void slap_index2bvlen( slap_mask_t idx, struct berval *bv )
60 for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
61 if ( !idxstr[i].mask ) continue;
62 if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
63 if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
64 ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
66 if ( bv->bv_len ) bv->bv_len++;
67 bv->bv_len += idxstr[i].word.bv_len;
72 /* caller must provide buffer space, after calling index2bvlen */
73 void slap_index2bv( slap_mask_t idx, struct berval *bv )
78 if ( !bv->bv_len ) return;
81 for ( i=0; !BER_BVISNULL( &idxstr[i].word ); i++ ) {
82 if ( !idxstr[i].mask ) continue;
83 if ( IS_SLAP_INDEX( idx, idxstr[i].mask )) {
84 if ( (idxstr[i].mask & SLAP_INDEX_SUBSTR) &&
85 ((idx & SLAP_INDEX_SUBSTR_DEFAULT) != idxstr[i].mask))
87 if ( ptr != bv->bv_val ) *ptr++ = ',';
88 ptr = lutil_strcopy( ptr, idxstr[i].word.bv_val );