Reputation: 4754
I'm trying to write a LDAP server with Net::LDAP::Server
The request routing/handling works fine, but the parsing of the incoming ldap filter causes me some troubles.
The incoming filter has this value/structure:
$VAR1 = {
'and' => [
{
'or' => [
{
'substrings' => {
'substrings' => [
{
'initial' => '233'
}
],
'type' => 'sn'
}
},
{
'substrings' => {
'substrings' => [
{
'initial' => '233'
}
],
'type' => 'sn'
}
},
{
'equalityMatch' => {
'assertionValue' => '233',
'attributeDesc' => 'telephoneNumber'
}
},
{
'equalityMatch' => {
'assertionValue' => '233',
'attributeDesc' => 'telephoneNumber'
}
}
]
}
]
};
Here my code to parse the LDAP filter
my $myFilter= $reqData->{'filter'};
print STDERR "Filter : $myFilter \n";
print STDERR Dumper($myFilter) ."\n";
my @andloop= $myFilter->{'and'};
my $and;
foreach $and(@andloop)
{
print STDERR "Filter AND: $and \n";
print STDERR Dumper($and) ."\n";
my $orValue;
foreach $orValue ($and)
{
print STDERR "Inside Filter OR: $orValue : $and\n";
print STDERR "Keys: ";
print STDERR Dumper($orValue) . "\n";
print STDERR "KeysOR: ";
my @or= $orValue;
print STDERR Dumper(@or[0]->{'or'}) . "\n";
print STDERR "OR Value[0]: " . Dumper(@or[0]) . "\n";
}
}
I can loop via the AND, but don't seem to dive down into the 'or' parts
Upvotes: 1
Views: 122
Reputation: 241988
$orValue
is an array reference. Dereference it to get a real array:
my @or = @$orValue;
You need to be more careful with references, they (usually) don't dereference automatically:
print STDERR "Filter : $myFilter \n";
print STDERR Dumper($myFilter), "\n";
for my $and (@{ $myFilter->{and} }) {
print STDERR "Filter AND: $and \n";
print STDERR Dumper($and) ."\n";
for my $or (@{ $and->{or} }) {
print STDERR "Inside Filter OR: $or : $and\n";
print STDERR "Keys: ";
print STDERR Dumper($or), "\n";
}
}
Upvotes: 3