CBuffer* CZIPFile::File::Decompress() { z_stream pStream; if ( m_nSize > 32*1024*1024 ) return NULL; if ( ! PrepareToDecompress( &pStream ) ) return NULL; if ( m_nCompression == 0 ) { CBuffer* pTarget = new CBuffer(); pTarget->EnsureBuffer( (DWORD)m_nSize ); ReadFile( m_pZIP->m_hFile, pTarget->m_pBuffer, (DWORD)m_nSize, &pTarget->m_nLength, NULL ); if ( pTarget->m_nLength == (DWORD)m_nSize ) return pTarget; delete pTarget; return NULL; } DWORD nSource = (DWORD)m_nCompressedSize; BYTE* pSource = new BYTE[ nSource ]; ReadFile( m_pZIP->m_hFile, pSource, nSource, &nSource, NULL ); if ( nSource != (DWORD)m_nCompressedSize ) { inflateEnd( &pStream ); return NULL; } CBuffer* pTarget = new CBuffer(); pTarget->EnsureBuffer( (DWORD)m_nSize ); pTarget->m_nLength = (DWORD)m_nSize; pStream.next_in = pSource; pStream.avail_in = (DWORD)m_nCompressedSize; pStream.next_out = pTarget->m_pBuffer; pStream.avail_out = pTarget->m_nLength; inflate( &pStream, Z_FINISH ); delete [] pSource; if ( pStream.avail_out != 0 ) { delete pTarget; pTarget = NULL; } inflateEnd( &pStream ); return pTarget; }
BOOL CHostBrowser::LoadDC(LPCTSTR pszFile, CQueryHit*& pHits) { CFile pFile; if ( ! pFile.Open( pszFile, CFile::modeRead | CFile::shareDenyWrite ) ) return FALSE; // File open error UINT nInSize = (UINT)pFile.GetLength(); if ( ! nInSize ) return FALSE; // Empty file CBuffer pBuffer; if ( ! pBuffer.EnsureBuffer( nInSize ) ) return FALSE; // Out of memory if ( pFile.Read( pBuffer.GetData(), nInSize ) != nInSize ) return FALSE; // File read error pBuffer.m_nLength = nInSize; if ( ! pBuffer.UnBZip() ) return FALSE; // Decompression error augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer.ReadString( pBuffer.m_nLength, CP_UTF8 ), TRUE ) ); if ( ! pXML.get() ) return FALSE; // XML decoding error // <FileListing Version="1" CID="SKCB4ZF4PZUDF7RKQ5LX6SVAARQER7QEVELZ2TY" Base="/" Generator="DC++ 0.762"> if ( ! pXML->IsNamed( L"FileListing" ) ) return FALSE; // Invalid XML file format // CString strTitle = pXML->GetAttributeValue( L"CID" ); return LoadDCDirectory( pXML.get(), pHits ); }
BOOL CSecurity::Import(LPCTSTR pszFile) { CString strText; CBuffer pBuffer; CFile pFile; if ( ! pFile.Open( pszFile, CFile::modeRead ) ) return FALSE; pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() ); pBuffer.m_nLength = (DWORD)pFile.GetLength(); pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); CXMLElement* pXML = CXMLElement::FromBytes( pBuffer.m_pBuffer, pBuffer.m_nLength, TRUE ); BOOL bResult = FALSE; if ( pXML != NULL ) { bResult = FromXML( pXML ); delete pXML; } else { CString strLine; while ( pBuffer.ReadLine( strLine ) ) { strLine.Trim(); if ( strLine.IsEmpty() ) continue; if ( strLine.GetAt( 0 ) == ';' ) continue; CSecureRule* pRule = new CSecureRule(); if ( pRule->FromGnucleusString( strLine ) ) { CQuickLock oLock( m_pSection ); m_pRules.AddTail( pRule ); bResult = TRUE; } else { delete pRule; } } } // Check all lists for newly denied hosts PostMainWndMessage( WM_SANITY_CHECK ); return bResult; }
BOOL CCollectionFile::LoadDC(LPCTSTR pszFile) { m_nType = SimpleCollection; // ToDo: Add schema detection m_sThisURI = CSchema::uriFolder; m_sParentURI = CSchema::uriCollectionsFolder; CFile pFile; if ( ! pFile.Open( pszFile, CFile::modeRead | CFile::shareDenyWrite ) ) return FALSE; // File open error UINT nInSize = (UINT)pFile.GetLength(); if ( ! nInSize ) return FALSE; // Empty file CBuffer pBuffer; if ( ! pBuffer.EnsureBuffer( nInSize ) ) return FALSE; // Out of memory if ( pFile.Read( pBuffer.GetData(), nInSize ) != nInSize ) return FALSE; // File read error pBuffer.m_nLength = nInSize; if ( ! pBuffer.UnBZip() ) return FALSE; // Decompression error augment::auto_ptr< CXMLElement > pXML ( CXMLElement::FromString( pBuffer.ReadString( pBuffer.m_nLength, CP_UTF8 ), TRUE ) ); if ( ! pXML.get() ) return FALSE; // XML decoding error // <FileListing Version="1" CID="SKCB4ZF4PZUDF7RKQ5LX6SVAARQER7QEVELZ2TY" Base="/" Generator="DC++ 0.762"> if ( ! pXML->IsNamed( L"FileListing" ) ) return FALSE; // Invalid XML file format m_sTitle = pXML->GetAttributeValue( L"CID" ); LoadDC( pXML.get() ); return ( m_pFiles.GetCount() != 0 ); }
BOOL CUploadTransferED2K::DispatchNextChunk() { ASSERT( m_nState == upsUploading ); if ( !m_pDiskFile ) return FALSE; ASSERT( m_nLength < SIZE_UNKNOWN ); ASSERT( m_nPosition < m_nLength ); QWORD nChunk = m_nLength - m_nPosition; nChunk = min( nChunk, QWORD(Settings.eDonkey.FrameSize) ); #if 0 // Use packet form CEDPacket* pPacket = CEDPacket::New( ED2K_C2C_SENDINGPART ); pPacket->Write( &m_pED2K, sizeof(MD4) ); pPacket->WriteLongLE( m_nOffset + m_nPosition ); pPacket->WriteLongLE( m_nOffset + m_nPosition + nChunk ); m_pDiskFile->Read( m_nFileBase + m_nOffset + m_nPosition, pPacket->GetWritePointer( nChunk ), nChunk, &nChunk ); // SetFilePointer( hFile, m_nFileBase + m_nOffset + m_nPosition, NULL, FILE_BEGIN ); // ReadFile( hFile, pPacket->WriteGetPointer( nChunk ), nChunk, &nChunk, NULL ); if ( nChunk == 0 ) { pPacket->Release(); return FALSE; } pPacket->m_nLength = sizeof(MD4) + 8 + nChunk; Send( pPacket ); #else // Raw write CBuffer* pBuffer = m_pClient->m_pOutput; pBuffer->EnsureBuffer( sizeof(ED2K_PART_HEADER) + (DWORD)nChunk ); ED2K_PART_HEADER* pHeader = (ED2K_PART_HEADER*)( pBuffer->m_pBuffer + pBuffer->m_nLength ); if ( ! m_pDiskFile->Read( m_nFileBase + m_nOffset + m_nPosition, &pHeader[1], nChunk, &nChunk ) ) return FALSE; // SetFilePointer( hFile, m_nFileBase + m_nOffset + m_nPosition, NULL, FILE_BEGIN ); // ReadFile( hFile, &pHeader[1], nChunk, &nChunk, NULL ); if ( nChunk == 0 ) return FALSE; pHeader->nProtocol = ED2K_PROTOCOL_EDONKEY; pHeader->nType = ED2K_C2C_SENDINGPART; pHeader->nLength = 1 + sizeof(MD4) + 8 + (DWORD)nChunk; pHeader->pMD4 = m_pED2K; pHeader->nOffset1 = (DWORD)( m_nOffset + m_nPosition ); pHeader->nOffset2 = (DWORD)( m_nOffset + m_nPosition + nChunk ); pBuffer->m_nLength += sizeof(ED2K_PART_HEADER) + (DWORD)nChunk; m_pClient->Send( NULL ); #endif m_nPosition += nChunk; m_nUploaded += nChunk; Statistics.Current.Uploads.Volume += ( nChunk / 1024 ); return TRUE; }
// If the contents of this buffer are between headers and compressed with gzip, this method can remove all that // Returns false on error BOOL CBuffer::Ungzip() { // Make sure there are at least 10 bytes in this buffer if ( m_nLength < 10 ) return FALSE; // Make sure the first 3 bytes are not 1f8b08 if ( m_pBuffer[0] != 0x1F || m_pBuffer[1] != 0x8B || m_pBuffer[2] != 8 ) return FALSE; // At a distance of 3 bytes into the buffer, read the byte there and call it nFlags BYTE nFlags = m_pBuffer[3]; // Remove the first 10 bytes of the buffer Remove( 10 ); // If there is a 1 in position 0000 0100 in the flags byte if ( nFlags & 0x04 ) { // Make sure the buffer has 2 or more bytes if ( m_nLength < 2 ) return FALSE; // Look at the first 2 bytes in the buffer as a word, this says how long the data it beyond it WORD nLen = *(WORD*)m_pBuffer; // If the buffer has less data than it should, return false if ( (int)m_nLength < (int)nLen + 2 ) return FALSE; // Remove the length word and the length it describes from the front of the buffer Remove( 2 + nLen ); } // If there is a 1 in position 0000 1000 in the flags byte if ( nFlags & 0x08 ) { // Loop until after we remove a 0 byte from the buffer for ( ;; ) { // If the buffer is empty, return false if ( m_nLength == 0 ) return FALSE; // Move the first byte of the buffer into an int int nChar = m_pBuffer[0]; // Copy one byte from the start of the buffer into an int named nChar Remove( 1 ); // Remove that first byte from the buffer // If we just removed a 0 byte, exit the loop if ( nChar == 0 ) break; } } // If there is a 1 in position 0001 0000 in the flags byte if ( nFlags & 0x10 ) { // Loop until after we remove a 0 byte from the buffer for ( ;; ) { // If the buffer is empty, return false if ( m_nLength == 0 ) return FALSE; // Move the first byte of the buffer into an int int nChar = m_pBuffer[0]; // Copy one byte from the start of the buffer into an int named nChar Remove( 1 ); // Remove that first byte from the buffer // If we just removed a 0 byte, exit the loop if ( nChar == 0 ) break; } } // If there is a 1 in position 0000 0010 in the flags byte if ( nFlags & 0x02 ) { // Make sure the buffer has at least 2 bytes, and then remove them if ( m_nLength < 2 ) return FALSE; Remove( 2 ); } // After removing all that header information from the front, remove the last 8 bytes from the end if ( m_nLength <= 8 ) return FALSE; // Make sure the buffer has more than 8 bytes m_nLength -= 8; // Remove the last 8 bytes in the buffer // Setup a z_stream structure to perform a raw inflate z_stream pStream; ZeroMemory( &pStream, sizeof(pStream) ); if ( Z_OK != inflateInit2( // Initialize a stream inflation with more options than just inflateInit &pStream, // Stream structure to initialize -MAX_WBITS ) ) { // Window bits value of -15 to perform a raw inflate // The Zlib function inflateInit2 returned something other than Z_OK, report error return FALSE; } // Make a new buffer for the output CBuffer pOutput; pOutput.EnsureBuffer( m_nLength * 6 ); // Guess that inflating the data won't make it more than 6 times as big // Tell the z_stream structure where to work pStream.next_in = m_pBuffer; // Decompress the memory here pStream.avail_in = m_nLength; // There is this much of it pStream.next_out = pOutput.m_pBuffer; // Write decompressed data here pStream.avail_out = pOutput.m_nBuffer; // Tell ZLib it has this much space, it make this smaller to show how much space is left // Call ZLib inflate to decompress all the data, and see if it returns Z_STREAM_END BOOL bSuccess = ( Z_STREAM_END == inflate( &pStream, Z_FINISH ) ); // The inflate call returned Z_STREAM_END if ( bSuccess ) { // Move the decompressed data from the output buffer into this one Clear(); // Record there are no bytes stored here, doesn't change the allocated block size Add(pOutput.m_pBuffer, // Add the memory at the start of the output buffer pOutput.m_nBuffer // The amount of space the buffer had when we gave it to Zlib - pStream.avail_out ); // Minus the amount it said it left, this is the number of bytes it wrote // Close ZLib and report success inflateEnd( &pStream ); return TRUE; } // The inflate call returned something else else { // Close ZLib and report error inflateEnd( &pStream ); return FALSE; } }
int CProfileProfilePage::LoadDefaultInterests() { int nCount = 0; const CString strFile = Settings.General.Path + _T("\\Data\\Interests.dat"); // Settings.General.DataPath ? CFile pFile; if ( ! pFile.Open( strFile, CFile::modeRead ) ) return nCount; try { CString strLine; CString strLang = _T(" ") + Settings.General.Language; CBuffer pBuffer; pBuffer.EnsureBuffer( (DWORD)pFile.GetLength() ); pBuffer.m_nLength = (DWORD)pFile.GetLength(); pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); // Format: Delineated List, enabled by prespecified #languages: #start en ... #end en // (Allows multiple/nested/overlapped languages, all applicable results displayed alphabetically) BOOL bActive = FALSE; while ( pBuffer.ReadLine( strLine ) ) { if ( strLine.GetLength() < 2 ) continue; // Blank line if ( strLine.GetAt( 0 ) == '#' ) // Language start/end line { if ( strLine.Find( strLang, 4 ) < 1 && strLine.Find( _T(" all"), 4 ) < 1 ) { if ( strLine.Left( 10 ) == _T("#languages") ) strLang = _T(" en"); } else if ( strLine.Left( 6 ) == _T("#start") || strLine.Left( 6 ) == _T("#begin") ) bActive = TRUE; else if ( strLine.Left( 4 ) == _T("#end") ) bActive = FALSE; //break; continue; } if ( ! bActive ) continue; // Disinterested language if ( strLine.Find( _T("\t") ) > 0 ) // Trim at whitespace (remove any comments) strLine.Left( strLine.Find( _T("\t") ) ); nCount++; m_wndInterestAll.AddString( strLine ); } } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } return nCount; }
void CListLoader::OnRun() { while ( IsThreadEnabled() && m_pQueue.GetCount() ) { CSecureRule* pRule = m_pQueue.GetHead(); if ( ! pRule || ! pRule->m_pContent || pRule->m_nType != CSecureRule::srExternal ) { m_pQueue.RemoveHead(); continue; } CString strPath = pRule->GetContentWords(); if ( strPath.GetLength() < 6 ) { m_pQueue.RemoveHead(); continue; } CString strCommentBase = pRule->m_sComment; if ( strCommentBase.IsEmpty() ) strCommentBase = _T("• %u"); else if ( strCommentBase.ReverseFind( _T('•') ) >= 0 ) strCommentBase = strCommentBase.Left( strCommentBase.ReverseFind( _T('•') ) + 1 ) + _T(" %u"); else strCommentBase += _T(" • %u"); if ( strPath[1] != _T(':') ) strPath = Settings.General.DataPath + strPath; CFile pFile; if ( ! pFile.Open( (LPCTSTR)strPath.GetBuffer(), CFile::modeRead ) ) { m_pQueue.RemoveHead(); continue; } const BYTE nIndex = Security.SetRuleIndex( pRule ); try { CBuffer pBuffer; const DWORD nLength = pFile.GetLength(); pBuffer.EnsureBuffer( nLength ); pBuffer.m_nLength = nLength; pFile.Read( pBuffer.m_pBuffer, nLength ); pFile.Close(); // Format: Delineated Lists CString strLine, strURN; DWORD nCount = 0; int nPos; //TIMER_START while ( pBuffer.ReadLine( strLine ) && IsThreadEnabled() && pRule ) { strLine.TrimRight(); if ( strLine.GetLength() < 7 ) continue; // Blank/Invalid line if ( strLine[ 0 ] == '#' ) { if ( strLine[ strLine.GetLength() - 1 ] == _T(':') && strLine.Find( _T("urn:") ) > 0 ) strURN = strLine.Mid( strLine.Find( _T("urn:") ) ); // Default "# urn:type:" continue; // Comment line } if ( strLine[ 0 ] < '0' || strLine[ 0 ] > 'z' ) // Whitespace/Chars continue; // Invalid line if ( ++nCount % 10 == 0 ) { if ( pRule->m_sComment.IsEmpty() ) strCommentBase = _T("• %u"); else if ( pRule->m_sComment.ReverseFind( _T('•') ) < 0 ) strCommentBase = pRule->m_sComment + _T(" • %u"); pRule->m_sComment.Format( strCommentBase, nCount ); Sleep( 1 ); // Limit CPU } // Hashes: if ( ( ! strURN.IsEmpty() && strLine.Find( _T('.'), 5 ) < 0 ) || StartsWith( strLine, _PT("urn:") ) ) { nPos = strLine.FindOneOf( _T(" \t") ); if ( nPos > 0 ) strLine.Truncate( nPos ); // Trim at whitespace (remove any trailing comments) if ( ! strURN.IsEmpty() && ! StartsWith( strLine, _PT("urn:") ) ) strLine = strURN + strLine; // Default "urn:type:" prepended if ( strLine.GetLength() > 35 ) Security.SetHashMap( strLine, nIndex ); else nCount--; continue; } // IPs: nPos = strLine.ReverseFind( _T(':') ); if ( nPos > 0 ) strLine = strLine.Mid( nPos + 1 ); // Remove leading comment for some formats nPos = strLine.FindOneOf( _T(" \t") ); if ( nPos > 0 ) strLine.Truncate( nPos ); // Trim at whitespace (remove any trailing comments) if ( strLine.GetLength() < 7 || strLine.Find( _T('.') ) < 1 ) { nCount--; continue; } nPos = strLine.Find( _T('-') ); // Possible Range if ( nPos < 0 ) // Single IP { Security.SetAddressMap( IPStringToDWORD( strLine, TRUE ), nIndex ); continue; } CString strFirst = strLine.Left( nPos ); CString strLast = strLine.Mid( nPos + 1 ); if ( strFirst == strLast ) { Security.SetAddressMap( IPStringToDWORD( strLine, TRUE ), nIndex ); continue; } // inet_addr( CT2CA( (LPCTSTR)strLast ) DWORD nFirst = IPStringToDWORD( strFirst, FALSE ); DWORD nLast = IPStringToDWORD( strLast, FALSE ); if ( nFirst < 10 || nFirst >= 0xE0000000 ) // 0 or "0.0." or "224-255" continue; // Redundant/Invalid //if ( Network.IsReserved( (IN_ADDR*)nFirst ) ) // Crash //if ( StartsWith( strFirst, _PT("0.0") ) || // StartsWith( strFirst, _PT("6.0") ) || // StartsWith( strFirst, _PT("7.0") ) || // StartsWith( strFirst, _PT("11.0") ) || // StartsWith( strFirst, _PT("55.0") ) || // StartsWith( strFirst, _PT("127.0") ) ) // continue; // Redundant for ( DWORD nRange = Settings.Security.ListRangeLimit ; nFirst <= nLast && nRange ; nFirst++, nRange-- ) { Security.SetAddressMap( htonl( nFirst ), nIndex ); // Reverse host-byte order } } if ( pRule ) pRule->m_sComment.Format( strCommentBase, nCount ); // Final update PostMainWndMessage( WM_SANITY_CHECK ); //TIMER_STOP } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } m_pQueue.RemoveHead(); // Done } Exit(); Wakeup(); Sleep( 5000 ); // Recheck if ( ! m_pQueue.GetCount() ) // && IsThreadEnabled() { CQuickLock oLock( Security.m_pSection ); Security.m_Cache.clear(); PostMainWndMessage( WM_SANITY_CHECK ); } }
void CMessageFilter::Load() { CFile pFile; CString strFilteredPhrases, strED2KSpamPhrases; const CString strFile = Settings.General.Path + _T("\\Data\\MessageFilter.dat"); // Delete current filter (if present) if ( m_pszFilteredPhrases ) delete [] m_pszFilteredPhrases; m_pszFilteredPhrases = NULL; // Load the message filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strED2KSpamPhrases ); pBuffer.ReadLine( strFilteredPhrases ); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // If file is still open close it pException->Delete(); } } // Insert some defaults if there was a read error if ( strED2KSpamPhrases.IsEmpty() ) strED2KSpamPhrases = _T("Your client is connecting too fast|Join the L33cher Team|PeerFactor|Your client is making too many connections|ZamBoR 2|AUTOMATED MESSAGE:|eMule FX the BEST eMule ever|DI-Emule"); if ( strFilteredPhrases.IsEmpty() ) strFilteredPhrases = _T(""); // Load the ED2K spam into the filter if ( strED2KSpamPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strED2KSpamPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strED2KSpamPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszED2KSpam = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszED2KSpam; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the blocked strings into the filter if ( strFilteredPhrases.GetLength() > 3 ) { LPCTSTR pszPtr = strFilteredPhrases; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == '|' ) { if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strFilteredPhrases.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszFilteredPhrases = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszFilteredPhrases; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }
void CAdultFilter::Load() { CFile pFile; CString strBlockedWords, strDubiousWords, strChildWords; const CString strFile = Settings.General.Path + _T("\\Data\\AdultFilter.dat"); // Settings.General.DataPath ? // Delete current adult filters (if present) if ( m_pszBlockedWords ) delete [] m_pszBlockedWords; m_pszBlockedWords = NULL; if ( m_pszDubiousWords ) delete [] m_pszDubiousWords; m_pszDubiousWords = NULL; if ( m_pszChildWords ) delete [] m_pszChildWords; m_pszChildWords = NULL; // Load the adult filter from disk if ( pFile.Open( strFile, CFile::modeRead ) ) { try { CBuffer pBuffer; const DWORD nLen = (DWORD)pFile.GetLength(); if ( ! pBuffer.EnsureBuffer( nLen ) ) AfxThrowUserException(); pBuffer.m_nLength = nLen; pFile.Read( pBuffer.m_pBuffer, pBuffer.m_nLength ); pFile.Close(); pBuffer.ReadLine( strBlockedWords ); // Line 1: words that are blocked if ( ! strBlockedWords.IsEmpty() && strBlockedWords.GetAt( 0 ) == '#' ) strBlockedWords.Empty(); pBuffer.ReadLine( strDubiousWords ); // Line 2: words that may be okay if ( ! strDubiousWords.IsEmpty() && strDubiousWords.GetAt( 0 ) == '#' ) strDubiousWords.Empty(); pBuffer.ReadLine( strChildWords ); // Line 3: words for child pornography if ( ! strChildWords.IsEmpty() && strChildWords.GetAt( 0 ) == '#' ) strChildWords.Empty(); } catch ( CException* pException ) { if ( pFile.m_hFile != CFile::hFileNull ) pFile.Close(); // File is still open so close it pException->Delete(); } } // Insert some defaults if the load failed if ( strBlockedWords.IsEmpty() ) strBlockedWords = L"xxx p**n f**k c**k c**t v****a pussy nude naked boobs breast hentai " L"lesbian w***e shit rape preteen hardcore lolita playboy penthouse " L"topless r-rated x-rated d***o pr0n erotic sexy o****m nipple fetish " L"upskirt beastiality bestiality pedofil necrofil t**s lolicon shemale fisting"; if ( strDubiousWords.IsEmpty() ) strDubiousWords = L"ass sex anal gay teen thong babe bikini viagra dick cum s***s"; if ( strChildWords.IsEmpty() ) strChildWords = L"child preteen"; // Load the blocked words into the Adult Filter if ( strBlockedWords.GetLength() > 3 ) { LPCTSTR pszPtr = strBlockedWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strBlockedWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszBlockedWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszBlockedWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load the possibly blocked words into the Adult Filter if ( strDubiousWords.GetLength() > 3 ) { LPCTSTR pszPtr = strDubiousWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strDubiousWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszDubiousWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszDubiousWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } // Load child pornography words into the Adult Filter if ( strChildWords.GetLength() > 3 ) { LPCTSTR pszPtr = strChildWords; int nWordLen = 3; CList< CString > pWords; int nStart = 0, nPos = 0; for ( ; *pszPtr ; nPos++, pszPtr++ ) { if ( *pszPtr == ' ' ) { if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } nStart = nPos + 1; } } if ( nStart < nPos ) { pWords.AddTail( strChildWords.Mid( nStart, nPos - nStart ) ); nWordLen += ( nPos - nStart ) + 1; } m_pszChildWords = new TCHAR[ nWordLen ]; LPTSTR pszFilter = m_pszChildWords; for ( POSITION pos = pWords.GetHeadPosition() ; pos ; ) { CString strWord( pWords.GetNext( pos ) ); ToLower( strWord ); CopyMemory( pszFilter, (LPCTSTR)strWord, sizeof( TCHAR ) * ( strWord.GetLength() + 1 ) ); pszFilter += strWord.GetLength() + 1; } *pszFilter++ = 0; *pszFilter++ = 0; } }