IdFingerServer.pas 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.6 12/2/2004 4:23:54 PM JPMugaas
  18. Adjusted for changes in Core.
  19. Rev 1.5 1/21/2004 2:29:40 PM JPMugaas
  20. InitComponent
  21. Rev 1.4 2/24/2003 08:41:24 PM JPMugaas
  22. Should compile with new code.
  23. Rev 1.3 1/17/2003 05:35:02 PM JPMugaas
  24. Now compiles with new design.
  25. Rev 1.2 1/9/2003 07:10:56 AM JPMugaas
  26. Changed Finger server API so developers do not have to mess with the Context
  27. and Connnection objects.
  28. Rev 1.1 1-1-2003 20:13:02 BGooijen
  29. Changed to support the new TIdContext class
  30. Rev 1.0 11/14/2002 02:19:56 PM JPMugaas
  31. 2000-May-15 J. Peter Mugaas
  32. -Added verbose querry event to complement TIdFinger
  33. 2000-Apr-22 J Peter Mugass
  34. -Ported to Indy
  35. 2000-Jan-13 MTL
  36. -Moved to new Palette Scheme (Winshoes Servers)
  37. 1999-Apr-13
  38. -Final Version
  39. }
  40. unit IdFingerServer;
  41. {
  42. Original Author: Ozz Nixon
  43. }
  44. interface
  45. {$i IdCompilerDefines.inc}
  46. uses
  47. Classes,
  48. IdAssignedNumbers,
  49. IdContext,
  50. IdCustomTCPServer;
  51. Type
  52. TIdFingerGetEvent = procedure (AContext:TIdContext; const AUserName: String; var VResponse : String) of object;
  53. TIdFingerServer = class ( TIdCustomTCPServer )
  54. protected
  55. FOnCommandFinger : TIdFingerGetEvent;
  56. FOnCommandVerboseFinger : TIdFingerGetEvent;
  57. //
  58. function DoExecute(AContext: TIdContext): boolean; override;
  59. public
  60. constructor Create(AOwner: TComponent); override;
  61. published
  62. {This event fires when you make a regular querry}
  63. property OnCommandFinger: TIdFingerGetEvent read FOnCommandFinger
  64. write FOnCommandFinger;
  65. { This event fires when you receive a VERBOSE finger request}
  66. property OnCommandVerboseFinger : TIdFingerGetEvent
  67. read FOnCommandVerboseFinger write FOnCommandVerboseFinger;
  68. property DefaultPort default IDPORT_Finger;
  69. end;
  70. implementation
  71. uses
  72. IdGlobal, SysUtils;
  73. constructor TIdFingerServer.Create(AOwner: TComponent);
  74. begin
  75. inherited Create(AOwner);
  76. DefaultPort := IdPORT_FINGER;
  77. end;
  78. function TIdFingerServer.DoExecute(AContext:TIdContext): boolean;
  79. var
  80. s, LResponse: String;
  81. begin
  82. Result := True;
  83. {We use TrimRight in case there are spaces ending the query which are problematic
  84. for verbose queries. CyberKit puts a space after the /W parameter}
  85. s := TrimRight(AContext.Connection.IOHandler.ReadLn);
  86. if Assigned(FOnCommandVerboseFinger) and TextEndsWith(s, '/W') then {Do not Localize}
  87. begin
  88. {we remove the /W switch before calling the event}
  89. SetLength(s, Length(s)-2);
  90. OnCommandVerboseFinger(AContext, s, LResponse);
  91. AContext.Connection.IOHandler.Write(LResponse);
  92. end
  93. else if Assigned(OnCommandFinger) then begin
  94. OnCommandFinger(AContext, s, LResponse);
  95. AContext.Connection.IOHandler.Write(LResponse);
  96. end;
  97. AContext.Connection.Disconnect;
  98. end;
  99. end.