/* filterindex.c - generate the list of candidate entries from a filter */
+#include "portable.h"
+
#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/socket.h>
+
+#include <ac/socket.h>
+#include <ac/string.h>
+
#include "slap.h"
#include "back-ldbm.h"
-extern char *first_word();
-extern char *next_word();
-extern char *phonetic();
-extern IDList *index_read();
-extern IDList *idl_intersection();
-extern IDList *idl_union();
-extern IDList *idl_notin();
-extern IDList *idl_allids();
-
-static IDList *ava_candidates();
-static IDList *presence_candidates();
-static IDList *approx_candidates();
-static IDList *list_candidates();
-static IDList *substring_candidates();
-static IDList *substring_comp_candidates();
+static ID_BLOCK *ava_candidates( Backend *be, Ava *ava, int type );
+static ID_BLOCK *presence_candidates( Backend *be, char *type );
+static ID_BLOCK *approx_candidates( Backend *be, Ava *ava );
+static ID_BLOCK *list_candidates( Backend *be, Filter *flist, int ftype );
+static ID_BLOCK *substring_candidates( Backend *be, Filter *f );
+static ID_BLOCK *substring_comp_candidates( Backend *be, char *type, char *val, int prepost );
/*
* test_filter - test a filter against a single entry.
* >0 an ldap error code
*/
-IDList *
+ID_BLOCK *
filter_candidates(
Backend *be,
Filter *f
)
{
- IDList *result;
+ ID_BLOCK *result, *tmp1, *tmp2;
Debug( LDAP_DEBUG_TRACE, "=> filter_candidates\n", 0, 0, 0 );
case LDAP_FILTER_NOT:
Debug( LDAP_DEBUG_FILTER, "\tNOT\n", 0, 0, 0 );
- result = idl_notin( be, idl_allids( be ), filter_candidates( be,
- f->f_not ) );
+ tmp1 = idl_allids( be );
+ tmp2 = filter_candidates( be, f->f_not );
+ result = idl_notin( be, tmp1, tmp2 );
+ idl_free( tmp2 );
+ idl_free( tmp1 );
break;
}
- Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %d\n",
- result ? result->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= filter_candidates %ld\n",
+ result ? ID_BLOCK_NIDS(result) : 0, 0, 0 );
return( result );
}
-static IDList *
+static ID_BLOCK *
ava_candidates(
Backend *be,
Ava *ava,
int type
)
{
- IDList *idl;
+ ID_BLOCK *idl;
Debug( LDAP_DEBUG_TRACE, "=> ava_candidates 0x%x\n", type, 0, 0 );
break;
}
- Debug( LDAP_DEBUG_TRACE, "<= ava_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= ava_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
presence_candidates(
Backend *be,
char *type
)
{
- IDList *idl;
+ ID_BLOCK *idl;
Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 );
idl = index_read( be, type, 0, "*" );
- Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= presence_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
approx_candidates(
Backend *be,
Ava *ava
)
{
char *w, *c;
- IDList *idl, *tmp;
+ ID_BLOCK *idl, *tmp;
Debug( LDAP_DEBUG_TRACE, "=> approx_candidates\n", 0, 0, 0 );
}
}
- Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= approx_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
list_candidates(
Backend *be,
Filter *flist,
int ftype
)
{
- IDList *idl, *tmp, *tmp2;
+ ID_BLOCK *idl, *tmp, *tmp2;
Filter *f;
Debug( LDAP_DEBUG_TRACE, "=> list_candidates 0x%x\n", ftype, 0, 0 );
}
}
- Debug( LDAP_DEBUG_TRACE, "<= list_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= list_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
substring_candidates(
Backend *be,
Filter *f
)
{
int i;
- IDList *idl, *tmp, *tmp2;
+ ID_BLOCK *idl, *tmp, *tmp2;
Debug( LDAP_DEBUG_TRACE, "=> substring_candidates\n", 0, 0, 0 );
}
}
- Debug( LDAP_DEBUG_TRACE, "<= substring_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= substring_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}
-static IDList *
+static ID_BLOCK *
substring_comp_candidates(
Backend *be,
char *type,
)
{
int i, len;
- IDList *idl, *tmp, *tmp2;
+ ID_BLOCK *idl, *tmp, *tmp2;
char *p;
char buf[SUBLEN + 1];
idl_free( tmp );
idl_free( tmp2 );
}
+
+ /* break if no candidates */
+ if( idl == NULL ) {
+ break;
+ }
}
- Debug( LDAP_DEBUG_TRACE, "<= substring_comp_candidates %d\n",
- idl ? idl->b_nids : 0, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "<= substring_comp_candidates %ld\n",
+ idl ? ID_BLOCK_NIDS(idl) : 0, 0, 0 );
return( idl );
}