/*

The contents of this file are subject to the Mozilla Public License
Version 1.1 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/

Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.

The Original Code is a portion of the Path Development API developed
by CygnaCom Solutions, Inc.

Portions created by CygnaCom Solutions, Inc. are Copyright (C) CygnaCom 
Solutions, Inc. All Rights Reserved.

Contributor(s): ______________________________________.

http://www.cygnacom.com

*/
/*------------------------------------------------------------------------*\
|  Project Name  :   Path Development API
|  File Name     :   CMAPIInterface.h
|  Creation Date :   May 17, 1999
|  Author        :   Matt Cooper (mcooper@cygnacom.com)
|  Last Mode Date:   May 17, 1999
|  Modification History:
|--------------------------------------------------------------------------
|
|     Known Bugs:   None
|                   
|--------------------------------------------------------------------------
| Cryptographic devices and technical data regarding them are subject to
| Federal Government export controls as specified in Title 22, Code of
| Federal Regulations, Parts 121 through 128.  Cryptographic devices
| implementing the Data Encryption Standard (DES) and technical data
| regarding them must comply with these Federal regulations
|--------------------------------------------------------------------------
| Copyright (c) 1999, CygnaCom Solutions, Inc.
| All Rights Reserved.
\*------------------------------------------------------------------------*/

// CMAPIInterface.h: interface for the CCMAPIInterface class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CMAPIINTERFACE_H__B40035F1_D258_11D2_B19E_00207814A98B__INCLUDED_)
#define AFX_CMAPIINTERFACE_H__B40035F1_D258_11D2_B19E_00207814A98B__INCLUDED_

#if defined(_WIN32)
	#if defined(_AFXDLL)
	#else
		#include "windows.h"
	#endif
#endif


#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#define CCMAPIINTERFACE_MAX_ERR_SIZE 256

#define CCMAPIINTERFACE_ERR_BASE			8000
#define CCMAPIINTERFACE_LOADLIB_FAILED		CCMAPIINTERFACE_ERR_BASE + 1
#define CCMAPIINTERFACE_ALLOC_ERR			CCMAPIINTERFACE_ERR_BASE + 2
#define CCMAPIINTERFACE_GETPROC_FAIL		CCMAPIINTERFACE_ERR_BASE + 3
#define CCMAPIINTERFACE_CMAPI_EXCEPTION		CCMAPIINTERFACE_ERR_BASE + 4
#define CCMAPIINTERFACE_SESSIONCREATE_FAIL	CCMAPIINTERFACE_ERR_BASE + 5
#define CCMAPIINTERFACE_SESSIONDESTROY_FAIL	CCMAPIINTERFACE_ERR_BASE + 6
#define CCMAPIINTERFACE_LIB_NOT_LOADED		CCMAPIINTERFACE_ERR_BASE + 7
#define CCMAPIINTERFACE_CODE_PTR_INVALID	CCMAPIINTERFACE_ERR_BASE + 8


#include "cmapi.h"
#include "Defines.h"

//#define WINAPI      __stdcall
//#define WINAPIV     __cdecl
#if !defined(CM_CALL)
#define CM_CALL	__cdecl
#endif

/* #if defined(_UNIX) *//* Modified by Masanori Satake. */
#if defined(_UNIX) || defined(VX) /* Added by Masanori Satake. */
	//short CM_DecodeCert(ulong sessionID, ASN1_Data encodedCert,Cert_struct **decCert);
	typedef short (*CMAPI_DECODECERT_PROC)(ULONG,ASN1_Data,Cert_struct**);

	//void CM_FreeCert(ulong sessionID, Cert_struct **decCert);
	typedef void (*CMAPI_FREECERT_PROC)(ULONG,Cert_struct**);

	//short CM_CreateSession(ulong *sessionID); // MAC - sessionID is NON ZERO..
	typedef short (*CMAPI_CREATESESSION_PROC)(ULONG*, cmLDAP_authInfo_st *, void *);

	//short CM_DestroySession(ulong *sessionID);
	typedef short (*CMAPI_DESTROYSESSION_PROC)(ULONG*);
#else
	//short CM_DecodeCert(ulong sessionID, ASN1_Data encodedCert,Cert_struct **decCert);
	typedef short (CM_CALL *CMAPI_DECODECERT_PROC)(ULONG,ASN1_Data,Cert_struct**);

	//void CM_FreeCert(ulong sessionID, Cert_struct **decCert);
	typedef void (CM_CALL *CMAPI_FREECERT_PROC)(ULONG,Cert_struct**);

	//short CM_CreateSession(ulong *sessionID); // MAC - sessionID is NON ZERO..
	typedef short (CM_CALL *CMAPI_CREATESESSION_PROC)(ULONG*, cmLDAP_authInfo_st *);

	//short CM_DestroySession(ulong *sessionID);
	typedef short (CM_CALL *CMAPI_DESTROYSESSION_PROC)(ULONG*);
#endif

// Define this to monitor #of Decode calls vs #of Free calls
// (Uses Win32 ASSERT macro )
#if defined(_DEBUG)
#define _DEBUGCOUNT
#endif

class CCMAPIInterface  
{
public:
	// Loads the CMAPI Dll and gets function addresses
  /* #ifndef VX *//* Added by Masanori Satake. */
	long LoadCMAPILibrary( char * libraryName );
	/*
#else
	long LoadCMAPILibrary();
#endif
	*/

	// Maps to CMAPI calls
	long FreeCert(Cert_struct **decCert);
	long DecodeCert(ASN1_Data encodedCert,Cert_struct **decCert);

	// "Last Error" string
	char m_lpszErrorString[CCMAPIINTERFACE_MAX_ERR_SIZE];

	CCMAPIInterface();
	virtual ~CCMAPIInterface();

protected:
	// Dll Name
	char* m_lpszLibraryName;

	// Dll handle
        #ifndef VX /* Added by Masanori Satake. */
	#if !defined(_UNIX)
		HINSTANCE m_hLibrary;
	#else
		void *m_hLibrary;	
	#endif
        #endif /* #ifndef VX */

	// Dll procedures
	CMAPI_DECODECERT_PROC		iDecodeCertProc;
	CMAPI_FREECERT_PROC			iFreeCertProc;
	CMAPI_CREATESESSION_PROC	iCreateSessionProc;
	CMAPI_DESTROYSESSION_PROC	iDestroySessionProc;
	// NULL's all of above
	void ZeroAllProcs();

	// CMAPI session handle
	ULONG m_sessionHandle;
	
	cmLDAP_authInfo_st *m_ldap_auth_info;
	void	*tib;
	
	// CMAPI Session creation / destruction
	long CreateSession();
	long DestroySession();


#ifdef _DEBUGCOUNT
	ULONG m_decodeCount;
	ULONG m_freeCount;
#endif


};

#endif // !defined(AFX_CMAPIINTERFACE_H__B40035F1_D258_11D2_B19E_00207814A98B__INCLUDED_)
