IdHostnameServer.pas 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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.2 12/2/2004 4:23:54 PM JPMugaas
  18. Adjusted for changes in Core.
  19. Rev 1.1 4/12/2003 10:24:08 PM GGrieve
  20. Fix to Compile
  21. Rev 1.0 11/13/2002 07:54:06 AM JPMugaas
  22. 2000-May-18: J. Peter Mugaas
  23. -Ported to Indy
  24. 2000-Jan-13: MTL
  25. -13-JAN-2000 MTL: Moved to new Palette Scheme (Winshoes Servers)
  26. 1999-May-13: Ozz Nixon
  27. -Final version
  28. }
  29. unit IdHostnameServer;
  30. interface
  31. {$i IdCompilerDefines.inc}
  32. {
  33. Original Author: Ozz Nixon
  34. Based on RFC 953
  35. }
  36. uses
  37. IdAssignedNumbers,
  38. IdContext,
  39. IdCustomTCPServer;
  40. Const
  41. KnownCommands: array [0..8] of string =
  42. (
  43. 'HNAME', {Do not Localize}
  44. 'HADDR', {Do not Localize}
  45. 'ALL', {Do not Localize}
  46. 'HELP', {Do not Localize}
  47. 'VERSION', {Do not Localize}
  48. 'ALL-OLD', {Do not Localize}
  49. 'DOMAINS', {Do not Localize}
  50. 'ALL-DOM', {Do not Localize}
  51. 'ALL-INGWAY' {Do not Localize}
  52. );
  53. Type
  54. THostNameOneParmEvent = procedure(AThread: TIdContext; const AParam: String) of object;
  55. TIdHostNameServer = class(TIdCustomTCPServer)
  56. protected
  57. FOnCommandHNAME: THostNameOneParmEvent;
  58. FOnCommandHADDR: THostNameOneParmEvent;
  59. FOnCommandALL: TIdContextEvent;
  60. FOnCommandHELP: TIdContextEvent;
  61. FOnCommandVERSION: TIdContextEvent;
  62. FOnCommandALLOLD: TIdContextEvent;
  63. FOnCommandDOMAINS: TIdContextEvent;
  64. FOnCommandALLDOM: TIdContextEvent;
  65. FOnCommandALLINGWAY: TIdContextEvent;
  66. //
  67. function DoExecute(AContext: TIdContext): Boolean; override;
  68. procedure InitComponent; override;
  69. published
  70. property DefaultPort default IdPORT_HOSTNAME;
  71. property OnCommandHNAME: THostNameOneParmEvent read fOnCommandHNAME write fOnCommandHNAME;
  72. property OnCommandHADDR: THostNameOneParmEvent read fOnCommandHADDR write fOnCommandHADDR;
  73. property OnCommandALL: TIdContextEvent read fOnCommandALL write fOnCommandALL;
  74. property OnCommandHELP: TIdContextEvent read fOnCommandHELP write fOnCommandHELP;
  75. property OnCommandVERSION: TIdContextEvent read fOnCommandVERSION write fOnCommandVERSION;
  76. property OnCommandALLOLD: TIdContextEvent read fOnCommandALLOLD write fOnCommandALLOLD;
  77. property OnCommandDOMAINS: TIdContextEvent read fOnCommandDOMAINS write fOnCommandDOMAINS;
  78. property OnCommandALLDOM: TIdContextEvent read fOnCommandALLDOM write fOnCommandALLDOM;
  79. property OnCommandALLINGWAY: TIdContextEvent read fOnCommandALLINGWAY write fOnCommandALLINGWAY;
  80. end;
  81. implementation
  82. uses
  83. IdGlobalCore,
  84. IdGlobal;
  85. procedure TIdHostNameServer.InitComponent;
  86. begin
  87. inherited InitComponent;
  88. DefaultPort := IdPORT_HOSTNAME;
  89. end;
  90. function TIdHostNameServer.DoExecute(AContext: TIdContext): Boolean;
  91. var
  92. S: String;
  93. begin
  94. Result := True;
  95. while AContext.Connection.Connected do
  96. begin
  97. S := AContext.Connection.IOHandler.ReadLn;
  98. case PosInStrArray(Fetch(S, CHAR32), KnownCommands, False) of
  99. 0 : {hname}
  100. if Assigned(OnCommandHNAME) then
  101. OnCommandHNAME(AContext, S);
  102. 1 : {haddr}
  103. if Assigned(OnCommandHADDR) then
  104. OnCommandHADDR(AContext, S);
  105. 2 : {all}
  106. if Assigned(OnCommandALL) then
  107. OnCommandALL(AContext);
  108. 3 : {help}
  109. if Assigned(OnCommandHELP) then
  110. OnCommandHELP(AContext);
  111. 4 : {version}
  112. if Assigned(OnCommandVERSION) then
  113. OnCommandVERSION(AContext);
  114. 5 : {all-old}
  115. if Assigned(OnCommandALLOLD) then
  116. OnCommandALLOLD(AContext);
  117. 6 : {domains}
  118. if Assigned(OnCommandDOMAINS) then
  119. OnCommandDOMAINS(AContext);
  120. 7 : {all-dom}
  121. if Assigned(OnCommandALLDOM) then
  122. OnCommandALLDOM(AContext);
  123. 8 : {all-ingway}
  124. if Assigned(OnCommandALLINGWAY) then
  125. OnCommandALLINGWAY(AContext);
  126. end;
  127. end;
  128. AContext.Connection.Disconnect;
  129. end;
  130. end.