os/security/contentmgmt/contentaccessfwfordrm/source/caf/data.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) 2003-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 <apmstd.h>
    20 
    21 #include <caf/data.h>
    22 #include <caf/agentinterface.h>
    23 #include "agentinfo.h"
    24 #include <caf/agentfactory.h>
    25 #include <caf/attributeset.h>
    26 #include <caf/virtualpath.h>
    27 #include "resolver.h"
    28 #include "agentinfo.h"
    29 #include <e32def.h>
    30 
    31 using namespace ContentAccess;
    32 
    33 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
    34 	{
    35 	CData *self = CData::NewLC(aVirtualPath, aIntent, aShareMode);
    36 	CleanupStack::Pop(self);
    37 	return self;
    38 	}
    39 
    40 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
    41 	{
    42 	CData *self = new (ELeave) CData;
    43 	CleanupStack::PushL(self);
    44 	self->ConstructL(aVirtualPath, aIntent, aShareMode);
    45 	return self;
    46 	}
    47 
    48 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
    49 	{
    50 	CData *self = CData::NewLC(aFile, aUniqueId, aIntent);
    51 	CleanupStack::Pop(self);
    52 	return self;
    53 	}
    54 		
    55 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
    56 	{
    57 	CData *self = new (ELeave) CData;
    58 	CleanupStack::PushL(self);
    59 	self->ConstructL(aFile, aUniqueId, aIntent);
    60 	return self;
    61 	}
    62 
    63 
    64 EXPORT_C CData* CData::NewL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
    65 	{
    66 	CData *self = CData::NewLC(aVirtualPath, aShareMode);
    67 	CleanupStack::Pop(self);
    68 	return self;
    69 	}
    70 
    71 EXPORT_C CData* CData::NewLC(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
    72 	{
    73 	CData *self = new (ELeave) CData;
    74 	CleanupStack::PushL(self);
    75 	self->ConstructL(aVirtualPath, aShareMode);
    76 	return self;
    77 	}
    78 
    79 EXPORT_C CData* CData::NewL(RFile& aFile, const TDesC& aUniqueId)
    80 	{
    81 	CData *self = CData::NewLC(aFile, aUniqueId);
    82 	CleanupStack::Pop(self);
    83 	return self;
    84 	}
    85 		
    86 EXPORT_C CData* CData::NewLC(RFile& aFile, const TDesC& aUniqueId)
    87 	{
    88 	CData *self = new (ELeave) CData;
    89 	CleanupStack::PushL(self);
    90 	self->ConstructL(aFile, aUniqueId);
    91 	return self;
    92 	}
    93 
    94 
    95 CData* CData::NewLC(TUid aUid,
    96 					const TVirtualPathPtr& aVirtualPath,
    97 					TIntent aIntent,
    98 					TContentShareMode aShareMode)
    99 	{
   100 	CData* self = new(ELeave) CData();
   101 	CleanupStack::PushL(self);
   102 	self->ConstructL(aUid, aVirtualPath, aIntent, aShareMode);
   103 	return self;
   104 	}
   105 
   106 CData* CData::NewLC(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
   107 	{
   108 	CData* self = new (ELeave) CData();
   109 	CleanupStack::PushL(self);
   110 	self->ConstructL(aUid, aFile, aUniqueId, aIntent);
   111 	return self;
   112 	}
   113 
   114 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   115 
   116 EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData)
   117 	{
   118 	CData* self = CData::NewLC(aHeaderData);
   119 	CleanupStack::Pop(self);
   120 	return self;
   121 	}
   122 		
   123 EXPORT_C CData* CData::NewL(const TDesC8& aHeaderData, TIntent aIntent)
   124 	{
   125 	CData* self = CData::NewLC(aHeaderData, aIntent);
   126 	CleanupStack::Pop(self);
   127 	return self;
   128 	}
   129 		
   130 EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData)
   131 	{
   132 	CData* self = new (ELeave) CData();
   133 	CleanupStack::PushL(self);
   134 	self->ConstructL(aHeaderData);
   135 	return self;
   136 	}
   137 		
   138 EXPORT_C CData* CData::NewLC(const TDesC8& aHeaderData, TIntent aIntent)
   139 	{
   140 	CData* self = new (ELeave) CData();
   141 	CleanupStack::PushL(self);
   142 	self->ConstructL(aHeaderData, aIntent);
   143 	return self;
   144 	}
   145 		
   146 CData* CData::NewLC(TUid aAgentUid, const TDesC8& aHeaderData, TIntent aIntent)
   147 	{
   148 	CData* self = new (ELeave) CData();
   149 	CleanupStack::PushL(self);
   150 	self->ConstructL(aAgentUid, aHeaderData, aIntent);
   151 	return self;
   152 	}
   153 
   154 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   155 
   156 CData::CData()
   157 	{ 
   158 	}
   159 
   160 CData::~CData() 
   161 	{ 
   162 	// Destroy the agent implementation
   163 	delete iAgentData;
   164 	
   165 	// close ECOM session, may result in the unloading of the DLL
   166 	delete iAgentFactory;
   167 	REComSession::FinalClose();
   168 	}
   169 
   170 
   171 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TIntent aIntent, TContentShareMode aShareMode)
   172 	{
   173 	// Create the agent resolver which will contains a reference to
   174 	// the agent responsible for this piece of content
   175 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   176 	
   177 	// Create a temporary buffer used to store the translated version of the URI
   178 	HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   179 	TPtr uri = actualUri->Des();
   180 	
   181 	// Find the agent who handles the file and translate the URI if it is pointing to a private directory 
   182 	CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
   183 
   184 	// Figure out the Uid of the agent
   185 	TUid agentUid = agentInfo.Agent().ImplementationUid();
   186 	
   187 	// call internal CData::NewL()
   188 	CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aIntent, aShareMode);
   189 	
   190 	CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
   191 	}
   192 
   193 void CData::ConstructL(const TVirtualPathPtr& aVirtualPath, TContentShareMode aShareMode)
   194 	{
   195 	// Create the agent resolver which will contains a reference to
   196 	// the agent responsible for this piece of content
   197 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   198 	
   199 	// Create a temporary buffer used to store the translated version of the URI
   200 	HBufC* actualUri = HBufC::NewLC(aVirtualPath.URI().Length() + KMaxSIDLength);
   201 	TPtr uri = actualUri->Des();
   202 	
   203 	// Find the agent who handles the file and translate the URI if it is pointing to a private directory 
   204 	CAgentInfo& agentInfo = resolver->ResolveFileL(aVirtualPath.URI(), uri, aShareMode);
   205 
   206 	// Figure out the Uid of the agent
   207 	TUid agentUid = agentInfo.Agent().ImplementationUid();
   208 	
   209 	// call internal CData::NewL()
   210 	CData::ConstructL(agentUid, TVirtualPathPtr(*actualUri, aVirtualPath.UniqueId()), aShareMode);
   211 	
   212 	CleanupStack::PopAndDestroy(2, resolver); // actualUri, resolver
   213 	}
   214 
   215 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
   216 	{
   217 	// Find the agent who handles the file
   218 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   219 	CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
   220 
   221 	// Figure out the Uid of the agent
   222 	TUid agentUid = agentInfo.Agent().ImplementationUid();
   223 
   224 	// call other constructL now that we have the Uid
   225 	CData::ConstructL(agentUid, aFile, aUniqueId, aIntent);
   226 
   227 	// Cleanup resolver after creating CData to unnecessary 
   228 	// unloading and loading of agent plug-ins
   229 	CleanupStack::PopAndDestroy(resolver); 
   230 	}
   231 
   232 void CData::ConstructL(RFile& aFile, const TDesC& aUniqueId)
   233 	{
   234 	// Find the agent who handles the file
   235 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   236 	CAgentInfo& agentInfo = resolver->ResolveFileL(aFile);
   237 
   238 	// Figure out the Uid of the agent
   239 	TUid agentUid = agentInfo.Agent().ImplementationUid();
   240 
   241 	// call other constructL now that we have the Uid
   242 	CData::ConstructL(agentUid, aFile, aUniqueId);
   243 
   244 	// Cleanup resolver after creating CData to unnecessary 
   245 	// unloading and loading of agent plug-ins
   246 	CleanupStack::PopAndDestroy(resolver); 
   247 	}
   248 
   249 void CData::ConstructL(TUid aUid,
   250 					   const TVirtualPathPtr& aVirtualPath,
   251 					   TIntent aIntent,
   252 					   TContentShareMode aShareMode)
   253 	{
   254 	CData::ConstructL(aUid, aVirtualPath, aShareMode);
   255 
   256 	// Ensure that client's intent is possible
   257 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
   258 	}
   259 
   260 void CData::ConstructL(TUid aUid,
   261 					   const TVirtualPathPtr& aVirtualPath,
   262 					   TContentShareMode aShareMode)
   263 	{
   264 	iAgentUid = aUid;
   265 
   266 	// create our own agent factory (de-facto session handle for ECOM)
   267 	iAgentFactory = CAgentFactory::NewL(iAgentUid);
   268 
   269 	// Create an instance of the Agent's CAgentData
   270 	iAgentData = iAgentFactory->CreateDataConsumerL(aVirtualPath, aShareMode);
   271 
   272 	}
   273 
   274 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId, TIntent aIntent)
   275 	{
   276 	CData::ConstructL(aUid, aFile, aUniqueId);
   277 
   278 	// Ensure that client's intent is possible
   279 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
   280 	}
   281 
   282 void CData::ConstructL(TUid aUid, RFile& aFile, const TDesC& aUniqueId)
   283 	{
   284 	iAgentUid = aUid;
   285 
   286 	// create our own agent factory (de-facto session handle for ECOM)
   287 	iAgentFactory = CAgentFactory::NewL(iAgentUid);
   288 
   289 	// Create an instance of the agent's CAgentData
   290 	// The agent must make a duplicate of the file handle
   291 	iAgentData = iAgentFactory->CreateDataConsumerL(aFile, aUniqueId);
   292   	}
   293   
   294 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   295   	
   296 void CData::ConstructL(const TDesC8& aHeaderData)
   297 	{
   298 	// Find the agent who handles the file
   299 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   300 	CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData);
   301 	
   302 	// Figure out the Uid of the agent
   303 	TUid agentUid = agentInfo.Agent().ImplementationUid();
   304 	CData::ConstructL(agentUid, aHeaderData);
   305 	
   306 	// Cleanup resolver after creating CData to unnecessary 
   307 	// unloading and loading of agent plug-ins
   308 	CleanupStack::PopAndDestroy(resolver); 
   309 	}
   310 
   311 void CData::ConstructL(const TDesC8& aHeaderData, TIntent aIntent)
   312 	{
   313 	CData::ConstructL(aHeaderData);
   314 	
   315 	// Ensure that client's intent is possible
   316 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
   317 	}
   318 	
   319 void CData::ConstructL(TUid aAgentUid, const TDesC8& aHeaderData)
   320 	{
   321 	iAgentUid = aAgentUid;
   322 	
   323 	iAgentFactory = CAgentFactory::NewL(iAgentUid);
   324 	// create an instance of agent's CAgentStreamData.
   325 	iAgentData = iAgentFactory->CreateDataConsumerL(aHeaderData);
   326 	}
   327 
   328 void CData::ConstructL(TUid aUid, const TDesC8& aHeaderData, TIntent aIntent)
   329 	{
   330 	CData::ConstructL(aUid, aHeaderData);
   331 	
   332 	// Ensure that client's intent is possible
   333 	User::LeaveIfError(iAgentData->EvaluateIntent(aIntent));
   334 	}
   335 	
   336 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   337 	
   338 EXPORT_C void CData::DataSizeL(TInt& aSize)
   339 	{
   340 	// ask the agent for the data size of the current content object
   341 	iAgentData->DataSizeL(aSize);
   342 	}
   343 
   344 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   345 EXPORT_C void CData::DataSize64L(TInt64& aSize)
   346 	{
   347 	// ask the agent for the data size of the current content object
   348 	TRAPD(err, iAgentData->DataSize64L(aSize));
   349 	if(err == KErrCANotSupported)
   350 		{
   351 		//fallback to 32bit API
   352 		TInt size32;
   353 		iAgentData->DataSizeL(size32);
   354 		aSize = size32;
   355 		}
   356 	else
   357 		User::LeaveIfError(err);
   358 	}
   359 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   360 
   361 EXPORT_C TInt CData::EvaluateIntent(TIntent aIntent)
   362 	{
   363 	// ask the agent to re-evaluate the intent on the current content object
   364 	return iAgentData->EvaluateIntent(aIntent);
   365 	}
   366 
   367 EXPORT_C TInt CData::ExecuteIntent(TIntent aIntent)
   368 	{
   369 	// ask the agent to re-evaluate the intent on the current content object
   370 	return iAgentData->ExecuteIntent(aIntent);
   371 	}
   372 
   373 EXPORT_C TInt CData::Read(TDes8& aDes) const
   374 	{
   375 	// ask the agent to read plaintext from the content object 
   376 	return iAgentData->Read(aDes);
   377 	}
   378 
   379 EXPORT_C TInt CData::Read(TDes8& aDes, TInt aLength) const
   380 	{
   381 	// ask the agent to read plaintext from the content object 
   382 	return iAgentData->Read(aDes, aLength);
   383 	}
   384 
   385 EXPORT_C void CData::Read(TDes8& aDes, 
   386 						  TRequestStatus& aStatus) const
   387 	{
   388 	// ask the agent to read plaintext from the content object 
   389 	iAgentData->Read(aDes, aStatus);
   390 	}
   391 
   392 EXPORT_C void CData::Read(TDes8& aDes, 
   393 						  TInt aLength, 
   394 						  TRequestStatus& aStatus) const
   395 	{
   396 	// ask the agent to read plaintext from the content object 
   397 	iAgentData->Read(aDes, aLength, aStatus);
   398 	}
   399 	
   400 EXPORT_C void CData::ReadCancel(TRequestStatus &aStatus) const
   401 	{
   402 	iAgentData->ReadCancel(aStatus);
   403 	}
   404 	
   405 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   406 
   407 EXPORT_C TInt CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket) const
   408 	{
   409 	return iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket);
   410 	}
   411 		
   412 EXPORT_C void CData::Read(const TDesC8& aEncryptedInputDataPacket, TDes8& aDecryptedOutputPacket, TRequestStatus& aStatus) const
   413 	{
   414 	iAgentData->Read(aEncryptedInputDataPacket, aDecryptedOutputPacket, aStatus);
   415 	}
   416 
   417 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   418 
   419 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   420 	EXPORT_C TInt CData::Read_Unused(TInt aPos, TDes8& aDes, 
   421 								TInt aLength, TRequestStatus& aStatus) const
   422 #else
   423 	EXPORT_C TInt CData::Read(TInt aPos, TDes8& aDes, 
   424 								TInt aLength, TRequestStatus& aStatus) const
   425 #endif
   426 	{
   427 	// ask the agent to read plaintext from the content object 
   428 	if(aPos<0)
   429 		return KErrArgument;
   430 	return iAgentData->Read(aPos, aDes, aLength, aStatus);
   431 	}
   432 
   433 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   434 EXPORT_C TInt CData::Read(TInt64 aPos, TDes8& aDes,
   435 						  TInt aLength, TRequestStatus& aStatus) const
   436 	{
   437 	// If agent does not support 64bit Read, a fallback to 32bit Read is provided automatically
   438 	// The above API method signature allows error codes to be returned
   439 	// via two different routes (return code & aStatus). Should the async request 
   440 	// dispatch fail then an error code is returned immediately via the 
   441 	// aStatus parameter rather than via the return code of the function.	
   442 
   443 	// NOTE: it is not generally not recommended for functions to be able to return
   444 	// error codes in two different ways as this places a bigger error-checking
   445 	// burden on clients.
   446 	if(aPos<0)
   447 		return KErrArgument;
   448 	
   449 	TInt rval = iAgentData->Read64(aPos, aDes, aLength, aStatus);
   450 	return (rval == KErrCANotSupported? iAgentData->Read((TInt)aPos, aDes, aLength, aStatus) : rval );
   451 	}
   452 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   453 
   454 EXPORT_C TInt CData::Seek(TSeek aMode,TInt& aPos) const
   455 	{
   456 	// ask the agent to seek witin the plaintext 
   457 	return iAgentData->Seek(aMode, aPos);
   458 	}
   459 
   460 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   461 EXPORT_C TInt CData::Seek64(TSeek aMode,TInt64& aPos) const
   462 	{
   463 	// ask the agent to seek witin the plaintext 
   464 	TInt rval64 = iAgentData->Seek64(aMode, aPos);
   465 	if(rval64 == KErrCANotSupported)
   466 		{
   467 		//fallback to 32bit API
   468 		TInt pos32 = I64INT(aPos);
   469 		TInt rval32 = iAgentData->Seek(aMode, pos32);
   470 		aPos = pos32;
   471 		return rval32;
   472 		}
   473 	return rval64;
   474 	}
   475 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   476 
   477 EXPORT_C TInt CData::SetProperty(TAgentProperty aProperty, TInt aValue)
   478 	{
   479 	// Set a property within the agent
   480 	return iAgentData->SetProperty(aProperty, aValue);
   481 	}
   482 
   483 EXPORT_C TInt CData::GetAttribute(TInt aAttribute, TInt& aValue) const
   484 	{
   485 	// Get an attribute related to this content object
   486 	return iAgentData->GetAttribute(aAttribute, aValue);
   487 	}
   488 
   489 EXPORT_C TInt CData::GetAttributeSet(RAttributeSet& aAttributeSet) const
   490 	{
   491 	// Get a set of attributes related to this content object
   492 	return iAgentData->GetAttributeSet(aAttributeSet);
   493 	}
   494 
   495 EXPORT_C TInt CData::GetStringAttribute(TInt aAttribute, TDes& aValue) const
   496 	{
   497 	// Get a string attribute related to this content object
   498 	return iAgentData->GetStringAttribute(aAttribute, aValue);
   499 	}
   500 
   501 EXPORT_C TInt CData::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const
   502 	{
   503 	// Get a set of string attributes related to this content object
   504 	return iAgentData->GetStringAttributeSet(aStringAttributeSet);
   505 	}
   506 
   507 #ifndef REMOVE_CAF1
   508 EXPORT_C void CData::SetQosL(TQosAttribute aQosAttr, TInt aValue)
   509 	{
   510 	if(aQosAttr == EQosBufferSize)
   511 		{
   512 		User::LeaveIfError(iAgentData->SetProperty(EAgentPropertyBufferSize, aValue));
   513 		}
   514 	}
   515 
   516 EXPORT_C TBool CData::GetMimeTypeL(TDes8& aMimeType) const
   517 	{
   518 	TBuf16 <KMaxDataTypeLength> mimeType;
   519 	TInt err = KErrNone;
   520 	if(iAgentUid != KF32AgentImplUid)
   521 		{
   522 		err = iAgentData->GetStringAttribute(EMimeType, mimeType);
   523 		if(err == KErrNone && mimeType.Length() != 0)
   524 			{
   525 			aMimeType.Copy(mimeType);
   526 			return ETrue;
   527 			}
   528 		}
   529 	return EFalse;
   530 	}
   531 #endif // REMOVE_CAF1