/*

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

// CertCache.h: interface for the CCertCache class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_CERTCACHE_H__E685FC26_E844_11D2_B1AB_00207814A98B__INCLUDED_)
#define AFX_CERTCACHE_H__E685FC26_E844_11D2_B1AB_00207814A98B__INCLUDED_

#include "Cache.h"
#include "CertsRec.h"
#include "Defines.h"


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


#define CERTCACHE_ERRBASE				14000		
#define CERTCACHE_NOT_INITIALIZED		CERTCACHE_ERRBASE + 1
#define CERTCACHE_INVALID_CERT_DATA		CERTCACHE_ERRBASE + 2
#define CERTCACHE_ALLOC_FAIL			CERTCACHE_ERRBASE + 3
#define CERTCACHE_DELETE_ERROR			CERTCACHE_ERRBASE + 4
#define CERTCACHE_INSERT_ERROR			CERTCACHE_ERRBASE + 5
#define CERTCACHE_OUTPUTFILE_FAIL		CERTCACHE_ERRBASE + 6
#define CERTCACHE_NO_SUCH_ENTRY			CERTCACHE_ERRBASE + 7
#define CERTCACHE_DEL_ERROR				CERTCACHE_ERRBASE + 8
#define CERTCACHE_REQUIRED_PARAM		CERTCACHE_ERRBASE + 9
#define CERTCACHE_PARAM_INVALID			CERTCACHE_ERRBASE + 10
#define CERTCACHE_NO_MORE_CERTS			CERTCACHE_ERRBASE + 11
#define CERTCACHE_FATAL_EXCEPTION		CERTCACHE_ERRBASE + 12
#define CERTCACHE_NO_CALLBACK_PTR		CERTCACHE_ERRBASE + 13



// vector size
#define	CERTCACHE_TABLE_SIZE		47
// maximum CCertsRec's - NOT max cert count!
#define CERTCACHE_MAX_ENTRY_COUNT	71
// allowed entry flux
#define CERTCACHE_MAX_ENTRY_FLUX	10


class CCertCache  
{
public:
	void ClearAllFlags( ULONG sessionMask );
	long GetCert(char *subject, char *issuer, Bytes_struct *serial, ULONG sessMask, LPCPL_SESSION_INFO  sessInfo, LPCERTCACHE_ENTRY_STRUCT *pCert );
	long SearchForMoreCerts(CCertsRec *pRec, LPCPL_SESSION_INFO sessInfo, char* subject);
	int IsAllSearched( ULONG search_flag );
	long GetNextCert( char *subject, ULONG sessMask, LPCPL_SESSION_INFO  sessInfo, LPCERTCACHE_ENTRY_STRUCT *pCert );
	int m_policyCount;
	char** m_lpLastArrPolicySet;
	char* m_lpszLastTrustedRootDN;
	char *m_lpszErrorString;
	long IsValid();
	long AddEntry(Bytes_struct *pBinCert, long type, CCertsRec **pNewRec = NULL );
	long RemoveOldItems();
	long ReindexEntryNums();
	long Initialize();
	long SortCerts(char *trustedRootDN, char **acceptablePolicySet);
	CCertCache();
	virtual ~CCertCache();

protected:
	CMemCache<CCertsRec>* m_lpCertTable;
	long m_entryCount;
	long m_lastEntryNum;
	CCertsRec tmpCertRec;

};

#endif // !defined(AFX_CERTCACHE_H__E685FC26_E844_11D2_B1AB_00207814A98B__INCLUDED_)
