|
1 /* |
|
2 * Copyright (c) 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: DS Sync flow |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef __NSMLDSCMDS_H__ |
|
20 #define __NSMLDSCMDS_H__ |
|
21 |
|
22 // INCLUDES |
|
23 #include <e32base.h> |
|
24 #include <SmlDataSyncDefs.h> |
|
25 #include "NSmlCmdsBase.h" |
|
26 #include "WBXMLDevInfParser.h" |
|
27 #include "nsmlagentlog.h" |
|
28 |
|
29 // FORWARD DECLARATIONS |
|
30 class CNSmlAgentBase; |
|
31 class CNSmlDSContent; |
|
32 class MSyncMLProgressObserver; |
|
33 class CWBXMLDevInfGenerator; |
|
34 class CWBXMLDevInfDocHandler; |
|
35 class CNSmlDbCaps; |
|
36 class CNSmlDbMetaHandler; |
|
37 class CNSmlDSBatchBuffer; |
|
38 |
|
39 inline void DeleteRPointerArray( TAny* aPtr ) |
|
40 { |
|
41 ( REINTERPRET_CAST ( RPointerArray<CNSmlDbCaps>*, aPtr ) )->ResetAndDestroy(); |
|
42 } |
|
43 |
|
44 // CLASS DECLARATION |
|
45 |
|
46 /** |
|
47 * CNSmlDSCmds implements DS specific parts of SyncML commands handling. |
|
48 * |
|
49 * @lib nsmldsagent.lib |
|
50 */ |
|
51 class CNSmlDSCmds : public CNSmlCmdsBase, public MWBXMLDevInfCallbacks |
|
52 { |
|
53 public: // constructors and destructor |
|
54 /** |
|
55 * Symbian 2-phased constructor. |
|
56 * @param aAgent Used synchronisation agent. |
|
57 * @param aSessionID Sync session Id. |
|
58 * @param aVerProto DS protocol version. |
|
59 * @param aPublicId Public Id of the used DS protocol. |
|
60 * @param aSyncMLUserName SyncML server username. |
|
61 * @param aSyncServer Used SyncML server's URI. |
|
62 * @param aDSContent Object used to handle datastore specific operations. |
|
63 * @param aDSObserver Observer callback. |
|
64 * @param aVersionCheck Whether the protocol version is checked or not. |
|
65 */ |
|
66 static CNSmlDSCmds* NewL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const TInt aPublicId, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, CNSmlDSContent& aDSContent, MSyncMLProgressObserver& aDSObserver, TBool aVersionCheck ); |
|
67 |
|
68 /** |
|
69 * Destructor. |
|
70 */ |
|
71 virtual ~CNSmlDSCmds(); |
|
72 |
|
73 public: // functions from base classes |
|
74 /** |
|
75 * From CNSmlCmdsBase. Builds a structure for the Alert command and calls |
|
76 * the WBXML generator. |
|
77 * @param aAlertCode Aler code. |
|
78 * @param aLastSyncAnchor Anchor/Last value to be inserted to the command. |
|
79 * @param aNextSyncAnchor Anchor/Next value to be inserted to the command. |
|
80 */ |
|
81 void DoAlertL( const TDesC8& aAlertCode, TTime* aLastSyncAnchor = NULL, TTime* aNextSyncAnchor = NULL ); |
|
82 |
|
83 /** |
|
84 * From CNSmlCmdsBase. Builds a structure for the Put command. A DevInfo |
|
85 * structure is constructed inside the Put. Finally the WBXML generator |
|
86 * is called. |
|
87 */ |
|
88 void DoPutL(); |
|
89 |
|
90 /** |
|
91 * From CNSmlCmdsBase. Builds a structure for the Results command. A DevInfo |
|
92 * structure is constructed inside the Results element. As a last step the |
|
93 * WBXML generator is called. |
|
94 * @return EReturnOK if the operation succeeded. |
|
95 */ |
|
96 CNSmlCmdsBase::TReturnValue DoResultsL(); |
|
97 |
|
98 /** |
|
99 * From CNSmlCmdsBase. Builds a structure for the Get command. This is used |
|
100 * to ask DevInfo from the server. At the end of this function the WBXML |
|
101 * generator is called. |
|
102 */ |
|
103 void DoGetL(); |
|
104 |
|
105 /** |
|
106 * From CNSmlCmdsBase. Builds a structure for the Sync command. Calls the |
|
107 * WBXML generator. |
|
108 * @return EReturnOK if completed successfully. |
|
109 */ |
|
110 CNSmlCmdsBase::TReturnValue DoStartSyncL(); |
|
111 |
|
112 /** |
|
113 * From CNSmlCmdsBase. Completes the generation of the Sync command. |
|
114 */ |
|
115 void DoEndSyncL(); |
|
116 |
|
117 /** |
|
118 * From CNSmlCmdsBase. Builds a structure for Add, Replace, Delete or Move |
|
119 * command. Content's data is retrieved via the CNSmlDSContent::FetchNextItemL |
|
120 * method. Finally the WBXML generator is called. |
|
121 * @return EReturnOK if completed without errors. |
|
122 */ |
|
123 CNSmlCmdsBase::TReturnValue DoAddOrReplaceOrDeleteL(); |
|
124 |
|
125 /** |
|
126 * From CNSmlCmdsBase. Builds a structure for the Map command. Map items are |
|
127 * retrieved by the CNSmlDSMapContainer::MapItemListL method. The WBXML |
|
128 * generator is called. |
|
129 * @return EReturnOK if completed successfully. |
|
130 */ |
|
131 CNSmlCmdsBase::TReturnValue DoMapL(); |
|
132 |
|
133 /** |
|
134 * From CNSmlCmdsBase. Handles the Results command received from a server. |
|
135 * The ParseDeviceInfoL function is called in order to process the received |
|
136 * DevInfo structure. |
|
137 * @param aResults The received Results element. |
|
138 */ |
|
139 void ProcessResultsCmdL( SmlResults_t* aResults ); |
|
140 |
|
141 /** |
|
142 * From CNSmlCmdsBase. Handles the Put command received from a server. |
|
143 * The ParseDeviceInfoL function is called in order to process the received |
|
144 * DevInfo structure. |
|
145 * @param aPut The received Put element. |
|
146 */ |
|
147 void ProcessPutCmdL( SmlPut_t* aPut ); |
|
148 |
|
149 /** |
|
150 * From CNSmlCmdsBase. Handles the Get command received from a server. |
|
151 * @param aGet The received Get element. |
|
152 */ |
|
153 void ProcessGetCmdL( SmlGet_t* aGet ); |
|
154 |
|
155 /** |
|
156 * From CNSmlCmdsBase. Handles the Alert command received from a server. |
|
157 * The CNSmlDSContent::SetIndexByLocalDatabaseL() function is called |
|
158 * to find the correct data store. In case of initialization Alert command |
|
159 * the received sync type is validated. |
|
160 * @param aAlert The received Alert element. |
|
161 * @param aNextAlert ETrue if the Alert is Next Alert. |
|
162 * @param aServerAlert ETrue if the Alert is Server Alert. |
|
163 * @param aDisplayAlert ETrue if the Alert is Display Alert. |
|
164 */ |
|
165 void ProcessAlertCmdL( SmlAlert_t* aAlert, TBool aNextAlert = EFalse, TBool aServerAlert = EFalse, TBool aDisplayAlert = EFalse ); |
|
166 |
|
167 /** |
|
168 * From CNSmlCmdsBase. Handles the Sync command received from a server. |
|
169 * The CNSmlDSContent::SetIndexByLocalDatabaseL() function is called |
|
170 * to find the correct data store. |
|
171 * @param aSync The received Sync element. |
|
172 */ |
|
173 void ProcessSyncL( SmlSync_t* aSync ); |
|
174 |
|
175 /** |
|
176 * From CNSmlCmdsBase. Handles the end of the received Sync command. |
|
177 */ |
|
178 void ProcessEndSyncL(); |
|
179 |
|
180 /** |
|
181 * From CNSmlCmdsBase. Handles the received Add, Replace, Delete and Move |
|
182 * commands. The UpdateL() function is called to handle items in the command. |
|
183 * @param aCmd Type of the received command. |
|
184 * @param aContent Content of the received command. |
|
185 */ |
|
186 void ProcessUpdatesL( const TDesC8& aCmd, SmlGenericCmd_t* aContent ); |
|
187 |
|
188 /** |
|
189 * From CNSmlCmdsBase. Handles the received Atomic command. Inside Atomic all |
|
190 * operations to data stores are performed in a transactional way. The received |
|
191 * Atomic command fails if the used data store does not support transactions. |
|
192 * @param aAtomic The received Atomic command. |
|
193 */ |
|
194 void ProcessAtomicL( SmlAtomic_t* aAtomic ); |
|
195 |
|
196 /** |
|
197 * From CNSmlCmdsBase. Handles the end of a previously received Atomic command. |
|
198 * All transactions are committed and their results checked. If any of the operations |
|
199 * has failed then all of them will be rolled back. |
|
200 */ |
|
201 void ProcessEndAtomicL(); |
|
202 |
|
203 /** |
|
204 * From CNSmlCmdsBase. An empty implementation. |
|
205 * @param aSequence The received Sequence element. |
|
206 */ |
|
207 void ProcessSequenceL( SmlSequence_t* aSequence); |
|
208 |
|
209 /** |
|
210 * From CNSmlCmdsBase. An empty implementation. |
|
211 */ |
|
212 void ProcessEndSequence(); |
|
213 |
|
214 /** |
|
215 * From CNSmlCmdsBase. Generates the end tag of the SyncML element. |
|
216 * @param aFinal ETrue if this is the last message from the client. |
|
217 */ |
|
218 void DoEndMessageL( TBool aFinal ); |
|
219 |
|
220 private: // constructors and operators |
|
221 /** |
|
222 * C++ constructor. |
|
223 * @param aDSContent Object used to handle datastore specific operations. |
|
224 * @param aDSObserver Observer callback. |
|
225 */ |
|
226 CNSmlDSCmds( CNSmlDSContent& aDSContent, MSyncMLProgressObserver& aDSObserver ); |
|
227 |
|
228 /** |
|
229 * Symbian 2nd phase constructor. |
|
230 * @param aAgent Used synchronisation agent. |
|
231 * @param aSessionID Sync session Id. |
|
232 * @param aVerProto DS protocol version. |
|
233 * @param aPublicId Public Id of the used DS protocol. |
|
234 * @param aSyncMLUserName SyncML server username. |
|
235 * @param aSyncServer Used SyncML server's URI. |
|
236 * @param aVersionCheck Whether the protocol version is checked or not. |
|
237 */ |
|
238 void ConstructL( CNSmlAgentBase* aAgent, const TDesC8& aSessionID, const TDesC8& aVerProto, const TInt aPublicId, const HBufC& aSyncMLUserName, CNSmlURI* aSyncServer, TBool aVersionCheck ); |
|
239 |
|
240 /** |
|
241 * Prohibit copy constructor. |
|
242 */ |
|
243 CNSmlDSCmds( const CNSmlDSCmds& aOther ); |
|
244 |
|
245 /** |
|
246 * Prohibit assignment operator. |
|
247 */ |
|
248 CNSmlDSCmds& operator=( const CNSmlDSCmds& aOther ); |
|
249 |
|
250 private: // functions from base classes |
|
251 /** |
|
252 * From MWBXMLDevInfCallbacks. Callback function used by the DevInfo parser. |
|
253 * @param aContent Pointer to the parsed content. |
|
254 * @return Return code defined in the SyncML toolkit. |
|
255 */ |
|
256 Ret_t smlDeviceInfoL( SmlDevInfDevInfPtr_t aContent ); |
|
257 |
|
258 private: // new functions |
|
259 TBool MatchServerAlertL( const SmlAlert_t* aAlert, TInt aStatusID ); |
|
260 TPtrC8 DoDeviceInfoL(TBool aConvert = EFalse); |
|
261 void SwitchAlertCode(TDes8& aAlertCode); |
|
262 void DoTargetWithFilterL( sml_target_s*& aTarget, const TDesC& aLocURIData ) const; |
|
263 void FreeDeviceInfo(); |
|
264 void ParseDeviceInfoL( TInt aStatusID, const TPtrC8& aDeviceInfo ); |
|
265 void ProcessDeviceInfoL( const SmlDevInfDevInf_t& aContent ); |
|
266 void ProcessCTCapL( SmlDevInfCtCapList_t& aCapList, const TDesC8& aCTType ) const; |
|
267 void ProcessFilterCapL ( SmlDevInfFilterCapList_t& aFilterCapList, const TDesC8& aCTType ) const; |
|
268 |
|
269 void DoNumberOfChangesL( SmlPcdata_t*& aNoc ) const; |
|
270 void UpdateL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, const TDesC8& aUID, const TSmlDbItemUid aParent ); |
|
271 TBool IsDevInfoContentTypeOkL( const SmlPcdata_t* aMeta, TInt aStatusID ); |
|
272 TBool IsLUIDOkLC( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, HBufC8*& aLUID ); |
|
273 TBool IsGUIDOkLC( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem, HBufC8*& aGUID ); |
|
274 TBool IsParentOkL( const sml_source_or_target_parent_s* aParent, TSmlDbItemUid& aGUID ); |
|
275 TBool IsParentOkLC( const sml_source_or_target_parent_s* aParent, HBufC8*& aGUID ); |
|
276 TBool IsFormatOkL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem ); |
|
277 TBool IsChrFormat( const SmlPcdata_t* aMeta, TPtrC8& aFormat ) const; |
|
278 TBool CheckAndSetReceivedMediaTypeL( const TDesC8& aCmd, const SmlGenericCmd_t* aContent, const SmlItem_t* aItem ); |
|
279 TBool MediaTypeSetOkL( const SmlPcdata_t* aMeta, TBool& aFound, TPtr8& aMediaType,const TDesC8& aCmd ) const; |
|
280 HBufC* AlertDataLC( const SmlItemList_t* aItemList ) const; |
|
281 void AppendCTCapsL( CNSmlDbCaps& aDbCaps,const SmlDevInfDatastore_t* aDataStore, SmlDevInfCtCapList_t* aCtCapList ) const; |
|
282 |
|
283 TInt AlertParameter ( const SmlPcdata_t* aData, const TDesC8& aParamID ) const; |
|
284 /** |
|
285 * Performs mapping between datastore operation return values and SyncML error codes. |
|
286 * @param aIndex Index to the current batch item. |
|
287 * @param aStatus Datastore operation's return value that should be mapped. |
|
288 */ |
|
289 void MapStatusCodeL( const TInt aIndex, const TInt aStatus ); |
|
290 |
|
291 TBool IsVersionOkL ( const SmlDevInfDevInf_t& aContent, TInt aStatusID ); |
|
292 TBool IsRxTxOkL( SmlDevInfDatastoreList_t* aCurrDatastore, TInt aStatusID, RPointerArray<CNSmlDbCaps>& aDbCapArray ); |
|
293 TBool UpdateServerIdInSettingsL( const SmlDevInfDevInf_t& aContent, TInt aStatusID ); |
|
294 |
|
295 /** |
|
296 * Buffers the received chunked item. |
|
297 * @param aUid UID of the received item. |
|
298 * @param aCurrItem Current item's data. |
|
299 * @param aMetaInCommand Current command's meta data. |
|
300 * @param aBuffer Buffer where the received chunk is read. |
|
301 * @return ESmlStatusOK if the whole item was received, |
|
302 * ESmlStatusItemAccepted if the item was accepted or an error code. |
|
303 */ |
|
304 TNSmlError::TNSmlSyncMLStatusCode GetChunkL( const TDesC8& aUid, const SmlItem_t* aCurrentItem, const SmlPcdata_t* aMetaInCommand, CBufBase*& aBuffer ); |
|
305 |
|
306 /** |
|
307 * Commits batched items. |
|
308 */ |
|
309 void CommitBatchL(); |
|
310 |
|
311 /** |
|
312 * Converts UID from literal to numeric presentation. |
|
313 * @param aLiteralUid UID in literal form. |
|
314 * @param aNumericUid On return contains UID in numeric form. |
|
315 * @result KErrNone if the conversion succeeded. |
|
316 */ |
|
317 TInt ConvertUid( const TDesC8& aLiteralUid, TSmlDbItemUid& aNumericUid ); |
|
318 |
|
319 private: // data |
|
320 // batched items buffer |
|
321 CNSmlDSBatchBuffer* iBatchBuffer; |
|
322 // device info switch |
|
323 TBool iDSDeviceInfoParsed; |
|
324 // MsgID of Get |
|
325 HBufC8* iDSGetMsgId; |
|
326 // CmdID of Get |
|
327 HBufC8* iDSGetCmdId; |
|
328 // command name of a partially sent large object |
|
329 HBufC8* iDSLargeObjectCmdName; |
|
330 // Target in Sync from a server |
|
331 CNSmlURI* iDSPreviousSyncTargetURI; |
|
332 // class for content specific processing |
|
333 CNSmlDSContent& iDSContent; |
|
334 // observer callback |
|
335 MSyncMLProgressObserver& iDSObserver; |
|
336 // WBXML generator |
|
337 CWBXMLDevInfGenerator* iDSDevGenerator; |
|
338 // buffer for received data |
|
339 CBufFlat* iDataBuffer; |
|
340 // flag to indicate if the item to be sent is a large object |
|
341 TBool iLargeData; |
|
342 // batch mode on/off |
|
343 TBool iBatchModeOn; |
|
344 // id of the ongoing atomic command |
|
345 TInt iAtomicId; |
|
346 // atomic transaction mode on/off |
|
347 TBool iAtomicModeOn; |
|
348 // atomic command has failed |
|
349 TBool iAtomicHasFailed; |
|
350 // UID of the received large object |
|
351 HBufC8* iLargeUid; |
|
352 // true if an item is opened |
|
353 TBool iItemOpened; |
|
354 // total number of sent bytes of a chunked item |
|
355 TInt iBytesSent; |
|
356 // UID generated by a datastore adapter |
|
357 TSmlDbItemUid iNewUid; |
|
358 }; |
|
359 |
|
360 #endif // __NSMLDSCMDS_H__ |
|
361 |
|
362 // End of File |