wmdrm/wmdrmengine/wmdrmserver/server/src/wmdrmsession.cpp
changeset 87 c938d010410d
parent 47 5ed7931150e9
equal deleted inserted replaced
84:b09186059647 87:c938d010410d
     1 /*
     1 /*
     2 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    40 // CWmDrmSession::CWmDrmSession
    40 // CWmDrmSession::CWmDrmSession
    41 // Constructor
    41 // Constructor
    42 //---------------------------------------------------------------------------
    42 //---------------------------------------------------------------------------
    43 //
    43 //
    44 CWmDrmSession::CWmDrmSession()
    44 CWmDrmSession::CWmDrmSession()
    45 	{
    45     {
    46 	}
    46     }
    47 
    47 
    48 //---------------------------------------------------------------------------
    48 //---------------------------------------------------------------------------
    49 // CWmDrmSession::~CWmDrmSession
    49 // CWmDrmSession::~CWmDrmSession
    50 // Destructor
    50 // Destructor
    51 //---------------------------------------------------------------------------
    51 //---------------------------------------------------------------------------
    52 //	
    52 //
    53 CWmDrmSession::~CWmDrmSession()
    53 CWmDrmSession::~CWmDrmSession()
    54 	{
    54     {
    55 	LOGFN( "CWmDrmSession::~CWmDrmSession" );
    55     LOGFN( "CWmDrmSession::~CWmDrmSession" );
    56     //Server().Cache()->FlushL();
    56     //Server().Cache()->FlushL();
    57 	delete iEnumerator;
    57     delete iEnumerator;
    58 	iEnumerator = NULL;
    58     iEnumerator = NULL;
    59     delete iSlot;
    59     delete iSlot;
    60 	iSlot = NULL;
    60     iSlot = NULL;
    61 	}
    61     }
    62 
    62 
    63 //---------------------------------------------------------------------------
    63 //---------------------------------------------------------------------------
    64 // CWmDrmSession::InitStoreL
    64 // CWmDrmSession::InitStoreL
    65 //---------------------------------------------------------------------------
    65 //---------------------------------------------------------------------------
    66 //
    66 //
    67 TInt CWmDrmSession::InitStoreL( const RMessage2& aMessage )
    67 TInt CWmDrmSession::InitStoreL( const RMessage2& aMessage )
    68     {
    68     {
    69     TInt r = KErrNone;
    69     TInt r = KErrNone;
    70     TBuf8<KMaxWmDrmStoreNameSize> store;
    70     TBuf8<KMaxWmDrmStoreNameSize> store;
    71     
    71 
    72     LOGFNR( "CWmDrmSession::InitStoreL", r );
    72     LOGFNR( "CWmDrmSession::InitStoreL", r );
    73     if ( aMessage.GetDesLength( 0 ) > KMaxWmDrmStoreNameSize || aMessage.GetDesLength( 0 ) <= 0 )
    73     if ( aMessage.GetDesLength( 0 ) > KMaxWmDrmStoreNameSize || aMessage.GetDesLength( 0 ) <= 0 )
    74         {
    74         {
    75         User::Leave( KErrArgument );
    75         User::Leave( KErrArgument );
    76         }
    76         }
    84     }
    84     }
    85 
    85 
    86 //---------------------------------------------------------------------------
    86 //---------------------------------------------------------------------------
    87 // CWmDrmSession::RemoveStoreL
    87 // CWmDrmSession::RemoveStoreL
    88 //---------------------------------------------------------------------------
    88 //---------------------------------------------------------------------------
    89 //    
    89 //
    90 TInt CWmDrmSession::RemoveStoreL( const RMessage2& aMessage )
    90 TInt CWmDrmSession::RemoveStoreL( const RMessage2& aMessage )
    91     {
    91     {
    92     TInt r = KErrNone;
    92     TInt r = KErrNone;
    93     TBuf8<KMaxWmDrmStoreNameSize> store;
    93     TBuf8<KMaxWmDrmStoreNameSize> store;
    94     
    94 
    95     LOGFNR( "CWmDrmSession::RemoveStoreL", r );
    95     LOGFNR( "CWmDrmSession::RemoveStoreL", r );
    96     if ( aMessage.GetDesLength( 0 ) > KMaxWmDrmStoreNameSize || aMessage.GetDesLength( 0 ) <= 0  )
    96     if ( aMessage.GetDesLength( 0 ) > KMaxWmDrmStoreNameSize || aMessage.GetDesLength( 0 ) <= 0  )
    97         {
    97         {
    98         User::Leave( KErrArgument );
    98         User::Leave( KErrArgument );
    99         }
    99         }
   104     }
   104     }
   105 
   105 
   106 //---------------------------------------------------------------------------
   106 //---------------------------------------------------------------------------
   107 // CWmDrmSession::InitNamespaceL
   107 // CWmDrmSession::InitNamespaceL
   108 //---------------------------------------------------------------------------
   108 //---------------------------------------------------------------------------
   109 //    
   109 //
   110 TInt CWmDrmSession::InitNamespaceL( const RMessage2& aMessage )
   110 TInt CWmDrmSession::InitNamespaceL( const RMessage2& aMessage )
   111     {
   111     {
   112     TInt r = KErrNone;
   112     TInt r = KErrNone;
   113     TBuf8<KMaxWmDrmStoreNameSize> store;
   113     TBuf8<KMaxWmDrmStoreNameSize> store;
   114     TBuf8<KMaxWmDrmNamespaceNameSize> nameSpace;
   114     TBuf8<KMaxWmDrmNamespaceNameSize> nameSpace;
   115     
   115 
   116     LOGFNR( "CWmDrmSession::InitNamespaceL", r );
   116     LOGFNR( "CWmDrmSession::InitNamespaceL", r );
   117     // :KLUDGE: Note: store length of zero is allowed
   117     // :KLUDGE: Note: store length of zero is allowed
   118     if ( aMessage.GetDesLengthL( 0 ) > KMaxWmDrmStoreNameSize ||
   118     if ( aMessage.GetDesLengthL( 0 ) > KMaxWmDrmStoreNameSize ||
   119         aMessage.GetDesLengthL( 1 ) > KMaxWmDrmNamespaceNameSize ||
   119         aMessage.GetDesLengthL( 1 ) > KMaxWmDrmNamespaceNameSize ||
   120         aMessage.GetDesLength( 1 ) <= 0 )
   120         aMessage.GetDesLength( 1 ) <= 0 )
   137     }
   137     }
   138 
   138 
   139 //---------------------------------------------------------------------------
   139 //---------------------------------------------------------------------------
   140 // CWmDrmSession::RemoveNamespaceL
   140 // CWmDrmSession::RemoveNamespaceL
   141 //---------------------------------------------------------------------------
   141 //---------------------------------------------------------------------------
   142 //    
   142 //
   143 TInt CWmDrmSession::RemoveNamespaceL( const RMessage2& aMessage )
   143 TInt CWmDrmSession::RemoveNamespaceL( const RMessage2& aMessage )
   144     {
   144     {
   145     TInt r = KErrNone;
   145     TInt r = KErrNone;
   146     TBuf8<KMaxWmDrmStoreNameSize> store;
   146     TBuf8<KMaxWmDrmStoreNameSize> store;
   147     TBuf8<KMaxWmDrmNamespaceNameSize> nameSpace;
   147     TBuf8<KMaxWmDrmNamespaceNameSize> nameSpace;
   148     
   148 
   149     LOGFNR( "CWmDrmSession::RemoveNamespaceL", r );
   149     LOGFNR( "CWmDrmSession::RemoveNamespaceL", r );
   150     // :KLUDGE: Note: store length of zero is allowed
   150     // :KLUDGE: Note: store length of zero is allowed
   151     if ( aMessage.GetDesLengthL( 0 ) > KMaxWmDrmStoreNameSize ||
   151     if ( aMessage.GetDesLengthL( 0 ) > KMaxWmDrmStoreNameSize ||
   152         aMessage.GetDesLengthL( 1 ) > KMaxWmDrmNamespaceNameSize ||
   152         aMessage.GetDesLengthL( 1 ) > KMaxWmDrmNamespaceNameSize ||
   153         aMessage.GetDesLength( 1 ) <= 0 )
   153         aMessage.GetDesLength( 1 ) <= 0 )
   170     }
   170     }
   171 
   171 
   172 //---------------------------------------------------------------------------
   172 //---------------------------------------------------------------------------
   173 // CWmDrmSession::SlotOpenL
   173 // CWmDrmSession::SlotOpenL
   174 //---------------------------------------------------------------------------
   174 //---------------------------------------------------------------------------
   175 //    
   175 //
   176 TInt CWmDrmSession::SlotOpenL( const RMessage2& aMessage )
   176 TInt CWmDrmSession::SlotOpenL( const RMessage2& aMessage )
   177     {
   177     {
   178     TInt r = KErrNone;
   178     TInt r = KErrNone;
   179     RBuf8 messageBuffer;
   179     RBuf8 messageBuffer;
   180 	TInt size;
   180     TInt size;
   181     
   181 
   182     LOGFNR( "CWmDrmSession::SlotOpenL", r );
   182     LOGFNR( "CWmDrmSession::SlotOpenL", r );
   183     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0 )
   183     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0 )
   184         {
   184         {
   185         User::Leave( KErrArgument );
   185         User::Leave( KErrArgument );
   186         }
   186         }
   200     }
   200     }
   201 
   201 
   202 //---------------------------------------------------------------------------
   202 //---------------------------------------------------------------------------
   203 // CWmDrmSession::SlotCreateL
   203 // CWmDrmSession::SlotCreateL
   204 //---------------------------------------------------------------------------
   204 //---------------------------------------------------------------------------
   205 //    
   205 //
   206 TInt CWmDrmSession::SlotCreateL( const RMessage2& aMessage )
   206 TInt CWmDrmSession::SlotCreateL( const RMessage2& aMessage )
   207     {
   207     {
   208     TInt r = KErrNone;
   208     TInt r = KErrNone;
   209     RBuf8 messageBuffer;
   209     RBuf8 messageBuffer;
   210 	TInt size;
   210     TInt size;
   211     
   211 
   212     LOGFNR( "CWmDrmSession::SlotCreateL", r );
   212     LOGFNR( "CWmDrmSession::SlotCreateL", r );
   213     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0  )
   213     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0  )
   214         {
   214         {
   215         User::Leave( KErrArgument );
   215         User::Leave( KErrArgument );
   216         }
   216         }
   221     if ( iSlot != NULL )
   221     if ( iSlot != NULL )
   222         {
   222         {
   223         delete iSlot;
   223         delete iSlot;
   224         iSlot = NULL;
   224         iSlot = NULL;
   225         }
   225         }
   226     
   226 
   227     iSlot = CSlot::NewL( &Server(), messageBuffer );
   227     iSlot = CSlot::NewL( &Server(), messageBuffer );
   228     iSlot->CreateL( size );
   228     iSlot->CreateL( size );
   229     CleanupStack::PopAndDestroy( &messageBuffer );
   229     CleanupStack::PopAndDestroy( &messageBuffer );
   230     return r;
   230     return r;
   231     }
   231     }
   232 
   232 
   233 //---------------------------------------------------------------------------
   233 //---------------------------------------------------------------------------
   234 // CWmDrmSession::SlotSeekL
   234 // CWmDrmSession::SlotSeekL
   235 //---------------------------------------------------------------------------
   235 //---------------------------------------------------------------------------
   236 //    
   236 //
   237 TInt CWmDrmSession::SlotSeekL( const RMessage2& aMessage )
   237 TInt CWmDrmSession::SlotSeekL( const RMessage2& aMessage )
   238     {
   238     {
   239     TInt r = KErrNone;
   239     TInt r = KErrNone;
   240     TSeek whence = ESeekStart;
   240     TSeek whence = ESeekStart;
   241     TInt pos = aMessage.Int0();
   241     TInt pos = aMessage.Int0();
   242     TInt size;
   242     TInt size;
   243     
   243 
   244     LOGFNR( "CWmDrmSession::SlotSeekL", r );
   244     LOGFNR( "CWmDrmSession::SlotSeekL", r );
   245     if ( iSlot == NULL )
   245     if ( iSlot == NULL )
   246         {
   246         {
   247         User::Leave( KErrNotReady );
   247         User::Leave( KErrNotReady );
   248         }
   248         }
   276     }
   276     }
   277 
   277 
   278 //---------------------------------------------------------------------------
   278 //---------------------------------------------------------------------------
   279 // CWmDrmSession::SlotReadL
   279 // CWmDrmSession::SlotReadL
   280 //---------------------------------------------------------------------------
   280 //---------------------------------------------------------------------------
   281 //    
   281 //
   282 TInt CWmDrmSession::SlotReadL( const RMessage2& aMessage )
   282 TInt CWmDrmSession::SlotReadL( const RMessage2& aMessage )
   283     {
   283     {
   284     TInt r = KErrNone;
   284     TInt r = KErrNone;
   285     RBuf8 buf;
   285     RBuf8 buf;
   286     TInt amountRead = 0;
   286     TInt amountRead = 0;
   287     
   287 
   288     LOGFNR( "CWmDrmSession::SlotReadL", r );
   288     LOGFNR( "CWmDrmSession::SlotReadL", r );
   289     if ( iSlot == NULL )
   289     if ( iSlot == NULL )
   290         {
   290         {
   291         User::Leave( KErrNotReady );
   291         User::Leave( KErrNotReady );
   292         }
   292         }
   304     }
   304     }
   305 
   305 
   306 //---------------------------------------------------------------------------
   306 //---------------------------------------------------------------------------
   307 // CWmDrmSession::SlotWriteL
   307 // CWmDrmSession::SlotWriteL
   308 //---------------------------------------------------------------------------
   308 //---------------------------------------------------------------------------
   309 //    
   309 //
   310 TInt CWmDrmSession::SlotWriteL( const RMessage2& aMessage )
   310 TInt CWmDrmSession::SlotWriteL( const RMessage2& aMessage )
   311     {
   311     {
   312     TInt r = KErrNone;
   312     TInt r = KErrNone;
   313     RBuf8 buf;
   313     RBuf8 buf;
   314     
   314 
   315     LOGFNR( "CWmDrmSession::SlotWriteL", r );
   315     LOGFNR( "CWmDrmSession::SlotWriteL", r );
   316     if ( iSlot == NULL )
   316     if ( iSlot == NULL )
   317         {
   317         {
   318         User::Leave( KErrNotReady );
   318         User::Leave( KErrNotReady );
   319         }
   319         }
   322     aMessage.ReadL( 0, buf );
   322     aMessage.ReadL( 0, buf );
   323     r = iSlot->WriteL( buf );
   323     r = iSlot->WriteL( buf );
   324     CleanupStack::PopAndDestroy( &buf );
   324     CleanupStack::PopAndDestroy( &buf );
   325     return r;
   325     return r;
   326     }
   326     }
   327     
   327 
   328 TInt CWmDrmSession::SlotResizeL( const RMessage2& aMessage )
   328 TInt CWmDrmSession::SlotResizeL( const RMessage2& aMessage )
   329     {
   329     {
   330     TInt r = KErrNone;
   330     TInt r = KErrNone;
   331     
   331 
   332     LOGFNR( "CWmDrmSession::SlotResizeL", r );
   332     LOGFNR( "CWmDrmSession::SlotResizeL", r );
   333     if ( iSlot == NULL )
   333     if ( iSlot == NULL )
   334         {
   334         {
   335         User::Leave( KErrNotReady );
   335         User::Leave( KErrNotReady );
   336         }
   336         }
   339     }
   339     }
   340 
   340 
   341 //---------------------------------------------------------------------------
   341 //---------------------------------------------------------------------------
   342 // CWmDrmSession::SlotDeleteL
   342 // CWmDrmSession::SlotDeleteL
   343 //---------------------------------------------------------------------------
   343 //---------------------------------------------------------------------------
   344 //    
   344 //
   345 TInt CWmDrmSession::SlotDeleteL( const RMessage2& aMessage )
   345 TInt CWmDrmSession::SlotDeleteL( const RMessage2& aMessage )
   346     {
   346     {
   347     TInt r = KErrNone;
   347     TInt r = KErrNone;
   348     RBuf8 messageBuffer;
   348     RBuf8 messageBuffer;
   349     
   349 
   350     LOGFNR( "CWmDrmSession::SlotDeleteL", r );
   350     LOGFNR( "CWmDrmSession::SlotDeleteL", r );
   351     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize )
   351     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize )
   352         {
   352         {
   353         User::Leave( KErrArgument );
   353         User::Leave( KErrArgument );
   354         }
   354         }
   369     }
   369     }
   370 
   370 
   371 //---------------------------------------------------------------------------
   371 //---------------------------------------------------------------------------
   372 // CWmDrmSession::SlotCloseL
   372 // CWmDrmSession::SlotCloseL
   373 //---------------------------------------------------------------------------
   373 //---------------------------------------------------------------------------
   374 //    
   374 //
   375 TInt CWmDrmSession::SlotCloseL( const RMessage2& /*aMessage*/ )
   375 TInt CWmDrmSession::SlotCloseL( const RMessage2& /*aMessage*/ )
   376     {
   376     {
   377     TInt r = KErrNone;
   377     TInt r = KErrNone;
   378     
   378 
   379     LOGFNR( "CWmDrmSession::SlotCloseL", r );
   379     LOGFNR( "CWmDrmSession::SlotCloseL", r );
   380     if ( iSlot == NULL )
   380     if ( iSlot == NULL )
   381         {
   381         {
   382         User::Leave( KErrNotReady );
   382         User::Leave( KErrNotReady );
   383         }
   383         }
   387     }
   387     }
   388 
   388 
   389 //---------------------------------------------------------------------------
   389 //---------------------------------------------------------------------------
   390 // CWmDrmSession::EnumerateStartL
   390 // CWmDrmSession::EnumerateStartL
   391 //---------------------------------------------------------------------------
   391 //---------------------------------------------------------------------------
   392 //    
   392 //
   393 TInt CWmDrmSession::EnumerateStartL( const RMessage2& aMessage )
   393 TInt CWmDrmSession::EnumerateStartL( const RMessage2& aMessage )
   394     {
   394     {
   395     TInt r = KErrNone;
   395     TInt r = KErrNone;
   396     RBuf8 messageBuffer;
   396     RBuf8 messageBuffer;
   397     
   397 
   398     LOGFNR( "CWmDrmSession::EnumerateStartL", r );
   398     LOGFNR( "CWmDrmSession::EnumerateStartL", r );
   399     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0  )
   399     if ( aMessage.GetDesLength( 0 ) > KMaxSlotNameSize || aMessage.GetDesLength( 0 ) <= 0  )
   400         {
   400         {
   401         User::Leave( KErrArgument );
   401         User::Leave( KErrArgument );
   402         }
   402         }
   420     }
   420     }
   421 
   421 
   422 //---------------------------------------------------------------------------
   422 //---------------------------------------------------------------------------
   423 // CWmDrmSession::EnumerateReloadL
   423 // CWmDrmSession::EnumerateReloadL
   424 //---------------------------------------------------------------------------
   424 //---------------------------------------------------------------------------
   425 //    
   425 //
   426 TInt CWmDrmSession::EnumerateReloadL( const RMessage2& aMessage )
   426 TInt CWmDrmSession::EnumerateReloadL( const RMessage2& aMessage )
   427     {
   427     {
   428     TInt r = KErrNone;
   428     TInt r = KErrNone;
   429     TBuf8<KWmDrmIdSize> hash;
   429     TBuf8<KWmDrmIdSize> hash;
   430     TBuf8<KWmDrmIdSize> id;
   430     TBuf8<KWmDrmIdSize> id;
   431     
   431 
   432     LOGFNR( "CWmDrmSession::EnumerateReloadL", r );
   432     LOGFNR( "CWmDrmSession::EnumerateReloadL", r );
   433     if ( iEnumerator == NULL )
   433     if ( iEnumerator == NULL )
   434         {
   434         {
   435         User::Leave( KErrNotReady );
   435         User::Leave( KErrNotReady );
   436         }
   436         }
   446     }
   446     }
   447 
   447 
   448 //---------------------------------------------------------------------------
   448 //---------------------------------------------------------------------------
   449 // CWmDrmSession::EnumerateNextL
   449 // CWmDrmSession::EnumerateNextL
   450 //---------------------------------------------------------------------------
   450 //---------------------------------------------------------------------------
   451 //    
   451 //
   452 TInt CWmDrmSession::EnumerateNextL( const RMessage2& aMessage )
   452 TInt CWmDrmSession::EnumerateNextL( const RMessage2& aMessage )
   453     {
   453     {
   454     TInt r = KErrNone;
   454     TInt r = KErrNone;
   455     TBuf8<KWmDrmIdSize> hash;
   455     TBuf8<KWmDrmIdSize> hash;
   456     TBuf8<KWmDrmIdSize> id;
   456     TBuf8<KWmDrmIdSize> id;
   457     
   457 
   458     LOGFNR( "CWmDrmSession::EnumerateNextL", r );
   458     LOGFNR( "CWmDrmSession::EnumerateNextL", r );
   459     if ( iEnumerator == NULL )
   459     if ( iEnumerator == NULL )
   460         {
   460         {
   461         User::Leave( KErrNotReady );
   461         User::Leave( KErrNotReady );
   462         }
   462         }
   476     }
   476     }
   477 
   477 
   478 //---------------------------------------------------------------------------
   478 //---------------------------------------------------------------------------
   479 // CWmDrmSession::EnumerateDeleteL
   479 // CWmDrmSession::EnumerateDeleteL
   480 //---------------------------------------------------------------------------
   480 //---------------------------------------------------------------------------
   481 //    
   481 //
   482 TInt CWmDrmSession::EnumerateDeleteL ( const RMessage2& /*aMessage*/ )
   482 TInt CWmDrmSession::EnumerateDeleteL ( const RMessage2& /*aMessage*/ )
   483     {
   483     {
   484     TInt r = KErrNone;
   484     TInt r = KErrNone;
   485     
   485 
   486     LOGFNR( "CWmDrmSession::EnumerateDeleteL", r );
   486     LOGFNR( "CWmDrmSession::EnumerateDeleteL", r );
   487     if ( iEnumerator == NULL )
   487     if ( iEnumerator == NULL )
   488         {
   488         {
   489         User::Leave( KErrNotReady );
   489         User::Leave( KErrNotReady );
   490         }
   490         }
   497 //---------------------------------------------------------------------------
   497 //---------------------------------------------------------------------------
   498 //
   498 //
   499 TInt CWmDrmSession::EnumerateEndL ( const RMessage2& /*aMessage*/ )
   499 TInt CWmDrmSession::EnumerateEndL ( const RMessage2& /*aMessage*/ )
   500     {
   500     {
   501     TInt r = KErrNone;
   501     TInt r = KErrNone;
   502     
   502 
   503     LOGFNR( "CWmDrmSession::EnumerateEndL", r );
   503     LOGFNR( "CWmDrmSession::EnumerateEndL", r );
   504     if ( iEnumerator == NULL )
   504     if ( iEnumerator == NULL )
   505         {
   505         {
   506         User::Leave( KErrNotReady );
   506         User::Leave( KErrNotReady );
   507         }
   507         }
   516 //---------------------------------------------------------------------------
   516 //---------------------------------------------------------------------------
   517 //
   517 //
   518 TInt CWmDrmSession::EmptyCacheL( const RMessage2& aMessage )
   518 TInt CWmDrmSession::EmptyCacheL( const RMessage2& aMessage )
   519     {
   519     {
   520     TInt r = KErrNone;
   520     TInt r = KErrNone;
   521     
   521 
   522     LOGFNR( "CWmDrmSession::EmptyCacheL", r );
   522     LOGFNR( "CWmDrmSession::EmptyCacheL", r );
   523     TRAP_IGNORE( EnumerateEndL( aMessage ) );
   523     TRAP_IGNORE( EnumerateEndL( aMessage ) );
   524     TRAP_IGNORE( SlotCloseL( aMessage ) );
   524     TRAP_IGNORE( SlotCloseL( aMessage ) );
   525     Server().ResetCacheL();
   525     Server().ResetCacheL();
   526     return r;
   526     return r;
   527     }
   527     }
   528 
   528 
   529 //---------------------------------------------------------------------------
   529 //---------------------------------------------------------------------------
   530 // CWmDrmSession::LogStats
   530 // CWmDrmSession::LogStats
   531 //---------------------------------------------------------------------------
   531 //---------------------------------------------------------------------------
   532 //    
   532 //
   533 TInt CWmDrmSession::LogStats( const RMessage2& /*aMessage*/ )
   533 TInt CWmDrmSession::LogStats( const RMessage2& /*aMessage*/ )
   534     {
   534     {
   535     TInt r = KErrNone;
   535     TInt r = KErrNone;
   536 
   536 
   537 #ifdef _LOGGING    
   537 #ifdef _LOGGING
   538     TInt cells;
   538     TInt cells;
   539     TInt amount;
   539     TInt amount;
   540     TInt i;
   540     TInt i;
   541     TInt j;
   541     TInt j;
   542     _LIT( KStatsDir, "wmdrm" );
   542     _LIT( KStatsDir, "wmdrm" );
   543     _LIT( KStatsFile, "wmdrmserver.txt" );
   543     _LIT( KStatsFile, "wmdrmserver.txt" );
   544     
   544 
   545     LOGFNR( "CWmDrmSession::LogStatsL", r );
   545     LOGFNR( "CWmDrmSession::LogStatsL", r );
   546     cells = User::AllocSize( amount );
   546     cells = User::AllocSize( amount );
   547     RFileLogger::Write( KStatsDir, KStatsFile, EFileLoggingModeAppend, _L( "Statistics:" ) );
   547     RFileLogger::Write( KStatsDir, KStatsFile, EFileLoggingModeAppend, _L( "Statistics:" ) );
   548     RFileLogger::WriteFormat( KStatsDir, KStatsFile, EFileLoggingModeAppend,
   548     RFileLogger::WriteFormat( KStatsDir, KStatsFile, EFileLoggingModeAppend,
   549         _L( "Memory: %d cells, %d bytes allocated" ), cells, amount );
   549         _L( "Memory: %d cells, %d bytes allocated" ), cells, amount );
   582             RFileLogger::Write( KStatsDir, KStatsFile, EFileLoggingModeAppend,
   582             RFileLogger::Write( KStatsDir, KStatsFile, EFileLoggingModeAppend,
   583                 *Server().EnumeratorCache()->iEnumeratorCache[i]->iEntries[j] );
   583                 *Server().EnumeratorCache()->iEnumeratorCache[i]->iEntries[j] );
   584             }
   584             }
   585         }
   585         }
   586 #endif
   586 #endif
   587     
   587 
   588     return r;
   588     return r;
   589     }
   589     }
   590 
   590 
   591 //---------------------------------------------------------------------------
   591 //---------------------------------------------------------------------------
   592 // CWmDrmSession::TimeValid
   592 // CWmDrmSession::TimeValid
   593 //---------------------------------------------------------------------------
   593 //---------------------------------------------------------------------------
   594 //
   594 //
   595 TInt CWmDrmSession::TimeValid( const RMessage2& /*aMessage*/ )
   595 TInt CWmDrmSession::TimeValid( const RMessage2& /*aMessage*/ )
   596     {
   596     {
   597     TInt r = KErrNone;
   597     TInt r = KErrNone;
   598     
   598 
   599     LOGFNR( "CWmDrmSession::TimeValid", r );
   599     LOGFNR( "CWmDrmSession::TimeValid", r );
   600     r = Server().Clock()->TimeIsGood();
   600     r = Server().Clock()->TimeIsGood();
   601     return r;
   601     return r;
   602     }
   602     }
   603 
   603 
   604 //---------------------------------------------------------------------------
   604 //---------------------------------------------------------------------------
   605 // CWmDrmSession::SetTimeAsValidL
   605 // CWmDrmSession::SetTimeAsValidL
   606 //---------------------------------------------------------------------------
   606 //---------------------------------------------------------------------------
   607 //    
   607 //
   608 void CWmDrmSession::SetTimeAsValidL( const RMessage2& aMessage )
   608 void CWmDrmSession::SetTimeAsValidL( const RMessage2& aMessage )
   609     {
   609     {
   610     LOGFN( "CWmDrmSession::TimeValid" );
   610     LOGFN( "CWmDrmSession::TimeValid" );
   611     Server().Clock()->SetTimeAsGoodL( aMessage.Int0() == 0 ? EFalse : ETrue );
   611     Server().Clock()->SetTimeAsGoodL( aMessage.Int0() == 0 ? EFalse : ETrue );
   612     }
   612     }
   613     
   613 
   614 
   614 
   615 //---------------------------------------------------------------------------
   615 //---------------------------------------------------------------------------
   616 // CWmDrmSession::DeleteRightsL
   616 // CWmDrmSession::DeleteRightsL
   617 //---------------------------------------------------------------------------
   617 //---------------------------------------------------------------------------
   618 //    
   618 //
   619 TInt CWmDrmSession::DeleteRightsL( const RMessage2& /*aMessage*/ )
   619 TInt CWmDrmSession::DeleteRightsL( const RMessage2& /*aMessage*/ )
   620     {
   620     {
   621     TInt r = KErrNone;
   621     TInt r = KErrNone;
   622     TBool wmDrmRightsConfigFound( EFalse );
   622     TBool wmDrmRightsConfigFound( EFalse );
   623     TChar driveLetter;
   623     TChar driveLetter;
   624     TDrmScheme drmScheme( EDrmSchemeWmDrm );
   624     TDrmScheme drmScheme( EDrmSchemeWmDrm );
   625     
   625 
   626     LOGFNR( "CWmDrmSession::DeleteRightsL", r );
   626     LOGFNR( "CWmDrmSession::DeleteRightsL", r );
   627     // Close EVERYTHING down, clear cache etc, so that we have nothing going on
   627     // Close EVERYTHING down, clear cache etc, so that we have nothing going on
   628     // When we start to delete stuff
   628     // When we start to delete stuff
   629     Server().ResetCacheL();
   629     Server().ResetCacheL();
   630     
   630 
   631     wmDrmRightsConfigFound = DrmRightsStoringLocation::CheckDrmRightsStorageDriveL(
   631     wmDrmRightsConfigFound = DrmRightsStoringLocation::CheckDrmRightsStorageDriveL(
   632 	  		Server().Fs(), drmScheme, driveLetter );
   632             Server().Fs(), drmScheme, driveLetter );
   633     
   633 
   634     // If WM DRM rights storage configuration is found, update both databases
   634     // If WM DRM rights storage configuration is found, update both databases
   635     if ( wmDrmRightsConfigFound )
   635     if ( wmDrmRightsConfigFound )
   636         {
   636         {
   637     	Server().DataStore()->UpdateDummyDbFileL( 
   637         Server().DataStore()->UpdateDummyDbFileL(
   638     	    Server().DataStore()->DummyDBSizeL( ETrue ), ETrue );
   638             Server().DataStore()->DummyDBSizeL( ETrue ), ETrue );
   639     	}
   639         }
   640     Server().DataStore()->UpdateDummyDbFileL( 
   640     Server().DataStore()->UpdateDummyDbFileL(
   641         Server().DataStore()->DummyDBSizeL( EFalse ), EFalse );
   641         Server().DataStore()->DummyDBSizeL( EFalse ), EFalse );
   642     
   642 
   643     // Delete license store
   643     // Delete license store
   644     Server().Db()->DeleteLicenseStoreL();
   644     Server().Db()->DeleteLicenseStoreL();
   645     
   645 
   646     // If WM DRM rights storage configuration is found, update both databases 
   646     // If WM DRM rights storage configuration is found, update both databases
   647     if ( wmDrmRightsConfigFound )
   647     if ( wmDrmRightsConfigFound )
   648     	{
   648         {
   649     	Server().DataStore()->UpdateDummyDbFileL( 0, ETrue );
   649         Server().DataStore()->UpdateDummyDbFileL( 0, ETrue );
   650     	}	
   650         }
   651     Server().DataStore()->UpdateDummyDbFileL( 0, EFalse );
   651     Server().DataStore()->UpdateDummyDbFileL( 0, EFalse );
   652     
   652 
   653     return r;
   653     return r;
   654     }
   654     }
   655 
   655 
   656 //---------------------------------------------------------------------------
   656 //---------------------------------------------------------------------------
   657 // CWmDrmSession::StoreStateL
   657 // CWmDrmSession::StoreStateL
   658 //---------------------------------------------------------------------------
   658 //---------------------------------------------------------------------------
   659 //
   659 //
   660 void CWmDrmSession::StoreStateL( const RMessage2& aMessage )
   660 void CWmDrmSession::StoreStateL( const RMessage2& aMessage )
   661     {
   661     {
   662     TWmDrmStoreState state;
   662     TWmDrmStoreState state;
   663     
   663 
   664     LOGFN( "CWmDrmSession::StoreStateL" );
   664     LOGFN( "CWmDrmSession::StoreStateL" );
   665     state = Server().DataStore()->DataStoreStateL();
   665     state = Server().DataStore()->DataStoreStateL();
   666     aMessage.WriteL( 0, TPckg<TWmDrmStoreState>( state ) );
   666     aMessage.WriteL( 0, TPckg<TWmDrmStoreState>( state ) );
   667     }
   667     }
   668 
   668 
   674     {
   674     {
   675     TTime time = Time::NullTTime();
   675     TTime time = Time::NullTTime();
   676     TBool validity = EFalse;
   676     TBool validity = EFalse;
   677     TPckg<TTime> timePckg(time);
   677     TPckg<TTime> timePckg(time);
   678     TPckg<TBool> validityPckg(validity);
   678     TPckg<TBool> validityPckg(validity);
   679     
   679 
   680     LOGFN( "CWmDrmSession::GetTimeL" );
   680     LOGFN( "CWmDrmSession::GetTimeL" );
   681     
   681 
   682     // Get the time from the clock
   682     // Get the time from the clock
   683     Server().Clock()->GetTimeL( time, validity );
   683     Server().Clock()->GetTimeL( time, validity );
   684     
   684 
   685     aMessage.WriteL(0, timePckg);
   685     aMessage.WriteL(0, timePckg);
   686     aMessage.WriteL(1, validityPckg);
   686     aMessage.WriteL(1, validityPckg);
   687     }
   687     }
   688 
   688 
   689 
   689 
   690 //---------------------------------------------------------------------------
   690 //---------------------------------------------------------------------------
   691 // CWmDrmSession::CommitDataL
   691 // CWmDrmSession::CommitDataL
   692 //---------------------------------------------------------------------------
   692 //---------------------------------------------------------------------------
   693 //
   693 //
   694 void CWmDrmSession::CommitDataL( const RMessage2& aMessage )
   694 void CWmDrmSession::CommitDataL( const RMessage2& /*aMessage*/ )
   695     {
   695     {
   696     
   696 
   697     LOGFN( "CWmDrmSession::CommitDataL" );
   697     LOGFN( "CWmDrmSession::CommitDataL" );
   698     
   698 
   699     // Force a commit on the database
   699     // Force a commit on the database
   700     Server().Db()->CheckDatabaseCommitL( ETrue );
   700     Server().Db()->CheckDatabaseCommitL( ETrue );
   701     }
   701     }
   702 
   702 
   703 
   703 
   704  
   704 
   705 //---------------------------------------------------------------------------
   705 //---------------------------------------------------------------------------
   706 // CWmDrmSession::ServiceL
   706 // CWmDrmSession::ServiceL
   707 //---------------------------------------------------------------------------
   707 //---------------------------------------------------------------------------
   708 //    
   708 //
   709 void CWmDrmSession::ServiceL( const RMessage2& aMessage )
   709 void CWmDrmSession::ServiceL( const RMessage2& aMessage )
   710 	{
   710     {
   711 	TInt r = KErrNone;
   711     TInt r = KErrNone;
   712 	TInt trap = KErrNone;
   712     TInt trap = KErrNone;
   713 	_LIT_SECURITY_POLICY_C1(drmCheck, ECapabilityDRM);
   713     _LIT_SECURITY_POLICY_C1(drmCheck, ECapabilityDRM);
   714     RThread client;
   714     RThread client;
   715 	
   715 
   716 	LOGFNR( "CWmDrmSession::ServiceL", r );
   716     LOGFNR( "CWmDrmSession::ServiceL", r );
   717 #ifdef _LOGGING
   717 #ifdef _LOGGING
   718     TInt c;
   718     TInt c;
   719     TInt s;
   719     TInt s;
   720     c = User::AllocSize(s);
   720     c = User::AllocSize(s);
   721     LOG3( "Memory: %d cells, %d bytes allocated", c, s );
   721     LOG3( "Memory: %d cells, %d bytes allocated", c, s );
   800             case EStoreState:
   800             case EStoreState:
   801                 TRAP( trap, StoreStateL( aMessage ) );
   801                 TRAP( trap, StoreStateL( aMessage ) );
   802                 break;
   802                 break;
   803             case EGetTime:
   803             case EGetTime:
   804                 TRAP( trap, GetTimeL( aMessage ) );
   804                 TRAP( trap, GetTimeL( aMessage ) );
   805                 break;      
   805                 break;
   806             case ECommitData:
   806             case ECommitData:
   807                 TRAP( trap, CommitDataL( aMessage ) );
   807                 TRAP( trap, CommitDataL( aMessage ) );
   808                 break;            
   808                 break;
   809             default:
   809             default:
   810                 r = KErrArgument;
   810                 r = KErrArgument;
   811                 break;
   811                 break;
   812                 }
   812                 }
   813         if ( trap != KErrNone )
   813         if ( trap != KErrNone )
   820             }
   820             }
   821         }
   821         }
   822     client.Close();
   822     client.Close();
   823     LOG2( "** ServiceL error: %d", r );
   823     LOG2( "** ServiceL error: %d", r );
   824     aMessage.Complete( r );
   824     aMessage.Complete( r );
   825 	}
   825     }
   826 
   826 
   827 //---------------------------------------------------------------------------
   827 //---------------------------------------------------------------------------
   828 // CWmDrmSession::ServiceError
   828 // CWmDrmSession::ServiceError
   829 //---------------------------------------------------------------------------
   829 //---------------------------------------------------------------------------
   830 //
   830 //
   831 void CWmDrmSession::ServiceError( const RMessage2& aMessage, TInt aError )
   831 void CWmDrmSession::ServiceError( const RMessage2& aMessage, TInt aError )
   832 	{
   832     {
   833 	LOGFN( "CWmDrmSession::ServiceError" );
   833     LOGFN( "CWmDrmSession::ServiceError" );
   834 	LOG2( "** Error: %d", aError );
   834     LOG2( "** Error: %d", aError );
   835 	CSession2::ServiceError( aMessage, aError );
   835     CSession2::ServiceError( aMessage, aError );
   836 	}
   836     }
   837 
   837 
   838 //---------------------------------------------------------------------------
   838 //---------------------------------------------------------------------------
   839 // CWmDrmSession::Server
   839 // CWmDrmSession::Server
   840 //---------------------------------------------------------------------------
   840 //---------------------------------------------------------------------------
   841 //
   841 //
   842 CWmDrmServer& CWmDrmSession::Server()
   842 CWmDrmServer& CWmDrmSession::Server()
   843 	{
   843     {
   844 	return *static_cast<CWmDrmServer*>( const_cast<CServer2*>( CSession2::Server() ) );
   844     return *static_cast<CWmDrmServer*>( const_cast<CServer2*>( CSession2::Server() ) );
   845 	}
   845     }