localisation/apparchitecture/apparc/ApaAppServer.cpp
branchSymbian2
changeset 1 8758140453c0
child 6 c108117318cb
equal deleted inserted replaced
0:e8c1ea2c6496 1:8758140453c0
       
     1 // Copyright (c) 2005-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 the License "Symbian Foundation License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #include "ApaServerAppPriv.h"
       
    17 
       
    18 //
       
    19 // CApaAppServiceBase
       
    20 //
       
    21 
       
    22 /** Constructor. */
       
    23 EXPORT_C CApaAppServiceBase::CApaAppServiceBase()
       
    24 	{
       
    25 	}
       
    26 	
       
    27 /** An implementation of the CreateL() method from CSession2.
       
    28 This can be further overridden by derived classes, but such
       
    29 implementations should also base-call. */
       
    30 EXPORT_C void CApaAppServiceBase::CreateL()
       
    31 	{
       
    32 	}
       
    33 
       
    34 /** Destructor. */
       
    35 EXPORT_C CApaAppServiceBase::~CApaAppServiceBase()
       
    36 	{
       
    37 	if (!iNotifyExitMsg.IsNull() && (iExitReason != KRequestPending))
       
    38 		{
       
    39 		iNotifyExitMsg.Complete(iExitReason);
       
    40 		}
       
    41 	}
       
    42 
       
    43 /** Virtual framework function that is called on receipt
       
    44 of a message from the client. This allows the service implementation
       
    45 to define a security policy for messages from the client.
       
    46 The default behaviour of this function is to pass security checks.
       
    47 @param	aMsg The message to check.
       
    48 @param	aAction A reference to the action to take if the security check
       
    49 		fails. This is either a value from TFailureAction or a negative
       
    50 		value which has meaning to the CustomFailureActionL() method of
       
    51 		a derived class.
       
    52 		The policy server framework gives this value a default of
       
    53 		EFailClient.  If a derived implementation wishes a
       
    54 		different value, then it should change this.
       
    55 @param 	aMissing A reference to the list of security attributes missing
       
    56 		from the checked process.  The policy server initialises this
       
    57 		object to zero (that is a sid of 0, a vid of 0, and no capabilities).
       
    58 		If derived implementations wish to take advantage of a list of
       
    59 		missing attributes in their implementation of CustomFailureActionL(),
       
    60 		then they should set those missing attributes here in
       
    61 		CustomSecurityCheckL().
       
    62 @return A value from CPolicyServer::TCustomResult.
       
    63 @see CPolicyServer */
       
    64 EXPORT_C CPolicyServer::TCustomResult CApaAppServiceBase::SecurityCheckL(const RMessage2& /*aMsg*/, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
    65 	{
       
    66 	return CPolicyServer::EPass;	// default is to pass security checks
       
    67 	}
       
    68 
       
    69 /** Framework function to handle client messages.
       
    70 Derived classes should override this method to receive messages from the client.
       
    71 These messages should have function ids starting from
       
    72 REikAppServiceBase::KServiceCmdBase.
       
    73 The behaviour for any unrecognised messages must be to
       
    74 base-call.
       
    75 @param aMessage The clients request message.
       
    76 @panic ApaAppServer 0 If this function does not recognise the function ID.*/
       
    77 EXPORT_C void CApaAppServiceBase::ServiceL(const RMessage2& aMessage)
       
    78 	{
       
    79 	switch (aMessage.Function())
       
    80 		{
       
    81 		case EApaAppServerNotifyServerExit:
       
    82 			NotifyServerExit(aMessage);
       
    83 			break;
       
    84 			
       
    85 		case EApaAppServerCancelNotifyServerExit:
       
    86 			CancelNotifyServerExit(aMessage);
       
    87 			break;
       
    88 			
       
    89 		default:
       
    90 			PanicAppServerClient(aMessage, EApaAppServerPanicIllegalFunction);
       
    91 			break;
       
    92 		}
       
    93 	}
       
    94 
       
    95 /** Handle leave errors from ServiceL().
       
    96 @param aMessage The client message that was being processed when the leave occured.
       
    97 @param aError The leave code. */
       
    98 EXPORT_C void CApaAppServiceBase::ServiceError(const RMessage2& aMessage,TInt aError)
       
    99 	{
       
   100 	CSession2::ServiceError(aMessage,aError);
       
   101 	}
       
   102 EXPORT_C TInt CApaAppServiceBase::CountResources()
       
   103 	{
       
   104 	return CSession2::CountResources();
       
   105 	}
       
   106 	
       
   107 EXPORT_C void CApaAppServiceBase::Disconnect(const RMessage2& aMessage)
       
   108 	{
       
   109 	CSession2::Disconnect(aMessage);
       
   110 	}
       
   111 void CApaAppServiceBase::NotifyServerExit(const RMessage2& aMessage)
       
   112 	{
       
   113 	if (!iNotifyExitMsg.IsNull())
       
   114 		{
       
   115 		PanicAppServerClient(aMessage, EApaAppServerPanicNotifyExitActive);
       
   116 		}
       
   117 	else
       
   118 		{
       
   119 		iNotifyExitMsg = aMessage;
       
   120 		iExitReason = KRequestPending;
       
   121 		}
       
   122 	}
       
   123 
       
   124 void CApaAppServiceBase::CancelNotifyServerExit(const RMessage2& aMessage) const
       
   125 	{
       
   126 	if (!iNotifyExitMsg.IsNull())
       
   127 		{
       
   128 		iNotifyExitMsg.Complete(KErrCancel);
       
   129 		}
       
   130 	aMessage.Complete(KErrNone);
       
   131 	}
       
   132 
       
   133 void CApaAppServiceBase::SendAppServerExitNotification(TInt aExitReason)
       
   134 	{
       
   135 	if (iExitReason == KRequestPending)
       
   136 		{
       
   137 		iExitReason = aExitReason;
       
   138 		}
       
   139 	}
       
   140 
       
   141 /** Extension mechanism - for internal BC proofing. */
       
   142 EXPORT_C void CApaAppServiceBase::ExtensionInterface(TUid /*aInterfaceId*/, TAny*& /*aImplementaion*/)
       
   143 	{
       
   144 	}
       
   145 EXPORT_C void CApaAppServiceBase::CApaAppServiceBase_Reserved1()
       
   146 	{
       
   147 	}
       
   148 	
       
   149 EXPORT_C void CApaAppServiceBase::CApaAppServiceBase_Reserved2()
       
   150 	{
       
   151 	}
       
   152 //
       
   153 // CApaAppServer
       
   154 //
       
   155 
       
   156 const TUint KApaAppServerRangeCount = 1;
       
   157 const TInt KApaAppServerRanges[KApaAppServerRangeCount] = 
       
   158 	{
       
   159 	0, //range is 0-KMaxTInt inclusive
       
   160 	};
       
   161 const TUint8 KApaAppServerElementsIndex[KApaAppServerRangeCount] = 
       
   162 	{
       
   163 	CPolicyServer::ECustomCheck, 	//applies to 0th range (req num: 0-KMaxTInt)
       
   164 	};
       
   165 //const CPolicyServer::TPolicyElement KApaAppServerElements[0] = 
       
   166 //	{
       
   167 //	}
       
   168 const CPolicyServer::TPolicy KApaAppServerPolicy =
       
   169 	{
       
   170 	CPolicyServer::ECustomCheck,
       
   171 	KApaAppServerRangeCount,					
       
   172 	KApaAppServerRanges,
       
   173 	KApaAppServerElementsIndex,
       
   174 	0,
       
   175 	};
       
   176 /** Constructor. */
       
   177 EXPORT_C CApaAppServer::CApaAppServer()
       
   178 :CPolicyServer(0,
       
   179 			   KApaAppServerPolicy,
       
   180 			   EUnsharableSessions)
       
   181 	{
       
   182 	}
       
   183 
       
   184 /** Destructor */
       
   185 EXPORT_C CApaAppServer::~CApaAppServer()
       
   186 	{
       
   187 	}
       
   188 
       
   189 /** Virtual ConstructL() function to allow second stage construction.
       
   190 This can be overridden for derived class construction, but must be
       
   191 base-called.
       
   192 @param aFixedServerName - the name that this server will use. */
       
   193 EXPORT_C void CApaAppServer::ConstructL(const TDesC& aFixedServerName)
       
   194 	{
       
   195 	StartL(aFixedServerName);
       
   196 	}
       
   197 
       
   198 EXPORT_C CSession2* CApaAppServer::NewSessionL(const TVersion& /*aVersion*/,const RMessage2& aMessage) const
       
   199 	{
       
   200 	TUid serviceUid = ConnectMessageServiceUid(aMessage);
       
   201 	return CreateServiceL(serviceUid);
       
   202 	}
       
   203 
       
   204 /** The server's main security checking function.
       
   205 This delegates connect checks to CreateServiceSecurityCheckL
       
   206 and checks on other messages to the target service implementation's
       
   207 SecurityCheckL function.
       
   208 For framework use only.
       
   209 @internalComponent */
       
   210 EXPORT_C CPolicyServer::TCustomResult CApaAppServer::CustomSecurityCheckL(const RMessage2& aMsg, TInt& aAction, TSecurityInfo& aMissing)
       
   211 	{
       
   212 	if (aMsg.Function() == RMessage2::EConnect)
       
   213 		{
       
   214 		TUid serviceUid = ConnectMessageServiceUid(aMsg);
       
   215 		return CreateServiceSecurityCheckL(serviceUid, aMsg, aAction, aMissing);
       
   216 		}
       
   217 	else
       
   218 		{
       
   219 		CApaAppServiceBase* service = static_cast<CApaAppServiceBase*>(aMsg.Session());
       
   220 		if (service)
       
   221 			{
       
   222 			return service->SecurityCheckL(aMsg, aAction, aMissing);
       
   223 			}
       
   224 		else
       
   225 			{
       
   226 			return CPolicyServer::EFail;
       
   227 			}
       
   228 		}
       
   229 	}
       
   230 
       
   231 /** Service creation function.
       
   232 When a client wants to connect to a server app, this function will be
       
   233 called to create the service requested by the client.
       
   234 This function must be overridden by server apps to create their
       
   235 implementations of the requested service.
       
   236 If the server app's implementation of this function does not recognise
       
   237 the service UID, it must base-call.
       
   238 @param aServiceType The UID of the service that the client wants to connect to.
       
   239 @return an object derived from CApaAppServiceBase that can handle the
       
   240 service type requested by the client. */
       
   241 EXPORT_C CApaAppServiceBase* CApaAppServer::CreateServiceL(TUid /*aServiceType*/) const
       
   242 	{
       
   243 	User::Leave(KErrNotSupported);
       
   244 	return NULL;
       
   245 	}
       
   246 
       
   247 /** Notifies clients that the server is going to exit.
       
   248 If a server application exits for any non-standard reason (ie anything
       
   249 except EEikCmdExit) this function should be called to forward the reason
       
   250 to the client. The UI framework will call this with EEikCmdExit if it has
       
   251 not already been done.
       
   252 @param aReason The exit reason from the server app. This will either be a
       
   253                command ID, eg EEikCmdExit, or an error code, eg KErrServerTerminated.
       
   254 @see CEikAppUi::Exit */
       
   255 EXPORT_C void CApaAppServer::NotifyServerExit(TInt aReason)
       
   256 	{
       
   257 	iSessionIter.SetToFirst();
       
   258 	CSession2* s;
       
   259 	while ((s=iSessionIter++)!=NULL)
       
   260 		{
       
   261 		static_cast<CApaAppServiceBase*>(s)->SendAppServerExitNotification(aReason);
       
   262 		}
       
   263 	}
       
   264 
       
   265 /** Function to allow security checks on the client before they
       
   266 connect to a service.
       
   267 Server apps should override this method if they want to restict
       
   268 connections to some services to clients with particular capabilities.
       
   269 @param aServiceType The UID of the service that the client wants to connect to.
       
   270 @param	aMsg The message to check.
       
   271 @param	aAction A reference to the action to take if the security check
       
   272 		fails. This is either a value from TFailureAction or a negative
       
   273 		value which has meaning to the CustomFailureActionL() method of
       
   274 		a derived class.
       
   275 		The policy server framework gives this value a default of
       
   276 		EFailClient.  If a derived implementation wishes a
       
   277 		different value, then it should change this.
       
   278 @param 	aMissing A reference to the list of security attributes missing
       
   279 		from the checked process.  The policy server initialises this
       
   280 		object to zero (that is a sid of 0, a vid of 0, and no capabilities).
       
   281 		If derived implementations wish to take advantage of a list of
       
   282 		missing attributes in their implementation of CustomFailureActionL(),
       
   283 		then they should set those missing attributes here in
       
   284 		CustomSecurityCheckL().
       
   285 @return A value from CPolicyServer::TCustomResult.
       
   286 @see CPolicyServer */
       
   287 EXPORT_C CPolicyServer::TCustomResult CApaAppServer::CreateServiceSecurityCheckL(TUid /*aServiceType*/, const RMessage2& /*aMsg*/, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/)
       
   288 	{
       
   289 	return CPolicyServer::EPass;
       
   290 	}
       
   291 
       
   292 TUid CApaAppServer::ConnectMessageServiceUid(const RMessage2& aMessage) const
       
   293 	{
       
   294 	// note: this function uses knowledge of the internal structure
       
   295 	// of connect messages
       
   296 	return TUid::Uid(aMessage.Int0());
       
   297 	}
       
   298 // From CServer2
       
   299 EXPORT_C void CApaAppServer::DoConnect(const RMessage2& aMessage)
       
   300 	{
       
   301 	CServer2::DoConnect(aMessage);
       
   302 	}
       
   303 	
       
   304 // Reserved
       
   305 EXPORT_C void CApaAppServer::CApaAppServer_Reserved1()
       
   306 	{
       
   307 	}
       
   308 	
       
   309 EXPORT_C void CApaAppServer::CApaAppServer_Reserved2()
       
   310 	{
       
   311 	}
       
   312 /** Extension mechanism - for internal BC proofing. */
       
   313 EXPORT_C void CApaAppServer::ExtensionInterface(TUid /*aInterfaceId*/, TAny*& /*aImplementaion*/)
       
   314 	{
       
   315 	}
       
   316 EXPORT_C MApaServerAppExitObserver::MApaServerAppExitObserver()
       
   317 	{
       
   318 	}
       
   319 	
       
   320 EXPORT_C void MApaServerAppExitObserver::MApaServerAppExitObserver_Reserved1()
       
   321 	{
       
   322 	}
       
   323 	
       
   324 EXPORT_C void MApaServerAppExitObserver::MApaServerAppExitObserver_Reserved2()
       
   325 	{
       
   326 	}
       
   327 //
       
   328 // static functions
       
   329 //
       
   330 
       
   331 void PanicAppServerClient(const RMessagePtr2& aMessage,TInt aPanic)
       
   332 	{
       
   333 	_LIT(KPanic,"ApaAppServer");
       
   334 	aMessage.Panic(KPanic,aPanic);
       
   335 	}