blib/lib/SMB/v2/Command/Write.pm untested

filter: Statementstmt 0.0% 0 / 39 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 4 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 57 SCAR 24.8
CC
3
Cov
0%
parse
6.0
pack
6.0
init
2.0
CRAP 12.0
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::v2::Command::Write;
17  
18 use strict;
19 use warnings;
20  
21 use parent 'SMB::v2::Command';
22  
23 use constant {
24 FLAGS_WRITE_THROUGH => 1, # SMB 3.*
25 FLAGS_WRITE_UNBUFFERED => 2, # SMB 3.02
26  
27 CHANNEL_NONE => 0,
28 CHANNEL_RDMA_V1 => 1, # SMB 3.*
29 CHANNEL_RDMA_V1_INVALIDATE => 2, # SMB 3.02
30 };
31  
32 sub init ($) {
33 $_[0]->set(
34 flags => 0,
35 offset => 0,
36 length => 0,
37 channel => 0,
38 remaining_bytes => 0,
39 fid => 0,
40 openfile => undef,
41 buffer => undef,
42 )
43 }
44  
45 sub parse ($$) {
46 my $self = shift;
47 my $parser = shift;
48  
49 if ($self->is_response) {
50 $parser->uint16; # reserved
51 $self->length($parser->uint32);
52 $self->remaining_bytes($parser->uint32);
53 $parser->uint16; # channel info offset
54 $parser->uint16; # channel info length
55 } else {
56 my $offset = $parser->uint16;
57 my $length = $parser->uint32;
58 $self->length($length);
59 $self->offset($parser->uint64);
60 $self->fid($parser->fid2);
61 $self->channel($parser->uint32);
62 $self->remaining_bytes($parser->uint32);
63 $parser->uint16; # channel info offset
64 $parser->uint16; # channel info length
65 $self->flags($parser->uint32);
66 $self->buffer($parser->bytes($length));
67 }
68  
69 return $self;
70 }
71  
72 sub pack ($$) {
73 my $self = shift;
74 my $packer = shift;
75  
76 if ($self->is_response) {
77 $packer
78 ->uint16(0) # reserved
79 ->uint32($self->length)
80 ->uint32($self->remaining_bytes)
81 ->uint16(0) # channel info offset
82 ->uint16(0) # channel info length
83 ;
84 } else {
85 my $buffer = $self->buffer // die "No buffer";
86  
87 $packer
88 ->stub('data-offset', 'uint16')
89 ->uint32(length($buffer))
90 ->uint64($self->offset)
91 ->fid2($self->fid || die "No fid set")
92 ->uint32($self->channel)
93 ->uint32($self->remaining_bytes)
94 ->uint16(0) # channel info offset
95 ->uint16(0) # channel info length
96 ->uint32($self->flags)
97 ->fill('data-offset', $packer->diff('smb-header'))
98 ->bytes($self->buffer)
99 ;
100 }
101 }
102  
103 1;