line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# FTN/Address.pm
|
2
|
|
|
|
|
|
|
#
|
3
|
|
|
|
|
|
|
# Copyright (c) 2005-2006 Serguei Trouchelle. All rights reserved.
|
4
|
|
|
|
|
|
|
#
|
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify it
|
6
|
|
|
|
|
|
|
# under the same terms as Perl itself.
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
# History:
|
9
|
|
|
|
|
|
|
# 1.03 2007/02/04 Quality update (Test::Pod, Test::Pod::Coverage), Data::Define used
|
10
|
|
|
|
|
|
|
# 1.02 2006/09/07 Added empty value processing
|
11
|
|
|
|
|
|
|
# 1.01 2005/02/16 Initial revision
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
FTN::Address - Process FTN addresses
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS
|
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $addr = new FTN::Address('2:464/4077');
|
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $address4D = $addr->get(); # 2:464/4077.0
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
my $address5D = $addr->getfull(); # 2:464/4077.0@fidonet
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
my $fqdn = $addr->fqdn(); # f4077.n464.z2.fidonet.net
|
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
my $addr = empty FTN::Address();
|
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
$addr->assign('2:464/4077');
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $address4D = $addr->get(); # 2:464/4077.0
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=head1 DESCRIPTION
|
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
FTN::Address
|
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 METHODS
|
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 new
|
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
This method creates FTN::Address object.
|
43
|
|
|
|
|
|
|
Takes FTN address as argument. Address can be feed in three addressing variants:
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
3D, ex.: new FTN::Address '2:464/0'
|
46
|
|
|
|
|
|
|
4D, ex.: new FTN::Address '2:464/4077.1'
|
47
|
|
|
|
|
|
|
5D, ex.: new FTN::Address '2:464/357.0@fidonet'
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
Default domain for 3D and 4D address is 'fidonet'
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 empty
|
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
This method creates empty FTN::Address object.
|
54
|
|
|
|
|
|
|
You cannot use it before assigning a new value.
|
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
Takes no parameters.
|
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 assign( $address )
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
This method assign new address to FTN::Address object.
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Takes FTN address as argument (like 'new' method).
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 get()
|
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
This method returns qualified 4D address.
|
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Takes no parameters.
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=head2 getfull()
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
This method returns qualified 5D address.
|
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Takes no parameters.
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head2 fqdn( [ $root_domain [, $level ] ] );
|
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
This method returns fully qualified domain name, as described in FSP-1026
|
79
|
|
|
|
|
|
|
Fidonet Technical Standards Comittee document. See this document for details.
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Valid values for level are "0, 1, 2, 3, 4, DOM, DO1, DO2, DO3, DO4"
|
82
|
|
|
|
|
|
|
Parameters can be omitted, default values will be used.
|
83
|
|
|
|
|
|
|
Default root domain is 'net', default level is '0'.
|
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
Examples:
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $addr = new FTN::Address('2:464/4077');
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
print $addr->fqdn(); # f4077.n464.z2.fidonet.net
|
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
print $addr->fqdn('org'); # f4077.n464.z2.fidonet.org
|
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
print $addr->fqdn('railways.dp.ua', 2); # f4077.n464.railways.dp.ua
|
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=head1 AUTHORS
|
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Serguei Trouchelle EFE
|
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 COPYRIGHT
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Copyright (c) 2005-2006 Serguei Trouchelle. All rights reserved.
|
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
104
|
|
|
|
|
|
|
under the same terms as Perl itself.
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
package FTN::Address;
|
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
require Exporter;
|
111
|
7
|
|
|
7
|
|
50363
|
use Config;
|
|
7
|
|
|
|
|
20
|
|
|
7
|
|
|
|
|
318
|
|
112
|
|
|
|
|
|
|
|
113
|
7
|
|
|
7
|
|
38
|
use strict;
|
|
7
|
|
|
|
|
12
|
|
|
7
|
|
|
|
|
279
|
|
114
|
7
|
|
|
7
|
|
36
|
use warnings;
|
|
7
|
|
|
|
|
19
|
|
|
7
|
|
|
|
|
258
|
|
115
|
|
|
|
|
|
|
|
116
|
7
|
|
|
7
|
|
6246
|
use Data::Define qw/brockets/;
|
|
7
|
|
|
|
|
4838
|
|
|
7
|
|
|
|
|
37
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
our @EXPORT_OK = qw//;
|
119
|
|
|
|
|
|
|
our %EXPORT_TAGS = ();
|
120
|
|
|
|
|
|
|
our @ISA = qw/Exporter/;
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
$FTN::Address::VERSION = "1.03";
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
our $DEFAULT_DOMAIN = 'fidonet';
|
125
|
|
|
|
|
|
|
our $DEFAULT_ROOT = 'net';
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
#
|
128
|
|
|
|
|
|
|
# Constructor
|
129
|
|
|
|
|
|
|
#
|
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
sub new {
|
132
|
14
|
|
|
14
|
1
|
4536
|
my $self = shift;
|
133
|
14
|
|
|
|
|
22
|
my $addr = shift;
|
134
|
14
|
100
|
66
|
|
|
145
|
if ($addr and $addr =~ m!^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$!) {
|
135
|
13
|
100
|
|
|
|
132
|
$self =
|
|
|
100
|
|
|
|
|
|
136
|
|
|
|
|
|
|
{'z' => $1,
|
137
|
|
|
|
|
|
|
'n' => $2,
|
138
|
|
|
|
|
|
|
'f' => $3,
|
139
|
|
|
|
|
|
|
'p' => $5 ? $5 : 0,
|
140
|
|
|
|
|
|
|
'd' => $7 ? $7 : $DEFAULT_DOMAIN,
|
141
|
|
|
|
|
|
|
};
|
142
|
13
|
|
|
|
|
61
|
$self->{'__addr'} = $self->{'z'} . ':' . $self->{'n'} . '/' .
|
143
|
|
|
|
|
|
|
$self->{'f'} . '.' . $self->{'p'};
|
144
|
13
|
|
|
|
|
36
|
$self->{'__addrd'} = $self->{'__addr'} . '@' . $self->{'d'};
|
145
|
|
|
|
|
|
|
} else {
|
146
|
1
|
|
|
|
|
7
|
$@ = join('', 'Invalid address: ', define($addr));
|
147
|
1
|
|
|
|
|
8
|
return undef;
|
148
|
|
|
|
|
|
|
}
|
149
|
|
|
|
|
|
|
|
150
|
13
|
|
|
|
|
22
|
bless $self;
|
151
|
13
|
|
|
|
|
34
|
return $self;
|
152
|
|
|
|
|
|
|
}
|
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
#
|
155
|
|
|
|
|
|
|
# Empty constructor
|
156
|
|
|
|
|
|
|
#
|
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub empty {
|
159
|
6
|
|
|
6
|
1
|
984
|
my $self = shift;
|
160
|
6
|
|
|
|
|
21
|
$self = {'__empty' => 1};
|
161
|
6
|
|
|
|
|
12
|
bless $self;
|
162
|
6
|
|
|
|
|
16
|
return $self;
|
163
|
|
|
|
|
|
|
}
|
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
#
|
166
|
|
|
|
|
|
|
# Assign new value
|
167
|
|
|
|
|
|
|
#
|
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub assign {
|
170
|
5
|
|
|
5
|
1
|
30
|
my $self = shift;
|
171
|
5
|
|
|
|
|
7
|
my $addr = shift;
|
172
|
5
|
50
|
33
|
|
|
54
|
if ($addr and $addr =~ m!^(\d+):(\d+)/(\d+)(\.(\d+))?(@(\w+))?$!) {
|
173
|
5
|
|
|
|
|
19
|
$self->{'z'} = $1;
|
174
|
5
|
|
|
|
|
13
|
$self->{'n'} = $2;
|
175
|
5
|
|
|
|
|
12
|
$self->{'f'} = $3;
|
176
|
5
|
100
|
|
|
|
17
|
$self->{'p'} = $5 ? $5 : 0;
|
177
|
5
|
100
|
|
|
|
18
|
$self->{'d'} = $7 ? $7 : $DEFAULT_DOMAIN;
|
178
|
5
|
|
|
|
|
21
|
$self->{'__addr'} = $self->{'z'} . ':' . $self->{'n'} . '/' .
|
179
|
|
|
|
|
|
|
$self->{'f'} . '.' . $self->{'p'};
|
180
|
5
|
|
|
|
|
20
|
$self->{'__addrd'} = $self->{'__addr'} . '@' . $self->{'d'};
|
181
|
5
|
|
|
|
|
15
|
delete $self->{'__empty'};
|
182
|
|
|
|
|
|
|
} else {
|
183
|
0
|
|
|
|
|
0
|
$@ = join('', 'Invalid address: ', $addr);
|
184
|
0
|
|
|
|
|
0
|
$self->{'__empty'} = 1;
|
185
|
0
|
|
|
|
|
0
|
return undef;
|
186
|
|
|
|
|
|
|
}
|
187
|
|
|
|
|
|
|
}
|
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
#
|
190
|
|
|
|
|
|
|
# get 4D address
|
191
|
|
|
|
|
|
|
#
|
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
sub get {
|
194
|
4
|
|
|
4
|
1
|
21
|
my $self = shift;
|
195
|
4
|
50
|
|
|
|
8
|
if ($self->{'__empty'}) {
|
196
|
0
|
|
|
|
|
0
|
$@ = 'Cannot use empty FTN::Address object';
|
197
|
0
|
|
|
|
|
0
|
return undef;
|
198
|
|
|
|
|
|
|
}
|
199
|
4
|
|
|
|
|
16
|
return $self->{'__addr'};
|
200
|
|
|
|
|
|
|
}
|
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
#
|
203
|
|
|
|
|
|
|
# get 5D address
|
204
|
|
|
|
|
|
|
#
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
sub getfull {
|
207
|
4
|
|
|
4
|
1
|
30
|
my $self = shift;
|
208
|
4
|
50
|
|
|
|
13
|
if ($self->{'__empty'}) {
|
209
|
0
|
|
|
|
|
0
|
$@ = 'Cannot use empty FTN::Address object';
|
210
|
0
|
|
|
|
|
0
|
return undef;
|
211
|
|
|
|
|
|
|
}
|
212
|
4
|
|
|
|
|
18
|
return $self->{'__addrd'};
|
213
|
|
|
|
|
|
|
}
|
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
#
|
216
|
|
|
|
|
|
|
# get FQDN
|
217
|
|
|
|
|
|
|
#
|
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub fqdn {
|
220
|
16
|
|
|
16
|
1
|
85
|
my $self = shift;
|
221
|
16
|
100
|
|
|
|
52
|
if ($self->{'__empty'}) {
|
222
|
1
|
|
|
|
|
2
|
$@ = 'Cannot use empty FTN::Address object';
|
223
|
1
|
|
|
|
|
7
|
return undef;
|
224
|
|
|
|
|
|
|
}
|
225
|
15
|
|
33
|
|
|
41
|
my $root = shift || $DEFAULT_ROOT;
|
226
|
15
|
|
100
|
|
|
46
|
my $level = shift || 0;
|
227
|
|
|
|
|
|
|
|
228
|
15
|
50
|
|
|
|
42
|
$level = $1 if $level =~ /^DO([M1234])$/;
|
229
|
15
|
50
|
|
|
|
37
|
$level = 0 if $level eq 'M';
|
230
|
|
|
|
|
|
|
|
231
|
15
|
100
|
|
|
|
81
|
if ($level eq '0') { # DOM - 5D ([pPP.]fFF.nNN.zZZ.fidonet.RD)
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
232
|
3
|
50
|
|
|
|
441
|
return ($self->{'p'} ? 'p' . $self->{'p'} . '.' : '') .
|
233
|
|
|
|
|
|
|
'f' . $self->{'f'} . '.' .
|
234
|
|
|
|
|
|
|
'n' . $self->{'n'} . '.' .
|
235
|
|
|
|
|
|
|
'z' . $self->{'z'} . '.' .
|
236
|
|
|
|
|
|
|
$self->{'d'} . '.' . $root;
|
237
|
|
|
|
|
|
|
} elsif ($level eq '1') { # DO1 - 1D (fFF.RD)
|
238
|
3
|
|
|
|
|
185
|
return 'f' . $self->{'f'} . '.' .
|
239
|
|
|
|
|
|
|
$root;
|
240
|
|
|
|
|
|
|
} elsif ($level eq '2') { # DO2 - 2D (fFF.nNN.RD)
|
241
|
3
|
|
|
|
|
152
|
return 'f' . $self->{'f'} . '.' .
|
242
|
|
|
|
|
|
|
'n' . $self->{'n'} . '.' .
|
243
|
|
|
|
|
|
|
$root;
|
244
|
|
|
|
|
|
|
} elsif ($level eq '3') { # DO3 - 3D (fFF.nNN.zZZ.RD)
|
245
|
3
|
|
|
|
|
137
|
return 'f' . $self->{'f'} . '.' .
|
246
|
|
|
|
|
|
|
'n' . $self->{'n'} . '.' .
|
247
|
|
|
|
|
|
|
'z' . $self->{'z'} . '.' .
|
248
|
|
|
|
|
|
|
$root;
|
249
|
|
|
|
|
|
|
} elsif ($level eq '4') { # DO4 - 4D ([pPP.]fFF.nNN.zZZ.RD)
|
250
|
3
|
50
|
|
|
|
139
|
return ($self->{'p'} ? 'p' . $self->{'p'} . '.' : '') .
|
251
|
|
|
|
|
|
|
'f' . $self->{'f'} . '.' .
|
252
|
|
|
|
|
|
|
'n' . $self->{'n'} . '.' .
|
253
|
|
|
|
|
|
|
'z' . $self->{'z'} . '.' .
|
254
|
|
|
|
|
|
|
$root;
|
255
|
|
|
|
|
|
|
} else {
|
256
|
0
|
|
|
|
|
|
$@ = 'Invalid level: ' . $level;
|
257
|
0
|
|
|
|
|
|
return undef;
|
258
|
|
|
|
|
|
|
}
|
259
|
|
|
|
|
|
|
}
|
260
|
|
|
|
|
|
|
|
261
|
|
|
|
|
|
|
1;
|