File Coverage

lib/SMB/Command.pm
Criterion Covered Total %
statement 12 61 19.6
branch 0 4 0.0
condition 0 16 0.0
subroutine 4 24 16.6
pod 1 20 5.0
total 17 125 13.6


line stmt bran cond sub pod time code
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 .
15              
16             package SMB::Command;
17              
18 2     2   813 use strict;
  2         6  
  2         54  
19 2     2   9 use warnings;
  2         3  
  2         66  
20              
21 2     2   12 use parent 'SMB';
  2         3  
  2         12  
22              
23             sub new ($$$$%) {
24 0     0 1   my $class = shift;
25 0   0       my $smb = shift || die "No smb parameter in $class constructor\n";
26 0   0       my $name = shift || die "No name parameter in $class constructor\n";
27 0   0       my $header = shift || die "No header parameter in $class constructor\n";
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     0 0   my $self = shift;
44 0   0       my $name = shift || '';
45              
46 0           return $self->name eq $name;
47             }
48              
49             sub is_response ($) {
50 0     0 0   my $self = shift;
51              
52 0           return $self->header->is_response;
53             }
54              
55             sub is_response_to ($$) {
56 0     0 0   my $self = shift;
57 0   0       my $request = shift || die;
58              
59 0           my $header1 = $request->header;
60 0           my $header2 = $self->header;
61              
62             return
63 0   0       !$header1->is_response &&
64             $header2->is_response &&
65             $header1->code == $header2->code &&
66             $header1->mid == $header2->mid;
67             }
68              
69 0     0 0   sub is_smb1 ($) { $_[0]->smb <= 1 }
70 0     0 0   sub is_smb2 ($) { $_[0]->smb >= 2 }
71              
72 0     0 0   sub status ($) { $_[0]->header->status }
73 0     0 0   sub set_status ($$) { $_[0]->header->status($_[1]); }
74 0     0 0   sub is_success ($) { $_[0]->status == 0 }
75 0     0 0   sub is_error ($) { $_[0]->status != 0 }
76              
77             my %STATUS_NAMES = do {
78 2     2   1075 no strict 'refs';
  2         5  
  2         1089  
79             map { "SMB::$_"->() => $_ } grep /^STATUS_/, keys %SMB::
80             };
81              
82             sub status_name ($) {
83 0     0 0   my $status = $_[0]->header->status;
84              
85 0   0       return $STATUS_NAMES{$status} || sprintf "%x", $status;
86             }
87              
88             # stub methods to be overloaded
89              
90             sub parse ($$%) {
91 0     0 0   my $self = shift;
92 0           my $parser = shift;
93              
94 0           return $self;
95             }
96              
97             sub pack ($$%) {
98 0     0 0   my $self = shift;
99 0           my $packer = shift;
100              
101 0           return $self;
102             }
103              
104             sub abort_pack ($$) {
105 0     0 0   my $self = shift;
106 0           my $packer = shift;
107 0           my $status = shift;
108              
109 0           return $self;
110             }
111              
112             sub has_next_in_chain ($) {
113 0     0 0   my $self = shift;
114              
115 0           return 0;
116             }
117              
118             sub is_fid_unset ($$) {
119 0     0 0   my $self = shift;
120 0           my $fid = shift;
121              
122 0           return 0;
123             }
124              
125             sub is_fid_null ($$) {
126 0     0 0   my $self = shift;
127 0           my $fid = shift;
128              
129 0           return 0;
130             }
131              
132       0 0   sub init ($) {
133             }
134              
135             # end of stub methods
136              
137             sub set ($%) {
138 0     0 0   my $self = shift;
139 0           my %values = @_;
140              
141 0           $self->{$_} = $values{$_} for keys %values;
142             }
143              
144             sub to_string ($) {
145 0     0 0   my $self = shift;
146              
147 0 0         return sprintf "SMB%d [%s %s] mid=%u uid=%x tid=%02x%s",
    0          
148             $self->smb, $self->name,
149             $self->is_response ? "Response" : "Request ",
150             $self->header->mid,
151             $self->header->uid,
152             $self->header->tid,
153             $self->status ? sprintf " status=%x", $self->status : '',
154             }
155              
156             1;