| 1 | # SMB-Perl library, Copyright (C) 2014-2018 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::Command; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 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 | sub new ($$$$%) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 0 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | my $smb = shift || die "No smb parameter in $class constructor\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die("No smb parameter in $class constructor\n")
MC/DC0%0/1
shift() || die("No smb parameter in $class constructor\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | 0 | ▶ | my $name = shift || die "No name parameter in $class constructor\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die("No name parameter in $class constructor\n")
MC/DC0%0/1
shift() || die("No name parameter in $class constructor\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | ▶ | my $header = shift || die "No header parameter in $class constructor\n"; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die("No header parameter in $class constructor\n")
MC/DC0%0/1
shift() || die("No header parameter in $class constructor\n")
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 0 | my %options = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 0 | my $self = $class->SUPER::new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | %options, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | smb => $smb, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | name => $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | header => $header, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 0 | $self->init; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | sub is ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | my $name = shift || ''; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || ''
MC/DC0%0/1
shift() || ''
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 0 | return $self->name eq $name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | sub is_response ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_response: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | return $self->header->is_response; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | sub is_response_to ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_response_to: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $request = shift || die; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
shift() || die()
MC/DC0%0/1
shift() || die()
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 0 | my $header1 = $request->header; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 0 | my $header2 = $self->header; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | return | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 0 | ▶ | !$header1->is_response && | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/9
!$header1->is_response && $header2->is_response && $header1->code == $header2->code && $header1->mid == $header2->mid
not $header1->is_response and $header2->is_response and $header1->code == $header2->code
not $header1->is_response and $header2->is_response
MC/DC0%0/4
!$header1->is_response && $header2->is_response && $header1->code == $header2->code && $header1->mid == $header2->mid
not $header1->is_response
$header2->is_response
$header1->code == $header2->code
$header1->mid == $header2->mid
Truth table0%0/5
not(A) and B and C && D
A= not $header1->is_responseB= $header2->is_responseC= $header1->code == $header2->codeD= $header1->mid == $header2->mid
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | $header2->is_response && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | $header1->code == $header2->code && | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $header1->mid == $header2->mid; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub is_smb1 ($) { $_[0]->smb <= 1 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_smb1: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub is_smb2 ($) { $_[0]->smb >= 2 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_smb2: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub status ($) { $_[0]->header->status } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | ▶ | sub set_status ($$) { $_[0]->header->status($_[1]); } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set_status: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub is_success ($) { $_[0]->status == 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_success: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | ▶ | sub is_error ($) { $_[0]->status != 0 } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
is_error: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | my %STATUS_NAMES = do { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | map { "SMB::$_"->() => $_ } grep /^STATUS_/, keys %SMB:: | |||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | sub status_name ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $status = $_[0]->header->status; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
status_name: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | return $STATUS_NAMES{$status} || sprintf "%x", $status; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$STATUS_NAMES{$status} || sprintf('%x', $status)
MC/DC0%0/2
$STATUS_NAMES{$status} || sprintf('%x', $status)
$STATUS_NAMES{$status}
sprintf('%x', $status)
Truth table0%0/3
A || B
A= $STATUS_NAMES{$status}B= sprintf('%x', $status)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | # stub methods to be overloaded | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | sub parse ($$%) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | my $parser = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub pack ($$%) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
pack: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $packer = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | ▶ | sub init ($) { | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | # end of stub methods | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | sub set ($%) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | my %values = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 0 | $self->{$_} = $values{$_} for keys %values; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | sub abort_pack ($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
abort_pack: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 0 | my $packer = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | my $status = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->set_status($status); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $packer->jump('status')->uint32($status)->jump('command-start'); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | sub to_string ($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_string: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | ▶ | return sprintf "SMB%d [%s %s] mid=%u uid=%x tid=%02x%s", | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | $self->smb, $self->name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | $self->is_response ? "Response" : "Request ", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | $self->header->mid, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | $self->header->uid, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | $self->header->tid, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | $self->status ? sprintf " status=%x", $self->status : '', | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||