X-Git-Url: http://dxcluster.org/gitweb/gitweb.cgi?a=blobdiff_plain;f=perl%2FDXUser.pm;h=a9c7ea030177eb75948a2c5954e9242ab121487e;hb=d9db74c1b2b9b57cb6d31e8c8c425f3636f62f87;hp=810bb7682d85c7f752249b013b2ef8ff3909fc81;hpb=584783d0ee480f9f56c167fc2e2aec280ba5e897;p=spider.git diff --git a/perl/DXUser.pm b/perl/DXUser.pm index 810bb768..a9c7ea03 100644 --- a/perl/DXUser.pm +++ b/perl/DXUser.pm @@ -11,7 +11,7 @@ package DXUser; require Exporter; @ISA = qw(Exporter); -use MLDBM qw(DB_File); +use DB_File; use Fcntl; use Carp; @@ -73,10 +73,16 @@ sub AUTOLOAD # 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; } @@ -88,7 +94,7 @@ use strict; sub finish { - $dbm = undef; + undef $dbm; untie %u; } @@ -110,7 +116,7 @@ sub new $self->{dxok} = 1; $self->{annok} = 1; $self->{lang} = $main::lang; - $u{call} = $self; + $u{call} = $self->encode(); return $self; } @@ -124,7 +130,8 @@ sub get 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 +159,8 @@ sub get_current my $dxchan = DXChannel->get($call); return $dxchan->user if $dxchan; - return $u{$call}; + my $s = $u{$call}; + return $s ? decode($s) : undef; } # @@ -163,7 +171,49 @@ sub put { 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; } #