File Coverage

blib/lib/AnyEvent/XMPP/Component.pm
Criterion Covered Total %
statement 4 6 66.6
branch n/a
condition n/a
subroutine 2 2 100.0
pod n/a
total 6 8 75.0


line stmt bran cond sub pod time code
1             package AnyEvent::XMPP::Component;
2 2     2   30031 use strict;
  2         4  
  2         65  
3 2     2   621 use AnyEvent::XMPP::Connection;
  0            
  0            
4             use AnyEvent::XMPP::Namespaces qw/xmpp_ns/;
5             our @ISA = qw/AnyEvent::XMPP::Connection/;
6              
7             =head1 NAME
8              
9             AnyEvent::XMPP::Component - "XML" stream that implements the XEP-0114
10              
11             =head1 SYNOPSIS
12              
13             use AnyEvent::XMPP::Component;
14              
15             my $con = AnyEvent::XMPP::Component->new (
16             domain => 'chat.jabber.org'
17             host => 'jabber.org',
18             port => 5347,
19             secret => 'insecurepasswordforthehackers'
20             );
21             $con->reg_cb (session_ready => sub { ... });
22             $con->connect;
23              
24             =head1 DESCRIPTION
25              
26             This module represents a XMPP connection to a server that authenticates as
27             component.
28              
29             This module is a subclass of C and inherits all methods.
30             For example C and the stanza sending routines.
31              
32             For additional events that can be registered to look below in the EVENTS section.
33              
34             Please note that for component several functionality in L
35             might have no effect or not the desired effect. Basically you should
36             use the L as component and only handle events
37             the handle with incoming data. And only use functions that send stanzas.
38              
39             No effect has the event C and the C
40             method of L, because those handle the usual SASL or iq-auth
41             authentication. "Jabber" components have a completly different authentication
42             mechanism.
43              
44             Also note that the support for some XEPs in L is just thought
45             for client side usage, if you miss any functionaly don't hesitate to ask the
46             author or send him a patch! (See L for contact information).
47              
48             =head1 METHODS
49              
50             =over 4
51              
52             =item B
53              
54             This is the constructor. It takes the same arguments as
55             the constructor of L along with a
56             few others:
57              
58             B: Please note that some arguments that L
59             usually takes have no effect when using this class. (That would be
60             the 'username', 'password', 'resource' and 'jid' arguments for example.)
61              
62             =over 4
63              
64             =item secret => $secret
65              
66             C<$secret> is the secret that will be used for authentication with the server.
67              
68             =back
69              
70             =cut
71              
72             sub new {
73             my $this = shift;
74             my $class = ref($this) || $this;
75              
76             my %args = @_;
77              
78             unless (exists $args{initial_presence}) {
79             $args{stream_namespace} = 'component';
80             }
81            
82             $args{host} ||= delete $args{server};
83             $args{host}
84             or die "Required 'host' argument missing to new for this component!";
85              
86             unless (defined $args{port}) {
87             $args{port} = 5347;
88             }
89              
90             my $self = $class->SUPER::new (%args);
91              
92             $self->{parser}->set_stream_cb (sub {
93             my $secret = $self->{parser}->{parser}->xml_escape ($self->{secret});
94             my $id = $self->{stream_id} = $_[0]->attr ('id');
95             $self->{writer}->send_handshake ($id, $secret);
96             });
97              
98             $self->reg_cb (recv_stanza_xml => sub {
99             my ($self, $node) = @_;
100             if ($node->eq (component => 'handshake')) {
101             $self->{authenticated} = 1;
102             $self->event ('session_ready');
103             }
104             },
105             stream_pre_authentication => sub {
106             my ($self, $rcon) = @_;
107             $$rcon = 0;
108             });
109              
110             $self
111             }
112              
113             sub default_namespace {
114             return 'component';
115             }
116              
117             sub authenticate {
118             warn "authenticate called! Please read the documentation of "
119             ."AnyEvent::XMPP::Component why this is an error!"
120             }
121              
122             =back
123              
124             =head1 EVENTS
125              
126             These additional events can be registered on with C:
127              
128             NOTE: The event C should _not_ be handled
129             and just ignored. Don't attach callbacks to it!
130              
131             =over 4
132              
133             =item session_ready
134              
135             This event indicates that the component has connected successfully
136             and can now be used to transmit stanzas.
137              
138             =back
139              
140             =head1 AUTHOR
141              
142             Robin Redeker, C<< >>, JID: C<< >>
143              
144             =head1 COPYRIGHT & LICENSE
145              
146             Copyright 2007, 2008 Robin Redeker, all rights reserved.
147              
148             This program is free software; you can redistribute it and/or modify it
149             under the same terms as Perl itself.
150              
151             =cut
152              
153             1; # End of AnyEvent::XMPP::Component