OpenInteract::Session::File - Create sessions within a filesystem


OpenInteract documentation Contained in the OpenInteract distribution.

Index


Code Index:

NAME

Top

OpenInteract::Session::File - Create sessions within a filesystem

SYNOPSIS

Top

 # In your configuration file

 [session_info]
 class       = Apache::Session::File
 ...

 [session_info.params]
 Directory     = /home/httpd/oi/sessions/data
 LockDirectory = /home/httpd/oi/sessions/lock
 ...

 [system_alias]
 session       = OpenInteract::Session::File

DESCRIPTION

Top

Provide a '_create_session' method for OpenInteract::Session so we can use a filesystem as a backend for Apache::Session.

Note that failure to create the session throws a '310' error, which clears out the session cookie so it does not keep happening. (See OpenInteract::Error::System for the code.)

METHODS

Top

_create_session( $session_id )

Overrides the method from parent OpenInteract::Session, using the configuration information:

BUGS

Top

None known.

TO DO

Top

Nothing.

SEE ALSO

Top

Apache::Session::File (Apache::Session::File)

OpenInteract::Session

COPYRIGHT

Top

AUTHORS

Top

Chris Winters <chris@cwinters.com>


OpenInteract documentation Contained in the OpenInteract distribution.

package OpenInteract::Session::File;

# $Id: File.pm,v 1.3 2002/09/08 20:52:44 lachoy Exp $

use strict;
use base qw( OpenInteract::Session );
use Apache::Session::File;

$OpenInteract::Session::File::VERSION = sprintf("%d.%02d", q$Revision: 1.3 $ =~ /(\d+)\.(\d+)/);

sub _create_session {
    my ( $class, $session_id ) = @_;
    my $R = OpenInteract::Request->instance;
    my $CONFIG = $R->CONFIG;
    my $session_params = $CONFIG->{session_info}{params} || {};
    unless ( $session_params->{Directory} and
             -d $session_params->{Directory} and
             $session_params->{LockDirectory} and
             -d $session_params->{LockDirectory} ) {
        $R->throw({ code => 310, type => 'session',
                    system_msg => "Both the 'Directory' and 'LockDirectory' " .
                                  "keys must be defined under the server " .
                                  "config key 'session_info.params'" });
        $R->scrib( 0, "Error thrown because directories (Dir: ",
                      "[$session_params->{Directory}]) (Lock: ",
                      "[$session_params->{LockDirectory}])" );
        return undef;
    }

    my %session = ();
    $R->DEBUG && $R->scrib( 1, "Trying to fetch session [$session_id]" );
    eval { tie %session, 'Apache::Session::File',
                         $session_id, $session_params };
    if ( $@ ) {
        $R->throw({ code       => 310,
                    type       => 'session',
                    system_msg => $@,
                    extra      => { session_id => $session_id } });
        $R->scrib( 0, "Error thrown. Now clear the cookie" );
        return undef;
    }
    return \%session if ( scalar keys %session );
    return undef;
}

1;


__END__