File: Application.pm

package info (click to toggle)
libapache-asp-perl 2.63-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster
  • size: 4,120 kB
  • sloc: perl: 6,044; php: 409; sh: 62; lisp: 22; makefile: 10
file content (75 lines) | stat: -rw-r--r-- 1,625 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75

package Apache::ASP::Application;

use Apache::ASP::State;
use Apache::ASP::Collection;

use strict;
no strict qw(refs);
use vars qw(@ISA);
@ISA = qw(Apache::ASP::Collection Apache::ASP::State);
use Fcntl qw(:flock O_RDWR O_CREAT );

sub new {
    my($asp) = @_;
    my(%self);

    unless(
	   tie(
	       %self,'Apache::ASP::State', $asp, 
	       'application', 'server', 
	       )
	   )
    {
	$asp->Error("can't tie to application state");
	return;
    }

    bless \%self;
}

sub Lock { shift->SUPER::LOCK };
sub UnLock { shift->SUPER::UNLOCK };

sub SessionCount {
    my $asp = tied(%{$_[0]})->{asp};
    if($asp->{session_count}) {
	$asp->{Internal}{SessionCount};
    } else {
	undef;
    }
}

sub GetSession {
    my($self, $id) = @_;
    my $asp = tied(%$self)->{'asp'};
    unless(defined $id and $id) {
	$asp->Warn("session id not defined");
	return;
    }
    unless(length($id) >= 8) {
	$asp->Warn("session id must be of at least 8 in length");
	return;
    }

    if($asp->{Session} and $asp->{Session}->SessionID() eq $id) {
	return $asp->{Session};
    } else {
	my $new_session = Apache::ASP::Session::new($asp, $id, O_RDWR, 'NOERR');
	if($new_session) {
	    if ($asp->{get_session_last}) {
		my $session_obj = tied %{$asp->{get_session_last}};
		$asp->{dbg} && $asp->Debug("freeing last session $asp->{get_session_last} $session_obj");
		$session_obj && $session_obj->DESTROY;
	    }
	    $asp->{get_session_last} = $new_session;
	    $asp->RegisterCleanup(sub {
				      my $session_obj = tied %$new_session;
				      $session_obj && $session_obj->DESTROY;
				  });
	}
	$new_session;
    }
}

1;