os/security/contentmgmt/contentaccessfwfordrm/source/caf/content.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 <caf/content.h>
    20 #include "resolver.h"
    21 #include <caf/data.h>
    22 #include <caf/agentfactory.h>
    23 #include "agentinfo.h"
    24 #include <caf/agentinterface.h>
    25 #include <caf/attributeset.h>
    26 #include <caf/agent.h>
    27 #include <caf/virtualpath.h>
    28 #include <caf/agentfactory.h>
    29 #include <caf/caferr.h>
    30 
    31 #ifndef REMOVE_CAF1
    32 #include <caf/attribute.h>
    33 #include <caf/bitset.h>
    34 #endif
    35 
    36 using namespace ContentAccess;
    37 
    38 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI) 
    39 	{
    40 	return CContent::NewLC(aURI, EContentShareReadOnly);
    41 	}
    42 
    43 EXPORT_C CContent* CContent::NewL(const TDesC& aURI)  
    44 	{
    45 	return CContent::NewL(aURI, EContentShareReadOnly);
    46 	}
    47 
    48 EXPORT_C CContent* CContent::NewLC(const TDesC& aURI, TContentShareMode aShareMode) 
    49 	{
    50 	CContent* self = new(ELeave) CContent();
    51 	CleanupStack::PushL(self);
    52 	self->ConstructL(aURI, aShareMode);
    53 	return self;
    54 	}
    55 
    56 EXPORT_C CContent* CContent::NewL(const TDesC& aURI, TContentShareMode aShareMode)  
    57 	{
    58 	CContent* self=CContent::NewLC(aURI, aShareMode);
    59 	CleanupStack::Pop(self);
    60 	return self;
    61 	}
    62 
    63 EXPORT_C CContent* CContent::NewLC(RFile& aFile) 
    64 	{
    65 	CContent* self = new(ELeave) CContent();
    66 	CleanupStack::PushL(self);
    67 	self->ConstructL(aFile);
    68 	return self;
    69 	}
    70 
    71 EXPORT_C CContent* CContent::NewL(RFile& aFile) 
    72 	{
    73 	CContent* self=CContent::NewLC(aFile);
    74 	CleanupStack::Pop(self);
    75 	return self;
    76 	}
    77 
    78 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    79 
    80 EXPORT_C CContent* CContent::NewLC(const TDesC8& aHeaderData) 
    81 	{
    82 	CContent* self = new(ELeave) CContent();
    83 	CleanupStack::PushL(self);
    84 	self->ConstructL(aHeaderData);
    85 	return self;
    86 	}
    87 
    88 EXPORT_C CContent* CContent::NewL(const TDesC8& aHeaderData) 
    89 	{
    90 	CContent* self=CContent::NewLC(aHeaderData);
    91 	CleanupStack::Pop(self);
    92 	return self;
    93 	}
    94 	
    95 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
    96 
    97 CContent::CContent() : iDefaultVirtualPath(KNullDesC(), KDefaultContentObject())
    98 	{ 
    99 	}
   100 
   101 CContent::~CContent() 
   102 	{ 
   103 	delete iAgentContent;
   104 	iFile.Close();
   105 	
   106 	if(iVirtualPath)
   107 		{
   108 		delete iVirtualPath;
   109 		}
   110 	
   111 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   112 	delete iHeaderData;
   113 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   114 	
   115 	// Finished with agent, this closes ECOM handle
   116 	delete iAgentFactory;
   117 	REComSession::FinalClose();
   118 	}
   119 
   120 
   121 void CContent::ConstructL(RFile &aFile) 
   122 	{
   123 	// Make our own copy of the file handle
   124 	User::LeaveIfError(iFile.Duplicate(aFile));
   125 	
   126 	// Rewind the file pointer
   127 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   128 	TInt64 pos = 0;
   129 #else
   130 	TInt pos = 0;
   131 #endif //SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   132 
   133 	iFile.Seek(ESeekStart, pos);
   134 	
   135 	// For case where CAF is built with an RFile
   136 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   137 	
   138 	// Find the agent who handles the file
   139 	CAgentInfo& agentInfo = resolver->ResolveFileL(iFile);
   140 
   141 	// copy the agent name and Uid
   142 	iAgent = agentInfo.Agent();
   143 
   144 	// Construct the agent factory (ECOM handle)
   145 	iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
   146 
   147 	// Construct the CAgentContent object
   148 	iAgentContent = iAgentFactory->CreateContentBrowserL(iFile);
   149 
   150 	// Finished with resolver (and the agentInfo object it owns)
   151 	CleanupStack::PopAndDestroy(resolver); 
   152 	}
   153 
   154 void CContent::ConstructL(const TDesC& aURI, TContentShareMode aShareMode) 
   155 	{
   156 	iShareMode = aShareMode;
   157 
   158 	// Create the agent resolver which will contains a reference to
   159 	// the agent responsible for this piece of content
   160 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   161 	
   162 	// Create a temporary buffer used to store the translated version of the URI
   163 	HBufC* actualUri = HBufC::NewLC(aURI.Length() + KMaxSIDLength);
   164 	TPtr uri = actualUri->Des();
   165 	
   166 	// Set the TVirtualPathPtr to point to the URI supplied, 
   167 	// this will decode any combined URI into the actual URI and uniqueId
   168 	// for use in subsequent functions
   169 	TVirtualPathPtr contentVirtualPath = aURI;
   170 
   171 	// Find the agent who handles the file and translate the URI if it is pointing to a private directory 
   172 	CAgentInfo& agentInfo = resolver->ResolveFileL(contentVirtualPath.URI(), uri, iShareMode);
   173 
   174 	// Set the iVirtualPath to point to the translated URI and the uniqueId
   175 	iVirtualPath = CVirtualPath::NewL(*actualUri, contentVirtualPath.UniqueId());
   176 	
   177 	iDefaultVirtualPath = *iVirtualPath;
   178 	
   179 	// Copy the agent name and Uid
   180 	iAgent = agentInfo.Agent();
   181 
   182 	// Construct the agent factory (ECOM handle)
   183 	iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
   184 
   185 	// Construct the agent content browser 
   186 	iAgentContent = iAgentFactory->CreateContentBrowserL(uri, iShareMode);	
   187 	
   188 	// Finished with resolver and the CAgentInfo object it owns
   189 	CleanupStack::PopAndDestroy(2, resolver); // actualUri
   190 	}
   191 
   192 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   193 
   194 void CContent::ConstructL(const TDesC8& aHeaderData) 
   195 	{
   196 	if(aHeaderData.Length() <= 0)
   197 		{
   198 		User::Leave(KErrMissingWmdrmHeaderData);
   199 		}
   200 	
   201 	iHeaderData = aHeaderData.AllocL();
   202 	
   203 	CAgentResolver* resolver = CAgentResolver::NewLC(EFalse);
   204 	
   205 	// Find the agent who handles the file
   206 	CAgentInfo& agentInfo = resolver->ResolveFileL(aHeaderData);
   207 
   208 	// copy the agent name and Uid
   209 	iAgent = agentInfo.Agent();
   210 
   211 	// Construct the agent factory (ECOM handle)
   212 	iAgentFactory = CAgentFactory::NewL(iAgent.ImplementationUid());
   213 	// Construct the CAgentContent object
   214 	iAgentContent = iAgentFactory->CreateContentBrowserL(aHeaderData);
   215 
   216 	// Finished with resolver (and the agentInfo object it owns)
   217 	CleanupStack::PopAndDestroy(resolver); 
   218 	}
   219 
   220 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   221 
   222 EXPORT_C TInt CContent::OpenContainer(const TDesC &aUniqueId) 
   223 	{
   224 	return iAgentContent->OpenContainer(aUniqueId);
   225 	}
   226 
   227 EXPORT_C TInt CContent::CloseContainer ()
   228 	{
   229 	return iAgentContent->CloseContainer();
   230 	}
   231 
   232 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray) const
   233 	{
   234 	iAgentContent->GetEmbeddedObjectsL(aArray);
   235 	}
   236 
   237 EXPORT_C void CContent::GetEmbeddedObjectsL (RStreamablePtrArray<CEmbeddedObject>& aArray, TEmbeddedType aType) const
   238 	{
   239 	iAgentContent->GetEmbeddedObjectsL(aArray, aType);
   240 	}
   241 
   242 EXPORT_C TInt  CContent::Search (RStreamablePtrArray<CEmbeddedObject>& aArray, const TDesC8 &aMimeType, TBool aRecursive) 
   243 	{
   244 	return iAgentContent->Search(aArray, aMimeType, aRecursive);
   245 	}
   246 
   247 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt &aValue) const
   248 	{
   249 	return GetAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId());
   250 	}
   251 
   252 EXPORT_C TInt CContent::GetAttribute (TInt aAttribute, TInt& aValue, const TDesC &aUniqueId) const
   253 	{
   254 	return iAgentContent->GetAttribute(aAttribute, aValue, aUniqueId);
   255 	}
   256 
   257 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet) const
   258 	{
   259 	return GetAttributeSet(aAttributeSet, iDefaultVirtualPath.UniqueId());
   260 	}
   261 
   262 EXPORT_C TInt CContent::GetAttributeSet(RAttributeSet& aAttributeSet, const TDesC& aUniqueId) const
   263 	{
   264 	return iAgentContent->GetAttributeSet(aAttributeSet, aUniqueId);
   265 	}
   266 
   267 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue) const
   268 	{
   269 	return GetStringAttribute(aAttribute, aValue, iDefaultVirtualPath.UniqueId());
   270 	}
   271 
   272 EXPORT_C TInt CContent::GetStringAttribute (TInt aAttribute, TDes &aValue, const TDesC &aUniqueId) const
   273 	{
   274 	return iAgentContent->GetStringAttribute(aAttribute, aValue, aUniqueId);
   275 	}
   276 
   277 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet) const
   278 	{
   279 	return GetStringAttributeSet(aStringAttributeSet, iDefaultVirtualPath.UniqueId());
   280 	}
   281 
   282 EXPORT_C TInt CContent::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, const TDesC& aUniqueId) const
   283 	{
   284 	return iAgentContent->GetStringAttributeSet(aStringAttributeSet, aUniqueId);
   285 	}
   286 
   287 EXPORT_C TInt CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer) 
   288 	{
   289 	return iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer);
   290 	}
   291 
   292 EXPORT_C void CContent::AgentSpecificCommand (TInt aCommand, const TDesC8 &aInputBuffer, TDes8 &aOutputBuffer, TRequestStatus &aStatus) 
   293 	{
   294 	iAgentContent->AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer, aStatus);
   295 	}
   296 
   297 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus) 
   298 	{
   299 	NotifyStatusChange(aMask, aStatus, iDefaultVirtualPath.UniqueId());
   300 	}
   301 
   302 EXPORT_C void CContent::NotifyStatusChange(TEventMask aMask, TRequestStatus &aStatus, const TDesC &aUniqueId) 
   303 	{
   304 	iAgentContent->NotifyStatusChange(aMask, aStatus, aUniqueId);
   305 	}
   306 
   307 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus) 
   308 	{
   309 	return CancelNotifyStatusChange(aStatus, iDefaultVirtualPath.UniqueId());
   310 	}
   311 
   312 EXPORT_C TInt CContent::CancelNotifyStatusChange(TRequestStatus &aStatus, const TDesC &aUniqueId) 
   313 	{
   314 	return iAgentContent->CancelNotifyStatusChange(aStatus, aUniqueId);
   315 	}
   316 
   317 EXPORT_C void  CContent::RequestRights(TRequestStatus &aStatus) 
   318 	{
   319 	RequestRights(aStatus, iDefaultVirtualPath.UniqueId());
   320 	}
   321 
   322 EXPORT_C void  CContent::RequestRights(TRequestStatus &aStatus, const TDesC &aUniqueId) 
   323 	{
   324 	iAgentContent->RequestRights(aStatus, aUniqueId);
   325 	}
   326 
   327 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus)
   328 	{
   329 	return CancelRequestRights(aStatus, iDefaultVirtualPath.UniqueId());
   330 	}
   331 
   332 EXPORT_C TInt CContent::CancelRequestRights(TRequestStatus &aStatus, const TDesC& aUniqueId)
   333 	{
   334 	return iAgentContent->CancelRequestRights(aStatus, aUniqueId);
   335 	}
   336 
   337 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo) const
   338 	{
   339 	DisplayInfoL(aInfo, iDefaultVirtualPath.UniqueId());
   340 	}
   341 
   342 EXPORT_C void CContent::DisplayInfoL(TDisplayInfo aInfo, const TDesC& aUniqueId) const
   343 	{
   344 	iAgentContent->DisplayInfoL(aInfo, aUniqueId);
   345 	}
   346 
   347 EXPORT_C TInt CContent::SetProperty(TAgentProperty aProperty, TInt aValue) 
   348 	{
   349 	return iAgentContent->SetProperty(aProperty, aValue);
   350 	}
   351 
   352 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent)
   353 	{
   354 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   355 	if(iHeaderData != NULL)
   356 		return OpenContentL(aIntent, *iHeaderData);
   357     else
   358 		return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
   359 #else
   360 	return OpenContentL(aIntent, iDefaultVirtualPath.UniqueId());
   361 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   362 	}
   363 
   364 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent)
   365 	{
   366 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   367 	if(iHeaderData != NULL)
   368 		return OpenContentLC(aIntent, *iHeaderData);
   369 	else
   370 		return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
   371 #else
   372 	return OpenContentLC(aIntent, iDefaultVirtualPath.UniqueId());
   373 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   374 	}
   375 
   376 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, const TDesC &aUniqueId)
   377 	{
   378 	CData* data = OpenContentLC(aIntent, aUniqueId);
   379 	CleanupStack::Pop(data);
   380 	return data;
   381 	}
   382 
   383 EXPORT_C CData* CContent::OpenContentLC(TIntent aIntent, const TDesC &aUniqueId)
   384 	{
   385 	// Open the content object specified by the Unique Id
   386 	if(iVirtualPath)
   387 		{
   388 		// create a CData based upon the URI supplied when this CContent was created
   389 		return CData::NewLC(iAgent.ImplementationUid(), TVirtualPathPtr(iDefaultVirtualPath.URI(), aUniqueId), aIntent, iShareMode);
   390 		}
   391 	else
   392 		{
   393 		// create a CData based upon the file handle supplied when this CContent was created
   394 		return CData::NewLC(iAgent.ImplementationUid(), iFile, aUniqueId, aIntent);
   395 		}
   396 	}
   397 	
   398 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   399 
   400 CData* CContent::OpenContentL(TIntent aIntent, const TDesC8& aHeaderData)
   401 	{
   402 	CData* data = OpenContentLC(aIntent, aHeaderData);
   403 	CleanupStack::Pop(data);
   404 	return data;
   405 	}
   406 
   407 CData* CContent::OpenContentLC(TIntent aIntent, const TDesC8& aHeaderData)
   408 	{
   409 	return CData::NewLC(iAgent.ImplementationUid(), aHeaderData, aIntent);
   410 	}
   411 	
   412 #endif //#ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   413 
   414 EXPORT_C const TAgent& CContent::Agent() const
   415 	{
   416 	// The agent handling this content
   417 	return iAgent;
   418 	}
   419 
   420 #ifndef REMOVE_CAF1 
   421 // Deprecated functions
   422 
   423 EXPORT_C CData* CContent::OpenContentL(TIntent aIntent, TContentShareMode aShareMode)
   424 	{
   425 	CData* data = NULL;
   426 	// Open the content object specified by the Unique Id
   427 	if(iVirtualPath)
   428 		{
   429 		// create a CData based upon the URI supplied when this CContent was created
   430 		data = CData::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath, aIntent, aShareMode);
   431 		}
   432 	else
   433 		{
   434 		// create a CData based upon the file handle supplied when this CContent was created
   435 		data = CData::NewLC(iAgent.ImplementationUid(), iFile, iDefaultVirtualPath.UniqueId(), aIntent);
   436 		}
   437 	CleanupStack::Pop(data);
   438 	return data;
   439 	}
   440 
   441 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded)
   442 	{
   443 	return NewAttributeL(aPreloaded, EContentShareReadOnly);
   444 	}
   445 
   446 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   447 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
   448 	{
   449 	CAttribute* attr = NULL;
   450 	
   451 	if(iVirtualPath)
   452 		{
   453 		// if we were opened with a file name
   454 		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode);
   455 		}
   456 	else if(iHeaderData)
   457 		{
   458 		attr = CAttribute::NewLC(iAgent.ImplementationUid(), *iHeaderData);
   459 		}
   460 	else
   461 		{
   462 		// if we were opened with a file handle 
   463 		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile);
   464 		}
   465 
   466 	// If aPreloaded is set, query the agent immediately for all the attributes
   467 	if (aPreloaded)
   468 		{
   469 		attr->QuerySet().SetAll();
   470 		attr->GetL();
   471 		}
   472 
   473 	CleanupStack::Pop(attr);
   474 	return attr;
   475 	}
   476 
   477 #else
   478 
   479 EXPORT_C CAttribute* CContent::NewAttributeL(TBool aPreloaded, TContentShareMode aShareMode)
   480 	{
   481 	CAttribute* attr = NULL;
   482 	
   483 	if(iVirtualPath)
   484 		{
   485 		// if we were opened with a file name
   486 		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iDefaultVirtualPath.URI(), aShareMode);
   487 		}
   488 	else
   489 		{
   490 		// if we were opened with a file handle 
   491 		attr = CAttribute::NewLC(iAgent.ImplementationUid(), iFile);
   492 		}
   493 
   494 	// If aPreloaded is set, query the agent immediately for all the attributes
   495 	if (aPreloaded)
   496 		{
   497 		attr->QuerySet().SetAll();
   498 		attr->GetL();
   499 		}
   500 
   501 	CleanupStack::Pop(attr);
   502 	return attr;
   503 	}
   504 
   505 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   506 
   507 #endif // REMOVE_CAF1
   508 
   509 // DLL entry point - only for EKA1
   510 
   511 
   512 
   513