omadrm/drmengine/server/src/DRMRightsClient.cpp
branchRCL_3
changeset 18 8a03a285ab14
parent 0 95b198f216e5
child 32 457cd4423b8c
child 49 69d8e75812b7
equal deleted inserted replaced
17:e16d72588c28 18:8a03a285ab14
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 #include <s32file.h>
    20 #include <s32file.h>
    21 #include <etelmm.h>
    21 #include <etelmm.h>
    22 #include "DRMRightsClient.h"
    22 #include "DRMRightsClient.h"
    23 #include "DRMEngineClientServer.h"
    23 #include "DRMEngineClientServer.h"
    24 #include "DRMPermission.h"
    24 #include "DrmPermission.h"
    25 #include "DRMAsset.h"
    25 #include "DrmAsset.h"
    26 #include "drmlog.h"
    26 #include "drmlog.h"
    27 
    27 
    28 #ifdef __DRM_FULL
    28 #ifdef __DRM_FULL
    29 #include "RDRMHelper.h"
    29 #include "rdrmhelper.h"
    30 #endif
    30 #endif
    31 
    31 
    32 // EXTERNAL DATA STRUCTURES
    32 // EXTERNAL DATA STRUCTURES
    33 // EXTERNAL FUNCTION PROTOTYPES  
    33 // EXTERNAL FUNCTION PROTOTYPES
    34 // CONSTANTS
    34 // CONSTANTS
    35 // MACROS
    35 // MACROS
    36 
    36 
    37 // LOCAL CONSTANTS AND MACROS
    37 // LOCAL CONSTANTS AND MACROS
    38 _LIT( KServerFileName, "rightsserver.exe" );
    38 _LIT( KServerFileName, "rightsserver.exe" );
    49 
    49 
    50 // MODULE DATA STRUCTURES
    50 // MODULE DATA STRUCTURES
    51 struct TDRMFileDeletion
    51 struct TDRMFileDeletion
    52     {
    52     {
    53     TDRMFileDeletion() : iName( KNullDesC ) {};
    53     TDRMFileDeletion() : iName( KNullDesC ) {};
    54     ~TDRMFileDeletion() 
    54     ~TDRMFileDeletion()
    55         {
    55         {
    56         if ( iName.Length() )
    56         if ( iName.Length() )
    57             {
    57             {
    58             iFs.Delete( iName );
    58             iFs.Delete( iName );
    59             }
    59             }
    60         
    60 
    61         iFs.Close();
    61         iFs.Close();
    62         }
    62         }
    63         
    63 
    64     RFs iFs;
    64     RFs iFs;
    65     TFileName iName;
    65     TFileName iName;
    66     };
    66     };
    67 
    67 
    68 template< class T > struct RDRMArrayReset
    68 template< class T > struct RDRMArrayReset
    69     {
    69     {
    70     RDRMArrayReset( T& aItem ) : iItem( aItem ), 
    70     RDRMArrayReset( T& aItem ) : iItem( aItem ),
    71                                  iCleanup( ResetAndDestroy, ( TAny* )this ) {};
    71                                  iCleanup( ResetAndDestroy, ( TAny* )this ) {};
    72     ~RDRMArrayReset() { };
    72     ~RDRMArrayReset() { };
    73     void PushL() 
    73     void PushL()
    74         {
    74         {
    75         CleanupStack::PushL( iCleanup );
    75         CleanupStack::PushL( iCleanup );
    76         };
    76         };
    77     
    77 
    78     static void ResetAndDestroy( TAny* aSelf ) 
    78     static void ResetAndDestroy( TAny* aSelf )
    79         {
    79         {
    80         ( ( RDRMArrayReset< T >* )( aSelf ) )->iItem.ResetAndDestroy(); 
    80         ( ( RDRMArrayReset< T >* )( aSelf ) )->iItem.ResetAndDestroy();
    81         ( ( RDRMArrayReset< T >* )( aSelf ) )->iItem.Close();
    81         ( ( RDRMArrayReset< T >* )( aSelf ) )->iItem.Close();
    82         };
    82         };
    83     
    83 
    84     private:        
    84     private:
    85         RDRMArrayReset(); // prohibit
    85         RDRMArrayReset(); // prohibit
    86     
    86 
    87     private:
    87     private:
    88         T& iItem;
    88         T& iItem;
    89         TCleanupItem iCleanup;
    89         TCleanupItem iCleanup;
    90         
    90 
    91     };
    91     };
    92     
    92 
    93 // LOCAL FUNCTION PROTOTYPES
    93 // LOCAL FUNCTION PROTOTYPES
    94 
    94 
    95 // FORWARD DECLARATIONS
    95 // FORWARD DECLARATIONS
    96 
    96 
    97 // ============================= LOCAL FUNCTIONS ===============================
    97 // ============================= LOCAL FUNCTIONS ===============================
   106 //
   106 //
   107 EXPORT_C RDRMRightsClient::RDRMRightsClient() :
   107 EXPORT_C RDRMRightsClient::RDRMRightsClient() :
   108     iPtr( NULL )
   108     iPtr( NULL )
   109     {
   109     {
   110     }
   110     }
   111     
   111 
   112 // -----------------------------------------------------------------------------
   112 // -----------------------------------------------------------------------------
   113 // RDRMRightsClient::~RDRMRightsClient
   113 // RDRMRightsClient::~RDRMRightsClient
   114 // Destructor.
   114 // Destructor.
   115 // -----------------------------------------------------------------------------
   115 // -----------------------------------------------------------------------------
   116 //
   116 //
   117 EXPORT_C RDRMRightsClient::~RDRMRightsClient()
   117 EXPORT_C RDRMRightsClient::~RDRMRightsClient()
   118     {
   118     {
   119     }    
   119     }
   120 
   120 
   121 // -----------------------------------------------------------------------------
   121 // -----------------------------------------------------------------------------
   122 // RDRMRightsClient::Connect
   122 // RDRMRightsClient::Connect
   123 // Opens connection to the server.
   123 // Opens connection to the server.
   124 // -----------------------------------------------------------------------------
   124 // -----------------------------------------------------------------------------
   125 //
   125 //
   126 EXPORT_C TInt RDRMRightsClient::Connect()
   126 EXPORT_C TInt RDRMRightsClient::Connect()
   127     {
   127     {
   128     TInt ret = KErrNone;
   128     TInt ret = KErrNone;
   129     TUint8 count = 0;    
   129     TUint8 count = 0;
   130     
   130 
   131     const TVersion requiredVersion( 
   131     const TVersion requiredVersion(
   132         DRMEngine::KServerMajorVersion,
   132         DRMEngine::KServerMajorVersion,
   133         DRMEngine::KServerMinorVersion,
   133         DRMEngine::KServerMinorVersion,
   134         DRMEngine::KServerBuildVersion );
   134         DRMEngine::KServerBuildVersion );
   135     
   135 
   136     FOREVER
   136     FOREVER
   137         {
   137         {
   138         DRMLOG( _L( "RDRMRightsClient::Connect(): Create a new session" ) );
   138         DRMLOG( _L( "RDRMRightsClient::Connect(): Create a new session" ) );
   139         ret = CreateSession( DRMEngine::KServerName,
   139         ret = CreateSession( DRMEngine::KServerName,
   140                              requiredVersion, 
   140                              requiredVersion,
   141                              KMaxMessageSlots );
   141                              KMaxMessageSlots );
   142                          
   142 
   143         if ( ret == KErrNotFound && count < KStartupCount )
   143         if ( ret == KErrNotFound && count < KStartupCount )
   144             {
   144             {
   145             ret = StartServer();
   145             ret = StartServer();
   146             if ( ret )
   146             if ( ret )
   147                 {
   147                 {
   148                 break;   
   148                 break;
   149                 }
   149                 }
   150             
   150 
   151             ++count;
   151             ++count;
   152             }
   152             }
   153         else
   153         else
   154             {
   154             {
   155             break;   
   155             break;
   156             }
   156             }
   157         }
   157         }
   158 
   158 
   159 #ifdef __DRM_FULL
   159 #ifdef __DRM_FULL
   160     // startup code, if it starts it starts if not it will be tried again.        
   160     // startup code, if it starts it starts if not it will be tried again.
   161     RDRMHelper helper;
   161     RDRMHelper helper;
   162     TInt ignore = helper.Connect(); // Start HelperServer
   162     TInt ignore = helper.Connect(); // Start HelperServer
   163     helper.Close();  
   163     helper.Close();
   164 #endif        
   164 #endif
   165 
   165 
   166     DRMLOG2( _L( "RDRMRightsClient::Connect(): Result: %d" ), ret );
   166     DRMLOG2( _L( "RDRMRightsClient::Connect(): Result: %d" ), ret );
   167     
   167 
   168     return ret;
   168     return ret;
   169     }
   169     }
   170 
   170 
   171 // -----------------------------------------------------------------------------
   171 // -----------------------------------------------------------------------------
   172 // RDRMRightsClient::Close
   172 // RDRMRightsClient::Close
   173 // Closes the connection to the server.
   173 // Closes the connection to the server.
   174 // -----------------------------------------------------------------------------
   174 // -----------------------------------------------------------------------------
   175 //
   175 //
   176 EXPORT_C void RDRMRightsClient::Close() 
   176 EXPORT_C void RDRMRightsClient::Close()
   177     {
   177     {
   178     DRMLOG( _L( "RDRMRightsClient::Close()" ) );
   178     DRMLOG( _L( "RDRMRightsClient::Close()" ) );
   179     RHandleBase::Close();
   179     RHandleBase::Close();
   180     }
   180     }
   181 
   181 
   182 EXPORT_C TInt RDRMRightsClient::StartServer()
   182 EXPORT_C TInt RDRMRightsClient::StartServer()
   183     {
   183     {
   184     DRMLOG( _L( "RDRMRightsClient::StartServer()" ) );
   184     DRMLOG( _L( "RDRMRightsClient::StartServer()" ) );
   185     
   185 
   186     RSemaphore semaphore;
   186     RSemaphore semaphore;
   187     RSemaphore semaphore2;
   187     RSemaphore semaphore2;
   188     TFindServer server( DRMEngine::KServerName );
   188     TFindServer server( DRMEngine::KServerName );
   189     TFullName name;
   189     TFullName name;
   190     RProcess process;
   190     RProcess process;
   191     TInt error = KErrNone;
   191     TInt error = KErrNone;
   192  
   192 
   193     // "local" semaphore
   193     // "local" semaphore
   194      error = semaphore2.CreateGlobal( KRightsServerStarterSemaphore,   // name
   194      error = semaphore2.CreateGlobal( KRightsServerStarterSemaphore,   // name
   195                                     1 ,              // count
   195                                     1 ,              // count
   196                                     EOwnerThread );  // owner
   196                                     EOwnerThread );  // owner
   197 
   197 
   198     if ( error == KErrAlreadyExists )
   198     if ( error == KErrAlreadyExists )
   199         {
   199         {
   200         error = semaphore2.OpenGlobal( KRightsServerStarterSemaphore );
   200         error = semaphore2.OpenGlobal( KRightsServerStarterSemaphore );
   201         }  
   201         }
   202 
   202 
   203 
   203 
   204     // Semaphore not created or opened, don't need to close
   204     // Semaphore not created or opened, don't need to close
   205     if( error )
   205     if( error )
   206         {
   206         {
   207         return error;
   207         return error;
   208         }
   208         }
   209           
   209 
   210     // Server updated semaphore      
   210     // Server updated semaphore
   211     error = semaphore.CreateGlobal( DRMEngine::KDRMSemaphore,   // name
   211     error = semaphore.CreateGlobal( DRMEngine::KDRMSemaphore,   // name
   212                                     0 ,              // count
   212                                     0 ,              // count
   213                                     EOwnerThread );  // owner
   213                                     EOwnerThread );  // owner
   214     
   214 
   215     if ( error == KErrAlreadyExists )
   215     if ( error == KErrAlreadyExists )
   216         {
   216         {
   217         error = semaphore.OpenGlobal( DRMEngine::KDRMSemaphore );
   217         error = semaphore.OpenGlobal( DRMEngine::KDRMSemaphore );
   218         }  
   218         }
   219   
   219 
   220     // Semaphore not created or opened, don't need to close
   220     // Semaphore not created or opened, don't need to close
   221     if( error )
   221     if( error )
   222         {
   222         {
   223         semaphore2.Close();
   223         semaphore2.Close();
   224         return error;
   224         return error;
   225         }
   225         }
   226         
   226 
   227     // Wait until server has done all its things.
   227     // Wait until server has done all its things.
   228     semaphore2.Wait();
   228     semaphore2.Wait();
   229                 
   229 
   230     // Check if the server is already running.
   230     // Check if the server is already running.
   231     error = server.Next( name );
   231     error = server.Next( name );
   232     
   232 
   233     if ( !error )
   233     if ( !error )
   234         {
   234         {
   235         // Yep, it's already running.
   235         // Yep, it's already running.
   236         error = KErrNone;
   236         error = KErrNone;
   237         }
   237         }
   238     else 
   238     else
   239         {
   239         {
   240         error = process.Create( KServerFileName,
   240         error = process.Create( KServerFileName,
   241                                 KNullDesC );
   241                                 KNullDesC );
   242         
   242 
   243         if ( !error )
   243         if ( !error )
   244             {
   244             {
   245             User::After( 1000 );
   245             User::After( 1000 );
   246             
   246 
   247             process.Resume();
   247             process.Resume();
   248             process.Close();
   248             process.Close();
   249             
   249 
   250             // Wait here for the server process startup to complete
   250             // Wait here for the server process startup to complete
   251             // server will signal the global semaphore
   251             // server will signal the global semaphore
   252             semaphore.Wait();
   252             semaphore.Wait();
   253             }
   253             }
   254         }
   254         }
   255         
   255 
   256     // Close both semaphores and signal the "local" one.    
   256     // Close both semaphores and signal the "local" one.
   257     semaphore.Close();         
   257     semaphore.Close();
   258     semaphore2.Signal();
   258     semaphore2.Signal();
   259     semaphore2.Close();   
   259     semaphore2.Close();
   260         
   260 
   261     DRMLOG2( _L( "RDRMRightsClient::StartServer(): %d" ), error );
   261     DRMLOG2( _L( "RDRMRightsClient::StartServer(): %d" ), error );
   262     return error; 
   262     return error;
   263     
   263 
   264     }
   264     }
   265 
   265 
   266 // -----------------------------------------------------------------------------
   266 // -----------------------------------------------------------------------------
   267 // RDRMRightsClient::AddRecord
   267 // RDRMRightsClient::AddRecord
   268 // Add a new entry to the rights database.
   268 // Add a new entry to the rights database.
   269 // -----------------------------------------------------------------------------
   269 // -----------------------------------------------------------------------------
   270 //
   270 //
   271 EXPORT_C TInt RDRMRightsClient::AddRecord( const TDesC8& aCEK, // Content encryption key
   271 EXPORT_C TInt RDRMRightsClient::AddRecord( const TDesC8& aCEK, // Content encryption key
   272                                   // The rights object which is to be added
   272                                   // The rights object which is to be added
   273                                   const CDRMPermission& aRightsObject, 
   273                                   const CDRMPermission& aRightsObject,
   274                                   const TDesC8& aCID, // Content-ID 
   274                                   const TDesC8& aCID, // Content-ID
   275                                   TDRMUniqueID& aID ) // Unique ID, out-parameter
   275                                   TDRMUniqueID& aID ) // Unique ID, out-parameter
   276     {
   276     {
   277     DRMLOG( _L( "RDRMRightsClient::AddRecord" ) );
   277     DRMLOG( _L( "RDRMRightsClient::AddRecord" ) );
   278     TInt error = KErrArgument;
   278     TInt error = KErrArgument;
   279     
   279 
   280     // Check the parameters.
   280     // Check the parameters.
   281     if ( aCEK.Length() )
   281     if ( aCEK.Length() )
   282         {
   282         {
   283         
   283 
   284         HBufC8* rightsData = NULL;
   284         HBufC8* rightsData = NULL;
   285         TRAP( error, rightsData = aRightsObject.ExportL() );
   285         TRAP( error, rightsData = aRightsObject.ExportL() );
   286         TInt size = aRightsObject.Size();
   286         TInt size = aRightsObject.Size();
   287         
   287 
   288         if ( rightsData && size > 0 )
   288         if ( rightsData && size > 0 )
   289             {
   289             {
   290             // For C/S communications.
   290             // For C/S communications.
   291             TPtr8 rightsObject( NULL, 0 );
   291             TPtr8 rightsObject( NULL, 0 );
   292             TPtr8 uid( reinterpret_cast< TUint8* >( &aID ),
   292             TPtr8 uid( reinterpret_cast< TUint8* >( &aID ),
   293                        0,
   293                        0,
   294                        sizeof( TDRMUniqueID ) );
   294                        sizeof( TDRMUniqueID ) );
   295         
   295 
   296             rightsObject.Set( const_cast< TUint8* >( rightsData->Ptr() ),
   296             rightsObject.Set( const_cast< TUint8* >( rightsData->Ptr() ),
   297                               size,
   297                               size,
   298                               size );
   298                               size );
   299         
   299 
   300               
   300 
   301             // Send the message.
   301             // Send the message.
   302             error = SendReceive( DRMEngine::EAddRecord, 
   302             error = SendReceive( DRMEngine::EAddRecord,
   303                              TIpcArgs( &aCID, &rightsObject, &aCEK, &uid ) );
   303                              TIpcArgs( &aCID, &rightsObject, &aCEK, &uid ) );
   304         
   304 
   305             delete rightsData;
   305             delete rightsData;
   306             rightsData = NULL;
   306             rightsData = NULL;
   307             }
   307             }
   308         }
   308         }
   309     
   309 
   310     DRMLOG2( _L( "RDRMRightsClient::AddRecord: %d" ), error );
   310     DRMLOG2( _L( "RDRMRightsClient::AddRecord: %d" ), error );
   311     return error;
   311     return error;
   312     }
   312     }
   313 
   313 
   314 
   314 
   323     const CDRMPermission& aRightsObject,
   323     const CDRMPermission& aRightsObject,
   324     const TDesC8& aCID,
   324     const TDesC8& aCID,
   325     TDRMUniqueID& aID ) // Unique ID, out-parameter
   325     TDRMUniqueID& aID ) // Unique ID, out-parameter
   326     {
   326     {
   327     DRMLOG( _L( "RDRMRightsClient::AddProtectedRecord" ) );
   327     DRMLOG( _L( "RDRMRightsClient::AddProtectedRecord" ) );
   328     
   328 
   329     TInt error = KErrNone;                                                       
   329     TInt error = KErrNone;
   330     TInt message = DRMEngine::EAddProtectedRecord;                                                                                    
   330     TInt message = DRMEngine::EAddProtectedRecord;
   331     HBufC8* rightsData = NULL;                                                   
   331     HBufC8* rightsData = NULL;
   332     TInt size = aRightsObject.Size();                                            
   332     TInt size = aRightsObject.Size();
   333     TPtr8 rightsObject( NULL, 0 );                                               
   333     TPtr8 rightsObject( NULL, 0 );
   334     TPtr8 uid( reinterpret_cast< TUint8* >( &aID ), 0,                           
   334     TPtr8 uid( reinterpret_cast< TUint8* >( &aID ), 0,
   335         sizeof( TDRMUniqueID ) );                                                
   335         sizeof( TDRMUniqueID ) );
   336     TPtr8 key( NULL, 0 );                                                        
   336     TPtr8 key( NULL, 0 );
   337                                                                                  
   337 
   338     TRAP( error, rightsData = aRightsObject.ExportL() );                                        
   338     TRAP( error, rightsData = aRightsObject.ExportL() );
   339     if ( !error ) 
   339     if ( !error )
   340         {    
   340         {
   341         rightsObject.Set( const_cast< TUint8* >( rightsData->Ptr() ), size,          
   341         rightsObject.Set( const_cast< TUint8* >( rightsData->Ptr() ), size,
   342             size );
   342             size );
   343                                                                             
   343 
   344         if ( aDomainRecord )                                                         
   344         if ( aDomainRecord )
   345             {
   345             {
   346             message = DRMEngine::EAddDomainRecord;
   346             message = DRMEngine::EAddDomainRecord;
   347             }                                                                        
   347             }
   348         error = SendReceive( message, TIpcArgs( &aCID, &rightsObject, &aProtectedCek, &uid ) );
   348         error = SendReceive( message, TIpcArgs( &aCID, &rightsObject, &aProtectedCek, &uid ) );
   349 
   349 
   350         delete rightsData;
   350         delete rightsData;
   351         rightsData = NULL;
   351         rightsData = NULL;
   352         }
   352         }
   353     DRMLOG2( _L( "RDRMRightsClient::AddProtectedRecord: %d" ), error );          
   353     DRMLOG2( _L( "RDRMRightsClient::AddProtectedRecord: %d" ), error );
   354     return error; 
   354     return error;
   355     }
   355     }
   356 
   356 
   357 // -----------------------------------------------------------------------------
   357 // -----------------------------------------------------------------------------
   358 // RDRMRightsClient::GetDBEntriesL
   358 // RDRMRightsClient::GetDBEntriesL
   359 // Get a file name from the server. The file contains the rights objects,
   359 // Get a file name from the server. The file contains the rights objects,
   363 EXPORT_C void RDRMRightsClient::GetDBEntriesL( const TDesC8& aId,
   363 EXPORT_C void RDRMRightsClient::GetDBEntriesL( const TDesC8& aId,
   364                                       RPointerArray< CDRMPermission >& aRightsList )
   364                                       RPointerArray< CDRMPermission >& aRightsList )
   365     {
   365     {
   366     DRMLOG( _L( "RDRMRightsClient::GetDBEntries" ) );
   366     DRMLOG( _L( "RDRMRightsClient::GetDBEntries" ) );
   367     if( aId.Length() )
   367     if( aId.Length() )
   368         {   
   368         {
   369         // Temporary file name from the server.
   369         // Temporary file name from the server.
   370         TDRMFileDeletion item;
   370         TDRMFileDeletion item;
   371         
   371 
   372         // Make sure that the array is empty.
   372         // Make sure that the array is empty.
   373         aRightsList.ResetAndDestroy();
   373         aRightsList.ResetAndDestroy();
   374         
   374 
   375         // For file operations. Destructor of TDRMFileDeletion
   375         // For file operations. Destructor of TDRMFileDeletion
   376         // deletes the file & closes the session.
   376         // deletes the file & closes the session.
   377         User::LeaveIfError( item.iFs.Connect() );  
   377         User::LeaveIfError( item.iFs.Connect() );
   378                 
   378 
   379         User::LeaveIfError( SendReceive( DRMEngine::EGetEntryList, 
   379         User::LeaveIfError( SendReceive( DRMEngine::EGetEntryList,
   380                                          TIpcArgs( &item.iName, &aId ) ) );
   380                                          TIpcArgs( &item.iName, &aId ) ) );
   381         
   381 
   382         // Convert the file to a list.
   382         // Convert the file to a list.
   383         FileToListL( item.iFs, item.iName, aRightsList );
   383         FileToListL( item.iFs, item.iName, aRightsList );
   384         
   384 
   385         DRMLOG( _L( "RDRMRightsClient::GetDBEntries ok" ) );    
   385         DRMLOG( _L( "RDRMRightsClient::GetDBEntries ok" ) );
   386     
   386 
   387         return;
   387         return;
   388         }
   388         }
   389     
   389 
   390     // Invalid parameter.
   390     // Invalid parameter.
   391     User::Leave( KErrArgument );
   391     User::Leave( KErrArgument );
   392     }
   392     }
   393 
   393 
   394 // -----------------------------------------------------------------------------
   394 // -----------------------------------------------------------------------------
   398 //
   398 //
   399 EXPORT_C CDRMPermission* RDRMRightsClient::GetDbEntryL( const TDesC8& aContentID,
   399 EXPORT_C CDRMPermission* RDRMRightsClient::GetDbEntryL( const TDesC8& aContentID,
   400                                                  const TDRMUniqueID& aUniqueID )
   400                                                  const TDRMUniqueID& aUniqueID )
   401     {
   401     {
   402     DRMLOG( _L( "RDRMRightsClient::GetDbEntryL" ) );
   402     DRMLOG( _L( "RDRMRightsClient::GetDbEntryL" ) );
   403     
   403 
   404     CDRMPermission* permission = NULL;
   404     CDRMPermission* permission = NULL;
   405     TInt size = 0;
   405     TInt size = 0;
   406     TPckg<TInt> package( size );
   406     TPckg<TInt> package( size );
   407     TPtrC8 uid( reinterpret_cast< TUint8* >( const_cast< TDRMUniqueID* >(
   407     TPtrC8 uid( reinterpret_cast< TUint8* >( const_cast< TDRMUniqueID* >(
   408         &aUniqueID ) ), sizeof( TDRMUniqueID ) );
   408         &aUniqueID ) ), sizeof( TDRMUniqueID ) );
   412     HBufC8* rightsData = HBufC8::NewMaxLC( size );
   412     HBufC8* rightsData = HBufC8::NewMaxLC( size );
   413     TPtr8 objectPkg( const_cast< TUint8* >( rightsData->Ptr() ), size,
   413     TPtr8 objectPkg( const_cast< TUint8* >( rightsData->Ptr() ), size,
   414         size );
   414         size );
   415     User::LeaveIfError( SendReceive( DRMEngine::EGetPreparedData,
   415     User::LeaveIfError( SendReceive( DRMEngine::EGetPreparedData,
   416         TIpcArgs( &objectPkg) ) );
   416         TIpcArgs( &objectPkg) ) );
   417     
   417 
   418     permission = CDRMPermission::NewLC();
   418     permission = CDRMPermission::NewLC();
   419     permission->ImportL( rightsData->Des() );
   419     permission->ImportL( rightsData->Des() );
   420     CleanupStack::Pop(); // permission
   420     CleanupStack::Pop(); // permission
   421     CleanupStack::PopAndDestroy(); // Rights data
   421     CleanupStack::PopAndDestroy(); // Rights data
   422     
   422 
   423     DRMLOG( _L( "RDRMRightsClient::GetDbEntryL ok" ) );
   423     DRMLOG( _L( "RDRMRightsClient::GetDbEntryL ok" ) );
   424     return permission;
   424     return permission;
   425     }
   425     }
   426 
   426 
   427 // -----------------------------------------------------------------------------
   427 // -----------------------------------------------------------------------------
   430 // -----------------------------------------------------------------------------
   430 // -----------------------------------------------------------------------------
   431 //
   431 //
   432 EXPORT_C TInt RDRMRightsClient::DeleteDbEntry( const TDesC8& aContentID )
   432 EXPORT_C TInt RDRMRightsClient::DeleteDbEntry( const TDesC8& aContentID )
   433     {
   433     {
   434     DRMLOG( _L( "RDRMRightsClient::DeleteDbEntry with CID" ) );
   434     DRMLOG( _L( "RDRMRightsClient::DeleteDbEntry with CID" ) );
   435     
   435 
   436     TInt error = KErrArgument;
   436     TInt error = KErrArgument;
   437     
   437 
   438     // Check the parameter.
   438     // Check the parameter.
   439     if ( aContentID.Length() )
   439     if ( aContentID.Length() )
   440         {
   440         {
   441         return SendReceive( DRMEngine::EDeleteWithCID, 
   441         return SendReceive( DRMEngine::EDeleteWithCID,
   442                             TIpcArgs( NULL, NULL, &aContentID ) );
   442                             TIpcArgs( NULL, NULL, &aContentID ) );
   443         }
   443         }
   444     
   444 
   445     return error;
   445     return error;
   446     }
   446     }
   447 
   447 
   448 // -----------------------------------------------------------------------------
   448 // -----------------------------------------------------------------------------
   449 // RDRMRightsClient::DeleteDbEntry
   449 // RDRMRightsClient::DeleteDbEntry
   452 //
   452 //
   453 EXPORT_C TInt RDRMRightsClient::DeleteDbEntry( const TDesC8& aContentID,
   453 EXPORT_C TInt RDRMRightsClient::DeleteDbEntry( const TDesC8& aContentID,
   454                                                const TDRMUniqueID& aUniqueID )
   454                                                const TDRMUniqueID& aUniqueID )
   455     {
   455     {
   456     DRMLOG( _L( "RDRMRightsClient::DeleteDbEntry with CID & UID" ) );
   456     DRMLOG( _L( "RDRMRightsClient::DeleteDbEntry with CID & UID" ) );
   457     
   457 
   458     if ( aContentID.Length() )
   458     if ( aContentID.Length() )
   459         {
   459         {
   460         // Something to do.
   460         // Something to do.
   461         // Put aUniqueID inside a descriptor.
   461         // Put aUniqueID inside a descriptor.
   462         // Works even if its typedef is changed.
   462         // Works even if its typedef is changed.
   463         TPtrC8 uid( reinterpret_cast< TUint8* >( 
   463         TPtrC8 uid( reinterpret_cast< TUint8* >(
   464                         const_cast< TDRMUniqueID* >( &aUniqueID ) ),
   464                         const_cast< TDRMUniqueID* >( &aUniqueID ) ),
   465                     sizeof( TDRMUniqueID ) );
   465                     sizeof( TDRMUniqueID ) );
   466         
   466 
   467         return SendReceive( DRMEngine::EDeleteRO, 
   467         return SendReceive( DRMEngine::EDeleteRO,
   468                             TIpcArgs( &uid, NULL, NULL, &aContentID ) );
   468                             TIpcArgs( &uid, NULL, NULL, &aContentID ) );
   469         }
   469         }
   470     
   470 
   471     return KErrArgument;
   471     return KErrArgument;
   472     }
   472     }
   473 
   473 
   474 // -----------------------------------------------------------------------------
   474 // -----------------------------------------------------------------------------
   475 // RDRMRightsClient::ExportContentIDList
   475 // RDRMRightsClient::ExportContentIDList
   476 // Overloaded method: requests all content IDs to be put to a file. 
   476 // Overloaded method: requests all content IDs to be put to a file.
   477 // Assumes that the given descriptor represents a buffer large enough to
   477 // Assumes that the given descriptor represents a buffer large enough to
   478 // contain the file name.
   478 // contain the file name.
   479 // -----------------------------------------------------------------------------
   479 // -----------------------------------------------------------------------------
   480 //
   480 //
   481 EXPORT_C TInt RDRMRightsClient::ExportContentIDList( TDes& aFileName )
   481 EXPORT_C TInt RDRMRightsClient::ExportContentIDList( TDes& aFileName )
   482     {
   482     {
   483     DRMLOG( _L( "RDRMRightsClient::ExportContentIDLis" ) );
   483     DRMLOG( _L( "RDRMRightsClient::ExportContentIDLis" ) );
   484     
   484 
   485     return SendReceive( DRMEngine::EExportCIDs, 
   485     return SendReceive( DRMEngine::EExportCIDs,
   486                         TIpcArgs( &aFileName ) );
   486                         TIpcArgs( &aFileName ) );
   487     
   487 
   488     }
   488     }
   489 
   489 
   490 // -----------------------------------------------------------------------------
   490 // -----------------------------------------------------------------------------
   491 // RDRMRightsClient::ExportContentIDList
   491 // RDRMRightsClient::ExportContentIDList
   492 // Overloaded method: requests all content IDs to be put to a file, 
   492 // Overloaded method: requests all content IDs to be put to a file,
   493 // and then converts the file into RPointerArray.
   493 // and then converts the file into RPointerArray.
   494 // -----------------------------------------------------------------------------
   494 // -----------------------------------------------------------------------------
   495 //
   495 //
   496 EXPORT_C TInt RDRMRightsClient::ExportContentIDList( RPointerArray< HBufC8 >& aCIDList )
   496 EXPORT_C TInt RDRMRightsClient::ExportContentIDList( RPointerArray< HBufC8 >& aCIDList )
   497     {
   497     {
   498     DRMLOG( _L( "RDRMRightsClient::ExportContentIDList to array" ) );
   498     DRMLOG( _L( "RDRMRightsClient::ExportContentIDList to array" ) );
   499     TFileName name;
   499     TFileName name;
   500     aCIDList.ResetAndDestroy();
   500     aCIDList.ResetAndDestroy();
   501     
   501 
   502     TInt error = ExportContentIDList( name );
   502     TInt error = ExportContentIDList( name );
   503     if ( !error )
   503     if ( !error )
   504         {
   504         {
   505         RFs fs;
   505         RFs fs;
   506         error = fs.Connect();
   506         error = fs.Connect();
   509             TRAP( error, URIFileToArrayL( fs, name, aCIDList ) );
   509             TRAP( error, URIFileToArrayL( fs, name, aCIDList ) );
   510             if ( error )
   510             if ( error )
   511                 {
   511                 {
   512                 aCIDList.ResetAndDestroy();
   512                 aCIDList.ResetAndDestroy();
   513                 }
   513                 }
   514             
   514 
   515             fs.Delete( name );
   515             fs.Delete( name );
   516             fs.Close();
   516             fs.Close();
   517             }
   517             }
   518         }
   518         }
   519     
   519 
   520     DRMLOG2( _L( "RDRMRightsClient::ExportContentIDList: %d" ), error );
   520     DRMLOG2( _L( "RDRMRightsClient::ExportContentIDList: %d" ), error );
   521             
   521 
   522     return error;
   522     return error;
   523     }
   523     }
   524 
   524 
   525 
   525 
   526 // -----------------------------------------------------------------------------
   526 // -----------------------------------------------------------------------------
   538     TRequestStatus status;
   538     TRequestStatus status;
   539 
   539 
   540     SendReceive( DRMEngine::EGetKey,
   540     SendReceive( DRMEngine::EGetKey,
   541         TIpcArgs( aIntent, const_cast<TDesC8*>(&aContentID), &aKey ),
   541         TIpcArgs( aIntent, const_cast<TDesC8*>(&aContentID), &aKey ),
   542         status );
   542         status );
   543         
   543 
   544     User::WaitForRequest( status );
   544     User::WaitForRequest( status );
   545 
   545 
   546     DRMLOG2( _L( "RDRMRightsClient::GetDecryptionKey: %d" ), status.Int() );
   546     DRMLOG2( _L( "RDRMRightsClient::GetDecryptionKey: %d" ), status.Int() );
   547     
   547 
   548     return status.Int();
   548     return status.Int();
   549     }
   549     }
   550 
   550 
   551 // -----------------------------------------------------------------------------
   551 // -----------------------------------------------------------------------------
   552 // RDRMRightsClient::CheckRights
   552 // RDRMRightsClient::CheckRights
   558     const TDesC8& aContentID,
   558     const TDesC8& aContentID,
   559     TUint32& aRejection )
   559     TUint32& aRejection )
   560     {
   560     {
   561     TInt error = KErrNone;
   561     TInt error = KErrNone;
   562     TInt size = 0;
   562     TInt size = 0;
   563     
   563 
   564     TPckg<TInt> package( size );
   564     TPckg<TInt> package( size );
   565     TPckg<TUint32> package2( aRejection );
   565     TPckg<TUint32> package2( aRejection );
   566         
   566 
   567     DRMLOG( _L( "RDRMRightsClient::CheckRights" ) );
   567     DRMLOG( _L( "RDRMRightsClient::CheckRights" ) );
   568     error = SendReceive( DRMEngine::ECheckRights, TIpcArgs( aIntent,
   568     error = SendReceive( DRMEngine::ECheckRights, TIpcArgs( aIntent,
   569         &aContentID, &package, &package2 ) );
   569         &aContentID, &package, &package2 ) );
   570         
   570 
   571     DRMLOG2( _L( "RDRMRightsClient::CheckRights: %d" ), error );
   571     DRMLOG2( _L( "RDRMRightsClient::CheckRights: %d" ), error );
   572     
   572 
   573     return error;
   573     return error;
   574     }
   574     }
   575 
   575 
   576 // -----------------------------------------------------------------------------
   576 // -----------------------------------------------------------------------------
   577 // RDRMRightsClient::GetActiveRightsL
   577 // RDRMRightsClient::GetActiveRightsL
   585     TUint32& aRejection )
   585     TUint32& aRejection )
   586     {
   586     {
   587     TInt r;
   587     TInt r;
   588     TInt size = 0;
   588     TInt size = 0;
   589     TPckg<TInt> package( size );
   589     TPckg<TInt> package( size );
   590     TPckg<TUint32> package2( aRejection );    
   590     TPckg<TUint32> package2( aRejection );
   591     CDRMPermission* permission = NULL;
   591     CDRMPermission* permission = NULL;
   592     HBufC8* buffer = NULL;
   592     HBufC8* buffer = NULL;
   593     
   593 
   594     DRMLOG( _L( "RDRMRightsClient::GetActiveRightsL" ) );
   594     DRMLOG( _L( "RDRMRightsClient::GetActiveRightsL" ) );
   595     r = SendReceive( DRMEngine::ECheckRights, TIpcArgs( aIntent, &aContentID,
   595     r = SendReceive( DRMEngine::ECheckRights, TIpcArgs( aIntent, &aContentID,
   596         &package, &package2 ) );
   596         &package, &package2 ) );
   597 
   597 
   598     // Get rights. Return NULL if no rights are available, otherwise leave
   598     // Get rights. Return NULL if no rights are available, otherwise leave
   611     else if ( r != KErrCANoRights && r != KErrCANoPermission &&
   611     else if ( r != KErrCANoRights && r != KErrCANoPermission &&
   612         r != KErrCAPendingRights )
   612         r != KErrCAPendingRights )
   613         {
   613         {
   614         User::Leave( r );
   614         User::Leave( r );
   615         }
   615         }
   616     
   616 
   617     DRMLOG( _L( "RDRMRightsClient::GetActiveRightsL: done" ) );
   617     DRMLOG( _L( "RDRMRightsClient::GetActiveRightsL: done" ) );
   618     return permission;
   618     return permission;
   619     }
   619     }
   620 
   620 
   621 // -----------------------------------------------------------------------------
   621 // -----------------------------------------------------------------------------
   629     {
   629     {
   630     DRMLOG( _L( "RDRMRightsClient::Count" ) );
   630     DRMLOG( _L( "RDRMRightsClient::Count" ) );
   631 
   631 
   632     TInt count = 0;
   632     TInt count = 0;
   633     TInt error = KErrNone;
   633     TInt error = KErrNone;
   634     
   634 
   635     TPtr8 ptr( reinterpret_cast< TUint8* >( &count ),
   635     TPtr8 ptr( reinterpret_cast< TUint8* >( &count ),
   636                0, 
   636                0,
   637                sizeof( TInt ) );
   637                sizeof( TInt ) );
   638     
   638 
   639     error = SendReceive( DRMEngine::ECount, 
   639     error = SendReceive( DRMEngine::ECount,
   640                          TIpcArgs( &ptr ) );
   640                          TIpcArgs( &ptr ) );
   641     
   641 
   642     if ( !error )
   642     if ( !error )
   643         {
   643         {
   644         error = count;
   644         error = count;
   645         }
   645         }
   646     
   646 
   647     DRMLOG2( _L( "RDRMRightsClient::Count: %d" ), error );
   647     DRMLOG2( _L( "RDRMRightsClient::Count: %d" ), error );
   648     
   648 
   649     return error;
   649     return error;
   650     }
   650     }
   651 
   651 
   652 // -----------------------------------------------------------------------------
   652 // -----------------------------------------------------------------------------
   653 // RDRMRightsClient::DeleteAll
   653 // RDRMRightsClient::DeleteAll
   655 // -----------------------------------------------------------------------------
   655 // -----------------------------------------------------------------------------
   656 //
   656 //
   657 EXPORT_C TInt RDRMRightsClient::DeleteAll()
   657 EXPORT_C TInt RDRMRightsClient::DeleteAll()
   658     {
   658     {
   659     DRMLOG( _L( "RDRMRightsClient::DeleteAll" ) );
   659     DRMLOG( _L( "RDRMRightsClient::DeleteAll" ) );
   660    
   660 
   661     TInt error = SendReceive( DRMEngine::EDeleteAll, TIpcArgs( NULL ) ); 
   661     TInt error = SendReceive( DRMEngine::EDeleteAll, TIpcArgs( NULL ) );
   662 
   662 
   663     DRMLOG2( _L( "RDRMRightsClient::DeleteAll: %d" ), error  );
   663     DRMLOG2( _L( "RDRMRightsClient::DeleteAll: %d" ), error  );
   664     
   664 
   665     return error;
   665     return error;
   666     }
   666     }
   667 
   667 
   668 // -----------------------------------------------------------------------------
   668 // -----------------------------------------------------------------------------
   669 // RDRMRightsClient::Consume()
   669 // RDRMRightsClient::Consume()
   670 // Consume the right with specific intent and contentID
   670 // Consume the right with specific intent and contentID
   671 // -----------------------------------------------------------------------------
   671 // -----------------------------------------------------------------------------
   672 //
   672 //
   673 EXPORT_C TInt RDRMRightsClient::Consume( const TInt aIntent, 
   673 EXPORT_C TInt RDRMRightsClient::Consume( const TInt aIntent,
   674                                          const TDesC8& aContentID )
   674                                          const TDesC8& aContentID )
   675     {
   675     {
   676     TInt error = KErrNone;
   676     TInt error = KErrNone;
   677     DRMLOG( _L( "RDRMRightsClient::Consume" ) );
   677     DRMLOG( _L( "RDRMRightsClient::Consume" ) );
   678    
   678 
   679     error = SendReceive( DRMEngine::EConsume, 
   679     error = SendReceive( DRMEngine::EConsume,
   680                          TIpcArgs( aIntent, &aContentID ) );
   680                          TIpcArgs( aIntent, &aContentID ) );
   681 
   681 
   682     DRMLOG2( _L( "RDRMRightsClient::Consume: %d" ), error  );
   682     DRMLOG2( _L( "RDRMRightsClient::Consume: %d" ), error  );
   683     return error;
   683     return error;
   684     }
   684     }
   686 // -----------------------------------------------------------------------------
   686 // -----------------------------------------------------------------------------
   687 // RDRMRightsClient::CheckConsume()
   687 // RDRMRightsClient::CheckConsume()
   688 // Check if Consume is possibke
   688 // Check if Consume is possibke
   689 // -----------------------------------------------------------------------------
   689 // -----------------------------------------------------------------------------
   690 //
   690 //
   691 EXPORT_C TInt RDRMRightsClient::CheckConsume( const TInt aIntent, 
   691 EXPORT_C TInt RDRMRightsClient::CheckConsume( const TInt aIntent,
   692                                               const TDesC8& aContentID )
   692                                               const TDesC8& aContentID )
   693     {
   693     {
   694     TInt error = KErrNone;
   694     TInt error = KErrNone;
   695     DRMLOG( _L( "RDRMRightsClient::CheckConsume" ) );
   695     DRMLOG( _L( "RDRMRightsClient::CheckConsume" ) );
   696    
   696 
   697     error = SendReceive( DRMEngine::ECheckConsume, 
   697     error = SendReceive( DRMEngine::ECheckConsume,
   698                          TIpcArgs( aIntent, &aContentID ) );
   698                          TIpcArgs( aIntent, &aContentID ) );
   699 
   699 
   700     DRMLOG2( _L( "RDRMRightsClient::CheckConsume: %d" ), error  );
   700     DRMLOG2( _L( "RDRMRightsClient::CheckConsume: %d" ), error  );
   701     return error;
   701     return error;
   702     }
   702     }
   715                         TIpcArgs ( &aLastTwoDataBlocks) );
   715                         TIpcArgs ( &aLastTwoDataBlocks) );
   716     }
   716     }
   717 
   717 
   718 // -----------------------------------------------------------------------------
   718 // -----------------------------------------------------------------------------
   719 // RDRMRightsClient::
   719 // RDRMRightsClient::
   720 // 
   720 //
   721 // -----------------------------------------------------------------------------
   721 // -----------------------------------------------------------------------------
   722 //
   722 //
   723 EXPORT_C TInt RDRMRightsClient::ForwardLockURI( HBufC8*& aURI )
   723 EXPORT_C TInt RDRMRightsClient::ForwardLockURI( HBufC8*& aURI )
   724     {
   724     {
   725     DRMLOG( _L( "RDRMRightsClient::ForwardLockURI" ) );
   725     DRMLOG( _L( "RDRMRightsClient::ForwardLockURI" ) );
   726     TBuf8< DRMEngine::KMaxOmaV1CIDLength > buf;
   726     TBuf8< DRMEngine::KMaxOmaV1CIDLength > buf;
   727     TInt error = SendReceive( DRMEngine::EGetFLUri,
   727     TInt error = SendReceive( DRMEngine::EGetFLUri,
   728                               TIpcArgs( &buf ) );
   728                               TIpcArgs( &buf ) );
   729                               
   729 
   730     if ( error )
   730     if ( error )
   731         {
   731         {
   732         aURI = NULL;
   732         aURI = NULL;
   733         return error;
   733         return error;
   734         }
   734         }
   735         
   735 
   736     aURI = buf.Alloc();
   736     aURI = buf.Alloc();
   737 
   737 
   738     if ( aURI )
   738     if ( aURI )
   739         {
   739         {
   740         return KErrNone;
   740         return KErrNone;
   741         }
   741         }
   742         
   742 
   743     return KErrNoMemory;
   743     return KErrNoMemory;
   744     }
   744     }
   745 
   745 
   746 
   746 
   747 // -----------------------------------------------------------------------------
   747 // -----------------------------------------------------------------------------
   748 // RDRMRightsClient::AddDomainRO
   748 // RDRMRightsClient::AddDomainRO
   749 // Add domain rights object xml representation to the rdb
   749 // Add domain rights object xml representation to the rdb
   750 // -----------------------------------------------------------------------------
   750 // -----------------------------------------------------------------------------
   751 //
   751 //
   752 EXPORT_C TInt RDRMRightsClient::AddDomainRO( const TDesC8& aRoId, 
   752 EXPORT_C TInt RDRMRightsClient::AddDomainRO( const TDesC8& aRoId,
   753                                              const TDesC8& aXmlData )
   753                                              const TDesC8& aXmlData )
   754     {
   754     {
   755     DRMLOG( _L( "RDRMRightsClient::AddDomainRO" ) );
   755     DRMLOG( _L( "RDRMRightsClient::AddDomainRO" ) );
   756     TInt error = KErrArgument;
   756     TInt error = KErrArgument;
   757     
   757 
   758     // Check the parameters.
   758     // Check the parameters.
   759     if ( aRoId.Length() && aXmlData.Length() )
   759     if ( aRoId.Length() && aXmlData.Length() )
   760         {     
   760         {
   761         // Send the message.
   761         // Send the message.
   762         error = SendReceive( DRMEngine::EAddDomainRO, 
   762         error = SendReceive( DRMEngine::EAddDomainRO,
   763                              TIpcArgs( &aRoId, &aXmlData) );
   763                              TIpcArgs( &aRoId, &aXmlData) );
   764         }
   764         }
   765         
   765 
   766     DRMLOG2( _L( "RDRMRightsClient::AddDomainRO: %d" ), error );
   766     DRMLOG2( _L( "RDRMRightsClient::AddDomainRO: %d" ), error );
   767     return error;    
   767     return error;
   768     };        
   768     };
   769 
   769 
   770 // -----------------------------------------------------------------------------
   770 // -----------------------------------------------------------------------------
   771 // RDRMRightsClient::GetDomainROL
   771 // RDRMRightsClient::GetDomainROL
   772 // Get domain rights object xml representation from the rdb
   772 // Get domain rights object xml representation from the rdb
   773 // -----------------------------------------------------------------------------
   773 // -----------------------------------------------------------------------------
   774 //
   774 //
   775 EXPORT_C HBufC8* RDRMRightsClient::GetDomainROL( const TDesC8& aRoId )
   775 EXPORT_C HBufC8* RDRMRightsClient::GetDomainROL( const TDesC8& aRoId )
   776     {
   776     {
   777     DRMLOG( _L( "RDRMRightsClient::GetDomainROL" ) );
   777     DRMLOG( _L( "RDRMRightsClient::GetDomainROL" ) );
   778     
   778 
   779     // Check the parameter.
   779     // Check the parameter.
   780     if ( aRoId.Length() )
   780     if ( aRoId.Length() )
   781         {
   781         {
   782         TInt size = 0;
   782         TInt size = 0;
   783         TPckg<TInt> package( size );
   783         TPckg<TInt> package( size );
   784         
   784 
   785         // Call the server. Throw an exception in case of an error.
   785         // Call the server. Throw an exception in case of an error.
   786         User::LeaveIfError( 
   786         User::LeaveIfError(
   787             SendReceive( DRMEngine::EGetDomainRO, 
   787             SendReceive( DRMEngine::EGetDomainRO,
   788                          TIpcArgs( &package, &aRoId ) ) );
   788                          TIpcArgs( &package, &aRoId ) ) );
   789 
   789 
   790         HBufC8* roData = HBufC8::NewMaxLC( size );
   790         HBufC8* roData = HBufC8::NewMaxLC( size );
   791         
   791 
   792         // Package 'object' into TPtr8.
   792         // Package 'object' into TPtr8.
   793         TPtr8 objectPkg( const_cast< TUint8* >( roData->Ptr() ),
   793         TPtr8 objectPkg( const_cast< TUint8* >( roData->Ptr() ),
   794                          size,
   794                          size,
   795                          size );
   795                          size );
   796 
   796 
   797         User::LeaveIfError( 
   797         User::LeaveIfError(
   798             SendReceive( DRMEngine::EGetPreparedData, 
   798             SendReceive( DRMEngine::EGetPreparedData,
   799                          TIpcArgs( &objectPkg) ) );
   799                          TIpcArgs( &objectPkg) ) );
   800         CleanupStack::Pop( roData ); // roData                 
   800         CleanupStack::Pop( roData ); // roData
   801         return roData;
   801         return roData;
   802         }
   802         }
   803     
   803 
   804     User::Leave( KErrArgument );
   804     User::Leave( KErrArgument );
   805     
   805 
   806     // Never reached.
   806     // Never reached.
   807     return NULL;    
   807     return NULL;
   808     }; 
   808     };
   809 
   809 
   810 // -----------------------------------------------------------------------------
   810 // -----------------------------------------------------------------------------
   811 // RDRMRightsClient::GetDomainROL
   811 // RDRMRightsClient::GetDomainROL
   812 // Get domain rights object xml representation from the rdb
   812 // Get domain rights object xml representation from the rdb
   813 // -----------------------------------------------------------------------------
   813 // -----------------------------------------------------------------------------
   821     HBufC8* buffer = NULL;
   821     HBufC8* buffer = NULL;
   822     HBufC8* ro = NULL;
   822     HBufC8* ro = NULL;
   823     TInt roSize;
   823     TInt roSize;
   824     TInt offset;
   824     TInt offset;
   825 
   825 
   826         
   826 
   827     DRMLOG(_L("RDRMRightsClient::GetDomainRoForCidL"));
   827     DRMLOG(_L("RDRMRightsClient::GetDomainRoForCidL"));
   828     User::LeaveIfError(SendReceive(DRMEngine::EGetDomainRoForCid,
   828     User::LeaveIfError(SendReceive(DRMEngine::EGetDomainRoForCid,
   829         TIpcArgs(&aContentId, &pkg)));
   829         TIpcArgs(&aContentId, &pkg)));
   830     if (size > 0)
   830     if (size > 0)
   831         {
   831         {
   837             TIpcArgs(&ptr)));
   837             TIpcArgs(&ptr)));
   838         offset = 0;
   838         offset = 0;
   839         while (offset < size)
   839         while (offset < size)
   840             {
   840             {
   841             Mem::Copy( &roSize, ptr.Ptr()+offset, sizeof(TInt) );
   841             Mem::Copy( &roSize, ptr.Ptr()+offset, sizeof(TInt) );
   842             offset += sizeof (TInt); 
   842             offset += sizeof (TInt);
   843             ro = ptr.Mid(offset, roSize).AllocL();
   843             ro = ptr.Mid(offset, roSize).AllocL();
   844             aRoList.Append(ro);
   844             aRoList.Append(ro);
   845             offset += roSize;
   845             offset += roSize;
   846             }
   846             }
   847         CleanupStack::PopAndDestroy();
   847         CleanupStack::PopAndDestroy();
   848         }
   848         }
   849     }; 
   849     };
   850 
   850 
   851 // -----------------------------------------------------------------------------
   851 // -----------------------------------------------------------------------------
   852 // RDRMRightsClient::
   852 // RDRMRightsClient::
   853 // 
   853 //
   854 // -----------------------------------------------------------------------------
   854 // -----------------------------------------------------------------------------
   855 //
   855 //
   856 EXPORT_C TInt RDRMRightsClient::Encrypt( const TDesC8& aIv,
   856 EXPORT_C TInt RDRMRightsClient::Encrypt( const TDesC8& aIv,
   857                        TPtr8& aData,
   857                        TPtr8& aData,
   858                        TBool aAddPadding )
   858                        TBool aAddPadding )
   859     {
   859     {
   860     return SendReceive( DRMEngine::EEncrypt, 
   860     return SendReceive( DRMEngine::EEncrypt,
   861                         TIpcArgs( &aIv, &aData, aAddPadding ) );
   861                         TIpcArgs( &aIv, &aData, aAddPadding ) );
   862     }                       
   862     }
   863 
   863 
   864 // -----------------------------------------------------------------------------
   864 // -----------------------------------------------------------------------------
   865 // RDRMRightsClient::
   865 // RDRMRightsClient::
   866 // 
   866 //
   867 // -----------------------------------------------------------------------------
   867 // -----------------------------------------------------------------------------
   868 //
   868 //
   869 EXPORT_C TInt RDRMRightsClient::Decrypt( const TDesC8& aIv,
   869 EXPORT_C TInt RDRMRightsClient::Decrypt( const TDesC8& aIv,
   870                        TPtr8& aData,
   870                        TPtr8& aData,
   871                        TBool aRemovePadding )
   871                        TBool aRemovePadding )
   872     {
   872     {
   873     return SendReceive( DRMEngine::EDecrypt, 
   873     return SendReceive( DRMEngine::EDecrypt,
   874                         TIpcArgs( &aIv, &aData, aRemovePadding ) );
   874                         TIpcArgs( &aIv, &aData, aRemovePadding ) );
   875     }                         
   875     }
   876 
   876 
   877 // -----------------------------------------------------------------------------
   877 // -----------------------------------------------------------------------------
   878 // RDRMRightsClient::
   878 // RDRMRightsClient::
   879 // 
   879 //
   880 // -----------------------------------------------------------------------------
   880 // -----------------------------------------------------------------------------
   881 //
   881 //
   882 EXPORT_C TInt RDRMRightsClient::InitializeKey( const TDesC8& aContentId )
   882 EXPORT_C TInt RDRMRightsClient::InitializeKey( const TDesC8& aContentId )
   883     {
   883     {
   884     return SendReceive( DRMEngine::EInitializeKey, 
   884     return SendReceive( DRMEngine::EInitializeKey,
   885                         TIpcArgs( &aContentId ) );
   885                         TIpcArgs( &aContentId ) );
   886     }
   886     }
   887 
   887 
   888 // -----------------------------------------------------------------------------
   888 // -----------------------------------------------------------------------------
   889 // RDRMRightsClient::
   889 // RDRMRightsClient::
   890 // 
   890 //
   891 // -----------------------------------------------------------------------------
   891 // -----------------------------------------------------------------------------
   892 //
   892 //
   893 EXPORT_C TInt RDRMRightsClient::InitializeGroupKey( const TDesC8& aGroupId,
   893 EXPORT_C TInt RDRMRightsClient::InitializeGroupKey( const TDesC8& aGroupId,
   894                                                     const TDesC8& aGroupKey,
   894                                                     const TDesC8& aGroupKey,
   895                                                     TEncryptionMethod aMethod )
   895                                                     TEncryptionMethod aMethod )
   896     {
   896     {
   897     return SendReceive( DRMEngine::EInitializeGroupKey, 
   897     return SendReceive( DRMEngine::EInitializeGroupKey,
   898                         TIpcArgs( &aGroupId, &aGroupKey, aMethod ) );
   898                         TIpcArgs( &aGroupId, &aGroupKey, aMethod ) );
   899     }                                            
   899     }
   900 
   900 
   901 // -----------------------------------------------------------------------------
   901 // -----------------------------------------------------------------------------
   902 // RDRMRightsClient::DeleteDomainRO
   902 // RDRMRightsClient::DeleteDomainRO
   903 // Delete domain rights object xml representation from the rdb
   903 // Delete domain rights object xml representation from the rdb
   904 // -----------------------------------------------------------------------------
   904 // -----------------------------------------------------------------------------
   905 //
   905 //
   906 EXPORT_C TInt RDRMRightsClient::DeleteDomainRO( const TDesC8& aRoId )
   906 EXPORT_C TInt RDRMRightsClient::DeleteDomainRO( const TDesC8& aRoId )
   907     {
   907     {
   908     DRMLOG( _L( "RDRMRightsClient::DeleteDomainRO" ) );
   908     DRMLOG( _L( "RDRMRightsClient::DeleteDomainRO" ) );
   909     
   909 
   910     // Check the parameter.
   910     // Check the parameter.
   911     if ( aRoId.Length() )
   911     if ( aRoId.Length() )
   912         {
   912         {
   913         return SendReceive( DRMEngine::EDeleteDomainRO, 
   913         return SendReceive( DRMEngine::EDeleteDomainRO,
   914                             TIpcArgs( &aRoId ) );
   914                             TIpcArgs( &aRoId ) );
   915         }
   915         }
   916     
   916 
   917     return KErrArgument;    
   917     return KErrArgument;
   918     }; 
   918     };
   919 
   919 
   920 
   920 
   921 // -----------------------------------------------------------------------------
   921 // -----------------------------------------------------------------------------
   922 // RDRMRightsClient::
   922 // RDRMRightsClient::
   923 // 
   923 //
   924 // -----------------------------------------------------------------------------
   924 // -----------------------------------------------------------------------------
   925 //
   925 //
   926 EXPORT_C TInt RDRMRightsClient::IsInCache( const TDesC8& aID,
   926 EXPORT_C TInt RDRMRightsClient::IsInCache( const TDesC8& aID,
   927                                            const TTime& aTime,
   927                                            const TTime& aTime,
   928                                            TBool& aInCache )
   928                                            TBool& aInCache )
   929     {
   929     {
   930     DRMLOG( _L( "RDRMRightsClient::IsInCache" ) );
   930     DRMLOG( _L( "RDRMRightsClient::IsInCache" ) );
   931     TPckgC< TTime > timePckg( aTime );
   931     TPckgC< TTime > timePckg( aTime );
   932     TPckg< TBool > inCache( aInCache );
   932     TPckg< TBool > inCache( aInCache );
   933         
   933 
   934     return SendReceive( DRMEngine::EIsInCache,
   934     return SendReceive( DRMEngine::EIsInCache,
   935                         TIpcArgs( &aID, &timePckg, &inCache ) );
   935                         TIpcArgs( &aID, &timePckg, &inCache ) );
   936     }
   936     }
   937     
   937 
   938 // -----------------------------------------------------------------------------
   938 // -----------------------------------------------------------------------------
   939 // RDRMRightsClient::
   939 // RDRMRightsClient::
   940 // 
   940 //
   941 // -----------------------------------------------------------------------------
   941 // -----------------------------------------------------------------------------
   942 //
   942 //
   943 EXPORT_C TInt RDRMRightsClient::IsInCache( const TDesC8& aID,
   943 EXPORT_C TInt RDRMRightsClient::IsInCache( const TDesC8& aID,
   944                                            TBool& aInCache )
   944                                            TBool& aInCache )
   945     {
   945     {
   946     DRMLOG( _L( "RDRMRightsClient::IsInCache" ) );
   946     DRMLOG( _L( "RDRMRightsClient::IsInCache" ) );
   947     
   947 
   948     TPckg< TBool > inCache( aInCache );
   948     TPckg< TBool > inCache( aInCache );
   949         
   949 
   950     return SendReceive( DRMEngine::EIsInCache,
   950     return SendReceive( DRMEngine::EIsInCache,
   951                         TIpcArgs( &aID, NULL, &inCache ) );
   951                         TIpcArgs( &aID, NULL, &inCache ) );
   952     }
   952     }
   953     
   953 
   954 // -----------------------------------------------------------------------------
   954 // -----------------------------------------------------------------------------
   955 // RDRMRightsClient::
   955 // RDRMRightsClient::
   956 // 
   956 //
   957 // -----------------------------------------------------------------------------
   957 // -----------------------------------------------------------------------------
   958 //
   958 //
   959 EXPORT_C TInt RDRMRightsClient::AddToCache( const TDesC8& aID,
   959 EXPORT_C TInt RDRMRightsClient::AddToCache( const TDesC8& aID,
   960                                             const TTime& aTime )
   960                                             const TTime& aTime )
   961     {
   961     {
   962     DRMLOG( _L( "RDRMRightsClient::AddToCache" ) );
   962     DRMLOG( _L( "RDRMRightsClient::AddToCache" ) );
   963     
   963 
   964     TPckgC< TTime > timePckg( aTime );
   964     TPckgC< TTime > timePckg( aTime );
   965     
   965 
   966     return SendReceive( DRMEngine::EAddToCache,
   966     return SendReceive( DRMEngine::EAddToCache,
   967                         TIpcArgs( &aID, &timePckg ) );
   967                         TIpcArgs( &aID, &timePckg ) );
   968     }
   968     }
   969 
   969 
   970 // -----------------------------------------------------------------------------
   970 // -----------------------------------------------------------------------------
   971 // RDRMRightsClient::
   971 // RDRMRightsClient::
   972 // 
   972 //
   973 // -----------------------------------------------------------------------------
   973 // -----------------------------------------------------------------------------
   974 //
   974 //
   975 EXPORT_C TInt RDRMRightsClient::AddToCache( const TDesC8& aID )
   975 EXPORT_C TInt RDRMRightsClient::AddToCache( const TDesC8& aID )
   976     {
   976     {
   977     DRMLOG( _L( "RDRMRightsClient::AddToCache" ) );
   977     DRMLOG( _L( "RDRMRightsClient::AddToCache" ) );
   978     
   978 
   979     return SendReceive( DRMEngine::EAddToCache,
   979     return SendReceive( DRMEngine::EAddToCache,
   980                         TIpcArgs( &aID, NULL ) );
   980                         TIpcArgs( &aID, NULL ) );
   981     }
   981     }
   982 
   982 
   983 // -----------------------------------------------------------------------------
   983 // -----------------------------------------------------------------------------
   984 // RDRMRightsClient::DeleteExpiredPermissions
   984 // RDRMRightsClient::DeleteExpiredPermissions
   985 // 
   985 //
   986 // -----------------------------------------------------------------------------
   986 // -----------------------------------------------------------------------------
   987 //
   987 //
   988 EXPORT_C void RDRMRightsClient::DeleteExpiredPermissions( TRequestStatus& aStatus )
   988 EXPORT_C void RDRMRightsClient::DeleteExpiredPermissions( TRequestStatus& aStatus )
   989     {
   989     {
   990     DRMLOG( _L( "RDRMRightsClient::DeleteExpiredPermissions" ) );
   990     DRMLOG( _L( "RDRMRightsClient::DeleteExpiredPermissions" ) );
   991     
   991 
   992     SendReceive( DRMEngine::EDeleteExpired, aStatus );
   992     SendReceive( DRMEngine::EDeleteExpired, aStatus );
   993     }
   993     }
   994  
   994 
   995 // -----------------------------------------------------------------------------
   995 // -----------------------------------------------------------------------------
   996 // RDRMRightsClient::SetEstimatedArrival
   996 // RDRMRightsClient::SetEstimatedArrival
   997 // sets the estimated RO arrival time to the given delta
   997 // sets the estimated RO arrival time to the given delta
   998 // -----------------------------------------------------------------------------
   998 // -----------------------------------------------------------------------------
   999 //
   999 //
  1002     {
  1002     {
  1003     DRMLOG( _L( "RDRMRightsClient::SetEstimatedArrival" ) );
  1003     DRMLOG( _L( "RDRMRightsClient::SetEstimatedArrival" ) );
  1004     TInt error = KErrNone;
  1004     TInt error = KErrNone;
  1005 
  1005 
  1006     TPckg< TTimeIntervalSeconds > delta( aDeltaSeconds );
  1006     TPckg< TTimeIntervalSeconds > delta( aDeltaSeconds );
  1007     
  1007 
  1008     error = SendReceive( DRMEngine::ESetEstimatedArrival, 
  1008     error = SendReceive( DRMEngine::ESetEstimatedArrival,
  1009                          TIpcArgs( &aContentID, &delta ) );
  1009                          TIpcArgs( &aContentID, &delta ) );
  1010     
  1010 
  1011     return error;    
  1011     return error;
  1012     };
  1012     };
  1013                                   
  1013 
  1014 // -----------------------------------------------------------------------------
  1014 // -----------------------------------------------------------------------------
  1015 // RDRMRightsClient::GetEstimatedArrival
  1015 // RDRMRightsClient::GetEstimatedArrival
  1016 // sets the amount of time in which the RO should arrive in
  1016 // sets the amount of time in which the RO should arrive in
  1017 // -----------------------------------------------------------------------------
  1017 // -----------------------------------------------------------------------------
  1018 //
  1018 //
  1021     {
  1021     {
  1022     DRMLOG( _L( "RDRMRightsClient::SetEstimatedArrival" ) );
  1022     DRMLOG( _L( "RDRMRightsClient::SetEstimatedArrival" ) );
  1023     TInt error = KErrNone;
  1023     TInt error = KErrNone;
  1024 
  1024 
  1025     TPckg< TTimeIntervalSeconds > delta( aDeltaSeconds );
  1025     TPckg< TTimeIntervalSeconds > delta( aDeltaSeconds );
  1026     
  1026 
  1027     error = SendReceive( DRMEngine::EGetEstimatedArrival, 
  1027     error = SendReceive( DRMEngine::EGetEstimatedArrival,
  1028                          TIpcArgs( &aContentID, &delta ) );
  1028                          TIpcArgs( &aContentID, &delta ) );
  1029     
  1029 
  1030     return error;     
  1030     return error;
  1031     }; 
  1031     };
  1032  
  1032 
  1033  
  1033 
  1034 // -----------------------------------------------------------------------------
  1034 // -----------------------------------------------------------------------------
  1035 // RDRMRightsClient::SetName
  1035 // RDRMRightsClient::SetName
  1036 // sets the name.
  1036 // sets the name.
  1037 // -----------------------------------------------------------------------------
  1037 // -----------------------------------------------------------------------------
  1038 //
  1038 //
  1041     {
  1041     {
  1042     DRMLOG( _L( "RDRMRightsClient::SetName" ) );
  1042     DRMLOG( _L( "RDRMRightsClient::SetName" ) );
  1043     return SendReceive( DRMEngine::ESetName,
  1043     return SendReceive( DRMEngine::ESetName,
  1044                         TIpcArgs( &aContentID, &aName ) );
  1044                         TIpcArgs( &aContentID, &aName ) );
  1045     }
  1045     }
  1046     
  1046 
  1047 // -----------------------------------------------------------------------------
  1047 // -----------------------------------------------------------------------------
  1048 // RDRMRightsClient::GetName
  1048 // RDRMRightsClient::GetName
  1049 // Gets the name. Two-phase operation.
  1049 // Gets the name. Two-phase operation.
  1050 // -----------------------------------------------------------------------------
  1050 // -----------------------------------------------------------------------------
  1051 //    
  1051 //
  1052 EXPORT_C TInt RDRMRightsClient::GetName( const TDesC8& aContentID,
  1052 EXPORT_C TInt RDRMRightsClient::GetName( const TDesC8& aContentID,
  1053                                          HBufC*& aName )
  1053                                          HBufC*& aName )
  1054     {
  1054     {
  1055     DRMLOG( _L( "RDRMRightsClient::GetName" ) );
  1055     DRMLOG( _L( "RDRMRightsClient::GetName" ) );
  1056     TPckgBuf< TInt > size( 0 );
  1056     TPckgBuf< TInt > size( 0 );
  1057     
  1057 
  1058     TInt error = SendReceive( DRMEngine::EGetName,
  1058     TInt error = SendReceive( DRMEngine::EGetName,
  1059                               TIpcArgs( &aContentID, &size ) );
  1059                               TIpcArgs( &aContentID, &size ) );
  1060     if ( !error )
  1060     if ( !error )
  1061         {
  1061         {
  1062         if ( !size() )
  1062         if ( !size() )
  1071             {
  1071             {
  1072             aName = HBufC::New( size() );
  1072             aName = HBufC::New( size() );
  1073             if ( aName )
  1073             if ( aName )
  1074                 {
  1074                 {
  1075                 TPtr data( aName->Des() );
  1075                 TPtr data( aName->Des() );
  1076                             
  1076 
  1077                 error = SendReceive( DRMEngine::EGetWideData,
  1077                 error = SendReceive( DRMEngine::EGetWideData,
  1078                                      TIpcArgs( &data ) );
  1078                                      TIpcArgs( &data ) );
  1079                 
  1079 
  1080                 if ( error )
  1080                 if ( error )
  1081                     {
  1081                     {
  1082                     delete aName; aName = NULL;
  1082                     delete aName; aName = NULL;
  1083                     }
  1083                     }
  1084                 }
  1084                 }
  1086                 {
  1086                 {
  1087                 error = KErrNoMemory;
  1087                 error = KErrNoMemory;
  1088                 }
  1088                 }
  1089             }
  1089             }
  1090         }
  1090         }
  1091         
  1091 
  1092     return error;
  1092     return error;
  1093     }
  1093     }
  1094 
  1094 
  1095 // -----------------------------------------------------------------------------
  1095 // -----------------------------------------------------------------------------
  1096 // RDRMRightsClient::Cancel
  1096 // RDRMRightsClient::Cancel
  1097 // -----------------------------------------------------------------------------
  1097 // -----------------------------------------------------------------------------
  1098 //      
  1098 //
  1099 EXPORT_C void RDRMRightsClient::Cancel()
  1099 EXPORT_C void RDRMRightsClient::Cancel()
  1100     {
  1100     {
  1101     DRMLOG( _L(" RDRMRightsClient::Cancel" ) );
  1101     DRMLOG( _L(" RDRMRightsClient::Cancel" ) );
  1102     SendReceive( DRMEngine::ECancel );
  1102     SendReceive( DRMEngine::ECancel );
  1103     }
  1103     }
  1104     
  1104 
  1105     
  1105 
  1106 // -----------------------------------------------------------------------------
  1106 // -----------------------------------------------------------------------------
  1107 // RDRMRightsClient::GetUdtData
  1107 // RDRMRightsClient::GetUdtData
  1108 // -----------------------------------------------------------------------------
  1108 // -----------------------------------------------------------------------------
  1109 //   
  1109 //
  1110 EXPORT_C TInt RDRMRightsClient::GetUdtData( TDes8& aUdtData )
  1110 EXPORT_C TInt RDRMRightsClient::GetUdtData( TDes8& aUdtData )
  1111     {
  1111     {
  1112     DRMLOG( _L( "RDRMRightsClient::GetUdtData" ) );
  1112     DRMLOG( _L( "RDRMRightsClient::GetUdtData" ) );
  1113     
  1113 
  1114     TInt error = SendReceive( DRMEngine::EGetUdtData,
  1114     TInt error = SendReceive( DRMEngine::EGetUdtData,
  1115                               TIpcArgs( &aUdtData ) );
  1115                               TIpcArgs( &aUdtData ) );
  1116         
  1116 
  1117     return error;        
  1117     return error;
  1118     };        
  1118     };
  1119 
  1119 
  1120 // -----------------------------------------------------------------------------
  1120 // -----------------------------------------------------------------------------
  1121 // RDRMRightsClient::InitializeUdt
  1121 // RDRMRightsClient::InitializeUdt
  1122 // -----------------------------------------------------------------------------
  1122 // -----------------------------------------------------------------------------
  1123 //   
  1123 //
  1124 EXPORT_C TInt RDRMRightsClient::InitiateUdt( const TDesC8& aKey )
  1124 EXPORT_C TInt RDRMRightsClient::InitiateUdt( const TDesC8& aKey )
  1125     {
  1125     {
  1126     DRMLOG( _L( "RDRMRightsClient::InitiateUdt" ) );
  1126     DRMLOG( _L( "RDRMRightsClient::InitiateUdt" ) );
  1127     
  1127 
  1128     TInt error = SendReceive( DRMEngine::EInitiateUdt,
  1128     TInt error = SendReceive( DRMEngine::EInitiateUdt,
  1129                               TIpcArgs( &aKey ) );     
  1129                               TIpcArgs( &aKey ) );
  1130     return error;        
  1130     return error;
  1131     };         
  1131     };
  1132 
  1132 
  1133 // -----------------------------------------------------------------------------
  1133 // -----------------------------------------------------------------------------
  1134 // RDRMRightsClient::InitOrphanedContentIdList
  1134 // RDRMRightsClient::InitOrphanedContentIdList
  1135 // -----------------------------------------------------------------------------
  1135 // -----------------------------------------------------------------------------
  1136 //
  1136 //
  1137 EXPORT_C void RDRMRightsClient::InitOrphanedContentIdList( TBool aPerformScan,
  1137 EXPORT_C void RDRMRightsClient::InitOrphanedContentIdList( TBool aPerformScan,
  1138                                                       TRequestStatus& aStatus )
  1138                                                       TRequestStatus& aStatus )
  1139     {
  1139     {
  1140     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList" ) );
  1140     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList" ) );
  1141         
  1141 
  1142     SendReceive( DRMEngine::EInitOrphanedList, 
  1142     SendReceive( DRMEngine::EInitOrphanedList,
  1143                  TIpcArgs( aPerformScan ), aStatus );
  1143                  TIpcArgs( aPerformScan ), aStatus );
  1144                  
  1144 
  1145     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList done" ) );                        
  1145     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList done" ) );
  1146     };
  1146     };
  1147 
  1147 
  1148 
  1148 
  1149 // -----------------------------------------------------------------------------
  1149 // -----------------------------------------------------------------------------
  1150 // RDRMRightsClient::ExportOrphanedContentIdList
  1150 // RDRMRightsClient::ExportOrphanedContentIdList
  1151 // -----------------------------------------------------------------------------
  1151 // -----------------------------------------------------------------------------
  1152 //   
  1152 //
  1153 EXPORT_C TInt RDRMRightsClient::ExportOrphanedContentIdList( TDes& aFileName )
  1153 EXPORT_C TInt RDRMRightsClient::ExportOrphanedContentIdList( TDes& aFileName )
  1154     {
  1154     {
  1155     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList" ) );
  1155     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList" ) );
  1156     
  1156 
  1157     return SendReceive( DRMEngine::EGetOrphanedList, 
  1157     return SendReceive( DRMEngine::EGetOrphanedList,
  1158                         TIpcArgs( &aFileName ) );
  1158                         TIpcArgs( &aFileName ) );
  1159             
  1159 
  1160     };        
  1160     };
  1161                  
  1161 
  1162 // -----------------------------------------------------------------------------
  1162 // -----------------------------------------------------------------------------
  1163 // RDRMRightsClient::ExportOrphanedContentIdList
  1163 // RDRMRightsClient::ExportOrphanedContentIdList
  1164 // -----------------------------------------------------------------------------
  1164 // -----------------------------------------------------------------------------
  1165 //   
  1165 //
  1166 EXPORT_C TInt RDRMRightsClient::ExportOrphanedContentIdList( 
  1166 EXPORT_C TInt RDRMRightsClient::ExportOrphanedContentIdList(
  1167                         RPointerArray<HBufC8>& aContentIdList )
  1167                         RPointerArray<HBufC8>& aContentIdList )
  1168     {
  1168     {
  1169     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList to array" ) );
  1169     DRMLOG( _L( "RDRMRightsClient::ExportOrphanedContentIdList to array" ) );
  1170     TFileName name;
  1170     TFileName name;
  1171     aContentIdList.ResetAndDestroy();
  1171     aContentIdList.ResetAndDestroy();
  1172     
  1172 
  1173     TInt error = ExportOrphanedContentIdList( name );
  1173     TInt error = ExportOrphanedContentIdList( name );
  1174     if ( !error )
  1174     if ( !error )
  1175         {
  1175         {
  1176         RFs fs;
  1176         RFs fs;
  1177         error = fs.Connect();
  1177         error = fs.Connect();
  1180             TRAP( error, URIFileToArrayL( fs, name, aContentIdList ) );
  1180             TRAP( error, URIFileToArrayL( fs, name, aContentIdList ) );
  1181             if ( error )
  1181             if ( error )
  1182                 {
  1182                 {
  1183                 aContentIdList.ResetAndDestroy();
  1183                 aContentIdList.ResetAndDestroy();
  1184                 }
  1184                 }
  1185             
  1185 
  1186             fs.Delete( name );
  1186             fs.Delete( name );
  1187             fs.Close();
  1187             fs.Close();
  1188             }
  1188             }
  1189         }
  1189         }
  1190     
  1190 
  1191     DRMLOG2( _L( "RDRMRightsClient::ExportOrphanedContentIdList to array: %d" ), error );
  1191     DRMLOG2( _L( "RDRMRightsClient::ExportOrphanedContentIdList to array: %d" ), error );
  1192             
  1192 
  1193     return error;        
  1193     return error;
  1194     }; 
  1194     };
  1195 
  1195 
  1196 // -----------------------------------------------------------------------------
  1196 // -----------------------------------------------------------------------------
  1197 // RDRMRightsClient::EncodeRightsIssuerField
  1197 // RDRMRightsClient::EncodeRightsIssuerField
  1198 // The encoded field is consturcted from
  1198 // The encoded field is consturcted from
  1199 // - F/L prefix
  1199 // - F/L prefix
  1200 // - phone serial number
  1200 // - phone serial number
  1201 // - base64encode(AES IV + AES encoded original field incl. padding)
  1201 // - base64encode(AES IV + AES encoded original field incl. padding)
  1202 // -----------------------------------------------------------------------------
  1202 // -----------------------------------------------------------------------------
  1203 //
  1203 //
  1204 EXPORT_C TInt RDRMRightsClient::EncodeRightsIssuerField( 
  1204 EXPORT_C TInt RDRMRightsClient::EncodeRightsIssuerField(
  1205                                     const TDesC8& aOldValue,
  1205                                     const TDesC8& aOldValue,
  1206                                     HBufC8*& aNewValue )
  1206                                     HBufC8*& aNewValue )
  1207     {
  1207     {
  1208     DRMLOG( _L( "RDRMRightsClient::EncodeRightsIssuerField" ) );
  1208     DRMLOG( _L( "RDRMRightsClient::EncodeRightsIssuerField" ) );
  1209 
  1209 
  1210     TInt error( KErrNone );
  1210     TInt error( KErrNone );
  1211     
  1211 
  1212     TInt size( aOldValue.Length() ); // original length
  1212     TInt size( aOldValue.Length() ); // original length
  1213     size += KDCFKeySize - ( size % KDCFKeySize ); // padding
  1213     size += KDCFKeySize - ( size % KDCFKeySize ); // padding
  1214     size += KDCFKeySize; // IV
  1214     size += KDCFKeySize; // IV
  1215     size += ( size + 2 ) / 3 * 4; // base64
  1215     size += ( size + 2 ) / 3 * 4; // base64
  1216     size += RMobilePhone::KPhoneSerialNumberSize;
  1216     size += RMobilePhone::KPhoneSerialNumberSize;
  1217     size += 3; // "flk"
  1217     size += 3; // "flk"
  1218     
  1218 
  1219     aNewValue = HBufC8::New( size );
  1219     aNewValue = HBufC8::New( size );
  1220     if ( aNewValue )
  1220     if ( aNewValue )
  1221         {
  1221         {
  1222         TPtr8 des( aNewValue->Des() );
  1222         TPtr8 des( aNewValue->Des() );
  1223         
  1223 
  1224         des = aOldValue;
  1224         des = aOldValue;
  1225         
  1225 
  1226         error = SendReceive( DRMEngine::EEncodeRightsIssuerField,
  1226         error = SendReceive( DRMEngine::EEncodeRightsIssuerField,
  1227                              TIpcArgs( &des ) );
  1227                              TIpcArgs( &des ) );
  1228         if ( error )
  1228         if ( error )
  1229             {
  1229             {
  1230             delete aNewValue;
  1230             delete aNewValue;
  1233         }
  1233         }
  1234     else
  1234     else
  1235         {
  1235         {
  1236         error = KErrNoMemory;
  1236         error = KErrNoMemory;
  1237         }
  1237         }
  1238     
  1238 
  1239     DRMLOG2( _L( "RDRMRightsClient::EncodeRightsIssuerField> %d" ), error );
  1239     DRMLOG2( _L( "RDRMRightsClient::EncodeRightsIssuerField> %d" ), error );
  1240     
  1240 
  1241     return error;
  1241     return error;
  1242     }
  1242     }
  1243     
  1243 
  1244 EXPORT_C TInt RDRMRightsClient::DecodeRightsIssuerField( 
  1244 EXPORT_C TInt RDRMRightsClient::DecodeRightsIssuerField(
  1245                                     const TDesC8& aEncoded,
  1245                                     const TDesC8& aEncoded,
  1246                                     HBufC8*& aDecoded )
  1246                                     HBufC8*& aDecoded )
  1247     {
  1247     {
  1248     DRMLOG( _L( "DRMRightsClient::DecodeRightsIssuerField" ) );
  1248     DRMLOG( _L( "DRMRightsClient::DecodeRightsIssuerField" ) );
  1249     
  1249 
  1250     TInt error( KErrNone );
  1250     TInt error( KErrNone );
  1251     
  1251 
  1252     aDecoded = HBufC8::New( aEncoded.Length() );
  1252     aDecoded = HBufC8::New( aEncoded.Length() );
  1253     if ( aDecoded )
  1253     if ( aDecoded )
  1254         {
  1254         {
  1255         TPtr8 des( aDecoded->Des() );
  1255         TPtr8 des( aDecoded->Des() );
  1256         
  1256 
  1257         error = SendReceive( DRMEngine::EDecodeRightsIssuerField,
  1257         error = SendReceive( DRMEngine::EDecodeRightsIssuerField,
  1258                              TIpcArgs( &aEncoded,
  1258                              TIpcArgs( &aEncoded,
  1259                                       &des ) );
  1259                                       &des ) );
  1260         if ( error )
  1260         if ( error )
  1261             {
  1261             {
  1270         }
  1270         }
  1271     else
  1271     else
  1272         {
  1272         {
  1273         error = KErrNoMemory;
  1273         error = KErrNoMemory;
  1274         }
  1274         }
  1275     
  1275 
  1276     DRMLOG2( _L( "DRMRightsClient::DecodeRightsIssuerField: error %d" ), error );
  1276     DRMLOG2( _L( "DRMRightsClient::DecodeRightsIssuerField: error %d" ), error );
  1277     
  1277 
  1278     return error;
  1278     return error;
  1279     }
  1279     }
  1280   
  1280 
  1281 // -----------------------------------------------------------------------------
  1281 // -----------------------------------------------------------------------------
  1282 // RDRMRightsClient::SetAuthenticationSeed
  1282 // RDRMRightsClient::SetAuthenticationSeed
  1283 // 
  1283 //
  1284 // -----------------------------------------------------------------------------
  1284 // -----------------------------------------------------------------------------
  1285 //
  1285 //
  1286 EXPORT_C TInt RDRMRightsClient::SetAuthenticationSeed( const TDesC8& aContentID,
  1286 EXPORT_C TInt RDRMRightsClient::SetAuthenticationSeed( const TDesC8& aContentID,
  1287                                                        const TDesC8& aSeed )
  1287                                                        const TDesC8& aSeed )
  1288     {
  1288     {
  1289     DRMLOG( _L( "RDRMRightsClient::SetAuthenticationSeed" ) );
  1289     DRMLOG( _L( "RDRMRightsClient::SetAuthenticationSeed" ) );
  1290     return SendReceive( DRMEngine::ESetAuthenticationSeed,
  1290     return SendReceive( DRMEngine::ESetAuthenticationSeed,
  1291                         TIpcArgs( &aContentID, &aSeed ) );
  1291                         TIpcArgs( &aContentID, &aSeed ) );
  1292     }
  1292     }
  1293     
  1293 
  1294 // -----------------------------------------------------------------------------
  1294 // -----------------------------------------------------------------------------
  1295 // RDRMRightsClient::GetAuthenticationSeed
  1295 // RDRMRightsClient::GetAuthenticationSeed
  1296 // 
  1296 //
  1297 // -----------------------------------------------------------------------------
  1297 // -----------------------------------------------------------------------------
  1298 //
  1298 //
  1299 EXPORT_C TInt RDRMRightsClient::GetAuthenticationSeed( const TDesC8& aContentID,
  1299 EXPORT_C TInt RDRMRightsClient::GetAuthenticationSeed( const TDesC8& aContentID,
  1300                                                        TDes8& aSeed )
  1300                                                        TDes8& aSeed )
  1301     {
  1301     {
  1302     DRMLOG( _L( "RDRMRightsClient::GetAuthenticationSeed" ) );
  1302     DRMLOG( _L( "RDRMRightsClient::GetAuthenticationSeed" ) );
  1303     return SendReceive( DRMEngine::EGetAuthenticationSeed,
  1303     return SendReceive( DRMEngine::EGetAuthenticationSeed,
  1304                         TIpcArgs( &aContentID, &aSeed ) );
  1304                         TIpcArgs( &aContentID, &aSeed ) );
  1305     }                                                       
  1305     }
  1306 
  1306 
  1307 // -----------------------------------------------------------------------------
  1307 // -----------------------------------------------------------------------------
  1308 // RDRMRightsClient::FileToListL
  1308 // RDRMRightsClient::FileToListL
  1309 // Converts the given file into an array.
  1309 // Converts the given file into an array.
  1310 // -----------------------------------------------------------------------------
  1310 // -----------------------------------------------------------------------------
  1313                                    const TDesC& aFileName,
  1313                                    const TDesC& aFileName,
  1314                                    RPointerArray< CDRMPermission >& aList )
  1314                                    RPointerArray< CDRMPermission >& aList )
  1315     {
  1315     {
  1316     DRMLOG( _L( "RDRMRightsClient::FileToListL" ) );
  1316     DRMLOG( _L( "RDRMRightsClient::FileToListL" ) );
  1317     TInt error = KErrNone;
  1317     TInt error = KErrNone;
  1318     
  1318 
  1319     // Temporary storage.
  1319     // Temporary storage.
  1320     CDRMPermission* tmpObject;
  1320     CDRMPermission* tmpObject;
  1321     
  1321 
  1322     // To access the file data.
  1322     // To access the file data.
  1323     RFileReadStream fileStream;
  1323     RFileReadStream fileStream;
  1324     
  1324 
  1325     // How many objects there is in the file.
  1325     // How many objects there is in the file.
  1326     TInt size = 0;
  1326     TInt size = 0;
  1327     
  1327 
  1328     // Temporary counter.
  1328     // Temporary counter.
  1329     TInt count = 0;
  1329     TInt count = 0;
  1330     
  1330 
  1331     
  1331 
  1332     // Open the file.
  1332     // Open the file.
  1333     User::LeaveIfError( fileStream.Open( aFs, aFileName, EFileRead | EFileStream ) );
  1333     User::LeaveIfError( fileStream.Open( aFs, aFileName, EFileRead | EFileStream ) );
  1334     CleanupClosePushL( fileStream );
  1334     CleanupClosePushL( fileStream );
  1335     
  1335 
  1336     size = fileStream.ReadInt32L();
  1336     size = fileStream.ReadInt32L();
  1337     
  1337 
  1338     while( count < size )
  1338     while( count < size )
  1339         {
  1339         {
  1340         // Allocate a new RO.
  1340         // Allocate a new RO.
  1341         tmpObject = CDRMPermission::NewL();
  1341         tmpObject = CDRMPermission::NewL();
  1342         
  1342 
  1343         // Read the object.
  1343         // Read the object.
  1344         TRAP( error, tmpObject->InternalizeL( fileStream ) );
  1344         TRAP( error, tmpObject->InternalizeL( fileStream ) );
  1345         
  1345 
  1346         if ( !error )
  1346         if ( !error )
  1347             {
  1347             {
  1348             // Add the object into the list.
  1348             // Add the object into the list.
  1349             error = aList.Append( tmpObject );
  1349             error = aList.Append( tmpObject );
  1350             }
  1350             }
  1351         
  1351 
  1352         if ( error )
  1352         if ( error )
  1353             {
  1353             {
  1354             delete tmpObject;
  1354             delete tmpObject;
  1355             User::Leave( error );
  1355             User::Leave( error );
  1356             }
  1356             }
  1357         
  1357 
  1358         // Now tmpObject is under responsibility of aList. 
  1358         // Now tmpObject is under responsibility of aList.
  1359         ++count;
  1359         ++count;
  1360         }
  1360         }
  1361     
  1361 
  1362     // All done.
  1362     // All done.
  1363     CleanupStack::PopAndDestroy(); // fileStream 
  1363     CleanupStack::PopAndDestroy(); // fileStream
  1364     }
  1364     }
  1365 
  1365 
  1366 // -----------------------------------------------------------------------------
  1366 // -----------------------------------------------------------------------------
  1367 // RDRMRightsClient::URIFileToArrayL
  1367 // RDRMRightsClient::URIFileToArrayL
  1368 // Converts the given file into an array.
  1368 // Converts the given file into an array.
  1374     {
  1374     {
  1375     DRMLOG( _L( "RDRMRightsClient::URIFileToArrayL" ) );
  1375     DRMLOG( _L( "RDRMRightsClient::URIFileToArrayL" ) );
  1376     RFileReadStream stream;
  1376     RFileReadStream stream;
  1377     TUint16 size = 0;
  1377     TUint16 size = 0;
  1378     TPtr8 data( NULL, 0, 0 );
  1378     TPtr8 data( NULL, 0, 0 );
  1379     
  1379 
  1380     User::LeaveIfError( stream.Open( aFs, aFile, EFileRead | EFileStream ) );
  1380     User::LeaveIfError( stream.Open( aFs, aFile, EFileRead | EFileStream ) );
  1381     CleanupClosePushL( stream );
  1381     CleanupClosePushL( stream );
  1382     
  1382 
  1383     size = stream.ReadUint16L();
  1383     size = stream.ReadUint16L();
  1384     while( size > 0 )
  1384     while( size > 0 )
  1385         {
  1385         {
  1386         HBufC8* tmp = HBufC8::NewLC( size );
  1386         HBufC8* tmp = HBufC8::NewLC( size );
  1387         data.Set( tmp->Des() );
  1387         data.Set( tmp->Des() );
  1388         stream.ReadL( data, size );
  1388         stream.ReadL( data, size );
  1389         User::LeaveIfError( aList.Append( tmp ) );
  1389         User::LeaveIfError( aList.Append( tmp ) );
  1390         CleanupStack::Pop(); // tmp
  1390         CleanupStack::Pop(); // tmp
  1391         size = stream.ReadUint16L();
  1391         size = stream.ReadUint16L();
  1392         }
  1392         }
  1393     
  1393 
  1394     // All read, return.
  1394     // All read, return.
  1395     
  1395 
  1396     CleanupStack::PopAndDestroy(); // stream
  1396     CleanupStack::PopAndDestroy(); // stream
  1397     }
  1397     }
  1398 
  1398 
  1399 // -----------------------------------------------------------------------------
  1399 // -----------------------------------------------------------------------------
  1400 // RDRMRightsClient::VerifyMacL
  1400 // RDRMRightsClient::VerifyMacL
  1401 // Verifies the MAC. 
  1401 // Verifies the MAC.
  1402 // -----------------------------------------------------------------------------
  1402 // -----------------------------------------------------------------------------
  1403 //    
  1403 //
  1404 EXPORT_C TInt RDRMRightsClient::VerifyMacL(const TDesC8& aSignedInfoElement,
  1404 EXPORT_C TInt RDRMRightsClient::VerifyMacL(const TDesC8& aSignedInfoElement,
  1405                                   const TDesC8& aMacValue ) const
  1405                                   const TDesC8& aMacValue ) const
  1406     {
  1406     {
  1407     DRMLOG( _L( "RDRMRightsClient::VerifyMacL" ) );
  1407     DRMLOG( _L( "RDRMRightsClient::VerifyMacL" ) );
  1408     
  1408 
  1409     TInt error = SendReceive( DRMEngine::EVerifyMac,
  1409     TInt error = SendReceive( DRMEngine::EVerifyMac,
  1410                               TIpcArgs( &aSignedInfoElement, &aMacValue) );
  1410                               TIpcArgs( &aSignedInfoElement, &aMacValue) );
  1411     return error;
  1411     return error;
  1412     }
  1412     }
  1413 
  1413 
  1414 
  1414 
  1415 // -----------------------------------------------------------------------------
  1415 // -----------------------------------------------------------------------------
  1416 // RDRMRightsClient::GetSupportedIndividualsL
  1416 // RDRMRightsClient::GetSupportedIndividualsL
  1417 // retrieves the supported individuals list
  1417 // retrieves the supported individuals list
  1418 // -----------------------------------------------------------------------------
  1418 // -----------------------------------------------------------------------------
  1419 //    
  1419 //
  1420 EXPORT_C TInt RDRMRightsClient::GetSupportedIndividualsL(
  1420 EXPORT_C TInt RDRMRightsClient::GetSupportedIndividualsL(
  1421                                     RPointerArray<HBufC8>& aIndividuals) const
  1421                                     RPointerArray<HBufC8>& aIndividuals) const
  1422     {
  1422     {
  1423     DRMLOG( _L( "RDRMRightsClient::GetSupportedIndividualsL" ) );
  1423     DRMLOG( _L( "RDRMRightsClient::GetSupportedIndividualsL" ) );
  1424     TPckgBuf< TInt > size( 0 );    
  1424     TPckgBuf< TInt > size( 0 );
  1425     TInt error = SendReceive( DRMEngine::EGetSupportedIndividuals,
  1425     TInt error = SendReceive( DRMEngine::EGetSupportedIndividuals,
  1426                               TIpcArgs( &size) );
  1426                               TIpcArgs( &size) );
  1427     HBufC8* dataBuf = NULL;
  1427     HBufC8* dataBuf = NULL;
  1428     HBufC8* individual = NULL;
  1428     HBufC8* individual = NULL;
  1429     TInt indivSize;
  1429     TInt indivSize;
  1430     TInt offset;
  1430     TInt offset;
  1431                                   
  1431 
  1432     if ( !error )
  1432     if ( !error )
  1433         {
  1433         {
  1434         if ( !size() )
  1434         if ( !size() )
  1435             {
  1435             {
  1436             return KErrNone;
  1436             return KErrNone;
  1439             {
  1439             {
  1440             dataBuf = HBufC8::NewLC( size() );
  1440             dataBuf = HBufC8::NewLC( size() );
  1441             if ( dataBuf )
  1441             if ( dataBuf )
  1442                 {
  1442                 {
  1443                 TPtr8 data( dataBuf->Des() );
  1443                 TPtr8 data( dataBuf->Des() );
  1444                             
  1444 
  1445                 error = SendReceive( DRMEngine::EGetPreparedData,
  1445                 error = SendReceive( DRMEngine::EGetPreparedData,
  1446                                      TIpcArgs( &data ) );
  1446                                      TIpcArgs( &data ) );
  1447                 
  1447 
  1448                 if ( !error )
  1448                 if ( !error )
  1449                     { 
  1449                     {
  1450                     offset = 0;
  1450                     offset = 0;
  1451                     while (offset < size())
  1451                     while (offset < size())
  1452                         {
  1452                         {
  1453                         Mem::Copy( &indivSize, data.Ptr()+offset, sizeof(TInt) );
  1453                         Mem::Copy( &indivSize, data.Ptr()+offset, sizeof(TInt) );
  1454                         offset += sizeof (TInt); 
  1454                         offset += sizeof (TInt);
  1455                         individual = data.Mid(offset, indivSize).AllocLC();
  1455                         individual = data.Mid(offset, indivSize).AllocLC();
  1456                         aIndividuals.AppendL(individual);
  1456                         aIndividuals.AppendL(individual);
  1457                         CleanupStack::Pop(); // individual
  1457                         CleanupStack::Pop(); // individual
  1458                         offset += indivSize;
  1458                         offset += indivSize;
  1459                         }
  1459                         }
  1460                     }
  1460                     }
  1461                 }
  1461                 }
  1462             CleanupStack::PopAndDestroy();   
  1462             CleanupStack::PopAndDestroy();
  1463             }
  1463             }
  1464         }                                             
  1464         }
  1465     return KErrNone;
  1465     return KErrNone;
  1466     }
  1466     }
  1467     
  1467 
  1468 // -----------------------------------------------------------------------------
  1468 // -----------------------------------------------------------------------------
  1469 // RDRMRightsClient::StopWatching
  1469 // RDRMRightsClient::StopWatching
  1470 // -----------------------------------------------------------------------------
  1470 // -----------------------------------------------------------------------------
  1471 //    
  1471 //
  1472 EXPORT_C void RDRMRightsClient::StopWatching() const
  1472 EXPORT_C void RDRMRightsClient::StopWatching() const
  1473     {
  1473     {
  1474     SendReceive( DRMEngine::EStopWatching );
  1474     SendReceive( DRMEngine::EStopWatching );
  1475     }
  1475     }
  1476 
  1476 
  1477 // -----------------------------------------------------------------------------
  1477 // -----------------------------------------------------------------------------
  1478 // RDRMRightsClient::UnwrapMacAndRek
  1478 // RDRMRightsClient::UnwrapMacAndRek
  1479 // -----------------------------------------------------------------------------
  1479 // -----------------------------------------------------------------------------
  1480 //    
  1480 //
  1481 EXPORT_C TInt RDRMRightsClient::UnwrapMacAndRek( const TDesC8& aMacAndRek,
  1481 EXPORT_C TInt RDRMRightsClient::UnwrapMacAndRek( const TDesC8& aMacAndRek,
  1482                                                  TKeyTransportScheme aTransportScheme,
  1482                                                  TKeyTransportScheme aTransportScheme,
  1483                                                  const TDesC8& aRightsIssuerId,
  1483                                                  const TDesC8& aRightsIssuerId,
  1484                                                  const TDesC8& aDomainId ) const
  1484                                                  const TDesC8& aDomainId ) const
  1485     {
  1485     {
  1486     HBufC8* data = NULL;
  1486     HBufC8* data = NULL;
  1487     TPtr8 dataPtr( NULL, 0 );
  1487     TPtr8 dataPtr( NULL, 0 );
  1488     TInt err = KErrNone;
  1488     TInt err = KErrNone;
  1489     
  1489 
  1490     data = HBufC8::New( 1 + aMacAndRek.Size() );
  1490     data = HBufC8::New( 1 + aMacAndRek.Size() );
  1491     
  1491 
  1492     if ( data )
  1492     if ( data )
  1493         {
  1493         {
  1494         dataPtr.Set( data->Des() );
  1494         dataPtr.Set( data->Des() );
  1495         dataPtr.SetLength( 1 ); 
  1495         dataPtr.SetLength( 1 );
  1496         dataPtr[0] = aTransportScheme;
  1496         dataPtr[0] = aTransportScheme;
  1497         dataPtr.Append( aMacAndRek );
  1497         dataPtr.Append( aMacAndRek );
  1498     
  1498 
  1499         if( aDomainId.Length() )
  1499         if( aDomainId.Length() )
  1500             {
  1500             {
  1501             err = SendReceive( DRMEngine::EUnwrapDomainMacAndRek, TIpcArgs( &dataPtr,
  1501             err = SendReceive( DRMEngine::EUnwrapDomainMacAndRek, TIpcArgs( &dataPtr,
  1502                                                                   &aRightsIssuerId,
  1502                                                                   &aRightsIssuerId,
  1503                                                                   &aDomainId ) );
  1503                                                                   &aDomainId ) );
  1509                                                                   NULL ) );
  1509                                                                   NULL ) );
  1510             }
  1510             }
  1511         delete data;
  1511         delete data;
  1512         data = NULL;
  1512         data = NULL;
  1513         }
  1513         }
  1514     else 
  1514     else
  1515         {
  1515         {
  1516         err = KErrNoMemory;
  1516         err = KErrNoMemory;
  1517         }
  1517         }
  1518     
  1518 
  1519     return err;
  1519     return err;
  1520     }
  1520     }
  1521     
  1521 
  1522 // -----------------------------------------------------------------------------
  1522 // -----------------------------------------------------------------------------
  1523 // RDRMRightsClient::GetRandomDataL
  1523 // RDRMRightsClient::GetRandomDataL
  1524 // -----------------------------------------------------------------------------
  1524 // -----------------------------------------------------------------------------
  1525 //    
  1525 //
  1526 EXPORT_C void RDRMRightsClient::GetRandomDataL( TDes8& aRandomData ) const
  1526 EXPORT_C void RDRMRightsClient::GetRandomDataL( TDes8& aRandomData ) const
  1527     {
  1527     {
  1528     if( !aRandomData.Length() )
  1528     if( !aRandomData.Length() )
  1529         {
  1529         {
  1530         User::Leave(KErrArgument);
  1530         User::Leave(KErrArgument);
  1533     }
  1533     }
  1534 
  1534 
  1535 // -----------------------------------------------------------------------------
  1535 // -----------------------------------------------------------------------------
  1536 // RDRMRightsClient::GetMeteringData()
  1536 // RDRMRightsClient::GetMeteringData()
  1537 // -----------------------------------------------------------------------------
  1537 // -----------------------------------------------------------------------------
  1538 //    
  1538 //
  1539 #ifndef RD_DRM_METERING
  1539 #ifndef RD_DRM_METERING
  1540 EXPORT_C HBufC8* RDRMRightsClient::GetMeteringDataL( const TDesC8& /*aRiId*/ )
  1540 EXPORT_C HBufC8* RDRMRightsClient::GetMeteringDataL( const TDesC8& /*aRiId*/ )
  1541     {
  1541     {
  1542     return NULL;
  1542     return NULL;
  1543     }
  1543     }
  1544 #else
  1544 #else
  1545 EXPORT_C HBufC8* RDRMRightsClient::GetMeteringDataL( const TDesC8& aRiId )
  1545 EXPORT_C HBufC8* RDRMRightsClient::GetMeteringDataL( const TDesC8& aRiId )
  1546     {
  1546     {
  1547     TInt error = KErrNone;
  1547     TInt error = KErrNone;
  1548     HBufC8* meteringData = NULL;
  1548     HBufC8* meteringData = NULL;
  1549        
  1549 
  1550     if ( aRiId.Length() )
  1550     if ( aRiId.Length() )
  1551         {
  1551         {
  1552         TInt size = 0;
  1552         TInt size = 0;
  1553         TPckg<TInt> package( size );
  1553         TPckg<TInt> package( size );
  1554         
  1554 
  1555         error = SendReceive( DRMEngine::EGetMeteringData, 
  1555         error = SendReceive( DRMEngine::EGetMeteringData,
  1556                            TIpcArgs( &package, &aRiId ) );
  1556                            TIpcArgs( &package, &aRiId ) );
  1557                            
  1557 
  1558         if ( error == KErrNotFound )
  1558         if ( error == KErrNotFound )
  1559             {
  1559             {
  1560             return NULL;
  1560             return NULL;
  1561             }
  1561             }
  1562             
  1562 
  1563         User::LeaveIfError( error );
  1563         User::LeaveIfError( error );
  1564 
  1564 
  1565         meteringData = HBufC8::NewMaxLC( size );
  1565         meteringData = HBufC8::NewMaxLC( size );
  1566         
  1566 
  1567         // Package 'object' into TPtr8.
  1567         // Package 'object' into TPtr8.
  1568         TPtr8 objectPkg( const_cast< TUint8* >( meteringData->Ptr() ),
  1568         TPtr8 objectPkg( const_cast< TUint8* >( meteringData->Ptr() ),
  1569                          size,
  1569                          size,
  1570                          size );
  1570                          size );
  1571 
  1571 
  1572         User::LeaveIfError( SendReceive( DRMEngine::EGetPreparedData,
  1572         User::LeaveIfError( SendReceive( DRMEngine::EGetPreparedData,
  1573                                          TIpcArgs( &objectPkg) ) );
  1573                                          TIpcArgs( &objectPkg) ) );
  1574         
  1574 
  1575         CleanupStack::Pop(); // meteringData
  1575         CleanupStack::Pop(); // meteringData
  1576         return meteringData;
  1576         return meteringData;
  1577         }
  1577         }
  1578     
  1578 
  1579     User::Leave( KErrArgument );
  1579     User::Leave( KErrArgument );
  1580     return NULL;
  1580     return NULL;
  1581     }
  1581     }
  1582 #endif //RD_DRM_METERING
  1582 #endif //RD_DRM_METERING
  1583  
  1583 
  1584  // -----------------------------------------------------------------------------
  1584  // -----------------------------------------------------------------------------
  1585 // RDRMRightsClient::DeleteMeteringDataL
  1585 // RDRMRightsClient::DeleteMeteringDataL
  1586 // -----------------------------------------------------------------------------
  1586 // -----------------------------------------------------------------------------
  1587 //    
  1587 //
  1588 #ifndef RD_DRM_METERING
  1588 #ifndef RD_DRM_METERING
  1589 EXPORT_C TInt RDRMRightsClient::DeleteMeteringDataL( const TDesC8& /*aRiId*/ )
  1589 EXPORT_C TInt RDRMRightsClient::DeleteMeteringDataL( const TDesC8& /*aRiId*/ )
  1590     {
  1590     {
  1591     return KErrNotSupported;
  1591     return KErrNotSupported;
  1592     }
  1592     }
  1593 #else    	
  1593 #else
  1594 EXPORT_C TInt RDRMRightsClient::DeleteMeteringDataL( const TDesC8& aRiId )
  1594 EXPORT_C TInt RDRMRightsClient::DeleteMeteringDataL( const TDesC8& aRiId )
  1595     {
  1595     {
  1596     if ( aRiId.Length() )
  1596     if ( aRiId.Length() )
  1597         {
  1597         {
  1598         User::LeaveIfError( SendReceive( DRMEngine::EDeleteMeteringData,
  1598         User::LeaveIfError( SendReceive( DRMEngine::EDeleteMeteringData,
  1602     else
  1602     else
  1603         {
  1603         {
  1604         return KErrArgument;
  1604         return KErrArgument;
  1605         }
  1605         }
  1606     }
  1606     }
  1607 #endif 
  1607 #endif
  1608 
  1608 
  1609 // ========================== OTHER EXPORTED FUNCTIONS =========================
  1609 // ========================== OTHER EXPORTED FUNCTIONS =========================
  1610               
  1610 
  1611     
  1611 
  1612 //  End of File  
  1612 //  End of File