| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Net::PSYC::MMP::Compress; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
43
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
37
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
5
|
use Compress::Zlib; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1343
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
my $dict = "_source_targetpsyc://_notice"; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
|
10
|
2
|
|
|
2
|
0
|
5
|
my $class = shift; |
|
11
|
2
|
|
|
|
|
6
|
my $obj = shift; |
|
12
|
2
|
|
|
|
|
8
|
my $self = { |
|
13
|
|
|
|
|
|
|
'connection' => $obj, |
|
14
|
|
|
|
|
|
|
}; |
|
15
|
|
|
|
|
|
|
|
|
16
|
2
|
|
|
|
|
13
|
bless $self, $class; |
|
17
|
|
|
|
|
|
|
|
|
18
|
2
|
|
|
|
|
11
|
return $self; |
|
19
|
|
|
|
|
|
|
} |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
sub init { |
|
22
|
4
|
|
|
4
|
0
|
8
|
my $self = shift; |
|
23
|
4
|
|
|
|
|
9
|
my $hook = shift; |
|
24
|
|
|
|
|
|
|
|
|
25
|
4
|
|
|
|
|
5
|
my $status; |
|
26
|
4
|
100
|
|
|
|
16
|
if ($hook eq 'decrypt') { |
|
|
|
50
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# ($self->{'i'}, $status) = inflateInit( Dictionary => $dict ); |
|
28
|
2
|
|
|
|
|
13
|
($self->{'i'}, $status) = inflateInit( ); |
|
29
|
2
|
|
|
|
|
812
|
if (Net::PSYC::FORK) { |
|
30
|
|
|
|
|
|
|
$self->{'connection'}->hook('receive', $self, 10); |
|
31
|
|
|
|
|
|
|
} else { |
|
32
|
2
|
|
|
|
|
11
|
$self->receive(); |
|
33
|
|
|
|
|
|
|
} |
|
34
|
2
|
50
|
|
|
|
17
|
if ($status == Z_OK) { |
|
35
|
2
|
|
|
|
|
19
|
$self->{'connection'}->hook('decrypt', $self, 10); |
|
36
|
2
|
|
|
|
|
7
|
return 1; |
|
37
|
|
|
|
|
|
|
} |
|
38
|
|
|
|
|
|
|
} elsif ($hook eq 'encrypt') { |
|
39
|
|
|
|
|
|
|
# ($self->{'d'}, $status) = deflateInit( Dictionary => $dict ); |
|
40
|
2
|
|
|
|
|
12
|
($self->{'d'}, $status) = deflateInit( ); |
|
41
|
2
|
50
|
|
|
|
1203
|
if ($status == Z_OK) { |
|
42
|
2
|
|
|
|
|
99
|
$self->{'connection'}->hook('encrypt', $self, -10); |
|
43
|
2
|
|
|
|
|
8
|
return 1; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
} |
|
46
|
0
|
|
|
|
|
0
|
return 0; |
|
47
|
|
|
|
|
|
|
} |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub receive { |
|
50
|
2
|
|
|
2
|
0
|
5
|
my $self = shift; |
|
51
|
2
|
|
|
|
|
24
|
$self->{'connection'}->rmhook('receive', $self); |
|
52
|
|
|
|
|
|
|
|
|
53
|
2
|
|
|
|
|
15
|
my ($out, $status) = $self->{'i'}->inflate(\$$self{'connection'}->{'I_BUFFER'}); |
|
54
|
2
|
50
|
|
|
|
116
|
if ($status == Z_OK) { |
|
55
|
2
|
|
|
|
|
16
|
$self->{'connection'}->{'I_BUFFER'} = $out; |
|
56
|
2
|
|
|
|
|
6
|
return 1; |
|
57
|
|
|
|
|
|
|
} |
|
58
|
0
|
|
|
|
|
0
|
Net::PSYC::W0('Could not decompress the incoming stream from %s: %s', |
|
59
|
|
|
|
|
|
|
$self->{'connection'}->{'psycaddr'}, $self->{'i'}->msg()); |
|
60
|
0
|
|
|
|
|
0
|
return 0; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub encrypt { |
|
64
|
15
|
|
|
15
|
0
|
24
|
my $self = shift; |
|
65
|
15
|
|
|
|
|
21
|
my $data = shift; |
|
66
|
|
|
|
|
|
|
|
|
67
|
15
|
|
|
|
|
50
|
my ($out, $status) = $self->{'d'}->deflate($data); |
|
68
|
15
|
50
|
|
|
|
222
|
if ($status == Z_OK) { |
|
69
|
15
|
|
|
|
|
69
|
$$data = $out; |
|
70
|
15
|
|
|
|
|
51
|
($out, $status) = $self->{'d'}->flush(Z_PARTIAL_FLUSH); |
|
71
|
15
|
|
|
|
|
460
|
$$data .= $out; |
|
72
|
15
|
|
|
|
|
82
|
return 1; |
|
73
|
|
|
|
|
|
|
} |
|
74
|
0
|
|
|
|
|
0
|
print STDERR "Zlib encryption for $self->{'connection'}->{'R_IP'}:$self->{'connection'}->{'R_PORT'} failed: $status (".$self->{'d'}->msg().")\n"; |
|
75
|
0
|
|
|
|
|
0
|
return 0; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub decrypt { |
|
79
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
80
|
0
|
|
|
|
|
0
|
my $data = shift; |
|
81
|
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
0
|
unless ($self->{'i'}) { |
|
83
|
0
|
|
|
|
|
0
|
print STDERR "You did not prepare me for zlib-deflation for $self->{'connection'}->{'R_IP'}:$self->{'connection'}->{'R_PORT'}\n"; |
|
84
|
0
|
|
|
|
|
0
|
return -1; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# TODO find out whether its better to use compress/uncompress. these |
|
88
|
|
|
|
|
|
|
# objects seem to be rather unneeded. |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
0
|
my ($out, $status) = $self->{'i'}->inflate($data); |
|
91
|
0
|
0
|
|
|
|
0
|
if ($status == Z_OK) { |
|
92
|
0
|
|
|
|
|
0
|
$$data = $out; |
|
93
|
0
|
|
|
|
|
0
|
return 1; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
0
|
|
|
|
|
0
|
print STDERR "Zlib decryption for $self->{'connection'}->{'R_IP'}:$self->{'connection'}->{'R_PORT'} failed: $status (".$self->{'i'}->msg().")\n"; |
|
96
|
0
|
|
|
|
|
0
|
return 0; |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub status { |
|
100
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
101
|
0
|
|
|
|
|
0
|
my $return = "_compress status:\n"; |
|
102
|
0
|
0
|
|
|
|
0
|
if ($self->{'d'}) { |
|
103
|
0
|
|
|
|
|
0
|
$return .= "OUT: ".$self->out_rate()."\n"; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
0
|
0
|
|
|
|
0
|
if ($self->{'i'}) { |
|
106
|
0
|
|
|
|
|
0
|
$return .= "IN: ".$self->in_rate()."\n"; |
|
107
|
|
|
|
|
|
|
} |
|
108
|
|
|
|
|
|
|
} |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# compression rates for incoming/outgoing data |
|
111
|
|
|
|
|
|
|
sub in_rate { |
|
112
|
2
|
|
|
2
|
0
|
6
|
my $self = shift; |
|
113
|
2
|
50
|
|
|
|
42
|
unless ($self->{'i'}) { |
|
114
|
0
|
|
|
|
|
0
|
return 1; |
|
115
|
|
|
|
|
|
|
} |
|
116
|
2
|
|
|
|
|
44
|
return $self->{'i'}->total_out() / $self->{'i'}->total_in(); |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub out_rate { |
|
120
|
2
|
|
|
2
|
0
|
4
|
my $self = shift; |
|
121
|
2
|
50
|
|
|
|
16
|
unless ($self->{'d'}) { |
|
122
|
0
|
|
|
|
|
0
|
return 1; |
|
123
|
|
|
|
|
|
|
} |
|
124
|
2
|
|
50
|
|
|
136
|
return $self->{'i'}->total_in() / ($self->{'i'}->total_out()||1); |
|
125
|
|
|
|
|
|
|
} |
|
126
|
|
|
|
|
|
|
1; |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
__END__ |