line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package AnyEvent::XMPP::SimpleConnection; |
2
|
1
|
|
|
1
|
|
2034
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
8
|
no warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use AnyEvent; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
18
|
|
6
|
1
|
|
|
1
|
|
1227
|
use IO::Handle; |
|
1
|
|
|
|
|
8176
|
|
|
1
|
|
|
|
|
57
|
|
7
|
1
|
|
|
1
|
|
9
|
use Encode; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
100
|
|
8
|
1
|
|
|
1
|
|
1087
|
use AnyEvent::Socket; |
|
1
|
|
|
|
|
17561
|
|
|
1
|
|
|
|
|
171
|
|
9
|
1
|
|
|
1
|
|
1485
|
use AnyEvent::Handle; |
|
1
|
|
|
|
|
8797
|
|
|
1
|
|
|
|
|
657
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
AnyEvent::XMPP::SimpleConnection - Low level TCP/TLS connection |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 SYNOPSIS |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
package foo; |
18
|
|
|
|
|
|
|
use AnyEvent::XMPP::SimpleConnection; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our @ISA = qw/AnyEvent::XMPP::SimpleConnection/; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
This module only implements the basic low level socket and SSL handling stuff. |
25
|
|
|
|
|
|
|
It is used by L and you shouldn't mess with it :-) |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
(NOTE: This is the part of AnyEvent::XMPP which I feel least confident about :-) |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub new { |
32
|
0
|
|
|
0
|
0
|
|
my $this = shift; |
33
|
0
|
|
0
|
|
|
|
my $class = ref($this) || $this; |
34
|
|
|
|
|
|
|
my $self = { |
35
|
0
|
|
|
0
|
|
|
disconnect_cb => sub {}, |
36
|
|
|
|
|
|
|
@_ |
37
|
0
|
|
|
|
|
|
}; |
38
|
0
|
|
|
|
|
|
bless $self, $class; |
39
|
0
|
|
|
|
|
|
return $self; |
40
|
|
|
|
|
|
|
} |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
sub connect { |
43
|
0
|
|
|
0
|
0
|
|
my ($self, $host, $service, $timeout) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
$self->{handle} |
46
|
|
|
|
|
|
|
and return 1; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
$self->{handle} = tcp_connect $host, $service, sub { |
49
|
0
|
|
|
0
|
|
|
my ($fh, $peerhost, $peerport) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
0
|
|
|
|
|
unless ($fh) { |
52
|
0
|
|
|
|
|
|
$self->disconnect ("Couldn't create socket to $host:$service: $!"); |
53
|
0
|
|
|
|
|
|
return; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
0
|
|
|
|
|
|
$self->{peer_host} = $peerhost; |
57
|
0
|
|
|
|
|
|
$self->{peer_port} = $peerport; |
58
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
binmode $fh, ":raw"; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
$self->{handle} = |
62
|
|
|
|
|
|
|
AnyEvent::Handle->new ( |
63
|
|
|
|
|
|
|
fh => $fh, |
64
|
|
|
|
|
|
|
on_eof => sub { |
65
|
0
|
|
|
|
|
|
$self->disconnect ("EOF on connection to $self->{peer_host}:$self->{peer_port}: $!"); |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
autocork => 1, |
68
|
|
|
|
|
|
|
on_error => sub { |
69
|
0
|
|
|
|
|
|
$self->disconnect ("Error on connection to $self->{peer_host}:$self->{peer_port}: $!"); |
70
|
|
|
|
|
|
|
}, |
71
|
|
|
|
|
|
|
on_read => sub { |
72
|
0
|
|
|
|
|
|
my ($hdl) = @_; |
73
|
0
|
|
|
|
|
|
my $data = $hdl->rbuf; |
74
|
0
|
|
|
|
|
|
$hdl->rbuf = ''; |
75
|
0
|
|
|
|
|
|
$data = decode_utf8 $data; |
76
|
0
|
|
|
|
|
|
$self->handle_data (\$data); |
77
|
|
|
|
|
|
|
}, |
78
|
0
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
$self->connected |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
}, sub { |
83
|
0
|
|
|
0
|
|
|
$timeout |
84
|
0
|
|
|
|
|
|
}; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
return 1; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
0
|
|
|
0
|
0
|
|
sub connected { |
90
|
|
|
|
|
|
|
# subclass responsibility |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
0
|
0
|
|
sub send_buffer_empty { |
94
|
|
|
|
|
|
|
# subclass responsibility |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
0
|
|
|
0
|
0
|
|
sub block_until_send_buffer_empty { |
98
|
|
|
|
|
|
|
# subclass responsibility |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
0
|
0
|
|
sub debug_wrote_data { |
102
|
|
|
|
|
|
|
# subclass responsibility |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub end_sockets { |
106
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
107
|
0
|
|
|
|
|
|
delete $self->{handle}; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub write_data { |
111
|
0
|
|
|
0
|
0
|
|
my ($self, $data) = @_; |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
$self->{handle}->push_write (encode_utf8 ($data)); |
114
|
0
|
|
|
|
|
|
$self->debug_wrote_data (encode_utf8 ($data)); |
115
|
|
|
|
|
|
|
$self->{handle}->on_drain (sub { |
116
|
0
|
|
|
0
|
|
|
$self->send_buffer_empty; |
117
|
0
|
|
|
|
|
|
}); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub enable_ssl { |
121
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
0
|
|
|
|
|
|
$self->{handle}->starttls ('connect'); |
124
|
0
|
|
|
|
|
|
$self->{ssl_enabled} = 1; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub disconnect { |
128
|
0
|
|
|
0
|
0
|
|
my ($self, $msg) = @_; |
129
|
0
|
|
|
|
|
|
$self->end_sockets; |
130
|
0
|
|
|
|
|
|
$self->{disconnect_cb}->($self->{peer_host}, $self->{peer_port}, $msg); |
131
|
0
|
|
|
|
|
|
$self->remove_all_callbacks; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
1; |