| 1 |
package POE::Component::Jabber::J14; |
| 2 |
use warnings; |
| 3 |
use strict; |
| 4 |
|
| 5 |
use 5.010; |
| 6 |
use POE; |
| 7 |
use POE::Component::Jabber::Events; |
| 8 |
use POE::Filter::XML; |
| 9 |
use POE::Filter::XML::Node; |
| 10 |
use POE::Filter::XML::NS qw/ :JABBER :IQ /; |
| 11 |
use Digest::SHA1 qw/ sha1_hex /; |
| 12 |
|
| 13 |
use base('POE::Component::Jabber::Protocol'); |
| 14 |
|
| 15 |
our $VERSION = '3.00'; |
| 16 |
|
| 17 |
sub get_version() |
| 18 |
{ |
| 19 |
return '0.9'; |
| 20 |
} |
| 21 |
|
| 22 |
sub get_xmlns() |
| 23 |
{ |
| 24 |
return +NS_JABBER_ACCEPT; |
| 25 |
} |
| 26 |
|
| 27 |
sub get_states() |
| 28 |
{ |
| 29 |
return [ 'set_auth', 'init_input_handler' ]; |
| 30 |
} |
| 31 |
|
| 32 |
sub get_input_event() |
| 33 |
{ |
| 34 |
return 'init_input_handler'; |
| 35 |
} |
| 36 |
|
| 37 |
sub set_auth() |
| 38 |
{ |
| 39 |
my ($kernel, $heap, $self) = @_[KERNEL, HEAP, OBJECT]; |
| 40 |
|
| 41 |
my $node = POE::Filter::XML::Node->new('handshake'); |
| 42 |
my $config = $heap->config(); |
| 43 |
$node->appendText(sha1_hex($self->{'sid'}.$config->{'password'})); |
| 44 |
$kernel->post($heap->events(), +PCJ_AUTHNEGOTIATE); |
| 45 |
$kernel->yield('output_handler', $node, 1); |
| 46 |
return; |
| 47 |
} |
| 48 |
|
| 49 |
sub init_input_handler() |
| 50 |
{ |
| 51 |
my ($kernel, $heap, $self, $node) = @_[KERNEL, HEAP, OBJECT, ARG0]; |
| 52 |
|
| 53 |
given($node->nodeName()) |
| 54 |
{ |
| 55 |
when('handshake') |
| 56 |
{ |
| 57 |
my $config = $heap->config(); |
| 58 |
$kernel->post($heap->events(), +PCJ_AUTHSUCCESS); |
| 59 |
$kernel->post($heap->events(), +PCJ_READY); |
| 60 |
$heap->jid($config->{'hostname'}); |
| 61 |
$heap->relinquish_states(); |
| 62 |
|
| 63 |
} |
| 64 |
|
| 65 |
when('stream:stream') |
| 66 |
{ |
| 67 |
$self->{'sid'} = $node->getAttribute('id'); |
| 68 |
$kernel->yield('set_auth'); |
| 69 |
|
| 70 |
} |
| 71 |
|
| 72 |
default |
| 73 |
{ |
| 74 |
$heap->debug_message('Unknown state: ' . $node->toString()); |
| 75 |
$kernel->post($heap->events(), +PCJ_AUTHFAIL); |
| 76 |
} |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
1; |
| 81 |
|
| 82 |
__END__ |
| 83 |
|
| 84 |
=pod |
| 85 |
|
| 86 |
=head1 NAME |
| 87 |
|
| 88 |
POE::Component::Jabber::J14 |
| 89 |
|
| 90 |
=head1 SYNOPSIS |
| 91 |
|
| 92 |
PCJ::J14 is a Protocol implementation that connects as a service to a jabberd14 |
| 93 |
server. |
| 94 |
|
| 95 |
=head1 DESCRIPTION |
| 96 |
|
| 97 |
PCJ::J14 authenticates with the server backend using the method outlined in |
| 98 |
XEP-114 (Jabber Component Protocol) |
| 99 |
[http://www.xmpp.org/extensions/xep-0114.html] |
| 100 |
|
| 101 |
=head1 METHODS |
| 102 |
|
| 103 |
Please see PCJ::Protocol for what methods this class supports. |
| 104 |
|
| 105 |
=head1 EVENTS |
| 106 |
|
| 107 |
Listed below are the exported events that end up in PCJ's main session: |
| 108 |
|
| 109 |
=over 2 |
| 110 |
|
| 111 |
=item set_auth |
| 112 |
|
| 113 |
This event constructs and sends the <handshake/> element for authentication. |
| 114 |
|
| 115 |
=item init_input_handler |
| 116 |
|
| 117 |
This is out main entry point that PCJ uses to send us all of the input. It |
| 118 |
handles the authentication response. |
| 119 |
|
| 120 |
=back |
| 121 |
|
| 122 |
=head1 NOTES AND BUGS |
| 123 |
|
| 124 |
This only implements the jabber:component:accept namespace (ie. the component |
| 125 |
initiates the connection to the server). |
| 126 |
|
| 127 |
Also be aware that before this protocol was documented as an XEP, it was widely |
| 128 |
implemented with loose rules. I conform to this document. If there is a problem |
| 129 |
with the implementation against older server implementations, let me know. |
| 130 |
|
| 131 |
The underlying backend has changed this release to now use a new Node |
| 132 |
implementation based on XML::LibXML::Element. Please see POE::Filter::XML::Node |
| 133 |
documentation for the relevant API changes. |
| 134 |
|
| 135 |
=head1 AUTHOR |
| 136 |
|
| 137 |
Copyright (c) 2003-2009 Nicholas Perez. Distributed under the GPL. |
| 138 |
|
| 139 |
=cut |