omadrm/drmengine/agentv2/src/Oma2AgentAttributes.cpp
changeset 0 95b198f216e5
child 9 89a1f2bd800d
child 23 493788a4a8a4
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2005-2009 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:  Access to content and data attributes
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // Includes
       
    20 #include <apgcli.h>
       
    21 #include <f32file.h>
       
    22 #include <charconv.h>
       
    23 
       
    24 #include <caf/caf.h>
       
    25 #include <caf/attributeset.h>
       
    26 #include <caf/stringattributeset.h>
       
    27 #include <caf/virtualpath.h>
       
    28 #include <caf/caferr.h>
       
    29 #include <utf.h>
       
    30 #include <drmagents.h>
       
    31 #include "oma2agent.h"
       
    32 #include "oma2agentattributes.h"
       
    33 #include "oma1dcf.h"
       
    34 #include "oma2dcf.h"
       
    35 #include "drmrightsclient.h"
       
    36 #include "DrmProtectedRoParser.h"
       
    37 
       
    38 using namespace ContentAccess;
       
    39 
       
    40 // LOCAL FUNCTION PROTOTYPES
       
    41 LOCAL_C HBufC* CollectEmbeddedRosL(
       
    42     COma2Dcf* aDcf);
       
    43 
       
    44 LOCAL_C HBufC* GetDomainRiUrlL(
       
    45     COma2Dcf* aDcf);
       
    46 
       
    47 LOCAL_C HBufC* GetDomainIdL(
       
    48     COma2Dcf* aDcf);
       
    49 
       
    50 LOCAL_C HBufC* GetDomainRiIdL(
       
    51     COma2Dcf* aDcf);
       
    52 
       
    53 LOCAL_C TInt CheckIntentL(
       
    54     const TDesC8& aContentId,
       
    55     TIntent aIntent,
       
    56     RDRMRightsClient* aRightsClient);
       
    57 
       
    58 LOCAL_C TInt GetEstimatedArrivalTime(
       
    59     const TDesC8& aContentId,
       
    60     RDRMRightsClient* aRightsClient);
       
    61 
       
    62 LOCAL_C TInt GetContentName(
       
    63     const TDesC8& aContentId,
       
    64     HBufC*& aContentName,
       
    65     RDRMRightsClient* aRightsClient );
       
    66 
       
    67 // LOCAL CONSTANTS
       
    68 
       
    69 _LIT16(KOma1DcfContentType16, "application/vnd.oma.drm.content");
       
    70 _LIT16(KOma2DcfContentType16, "application/vnd.oma.drm.dcf");
       
    71 const TInt KMaxAlbumTrack = 3;
       
    72 const TInt KMaxRecordingYear = 6;
       
    73 
       
    74 // ============================= LOCAL FUNCTIONS ===============================
       
    75 
       
    76 // -----------------------------------------------------------------------------
       
    77 // CollectEmbeddedRosL
       
    78 // Concatenate all rights objects embedded in a DCF into one buffer
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 LOCAL_C HBufC* CollectEmbeddedRosL(
       
    82     COma2Dcf* aDcf)
       
    83     {
       
    84     HBufC* r = NULL;
       
    85     HBufC* ro = NULL;
       
    86     TPtr ptr(NULL, 0);
       
    87     TInt i;
       
    88     TInt n;
       
    89 
       
    90     if (aDcf != NULL && aDcf->iRightsObjects.Count() > 0)
       
    91         {
       
    92         n = 0;
       
    93         for (i = 0; i < aDcf->iRightsObjects.Count(); i++)
       
    94             {
       
    95             n += aDcf->iRightsObjects[i]->Length();
       
    96             }
       
    97         r = HBufC::NewLC(n);
       
    98         ptr.Set(r->Des());
       
    99         for (i = 0; i < aDcf->iRightsObjects.Count(); i++)
       
   100             {
       
   101             ro = CnvUtfConverter::ConvertToUnicodeFromUtf8L(
       
   102                 *aDcf->iRightsObjects[i]);
       
   103             ptr.Append(*ro);
       
   104             delete ro;
       
   105             }
       
   106         CleanupStack::Pop(r);
       
   107         }
       
   108     return r;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // GetDomainRiUrlL
       
   113 // Returns the RI URL from the last embedded domain RO, to be used for
       
   114 // automatically joining a domain
       
   115 // -----------------------------------------------------------------------------
       
   116 //
       
   117 LOCAL_C HBufC* GetDomainRiUrlL(
       
   118     COma2Dcf* aDcf)
       
   119     {
       
   120     HBufC8* url = NULL;
       
   121     HBufC* r = NULL;
       
   122     CDrmProtectedRoParser* parser = NULL;
       
   123 
       
   124     if (aDcf != NULL && aDcf->iRightsObjects.Count() > 0)
       
   125         {
       
   126         parser = CDrmProtectedRoParser::NewL();
       
   127         CleanupStack::PushL(parser);
       
   128         url = parser->GetRiUrlL(*aDcf->iRightsObjects[ 0 ]);
       
   129         if (url != NULL)
       
   130             {
       
   131             CleanupStack::PushL(url);
       
   132             r = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*url);
       
   133             CleanupStack::PopAndDestroy(); // url
       
   134             }
       
   135         CleanupStack::PopAndDestroy(); // parser
       
   136         }
       
   137     return r;
       
   138     }
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 // GetDomainRiIdL
       
   142 // Returns the RI ID from the last embedded domain RO, to be used for
       
   143 // automatically joining a domain
       
   144 // -----------------------------------------------------------------------------
       
   145 //
       
   146 LOCAL_C HBufC* GetDomainRiIdL(
       
   147     COma2Dcf* aDcf)
       
   148     {
       
   149     HBufC8* id = NULL;
       
   150     HBufC* r = NULL;
       
   151     CDrmProtectedRoParser* parser = NULL;
       
   152     TInt i;
       
   153     TPtr ptr(NULL, 0);
       
   154 
       
   155     if (aDcf != NULL && aDcf->iRightsObjects.Count() > 0)
       
   156         {
       
   157         parser = CDrmProtectedRoParser::NewL();
       
   158         CleanupStack::PushL(parser);
       
   159         id = parser->GetRiIdL(*aDcf->iRightsObjects[ 0 ]);
       
   160         if (id != NULL)
       
   161             {
       
   162             CleanupStack::PushL(id);
       
   163             r = HBufC::NewL(id->Length() * 2);
       
   164             ptr.Set(r->Des());
       
   165             for (i = 0; i < id->Length(); i++)
       
   166                 {
       
   167                 ptr.Append((*id)[i]);
       
   168                 }
       
   169             CleanupStack::PopAndDestroy(); // url
       
   170             }
       
   171         CleanupStack::PopAndDestroy(); // parser
       
   172         }
       
   173     return r;
       
   174     }
       
   175 
       
   176 // -----------------------------------------------------------------------------
       
   177 // GetDomainIdL
       
   178 // Returns the domain ID from the last embedded domain RO, to be used for
       
   179 // automatically joining a domain
       
   180 // -----------------------------------------------------------------------------
       
   181 //
       
   182 LOCAL_C HBufC* GetDomainIdL(
       
   183     COma2Dcf* aDcf)
       
   184     {
       
   185     HBufC8* id = NULL;
       
   186     HBufC* r = NULL;
       
   187     CDrmProtectedRoParser* parser = NULL;
       
   188 
       
   189     if (aDcf != NULL && aDcf->iRightsObjects.Count() > 0)
       
   190         {
       
   191         parser = CDrmProtectedRoParser::NewL();
       
   192         CleanupStack::PushL(parser);
       
   193         id = parser->GetDomainIdL(*aDcf->iRightsObjects[ 0 ]);
       
   194         if (id != NULL)
       
   195             {
       
   196             CleanupStack::PushL(id);
       
   197             r = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*id);
       
   198             CleanupStack::PopAndDestroy(); // id
       
   199             }
       
   200         CleanupStack::PopAndDestroy(); // parser
       
   201         }
       
   202     return r;
       
   203     }
       
   204 
       
   205 // -----------------------------------------------------------------------------
       
   206 // CheckIntentL
       
   207 // Check the intent for a content ID via the rights server
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 LOCAL_C TInt CheckIntentL(
       
   211     const TDesC8& aContentId,
       
   212     TIntent aIntent,
       
   213     RDRMRightsClient* aRightsClient)
       
   214     {
       
   215     RDRMRightsClient client;
       
   216     TInt r;
       
   217     TBool retVal = EFalse;
       
   218     TUint32 reason = 0;
       
   219 
       
   220     if (aRightsClient == NULL)
       
   221         {
       
   222         User::LeaveIfError(client.Connect());
       
   223         r = client.CheckRights(aIntent, aContentId, reason);
       
   224         client.Close();
       
   225         }
       
   226     else
       
   227         {
       
   228         r = aRightsClient->CheckRights(aIntent, aContentId, reason);
       
   229         }
       
   230 
       
   231     // If the rights exist return ETrue
       
   232     if( r == KErrNone )
       
   233         {
       
   234         retVal = ETrue;
       
   235         }
       
   236 
       
   237     return retVal;
       
   238     }
       
   239 
       
   240 // -----------------------------------------------------------------------------
       
   241 // GetEstimatedArrivalTime
       
   242 // Get the estimated arrival time for the rights (value of the
       
   243 // X-OMA-Separate-Delivery header)
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 LOCAL_C TInt GetEstimatedArrivalTime(
       
   247     const TDesC8& aContentId,
       
   248     RDRMRightsClient* aRightsClient)
       
   249     {
       
   250     RDRMRightsClient client;
       
   251     TInt r;
       
   252     TTimeIntervalSeconds n;
       
   253 
       
   254     if (aRightsClient == NULL)
       
   255         {
       
   256         r = client.Connect();
       
   257         if (r != KErrNone)
       
   258             {
       
   259             return r;
       
   260             }
       
   261 
       
   262         r = client.GetEstimatedArrival(aContentId, n);
       
   263         client.Close();
       
   264         }
       
   265     else
       
   266         {
       
   267         r = aRightsClient->GetEstimatedArrival(aContentId, n);
       
   268         }
       
   269     if (r == KErrNone)
       
   270         {
       
   271         r = n.Int();
       
   272 
       
   273         // -1 is the special case when the arrival time has passed,
       
   274         // the first caller gets the KErrCAPendingRights meaning
       
   275         // the rights are still pending
       
   276         if( r == -1 )
       
   277             {
       
   278             r = KErrCAPendingRights;
       
   279             }
       
   280         }
       
   281 
       
   282     return r;
       
   283     }
       
   284 
       
   285 
       
   286 // -----------------------------------------------------------------------------
       
   287 // GetContentName
       
   288 // Get the content name stored into the rights database
       
   289 // -----------------------------------------------------------------------------
       
   290 //
       
   291 
       
   292 LOCAL_C TInt GetContentName(
       
   293     const TDesC8& aContentId,
       
   294     HBufC*& aContentName,
       
   295     RDRMRightsClient* aRightsClient )
       
   296     {
       
   297     RDRMRightsClient client;
       
   298     TInt r;
       
   299 
       
   300     if (aRightsClient == NULL)
       
   301         {
       
   302         r = client.Connect();
       
   303         if( !r )
       
   304             {
       
   305             r = client.GetName(aContentId, aContentName);
       
   306             }
       
   307         client.Close();
       
   308         }
       
   309     else
       
   310         {
       
   311         r = aRightsClient->GetName(aContentId, aContentName);
       
   312         }
       
   313 
       
   314     return r;
       
   315     };
       
   316 
       
   317 
       
   318 // ============================ MEMBER FUNCTIONS ===============================
       
   319 
       
   320 // -----------------------------------------------------------------------------
       
   321 // TOma2AgentAttributes::
       
   322 //
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 TInt TOma2AgentAttributes::GetAttribute(
       
   326     CDcfCommon& aDcfFile,
       
   327     TInt aAttribute,
       
   328     const TVirtualPathPtr& aVirtualPath,
       
   329     RDRMRightsClient* aRightsClient)
       
   330     {
       
   331     RDRMRightsClient client;
       
   332     TInt value = KErrCANotSupported;
       
   333     COma2Dcf* dcf2 = NULL;
       
   334     TBool protection = ETrue;
       
   335     HBufC8* buffer;
       
   336     TInt traperror = KErrNone;
       
   337 
       
   338     if (aDcfFile.iVersion == 2)
       
   339         {
       
   340         dcf2 = static_cast<COma2Dcf*>(&aDcfFile);
       
   341         if (dcf2->iEncryptionMethod == EMethodNULL)
       
   342             {
       
   343             protection = EFalse;
       
   344             }
       
   345         }
       
   346     if(aVirtualPath.UniqueId().Length() == 0)
       
   347         {
       
   348         // The DCF file itself
       
   349         switch(aAttribute)
       
   350             {
       
   351             case DRM::EDrmAgentUid:
       
   352                 value = DRM::EDrmOmaAgent;
       
   353                 break;
       
   354             case EIsProtected:
       
   355                 value = EFalse;
       
   356                 break;
       
   357             case EIsForwardable:
       
   358                 value = ETrue;
       
   359                 break;
       
   360             case EIsModifyable:
       
   361                 value = EFalse;
       
   362                 break;
       
   363             case EIsCopyable:
       
   364                 value = ETrue;
       
   365                 break;
       
   366             case EContentCDataInUse:
       
   367                 value = KErrCANotSupported;
       
   368                 break;
       
   369             case ECopyPaste:
       
   370                 value = ETrue;
       
   371                 break;
       
   372             case ECanMove:
       
   373                 value = ETrue;
       
   374                 break;
       
   375             case ECanRename:
       
   376                 value = ETrue;
       
   377                 break;
       
   378             case EFileType:
       
   379             case DRM::EDrmFileType:
       
   380                 value = aDcfFile.iVersion;
       
   381                 break;
       
   382             case ESilentRightsType:
       
   383                 value = 0;
       
   384                 break;
       
   385             case EDeliveryMethod:
       
   386                 if (aDcfFile.iVersion == 2)
       
   387                     {
       
   388                     value = EOmaDrm2;
       
   389                     }
       
   390                 else
       
   391                     {
       
   392                     if (aDcfFile.iContentID->Left(4).Compare(_L8("flk:")) == 0)
       
   393                         {
       
   394                         if (aRightsClient == NULL)
       
   395                             {
       
   396                             value = client.Connect();
       
   397                             if (value != KErrNone)
       
   398                                 {
       
   399                                 break;
       
   400                                 }
       
   401                             if (client.ForwardLockURI(buffer) == KErrNone &&
       
   402                                 buffer != NULL)
       
   403                                 {
       
   404                                 if (aDcfFile.iContentID->Compare(*buffer) == 0)
       
   405                                     {
       
   406                                     value = EOmaDrm1ForwardLock;
       
   407                                     }
       
   408                                 else
       
   409                                     {
       
   410                                     value = EOmaDrm1CombinedDelivery;
       
   411                                     }
       
   412                                 delete buffer;
       
   413                                 }
       
   414                             else
       
   415                                 {
       
   416                                 value = KErrGeneral;
       
   417                                 }
       
   418                             client.Close();
       
   419                             break;
       
   420                             }
       
   421                         else
       
   422                             {
       
   423                             if (aRightsClient->ForwardLockURI(buffer) == KErrNone &&
       
   424                             buffer != NULL)
       
   425                                 {
       
   426                                 if (aDcfFile.iContentID->Compare(*buffer) == 0)
       
   427                                     {
       
   428                                     value = EOmaDrm1ForwardLock;
       
   429                                     }
       
   430                                 else
       
   431                                     {
       
   432                                     value = EOmaDrm1CombinedDelivery;
       
   433                                     }
       
   434                                 delete buffer;
       
   435                                 }
       
   436                             else
       
   437                                 {
       
   438                                 value = KErrGeneral;
       
   439                                 }
       
   440                             }
       
   441                         }
       
   442                     else if (aDcfFile.iContentID->Left(4).Compare(_L8("ldf:")) == 0)
       
   443                         {
       
   444                         value = EOmaDrm1LocalDataFile;
       
   445                         }
       
   446                     else
       
   447                         {
       
   448                         value = EOmaDrm1SeparateDelivery;
       
   449                         }
       
   450                     }
       
   451                 break;
       
   452             case DRM::EDrmAllowedOutputs:
       
   453                 value = DRM::EDrmAllowAudioAnalog | DRM::EDrmAllowAudioBluetooth | DRM::EDrmAllowVideoMacroVision | DRM::EDrmAllowAudioFmTransmitter;
       
   454                 break;
       
   455             default:
       
   456                 value = KErrCANotSupported;
       
   457                 break;
       
   458             }
       
   459         }
       
   460     else
       
   461         {
       
   462         switch(aAttribute)
       
   463             {
       
   464             case DRM::EDrmAgentUid:
       
   465                 value = DRM::EDrmOmaAgent;
       
   466                 break;
       
   467             case EIsProtected:
       
   468                 value = protection;
       
   469                 break;
       
   470             case EIsForwardable:
       
   471                 if ((aDcfFile.iContentID->Left(4).Compare(_L8("flk:")) == 0)
       
   472                     ||
       
   473                     (aDcfFile.iContentID->Left(4).Compare(_L8("ldf:")) == 0))
       
   474                     {
       
   475                     value = EFalse;
       
   476                     }
       
   477                 else
       
   478                     {
       
   479                     if (aDcfFile.iRightsIssuerURL == NULL )
       
   480                         {
       
   481                         value = EFalse;
       
   482                         }
       
   483                      else
       
   484                         {
       
   485                         value = ETrue;
       
   486                         }
       
   487                     }
       
   488                 break;
       
   489             case EIsModifyable:
       
   490                 value = protection ? EFalse : ETrue;
       
   491                 break;
       
   492             case EIsCopyable:
       
   493                 value = protection ? EFalse : ETrue;
       
   494                 break;
       
   495             case ECanPlay:
       
   496                 if (!protection)
       
   497                     {
       
   498                     value = ETrue;
       
   499                     }
       
   500                 else
       
   501                     {
       
   502 
       
   503                     TRAP(traperror, value = CheckIntentL(*aDcfFile.iContentID, EPlay,
       
   504                         aRightsClient));
       
   505                     if( traperror )
       
   506                         {
       
   507                         value = traperror;
       
   508                         }
       
   509                     }
       
   510                 break;
       
   511             case ECanPrint:
       
   512                 if (!protection)
       
   513                     {
       
   514                     value = ETrue;
       
   515                     }
       
   516                 else
       
   517                     {
       
   518                     TRAP(traperror, value = CheckIntentL(*aDcfFile.iContentID, EPrint,
       
   519                         aRightsClient));
       
   520                     if( traperror )
       
   521                         {
       
   522                         value = traperror;
       
   523                         }
       
   524                     }
       
   525                 break;
       
   526             case ECanExecute:
       
   527                 if (!protection)
       
   528                     {
       
   529                     value = ETrue;
       
   530                     }
       
   531                 else
       
   532                     {
       
   533                     TRAP(traperror, value = CheckIntentL(*aDcfFile.iContentID, EExecute,
       
   534                         aRightsClient));
       
   535                     if( traperror )
       
   536                         {
       
   537                         value = traperror;
       
   538                         }
       
   539                     }
       
   540                 break;
       
   541             case ECanView:
       
   542                 if (!protection)
       
   543                     {
       
   544                     value = ETrue;
       
   545                     }
       
   546                 else
       
   547                     {
       
   548                     TRAP(traperror, value = CheckIntentL(*aDcfFile.iContentID, EView,
       
   549                         aRightsClient));
       
   550                     if( traperror )
       
   551                         {
       
   552                         value = traperror;
       
   553                         }
       
   554                     }
       
   555                 break;
       
   556             case EPreviewAvailable:
       
   557                 if (dcf2 != NULL && dcf2->iPreview != ENoPreview)
       
   558                     {
       
   559                     value = ETrue;
       
   560                     }
       
   561                 else
       
   562                     {
       
   563                     value = EFalse;
       
   564                     }
       
   565                 break;
       
   566             case EPreviewType:
       
   567                 value = ENoPreview;
       
   568                 if ( dcf2 != NULL && dcf2->iSilentRefresh == ENoSilentRefresh )
       
   569                     {
       
   570                     value = dcf2->iPreview;
       
   571                     }
       
   572                 else if ( dcf2 != NULL && dcf2->iPreviewOverridesSilentRefresh )
       
   573                     {
       
   574                     value = dcf2->iPreview;
       
   575                     }
       
   576                 break;
       
   577             case ESilentRightsType:
       
   578                 value = ENoSilentRefresh;
       
   579                 if( dcf2 != NULL && dcf2->iPreview == ENoPreview )
       
   580                     {
       
   581                     value = dcf2->iSilentRefresh;
       
   582                     }
       
   583                 else if (dcf2 != NULL && !dcf2->iPreviewOverridesSilentRefresh)
       
   584                     {
       
   585                     value = dcf2->iSilentRefresh;
       
   586                     }
       
   587                 break;
       
   588             case EContentCDataInUse:
       
   589                 value = KErrCANotSupported;
       
   590                 break;
       
   591             case ECanRewind:
       
   592                 value = ETrue;
       
   593                 break;
       
   594             case ECopyPaste:
       
   595                 value = protection;
       
   596                 break;
       
   597             case ECanMove:
       
   598                 value = ETrue;
       
   599                 break;
       
   600             case ECanRename:
       
   601                 value = ETrue;
       
   602                 break;
       
   603             case ECanAutomaticConsume:
       
   604                 value = ETrue;
       
   605                 break;
       
   606             case EFileType:
       
   607             case DRM::EDrmFileType:
       
   608                 value = aDcfFile.iVersion;
       
   609                 break;
       
   610             case EDeliveryMethod:
       
   611                 if (aDcfFile.iVersion == 2)
       
   612                     {
       
   613                     value = EOmaDrm2;
       
   614                     }
       
   615                 else
       
   616                     {
       
   617                     if (aDcfFile.iContentID->Left(4).Compare(_L8("flk:")) == 0)
       
   618                         {
       
   619                         if (aRightsClient == NULL)
       
   620                             {
       
   621                             value = client.Connect();
       
   622                             if (value != KErrNone)
       
   623                                 {
       
   624                                 break;
       
   625                                 }
       
   626                             if (client.ForwardLockURI(buffer) == KErrNone &&
       
   627                                 buffer != NULL)
       
   628                                 {
       
   629                                 if (aDcfFile.iContentID->Compare(*buffer) == 0)
       
   630                                     {
       
   631                                     value = EOmaDrm1ForwardLock;
       
   632                                     }
       
   633                                 else
       
   634                                     {
       
   635                                     value = EOmaDrm1CombinedDelivery;
       
   636                                     }
       
   637                                 delete buffer;
       
   638                                 }
       
   639                             else
       
   640                                 {
       
   641                                 value = KErrGeneral;
       
   642                                 }
       
   643                             client.Close();
       
   644                             break;
       
   645                             }
       
   646                         else
       
   647                             {
       
   648                             if (aRightsClient->ForwardLockURI(buffer) == KErrNone &&
       
   649                             buffer != NULL)
       
   650                                 {
       
   651                                 if (aDcfFile.iContentID->Compare(*buffer) == 0)
       
   652                                     {
       
   653                                     value = EOmaDrm1ForwardLock;
       
   654                                     }
       
   655                                 else
       
   656                                     {
       
   657                                     value = EOmaDrm1CombinedDelivery;
       
   658                                     }
       
   659                                 delete buffer;
       
   660                                 }
       
   661                             else
       
   662                                 {
       
   663                                 value = KErrGeneral;
       
   664                                 }
       
   665                             }
       
   666                         }
       
   667                     else if (aDcfFile.iContentID->Left(4).Compare(_L8("ldf:")) == 0)
       
   668                         {
       
   669                         value = EOmaDrm1LocalDataFile;
       
   670                         }
       
   671                     else
       
   672                         {
       
   673                         value = EOmaDrm1SeparateDelivery;
       
   674                         }
       
   675                     }
       
   676                 break;
       
   677             case ERecordingYear:
       
   678                 value = KErrNotSupported;
       
   679                  if (dcf2 != NULL && dcf2->iRecordingYear )
       
   680                      {
       
   681                      value = dcf2->iRecordingYear;
       
   682                      }
       
   683                 break;
       
   684             case DRM::EDrmAllowedOutputs:
       
   685                 value = DRM::EDrmAllowAudioAnalog | DRM::EDrmAllowAudioBluetooth | DRM::EDrmAllowVideoMacroVision;
       
   686                 break;
       
   687             case ERightsNone:
       
   688                 if (aRightsClient == NULL)
       
   689                     {
       
   690                     value = client.Connect();
       
   691                     if (value != KErrCANoRights)
       
   692                         {
       
   693                         break;
       
   694                         }
       
   695                     TUint32 reason = 0;
       
   696                     value = client.CheckRights(EPeek, *aDcfFile.iContentID, reason);
       
   697                     if(value == KErrCANoRights  || KErrCANoPermission)
       
   698                         {
       
   699                         value = ETrue;
       
   700                         }
       
   701                     client.Close();
       
   702                     }
       
   703                 else
       
   704                     {
       
   705                     TUint32 reason = 0;
       
   706                     value = aRightsClient->CheckRights(EPeek, *aDcfFile.iContentID, reason);
       
   707                     if(value == KErrCANoRights  || KErrCANoPermission)
       
   708                         {
       
   709                         value = ETrue;
       
   710                         }
       
   711                     }
       
   712                 break;
       
   713             case ERightsHaveExpired:
       
   714                 if (aRightsClient == NULL)
       
   715                     {
       
   716                     value = client.Connect();
       
   717                     if (value != KErrNone)
       
   718                         {
       
   719                         break;
       
   720                         }
       
   721                     value = ETrue;
       
   722                     TUint32 reason = 0;
       
   723                     value = client.CheckRights(EPlay, *aDcfFile.iContentID, reason);
       
   724                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   725                         {
       
   726                         value = EFalse;
       
   727                         }
       
   728                     value = client.CheckRights(EView, *aDcfFile.iContentID, reason);
       
   729                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   730                         {
       
   731                         value = EFalse;
       
   732                         }
       
   733                     value = client.CheckRights(EExecute, *aDcfFile.iContentID, reason);
       
   734                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   735                         {
       
   736                         value = EFalse;
       
   737                         }
       
   738                     value = client.CheckRights(EPrint, *aDcfFile.iContentID, reason);
       
   739                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   740                         {
       
   741                         value = EFalse;
       
   742                         }
       
   743                     client.Close();
       
   744                     }
       
   745                 else
       
   746                     {
       
   747                     value = ETrue;
       
   748                     TUint32 reason = 0;
       
   749                     value = aRightsClient->CheckRights(EPlay, *aDcfFile.iContentID, reason);
       
   750                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   751                         {
       
   752                         value = EFalse;
       
   753                         }
       
   754                     value = aRightsClient->CheckRights(EView, *aDcfFile.iContentID, reason);
       
   755                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   756                         {
       
   757                         value = EFalse;
       
   758                         }
       
   759                     value = aRightsClient->CheckRights(EExecute, *aDcfFile.iContentID, reason);
       
   760                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   761                         {
       
   762                         value = EFalse;
       
   763                         }
       
   764                     value = aRightsClient->CheckRights(EPrint, *aDcfFile.iContentID, reason);
       
   765                     if(value != KErrCANoRights  || KErrCANoPermission)
       
   766                         {
       
   767                         value = EFalse;
       
   768                         }
       
   769 
       
   770                     }
       
   771                 break;
       
   772             default:
       
   773                 value = KErrCANotSupported;
       
   774                 break;
       
   775             };
       
   776         }
       
   777     return value;
       
   778     }
       
   779 
       
   780 // -----------------------------------------------------------------------------
       
   781 // TOma2AgentAttributes::
       
   782 //
       
   783 // -----------------------------------------------------------------------------
       
   784 //
       
   785 TInt TOma2AgentAttributes::GetAttributeSet(
       
   786     CDcfCommon& aDcfFile,
       
   787     RAttributeSet& aAttributeSet,
       
   788     const TVirtualPathPtr& aVirtualPath,
       
   789     RDRMRightsClient* aRightsClient)
       
   790     {
       
   791     TInt i = 0;
       
   792     TInt attribute = 0;
       
   793     TInt value = 0;
       
   794     TInt numAttributes = aAttributeSet.Count();
       
   795 
       
   796     // loop through all the attriutes in the set and find their values
       
   797     for(i = 0; i < numAttributes; i++)
       
   798         {
       
   799         attribute = aAttributeSet[i];
       
   800         value = GetAttribute(aDcfFile, attribute, aVirtualPath, aRightsClient);
       
   801         aAttributeSet.SetValue(attribute, value, KErrNone);
       
   802         }
       
   803     return KErrNone;
       
   804     }
       
   805 
       
   806 // -----------------------------------------------------------------------------
       
   807 // TOma2AgentAttributes::
       
   808 //
       
   809 // -----------------------------------------------------------------------------
       
   810 //
       
   811 TInt TOma2AgentAttributes::GetStringAttribute(
       
   812     CDcfCommon& aDcfFile,
       
   813     TInt aAttribute,
       
   814     TDes& aValue,
       
   815     const TVirtualPathPtr& aVirtualPath,
       
   816     RDRMRightsClient* aRightsClient)
       
   817     {
       
   818     TInt err = KErrCANotSupported;
       
   819     HBufC* b = NULL;
       
   820     COma1Dcf* dcf1 = NULL;
       
   821     COma2Dcf* dcf2 = NULL;
       
   822     TPtrC8 ptr(NULL, 0);
       
   823     TPtr ptr16(NULL, 0, 0);
       
   824     TInt n;
       
   825     HBufC* contentName = NULL;
       
   826     TFileName fileName;
       
   827 
       
   828     aValue.Copy(KNullDesC);
       
   829     if (aDcfFile.iVersion == 2)
       
   830         {
       
   831         dcf2 = static_cast<COma2Dcf*>(&aDcfFile);
       
   832         }
       
   833     else
       
   834         {
       
   835         dcf1 = static_cast<COma1Dcf*>(&aDcfFile);
       
   836         }
       
   837     if (aVirtualPath.UniqueId().Length() == 0)
       
   838         {
       
   839         switch (aAttribute)
       
   840             {
       
   841             case DRM::EDrmAgentName:
       
   842                 TRAP(err, b = DRM::KDrmOmaAgentName().AllocL());
       
   843                 break;
       
   844             case EMimeType:
       
   845                 if (aDcfFile.iVersion == 1)
       
   846                     {
       
   847                     TRAP(err, b = KOma1DcfContentType16().AllocL());
       
   848                     }
       
   849                 else if (aDcfFile.iVersion == 2)
       
   850                     {
       
   851                     TRAP(err, b = KOma2DcfContentType16().AllocL());
       
   852                     }
       
   853                 break;
       
   854             case ETransactionTrackingId:
       
   855                 if (dcf2 != NULL && dcf2->iTransactionTracking)
       
   856                     {
       
   857                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iTransactionTracking));
       
   858                     }
       
   859                 break;
       
   860             case EEmbeddedRightsObject:
       
   861                 if (dcf2 != NULL)
       
   862                     {
       
   863                     TRAP(err, b = CollectEmbeddedRosL(dcf2));
       
   864                     }
       
   865                 break;
       
   866             case EDomainRightsIssuerUrl:
       
   867                 if (dcf2 != NULL)
       
   868                     {
       
   869                     TRAP(err, b = GetDomainRiUrlL(dcf2));
       
   870                     }
       
   871                 break;
       
   872             case EDomainRightsIssuerId:
       
   873                 if (dcf2 != NULL)
       
   874                     {
       
   875                     TRAP(err, b = GetDomainRiIdL(dcf2));
       
   876                     }
       
   877                 break;
       
   878             case EDomainId:
       
   879                 if (dcf2 != NULL)
       
   880                     {
       
   881                     TRAP(err, b = GetDomainIdL(dcf2));
       
   882                     }
       
   883                 break;
       
   884             case EFileName:
       
   885             case DRM::EDrmFileName:
       
   886                 err = aDcfFile.iFile.Name(fileName);
       
   887                 if( aValue.MaxLength() < fileName.Length() )
       
   888                     {
       
   889                     return KErrOverflow;
       
   890                     }
       
   891                 aValue.Copy(fileName);
       
   892                 break;
       
   893             case EContentName:
       
   894             case EDescription:
       
   895             case ETitle:
       
   896             case EAuthor:
       
   897             case EIconURI:
       
   898             case EPreviewURI:
       
   899             case EInstantPreviewUri:
       
   900             case EPreviewRightsUri:
       
   901             case EContentURI:
       
   902             case EContentID:
       
   903             case EInfoURL:
       
   904             case EPendingRightsETA:
       
   905             case ERightsIssuerUrl:
       
   906             case ESilentRightsUrl:
       
   907             default:
       
   908                 break;
       
   909             }
       
   910         }
       
   911     else
       
   912         {
       
   913         switch (aAttribute)
       
   914             {
       
   915             case DRM::EDrmAgentName:
       
   916                 TRAP(err, b = DRM::KDrmOmaAgentName().AllocL());
       
   917                 break;
       
   918             case EMimeType:
       
   919                 TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iMimeType));
       
   920                 break;
       
   921             case EDescription:
       
   922                 if (aDcfFile.iDescription)
       
   923                     {
       
   924                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iDescription));
       
   925                     }
       
   926                 break;
       
   927             case ETitle:
       
   928                 if (aDcfFile.iTitle)
       
   929                     {
       
   930                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iTitle));
       
   931                     }
       
   932                 break;
       
   933             case EAuthor:
       
   934                 if (dcf2 != NULL && dcf2->iAuthor)
       
   935                     {
       
   936                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iAuthor));
       
   937                     }
       
   938                 break;
       
   939             case EIconURI:
       
   940                 if (aDcfFile.iIconUri)
       
   941                     {
       
   942                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iIconUri));
       
   943                     }
       
   944                 break;
       
   945             case EPreviewURI:
       
   946                 if (dcf2 != NULL && dcf2->iPreviewParameter)
       
   947                     {
       
   948                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iPreviewParameter));
       
   949                     }
       
   950                 break;
       
   951             case EContentURI:
       
   952                 if (dcf2 != NULL && dcf2->iContentUrl)
       
   953                     {
       
   954                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iContentUrl));
       
   955                     }
       
   956                 break;
       
   957             case EContentID:
       
   958                 TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iContentID));
       
   959                 break;
       
   960             case EInfoURL:
       
   961                 if (dcf2 != NULL && dcf2->iInfoUri)
       
   962                     {
       
   963                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iInfoUri));
       
   964                     }
       
   965                 break;
       
   966             case EInstantPreviewUri:
       
   967                 if (dcf2 != NULL && dcf2->iPreview == EInstantPreview &&
       
   968                     dcf2->iPreviewParameter)
       
   969                     {
       
   970                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iPreviewParameter));
       
   971                     }
       
   972                 break;
       
   973             case EPreviewRightsUri:
       
   974                 if (dcf2 != NULL && dcf2->iPreview == EPreviewRights &&
       
   975                     dcf2->iPreviewParameter)
       
   976                     {
       
   977                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iPreviewParameter));
       
   978                     }
       
   979                 break;
       
   980             case ESilentRightsUrl:
       
   981                 if (dcf2 != NULL && dcf2->iSilentParameter &&
       
   982                     dcf2->iSilentParameter)
       
   983                     {
       
   984                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iSilentParameter));
       
   985                     }
       
   986                 break;
       
   987             case ERightsIssuerUrl:
       
   988 #ifndef __DRM_FULL
       
   989                 err = KErrNotSupported;
       
   990 #else
       
   991                 if (aDcfFile.iRightsIssuerURL != NULL)
       
   992                     {
       
   993                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*aDcfFile.iRightsIssuerURL));
       
   994                     }
       
   995 #endif
       
   996                 break;
       
   997             case ETransactionTrackingId:
       
   998                 if (dcf2 != NULL && dcf2->iTransactionTracking)
       
   999                     {
       
  1000                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iTransactionTracking));
       
  1001                     }
       
  1002                 break;
       
  1003             case EEmbeddedRightsObject:
       
  1004                 if (dcf2 != NULL)
       
  1005                     {
       
  1006                     TRAP(err, b = CollectEmbeddedRosL(dcf2));
       
  1007                     }
       
  1008                 break;
       
  1009             case EDomainRightsIssuerUrl:
       
  1010                 if (dcf2 != NULL)
       
  1011                     {
       
  1012                     TRAP(err, b = GetDomainRiUrlL(dcf2));
       
  1013                     }
       
  1014                 break;
       
  1015             case EDomainRightsIssuerId:
       
  1016                 if (dcf2 != NULL)
       
  1017                     {
       
  1018                     TRAP(err, b = GetDomainRiIdL(dcf2));
       
  1019                     }
       
  1020                 break;
       
  1021             case EDomainId:
       
  1022                 if (dcf2 != NULL)
       
  1023                     {
       
  1024                     TRAP(err, b = GetDomainIdL(dcf2));
       
  1025                     }
       
  1026                 break;
       
  1027             case EContentVendor:
       
  1028                 if (dcf1 != NULL)
       
  1029                     {
       
  1030                     TRAP(err, dcf1->GetHeaderL(KContentVendor, ptr));
       
  1031                     if (ptr.Length() > 0 && err == KErrNone)
       
  1032                         {
       
  1033                         TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(ptr));
       
  1034                         }
       
  1035                     }
       
  1036                 break;
       
  1037             case ECopyright:
       
  1038                 if (dcf2 != NULL && dcf2->iCopyRight)
       
  1039                     {
       
  1040                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iCopyRight));
       
  1041                     }
       
  1042                 break;
       
  1043             case EPendingRightsETA:
       
  1044                 n = GetEstimatedArrivalTime(*aDcfFile.iContentID, aRightsClient);
       
  1045                 TRAP(err, b = HBufC::NewL(16));
       
  1046                 if( err == KErrNone )
       
  1047                     {
       
  1048                     ptr16.Set(b->Des());
       
  1049                     ptr16.AppendNum(n);
       
  1050                     }
       
  1051                 break;
       
  1052             case EContentName:
       
  1053                 contentName = NULL;
       
  1054                 err = GetContentName( *aDcfFile.iContentID, contentName, aRightsClient );
       
  1055                 if( !err )
       
  1056                     {
       
  1057                     b = contentName;
       
  1058                     }
       
  1059                 break;
       
  1060 
       
  1061             case EOmaDrmContentLocation:
       
  1062                 break;
       
  1063             case EOmaDrmContentVersion:
       
  1064                 break;
       
  1065             case EPerformer:
       
  1066             case DRM::EDrmOriginalArtist:
       
  1067                  if (dcf2 != NULL && dcf2->iPerformer)
       
  1068                     {
       
  1069                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iPerformer));
       
  1070                     }
       
  1071                 break;
       
  1072             case EGenre: // flow through
       
  1073             case EOmaDrmGenre:
       
  1074                  if (dcf2 != NULL && dcf2->iGenre)
       
  1075                     {
       
  1076                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iGenre));
       
  1077                     }
       
  1078                 break;
       
  1079             case ERatingInfo:
       
  1080             case DRM::EDrmRatingInfo:
       
  1081                  if (dcf2 != NULL && dcf2->iRatingInfo)
       
  1082                     {
       
  1083                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iRatingInfo));
       
  1084                     }
       
  1085                 break;
       
  1086             case EClassificationInfo:
       
  1087                  if (dcf2 != NULL && dcf2->iClassificationInfo)
       
  1088                     {
       
  1089                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iClassificationInfo));
       
  1090                     }
       
  1091                 break;
       
  1092             case EKeyword:
       
  1093                  if (dcf2 != NULL && dcf2->iKeyword)
       
  1094                     {
       
  1095                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iKeyword));
       
  1096                     }
       
  1097                 break;
       
  1098             case ELocInfoName:
       
  1099                  if (dcf2 != NULL && dcf2->iLocInfoName)
       
  1100                     {
       
  1101                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iLocInfoName));
       
  1102                     }
       
  1103                 break;
       
  1104             case ELocInfoAstronomicalBody:
       
  1105                  if (dcf2 != NULL && dcf2->iLocInfoAstronomicalBody)
       
  1106                     {
       
  1107                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iLocInfoAstronomicalBody));
       
  1108                     }
       
  1109                 break;
       
  1110             case ELocInfoAdditionalNotes:
       
  1111                  if (dcf2 != NULL && dcf2->iLocInfoAdditionalNotes)
       
  1112                     {
       
  1113                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iLocInfoAdditionalNotes));
       
  1114                     }
       
  1115                 break;
       
  1116             case EAlbumTitle:
       
  1117                  if (dcf2 != NULL && dcf2->iAlbumTitle)
       
  1118                     {
       
  1119                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iAlbumTitle));
       
  1120                     }
       
  1121                 break;
       
  1122             case EAlbumTrack:
       
  1123             case DRM::EDrmTrackNumber:
       
  1124                 if( dcf2 != NULL && dcf2->iAlbumTrack)
       
  1125                     {
       
  1126                     TRAP(err, b = HBufC::NewL(KMaxAlbumTrack));
       
  1127                     if( err == KErrNone )
       
  1128                         {
       
  1129                         b->Des().AppendNum( dcf2->iAlbumTrack );
       
  1130                         }
       
  1131                     }
       
  1132                 break;
       
  1133             case ECoverUri:
       
  1134                  if (dcf2 != NULL && dcf2->iCoverUri)
       
  1135                     {
       
  1136                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iCoverUri));
       
  1137                     }
       
  1138                 break;
       
  1139             case ELyricsUrl:
       
  1140                  if (dcf2 != NULL && dcf2->iLyricsURL)
       
  1141                     {
       
  1142                     TRAP(err, b = CnvUtfConverter::ConvertToUnicodeFromUtf8L(*dcf2->iLyricsURL));
       
  1143                     }
       
  1144                 break;
       
  1145             case EFileName:
       
  1146             case DRM::EDrmFileName:
       
  1147                 err = aDcfFile.iFile.Name(fileName);
       
  1148                 if( aValue.MaxLength() < fileName.Length() )
       
  1149                     {
       
  1150                     return KErrOverflow;
       
  1151                     }
       
  1152                 aValue.Copy(fileName);
       
  1153                 break;
       
  1154             case DRM::EDrmFullName:
       
  1155                 err = aDcfFile.iFile.FullName(fileName);
       
  1156                 if ( aValue.MaxLength() < fileName.Length() )
       
  1157                     {
       
  1158                     return KErrOverflow;
       
  1159                     }
       
  1160                 aValue.Copy(fileName);
       
  1161                 break;
       
  1162             case DRM::EDrmRecordingYear:
       
  1163                 if( dcf2 != NULL && dcf2->iRecordingYear)
       
  1164                     {
       
  1165                     TRAP(err, b = HBufC::NewL(KMaxRecordingYear));
       
  1166                     if( err == KErrNone )
       
  1167                         {
       
  1168                         b->Des().AppendNum( dcf2->iRecordingYear );
       
  1169                         }
       
  1170                     }
       
  1171                 break;
       
  1172             default:
       
  1173                 break;
       
  1174             }
       
  1175         }
       
  1176 
       
  1177 
       
  1178     if (b != NULL)
       
  1179         {
       
  1180         if( b->Length() > aValue.MaxLength() )
       
  1181             {
       
  1182             delete b;
       
  1183             return KErrOverflow;
       
  1184             }
       
  1185         err = KErrNone;
       
  1186         aValue.Copy(*b);
       
  1187         delete b;
       
  1188         }
       
  1189     return err;
       
  1190     }
       
  1191 
       
  1192 // -----------------------------------------------------------------------------
       
  1193 // TOma2AgentAttributes::
       
  1194 //
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 TInt TOma2AgentAttributes::GetStringAttributeSet(
       
  1198     CDcfCommon& aDcfFile,
       
  1199     RStringAttributeSet& aStringAttributeSet,
       
  1200     const TVirtualPathPtr& aVirtualPath,
       
  1201     RDRMRightsClient* aRightsClient)
       
  1202     {
       
  1203     TInt i = 0;
       
  1204     TInt attribute = 0;
       
  1205     TInt err = KErrNone;
       
  1206     TBuf<KMaxDataTypeLength> buf;
       
  1207     TInt numAttributes = aStringAttributeSet.Count();
       
  1208 
       
  1209     for(i = 0; err == KErrNone && i < numAttributes; i++)
       
  1210         {
       
  1211         attribute = aStringAttributeSet[i];
       
  1212         err = GetStringAttribute(aDcfFile, attribute, buf, aVirtualPath,
       
  1213             aRightsClient);
       
  1214         err = aStringAttributeSet.SetValue(attribute, buf, err);
       
  1215         }
       
  1216     return err;
       
  1217     }
       
  1218 
       
  1219 // End of file