IdSSH.pas 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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.0 4/6/2003 04:35:12 PM JPMugaas
  18. }
  19. {
  20. Note that this unit is for defining Base classes for SSH implementers.
  21. Much of this is a Cut and Paste job from Indy 10's Base SSL classes. We make
  22. this separate in case we have to treat SSH far differently than SSL.
  23. }
  24. unit IdSSH;
  25. interface
  26. {$i IdCompilerDefines.inc}
  27. uses
  28. Classes,
  29. IdContainers,
  30. IdGlobalCore,
  31. IdIOHandler,
  32. IdIOHandlerSocket,
  33. IdIOHandlerStack,
  34. IdScheduler,
  35. IdServerIOHandler;
  36. type
  37. //client
  38. TIdSSHIOHandlerSocketBase = class(TIdIOHandlerStack)
  39. protected
  40. fPassThrough: Boolean;
  41. fIsPeer : Boolean;
  42. procedure InitComponent; override;
  43. procedure SetPassThrough(const AValue: Boolean); virtual;
  44. public
  45. function Clone : TIdSSHIOHandlerSocketBase; virtual; abstract;
  46. procedure StartSSH; virtual; abstract;
  47. property PassThrough: Boolean read fPassThrough write SetPassThrough;
  48. property IsPeer : Boolean read fIsPeer write fIsPeer;
  49. end;
  50. //server
  51. TIdServerIOHandlerSSHBase = class(TIdServerIOHandler)
  52. protected
  53. public
  54. //this is for the FTP Server to make a client IOHandler for it's data connection's IOHandler
  55. function MakeClientIOHandler(ATheThread:TIdThreadHandle ): TIdIOHandler; overload; override;
  56. function MakeClientIOHandler : TIdSSHIOHandlerSocketBase; reintroduce; overload; virtual; abstract;
  57. function MakeFTPSvrPort : TIdSSHIOHandlerSocketBase; virtual; abstract;
  58. function MakeFTPSvrPasv : TIdSSHIOHandlerSocketBase; virtual; abstract;
  59. end;
  60. type
  61. TIdClientSSHClass = class of TIdSSHIOHandlerSocketBase;
  62. TIdServerSSHClass = class of TIdServerIOHandlerSSHBase;
  63. Procedure RegisterSSH(const AProduct, AVendor, ACopyright,
  64. ADescription, AURL : String;
  65. const AClientClass : TIdClientSSHClass; const AServerClass : TIdServerSSHClass);
  66. type
  67. TIdSSHRegEntry = class(TCollectionItem)
  68. protected
  69. FProductName : String;
  70. FVendor : String;
  71. FCopyright : String;
  72. FDescription : String;
  73. FURL : String;
  74. FClientClass : TIdClientSSHClass;
  75. FServerClass : TIdServerSSHClass;
  76. public
  77. property ProductName : String read FProductName write FProductName;
  78. property Vendor : String read FVendor write FVendor;
  79. property Copyright : String read FCopyright write FCopyright;
  80. property Description : String read FDescription write FDescription;
  81. property URL : String read FURL write FURL;
  82. property ClientClass : TIdClientSSHClass read FClientClass write FClientClass;
  83. property ServerClass : TIdServerSSHClass read FServerClass write FServerClass;
  84. end;
  85. TIdSSHRegistry = class(TCollection)
  86. protected
  87. function GetItem ( Index: Integer ) : TIdSSHRegEntry;
  88. procedure SetItem ( Index: Integer; const Value: TIdSSHRegEntry );
  89. public
  90. constructor Create; reintroduce;
  91. function Add: TIdSSHRegEntry;
  92. property Items [ Index: Integer ] : TIdSSHRegEntry read GetItem
  93. write SetItem; default;
  94. end;
  95. var
  96. GSSHRegistry : TIdSSHRegistry;
  97. implementation
  98. uses SysUtils;
  99. Procedure RegisterSSH(const AProduct, AVendor, ACopyright,
  100. ADescription, AURL : String;
  101. const AClientClass : TIdClientSSHClass; const AServerClass : TIdServerSSHClass);
  102. var LR : TIdSSHRegEntry;
  103. begin
  104. LR := GSSHRegistry.Add;
  105. LR.ProductName := AProduct;
  106. LR.Vendor := AVendor;
  107. LR.Copyright := ACopyRight;
  108. LR.Description := ADescription;
  109. LR.URL := AURL;
  110. LR.ClientClass := AClientClass;
  111. LR.ServerClass := AServerClass;
  112. end;
  113. { TIdSSHIOHandlerSocketBase }
  114. procedure TIdSSHIOHandlerSocketBase.InitComponent;
  115. begin
  116. inherited;
  117. fPassThrough := True;
  118. end;
  119. procedure TIdSSHIOHandlerSocketBase.SetPassThrough(const AValue: Boolean);
  120. begin
  121. fPassThrough := AValue;
  122. end;
  123. { TIdServerIOHandlerSSHBase }
  124. function TIdServerIOHandlerSSHBase.MakeClientIOHandler(ATheThread:TIdThreadHandle ): TIdIOHandler;
  125. begin
  126. Result := MakeClientIOHandler;
  127. end;
  128. { TIdSSHRegistry }
  129. function TIdSSHRegistry.Add: TIdSSHRegEntry;
  130. begin
  131. Result := TIdSSHRegEntry( inherited Add );
  132. end;
  133. constructor TIdSSHRegistry.Create;
  134. begin
  135. inherited Create(TIdSSHRegEntry);
  136. end;
  137. function TIdSSHRegistry.GetItem(Index: Integer): TIdSSHRegEntry;
  138. begin
  139. Result := TIdSSHRegEntry ( inherited GetItem(Index) );
  140. end;
  141. procedure TIdSSHRegistry.SetItem(Index: Integer;
  142. const Value: TIdSSHRegEntry);
  143. begin
  144. inherited SetItem(Index,Value);
  145. end;
  146. initialization
  147. GSSHRegistry := TIdSSHRegistry.Create;
  148. finalization
  149. FreeAndNil(GSSHRegistry);
  150. end.