This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
/
SessionDB.pm
110 lines (95 loc) · 2.76 KB
/
SessionDB.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# SessionDB.pm: stores session information in files
#
# $Id: SessionDB.pm,v 1.2 2000/02/06 01:51:27 mike Exp $
#
# Copyright 1996-2000 by Michael J. Heins <mikeh@minivend.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public
# License along with this program; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA.
# $Id: SessionDB.pm,v 1.2 2000/02/06 01:51:27 mike Exp $
package Vend::SessionDB;
require Tie::Hash;
@ISA = qw(Tie::Hash);
use strict;
use Vend::Util;
use vars qw($VERSION);
$VERSION = substr(q$Revision: 1.2 $, 10);
my $SessionDB;
my $SessionLock;
my $Last;
my @Each;
sub TIEHASH {
my($self, $db) = @_;
$db = Vend::Data::database_exists_ref($db);
$db = $db->ref();
#::logDebug("$self: tied");
die "Vend::SessionDB: bad database\n"
unless $db;
bless { DB => $db }, $self;
}
sub FETCH {
my($self, $key) = @_;
#::logDebug("$self fetch: $key");
return undef unless $self->{DB}->record_exists($key);
#::logDebug("$self exists: $key");
return $self->{DB}->field($key, 'sessionlock') if $key =~ s/^LOCK_//;
#::logDebug("$self complex fetch: $key");
my $data = $self->{DB}->field($key, 'session');
return undef unless $data;
return $data;
}
sub FIRSTKEY {
my $self = shift;
my $tmp = pop @{$self->{DB}};
eval {
$self->{DB}->config('DELIMITER');
};
push @{$self->{DB}}, $tmp if $@;
return $self->{DB}->each_record();
}
sub NEXTKEY {
return $_[0]->{DB}->each_record();
}
sub EXISTS {
my($self,$key) = @_;
#::logDebug("$self EXISTS check: $key");
if ($key =~ s/^LOCK_//) {
return undef unless $self->{DB}->record_exists($key);
return undef unless $self->{DB}->field($key, 'sessionlock');
return 1;
}
return undef unless $self->{DB}->record_exists($key);
1;
}
sub DELETE {
my($self,$key) = @_;
#::logDebug("$self delete: $key");
if($key =~ s/^LOCK_// ) {
return undef unless $self->{DB}->record_exists($key);
$self->{DB}->set_field($key,'sessionlock','');
return 1;
}
$self->{DB}->delete_record($key);
}
sub STORE {
my($self, $key, $val) = @_;
my $locking = $key =~ s/^LOCK_//;
$self->{DB}->set_row($key) unless $self->{DB}->record_exists($key);
return $self->{DB}->set_field($key, 'sessionlock', $val) if $locking;
$self->{DB}->set_field( $key, 'session', $val);
return 1;
}
1;
__END__