parse substring search correctly

This commit is contained in:
leitner
2002-01-14 21:50:49 +00:00
parent 5413d2bdeb
commit 7f7fb3c2f9
3 changed files with 38 additions and 7 deletions

10
ldap.h
View File

@@ -21,15 +21,19 @@ struct PartialAttributeList {
struct PartialAttributeList* next;
};
struct Substring {
enum { prefix=0, any=1, suffix=2 } substrtype;
struct string s;
struct Substring* next;
};
struct Filter {
enum {
AND=0, OR=1, NOT=2, EQUAL=3, SUBSTRING=4, GREATEQUAL=5, LESSEQUAL=6, PRESENT=7, APPROX=8, EXTENSIBLE=9
} type;
struct AttributeValueAssertion ava;
struct Substring* substrings;
struct AttributeDescriptionList *a;
enum {
PREFIX=0, ANY=1, SUFFIX=2
} substrtype;
struct Filter* x,*next;
};

View File

@@ -79,9 +79,22 @@ int scan_ldapsearchfilter(const char* src,const char* max,struct Filter** f) {
if (!(tmp=scan_ldapstring(src+res,nmax,&(*f)->ava.desc))) goto error;
res+=tmp;
if (!(tmp=scan_asn1SEQUENCE(src+res,nmax,&len2))) goto error;
if (src+tmp+len2!=nmax) goto error;
res+=tmp;
goto error; /* TODO */
if (src+res+len2!=nmax) goto error;
while (src+res<nmax) {
struct Substring* s=malloc(sizeof(struct Substring));
unsigned long x;
enum asn1_tagtype tt;
enum asn1_tagclass tc;
if (!s) goto error;
if (!(tmp=scan_asn1string(src+res,nmax,&tc,&tt,&x,&s->s.s,&s->s.l))) goto error;
if (x>2) goto error;
s->substrtype=x;
res+=tmp;
s->next=(*f)->substrings;
(*f)->substrings=s;
}
break;
}
case 7: /* present [7] AttributeDescription, */
goto error;

18
t2.c
View File

@@ -36,7 +36,21 @@ mergesub:
printava(&f->ava,"==");
break;
case SUBSTRING:
printava(&f->ava,"\\in");
{
struct Substring* s=f->substrings;
int first=1;
printf("%.*s has ",(int)f->ava.desc.l,f->ava.desc.s);
while (s) {
if (!first) printf(" and "); first=0;
switch(s->substrtype) {
case prefix: printf("prefix \""); break;
case any: printf("substr \""); break;
case suffix: printf("suffix \""); break;
}
printf("%.*s\"",(int)s->s.l,s->s.s);
s=s->next;
}
}
break;
case GREATEQUAL:
printava(&f->ava,">=");
@@ -64,7 +78,7 @@ int main(int argc,char* argv[]) {
#if 1
unsigned long size;
// char* ldapsequence=mmap_read("req",&size);
char* ldapsequence=mmap_read(argc>1?argv[1]:"capture/127.000.000.001.32779-127.000.000.001.00389",&size);
char* ldapsequence=mmap_read(argc>1?argv[1]:"capture/127.000.000.001.38433-127.000.000.001.00389",&size);
long messageid, op, len;
int res,done=0;
while (done<size) {