Performing the actual reflection
Now, let’s move on to the meat of the script. The main handler,
iq_browse()
, starts by making sure
it has an IQ element:
sub iq_browse { my $node = shift; return unless $node->attr('type') eq IQ_GET and my $query = $node->getTag('', NS_BROWSE);
What we’re looking for is an IQ-get with a
jabber:iq:browse
-qualified query extension.
If there isn’t one, we exit out of the function, and
dispatching continues to the iq_notimpl()
function, because we didn’t return the special value represented
by m_HANDLED
.
If we do get a valid request, we first extract the relative DN
from the resource part of the JID specified
in the IQ-get’s to
attribute—the JID. If the request was
sent to ldap.cicero/ou=UK, ou=People
, then
we extract the relative DN ou=UK, ou=People
into $obj
like this:
my ($obj) = $node->attr('to') =~ /\/(.*)$/; debug("request: $obj");
Armed with a specification of what part of the LDAP hierarchy
needs to be searched, the next step is to call the
search()
method on the LDAP object in
$ldap
:
my $result = $ldap->search( base => $obj ? join(',', $obj, $basedn) : $basedn, filter => "(objectclass=*)", scope => 'one', );
As you can see, we’re specifying three parameters in the search()
method:
- base
This is the point within the LDAP hierarchy from which to start looking. We must specify this as a full DN, so we append the base DN (
dc=demo,dc=org
) to the relative DN received in the request to make an absolute DN:ou=UK, ou=People, dc=demo, dc=org
- filter ...
Get Programming Jabber now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.