line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::FreeDB2::Response::SignOn; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Copyright 2002, Vincenzo Zocca. |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# See LICENSE section for usage and distribution rights. |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require 5.005_62; |
8
|
2
|
|
|
2
|
|
12
|
use strict; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
76
|
|
9
|
2
|
|
|
2
|
|
11
|
use warnings; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
78
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
require Exporter; |
12
|
2
|
|
|
2
|
|
943
|
use AutoLoader qw(AUTOLOAD); |
|
2
|
|
|
|
|
1833
|
|
|
2
|
|
|
|
|
15
|
|
13
|
2
|
|
|
2
|
|
1025
|
use Error qw (:try); |
|
2
|
|
|
|
|
7280
|
|
|
2
|
|
|
|
|
20
|
|
14
|
2
|
|
|
2
|
|
367
|
use base qw (Net::FreeDB2::Response Exporter); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
1269
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
#our @ISA = qw(Exporter); |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Items to export into callers namespace by default. Note: do not export |
19
|
|
|
|
|
|
|
# names by default without a very good reason. Use EXPORT_OK instead. |
20
|
|
|
|
|
|
|
# Do not simply export all your public functions/methods/constants. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# This allows declaration use Net::FreeDB2::Response::SignOn ':all'; |
23
|
|
|
|
|
|
|
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK |
24
|
|
|
|
|
|
|
# will save memory. |
25
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
) ] ); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our @EXPORT = qw( |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
our ( $VERSION ) = '$Revision: 0.8.2.4 $ ' =~ /\$Revision:\s+([^\s]+)/; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
my $CODE_RX = '^\s*(\d{3})\s+'; |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
|
|
|
my $self = {}; |
42
|
0
|
|
0
|
|
|
|
bless ($self, (ref($class) || $class)); |
43
|
0
|
|
|
|
|
|
return ($self->_initialize (@_)); |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _initialize { |
47
|
0
|
|
|
0
|
|
|
my $self = shift; |
48
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
|
defined ($opt->{content_ref}) and $self->read ($opt); |
51
|
0
|
|
|
|
|
|
return ($self); |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub read { |
55
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
56
|
0
|
|
0
|
|
|
|
my $opt = shift || {}; |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
# Check if content_ref is specified |
59
|
0
|
0
|
|
|
|
|
exists ($opt->{content_ref}) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, option \'content_ref\' not defined.'); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Convert $opt->{content_ref} to @content_ref |
62
|
0
|
|
|
|
|
|
my @content_ref = split (/[\n\r]+/, ${$opt->{content_ref}}); |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
# Parse first line |
65
|
0
|
|
|
|
|
|
my $line = shift (@content_ref); |
66
|
0
|
|
|
|
|
|
my ($code) = $line =~ /$CODE_RX/; |
67
|
0
|
0
|
|
|
|
|
defined ($code) || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified \'content_ref\' does not contain a code.'); |
68
|
0
|
0
|
0
|
|
|
|
$code == 200 || $code == 201 || $code == 432 || $code == 433 || $code == 434 || throw Error::Simple ('ERROR: Net::FreeDB2::Response::SignOn::read, first line of specified \'content_ref\' does not contain a code.'); |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
69
|
0
|
|
|
|
|
|
$self->setWritePermission (1); |
70
|
0
|
0
|
|
|
|
|
if ($code == 200) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$self->setError (0); |
72
|
0
|
|
|
|
|
|
$self->setResult ('OK, read/write allowed'); |
73
|
|
|
|
|
|
|
} elsif ($code == 201) { |
74
|
0
|
|
|
|
|
|
$self->setError (0); |
75
|
0
|
|
|
|
|
|
$self->setResult ('OK, read only'); |
76
|
0
|
|
|
|
|
|
$self->setWritePermission (0); |
77
|
|
|
|
|
|
|
} elsif ($code == 432) { |
78
|
0
|
|
|
|
|
|
$self->setError (0); |
79
|
0
|
|
|
|
|
|
$self->setResult ('No connections allowed: permission denied'); |
80
|
|
|
|
|
|
|
} elsif ($code == 433) { |
81
|
0
|
|
|
|
|
|
$self->setError (0); |
82
|
0
|
|
|
|
|
|
$self->setResult ('No connections allowed: X users allowed, Y currently active'); |
83
|
|
|
|
|
|
|
} elsif ($code == 434) { |
84
|
0
|
|
|
|
|
|
$self->setError (0); |
85
|
0
|
|
|
|
|
|
$self->setResult ('No connections allowed: system load too high'); |
86
|
|
|
|
|
|
|
} else { |
87
|
0
|
|
|
|
|
|
throw Error::Simple ("ERROR: Net::FreeDB2::Response::SignOn::read, unknown code '$code' returned."); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# Parse the reats of the line |
91
|
0
|
|
|
|
|
|
my ($code, $hostname, $version, $date) = split (/\s+/, $line, 4); |
92
|
0
|
|
|
|
|
|
$self->setHostname ($hostname); |
93
|
0
|
|
|
|
|
|
$self->setVersion ($version); |
94
|
0
|
|
|
|
|
|
$self->setDate ($date); |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub setWritePermission { |
98
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
|
$self->{Net_FreeDB2_Response_SignOn}{write_permission} = shift; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub hasWritePermission { |
104
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
|
return ($self->{Net_FreeDB2_Response_SignOn}{write_permission}); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub setHostname { |
110
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
|
$self->{Net_FreeDB2_Response_SignOn}{hostname} = shift; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub getHostname { |
116
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
return ($self->{Net_FreeDB2_Response_SignOn}{hostname}); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub setVersion { |
122
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
123
|
|
|
|
|
|
|
|
124
|
0
|
|
|
|
|
|
$self->{Net_FreeDB2_Response_SignOn}{version} = shift; |
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub getVersion { |
128
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return ($self->{Net_FreeDB2_Response_SignOn}{version}); |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub setDate { |
134
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
$self->{Net_FreeDB2_Response_SignOn}{date} = shift; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
sub getDate { |
140
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
141
|
|
|
|
|
|
|
|
142
|
0
|
|
|
|
|
|
return ($self->{Net_FreeDB2_Response_SignOn}{date}); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
1; |
146
|
|
|
|
|
|
|
__END__ |