| 1 | package AnyEvent::XMPP::SimpleConnection; | ||||||||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 3 | 1 | ▶ | no warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 4 | |||||||||||||||||||||
| 5 | 1 | ▶ | use AnyEvent; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | 1 | ▶ | use IO::Handle; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 7 | 1 | ▶ | use Encode; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | 1 | ▶ | use AnyEvent::Socket; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 9 | 1 | ▶ | use AnyEvent::Handle; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 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<AnyEvent::XMPP::Connection> 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 | 0 | ▶ | sub new { | ||||||||||||||||||
|
Subroutine
new: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 32 | 0 | my $this = shift; | |||||||||||||||||||
| 33 | 0 | ▶ | my $class = ref($this) || $this; | ||||||||||||||||||
|
Condition0%0/3
ref $this || $this
MC/DC0%0/2
ref $this || $this
ref $this
$this
Truth table0%0/3
A || B
A= ref $thisB= $this
| |||||||||||||||||||||
| 34 | my $self = { | ||||||||||||||||||||
| 35 | 0 | ▶ | disconnect_cb => sub {}, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | @_ | ||||||||||||||||||||
| 37 | 0 | }; | |||||||||||||||||||
| 38 | 0 | bless $self, $class; | |||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||
| 40 | } | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | ▶ | sub connect { | ||||||||||||||||||
|
Subroutine
connect: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 43 | 0 | my ($self, $host, $service, $timeout) = @_; | |||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | $self->{handle} | ||||||||||||||||||||
| 46 | 0 | ▶ | and return 1; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 0 | ▶ | $self->{handle} = tcp_connect $host, $service, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||||||||||
| 49 | 0 | my ($fh, $peerhost, $peerport) = @_; | |||||||||||||||||||
| 50 | |||||||||||||||||||||
| 51 | 0 | ▶ | unless ($fh) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 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 | 0 | ▶ | on_eof => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 65 | 0 | $self->disconnect ("EOF on connection to $self->{peer_host}:$self->{peer_port}: $!"); | |||||||||||||||||||
| 66 | }, | ||||||||||||||||||||
| 67 | autocork => 1, | ||||||||||||||||||||
| 68 | 0 | ▶ | on_error => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 69 | 0 | $self->disconnect ("Error on connection to $self->{peer_host}:$self->{peer_port}: $!"); | |||||||||||||||||||
| 70 | }, | ||||||||||||||||||||
| 71 | 0 | ▶ | on_read => sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 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 | 0 | ▶ | }, sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 83 | 0 | $timeout | |||||||||||||||||||
| 84 | 0 | }; | |||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | 0 | return 1; | |||||||||||||||||||
| 87 | } | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | 0 | ▶ | sub connected { | ||||||||||||||||||
|
Subroutine
connected: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 90 | # subclass responsibility | ||||||||||||||||||||
| 91 | } | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | 0 | ▶ | sub send_buffer_empty { | ||||||||||||||||||
|
Subroutine
send_buffer_empty: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 94 | # subclass responsibility | ||||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | 0 | ▶ | sub block_until_send_buffer_empty { | ||||||||||||||||||
|
Subroutine
block_until_send_buffer_empty: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 98 | # subclass responsibility | ||||||||||||||||||||
| 99 | } | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | 0 | ▶ | sub debug_wrote_data { | ||||||||||||||||||
|
Subroutine
debug_wrote_data: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 102 | # subclass responsibility | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | 0 | ▶ | sub end_sockets { | ||||||||||||||||||
|
Subroutine
end_sockets: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 106 | 0 | my ($self) = @_; | |||||||||||||||||||
| 107 | 0 | delete $self->{handle}; | |||||||||||||||||||
| 108 | } | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | 0 | ▶ | sub write_data { | ||||||||||||||||||
|
Subroutine
write_data: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 111 | 0 | my ($self, $data) = @_; | |||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | 0 | $self->{handle}->push_write (encode_utf8 ($data)); | |||||||||||||||||||
| 114 | 0 | $self->debug_wrote_data (encode_utf8 ($data)); | |||||||||||||||||||
| 115 | 0 | ▶ | $self->{handle}->on_drain (sub { | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 116 | 0 | $self->send_buffer_empty; | |||||||||||||||||||
| 117 | 0 | }); | |||||||||||||||||||
| 118 | } | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | 0 | ▶ | sub enable_ssl { | ||||||||||||||||||
|
Subroutine
enable_ssl: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 121 | 0 | my ($self) = @_; | |||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | 0 | $self->{handle}->starttls ('connect'); | |||||||||||||||||||
| 124 | 0 | $self->{ssl_enabled} = 1; | |||||||||||||||||||
| 125 | } | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | 0 | ▶ | sub disconnect { | ||||||||||||||||||
|
Subroutine
disconnect: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 128 | 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 | 1; | |||||||||||||||||||