add case insensitive matching and dn normalizing in parse.
This commit is contained in:
18
README
18
README
@@ -11,11 +11,17 @@ some simple forms of SearchRequest, and it can even answer simple
|
||||
queries.
|
||||
|
||||
tinyldap now supports an external database representation with indexes.
|
||||
However, the indexes are not used yet by tinyldap. It still iterates
|
||||
through all records. Use "parse" to create the file "data" from an LDIF
|
||||
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.
|
||||
Use "parse" to create the file "data" from an LDIF file called
|
||||
"exp.ldif" (I can't give you my test data, sorry). Then use "addindex"
|
||||
to add indexes if you like. To make an index case insentive (and the
|
||||
corresponding attribute, too), give a third argument to addindex (e.g.
|
||||
"./addindex data sn i"; in case I extend this later, stick with "i").
|
||||
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!
|
||||
|
||||
parse will now normalize dn before writing it to the index. That means
|
||||
that the attribute names in dn are lowercased, ';' is converted to ','
|
||||
and spaces after ';' or ',' are removed.
|
||||
|
||||
12
addindex.c
12
addindex.c
@@ -12,11 +12,19 @@ mstorage_t idx;
|
||||
char* map;
|
||||
|
||||
int compar(const void* a,const void* b) {
|
||||
return strcmp(map+*(uint32*)a,map+*(uint32*)b);
|
||||
int i;
|
||||
if ((i=strcmp(map+*(uint32*)a,map+*(uint32*)b)))
|
||||
return i;
|
||||
else
|
||||
return *(uint32*)b-*(uint32*)a;
|
||||
}
|
||||
|
||||
int compari(const void* a,const void* b) {
|
||||
return strcasecmp(map+*(uint32*)a,map+*(uint32*)b);
|
||||
int i;
|
||||
if ((i=strcasecmp(map+*(uint32*)a,map+*(uint32*)b)))
|
||||
return i;
|
||||
else
|
||||
return *(uint32*)b-*(uint32*)a;
|
||||
}
|
||||
|
||||
int main(int argc,char* argv[]) {
|
||||
|
||||
31
ldif_parse.c
31
ldif_parse.c
@@ -3,6 +3,7 @@
|
||||
#include <open.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include "mduptab.h"
|
||||
#include "mstorage.h"
|
||||
#include "str.h"
|
||||
@@ -31,6 +32,30 @@ static void addattribute(struct ldaprec** l,long name,long val) {
|
||||
}
|
||||
}
|
||||
|
||||
/* "ou=fnord; O=fefe; c=de" -> "ou=fnord,o=fefe,c=de" */
|
||||
/* returns the length of the new string */
|
||||
static int normalize_dn(char* dest,const char* src,int len) {
|
||||
int makelower=1;
|
||||
char* orig=dest;
|
||||
while (len) {
|
||||
if (*src==';' || *src==',') {
|
||||
*dest=',';
|
||||
while (len>1 && src[1]==' ') { ++src; --len; }
|
||||
makelower=1;
|
||||
} else {
|
||||
if (makelower)
|
||||
*dest=tolower(*src);
|
||||
else
|
||||
*dest=*src;
|
||||
if (*dest=='=') makelower=0;
|
||||
}
|
||||
++dest;
|
||||
++src;
|
||||
--len;
|
||||
}
|
||||
return dest-orig;
|
||||
}
|
||||
|
||||
static int parserec(buffer* b, struct ldaprec** l) {
|
||||
char buf[8192];
|
||||
int n,i,eof=0,ofs=0;
|
||||
@@ -69,6 +94,9 @@ lookagain:
|
||||
|
||||
if (tmp==objectClass) {
|
||||
if ((val=mduptab_add(&classes,buf+i))<0) goto nomem;
|
||||
} else if (tmp==dn) {
|
||||
char* newdn=alloca(n-i+1);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,buf+i,n-i+1)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,buf+i,n-i+1))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
@@ -89,6 +117,9 @@ lookagain:
|
||||
#if 1
|
||||
if (tmp==objectClass) {
|
||||
if ((val=mduptab_add(&classes,buf+i))<0) goto nomem;
|
||||
} else if (tmp==dn) {
|
||||
char* newdn=alloca(n-i+1);
|
||||
if ((val=mstorage_add(&stringtable,newdn,normalize_dn(newdn,buf+i,n-i+1)))<0) goto nomem;
|
||||
} else
|
||||
if ((val=mstorage_add(&stringtable,buf+i,n-i+1))<0) goto nomem;
|
||||
addattribute(l,tmp,val);
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
#endif
|
||||
|
||||
#define verbose 0
|
||||
#define debug 0
|
||||
#define debug 1
|
||||
|
||||
char* map;
|
||||
long filelen;
|
||||
@@ -28,7 +28,7 @@ uint32 dn_ofs,objectClass_ofs;
|
||||
|
||||
#define BUFSIZE 8192
|
||||
|
||||
#if (verbose != 0)
|
||||
#if (debug != 0)
|
||||
/* debugging support functions, adapted from t2.c */
|
||||
static void printava(struct AttributeValueAssertion* a,const char* rel) {
|
||||
buffer_puts(buffer_2,"[");
|
||||
|
||||
Reference in New Issue
Block a user