backupandrestore/backupengine/src/abserver.cpp
changeset 0 d0791faffa3f
child 15 f85613f12947
equal deleted inserted replaced
-1:000000000000 0:d0791faffa3f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Implementation of CABServer class.
       
    15 // 
       
    16 //
       
    17 
       
    18 /**
       
    19  @file
       
    20 */
       
    21 
       
    22 #include <e32std.h>
       
    23 #include <e32base.h>
       
    24 #include <connect/abclientserver.h>
       
    25 #include "abserver.h"
       
    26 #include "absession.h"
       
    27 #include "absessionmap.h"
       
    28 #include "sbedataownermanager.h"
       
    29 #include <connect/panic.h>
       
    30 #include "sblog.h"
       
    31 
       
    32 namespace conn
       
    33 	{
       
    34 
       
    35 
       
    36 	/** Active Backup security request ranges
       
    37 	
       
    38 	This is a breakdown of the active backup requests into ranges
       
    39 	for security checking purposes.
       
    40 
       
    41 	@internalComponent
       
    42 	*/
       
    43 	const TInt myABRanges[] = {0,11};
       
    44 
       
    45 	/** Active Backup range count
       
    46 
       
    47 	The number of different security ranges for active backup request numbers
       
    48 
       
    49 	@internalComponent
       
    50 	*/
       
    51 	const TUint myABRangeCount = sizeof(myABRanges)/sizeof(myABRanges[0]);
       
    52 
       
    53 	/** Active Backup security action array
       
    54 
       
    55 	An array with a one-to-one mapping with the range array
       
    56 	specifiying what security action to take for each server request.
       
    57 
       
    58 	@internalComponent
       
    59 	*/
       
    60 	const TUint8 myABElementsIndex[myABRangeCount] =
       
    61 		{
       
    62 		CPolicyServer::EAlwaysPass,
       
    63 		CPolicyServer::ENotSupported
       
    64 		};
       
    65 
       
    66 	/**
       
    67 	@internalComponent
       
    68 	*/
       
    69 	const CPolicyServer::TPolicyElement myABElements[] =
       
    70 		{_INIT_SECURITY_POLICY_PASS};
       
    71 
       
    72 	/**
       
    73 	@internalComponent
       
    74 	*/
       
    75 	const CPolicyServer::TPolicy myABPolicy =
       
    76 		{
       
    77 		CPolicyServer::EAlwaysPass,
       
    78 		myABRangeCount,
       
    79 		myABRanges,
       
    80 		myABElementsIndex,
       
    81 		myABElements,
       
    82 		};
       
    83 
       
    84 	CABServer::CABServer(CDataOwnerManager* aDOM)
       
    85 		: CPolicyServer(EPriorityNormal,myABPolicy), iDOM(aDOM)
       
    86     /** 
       
    87     Class constructor
       
    88     */
       
    89 		{
       
    90 		__ASSERT_DEBUG(iDOM, Panic(KErrArgument));
       
    91 		}
       
    92 
       
    93 	CABServer::~CABServer()
       
    94     /**
       
    95     Class destructor
       
    96     */
       
    97 		{
       
    98 		delete iSessionMap;
       
    99 		}
       
   100 		
       
   101 	CABServer* CABServer::NewLC(CDataOwnerManager* aDOM)
       
   102 	/**
       
   103 	Constructs a new instance of the CABServer, calls ConstructL, 
       
   104 	and returns it to the caller leaving it on the cleanup stack.
       
   105 
       
   106 	@return The new instance of CABServer.
       
   107 	*/
       
   108 		{
       
   109 		CABServer* pSelf = new (ELeave) CABServer(aDOM);
       
   110 		CleanupStack::PushL(pSelf);
       
   111 		pSelf->ConstructL();
       
   112 		return pSelf;
       
   113 		}
       
   114 
       
   115 	void CABServer::ConstructL()
       
   116 	/**
       
   117 	Construct this instance of CABServer.
       
   118 	*/
       
   119 		{
       
   120 		iSessionMap = CABSessionMap::NewL();
       
   121 		//
       
   122 		// Start the server 
       
   123 		StartL(KABServerName);
       
   124 		}
       
   125 
       
   126 	void CABServer::AddSession()
       
   127 	/** Increments the server session count.
       
   128 	
       
   129 	The server will shutdown when its 
       
   130 	session count drops to zero.
       
   131 	*/
       
   132 		{
       
   133 		++iSessionCount;
       
   134 		}
       
   135 
       
   136 	void CABServer::DropSession()
       
   137 	/** Decrements the server session count.  
       
   138 	
       
   139 	The server will shutdown when its 
       
   140 	session count drops to zero.
       
   141 	*/
       
   142 		{		
       
   143 		--iSessionCount;
       
   144 		}
       
   145 		
       
   146 	void CABServer::RemoveElement(TSecureId aSecureId)
       
   147 	/**
       
   148 	Remove the element with key aSecureId from the session map
       
   149 	
       
   150 	@param aSecureId The key of the element to be removed
       
   151 	*/
       
   152 		{
       
   153 		iSessionMap->Delete(aSecureId);
       
   154 		}
       
   155 
       
   156 	void CABServer::SupplyDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
   157 		TDesC8& aBuffer, TBool aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
       
   158 	/**
       
   159 	Supply data to the data owner
       
   160 	
       
   161 	@param aSID The secure ID of the data owner to signal
       
   162 	@param aDriveNumber The drive number that the data corresponds to
       
   163 	@param aTransferType The type of operation to perform on the data
       
   164 	@param aBuffer The buffer containing data for the operation
       
   165 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
       
   166 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
       
   167 	@param aProxySID The secure ID of the proxy
       
   168 	*/
       
   169 		{
       
   170 		CABSession& session = iSessionMap->SessionL(aSID);
       
   171 		
       
   172 		session.SupplyDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
       
   173 		}
       
   174 
       
   175 	void CABServer::RequestDataL(TSecureId aSID, TDriveNumber aDriveNumber, TTransferDataType aTransferType, 
       
   176 		TPtr8& aBuffer, TBool& aLastSection, TBool aSuppressInitDataOwner, TSecureId aProxySID)
       
   177 	/**
       
   178 	Request data from the data owner
       
   179 	
       
   180 	@param aSID The secure ID of the data owner to signal
       
   181 	@param aDriveNumber The drive number that the data corresponds to
       
   182 	@param aTransferType The type of operation to perform on the data
       
   183 	@param aBuffer The buffer containing data for the operation
       
   184 	@param aLastSection Flag to indicate whether this is the last operation in a multi-part transfer
       
   185 	@param aSuppressInitDataOwner Suppress the initialisation of Data Owner
       
   186 	@param aProxySID The secure ID of the proxy
       
   187 	*/
       
   188 		{
       
   189 		CABSession& session = iSessionMap->SessionL(aSID);
       
   190 		
       
   191 		session.RequestDataL(aDriveNumber, aTransferType, aBuffer, aLastSection, aSuppressInitDataOwner, aProxySID);
       
   192 		}
       
   193 
       
   194 	void CABServer::GetExpectedDataSizeL(TSecureId aSID, TDriveNumber aDriveNumber, TUint& aSize)
       
   195 	/**
       
   196 	Get the expected size of the data that will be returned
       
   197 	
       
   198 	@param aSID The secure ID of the data owner to signal
       
   199 	@param aDriveNumber The drive number that the data corresponds to
       
   200 	@param aSize The size of the data owner's data
       
   201 	*/
       
   202 		{
       
   203 		CABSession& session = iSessionMap->SessionL(aSID);
       
   204 		
       
   205 		session.GetExpectedDataSizeL(aDriveNumber, aSize);
       
   206 		}
       
   207 		
       
   208 	void CABServer::AllSnapshotsSuppliedL(TSecureId aSID)
       
   209 	/** Lets the client know that all its snapshots have been supplied
       
   210 	
       
   211 	@param aSID The secure ID of the data owner to signal
       
   212 	*/
       
   213 		{
       
   214 		CABSession& session = iSessionMap->SessionL(aSID);
       
   215 		
       
   216 		session.AllSnapshotsSuppliedL();
       
   217 		}
       
   218 
       
   219 	void CABServer::InvalidateABSessions()
       
   220 	/** Set each CABSession currently hold for each active backup
       
   221 	 * client as invalid, since there maybe some delay for the
       
   222 	 * arrival of disconnect request from client. Within this time,
       
   223 	 * this session can not be used for another backup/restore.
       
   224 	 */
       
   225 		{
       
   226 		iSessionMap->InvalidateABSessions();
       
   227 		}
       
   228 	
       
   229 	TDataOwnerStatus CABServer::SessionReadyStateL(TSecureId aSID)
       
   230 	/**
       
   231 	Returns the status of the active backup client
       
   232 	
       
   233 	@param aSID The SecureId of the session to query for
       
   234 	@return Data owner status of the session
       
   235 	*/
       
   236 		{
       
   237 		CABSession& session = iSessionMap->SessionL(aSID);
       
   238 		
       
   239 		TDataOwnerStatus doStatus = EDataOwnerNotConnected;
       
   240 		if (session.Invalidated())
       
   241 			{
       
   242 			__LOG1("CABServer::SessionReadyStateL session for 0x%08x has been invalidated, return NotConnected",
       
   243 					aSID.iId);
       
   244 			
       
   245 			return doStatus;	
       
   246 			}
       
   247 		
       
   248 		if (session.CallbackInterfaceAvailable())
       
   249 			{
       
   250 			__LOG2("CABServer::SessionReadyStateL session for 0x%08x already have interface, confirmed:%d ",
       
   251 					aSID.iId, session.ConfirmedReadyForBUR());
       
   252 			
       
   253 			doStatus = EDataOwnerNotReady;
       
   254 			
       
   255 			if (session.ConfirmedReadyForBUR())
       
   256 				{
       
   257 				doStatus = EDataOwnerReady;
       
   258 				}
       
   259 			}
       
   260 		else 
       
   261 			{
       
   262 			__LOG2("CABServer::SessionReadyStateL session for 0x%08x does not have interface, confimed:%d",
       
   263 								aSID.iId, session.ConfirmedReadyForBUR());
       
   264 			
       
   265 			doStatus = EDataOwnerNotReady;
       
   266 			
       
   267 			if (session.ConfirmedReadyForBUR())
       
   268 				{
       
   269 				doStatus = EDataOwnerReadyNoImpl;
       
   270 				}				
       
   271 			}
       
   272 			
       
   273 		return doStatus;
       
   274 		}
       
   275 		
       
   276 	void CABServer::RestoreCompleteL(TSecureId aSID, TDriveNumber aDrive)
       
   277 	/**
       
   278 	Called to indicate to the active backup client that a restore has completed
       
   279 	
       
   280 	@param aSID The secure Id of the active client for which the restore has completed
       
   281 	@param aDrive The drive number for which the restore has completed
       
   282 	*/
       
   283 		{
       
   284 		CABSession& session = iSessionMap->SessionL(aSID);
       
   285 
       
   286 		session.RestoreCompleteL(aDrive);
       
   287 		}
       
   288 		
       
   289 	CSession2* CABServer::NewSessionL(const TVersion& aVersion,
       
   290 		const RMessage2& aMessage) const
       
   291 	/** Constructs a new AB session.
       
   292 	
       
   293 	Querys the supplied version infomation from the client
       
   294 	with that of this server, and leaves if they are incompatable.
       
   295 
       
   296 	@param aVersion The clients version information
       
   297 	@param aMessage Is ignored
       
   298 	@return A new instance of CABSession
       
   299 	@leave KErrNotSupported if the version passed in aVersion is not the same as this one
       
   300 	*/
       
   301 		{
       
   302 		TVersion thisVersion(KABMajorVersionNumber, 
       
   303 								KABMinorVersionNumber,
       
   304 								KABBuildVersionNumber);
       
   305 		
       
   306 	    if (!User::QueryVersionSupported(thisVersion, aVersion))
       
   307 			{
       
   308 			User::Leave(KErrNotSupported);
       
   309 			}
       
   310 			
       
   311 		TSecureId sid = aMessage.SecureId();
       
   312 
       
   313 		// The map creates the session and a map entry, then session ownership is passed to the server
       
   314 		return &(iSessionMap->CreateL(sid));
       
   315 		}
       
   316 
       
   317 	TInt CABServer::RunError(TInt aError)
       
   318 	/** Called when this active objects RunL leaves. 
       
   319 	
       
   320 	May be due to a bad client or the server itself.  In either 
       
   321 	case, complete the last outstanding message with the error 
       
   322 	code and continue handling client requests.
       
   323 
       
   324     @param aError  Standard Symbian OS error code
       
   325 	@return The error code to be passed back to the active scheduler framework.
       
   326 	*/
       
   327 		{
       
   328 		//
       
   329 		// A Bad descriptor is a bad client - panic it.
       
   330 		if(aError == KErrBadDescriptor)
       
   331 			{
       
   332 			PanicClient(KErrBadDescriptor);
       
   333 			}
       
   334 
       
   335 		//
       
   336 		// Complete the message and continue handling requests.
       
   337 		Message().Complete(aError);
       
   338 		ReStart();
       
   339 		return KErrNone;
       
   340 		}
       
   341 
       
   342 	void CABServer::PanicClient(TInt aPanic) const
       
   343 	/** Panic a client.
       
   344 
       
   345 	@param aPanic The panic code.
       
   346 	*/
       
   347 		{
       
   348 		__DEBUGGER()
       
   349 		_LIT(KPanicCategory,"AB Server");
       
   350 		RThread client;
       
   351 		Message().Client(client);
       
   352 		client.Panic(KPanicCategory, aPanic);
       
   353 		}
       
   354 
       
   355 	} // end namespace