omadrm/drmengine/dcf/src/DcfCommon.cpp
changeset 0 95b198f216e5
child 12 8a03a285ab14
equal deleted inserted replaced
-1:000000000000 0:95b198f216e5
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:  ?Description
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <e32base.h>
       
    22 #include <f32file.h>
       
    23 #include "DcfCommon.h"
       
    24 #include "Oma1Dcf.h"
       
    25 #include "Oma2Dcf.h"
       
    26 
       
    27 // ============================ MEMBER FUNCTIONS ===============================
       
    28 
       
    29 // -----------------------------------------------------------------------------
       
    30 // CDcfCommon::CDcfCommon
       
    31 // 
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 CDcfCommon::CDcfCommon():
       
    35     iData(NULL),
       
    36     iMimeType(NULL),
       
    37     iContentID(NULL),
       
    38     iRightsIssuerURL(NULL),
       
    39     iPadding(-1),
       
    40     iEncryptionMethod(EMethodAES_128_CBC),
       
    41     iTitle(NULL),
       
    42     iDescription(NULL),
       
    43     iIconUri(NULL)
       
    44     {
       
    45     }
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CDcfCommon::ConstructL
       
    49 // 
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void CDcfCommon::ConstructL(
       
    53     const RFile& aFile)
       
    54     {
       
    55     iFile.Duplicate(aFile);
       
    56     iFile.Size(iLength);
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // CDcfCommon::NewL
       
    61 // 
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CDcfCommon* CDcfCommon::NewL(
       
    65     const RFile& aFile)
       
    66     {
       
    67     TBuf8<256> buffer;
       
    68     TInt pos = 0;
       
    69     CDcfCommon* self = NULL;
       
    70 
       
    71     User::LeaveIfError(aFile.Seek(ESeekStart, pos));
       
    72     User::LeaveIfError(aFile.Read(buffer));
       
    73     if (COma1Dcf::IsValidDcf(buffer))
       
    74         {
       
    75         self = COma1Dcf::NewL(aFile);
       
    76         }
       
    77     else if (COma2Dcf::IsValidDcf(buffer))
       
    78         {
       
    79         self = COma2Dcf::NewL(aFile);
       
    80         }
       
    81 
       
    82     return self;
       
    83     }
       
    84 
       
    85 // -----------------------------------------------------------------------------
       
    86 // CDcfCommon::NewL
       
    87 // 
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C CDcfCommon* CDcfCommon::NewL(
       
    91     const TDesC& aFileName,
       
    92     RFs* aFs)
       
    93     {
       
    94     RFs* fs = NULL;
       
    95     RFile file;
       
    96     TInt r = KErrNone;
       
    97     CDcfCommon* self = NULL;
       
    98     
       
    99     if (aFs == NULL)
       
   100         {
       
   101         fs = new RFs();
       
   102         User::LeaveIfNull(fs);
       
   103         CleanupStack::PushL(fs);
       
   104         User::LeaveIfError(fs->Connect());
       
   105         }
       
   106     else 
       
   107         {
       
   108         fs = aFs;
       
   109         }
       
   110     
       
   111 	r = file.Open(*fs, aFileName, EFileStream | EFileRead | EFileShareReadersOrWriters );
       
   112     if( r == KErrInUse )
       
   113         {
       
   114     	r = file.Open(*fs, aFileName, EFileStream | EFileRead | EFileShareAny);        
       
   115 
       
   116 	    if (r == KErrInUse)
       
   117 	        {
       
   118     	    r = file.Open(*fs, aFileName, EFileStream | EFileRead |
       
   119     	        EFileShareReadersOnly);
       
   120 	        }
       
   121         }
       
   122 	if(r == KErrNone)
       
   123 	    {
       
   124 	    CleanupClosePushL(file);
       
   125 	    self = NewL(file);
       
   126 	    CleanupStack::PopAndDestroy();
       
   127 	    }
       
   128 
       
   129     if (aFs == NULL)
       
   130         {
       
   131         fs->Close();
       
   132         CleanupStack::PopAndDestroy();
       
   133         }
       
   134     return self;
       
   135     }
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CDcfCommon::NewL
       
   139 // 
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 EXPORT_C CDcfCommon::~CDcfCommon()
       
   143     {
       
   144     delete iData;
       
   145     delete iMimeType;
       
   146     delete iContentID;
       
   147     delete iRightsIssuerURL;
       
   148     delete iTitle;
       
   149     delete iDescription;
       
   150     delete iIconUri;
       
   151     if (iFile.SubSessionHandle() != KNullHandle)
       
   152         {
       
   153         iFile.Close();
       
   154         }
       
   155     }
       
   156 
       
   157 // -----------------------------------------------------------------------------
       
   158 // CDcfCommon::
       
   159 // 
       
   160 // -----------------------------------------------------------------------------
       
   161 //
       
   162 TInt CDcfCommon::CheckUniqueId(const TDesC& aUniqueId)
       
   163 	{
       
   164 	if (aUniqueId.Compare(KDefaultContentObject) == 0)
       
   165 	    {
       
   166 	    return 0;
       
   167 	    }
       
   168 	else
       
   169 	    {
       
   170 	    return KErrNotFound;
       
   171 	    }
       
   172 	}
       
   173 
       
   174 //  End of File