CCollectionFile::File* CCollectionFile::FindByURN(LPCTSTR pszURN) { Hashes::Sha1Hash oSHA1; Hashes::TigerHash oTiger; Hashes::Md5Hash oMD5; Hashes::Ed2kHash oED2K; Hashes::BtHash oBTH; oSHA1.fromUrn( pszURN ); oMD5.fromUrn( pszURN ); oTiger.fromUrn( pszURN ); oED2K.fromUrn( pszURN ); oBTH.fromUrn( pszURN ) || oBTH.fromUrn< Hashes::base16Encoding >( pszURN ); for ( POSITION pos = GetFileIterator(); pos; ) { File* pFile = GetNextFile( pos ); if ( validAndEqual( oSHA1, pFile->m_oSHA1 ) ) return pFile; if ( validAndEqual( oMD5, pFile->m_oMD5 ) ) return pFile; if ( validAndEqual( oTiger, pFile->m_oTiger ) ) return pFile; if ( validAndEqual( oED2K, pFile->m_oED2K ) ) return pFile; if ( validAndEqual( oBTH, pFile->m_oBTH ) ) return pFile; } return NULL; }
void CSearchInputBox::OnSearchPrefixTiger() { CString sSearch; m_wndSearch.GetWindowText( sSearch ); Hashes::TigerHash oTiger; if ( oTiger.fromUrn( sSearch ) || oTiger.fromString( sSearch ) ) sSearch = oTiger.toUrn(); else sSearch = _T("urn:tree:tiger/:[Tiger]"); m_wndSearch.SetWindowText( sSearch ); m_wndSearch.SetFocus(); m_wndSearch.SetSel( 16, -1 ); }
void CSearchInputBox::OnSearchPrefixSHA1Tiger() { CString sSearch; m_wndSearch.GetWindowText( sSearch ); Hashes::Sha1Hash oSHA1; Hashes::TigerHash oTiger; oSHA1.fromUrn( sSearch ) || oSHA1.fromString( sSearch ); oTiger.fromUrn( sSearch ) || oTiger.fromString( sSearch ); sSearch = _T("urn:bitprint:"); sSearch += oSHA1 ? oSHA1.toString() : _T("[SHA1]"); sSearch += _T("."); sSearch += oTiger ? oTiger.toString() : _T("[Tiger]"); m_wndSearch.SetWindowText( sSearch ); m_wndSearch.SetFocus(); m_wndSearch.SetSel( 13, -1 ); }
CLibraryFile* CLibraryMaps::LookupFileByURN(LPCTSTR pszURN, BOOL bSharedOnly, BOOL bAvailableOnly) const { ASSERT_VALID( this ); ASSERT( pszURN && *pszURN ); CLibraryFile* pFile = NULL; Hashes::TigerHash oTiger; Hashes::Sha1Hash oSHA1; Hashes::Ed2kHash oED2K; Hashes::BtHash oBTH; Hashes::Md5Hash oMD5; if ( oSHA1.fromUrn( pszURN ) ) { if ( ( pFile = LookupFileBySHA1( oSHA1, bSharedOnly, bAvailableOnly ) ) != NULL ) return pFile; } if ( oTiger.fromUrn( pszURN ) ) { if ( ( pFile = LookupFileByTiger( oTiger, bSharedOnly, bAvailableOnly ) ) != NULL ) return pFile; } if ( oED2K.fromUrn( pszURN ) ) { if ( ( pFile = LookupFileByED2K( oED2K, bSharedOnly, bAvailableOnly ) ) != NULL ) return pFile; } if ( oBTH.fromUrn( pszURN ) || oBTH.fromUrn< Hashes::base16Encoding >( pszURN ) ) { if ( ( pFile = LookupFileByBTH( oBTH, bSharedOnly, bAvailableOnly ) ) != NULL ) return pFile; } if ( oMD5.fromUrn( pszURN ) ) { if ( ( pFile = LookupFileByMD5( oMD5, bSharedOnly, bAvailableOnly ) ) != NULL ) return pFile; } return NULL; }
void CNewSearchDlg::OnChangeSearch() { CString strSearch; m_wndSearch.GetWindowText( strSearch ); BOOL bHash = FALSE; Hashes::TigerHash oTiger; Hashes::Sha1Hash oSHA1; Hashes::Ed2kHash oED2K; Hashes::Md5Hash oMD5; Hashes::BtHash oBTH; bHash |= static_cast< BOOL >( oSHA1.fromUrn( strSearch ) ); bHash |= static_cast< BOOL >( oTiger.fromUrn( strSearch ) ); bHash |= static_cast< BOOL >( oED2K.fromUrn( strSearch ) ); bHash |= static_cast< BOOL >( oMD5.fromUrn( strSearch ) ); bHash |= static_cast< BOOL >( oBTH.fromUrn( strSearch ) || oBTH.fromUrn< Hashes::base16Encoding >( strSearch ) ); if ( m_wndSchema.IsWindowVisible() == bHash ) m_wndSchema.ShowWindow( bHash ? SW_HIDE : SW_SHOW ); }
BOOL CUploadTransferDC::OnUpload(const std::string& strType, const std::string& strFilename, QWORD nOffset, QWORD nLength, const std::string& strOptions) { ASSERT( m_pClient ); if ( m_nState >= upsUploading ) { // Drop unsent data CLockedBuffer pOutput( m_pClient->GetOutput() ); pOutput->Clear(); m_nState = upsRequest; } ClearRequest(); m_sUserAgent = m_pClient->GetUserAgent(); m_pHost = m_pClient->m_pHost; m_sAddress = m_pClient->m_sAddress; UpdateCountry(); m_pClient->m_mInput.pLimit = &Settings.Bandwidth.Request; m_pClient->m_mOutput.pLimit = &m_nBandwidth; m_tRequest = GetTickCount(); BOOL bZip = ( strOptions.find("ZL1") != std::string::npos ); if ( strType == "tthl" ) { m_bGet = FALSE; if ( strFilename.substr( 0, 4 ) == "TTH/" ) { Hashes::TigerHash oTiger; if ( oTiger.fromString( CA2W( strFilename.substr( 4 ).c_str() ) ) ) { CSingleLock oLock( &Library.m_pSection ); if ( oLock.Lock( 1000 ) ) { if ( CLibraryFile* pFile = LibraryMaps.LookupFileByTiger( oTiger, TRUE, TRUE ) ) { if ( RequestTigerTree( pFile, nOffset, nLength ) ) return TRUE; } } } } } else if ( strType == "file" || strType =="get" ) { m_bGet = ( strType == "get" ); if ( strFilename == "files.xml" || strFilename == "files.xml.bz2" ) { if ( RequestFileList( TRUE, bZip, strFilename, nOffset, nLength ) ) return TRUE; } else if ( strFilename.substr( 0, 4 ) == "TTH/" ) { Hashes::TigerHash oTiger; if ( oTiger.fromString( CA2W( strFilename.substr( 4 ).c_str() ) ) ) { CSingleLock oLock( &Library.m_pSection ); if ( oLock.Lock( 1000 ) ) { if ( CLibraryFile* pFile = LibraryMaps.LookupFileByTiger( oTiger, TRUE, TRUE ) ) { if ( RequestFile( pFile, nOffset, nLength ) ) return TRUE; } } } } } else if ( strType == "list" ) { m_bGet = FALSE; if ( RequestFileList( FALSE, bZip, strFilename, nOffset, nLength ) ) return TRUE; } else if ( strType == "send" ) { if ( m_bGet ) { if ( m_pXML.GetCount() ) { // Send cached file list m_bGet = FALSE; StartSending( upsBrowse ); m_pClient->Write( &m_pXML ); m_pXML.Clear(); return TRUE; } else if ( SendFile() ) { // Send already requested file return TRUE; } } // else $Send without $Get } else { // Invalid request type theApp.Message( MSG_ERROR, _T("DC++ Invalid request type from %s"), (LPCTSTR)m_sAddress ); return FALSE; } theApp.Message( MSG_ERROR, IDS_UPLOAD_FILENOTFOUND, (LPCTSTR)m_sAddress, (LPCTSTR)CA2CT( strFilename.c_str() ) ); m_pClient->SendCommand( FILE_NOT_AVAILABLE ); return TRUE; }
BOOL CDownloadEditPage::OnApply() { if ( ! UpdateData() ) return FALSE; CString strMessage; Hashes::Sha1Hash oSHA1; Hashes::TigerHash oTiger; Hashes::Ed2kHash oED2K; Hashes::Md5Hash oMD5; Hashes::BtHash oBTH; oSHA1.fromString( m_sSHA1 ); oTiger.fromString( m_sTiger ); oED2K.fromString( m_sED2K ); oMD5.fromString( m_sMD5 ); oBTH.fromString( m_sBTH ); if ( ! m_sSHA1.IsEmpty() && ! oSHA1 ) { strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("SHA1") ); MsgBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_URN_SHA1 )->SetFocus(); return FALSE; } if ( ! m_sTiger.IsEmpty() && ! oTiger ) { strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("Tiger-Root") ); MsgBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_URN_TIGER )->SetFocus(); return FALSE; } if ( ! m_sED2K.IsEmpty() && ! oED2K ) { strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("ED2K") ); MsgBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_URN_ED2K )->SetFocus(); return FALSE; } if ( ! m_sMD5.IsEmpty() && ! oMD5 ) { strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("MD5") ); MsgBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_URN_MD5 )->SetFocus(); return FALSE; } if ( ! m_sBTH.IsEmpty() && ! oBTH ) { strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_BAD_HASH ), _T("BitTorrent") ); MsgBox( strMessage, MB_ICONEXCLAMATION ); GetDlgItem( IDC_URN_BTH )->SetFocus(); return FALSE; } CSingleLock pLock( &Transfers.m_pSection ); if ( ! pLock.Lock( 250 ) ) return FALSE; CDownloadSheet* pSheet = (CDownloadSheet*)GetParent(); CDownload* pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); // Invalid download bool bNeedUpdate = false; bool bCriticalChange = false; bNeedUpdate = pDownload->m_bSHA1Trusted ^ ( m_bSHA1Trusted == TRUE ); bNeedUpdate |= pDownload->m_bTigerTrusted ^ ( m_bTigerTrusted == TRUE ); bNeedUpdate |= pDownload->m_bED2KTrusted ^ ( m_bED2KTrusted == TRUE ); bNeedUpdate |= pDownload->m_bMD5Trusted ^ ( m_bMD5Trusted == TRUE ); bNeedUpdate |= pDownload->m_bBTHTrusted ^ ( m_bBTHTrusted == TRUE ); if ( pDownload->m_sName != m_sName ) { pLock.Unlock(); if ( MsgBox( IDS_DOWNLOAD_EDIT_CHANGE_NAME, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; // Was IDS_DOWNLOAD_EDIT_RENAME pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->Rename( m_sName ); bNeedUpdate = true; } QWORD nNewSize = 0; if ( _stscanf( m_sFileSize, _T("%I64u"), &nNewSize ) == 1 && nNewSize != pDownload->m_nSize ) { pLock.Unlock(); if ( MsgBox( IDS_DOWNLOAD_EDIT_CHANGE_SIZE, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_nSize = nNewSize; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } SYSTEMTIME tDate; m_wndDate.GetTime( &tDate ); if ( pDownload->m_tDate != tDate ) pDownload->m_tDate = tDate; if ( pDownload->m_oSHA1.isValid() != oSHA1.isValid() || validAndUnequal( pDownload->m_oSHA1, oSHA1 ) ) { pLock.Unlock(); strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("SHA1"), _T("SHA1") ); if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_oSHA1 = oSHA1; if ( oSHA1 ) pDownload->m_bSHA1Trusted = true; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } if ( pDownload->m_oTiger.isValid() != oTiger.isValid() || validAndUnequal( pDownload->m_oTiger, oTiger ) ) { pLock.Unlock(); strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("Tiger-Root"), _T("Tiger-Root") ); if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_oTiger = oTiger; if ( oTiger ) pDownload->m_bTigerTrusted = true; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } if ( pDownload->m_oED2K.isValid() != oED2K.isValid() || validAndUnequal( pDownload->m_oED2K, oED2K ) ) { pLock.Unlock(); strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("ED2K"), _T("ED2K") ); if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_oED2K = oED2K; if ( oED2K ) pDownload->m_bED2KTrusted = true; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } if ( pDownload->m_oMD5.isValid() != oMD5.isValid() || validAndUnequal( pDownload->m_oMD5, oMD5 ) ) { pLock.Unlock(); strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("MD5"), _T("MD5") ); if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_oMD5 = oMD5; if ( oMD5 ) pDownload->m_bMD5Trusted = true; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } if ( pDownload->m_oBTH.isValid() != oBTH.isValid() || validAndUnequal( pDownload->m_oBTH, oBTH ) ) { pLock.Unlock(); strMessage.Format( LoadString( IDS_DOWNLOAD_EDIT_CHANGE_HASH ), _T("BitTorrent"), _T("BitTorrent") ); if ( MsgBox( strMessage, MB_ICONQUESTION|MB_YESNO ) != IDYES ) return FALSE; pLock.Lock(); pDownload = pSheet->GetDownload(); if ( ! pDownload ) return CPropertyPageAdv::OnApply(); pDownload->m_oBTH = oBTH; if ( oBTH ) pDownload->m_bBTHTrusted = true; pDownload->CloseTransfers(); pDownload->ClearVerification(); bCriticalChange = true; } pDownload->m_bSHA1Trusted = m_bSHA1Trusted != FALSE; pDownload->m_bTigerTrusted = m_bTigerTrusted != FALSE; pDownload->m_bED2KTrusted = m_bED2KTrusted != FALSE; pDownload->m_bMD5Trusted = m_bMD5Trusted != FALSE; pDownload->m_bBTHTrusted = m_bBTHTrusted != FALSE; if ( bCriticalChange ) { pDownload->CloseTransfers(); pDownload->ClearSources(); pDownload->ClearFailedSources(); pDownload->ClearVerification(); bNeedUpdate = true; } if ( bNeedUpdate ) pDownload->SetModified(); return CPropertyPageAdv::OnApply(); }