contentmgmt/referencedrmagent/TestAgent/testagentmanager.cpp
changeset 15 da2ae96f639b
child 19 cd501b96611d
equal deleted inserted replaced
10:afc583cfa176 15:da2ae96f639b
       
     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/caf.h>
       
    20 #include <caf/dirstreamable.h>
       
    21 #include "testagentmanager.h"
       
    22 #include "testagentattributes.h"
       
    23 #include "TestAgentFile.h"
       
    24 #include "TestAgentDrmContent.h"
       
    25 #include <stringpool.h>
       
    26 #include <http.h>
       
    27 #include <http/rhttpheaders.h>
       
    28 #include <stringpool.h>
       
    29 using namespace ContentAccess;
       
    30 
       
    31 _LIT(KDrmContentExtension,".DRM");
       
    32 // Do not change the case of KDrmMimeType as it is needed for case testing.
       
    33 _LIT(KDrmMimeType, "APPLICATION/TESTAGENT.DRM");
       
    34 
       
    35 CTestAgentManager* CTestAgentManager::NewL()
       
    36 	{
       
    37 	CTestAgentManager* self = NewLC();
       
    38 	CleanupStack::Pop(self);
       
    39 	return self;
       
    40 	}
       
    41 
       
    42 CTestAgentManager* CTestAgentManager::NewLC()
       
    43 	{
       
    44 	CTestAgentManager* self=new(ELeave) CTestAgentManager();
       
    45 	CleanupStack::PushL(self);
       
    46 	self->ConstructL();
       
    47 	return self;
       
    48 	}
       
    49 
       
    50 CTestAgentManager::CTestAgentManager()
       
    51 	{
       
    52 	}
       
    53 
       
    54 CTestAgentManager::~CTestAgentManager()
       
    55 	{
       
    56 	delete iFileMan;
       
    57 	iFs.Close();
       
    58 	}
       
    59   
       
    60 void CTestAgentManager::ConstructL()
       
    61 	{
       
    62 	User::LeaveIfError(iFs.Connect());
       
    63 	iFileMan = CFileMan::NewL(iFs);
       
    64 	}
       
    65 
       
    66 
       
    67 TInt CTestAgentManager::DeleteFile(const TDesC &aFileName)	
       
    68 	{
       
    69 	// Most likely would have some kind of rights check here to determine if it can be
       
    70 	// deleted
       
    71 	return iFs.Delete(aFileName);
       
    72 	}
       
    73 
       
    74 TInt CTestAgentManager::CopyFile(const TDesC& /*aSource*/, const TDesC& /*aDestination*/)
       
    75 	{
       
    76 	return KErrCANotSupported;
       
    77 	}
       
    78 
       
    79 TInt CTestAgentManager::CopyFile(RFile& /*aSource*/, const TDesC& /*aDestination*/)
       
    80 	{
       
    81 	return KErrCANotSupported;
       
    82 	}
       
    83 
       
    84 TInt CTestAgentManager::RenameFile(const TDesC& /*aSource*/, const TDesC& /*aDestination*/)
       
    85 	{
       
    86 	return KErrCANotSupported;
       
    87 	}
       
    88 
       
    89 TInt CTestAgentManager::MkDir(const TDesC& /*aPath*/)
       
    90 	{
       
    91 	return KErrCANotSupported;
       
    92 	}
       
    93 
       
    94 TInt CTestAgentManager::MkDirAll(const TDesC& /*aPath*/)
       
    95 	{
       
    96 	return KErrCANotSupported;
       
    97 	}	
       
    98 
       
    99 TInt CTestAgentManager::RmDir(const TDesC& /*aPath*/)
       
   100 	{
       
   101 	return KErrCANotSupported;
       
   102 	}	
       
   103 
       
   104 TInt CTestAgentManager::GetDir(const TDesC& /*aName*/,TUint /*aEntryAttMask*/,TUint /*aEntrySortKey*/, CDir*& /*aEntryList*/) const 
       
   105 	{
       
   106 	return KErrCANotSupported;
       
   107 	}
       
   108 
       
   109 TInt CTestAgentManager::GetDir(const TDesC& /*aName*/,TUint /*aEntryAttMask*/,TUint /*aEntrySortKey*/, CDir*& /*aEntryList*/,CDir*& /*aDirList*/) const
       
   110 	{
       
   111 	return KErrCANotSupported;
       
   112 	}
       
   113 
       
   114 TInt CTestAgentManager::GetDir(const TDesC& /*aName*/,const TUidType& /*aEntryUid*/,TUint /*aEntrySortKey*/, CDir*& /*aFileList*/) const
       
   115 	{
       
   116 	return KErrCANotSupported;
       
   117 	}
       
   118 
       
   119 TInt CTestAgentManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath)
       
   120 	{
       
   121 	TRAPD(err, GetAttributeL(aAttribute, aValue, aVirtualPath));
       
   122 	return err;
       
   123 	}
       
   124 
       
   125 void CTestAgentManager::GetAttributeL(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath)
       
   126 	{
       
   127 	RFile file;
       
   128 	CTestAgentFileInterface *fileObject = NULL;
       
   129 
       
   130 	// check virtual path here to see it's ok
       
   131 	if(TTestAgentAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
       
   132 		{
       
   133 		User::Leave( KErrNotFound );	
       
   134 		}
       
   135 
       
   136 	// open file in order to retrieve an attribute from it
       
   137 	User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileStream | EFileRead | EFileShareReadersOnly));
       
   138 	CleanupClosePushL(file);
       
   139 
       
   140 	if(aVirtualPath.UniqueId().Length() == 0)
       
   141 		{
       
   142 		fileObject = CTestAgentFile::NewL(file);
       
   143 		}
       
   144 	else
       
   145 		{
       
   146 		fileObject = CTestAgentDrmContent::NewL(file);
       
   147 		}
       
   148 	CleanupStack::PushL(fileObject);
       
   149 
       
   150 	User::LeaveIfError(fileObject->GetAttribute(aAttribute, aValue));
       
   151 	CleanupStack::PopAndDestroy(2, &file);
       
   152 	}
       
   153 
       
   154 TInt CTestAgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
       
   155 	{
       
   156 	TRAPD(err, GetAttributeSetL(aAttributeSet, aVirtualPath));
       
   157 	return err;
       
   158 	}
       
   159 
       
   160 void CTestAgentManager::GetAttributeSetL(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
       
   161 	{
       
   162 	RFile file;
       
   163 	CTestAgentFileInterface *fileObject = NULL;	
       
   164 
       
   165 	// check virtual path here to see it's ok
       
   166 	if(TTestAgentAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
       
   167 		{
       
   168 		User::Leave( KErrNotFound );	
       
   169 		}
       
   170 
       
   171 	// open file in order to retrieve an attribute from it
       
   172 	User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileStream | EFileRead | EFileShareReadersOnly));
       
   173 	CleanupClosePushL(file);
       
   174 
       
   175 	if(aVirtualPath.UniqueId().Length() == 0)
       
   176 		{
       
   177 		fileObject = CTestAgentFile::NewL(file);
       
   178 		}
       
   179 	else
       
   180 		{
       
   181 		fileObject = CTestAgentDrmContent::NewL(file);
       
   182 		}
       
   183 	CleanupStack::PushL(fileObject);
       
   184 	User::LeaveIfError(TTestAgentAttributes::GetAttributeSet(*fileObject, aAttributeSet));
       
   185 	CleanupStack::PopAndDestroy(2, &file);
       
   186 	}
       
   187 
       
   188 TInt CTestAgentManager::GetStringAttributeSet(RStringAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
       
   189 	{
       
   190 	TRAPD(err, GetStringAttributeSetL(aAttributeSet, aVirtualPath));
       
   191 	return err;
       
   192 	}
       
   193 
       
   194 void CTestAgentManager::GetStringAttributeSetL(RStringAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
       
   195 	{
       
   196 	RFile file;
       
   197 	CTestAgentFileInterface *fileObject = NULL;
       
   198 	
       
   199 	// check virtual path here to see it's ok
       
   200 	if(TTestAgentAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
       
   201 		{
       
   202 		User::Leave(KErrNotFound);	
       
   203 		}
       
   204 
       
   205 	// open file in order to retrieve an attribute from it
       
   206 	User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileStream | EFileRead | EFileShareReadersOnly));
       
   207 
       
   208 	CleanupClosePushL(file);
       
   209 
       
   210 	if(aVirtualPath.UniqueId().Length() == 0)
       
   211 		{
       
   212 		fileObject = CTestAgentFile::NewL(file);
       
   213 		}
       
   214 	else
       
   215 		{
       
   216 		fileObject = CTestAgentDrmContent::NewL(file);
       
   217 		}
       
   218 
       
   219 	CleanupStack::PushL(fileObject);
       
   220 	User::LeaveIfError(TTestAgentAttributes::GetStringAttributeSet(*fileObject, aAttributeSet));
       
   221 	CleanupStack::PopAndDestroy(2, &file);
       
   222 	}
       
   223 
       
   224 TInt CTestAgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath)
       
   225 	{
       
   226 	TRAPD(err, GetStringAttributeL(aAttribute, aValue, aVirtualPath));
       
   227 	return err;
       
   228 	}
       
   229 
       
   230 void CTestAgentManager::GetStringAttributeL(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath)
       
   231 	{
       
   232 	RFile file;
       
   233 	CTestAgentFileInterface *fileObject = NULL;
       
   234 	
       
   235 	// check virtual path here to see it's ok
       
   236 	if(TTestAgentAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
       
   237 		{
       
   238 		User::Leave( KErrNotFound );	
       
   239 		}
       
   240 
       
   241 	// open file in order to retrieve an attribute from it
       
   242 	User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileStream | EFileRead | EFileShareReadersOnly));
       
   243 	CleanupClosePushL(file);
       
   244 
       
   245 	if(aVirtualPath.UniqueId().Length() == 0)
       
   246 		{
       
   247 		fileObject = CTestAgentFile::NewL(file);
       
   248 		}
       
   249 	else
       
   250 		{
       
   251 		fileObject = CTestAgentDrmContent::NewL(file);
       
   252 		}
       
   253 	CleanupStack::PushL(fileObject);
       
   254 
       
   255 	User::LeaveIfError(fileObject->GetStringAttribute(aAttribute, aValue));
       
   256 	CleanupStack::PopAndDestroy(2, &file);
       
   257 	}
       
   258 
       
   259 void CTestAgentManager::NotifyStatusChange(const TDesC& /*aURI*/, TEventMask /*aMask*/, TRequestStatus& aStatus)
       
   260 	{
       
   261 	TRequestStatus *ptr = &aStatus;
       
   262 	User::RequestComplete(ptr, KErrCANotSupported);
       
   263 	}
       
   264 
       
   265 TInt CTestAgentManager::CancelNotifyStatusChange(const TDesC& /*aURI*/, TRequestStatus& /*aStatus*/)
       
   266 	{
       
   267 	return KErrCANotSupported;
       
   268 	}
       
   269 
       
   270 TInt CTestAgentManager::SetProperty(TAgentProperty /*aProperty*/, TInt /*aValue*/)
       
   271 	{
       
   272 	return KErrNone;
       
   273 	}
       
   274 
       
   275 void CTestAgentManager::DisplayInfoL(TDisplayInfo /*aInfo*/, const TVirtualPathPtr& /*aVirtualPath*/)
       
   276 	{
       
   277 	User::Leave(KErrCANotSupported);
       
   278 	}	
       
   279 
       
   280 TBool CTestAgentManager::IsRecognizedL(const TDesC& aUri, TContentShareMode /*aShareMode*/) const
       
   281 	{
       
   282 	// This is a test implementation of IsRecognizedL
       
   283 	// For testing purposes it only recognizes DCF content files
       
   284 
       
   285 	TInt result;
       
   286 	
       
   287 	// Convert URI to uppercase
       
   288 	HBufC *uriUpper = aUri.AllocLC();
       
   289 	TPtr uriPtr(uriUpper->Des());
       
   290 	uriPtr.UpperCase();
       
   291 
       
   292 	// Check that the file extension is .DRM
       
   293 	TPtrC extension = uriPtr.Right(KDrmContentExtension().Length());
       
   294 	result = extension.Compare(KDrmContentExtension);
       
   295 	CleanupStack::PopAndDestroy(uriUpper);
       
   296 	
       
   297 	if(result == 0)
       
   298 		{
       
   299 		return ETrue;
       
   300 		}
       
   301 	else 
       
   302 		{
       
   303 		return EFalse;
       
   304 		}
       
   305 	}
       
   306 
       
   307 TBool CTestAgentManager::IsRecognizedL(RFile& aFile) const
       
   308 	{
       
   309 	// This is a test implementation of IsRecognizedL
       
   310 	// For testing purposes it only recognizes DCF content files
       
   311 
       
   312 	TInt result;
       
   313 	
       
   314 	// Convert URI to uppercase
       
   315 	HBufC *uriUpper = HBufC::NewLC(KMaxFileName);
       
   316 	TPtr uriPtr(uriUpper->Des());
       
   317 	aFile.Name(uriPtr);
       
   318 	uriPtr.UpperCase();
       
   319 
       
   320 	// Check that the file extension is .DRM
       
   321 	TPtrC extension = uriPtr.Right(KDrmContentExtension().Length());
       
   322 	result = extension.Compare(KDrmContentExtension);
       
   323 	CleanupStack::PopAndDestroy(uriUpper);
       
   324 	
       
   325 	if(result == 0)
       
   326 		{
       
   327 		return ETrue;
       
   328 		}
       
   329 	else 
       
   330 		{
       
   331 		return EFalse;
       
   332 		}
       
   333 	}
       
   334 
       
   335 TBool CTestAgentManager::RecognizeFileL(const TDesC& aFileName, const TDesC8& aBuffer, TDes8& aFileMimeType, TDes8& aContentMimeType) const
       
   336 	{
       
   337 	// This is a test implementation of DoRecognizeL
       
   338 	// For testing purposes it only recognizes DCF content files
       
   339 	TInt result;
       
   340 
       
   341 	// Convert filename to uppercase
       
   342 	HBufC *FileNameUpper = aFileName.AllocLC();
       
   343 	TPtr FileNamePtr(FileNameUpper->Des());
       
   344 	FileNamePtr.UpperCase();
       
   345 
       
   346 	// Check filename extension
       
   347 	TPtrC extension = FileNamePtr.Right(KDrmContentExtension().Length());
       
   348 	result = extension.Compare(KDrmContentExtension);
       
   349 	CleanupStack::PopAndDestroy(); // FileNameUpper
       
   350 
       
   351 	if(result == 0)
       
   352 		{
       
   353 		// It's a .DRM file
       
   354 		aFileMimeType.Copy(KDrmMimeType);
       
   355 	
       
   356 		if(aBuffer.Length() > 3)
       
   357 			{
       
   358 			// Find content type 
       
   359 			// content-type length is a single byte, stored at offset 0 in the DRM file
       
   360 			TUint8 length = aBuffer[0];
       
   361 
       
   362 			// find out if the file has been processed through supplier
       
   363 			// interface yet
       
   364 			if(aBuffer[length + 1] == (TUint8)'T')
       
   365 				{
       
   366 				// content type always starts at offset 1 in the DCF file
       
   367 				aContentMimeType.Copy(aBuffer.Mid(1,length));
       
   368 				}
       
   369 			}
       
   370 		return ETrue;
       
   371 		}
       
   372 	else
       
   373 		{
       
   374 		return EFalse;
       
   375 		}
       
   376 	}
       
   377 
       
   378 
       
   379 _LIT(KAgentSpecificCommandResponse, "output");
       
   380 
       
   381 TInt CTestAgentManager::AgentSpecificCommand(TInt aCommand, const TDesC8& /*aInputBuffer*/, TDes8& aOutputBuffer)
       
   382 	{
       
   383 	if(aCommand == 1)
       
   384 		{
       
   385 		aOutputBuffer.Copy(KAgentSpecificCommandResponse());
       
   386 		return KErrNone;
       
   387 		}
       
   388 	return KErrCANotSupported;
       
   389 	}
       
   390 
       
   391 void CTestAgentManager::AgentSpecificCommand(TInt aCommand, const TDesC8& aInputBuffer, TDes8& aOutputBuffer, TRequestStatus& aStatus)
       
   392 	{
       
   393 	TRequestStatus *ptr = &aStatus;
       
   394 	User::RequestComplete(ptr, AgentSpecificCommand(aCommand, aInputBuffer, aOutputBuffer));
       
   395 	}
       
   396 
       
   397 void CTestAgentManager::DisplayManagementInfoL()
       
   398 	{
       
   399 	User::Leave(KErrCANotSupported);
       
   400 	}
       
   401 
       
   402 //
       
   403 // This API is non-leaving and returns void. If we want to
       
   404 // make leavescan happy, the options are: 1. TRAP leave calls
       
   405 // and ignore the errors. 2. Panic. Both options could potentially
       
   406 // break RTA clients' testcases. Hence just leave it the way it is.
       
   407 #ifndef SYMBIAN_DISABLE_UPWARD_DEPENDENCY
       
   408 void CTestAgentManager::PrepareHTTPRequestHeaders(RStringPool& aStringPool, RHTTPHeaders& aRequestHeaders) const
       
   409 	{
       
   410 	TBuf8 <KMaxDataTypeLength> mimeType;
       
   411 	mimeType.Copy(KDrmMimeType());
       
   412 	RStringF valStr = aStringPool.OpenFStringL(mimeType);
       
   413 	CleanupClosePushL(valStr);
       
   414 	THTTPHdrVal val(valStr);
       
   415 	aRequestHeaders.SetFieldL(aStringPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), val);
       
   416 	CleanupStack::PopAndDestroy(&valStr);
       
   417 	}
       
   418 #else
       
   419 void CTestAgentManager::PrepareHTTPRequestHeaders(RStringPool& /*aStringPool*/, RHTTPHeaders& /*aRequestHeaders*/) const
       
   420 	{
       
   421 	}
       
   422 #endif
       
   423