Debian Codegraph @

lib/POE/Component/Jabber/J14.pm

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