X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=2c562ac70ed538d12373150fd08b2e15944a1b4f;hb=1006337e105ab06a0e468bc483332fd385dd5240;hp=84a569497171c9a0cc1584333130e59e8cc321ed;hpb=0e8259381a4d4f4ea9059cdabc0cc4c88e637a99;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 84a56949..2c562ac7 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -15,22 +15,24 @@ use Fcntl; use IO::File; use DXDebug; use DXUtil; +use LRU; use strict; use vars qw($VERSION $BRANCH); $VERSION = sprintf( "%d.%03d", q$Revision$ =~ /(\d+)\.(\d+)/ ); -$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ ) || 0; +$BRANCH = sprintf( "%d.%03d", q$Revision$ =~ /\d+\.\d+\.(\d+)\.(\d+)/ || (0,0)); $main::build += $VERSION; $main::branch += $BRANCH; -use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime); +use vars qw(%u $dbm $filename %valid $lastoperinterval $lasttime $lru $lrusize); %u = (); $dbm = undef; $filename = undef; $lastoperinterval = 60*24*60*60; $lasttime = 0; +$lrusize = 2000; # hash of valid elements and a simple prompt %valid = ( @@ -76,6 +78,8 @@ $lasttime = 0; wantann_talk => '0,Talklike Anns,yesno', wantpc90 => '1,Req PC90,yesno', wantnp => '1,Req New Protocol,yesno', + wantpc16 => '9,Want Users from node,yesno', + wantsendpc16 => '9,Send users to node,yesno', lastoper => '9,Last for/oper,cldatetime', nothere => '0,Not Here Text', registered => '9,Registered?,yesno', @@ -84,26 +88,29 @@ $lasttime = 0; build => '1,Build', ); -no strict; +#no strict; sub AUTOLOAD { my $self = shift; + no strict; my $name = $AUTOLOAD; return if $name =~ /::DESTROY$/; - $name =~ s/.*:://o; + $name =~ s/^.*:://o; confess "Non-existant field '$AUTOLOAD'" if !$valid{$name}; # this clever line of code creates a subroutine which takes over from autoload # from OO Perl - Conway - *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; - if (@_) { - $self->{$name} = shift; - } - return $self->{$name}; + *$AUTOLOAD = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}}; + &$AUTOLOAD($self, @_); +# *{$AUTOLOAD} = sub {@_ > 1 ? $_[0]->{$name} = $_[1] : $_[0]->{$name}} ; +# if (@_) { +# $self->{$name} = shift; +# } +# return $self->{$name}; } -use strict; +#use strict; # # initialise the system @@ -121,6 +128,7 @@ sub init } $filename = $fn; + $lru = LRU->newbase("DXUser", $lrusize); } sub del_file @@ -182,8 +190,16 @@ sub get my $pkg = shift; my $call = uc shift; my $data; + + # is it in the LRU cache? + my $ref = $lru->get($call); + return $ref if $ref; + + # search for it unless ($dbm->get($call, $data)) { - return decode($data); + $ref = decode($data); + $lru->put($call, $ref); + return $ref; } return undef; } @@ -233,7 +249,9 @@ sub put $dbm->del($call); delete $self->{annok} if $self->{annok}; delete $self->{dxok} if $self->{dxok}; - $dbm->put($call, $self->encode); + $lru->put($call, $self); + my $ref = $self->encode; + $dbm->put($call, $ref); } # @@ -277,6 +295,7 @@ sub del # for ($dbm->get_dup($call)) { # $dbm->del_dup($call, $_); # } + $lru->remove($call); $dbm->del($call); } @@ -400,8 +419,9 @@ print "There are $count user records and $err errors\n"; for ($action = R_FIRST; !$dbm->seq($key, $val, $action); $action = R_NEXT) { if (!is_callsign($key) || $key =~ /^0/) { - Log('DXCommand', "Export Error: $key\t$val"); - $dbm->del($key); + Log('DXCommand', "Export Error1: $key\t$val"); + eval {$dbm->del($key)}; + dbg(carp("Export Error1: $key\t$val\n$@")) if $@; ++$err; next; } @@ -410,8 +430,9 @@ print "There are $count user records and $err errors\n"; print $fh "$key\t" . $ref->encode . "\n"; ++$count; } else { - Log('DXCommand', "Export Error: $key\t$val"); - $dbm->del($key); + Log('DXCommand', "Export Error2: $key\t$val"); + eval {$dbm->del($key)}; + dbg(carp("Export Error2: $key\t$val\n$@")) if $@; ++$err; } } @@ -564,6 +585,16 @@ sub wantann_talk return _want('ann_talk', @_); } +sub wantpc16 +{ + return _want('pc16', @_); +} + +sub wantsendpc16 +{ + return _want('sendpc16', @_); +} + sub wantlogininfo { my $self = shift;