omadrm/drmengine/ro/src/DrmRights.cpp
changeset 0 95b198f216e5
child 12 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002 - 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:  Implementation of common DRM operations
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 
       
    21 #include "DrmAsset.h"
       
    22 #include "DrmRights.h"
       
    23 #include "DrmPermission.h"
       
    24 #include "DrmConstraint.h"
       
    25 
       
    26 // EXTERNAL DATA STRUCTURES
       
    27 
       
    28 // EXTERNAL FUNCTION PROTOTYPES
       
    29 
       
    30 // CONSTANTS
       
    31 
       
    32 // MACROS
       
    33 
       
    34 // LOCAL CONSTANTS AND MACROS
       
    35 
       
    36 _LIT(KNullDate,"00000000:000000.000000");
       
    37 
       
    38 // MODULE DATA STRUCTURES
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 
       
    42 // FORWARD DECLARATIONS
       
    43 
       
    44 // ============================= LOCAL FUNCTIONS ===============================
       
    45 
       
    46 // ============================ MEMBER FUNCTIONS ===============================
       
    47 
       
    48 // -----------------------------------------------------------------------------
       
    49 // CDRMRightsConstraints::CDRMRightsConstraints
       
    50 // Default constructor
       
    51 // -----------------------------------------------------------------------------
       
    52 EXPORT_C CDRMRightsConstraints::CDRMRightsConstraints(void)
       
    53     {
       
    54     iConstraint = NULL;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CDRMRightsConstraints::ConstructL
       
    59 // Symbian 2nd phase constructor can leave.
       
    60 // -----------------------------------------------------------------------------
       
    61 EXPORT_C void CDRMRightsConstraints::ConstructL(void)
       
    62     {
       
    63     iConstraint = CDRMConstraint::NewL();
       
    64     }
       
    65 
       
    66 // -----------------------------------------------------------------------------
       
    67 // CDRMRightsConstraints::NewL
       
    68 // Two-phased constructor.
       
    69 // -----------------------------------------------------------------------------
       
    70 EXPORT_C CDRMRightsConstraints* CDRMRightsConstraints::NewL(void)
       
    71     {
       
    72     CDRMRightsConstraints* self = new (ELeave) CDRMRightsConstraints;
       
    73     CleanupStack::PushL(self);
       
    74     self->ConstructL();
       
    75     CleanupStack::Pop(self);
       
    76     return self;
       
    77     }
       
    78 
       
    79 // Destructor
       
    80 EXPORT_C CDRMRightsConstraints::~CDRMRightsConstraints(void)
       
    81     {
       
    82     if (iConstraint) delete iConstraint;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CDRMRightsConstraints::FullRights
       
    87 // The FullRights function checks if the object contains any restrictions
       
    88 // or if usage is unconstrained.
       
    89 // -----------------------------------------------------------------------------
       
    90 EXPORT_C TBool CDRMRightsConstraints::FullRights(void)
       
    91     {
       
    92     return iConstraint->iActiveConstraints == EConstraintNone ? ETrue : EFalse;
       
    93     }
       
    94 
       
    95 // -----------------------------------------------------------------------------
       
    96 // CDRMRightsConstraints::IsPreview
       
    97 // The function checks if the object represents a preview constraint.
       
    98 // -----------------------------------------------------------------------------
       
    99 EXPORT_C TBool CDRMRightsConstraints::IsPreview(void)
       
   100     {
       
   101     if ((iConstraint->iActiveConstraints & EConstraintCounter) &&
       
   102         iConstraint->iOriginalCounter == 1)
       
   103         {
       
   104         return ETrue;
       
   105         }
       
   106     else
       
   107         {
       
   108         return EFalse;
       
   109         }
       
   110     }
       
   111 
       
   112 // -----------------------------------------------------------------------------
       
   113 // CDRMRightsConstraints::GetConstraintInfo
       
   114 // This function checks the expiration and the constraints of the object and
       
   115 // returns the prioryty value.
       
   116 // -----------------------------------------------------------------------------
       
   117 EXPORT_C void CDRMRightsConstraints::SetConstraint(CDRMConstraint& aConstraint)
       
   118     {
       
   119     TInt error = KErrNone;
       
   120     if( !iConstraint )
       
   121         {
       
   122         TRAP( error, iConstraint = CDRMConstraint::NewL());
       
   123         if( error )
       
   124             {
       
   125             return;
       
   126             }
       
   127         }
       
   128     TRAP( error, iConstraint->DuplicateL( aConstraint ) );
       
   129     }
       
   130 
       
   131 // -----------------------------------------------------------------------------
       
   132 // CDRMRightsConstraints::GetConstraintInfo
       
   133 // This function checks the expiration and the constraints of the object and
       
   134 // returns the prioryty value.
       
   135 // -----------------------------------------------------------------------------
       
   136 EXPORT_C TInt CDRMRightsConstraints::GetConstraintInfo(
       
   137     TUint32& aExpiration,
       
   138     TUint32& aConstType)
       
   139     {
       
   140     TTime currentTime;
       
   141     TTime time;
       
   142     TTimeIntervalSeconds interval;
       
   143     TTimeIntervalSeconds diff;
       
   144     TInt result = KErrNone;
       
   145     currentTime.HomeTime();
       
   146     TUint32 counter = 0;
       
   147     TUint32 originalCounter = 0;
       
   148     TInt priorValue = 0;
       
   149     aConstType = NULL;
       
   150 
       
   151     aExpiration = CDRMRights::EValidRights;
       
   152 
       
   153     if ( FullRights() )
       
   154         {
       
   155         aConstType = CDRMRights::ENoConstraints;
       
   156         return ENoConstraints * aExpiration;
       
   157         }
       
   158 
       
   159     result = GetEndTime(time);
       
   160     if (result == KErrNone)
       
   161         {
       
   162         aConstType |= CDRMRights::ETimeBased;
       
   163         if ( time < currentTime )
       
   164             {
       
   165             aExpiration = CDRMRights::EExpiredRights;
       
   166             }
       
   167         }
       
   168 
       
   169     result = GetStartTime(time);
       
   170     if (result == KErrNone && aExpiration != CDRMRights::EExpiredRights)
       
   171         {
       
   172         aConstType |= CDRMRights::ETimeBased;
       
   173         if ( time > currentTime )
       
   174             {
       
   175             aExpiration = CDRMRights::EFutureRights;
       
   176             }
       
   177         }
       
   178 
       
   179     result = GetInterval(interval);
       
   180     if(result == KErrNone && aExpiration != CDRMRights::EExpiredRights)
       
   181         {
       
   182         result = GetIntervalStart(time);
       
   183         if(result == KErrNone)
       
   184             {
       
   185             aConstType |= CDRMRights::ETimeBased;
       
   186             currentTime.SecondsFrom(time, diff);
       
   187             if (diff.Int() < 0)
       
   188                 {
       
   189                 aExpiration = CDRMRights::EFutureRights;
       
   190                 }
       
   191             else if ( interval < diff )
       
   192                 {
       
   193                 aExpiration = CDRMRights::EExpiredRights;
       
   194                 }
       
   195             }
       
   196         else
       
   197             {
       
   198             aConstType |= CDRMRights::EInActiveInterval;
       
   199             }
       
   200         }
       
   201     result = GetCounters( counter , originalCounter );
       
   202     if (result == KErrNone)
       
   203         {
       
   204         aConstType |= CDRMRights::ECountBased;
       
   205         if ( counter == 0 )
       
   206             {
       
   207             aExpiration = CDRMRights::EExpiredRights;
       
   208             }
       
   209         }
       
   210     result = GetTimedCounters( counter , originalCounter );
       
   211     if (result == KErrNone)
       
   212         {
       
   213         aConstType |= CDRMRights::ECountBased;
       
   214         if ( counter == 0 )
       
   215             {
       
   216             aExpiration = CDRMRights::EExpiredRights;
       
   217             }
       
   218         }
       
   219     result = GetAccumulated(interval);
       
   220     if(result == KErrNone && aExpiration != CDRMRights::EExpiredRights)
       
   221         {
       
   222         aConstType |= CDRMRights::ETimeBased | CDRMRights::ETimeIsAccumulatedTime;
       
   223         if (interval.Int() == 0)
       
   224             {
       
   225             aExpiration = CDRMRights::EExpiredRights;
       
   226             }
       
   227         }
       
   228     if (!aConstType)
       
   229         {
       
   230         return CDRMRights::EInvalidRights;
       
   231         }
       
   232 
       
   233     if ( (aConstType & CDRMRights::ECountBased) &&
       
   234         !(aConstType & CDRMRights::EInActiveInterval) &&
       
   235         !(aConstType & CDRMRights::ETimeBased) )
       
   236         {
       
   237         priorValue = ECount * aExpiration;
       
   238         }
       
   239     else if ( (aConstType & CDRMRights::ECountBased) &&
       
   240         (aConstType & CDRMRights::EInActiveInterval) &&
       
   241         !(aConstType & CDRMRights::ETimeBased) )
       
   242         {
       
   243         priorValue = EIntervalCount * aExpiration;
       
   244         }
       
   245     else if ( (aConstType & CDRMRights::ECountBased) &&
       
   246         (aConstType & CDRMRights::EInActiveInterval) &&
       
   247         (aConstType & CDRMRights::ETimeBased) )
       
   248         {
       
   249         priorValue = ETimeIntervalCount * aExpiration;
       
   250         }
       
   251     else if ( (aConstType & CDRMRights::ECountBased) &&
       
   252         !(aConstType & CDRMRights::EInActiveInterval) &&
       
   253         (aConstType & CDRMRights::ETimeBased) )
       
   254         {
       
   255         priorValue = ETimeCount * aExpiration;
       
   256         }
       
   257     else if ( !(aConstType & CDRMRights::ECountBased) &&
       
   258         (aConstType & CDRMRights::EInActiveInterval) &&
       
   259         !(aConstType & CDRMRights::ETimeBased) )
       
   260         {
       
   261         priorValue = EInterval * aExpiration;
       
   262         }
       
   263     else if ( !(aConstType & CDRMRights::ECountBased) &&
       
   264         (aConstType & CDRMRights::EInActiveInterval) &&
       
   265         (aConstType & CDRMRights::ETimeBased) )
       
   266         {
       
   267         priorValue = ETimeInterval * aExpiration;
       
   268         }
       
   269     else if ( !(aConstType & CDRMRights::ECountBased) &&
       
   270         !(aConstType & CDRMRights::EInActiveInterval) &&
       
   271         (aConstType & CDRMRights::ETimeBased) )
       
   272         {
       
   273         priorValue = ETime * aExpiration;
       
   274         }
       
   275 
       
   276     return priorValue;
       
   277     }
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CDRMRightsConstraints::GetExpirationDetails
       
   281 // The function returns the end time and amount of counts left of the object.
       
   282 // -----------------------------------------------------------------------------
       
   283 EXPORT_C TInt CDRMRightsConstraints::GetExpirationDetails(
       
   284     TTime& aEndTime,
       
   285     TInt& aCountsLeft)
       
   286     {
       
   287     TTime endTime;
       
   288     endTime.Set(KNullDate);
       
   289     TTimeIntervalSeconds interval;
       
   290     TTime intervalStart;
       
   291     intervalStart.Set(KNullDate);
       
   292     TTime intervalEnd;
       
   293     intervalEnd.Set(KNullDate);
       
   294 
       
   295     TUint32 counter = 0;
       
   296     TUint32 originalCounter = 0;
       
   297 
       
   298     TBool isEndTime = EFalse;
       
   299     TBool isInterval = EFalse;
       
   300     TBool isCount = EFalse;
       
   301 
       
   302     if (GetCounters(counter, originalCounter) == KErrNone)
       
   303         {
       
   304         isCount = ETrue;
       
   305         aCountsLeft = counter;
       
   306         }
       
   307     else
       
   308         {
       
   309         aCountsLeft = -1;
       
   310         }
       
   311     if (GetEndTime(endTime) == KErrNone)
       
   312         {
       
   313         isEndTime = ETrue;
       
   314         }
       
   315     if (GetIntervalStart(intervalStart) == KErrNone)
       
   316         {
       
   317         isInterval = ETrue;
       
   318         GetInterval(interval);
       
   319         intervalEnd = intervalStart + interval;
       
   320         }
       
   321     if (isInterval && isEndTime)
       
   322         {
       
   323         if (intervalEnd > endTime)
       
   324             {
       
   325             aEndTime = endTime;
       
   326             }
       
   327         else
       
   328             {
       
   329             aEndTime = intervalEnd;
       
   330             }
       
   331         }
       
   332     else if (isInterval)
       
   333         {
       
   334         aEndTime = intervalEnd;
       
   335         }
       
   336     else if (isEndTime)
       
   337         {
       
   338         aEndTime = endTime;
       
   339         }
       
   340     else if (!isCount)
       
   341         {
       
   342         // The object contains either a full or an inactive interval rights
       
   343         aEndTime.Set(KNullDate);
       
   344         aCountsLeft = -1;
       
   345         }
       
   346     return KErrNone;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // CDRMRightsConstraints::GetCounters
       
   351 // This function returns the current value of the count restriction and
       
   352 // original value of the count restriction.
       
   353 // -----------------------------------------------------------------------------
       
   354 EXPORT_C TInt CDRMRightsConstraints::GetCounters(
       
   355     TUint32& aCounter,
       
   356     TUint32& aOriginalCounter)
       
   357     {
       
   358     if (iConstraint->iActiveConstraints & EConstraintCounter)
       
   359         {
       
   360         aCounter = iConstraint->iCounter;
       
   361         aOriginalCounter = iConstraint->iOriginalCounter;
       
   362         return KErrNone;
       
   363         }
       
   364     else
       
   365         {
       
   366         return CDRMRights::ENoRights;
       
   367         }
       
   368     }
       
   369 
       
   370 // -----------------------------------------------------------------------------
       
   371 // CDRMRightsConstraints::GetCounters
       
   372 // This function returns the current value of the count restriction and
       
   373 // original value of the count restriction.
       
   374 // -----------------------------------------------------------------------------
       
   375 EXPORT_C TInt CDRMRightsConstraints::GetTimedCounters(
       
   376     TUint32& aCounter,
       
   377     TUint32& aOriginalCounter)
       
   378     {
       
   379     if (iConstraint->iActiveConstraints & EConstraintTimedCounter)
       
   380         {
       
   381         aCounter = iConstraint->iTimedCounter;
       
   382         aOriginalCounter = iConstraint->iOriginalCounter;
       
   383         return KErrNone;
       
   384         }
       
   385     else
       
   386         {
       
   387         return CDRMRights::ENoRights;
       
   388         }
       
   389     }
       
   390 
       
   391 // -----------------------------------------------------------------------------
       
   392 // CDRMRightsConstraints::GetStartTime
       
   393 //
       
   394 // This function returns the time when the constraint becomes valid or has
       
   395 // become valid.
       
   396 //
       
   397 // Cases:
       
   398 // 1. If an active interval is present, that time is always the correct start
       
   399 //    time
       
   400 // 2. If start time is defined that is the start time
       
   401 // 3. No active interval or start time defined CDRMRights::ENoRights
       
   402 //
       
   403 // -----------------------------------------------------------------------------
       
   404 EXPORT_C TInt CDRMRightsConstraints::GetStartTime(
       
   405     TTime& aStartTime)
       
   406     {
       
   407     // Activated interval is always the same or later than
       
   408     // the start time of the start-end
       
   409 
       
   410     if (iConstraint->iActiveConstraints & EConstraintInterval &&
       
   411         (iConstraint->iIntervalStart != Time::NullTTime() ) )
       
   412         {
       
   413         aStartTime = iConstraint->iIntervalStart;
       
   414         }
       
   415     else if (iConstraint->iActiveConstraints & EConstraintStartTime)
       
   416         {
       
   417         aStartTime = iConstraint->iStartTime;
       
   418         }
       
   419     else
       
   420         {
       
   421         return CDRMRights::ENoRights;
       
   422         }
       
   423     return KErrNone;
       
   424     }
       
   425 
       
   426 // -----------------------------------------------------------------------------
       
   427 // CDRMRightsConstraints::GetEndTime
       
   428 //
       
   429 // This function returns the time when the constraint will become invalid
       
   430 //
       
   431 // Cases:
       
   432 // 1. If both end time and activated interval is present the one which is closer
       
   433 //    to the present time will be chosen
       
   434 // 2. If only end time is available, that is returned
       
   435 // 3. If only activated interval is available, that is returned
       
   436 // 4. Otherwise CDRMRights::ENoRights
       
   437 //
       
   438 // -----------------------------------------------------------------------------
       
   439 EXPORT_C TInt CDRMRightsConstraints::GetEndTime(
       
   440     TTime& aEndTime)
       
   441     {
       
   442     // If both end time and interval have been activated
       
   443     // take the one which is closer
       
   444 
       
   445     if ((iConstraint->iActiveConstraints & EConstraintEndTime) &&
       
   446         (iConstraint->iActiveConstraints & EConstraintInterval) &&
       
   447         (iConstraint->iIntervalStart != Time::NullTTime() ) )
       
   448         {
       
   449         if( iConstraint->iEndTime <= (iConstraint->iIntervalStart +
       
   450                                       iConstraint->iInterval) )
       
   451             {
       
   452             aEndTime = iConstraint->iEndTime;
       
   453             }
       
   454         else
       
   455             {
       
   456             aEndTime = (iConstraint->iIntervalStart +
       
   457                         iConstraint->iInterval);
       
   458             }
       
   459         }
       
   460     else if (iConstraint->iActiveConstraints & EConstraintEndTime)
       
   461         {
       
   462         aEndTime = iConstraint->iEndTime;
       
   463         }
       
   464     else if (iConstraint->iActiveConstraints & EConstraintInterval &&
       
   465              (iConstraint->iIntervalStart != Time::NullTTime() ) )
       
   466         {
       
   467         aEndTime = (iConstraint->iIntervalStart +
       
   468                     iConstraint->iInterval);
       
   469         }
       
   470     else
       
   471         {
       
   472         return CDRMRights::ENoRights;
       
   473         }
       
   474     return KErrNone;
       
   475     }
       
   476 
       
   477 // -----------------------------------------------------------------------------
       
   478 // CDRMRightsConstraints::GetInterval
       
   479 // This function returns the interval time constraint
       
   480 // -----------------------------------------------------------------------------
       
   481 EXPORT_C TInt CDRMRightsConstraints::GetInterval(
       
   482     TTimeIntervalSeconds& aInterval)
       
   483     {
       
   484     if (iConstraint->iActiveConstraints & EConstraintInterval)
       
   485         {
       
   486         aInterval = iConstraint->iInterval;
       
   487         return KErrNone;
       
   488         }
       
   489     else
       
   490         {
       
   491         return CDRMRights::ENoRights;
       
   492         }
       
   493     }
       
   494 
       
   495 // -----------------------------------------------------------------------------
       
   496 // CDRMRightsConstraints::GetIntervalStart
       
   497 // This function returns the start of the interval time constraint
       
   498 // -----------------------------------------------------------------------------
       
   499 EXPORT_C TInt CDRMRightsConstraints::GetIntervalStart(
       
   500     TTime& aIntervalStart)
       
   501     {
       
   502     if (iConstraint->iActiveConstraints & EConstraintInterval &&
       
   503         iConstraint->iIntervalStart != Time::NullTTime())
       
   504         {
       
   505         aIntervalStart = iConstraint->iIntervalStart;
       
   506         return KErrNone;
       
   507         }
       
   508     else
       
   509         {
       
   510         return CDRMRights::ENoRights;
       
   511         }
       
   512     }
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CDRMRightsConstraints::GetAccumulated
       
   516 // This function returns the accumulated time constraint
       
   517 // -----------------------------------------------------------------------------
       
   518 EXPORT_C TInt CDRMRightsConstraints::GetAccumulated(
       
   519     TTimeIntervalSeconds& aAccumulated)
       
   520     {
       
   521     if (iConstraint->iActiveConstraints & EConstraintAccumulated)
       
   522         {
       
   523         aAccumulated = iConstraint->iAccumulatedTime;
       
   524         return KErrNone;
       
   525         }
       
   526     else
       
   527         {
       
   528         return CDRMRights::ENoRights;
       
   529         }
       
   530     }
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CDRMRightsConstraints::GetCounters
       
   534 // This function returns the current value of the count restriction and
       
   535 // original value of the count restriction.
       
   536 // -----------------------------------------------------------------------------
       
   537 EXPORT_C TInt CDRMRightsConstraints::SetCounters(
       
   538     TUint32 aCounter,
       
   539     TUint32 aOriginalCounter)
       
   540     {
       
   541     iConstraint->iCounter = aCounter;
       
   542     iConstraint->iOriginalCounter = aOriginalCounter;
       
   543     iConstraint->iActiveConstraints |= EConstraintCounter;
       
   544     return KErrNone;
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // CDRMRightsConstraints::SetStartTime
       
   549 // This function sets the start time constraint
       
   550 // -----------------------------------------------------------------------------
       
   551 EXPORT_C TInt CDRMRightsConstraints::SetStartTime(
       
   552     TTime aStartTime)
       
   553     {
       
   554     iConstraint->iStartTime = aStartTime;
       
   555     iConstraint->iActiveConstraints |= EConstraintStartTime;
       
   556     return KErrNone;
       
   557     }
       
   558 
       
   559 // -----------------------------------------------------------------------------
       
   560 // CDRMRightsConstraints::SetEndTime
       
   561 // This function sets the end time constraint
       
   562 // -----------------------------------------------------------------------------
       
   563 EXPORT_C TInt CDRMRightsConstraints::SetEndTime(
       
   564     TTime aEndTime)
       
   565     {
       
   566     iConstraint->iEndTime = aEndTime;
       
   567     iConstraint->iActiveConstraints |= EConstraintEndTime;
       
   568     return KErrNone;
       
   569     }
       
   570 
       
   571 // -----------------------------------------------------------------------------
       
   572 // CDRMRightsConstraints::SetInterval
       
   573 // This function sets the interval time constraint
       
   574 // -----------------------------------------------------------------------------
       
   575 EXPORT_C TInt CDRMRightsConstraints::SetInterval(
       
   576     TTimeIntervalSeconds aInterval)
       
   577     {
       
   578     iConstraint->iInterval = aInterval;
       
   579     iConstraint->iActiveConstraints |= EConstraintInterval;
       
   580     return KErrNone;
       
   581     }
       
   582 
       
   583 // -----------------------------------------------------------------------------
       
   584 // CDRMRightsConstraints::SetIntervalStart
       
   585 // This function sets the start of the interval time constraint
       
   586 // -----------------------------------------------------------------------------
       
   587 EXPORT_C TInt CDRMRightsConstraints::SetIntervalStart(
       
   588     TTime aStartTime)
       
   589     {
       
   590     iConstraint->iIntervalStart = aStartTime;
       
   591     iConstraint->iActiveConstraints |= EConstraintInterval;
       
   592     return KErrNone;
       
   593     }
       
   594 
       
   595 // -----------------------------------------------------------------------------
       
   596 // CDRMRightsConstraints::GetConstraint
       
   597 // -----------------------------------------------------------------------------
       
   598 EXPORT_C CDRMConstraint& CDRMRightsConstraints::GetConstraint(void)
       
   599     {
       
   600     return *iConstraint;
       
   601     }
       
   602 
       
   603 // -----------------------------------------------------------------------------
       
   604 // CDRMRightsConstraints::operator=
       
   605 // Assignment operator.
       
   606 // -----------------------------------------------------------------------------
       
   607 EXPORT_C CDRMRightsConstraints& CDRMRightsConstraints::operator=(
       
   608     CDRMRightsConstraints& aConstraint)
       
   609     {
       
   610     if (iConstraint)
       
   611         {
       
   612         delete iConstraint;
       
   613         iConstraint = NULL;
       
   614         }
       
   615     TRAP_IGNORE( iConstraint = CDRMConstraint::NewL() );
       
   616     if (iConstraint)
       
   617         {
       
   618         TRAP_IGNORE( iConstraint->DuplicateL( aConstraint.GetConstraint() ) );
       
   619         }
       
   620 
       
   621     return *this;
       
   622     }
       
   623 
       
   624 // -----------------------------------------------------------------------------
       
   625 // CDRMRights::CDRMRights
       
   626 // Default constructor.
       
   627 // -----------------------------------------------------------------------------
       
   628 EXPORT_C CDRMRights::CDRMRights(void):
       
   629     iAsset(NULL),
       
   630     iPermission(NULL)
       
   631     {
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // CDRMRights::ConstructL
       
   636 // Symbian 2nd phase constructor can leave.
       
   637 // -----------------------------------------------------------------------------
       
   638 EXPORT_C void CDRMRights::ConstructL(void)
       
   639     {
       
   640     iPermission = CDRMPermission::NewL();
       
   641     iAsset = CDRMAsset::NewL();
       
   642     }
       
   643 
       
   644 // -----------------------------------------------------------------------------
       
   645 // CDRMRights::NewL
       
   646 // Two-phased constructor.
       
   647 // -----------------------------------------------------------------------------
       
   648 EXPORT_C CDRMRights* CDRMRights::NewL(void)
       
   649     {
       
   650     CDRMRights* self = new (ELeave) CDRMRights;
       
   651     CleanupStack::PushL(self);
       
   652     self->ConstructL();
       
   653     CleanupStack::Pop(self);
       
   654     return self;
       
   655     }
       
   656 
       
   657 // Destructor
       
   658 EXPORT_C CDRMRights::~CDRMRights(void)
       
   659     {
       
   660     delete iAsset;
       
   661     delete iPermission;
       
   662     }
       
   663 
       
   664 // -----------------------------------------------------------------------------
       
   665 // CDRMRights::GetContentURI
       
   666 // This function returns the content URI of the object
       
   667 // -----------------------------------------------------------------------------
       
   668 EXPORT_C TInt CDRMRights::GetContentURI(HBufC8*& aContentURI)
       
   669     {
       
   670     TInt r;
       
   671 
       
   672     r = KErrNone;
       
   673     if (iAsset && iAsset->iUid)
       
   674         {
       
   675         aContentURI = HBufC8::NewMax(iAsset->iUid->Size());
       
   676         if (aContentURI)
       
   677             {
       
   678             *aContentURI = *iAsset->iUid;
       
   679             }
       
   680         else r = KErrNoMemory;
       
   681         }
       
   682     else
       
   683         {
       
   684         aContentURI = NULL;
       
   685         }
       
   686 
       
   687     return r;
       
   688     }
       
   689 
       
   690 // -----------------------------------------------------------------------------
       
   691 // CDRMRights::GetLocalID
       
   692 // This function returns the local ID of the object
       
   693 // -----------------------------------------------------------------------------
       
   694 EXPORT_C TUint32 CDRMRights::GetLocalID(void)
       
   695     {
       
   696     return iPermission->iUniqueID;
       
   697     }
       
   698 
       
   699 // -----------------------------------------------------------------------------
       
   700 // CDRMRights::GetAddTime
       
   701 // This function returns the time when the rights object was added to the
       
   702 // rights database.
       
   703 // -----------------------------------------------------------------------------
       
   704 EXPORT_C void CDRMRights::GetAddTime(TTime& aTime)
       
   705     {
       
   706     aTime = iPermission->iOriginalInsertTime;
       
   707     }
       
   708 
       
   709 // -----------------------------------------------------------------------------
       
   710 // CDRMRights::GetRightsInfo
       
   711 // This function checks the expiration and the constraints of the object and
       
   712 // retunrs the best constraint priority value.
       
   713 // -----------------------------------------------------------------------------
       
   714 EXPORT_C TInt CDRMRights::GetRightsInfo(
       
   715     TUint32 aConstraintSpec,
       
   716     TRestriction& aRestriction,
       
   717     TExpiration& aExpiration,
       
   718     TUint32& aConstType)
       
   719     {
       
   720     TInt r = 0;
       
   721     TBool noRights = ETrue;
       
   722 
       
   723     TUint32 playConst = NULL;
       
   724     TUint32 displayConst = NULL;
       
   725     TUint32 exeConst = NULL;
       
   726     TUint32 printConst = NULL;
       
   727 
       
   728     TUint32 playExpir = EExpiredRights;
       
   729     TUint32 displayExpir = EExpiredRights;
       
   730     TUint32 printExpir = EExpiredRights;
       
   731     TUint32 exeExpir = EExpiredRights;
       
   732 
       
   733     TInt playValue = NULL;
       
   734     TInt displayValue = NULL;
       
   735     TInt exeValue = NULL;
       
   736     TInt printValue = NULL;
       
   737     TInt compareValue = NULL;
       
   738 
       
   739     CDRMRightsConstraints* constraint = NULL;
       
   740 
       
   741     r = GetPlayRight(constraint);
       
   742     if (r && r != ENoRights)
       
   743         {
       
   744         return KErrNoMemory;
       
   745         }
       
   746     if (r == KErrNone &&
       
   747        (aConstraintSpec == CDRMRights::EPlay || aConstraintSpec == 0 ) )
       
   748         {
       
   749         noRights = EFalse;
       
   750         if (constraint->FullRights())
       
   751             {
       
   752             delete constraint;
       
   753             constraint = NULL;
       
   754             aExpiration = EValidRights;
       
   755             aConstType = ENoConstraints;
       
   756             aRestriction = EFullRights;
       
   757             return EFullRights;
       
   758             }
       
   759         else
       
   760             {
       
   761             playValue = constraint->GetConstraintInfo(playExpir, playConst);
       
   762             if (playValue > compareValue)
       
   763                 {
       
   764                 compareValue = playValue;
       
   765                 if(constraint->IsPreview())
       
   766                     {
       
   767                     aRestriction = EPreviewRights;
       
   768                     }
       
   769                 else
       
   770                     {
       
   771                     aRestriction = ERestrictedRights;
       
   772                     }
       
   773                 }
       
   774             }
       
   775         }
       
   776 
       
   777     delete constraint;
       
   778     constraint = NULL;
       
   779 
       
   780     r = GetDisplayRight(constraint);
       
   781     if (r && r != ENoRights)
       
   782         {
       
   783         return KErrNoMemory;
       
   784         }
       
   785     if (r == KErrNone &&
       
   786        (aConstraintSpec == CDRMRights::EDisplay || aConstraintSpec == 0 ) )
       
   787         {
       
   788         noRights = EFalse;
       
   789         if (constraint->FullRights())
       
   790             {
       
   791             delete constraint;
       
   792             constraint = NULL;
       
   793             aExpiration = EValidRights;
       
   794             aConstType = ENoConstraints;
       
   795             aRestriction = EFullRights;
       
   796             return EFullRights;
       
   797             }
       
   798         else
       
   799             {
       
   800             displayValue = constraint->GetConstraintInfo(displayExpir, displayConst);
       
   801             if (displayValue > compareValue)
       
   802                 {
       
   803                 compareValue = displayValue;
       
   804                 if(constraint->IsPreview())
       
   805                     {
       
   806                     aRestriction = EPreviewRights;
       
   807                     }
       
   808                 else
       
   809                     {
       
   810                     aRestriction = ERestrictedRights;
       
   811                     }
       
   812                 }
       
   813             }
       
   814         }
       
   815 
       
   816     delete constraint;
       
   817     constraint = NULL;
       
   818 
       
   819     r = GetExecuteRight(constraint);
       
   820     if (r && r != ENoRights)
       
   821         {
       
   822         return KErrNoMemory;
       
   823         }
       
   824     if (r == KErrNone &&
       
   825        (aConstraintSpec == CDRMRights::EExecute || aConstraintSpec == 0 ) )
       
   826         {
       
   827         noRights = EFalse;
       
   828         if (constraint->FullRights())
       
   829             {
       
   830             delete constraint;
       
   831             constraint = NULL;
       
   832             aExpiration = EValidRights;
       
   833             aConstType = ENoConstraints;
       
   834             aRestriction = EFullRights;
       
   835             return EFullRights;
       
   836             }
       
   837         else
       
   838             {
       
   839             exeValue = constraint->GetConstraintInfo(exeExpir, exeConst);
       
   840             if (exeValue > compareValue)
       
   841                 {
       
   842                 compareValue = exeValue;
       
   843                 if(constraint->IsPreview())
       
   844                     {
       
   845                     aRestriction = EPreviewRights;
       
   846                     }
       
   847                 else
       
   848                     {
       
   849                     aRestriction = ERestrictedRights;
       
   850                     }
       
   851                 }
       
   852             }
       
   853         }
       
   854 
       
   855     delete constraint;
       
   856     constraint = NULL;
       
   857 
       
   858     r = GetPrintRight(constraint);
       
   859     if (r && r != ENoRights)
       
   860         {
       
   861         return KErrNoMemory;
       
   862         }
       
   863     if (r == KErrNone &&
       
   864        (aConstraintSpec == CDRMRights::EPrint || aConstraintSpec == 0 ) )
       
   865         {
       
   866         noRights = EFalse;
       
   867         if (constraint->FullRights())
       
   868             {
       
   869             delete constraint;
       
   870             constraint = NULL;
       
   871             aExpiration = EValidRights;
       
   872             aConstType = ENoConstraints;
       
   873             aRestriction = EFullRights;
       
   874             return EFullRights;
       
   875             }
       
   876         else
       
   877             {
       
   878             printValue = constraint->GetConstraintInfo(printExpir, printConst);
       
   879             if (printValue > compareValue)
       
   880                 {
       
   881                 compareValue = exeValue;
       
   882                 if(constraint->IsPreview())
       
   883                     {
       
   884                     aRestriction = EPreviewRights;
       
   885                     }
       
   886                 else
       
   887                     {
       
   888                     aRestriction = ERestrictedRights;
       
   889                     }
       
   890                 }
       
   891             }
       
   892         }
       
   893 
       
   894     delete constraint;
       
   895     constraint = NULL;
       
   896 
       
   897     if (noRights)
       
   898         {
       
   899         delete constraint;
       
   900         constraint = NULL;
       
   901         aExpiration = EExpiredRights;
       
   902         return ENoRights;
       
   903         }
       
   904 
       
   905     if (aRestriction != ERestrictedRights)
       
   906         {
       
   907         aRestriction = EPreviewRights;
       
   908         }
       
   909 
       
   910     if (playExpir == EExpiredRights &&
       
   911         displayExpir == EExpiredRights &&
       
   912         printExpir == EExpiredRights &&
       
   913         exeExpir == EExpiredRights)
       
   914         {
       
   915         aExpiration = EExpiredRights;
       
   916         }
       
   917 
       
   918     if (playExpir == EFutureRights ||
       
   919         displayExpir == EFutureRights ||
       
   920         printExpir == EFutureRights ||
       
   921         exeExpir == EFutureRights)
       
   922         {
       
   923         aExpiration = EFutureRights;
       
   924         }
       
   925 
       
   926     if (playExpir == EValidRights ||
       
   927         displayExpir == EValidRights ||
       
   928         printExpir == EValidRights ||
       
   929         exeExpir == EValidRights)
       
   930         {
       
   931         aExpiration = EValidRights;
       
   932         }
       
   933 
       
   934     if (compareValue == playValue) aConstType = playConst;
       
   935     if (compareValue == displayValue) aConstType = displayConst;
       
   936     if (compareValue == exeValue) aConstType = exeConst;
       
   937     if (compareValue == printValue) aConstType = printConst;
       
   938 
       
   939     return compareValue;
       
   940     }
       
   941 
       
   942 // -----------------------------------------------------------------------------
       
   943 // CDRMRights::GetExpirationDetails
       
   944 // The function returns the end time and amount of counts left of the object.
       
   945 // -----------------------------------------------------------------------------
       
   946 EXPORT_C TInt CDRMRights::GetExpirationDetails(
       
   947     TUint32 aConstraintSpec,
       
   948     TTime& aEndTime,
       
   949     TInt& aCountsLeft)
       
   950     {
       
   951     TInt r = 0;
       
   952     CDRMRightsConstraints* constraint = NULL;
       
   953 
       
   954     TTime playEndTime;
       
   955     playEndTime.Set(KNullDate);
       
   956     TTime displayEndTime;
       
   957     displayEndTime.Set(KNullDate);
       
   958     TTime executeEndTime;
       
   959     executeEndTime.Set(KNullDate);
       
   960     TTime printEndTime;
       
   961     printEndTime.Set(KNullDate);
       
   962     TTime compareTime;
       
   963     compareTime.Set(KNullDate);
       
   964 
       
   965     TInt playCounter = 0;
       
   966     TInt displayCounter = 0;
       
   967     TInt executeCounter = 0;
       
   968     TInt printCounter = 0;
       
   969 
       
   970     TBool noRights = ETrue;
       
   971 
       
   972     aEndTime.Set(KNullDate);
       
   973     aCountsLeft  = 0;
       
   974 
       
   975     r = GetPlayRight(constraint);
       
   976     if (r == KErrNone &&
       
   977        (aConstraintSpec == CDRMRights::EPlay || aConstraintSpec == 0 ) )
       
   978         {
       
   979         noRights = EFalse;
       
   980         if (constraint->FullRights())
       
   981             {
       
   982             delete constraint;
       
   983             constraint = NULL;
       
   984             aEndTime.Set(KNullDate);
       
   985             aCountsLeft = -1;
       
   986             return KErrNone;
       
   987             }
       
   988         else
       
   989             {
       
   990             r = constraint->GetExpirationDetails(playEndTime, playCounter);
       
   991             if(playEndTime == compareTime && playCounter == -1)
       
   992                 {
       
   993                 delete constraint;
       
   994                 constraint = NULL;
       
   995                 return KErrNone;
       
   996                 }
       
   997             }
       
   998         }
       
   999 
       
  1000     delete constraint;
       
  1001     constraint = NULL;
       
  1002 
       
  1003     r = GetDisplayRight(constraint);
       
  1004     if (r == KErrNone &&
       
  1005        (aConstraintSpec == CDRMRights::EDisplay || aConstraintSpec == 0 ) )
       
  1006         {
       
  1007         noRights = EFalse;
       
  1008         if (constraint->FullRights())
       
  1009             {
       
  1010             delete constraint;
       
  1011             constraint = NULL;
       
  1012             aEndTime.Set(KNullDate);
       
  1013             aCountsLeft = -1;
       
  1014             return KErrNone;
       
  1015             }
       
  1016         else
       
  1017             {
       
  1018             r = constraint->GetExpirationDetails(displayEndTime, displayCounter);
       
  1019             if(displayEndTime == compareTime && displayCounter == -1)
       
  1020                 {
       
  1021                 delete constraint;
       
  1022                 constraint = NULL;
       
  1023                 return KErrNone;
       
  1024                 }
       
  1025             }
       
  1026         }
       
  1027 
       
  1028     delete constraint;
       
  1029     constraint = NULL;
       
  1030 
       
  1031     r = GetExecuteRight(constraint);
       
  1032     if (r == KErrNone &&
       
  1033        (aConstraintSpec == CDRMRights::EExecute || aConstraintSpec == 0 ) )
       
  1034         {
       
  1035         noRights = EFalse;
       
  1036         if (constraint->FullRights())
       
  1037             {
       
  1038             delete constraint;
       
  1039             constraint = NULL;
       
  1040             aEndTime.Set(KNullDate);
       
  1041             aCountsLeft = -1;
       
  1042             return KErrNone;
       
  1043             }
       
  1044         else
       
  1045             {
       
  1046             r = constraint->GetExpirationDetails(executeEndTime, executeCounter);
       
  1047             if(executeEndTime == compareTime && executeCounter == -1)
       
  1048                 {
       
  1049                 delete constraint;
       
  1050                 constraint = NULL;
       
  1051                 return KErrNone;
       
  1052                 }
       
  1053             }
       
  1054         }
       
  1055 
       
  1056     delete constraint;
       
  1057     constraint = NULL;
       
  1058 
       
  1059     r = GetPrintRight(constraint);
       
  1060     if (r == KErrNone &&
       
  1061        (aConstraintSpec == CDRMRights::EPrint || aConstraintSpec == 0 ) )
       
  1062         {
       
  1063         noRights = EFalse;
       
  1064         if (constraint->FullRights())
       
  1065             {
       
  1066             delete constraint;
       
  1067             constraint = NULL;
       
  1068             aEndTime.Set(KNullDate);
       
  1069             aCountsLeft = -1;
       
  1070             return KErrNone;
       
  1071             }
       
  1072         else
       
  1073             {
       
  1074             r = constraint->GetExpirationDetails(printEndTime, printCounter);
       
  1075             if(printEndTime == compareTime && printCounter == -1)
       
  1076                 {
       
  1077                 delete constraint;
       
  1078                 constraint = NULL;
       
  1079                 return KErrNone;
       
  1080                 }
       
  1081             }
       
  1082         }
       
  1083 
       
  1084     delete constraint;
       
  1085     constraint = NULL;
       
  1086 
       
  1087     if (noRights)
       
  1088         {
       
  1089         aEndTime.Set(KNullDate);
       
  1090         aCountsLeft = -1;
       
  1091         return ENoRights;
       
  1092         }
       
  1093 
       
  1094     compareTime.HomeTime();
       
  1095 
       
  1096     if (playCounter > aCountsLeft)
       
  1097         {
       
  1098         aEndTime = playEndTime;
       
  1099         aCountsLeft = playCounter;
       
  1100         }
       
  1101     if (displayCounter > aCountsLeft)
       
  1102         {
       
  1103         aEndTime = displayEndTime;
       
  1104         aCountsLeft = displayCounter;
       
  1105         }
       
  1106     if (executeCounter > aCountsLeft)
       
  1107         {
       
  1108         aEndTime = executeEndTime;
       
  1109         aCountsLeft = executeCounter;
       
  1110         }
       
  1111     if (printCounter > aCountsLeft)
       
  1112         {
       
  1113         aEndTime = printEndTime;
       
  1114         aCountsLeft = printCounter;
       
  1115         }
       
  1116 
       
  1117     if (aCountsLeft > 0 &&
       
  1118         playEndTime < compareTime && displayEndTime < compareTime &&
       
  1119         executeEndTime < compareTime && printEndTime < compareTime)
       
  1120         {
       
  1121         return KErrNone;
       
  1122         }
       
  1123 
       
  1124     if (playEndTime > aEndTime)
       
  1125         {
       
  1126         aEndTime = playEndTime;
       
  1127         aCountsLeft  = playCounter;
       
  1128         }
       
  1129     if (displayEndTime > aEndTime)
       
  1130         {
       
  1131         aEndTime = displayEndTime;
       
  1132         aCountsLeft  = displayCounter;
       
  1133         }
       
  1134     if (executeEndTime > aEndTime)
       
  1135         {
       
  1136         aEndTime = executeEndTime;
       
  1137         aCountsLeft  = executeCounter;
       
  1138         }
       
  1139     if (printEndTime > aEndTime)
       
  1140         {
       
  1141         aEndTime = printEndTime;
       
  1142         aCountsLeft  = printCounter;
       
  1143         }
       
  1144     return KErrNone;
       
  1145     }
       
  1146 
       
  1147 // -----------------------------------------------------------------------------
       
  1148 // CDRMRights::GetPlayRight
       
  1149 // This function returns the constraints associated with the play right.
       
  1150 // -----------------------------------------------------------------------------
       
  1151 EXPORT_C TInt CDRMRights::GetPlayRight(
       
  1152     CDRMRightsConstraints*& aConstraint)
       
  1153     {
       
  1154     TInt r = ENoRights;
       
  1155 
       
  1156     aConstraint = NULL;
       
  1157     if (iPermission->iAvailableRights & ERightsPlay)
       
  1158         {
       
  1159         TRAP(r, aConstraint = CDRMRightsConstraints::NewL());
       
  1160         if (r == KErrNone)
       
  1161             {
       
  1162             aConstraint->SetConstraint(*iPermission->iPlay);
       
  1163             }
       
  1164         }
       
  1165     return r;
       
  1166     }
       
  1167 
       
  1168 // -----------------------------------------------------------------------------
       
  1169 // CDRMRights::GetDisplayRight
       
  1170 // This function returns the constraints associated with the display right.
       
  1171 // -----------------------------------------------------------------------------
       
  1172 EXPORT_C TInt CDRMRights::GetDisplayRight(
       
  1173     CDRMRightsConstraints*& aConstraint)
       
  1174     {
       
  1175     TInt r = ENoRights;
       
  1176 
       
  1177     aConstraint = NULL;
       
  1178     if (iPermission->iAvailableRights & ERightsDisplay)
       
  1179         {
       
  1180         TRAP(r, aConstraint = CDRMRightsConstraints::NewL());
       
  1181         if (r == KErrNone)
       
  1182             {
       
  1183             aConstraint->SetConstraint(*iPermission->iDisplay);
       
  1184             }
       
  1185         }
       
  1186     return r;
       
  1187     }
       
  1188 
       
  1189 // -----------------------------------------------------------------------------
       
  1190 // CDRMRights::GetPrintRight
       
  1191 // This function returns the constraints associated with the print right.
       
  1192 // -----------------------------------------------------------------------------
       
  1193 EXPORT_C TInt CDRMRights::GetPrintRight(
       
  1194     CDRMRightsConstraints*& aConstraint)
       
  1195     {
       
  1196     TInt r = ENoRights;
       
  1197 
       
  1198     aConstraint = NULL;
       
  1199     if (iPermission->iAvailableRights & ERightsPrint)
       
  1200         {
       
  1201         TRAP(r, aConstraint = CDRMRightsConstraints::NewL());
       
  1202         if (r == KErrNone)
       
  1203             {
       
  1204             aConstraint->SetConstraint(*iPermission->iPrint);
       
  1205             }
       
  1206         }
       
  1207     return r;
       
  1208     }
       
  1209 
       
  1210 // -----------------------------------------------------------------------------
       
  1211 // CDRMRights::GetExecuteRight
       
  1212 // This function returns the constraints associated with the execute right.
       
  1213 // -----------------------------------------------------------------------------
       
  1214 EXPORT_C TInt CDRMRights::GetExecuteRight(
       
  1215     CDRMRightsConstraints*& aConstraint)
       
  1216     {
       
  1217     TInt r = ENoRights;
       
  1218 
       
  1219     aConstraint = NULL;
       
  1220     if (iPermission->iAvailableRights & ERightsExecute)
       
  1221         {
       
  1222         TRAP(r, aConstraint = CDRMRightsConstraints::NewL());
       
  1223         if (r == KErrNone)
       
  1224             {
       
  1225             aConstraint->SetConstraint(*iPermission->iExecute);
       
  1226             }
       
  1227         }
       
  1228     return r;
       
  1229     }
       
  1230 
       
  1231 // -----------------------------------------------------------------------------
       
  1232 // CDRMRights::SetContentURIAndLocalID
       
  1233 // This function sets the content URI and local ID of the object
       
  1234 // -----------------------------------------------------------------------------
       
  1235 EXPORT_C TInt CDRMRights::SetContentURIAndLocalID(
       
  1236     HBufC8* aContentURI,
       
  1237     TUint32 aLocalID)
       
  1238     {
       
  1239     TInt r = KErrNone;
       
  1240 
       
  1241     if (!iAsset)
       
  1242         {
       
  1243         TRAP(r, iAsset = CDRMAsset::NewL());
       
  1244         }
       
  1245 
       
  1246     if (iAsset)
       
  1247         {
       
  1248         if( iAsset->iUid )
       
  1249             {
       
  1250             delete iAsset->iUid;
       
  1251             }
       
  1252         iAsset->iUid = aContentURI;
       
  1253 
       
  1254         if ( !iPermission )
       
  1255             {
       
  1256             TRAP(r, iPermission = CDRMPermission::NewL());
       
  1257             }
       
  1258 
       
  1259         if ( iPermission )
       
  1260             {
       
  1261             iPermission->iUniqueID = aLocalID;
       
  1262             }
       
  1263         }
       
  1264 
       
  1265     return r;
       
  1266     }
       
  1267 
       
  1268 // -----------------------------------------------------------------------------
       
  1269 // CDRMRights::SetContentURI
       
  1270 // This function sets the content URI of the object
       
  1271 // -----------------------------------------------------------------------------
       
  1272 EXPORT_C TInt CDRMRights::SetContentURI(
       
  1273     HBufC8* aContentURI)
       
  1274     {
       
  1275     if (iAsset)
       
  1276         {
       
  1277         delete iAsset->iUid;
       
  1278         iAsset->iUid = aContentURI;
       
  1279         }
       
  1280 
       
  1281     return KErrNone;
       
  1282     }
       
  1283 
       
  1284 // -----------------------------------------------------------------------------
       
  1285 // CDRMRights::SetLocalID
       
  1286 // This function sets the content URI and local ID of the object
       
  1287 // -----------------------------------------------------------------------------
       
  1288 EXPORT_C TInt CDRMRights::SetLocalID(
       
  1289     TUint32 aLocalID)
       
  1290     {
       
  1291     iPermission->iUniqueID = aLocalID;
       
  1292     return KErrNone;
       
  1293     }
       
  1294 
       
  1295 // -----------------------------------------------------------------------------
       
  1296 // CDRMRights::GetAddTime
       
  1297 // This function sets the time when the rights object was added to the
       
  1298 // rights database.
       
  1299 // -----------------------------------------------------------------------------
       
  1300 EXPORT_C void CDRMRights::SetAddTime(
       
  1301     TTime aTime)
       
  1302     {
       
  1303     iPermission->iOriginalInsertTime = aTime;
       
  1304     }
       
  1305 
       
  1306 // -----------------------------------------------------------------------------
       
  1307 // CDRMRights::SetPlayRight
       
  1308 // This function sets the constraints associated with the play right.
       
  1309 // -----------------------------------------------------------------------------
       
  1310 EXPORT_C TInt CDRMRights::SetPlayRight(
       
  1311     CDRMRightsConstraints* aConstraint)
       
  1312     {
       
  1313     TInt error = KErrNone;
       
  1314 
       
  1315     if( !iPermission )
       
  1316         {
       
  1317         TRAP( error, iPermission = CDRMPermission::NewL());
       
  1318         if( error )
       
  1319             {
       
  1320             return error;
       
  1321             }
       
  1322         }
       
  1323     else if( !iPermission->iPlay )
       
  1324         {
       
  1325         TRAP( error, iPermission->iPlay = CDRMConstraint::NewL() );
       
  1326         if( error )
       
  1327             {
       
  1328             return error;
       
  1329             }
       
  1330         }
       
  1331 
       
  1332     TRAP( error, iPermission->iPlay->DuplicateL( aConstraint->GetConstraint() ) );
       
  1333     return error;
       
  1334     }
       
  1335 
       
  1336 // -----------------------------------------------------------------------------
       
  1337 // CDRMRights::SetDisplayRight
       
  1338 // This function sets the constraints associated with the display right.
       
  1339 // -----------------------------------------------------------------------------
       
  1340 EXPORT_C TInt CDRMRights::SetDisplayRight(
       
  1341     CDRMRightsConstraints* aConstraint)
       
  1342     {
       
  1343     TInt error = KErrNone;
       
  1344 
       
  1345     if( !iPermission )
       
  1346         {
       
  1347         TRAP( error, iPermission = CDRMPermission::NewL());
       
  1348         if( error )
       
  1349             {
       
  1350             return error;
       
  1351             }
       
  1352         }
       
  1353     else if( !iPermission->iDisplay )
       
  1354         {
       
  1355         TRAP( error, iPermission->iDisplay = CDRMConstraint::NewL() );
       
  1356         if( error )
       
  1357             {
       
  1358             return error;
       
  1359             }
       
  1360         }
       
  1361 
       
  1362     TRAP( error, iPermission->iDisplay->DuplicateL( aConstraint->GetConstraint() ) );
       
  1363     return error;
       
  1364     }
       
  1365 
       
  1366 // -----------------------------------------------------------------------------
       
  1367 // CDRMRights::SetPrintRight
       
  1368 // This function sets the constraints associated with the print right.
       
  1369 // -----------------------------------------------------------------------------
       
  1370 EXPORT_C TInt CDRMRights::SetPrintRight(
       
  1371     CDRMRightsConstraints* aConstraint)
       
  1372     {
       
  1373     TInt error = KErrNone;
       
  1374 
       
  1375     if( !iPermission )
       
  1376         {
       
  1377         TRAP( error, iPermission = CDRMPermission::NewL());
       
  1378         if( error )
       
  1379             {
       
  1380             return error;
       
  1381             }
       
  1382         }
       
  1383     else if( !iPermission->iPrint )
       
  1384         {
       
  1385         TRAP( error, iPermission->iPrint = CDRMConstraint::NewL() );
       
  1386         if( error )
       
  1387             {
       
  1388             return error;
       
  1389             }
       
  1390         }
       
  1391 
       
  1392     TRAP( error, iPermission->iPrint->DuplicateL( aConstraint->GetConstraint() ) );
       
  1393     return error;
       
  1394     }
       
  1395 
       
  1396 // -----------------------------------------------------------------------------
       
  1397 // CDRMRights::SetExecuteRight
       
  1398 // This function sets the constraints associated with the execute right.
       
  1399 // -----------------------------------------------------------------------------
       
  1400 EXPORT_C TInt CDRMRights::SetExecuteRight(
       
  1401     CDRMRightsConstraints* aConstraint)
       
  1402     {
       
  1403     TInt error = KErrNone;
       
  1404 
       
  1405     if( !iPermission )
       
  1406         {
       
  1407         TRAP( error, iPermission = CDRMPermission::NewL());
       
  1408         if( error )
       
  1409             {
       
  1410             return error;
       
  1411             }
       
  1412         }
       
  1413     else if( !iPermission->iExecute )
       
  1414         {
       
  1415         TRAP( error, iPermission->iExecute = CDRMConstraint::NewL() );
       
  1416         if( error )
       
  1417             {
       
  1418             return error;
       
  1419             }
       
  1420         }
       
  1421 
       
  1422     TRAP( error, iPermission->iExecute->DuplicateL( aConstraint->GetConstraint() ) );
       
  1423     return error;
       
  1424     }
       
  1425 
       
  1426 // -----------------------------------------------------------------------------
       
  1427 // CDRMRights::GetPermission
       
  1428 // -----------------------------------------------------------------------------
       
  1429 EXPORT_C CDRMPermission& CDRMRights::GetPermission(void)
       
  1430     {
       
  1431     return *iPermission;
       
  1432     }
       
  1433 
       
  1434 // -----------------------------------------------------------------------------
       
  1435 // CDRMRights::SetPermissionL
       
  1436 // -----------------------------------------------------------------------------
       
  1437 EXPORT_C void CDRMRights::SetPermissionL(CDRMPermission& aRO)
       
  1438     {
       
  1439     delete iPermission;
       
  1440     iPermission = NULL;
       
  1441     iPermission = CDRMPermission::NewL();
       
  1442     iPermission->DuplicateL(aRO);
       
  1443     }
       
  1444 
       
  1445 // -----------------------------------------------------------------------------
       
  1446 // CDRMRights::GetAsset
       
  1447 // -----------------------------------------------------------------------------
       
  1448 EXPORT_C CDRMAsset& CDRMRights::GetAsset(void)
       
  1449     {
       
  1450     return *iAsset;
       
  1451     }
       
  1452 
       
  1453 // -----------------------------------------------------------------------------
       
  1454 // CDRMRights::SetAssetL
       
  1455 // -----------------------------------------------------------------------------
       
  1456 EXPORT_C void CDRMRights::SetAssetL(CDRMAsset& aAsset)
       
  1457     {
       
  1458     delete iAsset;
       
  1459     iAsset = NULL;
       
  1460     iAsset = CDRMAsset::NewL();
       
  1461     iAsset->DuplicateL(aAsset);
       
  1462     }
       
  1463 
       
  1464 // -----------------------------------------------------------------------------
       
  1465 // CDRMRights::operator=
       
  1466 // Assignment operator.
       
  1467 // -----------------------------------------------------------------------------
       
  1468 EXPORT_C CDRMRights& CDRMRights::operator=(
       
  1469     CDRMRights& aRight)
       
  1470     {
       
  1471     TInt r = KErrNone;
       
  1472 
       
  1473     if (this == &aRight)
       
  1474         {
       
  1475         return *this;
       
  1476         }
       
  1477 
       
  1478     TRAP(r, SetAssetL(aRight.GetAsset()));
       
  1479     TRAP(r, SetPermissionL(aRight.GetPermission()));
       
  1480 
       
  1481     return* this;
       
  1482     }
       
  1483 
       
  1484 
       
  1485 // -----------------------------------------------------------------------------
       
  1486 // CDRMRights::ExternalizeL
       
  1487 // -----------------------------------------------------------------------------
       
  1488 EXPORT_C void CDRMRights::ExternalizeL(RWriteStream& aStream) const
       
  1489     {
       
  1490     iAsset->ExternalizeL(aStream);
       
  1491     iPermission->ExternalizeL(aStream);
       
  1492     }
       
  1493 
       
  1494 // -----------------------------------------------------------------------------
       
  1495 // CDRMRights::InternalizeL
       
  1496 // -----------------------------------------------------------------------------
       
  1497 EXPORT_C void CDRMRights::InternalizeL(RReadStream& aStream)
       
  1498     {
       
  1499     delete iAsset;
       
  1500     iAsset = NULL;
       
  1501     delete iPermission;
       
  1502     iPermission=NULL;
       
  1503 
       
  1504     iAsset = CDRMAsset::NewL();
       
  1505     iPermission = CDRMPermission::NewL();
       
  1506 
       
  1507     iAsset->InternalizeL(aStream);
       
  1508     iPermission->InternalizeL(aStream);
       
  1509     }
       
  1510 
       
  1511 // -----------------------------------------------------------------------------
       
  1512 // CDRMRights::Merge
       
  1513 // -----------------------------------------------------------------------------
       
  1514 EXPORT_C void CDRMRights::Merge(const CDRMRights& aRights)
       
  1515     {
       
  1516     iPermission->Merge(*aRights.iPermission);
       
  1517     }
       
  1518 
       
  1519 // End of file