unit Chilkat.Dns;

{
  Pascal wrapper for Chilkat Dns.
  Auto-generated by PascalWrapperGenerator -- do not edit manually.
}

{$IFDEF FPC}
  {$MODE DELPHI}
{$ENDIF}

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TDns wraps CkDns via the C bridge layer. }
  TDns = class(TChilkatBase)
  private
    FOnAbortCheck: TChilkatAbortCheckEvent;
    FOnPercentDone: TChilkatPercentDoneEvent;
    FOnProgressInfo: TChilkatProgressInfoEvent;
    function  GetLastErrorHtml: string;
    function  GetLastErrorText: string;
    function  GetLastErrorXml: string;
    function  GetVersion: string;
    function  GetDebugLogFilePath: string;
    procedure SetDebugLogFilePath(AValue: string);
    function  GetVerboseLogging: Boolean;
    procedure SetVerboseLogging(AValue: Boolean);
    function  GetLastMethodSuccess: Boolean;
    procedure SetLastMethodSuccess(AValue: Boolean);
    function  GetNumNameservers: Integer;
    function  GetHeartbeatMs: Integer;
    procedure SetHeartbeatMs(AValue: Integer);
    function  GetMaxWaitMs: Integer;
    procedure SetMaxWaitMs(AValue: Integer);
    function  GetTlsPref: Integer;
    procedure SetTlsPref(AValue: Integer);
    function  GetUncommonOptions: string;
    procedure SetUncommonOptions(AValue: string);
    procedure SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
    procedure SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
    procedure SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
  public
    constructor Create;
    destructor  Destroy; override;

    property LastErrorHtml: string read GetLastErrorHtml;
    property LastErrorText: string read GetLastErrorText;
    property LastErrorXml: string read GetLastErrorXml;
    property Version: string read GetVersion;
    property DebugLogFilePath: string read GetDebugLogFilePath write SetDebugLogFilePath;
    property VerboseLogging: Boolean read GetVerboseLogging write SetVerboseLogging;
    property LastMethodSuccess: Boolean read GetLastMethodSuccess write SetLastMethodSuccess;
    property NumNameservers: Integer read GetNumNameservers;
    property HeartbeatMs: Integer read GetHeartbeatMs write SetHeartbeatMs;
    property MaxWaitMs: Integer read GetMaxWaitMs write SetMaxWaitMs;
    property TlsPref: Integer read GetTlsPref write SetTlsPref;
    property UncommonOptions: string read GetUncommonOptions write SetUncommonOptions;

    { Event callbacks.  Return True from OnAbortCheck / OnPercentDone
      to abort the running method.  Callbacks are invoked on the
      thread that called the Chilkat method.  The HeartbeatMs
      property controls the AbortCheck frequency. }
    property OnAbortCheck: TChilkatAbortCheckEvent read FOnAbortCheck write SetOnAbortCheck;
    property OnPercentDone: TChilkatPercentDoneEvent read FOnPercentDone write SetOnPercentDone;
    property OnProgressInfo: TChilkatProgressInfoEvent read FOnProgressInfo write SetOnProgressInfo;

    function  GetNameserver(index: Integer): string;
    function  Query(const recordType: string; const domain: string; answer: TChilkatBase): Boolean;
    procedure AddNameserver(const ipAddr: string; supportsTls: Boolean);
    procedure RemoveNameserver(const ipAddr: string);
    procedure RemoveAllNameservers;
    procedure AddDefaultNameservers;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkDns_Create  = function(): Pointer; cdecl;
  TCkDns_Dispose = procedure(handle: Pointer); cdecl;
  TCkBridgeAbortCheckCb   = function(userData: Pointer): Integer; cdecl;
  TCkBridgePercentDoneCb  = function(pctDone: Integer; userData: Pointer): Integer; cdecl;
  TCkBridgeProgressInfoCb = procedure(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
  TCkDns_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkDns_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkDns_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkDns_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkDns_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkDns_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkDns_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkDns_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkDns_get_NumNameservers = function(handle: Pointer): Integer; cdecl;
  TCkDns_get_HeartbeatMs = function(handle: Pointer): Integer; cdecl;
  TCkDns_put_HeartbeatMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkDns_get_MaxWaitMs = function(handle: Pointer): Integer; cdecl;
  TCkDns_put_MaxWaitMs = procedure(handle: Pointer; value: Integer); cdecl;
  TCkDns_get_TlsPref = function(handle: Pointer): Integer; cdecl;
  TCkDns_put_TlsPref = procedure(handle: Pointer; value: Integer); cdecl;
  TCkDns_get_UncommonOptions = function(handle: Pointer): PAnsiChar; cdecl;
  TCkDns_put_UncommonOptions = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkDns_GetNameserver = function(handle: Pointer; index: Integer): PAnsiChar; cdecl;
  TCkDns_Query = function(handle: Pointer; recordType: PAnsiChar; domain: PAnsiChar; answer: Pointer): LongBool; cdecl;
  TCkDns_AddNameserver = procedure(handle: Pointer; ipAddr: PAnsiChar; supportsTls: LongBool); cdecl;
  TCkDns_RemoveNameserver = procedure(handle: Pointer; ipAddr: PAnsiChar); cdecl;
  TCkDns_RemoveAllNameservers = procedure(handle: Pointer); cdecl;
  TCkDns_AddDefaultNameservers = procedure(handle: Pointer); cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkDns_Create:  TCkDns_Create  = nil;
  CkDns_Dispose: TCkDns_Dispose = nil;
  CkDns_SetAbortCheckCallback:   TCkDns_SetAbortCheckCallback   = nil;
  CkDns_SetPercentDoneCallback:  TCkDns_SetPercentDoneCallback  = nil;
  CkDns_SetProgressInfoCallback: TCkDns_SetProgressInfoCallback = nil;
  CkDns_get_LastErrorHtml: TCkDns_get_LastErrorHtml = nil;
  CkDns_get_LastErrorText: TCkDns_get_LastErrorText = nil;
  CkDns_get_LastErrorXml: TCkDns_get_LastErrorXml = nil;
  CkDns_get_Version: TCkDns_get_Version = nil;
  CkDns_get_DebugLogFilePath: TCkDns_get_DebugLogFilePath = nil;
  CkDns_put_DebugLogFilePath: TCkDns_put_DebugLogFilePath = nil;
  CkDns_get_VerboseLogging: TCkDns_get_VerboseLogging = nil;
  CkDns_put_VerboseLogging: TCkDns_put_VerboseLogging = nil;
  CkDns_get_LastMethodSuccess: TCkDns_get_LastMethodSuccess = nil;
  CkDns_put_LastMethodSuccess: TCkDns_put_LastMethodSuccess = nil;
  CkDns_get_NumNameservers: TCkDns_get_NumNameservers = nil;
  CkDns_get_HeartbeatMs: TCkDns_get_HeartbeatMs = nil;
  CkDns_put_HeartbeatMs: TCkDns_put_HeartbeatMs = nil;
  CkDns_get_MaxWaitMs: TCkDns_get_MaxWaitMs = nil;
  CkDns_put_MaxWaitMs: TCkDns_put_MaxWaitMs = nil;
  CkDns_get_TlsPref: TCkDns_get_TlsPref = nil;
  CkDns_put_TlsPref: TCkDns_put_TlsPref = nil;
  CkDns_get_UncommonOptions: TCkDns_get_UncommonOptions = nil;
  CkDns_put_UncommonOptions: TCkDns_put_UncommonOptions = nil;
  CkDns_GetNameserver: TCkDns_GetNameserver = nil;
  CkDns_Query: TCkDns_Query = nil;
  CkDns_AddNameserver: TCkDns_AddNameserver = nil;
  CkDns_RemoveNameserver: TCkDns_RemoveNameserver = nil;
  CkDns_RemoveAllNameservers: TCkDns_RemoveAllNameservers = nil;
  CkDns_AddDefaultNameservers: TCkDns_AddDefaultNameservers = nil;

constructor TDns.Create;
begin
  inherited Create;
  FHandle := CkDns_Create();
end;

destructor TDns.Destroy;
begin
  if FHandle <> nil then
    CkDns_Dispose(FHandle);
  FHandle := nil;
  inherited;
end;

{ ---- Event callback thunks ---- }
{ Standalone cdecl functions registered with the C bridge.  The bridge
  passes back the userData pointer, which carries the Pascal object
  instance.  A non-zero return value aborts the running method. }

function TDns_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TDns;
begin
  Result := 0;
  obj := TDns(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

function TDns_PercentDoneThunk(pctDone: Integer; userData: Pointer): Integer; cdecl;
var
  obj: TDns;
begin
  Result := 0;
  obj := TDns(userData);
  if Assigned(obj) and Assigned(obj.FOnPercentDone) then
    if obj.FOnPercentDone(obj, pctDone) then Result := 1;
end;

procedure TDns_ProgressInfoThunk(name: PAnsiChar; value: PAnsiChar; userData: Pointer); cdecl;
var
  obj: TDns;
begin
  obj := TDns(userData);
  if Assigned(obj) and Assigned(obj.FOnProgressInfo) then
    obj.FOnProgressInfo(obj, CkToStr(name), CkToStr(value));
end;

procedure TDns.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkDns_SetAbortCheckCallback(FHandle, @TDns_AbortCheckThunk, Self)
  else
    CkDns_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TDns.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkDns_SetPercentDoneCallback(FHandle, @TDns_PercentDoneThunk, Self)
  else
    CkDns_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TDns.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkDns_SetProgressInfoCallback(FHandle, @TDns_ProgressInfoThunk, Self)
  else
    CkDns_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TDns.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkDns_get_LastErrorHtml(FHandle));
end;

function TDns.GetLastErrorText: string;
begin
  Result := CkToStr(CkDns_get_LastErrorText(FHandle));
end;

function TDns.GetLastErrorXml: string;
begin
  Result := CkToStr(CkDns_get_LastErrorXml(FHandle));
end;

function TDns.GetVersion: string;
begin
  Result := CkToStr(CkDns_get_Version(FHandle));
end;

function TDns.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkDns_get_DebugLogFilePath(FHandle));
end;

procedure TDns.SetDebugLogFilePath(AValue: string);
begin
  CkDns_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TDns.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkDns_get_VerboseLogging(FHandle));
end;

procedure TDns.SetVerboseLogging(AValue: Boolean);
begin
  CkDns_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TDns.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkDns_get_LastMethodSuccess(FHandle));
end;

procedure TDns.SetLastMethodSuccess(AValue: Boolean);
begin
  CkDns_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TDns.GetNumNameservers: Integer;
begin
  Result := CkDns_get_NumNameservers(FHandle);
end;

function TDns.GetHeartbeatMs: Integer;
begin
  Result := CkDns_get_HeartbeatMs(FHandle);
end;

procedure TDns.SetHeartbeatMs(AValue: Integer);
begin
  CkDns_put_HeartbeatMs(FHandle, AValue);
end;

function TDns.GetMaxWaitMs: Integer;
begin
  Result := CkDns_get_MaxWaitMs(FHandle);
end;

procedure TDns.SetMaxWaitMs(AValue: Integer);
begin
  CkDns_put_MaxWaitMs(FHandle, AValue);
end;

function TDns.GetTlsPref: Integer;
begin
  Result := CkDns_get_TlsPref(FHandle);
end;

procedure TDns.SetTlsPref(AValue: Integer);
begin
  CkDns_put_TlsPref(FHandle, AValue);
end;

function TDns.GetUncommonOptions: string;
begin
  Result := CkToStr(CkDns_get_UncommonOptions(FHandle));
end;

procedure TDns.SetUncommonOptions(AValue: string);
begin
  CkDns_put_UncommonOptions(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TDns.GetNameserver(index: Integer): string;
begin
  Result := CkToStr(CkDns_GetNameserver(FHandle, index));
end;

function TDns.Query(const recordType: string; const domain: string; answer: TChilkatBase): Boolean;
begin
  Result := Boolean(CkDns_Query(FHandle, PAnsiChar(StrToCk(recordType)), PAnsiChar(StrToCk(domain)), answer.Handle));
end;

procedure TDns.AddNameserver(const ipAddr: string; supportsTls: Boolean);
begin
  CkDns_AddNameserver(FHandle, PAnsiChar(StrToCk(ipAddr)), LongBool(supportsTls));
end;

procedure TDns.RemoveNameserver(const ipAddr: string);
begin
  CkDns_RemoveNameserver(FHandle, PAnsiChar(StrToCk(ipAddr)));
end;

procedure TDns.RemoveAllNameservers;
begin
  CkDns_RemoveAllNameservers(FHandle);
end;

procedure TDns.AddDefaultNameservers;
begin
  CkDns_AddDefaultNameservers(FHandle);
end;

initialization
  Chilkat_GetProcedureAddress(CkDns_Create,  'CkDns_Create');
  Chilkat_GetProcedureAddress(CkDns_Dispose, 'CkDns_Dispose');
  Chilkat_GetProcedureAddress(CkDns_SetAbortCheckCallback, 'CkDns_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkDns_SetPercentDoneCallback, 'CkDns_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkDns_SetProgressInfoCallback, 'CkDns_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkDns_get_LastErrorHtml, 'CkDns_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkDns_get_LastErrorText, 'CkDns_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkDns_get_LastErrorXml, 'CkDns_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkDns_get_Version, 'CkDns_get_Version');
  Chilkat_GetProcedureAddress(CkDns_get_DebugLogFilePath, 'CkDns_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkDns_put_DebugLogFilePath, 'CkDns_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkDns_get_VerboseLogging, 'CkDns_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkDns_put_VerboseLogging, 'CkDns_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkDns_get_LastMethodSuccess, 'CkDns_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkDns_put_LastMethodSuccess, 'CkDns_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkDns_get_NumNameservers, 'CkDns_get_NumNameservers');
  Chilkat_GetProcedureAddress(CkDns_get_HeartbeatMs, 'CkDns_get_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkDns_put_HeartbeatMs, 'CkDns_put_HeartbeatMs');
  Chilkat_GetProcedureAddress(CkDns_get_MaxWaitMs, 'CkDns_get_MaxWaitMs');
  Chilkat_GetProcedureAddress(CkDns_put_MaxWaitMs, 'CkDns_put_MaxWaitMs');
  Chilkat_GetProcedureAddress(CkDns_get_TlsPref, 'CkDns_get_TlsPref');
  Chilkat_GetProcedureAddress(CkDns_put_TlsPref, 'CkDns_put_TlsPref');
  Chilkat_GetProcedureAddress(CkDns_get_UncommonOptions, 'CkDns_get_UncommonOptions');
  Chilkat_GetProcedureAddress(CkDns_put_UncommonOptions, 'CkDns_put_UncommonOptions');
  Chilkat_GetProcedureAddress(CkDns_GetNameserver, 'CkDns_GetNameserver');
  Chilkat_GetProcedureAddress(CkDns_Query, 'CkDns_Query');
  Chilkat_GetProcedureAddress(CkDns_AddNameserver, 'CkDns_AddNameserver');
  Chilkat_GetProcedureAddress(CkDns_RemoveNameserver, 'CkDns_RemoveNameserver');
  Chilkat_GetProcedureAddress(CkDns_RemoveAllNameservers, 'CkDns_RemoveAllNameservers');
  Chilkat_GetProcedureAddress(CkDns_AddDefaultNameservers, 'CkDns_AddDefaultNameservers');

end.
