|
1 /* |
|
2 * Copyright (c) 2002-2004 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: DM-settings |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <sysutil.h> |
|
22 #include <nsmlconstants.h> |
|
23 #include <nsmldebug.h> |
|
24 #include <nsmldmconstants.h> |
|
25 |
|
26 #include "nsmldmsettings.h" |
|
27 |
|
28 |
|
29 //------------------------------------------------------------------------------ |
|
30 // |
|
31 // CNSmlDMProfile |
|
32 // |
|
33 //------------------------------------------------------------------------------ |
|
34 |
|
35 //------------------------------------------------------------------------------ |
|
36 // CNSmlDMProfile::NewL() |
|
37 // Creates a new instance of CNSmlDMProfile object. |
|
38 //------------------------------------------------------------------------------ |
|
39 |
|
40 CNSmlDMProfile* CNSmlDMProfile::NewL( RDbNamedDatabase* aDatabase ) |
|
41 { |
|
42 CNSmlDMProfile* self = CNSmlDMProfile::NewLC( aDatabase ); |
|
43 CleanupStack::Pop(); |
|
44 return self; |
|
45 } |
|
46 |
|
47 //------------------------------------------------------------------------------ |
|
48 // CNSmlDMProfile::NewLC() |
|
49 // Creates a new instance of CNSmlDMProfile object. |
|
50 // Pushes and leaves new instance into CleanupStack. |
|
51 //------------------------------------------------------------------------------ |
|
52 |
|
53 CNSmlDMProfile* CNSmlDMProfile::NewLC( RDbNamedDatabase* aDatabase ) |
|
54 { |
|
55 CNSmlDMProfile* self = new( ELeave ) CNSmlDMProfile; |
|
56 CleanupStack::PushL( self ); |
|
57 self->ConstructL( aDatabase ); |
|
58 return self; |
|
59 } |
|
60 |
|
61 //------------------------------------------------------------------------------ |
|
62 // CNSmlDMProfile::ConstructL() |
|
63 // Second phase constructor. |
|
64 //------------------------------------------------------------------------------ |
|
65 |
|
66 void CNSmlDMProfile::ConstructL( RDbNamedDatabase* aDatabase ) |
|
67 { |
|
68 iDatabase = aDatabase; |
|
69 iId = ( TUint ) KNSmlNewObject; |
|
70 |
|
71 User::LeaveIfError( iTableProfiles.Open( *iDatabase, KNSmlDMTableProfiles ) ); |
|
72 iColSetProfiles = iTableProfiles.ColSetL(); |
|
73 |
|
74 iDisplayName = HBufC::NewL( KNSmlDmMaxProfileNameLength ); |
|
75 iDMServerUsername = HBufC::NewL( KNSmlDmMaxUsernameLength ); |
|
76 iDMServerPassword = HBufC::NewL( KNSmlDmMaxPasswordLength ); |
|
77 iClientPassword = HBufC::NewL( KNSmlDmSharedSecretMaxLength ); |
|
78 iServerId = HBufC::NewL( KNSmlDmServerIdMaxLength ); |
|
79 iServerURL = HBufC::NewL( KNSmlDmMaxURLLength ); |
|
80 iHttpAuthUsername = HBufC::NewL( KNSmlDmMaxHttpAuthUsernameLength ); |
|
81 iHttpAuthPassword = HBufC::NewL( KNSmlDmMaxHttpAuthPasswordLength ); |
|
82 iProfileLock = EFalse; |
|
83 } |
|
84 |
|
85 //------------------------------------------------------------------------------ |
|
86 // CNSmlDMProfile::~CNSmlDMProfile() |
|
87 // Destructor. |
|
88 //------------------------------------------------------------------------------ |
|
89 |
|
90 EXPORT_C CNSmlDMProfile::~CNSmlDMProfile() |
|
91 { |
|
92 delete iDisplayName; |
|
93 delete iDMServerUsername; |
|
94 delete iDMServerPassword; |
|
95 delete iClientPassword; |
|
96 delete iServerId; |
|
97 delete iServerURL; |
|
98 delete iHttpAuthUsername; |
|
99 delete iHttpAuthPassword; |
|
100 |
|
101 iView.Close(); |
|
102 iWSView.Close(); |
|
103 iRSView.Close(); |
|
104 |
|
105 if(iColSetProfiles) |
|
106 { |
|
107 delete iColSetProfiles; |
|
108 } |
|
109 |
|
110 |
|
111 iTableProfiles.Close(); |
|
112 } |
|
113 |
|
114 //------------------------------------------------------------------------------ |
|
115 // CNSmlDMProfile::SaveL() |
|
116 // Saves a profile ie. writes all profile data to the database. |
|
117 // If save is succesfull returns KErrNone, |
|
118 // otherwise returns negative integer (defined in EPOC error codes). |
|
119 //------------------------------------------------------------------------------ |
|
120 |
|
121 EXPORT_C TInt CNSmlDMProfile::SaveL() |
|
122 { |
|
123 _DBG_FILE("CNSmlDMProfile::SaveL(): begin"); |
|
124 |
|
125 if ( iDatabase->InTransaction() ) |
|
126 { |
|
127 return ( KErrAccessDenied ); |
|
128 } |
|
129 |
|
130 iDatabase->Begin(); |
|
131 CNSmlDMCrypt* crypt = new(ELeave) CNSmlDMCrypt; |
|
132 CleanupStack::PushL(crypt); |
|
133 |
|
134 if ( iId == ( TUint ) KNSmlNewObject ) |
|
135 { |
|
136 // Check OOD before saving a New profile |
|
137 RFs fs; |
|
138 User::LeaveIfError( fs.Connect() ); |
|
139 CleanupClosePushL(fs); |
|
140 |
|
141 if (SysUtil::FFSSpaceBelowCriticalLevelL(&fs, KNSmlDmSettingsFatMinSize)) |
|
142 { |
|
143 iDatabase->Rollback(); |
|
144 CleanupStack::PopAndDestroy(2); // crypt, fs |
|
145 return KErrDiskFull; |
|
146 // do not write |
|
147 } |
|
148 CleanupStack::PopAndDestroy(); //fs |
|
149 |
|
150 //new profile |
|
151 iTableProfiles.InsertL(); |
|
152 |
|
153 TableProfilesSetColDesL( KNSmlDMProfileDisplayName, *iDisplayName ); |
|
154 TableProfilesSetColIntL( KNSmlDMProfileIAPId, iIAPId ); |
|
155 TableProfilesSetColIntL( KNSmlDMProfileTransportId, iTransportId ); |
|
156 |
|
157 TableProfilesSetColDesL( KNSmlDMProfileServerUsername, *iDMServerUsername ); |
|
158 TableProfilesSetColDesL( KNSmlDMProfileServerPassword, crypt->EncryptedL( *iDMServerPassword) ); |
|
159 TableProfilesSetColDesL( KNSmlDMProfileClientPassword, crypt->EncryptedL( *iClientPassword) ); |
|
160 |
|
161 TableProfilesSetColDesL( KNSmlDMProfileServerURL, *iServerURL ); |
|
162 TableProfilesSetColDesL( KNSmlDMProfileServerId, *iServerId ); |
|
163 |
|
164 TableProfilesSetColIntL( KNSmlDMProfileServerAlertedAction, iServerAlertAction ); |
|
165 TableProfilesSetColIntL( KNSmlDMProfileAuthenticationRequired, iAuthenticationRequired ); |
|
166 TableProfilesSetColIntL( KNSmlDMProfileCreatorId, iCreatorId ); |
|
167 TableProfilesSetColIntL( KNSmlDMProfileDeleteAllowed, iDeleteAllowed ); |
|
168 TableProfilesSetColIntL( KNSmlDMProfileSessionId, iDMSessionId ); |
|
169 TableProfilesSetColIntL( KNSmlDMProfileHidden, iProfileHidden ); |
|
170 |
|
171 TableProfilesSetColIntL( KNSmlDMProfileHttpAuthUsed, iHttpAuthUsed ); |
|
172 TableProfilesSetColDesL( KNSmlDMProfileHttpAuthUsername, *iHttpAuthUsername ); |
|
173 TableProfilesSetColDesL( KNSmlDMProfileHttpAuthPassword, crypt->EncryptedL( *iHttpAuthPassword ) ); |
|
174 TableProfilesSetColIntL(KNSmlDMProfileLock,iProfileLock); |
|
175 |
|
176 iId = iTableProfiles.ColUint( iColSetProfiles->ColNo( KNSmlDMProfileId) ); // Use autoincrement |
|
177 iId+= KMaxDataSyncID; |
|
178 iTableProfiles.SetColL( iColSetProfiles->ColNo( KNSmlDMProfileId ), iId ); |
|
179 |
|
180 iTableProfiles.PutL(); |
|
181 } |
|
182 else |
|
183 { |
|
184 //existing profile |
|
185 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
186 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
187 |
|
188 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
189 |
|
190 PrepareViewL( sqlStatementPtr, iView.EUpdatable ); |
|
191 |
|
192 CleanupStack::PopAndDestroy(); // sqlStatement |
|
193 |
|
194 if ( iView.FirstL() ) |
|
195 { |
|
196 iView.GetL(); |
|
197 iView.UpdateL(); |
|
198 |
|
199 ViewSetColDesL( KNSmlDMProfileDisplayName, *iDisplayName ); |
|
200 ViewSetColIntL( KNSmlDMProfileTransportId, iTransportId ); |
|
201 ViewSetColIntL( KNSmlDMProfileIAPId, iIAPId ); |
|
202 |
|
203 ViewSetColDesL( KNSmlDMProfileServerUsername, *iDMServerUsername ); |
|
204 ViewSetColDesL( KNSmlDMProfileServerPassword, crypt->EncryptedL( *iDMServerPassword ) ); |
|
205 ViewSetColDesL( KNSmlDMProfileClientPassword, crypt->EncryptedL( *iClientPassword) ); |
|
206 |
|
207 ViewSetColDesL( KNSmlDMProfileServerURL, *iServerURL ); |
|
208 ViewSetColDesL( KNSmlDMProfileServerId, *iServerId ); |
|
209 |
|
210 ViewSetColIntL( KNSmlDMProfileServerAlertedAction, iServerAlertAction ); |
|
211 ViewSetColIntL( KNSmlDMProfileAuthenticationRequired, iAuthenticationRequired ); |
|
212 ViewSetColIntL( KNSmlDMProfileCreatorId, iCreatorId ); |
|
213 ViewSetColIntL( KNSmlDMProfileDeleteAllowed, iDeleteAllowed ); |
|
214 ViewSetColIntL( KNSmlDMProfileSessionId, iDMSessionId); |
|
215 ViewSetColIntL( KNSmlDMProfileHidden, iProfileHidden ); |
|
216 |
|
217 ViewSetColIntL( KNSmlDMProfileHttpAuthUsed, iHttpAuthUsed ); |
|
218 ViewSetColDesL( KNSmlDMProfileHttpAuthUsername, *iHttpAuthUsername ); |
|
219 ViewSetColDesL( KNSmlDMProfileHttpAuthPassword, crypt->EncryptedL( *iHttpAuthPassword ) ); |
|
220 ViewSetColIntL( KNSmlDMProfileLock, iProfileLock ); |
|
221 |
|
222 iView.PutL(); |
|
223 } |
|
224 else |
|
225 { |
|
226 iDatabase->Rollback(); |
|
227 CleanupStack::PopAndDestroy(); //crypt |
|
228 |
|
229 return KErrNotFound; |
|
230 } |
|
231 |
|
232 } |
|
233 |
|
234 CleanupStack::PopAndDestroy(); //crypt |
|
235 CommitAndCompact(); |
|
236 |
|
237 _DBG_FILE("CNSmlDMProfile::SaveL(): end"); |
|
238 |
|
239 return KErrNone; |
|
240 } |
|
241 |
|
242 //------------------------------------------------------------------------------ |
|
243 // CNSmlDMProfile::IsNew() |
|
244 // Returns true if profile is new, otherwise false. |
|
245 //------------------------------------------------------------------------------ |
|
246 |
|
247 EXPORT_C TBool CNSmlDMProfile::IsNew() const |
|
248 { |
|
249 return ( iId == ( TUint ) KNSmlNewObject ); |
|
250 } |
|
251 |
|
252 //------------------------------------------------------------------------------ |
|
253 // CNSmlDMProfile::StrValue() |
|
254 // Returns a given string value. |
|
255 //------------------------------------------------------------------------------ |
|
256 |
|
257 EXPORT_C const TDesC& CNSmlDMProfile::StrValue( TNSmlDMProfileData aProfileItem ) const |
|
258 { |
|
259 HBufC* result = 0; |
|
260 switch ( aProfileItem ) |
|
261 { |
|
262 case ( EDMProfileDisplayName ) : |
|
263 { |
|
264 result = iDisplayName; |
|
265 } |
|
266 break; |
|
267 |
|
268 case ( EDMProfileServerUsername ) : |
|
269 { |
|
270 result = iDMServerUsername; |
|
271 } |
|
272 break; |
|
273 |
|
274 case ( EDMProfileServerPassword ) : |
|
275 { |
|
276 result = iDMServerPassword; |
|
277 } |
|
278 break; |
|
279 |
|
280 case ( EDMProfileClientPassword ) : |
|
281 { |
|
282 result = iClientPassword; |
|
283 } |
|
284 break; |
|
285 |
|
286 case ( EDMProfileServerURL ) : |
|
287 { |
|
288 result = iServerURL; |
|
289 } |
|
290 break; |
|
291 |
|
292 case ( EDMProfileServerId ) : |
|
293 { |
|
294 result = iServerId; |
|
295 } |
|
296 break; |
|
297 |
|
298 case ( EDMProfileHttpAuthUsername ) : |
|
299 { |
|
300 result = iHttpAuthUsername; |
|
301 } |
|
302 break; |
|
303 |
|
304 case ( EDMProfileHttpAuthPassword ) : |
|
305 { |
|
306 result = iHttpAuthPassword; |
|
307 } |
|
308 break; |
|
309 |
|
310 default: |
|
311 { |
|
312 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
313 } |
|
314 } |
|
315 return *result; |
|
316 } |
|
317 |
|
318 //------------------------------------------------------------------------------ |
|
319 // CNSmlDMProfile::IntValue() |
|
320 // Returns a given int value. |
|
321 //------------------------------------------------------------------------------ |
|
322 |
|
323 EXPORT_C TInt CNSmlDMProfile::IntValue( TNSmlDMProfileData aProfileItem ) const |
|
324 { |
|
325 TInt result( 0 ); |
|
326 switch ( aProfileItem ) |
|
327 { |
|
328 case ( EDMProfileId ) : |
|
329 { |
|
330 result = iId; |
|
331 } |
|
332 break; |
|
333 |
|
334 case ( EDMProfileIAPId ) : |
|
335 { |
|
336 result = iIAPId; |
|
337 } |
|
338 break; |
|
339 |
|
340 case ( EDMProfileTransportId ) : |
|
341 { |
|
342 result = iTransportId; |
|
343 } |
|
344 break; |
|
345 |
|
346 case ( EDMProfileSessionId ) : |
|
347 { |
|
348 result = iDMSessionId; |
|
349 } |
|
350 break; |
|
351 |
|
352 case ( EDMProfileServerAlertAction ) : |
|
353 { |
|
354 result = iServerAlertAction; |
|
355 } |
|
356 break; |
|
357 |
|
358 case ( EDMProfileAuthenticationRequired ) : |
|
359 { |
|
360 result = iAuthenticationRequired; |
|
361 } |
|
362 break; |
|
363 |
|
364 case ( EDMProfileCreatorId ) : |
|
365 { |
|
366 result = iCreatorId; |
|
367 } |
|
368 break; |
|
369 |
|
370 case ( EDMProfileDeleteAllowed ) : |
|
371 { |
|
372 result = iDeleteAllowed; |
|
373 } |
|
374 break; |
|
375 |
|
376 case ( EDMProfileHttpAuthUsed ) : |
|
377 { |
|
378 result = iHttpAuthUsed; |
|
379 } |
|
380 break; |
|
381 |
|
382 case ( EDMProfileHidden ) : |
|
383 { |
|
384 result = iProfileHidden; |
|
385 } |
|
386 break; |
|
387 case EDMProfileLock : |
|
388 { |
|
389 result = iProfileLock; |
|
390 } |
|
391 break; |
|
392 default: |
|
393 { |
|
394 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
395 } |
|
396 } |
|
397 return result; |
|
398 } |
|
399 |
|
400 //------------------------------------------------------------------------------ |
|
401 // CNSmlDMProfile::SetStrValue() |
|
402 // Sets a given string value. |
|
403 //------------------------------------------------------------------------------ |
|
404 |
|
405 EXPORT_C void CNSmlDMProfile::SetStrValue( TNSmlDMProfileData aProfileItem, const TDesC& aNewValue ) |
|
406 { |
|
407 switch ( aProfileItem ) |
|
408 { |
|
409 case ( EDMProfileDisplayName ) : |
|
410 { |
|
411 *iDisplayName = aNewValue; |
|
412 } |
|
413 break; |
|
414 |
|
415 case ( EDMProfileServerUsername ) : |
|
416 { |
|
417 *iDMServerUsername = aNewValue; |
|
418 } |
|
419 break; |
|
420 |
|
421 case ( EDMProfileServerPassword ) : |
|
422 { |
|
423 *iDMServerPassword = aNewValue; |
|
424 } |
|
425 break; |
|
426 |
|
427 case ( EDMProfileClientPassword ) : |
|
428 { |
|
429 *iClientPassword = aNewValue; |
|
430 } |
|
431 break; |
|
432 |
|
433 case ( EDMProfileServerURL ) : |
|
434 { |
|
435 *iServerURL = aNewValue; |
|
436 } |
|
437 break; |
|
438 |
|
439 case ( EDMProfileServerId ) : |
|
440 { |
|
441 *iServerId = aNewValue; |
|
442 } |
|
443 break; |
|
444 |
|
445 case ( EDMProfileHttpAuthUsername ) : |
|
446 { |
|
447 *iHttpAuthUsername = aNewValue; |
|
448 } |
|
449 break; |
|
450 |
|
451 case ( EDMProfileHttpAuthPassword ) : |
|
452 { |
|
453 *iHttpAuthPassword = aNewValue; |
|
454 } |
|
455 break; |
|
456 |
|
457 default: |
|
458 { |
|
459 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
460 } |
|
461 } |
|
462 } |
|
463 |
|
464 //------------------------------------------------------------------------------ |
|
465 // CNSmlDMProfile::SetIntValue() |
|
466 // Sets a given int value. |
|
467 //------------------------------------------------------------------------------ |
|
468 |
|
469 EXPORT_C void CNSmlDMProfile::SetIntValue( TNSmlDMProfileData aProfileItem, const TInt aNewValue ) |
|
470 { |
|
471 switch ( aProfileItem ) |
|
472 { |
|
473 case ( EDMProfileId ) : |
|
474 { |
|
475 iId = aNewValue; |
|
476 } |
|
477 break; |
|
478 |
|
479 case ( EDMProfileIAPId ) : |
|
480 { |
|
481 iIAPId = aNewValue; |
|
482 } |
|
483 break; |
|
484 |
|
485 case ( EDMProfileTransportId ) : |
|
486 { |
|
487 iTransportId = aNewValue; |
|
488 } |
|
489 break; |
|
490 |
|
491 case ( EDMProfileSessionId ) : |
|
492 { |
|
493 iDMSessionId = aNewValue; |
|
494 } |
|
495 break; |
|
496 |
|
497 case ( EDMProfileServerAlertAction ) : |
|
498 { |
|
499 iServerAlertAction = aNewValue; |
|
500 } |
|
501 break; |
|
502 |
|
503 case ( EDMProfileAuthenticationRequired ) : |
|
504 { |
|
505 iAuthenticationRequired = aNewValue; |
|
506 } |
|
507 break; |
|
508 |
|
509 case ( EDMProfileCreatorId ) : |
|
510 { |
|
511 iCreatorId = aNewValue; |
|
512 } |
|
513 break; |
|
514 |
|
515 case ( EDMProfileDeleteAllowed ) : |
|
516 { |
|
517 iDeleteAllowed = aNewValue; |
|
518 } |
|
519 break; |
|
520 case ( EDMProfileHidden ) : |
|
521 { |
|
522 iProfileHidden = aNewValue; |
|
523 } |
|
524 break; |
|
525 |
|
526 case ( EDMProfileHttpAuthUsed ) : |
|
527 { |
|
528 iHttpAuthUsed = aNewValue; |
|
529 } |
|
530 break; |
|
531 case ( EDMProfileLock ) : |
|
532 { |
|
533 iProfileLock = aNewValue; |
|
534 } |
|
535 break; |
|
536 default: |
|
537 { |
|
538 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
539 } |
|
540 } |
|
541 } |
|
542 |
|
543 //------------------------------------------------------------------------------ |
|
544 // CNSmlDMProfile::EqualData() |
|
545 // Compares all this profile data to |
|
546 // given profiles's data. |
|
547 //------------------------------------------------------------------------------ |
|
548 |
|
549 EXPORT_C TBool CNSmlDMProfile::EqualData( CNSmlDMProfile* aprofile ) const |
|
550 { |
|
551 if ( aprofile == NULL ) |
|
552 { |
|
553 return EFalse; |
|
554 } |
|
555 |
|
556 if ( *iDisplayName != *aprofile->iDisplayName ) |
|
557 { |
|
558 return EFalse; |
|
559 } |
|
560 |
|
561 if ( iTransportId != aprofile->iTransportId) |
|
562 { |
|
563 return EFalse; |
|
564 } |
|
565 |
|
566 if ( iIAPId != aprofile->iIAPId ) |
|
567 { |
|
568 return EFalse; |
|
569 } |
|
570 |
|
571 if ( *iClientPassword != *aprofile->iClientPassword ) |
|
572 { |
|
573 return EFalse; |
|
574 } |
|
575 |
|
576 if ( *iServerURL != *aprofile->iServerURL ) |
|
577 { |
|
578 return EFalse; |
|
579 } |
|
580 |
|
581 if ( *iServerId != *aprofile->iServerId ) |
|
582 { |
|
583 return EFalse; |
|
584 } |
|
585 |
|
586 if ( iDMSessionId != aprofile->iDMSessionId ) |
|
587 { |
|
588 return EFalse; |
|
589 } |
|
590 |
|
591 if ( iServerAlertAction != aprofile->iServerAlertAction ) |
|
592 { |
|
593 return EFalse; |
|
594 } |
|
595 |
|
596 if ( iAuthenticationRequired != aprofile->iAuthenticationRequired ) |
|
597 { |
|
598 return EFalse; |
|
599 } |
|
600 |
|
601 if ( iCreatorId != aprofile->iCreatorId) |
|
602 { |
|
603 return EFalse; |
|
604 } |
|
605 |
|
606 if ( iDeleteAllowed != aprofile->iDeleteAllowed ) |
|
607 { |
|
608 return EFalse; |
|
609 } |
|
610 |
|
611 if ( iHttpAuthUsed != aprofile->iHttpAuthUsed) |
|
612 { |
|
613 return EFalse; |
|
614 } |
|
615 |
|
616 if ( *iHttpAuthUsername != *aprofile->iHttpAuthUsername ) |
|
617 { |
|
618 return EFalse; |
|
619 } |
|
620 |
|
621 if ( *iHttpAuthPassword != *aprofile->iHttpAuthPassword ) |
|
622 { |
|
623 return EFalse; |
|
624 } |
|
625 if ( iProfileLock != aprofile->iProfileLock ) |
|
626 { |
|
627 return EFalse; |
|
628 } |
|
629 |
|
630 return ETrue; |
|
631 } |
|
632 |
|
633 //------------------------------------------------------------------------------ |
|
634 // CNSmlDMProfile::IsNullL() |
|
635 // Returns true if profile data is NULL, |
|
636 // otherwise false. |
|
637 //------------------------------------------------------------------------------ |
|
638 |
|
639 EXPORT_C TBool CNSmlDMProfile::IsNullL( const TDesC& aFieldName ) |
|
640 { |
|
641 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
642 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
643 |
|
644 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
645 |
|
646 PrepareViewL( sqlStatementPtr, iView.EReadOnly ); |
|
647 |
|
648 CleanupStack::PopAndDestroy(); // sqlStatement |
|
649 |
|
650 if ( iView.FirstL() ) |
|
651 { |
|
652 iView.GetL(); |
|
653 if ( iView.IsColNull( iColSetProfiles->ColNo( aFieldName ) ) ) |
|
654 { |
|
655 return ETrue; |
|
656 } |
|
657 } |
|
658 return EFalse; |
|
659 } |
|
660 |
|
661 //------------------------------------------------------------------------------ |
|
662 // CNSmlDMProfile::HasLogL() |
|
663 // Returns true if profile has Log-data, |
|
664 // otherwise false. |
|
665 //------------------------------------------------------------------------------ |
|
666 EXPORT_C TBool CNSmlDMProfile::HasLogL() |
|
667 { |
|
668 _DBG_FILE("CNSmlDMProfile::HasLogL(): begin"); |
|
669 |
|
670 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
671 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
672 |
|
673 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
674 |
|
675 PrepareViewL( sqlStatementPtr, iView.EReadOnly ); |
|
676 |
|
677 CleanupStack::PopAndDestroy(); // sqlStatement |
|
678 |
|
679 if ( iView.FirstL() ) |
|
680 { |
|
681 iView.GetL(); |
|
682 if ( iView.IsColNull( iColSetProfiles->ColNo( KNSmlDMProfileLog ) ) ) |
|
683 { |
|
684 return EFalse; |
|
685 } |
|
686 } |
|
687 |
|
688 _DBG_FILE("CNSmlDMProfile::HasLogL(): end"); |
|
689 |
|
690 return ETrue; |
|
691 } |
|
692 |
|
693 //------------------------------------------------------------------------------ |
|
694 // CNSmlDMProfile::HasLastSyncL() |
|
695 // Returns true if profile has Last sync data, |
|
696 // otherwise false. |
|
697 //------------------------------------------------------------------------------ |
|
698 EXPORT_C TBool CNSmlDMProfile::HasLastSyncL() |
|
699 { |
|
700 _DBG_FILE("CNSmlDMProfile::HasLogL(): begin"); |
|
701 |
|
702 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
703 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
704 |
|
705 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
706 |
|
707 PrepareViewL( sqlStatementPtr, iView.EReadOnly ); |
|
708 |
|
709 CleanupStack::PopAndDestroy(); // sqlStatement |
|
710 |
|
711 if ( iView.FirstL() ) |
|
712 { |
|
713 iView.GetL(); |
|
714 if ( iView.IsColNull( iColSetProfiles->ColNo( KNSmlDMLastSync ) ) ) |
|
715 { |
|
716 return EFalse; |
|
717 } |
|
718 } |
|
719 |
|
720 _DBG_FILE("CNSmlDMProfile::HasLogL(): end"); |
|
721 |
|
722 return ETrue; |
|
723 } |
|
724 |
|
725 //------------------------------------------------------------------------------ |
|
726 // CNSmlDMProfile::LogReadStreamL() |
|
727 // Reads log-data from database |
|
728 //------------------------------------------------------------------------------ |
|
729 EXPORT_C RReadStream& CNSmlDMProfile::LogReadStreamL() |
|
730 { |
|
731 _DBG_FILE("CNSmlDMProfile::LogReadStreamL(): begin"); |
|
732 |
|
733 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
734 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
735 |
|
736 sqlStatementPtr.Format(KDMSQLGetProfile, iId); |
|
737 |
|
738 User::LeaveIfError(iRSView.Prepare(*iDatabase, TDbQuery(sqlStatementPtr), RDbRowSet::EReadOnly)); |
|
739 User::LeaveIfError(iRSView.EvaluateAll()); |
|
740 |
|
741 CleanupStack::PopAndDestroy(); // sqlStatement |
|
742 |
|
743 // Get the structure of rowset |
|
744 CDbColSet* colSet = iRSView.ColSetL(); |
|
745 TDbColNo col = colSet->ColNo(KNSmlDMProfileLog()); // Ordinal position of long column |
|
746 delete colSet; |
|
747 colSet = NULL; |
|
748 |
|
749 // get row |
|
750 if( iRSView.FirstL() ) |
|
751 { |
|
752 iRSView.GetL(); |
|
753 iRs.OpenL(iRSView, col); |
|
754 } |
|
755 |
|
756 _DBG_FILE("CNSmlDMProfile::LogReadStreamL(): end"); |
|
757 |
|
758 return iRs; |
|
759 } |
|
760 |
|
761 //------------------------------------------------------------------------------ |
|
762 // CNSmlDMProfile::LogWriteStreamL() |
|
763 // Opens stream to database for writing |
|
764 //------------------------------------------------------------------------------ |
|
765 |
|
766 EXPORT_C RWriteStream& CNSmlDMProfile::LogWriteStreamL() |
|
767 { |
|
768 _DBG_FILE("CNSmlDMProfile::LogWriteStreamL(): begin"); |
|
769 |
|
770 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
771 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
772 |
|
773 sqlStatementPtr.Format(KDMSQLGetProfile, iId); |
|
774 |
|
775 // create a view on the database |
|
776 User::LeaveIfError(iWSView.Prepare(*iDatabase, TDbQuery(sqlStatementPtr), RDbRowSet::EUpdatable)); |
|
777 User::LeaveIfError(iWSView.EvaluateAll()); |
|
778 |
|
779 CleanupStack::PopAndDestroy(); // sqlStatement |
|
780 |
|
781 // Get the structure of rowset |
|
782 CDbColSet* colSet = iWSView.ColSetL(); |
|
783 TDbColNo col = colSet->ColNo(KNSmlDMProfileLog()); // Ordinal position of long column |
|
784 delete colSet; |
|
785 colSet = NULL; |
|
786 |
|
787 // get row |
|
788 iDatabase->Begin(); |
|
789 if( iWSView.FirstL() ) |
|
790 { |
|
791 iWSView.GetL(); |
|
792 iWSView.UpdateL(); |
|
793 iWs.OpenL(iWSView, col); |
|
794 } |
|
795 |
|
796 _DBG_FILE("CNSmlDMProfile::LogWriteStreamL(): end"); |
|
797 |
|
798 return iWs; |
|
799 } |
|
800 |
|
801 //------------------------------------------------------------------------------ |
|
802 // CNSmlDMProfile::WriteStreamCommitL() |
|
803 // |
|
804 // |
|
805 //------------------------------------------------------------------------------ |
|
806 EXPORT_C void CNSmlDMProfile::WriteStreamCommitL() |
|
807 { |
|
808 _DBG_FILE("CNSmlDMProfile::WriteStreamCommitL(): begin"); |
|
809 |
|
810 iWSView.PutL(); |
|
811 iWSView.Close(); |
|
812 CommitAndCompact(); |
|
813 |
|
814 _DBG_FILE("CNSmlDMProfile::WriteStreamCommitL(): end"); |
|
815 } |
|
816 |
|
817 |
|
818 //------------------------------------------------------------------------------ |
|
819 // CNSmlDMProfile::LastSyncReadStreamL() |
|
820 // Reads last sync-data from database |
|
821 //------------------------------------------------------------------------------ |
|
822 EXPORT_C RReadStream& CNSmlDMProfile::LastSyncReadStreamL() |
|
823 { |
|
824 _DBG_FILE("CNSmlDMProfile::LastSyncReadStreamL(): begin"); |
|
825 |
|
826 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
827 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
828 |
|
829 sqlStatementPtr.Format(KDMSQLGetProfile, iId); |
|
830 |
|
831 User::LeaveIfError(iRSView.Prepare(*iDatabase, TDbQuery(sqlStatementPtr), RDbRowSet::EReadOnly)); |
|
832 User::LeaveIfError(iRSView.EvaluateAll()); |
|
833 |
|
834 CleanupStack::PopAndDestroy(); // sqlStatement |
|
835 |
|
836 // Get the structure of rowset |
|
837 CDbColSet* colSet = iRSView.ColSetL(); |
|
838 TDbColNo col = colSet->ColNo(KNSmlDMLastSync()); // Ordinal position of long column |
|
839 delete colSet; |
|
840 colSet = NULL; |
|
841 |
|
842 // get row |
|
843 if( iRSView.FirstL() ) |
|
844 { |
|
845 iRSView.GetL(); |
|
846 iRs.OpenL(iRSView, col); |
|
847 } |
|
848 |
|
849 _DBG_FILE("CNSmlDMProfile::LastSyncReadStreamL(): end"); |
|
850 |
|
851 return iRs; |
|
852 } |
|
853 |
|
854 //------------------------------------------------------------------------------ |
|
855 // CNSmlDMProfile::LastSyncWriteStreamL() |
|
856 // writes last sync-data to database |
|
857 //------------------------------------------------------------------------------ |
|
858 EXPORT_C RWriteStream& CNSmlDMProfile::LastSyncWriteStreamL() |
|
859 { |
|
860 _DBG_FILE("CNSmlDMProfile::LastSyncWriteStreamL(): begin"); |
|
861 |
|
862 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
863 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
864 |
|
865 sqlStatementPtr.Format(KDMSQLGetProfile, iId); |
|
866 |
|
867 // create a view on the database |
|
868 User::LeaveIfError(iWSView.Prepare(*iDatabase, TDbQuery(sqlStatementPtr), RDbRowSet::EUpdatable)); |
|
869 User::LeaveIfError(iWSView.EvaluateAll()); |
|
870 |
|
871 CleanupStack::PopAndDestroy(); // sqlStatement |
|
872 |
|
873 // Get the structure of rowset |
|
874 CDbColSet* colSet = iWSView.ColSetL(); |
|
875 TDbColNo col = colSet->ColNo(KNSmlDMLastSync()); // Ordinal position of long column |
|
876 delete colSet; |
|
877 colSet = NULL; |
|
878 |
|
879 // get row |
|
880 iDatabase->Begin(); |
|
881 if( iWSView.FirstL() ) |
|
882 { |
|
883 iWSView.GetL(); |
|
884 iWSView.UpdateL(); |
|
885 iWs.OpenL(iWSView, col); |
|
886 } |
|
887 |
|
888 _DBG_FILE("CNSmlDMProfile::LastSyncWriteStreamL(): end"); |
|
889 |
|
890 return iWs; |
|
891 |
|
892 } |
|
893 |
|
894 //------------------------------------------------------------------------------ |
|
895 // CNSmlDMProfile::LastSyncStreamCommitL() |
|
896 |
|
897 //------------------------------------------------------------------------------ |
|
898 EXPORT_C void CNSmlDMProfile::LastSyncStreamCommitL() |
|
899 { |
|
900 _DBG_FILE("CNSmlDMProfile::LastSyncStreamCommitL(): begin"); |
|
901 |
|
902 iWSView.PutL(); |
|
903 iWSView.Close(); |
|
904 CommitAndCompact(); |
|
905 |
|
906 _DBG_FILE("CNSmlDMProfile::LastSyncStreamCommitL(): end"); |
|
907 } |
|
908 |
|
909 //------------------------------------------------------------------------------ |
|
910 // CNSmlDMProfile::PrepareViewL() |
|
911 // Closes and prepares the view |
|
912 // |
|
913 //------------------------------------------------------------------------------ |
|
914 void CNSmlDMProfile::PrepareViewL( const TDesC& aSql, RDbRowSet::TAccess aAccess ) |
|
915 { |
|
916 iView.Close(); |
|
917 User::LeaveIfError( iView.Prepare( *iDatabase, TDbQuery( aSql ), aAccess ) ); |
|
918 } |
|
919 |
|
920 //------------------------------------------------------------------------------ |
|
921 // CNSmlDMProfile::CommitAndCompact |
|
922 // Commits update and compacts the database |
|
923 // |
|
924 //------------------------------------------------------------------------------ |
|
925 void CNSmlDMProfile::CommitAndCompact() |
|
926 { |
|
927 iDatabase->Commit(); |
|
928 iDatabase->Compact(); |
|
929 } |
|
930 |
|
931 //------------------------------------------------------------------------------ |
|
932 // CNSmlDMProfile::TableProfilesSetColIntL |
|
933 // |
|
934 // |
|
935 //------------------------------------------------------------------------------ |
|
936 void CNSmlDMProfile::TableProfilesSetColIntL( const TDesC& aFieldName, TInt aValue) |
|
937 { |
|
938 iTableProfiles.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue ); |
|
939 } |
|
940 |
|
941 //------------------------------------------------------------------------------ |
|
942 // CNSmlDMProfile::TableProfilesSetColDesL |
|
943 // |
|
944 // |
|
945 //------------------------------------------------------------------------------ |
|
946 void CNSmlDMProfile::TableProfilesSetColDesL( const TDesC& aFieldName, TDesC& aValue) |
|
947 { |
|
948 iTableProfiles.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue ); |
|
949 } |
|
950 |
|
951 //------------------------------------------------------------------------------ |
|
952 // CNSmlDMProfile::ViewSetColIntL |
|
953 // |
|
954 // |
|
955 //------------------------------------------------------------------------------ |
|
956 void CNSmlDMProfile::ViewSetColIntL( const TDesC& aFieldName, TInt aValue) |
|
957 { |
|
958 iView.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue ); |
|
959 } |
|
960 |
|
961 //------------------------------------------------------------------------------ |
|
962 // CNSmlDMProfile::ViewSetColDesL |
|
963 // |
|
964 // |
|
965 //------------------------------------------------------------------------------ |
|
966 void CNSmlDMProfile::ViewSetColDesL( const TDesC& aFieldName, TDesC& aValue) |
|
967 { |
|
968 iView.SetColL( iColSetProfiles->ColNo( aFieldName ), aValue ); |
|
969 } |
|
970 |
|
971 //------------------------------------------------------------------------------ |
|
972 // CNSmlDMProfile::NonceLC() |
|
973 // Gets nonce. |
|
974 // If length of the returned string is 0, |
|
975 // nonce was not found. |
|
976 //------------------------------------------------------------------------------ |
|
977 |
|
978 EXPORT_C HBufC* CNSmlDMProfile::NonceLC( TNSmlDMProfileData aProfileItem) |
|
979 { |
|
980 _DBG_FILE("CNSmlDMProfile::NonceLC(): begin"); |
|
981 |
|
982 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + KNSmlDmMaxIntegerLength ); |
|
983 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
984 |
|
985 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
986 |
|
987 CNSmlDMProfile::PrepareViewL( sqlStatementPtr, iView.EReadOnly ); |
|
988 |
|
989 CleanupStack::PopAndDestroy(); // sqlStatement |
|
990 |
|
991 if(iView.Unevaluated()) |
|
992 { |
|
993 iView.EvaluateAll(); |
|
994 } |
|
995 |
|
996 HBufC* stringValue = NULL; |
|
997 |
|
998 if ( iView.FirstL() ) |
|
999 { |
|
1000 iView.GetL(); |
|
1001 |
|
1002 switch ( aProfileItem ) |
|
1003 { |
|
1004 case ( EDMProfileServerNonce ) : |
|
1005 { |
|
1006 RDbColReadStream in; |
|
1007 in.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ) ); |
|
1008 stringValue = HBufC::NewLC( iView.ColLength( iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ) ) ); |
|
1009 TPtr ptr = stringValue->Des(); |
|
1010 in.ReadL( ptr, iView.ColLength( iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ) ) ); |
|
1011 CleanupStack::Pop(); // stringValue |
|
1012 CleanupStack::PopAndDestroy(); //in |
|
1013 } |
|
1014 break; |
|
1015 |
|
1016 case ( EDMProfileClientNonce ) : |
|
1017 { |
|
1018 RDbColReadStream in; |
|
1019 in.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileClientNonce ) ); |
|
1020 stringValue = HBufC::NewLC( iView.ColLength( iColSetProfiles->ColNo( KNSmlDMProfileClientNonce ) ) ); |
|
1021 TPtr ptr = stringValue->Des(); |
|
1022 in.ReadL( ptr, iView.ColLength( iColSetProfiles->ColNo( KNSmlDMProfileClientNonce ) ) ); |
|
1023 CleanupStack::Pop(); // stringValue |
|
1024 CleanupStack::PopAndDestroy(); //in |
|
1025 } |
|
1026 break; |
|
1027 |
|
1028 default: |
|
1029 { |
|
1030 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
1031 } |
|
1032 } |
|
1033 |
|
1034 } |
|
1035 _DBG_FILE("CNSmlDMProfile::NonceLC(): end"); |
|
1036 |
|
1037 CleanupStack::PushL( stringValue ); |
|
1038 return stringValue; |
|
1039 } |
|
1040 |
|
1041 //------------------------------------------------------------------------------ |
|
1042 // CNSmlDMProfile::SetNonceL() |
|
1043 // Sets nonce. |
|
1044 //------------------------------------------------------------------------------ |
|
1045 |
|
1046 EXPORT_C void CNSmlDMProfile::SetNonceL( TNSmlDMProfileData aProfileItem, const TDesC& aNewValue ) |
|
1047 { |
|
1048 |
|
1049 _DBG_FILE("CNSmlDMProfile::SetNonceL begins"); |
|
1050 |
|
1051 HBufC* sqlStatement = HBufC::NewLC( KDMSQLGetProfile().Length() + 16 ); |
|
1052 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1053 |
|
1054 sqlStatementPtr.Format( KDMSQLGetProfile, iId ); |
|
1055 |
|
1056 PrepareViewL( sqlStatementPtr, iView.EUpdatable ); |
|
1057 |
|
1058 CleanupStack::PopAndDestroy(); // sqlStatement |
|
1059 |
|
1060 iDatabase->Begin(); |
|
1061 RDbColWriteStream out; |
|
1062 if ( iView.FirstL() ) |
|
1063 { |
|
1064 //existing row |
|
1065 iView.GetL(); |
|
1066 iView.UpdateL(); |
|
1067 switch ( aProfileItem ) |
|
1068 { |
|
1069 case ( EDMProfileServerNonce ) : |
|
1070 { |
|
1071 out.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ) ); |
|
1072 break; |
|
1073 } |
|
1074 case ( EDMProfileClientNonce ) : |
|
1075 { |
|
1076 out.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileClientNonce ) ); |
|
1077 break; |
|
1078 } |
|
1079 default: |
|
1080 { |
|
1081 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
1082 } |
|
1083 } |
|
1084 out.WriteL( aNewValue ); |
|
1085 out.Close(); |
|
1086 iView.PutL(); |
|
1087 } |
|
1088 else |
|
1089 { |
|
1090 //new row |
|
1091 PrepareViewL( KDMSQLGetProfile, iView.EUpdatable ); |
|
1092 iView.InsertL(); |
|
1093 switch ( aProfileItem ) |
|
1094 { |
|
1095 case ( EDMProfileServerNonce ) : |
|
1096 { |
|
1097 out.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ) ); |
|
1098 break; |
|
1099 } |
|
1100 case ( EDMProfileClientNonce ) : |
|
1101 { |
|
1102 out.OpenLC( iView, iColSetProfiles->ColNo( KNSmlDMProfileClientNonce ) ); |
|
1103 break; |
|
1104 } |
|
1105 default: |
|
1106 { |
|
1107 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
1108 } |
|
1109 } |
|
1110 out.WriteL( aNewValue ); |
|
1111 out.Close(); |
|
1112 iView.SetColL( iColSetProfiles->ColNo( KNSmlDMProfileServerNonce ), aNewValue ); |
|
1113 iView.PutL(); |
|
1114 } |
|
1115 |
|
1116 CommitAndCompact(); |
|
1117 CleanupStack::PopAndDestroy(); // out |
|
1118 |
|
1119 _DBG_FILE("CNSmlDMProfile::SetNonceL ends"); |
|
1120 |
|
1121 } |
|
1122 |
|
1123 //------------------------------------------------------------------------------ |
|
1124 // CNSmlDMProfile::ResetDatabaseL() |
|
1125 // |
|
1126 //------------------------------------------------------------------------------ |
|
1127 |
|
1128 |
|
1129 void CNSmlDMProfile::ResetDatabaseL( RDbNamedDatabase* aDatabase ) |
|
1130 { |
|
1131 iDatabase=aDatabase; |
|
1132 User::LeaveIfError( iTableProfiles.Open( *iDatabase, KNSmlDMTableProfiles ) ); |
|
1133 iColSetProfiles = iTableProfiles.ColSetL(); |
|
1134 } |
|
1135 |
|
1136 //------------------------------------------------------------------------------ |
|
1137 // CNSmlDMProfile::ResetID() |
|
1138 // |
|
1139 //------------------------------------------------------------------------------ |
|
1140 |
|
1141 void CNSmlDMProfile::ResetID() |
|
1142 { |
|
1143 iId = ( TUint ) KNSmlNewObject; |
|
1144 } |
|
1145 |
|
1146 //------------------------------------------------------------------------------ |
|
1147 // CNSmlDMProfile::CloseDbHandles() |
|
1148 // |
|
1149 //------------------------------------------------------------------------------ |
|
1150 void CNSmlDMProfile::CloseDbHandles() |
|
1151 { |
|
1152 if(iColSetProfiles) |
|
1153 { |
|
1154 delete iColSetProfiles; |
|
1155 } |
|
1156 iColSetProfiles = NULL; |
|
1157 iTableProfiles.Close(); |
|
1158 |
|
1159 } |
|
1160 // End of File |