File Coverage

lib/SMB/v2/Command/Close.pm
Criterion Covered Total %
statement 12 36 33.3
branch 0 22 0.0
condition 0 11 0.0
subroutine 4 7 57.1
pod 0 3 0.0
total 16 79 20.2


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::v2::Command::Close;
17              
18 1     1   5 use strict;
  1         1  
  1         22  
19 1     1   3 use warnings;
  1         2  
  1         20  
20              
21 1     1   3 use parent 'SMB::v2::Command';
  1         1  
  1         5  
22              
23             use constant {
24 1         316 FLAGS_POSTQUERY_ATTRIB => 1,
25 1     1   46 };
  1         1  
26              
27             sub init ($) {
28 0     0 0   $_[0]->set(
29             flags => 0,
30             fid => 0,
31             openfile => undef,
32             )
33             }
34              
35             sub parse ($$) {
36 0     0 0   my $self = shift;
37 0           my $parser = shift;
38              
39 0 0         if ($self->is_response) {
40 0           my $openfile = $self->openfile;
41 0   0       my $file = $openfile && $openfile->file;
42              
43 0           $self->flags($parser->uint16);
44 0           $parser->uint32; # reserved
45 0           my @values = ((map { $parser->uint64 } 1 .. 6), $parser->uint32);
  0            
46 0 0         $file->update(@values) if $file;
47             } else {
48 0           $self->flags($parser->uint16);
49 0           $parser->uint32; # reserved
50 0           $self->fid($parser->fid2);
51             }
52              
53 0           return $self;
54             }
55              
56             sub pack ($$) {
57 0     0 0   my $self = shift;
58 0           my $packer = shift;
59              
60 0 0         if ($self->is_response) {
61 0           my $openfile = $self->openfile;
62 0   0       my $file = $openfile && $openfile->file;
63              
64 0 0 0       return $self->abort_pack($packer, SMB::STATUS_FILE_CLOSED)
65             unless $file && $file->exists;
66              
67 0           my $skip_attr = !($self->flags & FLAGS_POSTQUERY_ATTRIB);
68              
69 0 0         $packer
    0          
    0          
    0          
    0          
    0          
    0          
70             ->uint16($self->flags)
71             ->uint32(0) # reserved
72             ->uint64($skip_attr ? 0 : $file->creation_time)
73             ->uint64($skip_attr ? 0 : $file->last_access_time)
74             ->uint64($skip_attr ? 0 : $file->last_write_time)
75             ->uint64($skip_attr ? 0 : $file->change_time)
76             ->uint64($skip_attr ? 0 : $file->allocation_size)
77             ->uint64($skip_attr ? 0 : $file->end_of_file)
78             ->uint32($skip_attr ? 0 : $file->attributes)
79             ;
80             } else {
81 0   0       $packer
82             ->uint16($self->flags)
83             ->uint32(0) # reserved
84             ->fid2($self->fid || die "No fid set")
85             ;
86             }
87             }
88              
89             1;