void CSTTrackerConnection::HTTPSessionOpenedL(TBool aResult, RHTTPSession& /*aHTTPSession*/)
{
	if (aResult)
	{
		// starts listening before connecting to the tracker
		// TODO this should be called from the torrent / torrentmanager
		iTorrent.TorrentMgr()->NetworkManager()->StartListeningL(
				0, iTorrent.Preferences()->IncomingPort());
		
		CreateUriL();
		
		// Parse string to URI (as defined in RFC2396)
		TUriParser8 uri;
		uri.Parse(*iUri);

		// Get request method string for HTTP GET
		RStringF method = iSession.StringPool().StringF(HTTP::EGET,
			RHTTPSession::GetTable());
			


		// Open transaction with previous method and parsed uri. This class will
		// receive transaction events in MHFRunL and MHFRunError.
		iTransaction = iSession.OpenTransactionL(uri, *this, method);

		// Set headers for request; user agent and accepted content type
		RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
		SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
		SetHeaderL(hdr, HTTP::EAccept, KAccept);

		// Submit the transaction. After this the framework will give transaction
		// events via MHFRunL and MHFRunError.
		LWRITE(iLog, _L("[Trackerconnection] Starting transaction: GET "));
		LWRITELN(iLog, *iUri);
		iTransaction.SubmitL();

		iRunning = ETrue;
		iConnectionTimeout->Reset(KMaxTrackerAnnounceTime * 1000);
	}
	else
	{
		LWRITE(iLog, _L("[Trackerconnection] Failed "));
		if (iObserver)
			iObserver->TrackerConnectionFailedL();
		
		/*iTorrent.SetFailedL(_L("Failed to establish network connection."));*/
	}
}
// -----------------------------------------------------------------------------
// CMessageMonitorPlugin::HandleMsgCreatedChangedL
// -----------------------------------------------------------------------------
//
void CMessageMonitorPlugin::HandleMsgCreatedChangedL( const CMsvEntrySelection& aSelection,
                                          	   		  const TMsvId aFolderId,
                                          	          const TMsvSessionEvent aEvent )
	{
	WRITELOG("ENTER CMessageMonitorPlugin::HandleMsgCreatedChangedL");
	
	TInt count( aSelection.Count() );
	
    // cycle through every message in the CMsvEntrySelection
	for ( TInt i=0; i < count; ++i )
		{
		// extract the message server entry from the parameters
		TMsvId msgId = aSelection[i];
		WRITELOG1("msgId: %d", msgId );					
		
        TMsvId service = 0;
        TMsvEntry entry;
		TInt err = iMsvSession->GetEntry( msgId, service, entry );

		WRITELOG1("HandleMsgCreatedChangedL error: %d ", err);		
		
		THarvesterEventType event = 
						( aEvent == EMsvEntriesCreated ) || entry.Unread() ? 
						  	  								 EHarvesterAdd : 
															 EHarvesterEdit;
		
        
        // ... we only want to process message entries, that are in the inbox
        // ... and are valid for adding to Mds.
        if ( ( !err ) && 
            ( KUidMsvMessageEntry == entry.iType ) && 
            ( KMsvGlobalInBoxIndexEntryId == aFolderId ) &&
            ( entry.Visible() && entry.Complete() && !entry.InPreparation() ) &&
            ( IsValidMessageTypeL( entry, *iMsvSession ) ) )
            {
            HBufC* uri = CreateUriL( entry.iMtm, msgId );    
            CleanupStack::PushL( uri );
            CHarvesterData* hd = CHarvesterData::NewL( uri );
            CleanupStack::Pop( uri );
            hd->SetEventType( event );
            hd->SetBinary( EFalse );
            hd->SetTakeSnapshot( EFalse );
			iMonitorPluginObserver->MonitorEvent( hd );
            }
        }
	WRITELOG("END CMessageMonitorPlugin::HandleMsgCreatedChangedL");	        
	}
// -----------------------------------------------------------------------------
// CMessageMonitorPlugin::HandleMsgDeletedL
// -----------------------------------------------------------------------------
//
void CMessageMonitorPlugin::HandleMsgDeletedL( const CMsvEntrySelection& aSelection )
	{
	WRITELOG("ENTER CMessageMonitorPlugin::HandleMsgDeletedL");
	
	TInt count( aSelection.Count() );	
	// cycle through every message in the CMsvEntrySelection
	for( TInt i = 0; i < count; ++i )
		{
		TMsvId msgId = aSelection[i];	
		WRITELOG1("msgId: %d", msgId );
		HBufC* uri = CreateUriL( KUidMsgTypeSMS, msgId );
		CleanupStack::PushL( uri );
		RemoveObjectL( *uri );
		CleanupStack::PopAndDestroy( uri );
		}
	WRITELOG("END CMessageMonitorPlugin::HandleMsgDeletedL");	
	}	
void CExampleInetProtUtil::ConstructL()
	{	
	
	iConsole = Console::NewL(KTest,TSize(KConsFullScreen,KConsFullScreen));
	iConsole->Printf ( KTest );
	_LIT(KTextStart, "\nPress any key to step through the example");
	iConsole->Printf ( KTextStart );
	iConsole->Getch ();

	//Create an URI
	CreateUriL();  

	//Modify URI components
	ModifyUriComponentsL();
	
	//Resolve
	ResolveUriL();
	
	//Parse the URI
	ParseUriL();
	
	//Validate URI components
	ValidateUriComponentsL();
	
	//Extract URI components
	ExtractUriComponentsL();
	
	//Retrieve Filename from a given Uri
	RetrieveFileNameL();
	
	//Add and Trim delimiters
	ModifyDelimiterL();
	
	//Text Utilities
	WhiteSpaceRemover();
	
	//Escape encode and decode
	EscapeEncodeDecodeL();	
	}
// -----------------------------------------------------------------------------
// CMessageMonitorPlugin::HandleMsgMovedL
// -----------------------------------------------------------------------------
//
void CMessageMonitorPlugin::HandleMsgMovedL( const TMsvId aFolderId1, 
											 const TMsvId aFolderId2, 
								   			 const CMsvEntrySelection& aSelection )
	{
	
	
	
	WRITELOG("ENTER CMessageMonitorPlugin::HandleMsgMovedL");
	
	TInt count( aSelection.Count() );
	// cycle through every message in the CMsvEntrySelection
	for ( TInt i=0; i < count; ++i )
		{
		TMsvId msgId = aSelection[i];
		WRITELOG1("msgId: %d", msgId );					
		
		TMsvId service = 0;
        TMsvEntry entry;
		TInt err = iMsvSession->GetEntry( msgId, service, entry );

        // if we have a message and it has been moved from the outbox to the sent 
        // items, and it is a valid message
        if ( ( !err ) &&
            ( KUidMsvMessageEntry == entry.iType ) &&
            ( KMsvSentEntryId == aFolderId1 ) &&
            ( KMsvGlobalOutBoxIndexEntryId == aFolderId2 ) && 
            ( IsValidMessageTypeL( entry, *iMsvSession ) ) )
            {            
            HBufC* uri = CreateUriL( entry.iMtm, msgId );
            CleanupStack::PushL( uri );
            CHarvesterData* hd = CHarvesterData::NewL( uri );
            CleanupStack::Pop( uri );
            hd->SetEventType( EHarvesterAdd );
            hd->SetTakeSnapshot( EFalse );
            hd->SetBinary( EFalse );
            iMonitorPluginObserver->MonitorEvent( hd );
            }
            
               
#ifdef __WINSCW__
		else if (!err && KMsvDraftEntryId == aFolderId2 && KMsvGlobalOutBoxIndexEntryId == aFolderId1 )
			{
		    if( entry.iMtm.iUid != KUidMsgTypeMultimedia.iUid )
		        {
                CClientMtmRegistry* clientMtmReg;
                clientMtmReg = CClientMtmRegistry::NewL(*iMsvSession);
                CleanupStack::PushL(clientMtmReg);
            
                CSmsClientMtm* smsMtm = static_cast<CSmsClientMtm*>(clientMtmReg->NewMtmL(KUidMsgTypeSMS)); 
                CleanupStack::PushL(smsMtm);
                smsMtm->SwitchCurrentEntryL( msgId );
            
                TMsvSelectionOrdering selection;
                selection.SetShowInvisibleEntries(ETrue);
            
                CMsvEntry* parentEntry = CMsvEntry::NewL( smsMtm->Session(),
                    smsMtm->Entry().Entry().Parent(), selection );
             
                CleanupStack::PushL(parentEntry);
                // Move the message
                TRAP_IGNORE( parentEntry->MoveL( msgId, KMsvSentEntryId ) );
                CleanupStack::PopAndDestroy(3,clientMtmReg); // parentEntry
		        }
			}
#endif             
		
        }
	WRITELOG("END CMessageMonitorPlugin::HandleMsgMovedL");	        
	}