PageRenderTime 35ms CodeModel.GetById 24ms app.highlight 9ms RepoModel.GetById 0ms app.codeStats 0ms

/packages/fcl-web/src/base/websession.pp

https://github.com/slibre/freepascal
Puppet | 102 lines | 80 code | 22 blank | 0 comment | 7 complexity | 8b4d03e8df65bf3ab36577ed1f640c45 MD5 | raw file
Possible License(s): LGPL-2.0, LGPL-2.1, LGPL-3.0
  1{
  2    $Id: header,v 1.1 2000/07/13 06:33:45 michael Exp $
  3    This file is part of the Free Component Library (FCL)
  4    Copyright (c) 1999-2000 by the Free Pascal development team
  5
  6    See the file COPYING.FPC, included in this distribution,
  7    for details about the copyright.
  8
  9    This program is distributed in the hope that it will be useful,
 10    but WITHOUT ANY WARRANTY; without even the implied warranty of
 11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 12
 13 **********************************************************************}
 14unit websession deprecated;
 15
 16{$mode objfpc}{$H+}
 17{ $define cgidebug}
 18interface
 19
 20uses
 21  Classes, SysUtils, fphttp, iniwebsession, httpdefs;
 22  
 23Type
 24  TIniWebSession = iniwebsession.TIniWebSession;
 25
 26  TFPWebSession = Class(iniwebsession.TIniWebSession)
 27  Public
 28    Property Cached;
 29    property SessionCookie;
 30    Property SessionCookiePath;
 31    Property SessionDir;
 32  end;
 33
 34Type
 35  TGetSessionEvent = Procedure(Var ASession : TCustomSession) of object;
 36
 37Var
 38  GlobalSessionDir : String deprecated;
 39  OnGetDefaultSession : TGetSessionEvent deprecated;
 40
 41Function GetDefaultSession : TCustomSession;
 42
 43implementation
 44type
 45
 46  { TWebSessionFactory }
 47
 48  TWebSessionFactory = Class(TIniSessionFactory)
 49  Protected
 50    Function DoCreateSession(ARequest : TRequest) : TCustomSession; override;
 51  end;
 52
 53
 54Function GetDefaultSession : TCustomSession;
 55
 56Var
 57  TD : String;
 58
 59begin
 60{$ifdef cgidebug}SendMethodEnter('GetDefaultSession');{$endif}
 61  Result:=Nil;
 62  If (GlobalSessionDir='') then
 63    begin
 64    TD:=IncludeTrailingPathDelimiter(GetTempDir(True));
 65    GlobalSessionDir:=TD+'fpwebsessions'+PathDelim;
 66    if Not ForceDirectories(GlobalSessionDir) then
 67      GlobalSessionDir:=TD; // Assuming temp dir is writeable
 68    end
 69  else
 70    GlobalSessionDir:=IncludeTrailingPathDelimiter(GlobalSessionDir);
 71{$ifdef cgidebug}SendDebug('GetDefaultSession, session dir: '+GlobalSessionDir);{$endif}
 72  If Assigned(OnGetDefaultSession) then
 73    OnGetDefaultSession(Result);
 74  if (Result=Nil) then
 75    begin
 76    {$ifdef cgidebug}Senddebug('Creating iniwebsession');{$endif}
 77    if (SessionFactory is TIniSessionFactory) then
 78      if ((SessionFactory as TIniSessionFactory).SessionDir='') then
 79        (SessionFactory as TIniSessionFactory).SessionDir:=GlobalSessionDir;
 80    Result:=SessionFactory.CreateSession(Nil);
 81    end;
 82{$ifdef cgidebug}SendMethodExit('GetDefaultSession');{$endif}
 83end;
 84
 85{ TWebSessionFactory }
 86
 87function TWebSessionFactory.DoCreateSession(ARequest: TRequest
 88  ): TCustomSession;
 89begin
 90  Result:=Nil;
 91  if Assigned(OnGetDefaultSession) then
 92    OnGetDefaultSession(Result);
 93  if Result=Nil then
 94  Result:=inherited DoCreateSession(ARequest);
 95end;
 96
 97
 98initialization
 99  IniWebSessionClass:=TFPWebSession;
100  SessionFactoryClass:=TWebSessionFactory;
101end.
102