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