Handling registration requests
The first of the handlers defined for <iq/>
elements is the iq_register()
function. We put it
first in the list, as we consider receipt of
<iq/>
elements in the
jabber:iq:register
namespace to be the most common.
We want this function to deal with the complete registration conversation.
This means it must respond to IQ-get and IQ-set requests.
sub iq_register { my $node = shift; debug("[iq_register]");
The element to be handled is the primary piece of data that the dispatcher passes to a callback. The element is received by the $node
variable, which is a Jabber::NodeFactory::Node
object.
Jabber::NodeFactory
is the wrapper around the
class that actually represents the elements (the nodes).
Nodes are created using
the Jabber::NodeFactory
class.
The first thing we should do is make sure it’s appropriate to continue
inside this function, which is designed to handle only
jabber:iq:register
-qualified queries. The namespace
jabber:iq:register
is represented with the constant NS_REGISTER
, imported
from the Jabber::NS
module:
return unless my $query = $node->getTag('', NS_REGISTER); debug("--> registration request");
The getTag()
method can have up to two arguments.
The first can be used to specify the name of the tag you want to get, and the second argument can contain a namespace to narrow down the request. For example, there are two <x/>
elements in this <message/>
element:
<message to='dj@qmacro.dyndns.org' from='piers@jabber.org' id='2941'> <body>Let ...
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.