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 "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
53 class CParserProperty;
56 class CParserPropertyValueCDesCArray;
58 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
59 const TInt KRandomnumberlen = 5;
60 const TInt KMaxGeneratedfilenamelen =16;
66 class CParserParam : public CBase
67 /** A Versit property parameter.
69 A property parameter consists of a name and optionally a value, both in descriptor
70 form. Parser properties (class CParserProperty) may own one or more property
75 The private parameter name and value members are stored as narrow (8-bit)
76 rather than 16-bit Unicode descriptors.
78 However, certain member functions take or return a Unicode value,
79 for the purpose of backwards compatibility. In this case a simple conversion
80 takes place: this ignores the top 8 bits (for Unicode -> Narrow) or adds zero
81 for the top 8-bits (for Narrow->Unicode).
87 IMPORT_C static CParserParam* NewL(const TDesC8& aName, const TDesC8& aValue);
88 IMPORT_C static CParserParam* NewL(const TDesC8& aName, const TDesC& aValue);
89 IMPORT_C ~CParserParam();
90 IMPORT_C void SetValueL(const TDesC8& aValue);
91 IMPORT_C void SetValueL(HBufC8* aValue);
92 IMPORT_C TInt ExternalizeL(RWriteStream& aStream) const;
93 IMPORT_C TPtrC8 Name() const;
94 IMPORT_C TPtrC8 Value() const;
95 IMPORT_C HBufC* ValueL() const;
96 IMPORT_C TInt ExternalizeL(RWriteStream& aStream, TInt& aLengthOutput, CVersitParser* aVersitParser) const;
98 CParserParam(HBufC8* aName, HBufC8* aValue);
108 class TVersitDateTime
109 /** Defines a Versit date and time.
111 This class is used throughout Versit to represent the date and time. It uses
112 a TDateTime object to store the date/time value and records whether this value
113 is local to the machine which originated the vCard, local to the machine on
114 which the code is running, or universal time (UTC).
116 The Year(), Month() and Day() member functions of class TDateTime may be used
117 to extract the date and time components from the TVersitDateTime::iDateTime.
122 /** Relative time flags. */
125 /** Time is stored in UTC. */
127 /** Time is local to the machine which originated the vCard. */
129 /** Time is local to the machine on which the code is running. */
134 IMPORT_C TVersitDateTime(const TDateTime& aDateTime,TRelativeTime aRelativeTime);
138 @deprecated since 9.1*/
139 enum TVersitDateTimeFlags
142 /** Indicates whether the relative time is to be externalized along with the date/time
145 The flag is set to 'EExportNullFlag' by default.
147 This is only implemented (by CParserTimePropertyValue::EncodeVersitDateTimeL())
148 if the date/time is universal. When the flag is set, the externalised value
149 is followed by the token, KVersitTokenUniversalTime. */
150 EExportTimeZoneDesignator=0x01,
151 EExportLeaveAsLocalTime=0x02
154 @deprecated since 9.1
156 inline void SetFlag(TVersitDateTimeFlags aFlag) { iFlags |= aFlag; }
158 @deprecated since 9.1
160 inline TBool IsFlagSet(TVersitDateTimeFlags aFlag) const { return iFlags & aFlag; }
162 @deprecated since 9.1
164 inline void ClearFlag(TVersitDateTimeFlags aFlag) { iFlags &= ~aFlag; }
166 /** The date/time value. */
168 /** Specifies whether the time value is local to the machine which originated the
169 vCard, local to the machine on which the code is running, or universal. */
170 TRelativeTime iRelativeTime;
176 // CParserPropertyValue
178 class CParserPropertyValue : public CBase
179 /** Abstract base class for all property values.
181 Defines a pure virtual ExternalizeL() function which should write out the
182 property value to a stream.
184 The type of derived class is returned by the Uid() function; the UID value is
185 specified on construction.
187 The other functions relate to the character set, encoding format and plug-in
188 used during externalising.
194 /** Externalises the property value to a write stream.
196 Implementations of this function are invoked by the parser's ExternalizeL()
199 @param aStream Stream to which the property value is externalised.
200 @param aEncodingCharset The character set and encoding information.
201 @param aLengthOutput The amount of text that has been outputted so far on the
202 line (for the property name), which may need to be taken into account when
203 calculating if and where any line break should occur. */
204 virtual void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput)=0;
205 IMPORT_C virtual TBool IsAsciiCharacterSetSufficient();
206 IMPORT_C virtual void EncodeL(CBufBase* aTarget,const TDesC8& aSource,const TUid& aEncoding) const;
207 IMPORT_C virtual TBool SupportsInterface(const TUid& /*aInterfaceUid*/) const;
208 inline TUid Uid() const;
209 inline void SetPlugIn(MVersitPlugIn* aPlugIn);
211 IMPORT_C CParserPropertyValue(const TUid& aPropertyValueUid);
212 IMPORT_C void FoldEncodeAndWriteValueToStreamL(RWriteStream& aStream, const TDesC& aValue
213 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
214 IMPORT_C void FoldEncodeAndWriteValueToStreamL(RWriteStream& aStream, const CDesCArray* aValueArray
215 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
216 IMPORT_C void FoldAndWriteValueToStreamL(RWriteStream& aStream, const TDesC& aValue
217 ,const Versit::TEncodingAndCharset& aEncodingCharset,TInt& aLengthOutput) const;
218 IMPORT_C static void Append(TDes16& aTarget,TDesC8& aSource);
220 inline MVersitPlugIn* PlugIn();
223 TUid iPropertyValueTypeUid;
224 MVersitPlugIn* iPlugIn;
228 // CParserTimePropertyValue
231 class CVersitDaylight;
233 class CParserTimePropertyValue : public CParserPropertyValue
234 /** Abstract base class for all of the date/time property value classes.
236 Provides date/time conversion functions between machine-local and universal
239 The date/time property value classes are CParserPropertyValueAlarm,
240 CParserPropertyValueDate, CParserPropertyValueDateTime,
241 CParserPropertyValueMultiDateTime, CParserPropertyValueDaylight and
242 CParserPropertyValueRecurrence.
248 /** This is implemented, where applicable, to convert date/time
249 values into universal time.
251 The date/time is checked against the daylight saving information provided
252 in aDaylight. If it falls inside the daylight saving period then the daylight
253 saving offset is subtracted from the time to convert it to universal time.
254 Otherwise aIncrement is added to the date/time of the alarm to convert it
257 Note that the daylight savings offset will adjust the time both for the daylight
258 saving and for the time zone.
260 The function has no effect if it date/times are already stored in universal
263 If aDaylight is a NULL pointer then aIncrement is used.
265 @param aIncrement A time interval in seconds which represents the time zone's
266 offset from universal time.
267 @param aDaylight Pointer to the specification for daylight saving. If the alarm's
268 time value is within the period for daylight saving, the value is modified
269 by the daylight saving offset (which accounts for both the time zone and daylight
271 @deprecated since 9.1
273 IMPORT_C virtual void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight)=0;
274 /** Pure virtual function which is implemented, where applicable, to convert the
275 date/time property value into machine-local time.
277 This process involves adjusting the date/time value by the offset in aIncrement.
279 The function has no effect if the value is already stored as machine-local
282 The universal date/times are assumed to have been corrected for any daylight saving
285 @param aIncrement A time interval which represents the number of seconds which
286 is to be added to the date/time value. This should normally be the universal
287 time offset for the machine's locale.
288 @deprecated since 9.1 */
289 IMPORT_C virtual void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement)=0;
290 static void ConvertDateTime(TDateTime& aDateTime,const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight,TBool aTo);
291 public: //from CParserPropertyValue
292 IMPORT_C virtual TBool SupportsInterface(const TUid& aInterfaceUid) const;
294 IMPORT_C CParserTimePropertyValue(const TUid& aPropertyValueUid);
295 IMPORT_C void ConvertDateTime(TDateTime* aDateTime,const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
296 IMPORT_C void EncodeVersitDateTimeL(TDes8& aBuf,const TVersitDateTime& aDateTime,TBool aEncodeTime=ETrue) const;
297 IMPORT_C void EncodeTimePeriodL(TDes8& aBuf,const TTime& aTimePeriod) const;
301 // CParserPropertyValueHBufC
303 class CParserPropertyValueHBufC : public CParserPropertyValue
304 /** A heap descriptor property value parser.
306 Many properties are stored using this class. Examples are vCard e-mails and
309 The UID for a heap descriptor property value is KVersitPropertyHBufCUid.
315 IMPORT_C static CParserPropertyValueHBufC* NewL(const TDesC& aValue);
316 IMPORT_C CParserPropertyValueHBufC(HBufC16* aValue);
317 IMPORT_C ~CParserPropertyValueHBufC();
318 IMPORT_C TPtrC Value() const;
319 IMPORT_C HBufC* TakeValueOwnership();
320 IMPORT_C CParserPropertyValueCDesCArray* TreatAsArrayPropertyLC(const CParserProperty& aOwningProperty) const;
321 public: // from CParserPropertyValue
322 IMPORT_C TBool IsAsciiCharacterSetSufficient();
323 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
325 CParserPropertyValueHBufC();
326 void ConstructL(const TDesC& aValue);
332 // CParserPropertyValueBinary
335 class CParserPropertyValueBinary : public CParserPropertyValue
336 /** A binary property value parser.
338 It is used to store logos, photos, alarm content and binary attachment as binary values.
340 The UID for a binary property value is KVersitPropertyBinaryUid.
346 IMPORT_C static CParserPropertyValueBinary* NewL(const TDesC8& aValue);
347 IMPORT_C static CParserPropertyValueBinary* NewLC(const TDesC8& aValue);
349 inline CParserPropertyValueBinary(CBufSeg& aValue);
350 IMPORT_C ~CParserPropertyValueBinary();
351 IMPORT_C const CBufSeg* Value() const;
352 public: // from CParserPropertyValue
353 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
355 inline CParserPropertyValueBinary();
356 void ConstructL(const TDesC8& aValue);
357 void ExternalizeL(RWriteStream& aStream, const Versit::TEncodingAndCharset& aEncodingCharset, TInt aLengthOutput, RReadStream& aReadStream);
363 #ifndef SYMBIAN_ENABLE_SPLIT_HEADERS
364 NONSHARABLE_CLASS(CParserPropertyValueBinaryFile) : public CParserPropertyValueBinary
365 /** A file property value parser.
367 It is used to store a file handle so that the binary data can be read through the handle when exporting.
368 It is not used when importing.
369 The UID for a binary property value is KVersitPropertyBinaryUid.
375 IMPORT_C static CParserPropertyValueBinaryFile* NewL(const RFile& aFileHandle);
376 IMPORT_C ~CParserPropertyValueBinaryFile();
377 public: // from CParserPropertyValue
378 void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
381 void ConstructL(const RFile& aFileHandle);
383 RFileReadStream iFileStream;
385 #endif //SYMBIAN_ENABLE_SPLIT_HEADERS
386 // CParserPropertyValueCDesCArray
388 class CParserPropertyValueCDesCArray : public CParserPropertyValue
389 /** A property value parser which stores an array of descriptors.
391 Can be used by both vCards and vCalendars, for example to store a postal address
392 or information about an organisation.
394 The UID for a descriptor array property value is KVersitPropertyCDesCArrayUid.
400 IMPORT_C CParserPropertyValueCDesCArray(CDesCArray* aValue);
401 IMPORT_C ~CParserPropertyValueCDesCArray();
402 inline CDesCArray* Value() const;
403 IMPORT_C TBool IsPresent(const TDesC& aValue) const;
404 public: // from CParserPropertyValue
405 IMPORT_C TBool IsAsciiCharacterSetSufficient();
406 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
412 // CParserPropertyValueTimeZone
415 class CParserPropertyValueTimeZone: public CParserPropertyValue
416 /** A time zone property value parser.
418 Stores and externalises a property value which represents the time zone information
419 for a vCard or vCalendar.
421 The time zone is specified as the universal time offset. This is a time interval
422 which is a positive or negative number of seconds from universal time. Time
423 zones east of universal time have positive numbers. Time zones west of universal
424 time have negative numbers.
426 The UID for a time zone property value is KVersitPropertyTimeZoneUid.
432 static void EncodeTimeZone(TDes8& aBuf,TTimeIntervalSeconds iValue);
433 IMPORT_C CParserPropertyValueTimeZone(TTimeIntervalSeconds aValue);
434 inline TTimeIntervalSeconds Value() const;
435 public: // from CParserPropertyValue
436 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
438 TTimeIntervalSeconds iValue;
444 class CVersitDaylight : public CBase
445 /** Universal time offset information, including the daylight savings offset.
447 This class deals with the daylight saving offset: a one hour offset that occurs
448 in many countries during part of the year. This offset needs to be taken into
449 account when converting Versit times (TVersitDateTimes) between universal
450 and machine-local times.
452 This class stores information about the offset, including its length in seconds,
453 when it takes effect and the standard time designations.
455 Note that the universal offset (iOffset) is the sum of the daylight saving
456 offset and any time zone offset, as it is the absolute offset from GMT.
458 An instance of this class is owned by the CParserPropertyValueDaylight class.
464 IMPORT_C static CVersitDaylight* NewL(TBool aSavings, TTimeIntervalSeconds aOffset, TVersitDateTime* aStartTime, TVersitDateTime* aEndTime, const TDesC& aStandardDesignation, const TDesC& aDaylightDesignation);
465 IMPORT_C ~CVersitDaylight();
467 CVersitDaylight(TBool aSavings, TTimeIntervalSeconds aOffset, TVersitDateTime* aStartTime, TVersitDateTime* aEndTime);
468 void ConstructL(const TDesC& aStandardDesignation, const TDesC& aDaylightDesignation);
470 /** A sort key than can be used when sorting an array of properties by start date/time. */
471 TInt64 iStartTimeSortKey;
472 /** The daylight savings flag: this is ETrue if daylight saving is in effect
473 in the locale and EFalse if not. */
475 /** The absolute offset from GMT, which is the sum of the time zone and daylight
476 saving offsets (in seconds). */
477 TTimeIntervalSeconds iOffset;
478 /** The date/time at which the period for daylight saving begins. */
479 TVersitDateTime* iStartTime;
480 /** The date/time at which the period for daylight saving ends. */
481 TVersitDateTime* iEndTime;
482 /** The standard time designation, e.g. GMT, EST. */
483 HBufC* iStandardDesignation;
484 /** The daylight saving time designation, e.g. BST, EDT. */
485 HBufC* iDaylightDesignation;
489 // CParserPropertyValueDaylight
491 class CParserPropertyValueDaylight : public CParserTimePropertyValue
492 /** A property value parser which contains the daylight savings rule for a vCalendar.
494 The property value is stored using an instance of the CVersitDaylight class.
496 The UID for a daylight savings rule property value is KVersitPropertyDaylightUid.
502 IMPORT_C CParserPropertyValueDaylight(CVersitDaylight* aValue);
503 IMPORT_C ~CParserPropertyValueDaylight();
504 inline CVersitDaylight* Value() const;
505 public: // from CParserTimePropertyValue
506 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
507 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
508 public: // from CParserPropertyValue
509 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt aLengthOutput);
511 CVersitDaylight* iValue;
515 // CParserPropertyValueDateTime
517 class CParserPropertyValueDateTime : public CParserTimePropertyValue
518 /** A date/time property value parser.
520 The date/time value is contained in a TVersitDateTime object.
522 The UID for a date/time property value is KVersitPropertyDateTimeUid.
528 IMPORT_C CParserPropertyValueDateTime(TVersitDateTime* aValue);
529 IMPORT_C ~CParserPropertyValueDateTime();
530 inline TVersitDateTime* Value() const;
531 public: // from CParserTimePropertyValue
532 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
533 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
534 public: // from CParserPropertyValue
535 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& /*aEncodingCharset*/,TInt /*aLengthOutput*/);
537 TVersitDateTime* iValue;
541 // CParserPropertyValueDate
543 class CParserPropertyValueDate : public CParserTimePropertyValue
544 /** A date property value parser.
546 The date value is contained in a TVersitDateTime object.
548 The UID for a date property value is KVersitPropertyDateUid.
554 IMPORT_C CParserPropertyValueDate(TVersitDateTime* aValue);
555 IMPORT_C ~CParserPropertyValueDate();
556 inline TVersitDateTime* Value() const;
557 public: // from CParserTimePropertyValue
558 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& /*aIncrement*/,const CVersitDaylight* /*aDaylight*/);
559 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& /*aIncrement*/);
560 public: // from CParserPropertyValue
561 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
563 TVersitDateTime* iValue;
567 // CParserPropertyValueMultiDateTime
569 class CParserPropertyValueMultiDateTime : public CParserTimePropertyValue
570 /** A property value parser which stores a list of date/time values using an array
571 of TVersitDateTime objects.
573 The UID for a multiple date/time property value is KVersitPropertyMultiDateTimeUid.
579 IMPORT_C CParserPropertyValueMultiDateTime(CArrayPtr<TVersitDateTime>* aValue);
580 IMPORT_C ~CParserPropertyValueMultiDateTime();
581 inline CArrayPtr<TVersitDateTime>* Value() const;
582 public: // from CParserTimePropertyValue
583 IMPORT_C void ConvertAllDateTimesToUTCL(const TTimeIntervalSeconds& aIncrement,const CVersitDaylight* aDaylight);
584 IMPORT_C void ConvertAllUTCDateTimesToMachineLocalL(const TTimeIntervalSeconds& aIncrement);
585 public: // from CParserPropertyValue
586 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& /*aEncodingCharset*/,TInt aLengthOutput);
588 CArrayPtr<TVersitDateTime>* iValue;
592 // CParserPropertyValueInt
594 class CParserPropertyValueInt : public CParserPropertyValue
595 /** An integer property value parser.
597 This stores a property value as a signed integer. For example, an employee
598 ID number might be stored using this class.
600 The UID for an integer property value is KVersitPropertyIntUid.
606 IMPORT_C CParserPropertyValueInt(TInt aValue);
607 inline TInt Value() const;
608 public: // from CParserPropertyValue
609 IMPORT_C void ExternalizeL(RWriteStream& aStream,const Versit::TEncodingAndCharset& aEncodingCharset,TInt /*aLengthOutput*/);
618 class CParserProperty : public CBase
619 /** A vCard or vCalendar property.
621 A property consists of a name, an optional value and one or more optional
624 The name, value and parameters are initialised on construction.
626 Versit properties have the general form:
628 Property Name (; Property Parameter Name(=Property Parameter Value)* : Property
631 where items in brackets are optional and * indicates that the item may be
634 For instance, TEL; HOME; ENCODING=QUOTED-PRINTABLE; CHARSET=US-ASCII : 01234 567890
636 Here, TEL is the property name; HOME, ENCODING and CHARSET are property parameter
637 names; QUOTED-PRINTABLE and US-ASCII are property parameter values. The component
638 following the colon is the property value.
640 Properties also have a name UID, which set during internalisation of a property
641 and used only during internalisation. It is set by SetNameUid() and is used
642 to allow number comparisons during internalisation. This provides a faster
643 alternative to string comparisons when checking a property to see if it is
644 a significant one (e.g. a begin or binary property). This is the only use
645 of the name UID: it is not used during externalisation of a property.
647 Note that grouped properties are supported by the derived class, CParserGroupedProperty.
648 The vCalender parser does not have property groups, and so stores all properties
649 using this base class, whereas the vCard parser stores all properties using
650 CParserGroupedProperty.
656 IMPORT_C static CParserProperty* NewL(CParserPropertyValue& aPropertyValue, const TDesC8& aName, CArrayPtr<CParserParam>* aArrayOfParams);
657 IMPORT_C CParserProperty(CArrayPtr<CParserParam>* aArrayOfParams);
658 IMPORT_C ~CParserProperty();
659 IMPORT_C virtual void ExternalizeL(RWriteStream& aStream, CVersitParser* aVersitParser = NULL);
660 IMPORT_C CParserParam* Param(const TDesC8& aParamName) const; // note params can only appear once
661 IMPORT_C void AddParamL(CParserParam* aParam);
662 IMPORT_C void DeleteParam(TDesC8& aParamName);
663 IMPORT_C void SetNameL(const TDesC8& aName);
664 IMPORT_C virtual TBool SupportsInterface(const TUid& /*aInterfaceUid*/) const;
665 IMPORT_C TPtrC8 Name() const;
666 inline void SetValue(CParserPropertyValue* aPropertyValue);
667 inline CParserPropertyValue* Value() const;
668 inline TUid Uid() const;
669 inline void SetNameUid(TUid aUid);
670 inline TUid NameUid() const;
671 inline void SetParamArray(CArrayPtr<CParserParam>* aArrayOfParams);
674 IMPORT_C TBool LoadBinaryValuesFromFilesL(RFs& aFileSession);
675 IMPORT_C TBool SaveBinaryValuesToFilesL(TInt aSizeThreshold,const TDesC& aPath,RFs& aFileSession);
677 IMPORT_C CParserProperty(CParserPropertyValue& aPropertyValue, CArrayPtr<CParserParam>* aArrayOfParams);
678 IMPORT_C static void ConstructSelfL(CParserProperty& aSelf,const TDesC8& aName);
681 IMPORT_C CArrayPtr<CParserParam>* ParamArray()const;
684 CParserPropertyValue* iPropertyValue;
685 HBufC8* iPropertyName;
686 TUid iPropertyNameUid;
687 CArrayPtr<CParserParam>* iArrayOfParams;
690 friend class CVersitParser;
691 inline HBufC8*& NameBuf();
692 IMPORT_C virtual void Reserved();
693 void ReadBinaryDataL(const CBufSeg* aBufseg_ptr,HBufC8** aBuffer);
694 void GenerateNameAndCreateFileL(RFs& aFileSession,TPtr8 aPropertyName,RFile& aFile,TDes& aFileName);