require Exporter;
@ISA = qw(Exporter);
-use MLDBM qw(DB_File);
+use DB_File;
use Fcntl;
use Carp;
#
sub init
{
- my ($pkg, $fn) = @_;
+ my ($pkg, $fn, $mode) = @_;
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;
}
sub finish
{
- $dbm = undef;
+ undef $dbm;
untie %u;
}
$self->{dxok} = 1;
$self->{annok} = 1;
$self->{lang} = $main::lang;
- $u{call} = $self;
+ $u{call} = $self->encode();
return $self;
}
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;
}
#
my $dxchan = DXChannel->get($call);
return $dxchan->user if $dxchan;
- return $u{$call};
+ my $s = $u{$call};
+ return $s ? decode($s) : undef;
}
#
{
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;
}
#