|
1 /* |
|
2 * Copyright (c) 2002-2005 Nokia Corporation 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 Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Symbian OS Server source. |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <ecom.h> |
|
20 #include <implementationinformation.h> |
|
21 |
|
22 #include "nsmlsosserver.h" |
|
23 |
|
24 // -------------------------------------------------------------------------- |
|
25 // CNSmlProfile::CNSmlProfile( TSmlUsageType aUsageType ) |
|
26 // -------------------------------------------------------------------------- |
|
27 // |
|
28 CNSmlProfile::CNSmlProfile( TSmlUsageType aUsageType, CNSmlSOSSession& aSession ) |
|
29 : iProfId(KNSmlNullId), iUsageType(aUsageType), iSession(aSession), iLocked(EFalse), |
|
30 iDataPtr(NULL, 0, 0) |
|
31 { |
|
32 } |
|
33 |
|
34 // -------------------------------------------------------------------------- |
|
35 // CNSmlProfile::~CNSmlProfile() |
|
36 // -------------------------------------------------------------------------- |
|
37 // |
|
38 CNSmlProfile::~CNSmlProfile() |
|
39 { |
|
40 delete iBuffer; |
|
41 } |
|
42 |
|
43 // -------------------------------------------------------------------------- |
|
44 // TInt CNSmlProfile::ProfileId() const |
|
45 // -------------------------------------------------------------------------- |
|
46 // |
|
47 TInt CNSmlProfile::ProfileId() const |
|
48 { |
|
49 return iProfId; |
|
50 } |
|
51 |
|
52 // -------------------------------------------------------------------------- |
|
53 // void CNSmlProfile::SetLocked() |
|
54 // -------------------------------------------------------------------------- |
|
55 // |
|
56 void CNSmlProfile::SetLocked() |
|
57 { |
|
58 iLocked = ETrue; |
|
59 } |
|
60 |
|
61 // -------------------------------------------------------------------------- |
|
62 // TBool CNSmlProfile::IsLocked() |
|
63 // -------------------------------------------------------------------------- |
|
64 // |
|
65 TBool CNSmlProfile::IsLocked() |
|
66 { |
|
67 return iLocked; |
|
68 } |
|
69 |
|
70 // -------------------------------------------------------------------------- |
|
71 // void CNSmlProfile::SetCreatorId( const TInt aCreatorId ) |
|
72 // -------------------------------------------------------------------------- |
|
73 // |
|
74 void CNSmlProfile::SetCreatorId( const TInt aCreatorId ) |
|
75 { |
|
76 iCreatorId = aCreatorId; |
|
77 } |
|
78 |
|
79 // -------------------------------------------------------------------------- |
|
80 // TInt CNSmlProfile::FetchDataL( const TInt aId, TBool aAllowHidden ) |
|
81 // -------------------------------------------------------------------------- |
|
82 // |
|
83 TInt CNSmlProfile::FetchDataL( const TInt aId, TBool aAllowHidden ) |
|
84 { |
|
85 iProfId = aId; |
|
86 TInt ret(KErrNotFound); |
|
87 // Get profile data and pack it into aData. |
|
88 switch ( iUsageType ) |
|
89 { |
|
90 case ESmlDataSync: |
|
91 { |
|
92 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
93 |
|
94 if ( prof ) |
|
95 { |
|
96 CleanupStack::PushL(prof); |
|
97 |
|
98 // check that hidden profiles are allowed |
|
99 if ( !aAllowHidden && prof->IntValue( EDSProfileHidden) ) |
|
100 { |
|
101 ret = KErrAccessDenied; |
|
102 } |
|
103 else |
|
104 { |
|
105 TInt namelen = prof->StrValue( EDSProfileDisplayName ).Size(); |
|
106 TInt unlen = prof->StrValue( EDSProfileSyncServerUsername ).Size(); |
|
107 TInt pwlen = prof->StrValue( EDSProfileSyncServerPassword ).Size(); |
|
108 TInt sidlen = prof->StrValue( EDSProfileServerId ).Size(); |
|
109 |
|
110 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
111 CleanupStack::PushL( buffer ); |
|
112 RBufWriteStream stream( *buffer ); |
|
113 CleanupClosePushL(stream); |
|
114 |
|
115 stream.WriteInt32L( namelen ); |
|
116 stream << prof->StrValue( EDSProfileDisplayName ); |
|
117 |
|
118 stream.WriteInt32L( unlen ); |
|
119 stream << prof->StrValue( EDSProfileSyncServerUsername ); |
|
120 |
|
121 stream.WriteInt32L( pwlen ); |
|
122 stream << prof->StrValue( EDSProfileSyncServerPassword ); |
|
123 |
|
124 stream.WriteInt32L( sidlen ); |
|
125 stream << prof->StrValue( EDSProfileServerId ); |
|
126 |
|
127 stream.WriteInt8L( prof->IntValue( EDSProfileServerAlertedAction ) ); |
|
128 stream.WriteInt32L( prof->IntValue( EDSProfileCreatorId ) ); |
|
129 |
|
130 stream.WriteInt8L( prof->IntValue( EDSProfileDeleteAllowed ) ); |
|
131 stream.WriteInt8L( prof->IntValue( EDSProfileProtocolVersion ) ); |
|
132 |
|
133 stream.CommitL(); |
|
134 |
|
135 CleanupStack::PopAndDestroy(&stream); |
|
136 |
|
137 delete iBuffer; |
|
138 iBuffer = buffer; |
|
139 CleanupStack::Pop( buffer ); |
|
140 ret = KErrNone; |
|
141 } |
|
142 |
|
143 CleanupStack::PopAndDestroy(prof); |
|
144 } |
|
145 break; |
|
146 } |
|
147 case ESmlDevMan: |
|
148 { |
|
149 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
150 if ( prof ) |
|
151 { |
|
152 CleanupStack::PushL(prof); |
|
153 |
|
154 if ( !aAllowHidden && prof->IntValue( EDMProfileHidden) ) |
|
155 { |
|
156 ret = KErrAccessDenied; |
|
157 } |
|
158 else |
|
159 { |
|
160 TInt namelen = prof->StrValue( EDMProfileDisplayName ).Size(); |
|
161 TInt sunlen = prof->StrValue( EDMProfileServerUsername ).Size(); |
|
162 TInt spwlen = prof->StrValue( EDMProfileServerPassword ).Size(); |
|
163 TInt sidlen = prof->StrValue( EDMProfileServerId ).Size(); |
|
164 TInt pwlen = prof->StrValue( EDMProfileClientPassword ).Size(); |
|
165 |
|
166 CBufFlat* buffer = CBufFlat::NewL( KDefaultNSmlBufferGranularity ); |
|
167 CleanupStack::PushL( buffer ); |
|
168 RBufWriteStream stream( *buffer ); |
|
169 CleanupClosePushL(stream); |
|
170 |
|
171 stream.WriteInt32L( namelen ); |
|
172 stream << prof->StrValue( EDMProfileDisplayName ); |
|
173 |
|
174 stream.WriteInt32L( sunlen ); |
|
175 stream << prof->StrValue( EDMProfileServerUsername ); |
|
176 |
|
177 stream.WriteInt32L( spwlen ); |
|
178 stream << prof->StrValue( EDMProfileServerPassword ); |
|
179 |
|
180 stream.WriteInt32L( sidlen ); |
|
181 stream << prof->StrValue( EDMProfileServerId ); |
|
182 |
|
183 stream.WriteInt8L( prof->IntValue( EDMProfileServerAlertAction ) ); |
|
184 stream.WriteInt32L( prof->IntValue( EDMProfileCreatorId ) ); |
|
185 stream.WriteInt8L( prof->IntValue( EDMProfileDeleteAllowed ) ); |
|
186 stream.WriteInt8L( prof->IntValue( EDMProfileLock ) ); |
|
187 stream.WriteInt32L( pwlen ); |
|
188 stream << prof->StrValue( EDMProfileClientPassword ); |
|
189 |
|
190 stream.CommitL(); |
|
191 |
|
192 CleanupStack::PopAndDestroy(&stream); |
|
193 |
|
194 delete iBuffer; |
|
195 iBuffer = buffer; |
|
196 CleanupStack::Pop( buffer ); |
|
197 |
|
198 ret = KErrNone; |
|
199 } |
|
200 CleanupStack::PopAndDestroy(prof); |
|
201 } |
|
202 break; |
|
203 } |
|
204 default: |
|
205 break; |
|
206 } |
|
207 return ret; |
|
208 } |
|
209 |
|
210 // -------------------------------------------------------------------------- |
|
211 // void CNSmlProfile::ConnectionListL( RArray<TInt>& aArray ) |
|
212 // -------------------------------------------------------------------------- |
|
213 // |
|
214 void CNSmlProfile::ConnectionListL( RArray<TInt>& aArray ) |
|
215 { |
|
216 if ( iProfId < KMaxDataSyncID ) // DS profile |
|
217 { |
|
218 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
219 if ( prof ) |
|
220 { |
|
221 // Currently there's only one connection per profile. |
|
222 aArray.AppendL( prof->IntValue( EDSProfileTransportId ) ); |
|
223 delete prof; |
|
224 prof = NULL; |
|
225 } |
|
226 } |
|
227 else // DM profile |
|
228 { |
|
229 CNSmlDMProfile* prof = iSession.DMSettings().ProfileL( iProfId ); |
|
230 if ( prof ) |
|
231 { |
|
232 aArray.AppendL( prof->IntValue( EDMProfileTransportId ) ); |
|
233 delete prof; |
|
234 prof = NULL; |
|
235 } |
|
236 } |
|
237 } |
|
238 |
|
239 // -------------------------------------------------------------------------- |
|
240 // void CNSmlProfile::TaskListL( RArray<TInt>& aArray ) |
|
241 // -------------------------------------------------------------------------- |
|
242 // |
|
243 void CNSmlProfile::TaskListL( RArray<TInt>& aArray ) |
|
244 { |
|
245 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
246 if ( prof ) |
|
247 { |
|
248 CleanupStack::PushL(prof); |
|
249 |
|
250 RImplInfoPtrArray implArray; |
|
251 CleanupStack::PushL(PtrArrCleanupItemRArr( CImplementationInformation, &implArray ) ); |
|
252 TUid ifUid = { KNSmlDSInterfaceUid }; |
|
253 REComSession::ListImplementationsL( ifUid, implArray ); |
|
254 for ( TInt i = 0 ; i < implArray.Count() ; i++ ) |
|
255 { |
|
256 CImplementationInformation* implInfo = implArray[i]; |
|
257 CNSmlDSContentType* ctype = prof->ContentType( implInfo->ImplementationUid().iUid ); |
|
258 if ( ctype ) |
|
259 { |
|
260 aArray.AppendL( ctype->IntValue( EDSAdapterTableId ) ); |
|
261 } |
|
262 } |
|
263 REComSession::FinalClose(); |
|
264 CleanupStack::PopAndDestroy(&implArray); |
|
265 CleanupStack::PopAndDestroy(prof); |
|
266 } |
|
267 } |
|
268 |
|
269 // -------------------------------------------------------------------------- |
|
270 // TInt CNSmlProfile::DataSize() |
|
271 // -------------------------------------------------------------------------- |
|
272 // |
|
273 TInt CNSmlProfile::DataSize() |
|
274 { |
|
275 return iBuffer->Size(); |
|
276 } |
|
277 |
|
278 // -------------------------------------------------------------------------- |
|
279 // const TPtr8& CNSmlProfile::ReadData() |
|
280 // -------------------------------------------------------------------------- |
|
281 // |
|
282 const TPtr8& CNSmlProfile::ReadData() |
|
283 { |
|
284 if ( iBuffer ) |
|
285 { |
|
286 iDataPtr.Set(iBuffer->Ptr(0)); |
|
287 } |
|
288 return iDataPtr; |
|
289 } |
|
290 |
|
291 // -------------------------------------------------------------------------- |
|
292 // TInt CNSmlProfile::UpdateDataL( TInt& aId , const TDesC8& aData, TBool& aIsHidden ) |
|
293 // -------------------------------------------------------------------------- |
|
294 // |
|
295 TInt CNSmlProfile::UpdateDataL( TInt& aId , const TDesC8& aData, TBool& aIsHidden ) |
|
296 { |
|
297 aIsHidden = EFalse; |
|
298 TInt ret(KErrNone); |
|
299 switch ( iUsageType ) |
|
300 { |
|
301 case ESmlDataSync: |
|
302 { |
|
303 CNSmlDSProfile* prof; |
|
304 |
|
305 if ( iProfId == KNSmlNullId ) |
|
306 { |
|
307 prof = iSession.DSSettings().CreateProfileL(); |
|
308 } |
|
309 else |
|
310 { |
|
311 prof = iSession.DSSettings().ProfileL( iProfId ); |
|
312 |
|
313 if ( !prof ) |
|
314 { |
|
315 User::Leave( KErrNotFound ); |
|
316 } |
|
317 } |
|
318 User::LeaveIfNull(prof); |
|
319 |
|
320 CleanupStack::PushL(prof); |
|
321 |
|
322 aIsHidden = prof->IntValue( EDSProfileHidden ); |
|
323 |
|
324 RDesReadStream stream; |
|
325 stream.Open(aData); |
|
326 CleanupClosePushL(stream); |
|
327 |
|
328 TInt maxlen(0); |
|
329 TInt pc(0); |
|
330 |
|
331 maxlen = stream.ReadInt32L(); |
|
332 prof->SetStrValue( EDSProfileDisplayName, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
333 maxlen = stream.ReadInt32L(); |
|
334 prof->SetStrValue( EDSProfileSyncServerUsername, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
335 maxlen = stream.ReadInt32L(); |
|
336 prof->SetStrValue( EDSProfileSyncServerPassword, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
337 maxlen = stream.ReadInt32L(); |
|
338 prof->SetStrValue( EDSProfileServerId, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
339 |
|
340 prof->SetIntValue( EDSProfileServerAlertedAction, stream.ReadInt8L() ); |
|
341 |
|
342 prof->SetIntValue( EDSProfileCreatorId, stream.ReadInt32L() ); |
|
343 |
|
344 prof->SetIntValue( EDSProfileProtocolVersion, stream.ReadInt8L() ); |
|
345 |
|
346 CleanupStack::PopAndDestroy(pc); |
|
347 |
|
348 ret = prof->SaveL(); |
|
349 |
|
350 // read id after SaveL() and return to client. |
|
351 iProfId = prof->IntValue( EDSProfileId ); |
|
352 |
|
353 aId = iProfId; |
|
354 |
|
355 CleanupStack::PopAndDestroy(&stream); |
|
356 CleanupStack::PopAndDestroy(prof); |
|
357 |
|
358 break; |
|
359 } |
|
360 case ESmlDevMan: |
|
361 { |
|
362 CNSmlDMProfile* prof; |
|
363 |
|
364 if ( iProfId == KNSmlNullId ) |
|
365 { |
|
366 prof = iSession.DMSettings().CreateProfileL(); |
|
367 } |
|
368 else |
|
369 { |
|
370 prof = iSession.DMSettings().ProfileL( iProfId ); |
|
371 |
|
372 if ( !prof ) |
|
373 { |
|
374 User::Leave( KErrNotFound ); |
|
375 } |
|
376 } |
|
377 User::LeaveIfNull(prof); |
|
378 |
|
379 CleanupStack::PushL(prof); |
|
380 |
|
381 RDesReadStream stream; |
|
382 stream.Open(aData); |
|
383 CleanupClosePushL(stream); |
|
384 |
|
385 TInt maxlen(0); |
|
386 TInt pc(0); |
|
387 |
|
388 maxlen = stream.ReadInt32L(); |
|
389 prof->SetStrValue( EDMProfileDisplayName, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
390 maxlen = stream.ReadInt32L(); |
|
391 prof->SetStrValue( EDMProfileServerUsername, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
392 maxlen = stream.ReadInt32L(); |
|
393 prof->SetStrValue( EDMProfileServerPassword, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
394 maxlen = stream.ReadInt32L(); |
|
395 HBufC* serverId = HBufC::NewLC(stream,maxlen); pc++; |
|
396 prof->SetStrValue( EDMProfileServerId, *serverId); |
|
397 |
|
398 prof->SetIntValue( EDMProfileServerAlertAction, stream.ReadInt8L() ); |
|
399 |
|
400 prof->SetIntValue( EDMProfileCreatorId ,stream.ReadInt32L() ); |
|
401 |
|
402 |
|
403 prof->SetIntValue( EDMProfileLock, stream.ReadInt8L() ); |
|
404 |
|
405 maxlen = stream.ReadInt32L(); |
|
406 prof->SetStrValue( EDMProfileClientPassword, HBufC::NewLC(stream,maxlen)->Des() ); pc++; |
|
407 |
|
408 |
|
409 |
|
410 if(iSession.DMSettings().ServerIdFoundL(*serverId,iProfId)) |
|
411 { |
|
412 ret = KErrAlreadyExists; |
|
413 } |
|
414 else |
|
415 { |
|
416 ret = prof->SaveL(); |
|
417 |
|
418 // read id after SaveL() and return to client. |
|
419 iProfId = prof->IntValue( EDMProfileId ); |
|
420 |
|
421 aId = iProfId; |
|
422 } |
|
423 |
|
424 CleanupStack::PopAndDestroy(pc); |
|
425 |
|
426 CleanupStack::PopAndDestroy(&stream); |
|
427 CleanupStack::PopAndDestroy(prof); |
|
428 break; |
|
429 } |
|
430 default: |
|
431 ret = KErrNotFound; |
|
432 break; |
|
433 } |
|
434 return ret; |
|
435 } |
|
436 |
|
437 // -------------------------------------------------------------------------- |
|
438 // TBool CNSmlProfile::DeleteTaskL( const TInt aId ) |
|
439 // -------------------------------------------------------------------------- |
|
440 // |
|
441 TBool CNSmlProfile::DeleteTaskL( const TInt aId ) |
|
442 { |
|
443 TBool deleted = EFalse; |
|
444 CNSmlDSProfile* prof = iSession.DSSettings().ProfileL( iProfId ); |
|
445 if ( prof ) |
|
446 { |
|
447 CleanupStack::PushL(prof); |
|
448 deleted = prof->DeleteContentTypeL( aId ); |
|
449 prof->SaveL(); |
|
450 CleanupStack::PopAndDestroy(prof); |
|
451 } |
|
452 |
|
453 return deleted; |
|
454 } |
|
455 |
|
456 // -------------------------------------------------------------------------- |
|
457 // TSmlUsageType CNSmlProfile::GetUsageType() |
|
458 // -------------------------------------------------------------------------- |
|
459 // |
|
460 TSmlUsageType CNSmlProfile::GetUsageType() |
|
461 { |
|
462 return iUsageType; |
|
463 } |
|
464 |
|
465 // End of File |