Пример #1
0
TInt TCmdUNSAFTimers::FindIapKeyL( CRepository& aRepository,
								   TInt aIapId,
								   TUint32& aKey ) const
    {
    RArray<TUint32> keys;
    CleanupClosePushL( keys );
    TInt err = aRepository.FindL( KUNSAFProtocolsIAPIdMask,
                                  KUNSAFProtocolsFieldTypeMask,
                                  keys );
	TInt ret = KErrNotFound;
    if ( err == KErrNone && keys.Count() > 0 )
        {
        for ( TInt i = 0; i < keys.Count() && ret == KErrNotFound; i++ )
            {
            TUint32 key = ( KUNSAFProtocolsIAPIdMask ^ ( keys[ i ] ) );
            key |= KUNSAFProtocolsIAPTableMask;
 
  			TInt iapId( 0 );
            Read( aRepository, KUNSAFProtocolsIAPIdMask | key, iapId );

            if ( iapId == aIapId )
            	{
            	aKey = key;	            
	            ret = KErrNone;
            	}
            }
        }

    CleanupStack::PopAndDestroy( &keys );
    return ret;
    }
Пример #2
0
TUint32 TCmdUNSAFTimers::CreateNewKeyL( CRepository& aRepository,
										TUint32 aKey,
										TUint32 aTable ) const
    {
    const TUint32 KInitialKey = 1;
	TUint32 newKey = KInitialKey;
    RArray<TUint32> keys;
    CleanupClosePushL( keys );
    TInt err = aRepository.FindL( aKey,
                                  KUNSAFProtocolsFieldTypeMask,
                                  keys );
    if ( err != KErrNotFound )
        {
        User::LeaveIfError( err );
        TInt keyCount = keys.Count();
        if ( keyCount != 0 )
            {
            // Find the biggest key and increment it by one
            keys.SortUnsigned();
            TUint32 maxKey = aKey ^ keys[ keyCount - 1 ];
            newKey = maxKey + 1;
            }
        }

    newKey |= aTable;
    CleanupStack::PopAndDestroy( &keys );
    return newKey;
    }
Пример #3
0
TInt TCmdUNSAFTimers::FindDomainKeyL( CRepository& aRepository,							
									  TPtrC8 aDomain,
									  TUint32& aKey ) const
    {
    RArray<TUint32> keys;
    CleanupClosePushL( keys );
    TInt err = aRepository.FindL( KUNSAFProtocolsDomainMask,
                                  KUNSAFProtocolsFieldTypeMask,
                                  keys );
	TInt ret = KErrNotFound;
    if ( err == KErrNone && keys.Count() > 0 )
        {
        for ( TInt i = 0; i < keys.Count() && ret == KErrNotFound; i++ )
            {
            TUint32 key = ( KUNSAFProtocolsDomainMask ^ ( keys[ i ] ) );
            key |= KUNSAFProtocolsDomainTableMask;

            TBuf8<KMaxServerNameLen> domain;
            if ( ( Read( aRepository,
            		     KUNSAFProtocolsDomainMask | key,
                         domain ) == KErrNone ) &&
                 ( domain == aDomain ) )
        		{
        		aKey = key;     
                ret = KErrNone;
        		}
            }
        }

    CleanupStack::PopAndDestroy( &keys );
    return ret;
    }
void T_NATFWTraversalAdapter::SetupL(  )
    {
    // Central Repository for NAT-FW Traversal settings
    CRepository* rep = CRepository::NewLC( KCRUidUNSAFProtocols );

    iNATFWDomainSpecificItem = CNATFWDomainSpecificItem::NewL();
    iNATFWIAPSpecificItem = CNATFWIAPSpecificItem::NewL();


    //////////////////////////////
    ////////// TMTEST ////////////
    //////////////////////////////
    /*_LIT8( KTesti, "101kakka,3,2,1" );
    TLex8 leksaaja( KTesti() );
    TInt arvoitus( KErrNotFound );
    TInt virhe = leksaaja.Val( arvoitus );
    DBG_PRINT_2( "Timo testaa: virhe = %d", virhe );
    DBG_PRINT_2( "Timo testaa: arvoitus = %d", arvoitus );*/
    //////////////////////////////
    //////// TMTEST END //////////
    //////////////////////////////


    // Load stored data data if exist
    RArray<TUint32> keys;
    CleanupClosePushL( keys );
    TInt err = rep->FindL( KUNSAFProtocolsDomainMask, 
        KUNSAFProtocolsFieldTypeMask, keys ); 
    if ( keys.Count() )
        {
        GetDomainSettingsL( keys[0], *iNATFWDomainSpecificItem );
        }
    err = rep->FindL( KUNSAFProtocolsIAPIdMask, 
        KUNSAFProtocolsFieldTypeMask, keys ); 
    
    if ( keys.Count() )
        {
        GetIAPSettingsL( keys[0], *iNATFWIAPSpecificItem );
        }

    CleanupStack::PopAndDestroy( &keys );
    CleanupStack::PopAndDestroy( rep );
    }
// ---------------------------------------------------------------------------
// T_NATFWTraversalAdapter::GetDomainSettingsL
// Gets one domain settings entry
// ---------------------------------------------------------------------------
//
void T_NATFWTraversalAdapter::GetDomainSettingsL( TUint32 aDomainKeyId,
    CNATFWDomainSpecificItem& aItem )
    {
    // Central Repository for NAT-FW Traversal settings
    CRepository* rep = CRepository::NewLC( KCRUidUNSAFProtocols ); // CS:1
    
    TUint32 key( KErrNone );
    // select domain 
    key = ( KUNSAFProtocolsDomainMask^( aDomainKeyId ) );
    key |= KUNSAFProtocolsDomainTableMask;
    // set key id
    aItem.SetDomainKey( aDomainKeyId );
    
    // set domain
    TInt actualLength = 0;
    TBuf8<1> tmp;
    rep->Get( KUNSAFProtocolsDomainMask|key, tmp, actualLength );
    
    if ( actualLength > 0 )
        {
        HBufC8* domainName = HBufC8::NewLC( actualLength );
        TPtr8 ptr( domainName->Des() );
        TInt err = rep->Get( KUNSAFProtocolsDomainMask|key, ptr ); 
        if( KErrNone == err )
            {
            aItem.SetDomainL( domainName->Des() );
            }
        else
            {
            aItem.SetDomainL( KNullDesC8() );
            }
        CleanupStack::PopAndDestroy( domainName );
        actualLength = 0;
        }

    // set STUN server address
    rep->Get( KUNSAFProtocolsSTUNServerMask|key, tmp, actualLength );
    
    if ( actualLength > 0 )
        {
        HBufC8* stunServerAddr = HBufC8::NewLC( actualLength );
        TPtr8 ptr ( stunServerAddr->Des() );
        TInt err = rep->Get( KUNSAFProtocolsSTUNServerMask|key, ptr );
        if( err == KErrNone ) 
            {
            aItem.SetSTUNServerAddrL( stunServerAddr->Des() );
            }
        else
            {
            aItem.SetSTUNServerAddrL( KNullDesC8() );
            }
        CleanupStack::PopAndDestroy( stunServerAddr );
        }
    
    // STUN server port
    TInt tmpValue( 0 );
    rep->Get( KUNSAFProtocolsSTUNServerPortMask|key, tmpValue );
    aItem.SetSTUNServerPort( tmpValue );

    // STUN server username
    rep->Get( KUNSAFProtocolsSTUNUsernameMask|key, tmp, actualLength );
    
    if ( actualLength > 0 )
        {
        HBufC8* stunUsername = HBufC8::NewLC( actualLength );
        TPtr8 ptr ( stunUsername->Des() );
        TInt err = rep->Get( KUNSAFProtocolsSTUNUsernameMask|key, ptr );
        if( err == KErrNone ) 
            {
            aItem.SetSTUNUsernameL( stunUsername->Des() );
            }
        else
            {
            aItem.SetSTUNUsernameL( KNullDesC8() );
            }
        CleanupStack::PopAndDestroy( stunUsername );
        }

    // STUN server password
    rep->Get( KUNSAFProtocolsSTUNPasswordMask|key, tmp, actualLength );
    
    if ( actualLength > 0 )
        {
        HBufC8* stunPassword = HBufC8::NewLC( actualLength );
        TPtr8 ptr ( stunPassword->Des() );
        TInt err = rep->Get( KUNSAFProtocolsSTUNPasswordMask|key, ptr );
        if( err == KErrNone ) 
            {
            aItem.SetSTUNPasswordL( stunPassword->Des() );
            }
        else
            {
            aItem.SetSTUNPasswordL( KNullDesC8() );
            }
        CleanupStack::PopAndDestroy( stunPassword );
        }

    // NAT refresh interval for UDP
    tmpValue = KErrNotFound;
    rep->Get( KUNSAFProtocolsDomainIntervalUDPMask|key, tmpValue );
    aItem.SetNATRefreshUDP( tmpValue );
    
    // NAT refresh interval for TCP
    tmpValue = KErrNotFound;
    rep->Get( KUNSAFProtocolsDomainIntervalTCPMask|key, tmpValue );
    aItem.SetNATRefreshTCP( tmpValue );
    
    // CRLF-based NAT binding refresh 
    tmpValue = KErrNotFound;
    rep->Get( KUNSAFProtocolsDomainEnableCRLFRefresh|key, tmpValue );
    aItem.SetEnableCRLFRefresh( tmpValue );

    TUint32 tempKey = aDomainKeyId|KUNSAFProtocolsFieldTypeMask;
    tempKey ^= KUNSAFProtocolsFieldTypeMask;
    
    RArray<TUint32> stunKeys;
    CleanupClosePushL( stunKeys ); // CS:2
    rep->FindL( tempKey|KUNSAFProtocolsSTUNAddressMask, 
        KUNSAFProtocolsSubTableFieldTypeMask, stunKeys );
    TInt stunKeyCount = stunKeys.Count();

    // STUN server items start from CenRep table index 1.
    for ( TInt counter = 1; counter < stunKeyCount; counter++ )
        {
        CWPStunServerItem* stunItem = CWPStunServerItem::NewLC(); // CS:3

        // Remove STUN server address mask from key.
        TUint32 tmpKey = KUNSAFProtocolsSTUNAddressMask^stunKeys[counter];

        // STUNSrvAddr
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsSTUNAddressMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* stunSrvAddr = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( stunSrvAddr->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsSTUNAddressMask, 
                ptr );
            if ( KErrNone == err )
                {
                stunItem->SetStunSrvAddrL( stunSrvAddr->Des() );
                }
            else
                {
                stunItem->SetStunSrvAddrL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( stunSrvAddr ); // CS:3
            }
        else if ( 0 == actualLength )
            {
            stunItem->SetStunSrvAddrL( KNullDesC8 );
            }

        // STUNSrvPort
        TInt tmpValue( KErrNotFound );
        rep->Get( tmpKey|KUNSAFProtocolsSTUNPortMask, tmpValue );
        stunItem->SetStunSrvPort( tmpValue );

        // STUNSrvUsername
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsSTUNUsernameMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* stunUsername = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( stunUsername->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsSTUNUsernameMask, 
                ptr );
            if ( KErrNone == err )
                {
                stunItem->SetStunUsernameL( stunUsername->Des() );
                }
            else
                {
                stunItem->SetStunUsernameL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( stunUsername ); // CS:3
            }
        else if ( 0 == actualLength )
            {
            stunItem->SetStunUsernameL( KNullDesC8 );
            }

        // STUNSrvPassword
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsSTUNPasswordMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* stunPassword = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( stunPassword->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsSTUNPasswordMask, 
                ptr );
            if ( KErrNone == err )
                {
                stunItem->SetStunPasswordL( stunPassword->Des() );
                }
            else
                {
                stunItem->SetStunPasswordL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( stunPassword ); // CS:3
            }
        else if ( 0 == actualLength )
            {
            stunItem->SetStunPasswordL( KNullDesC8 );
            }

        aItem.AddStunServerItemL( stunItem ); // Ownership transfer.

        CleanupStack::Pop( stunItem ); // CS:2
        }
    stunKeys.Close();
    CleanupStack::PopAndDestroy( &stunKeys ); // CS:1

    // STUNSharedSecret
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsDomainSharedSecretNotSupported, 
        tmpValue );
    aItem.SetDisableStunSharedSecret( tmpValue );

    // PortPoolStartPort
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsPortPoolStartPortMask, tmpValue );
    aItem.SetStartPortRange( tmpValue );

    // PortPoolEndPort
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsPortPoolEndPortMask, tmpValue );
    aItem.SetEndPortRange( tmpValue );

    // UsedNATProtocol
    actualLength = 0;
    rep->Get( key|KUNSAFProtocolsUsedNATProtocolMask, tmp, actualLength );
    if ( actualLength > 0 )
        {
        HBufC8* natProtocol = HBufC8::NewLC( actualLength ); // CS:4
        TPtr8 ptr( natProtocol->Des() );
        TInt err = rep->Get( key|KUNSAFProtocolsUsedNATProtocolMask, 
            ptr );
        if ( KErrNone == err )
            {
            aItem.SetNatProtocolL( natProtocol->Des() );
            }
        else
            {
            aItem.SetNatProtocolL( KNullDesC8 );
            }
        CleanupStack::PopAndDestroy( natProtocol ); // CS:3
        }
    else if ( 0 == actualLength )
        {
        aItem.SetNatProtocolL( KNullDesC8 );
        }

    // ICESpecific/NATUtilities
    actualLength = 0;
    rep->Get( key|KUNSAFProtocolsNATUtilities, tmp, actualLength );
    if ( actualLength > 0 )
        {
        HBufC8* natUtils = HBufC8::NewLC( actualLength ); // CS:4
        TPtr8 ptr( natUtils->Des() );
        TInt err = rep->Get( key|KUNSAFProtocolsNATUtilities, ptr );
        if ( KErrNone == err )
            {
            aItem.SetNatUtilitiesL( natUtils->Des() );
            }
        else
            {
            aItem.SetNatUtilitiesL( KNullDesC8 );
            }
        CleanupStack::PopAndDestroy( natUtils ); // CS:3
        }
    else if ( 0 == actualLength )
        {
        aItem.SetNatUtilitiesL( KNullDesC8 );
        }

    // ICESpecific/HostPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsHostPref, tmpValue );
    aItem.SetHostPref( tmpValue );

    // ICESpecific/ServerRefPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsServerRefPref, tmpValue );
    aItem.SetServerRefPref( tmpValue );

    // ICESpecific/RelayPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsRelayPref, tmpValue );
    aItem.SetRelayPref( tmpValue );

    // ICESpecific/PeerRefPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsPeerRefPref, tmpValue );
    aItem.SetPeerRefPref( tmpValue );

    // ICESpecific/IPv4Pref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsIPV4Pref, tmpValue );
    aItem.SetIPv4Pref( tmpValue );

    // ICESpecific/IPv6Pref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsIPV6Pref, tmpValue );
    aItem.SetIPv6Pref( tmpValue );

    // ICESpecific/VpnPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsVPNPref, tmpValue );
    aItem.SetVpnPref( tmpValue );

    // ICESpecific/UdpPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsUDPPref, tmpValue );
    aItem.SetUdpPref( tmpValue );

    // ICESpecific/TcpPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsTCPPref, tmpValue );
    aItem.SetTcpPref( tmpValue );

    // ICESpecific/TcpActivePref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsTCPActivePref, tmpValue );
    aItem.SetTcpActivePref( tmpValue );

    // ICESpecific/TcpPassivePref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsTCPPassivePref, tmpValue );
    aItem.SetTcpPassivePref( tmpValue );

    // ICESpecific/TCPSimultPref
    tmpValue = KErrNotFound;
    rep->Get( key|KUNSAFProtocolsTCPSimultPref, tmpValue );
    aItem.SetTcpSimultPref( tmpValue );

    // TURN server
    tempKey = aDomainKeyId|KUNSAFProtocolsFieldTypeMask;
    tempKey ^= KUNSAFProtocolsFieldTypeMask;
    
    RArray<TUint32> turnKeys;
    CleanupClosePushL( turnKeys ); // CS:2
    rep->FindL( tempKey|KUNSAFProtocolsTURNAddressMask, 
        KUNSAFProtocolsSubTableFieldTypeMask, turnKeys );
    TInt turnKeyCount = turnKeys.Count();
    for ( TInt counter = 0; counter < turnKeyCount; counter++ )
        {
        CWPTurnServerItem* turnItem = CWPTurnServerItem::NewLC(); // CS:3

        // Remove TURN server address mask from key.
        TUint32 tmpKey = KUNSAFProtocolsTURNAddressMask^turnKeys[counter];

        // TURNSrvAddr
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsTURNAddressMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* turnSrvAddr = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( turnSrvAddr->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsTURNAddressMask, 
                ptr );
            if ( KErrNone == err )
                {
                turnItem->SetTurnSrvAddrL( turnSrvAddr->Des() );
                }
            else
                {
                turnItem->SetTurnSrvAddrL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( turnSrvAddr ); // CS:3
            }
        else if ( 0 == actualLength )
            {
            turnItem->SetTurnSrvAddrL( KNullDesC8 );
            }

        // TURNSrvPort
        TInt tmpValue( KErrNotFound );
        rep->Get( tmpKey|KUNSAFProtocolsTURNPortMask, tmpValue );
        turnItem->SetTurnSrvPort( tmpValue );

        // TURNUsername
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsTURNUsernameMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* turnUsername = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( turnUsername->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsTURNUsernameMask, 
                ptr );
            if ( KErrNone == err )
                {
                turnItem->SetTurnUsernameL( turnUsername->Des() );
                }
            else
                {
                turnItem->SetTurnUsernameL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( turnUsername ); // CS:3
            }
        else
            {
            turnItem->SetTurnUsernameL( KNullDesC8 );
            }

        // TURNPassword
        actualLength = 0;
        rep->Get( tmpKey|KUNSAFProtocolsTURNPasswordMask, tmp, actualLength );
        if ( actualLength > 0 )
            {
            HBufC8* turnPassword = HBufC8::NewLC( actualLength ); // CS:4
            TPtr8 ptr( turnPassword->Des() );
            TInt err = rep->Get( tmpKey|KUNSAFProtocolsTURNPasswordMask, 
                ptr );
            if ( KErrNone == err )
                {
                turnItem->SetTurnPasswordL( turnPassword->Des() );
                }
            else
                {
                turnItem->SetTurnPasswordL( KNullDesC8 );
                }
            CleanupStack::PopAndDestroy( turnPassword ); // CS:3
            }
        else
            {
            turnItem->SetTurnPasswordL( KNullDesC8 );
            }
        aItem.AddTurnServerItemL( turnItem ); // Ownership transfer.
        CleanupStack::Pop( turnItem ); // CS:2
        }

    turnKeys.Close();
    CleanupStack::PopAndDestroy( &turnKeys ); // CS:1
    CleanupStack::PopAndDestroy( rep ); // CS:0
    }
Пример #6
0
LOCAL_C void FindL()
	{
	CRepository* repository;
	User::LeaveIfNull(repository = CRepository::NewLC(KUidPlatsecTestRepository));

	RArray<TUint32> foundIds;
	CleanupClosePushL(foundIds);

	TInt r = KErrNone;

	TRAPD(leaveReason, r = repository->FindL(0, 0, foundIds));
	if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory))
		{
		CleanupStack::PopAndDestroy(); //foundIds
		User::Leave(KErrNoMemory);
		}
	// Note that we are allowed to find any setting regardless of it's platsec
	// what we can't do is return the value
	TEST2(r, KErrNone);
	TEST(foundIds.Count()==KNumSettings);

	foundIds.Reset();

	TRAP(leaveReason, r = repository->FindL(23, 0, foundIds));  // 23 - just a random number, value is not important
	if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory))
		{
		CleanupStack::PopAndDestroy(); //foundIds
		User::Leave(KErrNoMemory);
		}
	TEST2(r, KErrNone);
	TEST(foundIds.Count()==KNumSettings);

	foundIds.Reset();

	TRAP(leaveReason, r = repository->FindL(0, 2, foundIds));
	if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory))
		{
		CleanupStack::PopAndDestroy(); //foundIds
		User::Leave(KErrNoMemory);
		}
	TEST2(r, KErrNone);
	TEST(foundIds.Count()==22);

	foundIds.Reset();

	TRAP(leaveReason, r = repository->FindL(4, 6, foundIds));
	if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory))
		{
		CleanupStack::PopAndDestroy(); //foundIds
		User::Leave(KErrNoMemory);
		}
	TEST2(r, KErrNone);
	TEST(foundIds.Count()==1);

	foundIds.Reset();

	TRAP(leaveReason, r = repository->FindL(15, 15, foundIds));
	if(OomTesting && (r==KErrNoMemory || leaveReason==KErrNoMemory))
		{
		CleanupStack::PopAndDestroy(); //foundIds
		User::Leave(KErrNoMemory);
		}
	TEST2(r, KErrNotFound);
	TEST(foundIds.Count()==0);

	CleanupStack::PopAndDestroy(); //foundIds
	CleanupStack::PopAndDestroy(repository);
	}