Exemple #1
0
void CRemote::PageNetwork()
{
	if ( CheckCookie() ) return;
	m_nTab = tabNetwork;

	CSingleLock pLock( &Network.m_pSection );
	if ( ! SafeLock( pLock ) ) return;

	DWORD nNeighbourID = 0;
	_stscanf( GetKey( L"drop" ), L"%lu", &nNeighbourID );

	if ( nNeighbourID != 0 )
	{
		if ( CNeighbour* pNeighbour = Neighbours.Get( nNeighbourID ) )
			pNeighbour->Close( IDS_CONNECTION_CLOSED );
	}

	Prepare();		// Header

	CString str;
	str.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );
	Add( L"random", str );
	Output( L"networkHeader" );

	PageNetworkNetwork( PROTOCOL_G2, &Settings.Gnutella2.Enabled, L"Gnutella2" );	// protocolNames[ PROTOCOL_G2 ]
	PageNetworkNetwork( PROTOCOL_G1, &Settings.Gnutella1.Enabled, L"Gnutella" ); 	// protocolNames[ PROTOCOL_G1 ]
	PageNetworkNetwork( PROTOCOL_ED2K, &Settings.eDonkey.Enabled, L"eDonkey" );		// protocolNames[ PROTOCOL_ED2K ]
	PageNetworkNetwork( PROTOCOL_DC, &Settings.DC.Enabled, L"DC++" );				// protocolNames[ PROTOCOL_DC ] )
	PageNetworkNetwork( PROTOCOL_BT, &Settings.BitTorrent.Enabled, L"BitTorrent" );	// protocolNames[ PROTOCOL_BT ] )

	Output( L"networkFooter" );
}
Exemple #2
0
void CRemote::PageNewSearch()
{
	if ( CheckCookie() ) return;

	CMainWnd* pMainWnd = (CMainWnd*)theApp.m_pMainWnd;
	if ( pMainWnd == NULL || ! pMainWnd->IsKindOf( RUNTIME_CLASS(CMainWnd) ) ) return;

	CSingleLock pLock( &theApp.m_pSection );
	if ( ! SafeLock( pLock ) ) return;

	const CString strSearch = GetKey( L"search" );
	const CString strSchema = GetKey( L"schema" );

	if ( strSearch.IsEmpty() || ( ! strSchema.IsEmpty() && SchemaCache.Get( strSchema ) == NULL ) )
	{
		m_sRedirect = L"home";
		return;
	}

	CQuerySearchPtr pSearch	= new CQuerySearch();
	pSearch->m_sSearch		= strSearch;
	pSearch->m_pSchema		= SchemaCache.Get( strSchema );

	CString strURI;
	if ( pSearch->m_pSchema != NULL )
		strURI = pSearch->m_pSchema->GetURI();

	Settings.Search.LastSchemaURI = strURI;

	pMainWnd->PostMessage( WM_OPENSEARCH, (WPARAM)pSearch.Detach() );
	pLock.Unlock();
	Sleep( 500 );

	m_sRedirect = L"search";
}
Exemple #3
0
void CRemote::PageHome()
{
	if ( CheckCookie() ) return;
	m_nTab = tabHome;

	Prepare();		// Header
	Output( L"home" );
}
Exemple #4
0
void CRemote::PageNewDownload()
{
	if ( CheckCookie() ) return;

	CEnvyURL pURI;
	if ( pURI.Parse( GetKey( L"uri" ) ) )
		Downloads.Add( pURI );

	m_sRedirect = L"downloads?group_reveal=all";
}
COSIGNSTATUS
CookieDatabase::CheckCookie( std::string& cookie, CosignServiceInfo* csi ) {

	std::wstring	wcookie;

	if ( StringToWString( cookie, wcookie ) == -1 ) {
		return( COSIGNERROR );
	}
	return( CheckCookie( wcookie, csi ) );
}
Exemple #6
0
void CRemote::PageImage(CString& strPath)
{
	if ( CheckCookie() ) return;

	strPath = strPath.Mid( 15 );
	if ( strPath.Find( L'%' ) >= 0 ) return;
	if ( strPath.Find( L'/' ) >= 0 ) return;
	if ( strPath.Find( L'\\' ) >= 0 ) return;

	strPath = Settings.General.Path + L"\\Remote\\Resources\\" + strPath;

	CFile hFile;
	if ( hFile.Open( strPath, CFile::modeRead ) )
	{
		m_pResponse.EnsureBuffer( (DWORD)hFile.GetLength() );
		hFile.Read( m_pResponse.m_pBuffer, (UINT)hFile.GetLength() );
		m_pResponse.m_nLength += (DWORD)hFile.GetLength();
		hFile.Close();
	}
}
Exemple #7
0
void CRemote::PageDownloads()
{
	if ( CheckCookie() ) return;
	m_nTab = tabDownloads;

	CString str;
	str.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );

	CSingleLock pLock( &DownloadGroups.m_pSection, TRUE );

	Prepare();		// Header
	Add( L"random", str );
	Output( L"downloadsHeader" );

	BOOL bExclusive = ! GetKey( L"group_exclusive" ).IsEmpty();
	BOOL bReveal = ! GetKey( L"group_reveal" ).IsEmpty();

	for ( POSITION posGroup = DownloadGroups.GetIterator(); posGroup != NULL; )
	{
		CDownloadGroup* pGroup = DownloadGroups.GetNext( posGroup );

		CString strGroupID;
		strGroupID.Format( L"%p", pGroup );
		Add( L"group_id", strGroupID );

		if ( bExclusive )
			pGroup->m_bRemoteSelected = ( GetKey( L"group_exclusive" ) == strGroupID );
		else if ( bReveal )
			pGroup->m_bRemoteSelected = TRUE;
		else if ( GetKey( L"group_select" ) == strGroupID )
			pGroup->m_bRemoteSelected = TRUE;
		else if ( GetKey( L"group_deselect" ) == strGroupID )
			pGroup->m_bRemoteSelected = FALSE;

		Add( L"group_caption", pGroup->m_sName );
		if ( pGroup->m_bRemoteSelected )
			Add( L"group_selected", L"true" );
		Output( L"downloadsTab" );
		Prepare( L"group_" );
	}

	if ( ! GetKey( L"filter_set" ).IsEmpty() )
	{
		Settings.Downloads.FilterMask &= ~( DLF_ACTIVE | DLF_PAUSED | DLF_QUEUED | DLF_SOURCES | DLF_SEED );
		if ( GetKey( L"filter_active" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_ACTIVE;
		if ( GetKey( L"filter_paused" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_PAUSED;
		if ( GetKey( L"filter_queued" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_QUEUED;
		if ( GetKey( L"filter_sources" ) == L"1" ) Settings.Downloads.FilterMask |= DLF_SOURCES;
		if ( GetKey( L"filter_seeds" ) == L"1" )  Settings.Downloads.FilterMask |= DLF_SEED;
		Settings.Downloads.ShowSources = ( GetKey( L"filter_show_all" ) == L"1" );
	}

	Add( L"filter_active", ( Settings.Downloads.FilterMask & DLF_ACTIVE ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_paused", ( Settings.Downloads.FilterMask & DLF_PAUSED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_queued", ( Settings.Downloads.FilterMask & DLF_QUEUED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_sources", ( Settings.Downloads.FilterMask & DLF_SOURCES ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_seeds", ( Settings.Downloads.FilterMask & DLF_PAUSED ) ? L"checked=\"checked\"" : L"" );
	Add( L"filter_show_all", Settings.Downloads.ShowSources ? L"checked=\"checked\"" : L"" );
	Output( L"downloadsTop" );

	for ( POSITION posDownload = Downloads.GetIterator(); posDownload != NULL; )
	{
		CDownload* pDownload = Downloads.GetNext( posDownload );

		CString strDownloadID;
		strDownloadID.Format( L"%p", pDownload );

		if ( GetKey( L"modify_id" ) == strDownloadID )
		{
			CString strAction = GetKey( L"modify_action" );
			strAction.MakeLower();

			if ( strAction == L"expand" )
			{
				if ( CDownloadsCtrl::IsExpandable( pDownload ) )
					pDownload->m_bExpanded = TRUE;
			}
			else if ( strAction == L"collapse" )
			{
				if ( CDownloadsCtrl::IsExpandable( pDownload ) )
					pDownload->m_bExpanded = FALSE;
			}
			else if ( strAction == L"resume" )
			{
				pDownload->Resume();
			}
			else if ( strAction == L"pause" )
			{
				if ( ! pDownload->IsPaused() && ! pDownload->IsTasking() )
					pDownload->Pause();
			}
			else if ( strAction == L"cancel" )
			{
				if ( ! pDownload->IsTasking() )
					pDownload->Remove();
				continue;
			}
			else if ( strAction == L"clear" )
			{
				if ( pDownload->IsCompleted() && ! pDownload->IsPreviewVisible() )
				{
					pDownload->Remove();
					continue;
				}
			}
			else if ( strAction == L"more_sources" )
			{
				// roo_koo_too improvement
				pDownload->FindMoreSources();
			}
		}

		if ( CDownloadsCtrl::IsFiltered( pDownload ) ) continue;

		CDownloadGroup* pGroup = NULL;

		for ( POSITION posGroup = DownloadGroups.GetIterator(); posGroup != NULL; )
		{
			pGroup = DownloadGroups.GetNext( posGroup );
			if ( pGroup->m_bRemoteSelected && pGroup->Contains( pDownload ) ) break;
			pGroup = NULL;
		}

		if ( pGroup == NULL ) continue;

		Add( L"download_id", strDownloadID );
		Add( L"download_filename", pDownload->GetDisplayName() );
		Add( L"download_size", ( pDownload->m_nSize == SIZE_UNKNOWN ) ?
			LoadString( IDS_STATUS_UNKNOWN ) : Settings.SmartVolume( pDownload->m_nSize ) );
		int nProgress = int( pDownload->GetProgress() );
		str.Format( L"%i", nProgress );
		Add( L"download_percent", str );
		str.Format( L"%i", 100 - nProgress );
		Add( L"download_percent_inverse", str );
		Add( L"download_speed", Settings.SmartSpeed( pDownload->GetMeasuredSpeed() ) );
		if ( CDownloadsCtrl::IsExpandable( pDownload ) )
		{
			if ( pDownload->m_bExpanded )
				Add( L"download_is_expanded", L"true" );
			else
				Add( L"download_is_collapsed", L"true" );
		}
		if ( pDownload->IsCompleted() )
			Add( L"download_is_complete", L"true" );
		else if ( pDownload->IsPaused() )
			Add( L"download_is_paused", L"true" );

		Add( L"download_status", pDownload->GetDownloadStatus() );
		Add( L"download_sources", pDownload->GetDownloadSources() );
		Output( L"downloadsDownload" );

		if ( pDownload->m_bExpanded && CDownloadsCtrl::IsExpandable( pDownload ) )
		{
			for ( POSITION posSource = pDownload->GetIterator(); posSource; )
			{
				CDownloadSource* pSource = pDownload->GetNext( posSource );

				ASSERT( pSource->m_pDownload == pDownload );

				CString strSourceID;
				strSourceID.Format( L"%p", pSource );

				if ( GetKey( L"modify_id" ) == strSourceID )
				{
					CString strModifyAction = GetKey( L"modify_action" );
					strModifyAction.MakeLower();

					if ( strModifyAction == L"access" )
					{
						// Only create a new Transfer if there isn't already one
						if ( pSource->IsIdle() && pSource->m_nProtocol != PROTOCOL_ED2K )
						{
							if ( pDownload->IsPaused() )
								pDownload->Resume();	// Workaround duplicate

							pDownload->Resume();

							if ( pSource->m_bPushOnly )
								pSource->PushRequest();
							else if ( CDownloadTransfer* pTransfer = pSource->CreateTransfer() )
								pTransfer->Initiate();
						}
					}
					else if ( strModifyAction == L"forget" )
					{
						pSource->Remove( TRUE, TRUE );
						continue;
					}
				}

				if ( Settings.Downloads.ShowSources || pSource->IsConnected() )
				{
					Add( L"source_id", strSourceID );
					Add( L"source_agent", pSource->m_sServer );
					Add( L"source_nick", pSource->m_sNick );

					if ( ! pSource->IsIdle() )
					{
						Add( L"source_status", pSource->GetState( FALSE ) );
						Add( L"source_volume", Settings.SmartVolume( pSource->GetDownloaded() ) );
						if ( DWORD nSpeed = pSource->GetMeasuredSpeed() )
							Add( L"source_speed", Settings.SmartSpeed( nSpeed ) );
						Add( L"source_address", pSource->GetAddress() );
						Add( L"source_caption", pSource->GetAddress() + L" - " + pSource->m_sNick );
					}
					else	// No transfer
					{
						Add( L"source_address", CString( inet_ntoa( pSource->m_pAddress ) ) );
						Add( L"source_caption", CString( inet_ntoa( pSource->m_pAddress ) ) + L" - " + pSource->m_sNick );

						if ( pSource->m_tAttempt > 0 )
						{
							DWORD tNow = GetTickCount();

							if ( pSource->m_tAttempt >= tNow )
							{
								tNow = ( pSource->m_tAttempt - tNow ) / 1000;
								CString strSourceStatus;
								strSourceStatus.Format( L"%.2u:%.2u", tNow / 60, tNow % 60 );
								Add( L"source_status", strSourceStatus );
							}
						}
					}

					Output( L"downloadsSource" );
					Prepare( L"source_" );
				}
			}
		}

		Prepare( L"download_" );
	} // for POSITION loop

	Output( L"downloadsBottom" );
	Output( L"downloadsFooter" );
}
Exemple #8
0
void CRemote::PageSearch()
{
	if ( CheckCookie() ) return;
	m_nTab = tabSearch;

	CMainWnd* pMainWnd = static_cast< CMainWnd* >( theApp.m_pMainWnd );
	if ( pMainWnd == NULL || ! pMainWnd->IsKindOf( RUNTIME_CLASS(CMainWnd) ) ) return;

	CSingleLock pLock( &theApp.m_pSection );
	if ( ! SafeLock( pLock ) ) return;

	INT_PTR nSearchID = NULL;
	INT_PTR nCloseID = NULL;
	CSearchWnd* pSearchWnd = NULL;
	CString str;

	_stscanf( GetKey( L"id" ), L"%Ii", &nSearchID );
	_stscanf( GetKey( L"close" ), L"%Ii", &nCloseID );

	Prepare();		// Header
	Output( L"searchHeader" );

	for ( CSearchWnd* pFindWnd = NULL; ( pFindWnd = static_cast< CSearchWnd* >( pMainWnd->m_pWindows.Find( RUNTIME_CLASS(CSearchWnd), pFindWnd ) ) ) != NULL; )
	{
		Prepare();
		INT_PTR nFindWnd = reinterpret_cast< INT_PTR >( pFindWnd );
		if ( nCloseID == nFindWnd )
		{
			pFindWnd->PostMessage( WM_CLOSE );
			continue;
		}
		else if ( nSearchID == nFindWnd )
		{
			pSearchWnd = pFindWnd;
			Add( L"search_selected", L"true" );
		}

		str.Format( L"%Ii", nFindWnd );
		Add( L"search_id", str );
		str = pFindWnd->GetCaption();
		if ( str.Find( L"Search : " ) == 0 ) str = str.Mid( 9 ).SpanExcluding( L"[" );
		Add( L"search_caption", str );
		Output( L"searchTab" );
	}

	if ( pSearchWnd == NULL )
	{
		str.Empty();

		for ( POSITION pos = SchemaCache.GetIterator(); pos != NULL; )
		{
			CSchemaPtr pSchema = SchemaCache.GetNext( pos );
			if ( ! pSchema->m_bPrivate && pSchema->m_nType == CSchema::stFile )
			{
				str += L"<option value=\"" + pSchema->GetURI();
				str += L"\">" + pSchema->m_sTitle;
				str += L"</option>\r\n";
			}
		}

		Prepare();		// Header
		Add( L"schema_option_list", str );
		Output( L"searchNew" );
		Output( L"searchFooter" );
		return;
	}

	if ( ! GetKey( L"stop" ).IsEmpty() )
	{
		pSearchWnd->PostMessage( WM_COMMAND, ID_SEARCH_STOP );
		Sleep( 500 );
	}

	CLockedMatchList pMatches( pSearchWnd->GetMatches() );

	str = GetKey( L"sort" );
	if ( ! str.IsEmpty() )
	{
		int nColumn = 0;
		_stscanf( str, L"%i", &nColumn );

		if ( pMatches->m_bSortDir != 1 && pMatches->m_nSortColumn == nColumn )
			pMatches->SetSortColumn( nColumn, FALSE );
		else
			pMatches->SetSortColumn( nColumn, TRUE );

		pSearchWnd->PostMessage( WM_TIMER, 7 );
	}

	str = GetKey( L"expcol" );
	if ( ! str.IsEmpty() )
	{
		CMatchFile** pLoop = pMatches->m_pFiles;
		for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
		{
			if ( (*pLoop)->GetURN() == str )
			{
				(*pLoop)->Expand( GetKey( L"collapse" ).IsEmpty() );
				pSearchWnd->PostMessage( WM_TIMER, 7 );
				break;
			}
		}
	}

	str = GetKey( L"download" );
	if ( ! str.IsEmpty() )
	{
		CMatchFile** pLoop = pMatches->m_pFiles;
		for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
		{
			if ( (*pLoop)->GetURN() == str )
			{
				Downloads.Add( *pLoop );
				pSearchWnd->PostMessage( WM_TIMER, 7 );
				m_sResponse.Empty();
				m_sRedirect = L"downloads?group_reveal=all";
				return;
			}
		}
	}

	if ( ! GetKey( L"setfilter" ).IsEmpty() )
	{
		pMatches->m_sFilter = GetKey( L"filter" );
		pMatches->Filter();
		pSearchWnd->PostMessage( WM_TIMER, 7 );
	}

	Prepare();		// Header
	str.Format( L"%Ii", nSearchID );
	Add( L"search_id", str );
	str.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );
	Add( L"random", str );
	if ( ! pSearchWnd->IsPaused() )
		Add( L"searching", L"true" );
	Add( L"search_filter", pMatches->m_sFilter );
	Output( L"searchTop" );

	PageSearchHeaderColumn( MATCH_COL_NAME, Skin.GetHeaderTranslation( L"CMatchCtrl", L"File" ), L"left" );
	PageSearchHeaderColumn( MATCH_COL_SIZE, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Size" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_RATING, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Rating" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_STATUS, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Status" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_COUNT, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Host/Count" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_SPEED, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Speed" ), L"center" );
	PageSearchHeaderColumn( MATCH_COL_CLIENT, Skin.GetHeaderTranslation( L"CMatchCtrl", L"Client" ), L"center" );

	Output( L"searchMiddle" );

	CMatchFile** pLoop = pMatches->m_pFiles;

	for ( DWORD nCount = 0; nCount < pMatches->m_nFiles; nCount++, pLoop++ )
	{
		CMatchFile* pFile = *pLoop;
		if ( pFile->GetFilteredCount() == 0 ) continue;

		Add( L"row_urn", pFile->GetURN() );
		Add( L"row_filename", pFile->m_sName );
		if ( pFile->GetFilteredCount() <= 1 )
			Add( L"row_single", L"true" );
		else if ( pFile->m_bExpanded )
			Add( L"row_expanded", L"true" );
		else
			Add( L"row_collapsed", L"true" );

		Output( L"searchRowStart" );

		PageSearchRowColumn( MATCH_COL_SIZE, pFile, Settings.SmartVolume( pFile->m_nSize ) );

		str.Empty();
		for ( INT_PTR nStar = pFile->m_nRating / max( 1, pFile->m_nRated ); nStar > 1; nStar -- ) str += L'*';
		PageSearchRowColumn( MATCH_COL_RATING, pFile, str );

		str.Empty();
		str += pFile->m_bBusy == TRI_TRUE ? L'B' : L'-';
		str += pFile->m_bPush == TRI_TRUE ? L'F' : L'-';
		str += pFile->m_bStable == TRI_FALSE ? L'U' : L'-';
		PageSearchRowColumn( MATCH_COL_STATUS, pFile, str );

		str.Empty();
		if ( pFile->GetFilteredCount() > 1 )
			str.Format(L"(%u sources)", pFile->GetFilteredCount());
		else
			str = (CString)inet_ntoa( pFile->GetBestAddress() );
		PageSearchRowColumn( MATCH_COL_COUNT, pFile, str );


		PageSearchRowColumn( MATCH_COL_SPEED, pFile, pFile->m_sSpeed );
		PageSearchRowColumn( MATCH_COL_CLIENT, pFile, pFile->GetFilteredCount() == 1 ? pFile->GetBestVendorName() : L"" );

		Output( L"searchRowEnd" );
		Prepare( L"column_" );
		Prepare( L"row_" );

		if ( pFile->m_bExpanded )
		{
			for ( CQueryHit* pHit = pFile->GetHits(); pHit != NULL; pHit = pHit->m_pNext )
			{
				if ( ! pHit->m_bFiltered ) continue;

				Add( L"row_urn", pFile->GetURN() );
				Add( L"row_filename", pHit->m_sName );
				Add( L"row_source", L"true" );
				Output( L"searchRowStart" );

				PageSearchRowColumn( MATCH_COL_SIZE, pFile, Settings.SmartVolume( pHit->m_nSize ) );
				str.Empty();
				for ( int nStar = pHit->m_nRating; nStar > 1; nStar -- ) str += L"*";
				PageSearchRowColumn( MATCH_COL_RATING, pFile, str );

				str.Empty();
				str += pFile->m_bBusy == TRI_TRUE ? L'B' : L'-';
				str += pFile->m_bPush == TRI_TRUE ? L'F' : L'-';
				str += pFile->m_bStable == TRI_FALSE ? L'U' : L'-';
				PageSearchRowColumn( MATCH_COL_STATUS, pFile, str );

				PageSearchRowColumn( MATCH_COL_COUNT, pFile, (CString)inet_ntoa( pHit->m_pAddress ) );
				PageSearchRowColumn( MATCH_COL_SPEED, pFile, pHit->m_sSpeed );
				PageSearchRowColumn( MATCH_COL_CLIENT, pFile, pHit->m_pVendor->m_sName );

				Output( L"searchRowEnd" );
				Prepare( L"column_" );
				Prepare( L"row_" );
			}
		}
	}

	Output( L"searchBottom" );
	Prepare();
	Output( L"searchFooter" );
}
Exemple #9
0
void CRemote::PageUploads()
{
	if ( CheckCookie() ) return;
	m_nTab = tabUploads;

	CSingleLock pLock( &UploadQueues.m_pSection, FALSE );
	if ( ! SafeLock( pLock ) )
		return;

	Prepare();		// Header

	CString strRandom;
	strRandom.Format( L"%i", GetRandomNum( 0i32, _I32_MAX ) );
	Add( L"random", strRandom );

	Output( L"uploadsHeader" );

	for ( POSITION posQueue = CUploadsCtrl::GetQueueIterator(); posQueue != NULL; )
	{
		CUploadQueue* pQueue = CUploadsCtrl::GetNextQueue( posQueue );

		CString strQueueID;
		strQueueID.Format( L"%p", pQueue );

		if ( GetKey( L"queue_expand" ) == strQueueID )
			pQueue->m_bExpanded = TRUE;
		else if ( GetKey( L"queue_collapse" ) == strQueueID )
			pQueue->m_bExpanded = FALSE;

		POSITION posFile = CUploadsCtrl::GetFileIterator( pQueue );
		if ( posFile == NULL ) continue;

		Prepare();
		Add( L"queue_id", strQueueID );
		Add( L"queue_caption", pQueue->m_sName );
		if ( pQueue->m_bExpanded )
			Add( L"queue_expanded", L"true" );

		if ( pQueue != UploadQueues.m_pTorrentQueue && pQueue != UploadQueues.m_pHistoryQueue )
		{
			CString str;
			str.Format( L"%u", pQueue->GetTransferCount() );
			Add( L"queue_transfers", str );
			str.Format( L"%u", pQueue->GetQueuedCount() );
			Add( L"queue_queued", str );
			Add( L"queue_bandwidth", Settings.SmartSpeed( pQueue->GetMeasuredSpeed() ) );
		}

		Output( L"uploadsQueueStart" );

		if ( pQueue->m_bExpanded )
		{
			while ( posFile != NULL )
			{
				int nPosition;
				CUploadFile* pFile = CUploadsCtrl::GetNextFile( pQueue, posFile, &nPosition );
				if ( pFile == NULL ) continue;
				CUploadTransfer* pTransfer = pFile->GetActive();

				CString strFileID;
				strFileID.Format( L"%p", pFile );

				if ( GetKey( L"drop" ) == strFileID )
				{
					pFile->Remove();
					continue;
				}

				Add( L"file_id", strFileID );
				Add( L"file_filename", pFile->m_sName );
				Add( L"file_size", Settings.SmartVolume( pFile->m_nSize ) );

				if ( pTransfer != NULL )
				{
					Add( L"file_address", pTransfer->m_sAddress );
					Add( L"file_nick", pTransfer->m_sRemoteNick );
					Add( L"file_user", pTransfer->m_sAddress + L" - " + pTransfer->m_sRemoteNick );
					Add( L"file_agent", pTransfer->m_sUserAgent );
				}

				CString str;
				if ( pTransfer == NULL || pTransfer->m_nState == upsNull )
				{
					LoadString( str, IDS_STATUS_COMPLETED );
				}
				else if ( pTransfer->m_nProtocol == PROTOCOL_BT )
				{
					CUploadTransferBT* pBT = (CUploadTransferBT*)pTransfer;

					if ( ! pBT->m_bInterested )
						LoadString( str, IDS_STATUS_UNINTERESTED );
					else if ( pBT->m_bChoked )
						LoadString( str, IDS_STATUS_CHOKED );
					else if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() )
						str = Settings.SmartSpeed( nSpeed );
				}
				else if ( nPosition > 0 )
				{
					LoadString( str, IDS_STATUS_Q );
					str.Format( L"%s %i", (LPCTSTR)str, nPosition );
				}
				else
				{
					if ( DWORD nSpeed = pTransfer->GetMeasuredSpeed() )
						str = Settings.SmartSpeed( nSpeed );
					else
						LoadString( str, IDS_STATUS_NEXT );
				}
				Add( L"file_speed", str );
				Add( L"file_status", str );

				Output( L"uploadsFile" );
				Prepare( L"file_" );
			}
		}

		Output( L"uploadsQueueEnd" );
		Prepare( L"queue_" );
	}

	Prepare();
	Output( L"uploadsFooter" );
}
COSIGNSTATUS
ConnectionList::CheckCookie( std::string* cookie, CosignServiceInfo* csi, BOOL tryAgain ) {

	Snet*	snet;
	std::string	out;
	std::string	in;
	int		goodConnections = 0;
	COSIGNSTATUS	status = COSIGNRETRY;

	CosignTrace1( L"connections.size() = %d", connections.size() );
	for( unsigned int i = 0; i < connections.size() && status == COSIGNRETRY; i++ ) {
		curConnection = snet = connections[ i ];
		CosignTrace1( L"CheckCookie iter %d", i );
		if ( !snet->tlsStarted() ) {
			out = "STARTTLS 2\r\n";
			CosignTrace1( ">> %s", out.c_str() );
			if ( snet->write( out ) == -1 ) {
				/// xxx on errors, delete connection?  Mark it as bad?
				CosignLog( L"Error writing data to socket %d\n", i );
				continue;
			}
			if ( snet->getLine() == -1 ) {
				CosignLog( L"Error reading data from socket %d\n", i );
				continue;
			}
			CosignTrace1( "<< %s", snet->data.c_str() );
			
			if ( snet->startTls( certificateContext, (WCHAR*)server.c_str() ) != 0 ) {
				CosignLog( L"Error starting TLS on socket %d\n", i );
				snet->close();
				continue;
			}
			if ( snet->getLine() == -1 ) {
				CosignLog( L"Error reading data(3) from socket %d\n", i );
				continue;
			}
			CosignTrace1( "<< %s\n", snet->data.c_str() );
		}
		
		out = "CHECK " + *cookie + "\r\n";
		CosignTrace1( ">> %s", out.c_str() );
		if ( snet->write( out ) == -1 ) {
			CosignLog( L"Error writing data(2) to socket %d\n", i );
			continue;
		}
		if ( snet->getLine() == -1 ) {
			CosignLog( L"Error reading data(4) from socket %d\n", i );
			continue;
		}
		CosignTrace1( "<< %s", snet->data.c_str() );
		in = snet->data;
		switch( in[ 0 ] ) {
		case '2':
			// Success!
			CosignTrace1( "Server returned 2xx: %s", in.c_str() );
			status = COSIGNLOGGEDIN;
			break;
		case '4':
			// Logged out
			CosignTrace1( "User is logged out: %s", in.c_str() );
			status = COSIGNLOGGEDOUT;
			break;
		case '5' :
			// Choose another connection
			CosignTrace1( "Trying a different server: %s", in.c_str() );
			status = COSIGNRETRY;
			break;
		default :
			CosignLog( "Server returned unexpected response: %s", in.c_str() );
			status = COSIGNERROR;
			break;
		}
		goodConnections++;
	}
	if (( connections.size() == 0 || goodConnections < connections.size() ) && tryAgain ) {
		/// repopulate and try again
		CosignTrace0( L"Repopulating and trying again..." );
		Depopulate();
		if ( Populate() <= 0 ) {
			CosignLog( L"Failed to repopulate the connection list" );
			status = COSIGNRETRY;
		} else {
			status = CheckCookie( cookie, csi, FALSE );
		}
	}

    /*
     * DAP UPENN: If status is COSIGNLOGGEDIN but goodConnnections is 0,
     * that means we repopulated and tried again successfully above and,
     * therefore, this block shouldn't run
     */
    if ( status == COSIGNLOGGEDIN && goodConnections != 0) {
		CosignTrace0( L"Putting values into csi" );
		std::vector<std::string>	authData;
		std::stringstream	cookieParser( in );
		copy( std::istream_iterator<std::string>(cookieParser), std::istream_iterator<std::string>(), std::back_inserter(authData) );
		if ( authData.size() < 4 ) {
			CosignLog( L"Incorrect number of arguments.  Expected at least 4, received %d", (int)authData.size() );
			return( COSIGNERROR );
		}
		csi->ipAddr = authData[ 1 ];
		csi->user = authData[ 2 ];
		csi->strFactors = csi->realm = authData[ 3 ];
		csi->factors.push_back( authData[ 3 ] );
		for ( unsigned int i = 4; i < authData.size(); i++ ) {
			csi->strFactors += " " + authData[i];
			csi->factors.push_back( authData[i] );
		}
		csi->krb5TicketPath.clear();
	}
	return( status );
}