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 return if $m->is_subrequest; # avoid reentrancy, as suggested by masonbook
27 my %cookies = CGI::Cookie->fetch();
28 my $cookiename = "RT_SID_".$RT::rtname.".".$ENV{'SERVER_PORT'};
30 mysql => 'Apache::Session::MySQL',
31 Pg => 'Apache::Session::Postgres',
32 # Oracle => 'Apache::Session::Oracle',
33 ) unless $RT::WebSessionClass;
34 my $session_class = $RT::WebSessionClass || $backends{$RT::DatabaseType} || 'Apache::Session::File';
35 my $pm = "$session_class.pm"; $pm =~ s|::|/|g; require $pm;
37 # morning bug avoidance attempt -- pdh 20030815
38 unless ($RT::Handle->dbh && $RT::Handle->dbh->ping) {
39 $RT::Handle->Connect();
42 tie %session, $session_class,
43 $SessionCookie || ( $cookies{$cookiename} ? $cookies{$cookiename}->value() : undef ),
44 $backends{$RT::DatabaseType} ? {
45 Handle => $RT::Handle->dbh,
46 LockHandle => $RT::Handle->dbh,
48 Directory => $RT::MasonSessionDir,
49 LockDirectory => $RT::MasonSessionDir,
54 # If the session is invalid, create a new session.
55 if ( $@ =~ /Object does not/i ) {
56 tie %session, $session_class, undef,
57 $backends{$RT::DatabaseType} ? {
58 Handle => $RT::Handle->dbh,
59 LockHandle => $RT::Handle->dbh,
61 Directory => $RT::MasonSessionDir,
62 LockDirectory => $RT::MasonSessionDir,
64 undef $cookies{$cookiename};
67 die "RT Couldn't write to session directory '$RT::MasonSessionDir': $@. Check that this dir ectory's permissions are correct.";
71 if ( !$cookies{$cookiename} ) {
72 my $cookie = new CGI::Cookie(
74 -value => $session{_session_id},
77 $r->header_out('Set-Cookie', $cookie->as_string);