summaryrefslogtreecommitdiff
path: root/packages/fcl-web
diff options
context:
space:
mode:
authormichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-09-30 08:54:19 +0000
committermichael <michael@3ad0048d-3df7-0310-abae-a5850022a9f2>2010-09-30 08:54:19 +0000
commitd838f61556a90834fe396099fe03c29a810c6e76 (patch)
tree077262eda325f3cf1f41d490205c9039f58a6ae2 /packages/fcl-web
parent02cc50c419a7f1387dd9577e3adc1648a3e22b0a (diff)
downloadfpc-d838f61556a90834fe396099fe03c29a810c6e76.tar.gz
* improved session management:
- GlobalSessionDir is now always used, even when creating descendents of TWebIniSession. - Explicitly Free session. (Prepares for persistent session info for fastcgi apps) git-svn-id: http://svn.freepascal.org/svn/fpc/trunk@16069 3ad0048d-3df7-0310-abae-a5850022a9f2
Diffstat (limited to 'packages/fcl-web')
-rw-r--r--packages/fcl-web/src/base/fpweb.pp6
-rw-r--r--packages/fcl-web/src/base/websession.pp36
2 files changed, 28 insertions, 14 deletions
diff --git a/packages/fcl-web/src/base/fpweb.pp b/packages/fcl-web/src/base/fpweb.pp
index 9797fbf4ce..95bfdfee77 100644
--- a/packages/fcl-web/src/base/fpweb.pp
+++ b/packages/fcl-web/src/base/fpweb.pp
@@ -465,11 +465,7 @@ begin
FRequest := Nil;
FResponse := Nil;
// Clean up session for the case the webmodule is used again
- if assigned(Session) then
- begin
- Session.Free;
- Session := nil;
- end;
+ DoneSession;
{$ifdef cgidebug}
SendMethodExit('WebModule('+Name+').handlerequest');
{$endif cgidebug}
diff --git a/packages/fcl-web/src/base/websession.pp b/packages/fcl-web/src/base/websession.pp
index 8868fec761..e4bb54c2cd 100644
--- a/packages/fcl-web/src/base/websession.pp
+++ b/packages/fcl-web/src/base/websession.pp
@@ -36,7 +36,9 @@ Type
Procedure CheckSession(ARequest : TRequest);
Procedure InitSession(AResponse : TResponse);
Procedure UpdateSession(AResponse : TResponse);
+ Procedure DoneSession; virtual;
Public
+ destructor destroy; override;
Procedure Notification(AComponent : TComponent;Operation : TOperation); override;
Procedure Loaded; Override;
Property CreateSession : Boolean Read FCreateSession Write FCreateSession;
@@ -59,6 +61,7 @@ Type
SID : String;
private
procedure FreeIniFile;
+ function GetSessionDir: String;
Protected
Procedure CheckSession;
Function GetSessionID : String; override;
@@ -66,7 +69,7 @@ Type
procedure SetSessionVariable(VarName : String; const AValue: String); override;
Property Cached : Boolean Read FCached Write FCached;
property SessionCookie : String Read FSessionCookie Write FSessionCookie;
- Property SessionDir : String Read FSessionDir Write FSessionDir;
+ Property SessionDir : String Read GetSessionDir Write FSessionDir;
Property SessionCookiePath : String Read FSessionCookiePath write FSessionCookiePath;
Public
Destructor Destroy; override;
@@ -107,7 +110,7 @@ Const
SData = 'Data';
KeyStart = 'Start'; // Start time of session
- KeyLast = 'Start'; // Last seen time of session
+ KeyLast = 'Last'; // Last seen time of session
KeyTimeOut = 'Timeout'; // Timeout in seconds;
SFPWebSession = 'FPWebSession'; // Cookie name for session.
@@ -118,9 +121,6 @@ resourcestring
Function GetDefaultSession : TCustomSession;
-Var
- W : TFPWebSession;
-
begin
{$ifdef cgidebug}SendMethodEnter('GetDefaultSession');{$endif}
Result:=Nil;
@@ -134,9 +134,7 @@ begin
if (Result=Nil) then
begin
{$ifdef cgidebug}Senddebug('Creating iniwebsession');{$endif}
- W:=TFPWebSession.Create(Nil);
- W.SessionDir:=GlobalSessionDir;
- Result:=W;
+ Result:=TFPWebSession.Create(Nil);
end;
{$ifdef cgidebug}SendMethodExit('GetDefaultSession');{$endif}
end;
@@ -157,6 +155,13 @@ begin
FreeAndNil(FIniFile);
end;
+function TIniWebSession.GetSessionDir: String;
+begin
+ Result:=FSessionDir;
+ If (Result='') then
+ Result:=GlobalSessionDir;
+end;
+
Procedure TIniWebSession.CheckSession;
begin
@@ -234,7 +239,7 @@ begin
L:=Finifile.ReadDateTime(SSession,KeyLast,0);
{$ifdef cgidebug}
If (L=0) then
- SendDebug('No datetime in inifile');
+ SendDebug('No datetime in inifile (or not valid datetime : '+Finifile.ReadString(SSession,KeyLast,''));
{$endif}
T:=FIniFile.ReadInteger(SSession,KeyTimeOut,Self.TimeOutMinutes);
{$ifdef cgidebug}SendDebug('Timeout :'+IntToStr(t));{$endif}
@@ -374,6 +379,19 @@ begin
FSession.UpdateResponse(AResponse);
end;
+procedure TSessionHTTPModule.DoneSession;
+begin
+ FreeAndNil(FSession);
+end;
+
+destructor TSessionHTTPModule.destroy;
+begin
+ // Prevent memory leaks.
+ If Assigned(FSession) then
+ DoneSession;
+ inherited destroy;
+end;
+
procedure TSessionHTTPModule.Notification(AComponent: TComponent;
Operation: TOperation);
begin