|
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, follows Symbian client/server |
|
15 * architecture |
|
16 */ |
|
17 |
|
18 #include <e32svr.h> |
|
19 #include <e32uid.h> |
|
20 #include <S32MEM.H> |
|
21 |
|
22 #include <xmlengdocument.h> |
|
23 #include <xmlengtext.h> |
|
24 |
|
25 #include "caldavserver.h" |
|
26 #include "caldavenginemgr.h" |
|
27 #include "caldavserverSession.h" |
|
28 #include "httpclient.h" |
|
29 |
|
30 const TUint KServerPolicyRangeCount = 2; |
|
31 |
|
32 const TInt KServerPolicyRanges[KServerPolicyRangeCount] = |
|
33 { |
|
34 0, // range is 0 inclusive |
|
35 200 |
|
36 // range is 1-KMaxTInt inclusive |
|
37 }; |
|
38 |
|
39 const TUint8 KServerPolicyElementsIndex[KServerPolicyRangeCount] = |
|
40 { |
|
41 0, // applies to 0th range |
|
42 CPolicyServer::ENotSupported |
|
43 // applies to 1st range |
|
44 }; |
|
45 |
|
46 /** |
|
47 * CPolicyServer::TPolicyElement() |
|
48 * |
|
49 */ |
|
50 const CPolicyServer::TPolicyElement |
|
51 KServerPolicyElements[] = |
|
52 { |
|
53 { |
|
54 _INIT_SECURITY_POLICY_C5(ECapabilityWriteDeviceData,ECapabilityWriteUserData, ECapabilityReadDeviceData,ECapabilityReadUserData,ECapabilityNetworkServices), CPolicyServer::EFailClient |
|
55 } |
|
56 }; |
|
57 |
|
58 const CPolicyServer::TPolicy KServerPolicy = |
|
59 { |
|
60 CPolicyServer::EAlwaysPass, // specifies all connect attempts should pass |
|
61 KServerPolicyRangeCount, |
|
62 KServerPolicyRanges, |
|
63 KServerPolicyElementsIndex, |
|
64 KServerPolicyElements |
|
65 }; |
|
66 |
|
67 /** |
|
68 * CCalDavServer::CCalDavServer |
|
69 * default constructor |
|
70 */ |
|
71 CCalDavServer::CCalDavServer(CActive::TPriority aActiveObjectPriority) : |
|
72 CPolicyServer(aActiveObjectPriority, KServerPolicy) |
|
73 { |
|
74 } |
|
75 |
|
76 /** |
|
77 * CCalDavServer::NewSessionL |
|
78 * Creates a new session with the server. |
|
79 */ |
|
80 CSession2* CCalDavServer::NewSessionL(const TVersion& aVersion, |
|
81 const RMessage2& /*aMessage*/) const |
|
82 { |
|
83 // Check that the version is OK |
|
84 TVersion v(KCalDavServerMajorVersionNumber, |
|
85 KCalDavServerMinorVersionNumber, KCalDavServerBuildVersionNumber); |
|
86 if (!User::QueryVersionSupported(v, aVersion)) |
|
87 User::Leave(KErrNotSupported); |
|
88 |
|
89 // CAN USE THE aMessage argument to check client's security and identity |
|
90 // can make use of this later but for now ignore. AH 4/5/05 |
|
91 // the connect message is delivered via the RMessage2 object passed. |
|
92 |
|
93 // do something with this later (and move it to the start of the function?) |
|
94 |
|
95 // Create the session. |
|
96 return new (ELeave) CCalDavServerSession(*const_cast<CCalDavServer*> (this)); |
|
97 } |
|
98 |
|
99 /** |
|
100 * CCalDavServer::PanicServer |
|
101 A utility function to panic the server. |
|
102 */ |
|
103 void CCalDavServer::PanicServer(TCalDavServPanic aPanic) |
|
104 { |
|
105 _LIT(KTxtServerPanic,"CalDav server panic"); |
|
106 User::Panic(KTxtServerPanic, aPanic); |
|
107 } |
|
108 |
|
109 /** |
|
110 * CCalDavServer::ThreadFunction |
|
111 * The count server thread function that initialises the server. |
|
112 */ |
|
113 TInt CCalDavServer::ThreadFunction(TAny* /**aStarted*/) |
|
114 { |
|
115 CTrapCleanup* cleanupStack = CTrapCleanup::New(); |
|
116 if (!(cleanupStack)) |
|
117 { |
|
118 PanicServer(ECreateTrapCleanup); |
|
119 } |
|
120 TRAPD( err, ThreadFunctionL() ); |
|
121 if (err != KErrNone) |
|
122 { |
|
123 PanicServer(ESvrCreateServer); |
|
124 } |
|
125 |
|
126 delete cleanupStack; |
|
127 cleanupStack = NULL; |
|
128 |
|
129 return KErrNone; |
|
130 |
|
131 } |
|
132 |
|
133 /** |
|
134 * CCalDavServer::NewLC |
|
135 * first phase construction |
|
136 */ |
|
137 CCalDavServer* CCalDavServer::NewLC() |
|
138 { |
|
139 CCalDavServer* self = |
|
140 new (ELeave) CCalDavServer(CActive::EPriorityStandard); |
|
141 CleanupStack::PushL(self); |
|
142 self->ConstructL(); |
|
143 return self; |
|
144 } |
|
145 |
|
146 /** |
|
147 * CCalDavServer::ConstructL |
|
148 * second phase construction |
|
149 */ |
|
150 void CCalDavServer::ConstructL() |
|
151 { |
|
152 StartL(KCalDavServerName); |
|
153 |
|
154 iMgr = CCalDavEngineMgr::NewL(); |
|
155 } |
|
156 |
|
157 /** |
|
158 * CCalDavServer::ThreadFunctionL |
|
159 * start scheduler and construct function |
|
160 */ |
|
161 void CCalDavServer::ThreadFunctionL() |
|
162 { |
|
163 // Construct active scheduler |
|
164 CActiveScheduler* activeScheduler = new (ELeave) CActiveScheduler; |
|
165 CleanupStack::PushL(activeScheduler); |
|
166 |
|
167 // Install active scheduler |
|
168 // We don't need to check whether an active scheduler is already installed |
|
169 // as this is a new thread, so there won't be one |
|
170 CActiveScheduler::Install(activeScheduler); |
|
171 |
|
172 // Construct our server, leave it on clean-up stack |
|
173 CCalDavServer::NewLC(); |
|
174 |
|
175 // Naming the server thread after the server helps to debug panics |
|
176 User::LeaveIfError(User::RenameThread(KCalDavServerName)); |
|
177 |
|
178 RProcess::Rendezvous(KErrNone); |
|
179 |
|
180 // Start handling requests |
|
181 CActiveScheduler::Start(); |
|
182 |
|
183 CleanupStack::PopAndDestroy(2, activeScheduler); //Anonymous CCalDavServer |
|
184 } |
|
185 |
|
186 /** |
|
187 * CCalDavServer::~CCalDavServer |
|
188 * default destructor |
|
189 */ |
|
190 CCalDavServer::~CCalDavServer() |
|
191 { |
|
192 if (iMgr) |
|
193 delete iMgr; |
|
194 } |
|
195 |
|
196 /** |
|
197 * CCalDavServer::SyncL |
|
198 * |
|
199 */ |
|
200 TInt CCalDavServer::SyncL(const TDesC &aCalendar) |
|
201 { |
|
202 return iMgr->SyncL(aCalendar); |
|
203 } |
|
204 |
|
205 /** |
|
206 * CCalDavServer::SyncAllL |
|
207 * |
|
208 */ |
|
209 TInt CCalDavServer::SyncAllL() |
|
210 { |
|
211 return iMgr->SyncAllL(); |
|
212 } |
|
213 |
|
214 /** |
|
215 * CCalDavServer::EnableL |
|
216 * |
|
217 */ |
|
218 TInt CCalDavServer::EnableL(const TDesC &aCalendar) |
|
219 { |
|
220 return iMgr->EnableL(aCalendar); |
|
221 } |
|
222 |
|
223 /** |
|
224 * CCalDavServer::DisableL |
|
225 * |
|
226 */ |
|
227 TInt CCalDavServer::DisableL(const TDesC &aCalendar) |
|
228 { |
|
229 return iMgr->DisableL(aCalendar); |
|
230 } |
|
231 |
|
232 /** |
|
233 * CCalDavServer::UrlL |
|
234 * |
|
235 */ |
|
236 TPtrC8 CCalDavServer::UrlL(const TDesC &aCalendar) |
|
237 { |
|
238 return iMgr->UrlL(aCalendar); |
|
239 } |
|
240 |
|
241 /** |
|
242 * CCalDavServer::SetUrlL |
|
243 * |
|
244 */ |
|
245 void CCalDavServer::SetUrlL(const TDesC &aCalendar, const TDesC8 &aUrl) |
|
246 { |
|
247 return iMgr->SetUrlL(aCalendar, aUrl); |
|
248 } |
|
249 |
|
250 /** |
|
251 * CCalDavServer::UsernameL |
|
252 * |
|
253 */ |
|
254 TPtrC8 CCalDavServer::UsernameL(const TDesC &aCalendar) |
|
255 { |
|
256 return iMgr->UsernameL(aCalendar); |
|
257 } |
|
258 |
|
259 /** |
|
260 * CCalDavServer::SetUsernameL |
|
261 * |
|
262 */ |
|
263 void CCalDavServer::SetUsernameL(const TDesC &aCalendar, const TDesC8 &aUsername) |
|
264 { |
|
265 return iMgr->SetUsernameL(aCalendar, aUsername); |
|
266 } |
|
267 |
|
268 /** |
|
269 * CCalDavServer::PasswordL |
|
270 * |
|
271 */ |
|
272 TPtrC8 CCalDavServer::PasswordL(const TDesC &aCalendar) |
|
273 { |
|
274 return iMgr->PasswordL(aCalendar); |
|
275 } |
|
276 |
|
277 /** |
|
278 * CCalDavServer::SetPasswordL |
|
279 * |
|
280 */ |
|
281 void CCalDavServer::SetPasswordL(const TDesC &aCalendar, const TDesC8 &aPassword) |
|
282 { |
|
283 return iMgr->SetPasswordL(aCalendar, aPassword); |
|
284 } |
|
285 |
|
286 /** |
|
287 * CCalDavServer::SyncIntervalL |
|
288 * |
|
289 */ |
|
290 TTimeIntervalMinutes CCalDavServer::SyncIntervalL(const TDesC &aCalendar) const |
|
291 { |
|
292 return iMgr->SyncIntervalL(aCalendar); |
|
293 } |
|
294 |
|
295 /** |
|
296 * CCalDavServer::SetSyncIntervalL |
|
297 * |
|
298 */ |
|
299 void CCalDavServer::SetSyncIntervalL(const TDesC &aCalendar, |
|
300 TTimeIntervalMinutes aSyncInterval) |
|
301 { |
|
302 iMgr->SetSyncIntervalL(aCalendar, aSyncInterval); |
|
303 } |
|
304 |
|
305 /** |
|
306 * CCalDavServer::EnabledSyncL |
|
307 * |
|
308 */ |
|
309 TBool CCalDavServer::EnabledSyncL(const TDesC &aCalendar) const |
|
310 { |
|
311 return iMgr->EnabledSyncL(aCalendar); |
|
312 } |
|
313 |
|
314 /** |
|
315 * CCalDavServer::PastDaysL |
|
316 * |
|
317 */ |
|
318 TTimeIntervalDays CCalDavServer::PastDaysL(const TDesC &aCalendar) const |
|
319 { |
|
320 return iMgr->PastDaysL(aCalendar); |
|
321 } |
|
322 |
|
323 /** |
|
324 * CCalDavServer::SetPastDaysL |
|
325 * |
|
326 */ |
|
327 void CCalDavServer::SetPastDaysL(const TDesC &aCalendar, TTimeIntervalDays aDays) |
|
328 { |
|
329 iMgr->SetPastDaysL(aCalendar, aDays); |
|
330 } |
|
331 |
|
332 /** |
|
333 * CCalDavServer::ImmediateSyncL |
|
334 * |
|
335 */ |
|
336 TBool CCalDavServer::ImmediateSyncL(const TDesC &aCalendar) const |
|
337 { |
|
338 return iMgr->ImmediateSyncL(aCalendar); |
|
339 } |
|
340 |
|
341 /** |
|
342 * CCalDavServer::SetImmediateSyncL |
|
343 * |
|
344 */ |
|
345 void CCalDavServer::SetImmediateSyncL(const TDesC &aCalendar, |
|
346 TBool aImmediateSyc) |
|
347 { |
|
348 iMgr->SetImmediateSyncL(aCalendar, aImmediateSyc); |
|
349 } |
|
350 |
|
351 /** |
|
352 * CCalDavServer::KeepServerEntryL |
|
353 * |
|
354 */ |
|
355 TBool CCalDavServer::KeepServerEntryL(const TDesC &aCalendar) const |
|
356 { |
|
357 return iMgr->KeepServerEntryL(aCalendar); |
|
358 } |
|
359 |
|
360 /** |
|
361 * CCalDavServer::SetKeepServerEntryL |
|
362 * |
|
363 */ |
|
364 void CCalDavServer::SetKeepServerEntryL(const TDesC &aCalendar, |
|
365 TBool aKeepServerEntry) |
|
366 { |
|
367 iMgr->SetKeepServerEntryL(aCalendar, aKeepServerEntry); |
|
368 } |
|
369 |
|
370 TInt E32Main() |
|
371 { |
|
372 return CCalDavServer::ThreadFunction(NULL); |
|
373 } |