Exemplo n.º 1
0
void CRepositoryBrowserSelection::Add (const CTreeItem* item)
{
    if (item == NULL)
        return;

    // extract the info from the list item

    SPath path;
    CString absPath = item->url;
    path.url = CTSVNPath (absPath);

    // we don't fully escape the urls, because the GetSVNApiPath() method
    // of the CTSVNPath already does escaping.
    // We only escape special chars here:
    // the '%' because we know that this char isn't escaped yet, and
    // the '"' char, because we pass these urls to the command line as well
    absPath.Replace (_T("%"), _T("%25"));
    absPath.Replace (_T("\""), _T("%22"));
    path.urlEscaped = CTSVNPath (absPath);

    path.isExternal = item->is_external;
    path.isFolder = true;
    path.isLocked = false;

    // store & accumulate in the corresponding repository bucket

    InternalAdd (item->repository, path);
}
void CRepositoryBrowserSelection::Add (const CItem* item)
{
    if (item == NULL)
        return;

    // extract the info from the list item

    SPath path;
    CString absPath = item->absolutepath;

    absPath.Replace (L"\\", L"%5C");
    path.url = CTSVNPath (absPath);

    // we don't fully escape the urls, because the GetSVNApiPath() method
    // of the CTSVNPath already does escaping.
    // We only escape special chars here:
    // the '%' because we know that this char isn't escaped yet, and
    // the '"' char, because we pass these urls to the command line as well
    absPath.Replace (L"%", L"%25");
    absPath.Replace (L"\"", L"%22");
    path.urlEscaped = CTSVNPath (absPath);

    path.isExternal = item->is_external;
    path.isFolder = item->kind == svn_node_dir;
    path.isLocked = !item->locktoken.IsEmpty();

    // store & accumulate in the corresponding repository bucket

    InternalAdd (item->repository, path);
}
Exemplo n.º 3
0
void ContactAsyncQueue::Add(int waitTime, HANDLE hContact, void *param)
{
	Lock();

	InternalAdd(waitTime, hContact, param);
	
	Release();
}
void CDownloadWithSources::Serialize(CArchive& ar, int nVersion)	// DOWNLOAD_SER_VERSION
{
	CDownloadBase::Serialize( ar, nVersion );

	CQuickLock pLock( Transfers.m_pSection );

	if ( ar.IsStoring() )
	{
		DWORD_PTR nSources = GetCount();
		if ( nSources > Settings.Downloads.SourcesWanted )
			nSources = Settings.Downloads.SourcesWanted;
		ar.WriteCount( nSources );

		for ( POSITION posSource = GetIterator() ; posSource && nSources ; nSources-- )
		{
			CDownloadSource* pSource = GetNext( posSource );

			pSource->Serialize( ar, nVersion );
		}

		ar.WriteCount( m_pXML != NULL ? 1 : 0 );
		if ( m_pXML ) m_pXML->Serialize( ar );
	}
	else // Loading
	{
		for ( DWORD_PTR nSources = ar.ReadCount() ; nSources ; nSources-- )
		{
			// Create new source
			//CDownloadSource* pSource = new CDownloadSource( (CDownload*)this );
			CAutoPtr< CDownloadSource > pSource( new CDownloadSource( static_cast< CDownload* >( this ) ) );
			if ( ! pSource )
				AfxThrowMemoryException();

			// Load details from disk
			pSource->Serialize( ar, nVersion );

			// Extract ed2k client ID from url (m_pAddress) because it wasn't saved
			if ( ! pSource->m_nPort && _tcsnicmp( pSource->m_sURL, _T("ed2kftp://"), 10 ) == 0 )
			{
				CString strURL = pSource->m_sURL.Mid(10);
				if ( ! strURL.IsEmpty() )
					_stscanf( strURL, _T("%lu"), &pSource->m_pAddress.S_un.S_addr );
			}

			InternalAdd( pSource.Detach() );
		}

		if ( ar.ReadCount() )
		{
			m_pXML = new CXMLElement();
			if ( ! m_pXML )
				AfxThrowMemoryException();

			m_pXML->Serialize( ar );
		}
	}
}
Exemplo n.º 5
0
void ContactAsyncQueue::AddAndRemovePreviousConsiderParam(int waitTime, HANDLE hContact, void *param)
{
	Lock();

	RemoveAllConsiderParam(hContact, param);
	InternalAdd(waitTime, hContact, param);

	Release();
}
Exemplo n.º 6
0
/**
 * This method adds the desired new item.
 *
 * @param		waitTime	- the time to wait until the callback is desired to run
 * @param		hContact	- the contact to perform the action for
 * @param		param			- a caller defined parameter passed to the callback function
 *
 * @retval	TRUE	- The item is added to the queue successfully.
 * @retval	FALSE	- The item is not added to the queue.
 **/
BOOL CContactQueue::Add(int waitTime, HANDLE hContact, PVOID param)
{
	BOOL rc;

	Lock();

	rc = InternalAdd(waitTime, hContact, param);

	Release();

	return rc;
}
Exemplo n.º 7
0
/**
 * This method removes all existing queue items for the contact with the same parameter as @e param
 * and adds a new queue item for the given contact. This method might be used to move an existing
 * entry, whose check_time has changed.
 *
 * @param		waitTime	- the time to wait until the callback is desired to run
 * @param		hContact	- the contact to perform the action for
 * @param		param			- a caller defined parameter passed to the callback function
 *
 * @retval	TRUE	- The item is added to the queue successfully.
 * @retval	FALSE	- The item is not added to the queue.
 **/
BOOL CContactQueue::AddUniqueConsiderParam(int waitTime, HANDLE hContact, PVOID param)
{
	BOOL rc;

	Lock();

	RemoveAllConsiderParam(hContact, param);
	rc = InternalAdd(waitTime, hContact, param);

	Release();

	return rc;
}
Exemplo n.º 8
0
/**
 * This method removes all existing queue items for the contact and adds a new queue item
 * for the given contact. This method might be used to move an existing entry, 
 * whose check_time has changed.
 *
 * @param		waitTime	- the time to wait until the callback is desired to run
 * @param		hContact	- the contact to perform the action for
 * @param		param			- a caller defined parameter passed to the callback function
 *
 * @retval	TRUE	- The item is added to the queue successfully.
 * @retval	FALSE	- The item is not added to the queue.
 **/
BOOL CContactQueue::AddUnique(INT waitTime, HANDLE hContact, PVOID param)
{
	BOOL rc;

	Lock();

	RemoveAll(hContact);
	rc = InternalAdd(waitTime, hContact, param);

	Release();

	return rc;
}
Exemplo n.º 9
0
void ContactAsyncQueue::AddIfDontHave(int waitTime, HANDLE hContact, void *param)
{
	Lock();

	int i;
	for (i = queue.getCount() - 1; i >= 0; --i)
		if (queue[i]->hContact == hContact)
			break;

	if (i < 0)
		InternalAdd(waitTime, hContact, param);

	Release();
}
Exemplo n.º 10
0
/**
 * This method adds the desired new item only, if the queue does not yet contain
 * an item for the contact.
 *
 * @param		waitTime	- the time to wait until the callback is desired to run
 * @param		hContact	- the contact to perform the action for
 * @param		param			- a caller defined parameter passed to the callback function
 *
 * @retval	TRUE	- The item is added to the queue successfully.
 * @retval	FALSE	- The item is not added to the queue.
 **/
BOOL CContactQueue::AddIfDontHave(int waitTime, HANDLE hContact, PVOID param)
{
	int i;
	BOOL rc;

	Lock();

	for (i = _queue.getCount() - 1; i >= 0; --i)
	{
		if (_queue[i]->hContact == hContact)
		{
			break;
		}
	}

	rc = (i == -1) ? InternalAdd(waitTime, hContact, param) : 0;

	Release();

	return rc;
}
Exemplo n.º 11
0
BOOL CDownloadWithSources::AddSourceInternal(CDownloadSource* pSource)
{
	if ( ! pSource )
		return FALSE;	// Out of memory

	if ( GetEffectiveSourceCount() > Settings.Downloads.SourcesWanted )
	{
		delete pSource;
		return FALSE;	// Too many sources
	}

	// Check/Reject if source is invalid
	if ( ! pSource->m_bPushOnly )
	{
		// Reject invalid IPs (Sometimes ed2k sends invalid 0.x.x.x sources)
		if ( pSource->m_pAddress.S_un.S_un_b.s_b1 == 0 || pSource->m_nPort == 0 )
		{
			delete pSource;
			return FALSE;
		}

		// Reject if source is the local IP/port
		if ( Network.IsSelfIP( pSource->m_pAddress ) )
		{
			if ( Settings.Connection.IgnoreOwnIP ||
				( pSource->m_nServerPort == 0 &&
				Settings.Connection.InPort == pSource->m_nPort ) )
			{
				delete pSource;
				return FALSE;
			}
		}
	}
	else if ( pSource->m_nProtocol == PROTOCOL_ED2K )
	{
		// Reject invalid server IPs (Sometimes ed2k sends invalid 0.x.x.x sources)
		if ( pSource->m_pServerAddress.S_un.S_un_b.s_b1 == 0 )
		{
			delete pSource;
			return FALSE;
		}
	}

	CQuickLock pLock( Transfers.m_pSection );

	if ( pSource->m_nRedirectionCount == 0 )	// Don't check for existing sources if source is a redirection
	{
		bool bDeleteSource = false;
		bool bHTTPSource = pSource->IsHTTPSource();
		bool bNeedHTTPSource = ! bHTTPSource &&
			Settings.Gnutella2.Enabled &&
			VendorCache.IsExtended( pSource->m_sServer );

		// Remove unneeded sources
		for ( POSITION posSource = GetIterator() ; posSource ; )
		{
			CDownloadSource* pExisting = GetNext( posSource );

			ASSERT( pSource != pExisting );
			if ( pExisting->Equals( pSource ) ) 	// IPs and ports are equal
			{
				bool bExistingHTTPSource = pExisting->IsHTTPSource();

				if ( bNeedHTTPSource && bExistingHTTPSource )
					bNeedHTTPSource = false;

				if ( ( pExisting->m_nProtocol == pSource->m_nProtocol ) ||
					 ( bExistingHTTPSource && bHTTPSource ) )
				{
					bDeleteSource = true;			// Same protocol
				}
				else if ( ! pExisting->IsIdle() )
				{
					// Already downloading so we can remove new non-HTTP source
					if ( bExistingHTTPSource && ! bHTTPSource )
						bDeleteSource = true;
				}
				else // We are not downloading
				{
					// ...So we can replace non-HTTP source with a new one
					if ( ! bExistingHTTPSource && bHTTPSource )
					{
						// Set connection delay the same as for the old source
						pSource->m_tAttempt = pExisting->m_tAttempt;
						pExisting->Remove( TRUE, FALSE );
					}
				}
			}
		}

		if ( bDeleteSource )
		{
			delete pSource;

			SetModified();

			return FALSE;
		}

		// Make additional G2 source from the existing non-HTTP PeerProject source
		if ( bNeedHTTPSource )
		{
			CString strURL = GetURL( pSource->m_pAddress, pSource->m_nPort );
			if ( ! strURL.IsEmpty() )
			{
				if ( CDownloadSource* pG2Source = new CDownloadSource( (CDownload*)this, strURL ) )
				{
					pG2Source->m_sServer = pSource->m_sServer;		// Copy user-agent
					pG2Source->m_tAttempt = pSource->m_tAttempt;	// Set the same connection delay
					pG2Source->m_nProtocol = PROTOCOL_HTTP;

					AddSourceInternal( pG2Source );
				}
			}
		}
	}

	InternalAdd( pSource );

	SetModified();

	return TRUE;
}