line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# $Id: Attributes.pm,v 1.5 2001/05/16 01:38:01 btrott Exp $ |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
package Net::SFTP::Attributes; |
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
49
|
|
5
|
|
|
|
|
|
|
|
6
|
2
|
|
|
2
|
|
9
|
use Net::SFTP::Constants qw( :att ); |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
9
|
|
7
|
2
|
|
|
2
|
|
618
|
use Net::SFTP::Buffer; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use vars qw( @FIELDS ); |
10
|
|
|
|
|
|
|
@FIELDS = qw( flags size uid gid perm atime mtime ); |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
for my $f (@FIELDS) { |
13
|
|
|
|
|
|
|
no strict 'refs'; |
14
|
|
|
|
|
|
|
*$f = sub { |
15
|
|
|
|
|
|
|
my $a = shift; |
16
|
|
|
|
|
|
|
$a->{$f} = shift if @_; |
17
|
|
|
|
|
|
|
$a->{$f}; |
18
|
|
|
|
|
|
|
}; |
19
|
|
|
|
|
|
|
} |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub new { |
22
|
|
|
|
|
|
|
my $class = shift; |
23
|
|
|
|
|
|
|
my $a = bless { }, $class; |
24
|
|
|
|
|
|
|
$a->init(@_); |
25
|
|
|
|
|
|
|
} |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub init { |
28
|
|
|
|
|
|
|
my $a = shift; |
29
|
|
|
|
|
|
|
my %param = @_; |
30
|
|
|
|
|
|
|
for my $f (@FIELDS) { |
31
|
|
|
|
|
|
|
$a->{$f} = 0; |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
if (my $stat = $param{Stat}) { |
34
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_SIZE; |
35
|
|
|
|
|
|
|
$a->{size} = $stat->[7]; |
36
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_UIDGID; |
37
|
|
|
|
|
|
|
$a->{uid} = $stat->[4]; |
38
|
|
|
|
|
|
|
$a->{gid} = $stat->[5]; |
39
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_PERMISSIONS; |
40
|
|
|
|
|
|
|
$a->{perm} = $stat->[2]; |
41
|
|
|
|
|
|
|
$a->{flags} |= SSH2_FILEXFER_ATTR_ACMODTIME; |
42
|
|
|
|
|
|
|
$a->{atime} = $stat->[8]; |
43
|
|
|
|
|
|
|
$a->{mtime} = $stat->[9]; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (my $buf = $param{Buffer}) { |
46
|
|
|
|
|
|
|
$a->{flags} = $buf->get_int32; |
47
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) { |
48
|
|
|
|
|
|
|
$a->{size} = $buf->get_int64; |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) { |
51
|
|
|
|
|
|
|
$a->{uid} = $buf->get_int32; |
52
|
|
|
|
|
|
|
$a->{gid} = $buf->get_int32; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
55
|
|
|
|
|
|
|
$a->{perm} = $buf->get_int32; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) { |
58
|
|
|
|
|
|
|
$a->{atime} = $buf->get_int32; |
59
|
|
|
|
|
|
|
$a->{mtime} = $buf->get_int32; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_EXTENDED) { |
62
|
|
|
|
|
|
|
my $extended_count = $buf->get_int32; |
63
|
|
|
|
|
|
|
for (1..$extended_count) { |
64
|
|
|
|
|
|
|
my $name = $buf->get_str; |
65
|
|
|
|
|
|
|
my $value = $buf->get_str; |
66
|
|
|
|
|
|
|
$a->{$name} = $value; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
$a; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub as_buffer { |
74
|
|
|
|
|
|
|
my $a = shift; |
75
|
|
|
|
|
|
|
my $buf = Net::SFTP::Buffer->new; |
76
|
|
|
|
|
|
|
$buf->put_int32($a->{flags}); |
77
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_SIZE) { |
78
|
|
|
|
|
|
|
$buf->put_int64(int $a->{size}); |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_UIDGID) { |
81
|
|
|
|
|
|
|
$buf->put_int32($a->{uid}); |
82
|
|
|
|
|
|
|
$buf->put_int32($a->{gid}); |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_PERMISSIONS) { |
85
|
|
|
|
|
|
|
$buf->put_int32($a->{perm}); |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
if ($a->{flags} & SSH2_FILEXFER_ATTR_ACMODTIME) { |
88
|
|
|
|
|
|
|
$buf->put_int32($a->{atime}); |
89
|
|
|
|
|
|
|
$buf->put_int32($a->{mtime}); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
$buf; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
1; |
95
|
|
|
|
|
|
|
__END__ |