author | hgs |
Tue, 19 Oct 2010 16:26:13 +0100 | |
changeset 55 | 44f437012c90 |
parent 51 | 7d4490026038 |
permissions | -rw-r--r-- |
17
55f2396f6d25
Revision: 201018
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
15
diff
changeset
|
1 |
// Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). |
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
2 |
// All rights reserved. |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
3 |
// This component and the accompanying materials are made available |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
4 |
// under the terms of "Eclipse Public License v1.0" |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
5 |
// which accompanies this distribution, and is available |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
7 |
// |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
8 |
// Initial Contributors: |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
9 |
// Nokia Corporation - initial contribution. |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
10 |
// |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
11 |
// Contributors: |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
12 |
// |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
13 |
// Description: |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
14 |
// |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
15 |
|
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
16 |
#ifndef __SQLBUR_H__ |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
17 |
#define __SQLBUR_H__ |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
18 |
|
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
19 |
#include <e32base.h> |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
20 |
#include <f32file.h> |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
21 |
#include <f32file64.h> |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
22 |
#include <e32property.h> |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
23 |
#include <connect/abclient.h> // MactiveBackupDataClient |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
24 |
#include "SqlSrvBurInterface.h" |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
25 |
|
51 | 26 |
//Forward declarations |
27 |
class CSqlBurCallback; |
|
28 |
||
29 |
#ifdef SQL_BUR_PROPERTY_MONITOR_TEST |
|
30 |
||
31 |
const TInt32 KSqlBurPropertyCategory = 0x10281e17;//the SQL server secure id (the bur tests have the same id, |
|
32 |
//in order to be able to operate with the property) |
|
33 |
const TUint KSqlBurBackupRestoreKeyValue = 0x1234DDD1; |
|
34 |
||
35 |
extern TInt TestModeSqlBurError; |
|
36 |
#define SQL_BUR_TEST_SET_ERROR(err) TestModeSqlBurError = err |
|
37 |
//This macro is called at the end of CSqlBurEventMonitor::RunL()and CSqlBurEventMonitor::RunError() |
|
38 |
//CActiveScheduler::Stop() is called here to return the execution control back to the test code. |
|
39 |
#define SQL_BUR_TEST_STOP() CActiveScheduler::Stop() |
|
40 |
||
41 |
#else |
|
42 |
||
43 |
const TInt32 KSqlBurPropertyCategory = KUidSystemCategoryValue; |
|
44 |
const TUint KSqlBurBackupRestoreKeyValue = conn::KUidBackupRestoreKey; |
|
45 |
||
46 |
#define SQL_BUR_TEST_SET_ERROR(err) (void)0 |
|
47 |
#define SQL_BUR_TEST_STOP() (void)0 |
|
48 |
||
49 |
#endif |
|
50 |
||
51 |
/** |
|
52 |
The system category of the backup and restore property, that is used for notifying active backup clients |
|
53 |
regarding beginning or the end of backup or restore process. |
|
54 |
Different value is used in SQL tests, because only the secure backup server can set or get the value of |
|
55 |
the {KUidSystemCategoryValue, conn::KUidBackupRestoreKey} property. |
|
56 |
@internalComponent |
|
57 |
*/ |
|
58 |
const TUid KSqlBurPropertyCategoryUid = {KSqlBurPropertyCategory}; |
|
59 |
||
60 |
/** |
|
61 |
The backup and restore property key, that is used for notifying active backup clients |
|
62 |
regarding beginning or the end of backup or restore process. |
|
63 |
Different value is used in SQL tests, because only the secure backup server can set or get the value of |
|
64 |
the {KUidSystemCategoryValue, conn::KUidBackupRestoreKey} property. |
|
65 |
@internalComponent |
|
66 |
*/ |
|
67 |
const TUint KSqlBurBackupRestoreKey = KSqlBurBackupRestoreKeyValue; |
|
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
68 |
|
15
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
69 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
70 |
////////////// Backup database file header format /////////////////// |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
71 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
72 |
|
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
73 |
////// No version (Version 0) |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
74 |
// 8 chars 8 chars 8 chars up to 256 characters (512 bytes) |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
75 |
// <32-bit checksum><32-bit filesize><32-bit filenamelen><filename - UTF16 encoded> |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
76 |
|
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
77 |
////// Version 2 |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
78 |
// 8 chars 8 chars 4 chars 16 chars 8 chars up to 256 characters (512 bytes) |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
79 |
// <32-bit checksum><FFFFAA55><Version N#><64-bit filesize><32-bit filenamelen><filename - UTF16 encoded> |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
80 |
|
51 | 81 |
const TInt KSqlBurHeaderVersion = 2; //Current backup database file header version |
15
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
82 |
|
51 | 83 |
const TUint32 KSqlBurMagicNum = 0xFFFFAA55; //Magic number. If the "old database file size" field in the header |
84 |
//has this value, then the header version is 2+ |
|
85 |
const TInt KSqlBurMaxHeaderSize = 256 + KMaxFileName; //The size of the buffer used for the operations on the header |
|
15
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
86 |
|
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
87 |
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
88 |
|
51 | 89 |
/** |
90 |
An object of this class is created to monitor the backup & restore property |
|
91 |
{KUidSystemCategory, KUidBackupRestoreKey}. |
|
92 |
If the property gets set, the CSqlBurEventMonitor object will create a CSqlBurClient |
|
93 |
instance to handle the backup or restore. |
|
15
3eacc0623088
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
94 |
|
51 | 95 |
@internalComponent |
96 |
*/ |
|
97 |
class CSqlBurEventMonitor : public CActive |
|
98 |
{ |
|
99 |
public: |
|
100 |
static CSqlBurEventMonitor* NewL(MSqlSrvBurInterface& aBufInterface); |
|
101 |
virtual ~CSqlBurEventMonitor(); |
|
102 |
#ifdef SQL_BUR_PROPERTY_MONITOR_TEST |
|
103 |
inline conn::CActiveBackupClient* ActiveBackupClient(); |
|
104 |
inline CSqlBurCallback* SqlBurCallback(); |
|
105 |
#endif |
|
106 |
||
107 |
private: |
|
108 |
CSqlBurEventMonitor(MSqlSrvBurInterface& aInterface); |
|
109 |
void ConstructL(); |
|
110 |
virtual void RunL(); |
|
111 |
virtual void DoCancel(); |
|
112 |
virtual TInt RunError(TInt aError); |
|
113 |
void CreateContentL(); |
|
114 |
void DestroyContent(); |
|
115 |
||
116 |
private: |
|
117 |
RProperty iBurProperty;//B&R property published by the B&R server. SQL server subscribes for notifications |
|
118 |
MSqlSrvBurInterface& iBurInterface;//Provided by the SQL server |
|
119 |
conn::CActiveBackupClient* iActiveBackupClient;//The connection with the B&R server |
|
120 |
CSqlBurCallback* iSqlBurCallback;//A "Database file list" interface provided by the SQL server |
|
121 |
||
122 |
}; |
|
123 |
||
124 |
#ifdef SQL_BUR_PROPERTY_MONITOR_TEST |
|
125 |
||
126 |
inline conn::CActiveBackupClient* CSqlBurEventMonitor::ActiveBackupClient() |
|
127 |
{ |
|
128 |
return iActiveBackupClient; |
|
129 |
} |
|
130 |
||
131 |
inline CSqlBurCallback* CSqlBurEventMonitor::SqlBurCallback() |
|
132 |
{ |
|
133 |
return iSqlBurCallback; |
|
134 |
} |
|
135 |
||
136 |
#endif |
|
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
137 |
|
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
138 |
/** |
51 | 139 |
This class is called by the Backup and Restore Framework |
140 |
when a backup or restore is requested by the user |
|
141 |
It implements the active proxy backup and restore as |
|
142 |
defined in the MActiveBackupDataClient interface. |
|
143 |
||
144 |
@internalComponent |
|
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
145 |
*/ |
51 | 146 |
class CSqlBurCallback : public CBase, public conn::MActiveBackupDataClient |
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
147 |
{ |
51 | 148 |
public: |
149 |
static CSqlBurCallback* NewL(MSqlSrvBurInterface& aBufInterface); |
|
150 |
virtual ~CSqlBurCallback(); |
|
151 |
||
152 |
//Implementations of virtuals from MActiveBackupDataClient - full backup |
|
153 |
virtual void InitialiseGetProxyBackupDataL(TSecureId aSid, TDriveNumber aDrive); |
|
154 |
virtual TUint GetExpectedDataSize(TDriveNumber aDrive); |
|
155 |
virtual void GetBackupDataSectionL(TPtr8& aBuffer, TBool& aFinished); |
|
156 |
||
157 |
//Implementations of virtuals from MActiveBackupDataClient - full restore |
|
158 |
virtual void InitialiseRestoreProxyBaseDataL(TSecureId aSid, TDriveNumber aDrive); |
|
159 |
virtual void RestoreComplete(TDriveNumber aDrive); |
|
160 |
virtual void RestoreBaseDataSectionL(TDesC8& aBuffer, TBool aFinished); |
|
161 |
||
162 |
virtual void TerminateMultiStageOperation(); |
|
163 |
virtual TUint GetDataChecksum(TDriveNumber aDrive); |
|
164 |
||
165 |
//Implementations of virtuals from MActiveBackupDataClient - incremental backup & restore - not supported |
|
166 |
virtual void AllSnapshotsSuppliedL(); |
|
167 |
virtual void ReceiveSnapshotDataL(TDriveNumber aDrive, TDesC8& aBuffer, TBool aLastSection); |
|
168 |
virtual void GetSnapshotDataL(TDriveNumber aDrive, TPtr8& aBuffer, TBool& aFinished); |
|
169 |
virtual void InitialiseGetBackupDataL(TDriveNumber aDrive); |
|
170 |
virtual void InitialiseRestoreBaseDataL(TDriveNumber aDrive); |
|
171 |
virtual void InitialiseRestoreIncrementDataL(TDriveNumber aDrive); |
|
172 |
virtual void RestoreIncrementDataSectionL(TDesC8& aBuffer, TBool aFinished); |
|
173 |
||
174 |
// to validate successful BUR |
|
175 |
TInt CheckSum(const RFile64 &aOpenFile, TUint64& aCheckSum) const; |
|
176 |
||
177 |
private: |
|
178 |
CSqlBurCallback(MSqlSrvBurInterface& aInterface); |
|
179 |
void CopyBufData(const TDesC8& aInBuf, TInt& aInBufReadPos, TDes& aOutBuf, TInt aDataLen); |
|
180 |
void BackupCleanup(); |
|
181 |
TInt RestoreCleanup(); |
|
182 |
void SetBackupError(TInt aError); |
|
183 |
||
184 |
private: |
|
185 |
||
186 |
// state machine for backup |
|
187 |
enum |
|
188 |
{ |
|
189 |
EBackupNoFileOpen=0, // not currently processing a file |
|
190 |
EBackupOpenNothingSent, // file open and ready, but nothing sent yet |
|
191 |
EBackupOpenPartHeaderSent, // part of the header is sent, but more remains |
|
192 |
EBackupOpenAllHeaderSent, // all of the header is sent, ready to send the data |
|
193 |
EBackupEndOfFile // all done, tidy up after backup |
|
194 |
}; |
|
195 |
||
196 |
// state machine for restore |
|
197 |
// this is more complicated because we are driven by the backup engine |
|
198 |
// and have incomplete information most of the time |
|
199 |
enum |
|
200 |
{ |
|
201 |
ERestoreExpectChecksum=0, // checksum marks the start of the next file |
|
202 |
ERestoreExpectOldFileSize, // the size of the file - backup file header version 0 |
|
203 |
ERestoreExpectVersion, // backup header version |
|
204 |
ERestoreExpectFileSize, // the size of the file, backup file header version 2+ |
|
205 |
ERestoreExpectFileNameSize, // the size of the file name |
|
206 |
ERestoreExpectFileName, // the name of the file to restore |
|
207 |
ERestoreExpectData, // now for the data |
|
208 |
ERestoreComplete // tidy up after restore |
|
209 |
}; |
|
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
210 |
|
51 | 211 |
MSqlSrvBurInterface& iInterface; //A "Database file list" interface provided by the SQL server |
212 |
RArray<HBufC*> iFileList; //An array with database file names for backup, provided by the SQL server |
|
213 |
RFile64 iFile; //A handle to file being backup/restored. |
|
214 |
TInt iFileIndex; //The index of the file name in iFileList being processed at the moment |
|
215 |
TUint iState; //Backup or restore state machine - current state |
|
216 |
TBuf<KSqlBurMaxHeaderSize> iBuffer; //Used for the header data |
|
217 |
TInt iHeaderSent; //How many header bytes sent so far |
|
218 |
TUint32 iChecksum; //Database archive checksum - used by the restore. |
|
219 |
TInt64 iFileSize; //Restored database file size - used by the restore. |
|
220 |
TUint32 iFileNameSize; //Restored database file name size - used by the restore. |
|
221 |
TDriveNumber iRestoreDrive; //The drive where the data is currently restored to. |
|
222 |
TSecureId iRestoreId; //The secure id of the client which data is being restored at the moment |
|
223 |
TInt iBackupError; //An error occured during the backup processing |
|
224 |
TFileName iRestoreDir; //The directory where temporary files will be created during restore. |
|
225 |
TParse iParse; |
|
0
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
226 |
|
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
227 |
}; |
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
228 |
|
08ec8eefde2f
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
diff
changeset
|
229 |
#endif // __SQLBUR_H__ |