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