コード例 #1
0
ファイル: Security.cpp プロジェクト: lemonxiao0/peerproject
void CSecurity::Ban(const CPeerProjectFile* pFile, int nBanLength, BOOL bMessage)
{
	CQuickLock oLock( m_pSection );

	const DWORD tNow = static_cast< DWORD >( time( NULL ) );

	for ( POSITION pos = GetIterator() ; pos ; )
	{
		POSITION posCurrent = pos;
		CSecureRule* pRule = GetNext( pos );

		if ( pRule->IsExpired( tNow ) )
		{
			m_pRules.RemoveAt( posCurrent );
			delete pRule;
			continue;
		}

		if ( pRule->Match( pFile ) )			// Non-regexp name, hash, or size:ext:0000
		{
			if ( pRule->m_nAction == CSecureRule::srDeny )
			{
				if ( nBanLength == banWeek && ( pRule->m_nExpire < tNow + 604000 ) )
					pRule->m_nExpire = tNow + 604800;
				else if ( nBanLength == banCustom && ( pRule->m_nExpire < tNow + Settings.Security.DefaultBan + 3600 ) )
					pRule->m_nExpire = tNow + Settings.Security.DefaultBan + 3600;
				else if ( nBanLength == banForever && ( pRule->m_nExpire != CSecureRule::srIndefinite ) )
					pRule->m_nExpire = CSecureRule::srIndefinite;
				return;
			}
		}
	}

	CSecureRule* pRule = NewBanRule( nBanLength );

	if ( pFile->m_oSHA1 || pFile->m_oTiger || pFile->m_oED2K || pFile->m_oBTH || pFile->m_oMD5 )
	{
		pRule->m_nType = CSecureRule::srContentHash;
		pRule->SetContentWords(
			( pFile->m_oSHA1  ? pFile->m_oSHA1.toUrn()  + _T(" ") : CString() ) +
			( pFile->m_oTiger ? pFile->m_oTiger.toUrn() + _T(" ") : CString() ) +
			( pFile->m_oED2K  ? pFile->m_oED2K.toUrn()  + _T(" ") : CString() ) +
			( pFile->m_oMD5   ? pFile->m_oMD5.toUrn()   + _T(" ") : CString() ) +
			( pFile->m_oBTH   ? pFile->m_oBTH.toUrn()             : CString() ) );
	}

	Add( pRule );

	if ( bMessage && pFile )
		theApp.Message( MSG_NOTICE, IDS_NETWORK_SECURITY_BLOCKED, (LPCTSTR)pFile->m_sName );
}