line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Apache2::Controller::Log::SessionSave; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=head1 NAME |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
Apache2::Controller::Log::SessionSave - Log phase handler to save |
6
|
|
|
|
|
|
|
session data from L hook. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 VERSION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
Version 1.001.001 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=cut |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
2295
|
use version; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
15
|
|
|
|
|
|
|
our $VERSION = version->new('1.001.001'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Don't do anything with this handler. It's set by |
20
|
|
|
|
|
|
|
L to save your session. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
81
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
27
|
1
|
|
|
1
|
|
5
|
use warnings FATAL => 'all'; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
41
|
|
28
|
1
|
|
|
1
|
|
6
|
use English '-no_match_vars'; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
29
|
|
|
|
|
|
|
|
30
|
1
|
|
|
|
|
131
|
use base qw( |
31
|
|
|
|
|
|
|
Apache2::Controller::NonResponseBase |
32
|
|
|
|
|
|
|
Apache2::Controller::Methods |
33
|
1
|
|
|
1
|
|
497
|
); |
|
1
|
|
|
|
|
2
|
|
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
use YAML::Syck; |
36
|
|
|
|
|
|
|
use Log::Log4perl qw(:easy); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
use Apache2::Const -compile => qw( OK HTTP_MULTIPLE_CHOICES ); |
39
|
|
|
|
|
|
|
use Apache2::RequestUtil (); |
40
|
|
|
|
|
|
|
use Apache2::Controller::X; |
41
|
|
|
|
|
|
|
use Apache2::Controller::Const qw( $DEFAULT_SESSION_SECRET ); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=head2 process |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
If aborted connection, don't save, and return. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
If status >- 300 and not set C<< $r->pnotes->{a2c}{session_force_save} >>, |
48
|
|
|
|
|
|
|
don't save, and return. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
If session object is not tied, throw an error. This may not do |
51
|
|
|
|
|
|
|
anything noticible to the user since the request response is |
52
|
|
|
|
|
|
|
finished, but you'll see it in the log. |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Update the top-level timestamp in the session if the directive |
55
|
|
|
|
|
|
|
C is set. |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Untie the session so Apache::Session saves it or not. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
=cut |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub process { |
62
|
|
|
|
|
|
|
my ($self) = @_; |
63
|
|
|
|
|
|
|
my $r = $self->{r}; |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
DEBUG "A2C session cleanup: start handler sub"; |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
my $pnotes_a2c = $r->pnotes->{a2c}; |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
# just return if connection was detected as aborted in Log phase |
70
|
|
|
|
|
|
|
# while the connection was still open |
71
|
|
|
|
|
|
|
if ($pnotes_a2c->{connection_aborted}) { |
72
|
|
|
|
|
|
|
DEBUG "Connection aborted. NOT saving session."; |
73
|
|
|
|
|
|
|
return Apache2::Const::OK; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# don't save if the status code >= 300 and they have not |
77
|
|
|
|
|
|
|
# set the special force-save flag. |
78
|
|
|
|
|
|
|
my $http_status = $r->status; |
79
|
|
|
|
|
|
|
if ($http_status >= Apache2::Const::HTTP_MULTIPLE_CHOICES) { |
80
|
|
|
|
|
|
|
if ($pnotes_a2c->{session_force_save}) { |
81
|
|
|
|
|
|
|
DEBUG "status $http_status, but pnotes->{a2c}{session_force_save} is set." |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
else { |
84
|
|
|
|
|
|
|
DEBUG "status $http_status, not saving session."; |
85
|
|
|
|
|
|
|
return Apache2::Const::OK; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
DEBUG "connection not aborted, saving session..."; |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# connection finished successfully thru whole cycle, so save session |
92
|
|
|
|
|
|
|
my $tied_session = $pnotes_a2c->{_tied_session}; |
93
|
|
|
|
|
|
|
a2cx 'no tied session in pnotes when saving' if !defined $tied_session; |
94
|
|
|
|
|
|
|
a2cx 'pnotes->{a2c}{_tied_session} is not actually tied when saving' |
95
|
|
|
|
|
|
|
if !tied %{$tied_session}; |
96
|
|
|
|
|
|
|
DEBUG "ref of pnotes tied_session is '$tied_session'."; |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
my $session_copy = $pnotes_a2c->{session}; |
99
|
|
|
|
|
|
|
a2cx 'no pnotes->{a2c}{session}' if !defined $session_copy; |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
# set the top-level timestamp to force Apache::Session to save |
102
|
|
|
|
|
|
|
# if our flag is set in directives. |
103
|
|
|
|
|
|
|
$session_copy->{a2c_timestamp} = time |
104
|
|
|
|
|
|
|
if $self->get_directive('A2C_Session_Always_Save'); |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
DEBUG sub{ |
107
|
|
|
|
|
|
|
"putting copy data back into tied session:\n".Dump($session_copy) |
108
|
|
|
|
|
|
|
}; |
109
|
|
|
|
|
|
|
%{$tied_session} = %{$session_copy}; |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
DEBUG sub { |
112
|
|
|
|
|
|
|
my %debug_sess = %{$tied_session}; |
113
|
|
|
|
|
|
|
"real session is now:\n".Dump(\%debug_sess); |
114
|
|
|
|
|
|
|
}; |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
DEBUG "untying session to save it"; |
117
|
|
|
|
|
|
|
untie %{$tied_session}; |
118
|
|
|
|
|
|
|
undef $tied_session; |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
DEBUG "Done saving session in PerlLogHandler"; |
121
|
|
|
|
|
|
|
return Apache2::Const::OK; |
122
|
|
|
|
|
|
|
}; |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=head1 SEE ALSO |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
L |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
L |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
L |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=head1 AUTHOR |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
Mark Hedges, C<< >> |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
Copyright 2008-2010 Mark Hedges, all rights reserved. |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
141
|
|
|
|
|
|
|
under the same terms as Perl itself. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This software is provided as-is, with no warranty |
144
|
|
|
|
|
|
|
and no guarantee of fitness |
145
|
|
|
|
|
|
|
for any particular purpose. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
1; |