AnyEvent-XMPP
view release on metacpan or search on metacpan
lib/AnyEvent/XMPP/Component.pm view on Meta::CPAN
$args{host}
or die "Required 'host' argument missing to new for this component!";
unless (defined $args{port}) {
$args{port} = 5347;
}
my $self = $class->SUPER::new (%args);
$self->{parser}->set_stream_cb (sub {
my $secret = $self->{parser}->{parser}->xml_escape ($self->{secret});
my $id = $self->{stream_id} = $_[0]->attr ('id');
$self->{writer}->send_handshake ($id, $secret);
});
$self->reg_cb (recv_stanza_xml => sub {
my ($self, $node) = @_;
if ($node->eq (component => 'handshake')) {
$self->{authenticated} = 1;
$self->event ('session_ready');
}
lib/AnyEvent/XMPP/Writer.pm view on Meta::CPAN
(eg. jabberd14 and ejabberd) have problems with XML namespaces. Thats the
reason why I'm assigning the namespace prefixes manually: The servers just
don't accept validly namespaced XML. The draft 3921bis does even state that a
client SHOULD generate a 'stream' prefix for the <stream> tag.
I advice you to explicitly set the namespaces too if you generate "XML" for
XMPP yourself, at least until all or most of the XMPP servers have been fixed.
Which might take some years :-) And maybe will happen never.
And another note: As XMPP requires all predefined entity characters to be
escaped in character data you need a "XML" writer that will escape everything:
RFC 3920 - 11.1. Restrictions:
character data or attribute values containing unescaped characters
that map to the predefined entities (Section 4.6 therein);
such characters MUST be escaped
This means:
You have to escape '>' in the character data. I don't know whether XML::Writer
does that. And I honestly don't care much about this. XMPP is broken by design and
I have barely time to writer my own XML parsers and writers to suit their sick taste
of "XML". (Do I repeat myself?)
I would be happy if they finally say (in RFC3920): "XMPP is NOT XML. It's just
XML-like, and some XML utilities allow you to process this kind of XML.".
=head1 METHODS
=over 4
lib/AnyEvent/XMPP/Writer.pm view on Meta::CPAN
sub send_whitespace_ping {
my ($self) = @_;
$self->{writer}->raw (' ');
$self->flush;
}
=item B<send_handshake ($streamid, $secret)>
This method sends a component handshake. Please note that C<$secret>
must be XML escaped!
=cut
sub send_handshake {
my ($self, $id, $secret) = @_;
my $out_secret = encode ("UTF-8", $secret);
my $out = lc sha1_hex ($id . $out_secret);
simxml ($self->{writer}, defns => 'component', node => {
ns => 'component', name => 'handshake', childs => [ $out ]
});
( run in 0.604 second using v1.01-cache-2.11-cpan-c21f80fb71c )