1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
53 class CParserProperty;
56 class CParserPropertyValueCDesCArray;
58 const TInt KRandomnumberlen = 5;
59 const TInt KMaxGeneratedfilenamelen =16;
64 class CParserParam : public CBase
65 /** A Versit property parameter.
67 A property parameter consists of a name and optionally a value, both in descriptor
68 form. Parser properties (class CParserProperty) may own one or more property
73 The private parameter name and value members are stored as narrow (8-bit)
74 rather than 16-bit Unicode descriptors.
76 However, certain member functions take or return a Unicode value,
77 for the purpose of backwards compatibility. In this case a simple conversion
78 takes place: this ignores the top 8 bits (for Unicode -> Narrow) or adds zero
79 for the top 8-bits (for Narrow->Unicode).
85 IMPORT_C static CParserParam* NewL(const TDesC8& aName, const TDesC8& aValue);
86 IMPORT_C static CParserParam* NewL(const TDesC8& aName, const TDesC& aValue);
87 IMPORT_C ~CParserParam();
88 IMPORT_C void SetValueL(const TDesC8& aValue);
89 IMPORT_C void SetValueL(HBufC8* aValue);
90 IMPORT_C TInt ExternalizeL(RWriteStream& aStream) const;
91 IMPORT_C TPtrC8 Name() const;
92 IMPORT_C TPtrC8 Value() const;
93 IMPORT_C HBufC* ValueL() const;
94 IMPORT_C TInt ExternalizeL(RWriteStream& aStream, TInt& aLengthOutput, CVersitParser* aVersitParser) const;
96 CParserParam(HBufC8* aName, HBufC8* aValue);
106 class TVersitDateTime
107 /** Defines a Versit date and time.
109 This class is used throughout Versit to represent the date and time. It uses
110 a TDateTime object to store the date/time value and records whether this value
111 is local to the machine which originated the vCard, local to the machine on
112 which the code is running, or universal time (UTC).
114 The Year(), Month() and Day() member functions of class TDateTime may be used
115 to extract the date and time components from the TVersitDateTime::iDateTime.
120 /** Relative time flags. */
123 /** Time is stored in UTC. */
125 /** Time is local to the machine which originated the vCard. */
127 /** Time is local to the machine on which the code is running. */
132 IMPORT_C TVersitDateTime(const TDateTime& aDateTime,TRelativeTime aRelativeTime);
136 @deprecated since 9.1*/
137 enum TVersitDateTimeFlags
140 /** Indicates whether the relative time is to be externalized along with the date/time
143 The flag is set to 'EExportNullFlag' by default.
145 This is only implemented (by CParserTimePropertyValue::EncodeVersitDateTimeL())
146 if the date/time is universal. When the flag is set, the externalised value
147 is followed by the token, KVersitTokenUniversalTime. */
148 EExportTimeZoneDesignator=0x01,
149 EExportLeaveAsLocalTime=0x02
152 @deprecated since 9.1
154 inline void SetFlag(TVersitDateTimeFlags aFlag) { iFlags |= aFlag; }
156 @deprecated since 9.1
158 inline TBool IsFlagSet(TVersitDateTimeFlags aFlag) const { return iFlags & aFlag; }
160 @deprecated since 9.1
162 inline void ClearFlag(TVersitDateTimeFlags aFlag) { iFlags &= ~aFlag; }
164 /** The date/time value. */
166 /** Specifies whether the time value is local to the machine which originated the
167 vCard, local to the machine on which the code is running, or universal. */
168 TRelativeTime iRelativeTime;
174 // CParserPropertyValue
176 class CParserPropertyValue : public CBase
177 /** Abstract base class for all property values.
179 Defines a pure virtual ExternalizeL() function which should write out the
180 property value to a stream.
182 The type of derived class is returned by the Uid() function; the UID value is
183 specified on construction.
185 The other functions relate to the character set, encoding format and plug-in
186 used during externalising.
192 /** Externalises the property value to a write stream.
194 Implementations of this function are invoked by the parser's ExternalizeL()
197 @param aStream Stream to which the property value is externalised.
198 @param aEncodingCharset The character set and encoding information.
199 @param aLengthOutput The amount of text that has been outputted so far on the
200 line (for the property name), which may need to be taken into account when
201 calculating if and where any line break should occur. */
202 virtual void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput)=0;
203 IMPORT_C virtual TBool IsAsciiCharacterSetSufficient();
204 IMPORT_C virtual void EncodeL(CBufBase* aTarget,const TDesC8& aSource,const TUid& aEncoding) const;
205 IMPORT_C virtual TBool SupportsInterface(const TUid& /*aInterfaceUid*/) const;
206 inline TUid Uid() const;
207 inline void SetPlugIn(MVersitPlugIn* aPlugIn);
209 IMPORT_C CParserPropertyValue(const TUid& aPropertyValueUid);
210 IMPORT_C void FoldEncodeAndWriteValueToStreamL(RWriteStream& aStream, const TDesC& aValue
211 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
212 IMPORT_C void FoldEncodeAndWriteValueToStreamL(RWriteStream& aStream, const CDesCArray* aValueArray
213 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
214 IMPORT_C void FoldAndWriteValueToStreamL(RWriteStream& aStream, const TDesC& aValue
215 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
216 IMPORT_C static void Append(TDes16& aTarget,TDesC8& aSource);
218 inline MVersitPlugIn* PlugIn();
221 TUid iPropertyValueTypeUid;
222 MVersitPlugIn* iPlugIn;
226 // CParserTimePropertyValue
229 class CVersitDaylight;
231 class CParserTimePropertyValue : public CParserPropertyValue
232 /** Abstract base class for all of the date/time property value classes.
234 Provides date/time conversion functions between machine-local and universal
237 The date/time property value classes are CParserPropertyValueAlarm,
238 CParserPropertyValueDate, CParserPropertyValueDateTime,
239 CParserPropertyValueMultiDateTime, CParserPropertyValueDaylight and
240 CParserPropertyValueRecurrence.
246 /** This is implemented, where applicable, to convert date/time
247 values into universal time.
249 The date/time is checked against the daylight saving information provided
250 in aDaylight. If it falls inside the daylight saving period then the daylight
251 saving offset is subtracted from the time to convert it to universal time.
252 Otherwise aIncrement is added to the date/time of the alarm to convert it
255 Note that the daylight savings offset will adjust the time both for the daylight
256 saving and for the time zone.
258 The function has no effect if it date/times are already stored in universal
261 If aDaylight is a NULL pointer then aIncrement is used.
263 @param aIncrement A time interval in seconds which represents the time zone's
264 offset from universal time.
265 @param aDaylight Pointer to the specification for daylight saving. If the alarm's
266 time value is within the period for daylight saving, the value is modified
267 by the daylight saving offset (which accounts for both the time zone and daylight
269 @deprecated since 9.1
271 IMPORT_C virtual void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight)=0;
272 /** Pure virtual function which is implemented, where applicable, to convert the
273 date/time property value into machine-local time.
275 This process involves adjusting the date/time value by the offset in aIncrement.
277 The function has no effect if the value is already stored as machine-local
280 The universal date/times are assumed to have been corrected for any daylight saving
283 @param aIncrement A time interval which represents the number of seconds which
284 is to be added to the date/time value. This should normally be the universal
285 time offset for the machine's locale.
286 @deprecated since 9.1 */
287 IMPORT_C virtual void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement)=0;
288 static void ConvertDateTime(TDateTime& aDateTime,const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight,TBool aTo);
289 public: //from CParserPropertyValue
290 IMPORT_C virtual TBool SupportsInterface(const TUid& aInterfaceUid) const;
292 IMPORT_C CParserTimePropertyValue(const TUid& aPropertyValueUid);
293 IMPORT_C void ConvertDateTime(TDateTime* aDateTime,const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
294 IMPORT_C void EncodeVersitDateTimeL(TDes8& aBuf,const TVersitDateTime& aDateTime,TBool aEncodeTime=ETrue) const;
295 IMPORT_C void EncodeTimePeriodL(TDes8& aBuf,const TTime& aTimePeriod) const;
299 // CParserPropertyValueHBufC
301 class CParserPropertyValueHBufC : public CParserPropertyValue
302 /** A heap descriptor property value parser.
304 Many properties are stored using this class. Examples are vCard e-mails and
307 The UID for a heap descriptor property value is KVersitPropertyHBufCUid.
313 IMPORT_C static CParserPropertyValueHBufC* NewL(const TDesC& aValue);
314 IMPORT_C CParserPropertyValueHBufC(HBufC16* aValue);
315 IMPORT_C ~CParserPropertyValueHBufC();
316 IMPORT_C TPtrC Value() const;
317 IMPORT_C HBufC* TakeValueOwnership();
318 IMPORT_C CParserPropertyValueCDesCArray* TreatAsArrayPropertyLC(const CParserProperty& aOwningProperty) const;
319 public: // from CParserPropertyValue
320 IMPORT_C TBool IsAsciiCharacterSetSufficient();
321 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
323 CParserPropertyValueHBufC();
324 void ConstructL(const TDesC& aValue);
330 // CParserPropertyValueBinary
333 class CParserPropertyValueBinary : public CParserPropertyValue
334 /** A binary property value parser.
336 It is used to store logos, photos, alarm content and binary attachment as binary values.
338 The UID for a binary property value is KVersitPropertyBinaryUid.
344 IMPORT_C static CParserPropertyValueBinary* NewL(const TDesC8& aValue);
345 IMPORT_C static CParserPropertyValueBinary* NewLC(const TDesC8& aValue);
347 inline CParserPropertyValueBinary(CBufSeg& aValue);
348 IMPORT_C ~CParserPropertyValueBinary();
349 IMPORT_C const CBufSeg* Value() const;
350 public: // from CParserPropertyValue
351 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
353 inline CParserPropertyValueBinary();
354 void ConstructL(const TDesC8& aValue);
355 void ExternalizeL(RWriteStream& aStream, const Versit::TEncodingAndCharset& aEncodingCharset, TInt aLengthOutput, RReadStream& aReadStream);
361 NONSHARABLE_CLASS(CParserPropertyValueBinaryFile) : public CParserPropertyValueBinary
362 /** A file property value parser.
364 It is used to store a file handle so that the binary data can be read through the handle when exporting.
365 It is not used when importing.
366 The UID for a binary property value is KVersitPropertyBinaryUid.
372 IMPORT_C static CParserPropertyValueBinaryFile* NewL(const RFile& aFileHandle);
373 IMPORT_C ~CParserPropertyValueBinaryFile();
374 public: // from CParserPropertyValue
375 void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
378 void ConstructL(const RFile& aFileHandle);
380 RFileReadStream iFileStream;
383 // CParserPropertyValueCDesCArray
385 class CParserPropertyValueCDesCArray : public CParserPropertyValue
386 /** A property value parser which stores an array of descriptors.
388 Can be used by both vCards and vCalendars, for example to store a postal address
389 or information about an organisation.
391 The UID for a descriptor array property value is KVersitPropertyCDesCArrayUid.
397 IMPORT_C CParserPropertyValueCDesCArray(CDesCArray* aValue);
398 IMPORT_C ~CParserPropertyValueCDesCArray();
399 inline CDesCArray* Value() const;
400 IMPORT_C TBool IsPresent(const TDesC& aValue) const;
401 public: // from CParserPropertyValue
402 IMPORT_C TBool IsAsciiCharacterSetSufficient();
403 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
409 // CParserPropertyValueTimeZone
412 class CParserPropertyValueTimeZone: public CParserPropertyValue
413 /** A time zone property value parser.
415 Stores and externalises a property value which represents the time zone information
416 for a vCard or vCalendar.
418 The time zone is specified as the universal time offset. This is a time interval
419 which is a positive or negative number of seconds from universal time. Time
420 zones east of universal time have positive numbers. Time zones west of universal
421 time have negative numbers.
423 The UID for a time zone property value is KVersitPropertyTimeZoneUid.
429 static void EncodeTimeZone(TDes8& aBuf,TTimeIntervalSeconds iValue);
430 IMPORT_C CParserPropertyValueTimeZone(TTimeIntervalSeconds aValue);
431 inline TTimeIntervalSeconds Value() const;
432 public: // from CParserPropertyValue
433 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
435 TTimeIntervalSeconds iValue;
441 class CVersitDaylight : public CBase
442 /** Universal time offset information, including the daylight savings offset.
444 This class deals with the daylight saving offset: a one hour offset that occurs
445 in many countries during part of the year. This offset needs to be taken into
446 account when converting Versit times (TVersitDateTimes) between universal
447 and machine-local times.
449 This class stores information about the offset, including its length in seconds,
450 when it takes effect and the standard time designations.
452 Note that the universal offset (iOffset) is the sum of the daylight saving
453 offset and any time zone offset, as it is the absolute offset from GMT.
455 An instance of this class is owned by the CParserPropertyValueDaylight class.
461 IMPORT_C static CVersitDaylight* NewL(TBool aSavings, TTimeIntervalSeconds aOffset, TVersitDateTime* aStartTime, TVersitDateTime* aEndTime, const TDesC& aStandardDesignation, const TDesC& aDaylightDesignation);
462 IMPORT_C ~CVersitDaylight();
464 CVersitDaylight(TBool aSavings, TTimeIntervalSeconds aOffset, TVersitDateTime* aStartTime, TVersitDateTime* aEndTime);
465 void ConstructL(const TDesC& aStandardDesignation, const TDesC& aDaylightDesignation);
467 /** A sort key than can be used when sorting an array of properties by start date/time. */
468 TInt64 iStartTimeSortKey;
469 /** The daylight savings flag: this is ETrue if daylight saving is in effect
470 in the locale and EFalse if not. */
472 /** The absolute offset from GMT, which is the sum of the time zone and daylight
473 saving offsets (in seconds). */
474 TTimeIntervalSeconds iOffset;
475 /** The date/time at which the period for daylight saving begins. */
476 TVersitDateTime* iStartTime;
477 /** The date/time at which the period for daylight saving ends. */
478 TVersitDateTime* iEndTime;
479 /** The standard time designation, e.g. GMT, EST. */
480 HBufC* iStandardDesignation;
481 /** The daylight saving time designation, e.g. BST, EDT. */
482 HBufC* iDaylightDesignation;
486 // CParserPropertyValueDaylight
488 class CParserPropertyValueDaylight : public CParserTimePropertyValue
489 /** A property value parser which contains the daylight savings rule for a vCalendar.
491 The property value is stored using an instance of the CVersitDaylight class.
493 The UID for a daylight savings rule property value is KVersitPropertyDaylightUid.
499 IMPORT_C CParserPropertyValueDaylight(CVersitDaylight* aValue);
500 IMPORT_C ~CParserPropertyValueDaylight();
501 inline CVersitDaylight* Value() const;
502 public: // from CParserTimePropertyValue
503 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
504 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
505 public: // from CParserPropertyValue
506 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
508 CVersitDaylight* iValue;
512 // CParserPropertyValueDateTime
514 class CParserPropertyValueDateTime : public CParserTimePropertyValue
515 /** A date/time property value parser.
517 The date/time value is contained in a TVersitDateTime object.
519 The UID for a date/time property value is KVersitPropertyDateTimeUid.
525 IMPORT_C CParserPropertyValueDateTime(TVersitDateTime* aValue);
526 IMPORT_C ~CParserPropertyValueDateTime();
527 inline TVersitDateTime* Value() const;
528 public: // from CParserTimePropertyValue
529 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
530 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
531 public: // from CParserPropertyValue
532 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& /*aEncodingCharset*/,TInt /*aLengthOutput*/);
534 TVersitDateTime* iValue;
538 // CParserPropertyValueDate
540 class CParserPropertyValueDate : public CParserTimePropertyValue
541 /** A date property value parser.
543 The date value is contained in a TVersitDateTime object.
545 The UID for a date property value is KVersitPropertyDateUid.
551 IMPORT_C CParserPropertyValueDate(TVersitDateTime* aValue);
552 IMPORT_C ~CParserPropertyValueDate();
553 inline TVersitDateTime* Value() const;
554 public: // from CParserTimePropertyValue
555 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& /*aIncrement*/,const CVersitDaylight* /*aDaylight*/);
556 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& /*aIncrement*/);
557 public: // from CParserPropertyValue
558 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
560 TVersitDateTime* iValue;
564 // CParserPropertyValueMultiDateTime
566 class CParserPropertyValueMultiDateTime : public CParserTimePropertyValue
567 /** A property value parser which stores a list of date/time values using an array
568 of TVersitDateTime objects.
570 The UID for a multiple date/time property value is KVersitPropertyMultiDateTimeUid.
576 IMPORT_C CParserPropertyValueMultiDateTime(CArrayPtr<TVersitDateTime>* aValue);
577 IMPORT_C ~CParserPropertyValueMultiDateTime();
578 inline CArrayPtr<TVersitDateTime>* Value() const;
579 public: // from CParserTimePropertyValue
580 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
581 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
582 public: // from CParserPropertyValue
583 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& /*aEncodingCharset*/,TInt aLengthOutput);
585 CArrayPtr<TVersitDateTime>* iValue;
589 // CParserPropertyValueInt
591 class CParserPropertyValueInt : public CParserPropertyValue
592 /** An integer property value parser.
594 This stores a property value as a signed integer. For example, an employee
595 ID number might be stored using this class.
597 The UID for an integer property value is KVersitPropertyIntUid.
603 IMPORT_C CParserPropertyValueInt(TInt aValue);
604 inline TInt Value() const;
605 public: // from CParserPropertyValue
606 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
615 class CParserProperty : public CBase
616 /** A vCard or vCalendar property.
618 A property consists of a name, an optional value and one or more optional
621 The name, value and parameters are initialised on construction.
623 Versit properties have the general form:
625 Property Name (; Property Parameter Name(=Property Parameter Value)* : Property
628 where items in brackets are optional and * indicates that the item may be
631 For instance, TEL; HOME; ENCODING=QUOTED-PRINTABLE; CHARSET=US-ASCII : 01234 567890
633 Here, TEL is the property name; HOME, ENCODING and CHARSET are property parameter
634 names; QUOTED-PRINTABLE and US-ASCII are property parameter values. The component
635 following the colon is the property value.
637 Properties also have a name UID, which set during internalisation of a property
638 and used only during internalisation. It is set by SetNameUid() and is used
639 to allow number comparisons during internalisation. This provides a faster
640 alternative to string comparisons when checking a property to see if it is
641 a significant one (e.g. a begin or binary property). This is the only use
642 of the name UID: it is not used during externalisation of a property.
644 Note that grouped properties are supported by the derived class, CParserGroupedProperty.
645 The vCalender parser does not have property groups, and so stores all properties
646 using this base class, whereas the vCard parser stores all properties using
647 CParserGroupedProperty.
653 IMPORT_C static CParserProperty* NewL(CParserPropertyValue& aPropertyValue, const TDesC8& aName, CArrayPtr<CParserParam>* aArrayOfParams);
654 IMPORT_C CParserProperty(CArrayPtr<CParserParam>* aArrayOfParams);
655 IMPORT_C ~CParserProperty();
656 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream, CVersitParser* aVersitParser = NULL);
657 IMPORT_C CParserParam* Param(const TDesC8& aParamName) const; // note params can only appear once
658 IMPORT_C void AddParamL(CParserParam* aParam);
659 IMPORT_C void DeleteParam(TDesC8& aParamName);
660 IMPORT_C void SetNameL(const TDesC8& aName);
661 IMPORT_C virtual TBool SupportsInterface(const TUid& /*aInterfaceUid*/) const;
662 IMPORT_C TPtrC8 Name() const;
663 inline void SetValue(CParserPropertyValue* aPropertyValue);
664 inline CParserPropertyValue* Value() const;
665 inline TUid Uid() const;
666 inline void SetNameUid(TUid aUid);
667 inline TUid NameUid() const;
668 inline void SetParamArray(CArrayPtr<CParserParam>* aArrayOfParams);
671 IMPORT_C TBool LoadBinaryValuesFromFilesL(RFs& aFileSession);
672 IMPORT_C TBool SaveBinaryValuesToFilesL(TInt aSizeThreshold,const TDesC& aPath,RFs& aFileSession);
674 IMPORT_C CParserProperty(CParserPropertyValue& aPropertyValue, CArrayPtr<CParserParam>* aArrayOfParams);
675 IMPORT_C static void ConstructSelfL(CParserProperty& aSelf,const TDesC8& aName);
678 IMPORT_C CArrayPtr<CParserParam>* ParamArray()const;
681 CParserPropertyValue* iPropertyValue;
682 HBufC8* iPropertyName;
683 TUid iPropertyNameUid;
684 CArrayPtr<CParserParam>* iArrayOfParams;
687 friend class CVersitParser;
688 inline HBufC8*& NameBuf();
689 IMPORT_C virtual void Reserved();
690 void ReadBinaryDataL(const CBufSeg* aBufseg_ptr,HBufC8** aBuffer);
691 void GenerateNameAndCreateFileL(RFs& aFileSession,TPtr8 aPropertyName,RFile& aFile,TDes& aFileName);