|
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 server alert handler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 //system includes |
|
21 #include <s32mem.h> |
|
22 #include <SyncMLDef.h> |
|
23 #include <implementationproxy.h> // TImplementationProxy definition |
|
24 #include <nsmlconstants.h> |
|
25 #include <nsmldebug.h> |
|
26 #include <nsmlunicodeconverter.h> |
|
27 #include <NSmlPrivateAPI.h> |
|
28 |
|
29 #include "WBXMLSyncMLParser.h" |
|
30 #include "WBXMLParser.h" |
|
31 #include "WBXMLParserError.h" |
|
32 #include "smlmetinfdtd.h" |
|
33 #include "NSmlURI.h" |
|
34 #include "nsmldsalert.h" |
|
35 #include "nsmldssettings.h" |
|
36 |
|
37 // ================= MEMBER FUNCTIONS ======================= |
|
38 |
|
39 // --------------------------------------------------------- |
|
40 // CNSmlDSAlert::CNSmlDSAlert() |
|
41 // Constructor |
|
42 // --------------------------------------------------------- |
|
43 // |
|
44 CNSmlDSAlert::CNSmlDSAlert() |
|
45 { |
|
46 } |
|
47 |
|
48 |
|
49 // --------------------------------------------------------- |
|
50 // CNSmlDSAlert::NewL() |
|
51 // Creates new instance of CNSmlDSAlert. |
|
52 // Does not leave instance pointer to CleanupStack. |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CNSmlDSAlert* CNSmlDSAlert::NewL() |
|
56 { |
|
57 CNSmlDSAlert* self = new (ELeave) CNSmlDSAlert(); |
|
58 return self; |
|
59 } |
|
60 |
|
61 // --------------------------------------------------------- |
|
62 // CNSmlDSAlert::~CNSmlDSAlert() |
|
63 // Destructor |
|
64 // --------------------------------------------------------- |
|
65 // |
|
66 CNSmlDSAlert::~CNSmlDSAlert() |
|
67 { |
|
68 } |
|
69 |
|
70 // --------------------------------------------------------- |
|
71 // CNSmlDSAlert::StartSync( const TDesC8& aSyncMLMessage, TInt aTransport, TBTDevAddr aBTAddress, |
|
72 // const TDesC& aBTName, MNSmlAlertObexPluginContext* aPluginContext ) |
|
73 // Both standards supported (1.1 and 1.2) |
|
74 // --------------------------------------------------------- |
|
75 // |
|
76 TNSmlAlertResult CNSmlDSAlert::StartSyncL( |
|
77 const TDesC8& aSyncMLMessage, |
|
78 TInt aTransport, |
|
79 TBTDevAddr /* aBTAddress */, |
|
80 const TDesC& /* aBTName */, |
|
81 MNSmlAlertObexPluginContext* /* aPluginContext */) |
|
82 { |
|
83 DBG_FILE(_S8("CNSmlDSAlert::StartSync begins")); |
|
84 // Handling 1.2 Notification package |
|
85 //================================== |
|
86 TSmlProtocolVersion protocol(ESmlVersion1_2); |
|
87 |
|
88 if ( ! Is12Package( aSyncMLMessage ) ) |
|
89 { |
|
90 // Handling 1.1 Package0 |
|
91 //====================== |
|
92 TRAPD( parseErr, ParseMessageL( aSyncMLMessage ) ); |
|
93 if ( ( parseErr != KErrNone ) || (iPacketShouldGoToMdo) ) |
|
94 { |
|
95 // It may be MDO package |
|
96 return TNSmlAlertResult( ENSmlErrNotConsumed ); |
|
97 } |
|
98 |
|
99 protocol = ESmlVersion1_1_2; |
|
100 |
|
101 } |
|
102 |
|
103 RNSmlPrivateAPI privateApi; |
|
104 TRAPD(openErr, privateApi.OpenL()); |
|
105 |
|
106 if ( openErr != KErrNone ) |
|
107 { |
|
108 return ENSmlErrUndefined; |
|
109 } |
|
110 |
|
111 const TUid transportId = { aTransport }; |
|
112 |
|
113 TRAPD(connErr, privateApi.SendL(aSyncMLMessage, ESmlDataSync, |
|
114 protocol, transportId )); |
|
115 |
|
116 if ( connErr != KErrNone ) |
|
117 { |
|
118 privateApi.Close(); |
|
119 return ENSmlErrUndefined; |
|
120 } |
|
121 |
|
122 privateApi.Close(); |
|
123 |
|
124 return ENSmlErrNone; |
|
125 } |
|
126 |
|
127 |
|
128 |
|
129 // |
|
130 // Private member functions |
|
131 // |
|
132 |
|
133 // --------------------------------------------------------- |
|
134 // CNSmlDSAlert::Is12Package( const TDesC8& aTriggerMessage ) const |
|
135 // |
|
136 // --------------------------------------------------------- |
|
137 TBool CNSmlDSAlert::Is12Package( const TDesC8& aTriggerMessage ) const |
|
138 { |
|
139 if ( aTriggerMessage.Length() > KNSmlDSAlertVersionPos ) |
|
140 { |
|
141 TInt version; |
|
142 version = ((TUint8) aTriggerMessage[ KNSmlDSAlertVersionPos ]) << 8; |
|
143 version |= (TUint8) aTriggerMessage[ KNSmlDSAlertVersionPos + 1 ]; |
|
144 version = version >> 6; |
|
145 if ( version == KNSmlDSAlertVersion ) |
|
146 { |
|
147 return ETrue; |
|
148 } |
|
149 } |
|
150 return EFalse; |
|
151 } |
|
152 |
|
153 |
|
154 // --------------------------------------------------------- |
|
155 // CNSmlDSAlert::ParseMessageL( const TDesC8& aSyncMLMessage ) |
|
156 // |
|
157 // --------------------------------------------------------- |
|
158 void CNSmlDSAlert::ParseMessageL( const TDesC8& aSyncMLMessage ) |
|
159 { |
|
160 DBG_FILE(_S8("CNSmlDSAlert::ParseMessageL begins")); |
|
161 CWBXMLSyncMLDocHandler* docHandler = CWBXMLSyncMLDocHandler::NewL( this ); |
|
162 CleanupStack::PushL( docHandler ); |
|
163 CWBXMLParser* parser = CWBXMLParser::NewL(); |
|
164 CleanupStack::PushL( parser ); |
|
165 parser->SetDocumentHandler( docHandler ); |
|
166 parser->SetExtensionHandler( docHandler ); |
|
167 RDesReadStream readStream; |
|
168 readStream.Open( aSyncMLMessage ); |
|
169 CleanupClosePushL ( readStream ); |
|
170 parser->SetDocumentL( readStream ); |
|
171 TWBXMLParserError ret = KWBXMLParserErrorOk; |
|
172 while ( ret == KWBXMLParserErrorOk ) |
|
173 { |
|
174 ret = parser->ParseL(); |
|
175 } |
|
176 CleanupStack::PopAndDestroy( 3 ); //readStream, parser, docHandler |
|
177 DBG_FILE(_S8("CNSmlDSAlert::ParseMessageL ends")); |
|
178 } |
|
179 |
|
180 |
|
181 // --------------------------------------------------------- |
|
182 // CNSmlDSAlert::PCDATAToUnicodeLC( const SmlPcdata_t& aPcdata, HBufC*& aUnicodeData ) const |
|
183 // Converts data in Pcdata structure (used by xml parser) |
|
184 // to Unicode |
|
185 // --------------------------------------------------------- |
|
186 void CNSmlDSAlert::PCDATAToUnicodeLC( const SmlPcdata_t& aPcdata, HBufC*& aUnicodeData ) const |
|
187 { |
|
188 if ( !aPcdata.content ) |
|
189 { |
|
190 aUnicodeData = NULL; |
|
191 aUnicodeData = HBufC::NewLC( 0 ); |
|
192 } |
|
193 TPtr8 pcdata( (TUint8*) aPcdata.content, aPcdata.length, aPcdata.length ); |
|
194 TrimRightSpaceAndNull( pcdata ); |
|
195 NSmlUnicodeConverter::HBufC16InUnicodeLC( pcdata, aUnicodeData ); |
|
196 } |
|
197 |
|
198 /// --------------------------------------------------------- |
|
199 // CNSmlDSAlert::TrimRightSpaceAndNull( TDes8& aDes ) const |
|
200 // Trims right spaces and zero terminator (NULL) |
|
201 // --------------------------------------------------------- |
|
202 void CNSmlDSAlert::TrimRightSpaceAndNull( TDes8& aDes ) const |
|
203 { |
|
204 aDes.TrimRight(); |
|
205 if ( aDes.Length() > 0 ) |
|
206 { |
|
207 if ( aDes[aDes.Length() - 1] == NULL ) |
|
208 { |
|
209 aDes.SetLength( aDes.Length() - 1 ); |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 // |
|
215 // Callback functions implementation |
|
216 // |
|
217 // --------------------------------------------------------- |
|
218 // CNSmlDSAlert::smlAlertCmdFuncL |
|
219 // Alert command from server. |
|
220 // --------------------------------------------------------- |
|
221 Ret_t CNSmlDSAlert::smlAlertCmdFuncL( SmlAlertPtr_t /*aAlert*/ ) |
|
222 { |
|
223 return 0; |
|
224 } |
|
225 // --------------------------------------------------------- |
|
226 // CNSmlDSAlert::smlGetCmdFuncL |
|
227 // Get command from server |
|
228 // --------------------------------------------------------- |
|
229 Ret_t CNSmlDSAlert::smlGetCmdFuncL( SmlGetPtr_t /*aContent*/ ) |
|
230 { |
|
231 return 0; |
|
232 } |
|
233 // --------------------------------------------------------- |
|
234 // CNSmlDSAlert::smlPutCmdFuncL |
|
235 // Put command from server |
|
236 // --------------------------------------------------------- |
|
237 Ret_t CNSmlDSAlert::smlPutCmdFuncL( SmlPutPtr_t /*aContent*/ ) |
|
238 { |
|
239 return 0; |
|
240 } |
|
241 // --------------------------------------------------------- |
|
242 // CNSmlDSAlert::smlResultsCmdFuncL |
|
243 // Results command from server |
|
244 // --------------------------------------------------------- |
|
245 Ret_t CNSmlDSAlert::smlResultsCmdFuncL( SmlResultsPtr_t /*aContent*/ ) |
|
246 { |
|
247 return 0; |
|
248 } |
|
249 // --------------------------------------------------------- |
|
250 // CNSmlDSAlert::smlStatusCmdFuncL |
|
251 // Status command from server |
|
252 // --------------------------------------------------------- |
|
253 Ret_t CNSmlDSAlert::smlStatusCmdFuncL( SmlStatusPtr_t /*aContent*/ ) |
|
254 { |
|
255 return 0; |
|
256 } |
|
257 // --------------------------------------------------------- |
|
258 // CNSmlDSAlert::smlStartMessageFuncL |
|
259 // SyncHdr from server |
|
260 // --------------------------------------------------------- |
|
261 Ret_t CNSmlDSAlert::smlStartMessageFuncL( SmlSyncHdrPtr_t aSyncHdr ) |
|
262 { |
|
263 |
|
264 if ( !aSyncHdr || !aSyncHdr->source || !aSyncHdr->source->locURI ) |
|
265 { |
|
266 User::Leave( KErrGeneral ); |
|
267 } |
|
268 |
|
269 if ( ( aSyncHdr->meta ) && |
|
270 ( aSyncHdr->meta->content ) && |
|
271 ( aSyncHdr->meta->contentType == SML_PCDATA_EXTENSION ) && |
|
272 ( aSyncHdr->meta->extension == SML_EXT_METINF ) ) |
|
273 { |
|
274 SmlMetInfMetInf_t* metInf; |
|
275 metInf = (SmlMetInfMetInf_t*) aSyncHdr->meta->content; |
|
276 if ( metInf->emi ) |
|
277 { |
|
278 TPtr8 emi( ( TUint8* ) metInf->emi->data->content, |
|
279 metInf->emi->data->length, |
|
280 metInf->emi->data->length ); |
|
281 TrimRightSpaceAndNull( emi ); |
|
282 |
|
283 if ( emi.Match(KMdoAgentSupportedVersion) != KErrNotFound ) |
|
284 { |
|
285 // the sync message should go to mdo, instead of ds |
|
286 iPacketShouldGoToMdo = ETrue; |
|
287 return 0; |
|
288 } |
|
289 } |
|
290 } |
|
291 |
|
292 return 0; |
|
293 } |
|
294 // --------------------------------------------------------- |
|
295 // CNSmlDSAlert::smlEndMessageFuncL |
|
296 // End of SyncML message was reached |
|
297 // --------------------------------------------------------- |
|
298 Ret_t CNSmlDSAlert::smlEndMessageFuncL( Boolean_t /*aFinal*/ ) |
|
299 { |
|
300 return 0; |
|
301 } |
|
302 // --------------------------------------------------------- |
|
303 // CNSmlDSAlert::smlStartSyncFuncL |
|
304 // Sync command from server |
|
305 // --------------------------------------------------------- |
|
306 Ret_t CNSmlDSAlert::smlStartSyncFuncL( SmlSyncPtr_t /*aContent*/ ) |
|
307 { |
|
308 return 0; |
|
309 } |
|
310 // --------------------------------------------------------- |
|
311 // CNSmlDSAlert::smlEndSyncFuncL |
|
312 // End of Sync command was reached |
|
313 // --------------------------------------------------------- |
|
314 Ret_t CNSmlDSAlert::smlEndSyncFuncL() |
|
315 { |
|
316 return 0; |
|
317 } |
|
318 // --------------------------------------------------------- |
|
319 // CNSmlDSAlert::smlStartAtomicFuncL |
|
320 // Atomic command from server, Atomic is not supported |
|
321 // --------------------------------------------------------- |
|
322 Ret_t CNSmlDSAlert::smlStartAtomicFuncL( SmlAtomicPtr_t /*aContent*/ ) |
|
323 { |
|
324 return 0; |
|
325 } |
|
326 // --------------------------------------------------------- |
|
327 // CNSmlDSAlert::smlEndAtomicFuncL |
|
328 // End of Atomic command was reached, Atomic is not supported |
|
329 // --------------------------------------------------------- |
|
330 Ret_t CNSmlDSAlert::smlEndAtomicFuncL() |
|
331 { |
|
332 return 0; |
|
333 } |
|
334 // --------------------------------------------------------- |
|
335 // CNSmlDSAlert::smlStartSequenceFuncL |
|
336 // Sequence command from server, Sequence is not supported |
|
337 // --------------------------------------------------------- |
|
338 Ret_t CNSmlDSAlert::smlStartSequenceFuncL( SmlSequencePtr_t /*aContent*/ ) |
|
339 { |
|
340 return 0; |
|
341 } |
|
342 // --------------------------------------------------------- |
|
343 // CNSmlDSAlert::smlEndSequenceFuncL |
|
344 // |
|
345 // --------------------------------------------------------- |
|
346 Ret_t CNSmlDSAlert::smlEndSequenceFuncL() |
|
347 { |
|
348 return 0; |
|
349 } |
|
350 // --------------------------------------------------------- |
|
351 // CNSmlDSAlert::smlAddCmdFuncL |
|
352 // |
|
353 // --------------------------------------------------------- |
|
354 Ret_t CNSmlDSAlert::smlAddCmdFuncL( SmlAddPtr_t /*aContent*/ ) |
|
355 { |
|
356 return 0; |
|
357 } |
|
358 // --------------------------------------------------------- |
|
359 // CNSmlDSAlert::smlCopyCmdFuncL |
|
360 // |
|
361 // --------------------------------------------------------- |
|
362 Ret_t CNSmlDSAlert::smlCopyCmdFuncL( SmlCopyPtr_t /*aContent*/) |
|
363 { |
|
364 return 0; |
|
365 } |
|
366 // --------------------------------------------------------- |
|
367 // CNSmlDSAlert::smlDeleteCmdFuncL |
|
368 // |
|
369 // --------------------------------------------------------- |
|
370 Ret_t CNSmlDSAlert::smlDeleteCmdFuncL( SmlDeletePtr_t /*aContent*/ ) |
|
371 { |
|
372 return 0; |
|
373 } |
|
374 // --------------------------------------------------------- |
|
375 // CNSmlDSAlert::smlExecCmdFuncL |
|
376 // |
|
377 // --------------------------------------------------------- |
|
378 Ret_t CNSmlDSAlert::smlExecCmdFuncL( SmlExecPtr_t /*aContent*/ ) |
|
379 { |
|
380 return 0; |
|
381 } |
|
382 // --------------------------------------------------------- |
|
383 // CNSmlDSAlert::smlMapCmdFuncL |
|
384 // |
|
385 // --------------------------------------------------------- |
|
386 Ret_t CNSmlDSAlert::smlMapCmdFuncL( SmlMapPtr_t /*aContent*/ ) |
|
387 { |
|
388 return 0; |
|
389 } |
|
390 // --------------------------------------------------------- |
|
391 // CNSmlDSAlert::smlReplaceCmdFuncL |
|
392 // |
|
393 // --------------------------------------------------------- |
|
394 Ret_t CNSmlDSAlert::smlReplaceCmdFuncL( SmlReplacePtr_t /*aContent*/ ) |
|
395 { |
|
396 return 0; |
|
397 } |
|
398 // --------------------------------------------------------- |
|
399 // CNSmlDSAlert::smlSearchCmdFuncL |
|
400 // |
|
401 // --------------------------------------------------------- |
|
402 Ret_t CNSmlDSAlert::smlSearchCmdFuncL( SmlSearchPtr_t /*aContent*/ ) |
|
403 { |
|
404 return 0; |
|
405 } |
|
406 |
|
407 //1.2 CHANGES: Move command |
|
408 // --------------------------------------------------------- |
|
409 // CNSmlDSAlert::smlMoveCmdFuncL |
|
410 // |
|
411 // --------------------------------------------------------- |
|
412 Ret_t CNSmlDSAlert::smlMoveCmdFuncL( SmlMovePtr_t /*aContent*/ ) |
|
413 { |
|
414 return 0; |
|
415 } |
|
416 //Changes end |
|
417 |
|
418 |
|
419 // ------------------------------------------------------------------------------------------------ |
|
420 // Implementationproxy for ECOM |
|
421 // ------------------------------------------------------------------------------------------------ |
|
422 // ------------------------------------------------------------------------------------------------ |
|
423 // Constants for implementation proxy |
|
424 // ------------------------------------------------------------------------------------------------ |
|
425 |
|
426 #ifndef IMPLEMENTATION_PROXY_ENTRY |
|
427 #define IMPLEMENTATION_PROXY_ENTRY(aUid, aFuncPtr) {{aUid},(aFuncPtr)} |
|
428 #endif |
|
429 |
|
430 const TImplementationProxy ImplementationTable[] = |
|
431 { |
|
432 IMPLEMENTATION_PROXY_ENTRY(KNSmlDSAlertImplUid, CNSmlDSAlert::NewL) |
|
433 }; |
|
434 |
|
435 // ------------------------------------------------------------------------------------------------ |
|
436 // TImplementationProxy* ImplementationGroupProxy |
|
437 // Implementation proxy |
|
438 // ------------------------------------------------------------------------------------------------ |
|
439 EXPORT_C const TImplementationProxy* ImplementationGroupProxy( TInt& aTableCount ) |
|
440 { |
|
441 _DBG_FILE("CNSmlDSAlert::ImplementationGroupProxy(): begin"); |
|
442 aTableCount = sizeof( ImplementationTable ) / sizeof( TImplementationProxy ); |
|
443 _DBG_FILE("CNSmlDSAlert::ImplementationGroupProxy(): end"); |
|
444 return ImplementationTable; |
|
445 } |
|
446 |
|
447 // End of File |