/*

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     :   Defines.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.
\*------------------------------------------------------------------------*/


#if !defined(__DEFINITIONS_HEADER_FILE_INCL__)
#define __DEFINITIONS_HEADER_FILE_INCL__

#include "cmapi.h"

#if defined(UNIX) || defined(BSD) || defined(_BSD)
	#ifndef _UNIX
	#define _UNIX
	#endif
#endif

#if defined(_UNIX)
	#include <stddef.h>
#endif

#ifndef ULONG
#define ULONG unsigned long
#endif

#ifndef NULL
#define NULL 0x0000
#endif

#ifndef BOOL
#define BOOL int
#endif

#ifndef TRUE
#define TRUE 1
#endif 

#ifndef FALSE
#define FALSE 0
#endif

#if !defined(__cplusplus)
	#error C++ compiler required.
#endif

#define CPLI_DO_NOT_INHIBIT_POLICY_MAPPING		0xFFFF
#define CPLI_DO_NOT_REQUIRE_EXPLICIT_POLICY		0xFFFF
#define CPLI_INHIBIT_POLICY_MAPPING				0x0000
#define CPLI_REQUIRE_EXPLICIT_POLICY			0x0000

#define CPL_ERR_BASE						40000
#define CPL_LIBRARY_NOT_INIT				CPL_ERR_BASE + 1
#define CPL_ALLOC_FAILURE					CPL_ERR_BASE + 2
#define CPL_PARAM_MISSING					CPL_ERR_BASE + 3
#define CPL_PTR_INVALID						CPL_ERR_BASE + 4
#define CPL_PATH_MUST_BE_NULL				CPL_ERR_BASE + 5
#define CPL_INVALID_SESSION_HANDLE			CPL_ERR_BASE + 6
#define CPL_NO_SUCH_SESSION					CPL_ERR_BASE + 7
#define CPL_NO_MORE_SESSIONS				CPL_ERR_BASE + 8
#define CPL_UNEXPECTED_ERROR				CPL_ERR_BASE + 9
#define CPL_INVALID_PARAM					CPL_ERR_BASE + 10
#define CPL_DECODE_CERT_FAIL				CPL_ERR_BASE + 11
#define CPL_WRONG_ISSUER					CPL_ERR_BASE + 12
#define CPL_NO_MORE_PATHS					CPL_ERR_BASE + 13
#define CPL_INVALID_ISSUER					CPL_ERR_BASE + 14
#define CPL_DUPLICATE_ISSUER				CPL_ERR_BASE + 15
#define CPL_CACHE_DISK_PATH_MISSING			CPL_ERR_BASE + 16
#define CPL_CACHE_FILE_READ_FAIL			CPL_ERR_BASE + 17
#define CPL_CACHE_FILE_WRITE_FAIL			CPL_ERR_BASE + 18
#define CPL_PATH_CACHE_ERROR				CPL_ERR_BASE + 19
#define CPL_CERT_CACHE_ERROR				CPL_ERR_BASE + 20
#define CPL_LOAD_LIBRARY_CMAPI_FAIL			CPL_ERR_BASE + 21
#define CPL_CMAPI_ERROR						CPL_ERR_BASE + 22
#define CPL_CALLBACK_PTRS_MISSING			CPL_ERR_BASE + 23
#define CPL_EXCEPTION_CAUGHT				CPL_ERR_BASE + 24

// Not returned from library ---->>
#define CPLI_GET_NEXT_TARGET_CERT			CPL_ERR_BASE + 100
#define CPLI_NULL_EXPECTED					CPL_ERR_BASE + 101	
#define CPLI_CROSSCERT_ASN_ERROR			CPL_ERR_BASE + 102
#define CPLI_NO_FORWARD_CERT				CPL_ERR_BASE + 103


#if defined(_WIN32) && defined(_DEBUG)
	#if !defined(ASSERT)
		#if defined(_ASSERTE)
			#include <crtdbg.h>
			#define ASSERT _ASSERTE
		#else
			#include <assert.h>
			#define ASSERT assert
		#endif
	#endif
#endif

typedef struct CertPath_struct
{
    Cert_struct *cert;
    Bytes_struct asn1cert;
    struct CertPath_struct *next;
} CertPath_struct;
/*
typedef struct EncObject_LL
{
	Bytes_struct	encObj;
	long			typeMask;
	short			locMask;
	struct			EncObject_LL	*next;
} EncObject_LL;
*/

typedef struct
{
	/* Subject cert tuple */
	char *subjectIssuerDN;
	Bytes_struct subjectSerial;
	/* Subject's issuer tuple */
	char *issuerCADN;
	Bytes_struct issuerSerial;

} PATH_ENTRY_STRUCT;

typedef PATH_ENTRY_STRUCT *    LPPATH_ENTRY_STRUCT;

typedef struct PATH_ENTRY_LIST
{
	PATH_ENTRY_STRUCT data;
	PATH_ENTRY_LIST *next;
} PATH_ENTRY_LIST; 

typedef PATH_ENTRY_LIST *    LPPATH_ENTRY_LIST;

typedef struct LOCAL_SESSION_INFO
{
	int IsInUse;
	ULONG mask;
	int usePathCache;
	char* subjectDN;
	char** desiredAlgOIDArray;
	unsigned short keyUsage; 
	Bytes_struct skid;
	CertPath_struct *pHead;
	int inhibitPolicyMapping;
	int requireExplicitPolicy;
	CertPath_struct *pPartialPath;
} LOCAL_SESSION_INFO;

typedef LOCAL_SESSION_INFO *LPLOCAL_SESSION_INFO;

/*
#define RAM_LOC			0x00000001
#define CLIENT_LOC		0x00000002
#define SERVER_LOC		0x00000004
#define DSA_LOC			0x00000008
*/
#define ALL_LOC			(RAM_LOC | CLIENT_LOC | SERVER_LOC | DSA_LOC)

/* cACertificate */
#define USER_CERT_TYPE	0x0001	/* User certificate requested (or found) */
/* userCertificate */
#define CA_CERT_TYPE	0x0002	/* CA certificate requested (or found) */
/* crossCertificatePair */
#define CROSS_CERT_TYPE	0x0004	/* Cross certificate pair requested (or found) */

// Old masks
//#define CA_CERT_TYPE	0x00010000
//#define USER_CERT_TYPE	0x00020000
//#define CROSS_CERT_TYPE	0x00040000

//The last path returned was verified
#define CPL_LAST_PATH_VALID		1
#define CPL_LAST_PATH_INVALID	2

#define CPL_MAX_SESSION		32

#ifndef CM_CALL
#define CM_CALL __cdecl
#endif

#if defined(_UNIX)
	typedef short (*CPL_GET_CERTS_CALLBACK)(void*,char*,long,short,EncObject_LL **);
	typedef void (*CPL_FREE_CERTS_CALLBACK)(void*,EncObject_LL** objectList);
// prototypes
//	short ext_get_objects(void* extHandle, char* DN, long typeMask, short locMask, EncObject_LL **objectList);
//	void ext_free_objects(void* extHandle, EncObject_LL** objectList);
#else
	typedef short (CM_CALL *CPL_GET_CERTS_CALLBACK)(void*,char*,long,short,EncObject_LL **);
	typedef void (CM_CALL *CPL_FREE_CERTS_CALLBACK)(void*,EncObject_LL** objectList);
// prototypes
//	short CM_CALLBACK ext_get_objects(void* extHandle, char* DN, long typeMask, short locMask, EncObject_LL **objectList);
//	void CM_CALLBACK ext_free_objects(void* extHandle, EncObject_LL** objectList);
#endif

typedef struct
{
	char** rootDN;
	char** acceptableAlgOIDArray;
	char** acceptablePolicySetArray;
	CPL_GET_CERTS_CALLBACK getCerts;
	CPL_FREE_CERTS_CALLBACK freeCerts;
	void* callbackHandle;
	short boundsMask;
} CPL_SESSION_INFO;

typedef CPL_SESSION_INFO *	LPCPL_SESSION_INFO;

typedef struct CERTCACHE_ENTRY_STRUCT
{
	unsigned long flag;
	long type;
	Cert_struct * pCert;
	Bytes_struct binCert;
	CERTCACHE_ENTRY_STRUCT *pNext;

} CERTCACHE_ENTRY_STRUCT;

typedef CERTCACHE_ENTRY_STRUCT *  LPCERTCACHE_ENTRY_STRUCT;

#if !defined (SOLARIS)
#if !defined(_AFXDLL)
#if !defined ( VX )
#include <fstream.h>

class CDumpClass : public ofstream
{
public:
	CDumpClass()
	{
		#if defined(_UNIX)
			ofstream::open("./cpdlib.log",ios::out | ios::ate | ios::trunc );
		#else
			ofstream::open("c:\\cpdlib.log",ios::out | ios::ate | ios::trunc );
		#endif
	}

	CDumpClass(char *fname)
	{
		ofstream::open(fname,ios::out | ios::ate | ios::trunc );
	}

	~CDumpClass()
	{
		ofstream::close();
	}

	void Flush(){ flush(); }

};

#ifdef _WIN32
extern CDumpClass afxDump;
#endif

#define DEBUG_NEW	new

#endif
#endif
#endif


#endif //__DEFINITIONS_HEADER_FILE_INCL__
