⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxdnsservercore.pas

📁 Well known and usefull component for delphi 7
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit DXDNSServerCore;

interface

///////////////////////////////////////////////////////////////////////////////
//    Component: TDXDNSServerCore
//       Author: G.E. Ozz Nixon Jr. (staff@bpdx.com)
// ========================================================================
// Source Owner: DX, Inc. 1995-2003
//    Copyright: All code is the property of DX, Inc. Licensed for
//               resell by Brain Patchwork DX (tm) and part of the
//               DX (r) product lines, which are (c) 1999-2003
//               DX, Inc. Source may not be distributed without
//               written permission from both Brain Patchwork DX,
//               and DX, Inc.
//      License: (Reminder), None of this code can be added to other
//               developer products without permission. This includes
//               but not limited to DCU's, DCP's, DLL's, OCX's, or
//               any other form of merging our technologies. All of
//               your products released to a public consumer be it
//               shareware, freeware, commercial, etc. must contain a
//               license notification somewhere visible in the
//               application.
//               Example is Internet Explorer - Help->About screen
//               shows the licensed code contained in the application.
// Code Version: (4th Generation Code)
// ========================================================================
//  Description: implements DNS (Domain Name Server) protocol
// ========================================================================
///////////////////////////////////////////////////////////////////////////////

uses
  Classes,
  DXString,
  DXServerCore;

{$I DXSock.def}

Type // structure changed in 3.0 code!
   PDXDNSQueryPacket=^TDXDNSQueryPacket;
   TDXDNSQueryPacket=Record
      ID:Word;     //2
      QR:Boolean;
      OpCode:Byte;
      AA:Boolean;
      TC:Boolean;
      RD:Boolean;
      RA:Boolean;
      Z:Byte;
      RCode:Byte;      //2
      QDCount:Word;//2
      ANCount:Word;//2
      NSCount:Word;//2
      ARCount:Word;//2
      Query:String;
      QueryType:Word;
      QueryClass:Word;
   End;

  DNSTSimpleEvent = procedure(ClientThread: TDXClientThread;QueryPacket:PDXDNSQueryPacket) of object;
  DNSTOtherEvent = procedure(ClientThread: TDXClientThread;QueryPacket:PDXDNSQueryPacket;Var Handled:Boolean) of object;

  TDXDNSServerCore = class(TDXServerCore)
  private
    fOnCommandA: DNSTSimpleEvent;        // 1
    fOnCommandNS: DNSTSimpleEvent;       // 2
    fOnCommandMD: DNSTSimpleEvent;       // 3
    fOnCommandMF: DNSTSimpleEvent;       // 4
    fOnCommandCNAME: DNSTSimpleEvent;    // 5
    fOnCommandSOA: DNSTSimpleEvent;      // 6
    fOnCommandMB: DNSTSimpleEvent;       // 7
    fOnCommandMG: DNSTSimpleEvent;       // 8
    fOnCommandMR: DNSTSimpleEvent;       // 9
    fOnCommandNULL: DNSTSimpleEvent;     //10
    fOnCommandWKS: DNSTSimpleEvent;      //11
    fOnCommandPTR: DNSTSimpleEvent;      //12
    fOnCommandHINFO: DNSTSimpleEvent;    //13
    fOnCommandMINFO: DNSTSimpleEvent;    //14
    fOnCommandMX: DNSTSimpleEvent;       //15
    fOnCommandTXT: DNSTSimpleEvent;      //16
    fOnCommandRP: DNSTSimpleEvent;       //17
    fOnCommandAFSDB: DNSTSimpleEvent;    //18
    fOnCommandX25: DNSTSimpleEvent;      //19
    fOnCommandISDN: DNSTSimpleEvent;     //20
    fOnCommandRT: DNSTSimpleEvent;       //21
    fOnCommandOSINSAP: DNSTSimpleEvent;  //22
    fOnCommandAXFR: DNSTSimpleEvent;     //252
    fOnCommandMAILB: DNSTSimpleEvent;    //253
    fOnCommandMAILA: DNSTSimpleEvent;    //254
    fOnCommandALL: DNSTSimpleEvent;      //255
    fOnCommandOther: DNSTOtherEvent;
  protected
    Procedure SetOnCommandA(Value:DNSTSimpleEvent);
    Procedure SetOnCommandNS(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMD(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMF(Value:DNSTSimpleEvent);
    Procedure SetOnCommandCNAME(Value:DNSTSimpleEvent);
    Procedure SetOnCommandSOA(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMB(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMG(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMR(Value:DNSTSimpleEvent);
    Procedure SetOnCommandNULL(Value:DNSTSimpleEvent);
    Procedure SetOnCommandWKS(Value:DNSTSimpleEvent);
    Procedure SetOnCommandPTR(Value:DNSTSimpleEvent);
    Procedure SetOnCommandHINFO(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMINFO(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMX(Value:DNSTSimpleEvent);
    Procedure SetOnCommandTXT(Value:DNSTSimpleEvent);
    Procedure SetOnCommandRP(Value:DNSTSimpleEvent);
    Procedure SetOnCommandAFSDB(Value:DNSTSimpleEvent);
    Procedure SetOnCommandX25(Value:DNSTSimpleEvent);
    Procedure SetOnCommandISDN(Value:DNSTSimpleEvent);
    Procedure SetOnCommandRT(Value:DNSTSimpleEvent);
    Procedure SetOnCommandOSINSAP(Value:DNSTSimpleEvent);
    Procedure SetOnCommandAXFR(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMAILB(Value:DNSTSimpleEvent);
    Procedure SetOnCommandMAILA(Value:DNSTSimpleEvent);
    Procedure SetOnCommandALL(Value:DNSTSimpleEvent);
  public
    constructor Create(AOwner:TComponent); {$IFNDEF OBJECTS_ONLY} override; {$ENDIF}
    destructor Destroy; override;
    procedure ProcessSession(ClientThread: TDXClientThread);
    Procedure AddSimpleEvent(Command:SmallInt;EventProc:DNSTSimpleEvent);
  published
    property OnCommandA: DNSTSimpleEvent read fOnCommandA
                                         write SetOnCommandA;
    property OnCommandNS: DNSTSimpleEvent read fOnCommandNS
                                          write SetOnCommandNS;
    property OnCommandMD: DNSTSimpleEvent read fOnCommandMD
                                          write SetOnCommandMD;
    property OnCommandMF: DNSTSimpleEvent read fOnCommandMF
                                          write SetOnCommandMF;
    property OnCommandCNAME: DNSTSimpleEvent read fOnCommandCNAME
                                             write SetOnCommandCNAME;
    property OnCommandSOA: DNSTSimpleEvent read fOnCommandSOA
                                           write SetOnCommandSOA;
    property OnCommandMB: DNSTSimpleEvent read fOnCommandMB
                                          write SetOnCommandMB;
    property OnCommandMG: DNSTSimpleEvent read fOnCommandMG
                                          write SetOnCommandMG;
    property OnCommandMR: DNSTSimpleEvent read fOnCommandMR
                                          write SetOnCommandMR;
    property OnCommandNULL: DNSTSimpleEvent read fOnCommandNULL
                                            write SetOnCommandNULL;
    property OnCommandWKS: DNSTSimpleEvent read fOnCommandWKS
                                           write SetOnCommandWKS;
    property OnCommandPTR: DNSTSimpleEvent read fOnCommandPTR
                                           write SetOnCommandPTR;
    property OnCommandHINFO: DNSTSimpleEvent read fOnCommandHINFO
                                             write SetOnCommandHINFO;
    property OnCommandMINFO: DNSTSimpleEvent read fOnCommandMINFO
                                             write SetOnCommandMINFO;
    property OnCommandMX: DNSTSimpleEvent read fOnCommandMX
                                          write SetOnCommandMX;
    property OnCommandTXT: DNSTSimpleEvent read fOnCommandTXT
                                           write SetOnCommandTXT;
    property OnCommandRP: DNSTSimpleEvent read fOnCommandRP
                                          write SetOnCommandRP;
    property OnCommandAFSDB: DNSTSimpleEvent read fOnCommandAFSDB
                                             write SetOnCommandAFSDB;
    property OnCommandX25: DNSTSimpleEvent read fOnCommandX25
                                           write SetOnCommandX25;
    property OnCommandISDN: DNSTSimpleEvent read fOnCommandISDN
                                            write SetOnCommandISDN;
    property OnCommandRT: DNSTSimpleEvent read fOnCommandRT
                                          write SetOnCommandRT;
    property OnCommandOSINSAP: DNSTSimpleEvent read fOnCommandOSINSAP
                                               write SetOnCommandOSINSAP;
    property OnCommandAXFR: DNSTSimpleEvent read fOnCommandAXFR
                                            write SetOnCommandAXFR;
    property OnCommandMAILB: DNSTSimpleEvent read fOnCommandMAILB
                                             write SetOnCommandMAILB;
    property OnCommandMAILA: DNSTSimpleEvent read fOnCommandMAILA
                                             write SetOnCommandMAILA;
    property OnCommandALL: DNSTSimpleEvent read fOnCommandALL
                                           write SetOnCommandALL;
    property OnCommandOther: DNSTOtherEvent read fOnCommandOther
                                            write fOnCommandOther;
  end;

implementation

Uses
   DXSock;
   
Type
  PDNSSimpleEvent=^TDNSSimpleEvent;
  TDNSSimpleEvent=record
     Tag:Integer;
     Command:SmallInt;
     EventProcedure:DNSTSimpleEvent;
  End;


(******************************************************************************
CREATE:
       Define the Default Port number to Listen On.
******************************************************************************)
constructor TDXDNSServerCore.Create(AOwner:TComponent);
begin
   inherited Create(AOwner);
   ServerPort:=53;
   ProtocolToBind:=wpUDPOnly;
end;

(******************************************************************************
DESTROY:
        Destory this object.
******************************************************************************)
destructor TDXDNSServerCore.Destroy;
Var
   PSimpleEvent:PDNSSimpleEvent;

begin
   If Assigned(fEventArray) then Begin
      While fEventArray.Count>0 do Begin
         Case PDNSSimpleEvent(fEventArray[0]).Tag of
            1:Begin
              PSimpleEvent:=fEventArray[0];
              Dispose(PSimpleEvent);
            End;
         End;
         fEventArray.Delete(0);
      End;
   End;
   inherited Destroy;
end;

Procedure TDXDNSServerCore.AddSimpleEvent(Command:SmallInt;EventProc:DNSTSimpleEvent);
Var
   PSimpleEvent:PDNSSimpleEvent;
   Loop:Integer;

Begin
   Loop:=0;
   While Loop<fEventArray.Count do Begin
      If PDNSSimpleEvent(fEventArray[Loop]).Command=Command then Begin
         PDNSSimpleEvent(fEventArray[Loop]).EventProcedure:=EventProc;
         Exit;
      End
      Else Inc(Loop);
   End;
   New(PSimpleEvent);
   PSimpleEvent.Tag:=1;      // Denotes Event in fEventArray is a TSimpleEvent!
   PSimpleEvent.Command:=Command;
   PSimpleEvent.EventProcedure:=EventProc;
   fEventArray.Add(PSimpleEvent);
End;

Procedure TDXDNSServerCore.SetOnCommandA(value:DNSTSimpleEvent);
Begin
   fOnCommandA:=Value;
   AddSimpleEvent(1,Value);
End;

Procedure TDXDNSServerCore.SetOnCommandNS(Value:DNSTSimpleEvent);
Begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -