|
1 /* |
|
2 * Copyright (c) 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: AgentLog db-interface |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include <sysutil.h> |
|
22 #include <bautils.h> |
|
23 #include <utf.h> |
|
24 #include <nsmlconstants.h> |
|
25 #include <nsmldebug.h> |
|
26 |
|
27 #include "nsmldbcaps.h" |
|
28 #include "nsmldsdefines.h" |
|
29 #include "nsmlagentlog.h" |
|
30 #include "smldevinfdtd.h" |
|
31 |
|
32 |
|
33 // CONSTANTS |
|
34 |
|
35 // Size of empty AgentLog database in bytes. |
|
36 const TInt KNSmlAgentLogEmptyDatabaseSize = 580; |
|
37 // Estimated maximum size of AgentLog table row without the unrestricted |
|
38 // ServerDeviceInfo and ServerFilterInfo fields. |
|
39 const TInt KNSmlAgentLogMaxFixedLogRowSize = 860; |
|
40 // Maximum size of Authentication table row without unrestricted Nonce field. |
|
41 const TInt KNSmlAgentLogMaxFixedAuthRowSize = 320; |
|
42 // Additional treshold used with OOD checks. |
|
43 const TInt KNSmlAgentLogTreshold = 50; |
|
44 |
|
45 _LIT8( KTabSeparator, " "); |
|
46 |
|
47 //============================================= |
|
48 // |
|
49 // CNSmlDSAgentLog |
|
50 // |
|
51 //============================================= |
|
52 |
|
53 //============================================= |
|
54 // CNSmlDSAgentLog::NewL() |
|
55 // Creates a new instance of CNSmlDSAgentLog object. |
|
56 //============================================= |
|
57 |
|
58 EXPORT_C CNSmlDSAgentLog* CNSmlDSAgentLog::NewL() |
|
59 { |
|
60 DBG_FILE(_S8("CNSmlDSAgentLog::NewL")); |
|
61 CNSmlDSAgentLog* self = CNSmlDSAgentLog::NewLC(); |
|
62 CleanupStack::Pop(); |
|
63 return self; |
|
64 } |
|
65 |
|
66 //============================================= |
|
67 // CNSmlDSAgentLog::NewLC() |
|
68 // Creates a new instance of CNSmlDSAgentLog object. |
|
69 // Pushes and leaves new instance into CleanupStack. |
|
70 //============================================= |
|
71 EXPORT_C CNSmlDSAgentLog* CNSmlDSAgentLog::NewLC() |
|
72 { |
|
73 DBG_FILE(_S8("CNSmlDSAgentLog::NewLC")); |
|
74 CNSmlDSAgentLog* self = new ( ELeave ) CNSmlDSAgentLog; |
|
75 CleanupStack::PushL( self ); |
|
76 self->ConstructL(); |
|
77 return self; |
|
78 } |
|
79 |
|
80 //============================================= |
|
81 // CNSmlDSAgentLog::ConstructL() |
|
82 // Second phase constructor. |
|
83 //============================================= |
|
84 |
|
85 void CNSmlDSAgentLog::ConstructL() |
|
86 { |
|
87 DBG_FILE(_S8("CNSmlDSAgentLog::ConstructL(): begin")); |
|
88 iLocalDB = HBufC::NewL( KNSmlMaxStringColumnLength ); |
|
89 iServerId = HBufC::NewL( KNSmlMaxServerIdLength ); |
|
90 iRemoteDB = HBufC::NewL( KNSmlMaxStringColumnLength ); |
|
91 |
|
92 User::LeaveIfError( iFsSession.Connect() ); |
|
93 User::LeaveIfError( iRdbSession.Connect() ); |
|
94 iFsSession.SetSessionToPrivate( KNSmlAgentLogDbDrive ); |
|
95 |
|
96 TParse name; |
|
97 |
|
98 TBool createdDatabase = EFalse; |
|
99 |
|
100 #ifdef SYMBIAN_SECURE_DBMS |
|
101 name.Set( KNSmlAgentLogDbName(), NULL, NULL ); |
|
102 #else |
|
103 name.Set( KNSmlAgentLogDbName(), KNSmlDatabasesNonSecurePath, NULL ); |
|
104 #endif |
|
105 // PP: data compatibility fix: If incompatible database is |
|
106 // found, it will be deleted & recreated. |
|
107 TInt retry0(5); |
|
108 while ( retry0>0 ) |
|
109 { |
|
110 retry0 = retry0 - 1; |
|
111 TInt err = iDatabase.Open( iRdbSession /*iFsSession*/, |
|
112 name.FullName(), |
|
113 KNSmlDBMSSecureSOSServerID ); |
|
114 if (err == KErrNone) |
|
115 { |
|
116 User::LeaveIfError( iTableAgentLog.Open( iDatabase, KNSmlTableAgentLog ) ); |
|
117 iColSet = iTableAgentLog.ColSetL(); |
|
118 |
|
119 //RD_SUSPEND_RESUME |
|
120 if (iColSet->ColNo( KNSmlAgentLogSuspendedState ) == KDbNullColNo |
|
121 || iColSet->ColNo( KNSmlAgentLogPreviousSyncType ) == KDbNullColNo |
|
122 || iColSet->ColNo( KNSmlAgentLogPreviousClientSyncType ) == KDbNullColNo) |
|
123 { |
|
124 iTableAgentLog.Close(); |
|
125 iDatabase.Close(); |
|
126 TInt error = iRdbSession.DeleteDatabase( name.FullName(), KNSmlSOSServerPolicyUID ); |
|
127 if (error == KErrNone) |
|
128 { |
|
129 err = KErrNotFound; |
|
130 } |
|
131 |
|
132 } |
|
133 } |
|
134 |
|
135 if ( err == KErrNotFound ) |
|
136 { |
|
137 CreateDatabaseL( name.FullName() ); |
|
138 User::LeaveIfError( iDatabase.Open( iRdbSession, |
|
139 name.FullName(), |
|
140 KNSmlDBMSSecureSOSServerID ) ); |
|
141 createdDatabase = ETrue; |
|
142 } |
|
143 else |
|
144 { |
|
145 User::LeaveIfError( err ); |
|
146 } |
|
147 |
|
148 if (createdDatabase) |
|
149 { |
|
150 User::LeaveIfError( iTableAgentLog.Open( iDatabase, KNSmlTableAgentLog ) ); |
|
151 iColSet = iTableAgentLog.ColSetL(); |
|
152 } |
|
153 |
|
154 User::LeaveIfError( iTableAuthentication.Open( iDatabase, KNSmlTableAuthentication ) ); |
|
155 iColSetTableAuth = iTableAuthentication.ColSetL(); |
|
156 TInt err2 = iTableDatastore.Open( iDatabase, KNSmlTableDatastore() ); |
|
157 // Table datastore missing => must delete db |
|
158 if ( err2==KErrNotFound ) |
|
159 { |
|
160 delete iColSetTableDS; |
|
161 iColSetTableDS = NULL; |
|
162 delete iColSetTableAuth; |
|
163 iColSetTableAuth = NULL; |
|
164 iTableAgentLog.Close(); |
|
165 iTableAuthentication.Close(); |
|
166 User::LeaveIfError(iDatabase.Destroy()); |
|
167 } |
|
168 else |
|
169 { |
|
170 retry0=0; |
|
171 User::LeaveIfError( err2 ); |
|
172 } |
|
173 } |
|
174 iColSetTableDS = iTableDatastore.ColSetL(); |
|
175 |
|
176 DBG_FILE(_S8("CNSmlDSAgentLog::ConstructL(): end")); |
|
177 } |
|
178 |
|
179 //============================================= |
|
180 // CNSmlDSAgentLog::~CNSmlDSAgentLog() |
|
181 // Destructor. |
|
182 //============================================= |
|
183 |
|
184 CNSmlDSAgentLog::~CNSmlDSAgentLog() |
|
185 { |
|
186 DBG_FILE(_S8("CNSmlDSAgentLog::~CNSmlDSAgentLog begins")); |
|
187 |
|
188 delete iLocalDB; |
|
189 delete iServerId; |
|
190 delete iRemoteDB; |
|
191 |
|
192 iView.Close(); |
|
193 delete iColSet; |
|
194 iTableAgentLog.Close(); |
|
195 |
|
196 // <MAPINFO_RESEND_MOD_BEGIN> |
|
197 delete iColSetTableDS; |
|
198 iTableDatastore.Close(); |
|
199 // <MAPINFO_RESEND_MOD_END> |
|
200 |
|
201 delete iColSetTableAuth; |
|
202 iTableAuthentication.Close(); |
|
203 |
|
204 iDatabase.Close(); |
|
205 iFsSession.Close(); |
|
206 iRdbSession.Close(); |
|
207 |
|
208 DBG_FILE(_S8("CNSmlDSAgentLog::~CNSmlDSAgentLog ends")); |
|
209 } |
|
210 |
|
211 //============================================= |
|
212 // CNSmlDSAgentLog::CreateDatabaseL() |
|
213 // Creates Agent Log database. |
|
214 //============================================= |
|
215 |
|
216 void CNSmlDSAgentLog::CreateDatabaseL(const TDesC& aFullName) |
|
217 { |
|
218 DBG_FILE(_S8("CNSmlDSAgentLog::CreateDatabaseL begins")); |
|
219 |
|
220 // Check OOD before crating new AgentLog database |
|
221 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
222 KNSmlAgentLogEmptyDatabaseSize + KNSmlAgentLogTreshold ) ) |
|
223 { |
|
224 User::Leave( KErrDiskFull ); |
|
225 } |
|
226 |
|
227 _LIT( KCreateAgentLogTable, "CREATE TABLE AgentLog ( Id INTEGER NOT NULL, \ |
|
228 ImplementationUID INTEGER NOT NULL, LocalDatabase CHAR(%d) NOT NULL, \ |
|
229 ServerId CHAR(%d), RemoteDatabase CHAR(%d) NOT NULL, \ |
|
230 LastSyncronised TIMESTAMP, SyncAnchor TIMESTAMP, SlowSyncRequest INTEGER, \ |
|
231 ServerDeviceInfo LONG VARCHAR, ServerSupportsNOC BIT, ServerSyncTypes INTEGER, \ |
|
232 ServerFilterInfo LONG VARCHAR, ServerSupportsHierarchicalSync BIT ,\ |
|
233 SyncSuspendedState INTEGER,PreviousSyncType INTEGER,\ |
|
234 PreviousClientSyncType INTEGER)" ); |
|
235 |
|
236 //RD_SUSPEND_RESUME- 3 new columns added |
|
237 _LIT( KCreateAuthenticationTable, "CREATE TABLE Authentication ( ServerId \ |
|
238 CHAR(%d), Nonce LONG VARCHAR, Type INTEGER, SessionId INTEGER )" ); |
|
239 |
|
240 // <MAPINFO_RESEND_MOD_BEGIN> |
|
241 _LIT( KCreateDatastoreTable, "CREATE TABLE %S ( %S COUNTER NOT NULL, \ |
|
242 %S INTEGER NOT NULL, %S INTEGER NOT NULL, %S LONG VARBINARY )" ); |
|
243 // <MAPINFO_RESEND_MOD_END> |
|
244 |
|
245 _LIT( KCreateVersionTable, "CREATE TABLE Version ( \ |
|
246 VerMajor UNSIGNED TINYINT, VerMinor UNSIGNED TINYINT )" ); |
|
247 |
|
248 HBufC* createAgentLogTable = HBufC::NewLC( KCreateAgentLogTable().Length() + 20 ); |
|
249 TPtr agentLogTablePtr = createAgentLogTable->Des(); |
|
250 HBufC* createAuthenticationTable = HBufC::NewLC( KCreateAuthenticationTable().Length() + 10); |
|
251 TPtr authenticationTablePtr = createAuthenticationTable->Des(); |
|
252 |
|
253 // <MAPINFO_RESEND_MOD_BEGIN> |
|
254 HBufC* createDatastoreTable = HBufC::NewLC( KCreateDatastoreTable().Length() * 3); |
|
255 TPtr datastoreTablePtr = createDatastoreTable->Des(); |
|
256 // <MAPINFO_RESEND_MOD_END> |
|
257 |
|
258 agentLogTablePtr.Format( KCreateAgentLogTable, KNSmlMaxDataLength, |
|
259 KNSmlMaxServerIdLength, KNSmlMaxRemoteNameLength ); |
|
260 authenticationTablePtr.Format( KCreateAuthenticationTable, KNSmlMaxServerIdLength ); |
|
261 |
|
262 // <MAPINFO_RESEND_MOD_BEGIN> |
|
263 datastoreTablePtr.Format(KCreateDatastoreTable(), &KNSmlTableDatastore(), &KNSmlDatastoreRowID(), &KNSmlDatastoreAgentlogID(), &KNSmlDatastoreStreamID(), &KNSmlDatastoreStreamData()); |
|
264 // <MAPINFO_RESEND_MOD_END> |
|
265 |
|
266 User::LeaveIfError( iDatabase.Create( iRdbSession, |
|
267 aFullName, |
|
268 KNSmlDBMSSecureSOSServerID ) ); |
|
269 iDatabase.Begin(); |
|
270 iDatabase.Execute( *createAgentLogTable ); |
|
271 iDatabase.Execute( *createAuthenticationTable ); |
|
272 // <MAPINFO_RESEND_MOD_BEGIN> |
|
273 iDatabase.Execute( *createDatastoreTable ); |
|
274 // <MAPINFO_RESEND_MOD_END> |
|
275 iDatabase.Execute( KCreateVersionTable() ); |
|
276 |
|
277 RDbTable table; |
|
278 User::LeaveIfError( table.Open( iDatabase, KNSmlTableVersion() ) ); |
|
279 CleanupClosePushL( table ); |
|
280 CDbColSet* colSet = table.ColSetL(); |
|
281 CleanupStack::PushL( colSet ); |
|
282 table.InsertL(); |
|
283 table.SetColL( colSet->ColNo( KNSmlVersionColumnMajor ), KNSmlAgentLogCurrentVersionMajor ); |
|
284 table.SetColL( colSet->ColNo( KNSmlVersionColumnMinor ), KNSmlAgentLogCurrentVersionMinor ); |
|
285 table.PutL(); |
|
286 |
|
287 CommitAndCompact(); |
|
288 iDatabase.Close(); |
|
289 |
|
290 DBG_FILE(_S8("CNSmlDSAgentLog::CreateDatabaseL ends")); |
|
291 // <MAPINFO_RESEND_MOD_BEGIN> |
|
292 CleanupStack::PopAndDestroy( 5 ); // createAgentLogTable, createAuthenticationTable, colset, table |
|
293 //CleanupStack::PopAndDestroy( 4 ); // createAgentLogTable, createAuthenticationTable, colset, table |
|
294 // <MAPINFO_RESEND_MOD_END> |
|
295 } |
|
296 |
|
297 //============================================= |
|
298 // CNSmlDSAgentLog::SetAgentLogKeyL() |
|
299 // Sets AgentLog key with given string values. |
|
300 //============================================= |
|
301 |
|
302 EXPORT_C void CNSmlDSAgentLog::SetAgentLogKeyL( const TInt aImplUid, const TDesC& aLocalDB, const TDesC& aServerId, const TDesC& aRemoteDB ) |
|
303 { |
|
304 DBG_FILE(_S8("CNSmlDSAgentLog::SetAgentLogKeyL begins")); |
|
305 HBufC* sql = HBufC::NewLC( KSQLGetAgentLogRow().Length() + 5 + aLocalDB.Length() + aServerId.Length() ); |
|
306 |
|
307 TPtr sqlPtr = sql->Des(); |
|
308 sqlPtr.Format( KSQLGetAgentLogRow, aImplUid, &aLocalDB, &aServerId ); |
|
309 |
|
310 PrepareViewL( *sql, iView.EReadOnly ); |
|
311 |
|
312 if ( iView.FirstL() ) |
|
313 { |
|
314 for(TInt i = 0; i < iView.CountL() ; i++ ) |
|
315 { |
|
316 iView.GetL(); |
|
317 if( aRemoteDB.CompareF( iView.ColDes16( iColSet->ColNo( KNSmlAgentLogRemoteDatabase ) ) ) == 0 ) |
|
318 { |
|
319 iID = iView.ColInt( iColSet->ColNo( KNSmlAgentLogId ) ); |
|
320 i = iView.CountL() ; // terminates the loop |
|
321 } |
|
322 else |
|
323 { |
|
324 iView.NextL(); |
|
325 } |
|
326 |
|
327 } |
|
328 } |
|
329 else |
|
330 { |
|
331 iID = KNSmlNewObject; |
|
332 } |
|
333 |
|
334 CleanupStack::PopAndDestroy( 1 ); // sql |
|
335 |
|
336 iImplUid = aImplUid; |
|
337 *iLocalDB = aLocalDB; |
|
338 *iServerId = aServerId; |
|
339 *iRemoteDB = aRemoteDB; |
|
340 |
|
341 DBG_FILE(_S8("CNSmlDSAgentLog::SetAgentLogKeyL ends")); |
|
342 } |
|
343 |
|
344 |
|
345 //============================================= |
|
346 // CNSmlDSAgentLog::SetIntValueL() |
|
347 // Sets given integer value. |
|
348 //============================================= |
|
349 |
|
350 EXPORT_C void CNSmlDSAgentLog::SetIntValueL( TNSmlAgentLogData aType, const TInt aNewValue ) |
|
351 { |
|
352 DBG_FILE(_S8("CNSmlDSAgentLog::SetIntValueL begins")); |
|
353 // BPSS-7NZESW : return if remote database value is empty |
|
354 if ( iLocalDB == NULL || iServerId == NULL ||iRemoteDB == NULL || iRemoteDB->Length() < 1 ) |
|
355 { |
|
356 return; |
|
357 } |
|
358 |
|
359 TBuf<32> columnName; |
|
360 TInt setValue( aNewValue ); |
|
361 |
|
362 switch ( aType ) |
|
363 { |
|
364 case ( EAgentLogSlowSyncRequest ) : |
|
365 columnName = KNSmlAgentLogSlowSyncRequest; |
|
366 break; |
|
367 |
|
368 case ( EAgentLogServerSupportsNOC ) : |
|
369 columnName = KNSmlAgentLogServerSupportsNOC; |
|
370 // Make sure that value is 1 or 0 |
|
371 if ( setValue ) |
|
372 { |
|
373 setValue = 1; |
|
374 } |
|
375 else |
|
376 { |
|
377 setValue = 0; |
|
378 } |
|
379 break; |
|
380 |
|
381 case ( EAgentLogServerSupportsHierarchicalSync ) : |
|
382 columnName = KNSmlAgentLogServerSupportsHierarchicalSync ; |
|
383 // Make sure that value is 1 or 0 |
|
384 if ( setValue ) |
|
385 { |
|
386 setValue = 1; |
|
387 } |
|
388 else |
|
389 { |
|
390 setValue = 0; |
|
391 } |
|
392 break; |
|
393 |
|
394 case ( EAgentLogServerSyncTypes ) : |
|
395 columnName = KNSmlAgentLogServerSyncTypes; |
|
396 break; |
|
397 //RD_SUSPEND_RESUME |
|
398 case (EAgentLogSyncSuspendedState) : |
|
399 columnName = KNSmlAgentLogSuspendedState; |
|
400 break; |
|
401 |
|
402 case (EAgentLogPreviousSyncType) : |
|
403 columnName=KNSmlAgentLogPreviousSyncType; |
|
404 break; |
|
405 case (EAgentLogPreviousClientSyncType): |
|
406 columnName=KNSmlAgentLogPreviousClientSyncType; |
|
407 break; |
|
408 |
|
409 default: |
|
410 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
411 } |
|
412 |
|
413 HBufC* sql = AgentLogRowSqlLC(); |
|
414 PrepareViewL( *sql, iView.EUpdatable ); |
|
415 |
|
416 iDatabase.Begin(); |
|
417 if ( iView.FirstL() ) |
|
418 { |
|
419 //existing row |
|
420 iView.GetL(); |
|
421 iView.UpdateL(); |
|
422 iView.SetColL( iColSet->ColNo( columnName ), setValue ); |
|
423 iView.PutL(); |
|
424 } |
|
425 else |
|
426 { |
|
427 //new row |
|
428 InitNewRowL(); |
|
429 iTableAgentLog.SetColL( iColSet->ColNo( columnName ), setValue ); |
|
430 iTableAgentLog.PutL(); |
|
431 } |
|
432 CommitAndCompact(); |
|
433 |
|
434 CleanupStack::PopAndDestroy( 1 ); // sql |
|
435 DBG_FILE(_S8("CNSmlDSAgentLog::SetIntValueL ends")); |
|
436 } |
|
437 |
|
438 //============================================= |
|
439 // CNSmlDSAgentLog::IntValueL() |
|
440 // Gets given integer value. |
|
441 //============================================= |
|
442 |
|
443 EXPORT_C TInt CNSmlDSAgentLog::IntValueL( TNSmlAgentLogData aType ) |
|
444 { |
|
445 DBG_FILE(_S8("CNSmlDSAgentLog::IntValueL begins")); |
|
446 HBufC* sql = AgentLogRowSqlLC(); |
|
447 |
|
448 TBuf<30>columnName; |
|
449 |
|
450 switch ( aType ) |
|
451 { |
|
452 case ( EAgentLogSlowSyncRequest ) : |
|
453 columnName = KNSmlAgentLogSlowSyncRequest; |
|
454 break; |
|
455 |
|
456 case ( EAgentLogServerSupportsNOC ) : |
|
457 columnName = KNSmlAgentLogServerSupportsNOC; |
|
458 break; |
|
459 |
|
460 case ( EAgentLogServerSyncTypes ) : |
|
461 columnName = KNSmlAgentLogServerSyncTypes; |
|
462 break; |
|
463 |
|
464 case EAgentLogServerSupportsHierarchicalSync: |
|
465 columnName = KNSmlAgentLogServerSupportsHierarchicalSync; |
|
466 break; |
|
467 //RD_SUSPEND_RESUME |
|
468 case (EAgentLogSyncSuspendedState) : |
|
469 columnName = KNSmlAgentLogSuspendedState; |
|
470 break; |
|
471 case (EAgentLogPreviousSyncType) : |
|
472 columnName=KNSmlAgentLogPreviousSyncType; |
|
473 break; |
|
474 case(EAgentLogPreviousClientSyncType): |
|
475 columnName=KNSmlAgentLogPreviousClientSyncType; |
|
476 break; |
|
477 //RD_SUSPEND_RESUME |
|
478 default: |
|
479 { |
|
480 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
481 } |
|
482 } |
|
483 |
|
484 PrepareViewL( *sql, iView.EReadOnly ); |
|
485 |
|
486 TInt status( 0 ); |
|
487 |
|
488 if ( iView.FirstL() ) |
|
489 { |
|
490 iView.GetL(); |
|
491 status = iView.ColInt( iColSet->ColNo( columnName ) ); |
|
492 } |
|
493 |
|
494 CleanupStack::PopAndDestroy( 1 ); // sql |
|
495 DBG_FILE(_S8("CNSmlDSAgentLog::IntValueL ends")); |
|
496 return status; |
|
497 } |
|
498 |
|
499 //============================================= |
|
500 // CNSmlDSAgentLog::SetTimeValueL() |
|
501 // Sets given datetime value. |
|
502 //============================================= |
|
503 |
|
504 EXPORT_C void CNSmlDSAgentLog::SetTimeValueL( TNSmlAgentLogData aType, const TTime& aNewValue ) |
|
505 { |
|
506 DBG_FILE(_S8("CNSmlDSAgentLog::SetTimeValueL begins")); |
|
507 if ( iLocalDB == NULL || iServerId == NULL || iRemoteDB == NULL ) |
|
508 { |
|
509 return; |
|
510 } |
|
511 |
|
512 HBufC* sql = AgentLogRowSqlLC(); |
|
513 |
|
514 TBuf<20> columnName; |
|
515 |
|
516 switch ( aType ) |
|
517 { |
|
518 case ( EAgentLogLastSyncronised ) : |
|
519 { |
|
520 columnName.Format( KColumn, &KNSmlAgentLogLastSyncronised ); |
|
521 } |
|
522 break; |
|
523 |
|
524 case ( EAgentLogLastSyncAnchor ) : |
|
525 { |
|
526 columnName.Format( KColumn, &KNSmlAgentLogLastSyncAnchor ); |
|
527 } |
|
528 break; |
|
529 |
|
530 default: |
|
531 { |
|
532 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
533 } |
|
534 } |
|
535 |
|
536 PrepareViewL( *sql, iView.EUpdatable ); |
|
537 |
|
538 iDatabase.Begin(); |
|
539 if ( iView.FirstL() ) |
|
540 { |
|
541 //existing row |
|
542 iView.GetL(); |
|
543 iView.UpdateL(); |
|
544 iView.SetColL( iColSet->ColNo( columnName ), aNewValue ); //check |
|
545 iView.PutL(); |
|
546 } |
|
547 else |
|
548 { |
|
549 //new row |
|
550 InitNewRowL(); |
|
551 iTableAgentLog.SetColL( iColSet->ColNo( columnName ), aNewValue ); |
|
552 iTableAgentLog.PutL(); |
|
553 } |
|
554 |
|
555 CommitAndCompact(); |
|
556 CleanupStack::PopAndDestroy( 1 ); // sql, |
|
557 DBG_FILE(_S8("CNSmlDSAgentLog::SetTimeValueL ends")); |
|
558 } |
|
559 |
|
560 //============================================= |
|
561 // CNSmlDSAgentLog::TimeValueL() |
|
562 // Gets given datetime value. |
|
563 // If the returned value is TTime(0), |
|
564 // given value was not found. |
|
565 //============================================= |
|
566 |
|
567 EXPORT_C TTime CNSmlDSAgentLog::TimeValueL( TNSmlAgentLogData aType ) |
|
568 { |
|
569 DBG_FILE(_S8("CNSmlDSAgentLog::TimeValueL begins")); |
|
570 HBufC* sql = AgentLogRowSqlLC(); |
|
571 TBuf<20> columnName; |
|
572 |
|
573 switch ( aType ) |
|
574 { |
|
575 case ( EAgentLogLastSyncronised ) : |
|
576 { |
|
577 columnName.Format( KColumn, &KNSmlAgentLogLastSyncronised ); |
|
578 } |
|
579 break; |
|
580 |
|
581 case ( EAgentLogLastSyncAnchor ) : |
|
582 { |
|
583 columnName.Format( KColumn, &KNSmlAgentLogLastSyncAnchor ); |
|
584 } |
|
585 break; |
|
586 |
|
587 default: |
|
588 { |
|
589 User::Panic( KNSmlIndexOutOfBoundStr, KNSmlPanicIndexOutOfBound ); |
|
590 } |
|
591 } |
|
592 |
|
593 PrepareViewL( *sql, iView.EReadOnly ); |
|
594 |
|
595 TTime dateTimeValue( 0 ); |
|
596 |
|
597 if ( iView.FirstL() ) |
|
598 { |
|
599 iView.GetL(); |
|
600 dateTimeValue = iView.ColTime( iColSet->ColNo( columnName ) ); |
|
601 } |
|
602 |
|
603 CleanupStack::PopAndDestroy( 1 ); // sql |
|
604 DBG_FILE(_S8("CNSmlDSAgentLog::TimeValueL ends")); |
|
605 return dateTimeValue; |
|
606 } |
|
607 |
|
608 //============================================= |
|
609 // CNSmlDSAgentLog::SetNonceL() |
|
610 // Sets nonce. |
|
611 //============================================= |
|
612 |
|
613 EXPORT_C void CNSmlDSAgentLog::SetNonceL( const TDesC& aServerId, const TDesC& aNewValue ) |
|
614 { |
|
615 DBG_FILE(_S8("CNSmlDSAgentLog::SetNonceL begins")); |
|
616 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
617 |
|
618 PrepareViewL( *sql, iView.EUpdatable ); |
|
619 iDatabase.Begin(); |
|
620 |
|
621 RDbColReadStream in; |
|
622 TInt oldNonceSize(0); |
|
623 if ( iView.FirstL() ) |
|
624 { |
|
625 iView.GetL(); |
|
626 in.OpenLC( iView, iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ); |
|
627 oldNonceSize = in.Source()->SizeL(); |
|
628 CleanupStack::PopAndDestroy(); // in |
|
629 } |
|
630 |
|
631 RDbColWriteStream out; |
|
632 if ( iView.FirstL() ) |
|
633 { |
|
634 //existing row |
|
635 |
|
636 // Check OOD before updating existing nonce value |
|
637 if ((aNewValue.Size() > oldNonceSize ) && (SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
638 ( aNewValue.Size() - oldNonceSize ) + KNSmlAgentLogTreshold ))) |
|
639 { |
|
640 iDatabase.Rollback(); |
|
641 User::Leave( KErrDiskFull ); |
|
642 } |
|
643 |
|
644 // Replace nonce |
|
645 iView.GetL(); |
|
646 iView.UpdateL(); |
|
647 out.OpenLC( iView, iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ); |
|
648 out.WriteL( aNewValue ); |
|
649 out.Close(); |
|
650 iView.PutL(); |
|
651 } |
|
652 else |
|
653 { |
|
654 //new row |
|
655 |
|
656 // Check OOD before inserting new row into Authentication table |
|
657 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, aNewValue.Size() + |
|
658 KNSmlAgentLogMaxFixedAuthRowSize + KNSmlAgentLogTreshold ) ) |
|
659 { |
|
660 iDatabase.Rollback(); |
|
661 User::Leave( KErrDiskFull ); |
|
662 } |
|
663 |
|
664 // Insert new row |
|
665 PrepareViewL( KSQLGetAuthenticationAll, iView.EUpdatable ); |
|
666 iView.InsertL(); |
|
667 out.OpenLC( iView, iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ); |
|
668 out.WriteL( aNewValue ); |
|
669 out.Close(); |
|
670 iView.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationServerId ), aServerId ); |
|
671 iView.PutL(); |
|
672 } |
|
673 |
|
674 CommitAndCompact(); |
|
675 CleanupStack::PopAndDestroy( 2 ); // sql, out |
|
676 DBG_FILE(_S8("CNSmlDSAgentLog::SetNonceL ends")); |
|
677 } |
|
678 |
|
679 //============================================= |
|
680 // CNSmlDSAgentLog::NonceL() |
|
681 // Gets nonce. |
|
682 // If length of the returned string is 0, |
|
683 // nonce was not found. |
|
684 //============================================= |
|
685 |
|
686 EXPORT_C HBufC* CNSmlDSAgentLog::NonceL( const TDesC& aServerId ) |
|
687 { |
|
688 DBG_FILE(_S8("CNSmlDSAgentLog::NonceL begins")); |
|
689 |
|
690 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
691 |
|
692 PrepareViewL( *sql, iView.EReadOnly ); |
|
693 |
|
694 HBufC* stringValue; |
|
695 |
|
696 if ( iView.FirstL() ) |
|
697 { |
|
698 iView.GetL(); |
|
699 RDbColReadStream in; |
|
700 in.OpenLC( iView, iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ); |
|
701 stringValue = HBufC::NewLC( iView.ColLength( iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ) ); |
|
702 TPtr ptr = stringValue->Des(); |
|
703 in.ReadL( ptr, iView.ColLength( iColSetTableAuth->ColNo( KNSmlAuthenticationNonce ) ) ); |
|
704 CleanupStack::Pop( 1 ); // stringValue |
|
705 CleanupStack::PopAndDestroy( 1 ); //in |
|
706 } |
|
707 else |
|
708 { |
|
709 //couldn't find |
|
710 stringValue = HBufC::NewL( 0 ); |
|
711 } |
|
712 |
|
713 CleanupStack::PopAndDestroy( 1 ); // sql |
|
714 DBG_FILE(_S8("CNSmlDSAgentLog::NonceL ends")); |
|
715 return stringValue; |
|
716 } |
|
717 |
|
718 //============================================= |
|
719 // CNSmlDSAgentLog::SetSessionIDL() |
|
720 // Sets session Id. |
|
721 //============================================= |
|
722 |
|
723 EXPORT_C void CNSmlDSAgentLog::SetSessionIDL( const TDesC& aServerId, const TInt aSessionID ) |
|
724 { |
|
725 DBG_FILE(_S8("CNSmlDSAgentLog::SetSessionIDL begins")); |
|
726 |
|
727 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
728 |
|
729 PrepareViewL( *sql, iView.EUpdatable ); |
|
730 |
|
731 iDatabase.Begin(); |
|
732 |
|
733 if ( iView.FirstL() ) |
|
734 { |
|
735 //existing row |
|
736 iView.GetL(); |
|
737 iView.UpdateL(); |
|
738 iView.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationSessionId ), ( TInt ) aSessionID ); |
|
739 iView.PutL(); |
|
740 } |
|
741 else |
|
742 { |
|
743 //new row |
|
744 |
|
745 // Check OOD before inserting new row into Authentication table |
|
746 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
747 KNSmlAgentLogMaxFixedAuthRowSize + KNSmlAgentLogTreshold ) ) |
|
748 { |
|
749 iDatabase.Rollback(); |
|
750 User::Leave( KErrDiskFull ); |
|
751 } |
|
752 |
|
753 iTableAuthentication.InsertL(); |
|
754 iTableAuthentication.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationServerId ), aServerId ); |
|
755 iTableAuthentication.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationSessionId ), aSessionID ); |
|
756 iTableAuthentication.PutL(); |
|
757 } |
|
758 |
|
759 CommitAndCompact(); |
|
760 CleanupStack::PopAndDestroy( 1 ); // sql |
|
761 DBG_FILE(_S8("CNSmlDSAgentLog::SetSessionIDL ends")); |
|
762 } |
|
763 |
|
764 //============================================= |
|
765 // CNSmlDSAgentLog::SessionIDL() |
|
766 // Get Session Id |
|
767 //============================================= |
|
768 |
|
769 EXPORT_C TInt CNSmlDSAgentLog::SessionIDL( const TDesC& aServerId ) |
|
770 { |
|
771 DBG_FILE(_S8("CNSmlDSAgentLog::SessionIDL begins")); |
|
772 |
|
773 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
774 |
|
775 PrepareViewL( *sql, iView.EReadOnly ); |
|
776 |
|
777 TInt id( 0 ); |
|
778 |
|
779 if ( iView.FirstL() ) |
|
780 { |
|
781 iView.GetL(); |
|
782 id = iView.ColInt( iColSetTableAuth->ColNo( KNSmlAuthenticationSessionId ) ); |
|
783 } |
|
784 |
|
785 CleanupStack::PopAndDestroy( 1 ); // sql |
|
786 DBG_FILE(_S8("CNSmlDSAgentLog::SessionIDL ends")); |
|
787 return id; |
|
788 } |
|
789 |
|
790 //============================================= |
|
791 // CNSmlDSAgentLog::SetAuthTypeL() |
|
792 // Set Authentication type |
|
793 //============================================= |
|
794 |
|
795 EXPORT_C void CNSmlDSAgentLog::SetAuthTypeL( const TDesC& aServerId, const TNSmlAgentLogAuthenticationType aNewValue ) |
|
796 { |
|
797 DBG_FILE(_S8("CNSmlDSAgentLog::SetAuthTypeL begins")); |
|
798 |
|
799 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
800 |
|
801 PrepareViewL( *sql, iView.EUpdatable ); |
|
802 |
|
803 iDatabase.Begin(); |
|
804 |
|
805 if ( iView.FirstL() ) |
|
806 { |
|
807 //existing row |
|
808 iView.GetL(); |
|
809 iView.UpdateL(); |
|
810 iView.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationType ), ( TInt ) aNewValue ); |
|
811 iView.PutL(); |
|
812 } |
|
813 else |
|
814 { |
|
815 //new row |
|
816 |
|
817 // Check OOD before inserting new row into Authentication table |
|
818 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
819 KNSmlAgentLogMaxFixedAuthRowSize + KNSmlAgentLogTreshold ) ) |
|
820 { |
|
821 iDatabase.Rollback(); |
|
822 User::Leave( KErrDiskFull ); |
|
823 } |
|
824 |
|
825 iTableAuthentication.InsertL(); |
|
826 iTableAuthentication.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationServerId ), aServerId ); |
|
827 iTableAuthentication.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationType ), (TInt)aNewValue ); |
|
828 iTableAuthentication.PutL(); |
|
829 } |
|
830 |
|
831 CommitAndCompact(); |
|
832 CleanupStack::PopAndDestroy( 1 ); // sql |
|
833 DBG_FILE(_S8("CNSmlDSAgentLog::SetAuthTypeL ends")); |
|
834 } |
|
835 |
|
836 //============================================= |
|
837 // CNSmlDSAgentLog::AuthTypeL() |
|
838 // Get authentication type |
|
839 //============================================= |
|
840 |
|
841 EXPORT_C TInt CNSmlDSAgentLog::AuthTypeL( const TDesC& aServerId ) |
|
842 { |
|
843 DBG_FILE(_S8("CNSmlDSAgentLog::AuthTypeL begins")); |
|
844 |
|
845 HBufC* sql = AuthenticationSqlLC( aServerId ); |
|
846 |
|
847 PrepareViewL( *sql, iView.EReadOnly ); |
|
848 |
|
849 TInt type( 0 ); |
|
850 |
|
851 if ( iView.FirstL() ) |
|
852 { |
|
853 iView.GetL(); |
|
854 type = iView.ColInt( iColSetTableAuth->ColNo( KNSmlAuthenticationType ) ); |
|
855 } |
|
856 |
|
857 CleanupStack::PopAndDestroy( 1 ); // sql |
|
858 DBG_FILE(_S8("CNSmlDSAgentLog::AuthTypeL ends")); |
|
859 return type; |
|
860 } |
|
861 |
|
862 //============================================= |
|
863 // CNSmlDSAgentLog::SetServerIdL() |
|
864 // Sets ServerId. |
|
865 //============================================= |
|
866 |
|
867 EXPORT_C void CNSmlDSAgentLog::SetServerIdL( TDesC& aOldServerId, TDesC& aNewValue ) |
|
868 { |
|
869 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerIdL begins")); |
|
870 HBufC* sql = AuthenticationSqlLC( aOldServerId ); |
|
871 |
|
872 PrepareViewL( *sql, iView.EUpdatable ); |
|
873 TInt replaceCount(0); // Number of replaced Server Ids |
|
874 |
|
875 iDatabase.Begin(); |
|
876 if ( iView.FirstL() ) |
|
877 { |
|
878 ++replaceCount; |
|
879 |
|
880 //existing row |
|
881 iView.GetL(); |
|
882 iView.UpdateL(); |
|
883 iView.SetColL( iColSetTableAuth->ColNo( KNSmlAuthenticationServerId ), aNewValue ); |
|
884 iView.PutL(); |
|
885 } |
|
886 else |
|
887 { |
|
888 // Given ServerId was not found. Update unsuccessful. |
|
889 DBG_FILE(_S8("CNSmlDSAgentLog::AuthenticationTable update unsuccessful")); |
|
890 } |
|
891 CleanupStack::PopAndDestroy(); // sql |
|
892 |
|
893 // Update all old Server Ids also in the agentlog table |
|
894 *iServerId = aNewValue; |
|
895 |
|
896 HBufC* sqlAgentLog = HBufC::NewLC( KSQLGetAgentLogRowWithServerId().Length() + aOldServerId.Length() ); |
|
897 TPtr sqlPtr = sqlAgentLog->Des(); |
|
898 sqlPtr.Format( KSQLGetAgentLogRowWithServerId, &aOldServerId ); |
|
899 |
|
900 |
|
901 PrepareViewL( *sqlAgentLog, iView.EUpdatable ); |
|
902 |
|
903 if ( iView.FirstL() ) |
|
904 { |
|
905 replaceCount += iView.CountL(); |
|
906 |
|
907 do |
|
908 { |
|
909 //existing row |
|
910 iView.GetL(); |
|
911 iView.UpdateL(); |
|
912 iView.SetColL( iColSet->ColNo( KNSmlAgentLogServerId ), aNewValue ); |
|
913 iView.PutL(); |
|
914 } |
|
915 while ( iView.NextL() ); |
|
916 } |
|
917 else |
|
918 { |
|
919 // Given ServerId was not found. Update unsuccessful. |
|
920 DBG_FILE(_S8("CNSmlDSAgentLog::AgentLogTable update unsuccessful")); |
|
921 } |
|
922 |
|
923 // Check OOD before commiting |
|
924 if ( (aNewValue.Size() > aOldServerId.Size()) && (SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, (replaceCount * |
|
925 (aNewValue.Size() - aOldServerId.Size())) + KNSmlAgentLogTreshold ))) |
|
926 { |
|
927 iDatabase.Rollback(); |
|
928 User::Leave( KErrDiskFull ); |
|
929 } |
|
930 |
|
931 CommitAndCompact(); |
|
932 CleanupStack::PopAndDestroy(); // sqlAgentLog |
|
933 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerIdL ends")); |
|
934 } |
|
935 |
|
936 //============================================= |
|
937 // CNSmlDSAgentLog::SetServerDeviceInfoL() |
|
938 // Sets Server Device Info given in parameter. |
|
939 //============================================= |
|
940 |
|
941 EXPORT_C void CNSmlDSAgentLog::SetServerDeviceInfoL( const RPointerArray<CNSmlDbCaps>& aDbCaps ) |
|
942 { |
|
943 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerDeviceInfoL begins")); |
|
944 |
|
945 _LIT8( KSeparator, ";"); |
|
946 |
|
947 CBufFlat* deviceData = CBufFlat::NewL(8); |
|
948 CleanupStack::PushL( deviceData ); |
|
949 TInt pos( 0 ); |
|
950 TBuf8<6> buffer; //for num part |
|
951 |
|
952 HBufC* stringValue16=0; |
|
953 |
|
954 TInt arrayCount(0); |
|
955 while (arrayCount<aDbCaps.Count()) |
|
956 { |
|
957 |
|
958 SmlDevInfDatastore_t* dataStore = aDbCaps[arrayCount]->DatastoreL(); |
|
959 CleanupStack::PushL(dataStore); |
|
960 |
|
961 buffer.Num( ( TInt )CNSmlDSAgentLog::EDataStore ); |
|
962 deviceData->InsertL( pos, buffer ); |
|
963 pos += buffer.Length(); |
|
964 |
|
965 deviceData->InsertL( pos, KSeparator ); |
|
966 pos++; |
|
967 deviceData->InsertL( pos, KSeparator ); |
|
968 pos++; |
|
969 |
|
970 |
|
971 if (dataStore->sourceref) |
|
972 { |
|
973 buffer.Num( ( TInt )CNSmlDSAgentLog::ESourceRef ); |
|
974 deviceData->InsertL( pos, buffer ); |
|
975 pos += buffer.Length(); |
|
976 |
|
977 deviceData->InsertL( pos, KSeparator ); |
|
978 pos++; |
|
979 |
|
980 deviceData->InsertL( pos, dataStore->sourceref->Data()); |
|
981 pos += dataStore->sourceref->Data().Length(); |
|
982 |
|
983 deviceData->InsertL( pos, KSeparator ); |
|
984 pos++; |
|
985 } |
|
986 |
|
987 if (dataStore->displayname) |
|
988 { |
|
989 buffer.Num( ( TInt )CNSmlDSAgentLog::EDisplayName ); |
|
990 deviceData->InsertL( pos, buffer ); |
|
991 pos += buffer.Length(); |
|
992 |
|
993 deviceData->InsertL( pos, KSeparator ); |
|
994 pos++; |
|
995 |
|
996 deviceData->InsertL( pos, dataStore->displayname->Data()); |
|
997 pos += dataStore->displayname->Data().Length(); |
|
998 |
|
999 deviceData->InsertL( pos, KSeparator ); |
|
1000 pos++; |
|
1001 } |
|
1002 |
|
1003 if (dataStore->maxguidsize) |
|
1004 { |
|
1005 buffer.Num( ( TInt )CNSmlDSAgentLog::EMaxGUIDSize ); |
|
1006 deviceData->InsertL( pos, buffer ); |
|
1007 pos += buffer.Length(); |
|
1008 |
|
1009 deviceData->InsertL( pos, KSeparator ); |
|
1010 pos++; |
|
1011 |
|
1012 deviceData->InsertL( pos, dataStore->maxguidsize->Data()); |
|
1013 pos += dataStore->maxguidsize->Data().Length(); |
|
1014 |
|
1015 deviceData->InsertL( pos, KSeparator ); |
|
1016 pos++; |
|
1017 } |
|
1018 |
|
1019 if (dataStore->rxpref) |
|
1020 { |
|
1021 buffer.Num( ( TInt )CNSmlDSAgentLog::ERxPref ); |
|
1022 deviceData->InsertL( pos, buffer ); |
|
1023 pos += buffer.Length(); |
|
1024 |
|
1025 deviceData->InsertL( pos, KSeparator ); |
|
1026 pos++; |
|
1027 |
|
1028 deviceData->InsertL( pos, dataStore->rxpref->cttype->Data()); |
|
1029 pos += dataStore->rxpref->cttype->Data().Length(); |
|
1030 |
|
1031 deviceData->InsertL( pos, KTabSeparator ); |
|
1032 pos++; |
|
1033 |
|
1034 deviceData->InsertL( pos, dataStore->rxpref->verct->Data()); |
|
1035 pos += dataStore->rxpref->verct->Data().Length(); |
|
1036 |
|
1037 deviceData->InsertL( pos, KSeparator ); |
|
1038 pos++; |
|
1039 } |
|
1040 |
|
1041 if (dataStore->rx) |
|
1042 { |
|
1043 SmlDevInfXmitListPtr_t rx= dataStore->rx; |
|
1044 |
|
1045 while (rx) |
|
1046 { |
|
1047 buffer.Num( ( TInt )CNSmlDSAgentLog::ERx); |
|
1048 deviceData->InsertL( pos, buffer ); |
|
1049 pos += buffer.Length(); |
|
1050 |
|
1051 deviceData->InsertL( pos, KSeparator ); |
|
1052 pos++; |
|
1053 |
|
1054 deviceData->InsertL( pos, rx->data->cttype->Data()); |
|
1055 pos += rx->data->cttype->Data().Length(); |
|
1056 |
|
1057 deviceData->InsertL( pos, KTabSeparator ); |
|
1058 pos++; |
|
1059 |
|
1060 deviceData->InsertL( pos, rx->data->verct->Data()); |
|
1061 pos += rx->data->verct->Data().Length(); |
|
1062 |
|
1063 deviceData->InsertL( pos, KSeparator ); |
|
1064 pos++; |
|
1065 |
|
1066 rx=rx->next; |
|
1067 } |
|
1068 } |
|
1069 |
|
1070 if (dataStore->txpref) |
|
1071 { |
|
1072 buffer.Num( ( TInt )CNSmlDSAgentLog::ETxPref ); |
|
1073 deviceData->InsertL( pos, buffer ); |
|
1074 pos += buffer.Length(); |
|
1075 |
|
1076 deviceData->InsertL( pos, KSeparator ); |
|
1077 pos++; |
|
1078 |
|
1079 deviceData->InsertL( pos, dataStore->txpref->cttype->Data()); |
|
1080 pos += dataStore->txpref->cttype->Data().Length(); |
|
1081 |
|
1082 deviceData->InsertL( pos, KTabSeparator ); |
|
1083 pos++; |
|
1084 |
|
1085 deviceData->InsertL( pos, dataStore->txpref->verct->Data()); |
|
1086 pos += dataStore->txpref->verct->Data().Length(); |
|
1087 |
|
1088 deviceData->InsertL( pos, KSeparator ); |
|
1089 pos++; |
|
1090 } |
|
1091 |
|
1092 if (dataStore->tx) |
|
1093 { |
|
1094 SmlDevInfXmitListPtr_t tx= dataStore->tx; |
|
1095 |
|
1096 while (tx) |
|
1097 { |
|
1098 buffer.Num( ( TInt )CNSmlDSAgentLog::ETx); |
|
1099 deviceData->InsertL( pos, buffer ); |
|
1100 pos += buffer.Length(); |
|
1101 |
|
1102 deviceData->InsertL( pos, KSeparator ); |
|
1103 pos++; |
|
1104 |
|
1105 deviceData->InsertL( pos, tx->data->cttype->Data()); |
|
1106 pos += tx->data->cttype->Data().Length(); |
|
1107 |
|
1108 deviceData->InsertL( pos, KTabSeparator ); |
|
1109 pos++; |
|
1110 |
|
1111 deviceData->InsertL( pos, tx->data->verct->Data()); |
|
1112 pos += tx->data->verct->Data().Length(); |
|
1113 |
|
1114 deviceData->InsertL( pos, KSeparator ); |
|
1115 pos++; |
|
1116 |
|
1117 tx=tx->next; |
|
1118 } |
|
1119 } |
|
1120 |
|
1121 if (dataStore->dsmem) |
|
1122 { |
|
1123 buffer.Num( ( TInt )CNSmlDSAgentLog::EDSMem ); |
|
1124 deviceData->InsertL( pos, buffer ); |
|
1125 pos += buffer.Length(); |
|
1126 |
|
1127 deviceData->InsertL( pos, KSeparator ); |
|
1128 pos++; |
|
1129 |
|
1130 deviceData->InsertL( pos, dataStore->dsmem->Data()); |
|
1131 pos += dataStore->dsmem->Data().Length(); |
|
1132 |
|
1133 deviceData->InsertL( pos, KSeparator ); |
|
1134 pos++; |
|
1135 } |
|
1136 |
|
1137 if (dataStore->supportHierarchicalSync) |
|
1138 { |
|
1139 buffer.Num( ( TInt )CNSmlDSAgentLog::ESupportHierarchicalSync ); |
|
1140 deviceData->InsertL( pos, buffer ); |
|
1141 pos += buffer.Length(); |
|
1142 |
|
1143 deviceData->InsertL( pos, KSeparator ); |
|
1144 pos++; |
|
1145 |
|
1146 deviceData->InsertL( pos, KSeparator ); |
|
1147 pos++; |
|
1148 } |
|
1149 |
|
1150 if (dataStore->synccap) |
|
1151 { |
|
1152 SmlPcdataListPtr_t syncType=dataStore->synccap->synctype; |
|
1153 |
|
1154 while (syncType) |
|
1155 { |
|
1156 buffer.Num( ( TInt )CNSmlDSAgentLog::ESyncCap); |
|
1157 deviceData->InsertL( pos, buffer ); |
|
1158 pos += buffer.Length(); |
|
1159 |
|
1160 deviceData->InsertL( pos, KSeparator ); |
|
1161 pos++; |
|
1162 |
|
1163 deviceData->InsertL( pos, dataStore->synccap->synctype->data->Data()); |
|
1164 pos += dataStore->synccap->synctype->data->Data().Length(); |
|
1165 |
|
1166 deviceData->InsertL( pos, KSeparator ); |
|
1167 pos++; |
|
1168 |
|
1169 syncType=syncType->next; |
|
1170 } |
|
1171 } |
|
1172 |
|
1173 sml_devinf_ctcaplist_s *ctCaps = dataStore->ctcap; |
|
1174 |
|
1175 CNSmlCtCapsHandler* ctCapsHandler = new(ELeave) CNSmlCtCapsHandler( ctCaps ); |
|
1176 CleanupStack::PushL( ctCapsHandler ); |
|
1177 CArrayFix<TNSmlCtCapData>* ctCapArray = new( ELeave ) CArrayFixFlat<TNSmlCtCapData>(8); |
|
1178 CleanupStack::PushL( ctCapArray ); |
|
1179 ctCapsHandler->GetCtCapsL( *ctCapArray ); |
|
1180 |
|
1181 for ( TInt i = 0; i < ctCapArray->Count(); i++ ) |
|
1182 { |
|
1183 buffer.Num( ( TInt ) ctCapArray->At( i ).iTag ); |
|
1184 deviceData->InsertL( pos, buffer ); |
|
1185 pos += buffer.Length(); |
|
1186 |
|
1187 deviceData->InsertL( pos, KSeparator ); |
|
1188 pos++; |
|
1189 |
|
1190 deviceData->InsertL( pos, ctCapArray->At( i ).iValue ); |
|
1191 pos += ctCapArray->At( i ).iValue.Length(); |
|
1192 |
|
1193 deviceData->InsertL( pos, KSeparator ); |
|
1194 pos++; |
|
1195 } |
|
1196 |
|
1197 CleanupStack::PopAndDestroy(3); //dataStore,ctCapsHandler,ctCapArray |
|
1198 |
|
1199 arrayCount++; |
|
1200 } |
|
1201 if (arrayCount>0) |
|
1202 { |
|
1203 TPtr8 stringValue = deviceData->Ptr( 0 ); |
|
1204 stringValue16 = HBufC::NewLC( stringValue.Size() * 2 ); |
|
1205 TPtr ptrStringValue16( stringValue16->Des() ); |
|
1206 CnvUtfConverter::ConvertToUnicodeFromUtf8( ptrStringValue16, stringValue ); |
|
1207 } |
|
1208 else |
|
1209 { |
|
1210 stringValue16 = KNullDesC().AllocLC(); |
|
1211 } |
|
1212 |
|
1213 |
|
1214 HBufC* sql = AgentLogRowSqlLC(); |
|
1215 |
|
1216 PrepareViewL( *sql, iView.EUpdatable ); |
|
1217 iDatabase.Begin(); |
|
1218 |
|
1219 RDbColReadStream in; |
|
1220 TInt oldDeviceInfoSize(0); |
|
1221 if ( iView.FirstL() ) |
|
1222 { |
|
1223 iView.GetL(); |
|
1224 in.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ); |
|
1225 oldDeviceInfoSize = in.Source()->SizeL(); |
|
1226 CleanupStack::PopAndDestroy(&in); |
|
1227 } |
|
1228 |
|
1229 RDbColWriteStream out; |
|
1230 if ( iView.FirstL() ) |
|
1231 { |
|
1232 //existing row |
|
1233 |
|
1234 // Check OOD before writing device info on existing row |
|
1235 if ((stringValue16->Size() > oldDeviceInfoSize ) && (SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
1236 ( stringValue16->Size() - oldDeviceInfoSize ) + KNSmlAgentLogTreshold ))) |
|
1237 { |
|
1238 iDatabase.Rollback(); |
|
1239 User::Leave( KErrDiskFull ); |
|
1240 } |
|
1241 |
|
1242 // Update device info |
|
1243 iView.GetL(); |
|
1244 iView.UpdateL(); |
|
1245 out.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ); |
|
1246 out.WriteL( *stringValue16 ); |
|
1247 out.Close(); |
|
1248 iView.PutL(); |
|
1249 } |
|
1250 else |
|
1251 { |
|
1252 //new row |
|
1253 |
|
1254 // Check OOD before inserting new row into AgentLog table |
|
1255 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
1256 KNSmlAgentLogMaxFixedLogRowSize + stringValue16->Size() + |
|
1257 KNSmlAgentLogTreshold ) ) |
|
1258 { |
|
1259 iDatabase.Rollback(); |
|
1260 User::Leave( KErrDiskFull ); |
|
1261 } |
|
1262 |
|
1263 // Insert new row |
|
1264 PrepareViewL( KSQLGetAgentLogAll, iView.EUpdatable ); |
|
1265 iID = GenerateIdL(); |
|
1266 iView.InsertL(); |
|
1267 iView.SetColL( iColSet->ColNo( KNSmlAgentLogId ), iID ); |
|
1268 out.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ); |
|
1269 out.WriteL( *stringValue16 ); |
|
1270 out.Close(); |
|
1271 iView.SetColL( iColSet->ColNo( KNSmlAgentLogImplementationUID ), iImplUid ); |
|
1272 iView.SetColL( iColSet->ColNo( KNSmlAgentLogLocalDatabase ), *iLocalDB ); |
|
1273 iView.SetColL( iColSet->ColNo( KNSmlAgentLogServerId ), *iServerId ); |
|
1274 iView.SetColL( iColSet->ColNo( KNSmlAgentLogRemoteDatabase ), *iRemoteDB ); |
|
1275 iView.PutL(); |
|
1276 } |
|
1277 |
|
1278 CommitAndCompact(); |
|
1279 CleanupStack::PopAndDestroy( 4 ); // sql, out, stringValue16, deviceData |
|
1280 |
|
1281 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerDeviceInfoL ends")); |
|
1282 } |
|
1283 |
|
1284 //============================================= |
|
1285 // CNSmlDSAgentLog::GetServerDeviceInfoL() |
|
1286 // Gets Server Device Info. |
|
1287 //============================================= |
|
1288 |
|
1289 EXPORT_C void CNSmlDSAgentLog::GetServerDeviceInfoL( RPointerArray<CNSmlDbCaps>& aDbCaps ) |
|
1290 { |
|
1291 DBG_FILE(_S8("CNSmlDSAgentLog::GetServerDeviceInfoL begins")); |
|
1292 |
|
1293 |
|
1294 HBufC* sql = AgentLogRowSqlLC(); |
|
1295 |
|
1296 PrepareViewL( *sql, iView.EReadOnly ); |
|
1297 |
|
1298 HBufC* stringValue; |
|
1299 |
|
1300 if ( iView.FirstL() ) |
|
1301 { |
|
1302 iView.GetL(); |
|
1303 RDbColReadStream in; |
|
1304 stringValue = HBufC::NewLC( iView.ColLength( iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ) ); |
|
1305 in.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ); |
|
1306 TPtr ptr = stringValue->Des(); |
|
1307 in.ReadL( ptr, iView.ColLength( iColSet->ColNo( KNSmlAgentLogServerDeviceInfo ) ) ); |
|
1308 CleanupStack::PopAndDestroy( 1 ); // in |
|
1309 } |
|
1310 else |
|
1311 { |
|
1312 //couldn't find |
|
1313 CleanupStack::PopAndDestroy( 1 ); // sql |
|
1314 return; |
|
1315 } |
|
1316 |
|
1317 TInt start( 0 ); |
|
1318 TInt firstSeparator( 0 ); |
|
1319 TBool firstFound( EFalse ); |
|
1320 TLex lex; |
|
1321 TInt numPart( 0 ); |
|
1322 TPtr ptrStringValue = stringValue->Des(); |
|
1323 |
|
1324 |
|
1325 if (stringValue->Length()>0) |
|
1326 { |
|
1327 CNSmlDbCaps* dbCaps = NULL; // |
|
1328 |
|
1329 CNSmlCtCap* cap=NULL; |
|
1330 CNSmlDevInfProp* prop=NULL; |
|
1331 CNSmlPropParam* param=NULL; |
|
1332 TInt pc(0); |
|
1333 for ( TInt i = 0; i < stringValue->Length(); i++ ) |
|
1334 { |
|
1335 if ( ptrStringValue[i] == ';' ) //; = separator |
|
1336 { |
|
1337 if ( !firstFound ) |
|
1338 { |
|
1339 firstSeparator = i; |
|
1340 firstFound = ETrue; |
|
1341 } |
|
1342 else |
|
1343 { |
|
1344 lex.Assign( stringValue->Mid( start, firstSeparator - start ) ); |
|
1345 lex.Val( numPart ); |
|
1346 |
|
1347 TPtrC ptrTemp = stringValue->Mid( firstSeparator + 1, i - firstSeparator - 1 ); |
|
1348 |
|
1349 HBufC8* stringPart = HBufC8::NewLC( ptrTemp.Length() ); |
|
1350 pc++; |
|
1351 TPtr8 ptrStringPart = stringPart->Des(); |
|
1352 |
|
1353 CnvUtfConverter::ConvertFromUnicodeToUtf8( ptrStringPart, ptrTemp ); |
|
1354 |
|
1355 TInt separator; |
|
1356 |
|
1357 switch(numPart) |
|
1358 { |
|
1359 case TNSmlCtCapData::ECtType: |
|
1360 cap = dbCaps->AddCtCapLC(); pc++; |
|
1361 cap->SetCtTypeL(ptrStringPart); |
|
1362 prop=0; |
|
1363 param=0; |
|
1364 break; |
|
1365 |
|
1366 case TNSmlCtCapData::EVerCt: |
|
1367 if (cap) |
|
1368 { |
|
1369 cap->SetVerCtL(ptrStringPart); |
|
1370 } |
|
1371 break; |
|
1372 |
|
1373 case TNSmlCtCapData::EFieldLevel: |
|
1374 if (cap) |
|
1375 { |
|
1376 cap->SetFieldLevelL(); |
|
1377 } |
|
1378 break; |
|
1379 |
|
1380 case TNSmlCtCapData::EPropName: |
|
1381 if (cap) |
|
1382 { |
|
1383 prop = cap->AddDevInfPropLC(ptrStringPart); |
|
1384 pc++; |
|
1385 param=0; |
|
1386 } |
|
1387 break; |
|
1388 |
|
1389 case TNSmlCtCapData::EPropDataType: |
|
1390 if (prop) |
|
1391 { |
|
1392 prop->SetDataTypeL(ptrStringPart); |
|
1393 } |
|
1394 break; |
|
1395 |
|
1396 case TNSmlCtCapData::EPropMaxOccur: |
|
1397 if (prop) |
|
1398 { |
|
1399 prop->SetMaxOccurL(ptrStringPart); |
|
1400 } |
|
1401 break; |
|
1402 |
|
1403 case TNSmlCtCapData::EPropNoTruncate: |
|
1404 if (prop) |
|
1405 { |
|
1406 prop->SetNoTruncateL(); |
|
1407 } |
|
1408 break; |
|
1409 |
|
1410 case TNSmlCtCapData::EPropValEnum: |
|
1411 if (prop) |
|
1412 { |
|
1413 prop->AddValEnumL(ptrStringPart); |
|
1414 } |
|
1415 break; |
|
1416 |
|
1417 case TNSmlCtCapData::EPropDisplayName: |
|
1418 if (prop) |
|
1419 { |
|
1420 prop->SetDisplayNameL(ptrStringPart); |
|
1421 } |
|
1422 break; |
|
1423 |
|
1424 case TNSmlCtCapData::EParamName: |
|
1425 if (prop) |
|
1426 { |
|
1427 param = prop->AddParamLC(ptrStringPart); |
|
1428 pc++; |
|
1429 } |
|
1430 break; |
|
1431 |
|
1432 case TNSmlCtCapData::EParamValEnum: |
|
1433 if (param) |
|
1434 { |
|
1435 param->AddValEnumL(ptrStringPart); |
|
1436 } |
|
1437 break; |
|
1438 |
|
1439 case TNSmlCtCapData::EParamDataType: |
|
1440 if (param) |
|
1441 { |
|
1442 param->SetDataTypeL(ptrStringPart); |
|
1443 } |
|
1444 break; |
|
1445 |
|
1446 case TNSmlCtCapData::EParamDisplayName: |
|
1447 if (param) |
|
1448 { |
|
1449 param->SetDisplayNameL(ptrStringPart); |
|
1450 } |
|
1451 break; |
|
1452 ////////////////////////// |
|
1453 |
|
1454 case EDataStore: |
|
1455 dbCaps = CNSmlDbCaps::NewL(); |
|
1456 aDbCaps.Append(dbCaps); |
|
1457 break; |
|
1458 |
|
1459 case ESourceRef: |
|
1460 dbCaps->SetSourceRefL(ptrStringPart); |
|
1461 |
|
1462 break; |
|
1463 |
|
1464 case EDisplayName: |
|
1465 dbCaps->SetDisplayNameL(ptrStringPart); |
|
1466 break; |
|
1467 |
|
1468 case EMaxGUIDSize: |
|
1469 dbCaps->SetMaxGuidSizeL(ptrStringPart); |
|
1470 break; |
|
1471 |
|
1472 case ERxPref: |
|
1473 separator = ptrStringPart.Locate(KTabSeparator()[0]); |
|
1474 dbCaps->SetRxPrefL(ptrStringPart.Left(separator),ptrStringPart.Right(ptrStringPart.Length()-separator-1)); |
|
1475 break; |
|
1476 |
|
1477 case ERx: |
|
1478 separator = ptrStringPart.Locate(KTabSeparator()[0]); |
|
1479 dbCaps->AddRxL(ptrStringPart.Left(separator),ptrStringPart.Right(ptrStringPart.Length()-separator-1)); |
|
1480 break; |
|
1481 |
|
1482 case ETxPref: |
|
1483 separator = ptrStringPart.Locate(KTabSeparator()[0]); |
|
1484 dbCaps->SetTxPrefL(ptrStringPart.Left(separator),ptrStringPart.Right(ptrStringPart.Length()-separator-1)); |
|
1485 break; |
|
1486 |
|
1487 |
|
1488 case ETx: |
|
1489 separator = ptrStringPart.Locate(KTabSeparator()[0]); |
|
1490 dbCaps->AddTxL(ptrStringPart.Left(separator),ptrStringPart.Right(ptrStringPart.Length()-separator-1)); |
|
1491 break; |
|
1492 |
|
1493 |
|
1494 case EDSMem: |
|
1495 break; |
|
1496 |
|
1497 case ESupportHierarchicalSync: |
|
1498 dbCaps->SetSupportHierarchicalSyncL(); |
|
1499 break; |
|
1500 |
|
1501 case ESyncCap: |
|
1502 break; |
|
1503 |
|
1504 default: |
|
1505 break; |
|
1506 |
|
1507 } |
|
1508 |
|
1509 start = i + 1; |
|
1510 firstFound = EFalse; |
|
1511 } |
|
1512 } |
|
1513 } |
|
1514 |
|
1515 CleanupStack::PopAndDestroy( pc ); // pc |
|
1516 |
|
1517 } |
|
1518 |
|
1519 CleanupStack::PopAndDestroy( 2 ); // sql, stringValue |
|
1520 |
|
1521 DBG_FILE(_S8("CNSmlDSAgentLog::GetServerDeviceInfoL ends")); |
|
1522 } |
|
1523 |
|
1524 //============================================= |
|
1525 // CNSmlDSAgentLog::SetServerFilterInfoL() |
|
1526 // Sets Server Filter Info given in parameter. |
|
1527 //============================================= |
|
1528 |
|
1529 EXPORT_C void CNSmlDSAgentLog::SetServerFilterInfoL( const CArrayFix<TNSmlFilterCapData>* aFilterInfoArr ) |
|
1530 { |
|
1531 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerFilterInfoL begins")); |
|
1532 _LIT8( KSeparator, ";"); |
|
1533 |
|
1534 CBufFlat* filterData = CBufFlat::NewL(8); |
|
1535 CleanupStack::PushL( filterData ); |
|
1536 TInt pos( 0 ); |
|
1537 TBuf8<6> buffer; //for num part |
|
1538 |
|
1539 for ( TInt i = 0; i < aFilterInfoArr->Count(); i++ ) |
|
1540 { |
|
1541 buffer.Num( ( TInt ) aFilterInfoArr->At( i ).iTag ); |
|
1542 filterData->InsertL( pos, buffer ); |
|
1543 pos += buffer.Length(); |
|
1544 |
|
1545 filterData->InsertL( pos, KSeparator ); |
|
1546 pos++; |
|
1547 |
|
1548 filterData->InsertL( pos, aFilterInfoArr->At( i ).iValue ); |
|
1549 pos += aFilterInfoArr->At( i ).iValue.Length(); |
|
1550 |
|
1551 filterData->InsertL( pos, KSeparator ); |
|
1552 pos++; |
|
1553 } |
|
1554 |
|
1555 TPtr8 stringValue = filterData->Ptr( 0 ); |
|
1556 |
|
1557 HBufC* stringValue16; |
|
1558 stringValue16 = HBufC::NewLC( stringValue.Size() * 2 ); |
|
1559 |
|
1560 TPtr ptrStringValue16( stringValue16->Des() ); |
|
1561 CnvUtfConverter::ConvertToUnicodeFromUtf8( ptrStringValue16, stringValue ); |
|
1562 |
|
1563 HBufC* sql = AgentLogRowSqlLC(); |
|
1564 |
|
1565 PrepareViewL( *sql, iView.EUpdatable ); |
|
1566 iDatabase.Begin(); |
|
1567 |
|
1568 RDbColReadStream in; |
|
1569 TInt oldFilterInfoSize(0); |
|
1570 if ( iView.FirstL() ) |
|
1571 { |
|
1572 iView.GetL(); |
|
1573 in.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ); |
|
1574 oldFilterInfoSize = in.Source()->SizeL(); |
|
1575 CleanupStack::PopAndDestroy(&in); |
|
1576 } |
|
1577 |
|
1578 RDbColWriteStream out; |
|
1579 if ( iView.FirstL() ) |
|
1580 { |
|
1581 //existing row |
|
1582 |
|
1583 // Check OOD before writing filter info on existing row |
|
1584 if ( (stringValue16->Size() > oldFilterInfoSize) && (SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
1585 (stringValue16->Size() - oldFilterInfoSize) + KNSmlAgentLogTreshold ))) |
|
1586 { |
|
1587 iDatabase.Rollback(); |
|
1588 User::Leave( KErrDiskFull ); |
|
1589 } |
|
1590 |
|
1591 // Update filter info |
|
1592 iView.GetL(); |
|
1593 iView.UpdateL(); |
|
1594 out.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ); |
|
1595 out.WriteL( ptrStringValue16 ); |
|
1596 out.Close(); |
|
1597 iView.PutL(); |
|
1598 } |
|
1599 else |
|
1600 { |
|
1601 //new row |
|
1602 |
|
1603 // Check OOD before inserting new row into AgentLog table |
|
1604 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
1605 KNSmlAgentLogMaxFixedLogRowSize + stringValue16->Size() + |
|
1606 KNSmlAgentLogTreshold ) ) |
|
1607 { |
|
1608 iDatabase.Rollback(); |
|
1609 User::Leave( KErrDiskFull ); |
|
1610 } |
|
1611 |
|
1612 // Insert new row |
|
1613 PrepareViewL( KSQLGetAgentLogAll, iView.EUpdatable ); |
|
1614 iID = GenerateIdL(); |
|
1615 iView.InsertL(); |
|
1616 iView.SetColL( iColSet->ColNo( KNSmlAgentLogId ), iID ); |
|
1617 out.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ); |
|
1618 out.WriteL( ptrStringValue16 ); |
|
1619 out.Close(); |
|
1620 iView.SetColL( iColSet->ColNo( KNSmlAgentLogImplementationUID ), iImplUid ); |
|
1621 iView.SetColL( iColSet->ColNo( KNSmlAgentLogLocalDatabase ), *iLocalDB ); |
|
1622 iView.SetColL( iColSet->ColNo( KNSmlAgentLogServerId ), *iServerId ); |
|
1623 iView.SetColL( iColSet->ColNo( KNSmlAgentLogRemoteDatabase ), *iRemoteDB ); |
|
1624 iView.PutL(); |
|
1625 } |
|
1626 |
|
1627 CommitAndCompact(); |
|
1628 CleanupStack::PopAndDestroy( 4 ); // sql, out, stringValue16, filterData |
|
1629 DBG_FILE(_S8("CNSmlDSAgentLog::SetServerFilterInfoL ends")); |
|
1630 } |
|
1631 |
|
1632 //============================================= |
|
1633 // CNSmlDSAgentLog::GetServerFilterInfoL() |
|
1634 // Gets Server Device Info. |
|
1635 //============================================= |
|
1636 |
|
1637 EXPORT_C void CNSmlDSAgentLog::GetServerFilterInfoL( CArrayFix<TNSmlFilterCapData>* aFilterInfoArr ) |
|
1638 { |
|
1639 DBG_FILE(_S8("CNSmlDSAgentLog::GetServerFilterInfoL begins")); |
|
1640 |
|
1641 HBufC* sql = AgentLogRowSqlLC(); |
|
1642 |
|
1643 PrepareViewL( *sql, iView.EReadOnly ); |
|
1644 |
|
1645 HBufC* stringValue; |
|
1646 |
|
1647 if ( iView.FirstL() ) |
|
1648 { |
|
1649 iView.GetL(); |
|
1650 RDbColReadStream in; |
|
1651 stringValue = HBufC::NewLC( iView.ColLength( iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ) ); |
|
1652 in.OpenLC( iView, iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ); |
|
1653 TPtr ptr = stringValue->Des(); |
|
1654 in.ReadL( ptr, iView.ColLength( iColSet->ColNo( KNSmlAgentLogServerFilterInfo ) ) ); |
|
1655 CleanupStack::PopAndDestroy( 1 ); // in |
|
1656 } |
|
1657 else |
|
1658 { |
|
1659 //couldn't find |
|
1660 CleanupStack::PopAndDestroy( 1 ); // sql |
|
1661 return; |
|
1662 } |
|
1663 |
|
1664 TInt start( 0 ); |
|
1665 TInt firstSeparator( 0 ); |
|
1666 TBool firstFound( EFalse ); |
|
1667 TLex lex; |
|
1668 TInt numPart( 0 ); |
|
1669 TPtr ptrStringValue = stringValue->Des(); |
|
1670 |
|
1671 for ( TInt i = 0; i < stringValue->Length(); i++ ) |
|
1672 { |
|
1673 if ( ptrStringValue[i] == ';' ) //; = separator |
|
1674 { |
|
1675 if ( !firstFound ) |
|
1676 { |
|
1677 firstSeparator = i; |
|
1678 firstFound = ETrue; |
|
1679 } |
|
1680 else |
|
1681 { |
|
1682 lex.Assign( stringValue->Mid( start, firstSeparator - start ) ); |
|
1683 lex.Val( numPart ); |
|
1684 |
|
1685 TPtrC ptrTemp = stringValue->Mid( firstSeparator + 1, i - firstSeparator - 1 ); |
|
1686 |
|
1687 HBufC8* stringPart = HBufC8::NewLC( ptrTemp.Length() ); |
|
1688 TPtr8 ptrStringPart = stringPart->Des(); |
|
1689 |
|
1690 CnvUtfConverter::ConvertFromUnicodeToUtf8( ptrStringPart, ptrTemp ); |
|
1691 |
|
1692 aFilterInfoArr->AppendL( TNSmlFilterCapData( TNSmlFilterCapData::TNSmlFilterCapTag(numPart), ptrStringPart ) ); |
|
1693 |
|
1694 CleanupStack::PopAndDestroy( 1 ); //stringPart |
|
1695 |
|
1696 start = i + 1; |
|
1697 firstFound = EFalse; |
|
1698 } |
|
1699 } |
|
1700 } |
|
1701 CleanupStack::PopAndDestroy( 2 ); // sql, stringValue |
|
1702 DBG_FILE(_S8("CNSmlDSAgentLog::GetServerFilterInfoL ends")); |
|
1703 } |
|
1704 |
|
1705 //============================================= |
|
1706 // CNSmlDSAgentLog::GenerateIdL() |
|
1707 // Generates a unique Id (Id's highest value before + 1) |
|
1708 // to a given table. |
|
1709 //============================================= |
|
1710 |
|
1711 TInt CNSmlDSAgentLog::GenerateIdL() |
|
1712 { |
|
1713 TInt lastKey( 0 ); |
|
1714 if ( iTableAgentLog.LastL() ) |
|
1715 { |
|
1716 iTableAgentLog.GetL(); |
|
1717 lastKey = iTableAgentLog.ColInt( iColSet->ColNo( KNSmlAgentLogId ) ); |
|
1718 iTableAgentLog.FirstL(); |
|
1719 iTableAgentLog.GetL(); |
|
1720 while ( iTableAgentLog.NextL() ) |
|
1721 { |
|
1722 iTableAgentLog.GetL(); |
|
1723 if ( lastKey < iTableAgentLog.ColInt( iColSet->ColNo( KNSmlAgentLogId ) ) ) |
|
1724 { |
|
1725 lastKey = iTableAgentLog.ColInt( iColSet->ColNo( KNSmlAgentLogId ) ); |
|
1726 } |
|
1727 } |
|
1728 } |
|
1729 return ( lastKey + 1 ); |
|
1730 } |
|
1731 |
|
1732 //============================================= |
|
1733 // CNSmlDSAgentLog::InitNewRowL() |
|
1734 // Initialises new row in Agent Log table |
|
1735 // |
|
1736 //============================================= |
|
1737 |
|
1738 void CNSmlDSAgentLog::InitNewRowL() |
|
1739 { |
|
1740 // Check OOD before inserting new row into AgentLog table |
|
1741 if ( SysUtil::FFSSpaceBelowCriticalLevelL( &iFsSession, |
|
1742 KNSmlAgentLogMaxFixedLogRowSize + KNSmlAgentLogTreshold ) ) |
|
1743 { |
|
1744 iDatabase.Rollback(); |
|
1745 User::Leave( KErrDiskFull ); |
|
1746 } |
|
1747 |
|
1748 // Insert new row |
|
1749 iID = GenerateIdL(); |
|
1750 iTableAgentLog.InsertL(); |
|
1751 iTableAgentLog.SetColL( iColSet->ColNo( KNSmlAgentLogId ), iID ); |
|
1752 iTableAgentLog.SetColL( iColSet->ColNo( KNSmlAgentLogImplementationUID ), iImplUid ); |
|
1753 iTableAgentLog.SetColL( iColSet->ColNo( KNSmlAgentLogLocalDatabase ), *iLocalDB ); |
|
1754 iTableAgentLog.SetColL( iColSet->ColNo( KNSmlAgentLogServerId ), *iServerId ); |
|
1755 iTableAgentLog.SetColL( iColSet->ColNo( KNSmlAgentLogRemoteDatabase ), *iRemoteDB ); |
|
1756 } |
|
1757 |
|
1758 //============================================= |
|
1759 // CNSmlDSAgentLog::AgentLogRowSqlLC() |
|
1760 // Makes SQL string for Agent Log table |
|
1761 // |
|
1762 //============================================= |
|
1763 |
|
1764 HBufC* CNSmlDSAgentLog::AgentLogRowSqlLC() const |
|
1765 { |
|
1766 HBufC* sql = HBufC::NewLC( KSQLGetAgentLogRowWithId().Length() + 5 ); |
|
1767 TPtr sqlPtr = sql->Des(); |
|
1768 sqlPtr.Format( KSQLGetAgentLogRowWithId, iID ); |
|
1769 return sql; |
|
1770 } |
|
1771 |
|
1772 //============================================= |
|
1773 // CNSmlDSAgentLog::AgentLogRowSqlLC() |
|
1774 // Makes SQL string for Authentication table |
|
1775 // |
|
1776 //============================================= |
|
1777 |
|
1778 HBufC* CNSmlDSAgentLog::AuthenticationSqlLC( const TDesC& aServerId ) const |
|
1779 { |
|
1780 HBufC* sql = HBufC::NewLC( KSQLGetAuthenticationRow().Length() + aServerId.Length() ); |
|
1781 TPtr sqlPtr = sql->Des(); |
|
1782 sqlPtr.Format( KSQLGetAuthenticationRow, &aServerId ); |
|
1783 return sql; |
|
1784 } |
|
1785 |
|
1786 //============================================= |
|
1787 // CNSmlDSAgentLog::PrepareViewL() |
|
1788 // Closes and prepares the view |
|
1789 // |
|
1790 //============================================= |
|
1791 |
|
1792 void CNSmlDSAgentLog::PrepareViewL( const TDesC& aSql, RDbRowSet::TAccess aAccess ) |
|
1793 { |
|
1794 iView.Close(); |
|
1795 User::LeaveIfError( iView.Prepare( iDatabase, TDbQuery( aSql ), aAccess ) ); |
|
1796 } |
|
1797 |
|
1798 //============================================= |
|
1799 // CNSmlDSAgentLog::CommitAndCompact |
|
1800 // Commits update and compacts the database |
|
1801 // |
|
1802 //============================================= |
|
1803 |
|
1804 void CNSmlDSAgentLog::CommitAndCompact() |
|
1805 { |
|
1806 iDatabase.Commit(); |
|
1807 iDatabase.Compact(); |
|
1808 } |
|
1809 |
|
1810 // <MAPINFO_RESEND_MOD_BEGIN> |
|
1811 |
|
1812 //============================================= |
|
1813 // |
|
1814 //============================================= |
|
1815 EXPORT_C MStreamBuf* CNSmlDSAgentLog::OpenReadStreamL( TUid aUid ) |
|
1816 { |
|
1817 DBG_FILE(_S8("CNSmlDSAgentLog::OpenReadStreamL(): begin")); |
|
1818 if( iReadStreamOpen ) |
|
1819 { |
|
1820 DBG_FILE(_S8("CNSmlDSAgentLog::OpenReadStreamL(): end (readstream already open)")); |
|
1821 User::Leave(KErrInUse); |
|
1822 } |
|
1823 |
|
1824 if( !IsPresentL(aUid) ) |
|
1825 { |
|
1826 DBG_FILE(_S8("CNSmlDSAgentLog::OpenReadStreamL(): end (readstream not found)")); |
|
1827 User::Leave(KErrNotFound); |
|
1828 } |
|
1829 |
|
1830 _LIT(KSQLStatement, "SELECT DatastoreData FROM Datastore WHERE DatastoreAID = %d AND DatastoreSID = %d"); |
|
1831 |
|
1832 HBufC* sqlStatement = HBufC::NewLC( KSQLStatement().Length() + 15); |
|
1833 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1834 |
|
1835 sqlStatementPtr.Format(KSQLStatement(), iID, aUid.iUid); |
|
1836 |
|
1837 // create a view on the database |
|
1838 User::LeaveIfError(iRSView.Prepare(iDatabase, TDbQuery(sqlStatementPtr, EDbCompareNormal), RDbRowSet::EReadOnly)); |
|
1839 User::LeaveIfError(iRSView.EvaluateAll()); |
|
1840 |
|
1841 // Get the structure of rowset |
|
1842 CDbColSet* colSet = iRSView.ColSetL(); |
|
1843 TDbColNo col = colSet->ColNo(KNSmlDatastoreStreamData()); // Ordinal position of long column |
|
1844 delete colSet; |
|
1845 |
|
1846 // get row |
|
1847 if( iRSView.FirstL() ) |
|
1848 { |
|
1849 iRSView.GetL(); |
|
1850 iRs.OpenL(iRSView, col); |
|
1851 } |
|
1852 |
|
1853 iReadStreamOpen = ETrue; |
|
1854 |
|
1855 DBG_FILE(_S8("CNSmlDSAgentLog::OpenReadStreamL(): end")); |
|
1856 |
|
1857 CleanupStack::PopAndDestroy(); // sqlStatement |
|
1858 |
|
1859 return iRs.Source(); |
|
1860 } |
|
1861 |
|
1862 //============================================= |
|
1863 // Open writestream for Uid |
|
1864 //============================================= |
|
1865 EXPORT_C MStreamBuf* CNSmlDSAgentLog::OpenWriteStreamL( TUid aUid ) |
|
1866 { |
|
1867 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): begin")); |
|
1868 if( iWriteStreamOpen ) |
|
1869 { |
|
1870 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): end (writestream already open)")); |
|
1871 User::Leave(KErrInUse); |
|
1872 } |
|
1873 |
|
1874 if( !IsPresentL(aUid) ) |
|
1875 { |
|
1876 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): creating new stream begin")); |
|
1877 iDatabase.Begin(); |
|
1878 RDbView view; |
|
1879 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(KSQLGetDatastoreAll()), RDbView::EUpdatable)); |
|
1880 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): Preparing view successful")); |
|
1881 CleanupClosePushL(view); |
|
1882 view.InsertL(); |
|
1883 view.SetColL( iColSetTableDS->ColNo( KNSmlDatastoreAgentlogID ), iID ); |
|
1884 view.SetColL( iColSetTableDS->ColNo( KNSmlDatastoreStreamID ), aUid.iUid ); |
|
1885 view.PutL(); |
|
1886 CleanupStack::PopAndDestroy(); // view |
|
1887 CommitAndCompact(); |
|
1888 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): creating new stream end")); |
|
1889 } |
|
1890 |
|
1891 _LIT(KSQLStatement, "SELECT DatastoreData FROM Datastore WHERE DatastoreAID = %d AND DatastoreSID = %d"); |
|
1892 |
|
1893 HBufC* sqlStatement = HBufC::NewLC( KSQLStatement().Length() + 15 ); |
|
1894 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1895 sqlStatementPtr.Format(KSQLStatement(), iID, aUid.iUid); |
|
1896 |
|
1897 // create a view on the database |
|
1898 User::LeaveIfError(iWSView.Prepare(iDatabase, TDbQuery(sqlStatementPtr, EDbCompareNormal), RDbRowSet::EUpdatable)); |
|
1899 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): Preparing view successful (second)")); |
|
1900 User::LeaveIfError(iWSView.EvaluateAll()); |
|
1901 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): EvaluateAll successful...")); |
|
1902 |
|
1903 // Get the structure of rowset |
|
1904 CDbColSet* colSet = iWSView.ColSetL(); |
|
1905 TDbColNo col = colSet->ColNo(KNSmlDatastoreStreamData()); // Ordinal position of long column |
|
1906 delete colSet; |
|
1907 |
|
1908 // get row |
|
1909 if( iWSView.FirstL() ) |
|
1910 { |
|
1911 iWSView.UpdateL(); |
|
1912 iWs.OpenL(iWSView, col); |
|
1913 } |
|
1914 |
|
1915 iWriteStreamOpen = ETrue; |
|
1916 |
|
1917 DBG_FILE(_S8("CNSmlDSAgentLog::OpenWriteStreamL(): end")); |
|
1918 |
|
1919 CleanupStack::PopAndDestroy(); // sqlStatement |
|
1920 |
|
1921 return iWs.Sink(); |
|
1922 } |
|
1923 |
|
1924 //============================================= |
|
1925 // Check if Uid already in use |
|
1926 //============================================= |
|
1927 EXPORT_C TBool CNSmlDSAgentLog::IsPresentL( TUid aUid ) |
|
1928 { |
|
1929 DBG_FILE(_S8("CNSmlDSAgentLog::IsPresentL(): begin")); |
|
1930 _LIT(KSQLStatement, "SELECT DatastoreData FROM Datastore WHERE DatastoreAID = %d AND DatastoreSID = %d"); |
|
1931 |
|
1932 HBufC* sqlStatement = HBufC::NewLC( KSQLStatement().Length() + 15); |
|
1933 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1934 |
|
1935 sqlStatementPtr.Format(KSQLStatement(), iID, aUid.iUid); |
|
1936 RDbView view; |
|
1937 User::LeaveIfError(view.Prepare(iDatabase, TDbQuery(sqlStatementPtr, EDbCompareNormal), RDbRowSet::EReadOnly)); |
|
1938 CleanupClosePushL(view); |
|
1939 User::LeaveIfError(view.EvaluateAll()); |
|
1940 TBool result(!view.IsEmptyL()); |
|
1941 DBG_FILE_CODE( result, _S8("CNSmlDSAgentLog::IsPresentL(): IsEmpty called...") ); |
|
1942 |
|
1943 CleanupStack::PopAndDestroy(2); // view, sqlStatement |
|
1944 |
|
1945 DBG_FILE(_S8("CNSmlDSAgentLog::IsPresentL(): end")); |
|
1946 return result; |
|
1947 } |
|
1948 |
|
1949 //============================================= |
|
1950 // Delete stream for Uid |
|
1951 //============================================= |
|
1952 EXPORT_C void CNSmlDSAgentLog::DeleteStreamL( TUid aUid ) |
|
1953 { |
|
1954 DBG_FILE(_S8("CNSmlDSAgentLog::DeleteStreamL(): begin")); |
|
1955 _LIT( KSQLDeleteDatastoreRow, "DELETE FROM Datastore WHERE DatastoreAID = %d AND DatastoreSID = %d" ); |
|
1956 |
|
1957 HBufC* sqlStatement = HBufC::NewLC( KSQLDeleteDatastoreRow().Length() + 15); |
|
1958 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1959 |
|
1960 sqlStatementPtr.Format(KSQLDeleteDatastoreRow(), iID, aUid.iUid); |
|
1961 iDatabase.Begin(); |
|
1962 TInt err = iDatabase.Execute(sqlStatementPtr); |
|
1963 if( err < KErrNone ) |
|
1964 { |
|
1965 iDatabase.Rollback(); |
|
1966 } |
|
1967 else |
|
1968 { |
|
1969 iDatabase.Commit(); |
|
1970 } |
|
1971 iDatabase.Compact(); |
|
1972 |
|
1973 CleanupStack::PopAndDestroy(); // sqlStatement |
|
1974 DBG_FILE(_S8("CNSmlDSAgentLog::DeleteStreamL(): end")); |
|
1975 } |
|
1976 |
|
1977 //============================================= |
|
1978 // Delete stream for datastore |
|
1979 //============================================= |
|
1980 EXPORT_C void CNSmlDSAgentLog::DeleteStoreL() |
|
1981 { |
|
1982 DBG_FILE(_S8("CNSmlDSAgentLog::DeleteStoreL(): begin")); |
|
1983 _LIT( KSQLDeleteDatastore, "DELETE FROM Datastore WHERE DatastoreAID = %d" ); |
|
1984 |
|
1985 HBufC* sqlStatement = HBufC::NewLC( KSQLDeleteDatastore().Length() + 15); |
|
1986 TPtr sqlStatementPtr = sqlStatement->Des(); |
|
1987 |
|
1988 sqlStatementPtr.Format(KSQLDeleteDatastore(), iID); |
|
1989 iDatabase.Begin(); |
|
1990 TInt err = iDatabase.Execute(sqlStatementPtr); |
|
1991 if( err < KErrNone ) |
|
1992 { |
|
1993 iDatabase.Rollback(); |
|
1994 } |
|
1995 else |
|
1996 { |
|
1997 iDatabase.Commit(); |
|
1998 } |
|
1999 iDatabase.Compact(); |
|
2000 |
|
2001 CleanupStack::PopAndDestroy(); // sqlStatement |
|
2002 |
|
2003 DBG_FILE(_S8("CNSmlDSAgentLog::DeleteStoreL(): end")); |
|
2004 } |
|
2005 |
|
2006 //============================================= |
|
2007 // Close write stream |
|
2008 //============================================= |
|
2009 EXPORT_C void CNSmlDSAgentLog::CloseWriteStreamL( TBool aCommit ) |
|
2010 { |
|
2011 DBG_FILE(_S8("CNSmlDSAgentLog::CloseWriteStreamL(): begin")); |
|
2012 if( !iWriteStreamOpen ) |
|
2013 { |
|
2014 DBG_FILE(_S8("CNSmlDSAgentLog::CloseWriteStreamL(): end (no writestream open)")); |
|
2015 return; |
|
2016 } |
|
2017 iWs.Close(); |
|
2018 if( aCommit ) |
|
2019 { |
|
2020 // Check OOD before saving |
|
2021 if (SysUtil::FFSSpaceBelowCriticalLevelL(&iFsSession, KNSmlAgentLogFatMinSize)) |
|
2022 { |
|
2023 iWSView.Close(); |
|
2024 iWriteStreamOpen = EFalse; |
|
2025 User::Leave( KErrDiskFull ); |
|
2026 } |
|
2027 iWSView.PutL(); |
|
2028 } |
|
2029 else |
|
2030 { |
|
2031 iWSView.Cancel(); |
|
2032 } |
|
2033 iWSView.Close(); |
|
2034 iWriteStreamOpen = EFalse; |
|
2035 DBG_FILE(_S8("CNSmlDSAgentLog::CloseWriteStreamL(): end")); |
|
2036 } |
|
2037 |
|
2038 //============================================= |
|
2039 // Close read stream |
|
2040 //============================================= |
|
2041 EXPORT_C void CNSmlDSAgentLog::CloseReadStreamL() |
|
2042 { |
|
2043 DBG_FILE(_S8("CNSmlDSAgentLog::CloseReadStreamL(): begin")); |
|
2044 if( !iReadStreamOpen ) |
|
2045 { |
|
2046 return; |
|
2047 } |
|
2048 iRs.Close(); |
|
2049 iRSView.Close(); |
|
2050 iReadStreamOpen = EFalse; |
|
2051 DBG_FILE(_S8("CNSmlDSAgentLog::CloseReadStreamL(): end")); |
|
2052 } |
|
2053 |
|
2054 // <MAPINFO_RESEND_MOD_END> |
|
2055 |
|
2056 //End of File |