cmmanager/cmmgr/cmmserver/src/cmmsession.cpp
changeset 27 489cf6208544
parent 20 9c97ad6591ae
child 40 c5b848e6c7d1
equal deleted inserted replaced
23:7ec726f93df1 27:489cf6208544
   205         case ECmmGetSupportedBearers:
   205         case ECmmGetSupportedBearers:
   206             {
   206             {
   207             GetSupportedBearersL( aMessage );
   207             GetSupportedBearersL( aMessage );
   208             }
   208             }
   209             break;
   209             break;
       
   210         case ECmmGetUncategorizedIcon:
       
   211             {
       
   212             GetUncategorizedIconL( aMessage );
       
   213             }
       
   214             break;
   210         case ECmmReadDefaultConnection:
   215         case ECmmReadDefaultConnection:
   211             {
   216             {
   212             ReadDefaultConnectionL( aMessage );
   217             ReadDefaultConnectionL( aMessage );
   213             }
   218             }
   214             break;
   219             break;
   267         case EDestMetadata:
   272         case EDestMetadata:
   268         case EDestGetProtectionLevel:
   273         case EDestGetProtectionLevel:
   269         case EDestIsConnected:
   274         case EDestIsConnected:
   270         case EDestIsHidden:
   275         case EDestIsHidden:
   271         case EDestIsEqual:
   276         case EDestIsEqual:
       
   277         case EDestGetIcon:
   272         case EDestAddConnMethod:
   278         case EDestAddConnMethod:
   273         case EDestAddEmbeddedDestination:
   279         case EDestAddEmbeddedDestination:
   274         case EDestDeleteConnMethod:
   280         case EDestDeleteConnMethod:
   275         case EDestRemoveConnMethod:
   281         case EDestRemoveConnMethod:
   276         case EDestModifyPriority:
   282         case EDestModifyPriority:
   278         case EDestSetMetadata:
   284         case EDestSetMetadata:
   279         case EDestSetProtection:
   285         case EDestSetProtection:
   280         case EDestSetHidden:
   286         case EDestSetHidden:
   281         case EDestUpdate:
   287         case EDestUpdate:
   282         case EDestDelete:
   288         case EDestDelete:
       
   289         case EDestSetIcon:
   283             {
   290             {
   284             ServiceDestinationL( aMessage );
   291             ServiceDestinationL( aMessage );
   285             }
   292             }
   286             break;
   293             break;
   287 
   294 
   680         return;
   687         return;
   681         }
   688         }
   682     CleanupStack::PushL( result );
   689     CleanupStack::PushL( result );
   683 
   690 
   684     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   691     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   685     if ( result && result->Length() > bufferLen )
   692     if ( result->Length() > bufferLen )
   686         {
   693         {
   687         User::Leave( KErrArgument );
   694         User::Leave( KErrArgument );
   688         }
   695         }
   689 
   696 
   690     TPtrC resultPtr = result->Des();
   697     TPtrC resultPtr = result->Des();
   712         return;
   719         return;
   713         }
   720         }
   714     CleanupStack::PushL( result );
   721     CleanupStack::PushL( result );
   715 
   722 
   716     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   723     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   717     if ( result && result->Length() > bufferLen )
   724     if ( result->Length() > bufferLen )
   718         {
   725         {
   719         User::Leave( KErrArgument );
   726         User::Leave( KErrArgument );
   720         }
   727         }
   721 
   728 
   722     TPtrC8 resultPtr = result->Des();
   729     TPtrC8 resultPtr = result->Des();
   780         return;
   787         return;
   781         }
   788         }
   782     CleanupStack::PushL( result );
   789     CleanupStack::PushL( result );
   783 
   790 
   784     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   791     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   785     if ( result && result->Length() > bufferLen )
   792     if ( result->Length() > bufferLen )
   786         {
   793         {
   787         User::Leave( KErrArgument );
   794         User::Leave( KErrArgument );
   788         }
   795         }
   789 
   796 
   790     TPtrC resultPtr = result->Des();
   797     TPtrC resultPtr = result->Des();
   812         return;
   819         return;
   813         }
   820         }
   814     CleanupStack::PushL( result );
   821     CleanupStack::PushL( result );
   815 
   822 
   816     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   823     TInt bufferLen = aMessage.GetDesMaxLength( 2 );
   817     if ( result && result->Length() > bufferLen )
   824     if ( result->Length() > bufferLen )
   818         {
   825         {
   819         User::Leave( KErrArgument );
   826         User::Leave( KErrArgument );
   820         }
   827         }
   821 
   828 
   822     TPtrC8 resultPtr = result->Des();
   829     TPtrC8 resultPtr = result->Des();
  1012 
  1019 
  1013     CleanupStack::PopAndDestroy( bearerBuf );
  1020     CleanupStack::PopAndDestroy( bearerBuf );
  1014     CleanupStack::PopAndDestroy( &bearerArray );
  1021     CleanupStack::PopAndDestroy( &bearerArray );
  1015 
  1022 
  1016     OstTraceFunctionExit0( DUP1_CCMMSESSION_GETSUPPORTEDBEARERSL_EXIT );
  1023     OstTraceFunctionExit0( DUP1_CCMMSESSION_GETSUPPORTEDBEARERSL_EXIT );
       
  1024     }
       
  1025 
       
  1026 // -----------------------------------------------------------------------------
       
  1027 // CCmmSession::GetUncategorizedIconL
       
  1028 // -----------------------------------------------------------------------------
       
  1029 //
       
  1030 void CCmmSession::GetUncategorizedIconL( const RMessage2& aMessage )
       
  1031     {
       
  1032     OstTraceFunctionEntry0( CCMMSESSION_GETUNCATEGORIZEDICONL_ENTRY );
       
  1033 
       
  1034     HBufC* result = KNullDesC().AllocLC(); //TODO, Is there an uncategorized icon?
       
  1035 
       
  1036     TInt bufferLen = aMessage.GetDesMaxLength( 0 );
       
  1037     if ( result->Length() > bufferLen )
       
  1038         {
       
  1039         User::Leave( KErrArgument );
       
  1040         }
       
  1041 
       
  1042     TPtrC resultPtr = result->Des();
       
  1043     aMessage.WriteL( 0, resultPtr );
       
  1044     CleanupStack::PopAndDestroy( result );
       
  1045 
       
  1046     OstTraceFunctionExit0( CCMMSESSION_GETUNCATEGORIZEDICONL_EXIT );
  1017     }
  1047     }
  1018 
  1048 
  1019 // -----------------------------------------------------------------------------
  1049 // -----------------------------------------------------------------------------
  1020 // CCmmSession::ReadDefaultConnectionL
  1050 // CCmmSession::ReadDefaultConnectionL
  1021 // -----------------------------------------------------------------------------
  1051 // -----------------------------------------------------------------------------
  1247     if ( connMethod->IsEmbeddedDestination() )
  1277     if ( connMethod->IsEmbeddedDestination() )
  1248         {
  1278         {
  1249         User::Leave( KErrArgument );
  1279         User::Leave( KErrArgument );
  1250         }
  1280         }
  1251 
  1281 
  1252     //TODO, capability check, what to do if anything is protected.
  1282     // Check the protection level of the destination.
       
  1283     // And based on that check the needed capabilities from the client.
       
  1284     CMManager::TProtectionLevel protLevel( CMManager::EProtLevel0 );
       
  1285     destination->GetProtectionL( protLevel );
       
  1286     CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  1287     if ( protLevel == CMManager::EProtLevel1 )
       
  1288         {
       
  1289         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  1290         }
       
  1291 
       
  1292     if ( capabilities == CPolicyServer::EFail )
       
  1293         {
       
  1294         User::Leave( KErrPermissionDenied );
       
  1295         }
  1253 
  1296 
  1254     // Add connection method into destination.
  1297     // Add connection method into destination.
  1255     TInt index = destination->AddConnMethodL( *connMethod );
  1298     TInt index = destination->AddConnMethodL( *connMethod );
  1256 
  1299 
  1257     // Update destination into database.
  1300     // Update destination into database.
  1311     if ( iCache.CheckIfCmConnected( connMethodId ) )
  1354     if ( iCache.CheckIfCmConnected( connMethodId ) )
  1312         {
  1355         {
  1313         User::Leave( KErrInUse );
  1356         User::Leave( KErrInUse );
  1314         }
  1357         }
  1315 
  1358 
  1316     //TODO, capability checks, what to do if anything is protected.
  1359     // Check the protection level of the source and target destination.
       
  1360     // And based on those check the needed capabilities from the client.
       
  1361     TBool protectionExists( EFalse );
       
  1362     CMManager::TProtectionLevel protLevelSource( CMManager::EProtLevel0 );
       
  1363     sourceDestination->GetProtectionL( protLevelSource );
       
  1364     if ( protLevelSource == CMManager::EProtLevel1 
       
  1365             || protLevelSource == CMManager::EProtLevel3 )
       
  1366         {
       
  1367         protectionExists = ETrue;
       
  1368         }
       
  1369 
       
  1370     // If source destination is not protected check the target destination.
       
  1371     if ( !protectionExists )
       
  1372         {
       
  1373         CMManager::TProtectionLevel protLevelTarget( CMManager::EProtLevel0 );
       
  1374         targetDestination->GetProtectionL( protLevelTarget );
       
  1375         if ( protLevelTarget == CMManager::EProtLevel1 )
       
  1376             {
       
  1377             protectionExists = ETrue;
       
  1378             }
       
  1379         }
       
  1380 
       
  1381     CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  1382     if ( protectionExists )
       
  1383         {
       
  1384         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  1385         }
       
  1386 
       
  1387     if ( capabilities == CPolicyServer::EFail )
       
  1388         {
       
  1389         User::Leave( KErrPermissionDenied );
       
  1390         }
  1317 
  1391 
  1318     // Add connection method into target destination and update it.
  1392     // Add connection method into target destination and update it.
  1319     attributesPckg().iIndex = targetDestination->AddConnMethodL( *connMethod );
  1393     attributesPckg().iIndex = targetDestination->AddConnMethodL( *connMethod );
  1320     targetDestination->UpdateL();
  1394     targetDestination->UpdateL();
  1321 
  1395 
  1341     CCmmDestinationInstance* destinationInstance =
  1415     CCmmDestinationInstance* destinationInstance =
  1342             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int0() );
  1416             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int0() );
  1343     CCmmConnMethodInstance* connMethodInstance =
  1417     CCmmConnMethodInstance* connMethodInstance =
  1344             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int1() );
  1418             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int1() );
  1345 
  1419 
  1346     //TODO, capability checks
  1420     // Check the protection level of the destination.
       
  1421     // And based on that check the needed capabilities from the client.
       
  1422     CMManager::TProtectionLevel protLevel( CMManager::EProtLevel0 );
       
  1423     destinationInstance->GetProtectionL( protLevel );
       
  1424     CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  1425     if ( protLevel == CMManager::EProtLevel1 || protLevel == CMManager::EProtLevel3 )
       
  1426         {
       
  1427         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  1428         }
       
  1429 
       
  1430     if ( capabilities == CPolicyServer::EFail )
       
  1431         {
       
  1432         User::Leave( KErrPermissionDenied );
       
  1433         }
  1347 
  1434 
  1348     destinationInstance->RemoveConnMethodFromDestinationL( *connMethodInstance );
  1435     destinationInstance->RemoveConnMethodFromDestinationL( *connMethodInstance );
  1349     destinationInstance->UpdateL();
  1436     destinationInstance->UpdateL();
  1350 
  1437 
  1351     OstTraceFunctionExit0( CCMMSESSION_REMOVECONNMETHODL_EXIT );
  1438     OstTraceFunctionExit0( CCMMSESSION_REMOVECONNMETHODL_EXIT );
  1361     OstTraceFunctionEntry0( CCMMSESSION_REMOVEALLREFERENCESL_ENTRY );
  1448     OstTraceFunctionEntry0( CCMMSESSION_REMOVEALLREFERENCESL_ENTRY );
  1362 
  1449 
  1363     CCmmConnMethodInstance* connMethodInstance =
  1450     CCmmConnMethodInstance* connMethodInstance =
  1364             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  1451             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  1365 
  1452 
       
  1453     TBool capabilityCheckNeeded( EFalse );
       
  1454     iCache.CheckIfConnMethodBelongsToProtectedDestinationL(
       
  1455             *connMethodInstance,
       
  1456             capabilityCheckNeeded );
       
  1457     if ( capabilityCheckNeeded )
       
  1458         {
       
  1459         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  1460         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  1461         if ( capabilities == CPolicyServer::EFail )
       
  1462             {
       
  1463             User::Leave( KErrPermissionDenied );
       
  1464             }
       
  1465         }
       
  1466 
  1366     iCache.CheckIfConnMethodReferencesCanBeRemovedL( *connMethodInstance );
  1467     iCache.CheckIfConnMethodReferencesCanBeRemovedL( *connMethodInstance );
  1367     iCache.RemoveAllReferencesToConnMethodL( *connMethodInstance );
  1468     iCache.RemoveAllReferencesToConnMethodL( *connMethodInstance );
  1368 
  1469 
  1369     OstTraceFunctionExit0( CCMMSESSION_REMOVEALLREFERENCESL_EXIT );
  1470     OstTraceFunctionExit0( CCMMSESSION_REMOVEALLREFERENCESL_EXIT );
  1370     }
  1471     }
  1452         case EDestIsEqual:
  1553         case EDestIsEqual:
  1453             {
  1554             {
  1454             DestinationIsEqualL( aMessage );
  1555             DestinationIsEqualL( aMessage );
  1455             }
  1556             }
  1456             break;
  1557             break;
       
  1558         case EDestGetIcon:
       
  1559             {
       
  1560             GetDestinationIconL( aMessage );
       
  1561             }
       
  1562             break;
  1457         case EDestAddConnMethod:
  1563         case EDestAddConnMethod:
  1458             {
  1564             {
  1459             DestAddConnMethodL( aMessage );
  1565             DestAddConnMethodL( aMessage );
  1460             }
  1566             }
  1461             break;
  1567             break;
  1505             }
  1611             }
  1506             break;
  1612             break;
  1507         case EDestDelete:
  1613         case EDestDelete:
  1508             {
  1614             {
  1509             DeleteDestinationL( aMessage );
  1615             DeleteDestinationL( aMessage );
       
  1616             }
       
  1617             break;
       
  1618         case EDestSetIcon:
       
  1619             {
       
  1620             SetDestinationIconL( aMessage );
  1510             }
  1621             }
  1511             break;
  1622             break;
  1512         default:
  1623         default:
  1513             {
  1624             {
  1514             User::Leave( KErrNotSupported );
  1625             User::Leave( KErrNotSupported );
  1845 
  1956 
  1846     OstTraceFunctionExit0( CCMMSESSION_GETDESTINATIONNAMEL_EXIT );
  1957     OstTraceFunctionExit0( CCMMSESSION_GETDESTINATIONNAMEL_EXIT );
  1847     }
  1958     }
  1848 
  1959 
  1849 // -----------------------------------------------------------------------------
  1960 // -----------------------------------------------------------------------------
       
  1961 // CCmmSession::GetDestinationIconL
       
  1962 // -----------------------------------------------------------------------------
       
  1963 //
       
  1964 void CCmmSession::GetDestinationIconL( const RMessage2& aMessage )
       
  1965     {
       
  1966     OstTraceFunctionEntry0( CCMMSESSION_GETDESTINATIONICONL_ENTRY );
       
  1967 
       
  1968     CCmmDestinationInstance* destinationInstance =
       
  1969             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  1970 
       
  1971     HBufC* icon = destinationInstance->GetDestinationIconL();
       
  1972     CleanupStack::PushL( icon );
       
  1973     TPtrC iconPtr( icon->Des() );
       
  1974 
       
  1975     TInt bufferLen = aMessage.GetDesMaxLength( 0 );
       
  1976     if ( iconPtr.Length() > bufferLen )
       
  1977         {
       
  1978         User::Leave( KErrArgument );
       
  1979         }
       
  1980 
       
  1981     aMessage.WriteL( 0, iconPtr );
       
  1982     CleanupStack::PopAndDestroy( icon );
       
  1983 
       
  1984     OstTraceFunctionExit0( CCMMSESSION_GETDESTINATIONICONL_EXIT );
       
  1985     }
       
  1986 
       
  1987 // -----------------------------------------------------------------------------
  1850 // CCmmSession::GetDestinationIdL
  1988 // CCmmSession::GetDestinationIdL
  1851 // -----------------------------------------------------------------------------
  1989 // -----------------------------------------------------------------------------
  1852 //
  1990 //
  1853 void CCmmSession::GetDestinationIdL( const RMessage2& aMessage )
  1991 void CCmmSession::GetDestinationIdL( const RMessage2& aMessage )
  1854     {
  1992     {
  2010     {
  2148     {
  2011     OstTraceFunctionEntry0( CCMMSESSION_DESTADDCONNMETHODL_ENTRY );
  2149     OstTraceFunctionEntry0( CCMMSESSION_DESTADDCONNMETHODL_ENTRY );
  2012 
  2150 
  2013     CCmmDestinationInstance* destination =
  2151     CCmmDestinationInstance* destination =
  2014             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2152             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2153 
       
  2154     // Check the protection and if protected check the needed capabilities.
       
  2155     CMManager::TProtectionLevel protLevel =
       
  2156             destination->CurrentProtectionLevel();
       
  2157     if ( protLevel == CMManager::EProtLevel1 )
       
  2158         {
       
  2159         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2160         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2161         if ( capabilities == CPolicyServer::EFail )
       
  2162             {
       
  2163             User::Leave( KErrPermissionDenied );
       
  2164             }
       
  2165         }
       
  2166 
  2015     CCmmConnMethodInstance* connMethod =
  2167     CCmmConnMethodInstance* connMethod =
  2016             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2168             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2017 
  2169 
  2018     if ( connMethod->IsEmbeddedDestination() )
  2170     if ( connMethod->IsEmbeddedDestination() )
  2019         {
  2171         {
  2033 //
  2185 //
  2034 void CCmmSession::DestAddEmbeddedDestinationL( const RMessage2& aMessage )
  2186 void CCmmSession::DestAddEmbeddedDestinationL( const RMessage2& aMessage )
  2035     {
  2187     {
  2036     OstTraceFunctionEntry0( CCMMSESSION_DESTADDEMBEDDEDDESTINATIONL_ENTRY );
  2188     OstTraceFunctionEntry0( CCMMSESSION_DESTADDEMBEDDEDDESTINATIONL_ENTRY );
  2037 
  2189 
  2038     CCmmDestinationInstance* destination =
  2190     CCmmDestinationInstance* destinationInstance =
  2039             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2191             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2192 
       
  2193     // Check the protection and if protected check the needed capabilities.
       
  2194     CMManager::TProtectionLevel protLevel = 
       
  2195             destinationInstance->CurrentProtectionLevel();
       
  2196     if ( protLevel == CMManager::EProtLevel1 )
       
  2197         {
       
  2198         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2199         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2200         if ( capabilities == CPolicyServer::EFail )
       
  2201             {
       
  2202             User::Leave( KErrPermissionDenied );
       
  2203             }
       
  2204         }
       
  2205 
  2040     CCmmDestinationInstance* embeddedDestination =
  2206     CCmmDestinationInstance* embeddedDestination =
  2041             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int0() );
  2207             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int0() );
  2042 
  2208 
  2043     TInt index = destination->AddEmbeddedDestinationL( *embeddedDestination );
  2209     TInt index = destinationInstance->AddEmbeddedDestinationL( *embeddedDestination );
  2044     TPckg<TInt> indexPckg( index );
  2210     TPckg<TInt> indexPckg( index );
  2045     aMessage.WriteL( 1, indexPckg );
  2211     aMessage.WriteL( 1, indexPckg );
  2046 
  2212 
  2047     OstTraceFunctionExit0( CCMMSESSION_DESTADDEMBEDDEDDESTINATIONL_EXIT );
  2213     OstTraceFunctionExit0( CCMMSESSION_DESTADDEMBEDDEDDESTINATIONL_EXIT );
  2048     }
  2214     }
  2057 
  2223 
  2058     CCmmDestinationInstance* destinationInstance =
  2224     CCmmDestinationInstance* destinationInstance =
  2059             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2225             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2060     CCmmConnMethodInstance* connMethodInstance =
  2226     CCmmConnMethodInstance* connMethodInstance =
  2061             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2227             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2062 
  2228     
  2063     //TODO, capability checks
  2229     // Check the protection of destination and if protected check the needed
       
  2230     // capabilities.
       
  2231     CMManager::TProtectionLevel protLevel = 
       
  2232             destinationInstance->CurrentProtectionLevel();
       
  2233     if ( protLevel == CMManager::EProtLevel1 ||
       
  2234             protLevel == CMManager::EProtLevel3 )
       
  2235         {
       
  2236         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2237         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2238         if ( capabilities == CPolicyServer::EFail )
       
  2239             {
       
  2240             User::Leave( KErrPermissionDenied );
       
  2241             }
       
  2242         }
       
  2243 
       
  2244     // Check the protection of CM and if protected check the needed
       
  2245     // capabilities.
       
  2246     CheckCapabilitiesForProtectedCML( aMessage, connMethodInstance );
  2064 
  2247 
  2065     destinationInstance->DeleteConnMethodFromDestinationL( *connMethodInstance );
  2248     destinationInstance->DeleteConnMethodFromDestinationL( *connMethodInstance );
  2066 
  2249 
  2067     OstTraceFunctionExit0( CCMMSESSION_DESTDELETECONNMETHODL_EXIT );
  2250     OstTraceFunctionExit0( CCMMSESSION_DESTDELETECONNMETHODL_EXIT );
  2068     }
  2251     }
  2078     CCmmDestinationInstance* destinationInstance =
  2261     CCmmDestinationInstance* destinationInstance =
  2079             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2262             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2080     CCmmConnMethodInstance* connMethodInstance =
  2263     CCmmConnMethodInstance* connMethodInstance =
  2081             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2264             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2082 
  2265 
  2083     //TODO, capability checks
  2266     // Check the protection of destination and if protected check the needed
       
  2267     // capabilities.
       
  2268     CMManager::TProtectionLevel protLevel = 
       
  2269             destinationInstance->CurrentProtectionLevel();
       
  2270     if ( protLevel == CMManager::EProtLevel1 ||
       
  2271             protLevel == CMManager::EProtLevel3 )
       
  2272         {
       
  2273         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2274         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2275         if ( capabilities == CPolicyServer::EFail )
       
  2276             {
       
  2277             User::Leave( KErrPermissionDenied );
       
  2278             }
       
  2279         }
  2084 
  2280 
  2085     destinationInstance->RemoveConnMethodFromDestinationL( *connMethodInstance );
  2281     destinationInstance->RemoveConnMethodFromDestinationL( *connMethodInstance );
  2086 
  2282 
  2087     OstTraceFunctionExit0( CCMMSESSION_DESTREMOVECONNMETHODL_EXIT );
  2283     OstTraceFunctionExit0( CCMMSESSION_DESTREMOVECONNMETHODL_EXIT );
  2088     }
  2284     }
  2095     {
  2291     {
  2096     OstTraceFunctionEntry0( CCMMSESSION_MODIFYCONNMETHODPRIORITYL_ENTRY );
  2292     OstTraceFunctionEntry0( CCMMSESSION_MODIFYCONNMETHODPRIORITYL_ENTRY );
  2097 
  2293 
  2098     CCmmDestinationInstance* destinationInstance =
  2294     CCmmDestinationInstance* destinationInstance =
  2099             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2295             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2296 
       
  2297     // Check the protection of destination and if protected check the needed
       
  2298     // capabilities.
       
  2299     CMManager::TProtectionLevel protLevel = 
       
  2300             destinationInstance->CurrentProtectionLevel();
       
  2301     if ( protLevel == CMManager::EProtLevel1 ||
       
  2302             protLevel == CMManager::EProtLevel3 )
       
  2303         {
       
  2304         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2305         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2306         if ( capabilities == CPolicyServer::EFail )
       
  2307             {
       
  2308             User::Leave( KErrPermissionDenied );
       
  2309             }
       
  2310         }
       
  2311 
  2100     CCmmConnMethodInstance* connMethodInstance =
  2312     CCmmConnMethodInstance* connMethodInstance =
  2101             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2313             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int0() );
  2102 
  2314 
  2103     //TODO, capability checks
       
  2104 
       
  2105     // Index values start from 0 (0 meaning highest priority).
  2315     // Index values start from 0 (0 meaning highest priority).
  2106     TUint index( ( TUint )aMessage.Int1() );
  2316     TUint index( ( TUint )aMessage.Int1() );
  2107 
  2317 
  2108     destinationInstance->ModifyConnMethodPriorityL( *connMethodInstance, index );
  2318     destinationInstance->ModifyConnMethodPriorityL( *connMethodInstance, index );
  2109 
  2319 
  2118     {
  2328     {
  2119     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONNAMEL_ENTRY );
  2329     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONNAMEL_ENTRY );
  2120 
  2330 
  2121     CCmmDestinationInstance* destinationInstance =
  2331     CCmmDestinationInstance* destinationInstance =
  2122             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2332             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2333 
       
  2334     // Check that client does not try to change the name of the Internet Destination.
       
  2335     TUint32 metadata( 0 );
       
  2336     destinationInstance->GetMetadataL( CMManager::ESnapMetadataPurpose, metadata );
       
  2337     if ( metadata == CMManager::ESnapPurposeInternet )
       
  2338         {
       
  2339         User::Leave( KErrPermissionDenied );
       
  2340         }
       
  2341 
       
  2342     // Check the protection and if protected check the needed capabilities.
       
  2343     CMManager::TProtectionLevel protLevel =
       
  2344             destinationInstance->CurrentProtectionLevel();
       
  2345     if ( protLevel == CMManager::EProtLevel1 ||
       
  2346             protLevel == CMManager::EProtLevel2 )
       
  2347         {
       
  2348         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2349         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2350         if ( capabilities == CPolicyServer::EFail )
       
  2351             {
       
  2352             User::Leave( KErrPermissionDenied );
       
  2353             }
       
  2354         }
  2123 
  2355 
  2124     // Load and check name.
  2356     // Load and check name.
  2125     TInt destNameLength = aMessage.GetDesLength( 0 );
  2357     TInt destNameLength = aMessage.GetDesLength( 0 );
  2126     if ( destNameLength <= 0 )
  2358     if ( destNameLength <= 0 )
  2127         {
  2359         {
  2145 
  2377 
  2146     OstTraceFunctionExit0( CCMMSESSION_SETDESTINATIONNAMEL_EXIT );
  2378     OstTraceFunctionExit0( CCMMSESSION_SETDESTINATIONNAMEL_EXIT );
  2147     }
  2379     }
  2148 
  2380 
  2149 // -----------------------------------------------------------------------------
  2381 // -----------------------------------------------------------------------------
  2150 // CCmmSession::SetDestinationMetadataL
  2382 // CCmmSession::SetDestinationIconL
  2151 // -----------------------------------------------------------------------------
  2383 // -----------------------------------------------------------------------------
  2152 //
  2384 //
  2153 void CCmmSession::SetDestinationMetadataL( const RMessage2& aMessage )
  2385 void CCmmSession::SetDestinationIconL( const RMessage2& aMessage )
  2154     {
  2386     {
  2155     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONMETADATAL_ENTRY );
  2387     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONICONL_ENTRY );
  2156 
       
  2157     //TODO, Capability check. Protection level or Internet destination.
       
  2158 
  2388 
  2159     CCmmDestinationInstance* destinationInstance =
  2389     CCmmDestinationInstance* destinationInstance =
  2160             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2390             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2391 
       
  2392     // Check the protection and if protected check the needed capabilities.
       
  2393     CMManager::TProtectionLevel protLevel =
       
  2394             destinationInstance->CurrentProtectionLevel(); //TODO, check the current level can't be altered without proper capas.
       
  2395     if ( protLevel == CMManager::EProtLevel1 ||
       
  2396             protLevel == CMManager::EProtLevel2 )
       
  2397         {
       
  2398         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2399         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2400         if ( capabilities == CPolicyServer::EFail )
       
  2401             {
       
  2402             User::Leave( KErrPermissionDenied );
       
  2403             }
       
  2404         }
       
  2405 
       
  2406     // Load and check name.
       
  2407     TInt destIconNameLength = aMessage.GetDesLength( 0 );
       
  2408     if ( destIconNameLength < 0 || destIconNameLength > KCmmStringLengthMax )
       
  2409         {
       
  2410         User::Leave( KErrArgument );
       
  2411         }
       
  2412 
       
  2413     HBufC* newIconName = HBufC::NewLC( destIconNameLength );
       
  2414     TPtr ptrNewIconName = newIconName->Des();
       
  2415     aMessage.ReadL( 0, ptrNewIconName );
       
  2416 
       
  2417     destinationInstance->SetDestinationIconL( *newIconName );
       
  2418     CleanupStack::PopAndDestroy( newIconName );
       
  2419 
       
  2420     OstTraceFunctionExit0( CCMMSESSION_SETDESTINATIONICONL_EXIT );
       
  2421     }
       
  2422 
       
  2423 // -----------------------------------------------------------------------------
       
  2424 // CCmmSession::SetDestinationMetadataL
       
  2425 // -----------------------------------------------------------------------------
       
  2426 //
       
  2427 void CCmmSession::SetDestinationMetadataL( const RMessage2& aMessage )
       
  2428     {
       
  2429     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONMETADATAL_ENTRY );
       
  2430 
       
  2431     CCmmDestinationInstance* destinationInstance =
       
  2432             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2433 
       
  2434     // Check the protection and if protected check the needed capabilities.
       
  2435     CMManager::TProtectionLevel protLevel =
       
  2436             destinationInstance->CurrentProtectionLevel();
       
  2437     if ( protLevel == CMManager::EProtLevel1 ||
       
  2438             protLevel == CMManager::EProtLevel2 )
       
  2439         {
       
  2440         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2441         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2442         if ( capabilities == CPolicyServer::EFail )
       
  2443             {
       
  2444             User::Leave( KErrPermissionDenied );
       
  2445             }
       
  2446         }
  2161 
  2447 
  2162     CMManager::TSnapMetadataField metadataField =
  2448     CMManager::TSnapMetadataField metadataField =
  2163             ( CMManager::TSnapMetadataField )aMessage.Int0();
  2449             ( CMManager::TSnapMetadataField )aMessage.Int0();
  2164     TUint32 metadata = aMessage.Int1();
  2450     TUint32 metadata = aMessage.Int1();
  2165 
  2451 
  2174 //
  2460 //
  2175 void CCmmSession::SetDestinationProtectionL( const RMessage2& aMessage )
  2461 void CCmmSession::SetDestinationProtectionL( const RMessage2& aMessage )
  2176     {
  2462     {
  2177     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONPROTECTIONL_ENTRY );
  2463     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONPROTECTIONL_ENTRY );
  2178 
  2464 
  2179     //TODO, Capability check: ECapabilityNetworkControl
  2465     // Check the needed capabilities.
       
  2466     CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2467     capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2468     if ( capabilities == CPolicyServer::EFail )
       
  2469         {
       
  2470         User::Leave( KErrPermissionDenied );
       
  2471         }
  2180 
  2472 
  2181     CCmmDestinationInstance* destinationInstance =
  2473     CCmmDestinationInstance* destinationInstance =
  2182             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2474             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2183     CMManager::TProtectionLevel protLevel =
  2475     CMManager::TProtectionLevel protLevel =
  2184             ( CMManager::TProtectionLevel )aMessage.Int0();
  2476             ( CMManager::TProtectionLevel )aMessage.Int0();
  2196     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONHIDDENL_ENTRY );
  2488     OstTraceFunctionEntry0( CCMMSESSION_SETDESTINATIONHIDDENL_ENTRY );
  2197 
  2489 
  2198     CCmmDestinationInstance* destinationInstance =
  2490     CCmmDestinationInstance* destinationInstance =
  2199             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2491             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2200 
  2492 
       
  2493     // Check the protection and if protected check the needed capabilities.
       
  2494     CMManager::TProtectionLevel protLevel =
       
  2495             destinationInstance->CurrentProtectionLevel();
       
  2496     if ( protLevel == CMManager::EProtLevel1 ||
       
  2497             protLevel == CMManager::EProtLevel2 )
       
  2498         {
       
  2499         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2500         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2501         if ( capabilities == CPolicyServer::EFail )
       
  2502             {
       
  2503             User::Leave( KErrPermissionDenied );
       
  2504             }
       
  2505         }
       
  2506 
  2201     TBool hidden = aMessage.Int0();
  2507     TBool hidden = aMessage.Int0();
  2202     destinationInstance->SetMetadataL( CMManager::ESnapMetadataHiddenAgent, hidden );
  2508     destinationInstance->SetMetadataL( CMManager::ESnapMetadataHiddenAgent, hidden );
  2203 
  2509 
  2204     OstTraceFunctionExit0( CCMMSESSION_SETDESTINATIONHIDDENL_EXIT );
  2510     OstTraceFunctionExit0( CCMMSESSION_SETDESTINATIONHIDDENL_EXIT );
  2205     }
  2511     }
  2212     {
  2518     {
  2213     OstTraceFunctionEntry0( CCMMSESSION_UPDATEDESTINATIONL_ENTRY );
  2519     OstTraceFunctionEntry0( CCMMSESSION_UPDATEDESTINATIONL_ENTRY );
  2214 
  2520 
  2215     CCmmDestinationInstance* destinationInstance =
  2521     CCmmDestinationInstance* destinationInstance =
  2216             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2522             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2523 
       
  2524     // Check the protection and if protected check the needed capabilities
       
  2525     CMManager::TProtectionLevel protLevel =
       
  2526             destinationInstance->CurrentProtectionLevel();
       
  2527     if ( protLevel == CMManager::EProtLevel1 ||
       
  2528          protLevel == CMManager::EProtLevel2 ||
       
  2529          protLevel == CMManager::EProtLevel3 )
       
  2530         {
       
  2531         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2532         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2533         if ( capabilities == CPolicyServer::EFail )
       
  2534             {
       
  2535             User::Leave( KErrPermissionDenied );
       
  2536             }
       
  2537         }
       
  2538 
  2217     destinationInstance->UpdateL();
  2539     destinationInstance->UpdateL();
  2218 
  2540 
  2219     OstTraceFunctionExit0( CCMMSESSION_UPDATEDESTINATIONL_EXIT );
  2541     OstTraceFunctionExit0( CCMMSESSION_UPDATEDESTINATIONL_EXIT );
  2220     }
  2542     }
  2221 
  2543 
  2227     {
  2549     {
  2228     OstTraceFunctionEntry0( CCMMSESSION_DELETEDESTINATIONL_ENTRY );
  2550     OstTraceFunctionEntry0( CCMMSESSION_DELETEDESTINATIONL_ENTRY );
  2229 
  2551 
  2230     CCmmDestinationInstance* destinationInstance =
  2552     CCmmDestinationInstance* destinationInstance =
  2231             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
  2553             ( CCmmDestinationInstance* )iDestinationObjects->AtL( aMessage.Int3() );
       
  2554 
       
  2555     // Check the protection of destination and if protected check the needed
       
  2556     // capabilities.
       
  2557     CMManager::TProtectionLevel protLevel =
       
  2558             destinationInstance->CurrentProtectionLevel();
       
  2559     if ( protLevel == CMManager::EProtLevel1 ||
       
  2560          protLevel == CMManager::EProtLevel2 ||
       
  2561          protLevel == CMManager::EProtLevel3 )
       
  2562         {
       
  2563         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  2564         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  2565         if ( capabilities == CPolicyServer::EFail )
       
  2566             {
       
  2567             User::Leave( KErrPermissionDenied );
       
  2568             }
       
  2569         }
  2232 
  2570 
  2233     iCache.CheckIfDestinationCanBeDeletedL( *destinationInstance );
  2571     iCache.CheckIfDestinationCanBeDeletedL( *destinationInstance );
  2234     iCache.DeleteDestinationL( *destinationInstance );
  2572     iCache.DeleteDestinationL( *destinationInstance );
  2235 
  2573 
  2236     // Close the destination handle. Destination instance destructor will
  2574     // Close the destination handle. Destination instance destructor will
  2378     {
  2716     {
  2379     OstTraceFunctionEntry0( CCMMSESSION_CREATECONNMETHODL_ENTRY );
  2717     OstTraceFunctionEntry0( CCMMSESSION_CREATECONNMETHODL_ENTRY );
  2380 
  2718 
  2381     TUint32 bearerType( aMessage.Int0() );
  2719     TUint32 bearerType( aMessage.Int0() );
  2382 
  2720 
  2383     CCmmConnMethodInstance* connMethod = CCmmConnMethodInstance::NewLC( this, &iCache );
  2721     CCmmConnMethodInstance* connMethodInstance =
  2384     iCache.CreateConnMethodL( *connMethod, NULL, bearerType, 0 );
  2722             CCmmConnMethodInstance::NewLC( this, &iCache );
  2385 
  2723     iCache.CreateConnMethodL( *connMethodInstance, NULL, bearerType, 0 );
  2386     iConnMethodContainer->AddL( ( CObject* ) connMethod );
  2724 
  2387     TInt handle = iConnMethodObjects->AddL( ( CObject* ) connMethod );
  2725     iConnMethodContainer->AddL( ( CObject* ) connMethodInstance );
  2388     connMethod->SetHandle( handle );
  2726     TInt handle = iConnMethodObjects->AddL( ( CObject* ) connMethodInstance );
  2389     CleanupStack::Pop( connMethod );
  2727     connMethodInstance->SetHandle( handle );
       
  2728     CleanupStack::Pop( connMethodInstance );
  2390 
  2729 
  2391     TPckg<TInt> handlePckg( handle );
  2730     TPckg<TInt> handlePckg( handle );
  2392     TInt error = aMessage.Write( 3, handlePckg );
  2731     TInt error = aMessage.Write( 3, handlePckg );
  2393     if ( error )
  2732     if ( error )
  2394         {
  2733         {
  2406 //
  2745 //
  2407 void CCmmSession::UpdateConnMethodL( const RMessage2& aMessage )
  2746 void CCmmSession::UpdateConnMethodL( const RMessage2& aMessage )
  2408     {
  2747     {
  2409     OstTraceFunctionEntry0( CCMMSESSION_UPDATECONNMETHODL_ENTRY );
  2748     OstTraceFunctionEntry0( CCMMSESSION_UPDATECONNMETHODL_ENTRY );
  2410 
  2749 
  2411     CCmmConnMethodInstance* connMethod =
  2750     CCmmConnMethodInstance* connMethodInstance =
  2412             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2751             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2413     connMethod->UpdateL();
  2752 
       
  2753     // Check if the Client has capabilities to delete this CM.
       
  2754     CheckCapabilitiesForProtectedCML( aMessage, connMethodInstance );
       
  2755 
       
  2756     connMethodInstance->UpdateL();
  2414 
  2757 
  2415     OstTraceFunctionExit0( CCMMSESSION_UPDATECONNMETHODL_EXIT );
  2758     OstTraceFunctionExit0( CCMMSESSION_UPDATECONNMETHODL_EXIT );
  2416     }
  2759     }
  2417 
  2760 
  2418 // -----------------------------------------------------------------------------
  2761 // -----------------------------------------------------------------------------
  2433 
  2776 
  2434     OstTraceFunctionExit0( CCMMSESSION_CLOSECONNMETHOD_EXIT );
  2777     OstTraceFunctionExit0( CCMMSESSION_CLOSECONNMETHOD_EXIT );
  2435     }
  2778     }
  2436 
  2779 
  2437 // -----------------------------------------------------------------------------
  2780 // -----------------------------------------------------------------------------
  2438 // CCmmSession::ConnMethodUpdateL
  2781 // CCmmSession::DeleteConnMethodL
  2439 // -----------------------------------------------------------------------------
  2782 // -----------------------------------------------------------------------------
  2440 //
  2783 //
  2441 void CCmmSession::DeleteConnMethodL( const RMessage2& aMessage )
  2784 void CCmmSession::DeleteConnMethodL( const RMessage2& aMessage )
  2442     {
  2785     {
  2443     OstTraceFunctionEntry0( CCMMSESSION_DELETECONNMETHODL_ENTRY );
  2786     OstTraceFunctionEntry0( CCMMSESSION_DELETECONNMETHODL_ENTRY );
  2444 
  2787 
  2445     CCmmConnMethodInstance* connMethodInstance =
  2788     CCmmConnMethodInstance* connMethodInstance =
  2446             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2789             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
       
  2790 
       
  2791     // Check if the Client has capabilities to delete this CM.
       
  2792     CheckCapabilitiesForProtectedCML( aMessage, connMethodInstance );
  2447 
  2793 
  2448     iCache.CheckIfConnMethodCanBeDeletedL( *connMethodInstance );
  2794     iCache.CheckIfConnMethodCanBeDeletedL( *connMethodInstance );
  2449     iCache.DeleteConnMethodL( *connMethodInstance );
  2795     iCache.DeleteConnMethodL( *connMethodInstance );
  2450     // Ignore the boolean return value. It is always true, or the
  2796     // Ignore the boolean return value. It is always true, or the
  2451     // DeleteL()-call leaves.
  2797     // DeleteL()-call leaves.
  2581         return;
  2927         return;
  2582         }
  2928         }
  2583     CleanupStack::PushL( value );
  2929     CleanupStack::PushL( value );
  2584     TPtrC valuePtr = value->Des();
  2930     TPtrC valuePtr = value->Des();
  2585 
  2931 
  2586     // check the buffer length of the given buffer
  2932     // Check the buffer length of the given buffer.
  2587     TInt bufferLen = aMessage.GetDesMaxLength( 1 );
  2933     TInt bufferLen = aMessage.GetDesMaxLength( 1 );
  2588     if ( valuePtr.Length() > bufferLen )
  2934     if ( valuePtr.Length() > bufferLen )
  2589         {
  2935         {
  2590         User::Leave( KErrArgument );
  2936         User::Leave( KErrArgument );
  2591         }
  2937         }
  2615         return;
  2961         return;
  2616         }
  2962         }
  2617     CleanupStack::PushL( value );
  2963     CleanupStack::PushL( value );
  2618     TPtrC8 valuePtr = value->Des();
  2964     TPtrC8 valuePtr = value->Des();
  2619 
  2965 
  2620     // check the buffer length of the given buffer
  2966     // Check the buffer length of the given buffer.
  2621     TInt bufferLen = aMessage.GetDesMaxLength( 1 );
  2967     TInt bufferLen = aMessage.GetDesMaxLength( 1 );
  2622     if ( valuePtr.Length() > bufferLen )
  2968     if ( valuePtr.Length() > bufferLen )
  2623         {
  2969         {
  2624         User::Leave( KErrArgument );
  2970         User::Leave( KErrArgument );
  2625         }
  2971         }
  2639     OstTraceFunctionEntry0( CCMMSESSION_SETINTATTRIBUTEL_ENTRY );
  2985     OstTraceFunctionEntry0( CCMMSESSION_SETINTATTRIBUTEL_ENTRY );
  2640 
  2986 
  2641     CCmmConnMethodInstance* cm =
  2987     CCmmConnMethodInstance* cm =
  2642             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2988             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2643 
  2989 
       
  2990     // Check the capability needed if protected CM
       
  2991     // ECapabilityWriteDeviceData is checked earlier already.
       
  2992     CheckCapabilitiesForProtectedCML( aMessage, cm );
       
  2993 
  2644     TUint32 attribute( aMessage.Int0() );
  2994     TUint32 attribute( aMessage.Int0() );
  2645     TUint32 value( aMessage.Int1() );
  2995     TUint32 value( aMessage.Int1() );
  2646 
  2996 
  2647     cm->SetIntAttributeL( attribute, value );
  2997     cm->SetIntAttributeL( attribute, value );
  2648 
  2998 
  2658     OstTraceFunctionEntry0( CCMMSESSION_SETBOOLATTRIBUTEL_ENTRY );
  3008     OstTraceFunctionEntry0( CCMMSESSION_SETBOOLATTRIBUTEL_ENTRY );
  2659 
  3009 
  2660     CCmmConnMethodInstance* cm =
  3010     CCmmConnMethodInstance* cm =
  2661             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  3011             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  2662 
  3012 
       
  3013     // Check the capability needed if protected CM
       
  3014     // ECapabilityWriteDeviceData is checked earlier already.
       
  3015     CheckCapabilitiesForProtectedCML( aMessage, cm );
       
  3016 
  2663     TUint32 attribute( aMessage.Int0() );
  3017     TUint32 attribute( aMessage.Int0() );
  2664     TBool value( aMessage.Int1() );
  3018     TBool value( aMessage.Int1() );
  2665 
  3019 
  2666     cm->SetBoolAttributeL( attribute, value );
  3020     cm->SetBoolAttributeL( attribute, value );
  2667 
  3021 
  2676     {
  3030     {
  2677     OstTraceFunctionEntry0( CCMMSESSION_SETSTRINGATTRIBUTEL_ENTRY );
  3031     OstTraceFunctionEntry0( CCMMSESSION_SETSTRINGATTRIBUTEL_ENTRY );
  2678 
  3032 
  2679     CCmmConnMethodInstance* cm =
  3033     CCmmConnMethodInstance* cm =
  2680             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  3034             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
       
  3035 
       
  3036     // Check the capability needed if protected CM
       
  3037     // ECapabilityWriteDeviceData is checked earlier already.
       
  3038     CheckCapabilitiesForProtectedCML( aMessage, cm );
  2681 
  3039 
  2682     TUint32 attribute( aMessage.Int0() );
  3040     TUint32 attribute( aMessage.Int0() );
  2683 
  3041 
  2684     HBufC* value = HBufC::NewLC( aMessage.GetDesLengthL( 1 ) );
  3042     HBufC* value = HBufC::NewLC( aMessage.GetDesLengthL( 1 ) );
  2685     TPtr valuePtr( value->Des() );
  3043     TPtr valuePtr( value->Des() );
  2700     {
  3058     {
  2701     OstTraceFunctionEntry0( CCMMSESSION_SETSTRING8ATTRIBUTEL_ENTRY );
  3059     OstTraceFunctionEntry0( CCMMSESSION_SETSTRING8ATTRIBUTEL_ENTRY );
  2702 
  3060 
  2703     CCmmConnMethodInstance* cm =
  3061     CCmmConnMethodInstance* cm =
  2704             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
  3062             ( CCmmConnMethodInstance* )iConnMethodObjects->AtL( aMessage.Int3() );
       
  3063 
       
  3064     // Check the capability needed if protected CM
       
  3065     // ECapabilityWriteDeviceData is checked earlier already.
       
  3066     CheckCapabilitiesForProtectedCML( aMessage, cm );
  2705 
  3067 
  2706     TUint32 attribute( aMessage.Int0() );
  3068     TUint32 attribute( aMessage.Int0() );
  2707 
  3069 
  2708     HBufC8* value = HBufC8::NewLC( aMessage.GetDesLengthL( 1 ) );
  3070     HBufC8* value = HBufC8::NewLC( aMessage.GetDesLengthL( 1 ) );
  2709     TPtr8 valuePtr( value->Des() );
  3071     TPtr8 valuePtr( value->Des() );
  2879     TUint32 bearerType( aMessage.Int1() );
  3241     TUint32 bearerType( aMessage.Int1() );
  2880 
  3242 
  2881     CCmmDestinationInstance* destination =
  3243     CCmmDestinationInstance* destination =
  2882             ( CCmmDestinationInstance* )iDestinationObjects->AtL( destinationHandle );
  3244             ( CCmmDestinationInstance* )iDestinationObjects->AtL( destinationHandle );
  2883 
  3245 
       
  3246     // Check the protection and if protected check the needed capabilities.
       
  3247     CMManager::TProtectionLevel protLevel =
       
  3248             destination->CurrentProtectionLevel();
       
  3249     if ( protLevel == CMManager::EProtLevel1 )
       
  3250         {
       
  3251         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  3252         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  3253         if ( capabilities == CPolicyServer::EFail )
       
  3254             {
       
  3255             User::Leave( KErrPermissionDenied );
       
  3256             }
       
  3257         }
       
  3258 
  2884     CCmmConnMethodInstance* connMethod = CCmmConnMethodInstance::NewLC( this, &iCache );
  3259     CCmmConnMethodInstance* connMethod = CCmmConnMethodInstance::NewLC( this, &iCache );
  2885     iCache.CreateConnMethodL( *connMethod, destination, bearerType, 0 );
  3260     iCache.CreateConnMethodL( *connMethod, destination, bearerType, 0 );
  2886 
  3261 
  2887     iConnMethodContainer->AddL( ( CObject* ) connMethod );
  3262     iConnMethodContainer->AddL( ( CObject* ) connMethod );
  2888     TInt handle = iConnMethodObjects->AddL( ( CObject* ) connMethod );
  3263     TInt handle = iConnMethodObjects->AddL( ( CObject* ) connMethod );
  2915     TUint32 connMethodId( aMessage.Int2() );
  3290     TUint32 connMethodId( aMessage.Int2() );
  2916 
  3291 
  2917     CCmmDestinationInstance* destination =
  3292     CCmmDestinationInstance* destination =
  2918             ( CCmmDestinationInstance* )iDestinationObjects->AtL( destinationHandle );
  3293             ( CCmmDestinationInstance* )iDestinationObjects->AtL( destinationHandle );
  2919 
  3294 
       
  3295     // Check the protection and if protected check the needed capabilities.
       
  3296     CMManager::TProtectionLevel protLevel =
       
  3297             destination->CurrentProtectionLevel();
       
  3298     if ( protLevel == CMManager::EProtLevel1 )
       
  3299         {
       
  3300         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  3301         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  3302         if ( capabilities == CPolicyServer::EFail )
       
  3303             {
       
  3304             User::Leave( KErrPermissionDenied );
       
  3305             }
       
  3306         }
       
  3307 
  2920     CCmmConnMethodInstance* connMethod =
  3308     CCmmConnMethodInstance* connMethod =
  2921             CCmmConnMethodInstance::NewLC( this, &iCache );
  3309             CCmmConnMethodInstance::NewLC( this, &iCache );
  2922     // Will check if ID is available.
  3310     // Will check if ID is available.
  2923     iCache.CreateConnMethodL( *connMethod, destination, bearerType, connMethodId );
  3311     iCache.CreateConnMethodL( *connMethod, destination, bearerType, connMethodId );
  2924 
  3312 
  3059         User::Leave( error );
  3447         User::Leave( error );
  3060         }
  3448         }
  3061     OstTraceFunctionExit0( CCMMSESSION_GETEMBEDDEDDESTINATIONL_EXIT );
  3449     OstTraceFunctionExit0( CCMMSESSION_GETEMBEDDEDDESTINATIONL_EXIT );
  3062     }
  3450     }
  3063 
  3451 
       
  3452 // -----------------------------------------------------------------------------
       
  3453 // Check if CM is protected and if so then check the needed capabilities.
       
  3454 // -----------------------------------------------------------------------------
       
  3455 //
       
  3456 void CCmmSession::CheckCapabilitiesForProtectedCML(
       
  3457         const RMessage2& aMessage,
       
  3458         CCmmConnMethodInstance* aConnectionMethodInstance )
       
  3459     {
       
  3460     OstTraceFunctionEntry0( CCMMSESSION_CHECKCAPABILITIESFORPROTECTEDCML_ENTRY );
       
  3461 
       
  3462     TBool prot = aConnectionMethodInstance->GetBoolAttributeL( CMManager::ECmProtected );
       
  3463     if ( prot )
       
  3464         {
       
  3465         CPolicyServer::TCustomResult capabilities( CPolicyServer::EPass );
       
  3466         capabilities = iServer.CapabilityCheckWithProtection( aMessage );
       
  3467         if ( capabilities == CPolicyServer::EFail )
       
  3468             {
       
  3469             User::Leave( KErrPermissionDenied );
       
  3470             }
       
  3471         }
       
  3472 
       
  3473     OstTraceFunctionExit0( CCMMSESSION_CHECKCAPABILITIESFORPROTECTEDCML_EXIT );
       
  3474     }
       
  3475 
  3064 // End of file
  3476 // End of file