{-------------------------------------------------------------------------------
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
      THIS ISN'T COMPLETE TRANSLATION OF C++ HEADERS AND NEVER WILL BE.

  FOR COPYRIGHT OF ORIGINAL ERIC YOUNG SOFTWARE LOOK AT FILES IN HEADER FOLDER.
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Author :      Jan Tomasek
Description :
EMail :       xtomasej@fel.cvut.cz       http://www.feld.cvut.cz/~x590tomasej
Creation :    Jul 1998
Version :     0.20
Support :
Legal issues:
      Copyright (C) 1998 by Jan Tomasek <xtomasej@fel.cvut.cz>
      All rights reserved.

      This library is free for commercial and non-commercial use as long as
      the following conditions are aheared to.  The following conditions
      apply to all code found in this distribution.  The documentation
      included with this distribution is covered by the same copyright terms.

      Copyright remains Jan Tomasek's, and as such any Copyright notices in
      the code are not to be removed.
      If this package is used in a product, Jan Tomasek should be given
      attribution as the author of the parts of the library used.
      This can be in the form of a textual message at program startup or
      in documentation (online or textual) provided with the package.

      Redistribution and use in source and binary forms, with or without
      modification, are permitted provided that the following conditions
      are met:
      1. Redistributions of source code must retain the copyright
         notice, this list of conditions and the following disclaimer.
      2. Redistributions in binary form must reproduce the above copyright
         notice, this list of conditions and the following disclaimer in the
         documentation and/or other materials provided with the distribution.
      3. All advertising materials mentioning features or use of this software
         must display the following acknowledgement:
             "This product includes software written by
              Jan Tomasek <xtomasej@fel.cvut.cz>"

      THIS SOFTWARE IS PROVIDED BY JAN TOMASEK ``AS IS'' AND
      ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
      IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
      ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
      FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
      DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
      OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
      HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
      LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
      OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
      SUCH DAMAGE.

      The licence and distribution terms for any publically available version or
      derivative of this code cannot be changed.  i.e. this code cannot simply
      be copied and put under another distribution licence
      [including the GNU Public Licence.]

History :
  28.07.98 Created
-------------------------------------------------------------------------------}
unit LIBeay;

interface
{$I SSLeay.def}    {Conditional definitions ...}

{$I SSLconst.inc}

Type

{$I convtype.inc}
{$I md2_t.inc}
{$I md5_t.inc}
{$I des_t.inc}
{$I mdc2t.inc}
{$I sha_t.inc}
{$I epv_t.inc}
{$I x509_t.inc}
{$I x509v_t.inc}
{$I err_t.inc}

{$I x509v_p0.inc}

Const
  BEGIN_IMP_FUNC : Pointer=nil;
{$I err_p1.inc}
{$I x509_p1.inc}
{$I md2_p1.inc}
{$I md5_p1.inc}
  END_IMP_FUNC   : Pointer=nil;

Function  Init:Boolean;
procedure Done;

implementation
Uses
  WinTypes,  WinProcs;
Const
  Initialized  : Boolean = False;
  Handle       : THandle = 0;
  _            ={$IFDEF Win32}'';{$ELSE}'_' ;{$ENDIF}
  LibraryName  ={$IFDEF Win32}'LIBeay32.dll';{$ELSE}'LIBeay16.dll';{$ENDIF}

{$I x509v_p4.inc}

Function LoadFunction(Var res:Boolean; FceName:String):Pointer;
Begin
  If res Then Begin
    FceName := _+FceName+#0;
    Result  := GetProcAddress(Handle, @FceName[1]);
    If Result=nil Then res:=False;
  End Else
    Result  := nil;
End;

{$I err_p2.inc}
{$I x509_p2.inc}
{$I md2_p2.inc}
{$I md5_p2.inc}

Function  Init:Boolean;
Begin
  If Initialized Then Begin Result:=True; Exit; End;
  
  Result := False;

  {-- Load external functions -------------------------------------------------}
  Handle := WinProcs.LoadLibrary(LibraryName);
  If Handle=0 Then Exit;

  Result :=True;
  err_p2(Result);
  x509_p2(Result);
  md2_p2(Result);
  md5_p2(Result);

  {-- Initalize library -------------------------------------------------------}
  Initialized := Result;
  If not Result Then Exit;
End;

Procedure SetFuncPoiter2Nil;
Begin
  { This is maybe danger construction !}
  FillChar(BEGIN_IMP_FUNC, (Longint(@END_IMP_FUNC)-Longint(@BEGIN_IMP_FUNC)), 0);
End;

Procedure Done;
Begin
  If not Initialized Then Exit;
  Initialized:=False;

  FreeLibrary(Handle); Handle:=0;
  SetFuncPoiter2Nil;
End;

initialization
  Initialized:=False;
{$IFDEF WIN32}
finalization
  If Initialized Then Done;
{$ENDIF}
end.
