]> dxcluster.net Git - spider.git/blob - perl/Thingy/Rt.pm
add uref for call in edu
[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
15 main::mkver($VERSION = q$Revision$);
16
17 use DXChannel;
18 use DXDebug;
19 use DXUtil;
20 use Thingy;
21 use Spot;
22
23 use vars qw(@ISA);
24 @ISA = qw(Thingy);
25
26 sub gen_Aranea
27 {
28         my $thing = shift;
29         unless ($thing->{Aranea}) {
30                 my @items;
31                 $thing->{Aranea} = Aranea::genmsg($thing, 'RT', @items);
32         }
33         return $thing->{Aranea};
34 }
35
36 sub from_Aranea
37 {
38         my $thing = shift;
39         return unless $thing;
40         return $thing;
41 }
42
43 sub gen_DXProt
44 {
45         my $thing = shift;
46         my $dxchan = shift;
47         return $thing->{DXProt};
48 }
49
50 #sub gen_DXCommandmode
51 #{
52 #       my $thing = shift;
53 #       my $dxchan = shift;
54 #       my $buf;
55 #
56 #       return $buf;
57 #}
58
59 sub from_DXProt
60 {
61         my $thing = shift;
62         while (@_) {
63                 my $k = shift;
64                 $thing->{$k} = shift;
65         }
66         ($thing->{hops}) = $thing->{DXProt} =~ /\^H(\d+)\^?~?$/ if exists $thing->{DXProt};
67         return $thing;
68 }
69
70 sub handle
71 {
72         my $thing = shift;
73         my $dxchan = shift;
74
75         if ($thing->{t}) {
76                 my $sub = "handle_$thing->{t}";
77                 if ($thing->can($sub)) {
78                         no strict 'refs';
79                         $thing = $thing->$sub($dxchan);
80                 }
81
82                 $thing->broadcast($dxchan) if $thing;
83         }
84 }
85
86 sub handle_eau
87 {
88         my $thing = shift;
89         my $dxchan = shift;
90
91         if (my $d = $thing->{d}) {
92                 my $nref;
93                 for (split /:/, $d) {
94                         my ($type, $here, $call) = unpack "A1 A1 A*", $_;
95                         if ($type eq 'U') {
96                                 unless ($nref) {
97                                         dbg("Thingy::Rt::ea need a node before $call");
98                                         return;
99                                 }
100                                 add_user($nref, $call, $here);
101                                 my $h = $dxchan->{call} eq $nref->{call} ? 3 : ($thing->{hops} || 99);
102                                 RouteDB::update($call, $dxchan->{call}, $h);
103                         } elsif ($type eq 'N') {
104                                 $nref = Route::Node::get($call);
105                                 unless ($nref) {
106                                         dbg("Thingy::Rt::ea need a definition for $call");
107                                         return;
108                                 }
109                                 my $h = $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99);
110                                 RouteDB::update($nref->{call}, $dxchan->{call}, $h);
111                         } else {
112                                 dbg("Thingy::Rt::ea invalid type $type");
113                                 return;
114                         }
115                 }
116         }
117         return $thing;
118 }
119
120 sub handle_edu
121 {
122         my $thing = shift;
123         my $dxchan = shift;
124
125         if (my $d = $thing->{d}) {
126                 my $nref;
127                 for (split /:/, $d) {
128                         my ($type, $here, $call) = unpack "A1 A1 A*", $_;
129                         if ($type eq 'U') {
130                                 unless ($nref) {
131                                         dbg("Thingy::Rt::edu need a node before $call");
132                                         return;
133                                 }
134                                 my $uref = Route::User::get($call);
135                                 unless ($uref) {
136                                         dbg("Thingy::Rt::edu $call not a user") if isdbg('chanerr');
137                                         next;
138                                 }
139                                 $nref->del_user($call);
140                                 RouteDB::delete($call, $dxchan->{call});
141                         } elsif ($type eq 'N') {
142                                 $nref = Route::Node::get($call);
143                                 unless ($nref) {
144                                         dbg("Thingy::Rt::ed need a definition for $call");
145                                         return;
146                                 }
147                                 RouteDB::update($nref->{call}, $dxchan->{call}, $dxchan->{call} eq $nref->{call} ? 2 : ($thing->{hops} || 99));
148                         } else {
149                                 dbg("Thingy::Rt::ed invalid type $type");
150                                 return;
151                         }
152                 }
153         }
154         return $thing;
155 }
156
157 sub in_filter
158 {
159         my $thing = shift;
160         my $dxchan = shift;
161         
162         # global route filtering on INPUT
163         if ($dxchan->{inroutefilter}) {
164                 my $r = Route::Node::get($thing->{origin});
165                 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});
166                 unless ($filter) {
167                         dbg("PCPROT: Rejected by input route filter") if isdbg('chanerr');
168                         return;
169                 }
170         }
171         return 1;
172 }
173
174 sub out_filter
175 {
176         my $thing = shift;
177         my $dxchan = shift;
178         
179         # global route filtering on OUTPUT
180         if ($dxchan->{routefilter}) {
181                 my $r = Route::Node::get($thing->{origin});
182                 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});          
183                 unless ($filter) {
184                         dbg("PCPROT: Rejected by output route filter") if isdbg('chanerr');
185                         return;
186                 }
187                 $thing->{hops} = $hops if $hops;
188         } elsif ($dxchan->{isolate}) {
189                 return;
190         }
191         return 1;
192 }
193
194 sub add_user
195 {
196         my $node = shift;
197         my $user = shift;
198         my $flag = shift;
199         
200         $node->add_user($user, $flag);
201         my $ur = upd_user_rec($user, $node);
202         $ur->put;
203 }
204
205 sub upd_user_rec
206 {
207         my $call = shift;
208         my $parentcall = shift;
209         
210         # add this station to the user database, if required
211         $call =~ s/-\d+$//o;    # remove ssid for users
212         my $user = DXUser->get_current($call);
213         $user = DXUser->new($call) if !$user;
214         $user->homenode($parentcall) if !$user->homenode;
215         $user->node($parentcall);
216         $user->lastin($main::systime) unless DXChannel->get($call);
217         return $user;
218 }
219 1;