unit Chilkat.TrustedRoots;

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

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

interface

uses
  SysUtils,
  Chilkat.Base;

type

  { TTrustedRoots wraps CkTrustedRoots via the C bridge layer. }
  TTrustedRoots = 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  GetNumCerts: Integer;
    function  GetTrustSystemCaRoots: Boolean;
    procedure SetTrustSystemCaRoots(AValue: Boolean);
    function  GetRejectSelfSignedCerts: Boolean;
    procedure SetRejectSelfSignedCerts(AValue: Boolean);
    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 NumCerts: Integer read GetNumCerts;
    property TrustSystemCaRoots: Boolean read GetTrustSystemCaRoots write SetTrustSystemCaRoots;
    property RejectSelfSignedCerts: Boolean read GetRejectSelfSignedCerts write SetRejectSelfSignedCerts;

    { 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  Activate: Boolean;
    function  AddCert(cert: TChilkatBase): Boolean;
    function  AddJavaKeyStore(keystore: TChilkatBase): Boolean;
    function  Deactivate: Boolean;
    function  LoadCaCertsPem(const path: string): Boolean;
    function  CertAt(index: Integer; cert: TChilkatBase): Boolean;
  end;

implementation

uses
  CkDllLoader,
  Chilkat.Utils;

{ ---- C bridge function pointer types ---- }
type
  TCkTrustedRoots_Create  = function(): Pointer; cdecl;
  TCkTrustedRoots_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;
  TCkTrustedRoots_SetAbortCheckCallback   = procedure(handle: Pointer; cb: TCkBridgeAbortCheckCb; userData: Pointer); cdecl;
  TCkTrustedRoots_SetPercentDoneCallback  = procedure(handle: Pointer; cb: TCkBridgePercentDoneCb; userData: Pointer); cdecl;
  TCkTrustedRoots_SetProgressInfoCallback = procedure(handle: Pointer; cb: TCkBridgeProgressInfoCb; userData: Pointer); cdecl;
  TCkTrustedRoots_get_LastErrorHtml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkTrustedRoots_get_LastErrorText = function(handle: Pointer): PAnsiChar; cdecl;
  TCkTrustedRoots_get_LastErrorXml = function(handle: Pointer): PAnsiChar; cdecl;
  TCkTrustedRoots_get_Version = function(handle: Pointer): PAnsiChar; cdecl;
  TCkTrustedRoots_get_DebugLogFilePath = function(handle: Pointer): PAnsiChar; cdecl;
  TCkTrustedRoots_put_DebugLogFilePath = procedure(handle: Pointer; value: PAnsiChar); cdecl;
  TCkTrustedRoots_get_VerboseLogging = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_put_VerboseLogging = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkTrustedRoots_get_LastMethodSuccess = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_put_LastMethodSuccess = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkTrustedRoots_get_NumCerts = function(handle: Pointer): Integer; cdecl;
  TCkTrustedRoots_get_TrustSystemCaRoots = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_put_TrustSystemCaRoots = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkTrustedRoots_get_RejectSelfSignedCerts = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_put_RejectSelfSignedCerts = procedure(handle: Pointer; value: LongBool); cdecl;
  TCkTrustedRoots_Activate = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_AddCert = function(handle: Pointer; cert: Pointer): LongBool; cdecl;
  TCkTrustedRoots_AddJavaKeyStore = function(handle: Pointer; keystore: Pointer): LongBool; cdecl;
  TCkTrustedRoots_Deactivate = function(handle: Pointer): LongBool; cdecl;
  TCkTrustedRoots_LoadCaCertsPem = function(handle: Pointer; path: PAnsiChar): LongBool; cdecl;
  TCkTrustedRoots_CertAt = function(handle: Pointer; index: Integer; cert: Pointer): LongBool; cdecl;

{ ---- C bridge function pointer variables ---- }
var
  CkTrustedRoots_Create:  TCkTrustedRoots_Create  = nil;
  CkTrustedRoots_Dispose: TCkTrustedRoots_Dispose = nil;
  CkTrustedRoots_SetAbortCheckCallback:   TCkTrustedRoots_SetAbortCheckCallback   = nil;
  CkTrustedRoots_SetPercentDoneCallback:  TCkTrustedRoots_SetPercentDoneCallback  = nil;
  CkTrustedRoots_SetProgressInfoCallback: TCkTrustedRoots_SetProgressInfoCallback = nil;
  CkTrustedRoots_get_LastErrorHtml: TCkTrustedRoots_get_LastErrorHtml = nil;
  CkTrustedRoots_get_LastErrorText: TCkTrustedRoots_get_LastErrorText = nil;
  CkTrustedRoots_get_LastErrorXml: TCkTrustedRoots_get_LastErrorXml = nil;
  CkTrustedRoots_get_Version: TCkTrustedRoots_get_Version = nil;
  CkTrustedRoots_get_DebugLogFilePath: TCkTrustedRoots_get_DebugLogFilePath = nil;
  CkTrustedRoots_put_DebugLogFilePath: TCkTrustedRoots_put_DebugLogFilePath = nil;
  CkTrustedRoots_get_VerboseLogging: TCkTrustedRoots_get_VerboseLogging = nil;
  CkTrustedRoots_put_VerboseLogging: TCkTrustedRoots_put_VerboseLogging = nil;
  CkTrustedRoots_get_LastMethodSuccess: TCkTrustedRoots_get_LastMethodSuccess = nil;
  CkTrustedRoots_put_LastMethodSuccess: TCkTrustedRoots_put_LastMethodSuccess = nil;
  CkTrustedRoots_get_NumCerts: TCkTrustedRoots_get_NumCerts = nil;
  CkTrustedRoots_get_TrustSystemCaRoots: TCkTrustedRoots_get_TrustSystemCaRoots = nil;
  CkTrustedRoots_put_TrustSystemCaRoots: TCkTrustedRoots_put_TrustSystemCaRoots = nil;
  CkTrustedRoots_get_RejectSelfSignedCerts: TCkTrustedRoots_get_RejectSelfSignedCerts = nil;
  CkTrustedRoots_put_RejectSelfSignedCerts: TCkTrustedRoots_put_RejectSelfSignedCerts = nil;
  CkTrustedRoots_Activate: TCkTrustedRoots_Activate = nil;
  CkTrustedRoots_AddCert: TCkTrustedRoots_AddCert = nil;
  CkTrustedRoots_AddJavaKeyStore: TCkTrustedRoots_AddJavaKeyStore = nil;
  CkTrustedRoots_Deactivate: TCkTrustedRoots_Deactivate = nil;
  CkTrustedRoots_LoadCaCertsPem: TCkTrustedRoots_LoadCaCertsPem = nil;
  CkTrustedRoots_CertAt: TCkTrustedRoots_CertAt = nil;

constructor TTrustedRoots.Create;
begin
  inherited Create;
  FHandle := CkTrustedRoots_Create();
end;

destructor TTrustedRoots.Destroy;
begin
  if FHandle <> nil then
    CkTrustedRoots_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 TTrustedRoots_AbortCheckThunk(userData: Pointer): Integer; cdecl;
var
  obj: TTrustedRoots;
begin
  Result := 0;
  obj := TTrustedRoots(userData);
  if Assigned(obj) and Assigned(obj.FOnAbortCheck) then
    if obj.FOnAbortCheck(obj) then Result := 1;
end;

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

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

procedure TTrustedRoots.SetOnAbortCheck(AValue: TChilkatAbortCheckEvent);
begin
  FOnAbortCheck := AValue;
  if Assigned(AValue) then
    CkTrustedRoots_SetAbortCheckCallback(FHandle, @TTrustedRoots_AbortCheckThunk, Self)
  else
    CkTrustedRoots_SetAbortCheckCallback(FHandle, nil, nil);
end;

procedure TTrustedRoots.SetOnPercentDone(AValue: TChilkatPercentDoneEvent);
begin
  FOnPercentDone := AValue;
  if Assigned(AValue) then
    CkTrustedRoots_SetPercentDoneCallback(FHandle, @TTrustedRoots_PercentDoneThunk, Self)
  else
    CkTrustedRoots_SetPercentDoneCallback(FHandle, nil, nil);
end;

procedure TTrustedRoots.SetOnProgressInfo(AValue: TChilkatProgressInfoEvent);
begin
  FOnProgressInfo := AValue;
  if Assigned(AValue) then
    CkTrustedRoots_SetProgressInfoCallback(FHandle, @TTrustedRoots_ProgressInfoThunk, Self)
  else
    CkTrustedRoots_SetProgressInfoCallback(FHandle, nil, nil);
end;

function TTrustedRoots.GetLastErrorHtml: string;
begin
  Result := CkToStr(CkTrustedRoots_get_LastErrorHtml(FHandle));
end;

function TTrustedRoots.GetLastErrorText: string;
begin
  Result := CkToStr(CkTrustedRoots_get_LastErrorText(FHandle));
end;

function TTrustedRoots.GetLastErrorXml: string;
begin
  Result := CkToStr(CkTrustedRoots_get_LastErrorXml(FHandle));
end;

function TTrustedRoots.GetVersion: string;
begin
  Result := CkToStr(CkTrustedRoots_get_Version(FHandle));
end;

function TTrustedRoots.GetDebugLogFilePath: string;
begin
  Result := CkToStr(CkTrustedRoots_get_DebugLogFilePath(FHandle));
end;

procedure TTrustedRoots.SetDebugLogFilePath(AValue: string);
begin
  CkTrustedRoots_put_DebugLogFilePath(FHandle, PAnsiChar(StrToCk(AValue)));
end;

function TTrustedRoots.GetVerboseLogging: Boolean;
begin
  Result := Boolean(CkTrustedRoots_get_VerboseLogging(FHandle));
end;

procedure TTrustedRoots.SetVerboseLogging(AValue: Boolean);
begin
  CkTrustedRoots_put_VerboseLogging(FHandle, LongBool(AValue));
end;

function TTrustedRoots.GetLastMethodSuccess: Boolean;
begin
  Result := Boolean(CkTrustedRoots_get_LastMethodSuccess(FHandle));
end;

procedure TTrustedRoots.SetLastMethodSuccess(AValue: Boolean);
begin
  CkTrustedRoots_put_LastMethodSuccess(FHandle, LongBool(AValue));
end;

function TTrustedRoots.GetNumCerts: Integer;
begin
  Result := CkTrustedRoots_get_NumCerts(FHandle);
end;

function TTrustedRoots.GetTrustSystemCaRoots: Boolean;
begin
  Result := Boolean(CkTrustedRoots_get_TrustSystemCaRoots(FHandle));
end;

procedure TTrustedRoots.SetTrustSystemCaRoots(AValue: Boolean);
begin
  CkTrustedRoots_put_TrustSystemCaRoots(FHandle, LongBool(AValue));
end;

function TTrustedRoots.GetRejectSelfSignedCerts: Boolean;
begin
  Result := Boolean(CkTrustedRoots_get_RejectSelfSignedCerts(FHandle));
end;

procedure TTrustedRoots.SetRejectSelfSignedCerts(AValue: Boolean);
begin
  CkTrustedRoots_put_RejectSelfSignedCerts(FHandle, LongBool(AValue));
end;

function TTrustedRoots.Activate: Boolean;
begin
  Result := Boolean(CkTrustedRoots_Activate(FHandle));
end;

function TTrustedRoots.AddCert(cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkTrustedRoots_AddCert(FHandle, cert.Handle));
end;

function TTrustedRoots.AddJavaKeyStore(keystore: TChilkatBase): Boolean;
begin
  Result := Boolean(CkTrustedRoots_AddJavaKeyStore(FHandle, keystore.Handle));
end;

function TTrustedRoots.Deactivate: Boolean;
begin
  Result := Boolean(CkTrustedRoots_Deactivate(FHandle));
end;

function TTrustedRoots.LoadCaCertsPem(const path: string): Boolean;
begin
  Result := Boolean(CkTrustedRoots_LoadCaCertsPem(FHandle, PAnsiChar(StrToCk(path))));
end;

function TTrustedRoots.CertAt(index: Integer; cert: TChilkatBase): Boolean;
begin
  Result := Boolean(CkTrustedRoots_CertAt(FHandle, index, cert.Handle));
end;

initialization
  Chilkat_GetProcedureAddress(CkTrustedRoots_Create,  'CkTrustedRoots_Create');
  Chilkat_GetProcedureAddress(CkTrustedRoots_Dispose, 'CkTrustedRoots_Dispose');
  Chilkat_GetProcedureAddress(CkTrustedRoots_SetAbortCheckCallback, 'CkTrustedRoots_SetAbortCheckCallback');
  Chilkat_GetProcedureAddress(CkTrustedRoots_SetPercentDoneCallback, 'CkTrustedRoots_SetPercentDoneCallback');
  Chilkat_GetProcedureAddress(CkTrustedRoots_SetProgressInfoCallback, 'CkTrustedRoots_SetProgressInfoCallback');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_LastErrorHtml, 'CkTrustedRoots_get_LastErrorHtml');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_LastErrorText, 'CkTrustedRoots_get_LastErrorText');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_LastErrorXml, 'CkTrustedRoots_get_LastErrorXml');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_Version, 'CkTrustedRoots_get_Version');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_DebugLogFilePath, 'CkTrustedRoots_get_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkTrustedRoots_put_DebugLogFilePath, 'CkTrustedRoots_put_DebugLogFilePath');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_VerboseLogging, 'CkTrustedRoots_get_VerboseLogging');
  Chilkat_GetProcedureAddress(CkTrustedRoots_put_VerboseLogging, 'CkTrustedRoots_put_VerboseLogging');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_LastMethodSuccess, 'CkTrustedRoots_get_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkTrustedRoots_put_LastMethodSuccess, 'CkTrustedRoots_put_LastMethodSuccess');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_NumCerts, 'CkTrustedRoots_get_NumCerts');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_TrustSystemCaRoots, 'CkTrustedRoots_get_TrustSystemCaRoots');
  Chilkat_GetProcedureAddress(CkTrustedRoots_put_TrustSystemCaRoots, 'CkTrustedRoots_put_TrustSystemCaRoots');
  Chilkat_GetProcedureAddress(CkTrustedRoots_get_RejectSelfSignedCerts, 'CkTrustedRoots_get_RejectSelfSignedCerts');
  Chilkat_GetProcedureAddress(CkTrustedRoots_put_RejectSelfSignedCerts, 'CkTrustedRoots_put_RejectSelfSignedCerts');
  Chilkat_GetProcedureAddress(CkTrustedRoots_Activate, 'CkTrustedRoots_Activate');
  Chilkat_GetProcedureAddress(CkTrustedRoots_AddCert, 'CkTrustedRoots_AddCert');
  Chilkat_GetProcedureAddress(CkTrustedRoots_AddJavaKeyStore, 'CkTrustedRoots_AddJavaKeyStore');
  Chilkat_GetProcedureAddress(CkTrustedRoots_Deactivate, 'CkTrustedRoots_Deactivate');
  Chilkat_GetProcedureAddress(CkTrustedRoots_LoadCaCertsPem, 'CkTrustedRoots_LoadCaCertsPem');
  Chilkat_GetProcedureAddress(CkTrustedRoots_CertAt, 'CkTrustedRoots_CertAt');

end.
