]> dxcluster.net Git - spider.git/blob - perl/Thingy/Rt.pm
bf178360f0a96f272e76c2684185f68b8c69ce1c
[spider.git] / perl / Thingy / Rt.pm
1 #
2 # Route Thingy handling
3 #
4 # $Id$
5 #
6 # Copyright (c) 2005 Dirk Koopman G1TLH
7 #
8
9 use strict;
10
11 package Thingy::Rt;
12
13 use vars qw($VERSION $BRANCH);
14 $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ );
15 $BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/  || (0,0));
16 $main::build += $VERSION;
17 $main::branch += $BRANCH;
18
19 use DXChannel;
20 use DXDebug;
21 use DXUtil;
22 use Thingy;
23 use Spot;
24
25 use vars qw(@ISA);
26 @ISA = qw(Thingy);
27
28 sub gen_Aranea
29 {
30         my $thing = shift;
31         unless ($thing->{Aranea}) {
32                 my @items;
33                 $thing->{Aranea} = Aranea::genmsg($thing, 'Rloc', @items);
34         }
35         return $thing->{Aranea};
36 }
37
38 sub from_Aranea
39 {
40         my $thing = shift;
41         return unless $thing;
42         return $thing;
43 }
44
45 sub gen_DXProt
46 {
47         my $thing = shift;
48         my $dxchan = shift;
49         return $thing->{DXProt};
50 }
51
52 sub gen_DXCommandmode
53 {
54         my $thing = shift;
55         my $dxchan = shift;
56         my $buf;
57
58         return $buf;
59 }
60
61 sub from_DXProt
62 {
63         my $thing = shift;
64         while (@_) {
65                 my $k = shift;
66                 $thing->{$k} = shift;
67         }
68         ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
69         return $thing;
70 }
71
72 sub handle
73 {
74         my $thing = shift;
75         my $dxchan = shift;
76
77         $thing->broadcast($dxchan);
78 }
79
80 sub in_filter
81 {
82         my $thing = shift;
83         my $dxchan = shift;
84         
85         # global route filtering on INPUT
86         if ($dxchan->{inroutefilter}) {
87                 my ($filter, $hops) = $dxchan->{inroutefilter}->it($thing->{routedata});
88                 unless ($filter) {
89                         dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr');
90                         return;
91                 }
92         }
93         return 1;
94 }
95
96 sub out_filter
97 {
98         my $thing = shift;
99         my $dxchan = shift;
100         
101         # global route filtering on INPUT
102         if ($dxchan->{routefilter}) {
103                 my ($filter, $hops) = $dxchan->{routefilter}->it($thing->{routedata});
104                 unless ($filter) {
105                         dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr');
106                         return;
107                 }
108                 $thing->{hops} = $hops if $hops;
109         } elsif ($dxchan->{isolate}) {
110                 return;
111         }
112         return 1;
113 }
114 1;