Apache-ASP
view release on metacpan or search on metacpan
lib/Apache/ASP/StateManager.pm view on Meta::CPAN
package Apache::ASP;
# quickly decomped out of Apache::ASP so we could load the routines only
# when we are managing State objects
use Apache::ASP::State;
use strict;
use vars qw(
$CleanupGroups
$SessionIDLength $SessionTimeout $StateManager
$DefaultStateDB $DefaultStateSerializer
);
$SessionTimeout = 20;
$StateManager = 10;
# Some OS's have hashed directory lookups up to 16 bytes, so we leave room
# for .lock extension ... nevermind, security is more important, back to 32
# $SessionIDLength = 11;
$SessionIDLength = 32;
$DefaultStateDB = 'SDBM_File';
$DefaultStateSerializer = 'Data::Dumper';
sub InitState {
my $self = shift;
my $r = $self->{r};
my $global_asa = $self->{GlobalASA};
## STATE INITS
# what percent of the session_timeout's time do we garbage collect
# state files and run programs like Session_OnEnd and Application_OnEnd
$self->{state_manager} = &config($self, 'StateManager', undef, $Apache::ASP::StateManager);
# state is the path where state files are stored, like $Session, $Application, etc.
$self->{state_dir} = &config($self, 'StateDir', undef, $self->{global}.'/.state');
$self->{state_dir} =~ tr///; # untaint
$self->{session_state} = &config($self, 'AllowSessionState', undef, 1);
$self->{state_serialize} = &config($self, 'ApplicationSerialize');
if($self->{state_db} = &config($self, 'StateDB')) {
# StateDB - Check StateDB module support
$Apache::ASP::State::DB{$self->{state_db}} ||
$self->Error("$self->{state_db} is not supported for StateDB, try: " .
join(", ", keys %Apache::ASP::State::DB));
$self->{state_db} =~ /^(.*)$/; # untaint
$self->{state_db} = $1; # untaint
# load the state database module && serializer
$self->LoadModule('StateDB', $self->{state_db});
}
if($self->{state_serializer} = &config($self, 'StateSerializer')) {
$self->{state_serializer} =~ tr///; # untaint
$self->LoadModule('StateSerializer', $self->{state_serializer});
}
# INTERNAL tie to the application internal info
my %Internal;
tie(%Internal, 'Apache::ASP::State', $self, 'internal', 'server')
|| $self->Error("can't tie to internal state");
my $internal = $self->{Internal} = bless \%Internal, 'Apache::ASP::State';
$self->{state_serialize} && $internal->LOCK;
# APPLICATION create application object
$self->{app_state} = &config($self, 'AllowApplicationState', undef, 1);
if($self->{app_state}) {
# load at runtime for CGI environments, preloaded for mod_perl
require Apache::ASP::Application;
($self->{Application} = &Apache::ASP::Application::new($self))
|| $self->Error("can't get application state");
$self->{state_serialize} && $self->{Application}->Lock;
} else {
$self->{dbg} && $self->Debug("no application allowed config");
}
# SESSION if we are tracking state, set up the appropriate objects
my $session;
if($self->{session_state}) {
## SESSION INITS
$self->{cookie_path} = &config($self, 'CookiePath', undef, '/');
$self->{cookie_domain} = &config($self, 'CookieDomain');
$self->{paranoid_session} = &config($self, 'ParanoidSession');
( run in 1.110 second using v1.01-cache-2.11-cpan-39bf76dae61 )