|
1 // Copyright (c) 2007-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 #include "lbsdevloggermacros.h" |
|
17 #include <lbs/lbsloccommon.h> |
|
18 #include "privacyserver.h" |
|
19 #include "privacysession.h" |
|
20 #include "privacyshutdown.h" |
|
21 |
|
22 |
|
23 /** |
|
24 LBSPRIVACY_POLICY_ALLOW_COMMDD |
|
25 |
|
26 If this is defined, clients need only the CommDD capability to |
|
27 use this server. |
|
28 |
|
29 If undefined, then clients must have all of the following capabilities: |
|
30 Location |
|
31 ProtServ |
|
32 ReadDeviceData |
|
33 WriteDeviceData |
|
34 */ |
|
35 #define LBSPRIVACY_POLICY_ALLOW_COMMDD |
|
36 |
|
37 |
|
38 /** |
|
39 Define the TPolicy for this server. |
|
40 */ |
|
41 const TUint KRangeCount = 3; |
|
42 const TInt KRanges[KRangeCount] = |
|
43 { |
|
44 0, |
|
45 1, // 1-11 |
|
46 12 |
|
47 }; |
|
48 const TUint8 KElementsIndex[KRangeCount] = |
|
49 { |
|
50 CPolicyServer::ENotSupported, |
|
51 CPolicyServer::ECustomCheck, // 1-11 |
|
52 CPolicyServer::ENotSupported |
|
53 }; |
|
54 const CPolicyServer::TPolicy KPolicy = |
|
55 { |
|
56 CPolicyServer::EAlwaysPass, |
|
57 KRangeCount, |
|
58 KRanges, |
|
59 KElementsIndex, |
|
60 NULL |
|
61 }; |
|
62 |
|
63 _LIT(KPrivacyServerName,"LBSPrivacyServer"); |
|
64 |
|
65 /** |
|
66 Static public constructor. |
|
67 |
|
68 @param aProtocol Interface to send privacy requests to. |
|
69 |
|
70 @return A new instance of this class. |
|
71 */ |
|
72 CPrivacyServer* CPrivacyServer::NewL(MPrivacyProtocol& aProtocol) |
|
73 { |
|
74 LBSLOG(ELogP1, "CPrivacyServer::NewL() Begin\n"); |
|
75 CPrivacyServer* self = new(ELeave) CPrivacyServer(aProtocol); |
|
76 CleanupStack::PushL(self); |
|
77 self->ConstructL(); |
|
78 CleanupStack::Pop(); |
|
79 |
|
80 LBSLOG(ELogP1, "CPrivacyServer::NewL() End\n"); |
|
81 return self; |
|
82 } |
|
83 |
|
84 |
|
85 /** |
|
86 Create a new session. |
|
87 |
|
88 @param aVersion Version information. |
|
89 @param aMessage Incoming message. |
|
90 |
|
91 @return A new CPrivacySession object. |
|
92 */ |
|
93 CSession2* CPrivacyServer::NewSessionL(const TVersion& aVersion, const RMessage2& /*aMessage*/) const |
|
94 { |
|
95 LBSLOG(ELogP1, "CPrivacyServer::NewSessionL() Begin\n"); |
|
96 |
|
97 // Check that the shutdown timer hasn't already requested |
|
98 // the LBS system to shutdown |
|
99 if (iShutdown->State() == CPrivacyShutdown::EShutdownStateShutdownRequested) |
|
100 { |
|
101 User::Leave(KErrServerTerminated); |
|
102 } |
|
103 |
|
104 TLbsProxyApiType apiType = ELbsProxyApiTypeUnknown; |
|
105 |
|
106 // Check the client version is supported. |
|
107 // We also use this to distinguish between local and network sessions. |
|
108 if (aVersion.iMajor == KLbsLocalPrivacyAPIVersionMajor && |
|
109 aVersion.iMinor == KLbsLocalPrivacyAPIVersionMinor && |
|
110 aVersion.iBuild == KLbsLocalPrivacyAPIVersionBuild) |
|
111 { |
|
112 apiType = ELbsProxyApiTypeLocal; |
|
113 } |
|
114 else if (aVersion.iMajor == KLbsNetworkPrivacyAPIVersionMajor && |
|
115 aVersion.iMinor == KLbsNetworkPrivacyAPIVersionMinor && |
|
116 aVersion.iBuild == KLbsNetworkPrivacyAPIVersionBuild) |
|
117 { |
|
118 apiType = ELbsProxyApiTypeNetwork; |
|
119 } |
|
120 else |
|
121 { |
|
122 // Unknown client version |
|
123 User::Leave(KErrNotSupported); |
|
124 } |
|
125 |
|
126 // Check we aren't about to exceed the maximum number of sessions for this request source |
|
127 if (MaxSessionsReached(apiType)) |
|
128 { |
|
129 User::Leave(KErrInUse); |
|
130 } |
|
131 |
|
132 // Need to castaway the const. |
|
133 CSession2* session = new (ELeave) CPrivacySession(iProtocol,apiType); |
|
134 |
|
135 LBSLOG(ELogP1, "CPrivacyServer::NewSessionL() End\n"); |
|
136 return session; |
|
137 } |
|
138 |
|
139 |
|
140 /** |
|
141 Set the shutdown delay. |
|
142 */ |
|
143 void CPrivacyServer::SetShutdownDelay(TInt32 aShutdownDelay) |
|
144 { |
|
145 iShutdownDelay = aShutdownDelay; |
|
146 } |
|
147 |
|
148 /** |
|
149 Set the maximum number of network sessions allowed. |
|
150 */ |
|
151 void CPrivacyServer::SetMaxNetworkSessions(TInt aMaxNetworkSessions) |
|
152 { |
|
153 iMaxNetworkSessions = aMaxNetworkSessions; |
|
154 } |
|
155 |
|
156 /** |
|
157 Destructor. |
|
158 */ |
|
159 CPrivacyServer::~CPrivacyServer() |
|
160 { |
|
161 LBSLOG(ELogP1, "CPrivacyServer::~CPrivacyServer() Begin\n"); |
|
162 delete iShutdown; |
|
163 LBSLOG(ELogP1, "CPrivacyServer::~CPrivacyServer() End\n"); |
|
164 } |
|
165 |
|
166 |
|
167 /** |
|
168 Increment the session count. |
|
169 |
|
170 This is to allow the server to keep track of the number of active sessions. |
|
171 */ |
|
172 void CPrivacyServer::IncSessionCount(TLbsProxyApiType aApiType) |
|
173 { |
|
174 LBSLOG(ELogP1, "CPrivacyServer::IncSessionCount() Begin\n"); |
|
175 |
|
176 if (aApiType == ELbsProxyApiTypeLocal) |
|
177 { |
|
178 ++iLocalSessionCount; |
|
179 } |
|
180 else if (aApiType == ELbsProxyApiTypeNetwork) |
|
181 { |
|
182 ++iNetworkSessionCount; |
|
183 } |
|
184 |
|
185 if (iShutdown && ((iLocalSessionCount + iNetworkSessionCount) == 1)) |
|
186 { |
|
187 // Cancel shutdown sequence as we have an active session |
|
188 LBSLOG(ELogP1, "CPrivacyServer::IncSessionCount() Cancelling shutdown timer\n"); |
|
189 iShutdown->Cancel(); |
|
190 } |
|
191 |
|
192 LBSLOG(ELogP1, "CPrivacyServer::IncSessionCount() End\n"); |
|
193 } |
|
194 |
|
195 |
|
196 /** |
|
197 Decrement the session count. |
|
198 |
|
199 This is to allow the server to keep track of the number of active sessions. |
|
200 */ |
|
201 void CPrivacyServer::DecSessionCount(TLbsProxyApiType aApiType) |
|
202 { |
|
203 LBSLOG(ELogP1, "CPrivacyServer::DecSessionCount() Begin\n"); |
|
204 |
|
205 if (aApiType == ELbsProxyApiTypeLocal) |
|
206 { |
|
207 --iLocalSessionCount; |
|
208 } |
|
209 else if (aApiType == ELbsProxyApiTypeNetwork) |
|
210 { |
|
211 --iNetworkSessionCount; |
|
212 } |
|
213 |
|
214 if (iShutdown && ((iLocalSessionCount + iNetworkSessionCount) <= 0)) |
|
215 { |
|
216 // Last session has disconnected, start shutdown timer |
|
217 LBSLOG(ELogP1, "CPrivacyServer::DecSessionCount() Session count zero - starting shutdown timer\n"); |
|
218 iShutdown->Start(iShutdownDelay); |
|
219 } |
|
220 |
|
221 LBSLOG(ELogP1, "CPrivacyServer::DecSessionCount() End\n"); |
|
222 } |
|
223 |
|
224 /** |
|
225 Determine if the maximum number of sessions has been reached for this request source |
|
226 |
|
227 */ |
|
228 TBool CPrivacyServer::MaxSessionsReached(TLbsProxyApiType aApiType) const |
|
229 { |
|
230 if (aApiType == ELbsProxyApiTypeNetwork) |
|
231 { |
|
232 return (iMaxNetworkSessions >= 0 && (iNetworkSessionCount >= iMaxNetworkSessions)); |
|
233 } |
|
234 |
|
235 // Unlimited number of local sessions allowed |
|
236 return EFalse; |
|
237 } |
|
238 |
|
239 /** |
|
240 Security policies used for custom security check below: |
|
241 */ |
|
242 static _LIT_SECURITY_POLICY_C1(KLocationPolicy, ECapabilityLocation); |
|
243 static _LIT_SECURITY_POLICY_C1(KReadDeviceDataPolicy, ECapabilityReadDeviceData); |
|
244 static _LIT_SECURITY_POLICY_C1(KCommDDPolicy, ECapabilityCommDD); |
|
245 static _LIT_SECURITY_POLICY_C1(KNetworkServicesPolicy, ECapabilityNetworkServices); |
|
246 |
|
247 |
|
248 /** |
|
249 Perform a custom security check. |
|
250 |
|
251 @param aMsg The message to check. |
|
252 @param aAction A reference to the action to take if the security check fails. |
|
253 @param aMissing A reference to the list of security attributes missing from the checked process. |
|
254 |
|
255 @return Enum specifying the result of the security check. |
|
256 */ |
|
257 CPolicyServer::TCustomResult CPrivacyServer::CustomSecurityCheckL(const RMessage2 &aMsg, TInt& /*aAction*/, TSecurityInfo& /*aMissing*/) |
|
258 { |
|
259 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() Begin\n"); |
|
260 switch(aMsg.Function()) |
|
261 { |
|
262 case ELbsPrivacyServerConnect: |
|
263 case ELbsPrivacyServerDisconnect: |
|
264 { |
|
265 if (KLocationPolicy().CheckPolicy(aMsg) && |
|
266 KReadDeviceDataPolicy.CheckPolicy(aMsg)) |
|
267 { |
|
268 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS)\n"); |
|
269 return EPass; |
|
270 } |
|
271 |
|
272 #ifdef LBSPRIVACY_POLICY_ALLOW_COMMDD |
|
273 if (KCommDDPolicy.CheckPolicy(aMsg)) |
|
274 { |
|
275 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS with CommDD)\n"); |
|
276 return EPass; |
|
277 } |
|
278 #endif |
|
279 break; |
|
280 } |
|
281 case ELbsPrivacyServerNotifyLocation: |
|
282 case ELbsPrivacyServerVerifyLocation: |
|
283 case ELbsPrivacyServerNotifyVerificationTimeout: |
|
284 case ELbsPrivacyServerCancelVerifyLocationRequest: |
|
285 { |
|
286 if (KLocationPolicy().CheckPolicy(aMsg) && |
|
287 KReadDeviceDataPolicy.CheckPolicy(aMsg) && |
|
288 KNetworkServicesPolicy.CheckPolicy(aMsg)) |
|
289 { |
|
290 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS)\n"); |
|
291 return EPass; |
|
292 } |
|
293 |
|
294 #ifdef LBSPRIVACY_POLICY_ALLOW_COMMDD |
|
295 if (KCommDDPolicy.CheckPolicy(aMsg)) |
|
296 { |
|
297 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS with CommDD)\n"); |
|
298 return EPass; |
|
299 } |
|
300 #endif |
|
301 break; |
|
302 } |
|
303 case ELbsPrivacyServerNewPrivacyRequestLocal: |
|
304 case ELbsPrivacyServerRepeatPrivacyRequestLocal: |
|
305 case ELbsPrivacyServerCompleteRequest: |
|
306 { |
|
307 if (KLocationPolicy().CheckPolicy(aMsg) && |
|
308 KReadDeviceDataPolicy.CheckPolicy(aMsg)) |
|
309 { |
|
310 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS)\n"); |
|
311 return EPass; |
|
312 } |
|
313 break; |
|
314 } |
|
315 case ELbsPrivacyServerNewPrivacyRequestNetwork: |
|
316 case ELbsPrivacyServerRepeatPrivacyRequestNetwork: |
|
317 { |
|
318 if (KLocationPolicy().CheckPolicy(aMsg) && |
|
319 KReadDeviceDataPolicy.CheckPolicy(aMsg) && |
|
320 KNetworkServicesPolicy.CheckPolicy(aMsg)) |
|
321 { |
|
322 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (PASS)\n"); |
|
323 return EPass; |
|
324 } |
|
325 break; |
|
326 } |
|
327 default: |
|
328 { |
|
329 return EFail; |
|
330 } |
|
331 } |
|
332 |
|
333 LBSLOG(ELogP1, "CPrivacyServer::CustomSecurityCheckL() End (FAIL)\n"); |
|
334 return EFail; |
|
335 } |
|
336 |
|
337 |
|
338 /** |
|
339 Constructor. |
|
340 |
|
341 @param aProtocol Interface to send privacy requests to. |
|
342 */ |
|
343 CPrivacyServer::CPrivacyServer(MPrivacyProtocol& aProtocol) : |
|
344 CPolicyServer(EPriorityStandard, KPolicy), |
|
345 iProtocol(aProtocol) |
|
346 { |
|
347 LBSLOG(ELogP1, "CPrivacyServer::CPrivacyServer()\n"); |
|
348 } |
|
349 |
|
350 |
|
351 /** |
|
352 Second phase constructor. |
|
353 */ |
|
354 void CPrivacyServer::ConstructL() |
|
355 { |
|
356 LBSLOG(ELogP1, "CPrivacyServer::ConstructL() Begin\n"); |
|
357 iShutdown = CPrivacyShutdown::NewL(); |
|
358 StartL(KPrivacyServerName); |
|
359 LBSLOG(ELogP1, "CPrivacyServer::ConstructL() End\n"); |
|
360 } |