示例#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((""));
    }
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((""));
    }
// -----------------------------------------------------------------------------
// CCommonTestClass::ExternalizeMPXCollectionTypeL()
// Returns: Symbian OS errors.
// -----------------------------------------------------------------------------
TInt CCommonTestClass::ExternalizeMPXCollectionTypeL()
    {
	FTRACE(FPrint(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL testing CMPXCollectionType::ExternalizeMPXCollectionTypeL begin")));
    iLog->Log(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL testing CMPXCollectionType::ExternalizeMPXCollectionTypeL begin"));
    TInt err = KErrNone;
    if ( iType != NULL )
        {
    	FTRACE(FPrint(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL started Externalize")));
        iLog->Log(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL started Externalize"));
        CBufBase* buffer = CBufFlat::NewL( 50 );
        CleanupStack::PushL( buffer );
        RBufWriteStream writeStream( *buffer );
        CleanupClosePushL( writeStream );
        iType->ExternalizeL( writeStream );
        writeStream.CommitL();
        buffer->Compress();
        CleanupStack::PopAndDestroy( &writeStream );
        CleanupStack::PopAndDestroy( buffer ); 
        }
    else
        {
        err = KErrBadTestParameter;
    	FTRACE(FPrint(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL Stif test script is wrong.")));
        iLog->Log(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL Stif test script is wrong."));
        }
	FTRACE(FPrint(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL testing CMPXCollectionType::ExternalizeMPXCollectionTypeL end err=%d"), err));
    iLog->Log(_L("CCommonTestClass::ExternalizeMPXCollectionTypeL testing CMPXCollectionType::ExternalizeMPXCollectionTypeL end err=%d"), err);
	return err;
    }
示例#4
0
// -----------------------------------------------------------------------------
// CSIPMessage::ToTextLC
// -----------------------------------------------------------------------------
//
EXPORT_C CBufBase* CSIPMessage::ToTextLC ()
	{
    CBufBase* encodedMessage = ToTextHeaderPartLC();
    TInt length = encodedMessage->Ptr(0).Length();
    encodedMessage->InsertL (length,*iContent);
	return encodedMessage;
	}
// -----------------------------------------------------------------------------
// CNATFWUNSAFMessage::EncodeMessageHeaderLC
// -----------------------------------------------------------------------------
//
CBufBase* CNATFWUNSAFMessage::EncodeMessageHeaderLC() const
{
    CBufBase* header = CBufFlat::NewL(EHeaderSize);
    CleanupStack::PushL(header);

    TUint16 messageType = Type();
    TUint16 bigEndianType(0);
    BigEndian::Put16(reinterpret_cast<TUint8*>(&bigEndianType), messageType);
    //First two bits of a STUN message are zero
    bigEndianType = bigEndianType & EMessageTypeMask;
    header->InsertL(EMessageTypeOffset, &bigEndianType, sizeof(bigEndianType));


    TUint16 msgLength = 0;
    //Value is zero, so it is same also in the big endian representation
    header->InsertL(EMessageLengthOffset, &msgLength, sizeof(msgLength));

    TUint32 bigEndianCookie(0);
    BigEndian::Put32(reinterpret_cast<TUint8*>(&bigEndianCookie), EMagicCookie);
    header->InsertL(EMagicCookieOffset,
                    &bigEndianCookie,
                    sizeof(bigEndianCookie));

    header->InsertL(ETransactionIDOffset,
                    iTransactionID,
                    KMaxNATFWUNSAFTransactionIdLength);
    return header;
}
// -----------------------------------------------------------------------------
//  CNSmlDmDevDetailAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
// const TDesC8& aLUID, const TDesC8& aType, const TInt aResultsRef, 
// const TInt aStatusRef )
// -----------------------------------------------------------------------------
void CNSmlDmDevDetailAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
                                                    const TDesC8& /*aLUID*/, 
                                                    const TDesC8& aType, 
                                                    const TInt aResultsRef, 
                                                    const TInt aStatusRef )
    {
    _DBG_FILE("CNSmlDmDevDetailAdapter::FetchLeafObjectSizeL(): begin");

    CBufBase *object = CBufFlat::NewL( 1 );
    CleanupStack::PushL( object );
    CSmlDmAdapter::TError retValue = FetchLeafObjectL( aURI, *object );

    TInt objSizeInBytes = object->Size();
    TBuf8<KNSmlMaxSizeBufferLength> stringObjSizeInBytes;
    stringObjSizeInBytes.Num( objSizeInBytes );
    object->Reset();
    object->InsertL( 0, stringObjSizeInBytes );
    
    iDmCallback->SetStatusL( aStatusRef, retValue );
    iDmCallback->SetResultsL( aResultsRef, *object, aType);
    CleanupStack::PopAndDestroy(); //object 

            
    _DBG_FILE("CNSmlDmDevDetailAdapter::FetchLeafObjectSizeL(): end");
    }
void ut_cstunbinding::UT_CSTUNBinding_HandleDataLL(  )
    {
    _LIT8( KPassword,"aaaabbbbccccdddd");
    TBufC8<16> password( KPassword );
    _LIT8( KTransactionId,"aaaabbbb");
    TNATFWUNSAFTransactionID transactionID;
    transactionID.Copy( KTransactionId );    
    
    CNATFWUNSAFBindingRequest* request = CNATFWUNSAFBindingRequest::NewLC( transactionID );
    CBufBase* msg = request->EncodeL( password );
    CleanupStack::PushL( msg );        
    TInt length = msg->Size();
    HBufC8* readBuf1 = HBufC8::NewLC( length );
    TPtr8 writable1( readBuf1->Des() );
    msg->Read( 0, writable1 );
    
    TInetAddr remoteAddr;
    TBool consumed = EFalse;    
    HBufC8* ptr = iBinding->HandleDataL( *readBuf1, consumed, remoteAddr );    
    EUNIT_ASSERT( NULL == ptr );             
    EUNIT_ASSERT( EFalse == consumed );
    
    delete ptr;
    CleanupStack::PopAndDestroy( readBuf1 );
    CleanupStack::PopAndDestroy( msg );
    CleanupStack::PopAndDestroy( request );  
    }
示例#8
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;
	}
//Encode UNSAF message with two attributes
void UT_CNATFWUNSAFMessage::TestEncode4L()
    {
    const TUint8 KExpectedResult[] =
        {
        0, 1, //UNSAF message type: Binding Request
        0, 36, //Message length
        0x21, 0x12, 0xa4, 0x42, //Magic cookie
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, //TransactionID

        //ERROR-CODE attribute
        0, 9,  //type
        0, 20, //length of value element
        0, 0, //zero
        2,  //class
        25, //number
        'E', 'r', 'r', 'o', //Reason Phrase
        'r', ' ', 'r', 'e',
        's', 'u', 'l', 't',
        ' ', 'n', 'o', 'w',

        //UNKNOWN-ATTRIBUTES attribute
        0, 0xa, //type
        0, 8, //length of value element
        0x12, 0x34, //first unknown attribute
        0xab, 0x0c,
        0xff, 0x90,
        0x12, 0x34        //repeated attribute
        };

    _LIT8(KReason, "Error result now");
    TInt responseCode = 225;
    CNATFWUNSAFAttribute* attr =
        CNATFWUNSAFErrorCodeAttribute::NewLC(responseCode, KReason);
    iMsg->AddAttributeL(attr);
    CleanupStack::Pop(attr);
    attr = NULL;

    TUint attrType = 0x1234;
    TUint attrType2 = 0xab0c;
    TUint attrType3 = 0xff90;

    CNATFWUNSAFUnknownAttributesAttribute* uaAttr =
        CNATFWUNSAFUnknownAttributesAttribute::NewLC();
    uaAttr->AddContainedAttributeL(attrType);
    uaAttr->AddContainedAttributeL(attrType2);
    uaAttr->AddContainedAttributeL(attrType3);

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

    CBufBase* msg = iMsg->EncodeL();

    CleanupStack::PushL(msg);
    EUNIT_ASSERT(CNATFWUNSAFMessage::EHeaderSize + 36 == msg->Size());
    CompareEncodedUNSAFMessageL(KExpectedResult, *msg);
    CleanupStack::PopAndDestroy(msg);
    }
示例#10
0
// ----------------------------------------------------------------------------
// 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 );
		}				
	}
// --------------------------------------------------------------------------
//  CNSmlDmAOAdapter::FetchLeafObjectSizeL
//  Fetches leaf object size.
// -------------------------------------------------------------------------
void CNSmlDmAOAdapter::FetchLeafObjectSizeL( const TDesC8& aURI, 
                                             const TDesC8& aLUID,
									         const TDesC8& /* aType */, 
									         TInt aResultsRef,
									         TInt aStatusRef )
    {
    LOGSTRING( "CNSmlDmAOAdapter::FetchLeafObjectSizeL: Start" );
    LOGSTRING3( "\tFetchLeafObjectSizeL  \tURI: %S, \tLUID: %S,", 
                         &aURI, &aLUID );
   
    CSmlDmAOCommandElement* cmd = 
    CSmlDmAOCommandElement::NewLC( ETrue, 
                                   aStatusRef, 
                                   aResultsRef, 
                                   CNSmlDmAOAdapter::EGetSizeCmd,
                                   LastURISeg( aURI ), 
                                   KNullDesC8);
                                   
    TInt luid( KDefaultLuid );
    
    if ( aLUID.Length() > 0 )
        {
        luid = DesToIntL( aLUID );    
        }
                                       
    iSettingStore->ExecuteCmdL( *cmd, luid );
    
    LOGSTRING2( "\tCmd executed with status: %d ", 
                          cmd->Status() );
    // if executed get status
    if ( cmd->Executed() ) 
        {
        Callback().SetStatusL( aStatusRef, cmd->Status() );            
        // if successful get results
        if ( cmd->Status() == CSmlDmAdapter::EOk )
            {
            LOGSTRING2( "\tCmd executed with result: %S ", 
                                  cmd->Data() );
            CBufBase* result = CBufFlat::NewL( cmd->Data()->Size() );
            CleanupStack::PushL( result );
            result->InsertL( 0, *cmd->Data() );
            Callback().SetResultsL( aResultsRef, *result, KNullDesC8 );
            CleanupStack::PopAndDestroy( result );
            }
        }
    else
        {
        // failed to execute command
        Callback().SetStatusL( aStatusRef, CSmlDmAdapter::EError );
        }
    
    CleanupStack::PopAndDestroy( cmd );
        
    LOGSTRING( "CNSmlDmAOAdapter::FetchLeafObjectSizeL: End" );
    }
示例#12
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);
    }
示例#13
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);
		}
	}
// ------------------------------------------------------------------------
//  CNSmlDmAOAdapter::ChildURIListL
//  Fetches child nodes of a node. these may be either all VENDORCONFIG 
//  nodes or leaf nodes under a VENDORCONFIG node. 
// ------------------------------------------------------------------------
void CNSmlDmAOAdapter::ChildURIListL( const TDesC8& aURI, 
                                      const TDesC8& aLUID,
					                  const CArrayFix<TSmlDmMappingInfo>& 
					                  /*aPreviousURISegmentList*/,
					                  TInt aResultsRef, 
					                  TInt aStatusRef )
    {
    LOGSTRING( "CNSmlDmAOAdapter::ChildURIListL: Start" );
    LOGSTRING3( "\tChildURIListL  URI: %S, LUID: %S ", 
                        &aURI, &aLUID );
    
    CBufBase* resultList = CBufFlat::NewL( KSmlMaxURISegLen );
    CleanupStack::PushL( resultList );
	
	// get all leaf nodes below VENDORCONFIG node
    if ( !aURI.Compare( KNSmlDmAOAdapterAO ) )
        {        
        CSmlDmAOCommandElement* cmd = 
        CSmlDmAOCommandElement::NewLC( EFalse, 
                                       aStatusRef,
                                       aResultsRef, 
                                       CNSmlDmAOAdapter::EGetCmd, 
                                       KNullDesC8, 
                                       KNullDesC8 );
                                       
        TInt luid( KDefaultLuid );
    
        if ( aLUID.Length() > 0 )
            {
            luid = DesToIntL( aLUID );    
            }
                                           
        iSettingStore->ExecuteCmdL( *cmd, luid );
        
        LOGSTRING2( "\tCmd executed with status: %d ", 
                              cmd->Status() );
   
        Callback().SetStatusL( aStatusRef, cmd->Status() );
        if( cmd->Status() == CSmlDmAdapter::EOk )
            {
            resultList->InsertL( 0, *cmd->Data() );
            Callback().SetResultsL( aResultsRef, 
                                    *resultList, 
                                    KNullDesC8 );
            } 
   
        CleanupStack::PopAndDestroy( cmd );               
        }        
   
    CleanupStack::PopAndDestroy( resultList );
    LOGSTRING( "CNSmlDmAOAdapter::ChildURIListL: End" );
    }
示例#15
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");
	}
示例#17
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);
    }
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
    }
//Encode UNSAF message with two attributes
void UT_CNATFWUNSAFMessage::TestEncode3L()
    {
    const TUint8 KExpectedResult[] =
        {
        0, 1, //UNSAF message type: Binding Request
        0, 24, //Message length
        0x21, 0x12, 0xa4, 0x42, //Magic cookie
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, //TransactionID

        //RESPONSE-ADDRESS attribute
        0, 2, //type
        0, 8, //length of value element
        0, //undefined
        1, //family
        0xab, 0xcd, //port
        5, 6, 7, 8, //address

        //MAPPED-ADDRESS attribute
        0, 1, //type
        0, 8, //length of value element
        0, //undefined
        1, //family
        0x12, 0x34, //port
        0x50, 0x40, 0xff, 0xaa //address
        };

    TInetAddr addr(INET_ADDR(5,6,7,8), 0xabcd);
    CNATFWUNSAFAttribute* attr =
        CNATFWUNSAFResponseAddressAttribute::NewLC(addr);
    iMsg->AddAttributeL(attr);
    CleanupStack::Pop(attr);
    attr = NULL;


    TInetAddr addr2(0x5040ffaa, 0x1234);
    attr = CNATFWUNSAFMappedAddressAttribute::NewLC(addr2);
    iMsg->AddAttributeL(attr);
    CleanupStack::Pop(attr);


    CBufBase* msg = iMsg->EncodeL();

    CleanupStack::PushL(msg);
    EUNIT_ASSERT(CNATFWUNSAFMessage::EHeaderSize + 24 == msg->Size());
    CompareEncodedUNSAFMessageL(KExpectedResult, *msg);

    CleanupStack::PopAndDestroy(msg);
    }
// -----------------------------------------------------------------------------
// CCommonTestClass::MpxAttStreamingL()
// Returns: Symbian OS errors.
// -----------------------------------------------------------------------------
TInt CCommonTestClass::MpxAttStreamingL(CStifItemParser& aItem)
    {
    FTRACE(FPrint(_L("CCommonTestClass::MpxAttStreamingL testing TMPXAttribute ExternalizeL and InternalizeL begin")));
    iLog->Log(_L("CCommonTestClass::MpxAttStreamingL testing TMPXAttribute ExternalizeL and InternalizeL begin"));
    TInt err=KErrNone;
    TUint index;
    
    // read in parameters
    if ( aItem.GetNextInt(index) )
        {
        iLog->Log(_L("Missing Parameter: index."));
        return KErrBadTestParameter;
        }
    if ( index >= iMPXAttArray.Count() )
        {
        iLog->Log(_L("Bad Parameter: index out of range."));
        return KErrBadTestParameter;
        }
    
    FTRACE(FPrint(_L("CCommonTestClass::MpxAttStreamingL started ExternalizeL")));
    iLog->Log(_L("CCommonTestClass::MpxAttStreamingL started ExternalizeL"));
    CBufBase* buffer = CBufFlat::NewL( 50 );
    CleanupStack::PushL( buffer );
    RBufWriteStream writeStream( *buffer );
    CleanupClosePushL( writeStream );
    iMPXAttArray[index].ExternalizeL( writeStream );
    writeStream.CommitL();
    buffer->Compress();
    CleanupStack::PopAndDestroy( &writeStream );

    FTRACE(FPrint(_L("CCommonTestClass::MpxAttStreamingL started InternalizeL")));
    iLog->Log(_L("CCommonTestClass::MpxAttStreamingL started InternalizeL"));
    RBufReadStream readStream( *buffer );
    CleanupClosePushL( readStream );                
    TMPXAttribute att;
    att.InternalizeL( readStream );
    CleanupStack::PopAndDestroy( &readStream );
    CleanupStack::PopAndDestroy( buffer );
    
    // verify streaming was correct
    if ( !TMPXAttribute::Match(att, iMPXAttArray[index]) )
        {
        iLog->Log(_L("Streaming Failed Verification."));
        err = KErrUnexpectedValue;
        }
    return err;
    }
示例#22
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;
	}
// --------------------------------------------------------------------------
// CNSmlDmAOAdapter::DDFVersionL
// Returns ddf version nr
// --------------------------------------------------------------------------
void CNSmlDmAOAdapter::DDFVersionL( CBufBase& aDDFVersion )
    {
    LOGSTRING( "CNSmlDmAOAdapter::DDFVersionL: Start" );
 
    aDDFVersion.InsertL( 0, KNSmlDmAOAdapterDDFVersion );
 
    LOGSTRING( "CNSmlDmAOAdapter::DDFVersionL:End" );
    }
//Encode UNSAF message without any attributes
void UT_CNATFWUNSAFMessage::TestEncodeL()
    {
    const TUint8 KExpectedResult[] =
        {
        0, 1, //UNSAF message type: Binding Request
        0, 0, //Message length
        0x21, 0x12, 0xa4, 0x42, //Magic cookie
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb //TransactionID
        };

    CBufBase* msg = iMsg->EncodeL();

    CleanupStack::PushL(msg);
    EUNIT_ASSERT(CNATFWUNSAFMessage::EHeaderSize == msg->Size());
    CompareEncodedUNSAFMessageL(KExpectedResult, *msg);
    CleanupStack::PopAndDestroy(msg);
    }
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;
    }
示例#27
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;
	}
// ----------------------------------------------------------------------------
// 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;
    }