os/security/contentmgmt/contentaccessfwfordrm/source/cafutils/virtualpath.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2004-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 the License "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: 
    15 *
    16 */
    17 
    18 
    19 #include <s32strm.h>
    20 #include <caf/virtualpath.h>
    21 #include "cafutils.h"
    22 
    23 using namespace ContentAccess;
    24 
    25 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aCombinedUriUniqueId)
    26 	{	
    27 	// TVirtualPathPtr performs the separation of URI and UniqueId if required
    28 	return CVirtualPath::NewL(TVirtualPathPtr(aCombinedUriUniqueId));
    29 	}
    30 
    31 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TDesC& aURI, const TDesC& aUniqueId)
    32 	{	
    33 	return CVirtualPath::NewL(TVirtualPathPtr(aURI, aUniqueId));
    34 	}
    35 
    36 EXPORT_C CVirtualPath* CVirtualPath::NewL(const TVirtualPathPtr& aPtr)
    37 	{	
    38 	CVirtualPath* self = new (ELeave) CVirtualPath(aPtr);
    39 	CleanupStack::PushL(self);
    40 	self->ConstructL();
    41 	CleanupStack::Pop(self);
    42 	return self;
    43 	}
    44 
    45 EXPORT_C CVirtualPath* CVirtualPath::NewL(RReadStream& aStream)
    46 	{
    47 	CVirtualPath* self = new (ELeave) CVirtualPath(TVirtualPathPtr(KNullDesC()));
    48 	CleanupStack::PushL(self);
    49 	self->InternalizeL(aStream);
    50 	CleanupStack::Pop(self);
    51 	return self;
    52 	}	
    53 
    54 
    55 CVirtualPath::CVirtualPath(const TVirtualPathPtr& aVirtualPath) : iCombinedUriUniqueIdPtr(KNullDesC16()), iVirtualPathPtr(aVirtualPath) 
    56 	{
    57 	}
    58 
    59 void CVirtualPath::ConstructL()
    60 	{
    61 	iURI = iVirtualPathPtr.URI().AllocL();
    62 	iUniqueId = iVirtualPathPtr.UniqueId().AllocL();
    63 	
    64 	// Make sure the TVirtualPathPtr points to the member
    65 	// variables not the arguments which could be deleted or modified at any time
    66 	iVirtualPathPtr.Set(*iURI, *iUniqueId);
    67 
    68 	// Create a combined URI descriptor that stores the URI and UniqueId of the content
    69 	CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
    70 	iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
    71 	}
    72 
    73 void CVirtualPath::CreateCombinedUriUniqueIdL(const TDesC& aUri, const TDesC& aUniqueId)
    74 	{
    75 	
    76 	// build a concatenated version of the URI and UniqueId
    77 	// The KCafVirtualPathSeparator is used to separate the URI from the UniqueId
    78 	HBufC* temp = HBufC::NewL(aUri.Length() + 1 + aUniqueId.Length());
    79 	CleanupStack::PushL(temp);
    80 
    81 	TPtr combinedUriAndUniqueId = temp->Des();
    82 	combinedUriAndUniqueId.Append(aUri);
    83 	combinedUriAndUniqueId.Append(KCafVirtualPathSeparator());
    84 	combinedUriAndUniqueId.Append(aUniqueId);
    85 
    86 	// Set iCombinedUriUniqueId since everything worked up to this point
    87 	delete iCombinedUriUniqueId;
    88 	iCombinedUriUniqueId = NULL;
    89 	iCombinedUriUniqueId = temp;
    90 	iCombinedUriUniqueIdPtr.Set(iCombinedUriUniqueId->Des());
    91 
    92 	// dont delete temp since it's now pointed to by iCombinedUriUniqueId
    93 	CleanupStack::Pop(temp);
    94 	}
    95 
    96 
    97 CVirtualPath::~CVirtualPath()
    98 	{
    99 	delete iURI;
   100 	delete iUniqueId;
   101 	delete iCombinedUriUniqueId;
   102 	}
   103 
   104 EXPORT_C const TDesC& CVirtualPath::URI() const
   105 	{
   106 	return *iURI;
   107 	}
   108 
   109 EXPORT_C const TDesC& CVirtualPath::UniqueId() const
   110 	{
   111 	return *iUniqueId;
   112 	}
   113 
   114 EXPORT_C const TDesC& CVirtualPath::GetCombinedUriUniqueId()
   115 	{
   116 	return iCombinedUriUniqueIdPtr;
   117 	}
   118 
   119 EXPORT_C void CVirtualPath::ExternalizeL(RWriteStream& aStream) const
   120 	{
   121 	TCafUtils::WriteDescriptor16L(aStream, *iURI);
   122 	TCafUtils::WriteDescriptor16L(aStream, *iUniqueId);
   123 	}	
   124 
   125 void CVirtualPath::InternalizeL(RReadStream& aStream)
   126 	{
   127 	// Allocate space for the URI, UniqueId and CombinedURI
   128 	iURI = TCafUtils::ReadDescriptor16L(aStream);
   129 	iUniqueId = TCafUtils::ReadDescriptor16L(aStream);
   130 
   131 	// Create a combined URI and UniqueId for these two
   132 	CreateCombinedUriUniqueIdL(*iURI, *iUniqueId);
   133 
   134 	// Set the TVirutalPathPtr member to be the URI and UniqueId
   135 	iVirtualPathPtr.Set(*iURI, *iUniqueId);
   136 	}