Import latest changes from devel include substrings indexing support

This commit is contained in:
Kurt Zeilenga 2000-08-23 01:15:32 +00:00
parent b0fd87270f
commit 6a56c8b4bb
15 changed files with 480 additions and 2080 deletions

File diff suppressed because it is too large Load diff

View file

@ -1,110 +0,0 @@
$OpenLDAP$
This document is being replaced with:
http://www.openldap.org/devel/programming.html
and
http://www.openldap.org/devel/contributing.html
However, some of the info here is still useful.
Coding guide lines and and hints for OpenLDAP developers.
=========================================================
Please add to this file when new points come up.
C source
--------
OpenLDAP requires many Standard C features to *build*. This
includes functional prototypes and offsetof macro. It is
possible to *build* OpenLDAP with a number of C translators
which are not fully compliant with Standard C.
OpenLDAP supports compiling and linking *with* applications
with most C compilers and libraries. The installed headers
are designed to provide K&R C compatiable function declarations
on non-standard compilers. In cases where the compiler does
not define __STDC__ but requires prototypes (ie: MSVC), the
application should define LDAP_NEEDS_PROTOTYPES. In cases
where the compiler does define __STDC__ but does not support
prototypes, the application should define LDAP_NO_PROTOTYPES.
.c files in the OpenLDAP source tree MUST #include "portable.h" before
any other include file, even system includes. portable.h may control
aspects of system includes, such as whether or not thread-safe library
functions are used. (Separate applications can't use portable.h, since
it is not installed. They can use ldap_features.h, though.)
.h files that are NOT INSTALLED may depend on features from portable.h.
.h files that *are* installed (from include/) should not depend on it.
Avoid unnecessary changes, like reindenting code, even if that leaves
the code a little ugly. Often switching your editors tab stops to
4 or 8 may make code easier to read. Unnecessary changes make it
harder to maintain and merge different CVS branches of the source.
Please follow the style of surrounding code.
Use feature-specific #if tests (like #ifdef HAVE_LWP) which configure
can figure out, not system-specific test (like #ifdef __SunOS_5_6).
When available, use include files from ldap/include/ac/ to get system
features or functions. The <ac/xxx.h> files try to fix crippled system
includes, and to hide #ifdef messes that portable programs need in order
to find a feature. Note that a file <ac/xxx.h> is not necessarily
designed to be equivalent to standard C's <xxx.h> file.
Nonstatic function and variable definitions in .c files should be
preceded by their declarations in .h files. Avoid implicit function
declarations. External declarations with should be avoided. In
.c files, include the appropriate .h file to obtain the declaration.
If the declaration is not available in any system header, add it
to the most appropriate ac/xxx.h header. Do NOT add extern
declarations to .c files.
When a function returns non-void, it should return a meaningful value.
Avoid implicit int.
It is recommended that ldap_cdef.h macros LDAP_F and LDAP_P be used
even for non-installed headers. See lber.h and ldap.h for examples.
CVS updating
------------
<URL:http://www.openldap.org/software/repo.html> describes how to check out
-stable. To get the -devel (HEAD) branch, omit `-r OPENLDAP_STABLE'.
You can use 'cvs status -v README' to get a list available CVS tags.
Core members should subscribe to the -core mailing list. This
list is for private discussions between core team members. The
openldap-devel@openldap.org mailing list is the primary developer
forum for both technical disscusions and coordinating efforts.
Please test patches before committing. This should include compiling
and linking the system AND running the test suite.
In general, a patch/bugfix should be applied to -devel and tested.
When the patch is considered stable, then it can be merged into -stable.
Same goes for other release engineering branches (like
OPENLDAP_REL_ENG_1_1). (-stable is rel eng 1.0).
Specific procjects may get their own branches, to be merged later.
Log messages: Just describe the change and reason. CVS adds your name,
date, etc.
Various tips and hints
----------------------
How to correct a CVS log message:
Commit the unchanged files again with the `-f' flag and with a log
message stating how the previous log was in error:
cvs commit -f cldap.c os-ip.c
Preferably, prepend a line something like this to the message:
"Forced commit to correct previous log, files were not changed."
Modify ldapconfig.h instead of ldapconfig.h.edit. Then `cvs commit'
from the include directory won't accidentally commit your private
ldapconfig.h.edit.

View file

@ -8,6 +8,7 @@
#include "portable.h"
#ifdef HAVE_SIGACTION
#include <ac/string.h>
#include <ac/signal.h>
lutil_sig_t

View file

@ -23,7 +23,7 @@ typedef struct ldbm_attrinfo {
#else
char *ai_desc;
#endif
slap_index ai_indexmask; /* how the attr is indexed */
slap_mask_t ai_indexmask; /* how the attr is indexed */
} AttrInfo;
static int
@ -64,7 +64,7 @@ attr_mask(
#else
const char *desc,
#endif
slap_index *indexmask )
slap_mask_t *indexmask )
{
AttrInfo *a;
@ -84,7 +84,7 @@ attr_index_config(
{
int rc;
int i;
slap_index mask;
slap_mask_t mask;
char **attrs;
char **indexes = NULL;
@ -115,7 +115,7 @@ attr_index_config(
mask = 0;
for ( i = 0; indexes[i] != NULL; i++ ) {
slap_index index;
slap_mask_t index;
rc = slap_str2index( indexes[i], &index );
if( rc != LDAP_SUCCESS ) {

View file

@ -107,7 +107,7 @@ struct ldbminfo {
ldap_pvt_thread_mutex_t li_root_mutex;
ldap_pvt_thread_mutex_t li_add_mutex;
int li_mode;
slap_index li_defaultmask;
slap_mask_t li_defaultmask;
char *li_directory;
Cache li_cache;
Avlnode *li_attrs;

View file

@ -24,7 +24,7 @@ static ID_BLOCK *approx_candidates(
Backend *be, AttributeAssertion *ava );
static ID_BLOCK *substring_candidates(
Backend *be,
Filter *f );
SubstringsAssertion *sub );
static ID_BLOCK *list_candidates(
Backend *be,
Filter *flist,
@ -69,7 +69,7 @@ filter_candidates(
case LDAP_FILTER_SUBSTRINGS:
Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 );
result = substring_candidates( be, f );
result = substring_candidates( be, f->f_sub );
break;
case LDAP_FILTER_GE:
@ -117,7 +117,7 @@ presence_candidates(
DBCache *db;
int rc;
char *dbname;
slap_index mask;
slap_mask_t mask;
struct berval *prefix;
Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
@ -128,11 +128,17 @@ presence_candidates(
&dbname, &mask, &prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"<= presence_candidates: index_param failed (%d)\n",
rc, 0, 0 );
return idl;
}
if( dbname == NULL ) {
/* not indexed */
Debug( LDAP_DEBUG_TRACE,
"<= presense_candidates: not indexed\n",
0, 0, 0 );
ber_bvfree( prefix );
return idl;
}
@ -184,7 +190,7 @@ equality_candidates(
int i;
int rc;
char *dbname;
slap_index mask;
slap_mask_t mask;
struct berval *prefix;
struct berval **keys = NULL;
MatchingRule *mr;
@ -197,11 +203,17 @@ equality_candidates(
&dbname, &mask, &prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"<= equality_candidates: index_param failed (%d)\n",
rc, 0, 0 );
return idl;
}
if( dbname == NULL ) {
/* not indexed */
Debug( LDAP_DEBUG_TRACE,
"<= equality_candidates: not indexed\n",
0, 0, 0 );
ber_bvfree( prefix );
return idl;
}
@ -209,7 +221,6 @@ equality_candidates(
mr = ava->aa_desc->ad_type->sat_equality;
if( !mr ) {
ber_bvfree( prefix );
/* return LDAP_INAPPROPRIATE_MATCHING; */
return idl;
}
@ -220,6 +231,7 @@ equality_candidates(
rc = (mr->smr_filter)(
LDAP_FILTER_EQUALITY,
mask,
ava->aa_desc->ad_type->sat_syntax,
mr,
prefix,
@ -229,6 +241,16 @@ equality_candidates(
ber_bvfree( prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<= equality_candidates: (%s%s) MR filter failed (%d)\n",
dbname, LDBM_SUFFIX, rc );
return idl;
}
if( keys == NULL ) {
Debug( LDAP_DEBUG_TRACE,
"<= equality_candidates: no keys (%s%s)\n",
dbname, LDBM_SUFFIX, 0 );
return idl;
}
@ -294,7 +316,7 @@ approx_candidates(
int i;
int rc;
char *dbname;
slap_index mask;
slap_mask_t mask;
struct berval *prefix;
struct berval **keys = NULL;
MatchingRule *mr;
@ -303,28 +325,33 @@ approx_candidates(
idl = idl_allids( be );
rc = index_param( be, ava->aa_desc, LDAP_FILTER_EQUALITY,
rc = index_param( be, ava->aa_desc, LDAP_FILTER_APPROX,
&dbname, &mask, &prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"<= approx_candidates: index_param failed (%d)\n",
rc, 0, 0 );
return idl;
}
if( dbname == NULL ) {
/* not indexed */
Debug( LDAP_DEBUG_ANY,
"<= approx_candidates: not indexed\n",
0, 0, 0 );
ber_bvfree( prefix );
return idl;
}
mr = ava->aa_desc->ad_type->sat_approx;
if( mr == NULL ) {
if( !mr ) {
/* no approx matching rule, try equality matching rule */
mr = ava->aa_desc->ad_type->sat_equality;
}
if( !mr ) {
ber_bvfree( prefix );
/* return LDAP_INAPPROPRIATE_MATCHING; */
return idl;
}
@ -334,7 +361,8 @@ approx_candidates(
}
rc = (mr->smr_filter)(
LDAP_FILTER_EQUALITY,
LDAP_FILTER_APPROX,
mask,
ava->aa_desc->ad_type->sat_syntax,
mr,
prefix,
@ -344,6 +372,16 @@ approx_candidates(
ber_bvfree( prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<= approx_candidates: (%s%s) MR filter failed (%d)\n",
dbname, LDBM_SUFFIX, rc );
return idl;
}
if( keys == NULL ) {
Debug( LDAP_DEBUG_TRACE,
"<= approx_candidates: no keys (%s%s)\n",
dbname, LDBM_SUFFIX, 0 );
return idl;
}
@ -438,16 +476,122 @@ list_candidates(
static ID_BLOCK *
substring_candidates(
Backend *be,
Filter *f
SubstringsAssertion *sub
)
{
ID_BLOCK *idl;
DBCache *db;
int i;
int rc;
char *dbname;
slap_mask_t mask;
struct berval *prefix;
struct berval **keys = NULL;
MatchingRule *mr;
Debug( LDAP_DEBUG_TRACE, "=> substring_candidates\n", 0, 0, 0 );
Debug( LDAP_DEBUG_TRACE, "=> substrings_candidates\n", 0, 0, 0 );
idl = idl_allids( be );
Debug( LDAP_DEBUG_TRACE, "<= substring_candidates %ld\n",
rc = index_param( be, sub->sa_desc, LDAP_FILTER_SUBSTRINGS,
&dbname, &mask, &prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"<= substrings_candidates: index_param failed (%d)\n",
rc, 0, 0 );
return idl;
}
if( dbname == NULL ) {
/* not indexed */
Debug( LDAP_DEBUG_ANY,
"<= substrings_candidates: not indexed\n",
0, 0, 0 );
ber_bvfree( prefix );
return idl;
}
mr = sub->sa_desc->ad_type->sat_substr;
if( !mr ) {
ber_bvfree( prefix );
return idl;
}
if( !mr->smr_filter ) {
ber_bvfree( prefix );
return idl;
}
rc = (mr->smr_filter)(
LDAP_FILTER_SUBSTRINGS,
mask,
sub->sa_desc->ad_type->sat_syntax,
mr,
prefix,
sub,
&keys );
ber_bvfree( prefix );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<= substrings_candidates: (%s%s) MR filter failed (%d)\n",
dbname, LDBM_SUFFIX, rc );
return idl;
}
if( keys == NULL ) {
Debug( LDAP_DEBUG_TRACE,
"<= substrings_candidates: (0x%04lx) no keys (%s%s)\n",
mask, dbname, LDBM_SUFFIX );
return idl;
}
db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_READER );
if ( db == NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= substrings_candidates db open failed (%s%s)\n",
dbname, LDBM_SUFFIX, 0 );
return idl;
}
for ( i= 0; keys[i] != NULL; i++ ) {
ID_BLOCK *save;
ID_BLOCK *tmp;
rc = key_read( be, db, keys[i], &tmp );
if( rc != LDAP_SUCCESS ) {
idl_free( idl );
idl = NULL;
Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates key read failed (%d)\n",
rc, 0, 0 );
break;
}
if( tmp == NULL ) {
idl_free( idl );
idl = NULL;
Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates NULL\n",
0, 0, 0 );
break;
}
save = idl;
idl = idl_intersection( be, idl, tmp );
idl_free( save );
if( idl == NULL ) break;
}
ber_bvecfree( keys );
ldbm_cache_close( be, db );
Debug( LDAP_DEBUG_TRACE, "<= substrings_candidates %ld\n",
idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}

View file

@ -22,7 +22,7 @@ static index_mask(
char **atname )
{
AttributeType *at;
slap_index mask = 0;
slap_mask_t mask = 0;
/* we do support indexing of binary attributes */
if( slap_ad_is_binary( desc ) ) return 0;
@ -77,10 +77,10 @@ int index_param(
AttributeDescription *desc,
int ftype,
char **dbnamep,
slap_index *maskp,
slap_mask_t *maskp,
struct berval **prefixp )
{
slap_index mask;
slap_mask_t mask;
char *dbname;
char *atname;
@ -135,7 +135,7 @@ static int indexer(
struct berval **vals,
ID id,
int op,
slap_index mask )
slap_mask_t mask )
{
int rc, i;
const char *text;
@ -169,6 +169,7 @@ static int indexer(
if( IS_SLAP_INDEX( mask, SLAP_INDEX_EQUALITY ) ) {
rc = ad->ad_type->sat_equality->smr_indexer(
LDAP_FILTER_EQUALITY,
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_equality,
@ -184,6 +185,7 @@ static int indexer(
if( IS_SLAP_INDEX( mask, SLAP_INDEX_APPROX ) ) {
rc = ad->ad_type->sat_approx->smr_indexer(
LDAP_FILTER_APPROX,
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_approx,
@ -199,6 +201,7 @@ static int indexer(
if( IS_SLAP_INDEX( mask, SLAP_INDEX_SUBSTR ) ) {
rc = ad->ad_type->sat_substr->smr_indexer(
LDAP_FILTER_SUBSTRINGS,
mask,
ad->ad_type->sat_syntax,
ad->ad_type->sat_substr,
@ -225,10 +228,10 @@ static int index_at_values(
ID id,
int op,
char ** dbnamep,
slap_index *maskp )
slap_mask_t *maskp )
{
slap_index mask;
slap_index tmpmask = 0;
slap_mask_t mask;
slap_mask_t tmpmask = 0;
int lindex = 0;
if( type->sat_sup ) {
@ -291,7 +294,7 @@ int index_values(
int op )
{
char *dbname = NULL;
slap_index mask;
slap_mask_t mask;
if( slap_ad_is_binary( desc ) ) {
/* binary attributes have no index capabilities */

View file

@ -35,7 +35,7 @@ Entry *deref_internal_r LDAP_P((
void attr_mask LDAP_P(( struct ldbminfo *li,
const char *desc,
slap_index *indexmask ));
slap_mask_t *indexmask ));
int attr_index_config LDAP_P(( struct ldbminfo *li,
const char *fname, int lineno,
@ -139,7 +139,7 @@ index_param LDAP_P((
AttributeDescription *desc,
int ftype,
char **dbname,
slap_index *mask,
slap_mask_t *mask,
struct berval **prefix ));
extern int

View file

@ -34,7 +34,7 @@ slap_index2prefix( int indextype )
return( prefix );
}
int slap_str2index( const char *str, slap_index *idx )
int slap_str2index( const char *str, slap_mask_t *idx )
{
if ( strcasecmp( str, "pres" ) == 0 ) {
*idx = SLAP_INDEX_PRESENT;

View file

@ -252,7 +252,7 @@ LDAP_SLAPD_F (int) read_config LDAP_P(( const char *fname ));
* index.c
*/
LDAP_SLAPD_F (int) slap_index2prefix LDAP_P(( int indextype ));
LDAP_SLAPD_F (int) slap_str2index LDAP_P(( const char *str, slap_index *idx ));
LDAP_SLAPD_F (int) slap_str2index LDAP_P(( const char *str, slap_mask_t *idx ));
/*
* connection.c

View file

@ -546,7 +546,7 @@ objectclass ( 2.16.840.1.113719.2.142.6.1.1 NAME 'LDAPsubEntry'
#
# OpenLDAProotDSE
# likely to change!
objectclass ( 1.3.6.1.4.1.4203.666.3.2
objectclass ( 1.3.6.1.4.1.4203.1.4.1
NAME ( 'OpenLDAProotDSE' 'LDAProotDSE' )
DESC 'OpenLDAP Root DSE object'
SUP top STRUCTURAL MAY cn )

View file

@ -8,23 +8,23 @@
# inetorgperson.schema
#
objectClass ( 1.3.6.1.4.1.4203.666.3.3 NAME 'OpenLDAPorg'
objectClass ( 1.3.6.1.4.1.4203.1.4.3 NAME 'OpenLDAPorg'
DESC 'OpenLDAP Organizational Object'
SUP organization
MAY ( authPassword $ buildingName $ displayName $ labeledURI ) )
objectClass ( 1.3.6.1.4.1.4203.666.3.4 NAME 'OpenLDAPou'
objectClass ( 1.3.6.1.4.1.4203.1.4.4 NAME 'OpenLDAPou'
DESC 'OpenLDAP Organizational Unit Object'
SUP organizationalUnit
MAY ( authPassword $ buildingName $ displayName $ labeledURI $ o ) )
objectClass ( 1.3.6.1.4.1.4203.666.3.5 NAME 'OpenLDAPperson'
objectClass ( 1.3.6.1.4.1.4203.1.4.5 NAME 'OpenLDAPperson'
DESC 'OpenLDAP Person'
SUP ( pilotPerson $ inetOrgPerson )
MUST ( uid $ cn )
MAY ( authPassword $ givenName $ labeledURI $ o ) )
objectClass ( 1.3.6.1.4.1.4203.666.3.6 NAME 'OpenLDAPdisplayableObject'
objectClass ( 1.3.6.1.4.1.4203.1.4.6 NAME 'OpenLDAPdisplayableObject'
DESC 'OpenLDAP Displayable Object'
MAY displayName AUXILIARY )

View file

@ -88,7 +88,7 @@
static int
octetStringMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -108,7 +108,8 @@ octetStringMatch(
/* Index generation function */
int octetStringIndexer(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -161,7 +162,8 @@ int octetStringIndexer(
/* Index generation function */
int octetStringFilter(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -254,7 +256,7 @@ dnNormalize(
static int
dnMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -329,7 +331,7 @@ booleanValidate(
static int
booleanMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -628,7 +630,7 @@ IA5StringNormalize(
static int
caseExactIA5Match(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -649,7 +651,7 @@ caseExactIA5Match(
static int
caseExactIA5SubstringsMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -773,7 +775,8 @@ done:
/* Index generation function */
int caseExactIA5Indexer(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -826,7 +829,8 @@ int caseExactIA5Indexer(
/* Index generation function */
int caseExactIA5Filter(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -868,16 +872,18 @@ int caseExactIA5Filter(
*keysp = keys;
return LDAP_SUCCESS;
}
/* Substrings Index generation function */
int caseExactIA5SubstringsIndexer(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
struct berval **values,
struct berval ***keysp )
{
int i, nkeys, types;
ber_len_t i, nkeys;
size_t slen, mlen;
struct berval **keys;
lutil_MD5_CTX MD5context;
@ -886,11 +892,6 @@ int caseExactIA5SubstringsIndexer(
digest.bv_val = MD5digest;
digest.bv_len = sizeof(MD5digest);
types = 0;
if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
/* no SUBSTR_ANY indexing */
nkeys=0;
for( i=0; values[i] != NULL; i++ ) {
/* count number of indices to generate */
@ -898,10 +899,28 @@ int caseExactIA5SubstringsIndexer(
continue;
}
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
}
}
if( flags & SLAP_INDEX_SUBSTR_ANY ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
}
}
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
}
}
}
assert( i > 0 );
@ -912,7 +931,6 @@ int caseExactIA5SubstringsIndexer(
return LDAP_SUCCESS;
}
nkeys *= types; /* We need to generate keys for each type */
keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
slen = strlen( syntax->ssyn_oid );
@ -920,20 +938,47 @@ int caseExactIA5SubstringsIndexer(
nkeys=0;
for( i=0; values[i] != NULL; i++ ) {
int j,max;
ber_len_t j,max;
struct berval *value;
value = values[i];
if( value->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
{
char pre = SLAP_INDEX_SUBSTR_PREFIX;
max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
for( j=0; j<max; j++ ) {
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
lutil_MD5Update( &MD5context,
prefix->bv_val, prefix->bv_len );
}
lutil_MD5Update( &MD5context,
&pre, sizeof( pre ) );
lutil_MD5Update( &MD5context,
syntax->ssyn_oid, slen );
lutil_MD5Update( &MD5context,
mr->smr_oid, mlen );
lutil_MD5Update( &MD5context,
&value->bv_val[j],
SLAP_INDEX_SUBSTR_MAXLEN );
lutil_MD5Final( MD5digest, &MD5context );
keys[nkeys++] = ber_bvdup( &digest );
}
}
max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
value = values[i];
for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
char pre;
if( flags & SLAP_MR_SUBSTR_INITIAL ) {
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
@ -953,7 +998,7 @@ int caseExactIA5SubstringsIndexer(
keys[nkeys++] = ber_bvdup( &digest );
}
if( flags & SLAP_MR_SUBSTR_FINAL ) {
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
@ -976,13 +1021,20 @@ int caseExactIA5SubstringsIndexer(
}
}
keys[nkeys] = NULL;
*keysp = keys;
if( nkeys > 0 ) {
keys[nkeys] = NULL;
*keysp = keys;
} else {
ch_free( keys );
*keysp = NULL;
}
return LDAP_SUCCESS;
}
int caseExactIA5SubstringsFilter(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -991,7 +1043,7 @@ int caseExactIA5SubstringsFilter(
{
SubstringsAssertion *sa = assertValue;
char pre;
int nkeys = 0;
ber_len_t nkeys = 0;
size_t slen, mlen, klen;
struct berval **keys;
lutil_MD5_CTX MD5context;
@ -999,12 +1051,24 @@ int caseExactIA5SubstringsFilter(
struct berval *value;
struct berval digest;
if( sa->sa_initial != NULL &&
if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
nkeys++;
}
if( sa->sa_final != NULL &&
if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
ber_len_t i;
for( i=0; sa->sa_any[i] != NULL; i++ ) {
if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
/* don't bother accounting for stepping */
nkeys += sa->sa_any[i]->bv_len -
( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
}
}
}
if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
nkeys++;
@ -1024,7 +1088,7 @@ int caseExactIA5SubstringsFilter(
keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
nkeys = 0;
if( sa->sa_initial != NULL &&
if( flags & SLAP_INDEX_SUBSTR_INITIAL && sa->sa_initial != NULL &&
sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
@ -1048,11 +1112,46 @@ int caseExactIA5SubstringsFilter(
value->bv_val, klen );
lutil_MD5Final( MD5digest, &MD5context );
ber_bvfree( value );
keys[nkeys++] = ber_bvdup( &digest );
}
if( sa->sa_final != NULL &&
if( flags & SLAP_INDEX_SUBSTR_ANY && sa->sa_any != NULL ) {
ber_len_t i, j;
pre = SLAP_INDEX_SUBSTR_PREFIX;
klen = SLAP_INDEX_SUBSTR_MAXLEN;
for( i=0; sa->sa_any[i] != NULL; i++ ) {
if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
continue;
}
value = sa->sa_any[i];
for(j=0;
j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
j += SLAP_INDEX_SUBSTR_STEP )
{
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
lutil_MD5Update( &MD5context,
prefix->bv_val, prefix->bv_len );
}
lutil_MD5Update( &MD5context,
&pre, sizeof( pre ) );
lutil_MD5Update( &MD5context,
syntax->ssyn_oid, slen );
lutil_MD5Update( &MD5context,
mr->smr_oid, mlen );
lutil_MD5Update( &MD5context,
&value->bv_val[j], klen );
lutil_MD5Final( MD5digest, &MD5context );
keys[nkeys++] = ber_bvdup( &digest );
}
}
}
if( flags & SLAP_INDEX_SUBSTR_FINAL && sa->sa_final != NULL &&
sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
@ -1076,20 +1175,24 @@ int caseExactIA5SubstringsFilter(
&value->bv_val[value->bv_len-klen], klen );
lutil_MD5Final( MD5digest, &MD5context );
ber_bvfree( value );
keys[nkeys++] = ber_bvdup( &digest );
}
keys[nkeys] = NULL;
if( nkeys > 0 ) {
keys[nkeys] = NULL;
*keysp = keys;
} else {
ch_free( keys );
*keysp = NULL;
}
*keysp = keys;
return LDAP_SUCCESS;
}
static int
caseIgnoreIA5Match(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -1124,7 +1227,7 @@ static char *strcasechr( const char *str, int c )
static int
caseIgnoreIA5SubstringsMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,
@ -1249,7 +1352,8 @@ done:
/* Index generation function */
int caseIgnoreIA5Indexer(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -1305,7 +1409,8 @@ int caseIgnoreIA5Indexer(
/* Index generation function */
int caseIgnoreIA5Filter(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -1348,19 +1453,21 @@ int caseIgnoreIA5Filter(
ber_bvfree( value );
*keysp = keys;
return LDAP_SUCCESS;
}
/* Substrings Index generation function */
int caseIgnoreIA5SubstringsIndexer(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
struct berval **values,
struct berval ***keysp )
{
int i, nkeys, types;
ber_len_t i, nkeys;
size_t slen, mlen;
struct berval **keys;
lutil_MD5_CTX MD5context;
@ -1369,11 +1476,6 @@ int caseIgnoreIA5SubstringsIndexer(
digest.bv_val = MD5digest;
digest.bv_len = sizeof(MD5digest);
types = 0;
if( flags & SLAP_MR_SUBSTR_INITIAL ) types++;
if( flags & SLAP_MR_SUBSTR_FINAL ) types++;
/* no SUBSTR_ANY indexing */
nkeys=0;
for( i=0; values[i] != NULL; i++ ) {
/* count number of indices to generate */
@ -1381,10 +1483,28 @@ int caseIgnoreIA5SubstringsIndexer(
continue;
}
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN - ( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
}
}
if( flags & SLAP_INDEX_SUBSTR_ANY ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
}
}
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
if( values[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
nkeys += SLAP_INDEX_SUBSTR_MAXLEN -
( SLAP_INDEX_SUBSTR_MINLEN - 1);
} else {
nkeys += values[i]->bv_len - ( SLAP_INDEX_SUBSTR_MINLEN - 1 );
}
}
}
assert( i > 0 );
@ -1395,7 +1515,6 @@ int caseIgnoreIA5SubstringsIndexer(
return LDAP_SUCCESS;
}
nkeys *= types; /* We need to generate keys for each type */
keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
slen = strlen( syntax->ssyn_oid );
@ -1408,16 +1527,44 @@ int caseIgnoreIA5SubstringsIndexer(
if( values[i]->bv_len < SLAP_INDEX_SUBSTR_MINLEN ) continue;
max = SLAP_INDEX_SUBSTR_MAXLEN < values[i]->bv_len
? SLAP_INDEX_SUBSTR_MAXLEN : values[i]->bv_len;
value = ber_bvdup( values[i] );
ldap_pvt_str2upper( value->bv_val );
if( ( flags & SLAP_INDEX_SUBSTR_ANY ) &&
( value->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) )
{
char pre = SLAP_INDEX_SUBSTR_PREFIX;
max = value->bv_len - ( SLAP_INDEX_SUBSTR_MAXLEN - 1);
for( j=0; j<max; j++ ) {
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
lutil_MD5Update( &MD5context,
prefix->bv_val, prefix->bv_len );
}
lutil_MD5Update( &MD5context,
&pre, sizeof( pre ) );
lutil_MD5Update( &MD5context,
syntax->ssyn_oid, slen );
lutil_MD5Update( &MD5context,
mr->smr_oid, mlen );
lutil_MD5Update( &MD5context,
&value->bv_val[j],
SLAP_INDEX_SUBSTR_MAXLEN );
lutil_MD5Final( MD5digest, &MD5context );
keys[nkeys++] = ber_bvdup( &digest );
}
}
max = SLAP_INDEX_SUBSTR_MAXLEN < value->bv_len
? SLAP_INDEX_SUBSTR_MAXLEN : value->bv_len;
for( j=SLAP_INDEX_SUBSTR_MINLEN; j<=max; j++ ) {
char pre;
if( flags & SLAP_MR_SUBSTR_INITIAL ) {
if( flags & SLAP_INDEX_SUBSTR_INITIAL ) {
pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
@ -1437,7 +1584,7 @@ int caseIgnoreIA5SubstringsIndexer(
keys[nkeys++] = ber_bvdup( &digest );
}
if( flags & SLAP_MR_SUBSTR_FINAL ) {
if( flags & SLAP_INDEX_SUBSTR_FINAL ) {
pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
@ -1462,13 +1609,20 @@ int caseIgnoreIA5SubstringsIndexer(
ber_bvfree( value );
}
keys[nkeys] = NULL;
*keysp = keys;
if( nkeys > 0 ) {
keys[nkeys] = NULL;
*keysp = keys;
} else {
ch_free( keys );
*keysp = NULL;
}
return LDAP_SUCCESS;
}
int caseIgnoreIA5SubstringsFilter(
unsigned flags,
slap_mask_t use,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *prefix,
@ -1477,7 +1631,7 @@ int caseIgnoreIA5SubstringsFilter(
{
SubstringsAssertion *sa = assertValue;
char pre;
int nkeys = 0;
ber_len_t nkeys = 0;
size_t slen, mlen, klen;
struct berval **keys;
lutil_MD5_CTX MD5context;
@ -1485,12 +1639,24 @@ int caseIgnoreIA5SubstringsFilter(
struct berval *value;
struct berval digest;
if( sa->sa_initial != NULL &&
if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
nkeys++;
}
if( sa->sa_final != NULL &&
if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
ber_len_t i;
for( i=0; sa->sa_any[i] != NULL; i++ ) {
if( sa->sa_any[i]->bv_len >= SLAP_INDEX_SUBSTR_MAXLEN ) {
/* don't bother accounting for stepping */
nkeys += sa->sa_any[i]->bv_len -
( SLAP_INDEX_SUBSTR_MAXLEN - 1 );
}
}
}
if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
nkeys++;
@ -1510,7 +1676,7 @@ int caseIgnoreIA5SubstringsFilter(
keys = ch_malloc( sizeof( struct berval * ) * (nkeys+1) );
nkeys = 0;
if( sa->sa_initial != NULL &&
if((flags & SLAP_INDEX_SUBSTR_INITIAL) && sa->sa_initial != NULL &&
sa->sa_initial->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
pre = SLAP_INDEX_SUBSTR_INITIAL_PREFIX;
@ -1539,7 +1705,46 @@ int caseIgnoreIA5SubstringsFilter(
keys[nkeys++] = ber_bvdup( &digest );
}
if( sa->sa_final != NULL &&
if((flags & SLAP_INDEX_SUBSTR_ANY) && sa->sa_any != NULL ) {
ber_len_t i, j;
pre = SLAP_INDEX_SUBSTR_PREFIX;
klen = SLAP_INDEX_SUBSTR_MAXLEN;
for( i=0; sa->sa_any[i] != NULL; i++ ) {
if( sa->sa_any[i]->bv_len < SLAP_INDEX_SUBSTR_MAXLEN ) {
continue;
}
value = ber_bvdup( sa->sa_any[i] );
ldap_pvt_str2upper( value->bv_val );
for(j=0;
j <= value->bv_len - SLAP_INDEX_SUBSTR_MAXLEN;
j += SLAP_INDEX_SUBSTR_STEP )
{
lutil_MD5Init( &MD5context );
if( prefix != NULL && prefix->bv_len > 0 ) {
lutil_MD5Update( &MD5context,
prefix->bv_val, prefix->bv_len );
}
lutil_MD5Update( &MD5context,
&pre, sizeof( pre ) );
lutil_MD5Update( &MD5context,
syntax->ssyn_oid, slen );
lutil_MD5Update( &MD5context,
mr->smr_oid, mlen );
lutil_MD5Update( &MD5context,
&value->bv_val[j], klen );
lutil_MD5Final( MD5digest, &MD5context );
keys[nkeys++] = ber_bvdup( &digest );
}
ber_bvfree( value );
}
}
if((flags & SLAP_INDEX_SUBSTR_FINAL) && sa->sa_final != NULL &&
sa->sa_final->bv_len >= SLAP_INDEX_SUBSTR_MINLEN )
{
pre = SLAP_INDEX_SUBSTR_FINAL_PREFIX;
@ -1568,9 +1773,14 @@ int caseIgnoreIA5SubstringsFilter(
keys[nkeys++] = ber_bvdup( &digest );
}
keys[nkeys] = NULL;
if( nkeys > 0 ) {
keys[nkeys] = NULL;
*keysp = keys;
} else {
ch_free( keys );
*keysp = NULL;
}
*keysp = keys;
return LDAP_SUCCESS;
}
@ -1632,7 +1842,7 @@ numericStringNormalize(
static int
objectIdentifierFirstComponentMatch(
int *matchp,
unsigned flags,
slap_mask_t flags,
Syntax *syntax,
MatchingRule *mr,
struct berval *value,

View file

@ -134,11 +134,15 @@ LDAP_SLAPD_F (int) slap_debug;
#define SLAP_INDEX_SUBSTR_INITIAL ( SLAP_INDEX_SUBSTR | 0x0100UL )
#define SLAP_INDEX_SUBSTR_ANY ( SLAP_INDEX_SUBSTR | 0x0200UL )
#define SLAP_INDEX_SUBSTR_FINAL ( SLAP_INDEX_SUBSTR | 0x0400UL )
#define SLAP_INDEX_SUBSTR_DEFAULT ( SLAP_INDEX_SUBSTR \
| SLAP_INDEX_SUBSTR_INITIAL | SLAP_INDEX_SUBSTR_FINAL )
#define SLAP_INDEX_SUBSTR_DEFAULT \
( SLAP_INDEX_SUBSTR \
| SLAP_INDEX_SUBSTR_INITIAL \
| SLAP_INDEX_SUBSTR_ANY \
| SLAP_INDEX_SUBSTR_FINAL )
#define SLAP_INDEX_SUBSTR_MINLEN 2
#define SLAP_INDEX_SUBSTR_MAXLEN 4
#define SLAP_INDEX_SUBSTR_STEP 2
#define SLAP_INDEX_FLAGS 0xF000UL
#define SLAP_INDEX_SUBTYPES 0x1000UL /* use index with subtypes */
@ -146,7 +150,7 @@ LDAP_SLAPD_F (int) slap_debug;
#define SLAP_INDEX_LANG 0x4000UL /* use index with lang subtypes */
#define SLAP_INDEX_AUTO_LANG 0x8000UL /* use mask with lang subtypes */
typedef long slap_index;
typedef unsigned long slap_mask_t;
/*
* there is a single index for each attribute. these prefixes ensure
@ -239,7 +243,7 @@ typedef int slap_mr_convert_func LDAP_P((
/* Normalizer */
typedef int slap_mr_normalize_func LDAP_P((
unsigned use,
slap_mask_t use,
struct slap_syntax *syntax, /* NULL if in is asserted value */
struct slap_matching_rule *mr,
struct berval * in,
@ -248,7 +252,7 @@ typedef int slap_mr_normalize_func LDAP_P((
/* Match (compare) function */
typedef int slap_mr_match_func LDAP_P((
int *match,
unsigned flags,
slap_mask_t use,
struct slap_syntax *syntax, /* syntax of stored value */
struct slap_matching_rule *mr,
struct berval * value,
@ -256,7 +260,8 @@ typedef int slap_mr_match_func LDAP_P((
/* Index generation function */
typedef int slap_mr_indexer_func LDAP_P((
unsigned flags,
slap_mask_t use,
slap_mask_t mask,
struct slap_syntax *syntax, /* syntax of stored value */
struct slap_matching_rule *mr,
struct berval *prefix,
@ -265,7 +270,8 @@ typedef int slap_mr_indexer_func LDAP_P((
/* Filter index function */
typedef int slap_mr_filter_func LDAP_P((
unsigned flags,
slap_mask_t use,
slap_mask_t mask,
struct slap_syntax *syntax, /* syntax of stored value */
struct slap_matching_rule *mr,
struct berval *prefix,
@ -274,7 +280,7 @@ typedef int slap_mr_filter_func LDAP_P((
typedef struct slap_matching_rule {
LDAPMatchingRule smr_mrule;
unsigned smr_usage;
slap_mask_t smr_usage;
#define SLAP_MR_TYPE_MASK 0xFF00U
#define SLAP_MR_SUBTYPE_MASK 0x00F0U

View file

@ -23,6 +23,7 @@ directory ./test-db
rootdn "cn=Manager, o=University of Michigan, c=US"
rootpw secret
index objectclass eq
index cn,sn,uid pres,eq,sub
index uid pres,eq,sub
index cn,sn pres,eq,sub,subany
dbnosync
dbnolocking