IdHostnameServer.pas 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. { $HDR$}
  2. {**********************************************************************}
  3. { Unit archived using Team Coherence }
  4. { Team Coherence is Copyright 2002 by Quality Software Components }
  5. { }
  6. { For further information / comments, visit our WEB site at }
  7. { http://www.TeamCoherence.com }
  8. {**********************************************************************}
  9. {}
  10. { $Log: 10189: IdHostnameServer.pas
  11. {
  12. { Rev 1.0 2002.11.12 10:40:54 PM czhower
  13. }
  14. unit IdHostnameServer;
  15. interface
  16. {
  17. 2000-May-18: J. Peter Mugaas
  18. -Ported to Indy
  19. 2000-Jan-13: MTL
  20. -13-JAN-2000 MTL: Moved to new Palette Scheme (Winshoes Servers)
  21. 1999-May-13: Ozz Nixon
  22. -Final version
  23. Original Author: Ozz Nixon
  24. Based on RFC 953
  25. }
  26. uses
  27. Classes,
  28. IdAssignedNumbers,
  29. IdTCPServer;
  30. Const
  31. KnownCommands:Array [1..9] of string=
  32. (
  33. 'HNAME', {Do not Localize}
  34. 'HADDR', {Do not Localize}
  35. 'ALL', {Do not Localize}
  36. 'HELP', {Do not Localize}
  37. 'VERSION', {Do not Localize}
  38. 'ALL-OLD', {Do not Localize}
  39. 'DOMAINS', {Do not Localize}
  40. 'ALL-DOM', {Do not Localize}
  41. 'ALL-INGWAY' {Do not Localize}
  42. );
  43. Type
  44. THostNameGetEvent = procedure(Thread: TIdPeerThread) of object;
  45. THostNameOneParmEvent = procedure(Thread: TIdPeerThread;Parm:String) of object;
  46. TIdHostNameServer = class(TIdTCPServer)
  47. protected
  48. FOnCommandHNAME:THostNameOneParmEvent;
  49. FOnCommandHADDR:THostNameOneParmEvent;
  50. FOnCommandALL:THostNameGetEvent;
  51. FOnCommandHELP:THostNameGetEvent;
  52. FOnCommandVERSION:THostNameGetEvent;
  53. FOnCommandALLOLD:THostNameGetEvent;
  54. FOnCommandDOMAINS:THostNameGetEvent;
  55. FOnCommandALLDOM:THostNameGetEvent;
  56. FOnCommandALLINGWAY:THostNameGetEvent;
  57. //
  58. function DoExecute(Thread: TIdPeerThread): boolean; override;
  59. public
  60. constructor Create(AOwner: TComponent); override;
  61. published
  62. property OnCommandHNAME: THostNameOneParmEvent read fOnCommandHNAME write fOnCommandHNAME;
  63. property OnCommandHADDR: THostNameOneParmEvent read fOnCommandHADDR write fOnCommandHADDR;
  64. property OnCommandALL: THostNameGetEvent read fOnCommandALL write fOnCommandALL;
  65. property OnCommandHELP: THostNameGetEvent read fOnCommandHELP write fOnCommandHELP;
  66. property OnCommandVERSION: THostNameGetEvent read fOnCommandVERSION write fOnCommandVERSION;
  67. property OnCommandALLOLD: THostNameGetEvent read fOnCommandALLOLD write fOnCommandALLOLD;
  68. property OnCommandDOMAINS: THostNameGetEvent read fOnCommandDOMAINS write fOnCommandDOMAINS;
  69. property OnCommandALLDOM: THostNameGetEvent read fOnCommandALLDOM write fOnCommandALLDOM;
  70. property OnCommandALLINGWAY: THostNameGetEvent read fOnCommandALLINGWAY write fOnCommandALLINGWAY;
  71. end;
  72. implementation
  73. uses
  74. IdGlobal,
  75. SysUtils;
  76. constructor TIdHostNameServer.Create(AOwner: TComponent);
  77. begin
  78. inherited Create(AOwner);
  79. DefaultPort := IdPORT_HOSTNAME;
  80. end;
  81. function TIdHostNameServer.DoExecute(Thread: TIdPeerThread): boolean;
  82. Var
  83. S,sCmd:String;
  84. begin
  85. result := true;
  86. while Thread.Connection.Connected do
  87. begin
  88. S := Thread.Connection.ReadLn;
  89. sCmd := UpperCase ( Fetch ( s, CHAR32 ) );
  90. case Succ(PosInStrArray ( Uppercase ( sCmd ), KnownCommands ) ) of
  91. 1 : {hname}
  92. if assigned ( OnCommandHNAME ) then
  93. OnCommandHNAME ( Thread, S );
  94. 2 : {haddr}
  95. if assigned ( OnCommandHADDR ) then
  96. OnCommandHADDR ( Thread, S );
  97. 3 : {all}
  98. if assigned ( OnCommandALL ) then
  99. OnCommandALL ( Thread );
  100. 4 : {help}
  101. if assigned ( OnCommandHELP ) then
  102. OnCommandHELP ( Thread );
  103. 5 : {version}
  104. if assigned ( OnCommandVERSION ) then
  105. OnCommandVERSION ( Thread );
  106. 6 : {all-old}
  107. if assigned ( OnCommandALLOLD ) then
  108. OnCommandALLOLD ( Thread );
  109. 7 : {domains}
  110. if assigned ( OnCommandDOMAINS ) then
  111. OnCommandDOMAINS ( Thread );
  112. 8 : {all-dom}
  113. if assigned ( OnCommandALLDOM ) then
  114. OnCommandALLDOM ( Thread );
  115. 9 : {all-ingway}
  116. if assigned ( OnCommandALLINGWAY ) then
  117. OnCommandALLINGWAY ( Thread );
  118. end; //while Thread.Connection.Connected do
  119. end; //while Thread.Connection.Connected do
  120. Thread.Connection.Disconnect;
  121. end; {doExecute}
  122. end.