omadrm/drmengine/server/inc/DRMContextDB.h
changeset 0 95b198f216e5
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2003 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 Rights Constraint
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DRMCONTEXTDB_H
       
    20 #define DRMCONTEXTDB_H
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include <e32base.h>
       
    25 #include <hash.h>
       
    26 
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 // MACROS
       
    31 
       
    32 // DATA TYPES
       
    33 
       
    34 // FORWARD DECLARATIONS
       
    35 class CDRMRIContext;
       
    36 class CDRMDomainContext;
       
    37 class CPermanentFileStore;
       
    38 class RWriteStream;
       
    39 class TStreamId;
       
    40 
       
    41 // TYPE DEFINITIONS
       
    42 
       
    43 // FUNCTION PROTOTYPES
       
    44 
       
    45 // CLASS DECLARATION
       
    46 
       
    47 /**
       
    48 *  CDRMContextDB implements the rights database required by DRM Engine
       
    49 *
       
    50 *  @lib RightsServer.dll
       
    51 *  @since 3.0
       
    52 */
       
    53 
       
    54 NONSHARABLE_CLASS( CDRMContextDB ) : public CBase 
       
    55     {
       
    56 public: // Constructors and destructor
       
    57 
       
    58     /**
       
    59     * NewLC
       
    60     *
       
    61     * Creates an instance of the CDRMContextDB class and returns a pointer 
       
    62     * to it. The function leaves the object into the cleanup stack
       
    63     *
       
    64     * @since    3.0
       
    65     * @param    aRightsIssuerContextFile : Full pathname of the ri context file
       
    66     * @param    aDomainContextFile : Full pathname of the domain context file
       
    67     * @param    aFileServer : File server instance to use
       
    68     * @return   Functional CDRMContextDB object, Function leaves if an error 
       
    69     *           occurs.
       
    70     */
       
    71     static CDRMContextDB* NewLC( const TFileName& aRightsIssuerContextFile, 
       
    72                                  const TFileName& aDomainContextFile,
       
    73                                  RFs& aFileServer );
       
    74     
       
    75     /**
       
    76     * NewL
       
    77     *
       
    78     * Creates an instance of the CDRMContextDB class and returns a pointer 
       
    79     * to it.
       
    80     *
       
    81     * @since    3.0
       
    82     * @param    aRightsIssuerContextFile : Full pathname of the ri context file
       
    83     * @param    aDomainContextFile : Full pathname of the domain context file
       
    84     * @param    aFileServer : File server instance to use   
       
    85     * @return   Functional CDRMContextDB object, Function leaves if an error 
       
    86     *           occurs.
       
    87     */
       
    88     static CDRMContextDB* NewL( const TFileName& aRightsIssuerContextFile, 
       
    89                                 const TFileName& aDomainContextFile,
       
    90                                 RFs& aFileServer );
       
    91     /**
       
    92     * OpenLC
       
    93     *
       
    94     * Opens the store and creates an instance of the CDRMContextDB class and returns
       
    95     * a pointer to it. The function leaves the object into the cleanup stack
       
    96     *
       
    97     * @since    3.0
       
    98     * @param    aRightsIssuerContextFile : Full pathname of the ri context file
       
    99     * @param    aDomainContextFile : Full pathname of the domain context file
       
   100     * @param    aFileServer : File server instance to use     
       
   101     * @return   Functional CDRMContextDB object, Function leaves if an error 
       
   102     *           occurs.
       
   103     */
       
   104     static CDRMContextDB* OpenLC( const TFileName& aRightsIssuerContextFile, 
       
   105                                   const TFileName& aDomainContextFile,
       
   106                                   RFs& aFileServer );
       
   107     /**
       
   108     * OpenL
       
   109     *
       
   110     * Opens the store and creates an instance of the CDRMContextDB class and returns
       
   111     * a pointer to it.
       
   112     *
       
   113     * @since    3.0
       
   114     * @param    aRightsIssuerContextFile : Full pathname of the ri context file
       
   115     * @param    aDomainContextFile : Full pathname of the domain context file
       
   116     * @param    aFileServer : File server instance to use      
       
   117     * @return   Functional CDRMContextDB object, Function leaves if an error 
       
   118     *           occurs.
       
   119     */
       
   120     static CDRMContextDB* OpenL( const TFileName& aRightsIssuerContextFile, 
       
   121                                  const TFileName& aDomainContextFile,
       
   122                                  RFs& aFileServer );
       
   123 
       
   124     /*
       
   125     * Destructor
       
   126     */ 
       
   127     virtual ~CDRMContextDB(); 
       
   128 
       
   129 
       
   130 public: // New functions
       
   131      
       
   132     
       
   133     /**
       
   134     * StoreDomainContextL
       
   135     * 
       
   136     * Writes the data of the domain context to the stream store
       
   137     *
       
   138     * @since    3.0
       
   139     * @param    aContext : CDRMDomainContext class to externalize
       
   140     * @return   The function leaves with Symbian OS error code if an
       
   141     *           error occurs
       
   142     */
       
   143     void StoreDomainContextL( const CDRMDomainContext& aContext );    
       
   144     
       
   145     /**
       
   146     * FetchDomainContextL
       
   147     * 
       
   148     * Reads the data of the object from the stream store
       
   149     *
       
   150     * @since    3.0
       
   151     * @param    aContext : a CDRMDomainContext class to internalize to
       
   152     *                      with the domain id set to the requested id
       
   153     * @return   The function leaves with Symbian OS error code if an
       
   154     *           error occurs
       
   155     */
       
   156     void FetchDomainContextL( CDRMDomainContext& aContext ) const;
       
   157     
       
   158     /**
       
   159     * FetchDomainContextL
       
   160     * 
       
   161     * Reads the data of the object from the stream
       
   162     *
       
   163     * @since    3.0
       
   164     * @param    aContext : a CDRMDomainContext class to internalize to
       
   165     *                      with the domain id set to the requested id
       
   166     * @param    aStream : stream to read from
       
   167     * @return   The function leaves with Symbian OS error code if an
       
   168     *           error occurs
       
   169     */
       
   170     void FetchDomainContextL( CDRMDomainContext& aContext, 
       
   171                               const TInt32& aStream ) const;    
       
   172 
       
   173     /**
       
   174     * DeleteDomainContextL
       
   175     * 
       
   176     * Deletes the data of the object from the stream store
       
   177     *
       
   178     * @since    3.0
       
   179     * @param    aDomainID : the domain to delete
       
   180     * @return   The function leaves with Symbian OS error code if an
       
   181     *           error occurs
       
   182     */
       
   183     void DeleteDomainContextL( const TDesC8& aDomainID );
       
   184 
       
   185 
       
   186     /**
       
   187     * StoreRightsIssuerContextL
       
   188     * 
       
   189     * Writes the data of the rights issuer context to the stream store
       
   190     *
       
   191     * @since    3.0
       
   192     * @param    aPermission : CDRMPermission class to externalize
       
   193     * @return   The function leaves with Symbian OS error code if an
       
   194     *           error occurs
       
   195     */
       
   196     void StoreRightsIssuerContextL( const CDRMRIContext& aContext );    
       
   197     
       
   198     /**
       
   199     * FetchRightsIssuerContextL
       
   200     * 
       
   201     * Reads the data of the object from the stream store
       
   202     *
       
   203     * @since    3.0
       
   204     * @param    aContext : a CDRMRightsIssuerContext class to internalize to
       
   205     *                      with the domain id set to the requested id
       
   206     * @return   The function leaves with Symbian OS error code if an
       
   207     *           error occurs
       
   208     */
       
   209     void FetchRightsIssuerContextL( CDRMRIContext& aContext ) const;
       
   210 
       
   211     /**
       
   212     * FetchRightsIssuerContextL
       
   213     * 
       
   214     * Reads the data of the object from the stream
       
   215     *
       
   216     * @since    3.0
       
   217     * @param    aContext : a CDRMRightsIssuerContext class to internalize to
       
   218     *                      with the domain id set to the requested id
       
   219     * @param    aStream : stream to read from
       
   220     * @return   The function leaves with Symbian OS error code if an
       
   221     *           error occurs
       
   222     */
       
   223     void FetchRightsIssuerContextL( CDRMRIContext& aContext, 
       
   224                                     const TInt32& aStream ) const;
       
   225     /**
       
   226     * DeleteRightsIssuerContextL
       
   227     * 
       
   228     * Deletes the data of the object from the stream store
       
   229     *
       
   230     * @since    3.0
       
   231     * @param    aRightsIssuerID : the rights issuer to delete
       
   232     * @return   The function leaves with Symbian OS error code if an
       
   233     *           error occurs
       
   234     */
       
   235     void DeleteRightsIssuerContextL( const TDesC8& aRightsIssuerID );
       
   236 
       
   237                            
       
   238     /**
       
   239     * WhiteListURLExistsL
       
   240     * 
       
   241     * Goes through all the Rights Issuer contexts and checks if the given URL
       
   242     * is in one of them.
       
   243     *
       
   244     * @since    3.0
       
   245     * @param    aPointerArray : return value pointer array of the permissions
       
   246     * @return   The function leaves with Symbian OS error code if an
       
   247     *           error occurs
       
   248     */
       
   249     TBool WhiteListURLExistsL( const TDesC8& aRightsIssuerURL );
       
   250 
       
   251     
       
   252     /**
       
   253     * DeleteExpiredDomainContextsL
       
   254     * 
       
   255     * Deletes the expired domain contexts
       
   256     *
       
   257     * @since    3.0
       
   258     * @param    aTime : the reference time, all contexts before this time will be
       
   259     *                   deleted
       
   260     * @return   The function leaves with Symbian OS error code if an
       
   261     *           error occurs
       
   262     */
       
   263     void DeleteExpiredDomainContextsL( const TTime& aTime );
       
   264  
       
   265  
       
   266     /**
       
   267     * DeleteExpiredRightsIssuerContextsL
       
   268     * 
       
   269     * Deletes the expired domain contexts
       
   270     *
       
   271     * @since    3.0
       
   272     * @param    aTime : the reference time, all contexts before this time will be
       
   273     *                   deleted
       
   274     * @return   The function leaves with Symbian OS error code if an
       
   275     *           error occurs
       
   276     */
       
   277     void DeleteExpiredRightsIssuerContextsL( const TTime& aTime );
       
   278     
       
   279     /**
       
   280     *
       
   281     * DeleteAllL
       
   282     *
       
   283     * Deletes all stored RI and Domain contexts
       
   284     *
       
   285     * @since    3.0
       
   286     * @param    aRightsIssuerContextFile: Full pathname of the ri context file
       
   287     * @param    aDomainContextFile: Full pathname of the domain context file
       
   288     *
       
   289     * @return   The function leaves with Symbian OS error code if an
       
   290     *           error occurs
       
   291     *
       
   292     */
       
   293     void DeleteAllL( const TFileName& aRightsIssuerContextFile, 
       
   294                      const TFileName& aDomainContextFile );
       
   295 
       
   296     /**
       
   297     *
       
   298     * FetchAllRightsIssuerContextsL
       
   299     *
       
   300     * Retrieves all stored RI contexts in a pointer array
       
   301     *
       
   302     * @since    3.2
       
   303     * @param    aContexts: RPointerArray for storage of the RI contexts
       
   304     *
       
   305     * @return   The function leaves with Symbian OS error code if an
       
   306     *           error occurs
       
   307     *
       
   308     */
       
   309     void FetchAllRightsIssuerContextsL( RPointerArray<CDRMRIContext>& aContexts) const;
       
   310 
       
   311     /**
       
   312     *
       
   313     * UpdateRightsIssuerContextL
       
   314     *
       
   315     * Updates the metering status of the RI context
       
   316     *
       
   317     * @since    3.2
       
   318     * @param    aContext: The RI context which has the updated data
       
   319     *
       
   320     * @return   The function leaves with Symbian OS error code if an
       
   321     *           error occurs
       
   322     *
       
   323     */
       
   324     void UpdateRightsIssuerContextL( const CDRMRIContext& aContext );  
       
   325 
       
   326 private:
       
   327 
       
   328     /**
       
   329     * CreateAndInitializeRIStoreL
       
   330     * 
       
   331     * Writes the data of index into the store root
       
   332     *
       
   333     * @since    3.0
       
   334     * @param    aRightsStore : Full path filename of the ri context store    
       
   335     * @return   The function leaves with Symbian OS error code if an
       
   336     *           error occurs
       
   337     */
       
   338     void CreateAndInitializeRIStoreL( const TFileName& aRIStore );
       
   339 
       
   340     /**
       
   341     * CreateAndInitializeDomainStoreL
       
   342     * 
       
   343     * Writes the data of index into the store root
       
   344     *
       
   345     * @since    3.0
       
   346     * @param    aRightsStore : Full path filename of the domain context store    
       
   347     * @return   The function leaves with Symbian OS error code if an
       
   348     *           error occurs
       
   349     */
       
   350     void CreateAndInitializeDomainStoreL( const TFileName& aDomainStore );
       
   351 
       
   352     /**
       
   353     * StoreDomainIndexL
       
   354     * 
       
   355     * Writes the data of index into the store root
       
   356     *
       
   357     * @since    3.0
       
   358     * @return   The function leaves with Symbian OS error code if an
       
   359     *           error occurs
       
   360     */
       
   361     void StoreDomainIndexL( RWriteStream& aStream ) const;
       
   362     
       
   363     /**
       
   364     * FetchDomainIndexL
       
   365     * 
       
   366     * Reads the data of the index from the store root
       
   367     *
       
   368     * @since    3.0
       
   369     * @return   The function leaves with Symbian OS error code if an
       
   370     *           error occurs
       
   371     */
       
   372     void FetchDomainIndexL();
       
   373 
       
   374     /**
       
   375     * StoreRightsIssuerIndexL
       
   376     * 
       
   377     * Writes the data of index into the store root
       
   378     *
       
   379     * @since    3.0
       
   380     * @return   The function leaves with Symbian OS error code if an
       
   381     *           error occurs
       
   382     */
       
   383     void StoreRightsIssuerIndexL( RWriteStream& aStream ) const;
       
   384     
       
   385     /**
       
   386     * FetchRightsIssuerIndexL
       
   387     * 
       
   388     * Reads the data of the index from the store root
       
   389     *
       
   390     * @since    3.0
       
   391     * @return   The function leaves with Symbian OS error code if an
       
   392     *           error occurs
       
   393     */
       
   394     void FetchRightsIssuerIndexL();
       
   395     
       
   396     /*
       
   397     * Default Constructor
       
   398     */ 
       
   399     CDRMContextDB( RFs& aFileServer );
       
   400 
       
   401     /*
       
   402     * 2nd phase Constructor
       
   403     *
       
   404     * @param    aRightsStore : Full path filename of the rights store
       
   405     */ 
       
   406     void ConstructL( const TFileName& aRightsIssuerContextFile, 
       
   407                      const TFileName& aDomainContextFile );
       
   408 
       
   409 private:
       
   410 
       
   411     NONSHARABLE_CLASS( TContextIndex )
       
   412         {
       
   413     public:
       
   414         
       
   415         TBuf8<SHA1_HASH> iContextID;
       
   416         TInt32 iStreamID;
       
   417         
       
   418         static TInt Compare( const TContextIndex& aFirst,
       
   419                              const TContextIndex& aSecond )
       
   420             {
       
   421             return aFirst.iContextID.Compare( aSecond.iContextID );
       
   422             };
       
   423             
       
   424         static TBool Match( const TContextIndex& aFirst,
       
   425                             const TContextIndex& aSecond )
       
   426             {
       
   427             if( aFirst.iContextID.Compare( aSecond.iContextID ) )
       
   428                 {
       
   429                 return EFalse;
       
   430                 }
       
   431             return ETrue;    
       
   432             };    
       
   433             
       
   434         };
       
   435 
       
   436     RFs& iFileServer;
       
   437 
       
   438     // File stores
       
   439     CPermanentFileStore* iDomainStore;
       
   440     CPermanentFileStore* iRightsIssuerStore;
       
   441     
       
   442     // Index arrays
       
   443     RArray<TContextIndex> iDomainArray;
       
   444     RArray<TContextIndex> iRightsIssuerArray;
       
   445    
       
   446     // Some index data
       
   447     };
       
   448 
       
   449 #endif      // DRMCONTEXTDB_H
       
   450             
       
   451 // End of File