Ejemplo n.º 1
0
// -----------------------------------------------------------------------------
// CSIPMessage::ToTextHeaderPartLC
// -----------------------------------------------------------------------------
//
EXPORT_C CBufBase* CSIPMessage::ToTextHeaderPartLC ()
    {
    const TInt KResultBufExpandSize = 100;
    CBufFlat* encodedHeaderPart = CBufFlat::NewL(KResultBufExpandSize);
    CleanupStack::PushL(encodedHeaderPart);
	HBufC8* firstLine = ToTextFirstLineLC ();    
    encodedHeaderPart->InsertL (0,*firstLine);
    TInt encodedLength = firstLine->Length();
    CleanupStack::PopAndDestroy(firstLine);
    encodedHeaderPart->InsertL (encodedLength,KCRLF);
    encodedLength += KCRLF().Length();

    // Add headers
	for (TInt i=0; i < iSIPHeaderListArray.Count(); i++)
		{
		TSglQueIter<CSIPHeaderBase> iter(iSIPHeaderListArray[i]);
        TInt headerCountInList=0;
		while (iter)
			{
			CSIPHeaderBase* header = iter++;
            HBufC8* headerAsText = NULL;
            if (++headerCountInList == 1 || !header->EncodeMultipleToOneLine())
                {
			    headerAsText = header->ToTextLC();
                }
            else
                {
                headerAsText = header->ToTextValueLC();
                }
            encodedHeaderPart->InsertL (encodedLength,*headerAsText);
            encodedLength += headerAsText->Length();
            CleanupStack::PopAndDestroy(headerAsText);
            if (!iter || !header->EncodeMultipleToOneLine())
                {
                encodedHeaderPart->InsertL (encodedLength,KCRLF);
                encodedLength += KCRLF().Length();
                }
            else 
                {
                encodedHeaderPart->InsertL (encodedLength,KComma);
                encodedLength += KComma().Length();
                }
			}
		}

    // Add Content-Length header
	HBufC8* contentLengthHeaderAsText = ToTextContentLengthLC ();
    encodedHeaderPart->InsertL (encodedLength,*contentLengthHeaderAsText);
    encodedLength += contentLengthHeaderAsText->Length();
    CleanupStack::PopAndDestroy(contentLengthHeaderAsText);

    // Add CRLF CRLF ending the header part
    encodedHeaderPart->InsertL (encodedLength,KCRLFCRLF);
    encodedLength += KCRLFCRLF().Length();

    return encodedHeaderPart;
    }
Ejemplo n.º 2
0
EXPORT_C HBufC8* CSTBencodedList::BencodeL() const
{
	CBufFlat* buf = CBufFlat::NewL(128);
	CleanupStack::PushL(buf);
	
	buf->InsertL(0, _L8("l"));
	
	for (TInt i=0; i<iItems.Count(); i++)
	{
		HBufC8* bencodedItem = iItems[i]->BencodeL();
		CleanupStack::PushL(bencodedItem);
		buf->InsertL(buf->Size(), *bencodedItem);
		CleanupStack::PopAndDestroy(); // bencodedItem		
	}
	
	buf->InsertL(buf->Size(), _L8("e"));
	
	HBufC8* bencodedData = buf->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(); // buf	
	
	return bencodedData;
}
void CBlueJackImpl::SendMessageL(const TBTDevAddr& aToAddress,
	const TDesC& aWithDeviceName,
	const TDesC& aWithMessageName,
	const TDesC8& aMessage,
	TInt	aConnectCount)
{
	CALLSTACKITEM_N(_CL("CBlueJackImpl"), _CL("SendMessageL"));

#ifndef NO_BT
	iSettings->SetLocalBTName(aWithDeviceName);
#endif

	iBuffer->Reset();
	iBuffer->InsertL(0, aMessage);
	iObject->SetTypeL(_L8("text/plain"));
	iObject->SetNameL(aWithMessageName);
	iObject->SetDescriptionL(_L("description of message"));

	iObex->SendMessage(aToAddress, iObject, aConnectCount);
}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::GetProcessDataL
// ----------------------------------------------------------------------------------------
CBufFlat* CTerminalControlServer::GetProcessDataL( const TDesC8 &aProcessName, TDesC8 &aDataName )
{
    RDEBUG("CTerminalControlServer::GetProcessDataL");

    _LIT8(KProcessDataFormat,
          "\
<process-information name=\"%S\">\r\n\
\t<process-data name=\"%S\" value=\"%S\"/>\r\n\
</process-information>\r\n\
");

    TTcProcessInfo info = FindLocalProcessInfoL( aProcessName );

    CBufFlat* processData;
    processData = 0;
    processData = CBufFlat::NewL(128);
    CleanupStack::PushL( processData );

    // Set process data
    if(aDataName == _L8("ID"))
    {
        TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
        numBuf.Num((TUint)info.iId);
        processData->InsertL(0, numBuf);
    }
    else if(aDataName == _L8("FromRAM"))
    {
        TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
        numBuf.Num((TUint)!info.iCodeInRom);
        processData->InsertL(0, numBuf);
    }
    else if(aDataName == _L8("MemoryInfo"))
    {
        TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> valueBuf;
        valueBuf.Num((TUint)info.iMemoryInfo.iCodeSize+
                     info.iMemoryInfo.iConstDataSize+
                     info.iMemoryInfo.iInitialisedDataSize+
                     info.iMemoryInfo.iUninitialisedDataSize);

        TInt responseLength = KProcessDataFormat().Length() + aProcessName.Length()
                              + aDataName.Length() + valueBuf.Length();

        HBufC8* buffer = HBufC8::NewLC( responseLength );

        buffer->Des().Format( KProcessDataFormat, &aProcessName, &aDataName, &valueBuf );
        processData->InsertL(0, *buffer);

        CleanupStack::PopAndDestroy( buffer );
    }
    else if(aDataName == _L8("Filename"))
    {
        TBuf8<sizeof(TFileName)> fname;
        fname.Copy(info.iFileName);
        processData->InsertL(0, fname);
    }
    else
    {
        User::Leave( KErrNotFound );
    }

    CleanupStack::Pop( processData );

    return processData;
}
// ----------------------------------------------------------------------------------------
// CTerminalControlServer::GetRunningProcessesL
// ----------------------------------------------------------------------------------------
CBufFlat* CTerminalControlServer::GetRunningProcessesL( )
{
    RDEBUG("CTerminalControlServer::GetRunningProcessesL");

    TFullName    processName;
    TFindProcess findProcess;
    CBufFlat *buffer = CBufFlat::NewL(128);
    iProcessInfoArray->Reset();

    while( KErrNone == findProcess.Next( processName ) )
    {
        TTcProcessInfo info;
        RProcess process;

        if( KErrNone == process.Open( findProcess ) )
        {
            //
            // Add process information to local array
            //
            info.iProcessName = processName;
            info.iFileName    = process.FileName();

            info.iHandle      = process.Handle();
            info.iId          = process.Id();
            info.iSecureId    = process.SecureId();

            info.iProtected   = EFalse;

            process.GetMemoryInfo( info.iMemoryInfo );

            User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            if( !info.iCodeInRom )
            {
                User::IsRomAddress( info.iCodeInRom, (TAny*)(info.iMemoryInfo.iCodeBase) );
            }

            iProcessInfoArray->AppendL( info );

            //
            // Add process also to return buffer
            //
            /*
            TInt appendPosition = buffer->Size();
            if(iProcessInfoArray->Count() >= 2)
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, proName);
                }
            else
                {
                TBuf8<sizeof(info.iProcessName)> proName;
                proName.Copy(info.iProcessName);
                buffer->InsertL(appendPosition, proName);
                }
            }

            */

            // Enumerate names from 1
            TInt appendPosition = buffer->Size();
            TBuf8<MAX_NUMBER_OF_DIGITS_IN_10BASE_INT64> numBuf;
            TBuf8<sizeof(KFormatProcessNamePrefix)+20> nameBuf;

            numBuf.Num(iProcessInfoArray->Count());
            nameBuf.Zero();
            nameBuf.Append(KFormatProcessNamePrefix);
            nameBuf.Append(numBuf);

            if(iProcessInfoArray->Count() >= 2)
            {
                buffer->InsertL(appendPosition, _L8("/"));
                buffer->InsertL(appendPosition+1, nameBuf);
            }
            else
            {
                buffer->InsertL(appendPosition, nameBuf);
            }
        }
    }
    /*
    	TUint32 flags = Exec::ProcessFlags(KCurrentProcessHandle);
    	if (flags & KProcessFlagSystemPermanent)
    		return ESystemPermanent;
    	if (flags & KProcessFlagSystemCritical)
    		return ESystemCritical;
    	if (flags & KThreadFlagProcessPermanent)
    		return EAllThreadsCritical;
    	return ENotCritical;
    */
    return buffer;
}
// ---------------------------------------------------------
// CT_LbsClientPosTp261::StartL
//
// (other items were commented in a header).
// ---------------------------------------------------------
//
void CT_LbsClientPosTp261::StartL()
    {
    _LIT(KService1, "Service1");
    _LIT(KService2, "Service2");
    _LIT(KService3, "Service3");

    _LIT(KContact1, "Contact1");
    _LIT(KContact2, "Contact2");
    _LIT(KContact3, "Contact3");

    CRequestor* serviceId1 = 
		CRequestor::NewL(CRequestor::ERequestorService, CRequestor::EFormatApplication, 
                    KService1);

    CRequestor* serviceId2 = 
        CRequestor::NewL(CRequestor::ERequestorService, CRequestor::EFormatApplication, 
                    KService2);

    CRequestor* serviceId3 = 
        CRequestor::NewL(CRequestor::ERequestorService, CRequestor::EFormatApplication, 
                    KService3);

    CRequestor* contactId1 = 
        CRequestor::NewL(CRequestor::ERequestorContact, CRequestor::EFormatTelephone, 
                    KContact1);

    CRequestor* contactId2 = 
        CRequestor::NewL(CRequestor::ERequestorContact, CRequestor::EFormatUrl, 
                    KContact2);

    CRequestor* contactId3 = 
        CRequestor::NewL(CRequestor::ERequestorContact, CRequestor::EFormatMail, 
                    KContact3);

    RRequestorStack stack = RRequestorStack();
    CleanupStack::PushL(TCleanupItem(CleanOp ,&stack));

    CleanupStack::PushL(serviceId1);
    CleanupStack::PushL(serviceId2);
    CleanupStack::PushL(serviceId3);
    CleanupStack::PushL(contactId1);
    CleanupStack::PushL(contactId2);
    CleanupStack::PushL(contactId3);
    
    ConnectL();
    OpenPositioner();
    
    stack.Append(serviceId1);
    stack.Append(contactId1);
    stack.Append(contactId2);
    stack.Append(serviceId2);
    stack.Append(contactId3);
    stack.Append(serviceId3);

    CleanupStack::Pop(contactId3);
    CleanupStack::Pop(contactId2);
    CleanupStack::Pop(contactId1);
    CleanupStack::Pop(serviceId3);
    CleanupStack::Pop(serviceId2);
    CleanupStack::Pop(serviceId1);

    TInt err = iPositioner.SetRequestor(stack);
    if (err != KErrNone)
    	{
    	_LIT(KErrorAndLeave, "Problems setting requestorstack");
    	LogErrorAndLeaveL(KErrorAndLeave);
    	}
    	
    const TInt KPosBufFlatExpandSize = 100;
    
    //ExternalizeL
    CBufFlat* bufFlat = CBufFlat::NewL(KPosBufFlatExpandSize);
    CleanupStack::PushL(bufFlat);
    
    RBufWriteStream stream(*bufFlat);
    CleanupClosePushL(stream);        
    stack.ExternalizeL(stream);
    
    TPtr8 dataPtr((TUint8*)NULL, 0);
    dataPtr.Set(bufFlat->Ptr(0));    

    CleanupStack::PopAndDestroy(&stream);                

    HBufC8* tempBuf = HBufC8::NewLC(bufFlat->Size());
    TPtr8 ptr = tempBuf->Des();
    ptr = dataPtr;
    
    //Internalize
    bufFlat->InsertL(0, ptr);
    
    RBufReadStream rstream(*bufFlat);
    CleanupClosePushL(rstream);
    
    RRequestorStack stack2 = RRequestorStack();
    CleanupStack::PushL(TCleanupItem(CleanOp ,&stack2));

    stack2.InternalizeL(rstream);
    
    // Verify the requestor stack
    VerifyRequestorStackL(stack2);
    _LIT(KResult, "The RequestorStack is correct after Externalize/Internalize");
    INFO_PRINTF1(KResult);

    CleanupStack::PopAndDestroy(1); // CleanupOp stack2

    CleanupStack::PopAndDestroy(&rstream);
    CleanupStack::PopAndDestroy(tempBuf);
    CleanupStack::PopAndDestroy(bufFlat);
    CleanupStack::PopAndDestroy(1); // CleanupOp stack1

    ClosePositioner();
    Disconnect();
    }
Ejemplo n.º 7
0
void CSTTrackerConnection::CreateUriL()
{
	TInetAddr localAddress;
	TInt getAddressRes = KErrGeneral;
	// only send IP if we are connected via proxy
	//if (Preferences()->IncomingConnectionsMode() == EEnabledWithProxy)
	//	getAddressRes = iNetMgr->Address(localAddress);
	
	CBufFlat* uriBuf = CBufFlat::NewL(512);
	CleanupStack::PushL(uriBuf);
	
	//TPtrC8 activeTracker = iTorrent.AnnounceList()->ActiveAddress();
	//LWRITE(iLog, _L("Active tracker: "));
	//LWRITELN(iLog, activeTracker);
	
	uriBuf->InsertL(uriBuf->Size(), *iAddress);
	uriBuf->InsertL(uriBuf->Size(), _L8("?"));
	
	uriBuf->InsertL(uriBuf->Size(), _L8("info_hash="));	
	HBufC8* encoded = EscapeUtils::EscapeEncodeL(iTorrent.InfoHash(), EscapeUtils::EEscapeUrlEncoded);
	CleanupStack::PushL(encoded);
	uriBuf->InsertL(uriBuf->Size(), *encoded);
	CleanupStack::PopAndDestroy(); // encoded
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&peer_id="));
	encoded = EscapeUtils::EscapeEncodeL(TorrentMgr()->PeerId(), EscapeUtils::EEscapeUrlEncoded);
	CleanupStack::PushL(encoded);
	uriBuf->InsertL(uriBuf->Size(), *encoded);
	CleanupStack::PopAndDestroy(); // encoded
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&key="));
	TBuf8<32> keyBuf;
	keyBuf.Num(TorrentMgr()->Key());
	uriBuf->InsertL(uriBuf->Size(), keyBuf);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&port="));
	TBuf8<32> portBuf;
	if (getAddressRes == KErrNone)
		portBuf.Num(localAddress.Port());
	else
		portBuf.Num(Preferences()->IncomingPort());
	uriBuf->InsertL(uriBuf->Size(), portBuf);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&uploaded="));
	TBuf8<24> bytesUploaded;
	bytesUploaded.Num(iTorrent.BytesUploaded());
	uriBuf->InsertL(uriBuf->Size(), bytesUploaded);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&downloaded="));
	TBuf8<24> bytesDownloaded;
	bytesDownloaded.Num(iTorrent.BytesDownloaded());
	uriBuf->InsertL(uriBuf->Size(), bytesDownloaded);
	
	uriBuf->InsertL(uriBuf->Size(), _L8("&left="));
	TBuf8<24> bytesLeft;
	bytesLeft.Num(iTorrent.BytesLeft());
	uriBuf->InsertL(uriBuf->Size(), bytesLeft);

	// it seems that some trackers support only compact responses
	uriBuf->InsertL(uriBuf->Size(), _L8("&compact=1"));

	if (iEvent != ETrackerEventNotSpecified)
	{
		uriBuf->InsertL(uriBuf->Size(), _L8("&event="));
		
		switch (iEvent)
		{
			case ETrackerEventStarted:
				uriBuf->InsertL(uriBuf->Size(), _L8("started"));
			break;
			
			case ETrackerEventStopped:
				uriBuf->InsertL(uriBuf->Size(), _L8("stopped"));
			break;
			
			case ETrackerEventCompleted:
				uriBuf->InsertL(uriBuf->Size(), _L8("completed"));
			break;
			
			default:
			break;
		}
	}
	
	if (getAddressRes == KErrNone)
	{
		TBuf<64> ipBuf;
		localAddress.Output(ipBuf);
		TBuf8<64> ipBuf8;
		ipBuf8.Copy(ipBuf);
		
		uriBuf->InsertL(uriBuf->Size(), _L8("&ip="));
		uriBuf->InsertL(uriBuf->Size(), ipBuf8);
		
		#ifdef LOG_TO_FILE
		// debug info
		LWRITE(iLog, _L("Sent to tracker: "));
		LWRITE(iLog, ipBuf);
		TBuf8<32> portBuf;
		portBuf.Num(localAddress.Port());
		LWRITE(iLog, _L(":"));
		LWRITELN(iLog, portBuf);
		#endif
		//		
	}
	
	iUri = uriBuf->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(); // uriBuf
	
	//iLog->WriteL(_L("[Trackerconnection] GET "));
	//iLog->WriteLineL(*iUri);
}