3 %# Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
5 %# (Except where explictly superceded by other copyright notices)
7 %# This work is made available to you under the terms of Version 2 of
8 %# the GNU General Public License. A copy of that license should have
9 %# been provided with this software, but in any event can be snarfed
12 %# This work is distributed in the hope that it will be useful, but
13 %# WITHOUT ANY WARRANTY; without even the implied warranty of
14 %# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 %# General Public License for more details.
17 %# Unless otherwise specified, all modifications, corrections or
18 %# extensions to this work which alter its source code become the
19 %# property of Best Practical Solutions, LLC when submitted for
20 %# inclusion in the work.
25 my %cookies = CGI::Cookie->fetch();
27 mysql => 'Apache::Session::MySQL',
28 Pg => 'Apache::Session::Postgres',
29 Oracle => 'Apache::Session::Oracle',
30 ) unless $RT::WebSessionClass;
31 my $session_class = $RT::WebSessionClass || $backends{$RT::DatabaseType} || 'Apache::Session::File';
32 my $pm = "$session_class.pm"; $pm =~ s|::|/|g; require $pm;
35 tie %session, $session_class,
36 $SessionCookie || ( $cookies{'RT_SID'} ? $cookies{'RT_SID'}->value() : undef ),
37 $backends{$RT::DatabaseType} ? {
38 Handle => $RT::Handle->dbh,
39 LockHandle => $RT::Handle->dbh,
41 Directory => $RT::MasonSessionDir,
42 LockDirectory => $RT::MasonSessionDir,
47 # If the session is invalid, create a new session.
48 if ( $@ =~ /Object does not/i ) {
49 tie %session, $session_class, undef,
50 $backends{$RT::DatabaseType} ? {
51 Handle => $RT::Handle->dbh,
52 LockHandle => $RT::Handle->dbh,
54 Directory => $RT::MasonSessionDir,
55 LockDirectory => $RT::MasonSessionDir,
57 undef $cookies{'RT_SID'};
60 die "RT Couldn't write to session directory '$RT::MasonSessionDir': $@. Check that this dir ectory's permissions are correct.";
64 if ( !$cookies{'RT_SID'} ) {
65 my $cookie = new CGI::Cookie(
67 -value => $session{_session_id},
70 $r->header_out('Set-Cookie', $cookie->as_string);