projects
/
spider.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
added show sun
[spider.git]
/
perl
/
DXUser.pm
diff --git
a/perl/DXUser.pm
b/perl/DXUser.pm
index 810bb7682d85c7f752249b013b2ef8ff3909fc81..a8fb7788c2e5406081f190c600970479c0a0b68b 100644
(file)
--- a/
perl/DXUser.pm
+++ b/
perl/DXUser.pm
@@
-11,7
+11,7
@@
package DXUser;
require Exporter;
@ISA = qw(Exporter);
require Exporter;
@ISA = qw(Exporter);
-use
MLDBM qw(DB_File)
;
+use
DB_File
;
use Fcntl;
use Carp;
use Fcntl;
use Carp;
@@
-49,6
+49,12
@@
$filename = undef;
hmsgno => '0,Highest Msgno',
group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
isolate => '9,Isolate network,yesno',
hmsgno => '0,Highest Msgno',
group => '0,Access Group,parray', # used to create a group of users/nodes for some purpose or other
isolate => '9,Isolate network,yesno',
+ wantbeep => '0,Rec Beep,yesno',
+ wantann => '0,Rec Announce,yesno',
+ wantwwv => '0,Rec WWV,yesno',
+ wanttalk => '0,Rec Talk,yesno',
+ wantwx => '0,Rec WX,yesno',
+ wantdx => '0,Rec DX Spots,yesno',
);
no strict;
);
no strict;
@@
-63,7
+69,6
@@
sub AUTOLOAD
confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
if (@_) {
$self->{$name} = shift;
confess "Non-existant field '$AUTOLOAD'" if !$valid{$name};
if (@_) {
$self->{$name} = shift;
- # $self->put();
}
return $self->{$name};
}
}
return $self->{$name};
}
@@
-73,10
+78,16
@@
sub AUTOLOAD
#
sub init
{
#
sub init
{
- my ($pkg, $fn) = @_;
+ my ($pkg, $fn
, $mode
) = @_;
confess "need a filename in User" if !$fn;
confess "need a filename in User" if !$fn;
- $dbm = tie (%u, MLDBM, $fn, O_CREAT|O_RDWR, 0666) or confess "can't open user file: $fn ($!)";
+ $fn .= ".v2";
+ if ($mode) {
+ $dbm = tie (%u, 'DB_File', $fn, O_CREAT|O_RDWR, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
+ } else {
+ $dbm = tie (%u, 'DB_File', $fn, O_RDONLY, 0666, $DB_BTREE) or confess "can't open user file: $fn ($!)";
+ }
+
$filename = $fn;
}
$filename = $fn;
}
@@
-88,7
+99,7
@@
use strict;
sub finish
{
sub finish
{
-
$dbm = undef
;
+
undef $dbm
;
untie %u;
}
untie %u;
}
@@
-110,7
+121,7
@@
sub new
$self->{dxok} = 1;
$self->{annok} = 1;
$self->{lang} = $main::lang;
$self->{dxok} = 1;
$self->{annok} = 1;
$self->{lang} = $main::lang;
- $u{call} = $self;
+ $u{call} = $self
->encode()
;
return $self;
}
return $self;
}
@@
-124,7
+135,8
@@
sub get
my $pkg = shift;
my $call = uc shift;
# $call =~ s/-\d+$//o; # strip ssid
my $pkg = shift;
my $call = uc shift;
# $call =~ s/-\d+$//o; # strip ssid
- return $u{$call};
+ my $s = $u{$call};
+ return $s ? decode($s) : undef;
}
#
}
#
@@
-152,7
+164,8
@@
sub get_current
my $dxchan = DXChannel->get($call);
return $dxchan->user if $dxchan;
my $dxchan = DXChannel->get($call);
return $dxchan->user if $dxchan;
- return $u{$call};
+ my $s = $u{$call};
+ return $s ? decode($s) : undef;
}
#
}
#
@@
-163,7
+176,49
@@
sub put
{
my $self = shift;
my $call = $self->{call};
{
my $self = shift;
my $call = $self->{call};
- $u{$call} = $self;
+ $u{$call} = $self->encode();
+}
+
+#
+# create a string from a user reference
+#
+sub encode
+{
+ my $self = shift;
+ my $out;
+ my $f;
+
+ $out = "bless( { ";
+ for $f (sort keys %$self) {
+ my $val = $$self{$f};
+ if (ref $val) { # it's an array (we think)
+ $out .= "'$f'=>[ ";
+ foreach (@$val) {
+ my $s = $_;
+ $out .= "'$s',";
+ }
+ $out .= " ],";
+ } else {
+ $val =~ s/'/\\'/og;
+ $val =~ s/\@/\\@/og;
+ $out .= "'$f'=>q{$val},";
+ }
+ }
+ $out .= " }, 'DXUser')";
+ return $out;
+}
+
+#
+# create a hash from a string
+#
+sub decode
+{
+ my $s = shift;
+ my $ref;
+ $s = '$ref = ' . $s;
+ eval $s;
+ confess $@ if $@;
+ return $ref;
}
#
}
#
@@
-274,5
+329,41
@@
sub sort
my $self = shift;
@_ ? $self->{'sort'} = shift : $self->{'sort'} ;
}
my $self = shift;
@_ ? $self->{'sort'} = shift : $self->{'sort'} ;
}
+
+# some accessors
+sub _want
+{
+ my $n = shift;
+ my $self = shift;
+ my $s = "want$n";
+ return $self->{$n} = shift if @_;
+ return defined $self->{$n} ? $self->{$n} : 1;
+}
+
+sub wantbeep
+{
+ return _want('beep', @_);
+}
+
+sub wantann
+{
+ return _want('ann', @_);
+}
+
+sub wantwwv
+{
+ return _want('wwv', @_);
+}
+
+sub wantwx
+{
+ return _want('wx', @_);
+}
+
+sub wantdx
+{
+ return _want('dx', @_);
+}
+
1;
__END__
1;
__END__