|
1 /* |
|
2 * Copyright (c) 2010 Sun Microsystems, Inc. and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributor: |
|
10 * Maximilian Odendahl |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Caldav server session, follows Symbian |
|
15 * client/server architecture |
|
16 */ |
|
17 |
|
18 #include <e32cmn.h> |
|
19 |
|
20 #include "caldavserversession.h" |
|
21 #include "caldavserver.h" |
|
22 #include "caldavutils.h" |
|
23 |
|
24 #define MAXLENGTH 500 |
|
25 |
|
26 CCalDavServerSession::CCalDavServerSession(CCalDavServer &aServer) : |
|
27 rServer(aServer) |
|
28 { |
|
29 } |
|
30 |
|
31 /** |
|
32 Services a client request. |
|
33 */ |
|
34 void CCalDavServerSession::ServiceL(const RMessage2& aMessage) |
|
35 { |
|
36 TRAP_IGNORE(DispatchMessageL(aMessage)); |
|
37 } |
|
38 |
|
39 /** |
|
40 Called by ServiceL() |
|
41 |
|
42 It tests the function code and then delegates to |
|
43 the appropriate function. |
|
44 */ |
|
45 void CCalDavServerSession::DispatchMessageL(const RMessage2& aMessage) |
|
46 { |
|
47 switch (aMessage.Function()) |
|
48 { |
|
49 case ECalDavEnable: |
|
50 EnableL(aMessage); |
|
51 return; |
|
52 case ECalDavDisable: |
|
53 DisableL(aMessage); |
|
54 return; |
|
55 case ECalDavSyncAll: |
|
56 SyncAllL(aMessage); |
|
57 return; |
|
58 case ECalDavSync: |
|
59 SyncL(aMessage); |
|
60 return; |
|
61 case ECalDavUrl: |
|
62 UrlL(aMessage); |
|
63 return; |
|
64 case ECalDavSetUrl: |
|
65 SetUrlL(aMessage); |
|
66 return; |
|
67 case ECalDavUsername: |
|
68 UsernameL(aMessage); |
|
69 return; |
|
70 case ECalDavSetUsername: |
|
71 SetUsernameL(aMessage); |
|
72 return; |
|
73 case ECalDavPassword: |
|
74 PasswordL(aMessage); |
|
75 return; |
|
76 case ECalDavSetPassword: |
|
77 SetPasswordL(aMessage); |
|
78 return; |
|
79 case ECalDavSyncInterval: |
|
80 SyncIntervalL(aMessage); |
|
81 return; |
|
82 case ECalDavSetSyncInterval: |
|
83 SetSyncIntervalL(aMessage); |
|
84 return; |
|
85 case ECalDavPastDays: |
|
86 PastDaysL(aMessage); |
|
87 return; |
|
88 case ECalDavSetPastDays: |
|
89 SetPastDaysL(aMessage); |
|
90 return; |
|
91 case ECalDavImmediateSync: |
|
92 ImmediateSyncL(aMessage); |
|
93 return; |
|
94 case ECalDavSetImmediateSync: |
|
95 SetImmediateSyncL(aMessage); |
|
96 return; |
|
97 case ECalDavKeepServer: |
|
98 KeepServerEntryL(aMessage); |
|
99 return; |
|
100 case ECalDavSetKeepServer: |
|
101 SetKeepServerEntryL(aMessage); |
|
102 return; |
|
103 case ECalDavEnabled: |
|
104 EnabledSyncL(aMessage); |
|
105 return; |
|
106 case ECalDavUnsupportedRequest: |
|
107 User::Leave(KErrNotSupported); |
|
108 // Requests that we don't understand at all are a different matter. |
|
109 // This is considered a client programming error, so we panic the |
|
110 // client - this also completes the message. |
|
111 default: |
|
112 PanicClient(aMessage, EBadRequest); |
|
113 return; |
|
114 } |
|
115 } |
|
116 |
|
117 /** |
|
118 Panics the client |
|
119 */ |
|
120 void CCalDavServerSession::PanicClient(const RMessage2& aMessage, TInt aPanic) const |
|
121 { |
|
122 _LIT(KTxtServer,"CalDav server"); |
|
123 aMessage.Panic(KTxtServer, aPanic); |
|
124 } |
|
125 |
|
126 void CCalDavServerSession::EnableL(const RMessage2& aMessage) |
|
127 { |
|
128 TUint length = aMessage.GetDesLength(0); |
|
129 HBufC* calendar = HBufC::NewLC(length); |
|
130 TPtr calendarPtr(calendar->Des()); |
|
131 aMessage.ReadL(0, calendarPtr); |
|
132 |
|
133 TInt result = rServer.EnableL(*calendar); |
|
134 |
|
135 CleanupStack::PopAndDestroy(calendar); |
|
136 aMessage.Complete(result); |
|
137 } |
|
138 |
|
139 void CCalDavServerSession::DisableL(const RMessage2& aMessage) |
|
140 { |
|
141 TUint length = aMessage.GetDesLength(0); |
|
142 HBufC* calendar = HBufC::NewLC(length); |
|
143 TPtr calendarPtr(calendar->Des()); |
|
144 aMessage.ReadL(0, calendarPtr); |
|
145 |
|
146 TInt result = rServer.DisableL(*calendar); |
|
147 CleanupStack::PopAndDestroy(calendar); |
|
148 aMessage.Complete(result); |
|
149 } |
|
150 |
|
151 void CCalDavServerSession::SyncL(const RMessage2& aMessage) |
|
152 { |
|
153 TUint length = aMessage.GetDesLength(0); |
|
154 HBufC* calendar = HBufC::NewLC(length); |
|
155 TPtr calendarPtr(calendar->Des()); |
|
156 aMessage.ReadL(0, calendarPtr); |
|
157 |
|
158 TInt result = rServer.SyncL(*calendar); |
|
159 CleanupStack::PopAndDestroy(calendar); |
|
160 aMessage.Complete(result); |
|
161 } |
|
162 |
|
163 void CCalDavServerSession::SyncAllL(const RMessage2& aMessage) |
|
164 { |
|
165 TInt result = rServer.SyncAllL(); |
|
166 aMessage.Complete(result); |
|
167 } |
|
168 |
|
169 void CCalDavServerSession::UrlL(const RMessage2& aMessage) |
|
170 { |
|
171 TUint length = aMessage.GetDesLength(0); |
|
172 HBufC* calendar = HBufC::NewLC(length); |
|
173 TPtr calendarPtr(calendar->Des()); |
|
174 aMessage.ReadL(0, calendarPtr); |
|
175 |
|
176 aMessage.WriteL(1, rServer.UrlL(*calendar)); |
|
177 CleanupStack::PopAndDestroy(calendar); |
|
178 aMessage.Complete(KErrNone); |
|
179 } |
|
180 |
|
181 void CCalDavServerSession::SetUrlL(const RMessage2& aMessage) |
|
182 { |
|
183 TUint length = aMessage.GetDesLength(0); |
|
184 HBufC* calendar = HBufC::NewLC(length); |
|
185 TPtr calendarPtr(calendar->Des()); |
|
186 aMessage.ReadL(0, calendarPtr); |
|
187 |
|
188 length = aMessage.GetDesLength(1); |
|
189 HBufC8* url = HBufC8::NewLC(length); |
|
190 TPtr8 urlPtr(url->Des()); |
|
191 aMessage.ReadL(1, urlPtr); |
|
192 |
|
193 rServer.SetUrlL(*calendar, *url); |
|
194 CleanupStack::PopAndDestroy(url); |
|
195 CleanupStack::PopAndDestroy(calendar); |
|
196 |
|
197 aMessage.Complete(KErrNone); |
|
198 } |
|
199 |
|
200 void CCalDavServerSession::UsernameL(const RMessage2& aMessage) |
|
201 { |
|
202 TUint length = aMessage.GetDesLength(0); |
|
203 HBufC* calendar = HBufC::NewLC(length); |
|
204 TPtr calendarPtr(calendar->Des()); |
|
205 aMessage.ReadL(0, calendarPtr); |
|
206 |
|
207 aMessage.WriteL(1, rServer.UsernameL(*calendar)); |
|
208 CleanupStack::PopAndDestroy(calendar); |
|
209 aMessage.Complete(KErrNone); |
|
210 } |
|
211 |
|
212 void CCalDavServerSession::SetUsernameL(const RMessage2& aMessage) |
|
213 { |
|
214 TUint length = aMessage.GetDesLength(0); |
|
215 HBufC* calendar = HBufC::NewLC(length); |
|
216 TPtr calendarPtr(calendar->Des()); |
|
217 aMessage.ReadL(0, calendarPtr); |
|
218 |
|
219 length = aMessage.GetDesLength(1); |
|
220 HBufC8* username = HBufC8::NewLC(length); |
|
221 TPtr8 usernamePtr(username->Des()); |
|
222 aMessage.ReadL(1, usernamePtr); |
|
223 |
|
224 rServer.SetUsernameL(*calendar, *username); |
|
225 CleanupStack::PopAndDestroy(username); |
|
226 CleanupStack::PopAndDestroy(calendar); |
|
227 |
|
228 aMessage.Complete(KErrNone); |
|
229 } |
|
230 |
|
231 void CCalDavServerSession::PasswordL(const RMessage2& aMessage) |
|
232 { |
|
233 TUint length = aMessage.GetDesLength(0); |
|
234 HBufC* calendar = HBufC::NewLC(length); |
|
235 TPtr calendarPtr(calendar->Des()); |
|
236 aMessage.ReadL(0, calendarPtr); |
|
237 |
|
238 aMessage.WriteL(1, rServer.PasswordL(*calendar)); |
|
239 CleanupStack::PopAndDestroy(calendar); |
|
240 aMessage.Complete(KErrNone); |
|
241 } |
|
242 |
|
243 void CCalDavServerSession::SetPasswordL(const RMessage2& aMessage) |
|
244 { |
|
245 TUint length = aMessage.GetDesLength(0); |
|
246 HBufC* calendar = HBufC::NewLC(length); |
|
247 TPtr calendarPtr(calendar->Des()); |
|
248 aMessage.ReadL(0, calendarPtr); |
|
249 |
|
250 length = aMessage.GetDesLength(1); |
|
251 HBufC8* password = HBufC8::NewLC(length); |
|
252 TPtr8 passwordPtr(password->Des()); |
|
253 aMessage.ReadL(1, passwordPtr); |
|
254 |
|
255 rServer.SetPasswordL(*calendar, *password); |
|
256 CleanupStack::PopAndDestroy(password); |
|
257 CleanupStack::PopAndDestroy(calendar); |
|
258 |
|
259 aMessage.Complete(KErrNone); |
|
260 } |
|
261 |
|
262 void CCalDavServerSession::SyncIntervalL(const RMessage2& aMessage) |
|
263 { |
|
264 TUint length = aMessage.GetDesLength(0); |
|
265 HBufC* calendar = HBufC::NewLC(length); |
|
266 TPtr calendarPtr(calendar->Des()); |
|
267 aMessage.ReadL(0, calendarPtr); |
|
268 |
|
269 TTimeIntervalMinutes interval = rServer.SyncIntervalL(*calendar); |
|
270 TPckg<TTimeIntervalMinutes> intervalDes(interval); |
|
271 aMessage.WriteL(1, intervalDes); |
|
272 |
|
273 CleanupStack::PopAndDestroy(calendar); |
|
274 aMessage.Complete(KErrNone); |
|
275 } |
|
276 |
|
277 void CCalDavServerSession::SetSyncIntervalL(const RMessage2& aMessage) |
|
278 { |
|
279 TUint length = aMessage.GetDesLength(0); |
|
280 HBufC* calendar = HBufC::NewLC(length); |
|
281 TPtr calendarPtr(calendar->Des()); |
|
282 aMessage.ReadL(0, calendarPtr); |
|
283 |
|
284 TTimeIntervalMinutes interval; |
|
285 ; |
|
286 TPckg<TTimeIntervalMinutes> intervalDes(interval); |
|
287 aMessage.ReadL(1, intervalDes); |
|
288 |
|
289 rServer.SetSyncIntervalL(*calendar, interval); |
|
290 CleanupStack::PopAndDestroy(calendar); |
|
291 aMessage.Complete(KErrNone); |
|
292 } |
|
293 |
|
294 void CCalDavServerSession::PastDaysL(const RMessage2& aMessage) |
|
295 { |
|
296 TUint length = aMessage.GetDesLength(0); |
|
297 HBufC* calendar = HBufC::NewLC(length); |
|
298 TPtr calendarPtr(calendar->Des()); |
|
299 aMessage.ReadL(0, calendarPtr); |
|
300 |
|
301 TTimeIntervalDays days = rServer.PastDaysL(*calendar); |
|
302 TPckg<TTimeIntervalDays> daysDes(days); |
|
303 aMessage.WriteL(1, daysDes); |
|
304 |
|
305 CleanupStack::PopAndDestroy(calendar); |
|
306 aMessage.Complete(KErrNone); |
|
307 } |
|
308 |
|
309 void CCalDavServerSession::SetPastDaysL(const RMessage2& aMessage) |
|
310 { |
|
311 TUint length = aMessage.GetDesLength(0); |
|
312 HBufC* calendar = HBufC::NewLC(length); |
|
313 TPtr calendarPtr(calendar->Des()); |
|
314 aMessage.ReadL(0, calendarPtr); |
|
315 |
|
316 TTimeIntervalDays days; |
|
317 TPckg<TTimeIntervalDays> daysDes(days); |
|
318 aMessage.ReadL(1, daysDes); |
|
319 |
|
320 rServer.SetPastDaysL(*calendar, days); |
|
321 CleanupStack::PopAndDestroy(calendar); |
|
322 aMessage.Complete(KErrNone); |
|
323 } |
|
324 |
|
325 void CCalDavServerSession::ImmediateSyncL(const RMessage2& aMessage) |
|
326 { |
|
327 TUint length = aMessage.GetDesLength(0); |
|
328 HBufC* calendar = HBufC::NewLC(length); |
|
329 TPtr calendarPtr(calendar->Des()); |
|
330 aMessage.ReadL(0, calendarPtr); |
|
331 |
|
332 TBool immediate = rServer.ImmediateSyncL(*calendar); |
|
333 TPckg<TBool> immediateDes(immediate); |
|
334 aMessage.WriteL(1, immediateDes); |
|
335 |
|
336 CleanupStack::PopAndDestroy(calendar); |
|
337 aMessage.Complete(KErrNone); |
|
338 } |
|
339 |
|
340 void CCalDavServerSession::SetImmediateSyncL(const RMessage2& aMessage) |
|
341 { |
|
342 TUint length = aMessage.GetDesLength(0); |
|
343 HBufC* calendar = HBufC::NewLC(length); |
|
344 TPtr calendarPtr(calendar->Des()); |
|
345 aMessage.ReadL(0, calendarPtr); |
|
346 |
|
347 TBool immediate; |
|
348 TPckg<TBool> immediateDes(immediate); |
|
349 aMessage.ReadL(1, immediateDes); |
|
350 rServer.SetImmediateSyncL(*calendar, immediate); |
|
351 |
|
352 CleanupStack::PopAndDestroy(calendar); |
|
353 aMessage.Complete(KErrNone); |
|
354 } |
|
355 |
|
356 void CCalDavServerSession::KeepServerEntryL(const RMessage2& aMessage) |
|
357 { |
|
358 TUint length = aMessage.GetDesLength(0); |
|
359 HBufC* calendar = HBufC::NewLC(length); |
|
360 TPtr calendarPtr(calendar->Des()); |
|
361 aMessage.ReadL(0, calendarPtr); |
|
362 |
|
363 TBool keepserver = rServer.ImmediateSyncL(*calendar); |
|
364 TPckg<TBool> keepserverDes(keepserver); |
|
365 aMessage.WriteL(1, keepserverDes); |
|
366 |
|
367 CleanupStack::PopAndDestroy(calendar); |
|
368 aMessage.Complete(KErrNone); |
|
369 } |
|
370 |
|
371 void CCalDavServerSession::EnabledSyncL(const RMessage2& aMessage) |
|
372 { |
|
373 TUint length = aMessage.GetDesLength(0); |
|
374 HBufC* calendar = HBufC::NewLC(length); |
|
375 TPtr calendarPtr(calendar->Des()); |
|
376 aMessage.ReadL(0, calendarPtr); |
|
377 |
|
378 TBool enabledsync = rServer.EnabledSyncL(*calendar); |
|
379 TPckg<TBool> enabledsyncDes(enabledsync); |
|
380 aMessage.WriteL(1, enabledsyncDes); |
|
381 |
|
382 CleanupStack::PopAndDestroy(calendar); |
|
383 aMessage.Complete(KErrNone); |
|
384 } |
|
385 |
|
386 void CCalDavServerSession::SetKeepServerEntryL(const RMessage2& aMessage) |
|
387 { |
|
388 TUint length = aMessage.GetDesLength(0); |
|
389 HBufC* calendar = HBufC::NewLC(length); |
|
390 TPtr calendarPtr(calendar->Des()); |
|
391 aMessage.ReadL(0, calendarPtr); |
|
392 |
|
393 TBool keepserver; |
|
394 TPckg<TBool> keepserverDes(keepserver); |
|
395 aMessage.ReadL(1, keepserverDes); |
|
396 rServer.SetImmediateSyncL(*calendar, keepserver); |
|
397 |
|
398 CleanupStack::PopAndDestroy(calendar); |
|
399 aMessage.Complete(KErrNone); |
|
400 } |