Handling version requests
Now that we’ve seen the iq_register() function,
the function to handle jabber:iq:version queries
looks pretty straightforward:
sub iq_version {
my $node = shift;
debug("[iq_version]");
return unless my $query = $node->getTag('', NS_VERSION)
and $node->attr('type', IQ_GET);
debug("--> version request");
$node = toFrom($node);
$node->attr('code', IQ_RESULT);
$query->insertTag('name')->data($NAME);
$query->insertTag('version')->data($VERSION);
$query->insertTag('os')->data(`uname -sr`);
$c->send($node);
return r_HANDLED;
}
Just as we check for whether the element is appropriate to handle
in iq_register(), we do here, too, this time
looking for an IQ-get with a query child tag qualified by the
NS_VERSION
(jabber:iq:version) namespace, which we grab in
$query.
Setting the <iq/>’s type to
result and flipping the addresses, we
then just have to add
<name/>,
<version/>, and
<os/> tags to the query child
with appropriate values, to end up with a response like the one
shown in Example 9-16.
If we do this, we deem the IQ to have been handled and
return the special r_HANDLED value, as before,
to stop the dispatching going any further for this element.
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