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