From d838f61556a90834fe396099fe03c29a810c6e76 Mon Sep 17 00:00:00 2001 From: michael Date: Thu, 30 Sep 2010 08:54:19 +0000 Subject: * 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 --- packages/fcl-web/src/base/fpweb.pp | 6 +----- packages/fcl-web/src/base/websession.pp | 36 ++++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 14 deletions(-) (limited to 'packages/fcl-web') 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 -- cgit v1.2.1