omadrm/drmengine/legacy/src/DRMCommon.cpp
branchRCL_3
changeset 18 8a03a285ab14
parent 0 95b198f216e5
child 32 457cd4423b8c
equal deleted inserted replaced
17:e16d72588c28 18:8a03a285ab14
    17 
    17 
    18 
    18 
    19 // INCLUDE FILES
    19 // INCLUDE FILES
    20 
    20 
    21 #include <f32file.h>
    21 #include <f32file.h>
    22 #include <s32file.h> 
    22 #include <s32file.h>
    23 #include <apmstd.h>
    23 #include <apmstd.h>
    24 #include <WSPDecoder.h>
    24 #include <wspdecoder.h>
    25 #include <WSPEncoder.h>
    25 #include <wspencoder.h>
    26 
    26 
    27 #include <barsc.h>
    27 #include <barsc.h>
    28 #include <barsread.h> 
    28 #include <barsread.h>
    29 
    29 
    30 #include <DRMCommon.rsg>
    30 #include <DRMCommon.rsg>
    31 
    31 
    32 #ifdef RD_MULTIPLE_DRIVE
    32 #ifdef RD_MULTIPLE_DRIVE
    33 #include <DriveInfo.h>
    33 #include <driveinfo.h>
    34 #endif
    34 #endif
    35 
    35 
    36 #include "DRMCommon.h"
    36 #include "DRMCommon.h"
    37 #include "DRMRightsClient.h"
    37 #include "DRMRightsClient.h"
    38 #include "DcfCommon.h"
    38 #include "DcfCommon.h"
    39 #include "Oma1Dcf.h"
    39 #include "Oma1Dcf.h"
    40 #include "Oma2Dcf.h"
    40 #include "oma2dcf.h"
    41 #include "DRMPermission.h"
    41 #include "DrmPermission.h"
    42 
    42 
    43 // EXTERNAL DATA STRUCTURES
    43 // EXTERNAL DATA STRUCTURES
    44 
    44 
    45 // EXTERNAL FUNCTION PROTOTYPES  
    45 // EXTERNAL FUNCTION PROTOTYPES
    46 
    46 
    47 // CONSTANTS
    47 // CONSTANTS
    48 
    48 
    49 const TInt KBufferSize = 1024;
    49 const TInt KBufferSize = 1024;
    50 _LIT8(KRiUrl, "Rights-Issuer");
    50 _LIT8(KRiUrl, "Rights-Issuer");
    88 
    88 
    89 // LOCAL FUNCTION PROTOTYPES
    89 // LOCAL FUNCTION PROTOTYPES
    90 
    90 
    91 /*
    91 /*
    92 LOCAL_C TInt CheckContentRightsL(
    92 LOCAL_C TInt CheckContentRightsL(
    93     const TDesC8& aContentURI, 
    93     const TDesC8& aContentURI,
    94     TUint32 aRightsSpec);
    94     TUint32 aRightsSpec);
    95 
    95 
    96 LOCAL_C TInt IsProtectedContentL(
    96 LOCAL_C TInt IsProtectedContentL(
    97     const TDesC8& aContent, 
    97     const TDesC8& aContent,
    98     TBool& aProtection);
    98     TBool& aProtection);
    99 
    99 
   100 LOCAL_C TInt GetNewHeaderBuffer(
   100 LOCAL_C TInt GetNewHeaderBuffer(
   101     HBufC8*& aOldHeaderBuf, 
   101     HBufC8*& aOldHeaderBuf,
   102     const TDesC8& aHeaderName, 
   102     const TDesC8& aHeaderName,
   103     const TDesC8& aHeaderValue, 
   103     const TDesC8& aHeaderValue,
   104     HBufC8*& aNewHeaderBuf
   104     HBufC8*& aNewHeaderBuf
   105     );
   105     );
   106 
   106 
   107 LOCAL_C TInt WriteNewFile(
   107 LOCAL_C TInt WriteNewFile(
   108     TFileName aFileName, 
   108     TFileName aFileName,
   109     HBufC8*& aHeaderBuf, 
   109     HBufC8*& aHeaderBuf,
   110     TUint32& aFirstPartLength, 
   110     TUint32& aFirstPartLength,
   111     TUint32& aDataLength, 
   111     TUint32& aDataLength,
   112     TUint32& aDataPartPos
   112     TUint32& aDataPartPos
   113     );
   113     );
   114 
   114 
   115 LOCAL_C TInt GetContentURIListL(
   115 LOCAL_C TInt GetContentURIListL(
   116     RPointerArray<HBufC8>*& aURIList);
   116     RPointerArray<HBufC8>*& aURIList);
   131     const TInt aIndex);
   131     const TInt aIndex);
   132 
   132 
   133 */
   133 */
   134 
   134 
   135 LOCAL_C void GetActiveRightsL(
   135 LOCAL_C void GetActiveRightsL(
   136     const TDesC8& aContentURI, 
   136     const TDesC8& aContentURI,
   137     TUint32 aRightsSpec, 
   137     TUint32 aRightsSpec,
   138     CDRMRights*& aRightsObject);
   138     CDRMRights*& aRightsObject);
   139 
   139 
   140 LOCAL_C TInt CheckFileRightsL(
   140 LOCAL_C TInt CheckFileRightsL(
   141     const TDesC& aFileName, 
   141     const TDesC& aFileName,
   142     TUint32 aRightsSpec);
   142     TUint32 aRightsSpec);
   143 
   143 
   144 LOCAL_C TInt CheckFileRightsL(
   144 LOCAL_C TInt CheckFileRightsL(
   145     RFile& aFileHandle, 
   145     RFile& aFileHandle,
   146     TUint32 aRightsSpec);
   146     TUint32 aRightsSpec);
   147 
   147 
   148 LOCAL_C TInt IsProtectedFileL(
   148 LOCAL_C TInt IsProtectedFileL(
   149     const TDesC& aFileName, 
   149     const TDesC& aFileName,
   150     TBool& aProtection);
   150     TBool& aProtection);
   151 
   151 
   152 LOCAL_C TInt IsProtectedFileL(
   152 LOCAL_C TInt IsProtectedFileL(
   153     RFile& aFileHandle, 
   153     RFile& aFileHandle,
   154     TBool& aProtection);
   154     TBool& aProtection);
   155 
   155 
   156 LOCAL_C TInt GetContentInfoL(
   156 LOCAL_C TInt GetContentInfoL(
   157     const TDesC8& aContent, 
   157     const TDesC8& aContent,
   158     DRMCommon::TContentProtection& aProtection, 
   158     DRMCommon::TContentProtection& aProtection,
   159     HBufC8*& aMIMEType, 
   159     HBufC8*& aMIMEType,
   160     HBufC8*& aContentURI, 
   160     HBufC8*& aContentURI,
   161     TUint& aDataLength);
   161     TUint& aDataLength);
   162 
   162 
   163 LOCAL_C TInt GetFileInfoL(
   163 LOCAL_C TInt GetFileInfoL(
   164     const TDesC& aFileName, 
   164     const TDesC& aFileName,
   165     DRMCommon::TContentProtection& aProtection, 
   165     DRMCommon::TContentProtection& aProtection,
   166     HBufC8*& aMIMEType, 
   166     HBufC8*& aMIMEType,
   167     HBufC8*& aContentURI, 
   167     HBufC8*& aContentURI,
   168     TUint& aDataLength);
   168     TUint& aDataLength);
   169 
   169 
   170 LOCAL_C TInt GetFileInfoL(
   170 LOCAL_C TInt GetFileInfoL(
   171     RFile& aFileHandle, 
   171     RFile& aFileHandle,
   172     DRMCommon::TContentProtection& aProtection, 
   172     DRMCommon::TContentProtection& aProtection,
   173     HBufC8*& aMIMEType, 
   173     HBufC8*& aMIMEType,
   174     HBufC8*& aContentURI, 
   174     HBufC8*& aContentURI,
   175     TUint& aDataLength);
   175     TUint& aDataLength);
   176 
   176 
   177 LOCAL_C void GetContentHeaderL(
   177 LOCAL_C void GetContentHeaderL(
   178     const TDesC8& aContent, 
   178     const TDesC8& aContent,
   179     const TDesC8& aHeaderName, 
   179     const TDesC8& aHeaderName,
   180     HBufC8*& aHeaderValue);
   180     HBufC8*& aHeaderValue);
   181 
   181 
   182 LOCAL_C void GetFileHeaderL(
   182 LOCAL_C void GetFileHeaderL(
   183     const TFileName& aFileName, 
   183     const TFileName& aFileName,
   184     const TDesC8& aHeaderName, 
   184     const TDesC8& aHeaderName,
   185     HBufC8*& aHeaderValue);
   185     HBufC8*& aHeaderValue);
   186 
   186 
   187 LOCAL_C void GetFileHeaderL(
   187 LOCAL_C void GetFileHeaderL(
   188     RFile& aFileHandle, 
   188     RFile& aFileHandle,
   189     const TDesC8& aHeaderName, 
   189     const TDesC8& aHeaderName,
   190     HBufC8*& aHeaderValue);
   190     HBufC8*& aHeaderValue);
   191 
   191 
   192 LOCAL_C void SetContentHeaderL(
   192 LOCAL_C void SetContentHeaderL(
   193     HBufC8*& aContent, 
   193     HBufC8*& aContent,
   194     const TDesC8& aHeaderName, 
   194     const TDesC8& aHeaderName,
   195     const TDesC8& aHeaderValue);
   195     const TDesC8& aHeaderValue);
   196 
   196 
   197 LOCAL_C void SetFileHeaderL(
   197 LOCAL_C void SetFileHeaderL(
   198     const TDesC16& aFileName, 
   198     const TDesC16& aFileName,
   199     const TDesC8& aHeaderName, 
   199     const TDesC8& aHeaderName,
   200     const TDesC8& aHeaderValue);
   200     const TDesC8& aHeaderValue);
   201 
   201 
   202 LOCAL_C void SetFileHeaderL(
   202 LOCAL_C void SetFileHeaderL(
   203     RFile& aFileHandle, 
   203     RFile& aFileHandle,
   204     const TDesC8& aHeaderName, 
   204     const TDesC8& aHeaderName,
   205     const TDesC8& aHeaderValue);
   205     const TDesC8& aHeaderValue);
   206 
   206 
   207 LOCAL_C void GetSingleRightsObjectL(
   207 LOCAL_C void GetSingleRightsObjectL(
   208     const TDesC8& aContentURI, 
   208     const TDesC8& aContentURI,
   209     TUint32 aLocalID, 
   209     TUint32 aLocalID,
   210     CDRMRights*& aRightsObject);
   210     CDRMRights*& aRightsObject);
   211 
   211 
   212 LOCAL_C void GetDetailedContentRightsL(
   212 LOCAL_C void GetDetailedContentRightsL(
   213     const TDesC8& aContentURI, 
   213     const TDesC8& aContentURI,
   214     RPointerArray<CDRMRights>*& aRightsList);
   214     RPointerArray<CDRMRights>*& aRightsList);
   215 
   215 
   216 LOCAL_C void GetDetailedFileRightsL(
   216 LOCAL_C void GetDetailedFileRightsL(
   217     const TDesC& aFileName, 
   217     const TDesC& aFileName,
   218     RPointerArray<CDRMRights>*& aRightsList);
   218     RPointerArray<CDRMRights>*& aRightsList);
   219 
   219 
   220 LOCAL_C void GetDetailedFileRightsL(
   220 LOCAL_C void GetDetailedFileRightsL(
   221     RFile& aFileHandle, 
   221     RFile& aFileHandle,
   222     RPointerArray<CDRMRights>*& aRightsList);
   222     RPointerArray<CDRMRights>*& aRightsList);
   223 
   223 
   224 LOCAL_C TInt RegisterDynamicDataTypeL(
   224 LOCAL_C TInt RegisterDynamicDataTypeL(
   225     const TDataType& aDataType);
   225     const TDataType& aDataType);
   226 
   226 
   228     const TInt aIndex);
   228     const TInt aIndex);
   229 
   229 
   230 LOCAL_C TInt CalculatePaddingL(
   230 LOCAL_C TInt CalculatePaddingL(
   231     COma1Dcf* dcf);
   231     COma1Dcf* dcf);
   232 
   232 
   233 LOCAL_C void DoResetAndDestroy( TAny* aPtr );  
   233 LOCAL_C void DoResetAndDestroy( TAny* aPtr );
   234 
   234 
   235 
   235 
   236 LOCAL_C TInt GetFileHandleRead(
   236 LOCAL_C TInt GetFileHandleRead(
   237     RFs& aFileServer, 
   237     RFs& aFileServer,
   238     RFile& aFile, 
   238     RFile& aFile,
   239     const TDesC& aFileName );
   239     const TDesC& aFileName );
   240 
   240 
   241 LOCAL_C void AddParents( 
   241 LOCAL_C void AddParents(
   242     DRMCommon* aDrmCommon, 
   242     DRMCommon* aDrmCommon,
   243     RPointerArray<CDRMRights>& aRights );
   243     RPointerArray<CDRMRights>& aRights );
   244 	
   244 
   245 // FORWARD DECLARATIONS
   245 // FORWARD DECLARATIONS
   246 
   246 
   247 using namespace ContentAccess;
   247 using namespace ContentAccess;
   248 
   248 
   249 // ============================= LOCAL FUNCTIONS ===============================
   249 // ============================= LOCAL FUNCTIONS ===============================
   256 LOCAL_C void DoResetAndDestroy( TAny* aPtr )
   256 LOCAL_C void DoResetAndDestroy( TAny* aPtr )
   257     {
   257     {
   258     ( reinterpret_cast< RPointerArray< CDRMPermission >* >( aPtr ) )->
   258     ( reinterpret_cast< RPointerArray< CDRMPermission >* >( aPtr ) )->
   259         ResetAndDestroy();
   259         ResetAndDestroy();
   260     }
   260     }
   261     
   261 
   262     
   262 
   263 // -----------------------------------------------------------------------------
   263 // -----------------------------------------------------------------------------
   264 // GetPermission
   264 // GetPermission
   265 // -----------------------------------------------------------------------------
   265 // -----------------------------------------------------------------------------
   266 LOCAL_C void GetPermission(
   266 LOCAL_C void GetPermission(
   267     RDRMRightsClient& aClient, 
   267     RDRMRightsClient& aClient,
   268     const TDesC8& aUri,
   268     const TDesC8& aUri,
   269     TIntent aIntent,
   269     TIntent aIntent,
   270     CDRMPermission*& aPermission )
   270     CDRMPermission*& aPermission )
   271     {
   271     {
   272     TInt r = KErrNone;
   272     TInt r = KErrNone;
   273     CDRMPermission* permission = NULL;
   273     CDRMPermission* permission = NULL;
   274     TUint32 reason = 0;
   274     TUint32 reason = 0;
   275     
   275 
   276     TRAP( r, permission = aClient.GetActiveRightsL( aIntent, aUri, reason ) );
   276     TRAP( r, permission = aClient.GetActiveRightsL( aIntent, aUri, reason ) );
   277     if ( permission != NULL )
   277     if ( permission != NULL )
   278         {
   278         {
   279         if ( aPermission == NULL )
   279         if ( aPermission == NULL )
   280             {
   280             {
   281             TRAP_IGNORE( aPermission = CDRMPermission::NewL() ); 
   281             TRAP_IGNORE( aPermission = CDRMPermission::NewL() );
   282             }
   282             }
   283         aPermission->Merge( *permission );
   283         aPermission->Merge( *permission );
   284         delete permission;
   284         delete permission;
   285         }
   285         }
   286     }
   286     }
   287     
   287 
   288 // -----------------------------------------------------------------------------
   288 // -----------------------------------------------------------------------------
   289 // GetActiveRightsL
   289 // GetActiveRightsL
   290 // Returns a possible active rights object. Adopts to broken callers who still
   290 // Returns a possible active rights object. Adopts to broken callers who still
   291 // use a bitmask for intent.
   291 // use a bitmask for intent.
   292 // -----------------------------------------------------------------------------
   292 // -----------------------------------------------------------------------------
   296     CDRMRights*& aRightsObject)
   296     CDRMRights*& aRightsObject)
   297     {
   297     {
   298     CDRMPermission* permission = NULL;
   298     CDRMPermission* permission = NULL;
   299     RDRMRightsClient client;
   299     RDRMRightsClient client;
   300     HBufC8* uri = NULL;
   300     HBufC8* uri = NULL;
   301         
   301 
   302     User::LeaveIfError( client.Connect() );
   302     User::LeaveIfError( client.Connect() );
   303     CleanupClosePushL( client );
   303     CleanupClosePushL( client );
   304 
   304 
   305     if ( aConstraints == 0 )
   305     if ( aConstraints == 0 )
   306         {
   306         {
   334         }
   334         }
   335     CleanupStack::PopAndDestroy(); // client
   335     CleanupStack::PopAndDestroy(); // client
   336     }
   336     }
   337 
   337 
   338 // -----------------------------------------------------------------------------
   338 // -----------------------------------------------------------------------------
   339 // 
   339 //
   340 //
   340 //
   341 // Parameters:
   341 // Parameters:
   342 //
   342 //
   343 // Returns:
   343 // Returns:
   344 // -----------------------------------------------------------------------------
   344 // -----------------------------------------------------------------------------
   345 LOCAL_C TInt IsProtectedFileL(
   345 LOCAL_C TInt IsProtectedFileL(
   346     const TDesC& aFileName, 
   346     const TDesC& aFileName,
   347     TBool& aProtection)
   347     TBool& aProtection)
   348     {
   348     {
   349     RFs fs;
   349     RFs fs;
   350     RFile file;
   350     RFile file;
   351     TInt r = KErrNone;
   351     TInt r = KErrNone;
   352     CDcfCommon* dcf = NULL;
   352     CDcfCommon* dcf = NULL;
   353 
   353 
   354     User::LeaveIfError(fs.Connect());
   354     User::LeaveIfError(fs.Connect());
   355     CleanupClosePushL(fs);
   355     CleanupClosePushL(fs);
   356     
   356 
   357     
   357 
   358     r = GetFileHandleRead( fs, file, aFileName );
   358     r = GetFileHandleRead( fs, file, aFileName );
   359     User::LeaveIfError(r);
   359     User::LeaveIfError(r);
   360     
   360 
   361     CleanupClosePushL(file);
   361     CleanupClosePushL(file);
   362     dcf = CDcfCommon::NewL(file);
   362     dcf = CDcfCommon::NewL(file);
   363     if (dcf != NULL)
   363     if (dcf != NULL)
   364         {
   364         {
   365         aProtection = ETrue;
   365         aProtection = ETrue;
   372     CleanupStack::PopAndDestroy(2); // file, fs
   372     CleanupStack::PopAndDestroy(2); // file, fs
   373     return r;
   373     return r;
   374     }
   374     }
   375 
   375 
   376 // -----------------------------------------------------------------------------
   376 // -----------------------------------------------------------------------------
   377 // 
   377 //
   378 //
   378 //
   379 // Parameters:
   379 // Parameters:
   380 //
   380 //
   381 // Returns:
   381 // Returns:
   382 // -----------------------------------------------------------------------------
   382 // -----------------------------------------------------------------------------
   383 LOCAL_C TInt IsProtectedFileL(
   383 LOCAL_C TInt IsProtectedFileL(
   384     RFile& aFileHandle, 
   384     RFile& aFileHandle,
   385     TBool& aProtection)
   385     TBool& aProtection)
   386     {
   386     {
   387     TInt r = KErrNone;
   387     TInt r = KErrNone;
   388     CDcfCommon* dcf = NULL;
   388     CDcfCommon* dcf = NULL;
   389 
   389 
   399         }
   399         }
   400     return r;
   400     return r;
   401     }
   401     }
   402 
   402 
   403 // -----------------------------------------------------------------------------
   403 // -----------------------------------------------------------------------------
   404 // 
   404 //
   405 //
   405 //
   406 // Parameters:
   406 // Parameters:
   407 //
   407 //
   408 // Returns:
   408 // Returns:
   409 // -----------------------------------------------------------------------------
   409 // -----------------------------------------------------------------------------
   410 TInt GetContentInfoL(
   410 TInt GetContentInfoL(
   411     const TDesC8& aContent, 
   411     const TDesC8& aContent,
   412     DRMCommon::TContentProtection& aProtection, 
   412     DRMCommon::TContentProtection& aProtection,
   413     HBufC8*& aMIMEType, 
   413     HBufC8*& aMIMEType,
   414     HBufC8*& aContentURI, 
   414     HBufC8*& aContentURI,
   415     TUint& aDataLength)
   415     TUint& aDataLength)
   416     {
   416     {
   417     TInt r = KErrNone;
   417     TInt r = KErrNone;
   418     COma1Dcf* dcf = NULL;
   418     COma1Dcf* dcf = NULL;
   419     TRAP(r, dcf = COma1Dcf::NewL(aContent));
   419     TRAP(r, dcf = COma1Dcf::NewL(aContent));
   420     if (dcf != NULL)
   420     if (dcf != NULL)
   421         {
   421         {
   422         CleanupStack::PushL( dcf );
   422         CleanupStack::PushL( dcf );
   423             
   423 
   424         if (dcf->iContentID->Left(4).Compare(KLDPrefix) == 0 ||
   424         if (dcf->iContentID->Left(4).Compare(KLDPrefix) == 0 ||
   425             dcf->iContentID->Left(4).Compare(KFLPrefix) == 0 ||
   425             dcf->iContentID->Left(4).Compare(KFLPrefix) == 0 ||
   426             dcf->iRightsIssuerURL == NULL)
   426             dcf->iRightsIssuerURL == NULL)
   427             {
   427             {
   428             aProtection = DRMCommon::EForwardLocked;
   428             aProtection = DRMCommon::EForwardLocked;
   464 
   464 
   465     return r;
   465     return r;
   466     }
   466     }
   467 
   467 
   468 // -----------------------------------------------------------------------------
   468 // -----------------------------------------------------------------------------
   469 // 
   469 //
   470 //
   470 //
   471 // Parameters:
   471 // Parameters:
   472 //
   472 //
   473 // Returns:
   473 // Returns:
   474 // -----------------------------------------------------------------------------
   474 // -----------------------------------------------------------------------------
   475 TInt GetFileInfoL(
   475 TInt GetFileInfoL(
   476     const TDesC& aFileName, 
   476     const TDesC& aFileName,
   477     DRMCommon::TContentProtection& aProtection, 
   477     DRMCommon::TContentProtection& aProtection,
   478     HBufC8*& aMIMEType, 
   478     HBufC8*& aMIMEType,
   479     HBufC8*& aContentURI, 
   479     HBufC8*& aContentURI,
   480     TUint& aDataLength)
   480     TUint& aDataLength)
   481     {
   481     {
   482     RFs fs;
   482     RFs fs;
   483     RFile file;
   483     RFile file;
   484     TInt r = KErrNone;
   484     TInt r = KErrNone;
   487     CData* data = NULL;
   487     CData* data = NULL;
   488 
   488 
   489     aProtection = DRMCommon::ENoDCFFile;
   489     aProtection = DRMCommon::ENoDCFFile;
   490     User::LeaveIfError(fs.Connect());
   490     User::LeaveIfError(fs.Connect());
   491     CleanupClosePushL(fs);
   491     CleanupClosePushL(fs);
   492     
   492 
   493     r = GetFileHandleRead( fs, file, aFileName );
   493     r = GetFileHandleRead( fs, file, aFileName );
   494     User::LeaveIfError(r);
   494     User::LeaveIfError(r);
   495     CleanupClosePushL(file);
   495     CleanupClosePushL(file);
   496     
   496 
   497     dcf = CDcfCommon::NewL(file);
   497     dcf = CDcfCommon::NewL(file);
   498     if (dcf != NULL)
   498     if (dcf != NULL)
   499         {
   499         {
   500         CleanupStack::PushL(dcf);
   500         CleanupStack::PushL(dcf);
   501         if (dcf->iVersion == EOma2Dcf)
   501         if (dcf->iVersion == EOma2Dcf)
   502             {
   502             {
   503             dcf2 = static_cast<COma2Dcf*>(dcf);
   503             dcf2 = static_cast<COma2Dcf*>(dcf);
   504             }
   504             }
   505             
   505 
   506         if (dcf->iContentID->Left(4).Compare(KLDPrefix) == 0 ||
   506         if (dcf->iContentID->Left(4).Compare(KLDPrefix) == 0 ||
   507             dcf->iContentID->Left(4).Compare(KFLPrefix) == 0 ||
   507             dcf->iContentID->Left(4).Compare(KFLPrefix) == 0 ||
   508             dcf->iRightsIssuerURL == NULL)
   508             dcf->iRightsIssuerURL == NULL)
   509             {
   509             {
   510             aProtection = DRMCommon::EForwardLocked;
   510             aProtection = DRMCommon::EForwardLocked;
   527             }
   527             }
   528         else
   528         else
   529             {
   529             {
   530             aMIMEType = NULL;
   530             aMIMEType = NULL;
   531             }
   531             }
   532         
   532 
   533         // Insert domain RO if it exists
   533         // Insert domain RO if it exists
   534         if (dcf2 != NULL && dcf2->iRightsObjects.Count() > 0)
   534         if (dcf2 != NULL && dcf2->iRightsObjects.Count() > 0)
   535             {
   535             {
   536             // Creating a CData object will insert the domain RO into the RDB
   536             // Creating a CData object will insert the domain RO into the RDB
   537             data = CData::NewL(file, KDefaultContentObject);
   537             data = CData::NewL(file, KDefaultContentObject);
   538             delete data;
   538             delete data;
   539             }
   539             }
   540             
   540 
   541         if (dcf->iVersion == EOma1Dcf && !dcf->iPlainTextLengthValid)
   541         if (dcf->iVersion == EOma1Dcf && !dcf->iPlainTextLengthValid)
   542             {
   542             {
   543             CalculatePaddingL(static_cast<COma1Dcf*>(dcf));
   543             CalculatePaddingL(static_cast<COma1Dcf*>(dcf));
   544             }
   544             }
   545 
   545 
   549     CleanupStack::PopAndDestroy(2); // file, fs
   549     CleanupStack::PopAndDestroy(2); // file, fs
   550     return r;
   550     return r;
   551     }
   551     }
   552 
   552 
   553 // -----------------------------------------------------------------------------
   553 // -----------------------------------------------------------------------------
   554 // 
   554 //
   555 //
   555 //
   556 // Parameters:
   556 // Parameters:
   557 //
   557 //
   558 // Returns:
   558 // Returns:
   559 // -----------------------------------------------------------------------------
   559 // -----------------------------------------------------------------------------
   560 TInt GetFileInfoL(
   560 TInt GetFileInfoL(
   561     RFile& aFileHandle, 
   561     RFile& aFileHandle,
   562     DRMCommon::TContentProtection& aProtection, 
   562     DRMCommon::TContentProtection& aProtection,
   563     HBufC8*& aMIMEType, 
   563     HBufC8*& aMIMEType,
   564     HBufC8*& aContentURI, 
   564     HBufC8*& aContentURI,
   565     TUint& aDataLength)
   565     TUint& aDataLength)
   566     {
   566     {
   567     TInt r = KErrNone;
   567     TInt r = KErrNone;
   568     CDcfCommon* dcf = NULL;
   568     CDcfCommon* dcf = NULL;
   569     COma2Dcf* dcf2 = NULL;
   569     COma2Dcf* dcf2 = NULL;
   570     CData* data = NULL;
   570     CData* data = NULL;
   571     TInt initialPos = 0;
   571     TInt initialPos = 0;
   572 
   572 
   573     // Store the initial filePos
   573     // Store the initial filePos
   574     User::LeaveIfError(aFileHandle.Seek(ESeekCurrent, initialPos)); 
   574     User::LeaveIfError(aFileHandle.Seek(ESeekCurrent, initialPos));
   575 
   575 
   576     aProtection = DRMCommon::ENoDCFFile;
   576     aProtection = DRMCommon::ENoDCFFile;
   577 
   577 
   578     dcf = CDcfCommon::NewL(aFileHandle);
   578     dcf = CDcfCommon::NewL(aFileHandle);
   579     if (dcf != NULL)
   579     if (dcf != NULL)
   616             {
   616             {
   617             // Creating a CData object will insert the domain RO into the RDB
   617             // Creating a CData object will insert the domain RO into the RDB
   618             data = CData::NewL(aFileHandle, KDefaultContentObject);
   618             data = CData::NewL(aFileHandle, KDefaultContentObject);
   619             delete data;
   619             delete data;
   620             }
   620             }
   621             
   621 
   622         if (dcf->iVersion == EOma1Dcf && !dcf->iPlainTextLengthValid)
   622         if (dcf->iVersion == EOma1Dcf && !dcf->iPlainTextLengthValid)
   623             {
   623             {
   624             CalculatePaddingL(static_cast<COma1Dcf*>(dcf));
   624             CalculatePaddingL(static_cast<COma1Dcf*>(dcf));
   625             }
   625             }
   626 
   626 
   631     User::LeaveIfError(aFileHandle.Seek(ESeekStart, initialPos));
   631     User::LeaveIfError(aFileHandle.Seek(ESeekStart, initialPos));
   632     return r;
   632     return r;
   633     }
   633     }
   634 
   634 
   635 // -----------------------------------------------------------------------------
   635 // -----------------------------------------------------------------------------
   636 // 
   636 //
   637 //
   637 //
   638 // Parameters:
   638 // Parameters:
   639 //
   639 //
   640 // Returns:
   640 // Returns:
   641 // -----------------------------------------------------------------------------
   641 // -----------------------------------------------------------------------------
   642 TInt CheckFileRightsL(
   642 TInt CheckFileRightsL(
   643     const TDesC& aFileName, 
   643     const TDesC& aFileName,
   644     TUint32 aRightsSpec)
   644     TUint32 aRightsSpec)
   645     {
   645     {
   646     RFs fs;
   646     RFs fs;
   647     RFile file;
   647     RFile file;
   648     CDcfCommon* dcf = NULL;
   648     CDcfCommon* dcf = NULL;
   649     TInt r = DRMCommon::ENoRights;
   649     TInt r = DRMCommon::ENoRights;
   650     RDRMRightsClient client;
   650     RDRMRightsClient client;
   651     TUint32 reason = 0;
   651     TUint32 reason = 0;
   652     
   652 
   653     User::LeaveIfError(fs.Connect());
   653     User::LeaveIfError(fs.Connect());
   654     CleanupClosePushL(fs);
   654     CleanupClosePushL(fs);
   655     
   655 
   656     r = GetFileHandleRead(fs, file, aFileName);
   656     r = GetFileHandleRead(fs, file, aFileName);
   657     User::LeaveIfError(r);
   657     User::LeaveIfError(r);
   658     CleanupClosePushL(file);
   658     CleanupClosePushL(file);
   659     
   659 
   660     dcf = CDcfCommon::NewL(file);
   660     dcf = CDcfCommon::NewL(file);
   661     if ( dcf == NULL )
   661     if ( dcf == NULL )
   662         {
   662         {
   663         User::Leave(KErrArgument);
   663         User::Leave(KErrArgument);
   664         }
   664         }
   669     CleanupStack::PopAndDestroy(4); // dcf, file, client, fs
   669     CleanupStack::PopAndDestroy(4); // dcf, file, client, fs
   670     return r;
   670     return r;
   671     }
   671     }
   672 
   672 
   673 // -----------------------------------------------------------------------------
   673 // -----------------------------------------------------------------------------
   674 // 
   674 //
   675 //
   675 //
   676 // Parameters:
   676 // Parameters:
   677 //
   677 //
   678 // Returns:
   678 // Returns:
   679 // -----------------------------------------------------------------------------
   679 // -----------------------------------------------------------------------------
   680 TInt CheckFileRightsL(
   680 TInt CheckFileRightsL(
   681     RFile& aFileHandle, 
   681     RFile& aFileHandle,
   682     TUint32 aRightsSpec)
   682     TUint32 aRightsSpec)
   683     {
   683     {
   684     CDcfCommon* dcf = NULL;
   684     CDcfCommon* dcf = NULL;
   685     TInt r = DRMCommon::ENoRights;
   685     TInt r = DRMCommon::ENoRights;
   686     RDRMRightsClient client;
   686     RDRMRightsClient client;
   687     TUint32 reason = 0;
   687     TUint32 reason = 0;
   688     
   688 
   689     dcf = CDcfCommon::NewL(aFileHandle);
   689     dcf = CDcfCommon::NewL(aFileHandle);
   690     if ( dcf == NULL )
   690     if ( dcf == NULL )
   691         {
   691         {
   692         User::Leave(KErrArgument);
   692         User::Leave(KErrArgument);
   693         }
   693         }
   698     CleanupStack::PopAndDestroy(2); // dcf, file
   698     CleanupStack::PopAndDestroy(2); // dcf, file
   699     return r;
   699     return r;
   700     }
   700     }
   701 
   701 
   702 // -----------------------------------------------------------------------------
   702 // -----------------------------------------------------------------------------
   703 // 
   703 //
   704 //
   704 //
   705 // Parameters:
   705 // Parameters:
   706 //
   706 //
   707 // Returns:
   707 // Returns:
   708 // -----------------------------------------------------------------------------
   708 // -----------------------------------------------------------------------------
   709 void GetSingleRightsObjectL(
   709 void GetSingleRightsObjectL(
   710     const TDesC8& aContentURI, 
   710     const TDesC8& aContentURI,
   711     TUint32 aLocalID, 
   711     TUint32 aLocalID,
   712     CDRMRights*& aRightsObject)
   712     CDRMRights*& aRightsObject)
   713     {
   713     {
   714     RDRMRightsClient client;
   714     RDRMRightsClient client;
   715     CDRMPermission* p = NULL;
   715     CDRMPermission* p = NULL;
   716     CDRMAsset* a = NULL;
   716     CDRMAsset* a = NULL;
   717     
   717 
   718     aRightsObject = NULL;
   718     aRightsObject = NULL;
   719     User::LeaveIfError(client.Connect());
   719     User::LeaveIfError(client.Connect());
   720     CleanupClosePushL(client);
   720     CleanupClosePushL(client);
   721     
   721 
   722     aRightsObject = CDRMRights::NewL(); 
   722     aRightsObject = CDRMRights::NewL();
   723     CleanupStack::PushL(aRightsObject);
   723     CleanupStack::PushL(aRightsObject);
   724     
   724 
   725     p = client.GetDbEntryL(aContentURI, aLocalID);
   725     p = client.GetDbEntryL(aContentURI, aLocalID);
   726     CleanupStack::PushL(p);
   726     CleanupStack::PushL(p);
   727     aRightsObject->SetPermissionL(*p);
   727     aRightsObject->SetPermissionL(*p);
   728     CleanupStack::PopAndDestroy(); // p
   728     CleanupStack::PopAndDestroy(); // p
   729 
   729 
   730     a = CDRMAsset::NewLC();
   730     a = CDRMAsset::NewLC();
   731     aRightsObject->SetAssetL(*a);
   731     aRightsObject->SetAssetL(*a);
   732     CleanupStack::PopAndDestroy();
   732     CleanupStack::PopAndDestroy();
   733     
   733 
   734     aRightsObject->SetContentURIAndLocalID(aContentURI.AllocL(), aLocalID);
   734     aRightsObject->SetContentURIAndLocalID(aContentURI.AllocL(), aLocalID);
   735     CleanupStack::Pop(); // aRightsObject
   735     CleanupStack::Pop(); // aRightsObject
   736     CleanupStack::PopAndDestroy(); // client
   736     CleanupStack::PopAndDestroy(); // client
   737     }
   737     }
   738 
   738 
   739 // -----------------------------------------------------------------------------
   739 // -----------------------------------------------------------------------------
   740 // 
   740 //
   741 //
   741 //
   742 // Parameters:
   742 // Parameters:
   743 //
   743 //
   744 // Returns:
   744 // Returns:
   745 // -----------------------------------------------------------------------------
   745 // -----------------------------------------------------------------------------
   746 void GetDetailedContentRightsL(
   746 void GetDetailedContentRightsL(
   747     const TDesC8& aContentURI, 
   747     const TDesC8& aContentURI,
   748     RPointerArray<CDRMRights>*& aRightsList)
   748     RPointerArray<CDRMRights>*& aRightsList)
   749     {
   749     {
   750     RDRMRightsClient client;
   750     RDRMRightsClient client;
   751     RPointerArray<CDRMPermission> rights;
   751     RPointerArray<CDRMPermission> rights;
   752     CDRMRights* ro = NULL;
   752     CDRMRights* ro = NULL;
   753     CDRMAsset* a  = NULL;
   753     CDRMAsset* a  = NULL;
   754     TInt i;
   754     TInt i;
   755     // Need a temporary pointer
   755     // Need a temporary pointer
   756     HBufC8* contentId = NULL;
   756     HBufC8* contentId = NULL;
   757     
   757 
   758     aRightsList = NULL;
   758     aRightsList = NULL;
   759     User::LeaveIfError(client.Connect());
   759     User::LeaveIfError(client.Connect());
   760     CleanupClosePushL(client);
   760     CleanupClosePushL(client);
   761 
   761 
   762     client.GetDBEntriesL(aContentURI, rights);
   762     client.GetDBEntriesL(aContentURI, rights);
   807     CleanupStack::Pop(2); // aRightsList ( two items )
   807     CleanupStack::Pop(2); // aRightsList ( two items )
   808     CleanupStack::PopAndDestroy(2); // rights, client
   808     CleanupStack::PopAndDestroy(2); // rights, client
   809     }
   809     }
   810 
   810 
   811 // -----------------------------------------------------------------------------
   811 // -----------------------------------------------------------------------------
   812 // 
   812 //
   813 //
   813 //
   814 // Parameters:
   814 // Parameters:
   815 //
   815 //
   816 // Returns:
   816 // Returns:
   817 // -----------------------------------------------------------------------------
   817 // -----------------------------------------------------------------------------
   818 void GetDetailedFileRightsL(
   818 void GetDetailedFileRightsL(
   819     const TDesC& aFileName, 
   819     const TDesC& aFileName,
   820     RPointerArray<CDRMRights>*& aRightsList)
   820     RPointerArray<CDRMRights>*& aRightsList)
   821     {
   821     {
   822     
   822 
   823     CDcfCommon* dcf = NULL;
   823     CDcfCommon* dcf = NULL;
   824     RFile file;
   824     RFile file;
   825     RFs fs;
   825     RFs fs;
   826     TInt r = KErrNone;
   826     TInt r = KErrNone;
   827     
   827 
   828     User::LeaveIfError(fs.Connect());
   828     User::LeaveIfError(fs.Connect());
   829     CleanupClosePushL(fs);
   829     CleanupClosePushL(fs);
   830 
   830 
   831     r = GetFileHandleRead( fs, file, aFileName );
   831     r = GetFileHandleRead( fs, file, aFileName );
   832     User::LeaveIfError(r);
   832     User::LeaveIfError(r);
   833     CleanupClosePushL(file);
   833     CleanupClosePushL(file);
   834     
   834 
   835     
   835 
   836     dcf = CDcfCommon::NewL(file);
   836     dcf = CDcfCommon::NewL(file);
   837     if (dcf == NULL)
   837     if (dcf == NULL)
   838         {
   838         {
   839         User::Leave(KErrArgument);
   839         User::Leave(KErrArgument);
   840         }
   840         }
   841     CleanupStack::PushL(dcf);
   841     CleanupStack::PushL(dcf);
   842     GetDetailedContentRightsL(*dcf->iContentID, aRightsList);
   842     GetDetailedContentRightsL(*dcf->iContentID, aRightsList);
   843     CleanupStack::PopAndDestroy(3); // dcf, file, client
   843     CleanupStack::PopAndDestroy(3); // dcf, file, client
   844    
   844 
   845     }
   845     }
   846 
   846 
   847 // -----------------------------------------------------------------------------
   847 // -----------------------------------------------------------------------------
   848 // 
   848 //
   849 //
   849 //
   850 // Parameters:
   850 // Parameters:
   851 //
   851 //
   852 // Returns:
   852 // Returns:
   853 // -----------------------------------------------------------------------------
   853 // -----------------------------------------------------------------------------
   854 void GetDetailedFileRightsL(
   854 void GetDetailedFileRightsL(
   855     RFile& aFileHandle, 
   855     RFile& aFileHandle,
   856     RPointerArray<CDRMRights>*& aRightsList)
   856     RPointerArray<CDRMRights>*& aRightsList)
   857     {
   857     {
   858     CDcfCommon* dcf = NULL;
   858     CDcfCommon* dcf = NULL;
   859     
   859 
   860     dcf = CDcfCommon::NewL(aFileHandle);
   860     dcf = CDcfCommon::NewL(aFileHandle);
   861     if (dcf == NULL)
   861     if (dcf == NULL)
   862         {
   862         {
   863         User::Leave(KErrArgument);
   863         User::Leave(KErrArgument);
   864         }
   864         }
   866     GetDetailedContentRightsL(*dcf->iContentID, aRightsList);
   866     GetDetailedContentRightsL(*dcf->iContentID, aRightsList);
   867     CleanupStack::PopAndDestroy(); // dcf
   867     CleanupStack::PopAndDestroy(); // dcf
   868     }
   868     }
   869 
   869 
   870 // -----------------------------------------------------------------------------
   870 // -----------------------------------------------------------------------------
   871 // 
   871 //
   872 //
   872 //
   873 // Parameters:
   873 // Parameters:
   874 //
   874 //
   875 // Returns:
   875 // Returns:
   876 // -----------------------------------------------------------------------------
   876 // -----------------------------------------------------------------------------
   877 LOCAL_C void  GetNewHeaderBufferL(
   877 LOCAL_C void  GetNewHeaderBufferL(
   878     HBufC8*& aOldHeaderBuf, 
   878     HBufC8*& aOldHeaderBuf,
   879     const TDesC8& aHeaderName, 
   879     const TDesC8& aHeaderName,
   880     const TDesC8& aHeaderValue, 
   880     const TDesC8& aHeaderValue,
   881     HBufC8*& aNewHeaderBuf
   881     HBufC8*& aNewHeaderBuf
   882     )
   882     )
   883     {
   883     {
   884     TInt oldHeaderValueLength = 0;
   884     TInt oldHeaderValueLength = 0;
   885     TInt offset = 0;
   885     TInt offset = 0;
   886     TPtr8 headerPtr(aOldHeaderBuf->Des());
   886     TPtr8 headerPtr(aOldHeaderBuf->Des());
   887     TPtr8 headerNamePtr(NULL, 0, 0);
   887     TPtr8 headerNamePtr(NULL, 0, 0);
   888     TPtr8 newHeaderPtr(NULL, 0, 0);
   888     TPtr8 newHeaderPtr(NULL, 0, 0);
   889     
   889 
   890     HBufC8* headerName = HBufC8::NewL(aHeaderName.Length() + 1);
   890     HBufC8* headerName = HBufC8::NewL(aHeaderName.Length() + 1);
   891     // Find the position of the text in the header
   891     // Find the position of the text in the header
   892     headerNamePtr.Set(headerName->Des());
   892     headerNamePtr.Set(headerName->Des());
   893     headerNamePtr.Copy(aHeaderName);
   893     headerNamePtr.Copy(aHeaderName);
   894     headerNamePtr.Append(KHeaderNameEnding);
   894     headerNamePtr.Append(KHeaderNameEnding);
   907             aHeaderValue.Length());
   907             aHeaderValue.Length());
   908         newHeaderPtr.Set(aNewHeaderBuf->Des());
   908         newHeaderPtr.Set(aNewHeaderBuf->Des());
   909         newHeaderPtr.Copy(headerPtr.Left(offset + aHeaderName.Length() + 1));
   909         newHeaderPtr.Copy(headerPtr.Left(offset + aHeaderName.Length() + 1));
   910         newHeaderPtr.Append(aHeaderValue);
   910         newHeaderPtr.Append(aHeaderValue);
   911         newHeaderPtr.Append(headerPtr.Right(headerPtr.Length() -
   911         newHeaderPtr.Append(headerPtr.Right(headerPtr.Length() -
   912             (offset + aHeaderName.Length() + 1 + oldHeaderValueLength)));                        
   912             (offset + aHeaderName.Length() + 1 + oldHeaderValueLength)));
   913         }
   913         }
   914     else
   914     else
   915         {
   915         {
   916         aNewHeaderBuf = HBufC8::NewL(headerPtr.Length() + aHeaderName.Length() +
   916         aNewHeaderBuf = HBufC8::NewL(headerPtr.Length() + aHeaderName.Length() +
   917             aHeaderValue.Length() + 3);
   917             aHeaderValue.Length() + 3);
   919         newHeaderPtr.Copy(headerPtr);
   919         newHeaderPtr.Copy(headerPtr);
   920         newHeaderPtr.Append(aHeaderName);
   920         newHeaderPtr.Append(aHeaderName);
   921         newHeaderPtr.Append(KHeaderNameEnding);
   921         newHeaderPtr.Append(KHeaderNameEnding);
   922         newHeaderPtr.Append(aHeaderValue);
   922         newHeaderPtr.Append(aHeaderValue);
   923         newHeaderPtr.Append(KHeaderEnding);
   923         newHeaderPtr.Append(KHeaderEnding);
   924         }        
   924         }
   925     }
   925     }
   926 
   926 
   927 // -----------------------------------------------------------------------------
   927 // -----------------------------------------------------------------------------
   928 // 
   928 //
   929 //
   929 //
   930 // Parameters:
   930 // Parameters:
   931 //
   931 //
   932 // Returns:
   932 // Returns:
   933 // -----------------------------------------------------------------------------
   933 // -----------------------------------------------------------------------------
   941     TPtrC tempFilePath;
   941     TPtrC tempFilePath;
   942     HBufC8* buffer = NULL;
   942     HBufC8* buffer = NULL;
   943     RFileWriteStream temp;
   943     RFileWriteStream temp;
   944     TPtr8 ptr(NULL, 0, 0);
   944     TPtr8 ptr(NULL, 0, 0);
   945     TInt offset = 0;
   945     TInt offset = 0;
   946     
   946 
   947     // Find the path of the file to be modified and put the tempfile
   947     // Find the path of the file to be modified and put the tempfile
   948     // into that directory
   948     // into that directory
   949     tempFilePath.Set(aOriginalFileName.Left(
   949     tempFilePath.Set(aOriginalFileName.Left(
   950         aOriginalFileName.LocateReverse('\\') + 1));
   950         aOriginalFileName.LocateReverse('\\') + 1));
   951     User::LeaveIfError(temp.Temp(aFs, tempFilePath, aTempFileName, EFileWrite));
   951     User::LeaveIfError(temp.Temp(aFs, tempFilePath, aTempFileName, EFileWrite));
   952     CleanupClosePushL( temp );
   952     CleanupClosePushL( temp );
   953     
   953 
   954     temp.WriteUint8L(1);
   954     temp.WriteUint8L(1);
   955     temp.WriteUint8L(aDcf.iMimeType->Length());
   955     temp.WriteUint8L(aDcf.iMimeType->Length());
   956     temp.WriteUint8L(aDcf.iContentID->Length());
   956     temp.WriteUint8L(aDcf.iContentID->Length());
   957     temp.WriteL(*aDcf.iMimeType);
   957     temp.WriteL(*aDcf.iMimeType);
   958     temp.WriteL(*aDcf.iContentID);
   958     temp.WriteL(*aDcf.iContentID);
   971     buffer = HBufC8::NewLC(KBufferSize);
   971     buffer = HBufC8::NewLC(KBufferSize);
   972     do
   972     do
   973         {
   973         {
   974         ptr.Set(buffer->Des());
   974         ptr.Set(buffer->Des());
   975         ptr.SetLength(0);
   975         ptr.SetLength(0);
   976         aOriginalFile.Read(ptr);         
   976         aOriginalFile.Read(ptr);
   977         if (ptr.Length() > 0)
   977         if (ptr.Length() > 0)
   978             {
   978             {
   979             temp.WriteL(ptr);
   979             temp.WriteL(ptr);
   980             }
   980             }
   981         }
   981         }
   982     while (ptr.Length() > 0);
   982     while (ptr.Length() > 0);
   983     temp.CommitL();           
   983     temp.CommitL();
   984     CleanupStack::PopAndDestroy(); // temp
   984     CleanupStack::PopAndDestroy(); // temp
   985     CleanupStack::PopAndDestroy(); //buffer
   985     CleanupStack::PopAndDestroy(); //buffer
   986     }
   986     }
   987 
   987 
   988 // -----------------------------------------------------------------------------
   988 // -----------------------------------------------------------------------------
   989 // 
   989 //
   990 //
   990 //
   991 // Parameters:
   991 // Parameters:
   992 //
   992 //
   993 // Returns:
   993 // Returns:
   994 // -----------------------------------------------------------------------------
   994 // -----------------------------------------------------------------------------
  1004     RFileWriteStream orig;
  1004     RFileWriteStream orig;
  1005     TFileName tempFile;
  1005     TFileName tempFile;
  1006     TPtr8 ptr(NULL, 0, 0);
  1006     TPtr8 ptr(NULL, 0, 0);
  1007     TInt offset = 0;
  1007     TInt offset = 0;
  1008     TInt fileSize = 0;
  1008     TInt fileSize = 0;
  1009     
  1009 
  1010     // Find the path of the file to be modified and put the tempfile
  1010     // Find the path of the file to be modified and put the tempfile
  1011     // into that directory
  1011     // into that directory
  1012     tempFilePath.Set(_L("C:\\"));
  1012     tempFilePath.Set(_L("C:\\"));
  1013     User::LeaveIfError( temp.Temp( aFs, tempFilePath, tempFile, 
  1013     User::LeaveIfError( temp.Temp( aFs, tempFilePath, tempFile,
  1014                         EFileWrite));
  1014                         EFileWrite));
  1015     CleanupClosePushL( temp );
  1015     CleanupClosePushL( temp );
  1016     
  1016 
  1017     temp.WriteUint8L(1);
  1017     temp.WriteUint8L(1);
  1018     temp.WriteUint8L(aDcf.iMimeType->Length());
  1018     temp.WriteUint8L(aDcf.iMimeType->Length());
  1019     temp.WriteUint8L(aDcf.iContentID->Length());
  1019     temp.WriteUint8L(aDcf.iContentID->Length());
  1020     temp.WriteL(*aDcf.iMimeType);
  1020     temp.WriteL(*aDcf.iMimeType);
  1021     temp.WriteL(*aDcf.iContentID);
  1021     temp.WriteL(*aDcf.iContentID);
  1034     buffer = HBufC8::NewLC(KBufferSize);
  1034     buffer = HBufC8::NewLC(KBufferSize);
  1035     do
  1035     do
  1036         {
  1036         {
  1037         ptr.Set(buffer->Des());
  1037         ptr.Set(buffer->Des());
  1038         ptr.SetLength(0);
  1038         ptr.SetLength(0);
  1039         aOriginalFile.Read(ptr);         
  1039         aOriginalFile.Read(ptr);
  1040         if (ptr.Length() > 0)
  1040         if (ptr.Length() > 0)
  1041             {
  1041             {
  1042             temp.WriteL(ptr);
  1042             temp.WriteL(ptr);
  1043             }
  1043             }
  1044         }
  1044         }
  1045     while (ptr.Length() > 0);
  1045     while (ptr.Length() > 0);
  1046     temp.CommitL();
  1046     temp.CommitL();
  1047     
  1047 
  1048     CleanupStack::PopAndDestroy(2); //buffer, temp
  1048     CleanupStack::PopAndDestroy(2); //buffer, temp
  1049     // Get the size of the temp file
  1049     // Get the size of the temp file
  1050 
  1050 
  1051 
  1051 
  1052     User::LeaveIfError( tempFileHandle.Open( aFs, tempFile, EFileRead ));
  1052     User::LeaveIfError( tempFileHandle.Open( aFs, tempFile, EFileRead ));
  1053     CleanupClosePushL( tempFileHandle );    
  1053     CleanupClosePushL( tempFileHandle );
  1054     tempFileHandle.Size( fileSize );               
  1054     tempFileHandle.Size( fileSize );
  1055     
  1055 
  1056     
  1056 
  1057     // Set the fileSize of the original file
  1057     // Set the fileSize of the original file
  1058     User::LeaveIfError( aOriginalFile.SetSize( fileSize ) );
  1058     User::LeaveIfError( aOriginalFile.SetSize( fileSize ) );
  1059     offset = 0;
  1059     offset = 0;
  1060     User::LeaveIfError( tempFileHandle.Seek( ESeekStart, offset ) );
  1060     User::LeaveIfError( tempFileHandle.Seek( ESeekStart, offset ) );
  1061     orig.Attach( aOriginalFile );
  1061     orig.Attach( aOriginalFile );
  1062     CleanupClosePushL( orig );
  1062     CleanupClosePushL( orig );
  1063      
  1063 
  1064     buffer = HBufC8::NewLC(KBufferSize);    
  1064     buffer = HBufC8::NewLC(KBufferSize);
  1065     // Copy the file over because we can't use other copy things:
  1065     // Copy the file over because we can't use other copy things:
  1066     do
  1066     do
  1067         {
  1067         {
  1068         ptr.Set(buffer->Des());
  1068         ptr.Set(buffer->Des());
  1069         ptr.SetLength(0);
  1069         ptr.SetLength(0);
  1070         tempFileHandle.Read(ptr);         
  1070         tempFileHandle.Read(ptr);
  1071         if (ptr.Length() > 0)
  1071         if (ptr.Length() > 0)
  1072             {
  1072             {
  1073             orig.WriteL(ptr);
  1073             orig.WriteL(ptr);
  1074             }
  1074             }
  1075         }
  1075         }
  1076     while (ptr.Length() > 0);
  1076     while (ptr.Length() > 0);
  1077     
  1077 
  1078     // Write the changes    
  1078     // Write the changes
  1079     orig.CommitL();
  1079     orig.CommitL();
  1080     
  1080 
  1081     // close the tempfile
  1081     // close the tempfile
  1082     CleanupStack::PopAndDestroy(3); // buffer, tempFileHandle, orig
  1082     CleanupStack::PopAndDestroy(3); // buffer, tempFileHandle, orig
  1083     
  1083 
  1084     // Delete the temp file
  1084     // Delete the temp file
  1085     User::LeaveIfError( aFs.Delete( tempFile ) );
  1085     User::LeaveIfError( aFs.Delete( tempFile ) );
  1086     }
  1086     }
  1087 
  1087 
  1088 // -----------------------------------------------------------------------------
  1088 // -----------------------------------------------------------------------------
  1089 // 
  1089 //
  1090 //
  1090 //
  1091 // Parameters:
  1091 // Parameters:
  1092 //
  1092 //
  1093 // Returns:
  1093 // Returns:
  1094 // -----------------------------------------------------------------------------
  1094 // -----------------------------------------------------------------------------
  1095 LOCAL_C void SetFileHeaderL(
  1095 LOCAL_C void SetFileHeaderL(
  1096     const TDesC16& aFileName, 
  1096     const TDesC16& aFileName,
  1097     const TDesC8& aHeaderName, 
  1097     const TDesC8& aHeaderName,
  1098     const TDesC8& aHeaderValue)
  1098     const TDesC8& aHeaderValue)
  1099     {
  1099     {
  1100     __UHEAP_MARK;
  1100     __UHEAP_MARK;
  1101     TFileName tempFileName;
  1101     TFileName tempFileName;
  1102     HBufC8* newHeaderBuf = NULL;
  1102     HBufC8* newHeaderBuf = NULL;
  1108     CleanupClosePushL(fs);
  1108     CleanupClosePushL(fs);
  1109     User::LeaveIfError( GetFileHandleRead( fs, file, aFileName ) );
  1109     User::LeaveIfError( GetFileHandleRead( fs, file, aFileName ) );
  1110 
  1110 
  1111     CleanupClosePushL(file);
  1111     CleanupClosePushL(file);
  1112     dcf = COma1Dcf::NewL(file);
  1112     dcf = COma1Dcf::NewL(file);
  1113     
  1113 
  1114     CleanupStack::PushL(dcf);
  1114     CleanupStack::PushL(dcf);
  1115     GetNewHeaderBufferL(dcf->iHeaders, aHeaderName, aHeaderValue, newHeaderBuf);
  1115     GetNewHeaderBufferL(dcf->iHeaders, aHeaderName, aHeaderValue, newHeaderBuf);
  1116     delete dcf->iHeaders;
  1116     delete dcf->iHeaders;
  1117     dcf->iHeaders = newHeaderBuf;
  1117     dcf->iHeaders = newHeaderBuf;
  1118     dcf->iHeaderLength = newHeaderBuf->Length();
  1118     dcf->iHeaderLength = newHeaderBuf->Length();
  1119     WriteNewFileL( fs, file, aFileName, *dcf, tempFileName );
  1119     WriteNewFileL( fs, file, aFileName, *dcf, tempFileName );
  1120     CleanupStack::PopAndDestroy(2); // file, dcf
  1120     CleanupStack::PopAndDestroy(2); // file, dcf
  1121     User::LeaveIfError( fs.Replace( tempFileName, aFileName ) );
  1121     User::LeaveIfError( fs.Replace( tempFileName, aFileName ) );
  1122     CleanupStack::PopAndDestroy(); // fs
  1122     CleanupStack::PopAndDestroy(); // fs
  1123     
  1123 
  1124     __UHEAP_MARKEND;
  1124     __UHEAP_MARKEND;
  1125     }
  1125     }
  1126 
  1126 
  1127 // -----------------------------------------------------------------------------
  1127 // -----------------------------------------------------------------------------
  1128 // 
  1128 //
  1129 //
  1129 //
  1130 // Parameters:
  1130 // Parameters:
  1131 //
  1131 //
  1132 // Returns:
  1132 // Returns:
  1133 // -----------------------------------------------------------------------------
  1133 // -----------------------------------------------------------------------------
  1134 LOCAL_C void SetFileHeaderL(
  1134 LOCAL_C void SetFileHeaderL(
  1135     RFile& aFileHandle, 
  1135     RFile& aFileHandle,
  1136     const TDesC8& aHeaderName, 
  1136     const TDesC8& aHeaderName,
  1137     const TDesC8& aHeaderValue)
  1137     const TDesC8& aHeaderValue)
  1138     {
  1138     {
  1139     HBufC8* newHeaderBuf = NULL;
  1139     HBufC8* newHeaderBuf = NULL;
  1140     COma1Dcf* dcf = NULL;
  1140     COma1Dcf* dcf = NULL;
  1141     RFs fs;
  1141     RFs fs;
  1142     
  1142 
  1143     User::LeaveIfError(fs.Connect());
  1143     User::LeaveIfError(fs.Connect());
  1144     CleanupClosePushL( fs );
  1144     CleanupClosePushL( fs );
  1145     
  1145 
  1146     dcf = COma1Dcf::NewL(aFileHandle);
  1146     dcf = COma1Dcf::NewL(aFileHandle);
  1147     if (dcf == NULL)
  1147     if (dcf == NULL)
  1148         {
  1148         {
  1149         User::Leave(KErrArgument);
  1149         User::Leave(KErrArgument);
  1150         }
  1150         }
  1156     WriteNewFileL(fs, aFileHandle, *dcf);
  1156     WriteNewFileL(fs, aFileHandle, *dcf);
  1157     CleanupStack::PopAndDestroy(2); // dcf, fs
  1157     CleanupStack::PopAndDestroy(2); // dcf, fs
  1158     }
  1158     }
  1159 
  1159 
  1160 // -----------------------------------------------------------------------------
  1160 // -----------------------------------------------------------------------------
  1161 // 
  1161 //
  1162 //
  1162 //
  1163 // Parameters:
  1163 // Parameters:
  1164 //
  1164 //
  1165 // Returns:
  1165 // Returns:
  1166 // -----------------------------------------------------------------------------
  1166 // -----------------------------------------------------------------------------
  1167 void SetContentHeaderL(
  1167 void SetContentHeaderL(
  1168     HBufC8*& aContent, 
  1168     HBufC8*& aContent,
  1169     const TDesC8& aHeaderName, 
  1169     const TDesC8& aHeaderName,
  1170     const TDesC8& aHeaderValue)
  1170     const TDesC8& aHeaderValue)
  1171     {
  1171     {
  1172     HBufC8* newHeaderBuf = NULL;
  1172     HBufC8* newHeaderBuf = NULL;
  1173     HBufC8* newContent = NULL;
  1173     HBufC8* newContent = NULL;
  1174     HBufC8* buffer;
  1174     HBufC8* buffer;
  1209     delete aContent;
  1209     delete aContent;
  1210     aContent = newContent;
  1210     aContent = newContent;
  1211     }
  1211     }
  1212 
  1212 
  1213 // -----------------------------------------------------------------------------
  1213 // -----------------------------------------------------------------------------
  1214 // 
  1214 //
  1215 //
  1215 //
  1216 // Parameters:
  1216 // Parameters:
  1217 //
  1217 //
  1218 // Returns:
  1218 // Returns:
  1219 // -----------------------------------------------------------------------------
  1219 // -----------------------------------------------------------------------------
  1220 void GetHeaderL(
  1220 void GetHeaderL(
  1221     const TDesC8& aContent, 
  1221     const TDesC8& aContent,
  1222     const TDesC8& aHeaderName, 
  1222     const TDesC8& aHeaderName,
  1223     HBufC8*& aHeaderValue)
  1223     HBufC8*& aHeaderValue)
  1224     {
  1224     {
  1225     
  1225 
  1226     TInt i;
  1226     TInt i;
  1227     TInt j;
  1227     TInt j;
  1228     TPtrC8 ptr( aContent );
  1228     TPtrC8 ptr( aContent );
  1229     
  1229 
  1230     // Add Room for CRLF and Semicolon:
  1230     // Add Room for CRLF and Semicolon:
  1231     HBufC8* buffer = HBufC8::NewMaxLC( aHeaderName.Length() + 3 );  
  1231     HBufC8* buffer = HBufC8::NewMaxLC( aHeaderName.Length() + 3 );
  1232     TPtr8 searchBuf( const_cast<TUint8*>(buffer->Ptr()), 0, buffer->Des().MaxSize() );  
  1232     TPtr8 searchBuf( const_cast<TUint8*>(buffer->Ptr()), 0, buffer->Des().MaxSize() );
  1233 
  1233 
  1234     searchBuf.Copy(aHeaderName);
  1234     searchBuf.Copy(aHeaderName);
  1235     searchBuf.Append(KHeaderNameEnding);
  1235     searchBuf.Append(KHeaderNameEnding);
  1236     
  1236 
  1237     // First see if the     
  1237     // First see if the
  1238     i = ptr.Find(searchBuf);
  1238     i = ptr.Find(searchBuf);
  1239     User::LeaveIfError( i );
  1239     User::LeaveIfError( i );
  1240         
  1240 
  1241     if( i > 0 )
  1241     if( i > 0 )
  1242         {
  1242         {
  1243         // if it's not the first one, use the search buffer:
  1243         // if it's not the first one, use the search buffer:
  1244         // Create the search buffer
  1244         // Create the search buffer
  1245         searchBuf.Copy(KHeaderEnding);
  1245         searchBuf.Copy(KHeaderEnding);
  1246         searchBuf.Append(aHeaderName);
  1246         searchBuf.Append(aHeaderName);
  1247         searchBuf.Append(KHeaderNameEnding);
  1247         searchBuf.Append(KHeaderNameEnding);
  1248     
  1248 
  1249         // First see if the     
  1249         // First see if the
  1250         i = ptr.Find(searchBuf);
  1250         i = ptr.Find(searchBuf);
  1251         User::LeaveIfError( i );      
  1251         User::LeaveIfError( i );
  1252         }
  1252         }
  1253     // Move search buffer    
  1253     // Move search buffer
  1254     i += searchBuf.Length();  
  1254     i += searchBuf.Length();
  1255     
  1255 
  1256     j = ptr.Mid(i).Find(KHeaderEnding);
  1256     j = ptr.Mid(i).Find(KHeaderEnding);
  1257     User::LeaveIfError( j );
  1257     User::LeaveIfError( j );
  1258             
  1258 
  1259     aHeaderValue = ptr.Mid(i, j).AllocL();  
  1259     aHeaderValue = ptr.Mid(i, j).AllocL();
  1260     CleanupStack::PopAndDestroy(); // buffer  
  1260     CleanupStack::PopAndDestroy(); // buffer
  1261     }
  1261     }
  1262 
  1262 
  1263 // -----------------------------------------------------------------------------
  1263 // -----------------------------------------------------------------------------
  1264 // 
  1264 //
  1265 //
  1265 //
  1266 // Parameters:
  1266 // Parameters:
  1267 //
  1267 //
  1268 // Returns:
  1268 // Returns:
  1269 // -----------------------------------------------------------------------------
  1269 // -----------------------------------------------------------------------------
  1270 void GetContentHeaderL(
  1270 void GetContentHeaderL(
  1271     const TDesC8& aContent, 
  1271     const TDesC8& aContent,
  1272     const TDesC8& aHeaderName, 
  1272     const TDesC8& aHeaderName,
  1273     HBufC8*& aHeaderValue)
  1273     HBufC8*& aHeaderValue)
  1274     {
  1274     {
  1275     COma1Dcf* dcf = NULL;
  1275     COma1Dcf* dcf = NULL;
  1276 
  1276 
  1277     dcf = COma1Dcf::NewL(aContent);
  1277     dcf = COma1Dcf::NewL(aContent);
  1278     CleanupStack::PushL(dcf);
  1278     CleanupStack::PushL(dcf);
  1279     GetHeaderL(*dcf->iHeaders, aHeaderName, aHeaderValue);
  1279     GetHeaderL(*dcf->iHeaders, aHeaderName, aHeaderValue);
  1280     CleanupStack::PopAndDestroy(); // dcf
  1280     CleanupStack::PopAndDestroy(); // dcf
  1281     }
  1281     }
  1282 // -----------------------------------------------------------------------------
  1282 // -----------------------------------------------------------------------------
  1283 // 
  1283 //
  1284 //
  1284 //
  1285 // Parameters:
  1285 // Parameters:
  1286 //
  1286 //
  1287 // Returns:
  1287 // Returns:
  1288 // -----------------------------------------------------------------------------
  1288 // -----------------------------------------------------------------------------
  1289 void GetFileHeaderL(
  1289 void GetFileHeaderL(
  1290     const TFileName& aFileName, 
  1290     const TFileName& aFileName,
  1291     const TDesC8& aHeaderName, 
  1291     const TDesC8& aHeaderName,
  1292     HBufC8*& aHeaderValue)
  1292     HBufC8*& aHeaderValue)
  1293     {
  1293     {
  1294     RFs fs;
  1294     RFs fs;
  1295     RFile file;
  1295     RFile file;
  1296 
  1296 
  1302     GetFileHeaderL(file, aHeaderName, aHeaderValue);
  1302     GetFileHeaderL(file, aHeaderName, aHeaderValue);
  1303     CleanupStack::PopAndDestroy(2); // fs, file
  1303     CleanupStack::PopAndDestroy(2); // fs, file
  1304     }
  1304     }
  1305 
  1305 
  1306 // -----------------------------------------------------------------------------
  1306 // -----------------------------------------------------------------------------
  1307 // 
  1307 //
  1308 //
  1308 //
  1309 // Parameters:
  1309 // Parameters:
  1310 //
  1310 //
  1311 // Returns:
  1311 // Returns:
  1312 // -----------------------------------------------------------------------------
  1312 // -----------------------------------------------------------------------------
  1313 void GetFileHeaderL(
  1313 void GetFileHeaderL(
  1314     RFile& aFileHandle, 
  1314     RFile& aFileHandle,
  1315     const TDesC8& aHeaderName, 
  1315     const TDesC8& aHeaderName,
  1316     HBufC8*& aHeaderValue)
  1316     HBufC8*& aHeaderValue)
  1317     {
  1317     {
  1318     CDcfCommon* dcf = NULL;
  1318     CDcfCommon* dcf = NULL;
  1319 
  1319 
  1320     aHeaderValue = NULL;
  1320     aHeaderValue = NULL;
  1353     TInt& aCount)
  1353     TInt& aCount)
  1354     {
  1354     {
  1355     TInt err = 0;
  1355     TInt err = 0;
  1356     TDataType type;
  1356     TDataType type;
  1357     RFs fs;
  1357     RFs fs;
  1358     RFileReadStream reader;    
  1358     RFileReadStream reader;
  1359     
  1359 
  1360     aCount = 0;
  1360     aCount = 0;
  1361     err = fs.Connect();
  1361     err = fs.Connect();
  1362     if (!err) 
  1362     if (!err)
  1363         {
  1363         {
  1364         
  1364 
  1365 #ifndef RD_MULTIPLE_DRIVE
  1365 #ifndef RD_MULTIPLE_DRIVE
  1366         
  1366 
  1367     err = reader.Open(fs, KDataTypesFile, EFileRead);
  1367     err = reader.Open(fs, KDataTypesFile, EFileRead);
  1368     
  1368 
  1369 #else //RD_MULTIPLE_DRIVE
  1369 #else //RD_MULTIPLE_DRIVE
  1370     
  1370 
  1371     TInt driveNumber( -1 );
  1371     TInt driveNumber( -1 );
  1372     TChar driveLetter;
  1372     TChar driveLetter;
  1373     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1373     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1374     fs.DriveToChar( driveNumber, driveLetter );
  1374     fs.DriveToChar( driveNumber, driveLetter );
  1375     
  1375 
  1376     TFileName dataTypesFile;
  1376     TFileName dataTypesFile;
  1377 	dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1377     dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1378           
  1378 
  1379     err = reader.Open(fs, dataTypesFile, EFileRead);
  1379     err = reader.Open(fs, dataTypesFile, EFileRead);
  1380     
  1380 
  1381 #endif
  1381 #endif
  1382         
  1382 
  1383         if (err == KErrNotFound)
  1383         if (err == KErrNotFound)
  1384             {
  1384             {
  1385             err = DRMCommon::EOk;
  1385             err = DRMCommon::EOk;
  1386             }
  1386             }
  1387         else
  1387         else
  1389             while (err == KErrNone)
  1389             while (err == KErrNone)
  1390                 {
  1390                 {
  1391                 TRAP(err, (reader >> type));
  1391                 TRAP(err, (reader >> type));
  1392                 if (err == KErrNone) aCount++;
  1392                 if (err == KErrNone) aCount++;
  1393                 }
  1393                 }
  1394             
  1394 
  1395             if (err == KErrEof)
  1395             if (err == KErrEof)
  1396                 {
  1396                 {
  1397                 err = DRMCommon::EOk;
  1397                 err = DRMCommon::EOk;
  1398                 }
  1398                 }
  1399             
  1399 
  1400             reader.Release();
  1400             reader.Release();
  1401             reader.Close();
  1401             reader.Close();
  1402             }
  1402             }
  1403         }
  1403         }
  1404     
  1404 
  1405     fs.Close();
  1405     fs.Close();
  1406     
  1406 
  1407     return err;
  1407     return err;
  1408     }
  1408     }
  1409 
  1409 
  1410 // -----------------------------------------------------------------------------
  1410 // -----------------------------------------------------------------------------
  1411 // SupportedDynamicDataType: Returns a registered dynamic datatype
  1411 // SupportedDynamicDataType: Returns a registered dynamic datatype
  1417 // Returns:
  1417 // Returns:
  1418 //      DRMCommon::EOk: Data type returned successfully
  1418 //      DRMCommon::EOk: Data type returned successfully
  1419 //      KErrEof: Data type not found
  1419 //      KErrEof: Data type not found
  1420 // -----------------------------------------------------------------------------
  1420 // -----------------------------------------------------------------------------
  1421 LOCAL_C TInt SupportedDynamicDataType(
  1421 LOCAL_C TInt SupportedDynamicDataType(
  1422     const TInt aIndex, 
  1422     const TInt aIndex,
  1423     TDataType& aDataType)
  1423     TDataType& aDataType)
  1424     {
  1424     {
  1425     TInt err = KErrNone;
  1425     TInt err = KErrNone;
  1426     TInt i;
  1426     TInt i;
  1427     RFs fs;
  1427     RFs fs;
  1428     TDataType type;
  1428     TDataType type;
  1429     RFileReadStream reader;
  1429     RFileReadStream reader;
  1430     
  1430 
  1431     err = fs.Connect();
  1431     err = fs.Connect();
  1432     if (!err) 
  1432     if (!err)
  1433         {
  1433         {
  1434         
  1434 
  1435 #ifndef RD_MULTIPLE_DRIVE
  1435 #ifndef RD_MULTIPLE_DRIVE
  1436         
  1436 
  1437         err = reader.Open(fs, KDataTypesFile, EFileRead);
  1437         err = reader.Open(fs, KDataTypesFile, EFileRead);
  1438     
  1438 
  1439 #else //RD_MULTIPLE_DRIVE
  1439 #else //RD_MULTIPLE_DRIVE
  1440     
  1440 
  1441         TInt driveNumber( -1 );
  1441         TInt driveNumber( -1 );
  1442         TChar driveLetter;
  1442         TChar driveLetter;
  1443         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1443         DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1444     	fs.DriveToChar( driveNumber, driveLetter );
  1444         fs.DriveToChar( driveNumber, driveLetter );
  1445         
  1445 
  1446     	TFileName dataTypesFile;
  1446         TFileName dataTypesFile;
  1447 	    dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1447         dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1448         
  1448 
  1449         err = reader.Open(fs, dataTypesFile, EFileRead);
  1449         err = reader.Open(fs, dataTypesFile, EFileRead);
  1450     
  1450 
  1451 #endif
  1451 #endif
  1452         
  1452 
  1453         if (!err) 
  1453         if (!err)
  1454             {
  1454             {
  1455             i = -1;
  1455             i = -1;
  1456             while (err == 0 && i != aIndex) 
  1456             while (err == 0 && i != aIndex)
  1457                 {
  1457                 {
  1458                 TRAP(err, (reader >> type));
  1458                 TRAP(err, (reader >> type));
  1459                 i++;
  1459                 i++;
  1460                 }
  1460                 }
  1461             
  1461 
  1462             if (!err)
  1462             if (!err)
  1463                 {
  1463                 {
  1464                 aDataType = type;  
  1464                 aDataType = type;
  1465                 }
  1465                 }
  1466             
  1466 
  1467             reader.Release();
  1467             reader.Release();
  1468             reader.Close();
  1468             reader.Close();
  1469             }
  1469             }
  1470         }
  1470         }
  1471     
  1471 
  1472     fs.Close();
  1472     fs.Close();
  1473     
  1473 
  1474     return err;
  1474     return err;
  1475     }
  1475     }
  1476 
  1476 
  1477 // -----------------------------------------------------------------------------
  1477 // -----------------------------------------------------------------------------
  1478 // SupportedStaticDataType: Returns a static DRM datatype
  1478 // SupportedStaticDataType: Returns a static DRM datatype
  1484 // Returns:
  1484 // Returns:
  1485 //      DRMCommon::EOk: Data type returned successfully
  1485 //      DRMCommon::EOk: Data type returned successfully
  1486 //      KErrEof: Data type not found
  1486 //      KErrEof: Data type not found
  1487 // -----------------------------------------------------------------------------
  1487 // -----------------------------------------------------------------------------
  1488 LOCAL_C TInt SupportedStaticDataType(
  1488 LOCAL_C TInt SupportedStaticDataType(
  1489     const TInt aIndex, 
  1489     const TInt aIndex,
  1490     TDataType& aDataType)
  1490     TDataType& aDataType)
  1491     {
  1491     {
  1492     TInt err = 0;
  1492     TInt err = 0;
  1493     TInt index = 0;
  1493     TInt index = 0;
  1494     TInt length = 0;
  1494     TInt length = 0;
  1495     TInt i = 0;
  1495     TInt i = 0;
  1496     RFs fs;
  1496     RFs fs;
  1497     RResourceFile resourceFile;
  1497     RResourceFile resourceFile;
  1498     HBufC8* res = NULL;
  1498     HBufC8* res = NULL;
  1499     TResourceReader theReader;
  1499     TResourceReader theReader;
  1500     
  1500 
  1501     err = fs.Connect();
  1501     err = fs.Connect();
  1502     if (err)
  1502     if (err)
  1503         {
  1503         {
  1504         fs.Close();
  1504         fs.Close();
  1505         return err;
  1505         return err;
  1506         }
  1506         }
  1507     
  1507 
  1508 #ifndef RD_MULTIPLE_DRIVE
  1508 #ifndef RD_MULTIPLE_DRIVE
  1509     
  1509 
  1510     TRAP(err, resourceFile.OpenL(fs, KResourceFile));
  1510     TRAP(err, resourceFile.OpenL(fs, KResourceFile));
  1511     
  1511 
  1512 #else //RD_MULTIPLE_DRIVE
  1512 #else //RD_MULTIPLE_DRIVE
  1513     
  1513 
  1514     TInt driveNumber( -1 );
  1514     TInt driveNumber( -1 );
  1515     TChar driveLetter;
  1515     TChar driveLetter;
  1516     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
  1516     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
  1517     fs.DriveToChar( driveNumber, driveLetter );
  1517     fs.DriveToChar( driveNumber, driveLetter );
  1518     
  1518 
  1519     TFileName resFile;
  1519     TFileName resFile;
  1520 	resFile.Format( KResourceFile, (TUint)driveLetter );
  1520     resFile.Format( KResourceFile, (TUint)driveLetter );
  1521     
  1521 
  1522     TRAP(err, resourceFile.OpenL(fs, resFile));
  1522     TRAP(err, resourceFile.OpenL(fs, resFile));
  1523     
  1523 
  1524 #endif
  1524 #endif
  1525     if (err)
  1525     if (err)
  1526         {
  1526         {
  1527         fs.Close();
  1527         fs.Close();
  1528         return err;
  1528         return err;
  1529         }
  1529         }
  1530     
  1530 
  1531     TRAP(err, (res = resourceFile.AllocReadL(DATATYPE))); 
  1531     TRAP(err, (res = resourceFile.AllocReadL(DATATYPE)));
  1532     if (err)
  1532     if (err)
  1533         {
  1533         {
  1534         resourceFile.Close();
  1534         resourceFile.Close();
  1535         fs.Close();
  1535         fs.Close();
  1536         return err;
  1536         return err;
  1537         }
  1537         }
  1538     
  1538 
  1539     theReader.SetBuffer(res);
  1539     theReader.SetBuffer(res);
  1540     index = aIndex + 1;
  1540     index = aIndex + 1;
  1541     TPtrC temp16(theReader.ReadTPtrC(index, res));
  1541     TPtrC temp16(theReader.ReadTPtrC(index, res));
  1542     length = temp16.Length();
  1542     length = temp16.Length();
  1543     HBufC8* temp = NULL;
  1543     HBufC8* temp = NULL;
  1544     temp = HBufC8::NewMax(length); 
  1544     temp = HBufC8::NewMax(length);
  1545     if (temp)
  1545     if (temp)
  1546         {
  1546         {
  1547         TPtr8 ptr(temp->Des());
  1547         TPtr8 ptr(temp->Des());
  1548         ptr.SetLength(length);
  1548         ptr.SetLength(length);
  1549         for (i = 0; i < length; i++)
  1549         for (i = 0; i < length; i++)
  1554         }
  1554         }
  1555     else
  1555     else
  1556         {
  1556         {
  1557         err = KErrNoMemory;
  1557         err = KErrNoMemory;
  1558         }
  1558         }
  1559     
  1559 
  1560     if (temp) 
  1560     if (temp)
  1561         {
  1561         {
  1562         delete temp;
  1562         delete temp;
  1563         }
  1563         }
  1564     
  1564 
  1565     temp = NULL;
  1565     temp = NULL;
  1566     resourceFile.Close();
  1566     resourceFile.Close();
  1567     if (res) 
  1567     if (res)
  1568         {
  1568         {
  1569         delete res;
  1569         delete res;
  1570         }
  1570         }
  1571     
  1571 
  1572     res = NULL;
  1572     res = NULL;
  1573     fs.Close();
  1573     fs.Close();
  1574     return err;
  1574     return err;
  1575     }
  1575     }
  1576 
  1576 
  1591     TInt i;
  1591     TInt i;
  1592     TDataType type;
  1592     TDataType type;
  1593     RFileWriteStream writer;
  1593     RFileWriteStream writer;
  1594     RFileReadStream reader;
  1594     RFileReadStream reader;
  1595     RFs fs;
  1595     RFs fs;
  1596     
  1596 
  1597     User::LeaveIfError(fs.Connect());
  1597     User::LeaveIfError(fs.Connect());
  1598     CleanupClosePushL(fs);
  1598     CleanupClosePushL(fs);
  1599     
  1599 
  1600     // Open the data types file
  1600     // Open the data types file
  1601     
  1601 
  1602 #ifndef RD_MULTIPLE_DRIVE
  1602 #ifndef RD_MULTIPLE_DRIVE
  1603 
  1603 
  1604     User::LeaveIfError(reader.Open(fs, KDataTypesFile, EFileRead));
  1604     User::LeaveIfError(reader.Open(fs, KDataTypesFile, EFileRead));
  1605     
  1605 
  1606 #else //RD_MULTIPLE_DRIVE
  1606 #else //RD_MULTIPLE_DRIVE
  1607     
  1607 
  1608     TInt driveNumber( -1 );
  1608     TInt driveNumber( -1 );
  1609     TChar driveLetter;
  1609     TChar driveLetter;
  1610     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1610     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1611     fs.DriveToChar( driveNumber, driveLetter );
  1611     fs.DriveToChar( driveNumber, driveLetter );
  1612     
  1612 
  1613     TFileName dataTypesFile;
  1613     TFileName dataTypesFile;
  1614 	dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1614     dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1615     
  1615 
  1616     User::LeaveIfError(reader.Open(fs, dataTypesFile, EFileRead));
  1616     User::LeaveIfError(reader.Open(fs, dataTypesFile, EFileRead));
  1617     
  1617 
  1618 #endif
  1618 #endif
  1619     
  1619 
  1620     CleanupReleasePushL(reader);
  1620     CleanupReleasePushL(reader);
  1621     
  1621 
  1622     // Create and open a replacement file
  1622     // Create and open a replacement file
  1623     
  1623 
  1624 #ifndef RD_MULTIPLE_DRIVE
  1624 #ifndef RD_MULTIPLE_DRIVE
  1625     
  1625 
  1626     User::LeaveIfError(writer.Replace(fs, KTempFile, EFileWrite));
  1626     User::LeaveIfError(writer.Replace(fs, KTempFile, EFileWrite));
  1627     
  1627 
  1628 #else //RD_MULTIPLE_DRIVE
  1628 #else //RD_MULTIPLE_DRIVE
  1629     
  1629 
  1630     TFileName tempFile;
  1630     TFileName tempFile;
  1631     tempFile.Format( KTempFile, (TUint)driveLetter );
  1631     tempFile.Format( KTempFile, (TUint)driveLetter );
  1632     
  1632 
  1633     User::LeaveIfError(writer.Replace(fs, tempFile, EFileWrite));
  1633     User::LeaveIfError(writer.Replace(fs, tempFile, EFileWrite));
  1634     
  1634 
  1635 #endif
  1635 #endif
  1636     
  1636 
  1637     CleanupReleasePushL(writer);
  1637     CleanupReleasePushL(writer);
  1638     
  1638 
  1639     // Write all dynamic types into the replacement file, excluding the
  1639     // Write all dynamic types into the replacement file, excluding the
  1640     // data type to be removed
  1640     // data type to be removed
  1641     
  1641 
  1642     r = KErrNone;
  1642     r = KErrNone;
  1643     for (i = 0; r == KErrNone; i++)
  1643     for (i = 0; r == KErrNone; i++)
  1644         {
  1644         {
  1645         TRAP(r, reader >> type);
  1645         TRAP(r, reader >> type);
  1646         if (r == KErrNone && i != aIndex)
  1646         if (r == KErrNone && i != aIndex)
  1649             writer.CommitL();
  1649             writer.CommitL();
  1650             }
  1650             }
  1651         }
  1651         }
  1652     CleanupStack::PopAndDestroy();
  1652     CleanupStack::PopAndDestroy();
  1653     CleanupStack::PopAndDestroy();
  1653     CleanupStack::PopAndDestroy();
  1654     
  1654 
  1655     // Replace the data type file with the replacement file
  1655     // Replace the data type file with the replacement file
  1656     
  1656 
  1657 #ifndef RD_MULTIPLE_DRIVE
  1657 #ifndef RD_MULTIPLE_DRIVE
  1658 
  1658 
  1659     fs.Replace(KTempFile, KDataTypesFile);
  1659     fs.Replace(KTempFile, KDataTypesFile);
  1660     
  1660 
  1661 #else //RD_MULTIPLE_DRIVE
  1661 #else //RD_MULTIPLE_DRIVE
  1662     
  1662 
  1663     fs.Replace(tempFile, dataTypesFile);
  1663     fs.Replace(tempFile, dataTypesFile);
  1664     
  1664 
  1665 #endif
  1665 #endif
  1666     
  1666 
  1667     
  1667 
  1668     CleanupStack::PopAndDestroy();
  1668     CleanupStack::PopAndDestroy();
  1669     
  1669 
  1670     return DRMCommon::EOk;
  1670     return DRMCommon::EOk;
  1671     }
  1671     }
  1672 
  1672 
  1673 // -----------------------------------------------------------------------------
  1673 // -----------------------------------------------------------------------------
  1674 // RegisterDynamicDataTypeL: Register a new dynamically addable data type
  1674 // RegisterDynamicDataTypeL: Register a new dynamically addable data type
  1684     TInt err = KErrNone;
  1684     TInt err = KErrNone;
  1685     TDataType type;
  1685     TDataType type;
  1686     RFileWriteStream writer;
  1686     RFileWriteStream writer;
  1687     RFileReadStream reader;
  1687     RFileReadStream reader;
  1688     RFs fs;
  1688     RFs fs;
  1689     
  1689 
  1690     User::LeaveIfError(fs.Connect());
  1690     User::LeaveIfError(fs.Connect());
  1691     CleanupClosePushL(fs);
  1691     CleanupClosePushL(fs);
  1692     
  1692 
  1693     // Create and open a replacement file
  1693     // Create and open a replacement file
  1694     
  1694 
  1695 #ifndef RD_MULTIPLE_DRIVE
  1695 #ifndef RD_MULTIPLE_DRIVE
  1696     
  1696 
  1697     User::LeaveIfError(writer.Replace(fs, KTempFile, EFileWrite));
  1697     User::LeaveIfError(writer.Replace(fs, KTempFile, EFileWrite));
  1698     
  1698 
  1699 #else //RD_MULTIPLE_DRIVE
  1699 #else //RD_MULTIPLE_DRIVE
  1700     
  1700 
  1701     TInt driveNumber( -1 );
  1701     TInt driveNumber( -1 );
  1702     TChar driveLetter;
  1702     TChar driveLetter;
  1703     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1703     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultSystem, driveNumber );
  1704     fs.DriveToChar( driveNumber, driveLetter );
  1704     fs.DriveToChar( driveNumber, driveLetter );
  1705     
  1705 
  1706     TFileName tempFile;
  1706     TFileName tempFile;
  1707 	tempFile.Format( KTempFile, (TUint)driveLetter );
  1707     tempFile.Format( KTempFile, (TUint)driveLetter );
  1708     
  1708 
  1709     User::LeaveIfError(writer.Replace(fs, tempFile, EFileWrite));
  1709     User::LeaveIfError(writer.Replace(fs, tempFile, EFileWrite));
  1710     
  1710 
  1711 #endif
  1711 #endif
  1712     
  1712 
  1713     CleanupReleasePushL(writer);
  1713     CleanupReleasePushL(writer);
  1714     
  1714 
  1715     // Write the new data type into the replacement file
  1715     // Write the new data type into the replacement file
  1716     
  1716 
  1717     writer << aDataType;
  1717     writer << aDataType;
  1718     writer.CommitL();
  1718     writer.CommitL();
  1719     
  1719 
  1720     // Write all other dynamic types into the replacement file
  1720     // Write all other dynamic types into the replacement file
  1721     
  1721 
  1722 #ifndef RD_MULTIPLE_DRIVE
  1722 #ifndef RD_MULTIPLE_DRIVE
  1723     
  1723 
  1724     err = reader.Open(fs, KDataTypesFile, EFileRead);
  1724     err = reader.Open(fs, KDataTypesFile, EFileRead);
  1725     
  1725 
  1726 #else //RD_MULTIPLE_DRIVE
  1726 #else //RD_MULTIPLE_DRIVE
  1727     
  1727 
  1728     TFileName dataTypesFile;
  1728     TFileName dataTypesFile;
  1729     dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1729     dataTypesFile.Format( KDataTypesFile, (TUint)driveLetter );
  1730     
  1730 
  1731     err = reader.Open(fs, dataTypesFile, EFileRead);
  1731     err = reader.Open(fs, dataTypesFile, EFileRead);
  1732     
  1732 
  1733 #endif
  1733 #endif
  1734     
  1734 
  1735     if (err == KErrNone)
  1735     if (err == KErrNone)
  1736         {
  1736         {
  1737         CleanupReleasePushL(reader);
  1737         CleanupReleasePushL(reader);
  1738         while (err == KErrNone)
  1738         while (err == KErrNone)
  1739             {
  1739             {
  1740             TRAP(err, (reader >> type, writer << type, writer.CommitL()));
  1740             TRAP(err, (reader >> type, writer << type, writer.CommitL()));
  1741             }
  1741             }
  1742         CleanupStack::PopAndDestroy();
  1742         CleanupStack::PopAndDestroy();
  1743         }
  1743         }
  1744     
  1744 
  1745     CleanupStack::PopAndDestroy();
  1745     CleanupStack::PopAndDestroy();
  1746     
  1746 
  1747     // Replace the data type file with the replacement file
  1747     // Replace the data type file with the replacement file
  1748     
  1748 
  1749 #ifndef RD_MULTIPLE_DRIVE
  1749 #ifndef RD_MULTIPLE_DRIVE
  1750     
  1750 
  1751     fs.Replace(KTempFile, KDataTypesFile);
  1751     fs.Replace(KTempFile, KDataTypesFile);
  1752     
  1752 
  1753 #else //RD_MULTIPLE_DRIVE
  1753 #else //RD_MULTIPLE_DRIVE
  1754     
  1754 
  1755     fs.Replace(tempFile, dataTypesFile);
  1755     fs.Replace(tempFile, dataTypesFile);
  1756     
  1756 
  1757 #endif
  1757 #endif
  1758     
  1758 
  1759     CleanupStack::PopAndDestroy();
  1759     CleanupStack::PopAndDestroy();
  1760     
  1760 
  1761     return DRMCommon::EOk;
  1761     return DRMCommon::EOk;
  1762     }
  1762     }
  1763 
  1763 
  1764 TInt CalculatePaddingL(COma1Dcf* dcf)
  1764 TInt CalculatePaddingL(COma1Dcf* dcf)
  1765     {
  1765     {
  1801         CleanupStack::PopAndDestroy(); // rdb
  1801         CleanupStack::PopAndDestroy(); // rdb
  1802         }
  1802         }
  1803 
  1803 
  1804     return dcf->iPadding;
  1804     return dcf->iPadding;
  1805     }
  1805     }
  1806     
  1806 
  1807 // ============================ MEMBER FUNCTIONS ===============================
  1807 // ============================ MEMBER FUNCTIONS ===============================
  1808 
  1808 
  1809 // -----------------------------------------------------------------------------
  1809 // -----------------------------------------------------------------------------
  1810 // DRMCommon::DRMCommon
  1810 // DRMCommon::DRMCommon
  1811 // C++ default constructor can NOT contain any code, that
  1811 // C++ default constructor can NOT contain any code, that
  1812 // might leave.
  1812 // might leave.
  1813 // -----------------------------------------------------------------------------
  1813 // -----------------------------------------------------------------------------
  1814 EXPORT_C DRMCommon::DRMCommon(void)
  1814 EXPORT_C DRMCommon::DRMCommon(void)
  1815     {
  1815     {
  1816     } 
  1816     }
  1817 
  1817 
  1818 // -----------------------------------------------------------------------------
  1818 // -----------------------------------------------------------------------------
  1819 // DRMCommon::ConstructL
  1819 // DRMCommon::ConstructL
  1820 // Symbian 2nd phase constructor can leave.
  1820 // Symbian 2nd phase constructor can leave.
  1821 // -----------------------------------------------------------------------------
  1821 // -----------------------------------------------------------------------------
  1822 EXPORT_C void DRMCommon::ConstructL()
  1822 EXPORT_C void DRMCommon::ConstructL()
  1823     {
  1823     {
  1824     } 
  1824     }
  1825 
  1825 
  1826 // -----------------------------------------------------------------------------
  1826 // -----------------------------------------------------------------------------
  1827 // DRMCommon::NewL
  1827 // DRMCommon::NewL
  1828 // Two-phased constructor.
  1828 // Two-phased constructor.
  1829 // -----------------------------------------------------------------------------
  1829 // -----------------------------------------------------------------------------
  1845 // -----------------------------------------------------------------------------
  1845 // -----------------------------------------------------------------------------
  1846 // DRMCommon::CheckContentRights
  1846 // DRMCommon::CheckContentRights
  1847 // Checks if the give rights for a specific content URI are available.
  1847 // Checks if the give rights for a specific content URI are available.
  1848 // -----------------------------------------------------------------------------
  1848 // -----------------------------------------------------------------------------
  1849 EXPORT_C TInt DRMCommon::CheckContentRights(
  1849 EXPORT_C TInt DRMCommon::CheckContentRights(
  1850     const TDesC8& aContentID, 
  1850     const TDesC8& aContentID,
  1851     TUint32 aRightsSpec)
  1851     TUint32 aRightsSpec)
  1852     {
  1852     {
  1853     TInt r = ENoRights;
  1853     TInt r = ENoRights;
  1854     RDRMRightsClient client;
  1854     RDRMRightsClient client;
  1855     TUint32 reason = 0;
  1855     TUint32 reason = 0;
  1856     
  1856 
  1857     if (client.Connect() == KErrNone)
  1857     if (client.Connect() == KErrNone)
  1858         {
  1858         {
  1859         r = client.CheckRights(aRightsSpec, aContentID, reason);
  1859         r = client.CheckRights(aRightsSpec, aContentID, reason);
  1860         client.Close();
  1860         client.Close();
  1861         }
  1861         }
  1866 // DRMCommon::CheckFileRights
  1866 // DRMCommon::CheckFileRights
  1867 // Checks if the give rights for a specific content URI are available by
  1867 // Checks if the give rights for a specific content URI are available by
  1868 // opening a given file and reading the content URI from there.
  1868 // opening a given file and reading the content URI from there.
  1869 // -----------------------------------------------------------------------------
  1869 // -----------------------------------------------------------------------------
  1870 EXPORT_C TInt DRMCommon::CheckFileRights(
  1870 EXPORT_C TInt DRMCommon::CheckFileRights(
  1871     const TDesC& aFileName, 
  1871     const TDesC& aFileName,
  1872     TUint32 aRightsSpec)
  1872     TUint32 aRightsSpec)
  1873     {
  1873     {
  1874     TInt r = KErrNone;
  1874     TInt r = KErrNone;
  1875     TInt retValue = KErrNone;
  1875     TInt retValue = KErrNone;
  1876     TRAP(r, retValue = CheckFileRightsL(aFileName, aRightsSpec));
  1876     TRAP(r, retValue = CheckFileRightsL(aFileName, aRightsSpec));
  1885 // DRMCommon::CheckFileRights
  1885 // DRMCommon::CheckFileRights
  1886 // Checks if the give rights for a specific content URI are available by
  1886 // Checks if the give rights for a specific content URI are available by
  1887 // opening a given file and reading the content URI from there.
  1887 // opening a given file and reading the content URI from there.
  1888 // -----------------------------------------------------------------------------
  1888 // -----------------------------------------------------------------------------
  1889 EXPORT_C TInt DRMCommon::CheckFileRights(
  1889 EXPORT_C TInt DRMCommon::CheckFileRights(
  1890     RFile& aFileHandle, 
  1890     RFile& aFileHandle,
  1891     TUint32 aRightsSpec)
  1891     TUint32 aRightsSpec)
  1892     {
  1892     {
  1893     TInt r = KErrNone;
  1893     TInt r = KErrNone;
  1894     TInt retValue = KErrNone;
  1894     TInt retValue = KErrNone;
  1895     TRAP(r, retValue = CheckFileRightsL(aFileHandle, aRightsSpec));
  1895     TRAP(r, retValue = CheckFileRightsL(aFileHandle, aRightsSpec));
  1904 // DRMCommon::IsProtectedContent
  1904 // DRMCommon::IsProtectedContent
  1905 // Check if a memory buffer contains DRM proteced content by looking for a
  1905 // Check if a memory buffer contains DRM proteced content by looking for a
  1906 // predefined header string.
  1906 // predefined header string.
  1907 // -----------------------------------------------------------------------------
  1907 // -----------------------------------------------------------------------------
  1908 EXPORT_C TInt DRMCommon::IsProtectedContent(
  1908 EXPORT_C TInt DRMCommon::IsProtectedContent(
  1909     const TDesC8& aContent, 
  1909     const TDesC8& aContent,
  1910     TBool& aProtection)
  1910     TBool& aProtection)
  1911     {
  1911     {
  1912     if (COma1Dcf::IsValidDcf(aContent) || COma2Dcf::IsValidDcf(aContent))
  1912     if (COma1Dcf::IsValidDcf(aContent) || COma2Dcf::IsValidDcf(aContent))
  1913         {
  1913         {
  1914         aProtection = ETrue;
  1914         aProtection = ETrue;
  1924 // DRMCommon::IsProtectedFile
  1924 // DRMCommon::IsProtectedFile
  1925 // Check if a file contains DRM proteced content by looking for a
  1925 // Check if a file contains DRM proteced content by looking for a
  1926 // predefined header string.
  1926 // predefined header string.
  1927 // -----------------------------------------------------------------------------
  1927 // -----------------------------------------------------------------------------
  1928 EXPORT_C TInt DRMCommon::IsProtectedFile(
  1928 EXPORT_C TInt DRMCommon::IsProtectedFile(
  1929     const TDesC& aFileName, 
  1929     const TDesC& aFileName,
  1930     TBool& aProtection)
  1930     TBool& aProtection)
  1931     {
  1931     {
  1932     TInt r = KErrNone;
  1932     TInt r = KErrNone;
  1933     TRAP(r, IsProtectedFileL(aFileName, aProtection));
  1933     TRAP(r, IsProtectedFileL(aFileName, aProtection));
  1934     return r;
  1934     return r;
  1938 // DRMCommon::IsProtectedFile
  1938 // DRMCommon::IsProtectedFile
  1939 // Check if a file contains DRM proteced content by looking for a
  1939 // Check if a file contains DRM proteced content by looking for a
  1940 // predefined header string.
  1940 // predefined header string.
  1941 // -----------------------------------------------------------------------------
  1941 // -----------------------------------------------------------------------------
  1942 EXPORT_C TInt DRMCommon::IsProtectedFile(
  1942 EXPORT_C TInt DRMCommon::IsProtectedFile(
  1943     RFile& aFileHandle, 
  1943     RFile& aFileHandle,
  1944     TBool& aProtection)
  1944     TBool& aProtection)
  1945     {
  1945     {
  1946     TInt r = KErrNone;
  1946     TInt r = KErrNone;
  1947     TRAP(r, IsProtectedFileL(aFileHandle, aProtection));
  1947     TRAP(r, IsProtectedFileL(aFileHandle, aProtection));
  1948     return r;
  1948     return r;
  1949     }
  1949     }
  1950     
  1950 
  1951 // -----------------------------------------------------------------------------
  1951 // -----------------------------------------------------------------------------
  1952 // DRMCommon::GetContentInfo
  1952 // DRMCommon::GetContentInfo
  1953 // Returns DRM information about a memory buffer.
  1953 // Returns DRM information about a memory buffer.
  1954 // -----------------------------------------------------------------------------
  1954 // -----------------------------------------------------------------------------
  1955 EXPORT_C TInt DRMCommon::GetContentInfo(
  1955 EXPORT_C TInt DRMCommon::GetContentInfo(
  1956     const TDesC8& aContent, 
  1956     const TDesC8& aContent,
  1957     TContentProtection& aProtection, 
  1957     TContentProtection& aProtection,
  1958     HBufC8*& aMIMEType, 
  1958     HBufC8*& aMIMEType,
  1959     HBufC8*& aContentURI, 
  1959     HBufC8*& aContentURI,
  1960     TUint& aDataLength)
  1960     TUint& aDataLength)
  1961     {
  1961     {
  1962     TInt r = KErrNone;
  1962     TInt r = KErrNone;
  1963     TRAP(r, GetContentInfoL(aContent, aProtection, aMIMEType, aContentURI, 
  1963     TRAP(r, GetContentInfoL(aContent, aProtection, aMIMEType, aContentURI,
  1964         aDataLength));
  1964         aDataLength));
  1965     return r;
  1965     return r;
  1966     }
  1966     }
  1967 
  1967 
  1968 // -----------------------------------------------------------------------------
  1968 // -----------------------------------------------------------------------------
  1969 // DRMCommon::GetFileInfo
  1969 // DRMCommon::GetFileInfo
  1970 // Returns DRM information about a file.
  1970 // Returns DRM information about a file.
  1971 // -----------------------------------------------------------------------------
  1971 // -----------------------------------------------------------------------------
  1972 EXPORT_C TInt DRMCommon::GetFileInfo(
  1972 EXPORT_C TInt DRMCommon::GetFileInfo(
  1973     const TDesC& aFileName, 
  1973     const TDesC& aFileName,
  1974     TContentProtection& aProtection, 
  1974     TContentProtection& aProtection,
  1975     HBufC8*& aMIMEType, 
  1975     HBufC8*& aMIMEType,
  1976     HBufC8*& aContentURI, 
  1976     HBufC8*& aContentURI,
  1977     TUint& aDataLength)
  1977     TUint& aDataLength)
  1978     {
  1978     {
  1979     TInt r = KErrNone;
  1979     TInt r = KErrNone;
  1980     TRAP(r, GetFileInfoL(aFileName, aProtection, aMIMEType, aContentURI, 
  1980     TRAP(r, GetFileInfoL(aFileName, aProtection, aMIMEType, aContentURI,
  1981         aDataLength));
  1981         aDataLength));
  1982     return r;
  1982     return r;
  1983     }
  1983     }
  1984 
  1984 
  1985 // -----------------------------------------------------------------------------
  1985 // -----------------------------------------------------------------------------
  1986 // DRMCommon::GetFileInfo
  1986 // DRMCommon::GetFileInfo
  1987 // Returns DRM information about a file.
  1987 // Returns DRM information about a file.
  1988 // -----------------------------------------------------------------------------
  1988 // -----------------------------------------------------------------------------
  1989 EXPORT_C TInt DRMCommon::GetFileInfo(
  1989 EXPORT_C TInt DRMCommon::GetFileInfo(
  1990     RFile& aFileHandle, 
  1990     RFile& aFileHandle,
  1991     TContentProtection& aProtection, 
  1991     TContentProtection& aProtection,
  1992     HBufC8*& aMIMEType, 
  1992     HBufC8*& aMIMEType,
  1993     HBufC8*& aContentURI, 
  1993     HBufC8*& aContentURI,
  1994     TUint& aDataLength)
  1994     TUint& aDataLength)
  1995     {
  1995     {
  1996     TInt r = KErrNone;
  1996     TInt r = KErrNone;
  1997     TRAP(r, GetFileInfoL(aFileHandle, aProtection, aMIMEType, aContentURI, 
  1997     TRAP(r, GetFileInfoL(aFileHandle, aProtection, aMIMEType, aContentURI,
  1998         aDataLength));
  1998         aDataLength));
  1999     return r;
  1999     return r;
  2000     }
  2000     }
  2001 
  2001 
  2002 // -----------------------------------------------------------------------------
  2002 // -----------------------------------------------------------------------------
  2003 // DRMCommon::GetContentHeader
  2003 // DRMCommon::GetContentHeader
  2004 // Returns an optional header from a memory buffer containing encrypted content.
  2004 // Returns an optional header from a memory buffer containing encrypted content.
  2005 // -----------------------------------------------------------------------------
  2005 // -----------------------------------------------------------------------------
  2006 EXPORT_C TInt DRMCommon::GetContentHeader(
  2006 EXPORT_C TInt DRMCommon::GetContentHeader(
  2007     const TDesC8& aContent, 
  2007     const TDesC8& aContent,
  2008     const TDesC8& aHeaderName, 
  2008     const TDesC8& aHeaderName,
  2009     HBufC8*& aHeaderValue)
  2009     HBufC8*& aHeaderValue)
  2010     {
  2010     {
  2011     TInt r = KErrNone;
  2011     TInt r = KErrNone;
  2012 
  2012 
  2013     TRAP(r, GetContentHeaderL(aContent, aHeaderName, aHeaderValue));
  2013     TRAP(r, GetContentHeaderL(aContent, aHeaderName, aHeaderValue));
  2017 // -----------------------------------------------------------------------------
  2017 // -----------------------------------------------------------------------------
  2018 // DRMCommon::GetFileHeader
  2018 // DRMCommon::GetFileHeader
  2019 // Returns an optional header from a file containing encrypted content.
  2019 // Returns an optional header from a file containing encrypted content.
  2020 // -----------------------------------------------------------------------------
  2020 // -----------------------------------------------------------------------------
  2021 EXPORT_C TInt DRMCommon::GetFileHeader(
  2021 EXPORT_C TInt DRMCommon::GetFileHeader(
  2022     const TFileName& aFileName, 
  2022     const TFileName& aFileName,
  2023     const TDesC8& aHeaderName, 
  2023     const TDesC8& aHeaderName,
  2024     HBufC8*& aHeaderValue)
  2024     HBufC8*& aHeaderValue)
  2025     {
  2025     {
  2026     TInt r = KErrNone;
  2026     TInt r = KErrNone;
  2027 
  2027 
  2028     TRAP(r, GetFileHeaderL(aFileName, aHeaderName, aHeaderValue));
  2028     TRAP(r, GetFileHeaderL(aFileName, aHeaderName, aHeaderValue));
  2032 // -----------------------------------------------------------------------------
  2032 // -----------------------------------------------------------------------------
  2033 // DRMCommon::GetFileHeader
  2033 // DRMCommon::GetFileHeader
  2034 // Returns an optional header from a file containing encrypted content.
  2034 // Returns an optional header from a file containing encrypted content.
  2035 // -----------------------------------------------------------------------------
  2035 // -----------------------------------------------------------------------------
  2036 EXPORT_C TInt DRMCommon::GetFileHeader(
  2036 EXPORT_C TInt DRMCommon::GetFileHeader(
  2037     RFile& aFileHandle, 
  2037     RFile& aFileHandle,
  2038     const TDesC8& aHeaderName, 
  2038     const TDesC8& aHeaderName,
  2039     HBufC8*& aHeaderValue)
  2039     HBufC8*& aHeaderValue)
  2040     {
  2040     {
  2041     TInt r = KErrNone;
  2041     TInt r = KErrNone;
  2042 
  2042 
  2043     TRAP(r, GetFileHeaderL(aFileHandle, aHeaderName, aHeaderValue));
  2043     TRAP(r, GetFileHeaderL(aFileHandle, aHeaderName, aHeaderValue));
  2047 // -----------------------------------------------------------------------------
  2047 // -----------------------------------------------------------------------------
  2048 // DRMAuthenticated::SetContentHeader
  2048 // DRMAuthenticated::SetContentHeader
  2049 // Sets the specified optional header field of a DCF buffer.
  2049 // Sets the specified optional header field of a DCF buffer.
  2050 // -----------------------------------------------------------------------------
  2050 // -----------------------------------------------------------------------------
  2051 EXPORT_C TInt DRMCommon::SetContentHeader(
  2051 EXPORT_C TInt DRMCommon::SetContentHeader(
  2052     HBufC8*& aContent, 
  2052     HBufC8*& aContent,
  2053     const TDesC8& aHeaderName, 
  2053     const TDesC8& aHeaderName,
  2054     const TDesC8& aHeaderValue)
  2054     const TDesC8& aHeaderValue)
  2055     {
  2055     {
  2056     TInt r = KErrNone;
  2056     TInt r = KErrNone;
  2057 
  2057 
  2058     TRAP(r, SetContentHeaderL(aContent, aHeaderName, aHeaderValue));
  2058     TRAP(r, SetContentHeaderL(aContent, aHeaderName, aHeaderValue));
  2062 // -----------------------------------------------------------------------------
  2062 // -----------------------------------------------------------------------------
  2063 // DRMCommon::SetContentHeader
  2063 // DRMCommon::SetContentHeader
  2064 // Sets the specified optional header field of a DCF buffer.
  2064 // Sets the specified optional header field of a DCF buffer.
  2065 // -----------------------------------------------------------------------------
  2065 // -----------------------------------------------------------------------------
  2066 EXPORT_C TInt DRMCommon::SetFileHeader(
  2066 EXPORT_C TInt DRMCommon::SetFileHeader(
  2067     const TDesC16& aFileName, 
  2067     const TDesC16& aFileName,
  2068     const TDesC8& aHeaderName, 
  2068     const TDesC8& aHeaderName,
  2069     const TDesC8& aHeaderValue)
  2069     const TDesC8& aHeaderValue)
  2070     {
  2070     {
  2071     TInt r = KErrNone;
  2071     TInt r = KErrNone;
  2072 
  2072 
  2073     TRAP(r, SetFileHeaderL(aFileName, aHeaderName, aHeaderValue));
  2073     TRAP(r, SetFileHeaderL(aFileName, aHeaderName, aHeaderValue));
  2077 // -----------------------------------------------------------------------------
  2077 // -----------------------------------------------------------------------------
  2078 // DRMCommon::SetContentHeader
  2078 // DRMCommon::SetContentHeader
  2079 // Sets the specified optional header field of a DCF buffer.
  2079 // Sets the specified optional header field of a DCF buffer.
  2080 // -----------------------------------------------------------------------------
  2080 // -----------------------------------------------------------------------------
  2081 EXPORT_C TInt DRMCommon::SetFileHeader(
  2081 EXPORT_C TInt DRMCommon::SetFileHeader(
  2082     RFile& aFileHandle, 
  2082     RFile& aFileHandle,
  2083     const TDesC8& aHeaderName, 
  2083     const TDesC8& aHeaderName,
  2084     const TDesC8& aHeaderValue)
  2084     const TDesC8& aHeaderValue)
  2085     {
  2085     {
  2086     TInt r = KErrNone;
  2086     TInt r = KErrNone;
  2087 
  2087 
  2088     TRAP(r, SetFileHeaderL(aFileHandle, aHeaderName, aHeaderValue));
  2088     TRAP(r, SetFileHeaderL(aFileHandle, aHeaderName, aHeaderValue));
  2092 // -----------------------------------------------------------------------------
  2092 // -----------------------------------------------------------------------------
  2093 // DRMCommon::GetSingleRightsObject
  2093 // DRMCommon::GetSingleRightsObject
  2094 // Looks up the rights object using the content URI and the local ID.
  2094 // Looks up the rights object using the content URI and the local ID.
  2095 // -----------------------------------------------------------------------------
  2095 // -----------------------------------------------------------------------------
  2096 EXPORT_C TInt DRMCommon::GetSingleRightsObject(
  2096 EXPORT_C TInt DRMCommon::GetSingleRightsObject(
  2097     const TDesC8& aContentURI, 
  2097     const TDesC8& aContentURI,
  2098     TUint32 aLocalID, 
  2098     TUint32 aLocalID,
  2099     CDRMRights*& aRightsObject)
  2099     CDRMRights*& aRightsObject)
  2100     {
  2100     {
  2101     TInt r = KErrNone;
  2101     TInt r = KErrNone;
  2102     TRAP(r, GetSingleRightsObjectL(aContentURI, aLocalID, aRightsObject));
  2102     TRAP(r, GetSingleRightsObjectL(aContentURI, aLocalID, aRightsObject));
  2103     return r;
  2103     return r;
  2106 // -----------------------------------------------------------------------------
  2106 // -----------------------------------------------------------------------------
  2107 // DRMCommon::GetDetailedContentRights
  2107 // DRMCommon::GetDetailedContentRights
  2108 // Returns all rights objects for a content URI
  2108 // Returns all rights objects for a content URI
  2109 // -----------------------------------------------------------------------------
  2109 // -----------------------------------------------------------------------------
  2110 EXPORT_C TInt DRMCommon::GetDetailedContentRights(
  2110 EXPORT_C TInt DRMCommon::GetDetailedContentRights(
  2111     const TDesC8& aContentURI, 
  2111     const TDesC8& aContentURI,
  2112     RPointerArray<CDRMRights>*& aRightsList)
  2112     RPointerArray<CDRMRights>*& aRightsList)
  2113     {
  2113     {
  2114     TInt r = KErrNone;
  2114     TInt r = KErrNone;
  2115 
  2115 
  2116     TRAP(r, GetDetailedContentRightsL(aContentURI, aRightsList));
  2116     TRAP(r, GetDetailedContentRightsL(aContentURI, aRightsList));
  2124 // -----------------------------------------------------------------------------
  2124 // -----------------------------------------------------------------------------
  2125 // DRMCommon::GetDetailedFileRights
  2125 // DRMCommon::GetDetailedFileRights
  2126 // Returns all rights objects for a content URI from a given file
  2126 // Returns all rights objects for a content URI from a given file
  2127 // -----------------------------------------------------------------------------
  2127 // -----------------------------------------------------------------------------
  2128 EXPORT_C TInt DRMCommon::GetDetailedFileRights(
  2128 EXPORT_C TInt DRMCommon::GetDetailedFileRights(
  2129     const TDesC& aFileName, 
  2129     const TDesC& aFileName,
  2130     RPointerArray<CDRMRights>*& aRightsList)
  2130     RPointerArray<CDRMRights>*& aRightsList)
  2131     {
  2131     {
  2132     TInt r = KErrNone;
  2132     TInt r = KErrNone;
  2133 
  2133 
  2134     TRAP(r, GetDetailedFileRightsL(aFileName, aRightsList));
  2134     TRAP(r, GetDetailedFileRightsL(aFileName, aRightsList));
  2136         {
  2136         {
  2137         AddParents( const_cast<DRMCommon*>(this), *aRightsList );
  2137         AddParents( const_cast<DRMCommon*>(this), *aRightsList );
  2138         }
  2138         }
  2139     return r;
  2139     return r;
  2140     }
  2140     }
  2141     
  2141 
  2142 // -----------------------------------------------------------------------------
  2142 // -----------------------------------------------------------------------------
  2143 // DRMCommon::GetDetailedFileRights
  2143 // DRMCommon::GetDetailedFileRights
  2144 // Returns all rights objects for a content URI from a given file
  2144 // Returns all rights objects for a content URI from a given file
  2145 // -----------------------------------------------------------------------------
  2145 // -----------------------------------------------------------------------------
  2146 EXPORT_C TInt DRMCommon::GetDetailedFileRights(
  2146 EXPORT_C TInt DRMCommon::GetDetailedFileRights(
  2147     RFile& aFileHandle, 
  2147     RFile& aFileHandle,
  2148     RPointerArray<CDRMRights>*& aRightsList)
  2148     RPointerArray<CDRMRights>*& aRightsList)
  2149     {
  2149     {
  2150     TInt r = KErrNone;
  2150     TInt r = KErrNone;
  2151 
  2151 
  2152     TRAP(r, GetDetailedFileRightsL(aFileHandle, aRightsList));
  2152     TRAP(r, GetDetailedFileRightsL(aFileHandle, aRightsList));
  2153     if (r == KErrNone)
  2153     if (r == KErrNone)
  2154         {
  2154         {
  2155         AddParents( const_cast<DRMCommon*>(this), *aRightsList );
  2155         AddParents( const_cast<DRMCommon*>(this), *aRightsList );
  2156         }
  2156         }
  2157     return r;
  2157     return r;
  2158     }    
  2158     }
  2159 
  2159 
  2160 // -----------------------------------------------------------------------------
  2160 // -----------------------------------------------------------------------------
  2161 // DRMCommon::GetActiveRights
  2161 // DRMCommon::GetActiveRights
  2162 // Returns a possible active rights object
  2162 // Returns a possible active rights object
  2163 // -----------------------------------------------------------------------------
  2163 // -----------------------------------------------------------------------------
  2165     const TDesC8& aContentURI,
  2165     const TDesC8& aContentURI,
  2166     TUint32 aConstraints,
  2166     TUint32 aConstraints,
  2167     CDRMRights*& aRightsObject)
  2167     CDRMRights*& aRightsObject)
  2168     {
  2168     {
  2169     TInt r = KErrNone;
  2169     TInt r = KErrNone;
  2170     
  2170 
  2171     TRAP( r, GetActiveRightsL( aContentURI, aConstraints, aRightsObject ) );
  2171     TRAP( r, GetActiveRightsL( aContentURI, aConstraints, aRightsObject ) );
  2172     if(r != KErrNone)
  2172     if(r != KErrNone)
  2173         {
  2173         {
  2174         return DRMCommon::ENoRights;    
  2174         return DRMCommon::ENoRights;
  2175         }
  2175         }
  2176     else 
  2176     else
  2177         {
  2177         {
  2178         CDRMRights::TRestriction restriction;
  2178         CDRMRights::TRestriction restriction;
  2179         CDRMRights::TExpiration expiration;
  2179         CDRMRights::TExpiration expiration;
  2180         TUint32 constType(0);
  2180         TUint32 constType(0);
  2181         aRightsObject->GetRightsInfo(aConstraints, restriction, expiration, constType);
  2181         aRightsObject->GetRightsInfo(aConstraints, restriction, expiration, constType);
  2190 EXPORT_C TInt DRMCommon::GetContentURIList(
  2190 EXPORT_C TInt DRMCommon::GetContentURIList(
  2191     RPointerArray<HBufC8>*& aURIList)
  2191     RPointerArray<HBufC8>*& aURIList)
  2192     {
  2192     {
  2193     RDRMRightsClient client;
  2193     RDRMRightsClient client;
  2194     TInt error = client.Connect();
  2194     TInt error = client.Connect();
  2195     
  2195 
  2196     aURIList = NULL;
  2196     aURIList = NULL;
  2197     if (!error)
  2197     if (!error)
  2198         {
  2198         {
  2199         aURIList = new RPointerArray<HBufC8>(10);
  2199         aURIList = new RPointerArray<HBufC8>(10);
  2200         if (aURIList)
  2200         if (aURIList)
  2212             {
  2212             {
  2213             error = KErrNoMemory;
  2213             error = KErrNoMemory;
  2214             }
  2214             }
  2215         client.Close();
  2215         client.Close();
  2216         }
  2216         }
  2217     
  2217 
  2218     return error;
  2218     return error;
  2219     }
  2219     }
  2220 
  2220 
  2221 // -----------------------------------------------------------------------------
  2221 // -----------------------------------------------------------------------------
  2222 // DRMCommon::Connect
  2222 // DRMCommon::Connect
  2223 // Does nothing
  2223 // Does nothing
  2224 // -----------------------------------------------------------------------------
  2224 // -----------------------------------------------------------------------------
  2225 EXPORT_C TInt DRMCommon::Connect()
  2225 EXPORT_C TInt DRMCommon::Connect()
  2226     {
  2226     {
  2227     RDRMRightsClient client; // Used to start RightsServer in bootup
  2227     RDRMRightsClient client; // Used to start RightsServer in bootup
  2228     TInt ignore = 0;				 // error will be ignored, if it fails to start the
  2228     TInt ignore = 0;                 // error will be ignored, if it fails to start the
  2229                              // rights server there is nothing we can really
  2229                              // rights server there is nothing we can really
  2230                              // do about it, and normally this would work and
  2230                              // do about it, and normally this would work and
  2231                              // return AOk, just used because of the SkinSrv
  2231                              // return AOk, just used because of the SkinSrv
  2232                              // Bootup thing
  2232                              // Bootup thing
  2233     ignore = client.Connect();        // Called by SkinSrv during bootup
  2233     ignore = client.Connect();        // Called by SkinSrv during bootup
  2234 		if( ignore ) 
  2234         if( ignore )
  2235 		    {
  2235             {
  2236 		    // The error shouldn't matter since it will be retried	
  2236             // The error shouldn't matter since it will be retried
  2237 		    }
  2237             }
  2238     client.Close();
  2238     client.Close();
  2239     return EOk;
  2239     return EOk;
  2240     }
  2240     }
  2241 
  2241 
  2242 // -----------------------------------------------------------------------------
  2242 // -----------------------------------------------------------------------------
  2272 // DRMCommon::Version
  2272 // DRMCommon::Version
  2273 // Returns the client side API version.
  2273 // Returns the client side API version.
  2274 // -----------------------------------------------------------------------------
  2274 // -----------------------------------------------------------------------------
  2275 EXPORT_C TVersion DRMCommon::Version()
  2275 EXPORT_C TVersion DRMCommon::Version()
  2276     {
  2276     {
  2277     return TVersion(KClientVersionMajor, 
  2277     return TVersion(KClientVersionMajor,
  2278         KClientVersionMinor, 
  2278         KClientVersionMinor,
  2279         KClientVersionBuild);
  2279         KClientVersionBuild);
  2280     }
  2280     }
  2281 
  2281 
  2282 // -----------------------------------------------------------------------------
  2282 // -----------------------------------------------------------------------------
  2283 // DRMCommon::ServerVersion
  2283 // DRMCommon::ServerVersion
  2284 // Returns the version of the DRM engine.
  2284 // Returns the version of the DRM engine.
  2285 // -----------------------------------------------------------------------------
  2285 // -----------------------------------------------------------------------------
  2286 EXPORT_C TVersion DRMCommon::ServerVersion()
  2286 EXPORT_C TVersion DRMCommon::ServerVersion()
  2287     {
  2287     {
  2288     return TVersion(KServerVersionMajor, 
  2288     return TVersion(KServerVersionMajor,
  2289         KServerVersionMinor, 
  2289         KServerVersionMinor,
  2290         KServerVersionBuild);
  2290         KServerVersionBuild);
  2291     }
  2291     }
  2292 
  2292 
  2293 // -----------------------------------------------------------------------------
  2293 // -----------------------------------------------------------------------------
  2294 // DRMCommon::DataTypesCount
  2294 // DRMCommon::DataTypesCount
  2298     TInt& aCount)
  2298     TInt& aCount)
  2299     {
  2299     {
  2300     TInt err = 0;
  2300     TInt err = 0;
  2301     TInt staticTotal = 0;
  2301     TInt staticTotal = 0;
  2302     TInt dynamicTotal = 0;
  2302     TInt dynamicTotal = 0;
  2303     
  2303 
  2304     err = StaticDataTypesCount(staticTotal);    
  2304     err = StaticDataTypesCount(staticTotal);
  2305     if (err)
  2305     if (err)
  2306         {
  2306         {
  2307         return err;  
  2307         return err;
  2308         }
  2308         }
  2309     
  2309 
  2310     err = DynamicDataTypesCount(dynamicTotal);
  2310     err = DynamicDataTypesCount(dynamicTotal);
  2311     if (err)
  2311     if (err)
  2312         {
  2312         {
  2313         return err;  
  2313         return err;
  2314         }
  2314         }
  2315     
  2315 
  2316     aCount = staticTotal + dynamicTotal;
  2316     aCount = staticTotal + dynamicTotal;
  2317     return err;
  2317     return err;
  2318     }
  2318     }
  2319 
  2319 
  2320 // -----------------------------------------------------------------------------
  2320 // -----------------------------------------------------------------------------
  2321 // DRMCommon::SupportedDataType
  2321 // DRMCommon::SupportedDataType
  2322 // Returns a specific DRM enabled MIME type.
  2322 // Returns a specific DRM enabled MIME type.
  2323 // -----------------------------------------------------------------------------
  2323 // -----------------------------------------------------------------------------
  2324 EXPORT_C TInt DRMCommon::SupportedDataType(
  2324 EXPORT_C TInt DRMCommon::SupportedDataType(
  2325     const TInt aIndex, 
  2325     const TInt aIndex,
  2326     TDataType& aDataType)
  2326     TDataType& aDataType)
  2327     {
  2327     {
  2328     TInt err = KErrNone;
  2328     TInt err = KErrNone;
  2329     TInt total = 0;
  2329     TInt total = 0;
  2330     TInt stat = 0;
  2330     TInt stat = 0;
  2331     
  2331 
  2332     err = DataTypesCount(total);
  2332     err = DataTypesCount(total);
  2333     if (!err) err = StaticDataTypesCount(stat);
  2333     if (!err) err = StaticDataTypesCount(stat);
  2334     if (!err)
  2334     if (!err)
  2335         {
  2335         {
  2336         if (0 <= aIndex && aIndex < stat)
  2336         if (0 <= aIndex && aIndex < stat)
  2344         else
  2344         else
  2345             {
  2345             {
  2346             err = KErrArgument;
  2346             err = KErrArgument;
  2347             }
  2347             }
  2348         }
  2348         }
  2349     
  2349 
  2350     return err;
  2350     return err;
  2351     }
  2351     }
  2352 
  2352 
  2353 // -----------------------------------------------------------------------------
  2353 // -----------------------------------------------------------------------------
  2354 // DRMCommon::StaticDataTypesCount
  2354 // DRMCommon::StaticDataTypesCount
  2359     {
  2359     {
  2360     TInt err = 0;
  2360     TInt err = 0;
  2361     RFs fs;
  2361     RFs fs;
  2362     RResourceFile resourceFile;
  2362     RResourceFile resourceFile;
  2363     TResourceReader theReader;
  2363     TResourceReader theReader;
  2364     
  2364 
  2365     err = fs.Connect();
  2365     err = fs.Connect();
  2366     
  2366 
  2367     if (err)
  2367     if (err)
  2368         {
  2368         {
  2369         fs.Close();
  2369         fs.Close();
  2370         return err;
  2370         return err;
  2371         }
  2371         }
  2372     
  2372 
  2373 #ifndef RD_MULTIPLE_DRIVE
  2373 #ifndef RD_MULTIPLE_DRIVE
  2374     
  2374 
  2375     TRAP(err, resourceFile.OpenL(fs, KResourceFile));
  2375     TRAP(err, resourceFile.OpenL(fs, KResourceFile));
  2376     
  2376 
  2377 #else //RD_MULTIPLE_DRIVE
  2377 #else //RD_MULTIPLE_DRIVE
  2378     
  2378 
  2379     TInt driveNumber( -1 );
  2379     TInt driveNumber( -1 );
  2380     TChar driveLetter;
  2380     TChar driveLetter;
  2381     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
  2381     DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRom, driveNumber );
  2382     fs.DriveToChar( driveNumber, driveLetter );
  2382     fs.DriveToChar( driveNumber, driveLetter );
  2383     
  2383 
  2384     TFileName resFile;
  2384     TFileName resFile;
  2385 	resFile.Format( KResourceFile, (TUint)driveLetter );
  2385     resFile.Format( KResourceFile, (TUint)driveLetter );
  2386     
  2386 
  2387     TRAP(err, resourceFile.OpenL(fs, resFile));
  2387     TRAP(err, resourceFile.OpenL(fs, resFile));
  2388     
  2388 
  2389 #endif
  2389 #endif
  2390     if (err)
  2390     if (err)
  2391         {
  2391         {
  2392         fs.Close();
  2392         fs.Close();
  2393         return err;
  2393         return err;
  2394         }
  2394         }
  2395     
  2395 
  2396     HBufC8* res = NULL;
  2396     HBufC8* res = NULL;
  2397     TRAP(err, (res = resourceFile.AllocReadL(DATATYPE))); 
  2397     TRAP(err, (res = resourceFile.AllocReadL(DATATYPE)));
  2398     if (err)
  2398     if (err)
  2399         {
  2399         {
  2400         resourceFile.Close();
  2400         resourceFile.Close();
  2401         fs.Close();
  2401         fs.Close();
  2402         return err;
  2402         return err;
  2403         }
  2403         }
  2404     
  2404 
  2405     
  2405 
  2406     theReader.SetBuffer(res);
  2406     theReader.SetBuffer(res);
  2407     aCount = theReader.ReadInt8();
  2407     aCount = theReader.ReadInt8();
  2408     
  2408 
  2409     delete res;
  2409     delete res;
  2410     res = NULL;
  2410     res = NULL;
  2411     resourceFile.Close();
  2411     resourceFile.Close();
  2412     fs.Close();
  2412     fs.Close();
  2413     return err;
  2413     return err;
  2422     {
  2422     {
  2423     TInt total = 0;
  2423     TInt total = 0;
  2424     TInt err = KErrNone;
  2424     TInt err = KErrNone;
  2425     TInt i;
  2425     TInt i;
  2426     TDataType type;
  2426     TDataType type;
  2427     
  2427 
  2428     if (aDataType.Des().Length() > 0)
  2428     if (aDataType.Des().Length() > 0)
  2429         {
  2429         {
  2430         err = DataTypesCount(total);
  2430         err = DataTypesCount(total);
  2431         for (i = 0 ; err == KErrNone && i < total ; i++)
  2431         for (i = 0 ; err == KErrNone && i < total ; i++)
  2432             {
  2432             {
  2433             err = SupportedDataType(i, type);
  2433             err = SupportedDataType(i, type);
  2434             if (type == aDataType)
  2434             if (type == aDataType)
  2435                 {
  2435                 {
  2436                 err = KErrAlreadyExists;   
  2436                 err = KErrAlreadyExists;
  2437                 }
  2437                 }
  2438             }
  2438             }
  2439         
  2439 
  2440         if (!err)
  2440         if (!err)
  2441             {
  2441             {
  2442             TRAP(err, RegisterDynamicDataTypeL(aDataType));
  2442             TRAP(err, RegisterDynamicDataTypeL(aDataType));
  2443             }
  2443             }
  2444         }
  2444         }
  2445     else
  2445     else
  2446         {
  2446         {
  2447         err = KErrArgument;  
  2447         err = KErrArgument;
  2448         }
  2448         }
  2449     return err;
  2449     return err;
  2450     }
  2450     }
  2451 
  2451 
  2452 // -----------------------------------------------------------------------------
  2452 // -----------------------------------------------------------------------------
  2457     const TInt aIndex)
  2457     const TInt aIndex)
  2458     {
  2458     {
  2459     TInt r;
  2459     TInt r;
  2460     TInt count;
  2460     TInt count;
  2461     TInt total;
  2461     TInt total;
  2462     
  2462 
  2463     StaticDataTypesCount(count);
  2463     StaticDataTypesCount(count);
  2464     r = DataTypesCount(total);
  2464     r = DataTypesCount(total);
  2465     if (r == KErrNone && aIndex >= count && aIndex < total)
  2465     if (r == KErrNone && aIndex >= count && aIndex < total)
  2466         {
  2466         {
  2467         TRAP(r, UnRegisterDynamicDataTypeL(aIndex - count));
  2467         TRAP(r, UnRegisterDynamicDataTypeL(aIndex - count));
  2493             for (TInt i = 0; !merged && i < parents->Count(); i++)
  2493             for (TInt i = 0; !merged && i < parents->Count(); i++)
  2494                 {
  2494                 {
  2495                 CDRMRights::TRestriction restriction;
  2495                 CDRMRights::TRestriction restriction;
  2496                 CDRMRights::TExpiration expiration;
  2496                 CDRMRights::TExpiration expiration;
  2497                 TUint32 constraints;
  2497                 TUint32 constraints;
  2498                 aRights->GetRightsInfo(EUnknown, restriction, expiration, 
  2498                 aRights->GetRightsInfo(EUnknown, restriction, expiration,
  2499                     constraints);
  2499                     constraints);
  2500                 if ( expiration == CDRMRights::EValidRights)
  2500                 if ( expiration == CDRMRights::EValidRights)
  2501                     {
  2501                     {
  2502                     aRights->Merge(*(*parents)[i]);
  2502                     aRights->Merge(*(*parents)[i]);
  2503                     merged = ETrue;
  2503                     merged = ETrue;
  2505                 }
  2505                 }
  2506             parents->ResetAndDestroy();
  2506             parents->ResetAndDestroy();
  2507             delete parents;
  2507             delete parents;
  2508             }
  2508             }
  2509         }
  2509         }
  2510     */    
  2510     */
  2511     }
  2511     }
  2512  
  2512 
  2513  
  2513 
  2514  
  2514 
  2515 
  2515 
  2516 // -----------------------------------------------------------------------------
  2516 // -----------------------------------------------------------------------------
  2517 // GetFileHandle
  2517 // GetFileHandle
  2518 // Get a file name trying to open it in the order required, which is:
  2518 // Get a file name trying to open it in the order required, which is:
  2519 // 1)  EFileShareReadersOrWriters
  2519 // 1)  EFileShareReadersOrWriters
  2520 // 2)  EFileShareAny
  2520 // 2)  EFileShareAny
  2521 // 3)  EFileShareReadersOnly
  2521 // 3)  EFileShareReadersOnly
  2522 // -----------------------------------------------------------------------------
  2522 // -----------------------------------------------------------------------------
  2523 LOCAL_C TInt GetFileHandleRead(
  2523 LOCAL_C TInt GetFileHandleRead(
  2524     RFs& aFileServer, 
  2524     RFs& aFileServer,
  2525     RFile& aFile, 
  2525     RFile& aFile,
  2526     const TDesC& aFileName )
  2526     const TDesC& aFileName )
  2527     {
  2527     {
  2528     TInt error = KErrNone;
  2528     TInt error = KErrNone;
  2529 
  2529 
  2530     // 1) Try to open in EFileShareReadersOrWriters
  2530     // 1) Try to open in EFileShareReadersOrWriters
  2534         // 2) Try to open in EFileShareAny
  2534         // 2) Try to open in EFileShareAny
  2535         error = aFile.Open( aFileServer, aFileName, EFileRead | EFileShareAny );
  2535         error = aFile.Open( aFileServer, aFileName, EFileRead | EFileShareAny );
  2536         if( error != KErrNone )
  2536         if( error != KErrNone )
  2537             {
  2537             {
  2538             // 3) Try to open in EFileShareReadersOnly
  2538             // 3) Try to open in EFileShareReadersOnly
  2539             error = aFile.Open( aFileServer, aFileName, EFileRead | EFileShareReadersOnly );            
  2539             error = aFile.Open( aFileServer, aFileName, EFileRead | EFileShareReadersOnly );
  2540             }
  2540             }
  2541         }
  2541         }
  2542     return error;   
  2542     return error;
  2543     };
  2543     };
  2544 
  2544 
  2545 // -----------------------------------------------------------------------------
  2545 // -----------------------------------------------------------------------------
  2546 // GetFileHandle
  2546 // GetFileHandle
  2547 // Get a file name trying to open it in the order required, which is:
  2547 // Get a file name trying to open it in the order required, which is:
  2548 // 1)  EFileShareReadersOrWriters
  2548 // 1)  EFileShareReadersOrWriters
  2549 // 2)  EFileShareAny
  2549 // 2)  EFileShareAny
  2550 // 3)  EFileShareReadersOnly
  2550 // 3)  EFileShareReadersOnly
  2551 // -----------------------------------------------------------------------------
  2551 // -----------------------------------------------------------------------------
  2552 LOCAL_C void AddParents( DRMCommon* aDrmCommon, 
  2552 LOCAL_C void AddParents( DRMCommon* aDrmCommon,
  2553                          RPointerArray<CDRMRights>& aRights ) 
  2553                          RPointerArray<CDRMRights>& aRights )
  2554     {
  2554     {
  2555     HBufC8* parent = NULL;
  2555     HBufC8* parent = NULL;
  2556     RPointerArray<CDRMRights>* parents = NULL;
  2556     RPointerArray<CDRMRights>* parents = NULL;
  2557     TInt error = KErrNone;
  2557     TInt error = KErrNone;
  2558     RPointerArray<HBufC8> usedParents;
  2558     RPointerArray<HBufC8> usedParents;
  2559     
  2559 
  2560     
  2560 
  2561     for( TInt i = 0; i < aRights.Count(); i++ )
  2561     for( TInt i = 0; i < aRights.Count(); i++ )
  2562         {
  2562         {
  2563         parent = aRights[i]->GetPermission().iParentUID;
  2563         parent = aRights[i]->GetPermission().iParentUID;
  2564         
  2564 
  2565         for(TInt counter = 0; counter < usedParents.Count(); counter++ )
  2565         for(TInt counter = 0; counter < usedParents.Count(); counter++ )
  2566             {
  2566             {
  2567             if( parent && !usedParents[counter]->Compare( *parent ) )
  2567             if( parent && !usedParents[counter]->Compare( *parent ) )
  2568                 {
  2568                 {
  2569                 parent = NULL;
  2569                 parent = NULL;
  2570                 }
  2570                 }
  2571             }
  2571             }
  2572         
  2572 
  2573         if( parent != NULL )
  2573         if( parent != NULL )
  2574             {
  2574             {
  2575             TRAP( error, usedParents.AppendL( parent ) );
  2575             TRAP( error, usedParents.AppendL( parent ) );
  2576             
  2576 
  2577             if( aDrmCommon->GetDetailedContentRights(parent->Des(), parents) == KErrNone )
  2577             if( aDrmCommon->GetDetailedContentRights(parent->Des(), parents) == KErrNone )
  2578                 {
  2578                 {
  2579                 for( TInt j = parents->Count()-1; j >= 0;j-- )
  2579                 for( TInt j = parents->Count()-1; j >= 0;j-- )
  2580                     { 
  2580                     {
  2581                     TRAP( error, aRights.AppendL( (*parents)[j] ) );
  2581                     TRAP( error, aRights.AppendL( (*parents)[j] ) );
  2582                     (*parents)[j] = NULL;
  2582                     (*parents)[j] = NULL;
  2583                     parents->Remove(j);
  2583                     parents->Remove(j);
  2584                     }
  2584                     }
  2585                 parents->ResetAndDestroy();    
  2585                 parents->ResetAndDestroy();
  2586                 delete parents;
  2586                 delete parents;
  2587                 parents = NULL;    
  2587                 parents = NULL;
  2588                 }
  2588                 }
  2589             
  2589 
  2590             }
  2590             }
  2591         }
  2591         }
  2592     usedParents.Reset();
  2592     usedParents.Reset();
  2593     usedParents.Close();        
  2593     usedParents.Close();
  2594     }
  2594     }
  2595 
  2595 
  2596 // -----------------------------------------------------------------------------
  2596 // -----------------------------------------------------------------------------
  2597 // DRMCommon::MapErrorCode
  2597 // DRMCommon::MapErrorCode
  2598 // Remaps DRM core specific error codes to DRM API error codes.
  2598 // Remaps DRM core specific error codes to DRM API error codes.