|
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 // privacyserver.cpp |
|
15 // |
|
16 // |
|
17 |
|
18 #include "lbsdevloggermacros.h" |
|
19 #include "privacysession.h" |
|
20 #include "privacyrequestinfo.h" |
|
21 #include "privacyprotocol.h" |
|
22 #include "EPos_PrivacyServerPanic.h" |
|
23 #include <lbs/lbsprivacyrequestcommon.h> |
|
24 |
|
25 |
|
26 /** |
|
27 Constructor. |
|
28 |
|
29 @param aProtocol Interface to send privacy requests to. |
|
30 */ |
|
31 CPrivacySession::CPrivacySession(MPrivacyProtocol& aProtocol, |
|
32 TLbsProxyApiType aApiType) : |
|
33 iProtocol(aProtocol), |
|
34 iApiType(aApiType) |
|
35 { |
|
36 LBSLOG(ELogP1, "CPrivacySession::CPrivacySession()\n"); |
|
37 } |
|
38 |
|
39 |
|
40 /** |
|
41 Destructor. |
|
42 */ |
|
43 CPrivacySession::~CPrivacySession() |
|
44 { |
|
45 LBSLOG(ELogP1, "CPrivacySession::~CPrivacySession()\n"); |
|
46 } |
|
47 |
|
48 |
|
49 /** |
|
50 Called when the session is created. |
|
51 */ |
|
52 void CPrivacySession::CreateL() |
|
53 { |
|
54 LBSLOG(ELogP1, "CPrivacySession::CreateL() Begin\n"); |
|
55 Server().IncSessionCount(iApiType); |
|
56 LBSLOG(ELogP1, "CPrivacySession::CreateL() End\n"); |
|
57 } |
|
58 |
|
59 |
|
60 /** |
|
61 Called when a message is received for this session. |
|
62 |
|
63 @param aMessage The message from the client. |
|
64 */ |
|
65 void CPrivacySession::ServiceL(const RMessage2& aMessage) |
|
66 { |
|
67 LBSLOG(ELogP1, "CPrivacySession::ServiceL() Begin\n"); |
|
68 switch (aMessage.Function()) |
|
69 { |
|
70 case ELbsPrivacyServerNotifyLocation: |
|
71 NotifyLocationRequest(aMessage); |
|
72 break; |
|
73 |
|
74 case ELbsPrivacyServerVerifyLocation: |
|
75 VerifyLocationRequest(aMessage); |
|
76 break; |
|
77 |
|
78 case ELbsPrivacyServerNotifyVerificationTimeout: |
|
79 NotifyVerificationTimeout(aMessage); |
|
80 break; |
|
81 |
|
82 case ELbsPrivacyServerCancelVerifyLocationRequest: |
|
83 CancelVerifyLocationRequest(aMessage); |
|
84 break; |
|
85 |
|
86 case ELbsPrivacyServerNewPrivacyRequestLocal: |
|
87 case ELbsPrivacyServerNewPrivacyRequestNetwork: |
|
88 NewPrivacyRequest(aMessage); |
|
89 break; |
|
90 |
|
91 case ELbsPrivacyServerRepeatPrivacyRequestLocal: |
|
92 case ELbsPrivacyServerRepeatPrivacyRequestNetwork: |
|
93 RepeatPrivacyRequest(aMessage); |
|
94 break; |
|
95 |
|
96 case ELbsPrivacyServerCompleteRequest: |
|
97 CompleteRequest(aMessage); |
|
98 break; |
|
99 |
|
100 default: |
|
101 User::Leave(KErrNotSupported); |
|
102 } |
|
103 LBSLOG(ELogP1, "CPrivacySession::ServiceL() End\n"); |
|
104 } |
|
105 |
|
106 |
|
107 /** |
|
108 Called when the session disconnects. |
|
109 |
|
110 @param aMessage The message from the client. |
|
111 */ |
|
112 void CPrivacySession::Disconnect(const RMessage2& aMessage) |
|
113 { |
|
114 LBSLOG(ELogP1, "CPrivacySession::Disconnect() Begin\n"); |
|
115 iProtocol.SessionDisconnected(this); |
|
116 Server().DecSessionCount(iApiType); |
|
117 CSession2::Disconnect(aMessage); |
|
118 LBSLOG(ELogP1, "CPrivacySession::Disconnect() End\n"); |
|
119 } |
|
120 |
|
121 |
|
122 /** |
|
123 Get a reference to the server for this session. |
|
124 |
|
125 @return A reference to the CPrivacyServer. |
|
126 */ |
|
127 CPrivacyServer& CPrivacySession::Server() |
|
128 { |
|
129 return *static_cast<CPrivacyServer*>(const_cast<CServer2*>(CSession2::Server())); |
|
130 } |
|
131 |
|
132 |
|
133 /** |
|
134 Cancel a verification request. |
|
135 |
|
136 @param aMessage The message from the client. |
|
137 */ |
|
138 void CPrivacySession::CancelVerifyLocationRequest(const RMessage2& aMessage) |
|
139 { |
|
140 LBSLOG(ELogP1, "CPrivacySession::CancelVerifyLocationRequest() Begin\n"); |
|
141 |
|
142 CCancelPrivacyRequestInfo* cancelInfo = NULL; |
|
143 TRAPD(err, cancelInfo = CCancelPrivacyRequestInfo::NewL()); |
|
144 if (err != KErrNone) |
|
145 { |
|
146 // Error creating request info object, complete with the error and return |
|
147 aMessage.Complete(err); |
|
148 return; |
|
149 } |
|
150 |
|
151 cancelInfo->SetRequestId(aMessage.Int0()); |
|
152 cancelInfo->SetCancelReason(aMessage.Int1()); |
|
153 |
|
154 if (!IsRequestInfoValid(*cancelInfo)) |
|
155 { |
|
156 aMessage.Panic(KPosPrivacyPanicCategory, |
|
157 EPosPrivSrvPanicRequestOverflow); |
|
158 delete cancelInfo; |
|
159 return; |
|
160 } |
|
161 |
|
162 aMessage.Complete(KErrNone); |
|
163 iProtocol.CancelVerifyLocationRequest(cancelInfo); |
|
164 |
|
165 LBSLOG(ELogP1, "CPrivacySession::CancelVerifyLocationRequest() End\n"); |
|
166 } |
|
167 |
|
168 |
|
169 /** |
|
170 Submit a notification request. |
|
171 |
|
172 @param aMessage The message from the client. |
|
173 */ |
|
174 void CPrivacySession::NotifyLocationRequest(const RMessage2& aMessage) |
|
175 { |
|
176 LBSLOG(ELogP1, "CPrivacySession::NotifyLocationRequest() Begin\n"); |
|
177 |
|
178 TLbsNetSessionId sessionId; |
|
179 iProtocol.GetNextSessionId(sessionId); |
|
180 |
|
181 TPckg<TInt> pkgReqId(sessionId.SessionNum()); |
|
182 TInt error = aMessage.Write(1,pkgReqId); |
|
183 if(error != KErrNone) |
|
184 { |
|
185 aMessage.Complete(error); |
|
186 return; |
|
187 } |
|
188 |
|
189 // NOTE: requestInfo does not complete the message in this case |
|
190 CPrivacyRequestInfo* requestInfo = NULL; |
|
191 TRAPD(err, requestInfo = CPrivacyRequestInfo::NewL(aMessage)); |
|
192 if (err != KErrNone) |
|
193 { |
|
194 // Error creating request info object, complete with the error and return |
|
195 aMessage.Complete(err); |
|
196 return; |
|
197 } |
|
198 |
|
199 TLbsExternalRequestInfo2 extRequestInfo; |
|
200 TPckg<TLbsExternalRequestInfo2> extRequestInfoPkg(extRequestInfo); |
|
201 aMessage.Read(0,extRequestInfoPkg); |
|
202 requestInfo->SetRequestInfo(extRequestInfo); |
|
203 |
|
204 requestInfo->SetRequestId(sessionId.SessionNum()); |
|
205 |
|
206 TLbsNetPosRequestPrivacy netPosRequestPrivacy; |
|
207 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(netPosRequestPrivacy); |
|
208 aMessage.Read(2,netPosRequestPrivacyPkg); |
|
209 requestInfo->SetRequestPrivacy(netPosRequestPrivacy); |
|
210 |
|
211 requestInfo->SetIsResponseRequired(EFalse); |
|
212 |
|
213 if (!IsRequestInfoValid(*requestInfo)) |
|
214 { |
|
215 aMessage.Panic(KPosPrivacyPanicCategory, |
|
216 EPosPrivSrvPanicInvalidArguments); |
|
217 delete requestInfo; |
|
218 return; |
|
219 } |
|
220 |
|
221 iProtocol.NotifyLocationRequest(requestInfo); |
|
222 aMessage.Complete(KErrNone); |
|
223 |
|
224 LBSLOG(ELogP1, "CPrivacySession::NotifyLocationRequest() End\n"); |
|
225 } |
|
226 |
|
227 |
|
228 /** |
|
229 Submit a notification timeout request. |
|
230 |
|
231 @param aMessage The message from the client. |
|
232 */ |
|
233 void CPrivacySession::NotifyVerificationTimeout(const RMessage2& aMessage) |
|
234 { |
|
235 LBSLOG(ELogP1, "CPrivacySession::NotifyVerificationTimeout() Begin\n"); |
|
236 |
|
237 // NOTE: requestInfo does not complete the message in this case |
|
238 CPrivacyRequestInfo* requestInfo = NULL; |
|
239 TRAPD(err, requestInfo = CPrivacyRequestInfo::NewL(aMessage)); |
|
240 if (err != KErrNone) |
|
241 { |
|
242 // Error creating request info object, complete with the error and return |
|
243 aMessage.Complete(err); |
|
244 return; |
|
245 } |
|
246 |
|
247 TLbsExternalRequestInfo2 extRequestInfo; |
|
248 TPckg<TLbsExternalRequestInfo2> extRequestInfoPkg(extRequestInfo); |
|
249 aMessage.Read(0,extRequestInfoPkg); |
|
250 requestInfo->SetRequestInfo(extRequestInfo); |
|
251 |
|
252 requestInfo->SetRequestId(aMessage.Int1()); |
|
253 |
|
254 TLbsNetPosRequestPrivacy netPosRequestPrivacy; |
|
255 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(netPosRequestPrivacy); |
|
256 aMessage.Read(2,netPosRequestPrivacyPkg); |
|
257 requestInfo->SetRequestPrivacy(netPosRequestPrivacy); |
|
258 |
|
259 requestInfo->SetIsResponseRequired(EFalse); |
|
260 |
|
261 if (!IsRequestInfoValid(*requestInfo)) |
|
262 { |
|
263 aMessage.Panic(KPosPrivacyPanicCategory, |
|
264 EPosPrivSrvPanicInvalidArguments); |
|
265 delete requestInfo; |
|
266 return; |
|
267 } |
|
268 |
|
269 iProtocol.NotifyVerificationTimeout(requestInfo); |
|
270 aMessage.Complete(KErrNone); |
|
271 |
|
272 LBSLOG(ELogP1, "CPrivacySession::NotifyVerificationTimeout() End\n"); |
|
273 } |
|
274 |
|
275 |
|
276 /** |
|
277 Submit a verify location request. |
|
278 |
|
279 @param aMessage The message from the client. |
|
280 */ |
|
281 void CPrivacySession::VerifyLocationRequest(const RMessage2& aMessage) |
|
282 { |
|
283 LBSLOG(ELogP1, "CPrivacySession::VerifyLocationRequest() Begin\n"); |
|
284 |
|
285 TLbsNetSessionId sessionId; |
|
286 iProtocol.GetNextSessionId(sessionId); |
|
287 |
|
288 TPckg<TInt> pkgReqId(sessionId.SessionNum()); |
|
289 TInt error = aMessage.Write(0,pkgReqId); |
|
290 if(error != KErrNone) |
|
291 { |
|
292 aMessage.Complete(error); |
|
293 return; |
|
294 } |
|
295 |
|
296 RSemaphore semaphore; |
|
297 error = semaphore.Open(aMessage, 3, EOwnerThread); |
|
298 if(error != KErrNone) |
|
299 { |
|
300 aMessage.Complete(error); |
|
301 return; |
|
302 } |
|
303 semaphore.Signal(); |
|
304 semaphore.Close(); |
|
305 |
|
306 CPrivacyRequestInfo* requestInfo = NULL; |
|
307 TRAPD(err, requestInfo = CPrivacyRequestInfo::NewL(aMessage)); |
|
308 if (err != KErrNone) |
|
309 { |
|
310 // Error creating request info object, complete with the error and return |
|
311 aMessage.Complete(err); |
|
312 return; |
|
313 } |
|
314 |
|
315 requestInfo->SetRequestId(sessionId.SessionNum()); |
|
316 |
|
317 TLbsExternalRequestInfo2 extRequestInfo; |
|
318 TPckg<TLbsExternalRequestInfo2> extRequestInfoPkg(extRequestInfo); |
|
319 aMessage.Read(1,extRequestInfoPkg); |
|
320 requestInfo->SetRequestInfo(extRequestInfo); |
|
321 |
|
322 TLbsNetPosRequestPrivacy netPosRequestPrivacy; |
|
323 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(netPosRequestPrivacy); |
|
324 aMessage.Read(2,netPosRequestPrivacyPkg); |
|
325 requestInfo->SetRequestPrivacy(netPosRequestPrivacy); |
|
326 |
|
327 requestInfo->SetIsResponseRequired(ETrue); |
|
328 |
|
329 if (!IsRequestInfoValid(*requestInfo)) |
|
330 { |
|
331 aMessage.Panic(KPosPrivacyPanicCategory, |
|
332 EPosPrivSrvPanicInvalidArguments); |
|
333 delete requestInfo; |
|
334 return; |
|
335 } |
|
336 |
|
337 iProtocol.VerifyLocationRequest(requestInfo); |
|
338 // The message should be completed later in this case |
|
339 |
|
340 LBSLOG(ELogP1, "CPrivacySession::VerifyLocationRequest() End\n"); |
|
341 } |
|
342 |
|
343 void CPrivacySession::NewPrivacyRequest(const RMessage2& aMessage) |
|
344 { |
|
345 TLbsNetSessionId sessionId; |
|
346 iProtocol.GetNextSessionId(sessionId); |
|
347 |
|
348 TPckg<TUint32> pkgReqId(sessionId.SessionNum()); |
|
349 TInt error = aMessage.Write(0,pkgReqId); |
|
350 if(error != KErrNone) |
|
351 { |
|
352 aMessage.Complete(error); |
|
353 return; |
|
354 } |
|
355 |
|
356 RSemaphore semaphore; |
|
357 error = semaphore.Open(aMessage, 3, EOwnerThread); |
|
358 if(error != KErrNone) |
|
359 { |
|
360 aMessage.Complete(error); |
|
361 return; |
|
362 } |
|
363 semaphore.Signal(); |
|
364 semaphore.Close(); |
|
365 |
|
366 PrivacyRequest(aMessage, sessionId.SessionNum()); |
|
367 } |
|
368 |
|
369 void CPrivacySession::RepeatPrivacyRequest(const RMessage2& aMessage) |
|
370 { |
|
371 PrivacyRequest(aMessage, aMessage.Int0()); |
|
372 } |
|
373 |
|
374 void CPrivacySession::PrivacyRequest(const RMessage2& aMessage, TInt aRequestId) |
|
375 { |
|
376 CPrivacyRequestInfo* requestInfo = NULL; |
|
377 TRAPD(err, requestInfo = CPrivacyRequestInfo::NewL(aMessage)); |
|
378 if (err != KErrNone) |
|
379 { |
|
380 // Error creating request info object, complete with the error and return |
|
381 aMessage.Complete(err); |
|
382 return; |
|
383 } |
|
384 |
|
385 requestInfo->SetRequestId(aRequestId); |
|
386 |
|
387 TLbsExternalRequestInfo2 extRequestInfo; |
|
388 TPckg<TLbsExternalRequestInfo2> extRequestInfoPkg(extRequestInfo); |
|
389 aMessage.Read(1,extRequestInfoPkg); |
|
390 requestInfo->SetRequestInfo(extRequestInfo); |
|
391 |
|
392 TLbsNetPosRequestPrivacy netPosRequestPrivacy; |
|
393 TPckg<TLbsNetPosRequestPrivacy> netPosRequestPrivacyPkg(netPosRequestPrivacy); |
|
394 aMessage.Read(2,netPosRequestPrivacyPkg); |
|
395 |
|
396 requestInfo->SetRequestPrivacy(netPosRequestPrivacy); |
|
397 |
|
398 requestInfo->SetIsResponseRequired(ETrue); |
|
399 requestInfo->SetIsSessionCompleteAutomatic(EFalse); |
|
400 requestInfo->SetConvertResponseCode(EFalse); |
|
401 |
|
402 if (!IsRequestInfoValid(*requestInfo)) |
|
403 { |
|
404 aMessage.Complete(netPosRequestPrivacy.RequestAction()); |
|
405 delete requestInfo; |
|
406 return; |
|
407 } |
|
408 |
|
409 iProtocol.PrivacyLocationRequest(requestInfo); |
|
410 // The message should be completed later in this case |
|
411 |
|
412 } |
|
413 |
|
414 void CPrivacySession::CompleteRequest(const RMessage2& aMessage) |
|
415 { |
|
416 |
|
417 TUint32 requestId(aMessage.Int0()); |
|
418 TInt reason(aMessage.Int1()); |
|
419 |
|
420 iProtocol.CompletePrivacyRequest(requestId, reason); |
|
421 |
|
422 aMessage.Complete(KErrNone); |
|
423 } |
|
424 |
|
425 /** |
|
426 Validates the data values for a privacy request. |
|
427 |
|
428 @param aRequestInfo The request data to validate |
|
429 */ |
|
430 TBool CPrivacySession::IsRequestInfoValid(const CRequestInfoBase& aRequestInfo) |
|
431 { |
|
432 LBSLOG(ELogP1, "CPrivacySession::IsRequestInfoValid() Begin\n"); |
|
433 |
|
434 TBool valid = (aRequestInfo.GetRequestId() >= 1); |
|
435 |
|
436 switch (aRequestInfo.Type()) |
|
437 { |
|
438 case CRequestInfoBase::EPrivacyRequestTypeRequest: |
|
439 { |
|
440 break; |
|
441 } |
|
442 case CRequestInfoBase::EPrivacyRequestTypeCancel: |
|
443 { |
|
444 const CCancelPrivacyRequestInfo& cancelInfo = |
|
445 static_cast<const CCancelPrivacyRequestInfo&>(aRequestInfo); |
|
446 |
|
447 valid &= (cancelInfo.CancelReason() == KErrCancel |
|
448 || cancelInfo.CancelReason() == KErrTimedOut); |
|
449 break; |
|
450 } |
|
451 default: |
|
452 { |
|
453 valid = EFalse; |
|
454 break; |
|
455 } |
|
456 } |
|
457 |
|
458 return valid; |
|
459 |
|
460 LBSLOG(ELogP1, "CPrivacySession::IsRequestInfoValid() End\n"); |
|
461 } |
|
462 |