line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
127
|
use strict;
|
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
43
|
|
2
|
1
|
|
|
1
|
|
5
|
use warnings;
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
37
|
|
3
|
1
|
|
|
1
|
|
4
|
use vars qw($VERSION);
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
4
|
|
|
|
|
|
|
$VERSION = "0.17";
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Net::Shared::Handler;
|
7
|
1
|
|
|
1
|
|
4
|
use IO::Socket;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
3020
|
use Storable qw(freeze thaw);
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
83
|
|
9
|
1
|
|
|
1
|
|
6
|
use Carp;
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1787
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new
|
12
|
|
|
|
|
|
|
{
|
13
|
1
|
|
|
1
|
0
|
274
|
my $proto = shift;
|
14
|
1
|
|
33
|
|
|
32
|
my $class = ref($proto) || $proto;
|
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
|
|
2
|
my $self = {};
|
17
|
1
|
|
|
|
|
4
|
$self->{vars} = {};
|
18
|
1
|
50
|
|
|
|
6
|
$self->{debug} = scalar @_ ? shift : 0;
|
19
|
1
|
50
|
|
|
|
4
|
if ($self->{debug})
|
20
|
|
|
|
|
|
|
{
|
21
|
0
|
|
|
|
|
0
|
print "Constructor for Handler.\n\n";
|
22
|
|
|
|
|
|
|
}
|
23
|
1
|
|
|
|
|
5
|
bless ($self, $class);
|
24
|
|
|
|
|
|
|
}
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub cleanup
|
27
|
|
|
|
|
|
|
{
|
28
|
0
|
|
|
0
|
0
|
0
|
my ($self, $return_value) = @_;
|
29
|
0
|
|
|
|
|
0
|
$self->destroy_all;
|
30
|
0
|
|
|
|
|
0
|
return $return_value;
|
31
|
|
|
|
|
|
|
}
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub add
|
34
|
|
|
|
|
|
|
{
|
35
|
1
|
|
|
1
|
0
|
77
|
my ($self, @vars) = @_;
|
36
|
1
|
50
|
|
|
|
14
|
print "Adding Objects:\n" if ($self->{debug});
|
37
|
1
|
|
|
|
|
11
|
foreach my $var (@vars)
|
38
|
|
|
|
|
|
|
{
|
39
|
3
|
|
|
|
|
61
|
$self->{vars}->{$$var->{name}.$$var->{ref}} = $var;
|
40
|
3
|
50
|
|
|
|
22
|
print "\t", $$var->{debug}, " added.\n" if ($self->{debug});
|
41
|
|
|
|
|
|
|
}
|
42
|
1
|
50
|
|
|
|
12
|
print "\n" if ($self->{debug});
|
43
|
|
|
|
|
|
|
}
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub remove
|
46
|
|
|
|
|
|
|
{
|
47
|
0
|
|
|
0
|
0
|
0
|
my ($self, @vars) = @_;
|
48
|
0
|
|
|
|
|
0
|
foreach my $var (@vars)
|
49
|
|
|
|
|
|
|
{
|
50
|
0
|
|
|
|
|
0
|
my $temp = $$var->{name}.$$var->{ref};
|
51
|
0
|
|
|
|
|
0
|
$$var->destroy_variable;
|
52
|
0
|
|
|
|
|
0
|
delete $self->{vars}->{$temp};
|
53
|
|
|
|
|
|
|
}
|
54
|
|
|
|
|
|
|
}
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub store
|
57
|
|
|
|
|
|
|
{
|
58
|
4
|
|
|
4
|
0
|
1218
|
my ($self, $var, $data) = @_;
|
59
|
4
|
|
|
|
|
23
|
$var = $self->{vars}->{$var->{name}.$var->{ref}};
|
60
|
4
|
100
|
|
|
|
23
|
my $address = exists($$var->{address}) ? $$var->{address} : '127.0.0.1';
|
61
|
|
|
|
|
|
|
|
62
|
4
|
50
|
|
|
|
69
|
my $send = IO::Socket::INET->new
|
63
|
|
|
|
|
|
|
(
|
64
|
|
|
|
|
|
|
Proto => 'tcp',
|
65
|
|
|
|
|
|
|
PeerAddr => $address,
|
66
|
|
|
|
|
|
|
PeerPort => $$var->{port}
|
67
|
|
|
|
|
|
|
) or croak( $self->cleanup($!) );
|
68
|
|
|
|
|
|
|
|
69
|
4
|
|
|
|
|
2189
|
$send->autoflush(1);
|
70
|
|
|
|
|
|
|
|
71
|
4
|
50
|
|
|
|
146
|
if ($$var->{debug})
|
72
|
|
|
|
|
|
|
{
|
73
|
0
|
|
|
|
|
0
|
print "Connected to ", $$var->{ref}, " for storing:\n";
|
74
|
0
|
|
|
|
|
0
|
print "\tPeerhost: ", $send->peerhost, "\n";
|
75
|
0
|
|
|
|
|
0
|
print "\tPeerport: ", $send->peerport, "\n";
|
76
|
0
|
|
|
|
|
0
|
print "\tLocalhost: ", $send->sockhost, "\n";
|
77
|
0
|
|
|
|
|
0
|
print "\tLocalport: ", $send->sockport, "\n\n";
|
78
|
|
|
|
|
|
|
}
|
79
|
|
|
|
|
|
|
|
80
|
4
|
|
|
|
|
22
|
my $header = $$var->build_header;
|
81
|
4
|
|
|
|
|
21
|
my $serialized_data = $$var->prepare_data(\$data);
|
82
|
|
|
|
|
|
|
|
83
|
4
|
|
|
|
|
167
|
my $bytes = syswrite($send, $header.$serialized_data, length($serialized_data) + length($header));
|
84
|
4
|
|
|
|
|
16
|
$send->close;
|
85
|
4
|
|
|
|
|
176
|
return $bytes;
|
86
|
|
|
|
|
|
|
}
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub retrieve
|
89
|
|
|
|
|
|
|
{
|
90
|
4
|
|
|
4
|
0
|
660
|
my ($self, $var) = @_;
|
91
|
4
|
|
|
|
|
17
|
$var = $self->{vars}->{$var->{name}.$var->{ref}};
|
92
|
|
|
|
|
|
|
|
93
|
4
|
100
|
|
|
|
194
|
my $address = exists($$var->{address}) ? $$var->{address} : '127.0.0.1';
|
94
|
4
|
50
|
|
|
|
31
|
my $message = IO::Socket::INET->new
|
95
|
|
|
|
|
|
|
(
|
96
|
|
|
|
|
|
|
Proto => 'tcp',
|
97
|
|
|
|
|
|
|
PeerPort => $$var->{port},
|
98
|
|
|
|
|
|
|
PeerAddr => $address
|
99
|
|
|
|
|
|
|
) or die ( $self->cleanup($!) );
|
100
|
|
|
|
|
|
|
|
101
|
4
|
|
|
|
|
1365
|
$message->sockopt (SO_REUSEADDR, 1);
|
102
|
4
|
|
|
|
|
71
|
$message->sockopt (SO_LINGER, 0);
|
103
|
|
|
|
|
|
|
|
104
|
4
|
|
|
|
|
39
|
$message->autoflush(1);
|
105
|
4
|
|
|
|
|
142
|
my $port = $message->sockport;
|
106
|
4
|
50
|
|
|
|
1281
|
if ($$var->{debug})
|
107
|
|
|
|
|
|
|
{
|
108
|
0
|
|
|
|
|
0
|
print "Connected to ", $$var->{ref}, " for retrieving:\n";
|
109
|
0
|
|
|
|
|
0
|
print "\tPeerhost: ", $message->peerhost, "\n";
|
110
|
0
|
|
|
|
|
0
|
print "\tPeerport: ", $message->peerport, "\n";
|
111
|
0
|
|
|
|
|
0
|
print "\tLocalhost: ", $message->sockhost, "\n";
|
112
|
0
|
|
|
|
|
0
|
print "\tLocalport: ", $message->sockport, "\n\n";
|
113
|
|
|
|
|
|
|
}
|
114
|
|
|
|
|
|
|
|
115
|
4
|
|
|
|
|
26
|
my $header = $$var->build_header;
|
116
|
4
|
|
|
|
|
128
|
syswrite($message, $header.$$var->{response}, length($$var->{response})+length($header));
|
117
|
4
|
|
|
|
|
15
|
$message->close;
|
118
|
|
|
|
|
|
|
|
119
|
4
|
50
|
|
|
|
147
|
$message = IO::Socket::INET->new
|
120
|
|
|
|
|
|
|
(
|
121
|
|
|
|
|
|
|
Listen => SOMAXCONN,
|
122
|
|
|
|
|
|
|
LocalPort => $port,
|
123
|
|
|
|
|
|
|
Reuse => 1,
|
124
|
|
|
|
|
|
|
LocalAddr => '127.0.0.1',
|
125
|
|
|
|
|
|
|
) or croak ( $self->cleanup($!) );
|
126
|
4
|
50
|
|
|
|
991
|
if ($$var->{debug})
|
127
|
|
|
|
|
|
|
{
|
128
|
0
|
|
|
|
|
0
|
print "Listening for ", $$var->{ref}, ":\n";
|
129
|
0
|
|
|
|
|
0
|
print "\tLocalport: ", $message->sockport, "\n\n";
|
130
|
|
|
|
|
|
|
}
|
131
|
4
|
|
|
|
|
30
|
while (my $connection = $message->accept)
|
132
|
|
|
|
|
|
|
{
|
133
|
4
|
50
|
|
|
|
22372
|
if ($$var->{debug})
|
134
|
|
|
|
|
|
|
{
|
135
|
0
|
|
|
|
|
0
|
print "Recieved a connection from ", $$var->{ref}, ":\n";
|
136
|
0
|
|
|
|
|
0
|
print "\tPeerhost: ", $connection->peerhost, "\n";
|
137
|
0
|
|
|
|
|
0
|
print "\tPeerport: ", $connection->peerport, "\n";
|
138
|
0
|
|
|
|
|
0
|
print "\tLocalhost: ", $connection->sockhost, "\n";
|
139
|
0
|
|
|
|
|
0
|
print "\tLocalport: ", $connection->sockport, "\n\n";
|
140
|
|
|
|
|
|
|
}
|
141
|
|
|
|
|
|
|
|
142
|
4
|
|
|
|
|
15146
|
my $sent = <$connection>;
|
143
|
4
|
50
|
|
|
|
31
|
$connection->close if $connection->connected;
|
144
|
4
|
|
|
|
|
317
|
$message->close;
|
145
|
4
|
|
|
|
|
99
|
return $self->inflate_data($sent);
|
146
|
|
|
|
|
|
|
}
|
147
|
0
|
0
|
|
|
|
0
|
$message->close if $message->connected;
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub set_remote_port
|
151
|
|
|
|
|
|
|
{
|
152
|
0
|
|
|
0
|
0
|
0
|
my ($self, $var, $port) = shift;
|
153
|
0
|
|
|
|
|
0
|
$$var->set_port($port);
|
154
|
|
|
|
|
|
|
}
|
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub set_remote_addr
|
157
|
|
|
|
|
|
|
{
|
158
|
0
|
|
|
0
|
0
|
0
|
my ($self, $var, $addr) = shift;
|
159
|
0
|
|
|
|
|
0
|
$$var->set_addr($addr);
|
160
|
|
|
|
|
|
|
}
|
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
sub destroy_all
|
163
|
|
|
|
|
|
|
{
|
164
|
2
|
|
|
2
|
0
|
106
|
my $self=shift;
|
165
|
2
|
50
|
|
|
|
11
|
print "Destroying variables: \n" if $self->{debug};
|
166
|
2
|
|
|
|
|
3
|
while ( my($key,$value) = each(%{$self->{vars}}))
|
|
5
|
|
|
|
|
38
|
|
167
|
|
|
|
|
|
|
{
|
168
|
3
|
|
|
|
|
12
|
my $temp = $$value->{name}.$$value->{ref};
|
169
|
3
|
50
|
|
|
|
26
|
my $temp1 = $$value->{debug} if $self->{debug};
|
170
|
3
|
|
|
|
|
19
|
$$value->destroy_variable;
|
171
|
3
|
|
|
|
|
11
|
delete $self->{vars}->{$temp};
|
172
|
3
|
50
|
|
|
|
14
|
print "\t", $temp1, " destroyed.\n" if $self->{debug};
|
173
|
|
|
|
|
|
|
}
|
174
|
2
|
50
|
|
|
|
215
|
print "\n" if $self->{debug};
|
175
|
|
|
|
|
|
|
}
|
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
sub inflate_data
|
178
|
|
|
|
|
|
|
{
|
179
|
4
|
|
|
4
|
0
|
9
|
my ($self,$data) = @_;
|
180
|
4
|
|
|
|
|
133
|
$data = join('',map(chr,split(/\*/,$data)));
|
181
|
4
|
|
|
|
|
39
|
$data = thaw($data);
|
182
|
4
|
|
|
|
|
126
|
return $$data;
|
183
|
|
|
|
|
|
|
}
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub DESTROY
|
186
|
|
|
|
|
|
|
{
|
187
|
1
|
|
|
1
|
|
3
|
my $self = shift;
|
188
|
1
|
|
|
|
|
4
|
$self->destroy_all;
|
189
|
|
|
|
|
|
|
}
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
"JAPH"; |