remove large commented out code area

begin framework for using the index
This commit is contained in:
leitner
2002-03-25 15:05:56 +00:00
parent 46d79c5751
commit e8dc6efb36
3 changed files with 32 additions and 97 deletions

2
README
View File

@@ -17,3 +17,5 @@ file called "exp.ldif" (I can't give you my test data, sorry). Then use
"addindex" to add indexes if you like. Use "dumpidx" to have the
contents of data displayed on screen. tinyldap has been modified to use
data instead of the in-memory linked list.
Do _not_ add an index for objectClass! It will not work!

View File

@@ -1,3 +1,4 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

View File

@@ -64,6 +64,31 @@ static int indexable(struct Filter* f) {
}
}
#define MAXINDEXMATCHES 100
static uint32 matches[MAXINDEXMATCHES];
static uint32 matchcounter;
/* find record given a data pointer */
static uint32 findrec(uint32 dat) {
uint32* records=(uint32*)(map+indices_offset);
uint32 bottom=0;
uint32 top=record_count;
while ((top>=bottom)) {
uint32 mid=(top+bottom)/2;
uint32 k,l;
uint32_unpack(&records[mid],&k);
uint32_unpack(map+k+8,&l);
if (l<dat) {
uint32_unpack(map+k,&l);
uint32_unpack(map+k+l*8+4,&l);
if (l>dat) return k; /* found! */
bottom=mid+1;
} else
top=mid-1;
}
return 0;
}
static void answerwith(uint32 ofs,struct SearchRequest* sr,long messageid,int out) {
uint32 k;
struct SearchResultEntry sre;
@@ -237,12 +262,12 @@ int handle(int in,int out) {
}
#endif
if ((tmp=scan_ldapsearchrequest(buf+res,buf+res+len,&sr))) {
#if 0
if (indexable(sr.filter)) {
buffer_putsflush(buffer_2,"query is indexable!\n");
} /* else */
#endif
{
/* Use the index to find matching data. Put the offsets
* of the matches in a table. Use findrec to locate
* the records that point to the data. */
} /* else */ {
char* x=map+5*4+size_of_string_table+attribute_count*8;
unsigned long i;
for (i=0; i<record_count; ++i) {
@@ -253,99 +278,6 @@ int handle(int in,int out) {
x+=j*8;
}
}
#ifdef OLD
struct ldaprec* r=first;
#if 0
buffer_puts(buffer_2,"baseObject: \"");
buffer_put(buffer_2,sr.baseObject.s,sr.baseObject.l);
buffer_putsflush(buffer_2,"\"\n");
#endif
while (r) {
#if 0
buffer_puts(buffer_2,"ldap_match(\"");
buffer_puts(buffer_2,r->dn);
buffer_putsflush(buffer_2,"\"\n");
#endif
if (ldap_match(r,&sr)) {
struct SearchResultEntry sre;
struct PartialAttributeList** pal=&sre.attributes;
sre.objectName.s=r->dn; sre.objectName.l=strlen(r->dn);
sre.attributes=0;
/* now go through list of requested attributes */
{
struct AttributeDescriptionList* adl=sr.attributes;
while (adl) {
const char* val=0;
int i=0;
#if 0
buffer_puts(buffer_2,"looking for attribute \"");
buffer_put(buffer_2,adl->a.s,adl->a.l);
buffer_putsflush(buffer_2,"\"\n");
#endif
if (!matchstring(&adl->a,"dn")) val=r->dn; else
if (!matchstring(&adl->a,"cn")) val=r->cn; else
if (!matchstring(&adl->a,"mail")) val=r->mail; else
if (!matchstring(&adl->a,"sn")) val=r->sn; else
for (; i<r->n; ++i) {
#if 0
buffer_puts(buffer_2,"comparing with \"");
buffer_puts(buffer_2,r->a[i].name);
buffer_putsflush(buffer_2,"\"\n");
#endif
if (!matchstring(&adl->a,r->a[i].name))
val=r->a[i].value;
}
if (val) {
*pal=malloc(sizeof(struct PartialAttributeList));
if (!*pal) {
nomem:
buffer_putsflush(buffer_2,"out of virtual memory!\n");
exit(1);
}
(*pal)->type=adl->a;
{
struct AttributeDescriptionList** a=&(*pal)->values;
while (i<r->n) {
*a=malloc(sizeof(struct AttributeDescriptionList));
if (!*a) goto nomem;
(*a)->a.s=val;
(*a)->a.l=strlen(val);
(*a)->next=0;
for (;i<r->n; ++i)
if (!matchstring(&adl->a,r->a[i].name)) {
val=r->a[i].value;
break;
}
}
}
(*pal)->next=0;
pal=&(*pal)->next;
}
adl=adl->next;
}
}
{
long l=fmt_ldapsearchresultentry(0,&sre);
char *buf=alloca(l+300); /* you never know ;) */
long tmp;
if (verbose) {
buffer_puts(buffer_2,"sre len ");
buffer_putulong(buffer_2,l);
buffer_putsflush(buffer_2,".\n");
}
tmp=fmt_ldapmessage(buf,messageid,SearchResultEntry,l);
fmt_ldapsearchresultentry(buf+tmp,&sre);
write(out,buf,l+tmp);
}
if (verbose) {
buffer_puts(buffer_2,"found: ");
buffer_puts(buffer_2,r->dn);
buffer_putsflush(buffer_2,"\n");
}
}
r=r->next;
}
#endif
} else {
buffer_putsflush(buffer_2,"couldn't parse search request!\n");
exit(1);