Supporting functions
The rest of the script consists of minor functions that play
roles in assisting the core iq_browse().
The iq_notimpl() function is exactly the
same as in the newsagent script in
Section 8.3; it serves to catch stray
IQ elements that in this case aren’t IQ-gets containing a
jabber:iq:browse query, and send them back
with a “Not Implemented” error. With IQs, this is preferable
to not responding at all, as responses are usually expected,
even if those responses are IQ-errors. It’s different with
<message/> and
<presence/> elements, as they
can be seen as “one-way” and valid fodder for an element-sink.
sub iq_notimpl {
my $node = shift;
$node = toFrom($node);
$node->attr('type', IQ_ERROR);
my $error = $node->insertTag('error');
$error->attr('code', '501');
$error->data('Not Implemented');
$c->send($node);
return r_HANDLED;
}
The strip() function, as described already,
removes a base DN from a fully qualified DN:
sub strip {
my ($fqdn, $basedn) = @_;
my @fqdn = split(/,/, $fqdn);
my @basedn_elements = split(/,/, $basedn);
return join(',', @fqdn[0 .. ($#fqdn - scalar @basedn_elements)]);
}
As well as sharing the iq_notimpl() function
with the newsagent script, ldapr
also shares the toFrom() function, which flips
around the values of the to and
from attributes of an element:
sub toFrom {
my $node = shift;
my $to = $node->attr('to');
$node->attr('to', $node->attr('from'));
$node->attr('from', $to);
return $node;
}
The isUser() function, also described earlier, makes ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access