os/security/contentmgmt/contentaccessfwfordrm/source/f32agent/f32agentmanager.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/cafpanic.h>
    20 #include <caf/virtualpathptr.h>
    21 #include <caf/dirstreamable.h>
    22 #include "f32agentmanager.h"
    23 #include "f32defaultattributes.h"
    24 #include <caf/f32agentui.h>
    25 
    26 using namespace ContentAccess;
    27 
    28 CF32AgentManager* CF32AgentManager::NewL()
    29 	{
    30 	CF32AgentManager* self=new(ELeave) CF32AgentManager();
    31 	CleanupStack::PushL(self);
    32 	self->ConstructL();
    33 	CleanupStack::Pop(self);
    34 	return self;
    35 	}
    36 
    37 CF32AgentManager::CF32AgentManager()
    38 	{
    39 	}
    40 
    41 CF32AgentManager::~CF32AgentManager()
    42 	{
    43 	delete iFileMan;
    44 	iFs.Close();
    45 	}
    46   
    47 void CF32AgentManager::ConstructL()
    48 	{
    49 	User::LeaveIfError(iFs.Connect());
    50 	iFileMan = CFileMan::NewL(iFs);
    51 	}
    52 
    53 TBool CF32AgentManager::IsRecognizedL(const TDesC&, TContentShareMode) const
    54 	{
    55 	// F32 should be the default agent and should never be called here
    56 	return EFalse;
    57 	}
    58 
    59 TBool CF32AgentManager::IsRecognizedL(RFile& ) const
    60 	{
    61 	return EFalse;
    62 	}	
    63 
    64 TBool CF32AgentManager::RecognizeFileL(const TDesC&, const TDesC8&, TDes8&, TDes8&) const
    65 	{
    66 	// F32 should be the default agent and should never be called here
    67 	return EFalse;
    68 	}
    69 
    70 TInt CF32AgentManager::DeleteFile(const TDesC &aFileName)
    71 	{
    72 	TInt err = KErrNone;
    73 	CF32AgentUi* ui = NULL;
    74 	TBool enableDelete = ETrue;
    75 	
    76 	// get a pointer to the UI
    77 	TRAP(err, ui = &AgentUiL());
    78 	if(err == KErrNone)
    79 		{
    80 		// UI confirmation supported, see if user wants to delete
    81 		TRAP(err, enableDelete = ui->ConfirmDeleteL(aFileName));
    82 		if(err == KErrNone && enableDelete)
    83 			{
    84 			// User agrees to delete
    85 			err = iFs.Delete(aFileName);
    86 			}
    87 		}
    88 	else if(err == KErrCANotSupported)
    89 		{
    90 		// UI is not supported, just delete it
    91 		err = iFs.Delete(aFileName);
    92 		}
    93 	return err;
    94 	}
    95 
    96 TInt CF32AgentManager::CopyFile(const TDesC& aSource, const TDesC& aDestination)
    97 	{
    98 	return iFileMan->Copy(aSource, aDestination);
    99 	}
   100 
   101 TInt CF32AgentManager::CopyFile(RFile& aSource, const TDesC& aDestination)
   102 	{
   103 	return iFileMan->Copy(aSource, aDestination);
   104 	}
   105 
   106 TInt CF32AgentManager::RenameFile(const TDesC& aSource, const TDesC& aDestination)
   107 	{
   108 	TInt result = iFileMan->Rename(aSource, aDestination); 
   109 	// If the files are on a different drive, Rename will fail 
   110 	// Therefore we simulate the Move by doing a Copy, followed by Delete 
   111 	if (result != KErrNone) 
   112 		{ 
   113 		result = iFileMan->Copy(aSource,aDestination); 
   114 		if (result == KErrNone) 
   115 			{ 
   116 			// If the copy was successful try and delete the original 
   117 			result = iFileMan->Delete(aSource); 
   118 			if (result != KErrNone) 
   119 				{
   120 				 // Delete failed so try to cleanup the destination file as we're going to exit with an error 
   121 				// We can safely ignore any error from this as the previous error is more important to propagate, since this is just cleanup
   122 				iFileMan->Delete(aDestination); 
   123 				} 
   124 			} 
   125 		} 
   126 	return result; 
   127 	}	
   128 
   129 TInt CF32AgentManager::MkDir(const TDesC& aPath)
   130 	{
   131 	return iFs.MkDir(aPath);
   132 	}
   133 
   134 TInt CF32AgentManager::MkDirAll(const TDesC& aPath)
   135 	{
   136 	return iFs.MkDirAll(aPath);
   137 	}
   138 
   139 TInt CF32AgentManager::RmDir(const TDesC& aPath)
   140 	{
   141 	return iFs.RmDir(aPath);
   142 	}
   143 
   144 TInt CF32AgentManager::RenameDir(const TDesC& aOldName, const TDesC& aNewName)
   145 	{
   146 	return iFs.Rename(aOldName, aNewName);
   147 	}
   148 
   149 TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList) const
   150 	{
   151 	return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList);
   152 	}
   153 
   154 TInt CF32AgentManager::GetDir(const TDesC& aName,TUint aEntryAttMask,TUint aEntrySortKey, CDir*& aEntryList,CDir*& aDirList) const 
   155 	{
   156 	return iFs.GetDir(aName, aEntryAttMask, aEntrySortKey, aEntryList, aDirList);
   157 	}
   158 
   159 TInt CF32AgentManager::GetDir(const TDesC& aName,const TUidType& aEntryUid,TUint aEntrySortKey, CDir*& aFileList) const 
   160 	{
   161 	return iFs.GetDir( aName, aEntryUid, aEntrySortKey, aFileList);
   162 	}
   163 
   164 TInt CF32AgentManager::GetAttribute(TInt aAttribute, TInt& aValue, const TVirtualPathPtr& aVirtualPath)
   165 	{
   166 	// check that the virtual path exists
   167 	if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
   168 		{
   169 		return KErrNotFound;	
   170 		}
   171 		
   172 	return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, aVirtualPath.URI());
   173 	}
   174 
   175 TInt CF32AgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath)
   176 	{
   177 	// check that the virtual path exists
   178 	if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
   179 		{
   180 		return KErrNotFound;	
   181 		}
   182 		
   183 	return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, aVirtualPath.URI());
   184 	}
   185 
   186 TInt CF32AgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, const TVirtualPathPtr& aVirtualPath) 
   187 	{
   188 	// check that the virtual path exists
   189 	if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
   190 		{
   191 		return KErrNotFound;	
   192 		}
   193 		
   194 	return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, aVirtualPath.URI());
   195 	}
   196 
   197 TInt CF32AgentManager::GetStringAttributeSet(RStringAttributeSet& aAttributeSet, const TVirtualPathPtr& aVirtualPath) 
   198 	{
   199 	// check that the virtual path exists
   200 	if(TF32DefaultAttributes::CheckVirtualPath(aVirtualPath) != KErrNone)
   201 		{
   202 		return KErrNotFound;	
   203 		}
   204 		
   205 	return TF32DefaultAttributes::GetStringAttributeSet(aAttributeSet, aVirtualPath.URI());
   206 	}
   207 
   208 TInt CF32AgentManager::GetAttribute(TInt aAttribute, TInt& aValue, RFile& aFile, const TDesC& aUniqueId)
   209 	{
   210 	// Check that the client hasn't specified some incorrect UniqueId
   211 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   212 		{
   213 		return KErrNotFound;
   214 		}
   215 		
   216 	return TF32DefaultAttributes::GetAttribute(aAttribute, aValue, aFile);
   217 	}
   218 
   219 TInt CF32AgentManager::GetAttributeSet(RAttributeSet& aAttributeSet, RFile& aFile, const TDesC& aUniqueId)
   220 	{
   221 	// Check that the client hasn't specified some incorrect UniqueId
   222 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   223 		{
   224 		return KErrNotFound;
   225 		}
   226 		
   227 	return TF32DefaultAttributes::GetAttributeSet(aAttributeSet, aFile);
   228 	}
   229 	
   230 TInt CF32AgentManager::GetStringAttributeSet(RStringAttributeSet& aStringAttributeSet, RFile& aFile, const TDesC& aUniqueId)
   231 	{
   232 	// Check that the client hasn't specified some incorrect UniqueId
   233 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   234 		{
   235 		return KErrNotFound;
   236 		}
   237 		
   238 	return TF32DefaultAttributes::GetStringAttributeSet(aStringAttributeSet, aFile);
   239 	}
   240 	
   241 TInt CF32AgentManager::GetStringAttribute(TInt aAttribute, TDes& aValue, RFile& aFile, const TDesC& aUniqueId)
   242 	{
   243 	// Check that the client hasn't specified some incorrect UniqueId
   244 	if(TF32DefaultAttributes::CheckUniqueId(aUniqueId) != KErrNone)
   245 		{
   246 		return KErrNotFound;
   247 		}
   248 
   249 	return TF32DefaultAttributes::GetStringAttribute(aAttribute, aValue, aFile);
   250 	}		
   251 
   252 
   253 void CF32AgentManager::NotifyStatusChange(const TDesC& , TEventMask , TRequestStatus& aStatus) 
   254 	{
   255 	TRequestStatus* ptr = &aStatus;
   256 	User::RequestComplete(ptr, KErrCANotSupported);
   257 	}
   258 
   259 TInt CF32AgentManager::CancelNotifyStatusChange(const TDesC& , TRequestStatus& ) 
   260 	{
   261 	return KErrCANotSupported;
   262 	}
   263 
   264 TInt CF32AgentManager::SetProperty(TAgentProperty aProperty, TInt aValue)
   265 	{
   266 	if(aProperty==EAgentPropertyAgentUI)
   267 		// should only pass type EAgentPropertyAgentUI 
   268 		{
   269 		
   270 		CF32AgentUi* ui = NULL;
   271 		// get a pointer to the UI
   272 		TRAPD(err, ui = &AgentUiL());
   273 		if(err)
   274 			{
   275 			return err;
   276 			}
   277 		return ui->SetProperty(aProperty, aValue);
   278 		}
   279 	else
   280 		{
   281 		return KErrCANotSupported;
   282 		}
   283 	}
   284 
   285 void CF32AgentManager::DisplayInfoL(TDisplayInfo aInfo, const TVirtualPathPtr& aVirtualPath) 
   286 	{
   287 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   288 	RFile64 file;
   289 #else
   290 	RFile file;
   291 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   292 
   293 	// Check that the client hasn't specified some incorrect UniqueId
   294 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aVirtualPath.UniqueId()));
   295 
   296 	// Open the file as read only
   297 	User::LeaveIfError(file.Open(iFs, aVirtualPath.URI(), EFileShareReadersOnly | EFileStream | EFileRead));
   298 	CleanupClosePushL(file);
   299 	AgentUiL().DisplayInfoL(aInfo, file);
   300 	CleanupStack::PopAndDestroy(&file);
   301 	}
   302 
   303 void CF32AgentManager::DisplayInfoL(TDisplayInfo aInfo, RFile& aFile, const TDesC& aUniqueId) 
   304 	{
   305 	// Check that the client hasn't specified some incorrect UniqueId
   306 	User::LeaveIfError(TF32DefaultAttributes::CheckUniqueId(aUniqueId));
   307 
   308 	// Open the file as read only
   309 	AgentUiL().DisplayInfoL(aInfo, aFile);
   310 	}
   311 
   312 
   313 TInt CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& )
   314 	{
   315 	return KErrCANotSupported;
   316 	}
   317 
   318 void CF32AgentManager::AgentSpecificCommand(TInt , const TDesC8& , TDes8& , TRequestStatus& aStatus) 
   319 	{
   320 	TRequestStatus* ptr = &aStatus;
   321 	User::RequestComplete(ptr, KErrCANotSupported);
   322 	}
   323 
   324 void CF32AgentManager::DisplayManagementInfoL() 
   325 	{
   326 	User::Panic(KCafPanicString, ECafPanicF32AgentManagementInfoNotSupported);
   327 	}
   328 
   329 CF32AgentUi& CF32AgentManager::AgentUiL()
   330 	{
   331 	if(!iAgentUi)
   332 		{
   333 		iAgentUi = TF32AgentUiFactory::CreateF32AgentUiL();
   334 		}
   335 	return *iAgentUi;
   336 	}
   337 
   338 void CF32AgentManager::PrepareHTTPRequestHeaders(RStringPool& /*aStringPool*/, RHTTPHeaders& /*aRequestHeaders*/) const
   339 	{
   340 	User::Panic(KCafPanicString, ECafPanicF32AgentPrepareHTTPHeadersNotSupported);
   341 	}
   342 
   343 #ifdef SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT
   344 
   345 TBool CF32AgentManager::IsRecognizedL(const TDesC8& /*aHeaderData*/) const
   346 	{
   347 	// F32 should be the default agent and should never be called here
   348 	return EFalse;
   349 	}
   350 	
   351 TBool CF32AgentManager::RecognizeContentL(const TDesC8&, TDes8&, TDes8&) const
   352 	{
   353 	// F32 should be the default agent and should never be called here
   354 	return EFalse;
   355 	}
   356 	
   357 TInt CF32AgentManager::GetAttribute(const TDesC8& aHeaderData, TInt aAttribute, TInt& aValue)
   358 	{
   359 	return TF32DefaultAttributes::GetAttribute(aHeaderData, aAttribute, aValue);
   360 	}
   361 
   362 TInt CF32AgentManager::GetAttributeSet(const TDesC8& aHeaderData, RAttributeSet& aAttributeSet)
   363 	{
   364 	return TF32DefaultAttributes::GetAttributeSet(aHeaderData, aAttributeSet);
   365 	}
   366 
   367 TInt CF32AgentManager::GetStringAttribute(const TDesC8& aHeaderData, TInt aAttribute, TDes& aValue) 
   368 	{
   369 	return TF32DefaultAttributes::GetStringAttribute(aHeaderData, aAttribute, aValue);
   370 	}
   371 
   372 TInt CF32AgentManager::GetStringAttributeSet(const TDesC8& aHeaderData, RStringAttributeSet& aAttributeSet) 
   373 	{
   374 	return TF32DefaultAttributes::GetStringAttributeSet(aHeaderData, aAttributeSet);
   375 	}
   376 	
   377 #endif //SYMBIAN_ENABLE_SDP_WMDRM_SUPPORT