Esempio n. 1
0
BOOL CAdultFilter::IsFiltered(LPCTSTR pszText) const
{
	if ( ! pszText )
		return FALSE;

	// Check blocked words
	if ( m_pszBlockedWords )
	{
		for ( LPCTSTR pszWord = m_pszBlockedWords ; *pszWord ; )
		{
			if ( _tcsistr( pszText, pszWord ) != NULL ) return TRUE;
			pszWord += _tcslen( pszWord ) + 1;
		}
	}

	// Check dubious words
	if ( m_pszDubiousWords )
	{
		size_t nDubiousWords = 0, nWordsPermitted = min( _tcslen( pszText ) / 8, 4u );

		for ( LPCTSTR pszWord = m_pszDubiousWords ; *pszWord ; )
		{
			if ( _tcsistr( pszText, pszWord ) != NULL ) nDubiousWords++;
			if ( nDubiousWords > nWordsPermitted ) return TRUE;
			pszWord += _tcslen( pszWord ) + 1;
		}
	}

	return FALSE;
}
Esempio n. 2
0
std::tstring UpdateChecker::XMLGetText(LPCTSTR xml, LPCTSTR tag)
{
	ASSERT(xml != NULL && tag != NULL);
	std::tstring properTag = _T("<");
	properTag += tag;
	const TCHAR* startPos = _tcsistr(xml, properTag.c_str());
	if (startPos != NULL)
		startPos = _tcschr(startPos, '>');
	if (startPos != NULL)
	{
		startPos++;
		properTag = _T("</");
		properTag += tag;
		const TCHAR* endPos = _tcsistr(startPos, properTag.c_str());
		if (endPos != NULL)
		{
			if (endPos - startPos > 0)
			{
				properTag.clear();
				properTag.append(startPos, endPos - startPos);
				return properTag;
			}
		}
	}
	return std::tstring();
}
Esempio n. 3
0
BOOL CSecureRule::Match(LPCTSTR pszContent) const
{
	if ( m_nType == srAddress || m_nType == srContentRegExp || m_nType == srExternal || ! pszContent || ! m_pContent )
		return FALSE;

	if ( m_nType == srContentHash )	// urn:
		return pszContent[3] == L':' && _tcsistr( pszContent, (LPCTSTR)m_pContent ) != NULL;

	if ( m_nType == srSizeType )	// size:
		return pszContent[4] == L':' && _tcsistr( pszContent, (LPCTSTR)m_pContent ) != NULL;

	for ( LPCTSTR pszFilter = m_pContent; *pszFilter; )
	{
		if ( _tcsistr( pszContent, pszFilter ) != NULL )
		{
			if ( m_nType == srContentAny )
				return TRUE;
		}
		else // Not found
		{
			if ( m_nType == srContentAll )
				return FALSE;
		}

		pszFilter += _tcslen( pszFilter ) + 1;
	}

	return m_nType == srContentAll;
}
BOOL CFileExecutor::Execute(LPCTSTR pszFile, BOOL bForce)
{
	CString strPath, strType;
	CWaitCursor pCursor;

	GetFileComponents( pszFile, strPath, strType );

	if ( strType.GetLength() > 0 && _tcsistr( _T("|co|collection|"), strType ) != NULL )
	{
		if ( CLibraryWnd* pWnd = GetLibraryWindow() )
		{
			pWnd->OnCollection( pszFile );
			return TRUE;
		}
	}

	if ( bForce == NULL && strType.GetLength() &&
		_tcsistr( Settings.Library.SafeExecute, strType ) == NULL )
	{
		CString strFormat, strPrompt;

		Skin.LoadString( strFormat, IDS_LIBRARY_CONFIRM_EXECUTE );
		strPrompt.Format( strFormat, pszFile );

		int nResult = AfxMessageBox( strPrompt,
			MB_ICONQUESTION|MB_YESNOCANCEL|MB_DEFBUTTON2 );

		if ( nResult == IDCANCEL ) return FALSE;
		else if ( nResult == IDNO ) return TRUE;
	}

	BOOL bShiftKey = ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) != 0;

	if ( Settings.MediaPlayer.EnablePlay && strType.GetLength() && ! bShiftKey )
	{
		if ( _tcsistr( Settings.MediaPlayer.FileTypes, strType ) != NULL )
		{
			BOOL bAudio = _tcsistr( _T("|ape|mid|mp3|ogg|wav|wma|"), strType ) != NULL;

			if ( CMediaWnd* pWnd = GetMediaWindow( ! bAudio ) )
			{
				pWnd->PlayFile( pszFile );
				return TRUE;
			}
		}
	}

	if ( ! bShiftKey )
		if ( Plugins.OnExecuteFile( pszFile ) ) return TRUE;

	ShellExecute( AfxGetMainWnd()->GetSafeHwnd(),
		NULL, pszFile, NULL, strPath, SW_SHOWNORMAL );

	return TRUE;
}
Esempio n. 5
0
// Takes a header and its value
// Reads and processes popular Gnutella headers
// Returns true to have ReadHeaders keep going
BOOL CConnection::OnHeaderLine(CString& strHeader, CString& strValue)
{
	theApp.Message( MSG_DEBUG | MSG_FACILITY_INCOMING, _T("%s >> %s: %s"), (LPCTSTR)m_sAddress, (LPCTSTR)strHeader, (LPCTSTR)strValue );

	// It's the user agent header
	if ( strHeader.CompareNoCase( _T("User-Agent") ) == 0 )
	{
		// Copy the value into the user agent member string
		m_sUserAgent = strValue;	// This tells what software the remote computer is running
		m_bClientExtended = VendorCache.IsExtended( m_sUserAgent );
	}
	// It's the remote IP header
	else if ( strHeader.CompareNoCase( _T("Remote-IP") ) == 0 )
	{
		// Add this address to our record of them
		Network.AcquireLocalAddress( strValue );
	}
	// It's the x my address, listen IP, or node header, like "X-My-Address: 10.254.0.16:6349"
	else if (  strHeader.CompareNoCase( _T("X-My-Address") ) == 0
			|| strHeader.CompareNoCase( _T("Listen-IP") ) == 0
			|| strHeader.CompareNoCase( _T("X-Node") ) == 0
			|| strHeader.CompareNoCase( _T("Node") ) == 0 )
	{
		// Find another colon in the value
		int nColon = strValue.Find( ':' );

		// If the remote computer first contacted us and the colon is there but not first
		if ( ! m_bInitiated && nColon > 0 )
		{
			// Read the number after the colon into nPort
			int nPort = protocolPorts[ PROTOCOL_G1 ];	// Start out nPort as the default value, 6346
			if ( _stscanf( strValue.Mid( nColon + 1 ), _T("%lu"), &nPort ) == 1 && nPort != 0 )		// Make sure 1 number was found, and isn't 0
			{
				// Save the found port number in m_pHost
				m_pHost.sin_port = htons( u_short( nPort ) );	// Convert Windows little endian to big for the Internet with htons
			}
		}
	}
	else if ( strHeader.CompareNoCase( _T("Accept") ) == 0 )
	{
		if ( _tcsistr( strValue, _T("application/x-gnutella-packets") ) &&
			m_nProtocol != PROTOCOL_G2 )
			m_nProtocol = PROTOCOL_G1;
		if ( _tcsistr( strValue, _T("application/x-gnutella2") ) ||
			 _tcsistr( strValue, _T("application/x-shareaza") ) ||
			 _tcsistr( strValue, _T("application/x-peerproject") ) )
			m_nProtocol = PROTOCOL_G2;
	}

	// Have ReadHeaders keep going
	return TRUE;
}
BOOL CFileExecutor::Enqueue(LPCTSTR pszFile, BOOL bForce)
{
	CString strPath, strType;
	CWaitCursor pCursor;

	GetFileComponents( pszFile, strPath, strType );

	if ( Plugins.OnEnqueueFile( pszFile ) ) return TRUE;

	if ( Settings.MediaPlayer.EnableEnqueue && strType.GetLength() &&
		 ( GetAsyncKeyState( VK_SHIFT ) & 0x8000 ) == 0 )
	{
		if ( _tcsistr( Settings.MediaPlayer.FileTypes, strType ) != NULL )
		{
			if ( CMediaWnd* pWnd = GetMediaWindow( FALSE ) )
			{
				pWnd->EnqueueFile( pszFile );
				return TRUE;
			}
		}
	}

	ShellExecute( AfxGetMainWnd()->GetSafeHwnd(),
		_T("Enqueue"), pszFile, NULL, strPath, SW_SHOWNORMAL );

	return TRUE;
}
Esempio n. 7
0
void CWebCtrl::EnterMenu(POINT* pPoint)
{
	if ( m_pThis != NULL )
	{
		SetWindowLongPtr( m_pThis->m_hWndThis, GWLP_WNDPROC, (LONG_PTR)m_pThis->m_pWndProc );
		m_pThis = NULL;
	}

	if ( pPoint == NULL || m_pMenu == NULL ) return;

	CPoint ptScreen( *pPoint );
	ptScreen.Offset( 2, 2 );

	CWnd* pChild = this;
	for ( ;; )
	{
		CPoint ptClient( ptScreen );
		pChild->ScreenToClient( &ptClient );
		CWnd* pNext = pChild->ChildWindowFromPoint( ptClient, CWP_ALL );
		if ( pNext == NULL || pNext == pChild ) break;
		pChild = pNext;
	}

	TCHAR szClass[128];
	GetClassName( *pChild, szClass, 128 );
	if ( _tcsistr( szClass, _T("Internet Explorer") ) == NULL ) return;

	m_pThis = this;
	m_hWndThis = pChild->GetSafeHwnd();
	m_pWndProc = (WNDPROC)(LONG_PTR)GetWindowLongPtr( m_hWndThis, GWLP_WNDPROC );
	SetWindowLongPtr( m_hWndThis, GWLP_WNDPROC, (LONG_PTR)&WebWndProc );
}
Esempio n. 8
0
// Checks the user agent to see if it's a leecher or banned client
BOOL CSecurity::IsClientBanned(const CString& sUserAgent)
{
	// No user agent- assume OK
	if ( sUserAgent.IsEmpty() )
		return FALSE;

	// Foxy (Private G2)
	if ( _tcsistr( sUserAgent, _T("Foxy") ) )					return TRUE;

	// i2hub leecher client. (Tested, does not upload)
	if ( _tcsistr( sUserAgent, _T("i2hub") ) )					return TRUE;

	// Check by content filter
	// ToDo: Implement user agent filter type
	return IsDenied( sUserAgent );
}
Esempio n. 9
0
BOOL CSecurity::IsVendorBlocked(const CString& sVendor) const
{
	// Foxy (Private G2)
	if ( _tcsistr( sVendor, _T("foxy") ) )						return TRUE;

	// Allow it
	return FALSE;
}
Esempio n. 10
0
BOOL DirImageInfoProvider::GetNextResult(Result& result)
{
	if (m_curResult == -1)
	{
		TCHAR path[MAX_PATH];
		if (GetFirstFileByArtistAlbum(path, m_Artist.c_str(), m_Album.c_str()))
		{
			BOOL bStrictSearch = HasMoreThanXFilesWithMinSizeY(path, m_StrictCriteriaMaxFilesNum, m_StrictCriteriaMaxFilesSize);
			WIN32_FIND_DATA dta;
			TCHAR wildCard[MAX_PATH];
			_sntprintf(wildCard, MAX_PATH, _T("%s*.jpg"), path);
			HANDLE hFileFinder = FindFirstFile(wildCard, &dta);
			if (hFileFinder != INVALID_HANDLE_VALUE)
			{
				do 
				{
					TCHAR bf[MAX_PATH];
					_sntprintf(bf, MAX_PATH, _T("%s%s"), path, dta.cFileName);
					if (IsLegalPicture(bf, m_Album.c_str(), bStrictSearch))
					{
						m_results.push_back(bf);
					}
				} 
				while (FindNextFile(hFileFinder, &dta));
				FindClose(hFileFinder);
				//===This code promotes the "front" image to be the first result
				if (m_results.size() > 1)
				{
					INT foundFront = -1;
					for (size_t i = 0; i < m_results.size(); i++)
					{
						if (_tcsistr(m_results[i].c_str(), _T("front")) != NULL)
						{
							foundFront = i;
							break;
						}
					}
					if (foundFront > 0)
					{
						std::tstring tmp = m_results[0];
						m_results[0] = m_results[foundFront];
						m_results[foundFront] = tmp;
					}
				}
				//===End
			}
		}
	}
	m_curResult++;
	if (m_curResult >= 0 && m_curResult < (INT)m_results.size())
	{
		result.service = m_request.service;
		result.main = m_results[m_curResult].c_str();
		result.additionalInfo = _T("(local)"); 
		return TRUE;
	}
	return FALSE;
}
Esempio n. 11
0
void CCorpChannelDx::OnRecdPacket(IRecdPacket* pPacket)
{
    if ( ! _tcscmp(pPacket->PakParam, "STOP") )
    {
        CChannel::OnRecdPacket( pPacket );
        return;
    }

    //CString xNewFile = Settings.Meeting.RecFile;
    CString xNewFile = "<DATE>\\<REMOTE>-<TIME>.PCM";

    if ( xNewFile.Find( "<DATE>" ) >= 0 )
    {
        SYSTEMTIME pTime;
        GetLocalTime( &pTime );

        CString strValue;
        strValue.Format( "%04i年%02i月%02i日",
                         pTime.wYear, pTime.wMonth, pTime.wDay );
        Replace( xNewFile, "<DATE>", strValue );
    }

    if ( xNewFile.Find( "<TIME>" ) >= 0 )
    {
        SYSTEMTIME pTime;
        GetLocalTime( &pTime );

        CString strValue;
        strValue.Format( "%02i时%02i分%02i秒%03i",
                         pTime.wHour, pTime.wMinute, pTime.wSecond, pTime.wMilliseconds );
        Replace( xNewFile, "<TIME>", strValue );
    }

    if ( xNewFile.Find( "<REMOTE>" ) >= 0 )
    {
        CString strValue;
        Replace( xNewFile, "<REMOTE>", RemoteId );
    }

    for ( LPCTSTR xPath = xNewFile, xPathExt = NULL;
            xPathExt = _tcsistr(xPath, "\\"); xPath = xPathExt + 1 )
    {
        CString strValue = xNewFile.Left(xPathExt - (LPCTSTR)xNewFile);
        CreateDirectory( "中国电信\\" + strValue, NULL );
    }

    SsmSetRecMixer( m_nChan, TRUE, 0 );
    if ( RecordFile(xNewFile, "中国电信") )
    {
        CHAR sError[1024];
        SsmGetLastErrMsg( sError );
        throw sError;
    }

    theApp.Message( MSG_TEMP,"Record[%i] -> %s", m_nChan, xNewFile );
}
Esempio n. 12
0
BOOL CMessageFilter::IsFiltered(LPCTSTR pszText)
{
	if ( ! Settings.Community.ChatFilter|| ! m_pszFilteredPhrases || ! pszText )
		return FALSE;

	// Check for filtered (spam) phrases
	for ( LPCTSTR pszWord = m_pszFilteredPhrases ; *pszWord ; )
	{
		if ( _tcsistr( pszText, pszWord ) != NULL ) return TRUE;
		pszWord += _tcslen( pszWord ) + 1;
	}

	return FALSE;
}
Esempio n. 13
0
BOOL CMessageFilter::IsED2KSpam( LPCTSTR pszText )
{
	if ( ! Settings.Community.ChatFilterED2K || ! m_pszED2KSpam || ! pszText )
		return FALSE;

	// Check for Ed2K spam phrases
	for ( LPCTSTR pszWord = m_pszED2KSpam ; *pszWord ; )
	{
		if ( _tcsistr( pszText, pszWord ) != NULL ) return TRUE;
		pszWord += _tcslen( pszWord ) + 1;
	}

	return FALSE;
}
Esempio n. 14
0
BOOL CAdultFilter::IsChildPornography(LPCTSTR pszText) const
{
	if ( ! pszText )
		return FALSE;

	for ( LPCTSTR pszWord = m_pszChildWords ; *pszWord ; )
	{
		if ( _tcsistr( pszText, pszWord ) != NULL )
			return ( IsFiltered( pszText ) );
		pszWord += _tcslen( pszWord ) + 1;
	}

	return FALSE;
}
Esempio n. 15
0
BOOL CSecurity::IsAgentBlocked(const CString& sUserAgent) const
{
	// The remote computer didn't send a "User-Agent", or it sent whitespace
	if ( sUserAgent.IsEmpty() ||
		CString( sUserAgent ).Trim().IsEmpty() )				return TRUE; // ?

	// Loop through the user-defined list of programs to block
	for ( string_set::const_iterator i = Settings.Uploads.BlockAgents.begin() ;
		i != Settings.Uploads.BlockAgents.end() ; i++ )
	{
		if ( _tcsistr( sUserAgent, *i ) )						return TRUE;
	}

	// Allow it
	return FALSE;
}
Esempio n. 16
0
///////////////////////////////////////////////////////////////////////////////
//
// _tcsistrrem()
//
// Purpose:     Remove substring in a string (case insensitive)
//
// Parameters:  str     - pointer to string; upon return, str will be updated 
//                        with the substring removals
//              substr  - substring to remove
//
// Returns:     TCHAR * - Pointer to the updated string. Because the 
//                        modification is done in place, the pointer  
//                        returned is the same as the pointer passed 
//                        as the input argument. 
//
TCHAR * _tcsistrrem(TCHAR * str, const TCHAR *substr)
{
	if (!str)
		return str;
	if (!substr)
		return str;

	TCHAR *target = NULL;
	size_t nSubstrLen = _tcslen(substr);
	TCHAR *cp = str;
	while ((target = _tcsistr(cp, substr)) != NULL)
	{
		_tcscpy(target, target + nSubstrLen);
		cp = target;
	}

	return str;
}
Esempio n. 17
0
CString CGraphRender::GetRecordFile(LPCTSTR pszPath, LPCTSTR fMask) const
{
	CString xNewFile = fMask ? fMask : _T("<USER>\\<DATE><TIME>.AVI");
	
	if ( xNewFile.Find( "<USER>" ) >= 0 )
	{
		Replace( xNewFile, "<USER>", GetNamed() );
	}
	
	if ( xNewFile.Find( "<DATE>" ) >= 0 )
	{
		SYSTEMTIME pTime;
		GetLocalTime( &pTime );
		
		CString strValue;
		strValue.Format( "%04i年%02i月%02i日",
			pTime.wYear, pTime.wMonth, pTime.wDay );
		Replace( xNewFile, "<DATE>", strValue );
	}
	
	if ( xNewFile.Find( "<TIME>" ) >= 0 )
	{
		SYSTEMTIME pTime;
		GetLocalTime( &pTime );
		
		CString strValue;
		strValue.Format( "%02i时%02i分%02i秒%03i",
			pTime.wHour, pTime.wMinute, pTime.wSecond, pTime.wMilliseconds );
		Replace( xNewFile, "<TIME>", strValue );
	}
	
	CString strPath = pszPath ? pszPath : _T(".");
	
	for ( LPCTSTR xPath = xNewFile, xPathExt = NULL;
		  xPathExt = _tcsistr(xPath, "\\"); xPath = xPathExt + 1 )
	{
		CString strValue = xNewFile.Left(xPathExt - (LPCTSTR)xNewFile);
		CreateDirectory( strPath + "\\" + strValue, NULL );
	}
	
	return strPath + "\\" + xNewFile;
}
Esempio n. 18
0
void CWizardInterfacePage::ClearSkins(LPCTSTR pszPath /*NULL*/)
{
	WIN32_FIND_DATA pFind;
	HANDLE hSearch;

	CString strPath;
	strPath.Format( L"%s\\Skins\\%s*.*",
		(LPCTSTR)Settings.General.Path, pszPath ? pszPath : L"" );

	hSearch = FindFirstFile( strPath, &pFind );

	if ( hSearch != INVALID_HANDLE_VALUE )
	{
		do
		{
			if ( pFind.cFileName[0] == L'.' ) continue;

			if ( pFind.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
			{
				if ( _tcsicmp( pFind.cFileName, L"Languages" ) == 0 ) continue;

				strPath.Format( L"%s%s\\",
					pszPath ? pszPath : L"", pFind.cFileName );

				ClearSkins( strPath );
			}
			else if ( _tcsistr( pFind.cFileName, L".xml" ) != NULL )
			{
				strPath.Format( L"%s%s",
					pszPath ? pszPath : L"", pFind.cFileName );

				if ( EndsWith( strPath, _P( L".xml" ) ) )
					theApp.WriteProfileInt( L"Skins", strPath, 0 );
			}
		}
		while ( FindNextFile( hSearch, &pFind ) );

		FindClose( hSearch );
	}
}
// Returns a string containing the most recent failed sources
CString	CDownloadWithSources::GetTopFailedSources(int nMaximum, PROTOCOLID nProtocol)
{
	// Currently we return only the string for G1, in X-NAlt format
	if ( nProtocol != PROTOCOL_G1 ) return CString();

	CString strSources, str;
	CFailedSource* pResult = NULL;
	CQuickLock pLock( Transfers.m_pSection );

	for ( POSITION pos = m_pFailedSources.GetHeadPosition() ; pos ; )
	{
		pResult = m_pFailedSources.GetNext( pos );
		// Only return sources which we detected as failed
		if ( pResult && pResult->m_bLocal )
		{
			if ( _tcsistr( pResult->m_sURL, _T("http://") ) != NULL )
			{
				int nPos = pResult->m_sURL.Find( ':', 8 );
				if ( nPos < 0 ) continue;
				str = pResult->m_sURL.Mid( 7, nPos - 7 );
				int nPosSlash = pResult->m_sURL.Find( '/', nPos );
				if ( nPosSlash < 0 ) continue;

				if ( ! strSources.IsEmpty() )
					strSources += ',';

				strSources += str;
				str = pResult->m_sURL.Mid( nPos + 1, nPosSlash - nPos - 1 );
				strSources += ':';
				strSources += str;

				if ( nMaximum == 1 )
					break;
				if ( nMaximum > 1 )
					nMaximum--;
			}
		}
	}
	return strSources;
}
Esempio n. 20
0
/*	@brief 開いたフォルダ リストへの登録

	@date 2001.12.26  CShareData::AddOPENFOLDERListから移動した。(YAZAKI)
*/
void CMRUFolder::Add( const TCHAR* pszFolder )
{
	if( NULL == pszFolder
	 || pszFolder[0] == _T('\0') )
	{	//	長さが0なら排除。
		return;
	}

	// すでに登録されている場合は、除外指定を無視する
	if( -1 == m_cRecentFolder.FindItemByText( pszFolder ) ){
		int nSize = m_pShareData->m_sHistory.m_aExceptMRU.size();
		for( int i = 0 ; i < nSize; i++ ){
			TCHAR szExceptMRU[_MAX_PATH];
			CFileNameManager::ExpandMetaToFolder( m_pShareData->m_sHistory.m_aExceptMRU[i], szExceptMRU, _countof(szExceptMRU) );
			if( NULL != _tcsistr( pszFolder, szExceptMRU ) ){
				return;
			}
		}
	}

	m_cRecentFolder.AppendItem( pszFolder );
}
Esempio n. 21
0
void CMediaVisDlg::Enumerate()
{
	CWaitCursor pCursor;
	HKEY hKey;

	if ( RegOpenKeyEx( HKEY_LOCAL_MACHINE,
		_T("Software\\Shareaza\\Shareaza\\Plugins\\AudioVis"),
		NULL, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;

	for ( DWORD nKey = 0 ; ; nKey++ )
	{
		DWORD dwType, dwName = sizeof(TCHAR) * 128, dwCLSID = 64 * sizeof(TCHAR);
		TCHAR szName[128], szCLSID[64];

		if ( RegEnumValue( hKey, nKey, szName, &dwName, NULL, &dwType, (LPBYTE)szCLSID, &dwCLSID )
			 != ERROR_SUCCESS ) break;

		if ( dwType != REG_SZ || dwCLSID / sizeof(TCHAR) != 39 || szCLSID[0] != '{' || szName[0] == '{' ) continue;
		szCLSID[ 38 ] = 0;

		CLSID pCLSID;
		if ( ! GUIDX::Decode( szCLSID, &pCLSID ) ) continue;
		if ( ! Plugins.LookupEnable( pCLSID, TRUE ) ) continue;

		if ( _tcsistr( szName, _T("wrap") ) )
		{
			if ( ! EnumerateWrapped( szName, pCLSID, szCLSID ) )
			{
				AddPlugin( szName, szCLSID, NULL );
			}
		}
		else
		{
			AddPlugin( szName, szCLSID, NULL );
		}
	}

	RegCloseKey( hKey );
}
Esempio n. 22
0
void CMediaVisDlg::Enumerate()
{
	CWaitCursor pCursor;
	HKEY hKey;

	if ( RegOpenKeyEx( HKEY_CURRENT_USER,
		REGISTRY_KEY _T("\\Plugins\\AudioVis"),
		NULL, KEY_READ, &hKey ) != ERROR_SUCCESS ) return;

	for ( DWORD nKey = 0 ; ; nKey++ )
	{
		DWORD dwType, dwName = 256, dwCLSID = 64 * sizeof(TCHAR);
		TCHAR szName[256], szCLSID[64];

		if ( RegEnumValue( hKey, nKey, szName, &dwName, NULL, &dwType, (LPBYTE)szCLSID, &dwCLSID )
			 != ERROR_SUCCESS ) break;

		if ( dwType != REG_SZ || dwCLSID / sizeof(TCHAR) != 39 || szCLSID[0] != '{' || szName[0] == '{' ) continue;
		szCLSID[ 38 ] = 0;

		CLSID pCLSID;
		if ( ! Hashes::fromGuid( szCLSID, &pCLSID ) ) continue;
		if ( ! Plugins.LookupEnable( pCLSID ) ) continue;

		if ( _tcsistr( szName, _T("wrap") ) )
		{
			if ( ! EnumerateWrapped( szName, pCLSID, szCLSID ) )
			{
				AddPlugin( szName, szCLSID, NULL );
			}
		}
		else
		{
			AddPlugin( szName, szCLSID, NULL );
		}
	}

	RegCloseKey( hKey );
}
Esempio n. 23
0
BOOL CLocalSearch::AddHitG2(CLibraryFile* pFile, int nIndex)
{
	CG2Packet* pPacket = (CG2Packet*)m_pPacket;
	CString strMetadata, strComment;
	BOOL bCollection = FALSE;
	BOOL bPreview = FALSE;
	DWORD nGroup = 0;

	// Pass 1: Calculate child group size

	if ( pFile->m_bTiger && pFile->m_bSHA1 )
	{
		nGroup += 5 + 3 + sizeof(SHA1) + sizeof(TIGEROOT);
	}
	else if ( pFile->m_bTiger )
	{
		nGroup += 5 + 4 + sizeof(TIGEROOT);
	}
	else if ( pFile->m_bSHA1 )
	{
		nGroup += 5 + 5 + sizeof(SHA1);
	}

	if ( pFile->m_bED2K )
	{
		nGroup += 5 + 5 + sizeof(MD4);
	}

	if ( m_pSearch == NULL || m_pSearch->m_bWantDN )
	{
		if ( pFile->GetSize() <= 0xFFFFFFFF )
		{
			nGroup += 8 + pPacket->GetStringLen( pFile->m_sName );
		}
		else
		{
			nGroup += 4 + 8;
			nGroup += 4 + pPacket->GetStringLen( pFile->m_sName );
		}

		if ( LPCTSTR pszType = _tcsrchr( pFile->m_sName, '.' ) )
		{
			if ( _tcsicmp( pszType, _T(".co") ) == 0 ||
				 _tcsicmp( pszType, _T(".collection") ) == 0 )
			{
				if ( ! pFile->m_bBogus )
				{
					nGroup += 2 + 7;
					bCollection = TRUE;
				}
			}
		}
	}

	if ( pFile->IsAvailable() && ( m_pSearch == NULL || m_pSearch->m_bWantURL ) )
	{
		nGroup += 5;
		if ( pFile->m_pSources.GetCount() ) nGroup += 7;

		if ( Settings.Uploads.SharePreviews )
		{
			if (	pFile->m_bCachedPreview ||
					_tcsistr( pFile->m_sName, _T(".jpg") ) ||
					_tcsistr( pFile->m_sName, _T(".png") ) )
			{
				bPreview = TRUE;
			}
		}

		if ( bPreview ) nGroup += 5;
	}

	if ( pFile->m_pMetadata != NULL && ( m_pSearch == NULL || m_pSearch->m_bWantXML ) )
	{
		strMetadata = pFile->m_pMetadata->ToString();
		int nMetadata = pPacket->GetStringLen( strMetadata );
		nGroup += 4 + nMetadata;
		if ( nMetadata > 0xFF )
		{
			nGroup ++;
			if ( nMetadata > 0xFFFF ) nGroup ++;
		}
	}

	if ( m_pSearch == NULL || m_pSearch->m_bWantCOM )
	{
		if ( pFile->m_nRating > 0 || pFile->m_sComments.GetLength() > 0 )
		{
			if ( pFile->m_nRating > 0 )
			{
				strComment.Format( _T("<comment rating=\"%i\">"), pFile->m_nRating - 1 );
				CXMLNode::ValueToString( pFile->m_sComments, strComment );
				if ( strComment.GetLength() > 2048 ) strComment = strComment.Left( 2048 );
				strComment += _T("</comment>");
			}
			else
			{
				strComment = _T("<comment>");
				CXMLNode::ValueToString( pFile->m_sComments, strComment );
				if ( strComment.GetLength() > 2048 ) strComment = strComment.Left( 2048 );
				strComment += _T("</comment>");
			}

			Replace( strComment, _T("\r\n"), _T("{n}") );
			int nComment = pPacket->GetStringLen( strComment );
			nGroup += 5 + nComment;
			if ( nComment > 0xFF )
			{
				nGroup ++;
				if ( nComment > 0xFFFF ) nGroup ++;
			}
		}

		if ( pFile->m_bBogus ) nGroup += 7;
	}
	else
	{
		if ( ! pFile->IsAvailable() ) return FALSE;
	}

	if ( m_pSearch == NULL ) nGroup += 8;

	nGroup += 4;

	// Pass 2: Write the child packet

	pPacket->WritePacket( "H", nGroup, TRUE );

	if ( pFile->m_bTiger && pFile->m_bSHA1 )
	{
		pPacket->WritePacket( "URN", 3 + sizeof(SHA1) + sizeof(TIGEROOT) );
		pPacket->WriteString( "bp" );
		pPacket->Write( &pFile->m_pSHA1, sizeof(SHA1) );
		pPacket->Write( &pFile->m_pTiger, sizeof(TIGEROOT) );
	}
	else if ( pFile->m_bTiger )
	{
		pPacket->WritePacket( "URN", 4 + sizeof(TIGEROOT) );
		pPacket->WriteString( "ttr" );
		pPacket->Write( &pFile->m_pTiger, sizeof(TIGEROOT) );
	}
	else if ( pFile->m_bSHA1 )
	{
		pPacket->WritePacket( "URN", 5 + sizeof(SHA1) );
		pPacket->WriteString( "sha1" );
		pPacket->Write( &pFile->m_pSHA1, sizeof(SHA1) );
	}

	if ( pFile->m_bED2K )
	{
		pPacket->WritePacket( "URN", 5 + sizeof(MD4) );
		pPacket->WriteString( "ed2k" );
		pPacket->Write( &pFile->m_pED2K, sizeof(MD4) );
	}

	if ( m_pSearch == NULL || m_pSearch->m_bWantDN )
	{
		if ( pFile->GetSize() <= 0xFFFFFFFF )
		{
			pPacket->WritePacket( "DN", pPacket->GetStringLen( pFile->m_sName ) + 4 );
			pPacket->WriteLongBE( (DWORD)pFile->GetSize() );
			pPacket->WriteString( pFile->m_sName, FALSE );
		}
		else
		{
			pPacket->WritePacket( "SZ", 8 );
			pPacket->WriteInt64( pFile->GetSize() );
			pPacket->WritePacket( "DN", pPacket->GetStringLen( pFile->m_sName ) );
			pPacket->WriteString( pFile->m_sName, FALSE );
		}

		if ( bCollection ) pPacket->WritePacket( "COLLECT", 0 );
	}

	{
		CSingleLock pQueueLock( &UploadQueues.m_pSection, TRUE );

		CUploadQueue* pQueue = UploadQueues.SelectQueue( PROTOCOL_HTTP, pFile );
		pPacket->WritePacket( "G", 1 );
		pPacket->WriteByte( pQueue ? pQueue->m_nIndex + 1 : 0 );
	}

	if ( pFile->IsAvailable() && ( m_pSearch == NULL || m_pSearch->m_bWantURL ) )
	{
		pPacket->WritePacket( "URL", 0 );

		if ( int nCount = pFile->m_pSources.GetCount() )
		{
			pPacket->WritePacket( "CSC", 2 );
			pPacket->WriteShortBE( (WORD)nCount );
		}

		if ( bPreview )
		{
			pPacket->WritePacket( "PVU", 0 );
		}
	}

	if ( strMetadata.GetLength() )
	{
		pPacket->WritePacket( "MD", pPacket->GetStringLen( strMetadata ) );
		pPacket->WriteString( strMetadata, FALSE );
	}

	if ( m_pSearch == NULL || m_pSearch->m_bWantCOM )
	{
		if ( strComment.GetLength() )
		{
			pPacket->WritePacket( "COM", pPacket->GetStringLen( strComment ) );
			pPacket->WriteString( strComment, FALSE );
		}

		if ( pFile->m_bBogus ) pPacket->WritePacket( "BOGUS", 0 );
	}

	if ( m_pSearch == NULL )
	{
		pPacket->WritePacket( "ID", 4 );
		pPacket->WriteLongBE( pFile->m_nIndex );
	}

	return TRUE;
}
Esempio n. 24
0
void CEmoticons::FormatText(CRichDocument* pDocument, LPCTSTR pszBody, BOOL bNewlines, COLORREF cr)
{
    static LPCTSTR pszURLs[] = { _T("\r"), _T("\n"), _T("http://"), _T("https://"), _T("ftp://"), _T("mailto:"), _T("aim:"), _T("www."), _T("magnet:?"), _T("ed2k://"), _T("dchub://"), _T("gnutella:"), _T("gnutella1:"), _T("gnutella2:"), _T("g2://"), _T("gnet:"), _T("peer:"), _T("peerproject:"), _T("shareaza:"), _T("raza:"), _T("gwc:"), _T("uhc:"), _T("ukhl:"), _T("mp2p:"), _T("sig2dat:"), NULL };
    BOOL bBold = FALSE, bItalic = FALSE, bUnderline = FALSE;
    CString str;

    while ( *pszBody )
    {
        LPCTSTR pszToken = _tcschr( pszBody, '[' );

        for ( int nURL = 0 ; pszURLs[ nURL ] != NULL ; nURL++ )
        {
            LPCTSTR pszFind = _tcsistr( pszBody, pszURLs[ nURL ] );
            if ( pszFind != NULL && ( pszToken == NULL || pszFind < pszToken ) ) pszToken = pszFind;
        }

        int nEmoticon = -1;
        LPCTSTR pszEmoticon = FindNext( pszBody, &nEmoticon );

        if ( pszEmoticon != NULL && ( pszToken == NULL || pszEmoticon < pszToken ) )
            pszToken = pszEmoticon;

        if ( pszToken != pszBody )
        {
            if ( pszToken != NULL )
            {
                TCHAR cSave = *pszToken;
                *(LPTSTR)pszToken = 0;
                str = pszBody;
                *(LPTSTR)pszToken = cSave;
            }
            else
            {
                str = pszBody;
            }

            pDocument->Add( retText, str, NULL,
                            ( bBold ? retfBold : 0 ) |
                            ( bItalic ? retfItalic : 0 ) |
                            ( bUnderline ? retfUnderline : 0 ) |
                            ( cr ? retfColor : 0 ) )->m_cColor = cr;
        }

        if ( pszToken == NULL ) break;

        pszBody = pszToken;
        if ( *pszBody == 0 ) break;

        if ( pszEmoticon == pszBody )
        {
            str.Format( _T("%i"), nEmoticon );
            pDocument->Add( retEmoticon, str );
            pszBody += _tcslen( GetText( nEmoticon ) );
            continue;
        }
        else if ( pszBody[0] == '\r' || pszBody[0] == '\n' )
        {
            if ( bNewlines )
                pDocument->Add( retNewline, _T("4") );

            pszBody ++;
            continue;
        }
        else if ( *pszBody != '[' )
        {
            for ( ; *pszToken ; pszToken++ )
            {
                if ( ! _istalnum( *pszToken ) &&
                        _tcschr( _T(":@/?=&%._-+;~#"), *pszToken ) == NULL )
                {
                    break;
                }
            }

            TCHAR cSave = *pszToken;
            *(LPTSTR)pszToken = 0;
            str = pszBody;
            *(LPTSTR)pszToken = cSave;

            if ( _tcsnicmp( str, _T("www."), 4 ) == 0 )
                str = _T("http://") + str;

            pDocument->Add( retLink, str, str,
                            ( bBold ? retfBold : 0 ) |
                            ( bItalic ? retfItalic : 0 ) |
                            ( bUnderline ? retfUnderline : 0 ) );

            pszBody = pszToken;
        }
        else if ( _tcsnicmp( pszBody, _T("[b]"), 3 ) == 0 )
        {
            bBold = TRUE;
        }
        else if ( _tcsnicmp( pszBody, _T("[/b]"), 4 ) == 0 )
        {
            bBold = FALSE;
        }
        else if ( _tcsnicmp( pszBody, _T("[i]"), 3 ) == 0 )
        {
            bItalic = TRUE;
        }
        else if ( _tcsnicmp( pszBody, _T("[/i]"), 4 ) == 0 )
        {
            bItalic = FALSE;
        }
        else if ( _tcsnicmp( pszBody, _T("[u]"), 3 ) == 0 )
        {
            bUnderline = TRUE;
        }
        else if ( _tcsnicmp( pszBody, _T("[/u]"), 4 ) == 0 )
        {
            bUnderline = FALSE;
        }
        else if ( _tcsnicmp( pszBody, _T("[/c]"), 4 ) == 0 )
        {
            cr = 0;
        }
        else if ( _tcsnicmp( pszBody, _T("[c:#"), 4 ) == 0 && _tcslen( pszBody ) >= 4 + 6 + 1 )
        {
            _tcsncpy_s( str.GetBuffer( 7 ), 7, pszBody + 4, 6 );
            str.ReleaseBuffer( 6 );
            int nRed = 0, nGreen = 0, nBlue = 0;
            _stscanf( str.Mid( 0, 2 ), _T("%x"), &nRed );
            _stscanf( str.Mid( 2, 2 ), _T("%x"), &nGreen );
            _stscanf( str.Mid( 4, 2 ), _T("%x"), &nBlue );
            cr = RGB( nRed, nGreen, nBlue );
        }

        if ( *pszBody == '[' )
        {
            pszToken = _tcschr( pszBody, ']' );
            if ( pszToken != NULL ) pszBody = pszToken + 1;
            else pszBody ++;
        }
    }
}
Esempio n. 25
0
BOOL CAlbumFolder::OrganiseFile(CLibraryFile* pFile)
{
	BOOL bResult = FALSE;

	if ( m_sSchemaURI == CSchema::uriAllFiles )
	{
		AddFile( pFile );
		return TRUE;
	}

	if ( m_bCollSHA1 && ( m_pCollection != NULL || GetCollection() ) )
	{
		if ( m_pCollSHA1 == pFile->m_pSHA1 ||
			 m_pCollection->FindFile( pFile, TRUE ) )
		{
			AddFile( pFile );
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}

	if ( pFile->m_pMetadata == NULL && m_pParent != NULL ) return FALSE;

	if ( m_sSchemaURI == CSchema::uriMusicRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriMusicAlbumCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strAlbum = pFile->m_pMetadata->GetAttributeValue( _T("album") );
		CXMLNode::UniformString( strAlbum );

		if ( strAlbum.IsEmpty() ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("tba") ) == 0 ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("na") ) == 0 ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("n/a") ) == 0 ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("none") ) == 0 ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("empty") ) == 0 ) return FALSE;
		if ( _tcsicmp( strAlbum, _T("unknown") ) == 0 ) return FALSE;
		if ( _tcsistr( strAlbum, _T("uploaded by") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("ripped by") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("downloaded") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("http") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("mp3") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("www.mp3sfinder.com") ) ) return FALSE;
		if ( _tcsistr( strAlbum, _T("single") ) ) strAlbum = _T("Singles");

		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pAlbum = GetNextFolder( pos );

			if ( pAlbum->m_sName.CompareNoCase( strAlbum ) == 0 )
			{
				bResult = pAlbum->OrganiseFile( pFile );
			}
			else if ( pAlbum->m_bAutoDelete )
			{
				pAlbum->RemoveFile( pFile );
			}
		}

		if ( bResult ) return TRUE;

		CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicAlbum, strAlbum, TRUE );

		return pAlbum->OrganiseFile( pFile );
	}
	else if ( m_sSchemaURI == CSchema::uriMusicAlbum )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strAlbum = pFile->m_pMetadata->GetAttributeValue( _T("album") );
		CXMLNode::UniformString( strAlbum );
		if ( _tcsistr( strAlbum, _T("single") ) ) strAlbum = _T("Singles");
		if ( strAlbum.CompareNoCase( m_sName ) ) return FALSE;

		AddFile( pFile );

		if ( _tcsistr( m_sName, _T("soundtrack") ) != NULL ||
			 _tcsistr( m_sName, _T("ost") ) != NULL )
		{
			// TODO: Scrap artist specific info !
			MetaFromFile( pFile );
		}
		else
		{
			MetaFromFile( pFile );
		}

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriMusicArtistCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strArtist = pFile->m_pMetadata->GetAttributeValue( _T("artist") );
		CXMLNode::UniformString( strArtist );

		Replace( strArtist, _T(" (www.mp3sfinder.com)"), _T("") );
		if ( strArtist.IsEmpty() ) return FALSE;

		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pAlbum = GetNextFolder( pos );

			if ( pAlbum->m_sName.CompareNoCase( strArtist ) == 0 )
			{
				bResult = pAlbum->OrganiseFile( pFile );
			}
			else if ( pAlbum->m_bAutoDelete )
			{
				pAlbum->RemoveFile( pFile );
			}
		}

		if ( bResult ) return TRUE;

		CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicArtist, strArtist, TRUE );

		return pAlbum->OrganiseFile( pFile );
	}
	else if ( m_sSchemaURI == CSchema::uriMusicArtist )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strArtist = pFile->m_pMetadata->GetAttributeValue( _T("artist") );
		CXMLNode::UniformString( strArtist );
		if ( strArtist.CompareNoCase( m_sName ) ) return FALSE;

		AddFile( pFile );
		MetaFromFile( pFile );

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriMusicGenreCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strGenre = pFile->m_pMetadata->GetAttributeValue( _T("genre") );
		if ( strGenre.IsEmpty() ) return FALSE;

		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pAlbum = GetNextFolder( pos );

			if ( pAlbum->m_sName.CompareNoCase( strGenre ) == 0 )
			{
				bResult = pAlbum->OrganiseFile( pFile );
			}
			else if ( pAlbum->m_bAutoDelete )
			{
				pAlbum->RemoveFile( pFile );
			}
		}

		if ( bResult ) return TRUE;

		CAlbumFolder* pAlbum = AddFolder( CSchema::uriMusicGenre, strGenre, TRUE );

		return pAlbum->OrganiseFile( pFile );
	}
	else if ( m_sSchemaURI == CSchema::uriMusicGenre )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;

		CString strGenre = pFile->m_pMetadata->GetAttributeValue( _T("genre") );
		if ( strGenre.CompareNoCase( m_sName ) ) return FALSE;

		AddFile( pFile );
		MetaFromFile( pFile );

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriMusicAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriAudio ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriVideoRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriVideoSeriesCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;

		CString strSeries = pFile->m_pMetadata->GetAttributeValue( _T("series") );
		CXMLNode::UniformString( strSeries );
		if ( strSeries.IsEmpty() ) return FALSE;

		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pAlbum = GetNextFolder( pos );

			if ( pAlbum->m_sName.CompareNoCase( strSeries ) == 0 )
			{
				bResult = pAlbum->OrganiseFile( pFile );
			}
			else if ( pAlbum->m_bAutoDelete )
			{
				pAlbum->RemoveFile( pFile );
			}
		}

		if ( bResult ) return TRUE;

		CAlbumFolder* pAlbum = AddFolder( CSchema::uriVideoSeries, strSeries, TRUE );

		return pAlbum->OrganiseFile( pFile );
	}
	else if ( m_sSchemaURI == CSchema::uriVideoSeries )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;

		CString strSeries = pFile->m_pMetadata->GetAttributeValue( _T("series") );
		CXMLNode::UniformString( strSeries );
		if ( strSeries.CompareNoCase( m_sName ) ) return FALSE;

		AddFile( pFile );
		MetaFromFile( pFile );

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriVideoFilmCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;

		CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
		if ( strType.CompareNoCase( _T("film") ) ) return FALSE;

		CString strTitle = pFile->m_pMetadata->GetAttributeValue( _T("title") );
		CXMLNode::UniformString( strTitle );
		if ( strTitle.IsEmpty() ) return FALSE;

		for ( POSITION pos = GetFolderIterator() ; pos ; )
		{
			CAlbumFolder* pAlbum = GetNextFolder( pos );

			if ( pAlbum->m_sName.CompareNoCase( strTitle ) == 0 )
			{
				bResult = pAlbum->OrganiseFile( pFile );
			}
			else if ( pAlbum->m_bAutoDelete )
			{
				pAlbum->RemoveFile( pFile );
			}
		}

		if ( bResult ) return TRUE;

		CAlbumFolder* pAlbum = AddFolder( CSchema::uriVideoFilm, strTitle, TRUE );

		return pAlbum->OrganiseFile( pFile );
	}
	else if ( m_sSchemaURI == CSchema::uriVideoFilm )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;

		CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
		if ( strType.CompareNoCase( _T("film") ) ) return FALSE;

		CString strTitle = pFile->m_pMetadata->GetAttributeValue( _T("title") );
		CXMLNode::UniformString( strTitle );
		if ( strTitle.CompareNoCase( m_sName ) ) return FALSE;

		AddFile( pFile );
		MetaFromFile( pFile );

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriVideoMusicCollection )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;

		CString strType = pFile->m_pMetadata->GetAttributeValue( _T("type") );
		if ( strType.CompareNoCase( _T("music video") ) ) return FALSE;

		AddFile( pFile );

		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriVideoAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriVideo ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriImageRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriImage ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriImageAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriImage ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriApplicationRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriApplication ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriApplicationAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriApplication ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriBookRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriBook ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriBookAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriBook ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}
	else if ( m_sSchemaURI == CSchema::uriDocumentRoot )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriDocument ) &&
			 ! pFile->IsSchemaURI( CSchema::uriSpreadsheet ) &&
			 ! pFile->IsSchemaURI( CSchema::uriPresentation ) ) return FALSE;
	}
	else if ( m_sSchemaURI == CSchema::uriDocumentAll )
	{
		if ( ! pFile->IsSchemaURI( CSchema::uriDocument ) &&
			 ! pFile->IsSchemaURI( CSchema::uriSpreadsheet ) &&
			 ! pFile->IsSchemaURI( CSchema::uriPresentation ) ) return FALSE;
		AddFile( pFile );
		return TRUE;
	}

	for ( POSITION pos = GetFolderIterator() ; pos ; )
	{
		bResult |= GetNextFolder( pos )->OrganiseFile( pFile );
	}

	return bResult;
}
Esempio n. 26
0
BOOL CShareMonkeyData::BuildRequest()
{
	int nCategory = 0;

	m_sURL = Settings.WebServices.ShareMonkeyBaseURL;
	m_pSchema = NULL;

	if ( m_nRequestType == stProductMatch )
	{
		CString str;
		str.Format( L"&offset=%i", m_nOffset );
		m_sURL += L"productMatch?v=latest&stores_amount=0&result_amount=1" + str;
	}
	else if ( m_nRequestType == stStoreMatch )
	{
		// storeMatch/<session_id>/<contributor_id>/<file_id>/<product_id>/COUNTRY
		CString str;
		str.Format( L"storeMatch/%s/%s/0/%s/%s",
					(LPCTSTR)m_sSessionID, (LPCTSTR)Settings.WebServices.ShareMonkeyCid,
					(LPCTSTR)m_sProductID, (LPCTSTR)m_sCountry );
		m_sURL += str;
	}
	else if ( m_nRequestType == stComparison )
	{
		m_sURL += L"productMatch?v=latest&stores_amount=0&result_amount=0";
	}

	if ( m_nRequestType == stProductMatch || m_nRequestType == stComparison )
	{
		if ( Network.m_pHost.sin_addr.s_addr != INADDR_NONE )
		{
			m_sURL += L"&user_ip_address=";
			m_sURL += inet_ntoa( Network.m_pHost.sin_addr );
		}
		else
		{
			m_sURL += L"&user_ip_address=" + m_sCountry;
		}

		{
			CQuickLock oLock( Library.m_pSection );

			CLibraryFile* pFile = Library.LookupFile( m_nFileIndex );
			if ( pFile == NULL ) return FALSE;

			m_sURL += L"&n=" + pFile->m_sName;
			m_sURL += L"&sha1=" + pFile->m_oSHA1.toString();
			m_sURL += L"&ed2k=" + pFile->m_oED2K.toString();
			m_sURL += L"&tth=" + pFile->m_oTiger.toString();
			if ( pFile->m_nSize != 0 )
			{
				CString strSize;
				strSize.Format( L"&s=%I64u", pFile->m_nSize );
				m_sURL += strSize;
			}

			bool bTorrent = false;
			bool bAppOrGame = false;

			if ( pFile->m_pSchema )
			{
				m_pSchema = SchemaCache.Get( (LPCTSTR)pFile->m_pSchema->GetURI() );
				if ( pFile->m_pSchema->CheckURI( CSchema::uriAudio ) )
				{
					nCategory = 1;
					if ( pFile->m_pMetadata )
					{
						CXMLAttribute* pAttribute = pFile->m_pMetadata->GetAttribute( L"title" );
						if ( pAttribute )
							m_sURL += L"&audiotitle=" + pAttribute->GetValue();
						pAttribute = pFile->m_pMetadata->GetAttribute( L"artist" );
						if ( pAttribute )
							m_sURL += L"&audioartist=" + pAttribute->GetValue();
						pAttribute = pFile->m_pMetadata->GetAttribute( L"album" );
						if ( pAttribute )
							m_sURL += L"&audioalbum=" + pAttribute->GetValue();
						pAttribute = pFile->m_pMetadata->GetAttribute( L"track" );
						if ( pAttribute )
							m_sURL += L"&tn=" + pAttribute->GetValue();
					}
				}
				else if ( pFile->m_pSchema->CheckURI( CSchema::uriDocument ) ||
						pFile->m_pSchema->CheckURI( CSchema::uriBook ) )
					nCategory = 2;
				else if ( pFile->m_pSchema->CheckURI( CSchema::uriApplication ) )
					nCategory = 4;
				else if ( pFile->m_pSchema->CheckURI( CSchema::uriBitTorrent ) )
					bTorrent = true;
				else if ( pFile->m_pSchema->CheckURI( CSchema::uriROM ) ||
						pFile->m_pSchema->CheckURI( CSchema::uriArchive ) )
					bAppOrGame = true;

				if ( bAppOrGame && pFile->m_pMetadata )
				{
					CString strWords = pFile->m_pSchema->GetIndexedWords( pFile->m_pMetadata->GetFirstElement() );
					if ( _tcsistr( strWords, L"game" ) != NULL )
						nCategory = 3;
					else if ( _tcsistr( strWords, L"software" ) != NULL ||
							_tcsistr( strWords, L"application" ) != NULL )
						nCategory = 4;
				}
				else if ( bTorrent && pFile->m_pMetadata && pFile->m_bMetadataAuto )
				{
					CXMLAttribute* pInfoHash = pFile->m_pMetadata->GetAttribute( L"hash" );
					if ( pInfoHash )
						m_sURL += L"&info_hash=" + pInfoHash->GetValue();
				}

				if ( nCategory != 0 )
				{
					CString strCategory;
					strCategory.Format( L"&category_id=%i", nCategory );
					m_sURL += strCategory;
				}
			}

			m_sURL += L"&cid=";
			m_sURL += Settings.WebServices.ShareMonkeyCid;
		}
	}

	return TRUE;
}
Esempio n. 27
0
///////////////////////////////////////////////////////////////////////////////
//
// _tcsistrrep()
//
// Purpose:     Replace one substring in a string with another 
//              substring (case insensitive)
//
// Parameters:  lpszStr    - Pointer to string; upon return, lpszStr will be 
//                           updated with the character removals
//              lpszOld    - Pointer to substring that is to be replaced
//              lpszNew    - Pointer to substring that will replace lpszOld
//              lpszResult - Pointer to buffer that receives result string.  
//                           This may be NULL, in which case the required size
//                           of the result buffer will be returned. (Call
//                           _tcsistrrep once to get size, then allocate 
//                           buffer, and call _tcsistrrep again.)
//
// Returns:     int        - Size of result string.  If lpszResult is NULL,
//                           the size of the buffer (in TCHARs) required to 
//                           hold the result string is returned.  Does not 
//                           include terminating nul character.  Returns 0
//                           if no replacements.
//
int _tcsistrrep(const TCHAR * lpszStr, 
				const TCHAR * lpszOld, 
				const TCHAR * lpszNew, 
				TCHAR * lpszResult)
{
	if (!lpszStr || !lpszOld || !lpszNew)
		return 0;

	size_t nStrLen = _tcslen(lpszStr);
	if (nStrLen == 0)
		return 0;

	size_t nOldLen = _tcslen(lpszOld);
	if (nOldLen == 0)
		return 0;

	size_t nNewLen = _tcslen(lpszNew);

	// loop once to figure out the size of the result string
	int nCount = 0;
	TCHAR *pszStart = (TCHAR *) lpszStr;
	TCHAR *pszEnd = (TCHAR *) lpszStr + nStrLen;
	TCHAR *pszTarget = NULL;
	TCHAR * pszResultStr = NULL;

	while (pszStart < pszEnd)
	{
		while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL)
		{
			nCount++;
			pszStart = pszTarget + nOldLen;
		}
		pszStart += _tcslen(pszStart);
	}

	// if any changes, make them now
	if (nCount > 0)
	{
		// allocate buffer for result string
		size_t nResultStrSize = nStrLen + (nNewLen - nOldLen) * nCount + 2;
		pszResultStr = new TCHAR [nResultStrSize];
		ZeroMemory(pszResultStr, nResultStrSize*sizeof(TCHAR));

		pszStart = (TCHAR *) lpszStr;
		pszEnd = (TCHAR *) lpszStr + nStrLen;
		TCHAR *cp = pszResultStr;

		// loop again to actually do the work
		while (pszStart < pszEnd)
		{
			while ((pszTarget = _tcsistr(pszStart, lpszOld)) != NULL)
			{
				int nCopyLen = (int)(pszTarget - pszStart);
				_tcsncpy(cp, &lpszStr[pszStart-lpszStr], nCopyLen);

				cp += nCopyLen;

				pszStart = pszTarget + nOldLen;

				_tcscpy(cp, lpszNew);

				cp += nNewLen;
			}
			_tcscpy(cp, pszStart);
			pszStart += _tcslen(pszStart);
		}

		//TRACE("pszResultStr=<%s>\n", pszResultStr);

		_ASSERTE(pszResultStr[nResultStrSize-2] == _T('\0'));

		if (lpszResult && pszResultStr)
			_tcscpy(lpszResult, pszResultStr);
	}

	int nSize = 0;
	if (pszResultStr)
	{
		nSize = (int)_tcslen(pszResultStr);
		delete [] pszResultStr;
	}

	//TRACE("_tcsistrrep returning %d\n", nSize);

	return nSize;
}
int CDownloadWithSources::AddSourceURLs(LPCTSTR pszURLs, BOOL bURN)
{
	CString strURLs( pszURLs );
	BOOL bQuote = FALSE;
	
	for ( int nScan = 0 ; nScan < strURLs.GetLength() ; nScan++ )
	{
		if ( strURLs[ nScan ] == '\"' )
		{
			bQuote = ! bQuote;
			strURLs.SetAt( nScan, ' ' );
		}
		else if ( strURLs[ nScan ] == ',' && bQuote )
		{
			strURLs.SetAt( nScan, '`' );
		}
	}
	
	strURLs += ',';
	
    int nCount = 0;
	for ( ; ; )
	{
		int nPos = strURLs.Find( ',' );
		if ( nPos < 0 ) break;
		
		CString strURL	= strURLs.Left( nPos );
		strURLs			= strURLs.Mid( nPos + 1 );
		strURL.TrimLeft();
		
		FILETIME tSeen = { 0, 0 };
		BOOL bSeen = FALSE;
		
		if ( _tcsistr( strURL, _T("://") ) != NULL )
		{
			nPos = strURL.ReverseFind( ' ' );
			
			if ( nPos > 0 )
			{
				CString strTime = strURL.Mid( nPos + 1 );
				strURL = strURL.Left( nPos );
				strURL.TrimRight();
				bSeen = TimeFromString( strTime, &tSeen );
			}
			
			for ( int nScan = 0 ; nScan < strURL.GetLength() ; nScan++ )
			{
				if ( strURL[ nScan ] == '`' ) strURL.SetAt( nScan, ',' );
			}
		}
		else
		{
			nPos = strURL.Find( ':' );
			if ( nPos < 1 ) continue;
			
			int nPort = 0;
			_stscanf( strURL.Mid( nPos + 1 ), _T("%i"), &nPort );
			strURL.Truncate( nPos );
			USES_CONVERSION;
			DWORD nAddress = inet_addr( T2CA( strURL ) );
			strURL.Empty();
			
			if ( ! Network.IsFirewalledAddress( &nAddress, TRUE ) && nPort != 0 && nAddress != INADDR_NONE )
			{
				if ( m_bSHA1 )
				{
					strURL.Format( _T("http://%s:%i/uri-res/N2R?%s"),
						(LPCTSTR)CString( inet_ntoa( *(IN_ADDR*)&nAddress ) ),
						nPort, (LPCTSTR)CSHA::HashToString( &m_pSHA1, TRUE ) );
				}
			}
		}
		
		if ( AddSourceURL( strURL, bURN, bSeen ? &tSeen : NULL ) ) nCount++;
	}
	
	return nCount;
}
///////////////////////////////////////////////////////////////////////////////
// Draw
int CXHtmlDraw::Draw(HDC hDC, 
					 LPCTSTR lpszText, 
					 XHTMLDRAWSTRUCT * pXHDS, 
					 BOOL bUnderlineUrl)
{
	TRACE(_T("in CXHtmlDraw::Draw:  <%s>  bUnderlineUrl=%d\n"), lpszText, bUnderlineUrl);

	static BOOL bInDraw = FALSE;

	if (bInDraw)
		return 0;
	bInDraw = TRUE;

	// check parameters ----------------------------------------------

	_ASSERTE(hDC);
	_ASSERTE(lpszText);
	_ASSERTE(pXHDS);
	if (!hDC || !lpszText || (lpszText[0] == _T('\0')) || !pXHDS)
	{
		bInDraw = FALSE;
		return 0;
	}

	HWND hWnd = ::WindowFromDC(hDC);

	if (!::IsWindow(hWnd))
	{
		TRACE(_T("warn: not a window\n"));
		bInDraw = FALSE;
		return 0;
	}

	// check if window is hidden ------------------------------------

	if (!::IsWindowVisible(hWnd))
	{
		TRACE(_T("warn: window invisible\n"));
		bInDraw = FALSE;
		return 0;
	}

	RECT rectClip;
	int nResult = ::GetClipBox(hDC, &rectClip);

	if (nResult == NULLREGION)
	{
		//	window is covered
		TRACE(_T("warn: window is covered\n"));
		bInDraw = FALSE;
		return 0;
	}

	// initialize for drawing ---------------------------------------

	// rectText is used to draw into the dc
	RECT rectText = pXHDS->rect;
	if ((rectText.left >=  rectText.right) || 
		(rectText.top >= rectText.bottom))
	{
		TRACE(_T("warn: bad rect\n"));
		bInDraw = FALSE;
		return 0;
	}

	// rectDraw is the rect for the entire drawing area
	RECT rectDraw = pXHDS->rect;
	int nRectWidth  = rectDraw.right - rectDraw.left;
	int nRectHeight = rectDraw.bottom - rectDraw.top;
	int nXOffset = rectDraw.left;

	// set up for double buffering
	HDC hMemDC = CreateCompatibleDC(hDC);
	HBITMAP hBitmap = CreateCompatibleBitmap(hDC, nRectWidth, nRectHeight);
	HBITMAP hOldBitmap = (HBITMAP) SelectObject(hMemDC, hBitmap);

	if (pXHDS->bTransparent && !pXHDS->hDC)
	{
		// save a bitmap of the original drawing area, in case
		// there are links, and we need to erase the underline
		pXHDS->hDC = CreateCompatibleDC(hDC);
		pXHDS->hBitmap = CreateCompatibleBitmap(hDC, nRectWidth, nRectHeight);
		pXHDS->hOldBitmap = (HBITMAP) SelectObject(pXHDS->hDC, pXHDS->hBitmap);
		BitBlt(pXHDS->hDC, 0, 0, nRectWidth, nRectHeight,
			hDC, rectDraw.left, rectDraw.top, SRCCOPY);
		BitBlt(hMemDC, 0, 0, nRectWidth, nRectHeight,
			hDC, rectDraw.left, rectDraw.top, SRCCOPY);
	}
	else if (pXHDS->bTransparent && pXHDS->hDC)
	{
		// restore the original drawing area from saved HDC
		BitBlt(hMemDC, 0, 0, nRectWidth, nRectHeight,
			pXHDS->hDC, 0, 0, SRCCOPY);
	}

	pXHDS->rectAnchor = rectText;	// save rect in case of anchor

	// remap rectText to memory dc - left and top start at 0
	rectText.left = 0;
	rectText.top = 0;
	rectText.right = nRectWidth;
	rectText.bottom = nRectHeight;

	// create initial font ------------------------------------------

	LOGFONT lf = { 0 };
	LOGFONT prev_lf = { 0 };

	if (pXHDS->bLogFont)
	{
		TRACE(_T("using logfont\n"));
		memcpy(&lf, &pXHDS->lf, sizeof(LOGFONT));
	}
	else
	{
		HFONT hfont = (HFONT)::GetCurrentObject(hDC, OBJ_FONT);	//+++1.1
		if (hfont)
			GetObject(hfont, sizeof(LOGFONT), &lf);
		else
			GetObject(GetStockObject(SYSTEM_FONT), sizeof(LOGFONT), &lf);
	}
	memcpy(&prev_lf, &lf, sizeof(LOGFONT));

	// variable initialization --------------------------------------

	TCHAR *pszText = new TCHAR [m_nMaxText+1];
	memset(pszText, 0, (m_nMaxText+1)*sizeof(TCHAR));
	_tcsncpy(pszText, lpszText, m_nMaxText);
	TCHAR *pTextBuffer = pszText;	// save buffer address for delete

	TCHAR *pszText1 = new TCHAR [m_nMaxText+1];
	memset(pszText1, 0, (m_nMaxText+1)*sizeof(TCHAR));

	if (pXHDS->pszAnchor)
		delete [] pXHDS->pszAnchor;
	pXHDS->pszAnchor = NULL;

	pXHDS->bHasAnchor = FALSE;
	pXHDS->bAnchorIsUnderlined = FALSE;
	BOOL bInAnchor = FALSE;

	int n = (int) _tcslen(pszText);		// n must be int

	int i = 0;
	int nWidth = 0;

	pXHDS->bHasAnchor = FALSE;
	pXHDS->nRightX = 0;
	
	COLORREF crText = pXHDS->crText;
	if (crText == COLOR_NONE)
		crText = GetSysColor(COLOR_WINDOWTEXT);

	COLORREF crBackground = pXHDS->crBackground;
	if (crBackground == COLOR_NONE)
		crBackground = GetSysColor(COLOR_WINDOW);

	COLORREF crTextNew = crText;
	COLORREF crBkgndNew = crBackground;

	// if no transparency, fill entire rect with default bg color
	if (!pXHDS->bTransparent)
	{
		HBRUSH hbrush = CreateSolidBrush(crBkgndNew); 
		_ASSERTE(hbrush);
		FillRect(hMemDC, &rectText, hbrush);
		if (hbrush)
			DeleteObject(hbrush);
	}

	BOOL bBold = pXHDS->bBold;
	BOOL bItalic = pXHDS->bItalic;
	BOOL bUnderline = pXHDS->bUnderline;
	BOOL bStrikeThrough = pXHDS->bStrikeThrough;
	BOOL bSubscript = FALSE;
	BOOL bSuperscript = FALSE;
	int nSizeChange = 0;

	// replace character entity names in text with codes ------------

	TCHAR ent[3] = { _T('\0') };
	ent[0] = _T('\001');	// each entity name is replaced with a two-character
							// code that begins with \001

	BOOL bCharacterEntities = FALSE;	// assume no char entities

	// we are replacing character entites with a two-character sequence,
	// so the resulting string will be shorter
	size_t buflen = _tcslen(pszText) + 100;
	TCHAR *buf = new TCHAR [buflen];
	memset(buf, 0, buflen*sizeof(TCHAR));

	for (i = 0; m_aCharEntities[i].pszName != NULL; i++)
	{
		ent[1] = m_aCharEntities[i].cCode;
		int nRep = _tcsistrrep(pszText, m_aCharEntities[i].pszName, ent, buf);
		if (nRep > 0)
		{
			bCharacterEntities = TRUE;
			_tcscpy(pszText, buf);
		}
	}

	delete [] buf;
	buf = NULL;

	TEXTMETRIC tm = { 0 };

	n = (int) _tcslen(pszText);	// get length again after char entity substitution
	int textLen = n;

	while ((n > 0) && pszText && (pszText < (pTextBuffer + textLen)))
	{
		TRACE(_T("start while:  n=%d  pszText=<%s>\n"), n, pszText);

		///////////////////////////////////////////////////////////////////////
		if (_tcsnicmp(pszText, _T("<B>"), 3) == 0)	// check for <b> or <B>
		{
			n -= 3;
			pszText += 3;
			bBold++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</B>"), 4) == 0)	// check for </B>
		{
			n -= 4;
			pszText += 4;
			if (bBold)
				bBold--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<I>"), 3) == 0)	// check for <I>
		{
			n -= 3;
			pszText += 3;
			bItalic++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</I>"), 4) == 0)	// check for </I>
		{
			n -= 4;
			pszText += 4;
			if (bItalic)
				bItalic--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<U>"), 3) == 0)		// check for <U>
		{
			n -= 3;
			pszText += 3;
			bUnderline++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</U>"), 4) == 0)	// check for </U>
		{
			n -= 4;
			pszText += 4;
			if (bUnderline)
				bUnderline--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<S>"), 3) == 0)		// check for <S>
		{
			n -= 3;
			pszText += 3;
			bStrikeThrough++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</S>"), 4) == 0)	// check for </S>
		{
			n -= 4;
			pszText += 4;
			if (bStrikeThrough)
				bStrikeThrough--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<BIG>"), 5) == 0)	// check for <BIG>
		{
			n -= 5;
			pszText += 5;
			if (lf.lfHeight > 0)
				lf.lfHeight += 2;
			else
				lf.lfHeight -= 2;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</BIG>"), 6) == 0)	// check for </BIG>
		{
			n -= 6;
			pszText += 6;
			if (lf.lfHeight > 0)
				lf.lfHeight -= 2;
			else
				lf.lfHeight += 2;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<SMALL>"), 7) == 0)	// check for <SMALL>
		{
			n -= 7;
			pszText += 7;
			if (lf.lfHeight > 0)
				lf.lfHeight -= 2;
			else
				lf.lfHeight += 2;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</SMALL>"), 8) == 0)	// check for </SMALL>
		{
			n -= 8;
			pszText += 8;
			if (lf.lfHeight > 0)
				lf.lfHeight += 2;
			else
				lf.lfHeight -= 2;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<SUB>"), 5) == 0)	// check for <SUB>
		{
			n -= 5;
			pszText += 5;
			bSubscript++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</SUB>"), 6) == 0)	// check for </SUB>
		{
			n -= 6;
			pszText += 6;
			if (bSubscript)
				bSubscript--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<SUP>"), 5) == 0)	// check for <SUP>
		{
			n -= 5;
			pszText += 5;
			bSuperscript++;// = TRUE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</SUP>"), 6) == 0)	// check for </SUP>
		{
			n -= 6;
			pszText += 6;
			if (bSuperscript)
				bSuperscript--;// = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<FONT"), 5) == 0)	// check for <FONT
		{
			TRACE(_T("found font\n"));
			TCHAR *cp = _tcschr(pszText, _T('>'));
			if (cp)
			{
				TCHAR szAttributes[XHTMLDRAW_MAX_TEXT] = { 0 };
				_tcsncpy(szAttributes, &pszText[5], cp-pszText-5);
				TRACE(_T("szAttributes=<%s>\n"), szAttributes);
				size_t m = _tcslen(szAttributes);
				n -= (int) (cp - pszText + 1);
				pszText = cp + 1;

				// loop to parse FONT attributes
				while (m > 0)
				{
					// trim left whitespace
					if ((_tcslen(szAttributes) > 0) && 
						(szAttributes[0] == _T(' ')))
					{
						m--;
						_tcscpy(szAttributes, &szAttributes[1]);
						continue;
					}

					///////////////////////////////////////////////////////////
					if (_tcsnicmp(szAttributes, _T("COLOR"), 5) == 0)
					{
						TRACE(_T("found color\n"));
						TCHAR *cp2 = _tcschr(szAttributes, _T('"'));
						if (cp2)
						{
							m -= (cp2 - szAttributes) + 1;
							_tcscpy(szAttributes, cp2+1);

							cp2 = _tcschr(szAttributes, _T('"'));
							if (cp2)
							{
								*cp2 = _T('\0');
								TCHAR szColor[XHTMLDRAW_MAX_TEXT] = { _T('\0') };
								_tcsncpy(szColor, szAttributes, cp2-szAttributes+1);
								TRACE(_T("szColor=<%s>\n"), szColor);
								CXNamedColors nc(szColor);
								if (!pXHDS->bIgnoreColorTag)
									crTextNew = nc.GetRGB();
								_tcscpy(szAttributes, cp2+1);
								m = _tcslen(szAttributes);
							}
						}
						else
							break;
					}
					///////////////////////////////////////////////////////////
					else if (_tcsnicmp(szAttributes, _T("BGCOLOR"), 7) == 0)
					{
						TRACE(_T("found bgcolor\n"));
						TCHAR *cp2 = _tcschr(szAttributes, _T('"'));
						if (cp2)
						{
							m -= cp2 - szAttributes + 1;
							_tcscpy(szAttributes, cp2+1);

							cp2 = _tcschr(szAttributes, _T('"'));
							if (cp2)
							{
								*cp2 = _T('\0');
								TCHAR szBgColor[XHTMLDRAW_MAX_TEXT] = { _T('\0') };
								_tcsncpy(szBgColor, szAttributes, cp2-szAttributes+1);
								TRACE(_T("szBgColor=<%s>\n"), szBgColor);
								CXNamedColors nc(szBgColor);
								crBkgndNew = nc.GetRGB();
								_tcscpy(szAttributes,  cp2+1);
								m = _tcslen(szAttributes);
							}
						}
						else
							break;
					}
					///////////////////////////////////////////////////////////
					else if (_tcsnicmp(szAttributes, _T("FACE"), 4) == 0)
					{
						TCHAR *cp2 = _tcschr(szAttributes, _T('"'));
						if (cp2)
						{
							m -= cp2 - szAttributes + 1;
							_tcscpy(szAttributes, cp2+1);
							cp2 = _tcschr(szAttributes, _T('"'));
							if (cp2)
							{
								const int nFaceSize = sizeof(lf.lfFaceName);	// in bytes
								int nMaxFaceSize = nFaceSize / sizeof(TCHAR);	// in TCHARs
								memset(lf.lfFaceName, 0, nFaceSize);
								int nNewFaceSize = (int)(cp2 - szAttributes);	// in TCHARs
								memset(&lf.lfFaceName, 0, nFaceSize);
								_tcsncpy(lf.lfFaceName, szAttributes, 
									(nNewFaceSize > nMaxFaceSize) ? nMaxFaceSize : nNewFaceSize);
								TRACE(_T("lf.lfFaceName=<%s>\n"), lf.lfFaceName);

								m -= cp2 - szAttributes + 1;
								if (m > 0)
									_tcscpy(szAttributes, cp2+1);
								else
									szAttributes[0] = _T('\0');
								m = _tcslen(szAttributes);
							}
						}
						else
							break;
					}
					///////////////////////////////////////////////////////////
					else if (_tcsnicmp(szAttributes, _T("SIZE"), 4) == 0)
					{
						TCHAR *cp2 = _tcschr(szAttributes, _T('"'));
						if (cp2)
						{
							m -= cp2 - szAttributes + 1;
							_tcscpy(szAttributes, cp2+1);
							cp2 = _tcschr(szAttributes, _T('"'));
							if (cp2)
							{
								int nSize = _ttoi(szAttributes);
								lf.lfHeight -= nSize;
								nSizeChange = nSize;

								m -= cp2 - szAttributes + 1;
								if (m > 0)
									_tcscpy(szAttributes, cp2+1);
								else
									szAttributes[0] = _T('\0');
								m = _tcslen(szAttributes);
							}
						}
						else
							break;
					}
					else
					{
						while ((_tcslen(szAttributes) > 0) && 
							   (szAttributes[0] != _T(' ')))
						{
							m--;
							_tcscpy(szAttributes, &szAttributes[1]);
						}
					}
				}
			}
			else
			{
				TRACE(_T("ERROR no closing >\n"));
				pszText += 5;
				n -= 5;
			}
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</FONT>"), 7) == 0)	// check for </FONT>
		{
			n -= 7;
			pszText += 7;
			crTextNew = crText;
			crBkgndNew = crBackground;
			memcpy(&lf, &prev_lf, sizeof(lf));
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("<A"), 2) == 0)	// check for <A
		{
			TCHAR *cp = 0;
			if ((cp = _tcsistr(pszText, _T("HREF="))) != NULL)	// check for HREF=
			{
				cp += 5;
				if (*cp == _T('"'))
					cp += 1;
				TCHAR *cp2 = _tcschr(cp, _T('>'));
				if (cp2)
				{
					size_t len = cp2 - cp;
					if (pXHDS->pszAnchor)
						delete [] pXHDS->pszAnchor;
					pXHDS->pszAnchor = new TCHAR [len+4];
					memset(pXHDS->pszAnchor, 0, (len+4)*sizeof(TCHAR));
					_tcsncpy(pXHDS->pszAnchor, cp, len);
					size_t last = _tcslen(pXHDS->pszAnchor);
					if (last > 0)
						last--;
					if (pXHDS->pszAnchor[last] == _T('"'))
						pXHDS->pszAnchor[last] = _T('\0');
					TRACE(_T("len=%d  pXHDS->szUrl=<%s>\n"), len, pXHDS->pszAnchor);
					n -= (int) (cp2 + 1 - pszText);
					pszText = cp2 + 1;
					TRACE(_T("pszText=<%s>\n"), pszText);

					// set start X of url
					pXHDS->rectAnchor.left = rectText.left + nXOffset;
					TRACE(_T("setting pXHDS->rectAnchor.left to %d\n"), pXHDS->rectAnchor.left);

					crTextNew = pXHDS->crAnchorText; //RGB(0,0,255);	//pXHDS->crText;
					crBkgndNew = crBackground;
					memcpy(&lf, &prev_lf, sizeof(lf));

					bInAnchor = TRUE;

					if (bUnderlineUrl)
					{
						pXHDS->bAnchorIsUnderlined = TRUE;
						bUnderline++;
					}
				}
			}
			else
			{
				TRACE(_T("ERROR no closing >\n"));
				pszText += 2;
				n -= 2;
			}
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		else if (_tcsnicmp(pszText, _T("</A>"), 4) == 0)	// check for </A>
		{
			n -= 4;
			pszText += 4;

			if (bInAnchor)
			{
				pXHDS->rectAnchor.right = rectText.left + nXOffset;
				pXHDS->bHasAnchor = TRUE;
				TRACE(_T("setting pXHDS->rectAnchor.right to %d\n"), pXHDS->rectAnchor.right);

				if (bUnderlineUrl)
					bUnderline--;
				crTextNew = crText;
				crBkgndNew = crBackground;
				memcpy(&lf, &prev_lf, sizeof(lf));
			}

			bInAnchor = FALSE;
			continue;
		}
		///////////////////////////////////////////////////////////////////////
		// plain text
		else
		{
			TRACE(_T("text:  pszText=<%s>\n"), pszText);
			TCHAR *cp = _tcschr(pszText, _T('<'));
			if (cp)
			{
				// there's another tag
				_tcsncpy(pszText1, pszText, cp - pszText);
				pszText1[cp-pszText] = _T('\0');
				TRACE(_T("pszText1=<%s>\n"), pszText1);

				if (_tcslen(pszText1) <= 0)
				{
					if (_tcslen(pszText) != 0)
					{
						_tcscpy(pszText1, pszText);
						n -= 1;
					}
				}
				pszText = cp;
			}
			else
			{
				// no more html tags
				_tcscpy(pszText1, pszText);
				pszText = NULL;
			}
		}
		TRACE(_T("pszText=<%s>\n"), pszText);
		TRACE(_T("pszText1=<%s>\n"), pszText1);

		// create new font ------------------------------------------

		lf.lfWeight    = bBold ? FW_BOLD : FW_NORMAL;
		lf.lfUnderline = (BYTE) bUnderline;
		lf.lfItalic    = (BYTE) bItalic;
		lf.lfStrikeOut = (BYTE) bStrikeThrough;

		HFONT hNewFont = CreateFontIndirect(&lf);
		_ASSERTE(hNewFont);

		HFONT hOldFont = (HFONT) SelectObject(hMemDC, hNewFont);

		SetTextColor(hMemDC, crTextNew);
		if (pXHDS->crTextBackground != COLOR_NONE)
			SetBkColor(hMemDC, pXHDS->crTextBackground);
		else
			SetBkMode(hMemDC, TRANSPARENT);		// need transparency for italic fonts

		// replace char entities ------------------------------------

		size_t end = _tcslen(pszText1);
		buflen = end + 100;
		_ASSERTE(buf == NULL);
		buf = new TCHAR [buflen];
		memset(buf, 0, buflen*sizeof(TCHAR));

		_tcsncpy(buf, pszText1, buflen-1);

		ReplaceCharEntities(buf, end);

		int len = (int)_tcslen(buf);
		SIZE size;
		GetTextExtentPoint32(hMemDC, buf, len, &size);
		LONG width = size.cx;

		if ((crBkgndNew != crBackground) &&
			(pXHDS->crTextBackground == COLOR_NONE))
		{
			// changing backgrounds, so fill in with new color
			HBRUSH hbrushnew = CreateSolidBrush(crBkgndNew); 
			if (hbrushnew)
			{
				RECT rect = rectText;
				rect.right = rect.left + width + 1;
				if (bItalic)
				{
					rect.right += 1;		// italic needs a little more
					if (!IsTrueType(hMemDC))
						rect.right += 2;	// non-TTF fonts need even more
				}
				if (rect.right > rectText.right)
					rect.right = rectText.right;
				FillRect(hMemDC, &rect, hbrushnew);
				DeleteObject(hbrushnew);
			}
		}

		UINT uFormat = pXHDS->uFormat;

		if (pXHDS->bUseEllipsis)
			uFormat |= DT_END_ELLIPSIS;

		if (pXHDS->bHasAnchor)
		{
			// set rect for anchor
			RECT rectCalc = rectText;
			int nHeight = DrawText(hMemDC, buf, -1, &rectCalc, uFormat | DT_CALCRECT);
			TRACE(_T("nHeight=%d -----\n"), nHeight);
			pXHDS->rectAnchor.bottom = pXHDS->rectAnchor.top + nHeight;
		}

		RECT savedrect = rectText;

		GetTextMetrics(hMemDC, &tm);
		int nBaselineAdjust = tm.tmAscent / 2;

		if (bSubscript)
		{
			rectText.top += nBaselineAdjust;
			rectText.bottom += nBaselineAdjust;
		}
		if (bSuperscript)
		{
			rectText.top -= nBaselineAdjust;
			rectText.bottom -= nBaselineAdjust;
		}

		// draw text ------------------------------------------------

		TRACE(_T("DrawText: <%s>\n"), buf);
		DrawText(hMemDC, buf, -1, &rectText, uFormat);

		rectText = savedrect;

		nSizeChange = 0;

		if (hOldFont)
			SelectObject(hMemDC, hOldFont);
		if (hNewFont)
			DeleteObject(hNewFont);
		hNewFont = 0;
		hOldFont = 0;

		delete [] buf;
		buf = NULL;

		rectText.left += width;

		n -= (int)_tcslen(pszText1);

	}	// while

	// save the rightmost pixel position - note that rectText
	// is remapped to 0,0 for the memory dc
	pXHDS->nRightX = rectText.left + nXOffset;
	TRACE(_T("nRightX = %d =====\n"), pXHDS->nRightX);

	// end double buffering
	BitBlt(hDC, rectDraw.left, rectDraw.top, nRectWidth, nRectHeight,
		hMemDC, 0, 0, SRCCOPY);			
	
	// swap back the original bitmap
	if (hOldBitmap)
		SelectObject(hMemDC, hOldBitmap);
	if (hBitmap)
		DeleteObject(hBitmap);
	hBitmap = 0;

	DeleteDC(hMemDC);
	hMemDC = 0;

	if (pTextBuffer)
		delete [] pTextBuffer;
	pTextBuffer = 0;
	if (pszText1)
		delete [] pszText1;
	pszText1 = 0;

	bInDraw = FALSE;

	return nWidth;
}
Esempio n. 30
0
BOOL CSecurity::IsClientBad(const CString& sUserAgent) const
{
	// No user agent- Assume bad. (Allowed connection but no searches performed)
	if ( sUserAgent.IsEmpty() ) 								return TRUE;

	// PeerProject Fakes
	if ( LPCTSTR szVersion = _tcsistr( sUserAgent, _T("PeerProject") ) )
	{
		szVersion += 11;
		if ( _tcsistr( sUserAgent, _T(" 1.") ) )				return FALSE;
	//	if ( _tcsistr( sUserAgent, _T(" 2.") ) )				return FALSE;

		return TRUE;
	}

	// Shareaza Fakes/Obsolete
	if ( LPCTSTR szVersion = _tcsistr( sUserAgent, _T("shareaza") ) )
	{
		szVersion += 8;
		if ( _tcsistr( sUserAgent, _T(" 2.0") ) )				return TRUE;
		if ( _tcsistr( sUserAgent, _T(" 2.") ) )				return FALSE;
		if ( _tcsistr( sUserAgent, _T("Plus") ) )				return FALSE;

		return TRUE;
	}

	// Dianlei: Shareaza rip-off
	// Based on Alpha code, need verification for current 1.x status
	if ( LPCTSTR szVersion = _tcsistr( sUserAgent, _T("Dianlei") ) )
	{
		szVersion += 7;
		if ( _tcsistr( szVersion, _T(" 0.") ) )					return TRUE;

		return FALSE;
	}

	// BearShare Selectivity
	if ( LPCTSTR szVersion = _tcsistr( sUserAgent, _T("BearShare") ) )
	{
		szVersion += 9;
		if ( _tcsistr( szVersion, _T(" 4.") ) )					return FALSE;
		if ( _tcsistr( szVersion, _T(" 5.") ) )					return FALSE;

		return TRUE;
	}

	// Any iMesh
	if ( _tcsistr( sUserAgent, _T("iMesh") ) )					return TRUE;

	// Other Miscillaneous

	if ( _tcsistr( sUserAgent, _T("Trilix") ) )					return TRUE;

	if ( _tcsistr( sUserAgent, _T("Gnutella Turbo") ) )			return TRUE;

	if ( _tcsistr( sUserAgent, _T("Mastermax File Sharing") ) )	return TRUE;

	if ( _tcsistr( sUserAgent, _T("Fildelarprogram") ) )		return TRUE;

	if ( _tcsistr( sUserAgent, _T("Fastload.TV") ) )			return TRUE;

	// Other GPL Violaters, Etc.

	if ( _tcsistr( sUserAgent, _T("K-Lite") ) )					return TRUE;

	if ( _tcsistr( sUserAgent, _T("SlingerX") ) )				return TRUE;

	if ( _tcsistr( sUserAgent, _T("C -3.0.1") ) )				return TRUE;

	if ( _tcsistr( sUserAgent, _T("vagaa") ) )					return TRUE;

	if ( _tcsistr( sUserAgent, _T("mxie") ) )					return TRUE;

	if ( _tcsistr( sUserAgent, _T("WinMX") ) )					return TRUE;

	if ( _tcsistr( sUserAgent, _T("eTomi") ) )					return TRUE;

	// Unknown- Assume OK
	return FALSE;
}