22b7d4c66a4242ca8c7440569cbe7a8fc56b6bb5
[spider.git] / perl / Thingy / Bye.pm
1 #
2 # Bye Thingy handling
3 #
4 # $Id$
5 #
6 # Copyright (c) 2005 Dirk Koopman G1TLH
7 #
8
9 use strict;
10
11 package Thingy::Bye;
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 Verify;
22 use Thingy;
23
24 use vars qw(@ISA);
25 @ISA = qw(Thingy);
26
27 sub gen_Aranea
28 {
29         my $thing = shift;
30         unless ($thing->{Aranea}) {
31                 my $s = sprintf "%X", int(rand() * 100000000);
32                 my $auth = Verify->new("DXSp,$main::mycall,$s");
33                 $thing->{Aranea} = Aranea::genmsg($thing, 'Bye',
34                                                                                   's'=>$s,
35                                                                                   auth=>$auth->challenge($main::me->user->passphrase)
36                                                                           );
37         }
38         return $thing->{Aranea};
39 }
40
41 sub handle
42 {
43         my $thing = shift;
44         my $dxchan = shift;
45         
46         # verify authenticity
47         if ($dxchan->{call} eq $thing->{origin}) {
48
49                 # for directly connected calls
50 #               if ($Thingy::Hello::verify_on_login) {
51 #                       my $pp = $dxchan->user->passphrase;
52 #                       unless ($pp) {
53 #                               dbglog('err', "Thingy::Bye::handle: verify on and $thing->{origin} has no passphrase");
54 #                               return;
55 #                       }
56 #                       my $auth = Verify->new("DXSp,$thing->{origin},$thing->{s}");
57 #                       unless ($auth->verify($thing->{auth}, $dxchan->user->passphrase)) {
58 #                               dbglog('err', "Thingy::Bye::handle: verify on and $thing->{origin} failed auth check");
59 #                               return;
60 #                       }
61 #               }
62                 
63                 my $int = $thing->{user} || $thing->{origin};
64                 RouteDB::delete_interface($int);
65         } else {
66                 
67                 # for otherwise connected calls, that come in relayed from other nodes
68                 # note that we cannot do any connections at this point
69                 my $nref = Route::Node::get($thing->{origin});
70                 if ($nref) {
71                         if (my $user = $thing->{user}) {
72                                 my $ur = Route::get($user);
73                                 if ($ur) {
74                                         if ($ur->isa('Route::Node')) {
75                                                 $nref->del($ur);
76                                         } elsif ($ur->isa('Route::User')) {
77                                                 $nref->del_user($ur);
78                                         }
79                                 }
80                         }
81                 }
82         }
83
84                 
85         $thing->broadcast($dxchan);
86 }
87
88 sub new
89 {
90         my $pkg = shift;
91         my $thing = $pkg->SUPER::new(origin=>$main::mycall, @_);
92         return $thing;
93 }
94 1;