| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170 |
- {
- $Project$
- $Workfile$
- $Revision$
- $DateUTC$
- $Id$
- This file is part of the Indy (Internet Direct) project, and is offered
- under the dual-licensing agreement described on the Indy website.
- (http://www.indyproject.org/)
- Copyright:
- (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
- }
- {
- $Log$
- }
- {
- Rev 1.6 1/19/05 11:18:16 AM RLebeau
- bug fix for GetConnectionID()
- Rev 1.5 2004.02.03 5:45:38 PM czhower
- Name changes
- Rev 1.4 2004.01.22 5:58:58 PM czhower
- IdCriticalSection
- Rev 1.3 1/21/2004 4:03:20 PM JPMugaas
- InitComponent
- Rev 1.2 2003.10.17 6:15:02 PM czhower
- consts removed
- Rev 1.1 2003.10.14 1:31:14 PM czhower
- DotNet
- Rev 1.0 3/22/2003 10:59:20 PM BGooijen
- Initial check in.
- ServerIntercept to ease debugging, data/status are logged to a file
- }
- unit IdServerInterceptLogBase;
- interface
- {$i IdCompilerDefines.inc}
- uses
- IdIntercept, IdGlobal, IdLogBase, IdBaseComponent, Classes;
- type
- TIdServerInterceptLogBase = class(TIdServerIntercept)
- protected
- FLock: TIdCriticalSection;
- FLogTime: Boolean;
- FReplaceCRLF: Boolean;
- //
- FHasInit: Boolean; // BGO: can be removed later, see comment below (.Init)
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Init; override;
- function Accept(AConnection: TComponent): TIdConnectionIntercept; override;
- procedure DoLogWriteString(const AText: string); virtual; abstract;
- procedure LogWriteString(const AText: string); virtual;
- published
- property LogTime: Boolean read FLogTime write FLogTime default True;
- property ReplaceCRLF: Boolean read FReplaceCRLF write FReplaceCRLF default true;
- end;
- TIdServerInterceptLogFileConnection = class(TIdLogBase) //BGO: i just love long class names <g>
- protected
- FServerInterceptLog:TIdServerInterceptLogBase;
- procedure LogReceivedData(const AText, AData: string); override;
- procedure LogSentData(const AText, AData: string); override;
- procedure LogStatus(const AText: string); override;
- function GetConnectionID: string; virtual;
- end;
- implementation
- uses
- {$IFDEF DCC_XE3_OR_ABOVE}
- System.SyncObjs,
- {$ENDIF}
- IdIOHandlerSocket,
- IdResourceStringsCore,
- IdTCPConnection,
- SysUtils;
- { TIdServerInterceptLogFile }
- constructor TIdServerInterceptLogBase.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner;
- FReplaceCRLF := True;
- FLogTime := True;
- FLock := TIdCriticalSection.Create;
- end;
- destructor TIdServerInterceptLogBase.Destroy;
- begin
- FLock.Free;
- inherited Destroy;
- end;
- function TIdServerInterceptLogBase.Accept(AConnection: TComponent): TIdConnectionIntercept;
- var
- LConn: TIdServerInterceptLogFileConnection;
- begin
- LConn := TIdServerInterceptLogFileConnection.Create(nil);
- LConn.FServerInterceptLog := Self;
- LConn.LogTime := FLogTime;
- LConn.ReplaceCRLF := FReplaceCRLF;
- LConn.Active := True;
- Result := LConn;
- end;
- procedure TIdServerInterceptLogBase.Init;
- begin
- end;
- procedure TIdServerInterceptLogBase.LogWriteString(const AText: string);
- begin
- if AText <> '' then begin
- FLock.Enter;
- try
- if not FHasInit then begin
- Init; // BGO: This is just a hack, TODO find out where to call init
- FHasInit := True;
- end;
- DoLogWriteString(AText);
- finally
- FLock.Leave;
- end;
- end;
- end;
- { TIdServerInterceptLogFileConnection }
- procedure TIdServerInterceptLogFileConnection.LogReceivedData(const AText, AData: string);
- begin
- FServerInterceptLog.LogWriteString(GetConnectionID + ' ' + RSLogRecv + AText + ': ' + AData + EOL); {Do not translate}
- end;
- procedure TIdServerInterceptLogFileConnection.LogSentData(const AText, AData: string);
- begin
- FServerInterceptLog.LogWriteString(GetConnectionID + ' ' + RSLogSent + AText + ': ' + AData + EOL); {Do not translate}
- end;
- procedure TIdServerInterceptLogFileConnection.LogStatus(const AText: string);
- begin
- FServerInterceptLog.LogWriteString(GetConnectionID + ' ' + RSLogStat + AText + EOL);
- end;
- function TIdServerInterceptLogFileConnection.GetConnectionID: string;
- var
- LSocket: TIdIOHandlerSocket;
- begin
- if FConnection is TIdTCPConnection then begin
- LSocket := TIdTCPConnection(FConnection).Socket;
- if (LSocket <> nil) and (LSocket.Binding <> nil) then begin
- Result := LSocket.Binding.PeerIP + ':' + IntToStr(LSocket.Binding.PeerPort);
- Exit;
- end;
- end;
- Result := '0.0.0.0:0';
- end;
- end.
-
|