40
|
1 |
/*
|
|
2 |
* Copyright (c) 2005-2007 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: Part of SyncML Data Synchronization Plug In Adapter
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
#include <e32std.h>
|
|
21 |
#include <msvids.h>
|
|
22 |
#include <txtrich.h>
|
|
23 |
#include "vmessageparser.h"
|
|
24 |
#include "logger.h"
|
|
25 |
|
|
26 |
|
|
27 |
const TInt KVersionMaxLength = 4;
|
|
28 |
const TInt KDateMaxLength = 48;
|
|
29 |
const TInt KTagAndValueMaxLength = 48;
|
|
30 |
const TInt KDefaultWriteBufSize = 1024;
|
|
31 |
|
|
32 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
33 |
|
|
34 |
// -----------------------------------------------------------------------------
|
|
35 |
// CVMessageParser* CVMessageParser::NewL()
|
|
36 |
// -----------------------------------------------------------------------------
|
|
37 |
//
|
|
38 |
CVMessageParser* CVMessageParser::NewL()
|
|
39 |
{
|
|
40 |
CVMessageParser* self = NewLC();
|
|
41 |
CleanupStack::Pop( self );
|
|
42 |
return self;
|
|
43 |
}
|
|
44 |
|
|
45 |
// -----------------------------------------------------------------------------
|
|
46 |
// CVMessageParser* CVMessageParser::NewLC()
|
|
47 |
// -----------------------------------------------------------------------------
|
|
48 |
//
|
|
49 |
CVMessageParser* CVMessageParser::NewLC()
|
|
50 |
{
|
|
51 |
CVMessageParser* self = new( ELeave ) CVMessageParser();
|
|
52 |
CleanupStack::PushL( self );
|
|
53 |
self->ConstructL();
|
|
54 |
return self;
|
|
55 |
}
|
|
56 |
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
// CVMessageParser::~CVMessageParser()
|
|
59 |
// -----------------------------------------------------------------------------
|
|
60 |
//
|
|
61 |
CVMessageParser::~CVMessageParser()
|
|
62 |
{
|
|
63 |
iRecipients.Close();
|
|
64 |
delete iMessageBody;
|
|
65 |
iMessageBody = NULL;
|
|
66 |
}
|
|
67 |
|
|
68 |
// -----------------------------------------------------------------------------
|
|
69 |
// CVMessageParser::CVMessageParser()
|
|
70 |
// -----------------------------------------------------------------------------
|
|
71 |
//
|
|
72 |
CVMessageParser::CVMessageParser()
|
|
73 |
{
|
|
74 |
}
|
|
75 |
|
|
76 |
// -----------------------------------------------------------------------------
|
|
77 |
// CVMessageParser::ConstructL()
|
|
78 |
// -----------------------------------------------------------------------------
|
|
79 |
//
|
|
80 |
void CVMessageParser::ConstructL()
|
|
81 |
{
|
|
82 |
}
|
|
83 |
|
|
84 |
// -----------------------------------------------------------------------------
|
|
85 |
// CVMessageParser::ReadMessage()
|
|
86 |
// -----------------------------------------------------------------------------
|
|
87 |
//
|
|
88 |
TInt CVMessageParser::ParseMessageL( const TDesC8& aVMessage )
|
|
89 |
{
|
|
90 |
LOGGER_ENTERFN( "CVMessageParser::ParseMessageL" );
|
|
91 |
|
|
92 |
const TUint8* ptr8 = aVMessage.Ptr();
|
|
93 |
const TUint16* ptr16 = reinterpret_cast<const TUint16*>( ptr8 );
|
|
94 |
iReadBuf.Set( ptr16, aVMessage.Length()/2 );
|
|
95 |
LOG(iReadBuf);
|
|
96 |
|
|
97 |
iReadBufPosition = 0;
|
|
98 |
|
|
99 |
TInt err = ReadMessageHeader();
|
|
100 |
|
|
101 |
if (err < 0)
|
|
102 |
{
|
|
103 |
LOGGER_WRITE_1( "ReadMessageHeader() failed with %d", err );
|
|
104 |
}
|
|
105 |
else
|
|
106 |
{
|
|
107 |
err = ReadMessageBodyL();
|
|
108 |
LOGGER_WRITE_1( "ReadMessageBody() result: %d", err );
|
|
109 |
}
|
|
110 |
LOGGER_LEAVEFN( "CVMessageParser::ParseMessageL" );
|
|
111 |
return err;
|
|
112 |
}
|
|
113 |
|
|
114 |
// -----------------------------------------------------------------------------
|
|
115 |
// CVMessageParser::ConstructMessageL()
|
|
116 |
// -----------------------------------------------------------------------------
|
|
117 |
//
|
|
118 |
void CVMessageParser::ConstructMessageL( CBufBase& aVMessage )
|
|
119 |
{
|
|
120 |
LOGGER_ENTERFN( "CVMessageParser::ConstructMessageL" );
|
|
121 |
LOGGER_WRITE_1( "Initial buffer size: %d", aVMessage.Size() );
|
|
122 |
|
|
123 |
iWriteBuf = &aVMessage;
|
|
124 |
iWriteBufPosition = 0,
|
|
125 |
iWriteIndentLevel = 0;
|
|
126 |
|
|
127 |
iWriteBufSize = KDefaultWriteBufSize;
|
|
128 |
if (iMessageBody)
|
|
129 |
{
|
|
130 |
iWriteBufSize += iMessageBody->Size();
|
|
131 |
}
|
|
132 |
|
|
133 |
iWriteBuf->ResizeL( iWriteBufSize );
|
|
134 |
LOGGER_WRITE_1( "Buffer size resized to %d", iWriteBuf->Size() );
|
|
135 |
|
|
136 |
WriteMessageLineL( KVMsgTagBegin, KVMsgSectionVMsg ); // BEGIN:VMSG
|
|
137 |
WriteMessagePropertiesL();
|
|
138 |
WriteMessageVCARDL( iSender.iName, iSender.iNumber );
|
|
139 |
WriteMessageEnvelopeL();
|
|
140 |
WriteMessageLineL( KVMsgTagEnd, KVMsgSectionVMsg ); // END:VMSG
|
|
141 |
|
|
142 |
iWriteBuf->ResizeL( iWriteBufPosition );
|
|
143 |
|
|
144 |
LOGGER_WRITE_1( "Message length: %d", iWriteBufPosition );
|
|
145 |
LOGGER_LEAVEFN( "CVMessageParser::ConstructMessageL" );
|
|
146 |
}
|
|
147 |
|
|
148 |
// -----------------------------------------------------------------------------
|
|
149 |
// CVMessageParser::ResetAll()
|
|
150 |
// -----------------------------------------------------------------------------
|
|
151 |
//
|
|
152 |
void CVMessageParser::ResetAll()
|
|
153 |
{
|
|
154 |
// Public data
|
|
155 |
|
|
156 |
iHomeTime = 0;
|
|
157 |
iUniversalTime = 0;
|
|
158 |
iFolder.Zero();
|
|
159 |
iStatus.Zero();
|
|
160 |
iSender.iNumber.Zero();
|
|
161 |
iSender.iName.Zero();
|
|
162 |
iRecipients.Reset();
|
|
163 |
if (iMessageBody)
|
|
164 |
{
|
|
165 |
delete iMessageBody;
|
|
166 |
iMessageBody = NULL;
|
|
167 |
}
|
|
168 |
|
|
169 |
|
|
170 |
// Private variables
|
|
171 |
iReadBufPosition = 0;
|
|
172 |
iWriteBufPosition = 0;
|
|
173 |
iWriteIndentLevel = 0;
|
|
174 |
iWriteBuf = NULL;
|
|
175 |
}
|
|
176 |
|
|
177 |
// -----------------------------------------------------------------------------
|
|
178 |
// CVMessageParser::LoadMessageBodyL()
|
|
179 |
// -----------------------------------------------------------------------------
|
|
180 |
//
|
|
181 |
void CVMessageParser::LoadMessageBodyL( CRichText &aMsgBody )
|
|
182 |
{
|
|
183 |
if (iMessageBody)
|
|
184 |
{
|
|
185 |
aMsgBody.InsertL(0, *iMessageBody);
|
|
186 |
}
|
|
187 |
}
|
|
188 |
|
|
189 |
// -----------------------------------------------------------------------------
|
|
190 |
// CVMessageParser::StoreMessageBodyL()
|
|
191 |
// -----------------------------------------------------------------------------
|
|
192 |
//
|
|
193 |
void CVMessageParser::StoreMessageBodyL( CRichText &aMsgBody )
|
|
194 |
{
|
|
195 |
if (iMessageBody)
|
|
196 |
{
|
|
197 |
LOGGER_WRITE( "Message body not empty" );
|
|
198 |
User::Leave( KErrGeneral );
|
|
199 |
}
|
|
200 |
|
|
201 |
TInt bodyLenght = aMsgBody.DocumentLength();
|
|
202 |
|
|
203 |
if (bodyLenght > 0)
|
|
204 |
{
|
|
205 |
iMessageBody = HBufC::NewL( bodyLenght );
|
|
206 |
TPtr16 ptrBody = iMessageBody->Des();
|
|
207 |
aMsgBody.Extract( ptrBody );
|
|
208 |
}
|
|
209 |
}
|
|
210 |
|
|
211 |
// -----------------------------------------------------------------------------
|
|
212 |
// CVMessageParser::ParseTelephoneNumber()
|
|
213 |
// -----------------------------------------------------------------------------
|
|
214 |
//
|
|
215 |
TBool CVMessageParser::ParseTelephoneNumber( const TDesC &aNumberString, TTelephoneNumber &aNumberStore )
|
|
216 |
{
|
|
217 |
_LIT( KStartMarker, "<" );
|
|
218 |
_LIT( KEndMarker, ">" );
|
|
219 |
LOGGER_WRITE_1("aNumberString: %S", &aNumberString );
|
|
220 |
TInt startMarker = aNumberString.Find( KStartMarker );
|
|
221 |
|
|
222 |
if (startMarker >= 0)
|
|
223 |
{
|
|
224 |
TInt endMarker = aNumberString.Find( KEndMarker );
|
|
225 |
if (endMarker <= (startMarker + 1))
|
|
226 |
{
|
|
227 |
LOGGER_WRITE( "Incorrect number" );
|
|
228 |
return EFalse;
|
|
229 |
}
|
|
230 |
else // case 1: Abc Pqr <+01234567890>
|
|
231 |
{
|
|
232 |
TPtrC16 name = aNumberString.Left( startMarker );
|
|
233 |
TPtrC16 number = aNumberString.Mid( (startMarker + 1), (endMarker - startMarker - 1) );
|
|
234 |
AssignDataToBuffer( name, aNumberStore.iName );
|
|
235 |
AssignDataToBuffer( number, aNumberStore.iNumber );
|
|
236 |
}
|
|
237 |
}
|
|
238 |
else // just number
|
|
239 |
{
|
|
240 |
AssignDataToBuffer( aNumberString, aNumberStore.iNumber );
|
|
241 |
aNumberStore.iName.Zero();
|
|
242 |
}
|
|
243 |
LOGGER_WRITE_1("aNumberStore.iName: %S", &aNumberStore.iName);
|
|
244 |
|
|
245 |
return ETrue;
|
|
246 |
}
|
|
247 |
|
|
248 |
// -----------------------------------------------------------------------------
|
|
249 |
// CVMessageParser::ReadMessageHeader()
|
|
250 |
// -----------------------------------------------------------------------------
|
|
251 |
//
|
|
252 |
TInt CVMessageParser::ReadMessageHeader()
|
|
253 |
{
|
|
254 |
LOGGER_WRITE( "CVMessageParser::ReadMessageHeader()" );
|
|
255 |
|
|
256 |
TInt err;
|
|
257 |
|
|
258 |
err = FindMessageTagWithValue( KVMsgTagBegin, KVMsgSectionVMsg );
|
|
259 |
if (err < 0)
|
|
260 |
{
|
|
261 |
return err;
|
|
262 |
}
|
|
263 |
|
|
264 |
err = ReadTaggedTimeStamp( iUniversalTime );
|
|
265 |
if ( err == KErrNone )
|
|
266 |
{
|
|
267 |
LOGGER_WRITE( "Time stamp tag found, universal time set" );
|
|
268 |
}
|
|
269 |
|
|
270 |
err = GetMessageTagValue( KVMsgTagStatus, iStatus );
|
|
271 |
if (err < 0)
|
|
272 |
{
|
|
273 |
return err;
|
|
274 |
}
|
|
275 |
err = GetMessageTagValue( KVMsgTagBox, iFolder );
|
|
276 |
if (err < 0)
|
|
277 |
{
|
|
278 |
return err;
|
|
279 |
}
|
|
280 |
err = FindMessageTagWithValue( KVMsgTagBegin, KVMsgSectionVCard );
|
|
281 |
if (err < 0)
|
|
282 |
{
|
|
283 |
return err;
|
|
284 |
}
|
|
285 |
err = ReadVCard( iSender );
|
|
286 |
if (err < 0)
|
|
287 |
{
|
|
288 |
return err;
|
|
289 |
}
|
|
290 |
err = FindMessageTagWithValue( KVMsgTagBegin, KVMsgSectionVEnv );
|
|
291 |
if (err < 0)
|
|
292 |
{
|
|
293 |
return err;
|
|
294 |
}
|
|
295 |
else
|
|
296 |
{
|
|
297 |
err = ReadEnvelope();
|
|
298 |
}
|
|
299 |
|
|
300 |
return err;
|
|
301 |
}
|
|
302 |
|
|
303 |
// -----------------------------------------------------------------------------
|
|
304 |
// CVMessageParser::ReadEnvelope()
|
|
305 |
// -----------------------------------------------------------------------------
|
|
306 |
//
|
|
307 |
TInt CVMessageParser::ReadEnvelope()
|
|
308 |
{
|
|
309 |
TBuf<KTagAndValueMaxLength> tagValue;
|
|
310 |
TInt err( KErrNone );
|
|
311 |
|
|
312 |
err = GetMessageTagValue( KVMsgTagBegin, tagValue );
|
|
313 |
if (err < 0)
|
|
314 |
{
|
|
315 |
return err;
|
|
316 |
}
|
|
317 |
else if (tagValue.Compare( KVMsgSectionVCard ) == 0)
|
|
318 |
{
|
|
319 |
TTelephoneNumber recipient;
|
|
320 |
err = ReadVCard( recipient );
|
|
321 |
if (err < 0)
|
|
322 |
{
|
|
323 |
return err;
|
|
324 |
}
|
|
325 |
else
|
|
326 |
{
|
|
327 |
if (recipient.iNumber.Length() > 0)
|
|
328 |
{
|
64
|
329 |
err = iRecipients.Append( recipient );
|
|
330 |
if (err)
|
|
331 |
{
|
|
332 |
LOGGER_WRITE_1( "iRecipients.Append err: %d", err );
|
|
333 |
return err;
|
|
334 |
}
|
40
|
335 |
}
|
|
336 |
|
|
337 |
err = FindMessageTagWithValue( KVMsgTagBegin, KVMsgSectionVEnv );
|
|
338 |
if (err >= 0)
|
|
339 |
{
|
|
340 |
err = ReadEnvelope();
|
|
341 |
}
|
|
342 |
}
|
|
343 |
}
|
|
344 |
else if (tagValue.Compare( KVMsgSectionVBody ) == 0)
|
|
345 |
{
|
|
346 |
err = KErrNone;
|
|
347 |
}
|
|
348 |
else
|
|
349 |
{
|
|
350 |
LOGGER_WRITE( "Unexpected message tag value" );
|
|
351 |
return KErrGeneral;
|
|
352 |
}
|
|
353 |
|
|
354 |
return err;
|
|
355 |
}
|
|
356 |
|
|
357 |
// -----------------------------------------------------------------------------
|
|
358 |
// CVMessageParser::ReadTaggedTimestamp()
|
|
359 |
// Read and parse tagged timestamp from vMessage (optional feature)
|
|
360 |
// Format: X-NOK-DT:yyyymmddThhmmssZ (example: X-NOK-DT:20060329T091530Z)
|
|
361 |
// -----------------------------------------------------------------------------
|
|
362 |
//
|
|
363 |
TInt CVMessageParser::ReadTaggedTimeStamp( TTime& aUniversalTime )
|
|
364 |
{
|
|
365 |
LOGGER_WRITE( "CVMessageParser::ReadTaggedTimestamp" );
|
|
366 |
|
|
367 |
TInt err( KErrNone );
|
|
368 |
TBuf<20> timeStamp;
|
|
369 |
|
|
370 |
err = GetMessageTagValue( KVMsgTagDateTime, timeStamp, EFalse );
|
|
371 |
if ( err < 0 )
|
|
372 |
{
|
|
373 |
return KErrNotFound;
|
|
374 |
}
|
|
375 |
|
|
376 |
LOG( timeStamp );
|
|
377 |
|
|
378 |
if (timeStamp.Length() != 16 || timeStamp[8] != 'T' || timeStamp[15] != 'Z')
|
|
379 |
{
|
|
380 |
return KErrNotSupported;
|
|
381 |
}
|
|
382 |
|
|
383 |
TLex lexYear( timeStamp.Mid( 0, 4 ) );
|
|
384 |
TLex lexMonth( timeStamp.Mid( 4, 2 ) );
|
|
385 |
TLex lexDay( timeStamp.Mid( 6, 2 ) );
|
|
386 |
TLex lexHour( timeStamp.Mid( 9, 2 ) );
|
|
387 |
TLex lexMinute( timeStamp.Mid( 11, 2 ) );
|
|
388 |
TLex lexSecond( timeStamp.Mid( 13, 2 ) );
|
|
389 |
|
|
390 |
TInt valYear( 0 );
|
|
391 |
TInt valMonth( 0 );
|
|
392 |
TInt valDay( 0 );
|
|
393 |
TInt valHour( 0 );
|
|
394 |
TInt valMinute( 0 );
|
|
395 |
TInt valSecond( 0 );
|
|
396 |
|
|
397 |
TBool parseDone( EFalse );
|
|
398 |
if ( lexYear.Val( valYear ) == KErrNone )
|
|
399 |
{
|
|
400 |
if ( lexMonth.Val( valMonth ) == KErrNone )
|
|
401 |
{
|
|
402 |
if ( lexDay.Val( valDay ) == KErrNone )
|
|
403 |
{
|
|
404 |
if ( lexHour.Val( valHour ) == KErrNone )
|
|
405 |
{
|
|
406 |
if ( lexMinute.Val( valMinute ) == KErrNone )
|
|
407 |
{
|
|
408 |
if ( lexSecond.Val( valSecond ) == KErrNone )
|
|
409 |
{
|
|
410 |
parseDone = ETrue;
|
|
411 |
}
|
|
412 |
}
|
|
413 |
}
|
|
414 |
}
|
|
415 |
}
|
|
416 |
}
|
|
417 |
if ( !parseDone )
|
|
418 |
{
|
|
419 |
return KErrNotSupported;
|
|
420 |
}
|
|
421 |
|
|
422 |
TDateTime dateTime;
|
|
423 |
TMonth month = static_cast<TMonth>(--valMonth);
|
|
424 |
err = dateTime.Set( valYear, month, --valDay, valHour, valMinute, valSecond, 0 );
|
|
425 |
if ( err != KErrNone )
|
|
426 |
{
|
|
427 |
return KErrNotSupported;
|
|
428 |
}
|
|
429 |
|
|
430 |
aUniversalTime = dateTime;
|
|
431 |
|
|
432 |
return KErrNone;
|
|
433 |
}
|
|
434 |
|
|
435 |
// -----------------------------------------------------------------------------
|
|
436 |
// CVMessageParser::ReadVCard()
|
|
437 |
// -----------------------------------------------------------------------------
|
|
438 |
//
|
|
439 |
TInt CVMessageParser::ReadVCard( TTelephoneNumber &aResult )
|
|
440 |
{
|
|
441 |
TInt err = KErrNone;
|
|
442 |
TBuf<KVersionMaxLength> version;
|
|
443 |
|
|
444 |
err = GetMessageTagValue( KVMsgTagVersion, version );
|
|
445 |
if (err < 0)
|
|
446 |
{
|
|
447 |
return err;
|
|
448 |
}
|
|
449 |
|
|
450 |
err = GetMessageTagValue( KVMsgTagName, aResult.iName );
|
|
451 |
if (err < 0)
|
|
452 |
{
|
|
453 |
return err;
|
|
454 |
}
|
|
455 |
|
|
456 |
err = GetMessageTagValue( KVMsgTagTelephone, aResult.iNumber );
|
|
457 |
if (err < 0)
|
|
458 |
{
|
|
459 |
return err;
|
|
460 |
}
|
|
461 |
|
|
462 |
err = FindMessageTagWithValue( KVMsgTagEnd, KVMsgSectionVCard );
|
|
463 |
if (err < 0)
|
|
464 |
{
|
|
465 |
return err;
|
|
466 |
}
|
|
467 |
|
|
468 |
return KErrNone;
|
|
469 |
}
|
|
470 |
|
|
471 |
// -----------------------------------------------------------------------------
|
|
472 |
// CVMessageParser::ReadMessageBody()
|
|
473 |
// -----------------------------------------------------------------------------
|
|
474 |
//
|
|
475 |
TInt CVMessageParser::ReadMessageBodyL()
|
|
476 |
{
|
|
477 |
LOGGER_WRITE( "CVMessageParser::ReadMessageBody()" );
|
|
478 |
|
|
479 |
TInt err;
|
|
480 |
|
|
481 |
TPtrC pBuf = iReadBuf.Mid( iReadBufPosition );
|
|
482 |
err = pBuf.Find( KVMsgLineFeed );
|
|
483 |
if (err < 0)
|
|
484 |
{
|
|
485 |
return err;
|
|
486 |
}
|
|
487 |
|
|
488 |
iReadBufPosition += ( err + KVMsgLineFeed().Length() );
|
|
489 |
TInt bodyStart = iReadBufPosition;
|
|
490 |
|
|
491 |
TBuf<KDateMaxLength> dateBuf;
|
|
492 |
err = GetMessageTagValue(KVMsgTagDate, dateBuf);
|
|
493 |
if (err < 0)
|
|
494 |
{
|
|
495 |
LOGGER_WRITE( "No date field in message body" );
|
|
496 |
iReadBufPosition = bodyStart;
|
|
497 |
}
|
|
498 |
else
|
|
499 |
{
|
|
500 |
for (TInt i = 0; i < dateBuf.Length(); i++)
|
|
501 |
{
|
|
502 |
// This is needed, because TTime::Parse() can not handle
|
|
503 |
// situation where '.' character is used as a delimiter in date.
|
|
504 |
// Expected date format is like 18.1.2005 17:32:50.
|
|
505 |
//
|
|
506 |
if (dateBuf[i] == ' ')
|
|
507 |
{
|
|
508 |
break;
|
|
509 |
}
|
|
510 |
else if (dateBuf[i] == '.')
|
|
511 |
{
|
|
512 |
dateBuf[i] = '/';
|
|
513 |
}
|
|
514 |
}
|
|
515 |
|
|
516 |
TLocale locale;
|
|
517 |
TDateFormat originalFormat = locale.DateFormat();
|
|
518 |
locale.SetDateFormat( EDateEuropean );
|
|
519 |
locale.Set(); // transfer the new locale settings to the system
|
|
520 |
|
|
521 |
err = iHomeTime.Parse( dateBuf );
|
|
522 |
if ( err < 0 )
|
|
523 |
{
|
|
524 |
LOGGER_WRITE_1( "Parsing date from message body failed with %d", err );
|
|
525 |
iHomeTime = 0;
|
|
526 |
}
|
|
527 |
locale.SetDateFormat( originalFormat );
|
|
528 |
locale.Set(); // transfer the original locale settings back to the system
|
|
529 |
|
|
530 |
TPtrC pDateStart = iReadBuf.Mid( iReadBufPosition );
|
|
531 |
err = pDateStart.Find( KVMsgLineFeed );
|
|
532 |
if (err < 0)
|
|
533 |
{
|
|
534 |
return err;
|
|
535 |
}
|
|
536 |
iReadBufPosition += ( err + KVMsgLineFeed().Length() );
|
|
537 |
bodyStart = iReadBufPosition;
|
|
538 |
}
|
|
539 |
|
|
540 |
err = FindMessageTagWithValue( KVMsgTagEnd, KVMsgSectionVBody );
|
|
541 |
if (err < 0)
|
|
542 |
{
|
|
543 |
return err;
|
|
544 |
}
|
|
545 |
else
|
|
546 |
{
|
|
547 |
TInt bodyLength = err - bodyStart;
|
|
548 |
iMessageBody = HBufC::NewL( bodyLength );
|
|
549 |
TPtrC pData = iReadBuf.Mid( bodyStart, bodyLength );
|
|
550 |
TPtr pMsgBody = iMessageBody->Des();
|
|
551 |
pMsgBody.Copy( pData );
|
|
552 |
pMsgBody.Trim();
|
|
553 |
err = pMsgBody.Length();
|
|
554 |
LOG( pMsgBody );
|
|
555 |
}
|
|
556 |
|
|
557 |
return err;
|
|
558 |
}
|
|
559 |
|
|
560 |
// -----------------------------------------------------------------------------
|
|
561 |
// CVMessageParser::FindMessageTagWithValue()
|
|
562 |
// -----------------------------------------------------------------------------
|
|
563 |
//
|
|
564 |
TInt CVMessageParser::FindMessageTagWithValue( const TDesC& aMsgTag, const TDesC& aValue )
|
|
565 |
{
|
|
566 |
TBuf<KTagAndValueMaxLength> tagAndValue( aMsgTag );
|
|
567 |
tagAndValue.Append( aValue );
|
|
568 |
|
|
569 |
TPtrC pBuf = iReadBuf.Mid( iReadBufPosition );
|
|
570 |
|
|
571 |
TInt err;
|
|
572 |
TInt tagStartPosition;
|
|
573 |
|
|
574 |
err = pBuf.Find( tagAndValue );
|
|
575 |
if (err < 0)
|
|
576 |
{
|
|
577 |
LOGGER_WRITE( "Message tag with value not found" );
|
|
578 |
return err;
|
|
579 |
}
|
|
580 |
else
|
|
581 |
{
|
|
582 |
tagStartPosition = iReadBufPosition + err; // position before tag and value
|
|
583 |
iReadBufPosition += ( err + tagAndValue.Length() ); // position after tag and value
|
|
584 |
}
|
|
585 |
|
|
586 |
return tagStartPosition;
|
|
587 |
}
|
|
588 |
|
|
589 |
// -----------------------------------------------------------------------------
|
|
590 |
// CVMessageParser::GetMessageTagValue()
|
|
591 |
// -----------------------------------------------------------------------------
|
|
592 |
//
|
|
593 |
TInt CVMessageParser::GetMessageTagValue( const TDesC& aMsgTag, TDes& aValue, TBool aMoveReadBufPosition )
|
|
594 |
{
|
|
595 |
TInt err;
|
|
596 |
TInt valueLength;
|
|
597 |
TInt readBufPosition( iReadBufPosition );
|
|
598 |
|
|
599 |
TPtrC pBuf = iReadBuf.Mid( readBufPosition );
|
|
600 |
|
|
601 |
err = pBuf.Find( aMsgTag );
|
|
602 |
if (err < 0)
|
|
603 |
{
|
|
604 |
LOGGER_WRITE( "Message tag not found" );
|
|
605 |
return err;
|
|
606 |
}
|
|
607 |
else
|
|
608 |
{
|
|
609 |
readBufPosition += (err + aMsgTag.Length());
|
|
610 |
}
|
|
611 |
|
|
612 |
TPtrC pValueStart = iReadBuf.Mid( readBufPosition );
|
|
613 |
|
|
614 |
err = pValueStart.Find( KVMsgLineFeed );
|
|
615 |
if (err < 0)
|
|
616 |
{
|
|
617 |
return err;
|
|
618 |
}
|
|
619 |
else
|
|
620 |
{
|
|
621 |
valueLength = err;
|
|
622 |
}
|
|
623 |
|
|
624 |
StoreMessageDataField( readBufPosition, valueLength, aValue );
|
|
625 |
|
|
626 |
if ( aMoveReadBufPosition )
|
|
627 |
{
|
|
628 |
iReadBufPosition = readBufPosition;
|
|
629 |
}
|
|
630 |
|
|
631 |
return valueLength;
|
|
632 |
}
|
|
633 |
|
|
634 |
// -----------------------------------------------------------------------------
|
|
635 |
// CVMessageParser::StoreMessageDataField()
|
|
636 |
// -----------------------------------------------------------------------------
|
|
637 |
//
|
|
638 |
void CVMessageParser::StoreMessageDataField(TInt aStart, TInt aLength, TDes &aLocalStore)
|
|
639 |
{
|
|
640 |
TInt copyLength;
|
|
641 |
|
|
642 |
copyLength = aLength > aLocalStore.MaxLength() ? aLocalStore.MaxLength() : aLength;
|
|
643 |
|
|
644 |
TPtrC pData = iReadBuf.Mid( aStart, copyLength );
|
|
645 |
aLocalStore.Copy( pData );
|
|
646 |
aLocalStore.Trim();
|
|
647 |
|
|
648 |
if (copyLength < aLength)
|
|
649 |
{
|
|
650 |
LOGGER_WRITE_2( "Data length: %d, stored: %d", aLength, copyLength );
|
|
651 |
}
|
|
652 |
}
|
|
653 |
|
|
654 |
// -----------------------------------------------------------------------------
|
|
655 |
// CVMessageParser::WriteMessagePropertiesL()
|
|
656 |
// -----------------------------------------------------------------------------
|
|
657 |
//
|
|
658 |
void CVMessageParser::WriteMessagePropertiesL()
|
|
659 |
{
|
|
660 |
LOGGER_WRITE( "CVMessageParser::WriteMessagePropertiesL()" );
|
|
661 |
WriteMessageLineL( KVMsgTagVersion, KVMsgVersion );
|
|
662 |
WriteMessageLineL( KVMsgTagStatus, iStatus );
|
|
663 |
WriteMessageLineL( KVMsgTagBox, iFolder );
|
|
664 |
WriteTaggedTimestampL( iUniversalTime );
|
|
665 |
}
|
|
666 |
|
|
667 |
// -----------------------------------------------------------------------------
|
|
668 |
// CVMessageParser::WriteMessageVCARDL()
|
|
669 |
// -----------------------------------------------------------------------------
|
|
670 |
//
|
|
671 |
void CVMessageParser::WriteMessageVCARDL(const TDesC& aName, const TDesC& aNumber)
|
|
672 |
{
|
|
673 |
LOGGER_WRITE( "CVMessageParser::WriteMessageVCARDL()" );
|
|
674 |
WriteMessageLineL( KVMsgTagBegin, KVMsgSectionVCard );
|
|
675 |
WriteMessageLineL( KVMsgTagVersion, KVMsgVCardVersion );
|
|
676 |
WriteMessageLineL( KVMsgTagName, aName );
|
|
677 |
WriteMessageLineL( KVMsgTagTelephone, aNumber );
|
|
678 |
WriteMessageLineL( KVMsgTagEnd, KVMsgSectionVCard );
|
|
679 |
}
|
|
680 |
|
|
681 |
// -----------------------------------------------------------------------------
|
|
682 |
// CVMessageParser::WriteMessageEnvelopeL()
|
|
683 |
// -----------------------------------------------------------------------------
|
|
684 |
//
|
|
685 |
void CVMessageParser::WriteMessageEnvelopeL()
|
|
686 |
{
|
|
687 |
LOGGER_WRITE( "CVMessageParser::WriteMessageEnvelopeL()" );
|
|
688 |
|
|
689 |
TInt i;
|
|
690 |
TInt numRecipients = iRecipients.Count();
|
|
691 |
|
|
692 |
for (i = 0; i < numRecipients; i++)
|
|
693 |
{
|
|
694 |
WriteMessageLineL( KVMsgTagBegin, KVMsgSectionVEnv );
|
|
695 |
WriteMessageVCARDL( iRecipients[i].iName, iRecipients[i].iNumber );
|
|
696 |
}
|
|
697 |
|
|
698 |
WriteMessageLineL( KVMsgTagBegin, KVMsgSectionVEnv );
|
|
699 |
WriteMessageBodyL();
|
|
700 |
WriteMessageLineL( KVMsgTagEnd, KVMsgSectionVEnv );
|
|
701 |
|
|
702 |
for (i = 0; i < numRecipients; i++)
|
|
703 |
{
|
|
704 |
WriteMessageLineL( KVMsgTagEnd, KVMsgSectionVEnv );
|
|
705 |
}
|
|
706 |
}
|
|
707 |
|
|
708 |
// -----------------------------------------------------------------------------
|
|
709 |
// CVMessageParser::WriteTaggedTimestampL()
|
|
710 |
// -----------------------------------------------------------------------------
|
|
711 |
//
|
|
712 |
void CVMessageParser::WriteTaggedTimestampL( TTime aUniversalTime )
|
|
713 |
{
|
|
714 |
LOGGER_WRITE( "CVMessageParser::WriteTaggedTimestamp()" );
|
|
715 |
|
|
716 |
TDateTime dateTime = aUniversalTime.DateTime();
|
|
717 |
|
|
718 |
TBuf<16> timestamp;
|
|
719 |
|
|
720 |
// Default timesamp format: yyyymmddThhmmssZ - like 20060329T091530Z
|
|
721 |
_LIT( KTimestampFormat, "%+04d%+02d%+02dT%+02d%+02d%+02dZ" );
|
|
722 |
timestamp.Format( KTimestampFormat,
|
|
723 |
dateTime.Year(),
|
|
724 |
dateTime.Month() + 1,
|
|
725 |
dateTime.Day() + 1,
|
|
726 |
dateTime.Hour(),
|
|
727 |
dateTime.Minute(),
|
|
728 |
dateTime.Second() );
|
|
729 |
|
|
730 |
WriteMessageLineL( KVMsgTagDateTime, timestamp );
|
|
731 |
}
|
|
732 |
|
|
733 |
// -----------------------------------------------------------------------------
|
|
734 |
// CVMessageParser::WriteMessageBodyL()
|
|
735 |
// -----------------------------------------------------------------------------
|
|
736 |
//
|
|
737 |
void CVMessageParser::WriteMessageBodyL()
|
|
738 |
{
|
|
739 |
LOGGER_WRITE( "CVMessageParser::WriteMessageBodyL()" );
|
|
740 |
|
|
741 |
WriteMessageLineL( KVMsgTagBegin, KVMsgSectionVBody );
|
|
742 |
|
|
743 |
// "Date" field is always device local time, not UTC
|
|
744 |
TBuf<KDateMaxLength> dateStr;
|
|
745 |
_LIT( KDateFormat, "%F%*D.%*M.%Y% %H:%T:%S" );
|
|
746 |
iHomeTime.FormatL( dateStr, KDateFormat );
|
|
747 |
WriteMessageLineL(KVMsgTagDate, dateStr );
|
|
748 |
|
|
749 |
if (iMessageBody)
|
|
750 |
{
|
|
751 |
LOG(*iMessageBody);
|
|
752 |
WriteMessageLineL( KDesNoData, *iMessageBody, EFalse );
|
|
753 |
}
|
|
754 |
else
|
|
755 |
{
|
|
756 |
LOGGER_WRITE( "Message body empty" );
|
|
757 |
}
|
|
758 |
|
|
759 |
WriteMessageLineL( KVMsgTagEnd, KVMsgSectionVBody );
|
|
760 |
}
|
|
761 |
|
|
762 |
// -----------------------------------------------------------------------------
|
|
763 |
// CVMessageParser::WriteMessageLineL()
|
|
764 |
// -----------------------------------------------------------------------------
|
|
765 |
//
|
|
766 |
void CVMessageParser::WriteMessageLineL( const TDesC& aMsgLineTag, const TDesC& aMsgLineData, TBool aIndent )
|
|
767 |
{
|
|
768 |
if (aIndent)
|
|
769 |
{
|
|
770 |
TInt indent = GetIndentLevel( aMsgLineTag );
|
|
771 |
TBuf<KTagAndValueMaxLength> indentSpace;
|
|
772 |
indentSpace.AppendFill( TChar(' '), indent );
|
|
773 |
WriteToMessageL( indentSpace );
|
|
774 |
}
|
|
775 |
|
|
776 |
if (aMsgLineTag.Length() > 0)
|
|
777 |
{
|
|
778 |
WriteToMessageL( aMsgLineTag );
|
|
779 |
}
|
|
780 |
|
|
781 |
WriteToMessageL( aMsgLineData );
|
|
782 |
WriteToMessageL( KVMsgLineFeed );
|
|
783 |
}
|
|
784 |
|
|
785 |
// -----------------------------------------------------------------------------
|
|
786 |
// CVMessageParser::WriteToMessageL()
|
|
787 |
// -----------------------------------------------------------------------------
|
|
788 |
//
|
|
789 |
void CVMessageParser::WriteToMessageL( const TDesC &aData )
|
|
790 |
{
|
|
791 |
TPtrC8 writeData;
|
|
792 |
|
|
793 |
const TUint16* ptr16 = aData.Ptr();
|
|
794 |
const TUint8* ptr8 = reinterpret_cast<const TUint8*>(ptr16);
|
|
795 |
writeData.Set( ptr8, aData.Length()*2 );
|
|
796 |
|
|
797 |
TInt newPosition = iWriteBufPosition + writeData.Length();
|
|
798 |
|
|
799 |
if (newPosition > iWriteBufSize)
|
|
800 |
{
|
|
801 |
LOGGER_WRITE( "Expand write buffer" );
|
|
802 |
TInt expandStep = newPosition - iWriteBufSize + 100;
|
|
803 |
iWriteBuf->ExpandL( iWriteBufSize, expandStep );
|
|
804 |
iWriteBufSize += expandStep;
|
|
805 |
LOGGER_WRITE_1( "Write buffer expanded to %d bytes", iWriteBufSize );
|
|
806 |
}
|
|
807 |
|
|
808 |
iWriteBuf->Write( iWriteBufPosition, writeData );
|
|
809 |
iWriteBufPosition = newPosition;
|
|
810 |
}
|
|
811 |
|
|
812 |
|
|
813 |
// -----------------------------------------------------------------------------
|
|
814 |
// CVMessageParser::GetIndentLevel()
|
|
815 |
// -----------------------------------------------------------------------------
|
|
816 |
//
|
|
817 |
TInt CVMessageParser::GetIndentLevel( const TDesC& aMsgLineTag )
|
|
818 |
{
|
|
819 |
if (aMsgLineTag.Compare( KVMsgTagEnd ) == 0)
|
|
820 |
{
|
|
821 |
iWriteIndentLevel--;
|
|
822 |
}
|
|
823 |
TInt result = iWriteIndentLevel * KIndentStepSize;
|
|
824 |
|
|
825 |
if (aMsgLineTag.Compare( KVMsgTagBegin ) == 0)
|
|
826 |
{
|
|
827 |
iWriteIndentLevel++;
|
|
828 |
}
|
|
829 |
return result;
|
|
830 |
}
|
|
831 |
|
|
832 |
// -----------------------------------------------------------------------------
|
|
833 |
// CVMessageParser::AssignDataToBuffer()
|
|
834 |
// -----------------------------------------------------------------------------
|
|
835 |
//
|
|
836 |
void CVMessageParser::AssignDataToBuffer( const TDesC &aData, TDes &aBuffer )
|
|
837 |
{
|
|
838 |
aBuffer.Zero();
|
|
839 |
|
|
840 |
if (aBuffer.MaxLength() >= aData.Length())
|
|
841 |
{
|
|
842 |
aBuffer = aData;
|
|
843 |
}
|
|
844 |
else
|
|
845 |
{
|
|
846 |
LOGGER_WRITE_1( "AssignDataToBuffer: too short buffer for data: %d", aBuffer.MaxLength() );
|
|
847 |
LOG( aData );
|
|
848 |
aBuffer = aData.Left( aBuffer.MaxLength() );
|
|
849 |
}
|
|
850 |
}
|
|
851 |
|
|
852 |
|
|
853 |
// End of File
|