make sure pc16/pc17 nodes are passed correctly
[spider.git] / perl / Thingy / RouteFilter.pm
1 #
2 # Thingy Route Filter handling
3 #
4 # This to provide multiple inheritance to Routing entities
5 # that wish to do standard filtering
6 #
7 # $Id$
8 #
9 # Copyright (c) 2005 Dirk Koopman G1TLH
10 #
11
12 use strict;
13
14 package Thingy::RouteFilter;
15
16 use vars qw($VERSION $BRANCH);
17
18 main::mkver($VERSION = q$Revision$);
19
20 use DXChannel;
21 use DXDebug;
22 use DXProt;
23 use Thingy;
24
25 use vars qw(@ISA);
26 @ISA = qw(Thingy);
27
28 sub _filter
29 {
30         my $dxchan = shift;
31         my @out;
32         
33         foreach my $r (@_) {
34                 my ($filter, $hops) = $dxchan->{routefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state});
35                 push @out, $r if $filter;
36         }
37         return @out;
38 }
39
40 sub gen_DXProt
41 {
42         my $thing = shift;
43         my @out;
44         push @out, DXProt::pc21(@{$thing->{fpc21n}}) if $thing->{fpc21n};
45         push @out, DXProt::pc17($thing->{fpc17n}, @{$thing->{pc17u}})  if $thing->{pc17u} && $thing->{fpc17n};
46         push @out, DXProt::pc19(@{$thing->{fpc19n}}) if $thing->{fpc19n};
47         push @out, DXProt::pc16($thing->{fpc16n}, @{$thing->{pc16u}}) if $thing->{pc16u} && $thing->{fpc16n};
48         return \@out;
49 }
50
51 sub in_filter
52 {
53         my $thing = shift;
54         my $dxchan = shift;
55         
56         # global route filtering on INPUT
57         if ($dxchan->{inroutefilter}) {
58                 my $r = Route::Node::get($thing->{origin}) || Route->new($thing->{origin});
59                 my ($filter, $hops) = $dxchan->{inroutefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state});
60                 unless ($filter) {
61                         dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr');
62                         return;
63                 }
64         } elsif ($dxchan->{isolate} && $thing->{origin} ne $main::mycall) {
65                 return;
66         }
67         return 1;
68 }
69
70 sub out_filter
71 {
72         my $thing = shift;
73         my $dxchan = shift;
74         
75         # global route filtering on OUTPUT
76         if ($dxchan->{routefilter}) {
77                 my $r = Route::Node::get($thing->{origin});
78                 my ($filter, $hops) = $dxchan->{routefilter}->it($dxchan->{call}, $dxchan->{dxcc}, $dxchan->{itu}, $dxchan->{cq}, $r->{call}, $r->{dxcc}, $r->{itu}, $r->{cq}, $dxchan->{state}, $r->{state});          
79                 unless ($filter) {
80                         dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr');
81                         return;
82                 }
83                 
84                 if ($dxchan->isa('DXProt')) {
85                         $thing->{hops} = $hops if $hops;
86                         delete $thing->{fpc16n};
87                         delete $thing->{fpc17n};
88                         delete $thing->{fpc19n};
89                         delete $thing->{fpc21n};
90         
91                         my @n16 = _filter($dxchan, $thing->{pc16n}) if $thing->{pc16u} && $thing->{pc16n};
92                         $thing->{fpc16n} = $n16[0] if @n16;
93                         my @n17 = _filter($dxchan, $thing->{pc17n}) if $thing->{pc17u} && $thing->{pc17n};
94                         $thing->{fpc17n} = $n17[0] if @n17;
95                         my @pc19 = _filter($dxchan, @{$thing->{pc19n}}) if $thing->{pc19n};
96                         $thing->{fpc19n} = \@pc19 if @pc19;
97                         my @pc21 = _filter($dxchan, @{$thing->{pc21n}}) if $thing->{pc21n};
98                         $thing->{fpc21n} = \@pc21 if @pc21;
99                 }
100                 return 1;
101                 
102         } elsif ($dxchan->{isolate}) {
103                 return if $thing->{origin} ne $main::mycall;
104         }
105         if ($dxchan->isa('DXProt')) {
106                 $thing->{fpc16n} ||= $thing->{pc16n}; 
107                 $thing->{fpc17n} ||= $thing->{pc17n}; 
108                 $thing->{fpc19n} ||= $thing->{pc18n}; 
109                 $thing->{fpc21n} ||= $thing->{pc21n}; 
110         }
111         return 1;
112 }
113
114 1;