omadrm/drmengine/roapstorage/src/DRMRIContext.cpp
changeset 0 95b198f216e5
child 84 b09186059647
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2004 - 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Datatype for the Common Rights Database Data
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <s32strm.h>
       
    22 #include <s32mem.h>
       
    23 #include <caf/caf.h>
       
    24 #include <uri8.h>
       
    25 
       
    26 #include "drmlog.h"
       
    27 #include "DRMRIContext.h"
       
    28 
       
    29 // EXTERNAL DATA STRUCTURES
       
    30 
       
    31 // EXTERNAL FUNCTION PROTOTYPES
       
    32 
       
    33 // CONSTANTS
       
    34 
       
    35 // MACROS
       
    36 
       
    37 // LOCAL CONSTANTS AND MACROS
       
    38 const TInt KMaxCertificateLength = 327680;
       
    39 const TInt KMaxUrlLength = 32768;
       
    40 const TInt KMaxRiAliasLength = 1024;
       
    41 
       
    42 // MODULE DATA STRUCTURES
       
    43 
       
    44 // LOCAL FUNCTION PROTOTYPES
       
    45 
       
    46 // FORWARD DECLARATIONS
       
    47 
       
    48 // ============================= LOCAL FUNCTIONS ===============================
       
    49 // ============================ MEMBER FUNCTIONS ===============================
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CDRMRIContext::NewLC
       
    53 // Two-phased constructor.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 EXPORT_C CDRMRIContext* CDRMRIContext::NewLC( const TDesC8& aRIID,
       
    57                                               const TDesC8& aRiAlias,
       
    58                                               const TDesC8& aVersion,
       
    59                                               const RPointerArray< HBufC8 >& aAlgorithms,
       
    60                                               const RPointerArray< HBufC8 >& aRIURLs,
       
    61                                               const TDesC8& aRightsIssuerURL,
       
    62                                               const TTime& aExpiryTime,
       
    63                                               const RPointerArray< HBufC8 >& aChain,
       
    64                                               const RPointerArray< HBufC8 >& aResponses,
       
    65                                               const TUint8 aDeviceCertCached,
       
    66                                               const TDesC8& aSelectedDeviceRoot,
       
    67                                               const TUint8 aIsMeteringAllowed )
       
    68     {
       
    69     CDRMRIContext* self = new( ELeave ) CDRMRIContext();
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL( aRIID, aRiAlias, aVersion, aAlgorithms,
       
    72                       aRIURLs, aRightsIssuerURL, aExpiryTime,
       
    73                       aChain, aResponses, aDeviceCertCached,
       
    74                       aSelectedDeviceRoot, aIsMeteringAllowed );
       
    75 
       
    76     return self;
       
    77     };
       
    78 
       
    79 
       
    80 // -----------------------------------------------------------------------------
       
    81 // CDRMRIContext::NewL
       
    82 // Two-phased constructor.
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 EXPORT_C CDRMRIContext* CDRMRIContext::NewL( const TDesC8& aRIID,
       
    86                                              const TDesC8& aRiAlias,
       
    87                                              const TDesC8& aVersion,
       
    88                                              const RPointerArray< HBufC8 >& aAlgorithms,
       
    89                                              const RPointerArray< HBufC8 >& aRIURLs,
       
    90                                              const TDesC8& aRightsIssuerURL,
       
    91                                              const TTime& aExpiryTime,
       
    92                                              const RPointerArray< HBufC8 >& aChain,
       
    93                                              const RPointerArray< HBufC8 >& aResponses,
       
    94                                              const TUint8 aDeviceCertCached,
       
    95                                              const TDesC8& aSelectedDeviceRoot,
       
    96                                              const TUint8 aIsMeteringAllowed )
       
    97     {
       
    98     CDRMRIContext* self = NewLC( aRIID, aRiAlias, aVersion, aAlgorithms,
       
    99                                  aRIURLs, aRightsIssuerURL, aExpiryTime,
       
   100                                  aChain, aResponses, aDeviceCertCached,
       
   101                                  aSelectedDeviceRoot, aIsMeteringAllowed );
       
   102     CleanupStack::Pop();
       
   103 
       
   104     return self;
       
   105     };
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // CDRMRIContext::NewLC
       
   109 // Two-phased constructor.
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 EXPORT_C CDRMRIContext* CDRMRIContext::NewLC()
       
   113     {
       
   114     CDRMRIContext* self = new( ELeave ) CDRMRIContext();
       
   115     CleanupStack::PushL( self );
       
   116 
       
   117     return self;
       
   118     };
       
   119 
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CDRMRIContext::NewL
       
   123 // Two-phased constructor.
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 EXPORT_C CDRMRIContext* CDRMRIContext::NewL()
       
   127     {
       
   128     CDRMRIContext* self = NewLC();
       
   129     CleanupStack::Pop();
       
   130 
       
   131     return self;
       
   132     };
       
   133 
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // Default Constructor - First phase.
       
   137 // Can be used by itself to generate an empty object
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 CDRMRIContext::CDRMRIContext()
       
   141     {
       
   142 
       
   143     };
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // Destructor
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 EXPORT_C CDRMRIContext::~CDRMRIContext()
       
   150     {
       
   151     // Delete the algorithm array
       
   152     iAlgorithms.ResetAndDestroy();
       
   153     iAlgorithms.Close();
       
   154 
       
   155     // Delete the ri uri array
       
   156     iRIURLs.ResetAndDestroy();
       
   157     iRIURLs.Close();
       
   158 
       
   159     // Delete the certificate chain
       
   160     iCertificateChain.ResetAndDestroy();
       
   161     iCertificateChain.Close();
       
   162 
       
   163     // Delete the OCSP responses
       
   164     iOcspResponse.ResetAndDestroy();
       
   165     iOcspResponse.Close();
       
   166 
       
   167     delete iRightsIssuerURL;
       
   168     delete iRiAlias;
       
   169     };
       
   170 
       
   171 // -----------------------------------------------------------------------------
       
   172 // CDRMRIContext::RIID
       
   173 // -----------------------------------------------------------------------------
       
   174 //
       
   175 EXPORT_C const TDesC8& CDRMRIContext::RIID() const
       
   176     {
       
   177     return iRIID;
       
   178     };
       
   179 
       
   180 // -----------------------------------------------------------------------------
       
   181 // CDRMRIContext::RIAlias
       
   182 // -----------------------------------------------------------------------------
       
   183 //
       
   184 EXPORT_C const TDesC8& CDRMRIContext::RIAlias() const
       
   185     {
       
   186     return *iRiAlias;
       
   187     };
       
   188 
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CDRMRIContext::Version
       
   192 // -----------------------------------------------------------------------------
       
   193 //
       
   194 EXPORT_C const TDesC8& CDRMRIContext::Version() const
       
   195     {
       
   196     return iVersion;
       
   197     };
       
   198 
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CDRMRIContext::Algorithms
       
   202 // -----------------------------------------------------------------------------
       
   203 //
       
   204 EXPORT_C const RPointerArray< HBufC8 >& CDRMRIContext::Algorithms() const
       
   205     {
       
   206     return iAlgorithms;
       
   207     };
       
   208 
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CDRMRIContext::RIURLs
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 EXPORT_C const RPointerArray< HBufC8 >& CDRMRIContext::RIURLs() const
       
   215     {
       
   216     return iRIURLs;
       
   217     };
       
   218 
       
   219 // -----------------------------------------------------------------------------
       
   220 // CDRMRIContext::RightsIssuerURL
       
   221 // -----------------------------------------------------------------------------
       
   222 //
       
   223 EXPORT_C const TDesC8& CDRMRIContext::RightsIssuerURL() const
       
   224     {
       
   225     return *iRightsIssuerURL;
       
   226     };
       
   227 
       
   228 // -----------------------------------------------------------------------------
       
   229 // CDRMRIContext::ExpiryTime
       
   230 // -----------------------------------------------------------------------------
       
   231 //
       
   232 EXPORT_C const TTime CDRMRIContext::ExpiryTime() const
       
   233     {
       
   234     return iExpiryTime;
       
   235     };
       
   236 
       
   237 // -----------------------------------------------------------------------------
       
   238 // CDRMRIContext::CertificateChain
       
   239 // -----------------------------------------------------------------------------
       
   240 //
       
   241 EXPORT_C const RPointerArray< HBufC8 >& CDRMRIContext::CertificateChain() const
       
   242     {
       
   243     return iCertificateChain;
       
   244     };
       
   245 
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CDRMRIContext::OCSPResponse
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 EXPORT_C const RPointerArray< HBufC8 >& CDRMRIContext::OCSPResponse() const
       
   252     {
       
   253     return iOcspResponse;
       
   254     };
       
   255 
       
   256 
       
   257 // -----------------------------------------------------------------------------
       
   258 // CDRMRIContext::DeviceCertCached
       
   259 // -----------------------------------------------------------------------------
       
   260 //
       
   261 EXPORT_C TUint8 CDRMRIContext::DeviceCertCached() const
       
   262     {
       
   263     return iDeviceCertCached;
       
   264     };
       
   265 
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CDRMRIContext::SelectedDeviceRoot
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 EXPORT_C const TDesC8& CDRMRIContext::SelectedDeviceRoot() const
       
   272     {
       
   273     return iSelectedDeviceRoot;
       
   274     };
       
   275 
       
   276 
       
   277 // -----------------------------------------------------------------------------
       
   278 // CDRMRIContext::IsMeteringAllowed
       
   279 // -----------------------------------------------------------------------------
       
   280 //
       
   281 EXPORT_C TUint8 CDRMRIContext::IsMeteringAllowed() const
       
   282     {
       
   283     return iIsMeteringAllowed;
       
   284     };
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // CDRMRIContext::SetRIIDL
       
   288 // -----------------------------------------------------------------------------
       
   289 //
       
   290 EXPORT_C void CDRMRIContext::SetRIIDL( const TDesC8& aRIID )
       
   291     {
       
   292     if ( ( aRIID.Length() <= 0 ) || ( aRIID.Length() > SHA1_HASH ) )
       
   293         {
       
   294         User::Leave( KErrArgument );
       
   295         }
       
   296     iRIID.Copy( aRIID );
       
   297     };
       
   298 
       
   299 
       
   300 // -----------------------------------------------------------------------------
       
   301 // CDRMRIContext::SetVersionL
       
   302 // -----------------------------------------------------------------------------
       
   303 //
       
   304 EXPORT_C void CDRMRIContext::SetVersionL( const TDesC8& aVersion )
       
   305     {
       
   306     if ( ( aVersion.Length() <= 0 ) ||
       
   307         ( aVersion.Length() > Roap::KMaxRoapVersionLength ) )
       
   308         {
       
   309         User::Leave( KErrArgument );
       
   310         }
       
   311     iVersion.Copy( aVersion );
       
   312     };
       
   313 
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // CDRMRIContext::SetAlgorithmsL
       
   317 // -----------------------------------------------------------------------------
       
   318 //
       
   319 EXPORT_C void CDRMRIContext::SetAlgorithmsL( const RPointerArray< HBufC8 >& aAlgorithms )
       
   320     {
       
   321     HBufC8* tempData = NULL;
       
   322 
       
   323     // Clear the old algorithms
       
   324     iAlgorithms.ResetAndDestroy();
       
   325 
       
   326     // Append the new stuff
       
   327     for( TInt i = 0; i < aAlgorithms.Count(); i++ )
       
   328         {
       
   329         tempData = aAlgorithms[i]->AllocLC();
       
   330         iAlgorithms.AppendL( tempData );
       
   331         CleanupStack::Pop();
       
   332         }
       
   333     };
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CDRMRIContext::SetRIURLsL
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C void CDRMRIContext::SetRIURLsL( const RPointerArray< HBufC8 >& aRIURLs )
       
   340     {
       
   341     HBufC8* tempData = NULL;
       
   342 
       
   343     // Clear the old algorithms
       
   344     iRIURLs.ResetAndDestroy();
       
   345 
       
   346     // Append the new stuff
       
   347     for( TInt i = 0; i < aRIURLs.Count(); i++ )
       
   348         {
       
   349         tempData = aRIURLs[i]->AllocLC();
       
   350         iRIURLs.AppendL( tempData );
       
   351         CleanupStack::Pop();
       
   352         }
       
   353     };
       
   354 
       
   355 // -----------------------------------------------------------------------------
       
   356 // CDRMRIContext::SetRightsIssuerURLL
       
   357 // -----------------------------------------------------------------------------
       
   358 //
       
   359 EXPORT_C void CDRMRIContext::SetRightsIssuerURLL(
       
   360     const TDesC8& aRightsIssuerURL )
       
   361     {
       
   362     HBufC8* newRightsIssuerURL = aRightsIssuerURL.AllocL();
       
   363 
       
   364     if( iRightsIssuerURL )
       
   365         {
       
   366         delete iRightsIssuerURL;
       
   367         iRightsIssuerURL = NULL;
       
   368         }
       
   369     iRightsIssuerURL = newRightsIssuerURL;
       
   370     };
       
   371 
       
   372 // -----------------------------------------------------------------------------
       
   373 // CDRMRIContext::SetExpiryTimeL
       
   374 // -----------------------------------------------------------------------------
       
   375 //
       
   376 EXPORT_C void CDRMRIContext::SetExpiryTimeL( const TTime& aExpiryTime )
       
   377     {
       
   378     iExpiryTime = aExpiryTime;
       
   379     };
       
   380 
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CDRMRIContext::SetCertificateChainL
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 EXPORT_C void CDRMRIContext::SetCertificateChainL( const RPointerArray< HBufC8 >& aChain )
       
   387     {
       
   388     HBufC8* tempData = NULL;
       
   389 
       
   390     // Clear the old algorithms
       
   391     iCertificateChain.ResetAndDestroy();
       
   392 
       
   393     // Append the new stuff
       
   394     for( TInt i = 0; i < aChain.Count(); i++ )
       
   395         {
       
   396         tempData = aChain[i]->AllocLC();
       
   397         iCertificateChain.AppendL( tempData );
       
   398         CleanupStack::Pop();
       
   399         }
       
   400     };
       
   401 
       
   402 
       
   403 // -----------------------------------------------------------------------------
       
   404 // CDRMRIContext::SetOCSPResponseL
       
   405 // -----------------------------------------------------------------------------
       
   406 //
       
   407 EXPORT_C void CDRMRIContext::SetOCSPResponseL( const RPointerArray< HBufC8 >& aResponses )
       
   408     {
       
   409     HBufC8* tempData = NULL;
       
   410 
       
   411     // Clear the old algorithms
       
   412     iOcspResponse.ResetAndDestroy();
       
   413 
       
   414     // Append the new stuff
       
   415     for( TInt i = 0; i < aResponses.Count(); i++ )
       
   416         {
       
   417         tempData = aResponses[i]->AllocLC();
       
   418         iOcspResponse.AppendL( tempData );
       
   419         CleanupStack::Pop();
       
   420         }
       
   421     };
       
   422 
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CDRMRIContext::SetDeviceCertCached
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 EXPORT_C void CDRMRIContext::SetDeviceCertCached( TUint8& aIsCached )
       
   429     {
       
   430     iDeviceCertCached = aIsCached;
       
   431     };
       
   432 
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CDRMRIContext::WhiteListURLExistsL
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 EXPORT_C TBool CDRMRIContext::WhiteListURLExistsL( const TDesC8& aURL ) const
       
   439     {
       
   440     TUriParser8 uri1;
       
   441     TUriParser8 uri2;
       
   442     uri1.Parse( aURL );
       
   443 
       
   444     for( TInt i = 0; i < iRIURLs.Count(); i++ )
       
   445         {
       
   446         uri2.Parse( *iRIURLs[i] );
       
   447         if ( uri2.Compare( uri1, EUriHost ) == 0 )
       
   448             {
       
   449             return ETrue;
       
   450             }
       
   451         }
       
   452 
       
   453     if( iRightsIssuerURL )
       
   454         {
       
   455         uri2.Parse( *iRightsIssuerURL );
       
   456         if ( uri2.Compare(uri1, EUriHost ) == 0 )
       
   457             {
       
   458             return ETrue;
       
   459             }
       
   460         }
       
   461     return EFalse;
       
   462     };
       
   463 
       
   464 // -----------------------------------------------------------------------------
       
   465 // CDRMRIContext::SetSelectedDeviceRoot
       
   466 // -----------------------------------------------------------------------------
       
   467 //
       
   468 EXPORT_C void CDRMRIContext::SetSelectedDeviceRoot( const TDesC8& aSelectedDeviceRoot )
       
   469     {
       
   470     if ( ( aSelectedDeviceRoot.Length() <= 0 ) ||
       
   471         ( aSelectedDeviceRoot.Length() > SHA1_HASH ) )
       
   472         {
       
   473         return;
       
   474         }
       
   475     iSelectedDeviceRoot.Copy( aSelectedDeviceRoot );
       
   476     };
       
   477 
       
   478 // -----------------------------------------------------------------------------
       
   479 // CDRMRIContext::SetMeteringStatus
       
   480 // -----------------------------------------------------------------------------
       
   481 //
       
   482 EXPORT_C void CDRMRIContext::SetMeteringStatus( const TBool aIsMeteringAllowed )
       
   483     {
       
   484     iIsMeteringAllowed = aIsMeteringAllowed;
       
   485     };
       
   486 
       
   487 // -----------------------------------------------------------------------------
       
   488 // CDRMRIContext::ExternalizeL
       
   489 // -----------------------------------------------------------------------------
       
   490 //
       
   491 EXPORT_C void CDRMRIContext::ExternalizeL( RWriteStream& aStream ) const
       
   492     {
       
   493     TInt dataLength = 0;
       
   494     TUint8 flag;
       
   495 
       
   496     // write the iRIID
       
   497     aStream.WriteL( iRIID );
       
   498 
       
   499     // write the iRiAlias
       
   500     if ( iRiAlias )
       
   501         {
       
   502         flag = ETrue;
       
   503         aStream << flag;
       
   504         aStream << *iRiAlias;
       
   505         }
       
   506     else
       
   507         {
       
   508         flag = EFalse;
       
   509         aStream << flag;
       
   510         }
       
   511 
       
   512     // write the version length
       
   513     aStream.WriteInt8L( static_cast<TInt8>(iVersion.Length() ) );
       
   514 
       
   515     // write the version
       
   516     if( iVersion.Length() )
       
   517         {
       
   518         aStream.WriteL( iVersion );
       
   519         }
       
   520 
       
   521     // write the algorithms
       
   522 
       
   523     // How many:
       
   524     aStream.WriteInt32L( iAlgorithms.Count() );
       
   525 
       
   526     // for each in rpointerarray
       
   527     for( TInt i = 0; i < iAlgorithms.Count(); i++ )
       
   528         {
       
   529         dataLength = 0;
       
   530         if( iAlgorithms[i] )
       
   531             {
       
   532             dataLength = iAlgorithms[i]->Length();
       
   533             }
       
   534         aStream.WriteInt32L( dataLength );
       
   535 
       
   536         if( dataLength )
       
   537             {
       
   538             aStream.WriteL( iAlgorithms[i]->Des() );
       
   539             }
       
   540         }
       
   541 
       
   542     // write the algorithms
       
   543 
       
   544     // How many:
       
   545     aStream.WriteInt32L( iRIURLs.Count() );
       
   546 
       
   547     // for each in rpointerarray
       
   548     for( TInt i = 0; i < iRIURLs.Count(); i++ )
       
   549         {
       
   550         dataLength = 0;
       
   551         if( iRIURLs[i] )
       
   552             {
       
   553             dataLength = iRIURLs[i]->Length();
       
   554             }
       
   555         aStream.WriteInt32L( dataLength );
       
   556 
       
   557         if( dataLength )
       
   558             {
       
   559             aStream.WriteL( iRIURLs[i]->Des() );
       
   560             }
       
   561         }
       
   562 
       
   563     // Write the rights issuer url
       
   564     if (iRightsIssuerURL)
       
   565         {
       
   566         flag = ETrue;
       
   567         aStream << flag;
       
   568         aStream << *iRightsIssuerURL;
       
   569         }
       
   570     else
       
   571         {
       
   572         flag = EFalse;
       
   573         aStream << flag;
       
   574         }
       
   575 
       
   576     // write the expiry time
       
   577     WriteInt64L( iExpiryTime.Int64(), aStream );
       
   578 
       
   579     // How many:
       
   580     aStream.WriteInt32L( iCertificateChain.Count() );
       
   581 
       
   582     // for each in rpointerarray
       
   583     for( TInt i = 0; i < iCertificateChain.Count(); i++ )
       
   584         {
       
   585         aStream << *(iCertificateChain[i]);
       
   586         }
       
   587 
       
   588     // How many:
       
   589     aStream.WriteInt32L( iOcspResponse.Count() );
       
   590 
       
   591     // for each in rpointerarray
       
   592     for( TInt i = 0; i < iOcspResponse.Count(); i++ )
       
   593         {
       
   594         aStream << *(iOcspResponse[i]);
       
   595         }
       
   596 
       
   597     // certificate caching indication
       
   598     aStream << iDeviceCertCached;
       
   599 
       
   600     // write the iSelectedDeviceRoot
       
   601     if (iSelectedDeviceRoot.Length())
       
   602         {
       
   603         flag = ETrue;
       
   604         aStream << flag;
       
   605         aStream.WriteL(iSelectedDeviceRoot);
       
   606         }
       
   607     else
       
   608         {
       
   609         flag = EFalse;
       
   610         aStream << flag;
       
   611         }
       
   612 
       
   613     // Add metering allowance info
       
   614     aStream << iIsMeteringAllowed;
       
   615     };
       
   616 
       
   617 // -----------------------------------------------------------------------------
       
   618 // CDRMRIContext::InternalizeL
       
   619 // -----------------------------------------------------------------------------
       
   620 //
       
   621 EXPORT_C void CDRMRIContext::InternalizeL( RReadStream& aStream )
       
   622     {
       
   623     TInt dataLength = 0;
       
   624     HBufC8* dataPart = 0;
       
   625     TPtr8 dataBuffer(NULL,0,0);
       
   626     TInt count = 0;
       
   627     TInt64 timeData;
       
   628     TUint8 flag;
       
   629 
       
   630     // read the iRIID
       
   631     aStream.ReadL( iRIID );
       
   632 
       
   633     // Read the rights issuer Alias
       
   634     if( iRiAlias )
       
   635         {
       
   636         delete iRiAlias;
       
   637         iRiAlias = NULL;
       
   638         }
       
   639 
       
   640     aStream >> flag;
       
   641     if (flag)
       
   642         {
       
   643         iRiAlias = HBufC8::NewL( aStream, KMaxRiAliasLength );
       
   644         }
       
   645 
       
   646     // size of the version string which is not always 20
       
   647     count = aStream.ReadInt8L();
       
   648 
       
   649     // read the version
       
   650     if( count )
       
   651         {
       
   652         aStream.ReadL( iVersion, count );
       
   653         }
       
   654 
       
   655     // read the algorithms
       
   656 
       
   657     // How many:
       
   658     count = aStream.ReadInt32L();
       
   659 
       
   660     // for each in rpointerarray
       
   661     for( TInt i = 0; i < count; i++ )
       
   662         {
       
   663         // Read the ContentID
       
   664         dataLength = aStream.ReadInt32L();
       
   665 
       
   666         if( dataLength )
       
   667             {
       
   668             // Reserve a new buffer:
       
   669             dataPart = HBufC8::NewMaxLC( dataLength );
       
   670 
       
   671             // Set the read buffer:
       
   672             dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength);
       
   673 
       
   674             // Read the data:
       
   675             aStream.ReadL( dataBuffer );
       
   676 
       
   677             // Pop the buffer
       
   678             CleanupStack::Pop(); // dataPart
       
   679 
       
   680             // assign the new content id
       
   681             iAlgorithms.AppendL( dataPart );
       
   682             }
       
   683         }
       
   684 
       
   685     // read the urls
       
   686 
       
   687     // How many:
       
   688     count = aStream.ReadInt32L();
       
   689 
       
   690     // for each in rpointerarray
       
   691     for( TInt i = 0; i < count; i++ )
       
   692         {
       
   693         // Read the ContentID
       
   694         dataLength = aStream.ReadInt32L();
       
   695 
       
   696         if( dataLength )
       
   697             {
       
   698             // Reserve a new buffer:
       
   699             dataPart = HBufC8::NewMaxLC( dataLength );
       
   700 
       
   701             // Set the read buffer:
       
   702             dataBuffer.Set(const_cast<TUint8*>(dataPart->Ptr()), 0, dataLength);
       
   703 
       
   704             // Read the data:
       
   705             aStream.ReadL( dataBuffer );
       
   706 
       
   707             // Pop the buffer
       
   708             CleanupStack::Pop(); // dataPart
       
   709 
       
   710             // assign the new content id
       
   711             iRIURLs.AppendL( dataPart );
       
   712             }
       
   713         }
       
   714 
       
   715     // Read the rights issuer url
       
   716     if( iRightsIssuerURL )
       
   717         {
       
   718         delete iRightsIssuerURL;
       
   719         iRightsIssuerURL = NULL;
       
   720         }
       
   721 
       
   722     aStream >> flag;
       
   723     if (flag)
       
   724         {
       
   725         iRightsIssuerURL = HBufC8::NewL( aStream, KMaxUrlLength );
       
   726         }
       
   727 
       
   728     // write the expiry time
       
   729     ReadInt64L( timeData, aStream );
       
   730     iExpiryTime = timeData;
       
   731 
       
   732     // How many:
       
   733     count = aStream.ReadInt32L();
       
   734 
       
   735     // for each in rpointerarray
       
   736     for( TInt i = 0; i < count; i++ )
       
   737         {
       
   738         // Read the certificate
       
   739         dataPart = HBufC8::NewL( aStream, KMaxCertificateLength );
       
   740 
       
   741         // assign the certificate
       
   742         iCertificateChain.AppendL( dataPart );
       
   743         }
       
   744 
       
   745     // How many:
       
   746     count = aStream.ReadInt32L();
       
   747 
       
   748      // for each in rpointerarray
       
   749     for( TInt i = 0; i < count; i++ )
       
   750         {
       
   751         // Read the certificate
       
   752         dataPart = HBufC8::NewL( aStream, KMaxCertificateLength );
       
   753 
       
   754         // assign the certificate
       
   755         iOcspResponse.AppendL( dataPart );
       
   756         }
       
   757 
       
   758     // certificate caching indication
       
   759     aStream >> iDeviceCertCached;
       
   760 
       
   761     // write the iSelectedDeviceRoot
       
   762     aStream >> flag;
       
   763     if(flag)
       
   764         {
       
   765         aStream.ReadL( iSelectedDeviceRoot );
       
   766         }
       
   767 
       
   768     aStream >> iIsMeteringAllowed;
       
   769 
       
   770     };
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CDRMRIContext::ImportL
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 EXPORT_C void CDRMRIContext::ImportL( const TDesC8& aBuffer )
       
   777     {
       
   778     TInt size = aBuffer.Size();
       
   779     RMemReadStream stream( (TAny*)( aBuffer.Ptr() ), size );
       
   780     CleanupClosePushL( stream );
       
   781 
       
   782     InternalizeL( stream );
       
   783 
       
   784     CleanupStack::PopAndDestroy(); // Stream
       
   785     };
       
   786 
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CDRMRIContext::ExportL
       
   790 // -----------------------------------------------------------------------------
       
   791 //
       
   792 EXPORT_C HBufC8* CDRMRIContext::ExportL() const
       
   793     {
       
   794     TInt size = Size();
       
   795     HBufC8* data = HBufC8::NewMaxLC( size );
       
   796 
       
   797     RMemWriteStream stream( (TAny*)( data->Ptr() ), size );
       
   798     CleanupClosePushL( stream );
       
   799 
       
   800     ExternalizeL( stream );
       
   801 
       
   802     CleanupStack::PopAndDestroy(); // Stream
       
   803     CleanupStack::Pop();
       
   804     return data;
       
   805     };
       
   806 
       
   807 
       
   808 // -----------------------------------------------------------------------------
       
   809 // CDRMRIContext::Size
       
   810 // -----------------------------------------------------------------------------
       
   811 //
       
   812 EXPORT_C TInt CDRMRIContext::Size() const
       
   813     {
       
   814     TInt size = 0;
       
   815 
       
   816     // get the size of iRIID
       
   817     size += SHA1_HASH;
       
   818 
       
   819     // get the size of RiAlias
       
   820     size += sizeof(TUint8);
       
   821     if( iRiAlias )
       
   822         {
       
   823         size += iRiAlias->Size();
       
   824         }
       
   825 
       
   826     // get the size of version
       
   827     size += sizeof(TInt8);
       
   828 
       
   829     size += iVersion.Length();
       
   830 
       
   831     // get the size of the algorithms
       
   832 
       
   833     // How many:
       
   834     size += sizeof(TInt32);
       
   835 
       
   836     // for each in rpointerarray
       
   837     for( TInt i = 0; i < iAlgorithms.Count(); i++ )
       
   838         {
       
   839         size += sizeof(TInt32);
       
   840 
       
   841         if( iAlgorithms[i] )
       
   842             {
       
   843             size += iAlgorithms[i]->Size();
       
   844             }
       
   845         }
       
   846 
       
   847     // get the size of the riurls
       
   848 
       
   849     // How many:
       
   850     size += sizeof(TInt32);
       
   851 
       
   852     // for each in rpointerarray
       
   853     for( TInt i = 0; i < iRIURLs.Count(); i++ )
       
   854         {
       
   855         size += sizeof(TInt32);
       
   856 
       
   857         if( iRIURLs[i] )
       
   858             {
       
   859             size += iRIURLs[i]->Size();
       
   860             }
       
   861         }
       
   862 
       
   863     // rights issuer url
       
   864     size += sizeof(TUint8);
       
   865     if( iRightsIssuerURL )
       
   866         {
       
   867         size += sizeof(TInt32);
       
   868         size += iRightsIssuerURL->Size();
       
   869         }
       
   870 
       
   871     // How many:
       
   872     size += sizeof(TInt32);
       
   873 
       
   874     // for each in rpointerarray
       
   875     for( TInt i = 0; i < iCertificateChain.Count(); i++ )
       
   876         {
       
   877         size += sizeof(TInt32);
       
   878 
       
   879         if( iCertificateChain[i] )
       
   880             {
       
   881             size += iCertificateChain[i]->Size();
       
   882             }
       
   883         }
       
   884 
       
   885     // How many:
       
   886     size += sizeof(TInt32);
       
   887 
       
   888     // for each in rpointerarray
       
   889     for( TInt i = 0; i < iOcspResponse.Count(); i++ )
       
   890         {
       
   891         size += sizeof(TInt32);
       
   892 
       
   893         if( iOcspResponse[i] )
       
   894             {
       
   895             size += iOcspResponse[i]->Size();
       
   896             }
       
   897         }
       
   898 
       
   899     // write the expiry time
       
   900     size += sizeof(TInt64);
       
   901 
       
   902     // certificate caching indication
       
   903     size += sizeof(TUint8);
       
   904 
       
   905     // get the size of iSelectedDeviceRoot
       
   906     size += sizeof(TUint8);
       
   907     if(iSelectedDeviceRoot.Length())
       
   908         {
       
   909         size += SHA1_HASH;
       
   910         }
       
   911 
       
   912     // get the size of iIsMeteringAllowed
       
   913     size += sizeof(TUint8);
       
   914 
       
   915     return size;
       
   916     };
       
   917 
       
   918 // -----------------------------------------------------------------------------
       
   919 // CDRMRIContext::ConstructL
       
   920 // Second phase constructor
       
   921 // -----------------------------------------------------------------------------
       
   922 //
       
   923 void CDRMRIContext::ConstructL( const TDesC8& aRIID,
       
   924                                 const TDesC8& aRiAlias,
       
   925                                 const TDesC8& aVersion,
       
   926                                 const RPointerArray< HBufC8 >& aAlgorithms,
       
   927                                 const RPointerArray< HBufC8 >& aRIURLs,
       
   928                                 const TDesC8& aRightsIssuerURL,
       
   929                                 const TTime& aExpiryTime,
       
   930                                 const RPointerArray< HBufC8 >& aChain,
       
   931                                 const RPointerArray< HBufC8 >& aResponses,
       
   932                                 const TUint8 aDeviceCertCached,
       
   933                                 const TDesC8& aSelectedDeviceRoot,
       
   934                                 const TUint8 aIsMeteringAllowed )
       
   935     {
       
   936     HBufC8* tempVar = NULL;
       
   937 
       
   938     if ( aRIID.Length() > SHA1_HASH )
       
   939         {
       
   940         User::Leave( KErrArgument);
       
   941         }
       
   942 
       
   943     iRIID.Copy( aRIID );
       
   944 
       
   945     if ( &aRiAlias  && aRiAlias.Length() )
       
   946         {
       
   947         iRiAlias = aRiAlias.AllocL();
       
   948         }
       
   949 
       
   950     // The size here should also be fixed
       
   951     iVersion.Copy( aVersion );
       
   952 
       
   953     // copy the algorithms
       
   954     for( TInt i = 0; i < aAlgorithms.Count(); i++ )
       
   955         {
       
   956         tempVar = aAlgorithms[i]->AllocLC();
       
   957         iAlgorithms.AppendL( tempVar );
       
   958         CleanupStack::Pop();
       
   959         }
       
   960 
       
   961     // copy the rights issuer urls
       
   962     for( TInt i = 0; i < aRIURLs.Count(); i++ )
       
   963         {
       
   964         tempVar = aRIURLs[i]->AllocLC();
       
   965         iRIURLs.AppendL( tempVar );
       
   966         CleanupStack::Pop();
       
   967         }
       
   968 
       
   969      // copy the rights issuer URL
       
   970      if ( aRightsIssuerURL.Length() )
       
   971         {
       
   972         iRightsIssuerURL = aRightsIssuerURL.AllocL();
       
   973         }
       
   974 
       
   975     // copy the certificate chain
       
   976     for( TInt i = 0; i < aChain.Count(); i++ )
       
   977         {
       
   978         tempVar = aChain[i]->AllocLC();
       
   979         iCertificateChain.AppendL( tempVar );
       
   980         CleanupStack::Pop();
       
   981         }
       
   982 
       
   983     // copy the certificate chain
       
   984     for( TInt i = 0; i < aResponses.Count(); i++ )
       
   985         {
       
   986         tempVar = aResponses[i]->AllocLC();
       
   987         iOcspResponse.AppendL( tempVar );
       
   988         CleanupStack::Pop();
       
   989         }
       
   990 
       
   991     // set the time
       
   992     iExpiryTime = aExpiryTime;
       
   993 
       
   994     // certificate caching indication
       
   995     iDeviceCertCached = aDeviceCertCached;
       
   996 
       
   997     if ( aSelectedDeviceRoot.Length() > SHA1_HASH )
       
   998         {
       
   999         User::Leave( KErrArgument);
       
  1000         }
       
  1001 
       
  1002     iSelectedDeviceRoot.Copy( aSelectedDeviceRoot );
       
  1003 
       
  1004     iIsMeteringAllowed = aIsMeteringAllowed;
       
  1005   };
       
  1006 
       
  1007 
       
  1008 // -----------------------------------------------------------------------------
       
  1009 // CDRMRIContext::WriteInt64L
       
  1010 // -----------------------------------------------------------------------------
       
  1011 //
       
  1012 void CDRMRIContext::WriteInt64L( const TInt64& aWrite, RWriteStream& aStream ) const
       
  1013     {
       
  1014     TPtr8 output( reinterpret_cast<TUint8*>(const_cast<TInt64*>(&aWrite)),
       
  1015                   sizeof(TInt64), sizeof(TInt64) );
       
  1016 
       
  1017     aStream.WriteL( output, sizeof(TInt64) );
       
  1018     }
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CDRMRIContext::ReadInt64L
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //
       
  1024 void CDRMRIContext::ReadInt64L( TInt64& aRead, RReadStream& aStream )
       
  1025     {
       
  1026     TPtr8 input( reinterpret_cast<TUint8*>(&aRead), 0, sizeof(TInt64) );
       
  1027 
       
  1028     aStream.ReadL( input, sizeof(TInt64) );
       
  1029     };
       
  1030 
       
  1031 // End of File