| 1 | # SMB Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||
| 12 | # | ||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | package SMB::Agent; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 1 | ▶ | use parent 'SMB'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 1 | ▶ | use SMB::Connection; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 1 | ▶ | use SMB::Auth; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | 1 | ▶ | use IO::Socket; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 26 | 1 | ▶ | use IO::Select; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | sub new ($%) { | ||||||||||||||||||||
| 29 | 0 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||
| 30 | 0 | my %options = @_; | |||||||||||||||||||
| 31 | |||||||||||||||||||||
| 32 | 0 | ▶ | $options{quiet} ||= 0; | ||||||||||||||||||
|
Condition0%0/2
$options{"quiet"} ||= 0
MC/DC0%0/1
$options{"quiet"} ||= 0
$options{"quiet"}
Truth table0%0/2
A
A= $options{"quiet"}
| |||||||||||||||||||||
| 33 | 0 | ▶ | $options{verbose} ||= 0; | ||||||||||||||||||
|
Condition0%0/2
$options{"verbose"} ||= 0
MC/DC0%0/1
$options{"verbose"} ||= 0
$options{"verbose"}
Truth table0%0/2
A
A= $options{"verbose"}
| |||||||||||||||||||||
| 34 | 0 | ▶ | $options{unique_conn_addr} ||= 0; | ||||||||||||||||||
|
Condition0%0/2
$options{"unique_conn_addr"} ||= 0
MC/DC0%0/1
$options{"unique_conn_addr"} ||= 0
$options{"unique_conn_addr"}
Truth table0%0/2
A
A= $options{"unique_conn_addr"}
| |||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | my $self = $class->SUPER::new( | |||||||||||||||||||
| 37 | %options, | ||||||||||||||||||||
| 38 | socket_pool => IO::Select->new, | ||||||||||||||||||||
| 39 | connections => {}, | ||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 0 | return $self; | |||||||||||||||||||
| 43 | } | ||||||||||||||||||||
| 44 | |||||||||||||||||||||
| 45 | sub get_connection_key ($$) { | ||||||||||||||||||||
| 46 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_connection_key: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 47 | 0 | my $socket = shift; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | 0 | ▶ | return $self->unique_conn_addr | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 50 | ? SMB::Connection->get_socket_addr($socket) | ||||||||||||||||||||
| 51 | : $socket->fileno; | ||||||||||||||||||||
| 52 | } | ||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | sub get_connection ($$) { | ||||||||||||||||||||
| 55 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
get_connection: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 56 | 0 | my $socket = shift; | |||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 0 | ▶ | my $key = $self->get_connection_key($socket) | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 59 | or return; | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | 0 | return $self->connections->{$key}; | |||||||||||||||||||
| 62 | } | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | sub add_connection ($$$%) { | ||||||||||||||||||||
| 65 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
add_connection: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 66 | 0 | my $socket = shift; | |||||||||||||||||||
| 67 | 0 | my $id = shift; | |||||||||||||||||||
| 68 | 0 | my %options = @_; | |||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | 0 | my $key = $self->get_connection_key($socket); | |||||||||||||||||||
| 71 | 0 | ▶ | return $self->connections->{$key} if $self->connections->{$key}; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 72 | |||||||||||||||||||||
| 73 | 0 | ▶ | $options{auth} //= SMB::Auth->new; | ||||||||||||||||||
|
Condition0%0/3
$options{"auth"} //= "SMB::Auth"->new
MC/DC0%0/2
$options{"auth"} //= "SMB::Auth"->new
$options{"auth"}
"SMB::Auth"->new
Truth table0%0/3
A //= B
A= $options{"auth"}B= "SMB::Auth"->new
| |||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | 0 | ▶ | my $connection = SMB::Connection->new( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 76 | $socket, $id, | ||||||||||||||||||||
| 77 | quiet => $self->quiet, | ||||||||||||||||||||
| 78 | verbose => $self->verbose, | ||||||||||||||||||||
| 79 | %options, | ||||||||||||||||||||
| 80 | ) or return; | ||||||||||||||||||||
| 81 | 0 | $self->socket_pool->add($socket); | |||||||||||||||||||
| 82 | 0 | $self->connections->{$key} = $connection; | |||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | 0 | ▶ | return wantarray ? ($key, $connection) : $connection; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | sub delete_connection ($$) { | ||||||||||||||||||||
| 88 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
delete_connection: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 89 | 0 | ▶ | my $connection = shift || return; | ||||||||||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | 0 | my $socket = $connection->socket; | |||||||||||||||||||
| 92 | 0 | $self->socket_pool->remove($socket); | |||||||||||||||||||
| 93 | 0 | delete $self->connections->{$self->get_connection_key($socket)}; | |||||||||||||||||||
| 94 | 0 | $connection->close; | |||||||||||||||||||
| 95 | } | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | sub delete_all_connections ($$) { | ||||||||||||||||||||
| 98 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
delete_all_connections: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | 0 | for (values %{$self->connections}) { | |||||||||||||||||||
| 101 | 0 | $self->delete_connection($_); | |||||||||||||||||||
| 102 | } | ||||||||||||||||||||
| 103 | } | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | sub DESTROY ($) { | ||||||||||||||||||||
| 106 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
DESTROY: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | 0 | $self->delete_all_connections; | |||||||||||||||||||
| 109 | } | ||||||||||||||||||||
| 110 | |||||||||||||||||||||
| 111 | 1 | 1; | |||||||||||||||||||