IdFinger.pas 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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 2004.02.03 5:45:10 PM czhower
  18. Name changes
  19. Rev 1.5 1/21/2004 2:29:38 PM JPMugaas
  20. InitComponent
  21. Rev 1.4 2/24/2003 08:41:20 PM JPMugaas
  22. Should compile with new code.
  23. Rev 1.3 12/8/2002 07:58:54 PM JPMugaas
  24. Now compiles properly.
  25. Rev 1.2 12/8/2002 07:26:38 PM JPMugaas
  26. Added published host and port properties.
  27. Rev 1.1 12/6/2002 05:29:34 PM JPMugaas
  28. Now decend from TIdTCPClientCustom instead of TIdTCPClient.
  29. Rev 1.0 11/14/2002 02:19:50 PM JPMugaas
  30. 2000-April-30 J. Peter Mugaas
  31. -adjusted CompleteQuery to permit recursive finger queries such
  32. as "[email protected]@example.com". I had mistakenly assumed that
  33. everything after the first @ was the host name.
  34. -Added option for verbose output request from server - note that
  35. many do not support this.
  36. }
  37. unit IdFinger;
  38. {*******************************************************}
  39. { }
  40. { Indy Finger Client TIdFinger }
  41. { }
  42. { Copyright (C) 2000 Winshoes Working Group }
  43. { Original author J. Peter Mugaas }
  44. { 2000-April-23 }
  45. { Based on RFC 1288 }
  46. { }
  47. {*******************************************************}
  48. interface
  49. {$i IdCompilerDefines.inc}
  50. uses
  51. IdAssignedNumbers,
  52. IdTCPClient;
  53. type
  54. TIdFinger = class(TIdTCPClientCustom)
  55. protected
  56. FQuery: String;
  57. FVerboseOutput: Boolean;
  58. Procedure SetCompleteQuery(AQuery: String);
  59. Function GetCompleteQuery: String;
  60. Procedure InitComponent; override;
  61. public
  62. {This connects to a server, does the finger querry specified in the Query
  63. property and returns the results of the querry}
  64. function Finger: String;
  65. published
  66. property Port default IdPORT_FINGER;
  67. property Host;
  68. {This is the querry to the server which you set with the Host Property}
  69. Property Query: String read FQuery write FQuery;
  70. {This is the complete querry such as "user@host"}
  71. Property CompleteQuery: String read GetCompleteQuery write SetCompleteQuery;
  72. {This indicates that the server should give more detailed information on
  73. some systems. However, this will probably not work on many systems so it is
  74. False by default}
  75. Property VerboseOutput: Boolean read FVerboseOutPut write FVerboseOutPut
  76. default False;
  77. end;
  78. implementation
  79. uses
  80. IdGlobal, IdGlobalProtocols,
  81. IdTCPConnection;
  82. { TIdFinger }
  83. procedure TIdFinger.InitComponent;
  84. begin
  85. inherited InitComponent;
  86. Port := IdPORT_FINGER;
  87. end;
  88. {This is the method used for retreiving Finger Data which is returned in the
  89. result}
  90. function TIdFinger.Finger: String;
  91. var
  92. QStr : String;
  93. begin
  94. QStr := FQuery;
  95. if VerboseOutPut then
  96. begin
  97. QStr := QStr + '/W'; {Do not Localize}
  98. end; //if VerboseOutPut then
  99. Connect;
  100. try
  101. {Write querry}
  102. Result := ''; {Do not Localize}
  103. IOHandler.WriteLn(QStr);
  104. {Read results}
  105. Result := IOHandler.AllData;
  106. finally
  107. Disconnect;
  108. end;
  109. end;
  110. function TIdFinger.GetCompleteQuery: String;
  111. begin
  112. Result := FQuery + '@' + Host; {Do not Localize}
  113. end;
  114. procedure TIdFinger.SetCompleteQuery(AQuery: String);
  115. var
  116. p : Integer;
  117. begin
  118. p := RPos('@', AQuery, -1); {Do not Localize}
  119. if p <> 0 then begin
  120. if p < Length(AQuery) then
  121. begin
  122. Host := Copy(AQuery, p+1, MaxInt);
  123. end;
  124. FQuery := Copy(AQuery, 1, p-1);
  125. end else begin
  126. FQuery := AQuery;
  127. end;
  128. end;
  129. end.