line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::RRP::Lite; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
32405
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
48
|
|
4
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION $DEBUG); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
92
|
|
5
|
|
|
|
|
|
|
$VERSION = '0.02'; |
6
|
|
|
|
|
|
|
$DEBUG = 0; |
7
|
1
|
|
|
1
|
|
555
|
use Net::RRP::Lite::Response; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
38
|
|
8
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
7
|
use constant CRLF => "\r\n"; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
105
|
|
10
|
1
|
|
|
1
|
|
6
|
use constant END_MARK => qr/\r\n\.\r\n/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
11
|
1
|
|
|
1
|
|
5
|
use constant READ_LEN => 64; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
949
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
__PACKAGE__->_mk_commands(qw(add check del describe mod quit renew session status transfer)); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub new { |
16
|
0
|
|
|
0
|
1
|
0
|
my($class, $sock) = @_; |
17
|
0
|
|
|
|
|
0
|
my $self = bless {_sock => $sock}, $class; |
18
|
0
|
|
|
|
|
0
|
$self->_read_until(END_MARK); # READ HELLO. |
19
|
0
|
|
|
|
|
0
|
return $self; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub connect { |
23
|
0
|
|
|
0
|
1
|
0
|
my($class, %args) = @_; |
24
|
0
|
|
|
|
|
0
|
require IO::Socket::SSL; |
25
|
0
|
0
|
|
|
|
0
|
my $sock = IO::Socket::SSL->new(%args) |
26
|
|
|
|
|
|
|
or _croak("could not make socket:$!"); |
27
|
0
|
|
|
|
|
0
|
return $class->new($sock); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub login { |
31
|
0
|
|
|
0
|
1
|
0
|
my($self, $registrer, $password) = @_; |
32
|
0
|
|
|
|
|
0
|
$self->request('SESSION', undef, { |
33
|
|
|
|
|
|
|
-Id => $registrer, |
34
|
|
|
|
|
|
|
-Password => $password, |
35
|
|
|
|
|
|
|
}); |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub disconnect { |
39
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
40
|
0
|
|
|
|
|
0
|
my $res = $self->request('QUIT'); |
41
|
0
|
|
|
|
|
0
|
$self->{_sock}->close; |
42
|
0
|
|
|
|
|
0
|
return $res; |
43
|
|
|
|
|
|
|
} |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub request { |
46
|
0
|
|
|
0
|
0
|
0
|
my($self, $command, $entity, $args) = @_; |
47
|
0
|
|
|
|
|
0
|
$self->_write_sock(sprintf("%s". CRLF, lc($command))); |
48
|
0
|
0
|
|
|
|
0
|
$self->_write_sock(sprintf("EntityName:%s". CRLF, $entity)) if $entity; |
49
|
0
|
0
|
|
|
|
0
|
if (ref($args) eq 'HASH') { |
50
|
0
|
|
|
|
|
0
|
while (my($key, $val) = each %$args) { |
51
|
0
|
0
|
|
|
|
0
|
if (ref($val) eq 'ARRAY') { |
52
|
0
|
|
|
|
|
0
|
for my $v(@$val) { |
53
|
0
|
|
|
|
|
0
|
$self->_write_sock(sprintf("%s:%s". CRLF, $key, $v)); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
else { |
57
|
0
|
|
|
|
|
0
|
$self->_write_sock(sprintf("%s:%s". CRLF, $key, $val)); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
0
|
|
|
|
|
0
|
$self->_write_sock(".". CRLF); |
62
|
0
|
|
|
|
|
0
|
my $result_data = $self->_read_until(END_MARK); |
63
|
0
|
|
|
|
|
0
|
return Net::RRP::Lite::Response->new($result_data); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _read_until { |
67
|
0
|
|
|
0
|
|
0
|
my($self, $stop) = @_; |
68
|
0
|
|
|
|
|
0
|
my $line = ""; |
69
|
0
|
|
|
|
|
0
|
my $buf = ""; |
70
|
0
|
|
|
|
|
0
|
my $len = 0; |
71
|
0
|
|
|
|
|
0
|
while (my $len = $self->{_sock}->sysread($line, READ_LEN)) { |
72
|
0
|
|
|
|
|
0
|
$buf .= $line; |
73
|
0
|
0
|
|
|
|
0
|
if ($buf =~ m/$stop/s) { |
74
|
0
|
0
|
|
|
|
0
|
if ($DEBUG) { |
75
|
0
|
|
|
|
|
0
|
warn "S:$_\r\n" for(split(/\r\n/, $`)); |
76
|
|
|
|
|
|
|
} |
77
|
0
|
|
|
|
|
0
|
return $`; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
} |
80
|
0
|
0
|
|
|
|
0
|
_croak("could not read data") unless $len; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub _write_sock { |
84
|
0
|
|
|
0
|
|
0
|
my($self, $data) = @_; |
85
|
0
|
0
|
|
|
|
0
|
warn "C:$data" if $DEBUG; |
86
|
0
|
|
|
|
|
0
|
$self->{_sock}->print($data); |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _mk_commands { |
90
|
1
|
|
|
1
|
|
6
|
my($class, @commands) = @_; |
91
|
1
|
|
|
1
|
|
7
|
no strict 'refs'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
152
|
|
92
|
1
|
|
|
|
|
3
|
for my $command(@commands) { |
93
|
10
|
|
|
|
|
53
|
*{"$class\:\:$command"} = sub { |
94
|
0
|
|
|
0
|
|
|
my($self, $entity, $args) = @_; |
95
|
0
|
|
|
|
|
|
$self->request($command, $entity, $args); |
96
|
|
|
|
|
|
|
} |
97
|
10
|
|
|
|
|
33
|
} |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _croak { |
101
|
0
|
|
|
0
|
|
|
require Carp; |
102
|
0
|
|
|
|
|
|
Carp::croak(@_); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
1; |
106
|
|
|
|
|
|
|
__END__ |