⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 revokecertlist.cpp

📁 一个简易的CA
💻 CPP
字号:
// RevokeCertList.cpp: implementation of the CRevokeCertList class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "RevokeCertList.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

#include "RevokeCert.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
IMPLEMENT_SERIAL(CRevokeCertList, CObject,0)

CRevokeCertList::CRevokeCertList()
{
	szErrStr[0] = '\0';
}

CRevokeCertList::~CRevokeCertList()
{
	ClearContent();
}
int CRevokeCertList::GetCount()
{
	return m_list.GetCount();
}

int CRevokeCertList::AutoAssemble(_RecordsetPtr pSet,
								  CString SNColName, 
								  CString TimeColName)
{
	ClearContent();
	try
	{
		pSet->MoveFirst();   
		while(pSet->EndOfFile==VARIANT_FALSE) 
		{
			CString strSN   = (char*)(_bstr_t)(pSet->Fields->GetItem
				(_variant_t((char*)(LPCTSTR)SNColName))->Value);
			CString strTime = (char*)(_bstr_t)(pSet->Fields->GetItem
				(_variant_t((char*)(LPCTSTR)TimeColName))->Value);			
			m_list.AddHead((CObject*)new CRevokeCert(strSN,strTime));
			pSet->MoveNext();  
		}		
	}//try
	catch (_com_error &e)
	{
		CString str=(char*)e.Description();
		sprintf(szErrStr,"%s",(char*)(LPCTSTR)str);
		return 0;
	}
	catch(CMemoryException me)
	{
		TCHAR   szCause[255];
		me.GetErrorMessage(szCause,255);
		sprintf(szErrStr,"%s",szCause);
		return 0;
	}
	return 1;
}

int CRevokeCertList::ClearContent()
{
	szErrStr[0] = '\0';
	if(!m_list.IsEmpty())
	{
		for(int i = 0 ; i < m_list.GetCount(); i++)
		{
			POSITION pos = m_list.FindIndex(i);
			if(pos == NULL)break;
			CRevokeCert *prev = (CRevokeCert*)m_list.GetAt(pos);
			if(prev != NULL)delete prev;
		}
	}
	if(!m_list.IsEmpty())m_list.RemoveAll();
	return 1;
}

void CRevokeCertList::GetErrString(char *pErrStr)
{
	if(pErrStr == NULL)return ;
	// strcpy没有越界检查
	strcpy(pErrStr,szErrStr);
	return;
}

long CRevokeCertList::GetSerialNumber(int position)
{
	sprintf(szErrStr,"第%d个记录不存在!",position);
	if( position > m_list.GetCount() || m_list.IsEmpty()) return -1;
	POSITION pos = m_list.FindIndex(position);
	if(pos == NULL)return -1;
	CRevokeCert *prev = (CRevokeCert*)m_list.GetAt(pos);
	if(prev != NULL) return prev->GetSNWithLong();
	else			 return -1;
}

char * CRevokeCertList::GetTimeStr(int position)
{
	sprintf(szErrStr,"取第%d个记录中时间失败!",position);
	if( position > m_list.GetCount() || m_list.IsEmpty()) return NULL;
	POSITION pos = m_list.FindIndex(position);
	if(pos == NULL)return NULL;
	CRevokeCert *prev = (CRevokeCert*)m_list.GetAt(pos);
	if(prev != NULL) return prev->GetTimeStr();
	else			 return NULL;
}

char * CRevokeCertList::GetSerialStr(int position)
{
	sprintf(szErrStr,"第%d个记录不存在!",position);
	if( position > m_list.GetCount() || m_list.IsEmpty()) return NULL;
	POSITION pos = m_list.FindIndex(position);
	if(pos == NULL)return NULL;
	CRevokeCert *prev = (CRevokeCert*)m_list.GetAt(pos);
	if(prev != NULL) return prev->GetSNStr();
	else			 return NULL;
}

time_t CRevokeCertList::GetTime_t(int position)
{
	sprintf(szErrStr,"取第%d个记录中时间失败!",position);
	if( position > m_list.GetCount() || m_list.IsEmpty()) return -1L;
	POSITION pos = m_list.FindIndex(position);
	if(pos == NULL)return -1L;
	CRevokeCert *prev = (CRevokeCert*)m_list.GetAt(pos);
	if(prev != NULL) return prev->GetTime();
	else			 return -1L;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -