| 1 | package OpenInteract2::SessionManager::File; | ||
| 2 | |||
| 3 | # $Id: File.pm,v 1.7 2005/03/18 04:09:51 lachoy Exp $ | ||
| 4 | |||
| 5 | use strict; | ||
| 6 | use base qw( OpenInteract2::SessionManager ); | ||
| 7 | use File::Spec::Functions qw( catdir ); | ||
| 8 | use Log::Log4perl qw( get_logger ); | ||
| 9 | use OpenInteract2::Constants qw( :log ); | ||
| 10 | use OpenInteract2::Context qw( CTX ); | ||
| 11 | use OpenInteract2::Exception qw( oi_error ); | ||
| 12 | |||
| 13 | $OpenInteract2::SessionManager::File::VERSION = sprintf("%d.%02d", q$Revision: 1.7 $ =~ /(\d+)\.(\d+)/); | ||
| 14 | |||
| 15 | my ( $log ); | ||
| 16 | |||
| 17 | sub _create_session { | ||
| 18 | my ( $class, $session_config, $session_id ) = @_; | ||
| 19 | $session_id = '' unless ( defined $session_id ); | ||
| 20 | $log ||= get_logger( LOG_SESSION ); | ||
| 21 | |||
| 22 | my $impl_class = $session_config->{impl_class}; | ||
| 23 | my $session_params = $session_config->{params}; | ||
| 24 | $log->is_info && | ||
| 25 | $log->info( "Trying to fetch File session '$session_id' ", | ||
| 26 | "with [Dir: $session_params->{Directory}] ", | ||
| 27 | "[LockDir: $session_params->{LockDirectory}] ", | ||
| 28 | "[Impl: $impl_class]" ); | ||
| 29 | my %session = (); | ||
| 30 | tie %session, $impl_class, $session_id, $session_params; | ||
| 31 | return \%session; | ||
| 32 | } | ||
| 33 | |||
| 34 | |||
| 35 | sub _validate_config { | ||
| 36 | my ( $class, $session_config ) = @_; | ||
| 37 | my @error_msg = (); | ||
| 38 | unless ( $session_config->{impl_class} ) { | ||
| 39 | push @error_msg, | ||
| 40 | join( '', "Cannot use file-based session storage without the ", | ||
| 41 | "parameter 'session_info.impl_class' set to the", | ||
| 42 | "correct session implementation. (Normally: ", | ||
| 43 | "Apache::Session::File)" ); | ||
| 44 | } | ||
| 45 | |||
| 46 | my $dir = $session_config->{params}{Directory}; | ||
| 47 | my $website_dir = CTX->lookup_directory( 'website' ); | ||
| 48 | if ( $dir && $dir !~ m!^(/|\w:)! ) { | ||
| 49 | $dir = catdir( $website_dir, $dir ); | ||
| 50 | $session_config->{params}{Directory} = $dir; | ||
| 51 | } | ||
| 52 | unless ( -d $dir ) { | ||
| 53 | push @error_msg, | ||
| 54 | join( '', "Server configuration key 'session_info.params.Directory' ", | ||
| 55 | "must refer to a valid directory. (Given: $dir)" ); | ||
| 56 | } | ||
| 57 | |||
| 58 | my $lock_dir = $session_config->{params}{LockDirectory}; | ||
| 59 | if ( $lock_dir && $lock_dir !~ m!^(/|\w:)! ) { | ||
| 60 | $lock_dir = catdir( $website_dir, $lock_dir ); | ||
| 61 | $session_config->{params}{LockDirectory} = $lock_dir; | ||
| 62 | } | ||
| 63 | unless ( -d $lock_dir ) { | ||
| 64 | push @error_msg, | ||
| 65 | join( '', "Server configuration key 'session_info.params.LockDirectory' ", | ||
| 66 | "must refer to a valid directory. (Given: $lock_dir)" ); | ||
| 67 | } | ||
| 68 | return @error_msg; | ||
| 69 | } | ||
| 70 | |||
| 71 | 1; | ||
| 72 | |||
| 73 | __END__ |