Debian Codegraph @

lib/POE/Component/Jabber/Legacy.pm

raw symbols ◀ ▶ SCIP
3 Debian patches touch this file
1 package POE::Component::Jabber::Legacyscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/;
2 use warningsscip-perl cpan POE-Component-Jabber 3 warnings/;
3 use strictscip-perl cpan POE-Component-Jabber 3 strict/;
4
5 use 5.010scip-perl cpan POE-Component-Jabber 3 `5.010`/;
•6 no if $] >= 5.017011, warnings => 'experimental::smartmatch';
7 no if $] >= 5.037010, warnings => 'deprecated::smartmatch';
8 use POEscip-perl cpan POE-Component-Jabber 3 POE/;
9 use POE::Component::Jabber::Eventsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Events/;
10 use POE::Filter::XMLscip-perl cpan POE-Component-Jabber 3 POE/Filter/XML/;
11 use POE::Filter::XML::Nodescip-perl cpan POE-Component-Jabber 3 POE/Filter/XML/Node/;
12 use POE::Filter::XML::NSscip-perl cpan POE-Component-Jabber 3 POE/Filter/XML/NS/ qw/ :JABBER :IQ /;
•13 use Digest::SHAscip-perl cpan POE-Component-Jabber 3 Digest/SHA/ qw/ sha1_hex /;
14
15 use basescip-perl cpan POE-Component-Jabber 3 base/('POE::Component::Jabber::Protocol');
16
17 our $VERSIONscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/$VERSION. = '3.00';
18
19 sub get_versionscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/get_version().()
20 {
21 return '0.9';
22 }
23
24 sub get_xmlnsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/get_xmlns().()
25 {
26 return +NS_JABBER_CLIENT;
27 }
28
29 sub get_statesscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/get_states().()
30 {
31 return [ 'set_auth', 'init_input_handler' ];
32 }
33
34 sub get_input_eventscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/get_input_event().()
35 {
36 return 'init_input_handler';
37 }
38
39 sub set_authscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/set_auth().()
40 {
41 my ($kernel, $heap) = @_scip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/`@_`.[KERNEL, HEAP];
42
43 my $config = $heap->configscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/config().();
44 my $node = POE::Filter::XML::Node->newscip-perl cpan POE-Component-Jabber 3 POE/Filter/XML/Node/new().('iq', ['type', +IQ_SET, 'id', 'AUTH']);
45 my $query = $node->appendChildscip-perl cpan POE-Component-Jabber 3 POE/Filter/XML/Node/appendChild().('query', ['xmlns', +NS_JABBER_AUTH]);
46
47 $query->appendChildscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendChild().('username')->appendTextscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendText().($config->{'username'});
48
49 if($config->{'plaintext'})
50 {
51 $query->appendChildscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendChild().('password')->appendTextscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendText().($config->{'password'});
52
53 } else {
54
55 my $hashed = sha1_hexscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/sha1_hex().($heap->sidscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/sid().().$config->{'password'});
56
57 $query->appendChildscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendChild().('digest')->appendTextscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendText().($hashed);
58 }
59
60 $query->appendChildscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendChild().('resource')->appendTextscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/appendText().($config->{'resource'});
61
62 $kernel->yieldscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/yield().('output_handler', $node, 1);
63
64 $heap->jidscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/jid().($config->{'username'} . '@' . $config->{'hostname'} . '/' .
65 $config->{'resource'});
66
67 return;
68 }
69
70 sub init_input_handlerscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/init_input_handler().()
71 {
72 my ($kernel, $heap, $node) = @_scip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/`@_`.[KERNEL, HEAP, ARG0];
73
74 my $config = $heap->configscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/config().();
75
76 if ($config->{'debug'})
77 {
78 $heap->debug_messagescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/debug_message().( "Recd: ".$node->toStringscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/toString().() );
79 }
80
81 given($node->nodeNamescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/nodeName().())
82 {
83 when('stream:stream')
84 {
85 $heap->sidscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/sid().($node->getAttributescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/getAttribute().('id'));
86 $kernel->yieldscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/yield().('set_auth');
87 $kernel->postscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/post().($heap->eventsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/events().(), +PCJ_AUTHNEGOTIATE);
88
89 }
90 when('iq')
91 {
92 given([$node->getAttributescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/getAttribute().('type'), $node->getAttributescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/getAttribute().('id')])
93 {
94 when([+IQ_RESULT, 'AUTH'])
95 {
96 $heap->relinquish_statesscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/relinquish_states().();
97 $kernel->postscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/post().($heap->eventsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/events().(), +PCJ_AUTHSUCCESS);
98 $kernel->postscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/post().($heap->eventsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/events().(), +PCJ_READY);
99
100 }
101 when([+IQ_ERROR, 'AUTH']) {
102
103 $heap->debug_messagescip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/debug_message().('Authentication Failed');
104 $kernel->yieldscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/yield().('shutdown');
105 $kernel->postscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/post().($heap->eventsscip-perl cpan POE-Component-Jabber 3 POE/Component/Jabber/Legacy/events().(), +PCJ_AUTHFAIL);
106 }
107 }
108 }
109 }
110
111 return;
112 }
113
114 1;
115
116 __END__
117
118 =pod
119
120 =head1 NAME
121
•122 POE::Component::Jabber::Legacy - connect using the pre-XMPP Jabber protocol
123
124 =head1 SYNOPSIS
125
126 PCJ::Legacy is a Protocol implementation for the legacy (ie. Pre-XMPP) Jabber
127 protocol.
128
129 =head1 DESCRIPTION
130
131 PCJ::Legacy implements the simple iq:auth authentication mechanism defined in
132 the deprecated XEP at http://www.xmpp.org/extensions/xep-0078.html. This
133 Protocol class is mainly used for connecting to legacy jabber servers that do
134 not conform the to XMPP1.0 RFC.
135
136 =head1 METHODS
137
138 Please see PCJ::Protocol for what methods this class supports.
139
140 =head1 EVENTS
141
142 Listed below are the exported events that end up in PCJ's main session:
143
144 =over 2
145
146 =item set_auth
147
148 This handles construction and sending of the iq:auth query.
149
150 =item init_input_handler
151
152 This is our main entry point. This is used by PCJ to deliver all input events
153 until we are finished. Also handles responses to authentication.
154
155 =back
156
157 =head1 NOTES AND BUGS
158
159 Ideally, this class wouldn't be necessary, but there is a large unmoving mass
160 of entrenched users and administrators that refuse to migrate to XMPP. It
161 largely doesn't help that debian still ships jabberd 1.4.3 which does NOT
162 support XMPP.
163
164 The underlying backend has changed this release to now use a new Node
165 implementation based on XML::LibXML::Element. Please see POE::Filter::XML::Node
166 documentation for the relevant API changes.
167
168 =head1 AUTHOR
169
170 Copyright (c) 2003-2009 Nicholas Perez. Distributed under the GPL.
171
172 =cut